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/chrome_ppapi_interfaces.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/rand_util_c.h" | 10 #include "base/rand_util_c.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/common/render_messages.h" | 12 #include "chrome/common/render_messages.h" |
13 #include "chrome/renderer/chrome_ppb_pdf_impl.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 "ppapi/c/private/ppb_nacl_private.h" | 17 #include "ppapi/c/private/ppb_nacl_private.h" |
18 #include "ppapi/c/private/ppb_pdf.h" | 18 #include "ppapi/c/private/ppb_pdf.h" |
19 #include "webkit/plugins/ppapi/ppapi_interface_factory.h" | 19 #include "webkit/plugins/ppapi/ppapi_interface_factory.h" |
20 | 20 |
21 #if !defined(DISABLE_NACL) | 21 #if !defined(DISABLE_NACL) |
22 #include "native_client/src/shared/imc/nacl_imc.h" | 22 #include "native_client/src/shared/imc/nacl_imc.h" |
23 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" | 23 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" |
24 #endif | 24 #endif |
25 | 25 |
26 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
27 #include "content/public/common/sandbox_init.h" | 27 #include "content/public/common/sandbox_init.h" |
28 #endif | 28 #endif |
29 | 29 |
| 30 #include "base/path_service.h" |
| 31 #include "chrome/common/chrome_paths.h" |
| 32 #include "content/public/browser/plugin_service.h" |
| 33 #include "content/public/common/content_client.h" |
| 34 #include "content/public/renderer/render_thread.h" |
| 35 #include "content/public/renderer/render_view.h" |
| 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 39 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
| 40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 42 #include "webkit/plugins/ppapi/host_globals.h" |
| 43 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 44 |
30 using content::RenderThread; | 45 using content::RenderThread; |
| 46 using webkit::ppapi::HostGlobals; |
| 47 using webkit::ppapi::PluginInstance; |
| 48 using WebKit::WebElement; |
| 49 using WebKit::WebView; |
31 | 50 |
32 namespace chrome { | 51 namespace chrome { |
33 | 52 |
34 #if !defined(DISABLE_NACL) | 53 #if !defined(DISABLE_NACL) |
35 namespace { | 54 namespace { |
36 base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> > | 55 base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> > |
37 g_background_thread_sender = LAZY_INSTANCE_INITIALIZER; | 56 g_background_thread_sender = LAZY_INSTANCE_INITIALIZER; |
38 } // namespace | 57 } // namespace |
39 | 58 |
40 // Launch NaCl's sel_ldr process. | 59 // Launch NaCl's sel_ldr process. |
41 bool LaunchSelLdr(const char* alleged_url, int socket_count, | 60 bool LaunchSelLdr(PP_Instance instance, |
| 61 const char* alleged_url, int socket_count, |
42 void* imc_handles, void* nacl_process_handle, | 62 void* imc_handles, void* nacl_process_handle, |
43 int* nacl_process_id) { | 63 int* nacl_process_id) { |
44 std::vector<nacl::FileDescriptor> sockets; | 64 std::vector<nacl::FileDescriptor> sockets; |
| 65 std::string ppapi_channel_name; |
45 base::ProcessHandle nacl_process; | 66 base::ProcessHandle nacl_process; |
46 IPC::Message::Sender* sender = RenderThread::Get(); | 67 IPC::Message::Sender* sender = RenderThread::Get(); |
47 if (sender == NULL) { | 68 if (sender == NULL) { |
48 sender = g_background_thread_sender.Pointer()->get(); | 69 sender = g_background_thread_sender.Pointer()->get(); |
49 } | 70 } |
50 if (!sender->Send( | 71 if (!sender->Send( |
51 new ChromeViewHostMsg_LaunchNaCl( | 72 new ChromeViewHostMsg_LaunchNaCl( |
52 GURL(alleged_url), | 73 GURL(alleged_url), |
53 socket_count, | 74 socket_count, |
54 &sockets, | 75 &sockets, |
| 76 &ppapi_channel_name, |
55 &nacl_process, | 77 &nacl_process, |
56 reinterpret_cast<base::ProcessId*>(nacl_process_id)))) { | 78 reinterpret_cast<base::ProcessId*>(nacl_process_id)))) { |
57 return false; | 79 return false; |
58 } | 80 } |
59 CHECK(static_cast<int>(sockets.size()) == socket_count); | 81 CHECK(static_cast<int>(sockets.size()) == socket_count); |
60 for (int i = 0; i < socket_count; i++) { | 82 for (int i = 0; i < socket_count; i++) { |
61 static_cast<nacl::Handle*>(imc_handles)[i] = | 83 static_cast<nacl::Handle*>(imc_handles)[i] = |
62 nacl::ToNativeHandle(sockets[i]); | 84 nacl::ToNativeHandle(sockets[i]); |
63 } | 85 } |
64 *static_cast<nacl::Handle*>(nacl_process_handle) = nacl_process; | 86 *static_cast<nacl::Handle*>(nacl_process_handle) = nacl_process; |
| 87 |
| 88 // Using the RenderView, establish the HostDispatcher for the PPAPI proxy. |
| 89 webkit::ppapi::PluginInstance* plugin_instance = |
| 90 content::GetHostGlobals()->GetInstance(instance); |
| 91 if (!plugin_instance) |
| 92 return false; |
| 93 FilePath nacl_plugin_path; |
| 94 if (!PathService::Get(chrome::FILE_NACL_PLUGIN, &nacl_plugin_path)) |
| 95 return false; |
| 96 |
| 97 WebView* view = |
| 98 plugin_instance->container()->element().document().frame()->view(); |
| 99 content::RenderView* render_view = content::RenderView::FromWebView(view); |
| 100 render_view->CreateHostDispatcher( |
| 101 nacl_plugin_path, *nacl_process_id, nacl_process, ppapi_channel_name); |
65 return true; | 102 return true; |
66 } | 103 } |
67 | 104 |
68 int UrandomFD(void) { | 105 int UrandomFD(void) { |
69 #if defined(OS_POSIX) | 106 #if defined(OS_POSIX) |
70 return GetUrandomFD(); | 107 return GetUrandomFD(); |
71 #else | 108 #else |
72 return 0; | 109 return 0; |
73 #endif | 110 #endif |
74 } | 111 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 #if !defined(DISABLE_NACL) | 155 #if !defined(DISABLE_NACL) |
119 if (interface_name == PPB_NACL_PRIVATE_INTERFACE) | 156 if (interface_name == PPB_NACL_PRIVATE_INTERFACE) |
120 return chrome::PPB_NaCl_Impl::GetInterface(); | 157 return chrome::PPB_NaCl_Impl::GetInterface(); |
121 #endif // DISABLE_NACL | 158 #endif // DISABLE_NACL |
122 if (interface_name == PPB_PDF_INTERFACE) | 159 if (interface_name == PPB_PDF_INTERFACE) |
123 return chrome::PPB_PDF_Impl::GetInterface(); | 160 return chrome::PPB_PDF_Impl::GetInterface(); |
124 return NULL; | 161 return NULL; |
125 } | 162 } |
126 | 163 |
127 } // namespace chrome | 164 } // namespace chrome |
OLD | NEW |