OLD | NEW |
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/path_service.h" |
12 #include "base/rand_util_c.h" | 13 #include "base/rand_util_c.h" |
| 14 #include "chrome/common/chrome_paths.h" |
| 15 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/render_messages.h" | 16 #include "chrome/common/render_messages.h" |
| 17 #include "content/public/common/content_client.h" |
14 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
15 #include "content/public/renderer/render_thread.h" | 19 #include "content/public/renderer/render_thread.h" |
| 20 #include "content/public/renderer/render_view.h" |
16 #include "ipc/ipc_sync_message_filter.h" | 21 #include "ipc/ipc_sync_message_filter.h" |
17 #include "native_client/src/shared/imc/nacl_imc.h" | |
18 #include "ppapi/c/private/ppb_nacl_private.h" | 22 #include "ppapi/c/private/ppb_nacl_private.h" |
19 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" | 23 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 29 #include "webkit/plugins/ppapi/host_globals.h" |
| 30 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
20 | 31 |
21 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
22 #include "content/public/common/sandbox_init.h" | 33 #include "content/public/common/sandbox_init.h" |
23 #endif | 34 #endif |
24 | 35 |
| 36 using content::RenderThread; |
| 37 using webkit::ppapi::HostGlobals; |
| 38 using webkit::ppapi::PluginInstance; |
| 39 using WebKit::WebView; |
| 40 |
25 namespace { | 41 namespace { |
26 | 42 |
27 base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> > | 43 base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> > |
28 g_background_thread_sender = LAZY_INSTANCE_INITIALIZER; | 44 g_background_thread_sender = LAZY_INSTANCE_INITIALIZER; |
29 | 45 |
| 46 IPC::ChannelHandle g_plugin_ppapi_channel; |
| 47 base::ProcessHandle g_plugin_process_handle; |
| 48 base::ProcessId g_plugin_process_id; |
| 49 |
30 // Launch NaCl's sel_ldr process. | 50 // Launch NaCl's sel_ldr process. |
31 bool LaunchSelLdr(const char* alleged_url, int socket_count, | 51 PP_Bool LaunchSelLdr(PP_Instance instance, |
32 void* imc_handles) { | 52 const char* alleged_url, int socket_count, |
| 53 void* imc_handles) { |
33 std::vector<nacl::FileDescriptor> sockets; | 54 std::vector<nacl::FileDescriptor> sockets; |
34 IPC::Message::Sender* sender = content::RenderThread::Get(); | 55 IPC::Message::Sender* sender = content::RenderThread::Get(); |
35 if (sender == NULL) | 56 if (sender == NULL) |
36 sender = g_background_thread_sender.Pointer()->get(); | 57 sender = g_background_thread_sender.Pointer()->get(); |
37 | 58 |
38 if (!sender->Send(new ChromeViewHostMsg_LaunchNaCl( | 59 if (!sender->Send(new ChromeViewHostMsg_LaunchNaCl( |
39 GURL(alleged_url), socket_count, &sockets))) | 60 GURL(alleged_url), socket_count, &sockets, |
40 return false; | 61 &g_plugin_ppapi_channel, |
| 62 &g_plugin_process_handle, |
| 63 &g_plugin_process_id))) |
| 64 return PP_FALSE; |
41 | 65 |
42 CHECK(static_cast<int>(sockets.size()) == socket_count); | 66 CHECK(static_cast<int>(sockets.size()) == socket_count); |
43 for (int i = 0; i < socket_count; i++) { | 67 for (int i = 0; i < socket_count; i++) { |
44 static_cast<nacl::Handle*>(imc_handles)[i] = | 68 static_cast<nacl::Handle*>(imc_handles)[i] = |
45 nacl::ToNativeHandle(sockets[i]); | 69 nacl::ToNativeHandle(sockets[i]); |
46 } | 70 } |
47 return true; | 71 |
| 72 return PP_TRUE; |
| 73 } |
| 74 |
| 75 PP_Bool StartPpapiProxy(PP_Instance instance) { |
| 76 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 77 switches::kEnableNaClIPCProxy)) { |
| 78 webkit::ppapi::PluginInstance* plugin_instance = |
| 79 content::GetHostGlobals()->GetInstance(instance); |
| 80 if (!plugin_instance) |
| 81 return PP_FALSE; |
| 82 FilePath plugin_path; |
| 83 if (!PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_path)) |
| 84 return PP_FALSE; |
| 85 if (g_plugin_ppapi_channel.name.empty()) |
| 86 return PP_FALSE; |
| 87 |
| 88 WebView* view = |
| 89 plugin_instance->container()->element().document().frame()->view(); |
| 90 content::RenderView* render_view = content::RenderView::FromWebView(view); |
| 91 // Establish the HostDispatcher for the PPAPI proxy. |
| 92 if (render_view->CreatePepperHostDispatcher( |
| 93 plugin_path, |
| 94 g_plugin_process_id, |
| 95 g_plugin_process_handle, |
| 96 g_plugin_ppapi_channel)) |
| 97 return PP_TRUE; |
| 98 } |
| 99 |
| 100 return PP_FALSE; |
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 } |
57 | 110 |
(...skipping 15 matching lines...) Expand all Loading... |
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 |
OLD | NEW |