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

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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 plugin_pdf_interface_(NULL), 338 plugin_pdf_interface_(NULL),
329 plugin_selection_interface_(NULL), 339 plugin_selection_interface_(NULL),
330 plugin_zoom_interface_(NULL), 340 plugin_zoom_interface_(NULL),
331 #if defined(OS_LINUX) 341 #if defined(OS_LINUX)
332 canvas_(NULL), 342 canvas_(NULL),
333 #endif // defined(OS_LINUX) 343 #endif // defined(OS_LINUX)
334 plugin_print_interface_(NULL), 344 plugin_print_interface_(NULL),
335 plugin_graphics_3d_interface_(NULL), 345 plugin_graphics_3d_interface_(NULL),
336 always_on_top_(false), 346 always_on_top_(false),
337 fullscreen_container_(NULL), 347 fullscreen_container_(NULL),
338 fullscreen_(false) { 348 fullscreen_(false),
349 message_channel_(NULL) {
339 pp_instance_ = ResourceTracker::Get()->AddInstance(this); 350 pp_instance_ = ResourceTracker::Get()->AddInstance(this);
340 351
341 memset(&current_print_settings_, 0, sizeof(current_print_settings_)); 352 memset(&current_print_settings_, 0, sizeof(current_print_settings_));
342 DCHECK(delegate); 353 DCHECK(delegate);
343 module_->InstanceCreated(this); 354 module_->InstanceCreated(this);
344 delegate_->InstanceCreated(this); 355 delegate_->InstanceCreated(this);
356 message_channel_.reset(new MessageChannel(this));
345 } 357 }
346 358
347 PluginInstance::~PluginInstance() { 359 PluginInstance::~PluginInstance() {
348 // Free all the plugin objects. This will automatically clear the back- 360 // 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. 361 // pointer from the NPObject so WebKit can't call into the plugin any more.
350 // 362 //
351 // Swap out the set so we can delete from it (the objects will try to 363 // Swap out the set so we can delete from it (the objects will try to
352 // unregister themselves inside the delete call). 364 // unregister themselves inside the delete call).
353 PluginObjectSet plugin_object_copy; 365 PluginObjectSet plugin_object_copy;
354 live_plugin_objects_.swap(plugin_object_copy); 366 live_plugin_objects_.swap(plugin_object_copy);
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 try_catch.SetException("Exception caught"); 595 try_catch.SetException("Exception caught");
584 WebBindings::releaseVariantValue(&result); 596 WebBindings::releaseVariantValue(&result);
585 return PP_MakeUndefined(); 597 return PP_MakeUndefined();
586 } 598 }
587 599
588 PP_Var ret = Var::NPVariantToPPVar(this, &result); 600 PP_Var ret = Var::NPVariantToPPVar(this, &result);
589 WebBindings::releaseVariantValue(&result); 601 WebBindings::releaseVariantValue(&result);
590 return ret; 602 return ret;
591 } 603 }
592 604
605 void PluginInstance::PostMessage(PP_Var message) {
606 message_channel_->PostMessageToJavaScript(message);
607 }
608
593 void PluginInstance::Delete() { 609 void PluginInstance::Delete() {
594 // Keep a reference on the stack. See NOTE above. 610 // Keep a reference on the stack. See NOTE above.
595 scoped_refptr<PluginInstance> ref(this); 611 scoped_refptr<PluginInstance> ref(this);
596 instance_interface_->DidDestroy(pp_instance()); 612 instance_interface_->DidDestroy(pp_instance());
597 613
598 if (fullscreen_container_) { 614 if (fullscreen_container_) {
599 fullscreen_container_->Destroy(); 615 fullscreen_container_->Destroy();
600 fullscreen_container_ = NULL; 616 fullscreen_container_ = NULL;
601 } 617 }
602 container_ = NULL; 618 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++) { 658 for (size_t i = 0; i < pp_events.size(); i++) {
643 rv |= PPBoolToBool(instance_interface_->HandleInputEvent(pp_instance(), 659 rv |= PPBoolToBool(instance_interface_->HandleInputEvent(pp_instance(),
644 &pp_events[i])); 660 &pp_events[i]));
645 } 661 }
646 662
647 if (cursor_.get()) 663 if (cursor_.get())
648 *cursor_info = *cursor_; 664 *cursor_info = *cursor_;
649 return rv; 665 return rv;
650 } 666 }
651 667
668 void PluginInstance::HandleMessage(PP_Var message) {
669 if ((instance_interface_ != NULL) &&
670 (instance_interface_->HandleMessage != NULL)) {
671 instance_interface_->HandleMessage(pp_instance(), message);
672 }
673 }
674
652 PP_Var PluginInstance::GetInstanceObject() { 675 PP_Var PluginInstance::GetInstanceObject() {
653 return instance_interface_->GetInstanceObject(pp_instance()); 676 return instance_interface_->GetInstanceObject(pp_instance());
654 } 677 }
655 678
656 void PluginInstance::ViewChanged(const gfx::Rect& position, 679 void PluginInstance::ViewChanged(const gfx::Rect& position,
657 const gfx::Rect& clip) { 680 const gfx::Rect& clip) {
658 fullscreen_ = (fullscreen_container_ != NULL); 681 fullscreen_ = (fullscreen_container_ != NULL);
659 position_ = position; 682 position_ = position;
660 683
661 if (clip.IsEmpty()) { 684 if (clip.IsEmpty()) {
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 return found->second; 1360 return found->second;
1338 } 1361 }
1339 1362
1340 bool PluginInstance::IsFullPagePlugin() const { 1363 bool PluginInstance::IsFullPagePlugin() const {
1341 WebFrame* frame = container()->element().document().frame(); 1364 WebFrame* frame = container()->element().document().frame();
1342 return frame->view()->mainFrame()->document().isPluginDocument(); 1365 return frame->view()->mainFrame()->document().isPluginDocument();
1343 } 1366 }
1344 1367
1345 } // namespace ppapi 1368 } // namespace ppapi
1346 } // namespace webkit 1369 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698