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

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

Issue 10214007: 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, 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 "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/rand_util_c.h" 12 #include "base/rand_util_c.h"
13 #include "chrome/common/render_messages.h" 13 #include "chrome/common/render_messages.h"
14 #include "content/public/common/content_switches.h" 14 #include "content/public/common/content_switches.h"
15 #include "content/public/renderer/render_thread.h" 15 #include "content/public/renderer/render_thread.h"
16 #include "ipc/ipc_sync_message_filter.h" 16 #include "ipc/ipc_sync_message_filter.h"
17 #include "native_client/src/shared/imc/nacl_imc.h" 17 #include "native_client/src/shared/imc/nacl_imc.h"
18 #include "ppapi/c/private/ppb_nacl_private.h" 18 #include "ppapi/c/private/ppb_nacl_private.h"
19 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" 19 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h"
20 20
21 #if defined(OS_WIN) 21 #if defined(OS_WIN)
22 #include "content/public/common/sandbox_init.h" 22 #include "content/public/common/sandbox_init.h"
23 #endif 23 #endif
24 24
25 #include "base/path_service.h"
26 #include "chrome/common/chrome_paths.h"
27 #include "content/public/browser/plugin_service.h"
28 #include "content/public/common/content_client.h"
29 #include "content/public/renderer/render_thread.h"
30 #include "content/public/renderer/render_view.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h"
35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
37 #include "webkit/plugins/ppapi/host_globals.h"
38 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
39
40 using content::RenderThread;
41 using webkit::ppapi::HostGlobals;
42 using webkit::ppapi::PluginInstance;
43 using WebKit::WebElement;
44 using WebKit::WebView;
bbudge 2012/05/07 18:08:53 I will get these sorted and pruned down to just wh
45
25 namespace { 46 namespace {
26 47
27 base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> > 48 base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> >
28 g_background_thread_sender = LAZY_INSTANCE_INITIALIZER; 49 g_background_thread_sender = LAZY_INSTANCE_INITIALIZER;
29 50
51 IPC::ChannelHandle g_plugin_ppapi_channel;
52 base::ProcessHandle g_plugin_process_handle;
53 base::ProcessId g_plugin_process_id;
bbudge 2012/05/07 18:08:53 I need to figure out what to do with these globals
54
30 // Launch NaCl's sel_ldr process. 55 // Launch NaCl's sel_ldr process.
31 bool LaunchSelLdr(const char* alleged_url, int socket_count, 56 bool LaunchSelLdr(PP_Instance instance,
57 const char* alleged_url, int socket_count,
32 void* imc_handles) { 58 void* imc_handles) {
33 std::vector<nacl::FileDescriptor> sockets; 59 std::vector<nacl::FileDescriptor> sockets;
34 IPC::Message::Sender* sender = content::RenderThread::Get(); 60 IPC::Message::Sender* sender = content::RenderThread::Get();
35 if (sender == NULL) 61 if (sender == NULL)
36 sender = g_background_thread_sender.Pointer()->get(); 62 sender = g_background_thread_sender.Pointer()->get();
37 63
38 if (!sender->Send(new ChromeViewHostMsg_LaunchNaCl( 64 if (!sender->Send(new ChromeViewHostMsg_LaunchNaCl(
39 GURL(alleged_url), socket_count, &sockets))) 65 GURL(alleged_url), socket_count, &sockets,
66 &g_plugin_ppapi_channel,
67 &g_plugin_process_handle,
68 &g_plugin_process_id)))
40 return false; 69 return false;
41 70
42 CHECK(static_cast<int>(sockets.size()) == socket_count); 71 CHECK(static_cast<int>(sockets.size()) == socket_count);
43 for (int i = 0; i < socket_count; i++) { 72 for (int i = 0; i < socket_count; i++) {
44 static_cast<nacl::Handle*>(imc_handles)[i] = 73 static_cast<nacl::Handle*>(imc_handles)[i] =
45 nacl::ToNativeHandle(sockets[i]); 74 nacl::ToNativeHandle(sockets[i]);
46 } 75 }
76
77 return true;
78 }
79
80 bool StartPpapiProxy(PP_Instance instance) {
81 // Using the RenderView, establish the HostDispatcher for the PPAPI proxy.
82 webkit::ppapi::PluginInstance* plugin_instance =
83 content::GetHostGlobals()->GetInstance(instance);
84 if (!plugin_instance)
85 return false;
86 FilePath plugin_path;
87 if (!PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_path))
88 return false;
89 if (g_plugin_ppapi_channel.name.empty())
90 return false;
91
92 WebView* view =
93 plugin_instance->container()->element().document().frame()->view();
94 content::RenderView* render_view = content::RenderView::FromWebView(view);
95 render_view->CreatePepperHostDispatcher(plugin_path,
96 g_plugin_process_id,
97 g_plugin_process_handle,
98 g_plugin_ppapi_channel);
99
47 return true; 100 return true;
48 } 101 }
49 102
50 int UrandomFD(void) { 103 int UrandomFD(void) {
51 #if defined(OS_POSIX) 104 #if defined(OS_POSIX)
52 return GetUrandomFD(); 105 return GetUrandomFD();
53 #else 106 #else
54 return 0; 107 return 0;
55 #endif 108 #endif
56 } 109 }
(...skipping 16 matching lines...) Expand all
73 return content::BrokerDuplicateHandle(source_handle, process_id, 126 return content::BrokerDuplicateHandle(source_handle, process_id,
74 target_handle, desired_access, 127 target_handle, desired_access,
75 options); 128 options);
76 #else 129 #else
77 return 0; 130 return 0;
78 #endif 131 #endif
79 } 132 }
80 133
81 const PPB_NaCl_Private nacl_interface = { 134 const PPB_NaCl_Private nacl_interface = {
82 &LaunchSelLdr, 135 &LaunchSelLdr,
136 &StartPpapiProxy,
83 &UrandomFD, 137 &UrandomFD,
84 &Are3DInterfacesDisabled, 138 &Are3DInterfacesDisabled,
85 &EnableBackgroundSelLdrLaunch, 139 &EnableBackgroundSelLdrLaunch,
86 &BrokerDuplicateHandle, 140 &BrokerDuplicateHandle,
87 }; 141 };
88 142
89 } // namespace 143 } // namespace
90 144
91 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { 145 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() {
92 return &nacl_interface; 146 return &nacl_interface;
93 } 147 }
94 148
95 #endif // DISABLE_NACL 149 #endif // DISABLE_NACL
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698