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

Side by Side Diff: content/renderer/pepper/pepper_plugin_instance_impl.cc

Issue 290553004: PPAPI: Refactor MessageChannel to prep for sync postMessae (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: a little more cleanup Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 #include "ppapi/proxy/url_loader_resource.h" 73 #include "ppapi/proxy/url_loader_resource.h"
74 #include "ppapi/shared_impl/ppapi_permissions.h" 74 #include "ppapi/shared_impl/ppapi_permissions.h"
75 #include "ppapi/shared_impl/ppapi_preferences.h" 75 #include "ppapi/shared_impl/ppapi_preferences.h"
76 #include "ppapi/shared_impl/ppb_gamepad_shared.h" 76 #include "ppapi/shared_impl/ppb_gamepad_shared.h"
77 #include "ppapi/shared_impl/ppb_input_event_shared.h" 77 #include "ppapi/shared_impl/ppb_input_event_shared.h"
78 #include "ppapi/shared_impl/ppb_url_util_shared.h" 78 #include "ppapi/shared_impl/ppb_url_util_shared.h"
79 #include "ppapi/shared_impl/ppb_view_shared.h" 79 #include "ppapi/shared_impl/ppb_view_shared.h"
80 #include "ppapi/shared_impl/ppp_instance_combined.h" 80 #include "ppapi/shared_impl/ppp_instance_combined.h"
81 #include "ppapi/shared_impl/resource.h" 81 #include "ppapi/shared_impl/resource.h"
82 #include "ppapi/shared_impl/scoped_pp_resource.h" 82 #include "ppapi/shared_impl/scoped_pp_resource.h"
83 #include "ppapi/shared_impl/scoped_pp_var.h"
83 #include "ppapi/shared_impl/time_conversion.h" 84 #include "ppapi/shared_impl/time_conversion.h"
84 #include "ppapi/shared_impl/url_request_info_data.h" 85 #include "ppapi/shared_impl/url_request_info_data.h"
85 #include "ppapi/shared_impl/var.h" 86 #include "ppapi/shared_impl/var.h"
86 #include "ppapi/thunk/enter.h" 87 #include "ppapi/thunk/enter.h"
87 #include "ppapi/thunk/ppb_buffer_api.h" 88 #include "ppapi/thunk/ppb_buffer_api.h"
88 #include "printing/metafile.h" 89 #include "printing/metafile.h"
89 #include "printing/metafile_skia_wrapper.h" 90 #include "printing/metafile_skia_wrapper.h"
90 #include "printing/units.h" 91 #include "printing/units.h"
91 #include "skia/ext/platform_canvas.h" 92 #include "skia/ext/platform_canvas.h"
92 #include "skia/ext/platform_device.h" 93 #include "skia/ext/platform_device.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 #endif 140 #endif
140 141
141 using base::StringPrintf; 142 using base::StringPrintf;
142 using ppapi::InputEventData; 143 using ppapi::InputEventData;
143 using ppapi::PpapiGlobals; 144 using ppapi::PpapiGlobals;
144 using ppapi::PPB_InputEvent_Shared; 145 using ppapi::PPB_InputEvent_Shared;
145 using ppapi::PPB_View_Shared; 146 using ppapi::PPB_View_Shared;
146 using ppapi::PPP_Instance_Combined; 147 using ppapi::PPP_Instance_Combined;
147 using ppapi::Resource; 148 using ppapi::Resource;
148 using ppapi::ScopedPPResource; 149 using ppapi::ScopedPPResource;
150 using ppapi::ScopedPPVar;
149 using ppapi::StringVar; 151 using ppapi::StringVar;
150 using ppapi::TrackedCallback; 152 using ppapi::TrackedCallback;
151 using ppapi::thunk::EnterResourceNoLock; 153 using ppapi::thunk::EnterResourceNoLock;
152 using ppapi::thunk::PPB_Buffer_API; 154 using ppapi::thunk::PPB_Buffer_API;
153 using ppapi::thunk::PPB_Gamepad_API; 155 using ppapi::thunk::PPB_Gamepad_API;
154 using ppapi::thunk::PPB_Graphics2D_API; 156 using ppapi::thunk::PPB_Graphics2D_API;
155 using ppapi::thunk::PPB_Graphics3D_API; 157 using ppapi::thunk::PPB_Graphics3D_API;
156 using ppapi::thunk::PPB_ImageData_API; 158 using ppapi::thunk::PPB_ImageData_API;
157 using ppapi::Var; 159 using ppapi::Var;
158 using ppapi::ArrayBufferVar; 160 using ppapi::ArrayBufferVar;
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 ppapi::Preferences(render_frame_->render_view()->webkit_preferences()), 817 ppapi::Preferences(render_frame_->render_view()->webkit_preferences()),
816 arg_names, 818 arg_names,
817 arg_values); 819 arg_values);
818 820
819 argn_ = arg_names; 821 argn_ = arg_names;
820 argv_ = arg_values; 822 argv_ = arg_values;
821 scoped_ptr<const char * []> argn_array(StringVectorToArgArray(argn_)); 823 scoped_ptr<const char * []> argn_array(StringVectorToArgArray(argn_));
822 scoped_ptr<const char * []> argv_array(StringVectorToArgArray(argv_)); 824 scoped_ptr<const char * []> argv_array(StringVectorToArgArray(argv_));
823 bool success = PP_ToBool(instance_interface_->DidCreate( 825 bool success = PP_ToBool(instance_interface_->DidCreate(
824 pp_instance(), argn_.size(), argn_array.get(), argv_array.get())); 826 pp_instance(), argn_.size(), argn_array.get(), argv_array.get()));
825 if (success) 827 // We don't support Messaging in-process. For in-process, MessageChannel will
826 message_channel_->StopQueueingJavaScriptMessages(); 828 // continue queueing messages. If later the instance is ResetAsProxied, the
829 // MessageChannel will be Start()ed at that time.
830 if (success && module()->IsProxied())
831 message_channel_->Start();
827 return success; 832 return success;
828 } 833 }
829 834
830 bool PepperPluginInstanceImpl::HandleDocumentLoad( 835 bool PepperPluginInstanceImpl::HandleDocumentLoad(
831 const blink::WebURLResponse& response) { 836 const blink::WebURLResponse& response) {
832 DCHECK(!document_loader_); 837 DCHECK(!document_loader_);
833 if (external_document_load_) { 838 if (external_document_load_) {
834 // The external proxy isn't available, so save the response and record 839 // The external proxy isn't available, so save the response and record
835 // document load notifications for later replay. 840 // document load notifications for later replay.
836 external_document_response_ = response; 841 external_document_response_ = response;
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 pp_instance(), event_resource->pp_resource())); 1110 pp_instance(), event_resource->pp_resource()));
1106 } 1111 }
1107 } 1112 }
1108 } 1113 }
1109 1114
1110 if (cursor_) 1115 if (cursor_)
1111 *cursor_info = *cursor_; 1116 *cursor_info = *cursor_;
1112 return rv; 1117 return rv;
1113 } 1118 }
1114 1119
1115 void PepperPluginInstanceImpl::HandleMessage(PP_Var message) { 1120 void PepperPluginInstanceImpl::HandleMessage(ScopedPPVar message) {
1116 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleMessage"); 1121 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleMessage");
1117 ppapi::proxy::HostDispatcher* dispatcher = 1122 ppapi::proxy::HostDispatcher* dispatcher =
1118 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); 1123 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance());
1119 if (!dispatcher || (message.type == PP_VARTYPE_OBJECT)) { 1124 if (!dispatcher || (message.get().type == PP_VARTYPE_OBJECT)) {
1120 // The dispatcher should always be valid, and the browser should never send 1125 // The dispatcher should always be valid, and the browser should never send
1121 // an 'object' var over PPP_Messaging. 1126 // an 'object' var over PPP_Messaging.
1122 NOTREACHED(); 1127 NOTREACHED();
1123 return; 1128 return;
1124 } 1129 }
1125 dispatcher->Send(new PpapiMsg_PPPMessaging_HandleMessage( 1130 dispatcher->Send(new PpapiMsg_PPPMessaging_HandleMessage(
1126 ppapi::API_ID_PPP_MESSAGING, 1131 ppapi::API_ID_PPP_MESSAGING,
1127 pp_instance(), 1132 pp_instance(),
1128 ppapi::proxy::SerializedVarSendInputShmem(dispatcher, message, 1133 ppapi::proxy::SerializedVarSendInputShmem(dispatcher, message.get(),
1129 pp_instance()))); 1134 pp_instance())));
1130 } 1135 }
1131 1136
1132 PP_Var PepperPluginInstanceImpl::GetInstanceObject() { 1137 PP_Var PepperPluginInstanceImpl::GetInstanceObject() {
1133 // Keep a reference on the stack. See NOTE above. 1138 // Keep a reference on the stack. See NOTE above.
1134 scoped_refptr<PepperPluginInstanceImpl> ref(this); 1139 scoped_refptr<PepperPluginInstanceImpl> ref(this);
1135 1140
1136 // If the plugin supports the private instance interface, try to retrieve its 1141 // If the plugin supports the private instance interface, try to retrieve its
1137 // instance object. 1142 // instance object.
1138 if (LoadPrivateInterface()) 1143 if (LoadPrivateInterface())
(...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after
2729 components); 2734 components);
2730 } 2735 }
2731 2736
2732 PP_ExternalPluginResult PepperPluginInstanceImpl::ResetAsProxied( 2737 PP_ExternalPluginResult PepperPluginInstanceImpl::ResetAsProxied(
2733 scoped_refptr<PluginModule> module) { 2738 scoped_refptr<PluginModule> module) {
2734 // Save the original module and switch over to the new one now that this 2739 // Save the original module and switch over to the new one now that this
2735 // plugin is using the IPC-based proxy. 2740 // plugin is using the IPC-based proxy.
2736 original_module_ = module_; 2741 original_module_ = module_;
2737 module_ = module; 2742 module_ = module;
2738 2743
2739 // Don't send any messages to the plugin until DidCreate() has finished.
2740 message_channel_->QueueJavaScriptMessages();
2741
2742 // For NaCl instances, remember the NaCl plugin instance interface, so we 2744 // For NaCl instances, remember the NaCl plugin instance interface, so we
2743 // can shut it down by calling its DidDestroy in our Delete() method. 2745 // can shut it down by calling its DidDestroy in our Delete() method.
2744 original_instance_interface_.reset(instance_interface_.release()); 2746 original_instance_interface_.reset(instance_interface_.release());
2745 2747
2746 base::Callback<const void*(const char*)> get_plugin_interface_func = 2748 base::Callback<const void*(const char*)> get_plugin_interface_func =
2747 base::Bind(&PluginModule::GetPluginInterface, module_.get()); 2749 base::Bind(&PluginModule::GetPluginInterface, module_.get());
2748 PPP_Instance_Combined* ppp_instance_combined = 2750 PPP_Instance_Combined* ppp_instance_combined =
2749 PPP_Instance_Combined::Create(get_plugin_interface_func); 2751 PPP_Instance_Combined::Create(get_plugin_interface_func);
2750 if (!ppp_instance_combined) { 2752 if (!ppp_instance_combined) {
2751 // The proxy must support at least one usable PPP_Instance interface. 2753 // The proxy must support at least one usable PPP_Instance interface.
(...skipping 15 matching lines...) Expand all
2767 plugin_selection_interface_ = NULL; 2769 plugin_selection_interface_ = NULL;
2768 plugin_textinput_interface_ = NULL; 2770 plugin_textinput_interface_ = NULL;
2769 plugin_zoom_interface_ = NULL; 2771 plugin_zoom_interface_ = NULL;
2770 2772
2771 // Re-send the DidCreate event via the proxy. 2773 // Re-send the DidCreate event via the proxy.
2772 scoped_ptr<const char * []> argn_array(StringVectorToArgArray(argn_)); 2774 scoped_ptr<const char * []> argn_array(StringVectorToArgArray(argn_));
2773 scoped_ptr<const char * []> argv_array(StringVectorToArgArray(argv_)); 2775 scoped_ptr<const char * []> argv_array(StringVectorToArgArray(argv_));
2774 if (!instance_interface_->DidCreate( 2776 if (!instance_interface_->DidCreate(
2775 pp_instance(), argn_.size(), argn_array.get(), argv_array.get())) 2777 pp_instance(), argn_.size(), argn_array.get(), argv_array.get()))
2776 return PP_EXTERNAL_PLUGIN_ERROR_INSTANCE; 2778 return PP_EXTERNAL_PLUGIN_ERROR_INSTANCE;
2777 message_channel_->StopQueueingJavaScriptMessages(); 2779 message_channel_->Start();
2778 2780
2779 // Clear sent_initial_did_change_view_ and cancel any pending DidChangeView 2781 // Clear sent_initial_did_change_view_ and cancel any pending DidChangeView
2780 // event. This way, SendDidChangeView will send the "current" view 2782 // event. This way, SendDidChangeView will send the "current" view
2781 // immediately (before other events like HandleDocumentLoad). 2783 // immediately (before other events like HandleDocumentLoad).
2782 sent_initial_did_change_view_ = false; 2784 sent_initial_did_change_view_ = false;
2783 view_change_weak_ptr_factory_.InvalidateWeakPtrs(); 2785 view_change_weak_ptr_factory_.InvalidateWeakPtrs();
2784 SendDidChangeView(); 2786 SendDidChangeView();
2785 2787
2786 DCHECK(external_document_load_); 2788 DCHECK(external_document_load_);
2787 external_document_load_ = false; 2789 external_document_load_ = false;
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
3138 // Running out-of-process. Initiate an IPC call to notify the plugin 3140 // Running out-of-process. Initiate an IPC call to notify the plugin
3139 // process. 3141 // process.
3140 ppapi::proxy::HostDispatcher* dispatcher = 3142 ppapi::proxy::HostDispatcher* dispatcher =
3141 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); 3143 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance());
3142 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( 3144 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad(
3143 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); 3145 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data));
3144 } 3146 }
3145 } 3147 }
3146 3148
3147 } // namespace content 3149 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698