| 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/chrome_ppapi_interfaces.h" | 5 #include "chrome/renderer/pepper/ppb_nacl_private_impl.h" |
| 6 |
| 7 #ifndef DISABLE_NACL |
| 6 | 8 |
| 7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 8 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "base/rand_util_c.h" | 12 #include "base/rand_util_c.h" |
| 11 #include "base/utf_string_conversions.h" | |
| 12 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
| 13 #include "chrome/renderer/chrome_ppb_pdf_impl.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 "ppapi/c/private/ppb_nacl_private.h" | 18 #include "ppapi/c/private/ppb_nacl_private.h" |
| 18 #include "ppapi/c/private/ppb_pdf.h" | |
| 19 #include "webkit/plugins/ppapi/ppapi_interface_factory.h" | |
| 20 | |
| 21 #if !defined(DISABLE_NACL) | |
| 22 #include "native_client/src/shared/imc/nacl_imc.h" | |
| 23 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" | 19 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" |
| 24 #endif | |
| 25 | 20 |
| 26 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
| 27 #include "content/public/common/sandbox_init.h" | 22 #include "content/public/common/sandbox_init.h" |
| 28 #endif | 23 #endif |
| 29 | 24 |
| 30 using content::RenderThread; | 25 namespace { |
| 31 | 26 |
| 32 namespace chrome { | |
| 33 | |
| 34 #if !defined(DISABLE_NACL) | |
| 35 namespace { | |
| 36 base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> > | 27 base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> > |
| 37 g_background_thread_sender = LAZY_INSTANCE_INITIALIZER; | 28 g_background_thread_sender = LAZY_INSTANCE_INITIALIZER; |
| 38 } // namespace | |
| 39 | 29 |
| 40 // Launch NaCl's sel_ldr process. | 30 // Launch NaCl's sel_ldr process. |
| 41 bool LaunchSelLdr(const char* alleged_url, int socket_count, | 31 bool LaunchSelLdr(const char* alleged_url, int socket_count, |
| 42 void* imc_handles, void* nacl_process_handle, | 32 void* imc_handles, void* nacl_process_handle, |
| 43 int* nacl_process_id) { | 33 int* nacl_process_id) { |
| 44 std::vector<nacl::FileDescriptor> sockets; | 34 std::vector<nacl::FileDescriptor> sockets; |
| 45 IPC::Message::Sender* sender = RenderThread::Get(); | 35 IPC::Message::Sender* sender = content::RenderThread::Get(); |
| 46 if (sender == NULL) { | 36 if (sender == NULL) |
| 47 sender = g_background_thread_sender.Pointer()->get(); | 37 sender = g_background_thread_sender.Pointer()->get(); |
| 48 } | 38 |
| 49 if (!sender->Send( | 39 if (!sender->Send(new ChromeViewHostMsg_LaunchNaCl( |
| 50 new ChromeViewHostMsg_LaunchNaCl( | 40 GURL(alleged_url), socket_count, &sockets))) |
| 51 GURL(alleged_url), socket_count, &sockets))) { | |
| 52 return false; | 41 return false; |
| 53 } | 42 |
| 54 CHECK(static_cast<int>(sockets.size()) == socket_count); | 43 CHECK(static_cast<int>(sockets.size()) == socket_count); |
| 55 for (int i = 0; i < socket_count; i++) { | 44 for (int i = 0; i < socket_count; i++) { |
| 56 static_cast<nacl::Handle*>(imc_handles)[i] = | 45 static_cast<nacl::Handle*>(imc_handles)[i] = |
| 57 nacl::ToNativeHandle(sockets[i]); | 46 nacl::ToNativeHandle(sockets[i]); |
| 58 } | 47 } |
| 59 // TODO(mseaborn): Remove the arguments nacl_process_handle and | 48 // TODO(mseaborn): Remove the arguments nacl_process_handle and |
| 60 // nacl_process_id from the interface. | 49 // nacl_process_id from the interface. |
| 61 *reinterpret_cast<base::ProcessHandle*>(nacl_process_handle) = | 50 *reinterpret_cast<base::ProcessHandle*>(nacl_process_handle) = |
| 62 (base::ProcessHandle) -1; | 51 (base::ProcessHandle) -1; |
| 63 *nacl_process_id = 0; | 52 *nacl_process_id = 0; |
| 64 return true; | 53 return true; |
| 65 } | 54 } |
| 66 | 55 |
| 67 int UrandomFD(void) { | 56 int UrandomFD(void) { |
| 68 #if defined(OS_POSIX) | 57 #if defined(OS_POSIX) |
| 69 return GetUrandomFD(); | 58 return GetUrandomFD(); |
| 70 #else | 59 #else |
| 71 return 0; | 60 return 0; |
| 72 #endif | 61 #endif |
| 73 } | 62 } |
| 74 | 63 |
| 75 bool Are3DInterfacesDisabled() { | 64 bool Are3DInterfacesDisabled() { |
| 76 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisable3DAPIs); | 65 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisable3DAPIs); |
| 77 } | 66 } |
| 78 | 67 |
| 79 void EnableBackgroundSelLdrLaunch() { | 68 void EnableBackgroundSelLdrLaunch() { |
| 80 g_background_thread_sender.Get() = | 69 g_background_thread_sender.Get() = |
| 81 RenderThread::Get()->GetSyncMessageFilter(); | 70 content::RenderThread::Get()->GetSyncMessageFilter(); |
| 82 } | 71 } |
| 83 | 72 |
| 84 int BrokerDuplicateHandle(void* source_handle, | 73 int BrokerDuplicateHandle(void* source_handle, |
| 85 unsigned int process_id, | 74 unsigned int process_id, |
| 86 void** target_handle, | 75 void** target_handle, |
| 87 unsigned int desired_access, | 76 unsigned int desired_access, |
| 88 unsigned int options) { | 77 unsigned int options) { |
| 89 #if defined(OS_WIN) | 78 #if defined(OS_WIN) |
| 90 return content::BrokerDuplicateHandle(source_handle, process_id, | 79 return content::BrokerDuplicateHandle(source_handle, process_id, |
| 91 target_handle, desired_access, | 80 target_handle, desired_access, |
| 92 options); | 81 options); |
| 93 #else | 82 #else |
| 94 return 0; | 83 return 0; |
| 95 #endif | 84 #endif |
| 96 } | 85 } |
| 97 | 86 |
| 98 const PPB_NaCl_Private ppb_nacl = { | 87 const PPB_NaCl_Private nacl_interface = { |
| 99 &LaunchSelLdr, | 88 &LaunchSelLdr, |
| 100 &UrandomFD, | 89 &UrandomFD, |
| 101 &Are3DInterfacesDisabled, | 90 &Are3DInterfacesDisabled, |
| 102 &EnableBackgroundSelLdrLaunch, | 91 &EnableBackgroundSelLdrLaunch, |
| 103 &BrokerDuplicateHandle, | 92 &BrokerDuplicateHandle, |
| 104 }; | 93 }; |
| 105 | 94 |
| 106 class PPB_NaCl_Impl { | 95 } // namespace |
| 107 public: | |
| 108 // Returns a pointer to the interface implementing PPB_NaCl_Private that is | |
| 109 // exposed to the plugin. | |
| 110 static const PPB_NaCl_Private* GetInterface() { | |
| 111 return &ppb_nacl; | |
| 112 } | |
| 113 }; | |
| 114 #endif // DISABLE_NACL | |
| 115 | 96 |
| 116 const void* ChromePPAPIInterfaceFactory(const std::string& interface_name) { | 97 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { |
| 117 #if !defined(DISABLE_NACL) | 98 return &nacl_interface; |
| 118 if (interface_name == PPB_NACL_PRIVATE_INTERFACE) | |
| 119 return chrome::PPB_NaCl_Impl::GetInterface(); | |
| 120 #endif // DISABLE_NACL | |
| 121 if (interface_name == PPB_PDF_INTERFACE) | |
| 122 return chrome::PPB_PDF_Impl::GetInterface(); | |
| 123 return NULL; | |
| 124 } | 99 } |
| 125 | 100 |
| 126 } // namespace chrome | 101 #endif // DISABLE_NACL |
| OLD | NEW |