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

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_renderer_pepper_host_factory.h"
44 #include "content/renderer/pepper/pepper_broker_impl.h" 45 #include "content/renderer/pepper/pepper_broker_impl.h"
45 #include "content/renderer/pepper/pepper_device_enumeration_event_handler.h" 46 #include "content/renderer/pepper/pepper_device_enumeration_event_handler.h"
46 #include "content/renderer/pepper/pepper_hung_plugin_filter.h" 47 #include "content/renderer/pepper/pepper_hung_plugin_filter.h"
47 #include "content/renderer/pepper/pepper_in_process_resource_creation.h" 48 #include "content/renderer/pepper/pepper_in_process_resource_creation.h"
49 #include "content/renderer/pepper/pepper_instance_state_accessor.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 : module_(module),
113 instance_state_(module),
114 host_factory_(rv, perms, &instance_state_) {
115 }
109 virtual ~HostDispatcherWrapper() {} 116 virtual ~HostDispatcherWrapper() {}
110 117
111 bool Init(const IPC::ChannelHandle& channel_handle, 118 bool Init(const IPC::ChannelHandle& channel_handle,
112 PP_Module pp_module,
113 PP_GetInterface_Func local_get_interface, 119 PP_GetInterface_Func local_get_interface,
114 const ppapi::Preferences& preferences, 120 const ppapi::Preferences& preferences,
121 const ppapi::PpapiPermissions& permissions,
115 PepperHungPluginFilter* filter) { 122 PepperHungPluginFilter* filter) {
116 if (channel_handle.name.empty()) 123 if (channel_handle.name.empty())
117 return false; 124 return false;
118 125
119 #if defined(OS_POSIX) 126 #if defined(OS_POSIX)
120 DCHECK_NE(-1, channel_handle.socket.fd); 127 DCHECK_NE(-1, channel_handle.socket.fd);
121 if (channel_handle.socket.fd == -1) 128 if (channel_handle.socket.fd == -1)
122 return false; 129 return false;
123 #endif 130 #endif
124 131
125 dispatcher_delegate_.reset(new PepperProxyChannelDelegateImpl); 132 dispatcher_delegate_.reset(new PepperProxyChannelDelegateImpl);
126 dispatcher_.reset(new ppapi::proxy::HostDispatcher( 133 dispatcher_.reset(new ppapi::proxy::HostDispatcher(
127 pp_module, local_get_interface, filter)); 134 module_->pp_module(), local_get_interface, filter));
135
136 host_.reset(new ppapi::host::PpapiHost(dispatcher_.get(), &host_factory_,
137 permissions));
138 dispatcher_->AddFilter(host_.get());
128 139
129 if (!dispatcher_->InitHostWithChannel(dispatcher_delegate_.get(), 140 if (!dispatcher_->InitHostWithChannel(dispatcher_delegate_.get(),
130 channel_handle, 141 channel_handle,
131 true, // Client. 142 true, // Client.
132 preferences)) { 143 preferences)) {
133 dispatcher_.reset(); 144 dispatcher_.reset();
134 dispatcher_delegate_.reset(); 145 dispatcher_delegate_.reset();
135 return false; 146 return false;
136 } 147 }
137 dispatcher_->channel()->SetRestrictDispatchChannelGroup( 148 dispatcher_->channel()->SetRestrictDispatchChannelGroup(
138 content::kRendererRestrictDispatchGroup_Pepper); 149 content::kRendererRestrictDispatchGroup_Pepper);
139 return true; 150 return true;
140 } 151 }
141 152
142 // OutOfProcessProxy implementation. 153 // OutOfProcessProxy implementation.
143 virtual const void* GetProxiedInterface(const char* name) { 154 virtual const void* GetProxiedInterface(const char* name) {
144 return dispatcher_->GetProxiedInterface(name); 155 return dispatcher_->GetProxiedInterface(name);
145 } 156 }
146 virtual void AddInstance(PP_Instance instance) { 157 virtual void AddInstance(PP_Instance instance) {
147 ppapi::proxy::HostDispatcher::SetForInstance(instance, dispatcher_.get()); 158 ppapi::proxy::HostDispatcher::SetForInstance(instance, dispatcher_.get());
148 } 159 }
149 virtual void RemoveInstance(PP_Instance instance) { 160 virtual void RemoveInstance(PP_Instance instance) {
150 ppapi::proxy::HostDispatcher::RemoveForInstance(instance); 161 ppapi::proxy::HostDispatcher::RemoveForInstance(instance);
151 } 162 }
152 163
153 private: 164 private:
165 webkit::ppapi::PluginModule* module_;
166 PepperInstanceStateAccessorImpl instance_state_;
167 ContentRendererPepperHostFactory host_factory_;
168
169 scoped_ptr<ppapi::host::PpapiHost> host_;
170
154 scoped_ptr<ppapi::proxy::HostDispatcher> dispatcher_; 171 scoped_ptr<ppapi::proxy::HostDispatcher> dispatcher_;
155 scoped_ptr<ppapi::proxy::ProxyChannel::Delegate> dispatcher_delegate_; 172 scoped_ptr<ppapi::proxy::ProxyChannel::Delegate> dispatcher_delegate_;
156 }; 173 };
157 174
158 class QuotaCallbackTranslator : public QuotaDispatcher::Callback { 175 class QuotaCallbackTranslator : public QuotaDispatcher::Callback {
159 public: 176 public:
160 typedef webkit::ppapi::PluginDelegate::AvailableSpaceCallback PluginCallback; 177 typedef webkit::ppapi::PluginDelegate::AvailableSpaceCallback PluginCallback;
161 explicit QuotaCallbackTranslator(const PluginCallback& cb) : callback_(cb) {} 178 explicit QuotaCallbackTranslator(const PluginCallback& cb) : callback_(cb) {}
162 virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) OVERRIDE { 179 virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) OVERRIDE {
163 callback_.Run(std::max(static_cast<int64>(0), quota - usage)); 180 callback_.Run(std::max(static_cast<int64>(0), quota - usage));
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 plugin_child_id)); 335 plugin_child_id));
319 336
320 // Create a new HostDispatcher for the proxying, and hook it to a new 337 // Create a new HostDispatcher for the proxying, and hook it to a new
321 // PluginModule. Note that AddLiveModule must be called before any early 338 // PluginModule. Note that AddLiveModule must be called before any early
322 // returns since the module's destructor will remove itself. 339 // returns since the module's destructor will remove itself.
323 module = new webkit::ppapi::PluginModule( 340 module = new webkit::ppapi::PluginModule(
324 info->name, path, 341 info->name, path,
325 PepperPluginRegistry::GetInstance(), 342 PepperPluginRegistry::GetInstance(),
326 permissions); 343 permissions);
327 PepperPluginRegistry::GetInstance()->AddLiveModule(path, module); 344 PepperPluginRegistry::GetInstance()->AddLiveModule(path, module);
328 scoped_ptr<HostDispatcherWrapper> dispatcher(new HostDispatcherWrapper); 345 scoped_ptr<HostDispatcherWrapper> dispatcher(
346 new HostDispatcherWrapper(render_view_, module, permissions));
329 if (!dispatcher->Init( 347 if (!dispatcher->Init(
330 channel_handle, 348 channel_handle,
331 module->pp_module(),
332 webkit::ppapi::PluginModule::GetLocalGetInterfaceFunc(), 349 webkit::ppapi::PluginModule::GetLocalGetInterfaceFunc(),
333 GetPreferences(), 350 GetPreferences(),
351 permissions,
334 hung_filter.get())) 352 hung_filter.get()))
335 return scoped_refptr<webkit::ppapi::PluginModule>(); 353 return scoped_refptr<webkit::ppapi::PluginModule>();
336 module->InitAsProxied(dispatcher.release()); 354 module->InitAsProxied(dispatcher.release());
337 return module; 355 return module;
338 } 356 }
339 357
340 scoped_refptr<webkit::ppapi::PluginModule> 358 scoped_refptr<webkit::ppapi::PluginModule>
341 PepperPluginDelegateImpl::CreateBrowserPluginModule( 359 PepperPluginDelegateImpl::CreateBrowserPluginModule(
342 const IPC::ChannelHandle& channel_handle, 360 const IPC::ChannelHandle& channel_handle,
343 int guest_process_id) { 361 int guest_process_id) {
344 BrowserPluginRegistry* registry = 362 BrowserPluginRegistry* registry =
345 RenderThreadImpl::current()->browser_plugin_registry(); 363 RenderThreadImpl::current()->browser_plugin_registry();
346 scoped_refptr<webkit::ppapi::PluginModule> module = 364 scoped_refptr<webkit::ppapi::PluginModule> module =
347 registry->GetModule(guest_process_id); 365 registry->GetModule(guest_process_id);
348 if (module) 366 if (module)
349 return module; 367 return module;
350 368
369 ppapi::PpapiPermissions permissions;
370
351 FilePath path(kBrowserPluginPath); 371 FilePath path(kBrowserPluginPath);
352 scoped_refptr<PepperHungPluginFilter> hung_filter( 372 scoped_refptr<PepperHungPluginFilter> hung_filter(
353 new PepperHungPluginFilter(path, 373 new PepperHungPluginFilter(path,
354 render_view_->routing_id(), 374 render_view_->routing_id(),
355 guest_process_id)); 375 guest_process_id));
356 // Create a new HostDispatcher for the proxying, and hook it to a new 376 // Create a new HostDispatcher for the proxying, and hook it to a new
357 // PluginModule. 377 // PluginModule.
358 module = new webkit::ppapi::PluginModule(kBrowserPluginName, 378 module = new webkit::ppapi::PluginModule(kBrowserPluginName,
359 path, 379 path,
360 registry, 380 registry,
361 ppapi::PpapiPermissions()); 381 permissions);
362 RenderThreadImpl::current()->browser_plugin_registry()->AddModule( 382 RenderThreadImpl::current()->browser_plugin_registry()->AddModule(
363 guest_process_id, module); 383 guest_process_id, module);
364 scoped_ptr<HostDispatcherWrapper> dispatcher(new HostDispatcherWrapper); 384 scoped_ptr<HostDispatcherWrapper> dispatcher(
385 new HostDispatcherWrapper(render_view_, module, permissions));
365 if (!dispatcher->Init( 386 if (!dispatcher->Init(
366 channel_handle, 387 channel_handle,
367 module->pp_module(),
368 webkit::ppapi::PluginModule::GetLocalGetInterfaceFunc(), 388 webkit::ppapi::PluginModule::GetLocalGetInterfaceFunc(),
369 GetPreferences(), 389 GetPreferences(),
390 permissions,
370 hung_filter.get())) 391 hung_filter.get()))
371 return scoped_refptr<webkit::ppapi::PluginModule>(); 392 return scoped_refptr<webkit::ppapi::PluginModule>();
372 module->InitAsProxied(dispatcher.release()); 393 module->InitAsProxied(dispatcher.release());
373 return module; 394 return module;
374 } 395 }
375 396
376 scoped_refptr<PepperBrokerImpl> PepperPluginDelegateImpl::CreateBroker( 397 scoped_refptr<PepperBrokerImpl> PepperPluginDelegateImpl::CreateBroker(
377 webkit::ppapi::PluginModule* plugin_module) { 398 webkit::ppapi::PluginModule* plugin_module) {
378 DCHECK(plugin_module); 399 DCHECK(plugin_module);
379 DCHECK(!plugin_module->GetBroker()); 400 DCHECK(!plugin_module->GetBroker());
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 if (!broker_impl.get()) 800 if (!broker_impl.get())
780 return NULL; 801 return NULL;
781 broker = broker_impl; 802 broker = broker_impl;
782 } 803 }
783 804
784 // Adds a reference, ensuring not deleted when broker_impl goes out of scope. 805 // Adds a reference, ensuring not deleted when broker_impl goes out of scope.
785 broker->Connect(client); 806 broker->Connect(client);
786 return broker; 807 return broker;
787 } 808 }
788 809
789 bool PepperPluginDelegateImpl::RunFileChooser(
790 const WebKit::WebFileChooserParams& params,
791 WebKit::WebFileChooserCompletion* chooser_completion) {
792 return render_view_->runFileChooser(params, chooser_completion);
793 }
794
795 bool PepperPluginDelegateImpl::AsyncOpenFile( 810 bool PepperPluginDelegateImpl::AsyncOpenFile(
796 const FilePath& path, 811 const FilePath& path,
797 int flags, 812 int flags,
798 const AsyncOpenFileCallback& callback) { 813 const AsyncOpenFileCallback& callback) {
799 int message_id = pending_async_open_files_.Add( 814 int message_id = pending_async_open_files_.Add(
800 new AsyncOpenFileCallback(callback)); 815 new AsyncOpenFileCallback(callback));
801 IPC::Message* msg = new ViewHostMsg_AsyncOpenFile( 816 IPC::Message* msg = new ViewHostMsg_AsyncOpenFile(
802 render_view_->routing_id(), path, flags, message_id); 817 render_view_->routing_id(), path, flags, message_id);
803 return render_view_->Send(msg); 818 return render_view_->Send(msg);
804 } 819 }
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 else 1750 else
1736 return render_view_->mouse_lock_dispatcher(); 1751 return render_view_->mouse_lock_dispatcher();
1737 } 1752 }
1738 1753
1739 webkit_glue::ClipboardClient* 1754 webkit_glue::ClipboardClient*
1740 PepperPluginDelegateImpl::CreateClipboardClient() const { 1755 PepperPluginDelegateImpl::CreateClipboardClient() const {
1741 return new RendererClipboardClient; 1756 return new RendererClipboardClient;
1742 } 1757 }
1743 1758
1744 } // namespace content 1759 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698