OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/nacl/renderer/ppb_nacl_private_impl.h" | 5 #include "components/nacl/renderer/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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 // Check that we are on the main renderer thread. | 72 // Check that we are on the main renderer thread. |
73 DCHECK(content::RenderThread::Get()); | 73 DCHECK(content::RenderThread::Get()); |
74 content::RendererPpapiHost *host = | 74 content::RendererPpapiHost *host = |
75 content::RendererPpapiHost::GetForPPInstance(instance); | 75 content::RendererPpapiHost::GetForPPInstance(instance); |
76 if (!host) | 76 if (!host) |
77 return 0; | 77 return 0; |
78 return host->GetRoutingIDForWidget(instance); | 78 return host->GetRoutingIDForWidget(instance); |
79 } | 79 } |
80 | 80 |
81 // Launch NaCl's sel_ldr process. | 81 // Launch NaCl's sel_ldr process. |
82 PP_ExternalPluginResult LaunchSelLdr(PP_Instance instance, | 82 void LaunchSelLdr(PP_Instance instance, |
83 const char* alleged_url, | 83 const char* alleged_url, |
84 PP_Bool uses_irt, | 84 PP_Bool uses_irt, |
85 PP_Bool uses_ppapi, | 85 PP_Bool uses_ppapi, |
86 PP_Bool enable_ppapi_dev, | 86 PP_Bool enable_ppapi_dev, |
87 PP_Bool enable_dyncode_syscalls, | 87 PP_Bool enable_dyncode_syscalls, |
88 PP_Bool enable_exception_handling, | 88 PP_Bool enable_exception_handling, |
89 PP_Bool enable_crash_throttling, | 89 PP_Bool enable_crash_throttling, |
90 void* imc_handle, | 90 void* imc_handle, |
91 struct PP_Var* error_message) { | 91 struct PP_Var* error_message, |
| 92 PP_CompletionCallback callback) { |
92 nacl::FileDescriptor result_socket; | 93 nacl::FileDescriptor result_socket; |
93 IPC::Sender* sender = content::RenderThread::Get(); | 94 IPC::Sender* sender = content::RenderThread::Get(); |
94 DCHECK(sender); | 95 DCHECK(sender); |
95 *error_message = PP_MakeUndefined(); | 96 *error_message = PP_MakeUndefined(); |
96 int routing_id = 0; | 97 int routing_id = 0; |
97 // If the nexe uses ppapi APIs, we need a routing ID. | 98 // If the nexe uses ppapi APIs, we need a routing ID. |
98 // To get the routing ID, we must be on the main thread. | 99 // To get the routing ID, we must be on the main thread. |
99 // Some nexes do not use ppapi and launch from the background thread, | 100 // Some nexes do not use ppapi and launch from the background thread, |
100 // so those nexes can skip finding a routing_id. | 101 // so those nexes can skip finding a routing_id. |
101 if (uses_ppapi) { | 102 if (uses_ppapi) { |
102 routing_id = GetRoutingID(instance); | 103 routing_id = GetRoutingID(instance); |
103 if (!routing_id) | 104 if (!routing_id) { |
104 return PP_EXTERNAL_PLUGIN_FAILED; | 105 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 106 FROM_HERE, |
| 107 base::Bind(callback.func, callback.user_data, |
| 108 static_cast<int32_t>(PP_ERROR_FAILED))); |
| 109 return; |
| 110 } |
105 } | 111 } |
106 | 112 |
107 InstanceInfo instance_info; | 113 InstanceInfo instance_info; |
108 instance_info.url = GURL(alleged_url); | 114 instance_info.url = GURL(alleged_url); |
109 | 115 |
110 uint32_t perm_bits = ppapi::PERMISSION_NONE; | 116 uint32_t perm_bits = ppapi::PERMISSION_NONE; |
111 // Conditionally block 'Dev' interfaces. We do this for the NaCl process, so | 117 // Conditionally block 'Dev' interfaces. We do this for the NaCl process, so |
112 // it's clearer to developers when they are using 'Dev' inappropriately. We | 118 // it's clearer to developers when they are using 'Dev' inappropriately. We |
113 // must also check on the trusted side of the proxy. | 119 // must also check on the trusted side of the proxy. |
114 if (enable_ppapi_dev) | 120 if (enable_ppapi_dev) |
115 perm_bits |= ppapi::PERMISSION_DEV; | 121 perm_bits |= ppapi::PERMISSION_DEV; |
116 instance_info.permissions = | 122 instance_info.permissions = |
117 ppapi::PpapiPermissions::GetForCommandLine(perm_bits); | 123 ppapi::PpapiPermissions::GetForCommandLine(perm_bits); |
118 std::string error_message_string; | 124 std::string error_message_string; |
119 nacl::NaClLaunchResult launch_result; | 125 nacl::NaClLaunchResult launch_result; |
120 | 126 |
121 if (!sender->Send(new NaClHostMsg_LaunchNaCl( | 127 if (!sender->Send(new NaClHostMsg_LaunchNaCl( |
122 nacl::NaClLaunchParams(instance_info.url.spec(), | 128 nacl::NaClLaunchParams(instance_info.url.spec(), |
123 routing_id, | 129 routing_id, |
124 perm_bits, | 130 perm_bits, |
125 PP_ToBool(uses_irt), | 131 PP_ToBool(uses_irt), |
126 PP_ToBool(enable_dyncode_syscalls), | 132 PP_ToBool(enable_dyncode_syscalls), |
127 PP_ToBool(enable_exception_handling), | 133 PP_ToBool(enable_exception_handling), |
128 PP_ToBool(enable_crash_throttling)), | 134 PP_ToBool(enable_crash_throttling)), |
129 &launch_result, | 135 &launch_result, |
130 &error_message_string))) { | 136 &error_message_string))) { |
131 return PP_EXTERNAL_PLUGIN_FAILED; | 137 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 138 FROM_HERE, |
| 139 base::Bind(callback.func, callback.user_data, |
| 140 static_cast<int32_t>(PP_ERROR_FAILED))); |
| 141 return; |
132 } | 142 } |
133 if (!error_message_string.empty()) { | 143 if (!error_message_string.empty()) { |
134 *error_message = ppapi::StringVar::StringToPPVar(error_message_string); | 144 *error_message = ppapi::StringVar::StringToPPVar(error_message_string); |
135 return PP_EXTERNAL_PLUGIN_FAILED; | 145 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 146 FROM_HERE, |
| 147 base::Bind(callback.func, callback.user_data, |
| 148 static_cast<int32_t>(PP_ERROR_FAILED))); |
| 149 return; |
136 } | 150 } |
137 result_socket = launch_result.imc_channel_handle; | 151 result_socket = launch_result.imc_channel_handle; |
138 instance_info.channel_handle = launch_result.ipc_channel_handle; | 152 instance_info.channel_handle = launch_result.ipc_channel_handle; |
139 instance_info.plugin_pid = launch_result.plugin_pid; | 153 instance_info.plugin_pid = launch_result.plugin_pid; |
140 instance_info.plugin_child_id = launch_result.plugin_child_id; | 154 instance_info.plugin_child_id = launch_result.plugin_child_id; |
141 // Don't save instance_info if channel handle is invalid. | 155 // Don't save instance_info if channel handle is invalid. |
142 bool invalid_handle = instance_info.channel_handle.name.empty(); | 156 bool invalid_handle = instance_info.channel_handle.name.empty(); |
143 #if defined(OS_POSIX) | 157 #if defined(OS_POSIX) |
144 if (!invalid_handle) | 158 if (!invalid_handle) |
145 invalid_handle = (instance_info.channel_handle.socket.fd == -1); | 159 invalid_handle = (instance_info.channel_handle.socket.fd == -1); |
146 #endif | 160 #endif |
147 if (!invalid_handle) | 161 if (!invalid_handle) |
148 g_instance_info.Get()[instance] = instance_info; | 162 g_instance_info.Get()[instance] = instance_info; |
149 | 163 |
150 *(static_cast<NaClHandle*>(imc_handle)) = | 164 *(static_cast<NaClHandle*>(imc_handle)) = |
151 nacl::ToNativeHandle(result_socket); | 165 nacl::ToNativeHandle(result_socket); |
152 | 166 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
153 return PP_EXTERNAL_PLUGIN_OK; | 167 FROM_HERE, |
| 168 base::Bind(callback.func, callback.user_data, |
| 169 static_cast<int32_t>(PP_OK))); |
154 } | 170 } |
155 | 171 |
156 PP_ExternalPluginResult StartPpapiProxy(PP_Instance instance) { | 172 PP_ExternalPluginResult StartPpapiProxy(PP_Instance instance) { |
157 InstanceInfoMap& map = g_instance_info.Get(); | 173 InstanceInfoMap& map = g_instance_info.Get(); |
158 InstanceInfoMap::iterator it = map.find(instance); | 174 InstanceInfoMap::iterator it = map.find(instance); |
159 if (it == map.end()) { | 175 if (it == map.end()) { |
160 DLOG(ERROR) << "Could not find instance ID"; | 176 DLOG(ERROR) << "Could not find instance ID"; |
161 return PP_EXTERNAL_PLUGIN_FAILED; | 177 return PP_EXTERNAL_PLUGIN_FAILED; |
162 } | 178 } |
163 InstanceInfo instance_info = it->second; | 179 InstanceInfo instance_info = it->second; |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 | 477 |
462 namespace nacl { | 478 namespace nacl { |
463 | 479 |
464 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 480 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
465 return &nacl_interface; | 481 return &nacl_interface; |
466 } | 482 } |
467 | 483 |
468 } // namespace nacl | 484 } // namespace nacl |
469 | 485 |
470 #endif // DISABLE_NACL | 486 #endif // DISABLE_NACL |
OLD | NEW |