| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/renderer/chrome_ppapi_interfaces.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/lazy_instance.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "base/rand_util_c.h" | |
| 11 #include "base/utf_string_conversions.h" | |
| 12 #include "chrome/common/render_messages.h" | |
| 13 #include "chrome/renderer/chrome_ppb_pdf_impl.h" | |
| 14 #include "content/public/common/content_switches.h" | |
| 15 #include "content/public/renderer/render_thread.h" | |
| 16 #include "ipc/ipc_sync_message_filter.h" | |
| 17 #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" | |
| 24 #endif | |
| 25 | |
| 26 #if defined(OS_WIN) | |
| 27 #include "content/public/common/sandbox_init.h" | |
| 28 #endif | |
| 29 | |
| 30 using content::RenderThread; | |
| 31 | |
| 32 namespace chrome { | |
| 33 | |
| 34 #if !defined(DISABLE_NACL) | |
| 35 namespace { | |
| 36 base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> > | |
| 37 g_background_thread_sender = LAZY_INSTANCE_INITIALIZER; | |
| 38 } // namespace | |
| 39 | |
| 40 // Launch NaCl's sel_ldr process. | |
| 41 bool LaunchSelLdr(const char* alleged_url, int socket_count, | |
| 42 void* imc_handles, void* nacl_process_handle, | |
| 43 int* nacl_process_id) { | |
| 44 std::vector<nacl::FileDescriptor> sockets; | |
| 45 IPC::Message::Sender* sender = RenderThread::Get(); | |
| 46 if (sender == NULL) { | |
| 47 sender = g_background_thread_sender.Pointer()->get(); | |
| 48 } | |
| 49 if (!sender->Send( | |
| 50 new ChromeViewHostMsg_LaunchNaCl( | |
| 51 GURL(alleged_url), socket_count, &sockets))) { | |
| 52 return false; | |
| 53 } | |
| 54 CHECK(static_cast<int>(sockets.size()) == socket_count); | |
| 55 for (int i = 0; i < socket_count; i++) { | |
| 56 static_cast<nacl::Handle*>(imc_handles)[i] = | |
| 57 nacl::ToNativeHandle(sockets[i]); | |
| 58 } | |
| 59 // TODO(mseaborn): Remove the arguments nacl_process_handle and | |
| 60 // nacl_process_id from the interface. | |
| 61 *reinterpret_cast<base::ProcessHandle*>(nacl_process_handle) = | |
| 62 (base::ProcessHandle) -1; | |
| 63 *nacl_process_id = 0; | |
| 64 return true; | |
| 65 } | |
| 66 | |
| 67 int UrandomFD(void) { | |
| 68 #if defined(OS_POSIX) | |
| 69 return GetUrandomFD(); | |
| 70 #else | |
| 71 return 0; | |
| 72 #endif | |
| 73 } | |
| 74 | |
| 75 bool Are3DInterfacesDisabled() { | |
| 76 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisable3DAPIs); | |
| 77 } | |
| 78 | |
| 79 void EnableBackgroundSelLdrLaunch() { | |
| 80 g_background_thread_sender.Get() = | |
| 81 RenderThread::Get()->GetSyncMessageFilter(); | |
| 82 } | |
| 83 | |
| 84 int BrokerDuplicateHandle(void* source_handle, | |
| 85 unsigned int process_id, | |
| 86 void** target_handle, | |
| 87 unsigned int desired_access, | |
| 88 unsigned int options) { | |
| 89 #if defined(OS_WIN) | |
| 90 return content::BrokerDuplicateHandle(source_handle, process_id, | |
| 91 target_handle, desired_access, | |
| 92 options); | |
| 93 #else | |
| 94 return 0; | |
| 95 #endif | |
| 96 } | |
| 97 | |
| 98 const PPB_NaCl_Private ppb_nacl = { | |
| 99 &LaunchSelLdr, | |
| 100 &UrandomFD, | |
| 101 &Are3DInterfacesDisabled, | |
| 102 &EnableBackgroundSelLdrLaunch, | |
| 103 &BrokerDuplicateHandle, | |
| 104 }; | |
| 105 | |
| 106 class PPB_NaCl_Impl { | |
| 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 | |
| 116 const void* ChromePPAPIInterfaceFactory(const std::string& interface_name) { | |
| 117 #if !defined(DISABLE_NACL) | |
| 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 } | |
| 125 | |
| 126 } // namespace chrome | |
| OLD | NEW |