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

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

Issue 6716005: A proposal and implementation for an initial postMessage interface. These in... (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"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "ppapi/c/dev/ppb_find_dev.h" 12 #include "ppapi/c/dev/ppb_find_dev.h"
13 #include "ppapi/c/dev/ppb_fullscreen_dev.h" 13 #include "ppapi/c/dev/ppb_fullscreen_dev.h"
14 #include "ppapi/c/dev/ppb_messaging_dev.h"
14 #include "ppapi/c/dev/ppb_zoom_dev.h" 15 #include "ppapi/c/dev/ppb_zoom_dev.h"
15 #include "ppapi/c/dev/ppp_find_dev.h" 16 #include "ppapi/c/dev/ppp_find_dev.h"
17 #include "ppapi/c/dev/ppp_messaging_dev.h"
16 #include "ppapi/c/dev/ppp_selection_dev.h" 18 #include "ppapi/c/dev/ppp_selection_dev.h"
17 #include "ppapi/c/dev/ppp_zoom_dev.h" 19 #include "ppapi/c/dev/ppp_zoom_dev.h"
18 #include "ppapi/c/pp_input_event.h" 20 #include "ppapi/c/pp_input_event.h"
19 #include "ppapi/c/pp_instance.h" 21 #include "ppapi/c/pp_instance.h"
20 #include "ppapi/c/pp_rect.h" 22 #include "ppapi/c/pp_rect.h"
21 #include "ppapi/c/pp_resource.h" 23 #include "ppapi/c/pp_resource.h"
22 #include "ppapi/c/pp_var.h" 24 #include "ppapi/c/pp_var.h"
23 #include "ppapi/c/ppb_core.h" 25 #include "ppapi/c/ppb_core.h"
24 #include "ppapi/c/ppb_instance.h" 26 #include "ppapi/c/ppb_instance.h"
25 #include "ppapi/c/ppp_instance.h" 27 #include "ppapi/c/ppp_instance.h"
26 #include "printing/units.h" 28 #include "printing/units.h"
27 #include "skia/ext/vector_platform_device.h" 29 #include "skia/ext/vector_platform_device.h"
28 #include "skia/ext/platform_canvas.h" 30 #include "skia/ext/platform_canvas.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" 38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 39 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" 40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
39 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
40 #include "ui/gfx/rect.h" 42 #include "ui/gfx/rect.h"
41 #include "ui/gfx/skia_util.h" 43 #include "ui/gfx/skia_util.h"
42 #include "webkit/plugins/ppapi/common.h" 44 #include "webkit/plugins/ppapi/common.h"
43 #include "webkit/plugins/ppapi/event_conversion.h" 45 #include "webkit/plugins/ppapi/event_conversion.h"
44 #include "webkit/plugins/ppapi/fullscreen_container.h" 46 #include "webkit/plugins/ppapi/fullscreen_container.h"
47 #include "webkit/plugins/ppapi/message_channel.h"
45 #include "webkit/plugins/ppapi/plugin_delegate.h" 48 #include "webkit/plugins/ppapi/plugin_delegate.h"
46 #include "webkit/plugins/ppapi/plugin_module.h" 49 #include "webkit/plugins/ppapi/plugin_module.h"
47 #include "webkit/plugins/ppapi/plugin_object.h" 50 #include "webkit/plugins/ppapi/plugin_object.h"
48 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" 51 #include "webkit/plugins/ppapi/ppb_buffer_impl.h"
49 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" 52 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h"
50 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" 53 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
51 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" 54 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h"
52 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" 55 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h"
53 #include "webkit/plugins/ppapi/ppp_pdf.h" 56 #include "webkit/plugins/ppapi/ppp_pdf.h"
54 #include "webkit/plugins/ppapi/string.h" 57 #include "webkit/plugins/ppapi/string.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 typedef bool (*RenderPDFPageToDCProc)( 96 typedef bool (*RenderPDFPageToDCProc)(
94 const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc, 97 const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc,
95 int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y, 98 int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y,
96 int bounds_width, int bounds_height, bool fit_to_bounds, 99 int bounds_width, int bounds_height, bool fit_to_bounds,
97 bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds); 100 bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds);
98 #endif // defined(OS_WIN) 101 #endif // defined(OS_WIN)
99 102
100 namespace { 103 namespace {
101 104
102 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \ 105 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \
103 COMPILE_ASSERT(int(WebCursorInfo::webkit_name) == int(np_name), \ 106 COMPILE_ASSERT(static_cast<int>(WebCursorInfo::webkit_name) \
107 == static_cast<int>(np_name), \
104 mismatching_enums) 108 mismatching_enums)
105 109
106 COMPILE_ASSERT_MATCHING_ENUM(TypePointer, PP_CURSORTYPE_POINTER); 110 COMPILE_ASSERT_MATCHING_ENUM(TypePointer, PP_CURSORTYPE_POINTER);
107 COMPILE_ASSERT_MATCHING_ENUM(TypeCross, PP_CURSORTYPE_CROSS); 111 COMPILE_ASSERT_MATCHING_ENUM(TypeCross, PP_CURSORTYPE_CROSS);
108 COMPILE_ASSERT_MATCHING_ENUM(TypeHand, PP_CURSORTYPE_HAND); 112 COMPILE_ASSERT_MATCHING_ENUM(TypeHand, PP_CURSORTYPE_HAND);
109 COMPILE_ASSERT_MATCHING_ENUM(TypeIBeam, PP_CURSORTYPE_IBEAM); 113 COMPILE_ASSERT_MATCHING_ENUM(TypeIBeam, PP_CURSORTYPE_IBEAM);
110 COMPILE_ASSERT_MATCHING_ENUM(TypeWait, PP_CURSORTYPE_WAIT); 114 COMPILE_ASSERT_MATCHING_ENUM(TypeWait, PP_CURSORTYPE_WAIT);
111 COMPILE_ASSERT_MATCHING_ENUM(TypeHelp, PP_CURSORTYPE_HELP); 115 COMPILE_ASSERT_MATCHING_ENUM(TypeHelp, PP_CURSORTYPE_HELP);
112 COMPILE_ASSERT_MATCHING_ENUM(TypeEastResize, PP_CURSORTYPE_EASTRESIZE); 116 COMPILE_ASSERT_MATCHING_ENUM(TypeEastResize, PP_CURSORTYPE_EASTRESIZE);
113 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthResize, PP_CURSORTYPE_NORTHRESIZE); 117 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthResize, PP_CURSORTYPE_NORTHRESIZE);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 259
256 PP_Bool GetScreenSize(PP_Instance instance_id, PP_Size* size) { 260 PP_Bool GetScreenSize(PP_Instance instance_id, PP_Size* size) {
257 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); 261 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
258 if (!instance || !size) 262 if (!instance || !size)
259 return PP_FALSE; 263 return PP_FALSE;
260 gfx::Size screen_size = instance->delegate()->GetScreenSize(); 264 gfx::Size screen_size = instance->delegate()->GetScreenSize();
261 *size = PP_MakeSize(screen_size.width(), screen_size.height()); 265 *size = PP_MakeSize(screen_size.width(), screen_size.height());
262 return PP_TRUE; 266 return PP_TRUE;
263 } 267 }
264 268
265
266 const PPB_Fullscreen_Dev ppb_fullscreen = { 269 const PPB_Fullscreen_Dev ppb_fullscreen = {
267 &IsFullscreen, 270 &IsFullscreen,
268 &SetFullscreen, 271 &SetFullscreen,
269 &GetScreenSize 272 &GetScreenSize
270 }; 273 };
271 274
275 void PostMessage(PP_Instance instance_id, PP_Var message) {
276 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
277 if (!instance)
278 return;
279 instance->PostMessage(message);
280 }
281
282 const PPB_Messaging_Dev ppb_messaging = {
283 &PostMessage
284 };
285
272 void ZoomChanged(PP_Instance instance_id, double factor) { 286 void ZoomChanged(PP_Instance instance_id, double factor) {
273 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); 287 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
274 if (!instance) 288 if (!instance)
275 return; 289 return;
276 290
277 // We only want to tell the page to change its zoom if the whole page is the 291 // We only want to tell the page to change its zoom if the whole page is the
278 // plugin. If we're in an iframe, then don't do anything. 292 // plugin. If we're in an iframe, then don't do anything.
279 if (!instance->IsFullPagePlugin()) 293 if (!instance->IsFullPagePlugin())
280 return; 294 return;
281 295
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 : delegate_(delegate), 333 : delegate_(delegate),
320 module_(module), 334 module_(module),
321 instance_interface_(instance_interface), 335 instance_interface_(instance_interface),
322 pp_instance_(0), 336 pp_instance_(0),
323 container_(NULL), 337 container_(NULL),
324 full_frame_(false), 338 full_frame_(false),
325 has_webkit_focus_(false), 339 has_webkit_focus_(false),
326 has_content_area_focus_(false), 340 has_content_area_focus_(false),
327 find_identifier_(-1), 341 find_identifier_(-1),
328 plugin_find_interface_(NULL), 342 plugin_find_interface_(NULL),
343 plugin_messaging_interface_(NULL),
329 plugin_pdf_interface_(NULL), 344 plugin_pdf_interface_(NULL),
330 plugin_selection_interface_(NULL), 345 plugin_selection_interface_(NULL),
331 plugin_zoom_interface_(NULL), 346 plugin_zoom_interface_(NULL),
347 checked_for_plugin_messaging_interface_(false),
332 #if defined(OS_LINUX) 348 #if defined(OS_LINUX)
333 canvas_(NULL), 349 canvas_(NULL),
334 #endif // defined(OS_LINUX) 350 #endif // defined(OS_LINUX)
335 plugin_print_interface_(NULL), 351 plugin_print_interface_(NULL),
336 plugin_graphics_3d_interface_(NULL), 352 plugin_graphics_3d_interface_(NULL),
337 always_on_top_(false), 353 always_on_top_(false),
338 fullscreen_container_(NULL), 354 fullscreen_container_(NULL),
339 fullscreen_(false), 355 fullscreen_(false),
356 message_channel_(NULL),
340 sad_plugin_(NULL) { 357 sad_plugin_(NULL) {
341 pp_instance_ = ResourceTracker::Get()->AddInstance(this); 358 pp_instance_ = ResourceTracker::Get()->AddInstance(this);
342 359
343 memset(&current_print_settings_, 0, sizeof(current_print_settings_)); 360 memset(&current_print_settings_, 0, sizeof(current_print_settings_));
344 DCHECK(delegate); 361 DCHECK(delegate);
345 module_->InstanceCreated(this); 362 module_->InstanceCreated(this);
346 delegate_->InstanceCreated(this); 363 delegate_->InstanceCreated(this);
364 message_channel_.reset(new MessageChannel(this));
347 } 365 }
348 366
349 PluginInstance::~PluginInstance() { 367 PluginInstance::~PluginInstance() {
350 // Free all the plugin objects. This will automatically clear the back- 368 // Free all the plugin objects. This will automatically clear the back-
351 // pointer from the NPObject so WebKit can't call into the plugin any more. 369 // pointer from the NPObject so WebKit can't call into the plugin any more.
352 // 370 //
353 // Swap out the set so we can delete from it (the objects will try to 371 // Swap out the set so we can delete from it (the objects will try to
354 // unregister themselves inside the delete call). 372 // unregister themselves inside the delete call).
355 PluginObjectSet plugin_object_copy; 373 PluginObjectSet plugin_object_copy;
356 live_plugin_objects_.swap(plugin_object_copy); 374 live_plugin_objects_.swap(plugin_object_copy);
(...skipping 19 matching lines...) Expand all
376 const PPB_Find_Dev* PluginInstance::GetFindInterface() { 394 const PPB_Find_Dev* PluginInstance::GetFindInterface() {
377 return &ppb_find; 395 return &ppb_find;
378 } 396 }
379 397
380 // static 398 // static
381 const PPB_Fullscreen_Dev* PluginInstance::GetFullscreenInterface() { 399 const PPB_Fullscreen_Dev* PluginInstance::GetFullscreenInterface() {
382 return &ppb_fullscreen; 400 return &ppb_fullscreen;
383 } 401 }
384 402
385 // static 403 // static
404 const PPB_Messaging_Dev* PluginInstance::GetMessagingInterface() {
405 return &ppb_messaging;
406 }
407
408 // static
386 const PPB_Zoom_Dev* PluginInstance::GetZoomInterface() { 409 const PPB_Zoom_Dev* PluginInstance::GetZoomInterface() {
387 return &ppb_zoom; 410 return &ppb_zoom;
388 } 411 }
389 412
390 // NOTE: Any of these methods that calls into the plugin needs to take into 413 // NOTE: Any of these methods that calls into the plugin needs to take into
391 // account that the plugin may use Var to remove the <embed> from the DOM, which 414 // account that the plugin may use Var to remove the <embed> from the DOM, which
392 // will make the WebPluginImpl drop its reference, usually the last one. If a 415 // will make the WebPluginImpl drop its reference, usually the last one. If a
393 // method needs to access a member of the instance after the call has returned, 416 // method needs to access a member of the instance after the call has returned,
394 // then it needs to keep its own reference on the stack. 417 // then it needs to keep its own reference on the stack.
395 418
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 try_catch.SetException("Exception caught"); 620 try_catch.SetException("Exception caught");
598 WebBindings::releaseVariantValue(&result); 621 WebBindings::releaseVariantValue(&result);
599 return PP_MakeUndefined(); 622 return PP_MakeUndefined();
600 } 623 }
601 624
602 PP_Var ret = Var::NPVariantToPPVar(this, &result); 625 PP_Var ret = Var::NPVariantToPPVar(this, &result);
603 WebBindings::releaseVariantValue(&result); 626 WebBindings::releaseVariantValue(&result);
604 return ret; 627 return ret;
605 } 628 }
606 629
630 void PluginInstance::PostMessage(PP_Var message) {
631 message_channel_->PostMessageToJavaScript(message);
632 }
633
607 void PluginInstance::Delete() { 634 void PluginInstance::Delete() {
608 // Keep a reference on the stack. See NOTE above. 635 // Keep a reference on the stack. See NOTE above.
609 scoped_refptr<PluginInstance> ref(this); 636 scoped_refptr<PluginInstance> ref(this);
610 instance_interface_->DidDestroy(pp_instance()); 637 instance_interface_->DidDestroy(pp_instance());
611 638
612 if (fullscreen_container_) { 639 if (fullscreen_container_) {
613 fullscreen_container_->Destroy(); 640 fullscreen_container_->Destroy();
614 fullscreen_container_ = NULL; 641 fullscreen_container_ = NULL;
615 } 642 }
616 container_ = NULL; 643 container_ = NULL;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 for (size_t i = 0; i < pp_events.size(); i++) { 683 for (size_t i = 0; i < pp_events.size(); i++) {
657 rv |= PPBoolToBool(instance_interface_->HandleInputEvent(pp_instance(), 684 rv |= PPBoolToBool(instance_interface_->HandleInputEvent(pp_instance(),
658 &pp_events[i])); 685 &pp_events[i]));
659 } 686 }
660 687
661 if (cursor_.get()) 688 if (cursor_.get())
662 *cursor_info = *cursor_; 689 *cursor_info = *cursor_;
663 return rv; 690 return rv;
664 } 691 }
665 692
693 void PluginInstance::HandleMessage(PP_Var message) {
694 // Keep a reference on the stack. See NOTE above.
695 scoped_refptr<PluginInstance> ref(this);
696 if (!LoadMessagingInterface())
697 return;
698 plugin_messaging_interface_->HandleMessage(pp_instance(), message);
699 }
700
666 PP_Var PluginInstance::GetInstanceObject() { 701 PP_Var PluginInstance::GetInstanceObject() {
667 return instance_interface_->GetInstanceObject(pp_instance()); 702 return instance_interface_->GetInstanceObject(pp_instance());
668 } 703 }
669 704
670 void PluginInstance::ViewChanged(const gfx::Rect& position, 705 void PluginInstance::ViewChanged(const gfx::Rect& position,
671 const gfx::Rect& clip) { 706 const gfx::Rect& clip) {
672 fullscreen_ = (fullscreen_container_ != NULL); 707 fullscreen_ = (fullscreen_container_ != NULL);
673 position_ = position; 708 position_ = position;
674 709
675 if (clip.IsEmpty()) { 710 if (clip.IsEmpty()) {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 bool PluginInstance::LoadFindInterface() { 867 bool PluginInstance::LoadFindInterface() {
833 if (!plugin_find_interface_) { 868 if (!plugin_find_interface_) {
834 plugin_find_interface_ = 869 plugin_find_interface_ =
835 reinterpret_cast<const PPP_Find_Dev*>(module_->GetPluginInterface( 870 reinterpret_cast<const PPP_Find_Dev*>(module_->GetPluginInterface(
836 PPP_FIND_DEV_INTERFACE)); 871 PPP_FIND_DEV_INTERFACE));
837 } 872 }
838 873
839 return !!plugin_find_interface_; 874 return !!plugin_find_interface_;
840 } 875 }
841 876
877 bool PluginInstance::LoadMessagingInterface() {
878 if (!checked_for_plugin_messaging_interface_) {
879 checked_for_plugin_messaging_interface_ = true;
880 plugin_messaging_interface_ =
881 reinterpret_cast<const PPP_Messaging_Dev*>(module_->GetPluginInterface(
882 PPP_MESSAGING_DEV_INTERFACE));
883 }
884
885 return !!plugin_messaging_interface_;
886 }
887
842 bool PluginInstance::LoadPdfInterface() { 888 bool PluginInstance::LoadPdfInterface() {
843 if (!plugin_pdf_interface_) { 889 if (!plugin_pdf_interface_) {
844 plugin_pdf_interface_ = 890 plugin_pdf_interface_ =
845 reinterpret_cast<const PPP_Pdf*>(module_->GetPluginInterface( 891 reinterpret_cast<const PPP_Pdf*>(module_->GetPluginInterface(
846 PPP_PDF_INTERFACE)); 892 PPP_PDF_INTERFACE));
847 } 893 }
848 894
849 return !!plugin_pdf_interface_; 895 return !!plugin_pdf_interface_;
850 } 896 }
851 897
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 return found->second; 1412 return found->second;
1367 } 1413 }
1368 1414
1369 bool PluginInstance::IsFullPagePlugin() const { 1415 bool PluginInstance::IsFullPagePlugin() const {
1370 WebFrame* frame = container()->element().document().frame(); 1416 WebFrame* frame = container()->element().document().frame();
1371 return frame->view()->mainFrame()->document().isPluginDocument(); 1417 return frame->view()->mainFrame()->document().isPluginDocument();
1372 } 1418 }
1373 1419
1374 } // namespace ppapi 1420 } // namespace ppapi
1375 } // namespace webkit 1421 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698