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

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

Issue 10544089: Implement the file chooser as a new resource "host" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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_delegate_impl.h" 5 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <cstddef> 8 #include <cstddef>
9 #include <map> 9 #include <map>
10 #include <queue> 10 #include <queue>
(...skipping 23 matching lines...) Expand all
34 #include "content/public/common/referrer.h" 34 #include "content/public/common/referrer.h"
35 #include "content/public/renderer/content_renderer_client.h" 35 #include "content/public/renderer/content_renderer_client.h"
36 #include "content/renderer/browser_plugin/old/browser_plugin_constants.h" 36 #include "content/renderer/browser_plugin/old/browser_plugin_constants.h"
37 #include "content/renderer/browser_plugin/old/browser_plugin_registry.h" 37 #include "content/renderer/browser_plugin/old/browser_plugin_registry.h"
38 #include "content/renderer/gamepad_shared_memory_reader.h" 38 #include "content/renderer/gamepad_shared_memory_reader.h"
39 #include "content/renderer/media/audio_hardware.h" 39 #include "content/renderer/media/audio_hardware.h"
40 #include "content/renderer/media/media_stream_dispatcher.h" 40 #include "content/renderer/media/media_stream_dispatcher.h"
41 #include "content/renderer/media/pepper_platform_video_decoder_impl.h" 41 #include "content/renderer/media/pepper_platform_video_decoder_impl.h"
42 #include "content/renderer/p2p/p2p_transport_impl.h" 42 #include "content/renderer/p2p/p2p_transport_impl.h"
43 #include "content/renderer/p2p/socket_dispatcher.h" 43 #include "content/renderer/p2p/socket_dispatcher.h"
44 #include "content/renderer/pepper/content_instance_glue_impl.h"
45 #include "content/renderer/pepper/content_renderer_pepper_host_factory.h"
44 #include "content/renderer/pepper/pepper_broker_impl.h" 46 #include "content/renderer/pepper/pepper_broker_impl.h"
45 #include "content/renderer/pepper/pepper_device_enumeration_event_handler.h" 47 #include "content/renderer/pepper/pepper_device_enumeration_event_handler.h"
46 #include "content/renderer/pepper/pepper_hung_plugin_filter.h" 48 #include "content/renderer/pepper/pepper_hung_plugin_filter.h"
47 #include "content/renderer/pepper/pepper_in_process_resource_creation.h" 49 #include "content/renderer/pepper/pepper_in_process_resource_creation.h"
48 #include "content/renderer/pepper/pepper_platform_audio_input_impl.h" 50 #include "content/renderer/pepper/pepper_platform_audio_input_impl.h"
49 #include "content/renderer/pepper/pepper_platform_audio_output_impl.h" 51 #include "content/renderer/pepper/pepper_platform_audio_output_impl.h"
50 #include "content/renderer/pepper/pepper_platform_context_3d_impl.h" 52 #include "content/renderer/pepper/pepper_platform_context_3d_impl.h"
51 #include "content/renderer/pepper/pepper_platform_image_2d_impl.h" 53 #include "content/renderer/pepper/pepper_platform_image_2d_impl.h"
52 #include "content/renderer/pepper/pepper_platform_video_capture_impl.h" 54 #include "content/renderer/pepper/pepper_platform_video_capture_impl.h"
53 #include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h" 55 #include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h"
54 #include "content/renderer/render_thread_impl.h" 56 #include "content/renderer/render_thread_impl.h"
55 #include "content/renderer/render_view_impl.h" 57 #include "content/renderer/render_view_impl.h"
56 #include "content/renderer/render_widget_fullscreen_pepper.h" 58 #include "content/renderer/render_widget_fullscreen_pepper.h"
57 #include "content/renderer/renderer_clipboard_client.h" 59 #include "content/renderer/renderer_clipboard_client.h"
58 #include "content/renderer/renderer_restrict_dispatch_group.h" 60 #include "content/renderer/renderer_restrict_dispatch_group.h"
59 #include "content/renderer/webplugin_delegate_proxy.h" 61 #include "content/renderer/webplugin_delegate_proxy.h"
60 #include "googleurl/src/gurl.h" 62 #include "googleurl/src/gurl.h"
61 #include "ipc/ipc_channel_handle.h" 63 #include "ipc/ipc_channel_handle.h"
62 #include "media/video/capture/video_capture_proxy.h" 64 #include "media/video/capture/video_capture_proxy.h"
63 #include "ppapi/c/dev/pp_video_dev.h" 65 #include "ppapi/c/dev/pp_video_dev.h"
64 #include "ppapi/c/pp_errors.h" 66 #include "ppapi/c/pp_errors.h"
65 #include "ppapi/c/private/ppb_flash.h" 67 #include "ppapi/c/private/ppb_flash.h"
68 #include "ppapi/host/ppapi_host.h"
66 #include "ppapi/proxy/host_dispatcher.h" 69 #include "ppapi/proxy/host_dispatcher.h"
67 #include "ppapi/proxy/pepper_file_messages.h" 70 #include "ppapi/proxy/pepper_file_messages.h"
68 #include "ppapi/proxy/ppapi_messages.h" 71 #include "ppapi/proxy/ppapi_messages.h"
69 #include "ppapi/shared_impl/file_path.h" 72 #include "ppapi/shared_impl/file_path.h"
70 #include "ppapi/shared_impl/platform_file.h" 73 #include "ppapi/shared_impl/platform_file.h"
71 #include "ppapi/shared_impl/ppapi_permissions.h" 74 #include "ppapi/shared_impl/ppapi_permissions.h"
72 #include "ppapi/shared_impl/ppapi_preferences.h" 75 #include "ppapi/shared_impl/ppapi_preferences.h"
73 #include "ppapi/shared_impl/ppb_device_ref_shared.h" 76 #include "ppapi/shared_impl/ppb_device_ref_shared.h"
74 #include "ppapi/thunk/enter.h" 77 #include "ppapi/thunk/enter.h"
75 #include "ppapi/thunk/ppb_tcp_server_socket_private_api.h" 78 #include "ppapi/thunk/ppb_tcp_server_socket_private_api.h"
76 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" 79 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
77 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 80 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
78 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserComplet ion.h"
79 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams. h"
80 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 81 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
81 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 82 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
82 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 83 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
83 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" 84 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
84 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 85 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
85 #include "ui/gfx/size.h" 86 #include "ui/gfx/size.h"
86 #include "webkit/fileapi/file_system_callback_dispatcher.h" 87 #include "webkit/fileapi/file_system_callback_dispatcher.h"
87 #include "webkit/plugins/npapi/webplugin.h" 88 #include "webkit/plugins/npapi/webplugin.h"
88 #include "webkit/plugins/ppapi/ppb_file_io_impl.h" 89 #include "webkit/plugins/ppapi/ppb_file_io_impl.h"
89 #include "webkit/plugins/ppapi/plugin_module.h" 90 #include "webkit/plugins/ppapi/plugin_module.h"
90 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 91 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
91 #include "webkit/plugins/ppapi/ppb_flash_impl.h" 92 #include "webkit/plugins/ppapi/ppb_flash_impl.h"
92 #include "webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.h" 93 #include "webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.h"
93 #include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h" 94 #include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h"
94 #include "webkit/plugins/ppapi/ppb_udp_socket_private_impl.h" 95 #include "webkit/plugins/ppapi/ppb_udp_socket_private_impl.h"
95 #include "webkit/plugins/ppapi/resource_helper.h" 96 #include "webkit/plugins/ppapi/resource_helper.h"
96 #include "webkit/plugins/webplugininfo.h" 97 #include "webkit/plugins/webplugininfo.h"
97 98
98 using WebKit::WebView; 99 using WebKit::WebView;
99 using WebKit::WebFrame; 100 using WebKit::WebFrame;
100 101
101 namespace content { 102 namespace content {
102 103
103 namespace { 104 namespace {
104 105
105 class HostDispatcherWrapper 106 class HostDispatcherWrapper
106 : public webkit::ppapi::PluginDelegate::OutOfProcessProxy { 107 : public webkit::ppapi::PluginDelegate::OutOfProcessProxy {
107 public: 108 public:
108 HostDispatcherWrapper() {} 109 HostDispatcherWrapper(RenderViewImpl* rv,
110 webkit::ppapi::PluginModule* module,
111 const ppapi::PpapiPermissions& perms)
112 : render_view_(rv),
113 module_(module),
114 instance_glue_(module),
115 host_factory_(rv, perms, &instance_glue_) {
116 }
109 virtual ~HostDispatcherWrapper() {} 117 virtual ~HostDispatcherWrapper() {}
110 118
111 bool Init(const IPC::ChannelHandle& channel_handle, 119 bool Init(const IPC::ChannelHandle& channel_handle,
112 PP_Module pp_module,
113 PP_GetInterface_Func local_get_interface, 120 PP_GetInterface_Func local_get_interface,
114 const ppapi::Preferences& preferences, 121 const ppapi::Preferences& preferences,
122 const ppapi::PpapiPermissions& permissions,
115 PepperHungPluginFilter* filter) { 123 PepperHungPluginFilter* filter) {
116 if (channel_handle.name.empty()) 124 if (channel_handle.name.empty())
117 return false; 125 return false;
118 126
119 #if defined(OS_POSIX) 127 #if defined(OS_POSIX)
120 DCHECK_NE(-1, channel_handle.socket.fd); 128 DCHECK_NE(-1, channel_handle.socket.fd);
121 if (channel_handle.socket.fd == -1) 129 if (channel_handle.socket.fd == -1)
122 return false; 130 return false;
123 #endif 131 #endif
124 132
125 dispatcher_delegate_.reset(new PepperProxyChannelDelegateImpl); 133 dispatcher_delegate_.reset(new PepperProxyChannelDelegateImpl);
126 dispatcher_.reset(new ppapi::proxy::HostDispatcher( 134 dispatcher_.reset(new ppapi::proxy::HostDispatcher(
127 pp_module, local_get_interface, filter)); 135 module_->pp_module(), local_get_interface, filter));
136
137 host_.reset(new ppapi::host::PpapiHost(dispatcher_.get(), &host_factory_,
138 permissions));
139 dispatcher_->AddFilter(host_.get());
128 140
129 if (!dispatcher_->InitHostWithChannel(dispatcher_delegate_.get(), 141 if (!dispatcher_->InitHostWithChannel(dispatcher_delegate_.get(),
130 channel_handle, 142 channel_handle,
131 true, // Client. 143 true, // Client.
132 preferences)) { 144 preferences)) {
133 dispatcher_.reset(); 145 dispatcher_.reset();
134 dispatcher_delegate_.reset(); 146 dispatcher_delegate_.reset();
135 return false; 147 return false;
136 } 148 }
137 dispatcher_->channel()->SetRestrictDispatchChannelGroup( 149 dispatcher_->channel()->SetRestrictDispatchChannelGroup(
138 content::kRendererRestrictDispatchGroup_Pepper); 150 content::kRendererRestrictDispatchGroup_Pepper);
139 return true; 151 return true;
140 } 152 }
141 153
142 // OutOfProcessProxy implementation. 154 // OutOfProcessProxy implementation.
143 virtual const void* GetProxiedInterface(const char* name) { 155 virtual const void* GetProxiedInterface(const char* name) {
144 return dispatcher_->GetProxiedInterface(name); 156 return dispatcher_->GetProxiedInterface(name);
145 } 157 }
146 virtual void AddInstance(PP_Instance instance) { 158 virtual void AddInstance(PP_Instance instance) {
147 ppapi::proxy::HostDispatcher::SetForInstance(instance, dispatcher_.get()); 159 ppapi::proxy::HostDispatcher::SetForInstance(instance, dispatcher_.get());
148 } 160 }
149 virtual void RemoveInstance(PP_Instance instance) { 161 virtual void RemoveInstance(PP_Instance instance) {
150 ppapi::proxy::HostDispatcher::RemoveForInstance(instance); 162 ppapi::proxy::HostDispatcher::RemoveForInstance(instance);
151 } 163 }
152 164
153 private: 165 private:
166 RenderViewImpl* render_view_;
167 webkit::ppapi::PluginModule* module_;
168 ContentInstanceGlueImpl instance_glue_;
169 ContentRendererPepperHostFactory host_factory_;
170
171 scoped_ptr<ppapi::host::PpapiHost> host_;
172
154 scoped_ptr<ppapi::proxy::HostDispatcher> dispatcher_; 173 scoped_ptr<ppapi::proxy::HostDispatcher> dispatcher_;
155 scoped_ptr<ppapi::proxy::ProxyChannel::Delegate> dispatcher_delegate_; 174 scoped_ptr<ppapi::proxy::ProxyChannel::Delegate> dispatcher_delegate_;
156 }; 175 };
157 176
158 class QuotaCallbackTranslator : public QuotaDispatcher::Callback { 177 class QuotaCallbackTranslator : public QuotaDispatcher::Callback {
159 public: 178 public:
160 typedef webkit::ppapi::PluginDelegate::AvailableSpaceCallback PluginCallback; 179 typedef webkit::ppapi::PluginDelegate::AvailableSpaceCallback PluginCallback;
161 explicit QuotaCallbackTranslator(const PluginCallback& cb) : callback_(cb) {} 180 explicit QuotaCallbackTranslator(const PluginCallback& cb) : callback_(cb) {}
162 virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) OVERRIDE { 181 virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) OVERRIDE {
163 callback_.Run(std::max(static_cast<int64>(0), quota - usage)); 182 callback_.Run(std::max(static_cast<int64>(0), quota - usage));
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 plugin_child_id)); 273 plugin_child_id));
255 274
256 // Create a new HostDispatcher for the proxying, and hook it to a new 275 // Create a new HostDispatcher for the proxying, and hook it to a new
257 // PluginModule. Note that AddLiveModule must be called before any early 276 // PluginModule. Note that AddLiveModule must be called before any early
258 // returns since the module's destructor will remove itself. 277 // returns since the module's destructor will remove itself.
259 module = new webkit::ppapi::PluginModule( 278 module = new webkit::ppapi::PluginModule(
260 info->name, path, 279 info->name, path,
261 PepperPluginRegistry::GetInstance(), 280 PepperPluginRegistry::GetInstance(),
262 permissions); 281 permissions);
263 PepperPluginRegistry::GetInstance()->AddLiveModule(path, module); 282 PepperPluginRegistry::GetInstance()->AddLiveModule(path, module);
264 scoped_ptr<HostDispatcherWrapper> dispatcher(new HostDispatcherWrapper); 283 scoped_ptr<HostDispatcherWrapper> dispatcher(
284 new HostDispatcherWrapper(render_view_, module, permissions));
265 if (!dispatcher->Init( 285 if (!dispatcher->Init(
266 channel_handle, 286 channel_handle,
267 module->pp_module(),
268 webkit::ppapi::PluginModule::GetLocalGetInterfaceFunc(), 287 webkit::ppapi::PluginModule::GetLocalGetInterfaceFunc(),
269 GetPreferences(), 288 GetPreferences(),
289 permissions,
270 hung_filter.get())) 290 hung_filter.get()))
271 return scoped_refptr<webkit::ppapi::PluginModule>(); 291 return scoped_refptr<webkit::ppapi::PluginModule>();
272 module->InitAsProxied(dispatcher.release()); 292 module->InitAsProxied(dispatcher.release());
273 return module; 293 return module;
274 } 294 }
275 295
276 scoped_refptr<webkit::ppapi::PluginModule> 296 scoped_refptr<webkit::ppapi::PluginModule>
277 PepperPluginDelegateImpl::CreateBrowserPluginModule( 297 PepperPluginDelegateImpl::CreateBrowserPluginModule(
278 const IPC::ChannelHandle& channel_handle, 298 const IPC::ChannelHandle& channel_handle,
279 int guest_process_id) { 299 int guest_process_id) {
280 BrowserPluginRegistry* registry = 300 BrowserPluginRegistry* registry =
281 RenderThreadImpl::current()->browser_plugin_registry(); 301 RenderThreadImpl::current()->browser_plugin_registry();
282 scoped_refptr<webkit::ppapi::PluginModule> module = 302 scoped_refptr<webkit::ppapi::PluginModule> module =
283 registry->GetModule(guest_process_id); 303 registry->GetModule(guest_process_id);
284 if (module) 304 if (module)
285 return module; 305 return module;
286 306
307 ppapi::PpapiPermissions permissions;
308
287 FilePath path(kBrowserPluginPath); 309 FilePath path(kBrowserPluginPath);
288 scoped_refptr<PepperHungPluginFilter> hung_filter( 310 scoped_refptr<PepperHungPluginFilter> hung_filter(
289 new PepperHungPluginFilter(path, 311 new PepperHungPluginFilter(path,
290 render_view_->routing_id(), 312 render_view_->routing_id(),
291 guest_process_id)); 313 guest_process_id));
292 // Create a new HostDispatcher for the proxying, and hook it to a new 314 // Create a new HostDispatcher for the proxying, and hook it to a new
293 // PluginModule. 315 // PluginModule.
294 module = new webkit::ppapi::PluginModule(kBrowserPluginName, 316 module = new webkit::ppapi::PluginModule(kBrowserPluginName,
295 path, 317 path,
296 registry, 318 registry,
297 ppapi::PpapiPermissions()); 319 permissions);
298 RenderThreadImpl::current()->browser_plugin_registry()->AddModule( 320 RenderThreadImpl::current()->browser_plugin_registry()->AddModule(
299 guest_process_id, module); 321 guest_process_id, module);
300 scoped_ptr<HostDispatcherWrapper> dispatcher(new HostDispatcherWrapper); 322 scoped_ptr<HostDispatcherWrapper> dispatcher(
323 new HostDispatcherWrapper(render_view_, module, permissions));
301 if (!dispatcher->Init( 324 if (!dispatcher->Init(
302 channel_handle, 325 channel_handle,
303 module->pp_module(),
304 webkit::ppapi::PluginModule::GetLocalGetInterfaceFunc(), 326 webkit::ppapi::PluginModule::GetLocalGetInterfaceFunc(),
305 GetPreferences(), 327 GetPreferences(),
328 permissions,
306 hung_filter.get())) 329 hung_filter.get()))
307 return scoped_refptr<webkit::ppapi::PluginModule>(); 330 return scoped_refptr<webkit::ppapi::PluginModule>();
308 module->InitAsProxied(dispatcher.release()); 331 module->InitAsProxied(dispatcher.release());
309 return module; 332 return module;
310 } 333 }
311 334
312 scoped_refptr<PepperBrokerImpl> PepperPluginDelegateImpl::CreateBroker( 335 scoped_refptr<PepperBrokerImpl> PepperPluginDelegateImpl::CreateBroker(
313 webkit::ppapi::PluginModule* plugin_module) { 336 webkit::ppapi::PluginModule* plugin_module) {
314 DCHECK(plugin_module); 337 DCHECK(plugin_module);
315 DCHECK(!plugin_module->GetBroker()); 338 DCHECK(!plugin_module->GetBroker());
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 if (!broker_impl.get()) 738 if (!broker_impl.get())
716 return NULL; 739 return NULL;
717 broker = broker_impl; 740 broker = broker_impl;
718 } 741 }
719 742
720 // Adds a reference, ensuring not deleted when broker_impl goes out of scope. 743 // Adds a reference, ensuring not deleted when broker_impl goes out of scope.
721 broker->Connect(client); 744 broker->Connect(client);
722 return broker; 745 return broker;
723 } 746 }
724 747
725 bool PepperPluginDelegateImpl::RunFileChooser(
726 const WebKit::WebFileChooserParams& params,
727 WebKit::WebFileChooserCompletion* chooser_completion) {
728 return render_view_->runFileChooser(params, chooser_completion);
729 }
730
731 bool PepperPluginDelegateImpl::AsyncOpenFile( 748 bool PepperPluginDelegateImpl::AsyncOpenFile(
732 const FilePath& path, 749 const FilePath& path,
733 int flags, 750 int flags,
734 const AsyncOpenFileCallback& callback) { 751 const AsyncOpenFileCallback& callback) {
735 int message_id = pending_async_open_files_.Add( 752 int message_id = pending_async_open_files_.Add(
736 new AsyncOpenFileCallback(callback)); 753 new AsyncOpenFileCallback(callback));
737 IPC::Message* msg = new ViewHostMsg_AsyncOpenFile( 754 IPC::Message* msg = new ViewHostMsg_AsyncOpenFile(
738 render_view_->routing_id(), path, flags, message_id); 755 render_view_->routing_id(), path, flags, message_id);
739 return render_view_->Send(msg); 756 return render_view_->Send(msg);
740 } 757 }
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after
1719 else 1736 else
1720 return render_view_->mouse_lock_dispatcher(); 1737 return render_view_->mouse_lock_dispatcher();
1721 } 1738 }
1722 1739
1723 webkit_glue::ClipboardClient* 1740 webkit_glue::ClipboardClient*
1724 PepperPluginDelegateImpl::CreateClipboardClient() const { 1741 PepperPluginDelegateImpl::CreateClipboardClient() const {
1725 return new RendererClipboardClient; 1742 return new RendererClipboardClient;
1726 } 1743 }
1727 1744
1728 } // namespace content 1745 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698