Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(660)

Side by Side Diff: webkit/plugins/ppapi/ppapi_plugin_instance.cc

Issue 6538028: A proposal for an initial postMessage interface. This will allow JavaScript ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
(...skipping 24 matching lines...) Expand all
35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" 38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
39 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 39 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
40 #include "ui/gfx/rect.h" 40 #include "ui/gfx/rect.h"
41 #include "ui/gfx/skia_util.h" 41 #include "ui/gfx/skia_util.h"
42 #include "webkit/plugins/ppapi/common.h" 42 #include "webkit/plugins/ppapi/common.h"
43 #include "webkit/plugins/ppapi/event_conversion.h" 43 #include "webkit/plugins/ppapi/event_conversion.h"
44 #include "webkit/plugins/ppapi/fullscreen_container.h" 44 #include "webkit/plugins/ppapi/fullscreen_container.h"
45 #include "webkit/plugins/ppapi/message_channel.h"
45 #include "webkit/plugins/ppapi/plugin_delegate.h" 46 #include "webkit/plugins/ppapi/plugin_delegate.h"
46 #include "webkit/plugins/ppapi/plugin_module.h" 47 #include "webkit/plugins/ppapi/plugin_module.h"
47 #include "webkit/plugins/ppapi/plugin_object.h" 48 #include "webkit/plugins/ppapi/plugin_object.h"
48 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" 49 #include "webkit/plugins/ppapi/ppb_buffer_impl.h"
49 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" 50 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h"
50 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" 51 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
51 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" 52 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h"
52 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" 53 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h"
53 #include "webkit/plugins/ppapi/ppp_pdf.h" 54 #include "webkit/plugins/ppapi/ppp_pdf.h"
54 #include "webkit/plugins/ppapi/string.h" 55 #include "webkit/plugins/ppapi/string.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 typedef bool (*RenderPDFPageToDCProc)( 93 typedef bool (*RenderPDFPageToDCProc)(
93 const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc, 94 const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc,
94 int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y, 95 int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y,
95 int bounds_width, int bounds_height, bool fit_to_bounds, 96 int bounds_width, int bounds_height, bool fit_to_bounds,
96 bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds); 97 bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds);
97 #endif // defined(OS_WIN) 98 #endif // defined(OS_WIN)
98 99
99 namespace { 100 namespace {
100 101
101 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \ 102 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \
102 COMPILE_ASSERT(int(WebCursorInfo::webkit_name) == int(np_name), \ 103 COMPILE_ASSERT(static_cast<int>(WebCursorInfo::webkit_name) \
104 == static_cast<int>(np_name), \
103 mismatching_enums) 105 mismatching_enums)
104 106
105 COMPILE_ASSERT_MATCHING_ENUM(TypePointer, PP_CURSORTYPE_POINTER); 107 COMPILE_ASSERT_MATCHING_ENUM(TypePointer, PP_CURSORTYPE_POINTER);
106 COMPILE_ASSERT_MATCHING_ENUM(TypeCross, PP_CURSORTYPE_CROSS); 108 COMPILE_ASSERT_MATCHING_ENUM(TypeCross, PP_CURSORTYPE_CROSS);
107 COMPILE_ASSERT_MATCHING_ENUM(TypeHand, PP_CURSORTYPE_HAND); 109 COMPILE_ASSERT_MATCHING_ENUM(TypeHand, PP_CURSORTYPE_HAND);
108 COMPILE_ASSERT_MATCHING_ENUM(TypeIBeam, PP_CURSORTYPE_IBEAM); 110 COMPILE_ASSERT_MATCHING_ENUM(TypeIBeam, PP_CURSORTYPE_IBEAM);
109 COMPILE_ASSERT_MATCHING_ENUM(TypeWait, PP_CURSORTYPE_WAIT); 111 COMPILE_ASSERT_MATCHING_ENUM(TypeWait, PP_CURSORTYPE_WAIT);
110 COMPILE_ASSERT_MATCHING_ENUM(TypeHelp, PP_CURSORTYPE_HELP); 112 COMPILE_ASSERT_MATCHING_ENUM(TypeHelp, PP_CURSORTYPE_HELP);
111 COMPILE_ASSERT_MATCHING_ENUM(TypeEastResize, PP_CURSORTYPE_EASTRESIZE); 113 COMPILE_ASSERT_MATCHING_ENUM(TypeEastResize, PP_CURSORTYPE_EASTRESIZE);
112 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthResize, PP_CURSORTYPE_NORTHRESIZE); 114 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthResize, PP_CURSORTYPE_NORTHRESIZE);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 196
195 PP_Var ExecuteScript(PP_Instance instance_id, 197 PP_Var ExecuteScript(PP_Instance instance_id,
196 PP_Var script, 198 PP_Var script,
197 PP_Var* exception) { 199 PP_Var* exception) {
198 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); 200 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
199 if (!instance) 201 if (!instance)
200 return PP_MakeUndefined(); 202 return PP_MakeUndefined();
201 return instance->ExecuteScript(script, exception); 203 return instance->ExecuteScript(script, exception);
202 } 204 }
203 205
206 void PostMessage(PP_Instance instance_id, PP_Var message) {
207 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
208 if (!instance)
209 return;
210 instance->PostMessage(message);
211 }
212
204 const PPB_Instance ppb_instance = { 213 const PPB_Instance ppb_instance = {
205 &GetWindowObject, 214 &GetWindowObject,
206 &GetOwnerElementObject, 215 &GetOwnerElementObject,
207 &BindGraphics, 216 &BindGraphics,
208 &IsFullFrame, 217 &IsFullFrame,
209 &ExecuteScript, 218 &ExecuteScript,
219 &PostMessage
210 }; 220 };
211 221
212 void NumberOfFindResultsChanged(PP_Instance instance_id, 222 void NumberOfFindResultsChanged(PP_Instance instance_id,
213 int32_t total, 223 int32_t total,
214 PP_Bool final_result) { 224 PP_Bool final_result) {
215 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); 225 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
216 if (!instance) 226 if (!instance)
217 return; 227 return;
218 228
219 DCHECK_NE(instance->find_identifier(), -1); 229 DCHECK_NE(instance->find_identifier(), -1);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 317
308 const PPB_Zoom_Dev ppb_zoom = { 318 const PPB_Zoom_Dev ppb_zoom = {
309 &ZoomChanged, 319 &ZoomChanged,
310 &ZoomLimitsChanged 320 &ZoomLimitsChanged
311 }; 321 };
312 322
313 } // namespace 323 } // namespace
314 324
315 PluginInstance::PluginInstance(PluginDelegate* delegate, 325 PluginInstance::PluginInstance(PluginDelegate* delegate,
316 PluginModule* module, 326 PluginModule* module,
317 const PPP_Instance* instance_interface) 327 const PPP_Instance* instance_interface,
328 InterfaceOwner ppp_instance_owner)
318 : delegate_(delegate), 329 : delegate_(delegate),
319 module_(module), 330 module_(module),
320 instance_interface_(instance_interface), 331 instance_interface_(instance_interface),
321 pp_instance_(0), 332 pp_instance_(0),
322 container_(NULL), 333 container_(NULL),
323 full_frame_(false), 334 full_frame_(false),
324 has_webkit_focus_(false), 335 has_webkit_focus_(false),
325 has_content_area_focus_(false), 336 has_content_area_focus_(false),
326 find_identifier_(-1), 337 find_identifier_(-1),
327 plugin_find_interface_(NULL), 338 plugin_find_interface_(NULL),
328 plugin_pdf_interface_(NULL), 339 plugin_pdf_interface_(NULL),
329 plugin_selection_interface_(NULL), 340 plugin_selection_interface_(NULL),
330 plugin_zoom_interface_(NULL), 341 plugin_zoom_interface_(NULL),
331 #if defined(OS_LINUX) 342 #if defined(OS_LINUX)
332 canvas_(NULL), 343 canvas_(NULL),
333 #endif // defined(OS_LINUX) 344 #endif // defined(OS_LINUX)
334 plugin_print_interface_(NULL), 345 plugin_print_interface_(NULL),
335 plugin_graphics_3d_interface_(NULL), 346 plugin_graphics_3d_interface_(NULL),
336 always_on_top_(false), 347 always_on_top_(false),
337 fullscreen_container_(NULL), 348 fullscreen_container_(NULL),
338 fullscreen_(false) { 349 fullscreen_(false),
350 message_channel_(NULL),
351 ppp_instance_owner_(ppp_instance_owner) {
339 pp_instance_ = ResourceTracker::Get()->AddInstance(this); 352 pp_instance_ = ResourceTracker::Get()->AddInstance(this);
340 353
341 memset(&current_print_settings_, 0, sizeof(current_print_settings_)); 354 memset(&current_print_settings_, 0, sizeof(current_print_settings_));
342 DCHECK(delegate); 355 DCHECK(delegate);
343 module_->InstanceCreated(this); 356 module_->InstanceCreated(this);
344 delegate_->InstanceCreated(this); 357 delegate_->InstanceCreated(this);
358 message_channel_.reset(new MessageChannel(this));
345 } 359 }
346 360
347 PluginInstance::~PluginInstance() { 361 PluginInstance::~PluginInstance() {
348 // Free all the plugin objects. This will automatically clear the back- 362 // Free all the plugin objects. This will automatically clear the back-
349 // pointer from the NPObject so WebKit can't call into the plugin any more. 363 // pointer from the NPObject so WebKit can't call into the plugin any more.
350 // 364 //
351 // Swap out the set so we can delete from it (the objects will try to 365 // Swap out the set so we can delete from it (the objects will try to
352 // unregister themselves inside the delete call). 366 // unregister themselves inside the delete call).
353 PluginObjectSet plugin_object_copy; 367 PluginObjectSet plugin_object_copy;
354 live_plugin_objects_.swap(plugin_object_copy); 368 live_plugin_objects_.swap(plugin_object_copy);
355 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); 369 for (PluginObjectSet::iterator i = plugin_object_copy.begin();
356 i != plugin_object_copy.end(); ++i) 370 i != plugin_object_copy.end(); ++i)
357 delete *i; 371 delete *i;
358 372
359 delegate_->InstanceDeleted(this); 373 delegate_->InstanceDeleted(this);
360 module_->InstanceDeleted(this); 374 module_->InstanceDeleted(this);
361 375
362 ResourceTracker::Get()->InstanceDeleted(pp_instance_); 376 ResourceTracker::Get()->InstanceDeleted(pp_instance_);
363 #if defined(OS_LINUX) 377 #if defined(OS_LINUX)
364 ranges_.clear(); 378 ranges_.clear();
365 #endif // defined(OS_LINUX) 379 #endif // defined(OS_LINUX)
380
381 if (BROWSER_OWNS_INTERFACE == ppp_instance_owner_)
382 delete const_cast<PPP_Instance*>(instance_interface_);
366 } 383 }
367 384
368 // static 385 // static
369 const PPB_Instance* PluginInstance::GetInterface() { 386 const void* PluginInstance::GetInterface(const std::string& interface) {
370 return &ppb_instance; 387 // At the time of writing, we support both 0.4 and 0.5. But for future-
388 // proofing, we also compare to PPB_INSTANCE_INTERFACE so that we can work
389 // with later versions, assuming other parts work. If PPB_Instance changes
390 // in a fashion that breaks the struct layout (e.g. modifying or deleting
391 // functions), this code must either get more complicated (to return a
392 // different, backwards-compatible struct) or just get rid of support for
393 // 0.4 and 0.5.
394 if ((interface == PPB_INSTANCE_INTERFACE_0_4)
395 || (interface == PPB_INSTANCE_INTERFACE_0_5)
396 || (interface == PPB_INSTANCE_INTERFACE))
397 return &ppb_instance;
398 return NULL;
371 } 399 }
372 400
373 // static 401 // static
374 const PPB_Find_Dev* PluginInstance::GetFindInterface() { 402 const PPB_Find_Dev* PluginInstance::GetFindInterface() {
375 return &ppb_find; 403 return &ppb_find;
376 } 404 }
377 405
378 // static 406 // static
379 const PPB_Fullscreen_Dev* PluginInstance::GetFullscreenInterface() { 407 const PPB_Fullscreen_Dev* PluginInstance::GetFullscreenInterface() {
380 return &ppb_fullscreen; 408 return &ppb_fullscreen;
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 try_catch.SetException("Exception caught"); 611 try_catch.SetException("Exception caught");
584 WebBindings::releaseVariantValue(&result); 612 WebBindings::releaseVariantValue(&result);
585 return PP_MakeUndefined(); 613 return PP_MakeUndefined();
586 } 614 }
587 615
588 PP_Var ret = Var::NPVariantToPPVar(this, &result); 616 PP_Var ret = Var::NPVariantToPPVar(this, &result);
589 WebBindings::releaseVariantValue(&result); 617 WebBindings::releaseVariantValue(&result);
590 return ret; 618 return ret;
591 } 619 }
592 620
621 void PluginInstance::PostMessage(PP_Var message) {
622 message_channel_->PostMessageToJavaScript(message);
623 }
624
593 void PluginInstance::Delete() { 625 void PluginInstance::Delete() {
594 // Keep a reference on the stack. See NOTE above. 626 // Keep a reference on the stack. See NOTE above.
595 scoped_refptr<PluginInstance> ref(this); 627 scoped_refptr<PluginInstance> ref(this);
596 instance_interface_->DidDestroy(pp_instance()); 628 instance_interface_->DidDestroy(pp_instance());
597 629
598 if (fullscreen_container_) { 630 if (fullscreen_container_) {
599 fullscreen_container_->Destroy(); 631 fullscreen_container_->Destroy();
600 fullscreen_container_ = NULL; 632 fullscreen_container_ = NULL;
601 } 633 }
602 container_ = NULL; 634 container_ = NULL;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 for (size_t i = 0; i < pp_events.size(); i++) { 674 for (size_t i = 0; i < pp_events.size(); i++) {
643 rv |= PPBoolToBool(instance_interface_->HandleInputEvent(pp_instance(), 675 rv |= PPBoolToBool(instance_interface_->HandleInputEvent(pp_instance(),
644 &pp_events[i])); 676 &pp_events[i]));
645 } 677 }
646 678
647 if (cursor_.get()) 679 if (cursor_.get())
648 *cursor_info = *cursor_; 680 *cursor_info = *cursor_;
649 return rv; 681 return rv;
650 } 682 }
651 683
684 void PluginInstance::HandleMessage(PP_Var message) {
685 if ((instance_interface_ != NULL) &&
686 (instance_interface_->HandleMessage != NULL)) {
687 instance_interface_->HandleMessage(pp_instance(), message);
688 }
689 }
690
652 PP_Var PluginInstance::GetInstanceObject() { 691 PP_Var PluginInstance::GetInstanceObject() {
653 return instance_interface_->GetInstanceObject(pp_instance()); 692 return instance_interface_->GetInstanceObject(pp_instance());
654 } 693 }
655 694
656 void PluginInstance::ViewChanged(const gfx::Rect& position, 695 void PluginInstance::ViewChanged(const gfx::Rect& position,
657 const gfx::Rect& clip) { 696 const gfx::Rect& clip) {
658 fullscreen_ = (fullscreen_container_ != NULL); 697 fullscreen_ = (fullscreen_container_ != NULL);
659 position_ = position; 698 position_ = position;
660 699
661 if (clip.IsEmpty()) { 700 if (clip.IsEmpty()) {
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 return found->second; 1376 return found->second;
1338 } 1377 }
1339 1378
1340 bool PluginInstance::IsFullPagePlugin() const { 1379 bool PluginInstance::IsFullPagePlugin() const {
1341 WebFrame* frame = container()->element().document().frame(); 1380 WebFrame* frame = container()->element().document().frame();
1342 return frame->view()->mainFrame()->document().isPluginDocument(); 1381 return frame->view()->mainFrame()->document().isPluginDocument();
1343 } 1382 }
1344 1383
1345 } // namespace ppapi 1384 } // namespace ppapi
1346 } // namespace webkit 1385 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698