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" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 }; | 50 }; |
51 | 51 |
52 typedef std::map<PP_Instance, InstanceInfo> InstanceInfoMap; | 52 typedef std::map<PP_Instance, InstanceInfo> InstanceInfoMap; |
53 | 53 |
54 base::LazyInstance<InstanceInfoMap> g_instance_info = | 54 base::LazyInstance<InstanceInfoMap> g_instance_info = |
55 LAZY_INSTANCE_INITIALIZER; | 55 LAZY_INSTANCE_INITIALIZER; |
56 | 56 |
57 // Launch NaCl's sel_ldr process. | 57 // Launch NaCl's sel_ldr process. |
58 PP_NaClResult LaunchSelLdr(PP_Instance instance, | 58 PP_NaClResult LaunchSelLdr(PP_Instance instance, |
59 const char* alleged_url, | 59 const char* alleged_url, |
| 60 PP_Bool uses_ppapi, |
60 PP_Bool enable_ppapi_dev, | 61 PP_Bool enable_ppapi_dev, |
61 int socket_count, | 62 int socket_count, |
62 void* imc_handles) { | 63 void* imc_handles) { |
63 std::vector<nacl::FileDescriptor> sockets; | 64 std::vector<nacl::FileDescriptor> sockets; |
64 IPC::Sender* sender = content::RenderThread::Get(); | 65 IPC::Sender* sender = content::RenderThread::Get(); |
65 if (sender == NULL) | 66 if (sender == NULL) |
66 sender = g_background_thread_sender.Pointer()->get(); | 67 sender = g_background_thread_sender.Pointer()->get(); |
67 | 68 |
68 webkit::ppapi::PluginInstance* plugin_instance = | 69 int routing_id = 0; |
69 content::GetHostGlobals()->GetInstance(instance); | 70 // If the nexe uses ppapi APIs, we need a routing ID. |
70 if (!plugin_instance) | 71 // To get the routing ID, we must be on the main thread. |
71 return PP_NACL_FAILED; | 72 // Some nexes do not use ppapi and launch from the background thread, |
| 73 // so those nexes can skip finding a routing_id. |
| 74 if (uses_ppapi) { |
| 75 // Check that we are on the main renderer thread. |
| 76 CHECK(content::RenderThread::Get()); |
| 77 webkit::ppapi::PluginInstance* plugin_instance = |
| 78 content::GetHostGlobals()->GetInstance(instance); |
| 79 if (!plugin_instance) |
| 80 return PP_NACL_FAILED; |
72 | 81 |
73 WebKit::WebView* web_view = | 82 WebKit::WebView* web_view = |
74 plugin_instance->container()->element().document().frame()->view(); | 83 plugin_instance->container()->element().document().frame()->view(); |
75 content::RenderView* render_view = | 84 content::RenderView* render_view = |
76 content::RenderView::FromWebView(web_view); | 85 content::RenderView::FromWebView(web_view); |
77 if (!render_view) | 86 if (!render_view) |
78 return PP_NACL_FAILED; | 87 return PP_NACL_FAILED; |
| 88 routing_id = render_view->GetRoutingID(); |
| 89 } |
79 | 90 |
80 InstanceInfo instance_info; | 91 InstanceInfo instance_info; |
81 instance_info.url = GURL(alleged_url); | 92 instance_info.url = GURL(alleged_url); |
82 | 93 |
83 uint32_t perm_bits = ppapi::PERMISSION_NONE; | 94 uint32_t perm_bits = ppapi::PERMISSION_NONE; |
84 // Conditionally block 'Dev' interfaces. We do this for the NaCl process, so | 95 // Conditionally block 'Dev' interfaces. We do this for the NaCl process, so |
85 // it's clearer to developers when they are using 'Dev' inappropriately. We | 96 // it's clearer to developers when they are using 'Dev' inappropriately. We |
86 // must also check on the trusted side of the proxy. | 97 // must also check on the trusted side of the proxy. |
87 // TODO(bbudge) verify we're blocking 'Dev' interfaces on the trusted side. | 98 // TODO(bbudge) verify we're blocking 'Dev' interfaces on the trusted side. |
88 if (enable_ppapi_dev) | 99 if (enable_ppapi_dev) |
89 perm_bits |= ppapi::PERMISSION_DEV; | 100 perm_bits |= ppapi::PERMISSION_DEV; |
90 instance_info.permissions = ppapi::PpapiPermissions(perm_bits); | 101 instance_info.permissions = ppapi::PpapiPermissions(perm_bits); |
91 | 102 |
92 if (!sender->Send(new ChromeViewHostMsg_LaunchNaCl( | 103 if (!sender->Send(new ChromeViewHostMsg_LaunchNaCl( |
93 instance_info.url, | 104 instance_info.url, |
94 render_view->GetRoutingID(), | 105 routing_id, |
95 perm_bits, | 106 perm_bits, |
96 socket_count, &sockets, | 107 socket_count, &sockets, |
97 &instance_info.channel_handle, | 108 &instance_info.channel_handle, |
98 &instance_info.plugin_child_id))) { | 109 &instance_info.plugin_child_id))) { |
99 return PP_NACL_FAILED; | 110 return PP_NACL_FAILED; |
100 } | 111 } |
101 | 112 |
102 // Don't save instance_info if channel handle is invalid. | 113 // Don't save instance_info if channel handle is invalid. |
103 bool invalid_handle = instance_info.channel_handle.name.empty(); | 114 bool invalid_handle = instance_info.channel_handle.name.empty(); |
104 #if defined(OS_POSIX) | 115 #if defined(OS_POSIX) |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 &IsPnaclEnabled | 265 &IsPnaclEnabled |
255 }; | 266 }; |
256 | 267 |
257 } // namespace | 268 } // namespace |
258 | 269 |
259 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { | 270 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { |
260 return &nacl_interface; | 271 return &nacl_interface; |
261 } | 272 } |
262 | 273 |
263 #endif // DISABLE_NACL | 274 #endif // DISABLE_NACL |
OLD | NEW |