OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/pepper/pepper_plugin_instance_impl.h" | 5 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "content/public/common/page_zoom.h" | 25 #include "content/public/common/page_zoom.h" |
26 #include "content/public/renderer/content_renderer_client.h" | 26 #include "content/public/renderer/content_renderer_client.h" |
27 #include "content/renderer/compositor_bindings/web_layer_impl.h" | 27 #include "content/renderer/compositor_bindings/web_layer_impl.h" |
28 #include "content/renderer/gpu/render_widget_compositor.h" | 28 #include "content/renderer/gpu/render_widget_compositor.h" |
29 #include "content/renderer/pepper/content_decryptor_delegate.h" | 29 #include "content/renderer/pepper/content_decryptor_delegate.h" |
30 #include "content/renderer/pepper/event_conversion.h" | 30 #include "content/renderer/pepper/event_conversion.h" |
31 #include "content/renderer/pepper/fullscreen_container.h" | 31 #include "content/renderer/pepper/fullscreen_container.h" |
32 #include "content/renderer/pepper/gfx_conversion.h" | 32 #include "content/renderer/pepper/gfx_conversion.h" |
33 #include "content/renderer/pepper/host_dispatcher_wrapper.h" | 33 #include "content/renderer/pepper/host_dispatcher_wrapper.h" |
34 #include "content/renderer/pepper/host_globals.h" | 34 #include "content/renderer/pepper/host_globals.h" |
35 #include "content/renderer/pepper/message_channel.h" | |
36 #include "content/renderer/pepper/npapi_glue.h" | |
37 #include "content/renderer/pepper/pepper_browser_connection.h" | 35 #include "content/renderer/pepper/pepper_browser_connection.h" |
38 #include "content/renderer/pepper/pepper_compositor_host.h" | 36 #include "content/renderer/pepper/pepper_compositor_host.h" |
39 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h" | 37 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h" |
40 #include "content/renderer/pepper/pepper_graphics_2d_host.h" | 38 #include "content/renderer/pepper/pepper_graphics_2d_host.h" |
41 #include "content/renderer/pepper/pepper_in_process_router.h" | 39 #include "content/renderer/pepper/pepper_in_process_router.h" |
| 40 #include "content/renderer/pepper/pepper_try_catch.h" |
42 #include "content/renderer/pepper/pepper_url_loader_host.h" | 41 #include "content/renderer/pepper/pepper_url_loader_host.h" |
43 #include "content/renderer/pepper/plugin_module.h" | 42 #include "content/renderer/pepper/plugin_module.h" |
44 #include "content/renderer/pepper/plugin_object.h" | 43 #include "content/renderer/pepper/plugin_object.h" |
45 #include "content/renderer/pepper/ppapi_preferences_builder.h" | 44 #include "content/renderer/pepper/ppapi_preferences_builder.h" |
46 #include "content/renderer/pepper/ppb_buffer_impl.h" | 45 #include "content/renderer/pepper/ppb_buffer_impl.h" |
47 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" | 46 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" |
48 #include "content/renderer/pepper/ppb_image_data_impl.h" | 47 #include "content/renderer/pepper/ppb_image_data_impl.h" |
49 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" | 48 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
50 #include "content/renderer/pepper/url_request_info_util.h" | 49 #include "content/renderer/pepper/url_request_info_util.h" |
51 #include "content/renderer/pepper/url_response_info_util.h" | 50 #include "content/renderer/pepper/url_response_info_util.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" | 107 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" |
109 #include "third_party/WebKit/public/web/WebDataSource.h" | 108 #include "third_party/WebKit/public/web/WebDataSource.h" |
110 #include "third_party/WebKit/public/web/WebDocument.h" | 109 #include "third_party/WebKit/public/web/WebDocument.h" |
111 #include "third_party/WebKit/public/web/WebElement.h" | 110 #include "third_party/WebKit/public/web/WebElement.h" |
112 #include "third_party/WebKit/public/web/WebInputEvent.h" | 111 #include "third_party/WebKit/public/web/WebInputEvent.h" |
113 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 112 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
114 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 113 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
115 #include "third_party/WebKit/public/web/WebPrintParams.h" | 114 #include "third_party/WebKit/public/web/WebPrintParams.h" |
116 #include "third_party/WebKit/public/web/WebPrintScalingOption.h" | 115 #include "third_party/WebKit/public/web/WebPrintScalingOption.h" |
117 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 116 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
| 117 #include "third_party/WebKit/public/web/WebScriptSource.h" |
118 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 118 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
119 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 119 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
120 #include "third_party/WebKit/public/web/WebView.h" | 120 #include "third_party/WebKit/public/web/WebView.h" |
121 #include "third_party/khronos/GLES2/gl2.h" | 121 #include "third_party/khronos/GLES2/gl2.h" |
122 #include "third_party/skia/include/core/SkCanvas.h" | 122 #include "third_party/skia/include/core/SkCanvas.h" |
123 #include "third_party/skia/include/core/SkRect.h" | 123 #include "third_party/skia/include/core/SkRect.h" |
124 #include "ui/gfx/image/image_skia.h" | 124 #include "ui/gfx/image/image_skia.h" |
125 #include "ui/gfx/image/image_skia_rep.h" | 125 #include "ui/gfx/image/image_skia_rep.h" |
126 #include "ui/gfx/range/range.h" | 126 #include "ui/gfx/range/range.h" |
127 #include "ui/gfx/rect_conversions.h" | 127 #include "ui/gfx/rect_conversions.h" |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 filtered_input_event_mask_(0), | 552 filtered_input_event_mask_(0), |
553 text_input_type_(kPluginDefaultTextInputType), | 553 text_input_type_(kPluginDefaultTextInputType), |
554 text_input_caret_(0, 0, 0, 0), | 554 text_input_caret_(0, 0, 0, 0), |
555 text_input_caret_bounds_(0, 0, 0, 0), | 555 text_input_caret_bounds_(0, 0, 0, 0), |
556 text_input_caret_set_(false), | 556 text_input_caret_set_(false), |
557 selection_caret_(0), | 557 selection_caret_(0), |
558 selection_anchor_(0), | 558 selection_anchor_(0), |
559 pending_user_gesture_(0.0), | 559 pending_user_gesture_(0.0), |
560 document_loader_(NULL), | 560 document_loader_(NULL), |
561 external_document_load_(false), | 561 external_document_load_(false), |
562 npp_(new NPP_t), | |
563 isolate_(v8::Isolate::GetCurrent()), | 562 isolate_(v8::Isolate::GetCurrent()), |
564 is_deleted_(false), | 563 is_deleted_(false), |
565 last_input_number_(0), | 564 last_input_number_(0), |
566 is_tracking_latency_(false), | 565 is_tracking_latency_(false), |
567 view_change_weak_ptr_factory_(this), | 566 view_change_weak_ptr_factory_(this), |
568 weak_factory_(this) { | 567 weak_factory_(this) { |
569 pp_instance_ = HostGlobals::Get()->AddInstance(this); | 568 pp_instance_ = HostGlobals::Get()->AddInstance(this); |
570 | 569 |
571 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 570 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
572 module_->InstanceCreated(this); | 571 module_->InstanceCreated(this); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); | 612 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); |
614 | 613 |
615 if (GetContentClient()->renderer() && // NULL in unit tests. | 614 if (GetContentClient()->renderer() && // NULL in unit tests. |
616 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) | 615 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) |
617 external_document_load_ = true; | 616 external_document_load_ = true; |
618 } | 617 } |
619 | 618 |
620 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { | 619 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { |
621 DCHECK(!fullscreen_container_); | 620 DCHECK(!fullscreen_container_); |
622 | 621 |
623 // Free all the plugin objects. This will automatically clear the back- | 622 // Free all the plugin objects. This will prevent WebKit from calling into the |
624 // pointer from the NPObject so WebKit can't call into the plugin any more. | 623 // plugin any more. |
625 // | |
626 // Swap out the set so we can delete from it (the objects will try to | |
627 // unregister themselves inside the delete call). | |
628 PluginObjectSet plugin_object_copy; | 624 PluginObjectSet plugin_object_copy; |
629 live_plugin_objects_.swap(plugin_object_copy); | 625 live_plugin_objects_.swap(plugin_object_copy); |
630 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); | 626 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); |
631 i != plugin_object_copy.end(); | 627 i != plugin_object_copy.end(); |
632 ++i) | 628 ++i) { |
633 delete *i; | 629 (*i)->InstanceDeleted(); |
| 630 } |
634 | 631 |
635 if (TrackedCallback::IsPending(lock_mouse_callback_)) | 632 if (TrackedCallback::IsPending(lock_mouse_callback_)) |
636 lock_mouse_callback_->Abort(); | 633 lock_mouse_callback_->Abort(); |
637 | 634 |
638 if (!instance_deleted_callback_.is_null()) | 635 if (!instance_deleted_callback_.is_null()) |
639 instance_deleted_callback_.Run(); | 636 instance_deleted_callback_.Run(); |
640 | 637 |
641 if (!module_->IsProxied() && render_frame_) { | 638 if (!module_->IsProxied() && render_frame_) { |
642 PepperBrowserConnection* browser_connection = | 639 PepperBrowserConnection* browser_connection = |
643 PepperBrowserConnection::Get(render_frame_); | 640 PepperBrowserConnection::Get(render_frame_); |
(...skipping 10 matching lines...) Expand all Loading... |
654 // want to look up in the global map to get info off of our object. | 651 // want to look up in the global map to get info off of our object. |
655 HostGlobals::Get()->InstanceDeleted(pp_instance_); | 652 HostGlobals::Get()->InstanceDeleted(pp_instance_); |
656 } | 653 } |
657 | 654 |
658 // NOTE: Any of these methods that calls into the plugin needs to take into | 655 // NOTE: Any of these methods that calls into the plugin needs to take into |
659 // account that the plugin may use Var to remove the <embed> from the DOM, which | 656 // account that the plugin may use Var to remove the <embed> from the DOM, which |
660 // will make the PepperWebPluginImpl drop its reference, usually the last one. | 657 // will make the PepperWebPluginImpl drop its reference, usually the last one. |
661 // If a method needs to access a member of the instance after the call has | 658 // If a method needs to access a member of the instance after the call has |
662 // returned, then it needs to keep its own reference on the stack. | 659 // returned, then it needs to keep its own reference on the stack. |
663 | 660 |
| 661 v8::Local<v8::Object> PepperPluginInstanceImpl::GetMessageChannelObject() { |
| 662 return v8::Local<v8::Object>::New(isolate_, message_channel_); |
| 663 } |
| 664 |
| 665 MessageChannel* PepperPluginInstanceImpl::GetMessageChannel() { |
| 666 MessageChannel* message_channel; |
| 667 v8::HandleScope scope(isolate_); |
| 668 if (gin::ConvertFromV8(isolate_, GetMessageChannelObject(), &message_channel)) |
| 669 return message_channel; |
| 670 return NULL; |
| 671 } |
| 672 |
| 673 v8::Handle<v8::Context> PepperPluginInstanceImpl::GetPluginContext() { |
| 674 if (!container_) |
| 675 return v8::Handle<v8::Context>(); |
| 676 v8::Handle<v8::Context> context = |
| 677 container_->element().document().frame()->mainWorldScriptContext(); |
| 678 DCHECK(context->GetIsolate() == isolate_); |
| 679 return context; |
| 680 } |
| 681 |
664 void PepperPluginInstanceImpl::Delete() { | 682 void PepperPluginInstanceImpl::Delete() { |
665 is_deleted_ = true; | 683 is_deleted_ = true; |
666 | 684 |
667 if (render_frame_ && | 685 if (render_frame_ && |
668 render_frame_->render_view()->plugin_find_handler() == this) { | 686 render_frame_->render_view()->plugin_find_handler() == this) { |
669 render_frame_->render_view()->set_plugin_find_handler(NULL); | 687 render_frame_->render_view()->set_plugin_find_handler(NULL); |
670 } | 688 } |
671 | 689 |
672 // Keep a reference on the stack. See NOTE above. | 690 // Keep a reference on the stack. See NOTE above. |
673 scoped_refptr<PepperPluginInstanceImpl> ref(this); | 691 scoped_refptr<PepperPluginInstanceImpl> ref(this); |
674 // Force the MessageChannel to release its "passthrough object" which should | 692 // Force the MessageChannel to release its "passthrough object" which should |
675 // release our last reference to the "InstanceObject" and will probably | 693 // release our last reference to the "InstanceObject" and will probably |
676 // destroy it. We want to do this prior to calling DidDestroy in case the | 694 // destroy it. We want to do this prior to calling DidDestroy in case the |
677 // destructor of the instance object tries to use the instance. | 695 // destructor of the instance object tries to use the instance. |
678 message_channel_->SetPassthroughObject(NULL); | 696 GetMessageChannel()->SetPassthroughObject(v8::Handle<v8::Object>()); |
679 // If this is a NaCl plugin instance, shut down the NaCl plugin by calling | 697 // If this is a NaCl plugin instance, shut down the NaCl plugin by calling |
680 // its DidDestroy. Don't call DidDestroy on the untrusted plugin instance, | 698 // its DidDestroy. Don't call DidDestroy on the untrusted plugin instance, |
681 // since there is little that it can do at this point. | 699 // since there is little that it can do at this point. |
682 if (original_instance_interface_) | 700 if (original_instance_interface_) |
683 original_instance_interface_->DidDestroy(pp_instance()); | 701 original_instance_interface_->DidDestroy(pp_instance()); |
684 else | 702 else |
685 instance_interface_->DidDestroy(pp_instance()); | 703 instance_interface_->DidDestroy(pp_instance()); |
686 // Ensure we don't attempt to call functions on the destroyed instance. | 704 // Ensure we don't attempt to call functions on the destroyed instance. |
687 original_instance_interface_.reset(); | 705 original_instance_interface_.reset(); |
688 instance_interface_.reset(); | 706 instance_interface_.reset(); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 "Flash.UsesGPU", is_xp * 4 + needs_gpu * 2 + prefs.is_webgl_supported, 8); | 848 "Flash.UsesGPU", is_xp * 4 + needs_gpu * 2 + prefs.is_webgl_supported, 8); |
831 #endif | 849 #endif |
832 } | 850 } |
833 | 851 |
834 bool PepperPluginInstanceImpl::Initialize( | 852 bool PepperPluginInstanceImpl::Initialize( |
835 const std::vector<std::string>& arg_names, | 853 const std::vector<std::string>& arg_names, |
836 const std::vector<std::string>& arg_values, | 854 const std::vector<std::string>& arg_values, |
837 bool full_frame) { | 855 bool full_frame) { |
838 if (!render_frame_) | 856 if (!render_frame_) |
839 return false; | 857 return false; |
840 message_channel_.reset(new MessageChannel(this)); | 858 MessageChannel::Create(this, &message_channel_); |
841 | 859 |
842 full_frame_ = full_frame; | 860 full_frame_ = full_frame; |
843 | 861 |
844 UpdateTouchEventRequest(); | 862 UpdateTouchEventRequest(); |
845 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); | 863 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); |
846 | 864 |
847 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build( | 865 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build( |
848 render_frame_->render_view()->webkit_preferences())), | 866 render_frame_->render_view()->webkit_preferences())), |
849 arg_names, | 867 arg_names, |
850 arg_values); | 868 arg_values); |
851 | 869 |
852 argn_ = arg_names; | 870 argn_ = arg_names; |
853 argv_ = arg_values; | 871 argv_ = arg_values; |
854 scoped_ptr<const char * []> argn_array(StringVectorToArgArray(argn_)); | 872 scoped_ptr<const char * []> argn_array(StringVectorToArgArray(argn_)); |
855 scoped_ptr<const char * []> argv_array(StringVectorToArgArray(argv_)); | 873 scoped_ptr<const char * []> argv_array(StringVectorToArgArray(argv_)); |
856 bool success = PP_ToBool(instance_interface_->DidCreate( | 874 bool success = PP_ToBool(instance_interface_->DidCreate( |
857 pp_instance(), argn_.size(), argn_array.get(), argv_array.get())); | 875 pp_instance(), argn_.size(), argn_array.get(), argv_array.get())); |
858 // If this is a plugin that hosts external plugins, we should delay messages | 876 // If this is a plugin that hosts external plugins, we should delay messages |
859 // so that the child plugin that's created later will receive all the | 877 // so that the child plugin that's created later will receive all the |
860 // messages. (E.g., NaCl trusted plugin starting a child NaCl app.) | 878 // messages. (E.g., NaCl trusted plugin starting a child NaCl app.) |
861 // | 879 // |
862 // A host for external plugins will call ResetAsProxied later, at which point | 880 // A host for external plugins will call ResetAsProxied later, at which point |
863 // we can Start() the message_channel_. | 881 // we can Start() the message_channel_. |
864 if (success && (!module_->renderer_ppapi_host()->IsExternalPluginHost())) | 882 if (success && (!module_->renderer_ppapi_host()->IsExternalPluginHost())) |
865 message_channel_->Start(); | 883 GetMessageChannel()->Start(); |
866 return success; | 884 return success; |
867 } | 885 } |
868 | 886 |
869 bool PepperPluginInstanceImpl::HandleDocumentLoad( | 887 bool PepperPluginInstanceImpl::HandleDocumentLoad( |
870 const blink::WebURLResponse& response) { | 888 const blink::WebURLResponse& response) { |
871 DCHECK(!document_loader_); | 889 DCHECK(!document_loader_); |
872 if (external_document_load_) { | 890 if (external_document_load_) { |
873 // The external proxy isn't available, so save the response and record | 891 // The external proxy isn't available, so save the response and record |
874 // document load notifications for later replay. | 892 // document load notifications for later replay. |
875 external_document_response_ = response; | 893 external_document_response_ = response; |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 ppapi::proxy::SerializedVarSendInputShmem(dispatcher, message.get(), | 1217 ppapi::proxy::SerializedVarSendInputShmem(dispatcher, message.get(), |
1200 pp_instance()), | 1218 pp_instance()), |
1201 &msg_reply, | 1219 &msg_reply, |
1202 &was_handled)); | 1220 &was_handled)); |
1203 *result = ScopedPPVar(ScopedPPVar::PassRef(), msg_reply.Return(dispatcher)); | 1221 *result = ScopedPPVar(ScopedPPVar::PassRef(), msg_reply.Return(dispatcher)); |
1204 TRACE_EVENT0("ppapi", | 1222 TRACE_EVENT0("ppapi", |
1205 "PepperPluginInstanceImpl::HandleBlockingMessage return."); | 1223 "PepperPluginInstanceImpl::HandleBlockingMessage return."); |
1206 return was_handled; | 1224 return was_handled; |
1207 } | 1225 } |
1208 | 1226 |
1209 PP_Var PepperPluginInstanceImpl::GetInstanceObject() { | 1227 PP_Var PepperPluginInstanceImpl::GetInstanceObject(v8::Isolate* isolate) { |
1210 // Keep a reference on the stack. See NOTE above. | 1228 // Keep a reference on the stack. See NOTE above. |
1211 scoped_refptr<PepperPluginInstanceImpl> ref(this); | 1229 scoped_refptr<PepperPluginInstanceImpl> ref(this); |
1212 | 1230 |
| 1231 CHECK(isolate == isolate_); |
| 1232 |
1213 // If the plugin supports the private instance interface, try to retrieve its | 1233 // If the plugin supports the private instance interface, try to retrieve its |
1214 // instance object. | 1234 // instance object. |
1215 if (LoadPrivateInterface()) | 1235 if (LoadPrivateInterface()) |
1216 return plugin_private_interface_->GetInstanceObject(pp_instance()); | 1236 return plugin_private_interface_->GetInstanceObject(pp_instance()); |
1217 return PP_MakeUndefined(); | 1237 return PP_MakeUndefined(); |
1218 } | 1238 } |
1219 | 1239 |
1220 void PepperPluginInstanceImpl::ViewChanged( | 1240 void PepperPluginInstanceImpl::ViewChanged( |
1221 const gfx::Rect& position, | 1241 const gfx::Rect& position, |
1222 const gfx::Rect& clip, | 1242 const gfx::Rect& clip, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1338 void PepperPluginInstanceImpl::SetLinkUnderCursor(const std::string& url) { | 1358 void PepperPluginInstanceImpl::SetLinkUnderCursor(const std::string& url) { |
1339 link_under_cursor_ = base::UTF8ToUTF16(url); | 1359 link_under_cursor_ = base::UTF8ToUTF16(url); |
1340 } | 1360 } |
1341 | 1361 |
1342 void PepperPluginInstanceImpl::SetTextInputType(ui::TextInputType type) { | 1362 void PepperPluginInstanceImpl::SetTextInputType(ui::TextInputType type) { |
1343 text_input_type_ = type; | 1363 text_input_type_ = type; |
1344 render_frame_->PepperTextInputTypeChanged(this); | 1364 render_frame_->PepperTextInputTypeChanged(this); |
1345 } | 1365 } |
1346 | 1366 |
1347 void PepperPluginInstanceImpl::PostMessageToJavaScript(PP_Var message) { | 1367 void PepperPluginInstanceImpl::PostMessageToJavaScript(PP_Var message) { |
1348 message_channel_->PostMessageToJavaScript(message); | 1368 GetMessageChannel()->PostMessageToJavaScript(message); |
1349 } | 1369 } |
1350 | 1370 |
1351 int32_t PepperPluginInstanceImpl::RegisterMessageHandler( | 1371 int32_t PepperPluginInstanceImpl::RegisterMessageHandler( |
1352 PP_Instance instance, | 1372 PP_Instance instance, |
1353 void* user_data, | 1373 void* user_data, |
1354 const PPP_MessageHandler_0_1* handler, | 1374 const PPP_MessageHandler_0_1* handler, |
1355 PP_Resource message_loop) { | 1375 PP_Resource message_loop) { |
1356 // Not supported in-process. | 1376 // Not supported in-process. |
1357 NOTIMPLEMENTED(); | 1377 NOTIMPLEMENTED(); |
1358 return PP_ERROR_FAILED; | 1378 return PP_ERROR_FAILED; |
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2339 | 2359 |
2340 const ViewData* PepperPluginInstanceImpl::GetViewData(PP_Instance instance) { | 2360 const ViewData* PepperPluginInstanceImpl::GetViewData(PP_Instance instance) { |
2341 return &view_data_; | 2361 return &view_data_; |
2342 } | 2362 } |
2343 | 2363 |
2344 PP_Bool PepperPluginInstanceImpl::FlashIsFullscreen(PP_Instance instance) { | 2364 PP_Bool PepperPluginInstanceImpl::FlashIsFullscreen(PP_Instance instance) { |
2345 return PP_FromBool(flash_fullscreen_); | 2365 return PP_FromBool(flash_fullscreen_); |
2346 } | 2366 } |
2347 | 2367 |
2348 PP_Var PepperPluginInstanceImpl::GetWindowObject(PP_Instance instance) { | 2368 PP_Var PepperPluginInstanceImpl::GetWindowObject(PP_Instance instance) { |
2349 if (!container_) | 2369 ScopedPPVar script(ScopedPPVar::PassRef(), |
2350 return PP_MakeUndefined(); | 2370 StringVar::StringToPPVar("window")); |
2351 | 2371 return ExecuteScript(pp_instance(), script.get(), NULL); |
2352 WebLocalFrame* frame = container_->element().document().frame(); | |
2353 if (!frame) | |
2354 return PP_MakeUndefined(); | |
2355 | |
2356 return NPObjectToPPVar(this, frame->windowObject()); | |
2357 } | 2372 } |
2358 | 2373 |
2359 PP_Var PepperPluginInstanceImpl::GetOwnerElementObject(PP_Instance instance) { | 2374 PP_Var PepperPluginInstanceImpl::GetOwnerElementObject(PP_Instance instance) { |
2360 if (!container_) | 2375 if (!container_) |
2361 return PP_MakeUndefined(); | 2376 return PP_MakeUndefined(); |
2362 return NPObjectToPPVar(this, container_->scriptableObjectForElement()); | 2377 PepperTryCatchVar try_catch(this, true, NULL); |
| 2378 ScopedPPVar result = try_catch.FromV8(container_->getV8ObjectForElement()); |
| 2379 DCHECK(!try_catch.HasException()); |
| 2380 return result.Release(); |
2363 } | 2381 } |
2364 | 2382 |
2365 PP_Var PepperPluginInstanceImpl::ExecuteScript(PP_Instance instance, | 2383 PP_Var PepperPluginInstanceImpl::ExecuteScript(PP_Instance instance, |
2366 PP_Var script, | 2384 PP_Var script_var, |
2367 PP_Var* exception) { | 2385 PP_Var* exception) { |
| 2386 if (!container_) |
| 2387 return PP_MakeUndefined(); |
| 2388 |
2368 // Executing the script may remove the plugin from the DOM, so we need to keep | 2389 // Executing the script may remove the plugin from the DOM, so we need to keep |
2369 // a reference to ourselves so that we can still process the result after the | 2390 // a reference to ourselves so that we can still process the result after the |
2370 // WebBindings::evaluate() below. | 2391 // WebBindings::evaluate() below. |
2371 scoped_refptr<PepperPluginInstanceImpl> ref(this); | 2392 scoped_refptr<PepperPluginInstanceImpl> ref(this); |
2372 TryCatch try_catch(exception); | 2393 PepperTryCatchVar try_catch(this, true, exception); |
2373 if (try_catch.has_exception()) | |
2374 return PP_MakeUndefined(); | |
2375 | |
2376 // Convert the script into an inconvenient NPString object. | |
2377 StringVar* script_string = StringVar::FromPPVar(script); | |
2378 if (!script_string) { | |
2379 try_catch.SetException("Script param to ExecuteScript must be a string."); | |
2380 return PP_MakeUndefined(); | |
2381 } | |
2382 NPString np_script; | |
2383 np_script.UTF8Characters = script_string->value().c_str(); | |
2384 np_script.UTF8Length = script_string->value().length(); | |
2385 | |
2386 // Get the current frame to pass to the evaluate function. | |
2387 WebLocalFrame* frame = container_->element().document().frame(); | 2394 WebLocalFrame* frame = container_->element().document().frame(); |
2388 if (!frame) { | 2395 if (!frame) { |
2389 try_catch.SetException("No frame to execute script in."); | 2396 try_catch.SetException("No frame to execute script in."); |
2390 return PP_MakeUndefined(); | 2397 return PP_MakeUndefined(); |
2391 } | 2398 } |
2392 | 2399 |
2393 NPVariant result; | 2400 StringVar* script_string_var = StringVar::FromPPVar(script_var); |
2394 bool ok = false; | 2401 if (!script_string_var) { |
2395 if (IsProcessingUserGesture()) { | 2402 try_catch.SetException("Script param to ExecuteScript must be a string."); |
2396 blink::WebScopedUserGesture user_gesture(CurrentUserGestureToken()); | |
2397 ok = | |
2398 WebBindings::evaluate(NULL, frame->windowObject(), &np_script, &result); | |
2399 } else { | |
2400 ok = | |
2401 WebBindings::evaluate(NULL, frame->windowObject(), &np_script, &result); | |
2402 } | |
2403 if (!ok) { | |
2404 // TryCatch doesn't catch the exceptions properly. Since this is only for | |
2405 // a trusted API, just set to a general exception message. | |
2406 try_catch.SetException("Exception caught"); | |
2407 WebBindings::releaseVariantValue(&result); | |
2408 return PP_MakeUndefined(); | 2403 return PP_MakeUndefined(); |
2409 } | 2404 } |
2410 | 2405 |
2411 PP_Var ret = NPVariantToPPVar(this, &result); | 2406 std::string script_string = script_string_var->value(); |
2412 WebBindings::releaseVariantValue(&result); | 2407 blink::WebScriptSource script( |
2413 return ret; | 2408 blink::WebString::fromUTF8(script_string.c_str())); |
| 2409 v8::Handle<v8::Value> result; |
| 2410 if (IsProcessingUserGesture()) { |
| 2411 blink::WebScopedUserGesture user_gesture(CurrentUserGestureToken()); |
| 2412 result = frame->executeScriptAndReturnValue(script); |
| 2413 } else { |
| 2414 result = frame->executeScriptAndReturnValue(script); |
| 2415 } |
| 2416 |
| 2417 ScopedPPVar var_result = try_catch.FromV8(result); |
| 2418 if (try_catch.HasException()) |
| 2419 return PP_MakeUndefined(); |
| 2420 |
| 2421 return var_result.Release(); |
2414 } | 2422 } |
2415 | 2423 |
2416 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputSampleRate( | 2424 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputSampleRate( |
2417 PP_Instance instance) { | 2425 PP_Instance instance) { |
2418 RenderThreadImpl* thread = RenderThreadImpl::current(); | 2426 RenderThreadImpl* thread = RenderThreadImpl::current(); |
2419 return thread->GetAudioHardwareConfig()->GetOutputSampleRate(); | 2427 return thread->GetAudioHardwareConfig()->GetOutputSampleRate(); |
2420 } | 2428 } |
2421 | 2429 |
2422 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputBufferSize( | 2430 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputBufferSize( |
2423 PP_Instance instance) { | 2431 PP_Instance instance) { |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2932 plugin_selection_interface_ = NULL; | 2940 plugin_selection_interface_ = NULL; |
2933 plugin_textinput_interface_ = NULL; | 2941 plugin_textinput_interface_ = NULL; |
2934 plugin_zoom_interface_ = NULL; | 2942 plugin_zoom_interface_ = NULL; |
2935 | 2943 |
2936 // Re-send the DidCreate event via the proxy. | 2944 // Re-send the DidCreate event via the proxy. |
2937 scoped_ptr<const char * []> argn_array(StringVectorToArgArray(argn_)); | 2945 scoped_ptr<const char * []> argn_array(StringVectorToArgArray(argn_)); |
2938 scoped_ptr<const char * []> argv_array(StringVectorToArgArray(argv_)); | 2946 scoped_ptr<const char * []> argv_array(StringVectorToArgArray(argv_)); |
2939 if (!instance_interface_->DidCreate( | 2947 if (!instance_interface_->DidCreate( |
2940 pp_instance(), argn_.size(), argn_array.get(), argv_array.get())) | 2948 pp_instance(), argn_.size(), argn_array.get(), argv_array.get())) |
2941 return PP_EXTERNAL_PLUGIN_ERROR_INSTANCE; | 2949 return PP_EXTERNAL_PLUGIN_ERROR_INSTANCE; |
2942 message_channel_->Start(); | 2950 GetMessageChannel()->Start(); |
2943 | 2951 |
2944 // Clear sent_initial_did_change_view_ and cancel any pending DidChangeView | 2952 // Clear sent_initial_did_change_view_ and cancel any pending DidChangeView |
2945 // event. This way, SendDidChangeView will send the "current" view | 2953 // event. This way, SendDidChangeView will send the "current" view |
2946 // immediately (before other events like HandleDocumentLoad). | 2954 // immediately (before other events like HandleDocumentLoad). |
2947 sent_initial_did_change_view_ = false; | 2955 sent_initial_did_change_view_ = false; |
2948 view_change_weak_ptr_factory_.InvalidateWeakPtrs(); | 2956 view_change_weak_ptr_factory_.InvalidateWeakPtrs(); |
2949 SendDidChangeView(); | 2957 SendDidChangeView(); |
2950 | 2958 |
2951 DCHECK(external_document_load_); | 2959 DCHECK(external_document_load_); |
2952 external_document_load_ = false; | 2960 external_document_load_ = false; |
2953 if (!external_document_response_.isNull()) { | 2961 if (!external_document_response_.isNull()) { |
2954 document_loader_ = NULL; | 2962 document_loader_ = NULL; |
2955 // Pass the response to the new proxy. | 2963 // Pass the response to the new proxy. |
2956 HandleDocumentLoad(external_document_response_); | 2964 HandleDocumentLoad(external_document_response_); |
2957 external_document_response_ = blink::WebURLResponse(); | 2965 external_document_response_ = blink::WebURLResponse(); |
2958 // Replay any document load events we've received to the real loader. | 2966 // Replay any document load events we've received to the real loader. |
2959 external_document_loader_->ReplayReceivedData(document_loader_); | 2967 external_document_loader_->ReplayReceivedData(document_loader_); |
2960 external_document_loader_.reset(NULL); | 2968 external_document_loader_.reset(NULL); |
2961 } | 2969 } |
2962 | 2970 |
2963 return PP_EXTERNAL_PLUGIN_OK; | 2971 return PP_EXTERNAL_PLUGIN_OK; |
2964 } | 2972 } |
2965 | 2973 |
2966 bool PepperPluginInstanceImpl::IsValidInstanceOf(PluginModule* module) { | 2974 bool PepperPluginInstanceImpl::IsValidInstanceOf(PluginModule* module) { |
2967 DCHECK(module); | 2975 DCHECK(module); |
2968 return module == module_.get() || module == original_module_.get(); | 2976 return module == module_.get() || module == original_module_.get(); |
2969 } | 2977 } |
2970 | 2978 |
2971 NPP PepperPluginInstanceImpl::instanceNPP() { return npp_.get(); } | |
2972 | |
2973 PepperPluginInstance* PepperPluginInstance::Get(PP_Instance instance_id) { | 2979 PepperPluginInstance* PepperPluginInstance::Get(PP_Instance instance_id) { |
2974 return HostGlobals::Get()->GetInstance(instance_id); | 2980 return HostGlobals::Get()->GetInstance(instance_id); |
2975 } | 2981 } |
2976 | 2982 |
2977 RenderView* PepperPluginInstanceImpl::GetRenderView() { | 2983 RenderView* PepperPluginInstanceImpl::GetRenderView() { |
2978 return render_frame_ ? render_frame_->render_view() : NULL; | 2984 return render_frame_ ? render_frame_->render_view() : NULL; |
2979 } | 2985 } |
2980 | 2986 |
2981 blink::WebPluginContainer* PepperPluginInstanceImpl::GetContainer() { | 2987 blink::WebPluginContainer* PepperPluginInstanceImpl::GetContainer() { |
2982 return container_; | 2988 return container_; |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3169 int PepperPluginInstanceImpl::MakePendingFileRefRendererHost( | 3175 int PepperPluginInstanceImpl::MakePendingFileRefRendererHost( |
3170 const base::FilePath& path) { | 3176 const base::FilePath& path) { |
3171 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); | 3177 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); |
3172 PepperFileRefRendererHost* file_ref_host( | 3178 PepperFileRefRendererHost* file_ref_host( |
3173 new PepperFileRefRendererHost(host_impl, pp_instance(), 0, path)); | 3179 new PepperFileRefRendererHost(host_impl, pp_instance(), 0, path)); |
3174 return host_impl->GetPpapiHost()->AddPendingResourceHost( | 3180 return host_impl->GetPpapiHost()->AddPendingResourceHost( |
3175 scoped_ptr<ppapi::host::ResourceHost>(file_ref_host)); | 3181 scoped_ptr<ppapi::host::ResourceHost>(file_ref_host)); |
3176 } | 3182 } |
3177 | 3183 |
3178 void PepperPluginInstanceImpl::SetEmbedProperty(PP_Var key, PP_Var value) { | 3184 void PepperPluginInstanceImpl::SetEmbedProperty(PP_Var key, PP_Var value) { |
3179 message_channel_->SetReadOnlyProperty(key, value); | 3185 GetMessageChannel()->SetReadOnlyProperty(key, value); |
3180 } | 3186 } |
3181 | 3187 |
3182 bool PepperPluginInstanceImpl::CanAccessMainFrame() const { | 3188 bool PepperPluginInstanceImpl::CanAccessMainFrame() const { |
3183 if (!container_) | 3189 if (!container_) |
3184 return false; | 3190 return false; |
3185 blink::WebDocument containing_document = container_->element().document(); | 3191 blink::WebDocument containing_document = container_->element().document(); |
3186 | 3192 |
3187 if (!containing_document.frame() || !containing_document.frame()->view() || | 3193 if (!containing_document.frame() || !containing_document.frame()->view() || |
3188 !containing_document.frame()->view()->mainFrame()) { | 3194 !containing_document.frame()->view()->mainFrame()) { |
3189 return false; | 3195 return false; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3306 // Running out-of-process. Initiate an IPC call to notify the plugin | 3312 // Running out-of-process. Initiate an IPC call to notify the plugin |
3307 // process. | 3313 // process. |
3308 ppapi::proxy::HostDispatcher* dispatcher = | 3314 ppapi::proxy::HostDispatcher* dispatcher = |
3309 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); | 3315 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); |
3310 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( | 3316 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( |
3311 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); | 3317 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); |
3312 } | 3318 } |
3313 } | 3319 } |
3314 | 3320 |
3315 } // namespace content | 3321 } // namespace content |
OLD | NEW |