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 15 matching lines...) Expand all Loading... |
26 #include "content/public/common/page_zoom.h" | 26 #include "content/public/common/page_zoom.h" |
27 #include "content/public/renderer/content_renderer_client.h" | 27 #include "content/public/renderer/content_renderer_client.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" | 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" | 36 #include "content/renderer/pepper/pepper_browser_connection.h" |
38 #include "content/renderer/pepper/pepper_compositor_host.h" | 37 #include "content/renderer/pepper/pepper_compositor_host.h" |
39 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h" | 38 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h" |
40 #include "content/renderer/pepper/pepper_graphics_2d_host.h" | 39 #include "content/renderer/pepper/pepper_graphics_2d_host.h" |
41 #include "content/renderer/pepper/pepper_in_process_router.h" | 40 #include "content/renderer/pepper/pepper_in_process_router.h" |
| 41 #include "content/renderer/pepper/pepper_try_catch.h" |
42 #include "content/renderer/pepper/pepper_url_loader_host.h" | 42 #include "content/renderer/pepper/pepper_url_loader_host.h" |
43 #include "content/renderer/pepper/plugin_module.h" | 43 #include "content/renderer/pepper/plugin_module.h" |
44 #include "content/renderer/pepper/plugin_object.h" | 44 #include "content/renderer/pepper/plugin_object.h" |
45 #include "content/renderer/pepper/ppapi_preferences_builder.h" | 45 #include "content/renderer/pepper/ppapi_preferences_builder.h" |
46 #include "content/renderer/pepper/ppb_buffer_impl.h" | 46 #include "content/renderer/pepper/ppb_buffer_impl.h" |
47 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" | 47 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" |
48 #include "content/renderer/pepper/ppb_image_data_impl.h" | 48 #include "content/renderer/pepper/ppb_image_data_impl.h" |
49 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" | 49 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
50 #include "content/renderer/pepper/url_request_info_util.h" | 50 #include "content/renderer/pepper/url_request_info_util.h" |
51 #include "content/renderer/pepper/url_response_info_util.h" | 51 #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" | 108 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" |
109 #include "third_party/WebKit/public/web/WebDataSource.h" | 109 #include "third_party/WebKit/public/web/WebDataSource.h" |
110 #include "third_party/WebKit/public/web/WebDocument.h" | 110 #include "third_party/WebKit/public/web/WebDocument.h" |
111 #include "third_party/WebKit/public/web/WebElement.h" | 111 #include "third_party/WebKit/public/web/WebElement.h" |
112 #include "third_party/WebKit/public/web/WebInputEvent.h" | 112 #include "third_party/WebKit/public/web/WebInputEvent.h" |
113 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 113 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
114 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 114 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
115 #include "third_party/WebKit/public/web/WebPrintParams.h" | 115 #include "third_party/WebKit/public/web/WebPrintParams.h" |
116 #include "third_party/WebKit/public/web/WebPrintScalingOption.h" | 116 #include "third_party/WebKit/public/web/WebPrintScalingOption.h" |
117 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 117 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
| 118 #include "third_party/WebKit/public/web/WebScriptSource.h" |
118 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 119 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
119 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 120 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
120 #include "third_party/WebKit/public/web/WebView.h" | 121 #include "third_party/WebKit/public/web/WebView.h" |
121 #include "third_party/khronos/GLES2/gl2.h" | 122 #include "third_party/khronos/GLES2/gl2.h" |
122 #include "third_party/skia/include/core/SkCanvas.h" | 123 #include "third_party/skia/include/core/SkCanvas.h" |
123 #include "third_party/skia/include/core/SkRect.h" | 124 #include "third_party/skia/include/core/SkRect.h" |
124 #include "ui/gfx/image/image_skia.h" | 125 #include "ui/gfx/image/image_skia.h" |
125 #include "ui/gfx/image/image_skia_rep.h" | 126 #include "ui/gfx/image/image_skia_rep.h" |
126 #include "ui/gfx/range/range.h" | 127 #include "ui/gfx/range/range.h" |
127 #include "ui/gfx/rect_conversions.h" | 128 #include "ui/gfx/rect_conversions.h" |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 checked_for_plugin_input_event_interface_(false), | 537 checked_for_plugin_input_event_interface_(false), |
537 checked_for_plugin_pdf_interface_(false), | 538 checked_for_plugin_pdf_interface_(false), |
538 gamepad_impl_(new GamepadImpl()), | 539 gamepad_impl_(new GamepadImpl()), |
539 uma_private_impl_(NULL), | 540 uma_private_impl_(NULL), |
540 plugin_print_interface_(NULL), | 541 plugin_print_interface_(NULL), |
541 plugin_graphics_3d_interface_(NULL), | 542 plugin_graphics_3d_interface_(NULL), |
542 always_on_top_(false), | 543 always_on_top_(false), |
543 fullscreen_container_(NULL), | 544 fullscreen_container_(NULL), |
544 flash_fullscreen_(false), | 545 flash_fullscreen_(false), |
545 desired_fullscreen_state_(false), | 546 desired_fullscreen_state_(false), |
| 547 message_channel_(NULL), |
546 sad_plugin_(NULL), | 548 sad_plugin_(NULL), |
547 input_event_mask_(0), | 549 input_event_mask_(0), |
548 filtered_input_event_mask_(0), | 550 filtered_input_event_mask_(0), |
549 text_input_type_(kPluginDefaultTextInputType), | 551 text_input_type_(kPluginDefaultTextInputType), |
550 text_input_caret_(0, 0, 0, 0), | 552 text_input_caret_(0, 0, 0, 0), |
551 text_input_caret_bounds_(0, 0, 0, 0), | 553 text_input_caret_bounds_(0, 0, 0, 0), |
552 text_input_caret_set_(false), | 554 text_input_caret_set_(false), |
553 selection_caret_(0), | 555 selection_caret_(0), |
554 selection_anchor_(0), | 556 selection_anchor_(0), |
555 pending_user_gesture_(0.0), | 557 pending_user_gesture_(0.0), |
556 document_loader_(NULL), | 558 document_loader_(NULL), |
557 external_document_load_(false), | 559 external_document_load_(false), |
558 npp_(new NPP_t), | |
559 isolate_(v8::Isolate::GetCurrent()), | 560 isolate_(v8::Isolate::GetCurrent()), |
560 is_deleted_(false), | 561 is_deleted_(false), |
561 last_input_number_(0), | 562 last_input_number_(0), |
562 is_tracking_latency_(false), | 563 is_tracking_latency_(false), |
563 view_change_weak_ptr_factory_(this), | 564 view_change_weak_ptr_factory_(this), |
564 weak_factory_(this) { | 565 weak_factory_(this) { |
565 pp_instance_ = HostGlobals::Get()->AddInstance(this); | 566 pp_instance_ = HostGlobals::Get()->AddInstance(this); |
566 | 567 |
567 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 568 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
568 module_->InstanceCreated(this); | 569 module_->InstanceCreated(this); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); | 610 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); |
610 | 611 |
611 if (GetContentClient()->renderer() && // NULL in unit tests. | 612 if (GetContentClient()->renderer() && // NULL in unit tests. |
612 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) | 613 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) |
613 external_document_load_ = true; | 614 external_document_load_ = true; |
614 } | 615 } |
615 | 616 |
616 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { | 617 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { |
617 DCHECK(!fullscreen_container_); | 618 DCHECK(!fullscreen_container_); |
618 | 619 |
619 // Free all the plugin objects. This will automatically clear the back- | 620 // Notify all the plugin objects of deletion. This will prevent blink from |
620 // pointer from the NPObject so WebKit can't call into the plugin any more. | 621 // calling into the plugin any more. |
621 // | 622 // |
622 // Swap out the set so we can delete from it (the objects will try to | 623 // Swap out the set so we can delete from it (the objects will try to |
623 // unregister themselves inside the delete call). | 624 // unregister themselves inside the delete call). |
624 PluginObjectSet plugin_object_copy; | 625 PluginObjectSet plugin_object_copy; |
625 live_plugin_objects_.swap(plugin_object_copy); | 626 live_plugin_objects_.swap(plugin_object_copy); |
626 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); | 627 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); |
627 i != plugin_object_copy.end(); | 628 i != plugin_object_copy.end(); |
628 ++i) | 629 ++i) { |
629 delete *i; | 630 (*i)->InstanceDeleted(); |
| 631 } |
| 632 |
| 633 if (message_channel_) |
| 634 message_channel_->InstanceDeleted(); |
| 635 message_channel_object_.Reset(); |
630 | 636 |
631 if (TrackedCallback::IsPending(lock_mouse_callback_)) | 637 if (TrackedCallback::IsPending(lock_mouse_callback_)) |
632 lock_mouse_callback_->Abort(); | 638 lock_mouse_callback_->Abort(); |
633 | 639 |
634 if (!instance_deleted_callback_.is_null()) | 640 if (!instance_deleted_callback_.is_null()) |
635 instance_deleted_callback_.Run(); | 641 instance_deleted_callback_.Run(); |
636 | 642 |
637 if (!module_->IsProxied() && render_frame_) { | 643 if (!module_->IsProxied() && render_frame_) { |
638 PepperBrowserConnection* browser_connection = | 644 PepperBrowserConnection* browser_connection = |
639 PepperBrowserConnection::Get(render_frame_); | 645 PepperBrowserConnection::Get(render_frame_); |
(...skipping 10 matching lines...) Expand all Loading... |
650 // want to look up in the global map to get info off of our object. | 656 // want to look up in the global map to get info off of our object. |
651 HostGlobals::Get()->InstanceDeleted(pp_instance_); | 657 HostGlobals::Get()->InstanceDeleted(pp_instance_); |
652 } | 658 } |
653 | 659 |
654 // NOTE: Any of these methods that calls into the plugin needs to take into | 660 // NOTE: Any of these methods that calls into the plugin needs to take into |
655 // account that the plugin may use Var to remove the <embed> from the DOM, which | 661 // account that the plugin may use Var to remove the <embed> from the DOM, which |
656 // will make the PepperWebPluginImpl drop its reference, usually the last one. | 662 // will make the PepperWebPluginImpl drop its reference, usually the last one. |
657 // If a method needs to access a member of the instance after the call has | 663 // If a method needs to access a member of the instance after the call has |
658 // returned, then it needs to keep its own reference on the stack. | 664 // returned, then it needs to keep its own reference on the stack. |
659 | 665 |
| 666 v8::Local<v8::Object> PepperPluginInstanceImpl::GetMessageChannelObject() { |
| 667 return v8::Local<v8::Object>::New(isolate_, message_channel_object_); |
| 668 } |
| 669 |
| 670 void PepperPluginInstanceImpl::MessageChannelDestroyed() { |
| 671 message_channel_ = NULL; |
| 672 message_channel_object_.Reset(); |
| 673 } |
| 674 |
660 v8::Local<v8::Context> PepperPluginInstanceImpl::GetContext() { | 675 v8::Local<v8::Context> PepperPluginInstanceImpl::GetContext() { |
661 if (!container_) | 676 if (!container_) |
662 return v8::Handle<v8::Context>(); | 677 return v8::Handle<v8::Context>(); |
663 WebLocalFrame* frame = container_->element().document().frame(); | 678 WebLocalFrame* frame = container_->element().document().frame(); |
664 if (!frame) | 679 if (!frame) |
665 return v8::Handle<v8::Context>(); | 680 return v8::Handle<v8::Context>(); |
666 | 681 |
667 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | 682 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
668 DCHECK(context->GetIsolate() == isolate_); | 683 DCHECK(context->GetIsolate() == isolate_); |
669 return context; | 684 return context; |
670 } | 685 } |
671 | 686 |
672 void PepperPluginInstanceImpl::Delete() { | 687 void PepperPluginInstanceImpl::Delete() { |
673 is_deleted_ = true; | 688 is_deleted_ = true; |
674 | 689 |
675 if (render_frame_ && | 690 if (render_frame_ && |
676 render_frame_->render_view()->plugin_find_handler() == this) { | 691 render_frame_->render_view()->plugin_find_handler() == this) { |
677 render_frame_->render_view()->set_plugin_find_handler(NULL); | 692 render_frame_->render_view()->set_plugin_find_handler(NULL); |
678 } | 693 } |
679 | 694 |
680 // Keep a reference on the stack. See NOTE above. | 695 // Keep a reference on the stack. See NOTE above. |
681 scoped_refptr<PepperPluginInstanceImpl> ref(this); | 696 scoped_refptr<PepperPluginInstanceImpl> ref(this); |
682 // Force the MessageChannel to release its "passthrough object" which should | 697 // Force the MessageChannel to release its "passthrough object" which should |
683 // release our last reference to the "InstanceObject" and will probably | 698 // release our last reference to the "InstanceObject" and will probably |
684 // destroy it. We want to do this prior to calling DidDestroy in case the | 699 // destroy it. We want to do this prior to calling DidDestroy in case the |
685 // destructor of the instance object tries to use the instance. | 700 // destructor of the instance object tries to use the instance. |
686 message_channel_->SetPassthroughObject(NULL); | 701 if (message_channel_) |
| 702 message_channel_->SetPassthroughObject(v8::Handle<v8::Object>()); |
687 // If this is a NaCl plugin instance, shut down the NaCl plugin by calling | 703 // If this is a NaCl plugin instance, shut down the NaCl plugin by calling |
688 // its DidDestroy. Don't call DidDestroy on the untrusted plugin instance, | 704 // its DidDestroy. Don't call DidDestroy on the untrusted plugin instance, |
689 // since there is little that it can do at this point. | 705 // since there is little that it can do at this point. |
690 if (original_instance_interface_) | 706 if (original_instance_interface_) |
691 original_instance_interface_->DidDestroy(pp_instance()); | 707 original_instance_interface_->DidDestroy(pp_instance()); |
692 else | 708 else |
693 instance_interface_->DidDestroy(pp_instance()); | 709 instance_interface_->DidDestroy(pp_instance()); |
694 // Ensure we don't attempt to call functions on the destroyed instance. | 710 // Ensure we don't attempt to call functions on the destroyed instance. |
695 original_instance_interface_.reset(); | 711 original_instance_interface_.reset(); |
696 instance_interface_.reset(); | 712 instance_interface_.reset(); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 "Flash.UsesGPU", is_xp * 4 + needs_gpu * 2 + prefs.is_webgl_supported, 8); | 854 "Flash.UsesGPU", is_xp * 4 + needs_gpu * 2 + prefs.is_webgl_supported, 8); |
839 #endif | 855 #endif |
840 } | 856 } |
841 | 857 |
842 bool PepperPluginInstanceImpl::Initialize( | 858 bool PepperPluginInstanceImpl::Initialize( |
843 const std::vector<std::string>& arg_names, | 859 const std::vector<std::string>& arg_names, |
844 const std::vector<std::string>& arg_values, | 860 const std::vector<std::string>& arg_values, |
845 bool full_frame) { | 861 bool full_frame) { |
846 if (!render_frame_) | 862 if (!render_frame_) |
847 return false; | 863 return false; |
848 message_channel_.reset(new MessageChannel(this)); | 864 message_channel_ = MessageChannel::Create(this, &message_channel_object_); |
849 | 865 |
850 full_frame_ = full_frame; | 866 full_frame_ = full_frame; |
851 | 867 |
852 UpdateTouchEventRequest(); | 868 UpdateTouchEventRequest(); |
853 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); | 869 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); |
854 | 870 |
855 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build( | 871 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build( |
856 render_frame_->render_view()->webkit_preferences())), | 872 render_frame_->render_view()->webkit_preferences())), |
857 arg_names, | 873 arg_names, |
858 arg_values); | 874 arg_values); |
859 | 875 |
860 argn_ = arg_names; | 876 argn_ = arg_names; |
861 argv_ = arg_values; | 877 argv_ = arg_values; |
862 scoped_ptr<const char * []> argn_array(StringVectorToArgArray(argn_)); | 878 scoped_ptr<const char * []> argn_array(StringVectorToArgArray(argn_)); |
863 scoped_ptr<const char * []> argv_array(StringVectorToArgArray(argv_)); | 879 scoped_ptr<const char * []> argv_array(StringVectorToArgArray(argv_)); |
864 bool success = PP_ToBool(instance_interface_->DidCreate( | 880 bool success = PP_ToBool(instance_interface_->DidCreate( |
865 pp_instance(), argn_.size(), argn_array.get(), argv_array.get())); | 881 pp_instance(), argn_.size(), argn_array.get(), argv_array.get())); |
866 // If this is a plugin that hosts external plugins, we should delay messages | 882 // If this is a plugin that hosts external plugins, we should delay messages |
867 // so that the child plugin that's created later will receive all the | 883 // so that the child plugin that's created later will receive all the |
868 // messages. (E.g., NaCl trusted plugin starting a child NaCl app.) | 884 // messages. (E.g., NaCl trusted plugin starting a child NaCl app.) |
869 // | 885 // |
870 // A host for external plugins will call ResetAsProxied later, at which point | 886 // A host for external plugins will call ResetAsProxied later, at which point |
871 // we can Start() the message_channel_. | 887 // we can Start() the MessageChannel. |
872 if (success && (!module_->renderer_ppapi_host()->IsExternalPluginHost())) | 888 if (success && (!module_->renderer_ppapi_host()->IsExternalPluginHost())) { |
873 message_channel_->Start(); | 889 if (message_channel_) |
| 890 message_channel_->Start(); |
| 891 } |
874 return success; | 892 return success; |
875 } | 893 } |
876 | 894 |
877 bool PepperPluginInstanceImpl::HandleDocumentLoad( | 895 bool PepperPluginInstanceImpl::HandleDocumentLoad( |
878 const blink::WebURLResponse& response) { | 896 const blink::WebURLResponse& response) { |
879 DCHECK(!document_loader_); | 897 DCHECK(!document_loader_); |
880 if (external_document_load_) { | 898 if (external_document_load_) { |
881 // The external proxy isn't available, so save the response and record | 899 // The external proxy isn't available, so save the response and record |
882 // document load notifications for later replay. | 900 // document load notifications for later replay. |
883 external_document_response_ = response; | 901 external_document_response_ = response; |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1166 } | 1184 } |
1167 } | 1185 } |
1168 | 1186 |
1169 if (cursor_) | 1187 if (cursor_) |
1170 *cursor_info = *cursor_; | 1188 *cursor_info = *cursor_; |
1171 return rv; | 1189 return rv; |
1172 } | 1190 } |
1173 | 1191 |
1174 void PepperPluginInstanceImpl::HandleMessage(ScopedPPVar message) { | 1192 void PepperPluginInstanceImpl::HandleMessage(ScopedPPVar message) { |
1175 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleMessage"); | 1193 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleMessage"); |
| 1194 if (is_deleted_) |
| 1195 return; |
1176 ppapi::proxy::HostDispatcher* dispatcher = | 1196 ppapi::proxy::HostDispatcher* dispatcher = |
1177 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); | 1197 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); |
1178 if (!dispatcher || (message.get().type == PP_VARTYPE_OBJECT)) { | 1198 if (!dispatcher || (message.get().type == PP_VARTYPE_OBJECT)) { |
1179 // The dispatcher should always be valid, and MessageChannel should never | 1199 // The dispatcher should always be valid, and MessageChannel should never |
1180 // send an 'object' var over PPP_Messaging. | 1200 // send an 'object' var over PPP_Messaging. |
1181 NOTREACHED(); | 1201 NOTREACHED(); |
1182 return; | 1202 return; |
1183 } | 1203 } |
1184 dispatcher->Send(new PpapiMsg_PPPMessaging_HandleMessage( | 1204 dispatcher->Send(new PpapiMsg_PPPMessaging_HandleMessage( |
1185 ppapi::API_ID_PPP_MESSAGING, | 1205 ppapi::API_ID_PPP_MESSAGING, |
1186 pp_instance(), | 1206 pp_instance(), |
1187 ppapi::proxy::SerializedVarSendInputShmem(dispatcher, message.get(), | 1207 ppapi::proxy::SerializedVarSendInputShmem(dispatcher, message.get(), |
1188 pp_instance()))); | 1208 pp_instance()))); |
1189 } | 1209 } |
1190 | 1210 |
1191 bool PepperPluginInstanceImpl::HandleBlockingMessage(ScopedPPVar message, | 1211 bool PepperPluginInstanceImpl::HandleBlockingMessage(ScopedPPVar message, |
1192 ScopedPPVar* result) { | 1212 ScopedPPVar* result) { |
1193 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleBlockingMessage"); | 1213 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleBlockingMessage"); |
| 1214 if (is_deleted_) |
| 1215 return false; |
1194 ppapi::proxy::HostDispatcher* dispatcher = | 1216 ppapi::proxy::HostDispatcher* dispatcher = |
1195 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); | 1217 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); |
1196 if (!dispatcher || (message.get().type == PP_VARTYPE_OBJECT)) { | 1218 if (!dispatcher || (message.get().type == PP_VARTYPE_OBJECT)) { |
1197 // The dispatcher should always be valid, and MessageChannel should never | 1219 // The dispatcher should always be valid, and MessageChannel should never |
1198 // send an 'object' var over PPP_Messaging. | 1220 // send an 'object' var over PPP_Messaging. |
1199 NOTREACHED(); | 1221 NOTREACHED(); |
1200 return false; | 1222 return false; |
1201 } | 1223 } |
1202 ppapi::proxy::ReceiveSerializedVarReturnValue msg_reply; | 1224 ppapi::proxy::ReceiveSerializedVarReturnValue msg_reply; |
1203 bool was_handled = false; | 1225 bool was_handled = false; |
1204 dispatcher->Send(new PpapiMsg_PPPMessageHandler_HandleBlockingMessage( | 1226 dispatcher->Send(new PpapiMsg_PPPMessageHandler_HandleBlockingMessage( |
1205 ppapi::API_ID_PPP_MESSAGING, | 1227 ppapi::API_ID_PPP_MESSAGING, |
1206 pp_instance(), | 1228 pp_instance(), |
1207 ppapi::proxy::SerializedVarSendInputShmem(dispatcher, message.get(), | 1229 ppapi::proxy::SerializedVarSendInputShmem(dispatcher, message.get(), |
1208 pp_instance()), | 1230 pp_instance()), |
1209 &msg_reply, | 1231 &msg_reply, |
1210 &was_handled)); | 1232 &was_handled)); |
1211 *result = ScopedPPVar(ScopedPPVar::PassRef(), msg_reply.Return(dispatcher)); | 1233 *result = ScopedPPVar(ScopedPPVar::PassRef(), msg_reply.Return(dispatcher)); |
1212 TRACE_EVENT0("ppapi", | 1234 TRACE_EVENT0("ppapi", |
1213 "PepperPluginInstanceImpl::HandleBlockingMessage return."); | 1235 "PepperPluginInstanceImpl::HandleBlockingMessage return."); |
1214 return was_handled; | 1236 return was_handled; |
1215 } | 1237 } |
1216 | 1238 |
1217 PP_Var PepperPluginInstanceImpl::GetInstanceObject() { | 1239 PP_Var PepperPluginInstanceImpl::GetInstanceObject(v8::Isolate* isolate) { |
1218 // Keep a reference on the stack. See NOTE above. | 1240 // Keep a reference on the stack. See NOTE above. |
1219 scoped_refptr<PepperPluginInstanceImpl> ref(this); | 1241 scoped_refptr<PepperPluginInstanceImpl> ref(this); |
1220 | 1242 |
| 1243 DCHECK_EQ(isolate, isolate_); |
| 1244 |
1221 // If the plugin supports the private instance interface, try to retrieve its | 1245 // If the plugin supports the private instance interface, try to retrieve its |
1222 // instance object. | 1246 // instance object. |
1223 if (LoadPrivateInterface()) | 1247 if (LoadPrivateInterface()) |
1224 return plugin_private_interface_->GetInstanceObject(pp_instance()); | 1248 return plugin_private_interface_->GetInstanceObject(pp_instance()); |
1225 return PP_MakeUndefined(); | 1249 return PP_MakeUndefined(); |
1226 } | 1250 } |
1227 | 1251 |
1228 void PepperPluginInstanceImpl::ViewChanged( | 1252 void PepperPluginInstanceImpl::ViewChanged( |
1229 const gfx::Rect& position, | 1253 const gfx::Rect& position, |
1230 const gfx::Rect& clip, | 1254 const gfx::Rect& clip, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 void PepperPluginInstanceImpl::SetLinkUnderCursor(const std::string& url) { | 1370 void PepperPluginInstanceImpl::SetLinkUnderCursor(const std::string& url) { |
1347 link_under_cursor_ = base::UTF8ToUTF16(url); | 1371 link_under_cursor_ = base::UTF8ToUTF16(url); |
1348 } | 1372 } |
1349 | 1373 |
1350 void PepperPluginInstanceImpl::SetTextInputType(ui::TextInputType type) { | 1374 void PepperPluginInstanceImpl::SetTextInputType(ui::TextInputType type) { |
1351 text_input_type_ = type; | 1375 text_input_type_ = type; |
1352 render_frame_->PepperTextInputTypeChanged(this); | 1376 render_frame_->PepperTextInputTypeChanged(this); |
1353 } | 1377 } |
1354 | 1378 |
1355 void PepperPluginInstanceImpl::PostMessageToJavaScript(PP_Var message) { | 1379 void PepperPluginInstanceImpl::PostMessageToJavaScript(PP_Var message) { |
1356 message_channel_->PostMessageToJavaScript(message); | 1380 if (message_channel_) |
| 1381 message_channel_->PostMessageToJavaScript(message); |
1357 } | 1382 } |
1358 | 1383 |
1359 int32_t PepperPluginInstanceImpl::RegisterMessageHandler( | 1384 int32_t PepperPluginInstanceImpl::RegisterMessageHandler( |
1360 PP_Instance instance, | 1385 PP_Instance instance, |
1361 void* user_data, | 1386 void* user_data, |
1362 const PPP_MessageHandler_0_1* handler, | 1387 const PPP_MessageHandler_0_1* handler, |
1363 PP_Resource message_loop) { | 1388 PP_Resource message_loop) { |
1364 // Not supported in-process. | 1389 // Not supported in-process. |
1365 NOTIMPLEMENTED(); | 1390 NOTIMPLEMENTED(); |
1366 return PP_ERROR_FAILED; | 1391 return PP_ERROR_FAILED; |
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2345 } | 2370 } |
2346 | 2371 |
2347 PP_Bool PepperPluginInstanceImpl::FlashIsFullscreen(PP_Instance instance) { | 2372 PP_Bool PepperPluginInstanceImpl::FlashIsFullscreen(PP_Instance instance) { |
2348 return PP_FromBool(flash_fullscreen_); | 2373 return PP_FromBool(flash_fullscreen_); |
2349 } | 2374 } |
2350 | 2375 |
2351 PP_Var PepperPluginInstanceImpl::GetWindowObject(PP_Instance instance) { | 2376 PP_Var PepperPluginInstanceImpl::GetWindowObject(PP_Instance instance) { |
2352 if (!container_) | 2377 if (!container_) |
2353 return PP_MakeUndefined(); | 2378 return PP_MakeUndefined(); |
2354 | 2379 |
| 2380 PepperTryCatchVar try_catch(this, NULL); |
2355 WebLocalFrame* frame = container_->element().document().frame(); | 2381 WebLocalFrame* frame = container_->element().document().frame(); |
2356 if (!frame) | 2382 if (!frame) { |
| 2383 try_catch.SetException("No frame exists for window object."); |
2357 return PP_MakeUndefined(); | 2384 return PP_MakeUndefined(); |
| 2385 } |
2358 | 2386 |
2359 return NPObjectToPPVar(this, frame->windowObject()); | 2387 ScopedPPVar result = |
| 2388 try_catch.FromV8(frame->mainWorldScriptContext()->Global()); |
| 2389 DCHECK(!try_catch.HasException()); |
| 2390 return result.Release(); |
2360 } | 2391 } |
2361 | 2392 |
2362 PP_Var PepperPluginInstanceImpl::GetOwnerElementObject(PP_Instance instance) { | 2393 PP_Var PepperPluginInstanceImpl::GetOwnerElementObject(PP_Instance instance) { |
2363 if (!container_) | 2394 if (!container_) |
2364 return PP_MakeUndefined(); | 2395 return PP_MakeUndefined(); |
2365 return NPObjectToPPVar(this, container_->scriptableObjectForElement()); | 2396 PepperTryCatchVar try_catch(this, NULL); |
| 2397 ScopedPPVar result = try_catch.FromV8(container_->v8ObjectForElement()); |
| 2398 DCHECK(!try_catch.HasException()); |
| 2399 return result.Release(); |
2366 } | 2400 } |
2367 | 2401 |
2368 PP_Var PepperPluginInstanceImpl::ExecuteScript(PP_Instance instance, | 2402 PP_Var PepperPluginInstanceImpl::ExecuteScript(PP_Instance instance, |
2369 PP_Var script, | 2403 PP_Var script_var, |
2370 PP_Var* exception) { | 2404 PP_Var* exception) { |
| 2405 if (!container_) |
| 2406 return PP_MakeUndefined(); |
| 2407 |
2371 // Executing the script may remove the plugin from the DOM, so we need to keep | 2408 // Executing the script may remove the plugin from the DOM, so we need to keep |
2372 // a reference to ourselves so that we can still process the result after the | 2409 // a reference to ourselves so that we can still process the result after the |
2373 // WebBindings::evaluate() below. | 2410 // WebBindings::evaluate() below. |
2374 scoped_refptr<PepperPluginInstanceImpl> ref(this); | 2411 scoped_refptr<PepperPluginInstanceImpl> ref(this); |
2375 TryCatch try_catch(exception); | 2412 PepperTryCatchVar try_catch(this, exception); |
2376 if (try_catch.has_exception()) | 2413 |
| 2414 // Check for an exception due to the context being destroyed. |
| 2415 if (try_catch.HasException()) |
2377 return PP_MakeUndefined(); | 2416 return PP_MakeUndefined(); |
2378 | 2417 |
2379 // Convert the script into an inconvenient NPString object. | 2418 WebLocalFrame* frame = container_->element().document().frame(); |
2380 StringVar* script_string = StringVar::FromPPVar(script); | 2419 if (!frame) { |
2381 if (!script_string) { | 2420 try_catch.SetException("No frame to execute script in."); |
| 2421 return PP_MakeUndefined(); |
| 2422 } |
| 2423 |
| 2424 StringVar* script_string_var = StringVar::FromPPVar(script_var); |
| 2425 if (!script_string_var) { |
2382 try_catch.SetException("Script param to ExecuteScript must be a string."); | 2426 try_catch.SetException("Script param to ExecuteScript must be a string."); |
2383 return PP_MakeUndefined(); | 2427 return PP_MakeUndefined(); |
2384 } | 2428 } |
2385 NPString np_script; | |
2386 np_script.UTF8Characters = script_string->value().c_str(); | |
2387 np_script.UTF8Length = script_string->value().length(); | |
2388 | 2429 |
2389 // Get the current frame to pass to the evaluate function. | 2430 std::string script_string = script_string_var->value(); |
2390 WebLocalFrame* frame = NULL; | 2431 blink::WebScriptSource script( |
2391 if (container_) | 2432 blink::WebString::fromUTF8(script_string.c_str())); |
2392 frame = container_->element().document().frame(); | 2433 v8::Handle<v8::Value> result; |
2393 if (!frame || !frame->windowObject()) { | 2434 if (IsProcessingUserGesture()) { |
2394 try_catch.SetException("No context in which to execute script."); | 2435 blink::WebScopedUserGesture user_gesture(CurrentUserGestureToken()); |
2395 return PP_MakeUndefined(); | 2436 result = frame->executeScriptAndReturnValue(script); |
| 2437 } else { |
| 2438 result = frame->executeScriptAndReturnValue(script); |
2396 } | 2439 } |
2397 | 2440 |
2398 NPVariant result; | 2441 // Check for an exception due to the context being destroyed. |
2399 bool ok = false; | 2442 if (try_catch.HasException()) |
2400 if (IsProcessingUserGesture()) { | |
2401 blink::WebScopedUserGesture user_gesture(CurrentUserGestureToken()); | |
2402 ok = | |
2403 WebBindings::evaluate(NULL, frame->windowObject(), &np_script, &result); | |
2404 } else { | |
2405 ok = | |
2406 WebBindings::evaluate(NULL, frame->windowObject(), &np_script, &result); | |
2407 } | |
2408 if (!ok) { | |
2409 // TryCatch doesn't catch the exceptions properly. Since this is only for | |
2410 // a trusted API, just set to a general exception message. | |
2411 try_catch.SetException("Exception caught"); | |
2412 WebBindings::releaseVariantValue(&result); | |
2413 return PP_MakeUndefined(); | 2443 return PP_MakeUndefined(); |
2414 } | |
2415 | 2444 |
2416 PP_Var ret = NPVariantToPPVar(this, &result); | 2445 ScopedPPVar var_result = try_catch.FromV8(result); |
2417 WebBindings::releaseVariantValue(&result); | 2446 if (try_catch.HasException()) |
2418 return ret; | 2447 return PP_MakeUndefined(); |
| 2448 |
| 2449 return var_result.Release(); |
2419 } | 2450 } |
2420 | 2451 |
2421 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputSampleRate( | 2452 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputSampleRate( |
2422 PP_Instance instance) { | 2453 PP_Instance instance) { |
2423 RenderThreadImpl* thread = RenderThreadImpl::current(); | 2454 RenderThreadImpl* thread = RenderThreadImpl::current(); |
2424 return thread->GetAudioHardwareConfig()->GetOutputSampleRate(); | 2455 return thread->GetAudioHardwareConfig()->GetOutputSampleRate(); |
2425 } | 2456 } |
2426 | 2457 |
2427 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputBufferSize( | 2458 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputBufferSize( |
2428 PP_Instance instance) { | 2459 PP_Instance instance) { |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2937 plugin_selection_interface_ = NULL; | 2968 plugin_selection_interface_ = NULL; |
2938 plugin_textinput_interface_ = NULL; | 2969 plugin_textinput_interface_ = NULL; |
2939 plugin_zoom_interface_ = NULL; | 2970 plugin_zoom_interface_ = NULL; |
2940 | 2971 |
2941 // Re-send the DidCreate event via the proxy. | 2972 // Re-send the DidCreate event via the proxy. |
2942 scoped_ptr<const char * []> argn_array(StringVectorToArgArray(argn_)); | 2973 scoped_ptr<const char * []> argn_array(StringVectorToArgArray(argn_)); |
2943 scoped_ptr<const char * []> argv_array(StringVectorToArgArray(argv_)); | 2974 scoped_ptr<const char * []> argv_array(StringVectorToArgArray(argv_)); |
2944 if (!instance_interface_->DidCreate( | 2975 if (!instance_interface_->DidCreate( |
2945 pp_instance(), argn_.size(), argn_array.get(), argv_array.get())) | 2976 pp_instance(), argn_.size(), argn_array.get(), argv_array.get())) |
2946 return PP_EXTERNAL_PLUGIN_ERROR_INSTANCE; | 2977 return PP_EXTERNAL_PLUGIN_ERROR_INSTANCE; |
2947 message_channel_->Start(); | 2978 if (message_channel_) |
| 2979 message_channel_->Start(); |
2948 | 2980 |
2949 // Clear sent_initial_did_change_view_ and cancel any pending DidChangeView | 2981 // Clear sent_initial_did_change_view_ and cancel any pending DidChangeView |
2950 // event. This way, SendDidChangeView will send the "current" view | 2982 // event. This way, SendDidChangeView will send the "current" view |
2951 // immediately (before other events like HandleDocumentLoad). | 2983 // immediately (before other events like HandleDocumentLoad). |
2952 sent_initial_did_change_view_ = false; | 2984 sent_initial_did_change_view_ = false; |
2953 view_change_weak_ptr_factory_.InvalidateWeakPtrs(); | 2985 view_change_weak_ptr_factory_.InvalidateWeakPtrs(); |
2954 SendDidChangeView(); | 2986 SendDidChangeView(); |
2955 | 2987 |
2956 DCHECK(external_document_load_); | 2988 DCHECK(external_document_load_); |
2957 external_document_load_ = false; | 2989 external_document_load_ = false; |
2958 if (!external_document_response_.isNull()) { | 2990 if (!external_document_response_.isNull()) { |
2959 document_loader_ = NULL; | 2991 document_loader_ = NULL; |
2960 // Pass the response to the new proxy. | 2992 // Pass the response to the new proxy. |
2961 HandleDocumentLoad(external_document_response_); | 2993 HandleDocumentLoad(external_document_response_); |
2962 external_document_response_ = blink::WebURLResponse(); | 2994 external_document_response_ = blink::WebURLResponse(); |
2963 // Replay any document load events we've received to the real loader. | 2995 // Replay any document load events we've received to the real loader. |
2964 external_document_loader_->ReplayReceivedData(document_loader_); | 2996 external_document_loader_->ReplayReceivedData(document_loader_); |
2965 external_document_loader_.reset(NULL); | 2997 external_document_loader_.reset(NULL); |
2966 } | 2998 } |
2967 | 2999 |
2968 return PP_EXTERNAL_PLUGIN_OK; | 3000 return PP_EXTERNAL_PLUGIN_OK; |
2969 } | 3001 } |
2970 | 3002 |
2971 bool PepperPluginInstanceImpl::IsValidInstanceOf(PluginModule* module) { | 3003 bool PepperPluginInstanceImpl::IsValidInstanceOf(PluginModule* module) { |
2972 DCHECK(module); | 3004 DCHECK(module); |
2973 return module == module_.get() || module == original_module_.get(); | 3005 return module == module_.get() || module == original_module_.get(); |
2974 } | 3006 } |
2975 | 3007 |
2976 NPP PepperPluginInstanceImpl::instanceNPP() { return npp_.get(); } | |
2977 | |
2978 PepperPluginInstance* PepperPluginInstance::Get(PP_Instance instance_id) { | 3008 PepperPluginInstance* PepperPluginInstance::Get(PP_Instance instance_id) { |
2979 return HostGlobals::Get()->GetInstance(instance_id); | 3009 return HostGlobals::Get()->GetInstance(instance_id); |
2980 } | 3010 } |
2981 | 3011 |
2982 RenderView* PepperPluginInstanceImpl::GetRenderView() { | 3012 RenderView* PepperPluginInstanceImpl::GetRenderView() { |
2983 return render_frame_ ? render_frame_->render_view() : NULL; | 3013 return render_frame_ ? render_frame_->render_view() : NULL; |
2984 } | 3014 } |
2985 | 3015 |
2986 blink::WebPluginContainer* PepperPluginInstanceImpl::GetContainer() { | 3016 blink::WebPluginContainer* PepperPluginInstanceImpl::GetContainer() { |
2987 return container_; | 3017 return container_; |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3174 int PepperPluginInstanceImpl::MakePendingFileRefRendererHost( | 3204 int PepperPluginInstanceImpl::MakePendingFileRefRendererHost( |
3175 const base::FilePath& path) { | 3205 const base::FilePath& path) { |
3176 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); | 3206 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); |
3177 PepperFileRefRendererHost* file_ref_host( | 3207 PepperFileRefRendererHost* file_ref_host( |
3178 new PepperFileRefRendererHost(host_impl, pp_instance(), 0, path)); | 3208 new PepperFileRefRendererHost(host_impl, pp_instance(), 0, path)); |
3179 return host_impl->GetPpapiHost()->AddPendingResourceHost( | 3209 return host_impl->GetPpapiHost()->AddPendingResourceHost( |
3180 scoped_ptr<ppapi::host::ResourceHost>(file_ref_host)); | 3210 scoped_ptr<ppapi::host::ResourceHost>(file_ref_host)); |
3181 } | 3211 } |
3182 | 3212 |
3183 void PepperPluginInstanceImpl::SetEmbedProperty(PP_Var key, PP_Var value) { | 3213 void PepperPluginInstanceImpl::SetEmbedProperty(PP_Var key, PP_Var value) { |
3184 message_channel_->SetReadOnlyProperty(key, value); | 3214 if (message_channel_) |
| 3215 message_channel_->SetReadOnlyProperty(key, value); |
3185 } | 3216 } |
3186 | 3217 |
3187 bool PepperPluginInstanceImpl::CanAccessMainFrame() const { | 3218 bool PepperPluginInstanceImpl::CanAccessMainFrame() const { |
3188 if (!container_) | 3219 if (!container_) |
3189 return false; | 3220 return false; |
3190 blink::WebDocument containing_document = container_->element().document(); | 3221 blink::WebDocument containing_document = container_->element().document(); |
3191 | 3222 |
3192 if (!containing_document.frame() || !containing_document.frame()->view() || | 3223 if (!containing_document.frame() || !containing_document.frame()->view() || |
3193 !containing_document.frame()->view()->mainFrame()) { | 3224 !containing_document.frame()->view()->mainFrame()) { |
3194 return false; | 3225 return false; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3311 // Running out-of-process. Initiate an IPC call to notify the plugin | 3342 // Running out-of-process. Initiate an IPC call to notify the plugin |
3312 // process. | 3343 // process. |
3313 ppapi::proxy::HostDispatcher* dispatcher = | 3344 ppapi::proxy::HostDispatcher* dispatcher = |
3314 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); | 3345 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); |
3315 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( | 3346 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( |
3316 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); | 3347 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); |
3317 } | 3348 } |
3318 } | 3349 } |
3319 | 3350 |
3320 } // namespace content | 3351 } // namespace content |
OLD | NEW |