| 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/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" | 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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 filtered_input_event_mask_(0), | 553 filtered_input_event_mask_(0), |
| 553 text_input_type_(kPluginDefaultTextInputType), | 554 text_input_type_(kPluginDefaultTextInputType), |
| 554 text_input_caret_(0, 0, 0, 0), | 555 text_input_caret_(0, 0, 0, 0), |
| 555 text_input_caret_bounds_(0, 0, 0, 0), | 556 text_input_caret_bounds_(0, 0, 0, 0), |
| 556 text_input_caret_set_(false), | 557 text_input_caret_set_(false), |
| 557 selection_caret_(0), | 558 selection_caret_(0), |
| 558 selection_anchor_(0), | 559 selection_anchor_(0), |
| 559 pending_user_gesture_(0.0), | 560 pending_user_gesture_(0.0), |
| 560 document_loader_(NULL), | 561 document_loader_(NULL), |
| 561 external_document_load_(false), | 562 external_document_load_(false), |
| 562 npp_(new NPP_t), | |
| 563 isolate_(v8::Isolate::GetCurrent()), | 563 isolate_(v8::Isolate::GetCurrent()), |
| 564 is_deleted_(false), | 564 is_deleted_(false), |
| 565 last_input_number_(0), | 565 last_input_number_(0), |
| 566 is_tracking_latency_(false), | 566 is_tracking_latency_(false), |
| 567 view_change_weak_ptr_factory_(this), | 567 view_change_weak_ptr_factory_(this), |
| 568 weak_factory_(this) { | 568 weak_factory_(this) { |
| 569 pp_instance_ = HostGlobals::Get()->AddInstance(this); | 569 pp_instance_ = HostGlobals::Get()->AddInstance(this); |
| 570 | 570 |
| 571 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 571 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
| 572 module_->InstanceCreated(this); | 572 module_->InstanceCreated(this); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); | 613 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); |
| 614 | 614 |
| 615 if (GetContentClient()->renderer() && // NULL in unit tests. | 615 if (GetContentClient()->renderer() && // NULL in unit tests. |
| 616 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) | 616 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) |
| 617 external_document_load_ = true; | 617 external_document_load_ = true; |
| 618 } | 618 } |
| 619 | 619 |
| 620 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { | 620 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { |
| 621 DCHECK(!fullscreen_container_); | 621 DCHECK(!fullscreen_container_); |
| 622 | 622 |
| 623 // Free all the plugin objects. This will automatically clear the back- | 623 // Notify all the plugin objects of deletion. This will prevent blink from |
| 624 // pointer from the NPObject so WebKit can't call into the plugin any more. | 624 // calling into the plugin any more. |
| 625 // | 625 // |
| 626 // Swap out the set so we can delete from it (the objects will try to | 626 // Swap out the set so we can delete from it (the objects will try to |
| 627 // unregister themselves inside the delete call). | 627 // unregister themselves inside the delete call). |
| 628 PluginObjectSet plugin_object_copy; | 628 PluginObjectSet plugin_object_copy; |
| 629 live_plugin_objects_.swap(plugin_object_copy); | 629 live_plugin_objects_.swap(plugin_object_copy); |
| 630 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); | 630 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); |
| 631 i != plugin_object_copy.end(); | 631 i != plugin_object_copy.end(); |
| 632 ++i) | 632 ++i) { |
| 633 delete *i; | 633 (*i)->InstanceDeleted(); |
| 634 } |
| 634 | 635 |
| 635 if (TrackedCallback::IsPending(lock_mouse_callback_)) | 636 if (TrackedCallback::IsPending(lock_mouse_callback_)) |
| 636 lock_mouse_callback_->Abort(); | 637 lock_mouse_callback_->Abort(); |
| 637 | 638 |
| 638 if (!instance_deleted_callback_.is_null()) | 639 if (!instance_deleted_callback_.is_null()) |
| 639 instance_deleted_callback_.Run(); | 640 instance_deleted_callback_.Run(); |
| 640 | 641 |
| 641 if (!module_->IsProxied() && render_frame_) { | 642 if (!module_->IsProxied() && render_frame_) { |
| 642 PepperBrowserConnection* browser_connection = | 643 PepperBrowserConnection* browser_connection = |
| 643 PepperBrowserConnection::Get(render_frame_); | 644 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. | 655 // want to look up in the global map to get info off of our object. |
| 655 HostGlobals::Get()->InstanceDeleted(pp_instance_); | 656 HostGlobals::Get()->InstanceDeleted(pp_instance_); |
| 656 } | 657 } |
| 657 | 658 |
| 658 // NOTE: Any of these methods that calls into the plugin needs to take into | 659 // 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 | 660 // 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. | 661 // 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 | 662 // 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. | 663 // returned, then it needs to keep its own reference on the stack. |
| 663 | 664 |
| 665 v8::Local<v8::Object> PepperPluginInstanceImpl::GetMessageChannelObject() { |
| 666 return v8::Local<v8::Object>::New(isolate_, message_channel_); |
| 667 } |
| 668 |
| 669 MessageChannel* PepperPluginInstanceImpl::GetMessageChannel() { |
| 670 MessageChannel* message_channel = NULL; |
| 671 v8::HandleScope scope(isolate_); |
| 672 v8::Context::Scope context_scope(GetContext()); |
| 673 if (gin::ConvertFromV8(isolate_, GetMessageChannelObject(), &message_channel)) |
| 674 return message_channel; |
| 675 return NULL; |
| 676 } |
| 677 |
| 664 v8::Local<v8::Context> PepperPluginInstanceImpl::GetContext() { | 678 v8::Local<v8::Context> PepperPluginInstanceImpl::GetContext() { |
| 665 if (!container_) | 679 if (!container_) |
| 666 return v8::Handle<v8::Context>(); | 680 return v8::Handle<v8::Context>(); |
| 667 WebLocalFrame* frame = container_->element().document().frame(); | 681 WebLocalFrame* frame = container_->element().document().frame(); |
| 668 if (!frame) | 682 if (!frame) |
| 669 return v8::Handle<v8::Context>(); | 683 return v8::Handle<v8::Context>(); |
| 670 | 684 |
| 671 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | 685 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
| 672 DCHECK(context->GetIsolate() == isolate_); | 686 DCHECK(context->GetIsolate() == isolate_); |
| 673 return context; | 687 return context; |
| 674 } | 688 } |
| 675 | 689 |
| 676 void PepperPluginInstanceImpl::Delete() { | 690 void PepperPluginInstanceImpl::Delete() { |
| 677 is_deleted_ = true; | 691 is_deleted_ = true; |
| 678 | 692 |
| 679 if (render_frame_ && | 693 if (render_frame_ && |
| 680 render_frame_->render_view()->plugin_find_handler() == this) { | 694 render_frame_->render_view()->plugin_find_handler() == this) { |
| 681 render_frame_->render_view()->set_plugin_find_handler(NULL); | 695 render_frame_->render_view()->set_plugin_find_handler(NULL); |
| 682 } | 696 } |
| 683 | 697 |
| 684 // Keep a reference on the stack. See NOTE above. | 698 // Keep a reference on the stack. See NOTE above. |
| 685 scoped_refptr<PepperPluginInstanceImpl> ref(this); | 699 scoped_refptr<PepperPluginInstanceImpl> ref(this); |
| 686 // Force the MessageChannel to release its "passthrough object" which should | 700 // Force the MessageChannel to release its "passthrough object" which should |
| 687 // release our last reference to the "InstanceObject" and will probably | 701 // release our last reference to the "InstanceObject" and will probably |
| 688 // destroy it. We want to do this prior to calling DidDestroy in case the | 702 // destroy it. We want to do this prior to calling DidDestroy in case the |
| 689 // destructor of the instance object tries to use the instance. | 703 // destructor of the instance object tries to use the instance. |
| 690 message_channel_->SetPassthroughObject(NULL); | 704 GetMessageChannel()->SetPassthroughObject(v8::Handle<v8::Object>()); |
| 691 // If this is a NaCl plugin instance, shut down the NaCl plugin by calling | 705 // If this is a NaCl plugin instance, shut down the NaCl plugin by calling |
| 692 // its DidDestroy. Don't call DidDestroy on the untrusted plugin instance, | 706 // its DidDestroy. Don't call DidDestroy on the untrusted plugin instance, |
| 693 // since there is little that it can do at this point. | 707 // since there is little that it can do at this point. |
| 694 if (original_instance_interface_) | 708 if (original_instance_interface_) |
| 695 original_instance_interface_->DidDestroy(pp_instance()); | 709 original_instance_interface_->DidDestroy(pp_instance()); |
| 696 else | 710 else |
| 697 instance_interface_->DidDestroy(pp_instance()); | 711 instance_interface_->DidDestroy(pp_instance()); |
| 698 // Ensure we don't attempt to call functions on the destroyed instance. | 712 // Ensure we don't attempt to call functions on the destroyed instance. |
| 699 original_instance_interface_.reset(); | 713 original_instance_interface_.reset(); |
| 700 instance_interface_.reset(); | 714 instance_interface_.reset(); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 "Flash.UsesGPU", is_xp * 4 + needs_gpu * 2 + prefs.is_webgl_supported, 8); | 856 "Flash.UsesGPU", is_xp * 4 + needs_gpu * 2 + prefs.is_webgl_supported, 8); |
| 843 #endif | 857 #endif |
| 844 } | 858 } |
| 845 | 859 |
| 846 bool PepperPluginInstanceImpl::Initialize( | 860 bool PepperPluginInstanceImpl::Initialize( |
| 847 const std::vector<std::string>& arg_names, | 861 const std::vector<std::string>& arg_names, |
| 848 const std::vector<std::string>& arg_values, | 862 const std::vector<std::string>& arg_values, |
| 849 bool full_frame) { | 863 bool full_frame) { |
| 850 if (!render_frame_) | 864 if (!render_frame_) |
| 851 return false; | 865 return false; |
| 852 message_channel_.reset(new MessageChannel(this)); | 866 MessageChannel::Create(this, &message_channel_); |
| 853 | 867 |
| 854 full_frame_ = full_frame; | 868 full_frame_ = full_frame; |
| 855 | 869 |
| 856 UpdateTouchEventRequest(); | 870 UpdateTouchEventRequest(); |
| 857 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); | 871 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); |
| 858 | 872 |
| 859 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build( | 873 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build( |
| 860 render_frame_->render_view()->webkit_preferences())), | 874 render_frame_->render_view()->webkit_preferences())), |
| 861 arg_names, | 875 arg_names, |
| 862 arg_values); | 876 arg_values); |
| 863 | 877 |
| 864 argn_ = arg_names; | 878 argn_ = arg_names; |
| 865 argv_ = arg_values; | 879 argv_ = arg_values; |
| 866 scoped_ptr<const char * []> argn_array(StringVectorToArgArray(argn_)); | 880 scoped_ptr<const char * []> argn_array(StringVectorToArgArray(argn_)); |
| 867 scoped_ptr<const char * []> argv_array(StringVectorToArgArray(argv_)); | 881 scoped_ptr<const char * []> argv_array(StringVectorToArgArray(argv_)); |
| 868 bool success = PP_ToBool(instance_interface_->DidCreate( | 882 bool success = PP_ToBool(instance_interface_->DidCreate( |
| 869 pp_instance(), argn_.size(), argn_array.get(), argv_array.get())); | 883 pp_instance(), argn_.size(), argn_array.get(), argv_array.get())); |
| 870 // If this is a plugin that hosts external plugins, we should delay messages | 884 // If this is a plugin that hosts external plugins, we should delay messages |
| 871 // so that the child plugin that's created later will receive all the | 885 // so that the child plugin that's created later will receive all the |
| 872 // messages. (E.g., NaCl trusted plugin starting a child NaCl app.) | 886 // messages. (E.g., NaCl trusted plugin starting a child NaCl app.) |
| 873 // | 887 // |
| 874 // A host for external plugins will call ResetAsProxied later, at which point | 888 // A host for external plugins will call ResetAsProxied later, at which point |
| 875 // we can Start() the message_channel_. | 889 // we can Start() the message_channel_. |
| 876 if (success && (!module_->renderer_ppapi_host()->IsExternalPluginHost())) | 890 if (success && (!module_->renderer_ppapi_host()->IsExternalPluginHost())) |
| 877 message_channel_->Start(); | 891 GetMessageChannel()->Start(); |
| 878 return success; | 892 return success; |
| 879 } | 893 } |
| 880 | 894 |
| 881 bool PepperPluginInstanceImpl::HandleDocumentLoad( | 895 bool PepperPluginInstanceImpl::HandleDocumentLoad( |
| 882 const blink::WebURLResponse& response) { | 896 const blink::WebURLResponse& response) { |
| 883 DCHECK(!document_loader_); | 897 DCHECK(!document_loader_); |
| 884 if (external_document_load_) { | 898 if (external_document_load_) { |
| 885 // 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 |
| 886 // document load notifications for later replay. | 900 // document load notifications for later replay. |
| 887 external_document_response_ = response; | 901 external_document_response_ = response; |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 ppapi::proxy::SerializedVarSendInputShmem(dispatcher, message.get(), | 1225 ppapi::proxy::SerializedVarSendInputShmem(dispatcher, message.get(), |
| 1212 pp_instance()), | 1226 pp_instance()), |
| 1213 &msg_reply, | 1227 &msg_reply, |
| 1214 &was_handled)); | 1228 &was_handled)); |
| 1215 *result = ScopedPPVar(ScopedPPVar::PassRef(), msg_reply.Return(dispatcher)); | 1229 *result = ScopedPPVar(ScopedPPVar::PassRef(), msg_reply.Return(dispatcher)); |
| 1216 TRACE_EVENT0("ppapi", | 1230 TRACE_EVENT0("ppapi", |
| 1217 "PepperPluginInstanceImpl::HandleBlockingMessage return."); | 1231 "PepperPluginInstanceImpl::HandleBlockingMessage return."); |
| 1218 return was_handled; | 1232 return was_handled; |
| 1219 } | 1233 } |
| 1220 | 1234 |
| 1221 PP_Var PepperPluginInstanceImpl::GetInstanceObject() { | 1235 PP_Var PepperPluginInstanceImpl::GetInstanceObject(v8::Isolate* isolate) { |
| 1222 // Keep a reference on the stack. See NOTE above. | 1236 // Keep a reference on the stack. See NOTE above. |
| 1223 scoped_refptr<PepperPluginInstanceImpl> ref(this); | 1237 scoped_refptr<PepperPluginInstanceImpl> ref(this); |
| 1224 | 1238 |
| 1239 DCHECK_EQ(isolate, isolate_); |
| 1240 |
| 1225 // If the plugin supports the private instance interface, try to retrieve its | 1241 // If the plugin supports the private instance interface, try to retrieve its |
| 1226 // instance object. | 1242 // instance object. |
| 1227 if (LoadPrivateInterface()) | 1243 if (LoadPrivateInterface()) |
| 1228 return plugin_private_interface_->GetInstanceObject(pp_instance()); | 1244 return plugin_private_interface_->GetInstanceObject(pp_instance()); |
| 1229 return PP_MakeUndefined(); | 1245 return PP_MakeUndefined(); |
| 1230 } | 1246 } |
| 1231 | 1247 |
| 1232 void PepperPluginInstanceImpl::ViewChanged( | 1248 void PepperPluginInstanceImpl::ViewChanged( |
| 1233 const gfx::Rect& position, | 1249 const gfx::Rect& position, |
| 1234 const gfx::Rect& clip, | 1250 const gfx::Rect& clip, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 void PepperPluginInstanceImpl::SetLinkUnderCursor(const std::string& url) { | 1366 void PepperPluginInstanceImpl::SetLinkUnderCursor(const std::string& url) { |
| 1351 link_under_cursor_ = base::UTF8ToUTF16(url); | 1367 link_under_cursor_ = base::UTF8ToUTF16(url); |
| 1352 } | 1368 } |
| 1353 | 1369 |
| 1354 void PepperPluginInstanceImpl::SetTextInputType(ui::TextInputType type) { | 1370 void PepperPluginInstanceImpl::SetTextInputType(ui::TextInputType type) { |
| 1355 text_input_type_ = type; | 1371 text_input_type_ = type; |
| 1356 render_frame_->PepperTextInputTypeChanged(this); | 1372 render_frame_->PepperTextInputTypeChanged(this); |
| 1357 } | 1373 } |
| 1358 | 1374 |
| 1359 void PepperPluginInstanceImpl::PostMessageToJavaScript(PP_Var message) { | 1375 void PepperPluginInstanceImpl::PostMessageToJavaScript(PP_Var message) { |
| 1360 message_channel_->PostMessageToJavaScript(message); | 1376 GetMessageChannel()->PostMessageToJavaScript(message); |
| 1361 } | 1377 } |
| 1362 | 1378 |
| 1363 int32_t PepperPluginInstanceImpl::RegisterMessageHandler( | 1379 int32_t PepperPluginInstanceImpl::RegisterMessageHandler( |
| 1364 PP_Instance instance, | 1380 PP_Instance instance, |
| 1365 void* user_data, | 1381 void* user_data, |
| 1366 const PPP_MessageHandler_0_1* handler, | 1382 const PPP_MessageHandler_0_1* handler, |
| 1367 PP_Resource message_loop) { | 1383 PP_Resource message_loop) { |
| 1368 // Not supported in-process. | 1384 // Not supported in-process. |
| 1369 NOTIMPLEMENTED(); | 1385 NOTIMPLEMENTED(); |
| 1370 return PP_ERROR_FAILED; | 1386 return PP_ERROR_FAILED; |
| (...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2354 } | 2370 } |
| 2355 | 2371 |
| 2356 PP_Bool PepperPluginInstanceImpl::FlashIsFullscreen(PP_Instance instance) { | 2372 PP_Bool PepperPluginInstanceImpl::FlashIsFullscreen(PP_Instance instance) { |
| 2357 return PP_FromBool(flash_fullscreen_); | 2373 return PP_FromBool(flash_fullscreen_); |
| 2358 } | 2374 } |
| 2359 | 2375 |
| 2360 PP_Var PepperPluginInstanceImpl::GetWindowObject(PP_Instance instance) { | 2376 PP_Var PepperPluginInstanceImpl::GetWindowObject(PP_Instance instance) { |
| 2361 if (!container_) | 2377 if (!container_) |
| 2362 return PP_MakeUndefined(); | 2378 return PP_MakeUndefined(); |
| 2363 | 2379 |
| 2380 PepperTryCatchVar try_catch(this, NULL); |
| 2364 WebLocalFrame* frame = container_->element().document().frame(); | 2381 WebLocalFrame* frame = container_->element().document().frame(); |
| 2365 if (!frame) | 2382 if (!frame) { |
| 2383 try_catch.SetException("No frame exists for window object."); |
| 2366 return PP_MakeUndefined(); | 2384 return PP_MakeUndefined(); |
| 2385 } |
| 2367 | 2386 |
| 2368 return NPObjectToPPVar(this, frame->windowObject()); | 2387 ScopedPPVar result = |
| 2388 try_catch.FromV8(frame->mainWorldScriptContext()->Global()); |
| 2389 DCHECK(!try_catch.HasException()); |
| 2390 return result.Release(); |
| 2369 } | 2391 } |
| 2370 | 2392 |
| 2371 PP_Var PepperPluginInstanceImpl::GetOwnerElementObject(PP_Instance instance) { | 2393 PP_Var PepperPluginInstanceImpl::GetOwnerElementObject(PP_Instance instance) { |
| 2372 if (!container_) | 2394 if (!container_) |
| 2373 return PP_MakeUndefined(); | 2395 return PP_MakeUndefined(); |
| 2374 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(); |
| 2375 } | 2400 } |
| 2376 | 2401 |
| 2377 PP_Var PepperPluginInstanceImpl::ExecuteScript(PP_Instance instance, | 2402 PP_Var PepperPluginInstanceImpl::ExecuteScript(PP_Instance instance, |
| 2378 PP_Var script, | 2403 PP_Var script_var, |
| 2379 PP_Var* exception) { | 2404 PP_Var* exception) { |
| 2405 if (!container_) |
| 2406 return PP_MakeUndefined(); |
| 2407 |
| 2380 // 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 |
| 2381 // 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 |
| 2382 // WebBindings::evaluate() below. | 2410 // WebBindings::evaluate() below. |
| 2383 scoped_refptr<PepperPluginInstanceImpl> ref(this); | 2411 scoped_refptr<PepperPluginInstanceImpl> ref(this); |
| 2384 TryCatch try_catch(exception); | 2412 PepperTryCatchVar try_catch(this, exception); |
| 2385 if (try_catch.has_exception()) | 2413 WebLocalFrame* frame = container_->element().document().frame(); |
| 2414 if (!frame) { |
| 2415 try_catch.SetException("No frame to execute script in."); |
| 2386 return PP_MakeUndefined(); | 2416 return PP_MakeUndefined(); |
| 2417 } |
| 2387 | 2418 |
| 2388 // Convert the script into an inconvenient NPString object. | 2419 StringVar* script_string_var = StringVar::FromPPVar(script_var); |
| 2389 StringVar* script_string = StringVar::FromPPVar(script); | 2420 if (!script_string_var) { |
| 2390 if (!script_string) { | |
| 2391 try_catch.SetException("Script param to ExecuteScript must be a string."); | 2421 try_catch.SetException("Script param to ExecuteScript must be a string."); |
| 2392 return PP_MakeUndefined(); | 2422 return PP_MakeUndefined(); |
| 2393 } | 2423 } |
| 2394 NPString np_script; | |
| 2395 np_script.UTF8Characters = script_string->value().c_str(); | |
| 2396 np_script.UTF8Length = script_string->value().length(); | |
| 2397 | 2424 |
| 2398 // Get the current frame to pass to the evaluate function. | 2425 std::string script_string = script_string_var->value(); |
| 2399 WebLocalFrame* frame = NULL; | 2426 blink::WebScriptSource script( |
| 2400 if (container_) | 2427 blink::WebString::fromUTF8(script_string.c_str())); |
| 2401 frame = container_->element().document().frame(); | 2428 v8::Handle<v8::Value> result; |
| 2402 if (!frame || !frame->windowObject()) { | 2429 if (IsProcessingUserGesture()) { |
| 2403 try_catch.SetException("No context in which to execute script."); | 2430 blink::WebScopedUserGesture user_gesture(CurrentUserGestureToken()); |
| 2404 return PP_MakeUndefined(); | 2431 result = frame->executeScriptAndReturnValue(script); |
| 2432 } else { |
| 2433 result = frame->executeScriptAndReturnValue(script); |
| 2405 } | 2434 } |
| 2406 | 2435 |
| 2407 NPVariant result; | 2436 ScopedPPVar var_result = try_catch.FromV8(result); |
| 2408 bool ok = false; | 2437 if (try_catch.HasException()) |
| 2409 if (IsProcessingUserGesture()) { | |
| 2410 blink::WebScopedUserGesture user_gesture(CurrentUserGestureToken()); | |
| 2411 ok = | |
| 2412 WebBindings::evaluate(NULL, frame->windowObject(), &np_script, &result); | |
| 2413 } else { | |
| 2414 ok = | |
| 2415 WebBindings::evaluate(NULL, frame->windowObject(), &np_script, &result); | |
| 2416 } | |
| 2417 if (!ok) { | |
| 2418 // TryCatch doesn't catch the exceptions properly. Since this is only for | |
| 2419 // a trusted API, just set to a general exception message. | |
| 2420 try_catch.SetException("Exception caught"); | |
| 2421 WebBindings::releaseVariantValue(&result); | |
| 2422 return PP_MakeUndefined(); | 2438 return PP_MakeUndefined(); |
| 2423 } | |
| 2424 | 2439 |
| 2425 PP_Var ret = NPVariantToPPVar(this, &result); | 2440 return var_result.Release(); |
| 2426 WebBindings::releaseVariantValue(&result); | |
| 2427 return ret; | |
| 2428 } | 2441 } |
| 2429 | 2442 |
| 2430 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputSampleRate( | 2443 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputSampleRate( |
| 2431 PP_Instance instance) { | 2444 PP_Instance instance) { |
| 2432 RenderThreadImpl* thread = RenderThreadImpl::current(); | 2445 RenderThreadImpl* thread = RenderThreadImpl::current(); |
| 2433 return thread->GetAudioHardwareConfig()->GetOutputSampleRate(); | 2446 return thread->GetAudioHardwareConfig()->GetOutputSampleRate(); |
| 2434 } | 2447 } |
| 2435 | 2448 |
| 2436 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputBufferSize( | 2449 uint32_t PepperPluginInstanceImpl::GetAudioHardwareOutputBufferSize( |
| 2437 PP_Instance instance) { | 2450 PP_Instance instance) { |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2946 plugin_selection_interface_ = NULL; | 2959 plugin_selection_interface_ = NULL; |
| 2947 plugin_textinput_interface_ = NULL; | 2960 plugin_textinput_interface_ = NULL; |
| 2948 plugin_zoom_interface_ = NULL; | 2961 plugin_zoom_interface_ = NULL; |
| 2949 | 2962 |
| 2950 // Re-send the DidCreate event via the proxy. | 2963 // Re-send the DidCreate event via the proxy. |
| 2951 scoped_ptr<const char * []> argn_array(StringVectorToArgArray(argn_)); | 2964 scoped_ptr<const char * []> argn_array(StringVectorToArgArray(argn_)); |
| 2952 scoped_ptr<const char * []> argv_array(StringVectorToArgArray(argv_)); | 2965 scoped_ptr<const char * []> argv_array(StringVectorToArgArray(argv_)); |
| 2953 if (!instance_interface_->DidCreate( | 2966 if (!instance_interface_->DidCreate( |
| 2954 pp_instance(), argn_.size(), argn_array.get(), argv_array.get())) | 2967 pp_instance(), argn_.size(), argn_array.get(), argv_array.get())) |
| 2955 return PP_EXTERNAL_PLUGIN_ERROR_INSTANCE; | 2968 return PP_EXTERNAL_PLUGIN_ERROR_INSTANCE; |
| 2956 message_channel_->Start(); | 2969 GetMessageChannel()->Start(); |
| 2957 | 2970 |
| 2958 // Clear sent_initial_did_change_view_ and cancel any pending DidChangeView | 2971 // Clear sent_initial_did_change_view_ and cancel any pending DidChangeView |
| 2959 // event. This way, SendDidChangeView will send the "current" view | 2972 // event. This way, SendDidChangeView will send the "current" view |
| 2960 // immediately (before other events like HandleDocumentLoad). | 2973 // immediately (before other events like HandleDocumentLoad). |
| 2961 sent_initial_did_change_view_ = false; | 2974 sent_initial_did_change_view_ = false; |
| 2962 view_change_weak_ptr_factory_.InvalidateWeakPtrs(); | 2975 view_change_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 2963 SendDidChangeView(); | 2976 SendDidChangeView(); |
| 2964 | 2977 |
| 2965 DCHECK(external_document_load_); | 2978 DCHECK(external_document_load_); |
| 2966 external_document_load_ = false; | 2979 external_document_load_ = false; |
| 2967 if (!external_document_response_.isNull()) { | 2980 if (!external_document_response_.isNull()) { |
| 2968 document_loader_ = NULL; | 2981 document_loader_ = NULL; |
| 2969 // Pass the response to the new proxy. | 2982 // Pass the response to the new proxy. |
| 2970 HandleDocumentLoad(external_document_response_); | 2983 HandleDocumentLoad(external_document_response_); |
| 2971 external_document_response_ = blink::WebURLResponse(); | 2984 external_document_response_ = blink::WebURLResponse(); |
| 2972 // Replay any document load events we've received to the real loader. | 2985 // Replay any document load events we've received to the real loader. |
| 2973 external_document_loader_->ReplayReceivedData(document_loader_); | 2986 external_document_loader_->ReplayReceivedData(document_loader_); |
| 2974 external_document_loader_.reset(NULL); | 2987 external_document_loader_.reset(NULL); |
| 2975 } | 2988 } |
| 2976 | 2989 |
| 2977 return PP_EXTERNAL_PLUGIN_OK; | 2990 return PP_EXTERNAL_PLUGIN_OK; |
| 2978 } | 2991 } |
| 2979 | 2992 |
| 2980 bool PepperPluginInstanceImpl::IsValidInstanceOf(PluginModule* module) { | 2993 bool PepperPluginInstanceImpl::IsValidInstanceOf(PluginModule* module) { |
| 2981 DCHECK(module); | 2994 DCHECK(module); |
| 2982 return module == module_.get() || module == original_module_.get(); | 2995 return module == module_.get() || module == original_module_.get(); |
| 2983 } | 2996 } |
| 2984 | 2997 |
| 2985 NPP PepperPluginInstanceImpl::instanceNPP() { return npp_.get(); } | |
| 2986 | |
| 2987 PepperPluginInstance* PepperPluginInstance::Get(PP_Instance instance_id) { | 2998 PepperPluginInstance* PepperPluginInstance::Get(PP_Instance instance_id) { |
| 2988 return HostGlobals::Get()->GetInstance(instance_id); | 2999 return HostGlobals::Get()->GetInstance(instance_id); |
| 2989 } | 3000 } |
| 2990 | 3001 |
| 2991 RenderView* PepperPluginInstanceImpl::GetRenderView() { | 3002 RenderView* PepperPluginInstanceImpl::GetRenderView() { |
| 2992 return render_frame_ ? render_frame_->render_view() : NULL; | 3003 return render_frame_ ? render_frame_->render_view() : NULL; |
| 2993 } | 3004 } |
| 2994 | 3005 |
| 2995 blink::WebPluginContainer* PepperPluginInstanceImpl::GetContainer() { | 3006 blink::WebPluginContainer* PepperPluginInstanceImpl::GetContainer() { |
| 2996 return container_; | 3007 return container_; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3183 int PepperPluginInstanceImpl::MakePendingFileRefRendererHost( | 3194 int PepperPluginInstanceImpl::MakePendingFileRefRendererHost( |
| 3184 const base::FilePath& path) { | 3195 const base::FilePath& path) { |
| 3185 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); | 3196 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); |
| 3186 PepperFileRefRendererHost* file_ref_host( | 3197 PepperFileRefRendererHost* file_ref_host( |
| 3187 new PepperFileRefRendererHost(host_impl, pp_instance(), 0, path)); | 3198 new PepperFileRefRendererHost(host_impl, pp_instance(), 0, path)); |
| 3188 return host_impl->GetPpapiHost()->AddPendingResourceHost( | 3199 return host_impl->GetPpapiHost()->AddPendingResourceHost( |
| 3189 scoped_ptr<ppapi::host::ResourceHost>(file_ref_host)); | 3200 scoped_ptr<ppapi::host::ResourceHost>(file_ref_host)); |
| 3190 } | 3201 } |
| 3191 | 3202 |
| 3192 void PepperPluginInstanceImpl::SetEmbedProperty(PP_Var key, PP_Var value) { | 3203 void PepperPluginInstanceImpl::SetEmbedProperty(PP_Var key, PP_Var value) { |
| 3193 message_channel_->SetReadOnlyProperty(key, value); | 3204 GetMessageChannel()->SetReadOnlyProperty(key, value); |
| 3194 } | 3205 } |
| 3195 | 3206 |
| 3196 bool PepperPluginInstanceImpl::CanAccessMainFrame() const { | 3207 bool PepperPluginInstanceImpl::CanAccessMainFrame() const { |
| 3197 if (!container_) | 3208 if (!container_) |
| 3198 return false; | 3209 return false; |
| 3199 blink::WebDocument containing_document = container_->element().document(); | 3210 blink::WebDocument containing_document = container_->element().document(); |
| 3200 | 3211 |
| 3201 if (!containing_document.frame() || !containing_document.frame()->view() || | 3212 if (!containing_document.frame() || !containing_document.frame()->view() || |
| 3202 !containing_document.frame()->view()->mainFrame()) { | 3213 !containing_document.frame()->view()->mainFrame()) { |
| 3203 return false; | 3214 return false; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3320 // Running out-of-process. Initiate an IPC call to notify the plugin | 3331 // Running out-of-process. Initiate an IPC call to notify the plugin |
| 3321 // process. | 3332 // process. |
| 3322 ppapi::proxy::HostDispatcher* dispatcher = | 3333 ppapi::proxy::HostDispatcher* dispatcher = |
| 3323 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); | 3334 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); |
| 3324 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( | 3335 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( |
| 3325 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); | 3336 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); |
| 3326 } | 3337 } |
| 3327 } | 3338 } |
| 3328 | 3339 |
| 3329 } // namespace content | 3340 } // namespace content |
| OLD | NEW |