Chromium Code Reviews| 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; | |
|
dmichael (off chromium)
2012/05/10 19:38:58
I think this one will have to be a LazyInstance if
| |
| 47 base::ProcessHandle g_plugin_process_handle; | |
| 48 base::ProcessId g_plugin_process_id; | |
|
dmichael (off chromium)
2012/05/10 19:38:58
Suppose one page has >1 NaCl module embedded on it
bbudge
2012/05/11 01:21:16
This is just for the sake of getting something wor
| |
| 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 bool LaunchSelLdr(PP_Instance instance, |
| 52 const char* alleged_url, int socket_count, | |
| 32 void* imc_handles) { | 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, |
| 61 &g_plugin_ppapi_channel, | |
| 62 &g_plugin_process_handle, | |
| 63 &g_plugin_process_id))) | |
| 40 return false; | 64 return 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 } |
| 71 | |
| 47 return true; | 72 return true; |
| 48 } | 73 } |
| 49 | 74 |
| 75 bool StartPpapiProxy(PP_Instance instance) { | |
| 76 // Using the RenderView, establish the HostDispatcher for the PPAPI proxy. | |
|
dmichael (off chromium)
2012/05/10 19:38:58
I think this comment might be better right before
bbudge
2012/05/11 01:21:16
Done.
| |
| 77 webkit::ppapi::PluginInstance* plugin_instance = | |
| 78 content::GetHostGlobals()->GetInstance(instance); | |
| 79 if (!plugin_instance) | |
| 80 return false; | |
| 81 FilePath plugin_path; | |
| 82 if (!PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_path)) | |
| 83 return false; | |
| 84 if (g_plugin_ppapi_channel.name.empty()) | |
| 85 return false; | |
| 86 | |
| 87 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 88 switches::kEnableNaClIPCProxy)) { | |
|
dmichael (off chromium)
2012/05/10 19:38:58
Maybe you should check for that switch at the begi
bbudge
2012/05/11 01:21:16
Yes indeed.
| |
| 89 WebView* view = | |
| 90 plugin_instance->container()->element().document().frame()->view(); | |
| 91 content::RenderView* render_view = content::RenderView::FromWebView(view); | |
| 92 render_view->CreatePepperHostDispatcher(plugin_path, | |
| 93 g_plugin_process_id, | |
| 94 g_plugin_process_handle, | |
| 95 g_plugin_ppapi_channel); | |
| 96 return true; | |
| 97 } | |
| 98 | |
| 99 return false; | |
| 100 } | |
| 101 | |
| 50 int UrandomFD(void) { | 102 int UrandomFD(void) { |
| 51 #if defined(OS_POSIX) | 103 #if defined(OS_POSIX) |
| 52 return GetUrandomFD(); | 104 return GetUrandomFD(); |
| 53 #else | 105 #else |
| 54 return 0; | 106 return 0; |
| 55 #endif | 107 #endif |
| 56 } | 108 } |
| 57 | 109 |
| 58 bool Are3DInterfacesDisabled() { | 110 bool Are3DInterfacesDisabled() { |
| 59 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisable3DAPIs); | 111 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisable3DAPIs); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 73 return content::BrokerDuplicateHandle(source_handle, process_id, | 125 return content::BrokerDuplicateHandle(source_handle, process_id, |
| 74 target_handle, desired_access, | 126 target_handle, desired_access, |
| 75 options); | 127 options); |
| 76 #else | 128 #else |
| 77 return 0; | 129 return 0; |
| 78 #endif | 130 #endif |
| 79 } | 131 } |
| 80 | 132 |
| 81 const PPB_NaCl_Private nacl_interface = { | 133 const PPB_NaCl_Private nacl_interface = { |
| 82 &LaunchSelLdr, | 134 &LaunchSelLdr, |
| 135 &StartPpapiProxy, | |
| 83 &UrandomFD, | 136 &UrandomFD, |
| 84 &Are3DInterfacesDisabled, | 137 &Are3DInterfacesDisabled, |
| 85 &EnableBackgroundSelLdrLaunch, | 138 &EnableBackgroundSelLdrLaunch, |
| 86 &BrokerDuplicateHandle, | 139 &BrokerDuplicateHandle, |
| 87 }; | 140 }; |
| 88 | 141 |
| 89 } // namespace | 142 } // namespace |
| 90 | 143 |
| 91 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { | 144 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { |
| 92 return &nacl_interface; | 145 return &nacl_interface; |
| 93 } | 146 } |
| 94 | 147 |
| 95 #endif // DISABLE_NACL | 148 #endif // DISABLE_NACL |
| OLD | NEW |