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

Side by Side Diff: chrome/renderer/pepper/ppb_nacl_private_impl.cc

Issue 10625007: Revert 143656 - Add an IPC channel between the NaCl loader process and the renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 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 "chrome/renderer/pepper/ppb_nacl_private_impl.h" 5 #include "chrome/renderer/pepper/ppb_nacl_private_impl.h"
6 6
7 #ifndef DISABLE_NACL 7 #ifndef DISABLE_NACL
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop.h"
13 #include "base/rand_util.h" 12 #include "base/rand_util.h"
14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/render_messages.h" 13 #include "chrome/common/render_messages.h"
16 #include "content/public/common/content_client.h"
17 #include "content/public/common/content_switches.h" 14 #include "content/public/common/content_switches.h"
18 #include "content/public/common/sandbox_init.h"
19 #include "content/public/renderer/render_thread.h" 15 #include "content/public/renderer/render_thread.h"
20 #include "content/public/renderer/render_view.h"
21 #include "ipc/ipc_sync_message_filter.h" 16 #include "ipc/ipc_sync_message_filter.h"
22 #include "ppapi/c/private/ppb_nacl_private.h" 17 #include "ppapi/c/private/ppb_nacl_private.h"
23 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" 18 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h"
24 #include "ppapi/proxy/host_dispatcher.h"
25 #include "ppapi/proxy/proxy_channel.h"
26 #include "ppapi/shared_impl/ppapi_preferences.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
32 #include "webkit/plugins/ppapi/host_globals.h"
33 #include "webkit/plugins/ppapi/plugin_module.h"
34 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
35 19
36 using content::RenderThread; 20 #if defined(OS_WIN)
37 using content::RenderView; 21 #include "content/public/common/sandbox_init.h"
38 using webkit::ppapi::HostGlobals; 22 #endif
39 using webkit::ppapi::PluginInstance;
40 using webkit::ppapi::PluginDelegate;
41 using WebKit::WebView;
42 23
43 namespace { 24 namespace {
44 25
45 base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> > 26 base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> >
46 g_background_thread_sender = LAZY_INSTANCE_INITIALIZER; 27 g_background_thread_sender = LAZY_INSTANCE_INITIALIZER;
47 28
48 typedef std::map<PP_Instance, IPC::ChannelHandle> ChannelHandleMap;
49
50 base::LazyInstance<ChannelHandleMap> g_channel_handle_map =
51 LAZY_INSTANCE_INITIALIZER;
52
53 // Launch NaCl's sel_ldr process. 29 // Launch NaCl's sel_ldr process.
54 PP_Bool LaunchSelLdr(PP_Instance instance, 30 PP_Bool LaunchSelLdr(PP_Instance instance,
55 const char* alleged_url, 31 const char* alleged_url, int socket_count,
56 int socket_count,
57 void* imc_handles) { 32 void* imc_handles) {
58 std::vector<nacl::FileDescriptor> sockets; 33 std::vector<nacl::FileDescriptor> sockets;
59 IPC::Sender* sender = content::RenderThread::Get(); 34 IPC::Sender* sender = content::RenderThread::Get();
60 if (sender == NULL) 35 if (sender == NULL)
61 sender = g_background_thread_sender.Pointer()->get(); 36 sender = g_background_thread_sender.Pointer()->get();
62 37
63 IPC::ChannelHandle channel_handle;
64 if (!sender->Send(new ChromeViewHostMsg_LaunchNaCl( 38 if (!sender->Send(new ChromeViewHostMsg_LaunchNaCl(
65 GURL(alleged_url), socket_count, &sockets, 39 GURL(alleged_url), socket_count, &sockets)))
66 &channel_handle))) {
67 return PP_FALSE; 40 return PP_FALSE;
68 }
69
70 // Don't save invalid channel handles.
71 bool invalid_handle = channel_handle.name.empty();
72
73 #if defined(OS_POSIX)
74 if (!invalid_handle)
75 invalid_handle = (channel_handle.socket.fd == -1);
76 #endif
77
78 if (!invalid_handle)
79 g_channel_handle_map.Get()[instance] = channel_handle;
80 41
81 CHECK(static_cast<int>(sockets.size()) == socket_count); 42 CHECK(static_cast<int>(sockets.size()) == socket_count);
82 for (int i = 0; i < socket_count; i++) { 43 for (int i = 0; i < socket_count; i++) {
83 static_cast<nacl::Handle*>(imc_handles)[i] = 44 static_cast<nacl::Handle*>(imc_handles)[i] =
84 nacl::ToNativeHandle(sockets[i]); 45 nacl::ToNativeHandle(sockets[i]);
85 } 46 }
86 47
87 return PP_TRUE; 48 return PP_TRUE;
88 } 49 }
89 50
90 class ProxyChannelDelegate
91 : public ppapi::proxy::ProxyChannel::Delegate {
92 public:
93 ProxyChannelDelegate();
94 virtual ~ProxyChannelDelegate();
95
96 // ProxyChannel::Delegate implementation.
97 virtual base::MessageLoopProxy* GetIPCMessageLoop() OVERRIDE;
98 virtual base::WaitableEvent* GetShutdownEvent() OVERRIDE;
99 virtual IPC::PlatformFileForTransit ShareHandleWithRemote(
100 base::PlatformFile handle,
101 const IPC::SyncChannel& channel,
102 bool should_close_source) OVERRIDE;
103 private:
104 // TODO(bbudge) Modify the content public API so we can get
105 // the renderer process's shutdown event.
106 base::WaitableEvent shutdown_event_;
107 };
108
109 ProxyChannelDelegate::ProxyChannelDelegate()
110 : shutdown_event_(true, false) {
111 }
112
113 ProxyChannelDelegate::~ProxyChannelDelegate() {
114 }
115
116 base::MessageLoopProxy* ProxyChannelDelegate::GetIPCMessageLoop() {
117 return RenderThread::Get()->GetIOMessageLoopProxy().get();
118 }
119
120 base::WaitableEvent* ProxyChannelDelegate::GetShutdownEvent() {
121 return &shutdown_event_;
122 }
123
124 IPC::PlatformFileForTransit ProxyChannelDelegate::ShareHandleWithRemote(
125 base::PlatformFile handle,
126 const IPC::SyncChannel& channel,
127 bool should_close_source) {
128 return content::BrokerGetFileHandleForProcess(handle, channel.peer_pid(),
129 should_close_source);
130 }
131
132 // Stubbed out SyncMessageStatusReceiver, required by HostDispatcher.
133 // TODO(bbudge) Use a content::PepperHungPluginFilter instead.
134 class SyncMessageStatusReceiver
135 : public ppapi::proxy::HostDispatcher::SyncMessageStatusReceiver {
136 public:
137 SyncMessageStatusReceiver() {}
138
139 // SyncMessageStatusReceiver implementation.
140 virtual void BeginBlockOnSyncMessage() OVERRIDE {}
141 virtual void EndBlockOnSyncMessage() OVERRIDE {}
142
143 private:
144 virtual ~SyncMessageStatusReceiver() {}
145 };
146
147 class OutOfProcessProxy : public PluginDelegate::OutOfProcessProxy {
148 public:
149 OutOfProcessProxy() {}
150 virtual ~OutOfProcessProxy() {}
151
152 bool Init(const IPC::ChannelHandle& channel_handle,
153 PP_Module pp_module,
154 PP_GetInterface_Func local_get_interface,
155 const ppapi::Preferences& preferences,
156 SyncMessageStatusReceiver* status_receiver) {
157 dispatcher_delegate_.reset(new ProxyChannelDelegate);
158 dispatcher_.reset(new ppapi::proxy::HostDispatcher(
159 pp_module, local_get_interface, status_receiver));
160
161 if (!dispatcher_->InitHostWithChannel(dispatcher_delegate_.get(),
162 channel_handle,
163 true, // Client.
164 preferences)) {
165 dispatcher_.reset();
166 dispatcher_delegate_.reset();
167 return false;
168 }
169
170 return true;
171 }
172
173 // OutOfProcessProxy implementation.
174 virtual const void* GetProxiedInterface(const char* name) OVERRIDE {
175 return dispatcher_->GetProxiedInterface(name);
176 }
177 virtual void AddInstance(PP_Instance instance) OVERRIDE {
178 ppapi::proxy::HostDispatcher::SetForInstance(instance, dispatcher_.get());
179 }
180 virtual void RemoveInstance(PP_Instance instance) OVERRIDE {
181 ppapi::proxy::HostDispatcher::RemoveForInstance(instance);
182 }
183
184 private:
185 scoped_ptr<ppapi::proxy::HostDispatcher> dispatcher_;
186 scoped_ptr<ppapi::proxy::ProxyChannel::Delegate> dispatcher_delegate_;
187 };
188
189 PP_Bool StartPpapiProxy(PP_Instance instance) { 51 PP_Bool StartPpapiProxy(PP_Instance instance) {
190 if (CommandLine::ForCurrentProcess()->HasSwitch(
191 switches::kEnableNaClIPCProxy)) {
192 ChannelHandleMap& map = g_channel_handle_map.Get();
193 ChannelHandleMap::iterator it = map.find(instance);
194 if (it == map.end())
195 return PP_FALSE;
196 IPC::ChannelHandle channel_handle = it->second;
197 map.erase(it);
198
199 webkit::ppapi::PluginInstance* plugin_instance =
200 content::GetHostGlobals()->GetInstance(instance);
201 if (!plugin_instance)
202 return PP_FALSE;
203
204 WebView* web_view =
205 plugin_instance->container()->element().document().frame()->view();
206 RenderView* render_view = content::RenderView::FromWebView(web_view);
207
208 webkit::ppapi::PluginModule* plugin_module = plugin_instance->module();
209
210 scoped_refptr<SyncMessageStatusReceiver>
211 status_receiver(new SyncMessageStatusReceiver());
212 scoped_ptr<OutOfProcessProxy> out_of_process_proxy(new OutOfProcessProxy);
213 if (out_of_process_proxy->Init(
214 channel_handle,
215 plugin_module->pp_module(),
216 webkit::ppapi::PluginModule::GetLocalGetInterfaceFunc(),
217 ppapi::Preferences(render_view->GetWebkitPreferences()),
218 status_receiver.get())) {
219 plugin_module->InitAsProxiedNaCl(
220 out_of_process_proxy.PassAs<PluginDelegate::OutOfProcessProxy>(),
221 instance);
222 return PP_TRUE;
223 }
224 }
225
226 return PP_FALSE; 52 return PP_FALSE;
227 } 53 }
228 54
229 int UrandomFD(void) { 55 int UrandomFD(void) {
230 #if defined(OS_POSIX) 56 #if defined(OS_POSIX)
231 return base::GetUrandomFD(); 57 return base::GetUrandomFD();
232 #else 58 #else
233 return -1; 59 return -1;
234 #endif 60 #endif
235 } 61 }
(...skipping 30 matching lines...) Expand all
266 &BrokerDuplicateHandle, 92 &BrokerDuplicateHandle,
267 }; 93 };
268 94
269 } // namespace 95 } // namespace
270 96
271 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { 97 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() {
272 return &nacl_interface; 98 return &nacl_interface;
273 } 99 }
274 100
275 #endif // DISABLE_NACL 101 #endif // DISABLE_NACL
OLDNEW
« no previous file with comments | « chrome/nacl/nacl_listener.cc ('k') | ppapi/native_client/src/trusted/plugin/nacl_entry_points.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698