Chromium Code Reviews| 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 #include <numeric> | 7 #include <numeric> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 LAZY_INSTANCE_INITIALIZER; | 106 LAZY_INSTANCE_INITIALIZER; |
| 107 | 107 |
| 108 nacl::NexeLoadManager* GetNexeLoadManager(PP_Instance instance) { | 108 nacl::NexeLoadManager* GetNexeLoadManager(PP_Instance instance) { |
| 109 NexeLoadManagerMap& map = g_load_manager_map.Get(); | 109 NexeLoadManagerMap& map = g_load_manager_map.Get(); |
| 110 NexeLoadManagerMap::iterator iter = map.find(instance); | 110 NexeLoadManagerMap::iterator iter = map.find(instance); |
| 111 if (iter != map.end()) | 111 if (iter != map.end()) |
| 112 return iter->second; | 112 return iter->second; |
| 113 return NULL; | 113 return NULL; |
| 114 } | 114 } |
| 115 | 115 |
| 116 PP_NaClFileInfo MakeInvalidNaClFileInfo() { | |
| 117 const PP_NaClFileInfo kInvalidNaClFileInfo = { | |
|
hidehiko
2014/06/20 04:36:11
nit: Sorry for my poor explanation. I meant that p
| |
| 118 PP_kInvalidFileHandle, | |
| 119 0, // token_lo | |
| 120 0, // token_hi | |
| 121 }; | |
| 122 return kInvalidNaClFileInfo; | |
| 123 } | |
| 124 | |
| 116 int GetRoutingID(PP_Instance instance) { | 125 int GetRoutingID(PP_Instance instance) { |
| 117 // Check that we are on the main renderer thread. | 126 // Check that we are on the main renderer thread. |
| 118 DCHECK(content::RenderThread::Get()); | 127 DCHECK(content::RenderThread::Get()); |
| 119 content::RendererPpapiHost *host = | 128 content::RendererPpapiHost *host = |
| 120 content::RendererPpapiHost::GetForPPInstance(instance); | 129 content::RendererPpapiHost::GetForPPInstance(instance); |
| 121 if (!host) | 130 if (!host) |
| 122 return 0; | 131 return 0; |
| 123 return host->GetRoutingIDForWidget(instance); | 132 return host->GetRoutingIDForWidget(instance); |
| 124 } | 133 } |
| 125 | 134 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 138 return true; | 147 return true; |
| 139 } | 148 } |
| 140 | 149 |
| 141 void PostPPCompletionCallback(PP_CompletionCallback callback, | 150 void PostPPCompletionCallback(PP_CompletionCallback callback, |
| 142 int32_t status) { | 151 int32_t status) { |
| 143 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 152 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 144 FROM_HERE, | 153 FROM_HERE, |
| 145 base::Bind(callback.func, callback.user_data, status)); | 154 base::Bind(callback.func, callback.user_data, status)); |
| 146 } | 155 } |
| 147 | 156 |
| 157 bool ManifestResolveKey(PP_Instance instance, | |
| 158 bool is_helper_process, | |
| 159 const std::string& key, | |
| 160 std::string* full_url, | |
| 161 PP_PNaClOptions* pnacl_options); | |
| 162 | |
| 163 typedef base::Callback<void(int32_t, const PP_NaClFileInfo&)> | |
| 164 DownloadFileCallback; | |
| 165 | |
| 166 void DownloadFile(PP_Instance instance, | |
| 167 const char* url, | |
| 168 DownloadFileCallback callback); | |
|
hidehiko
2014/06/20 04:36:11
Oops, sorry I overlooked this in a last cycle.
con
| |
| 169 | |
| 148 // Thin adapter from PPP_ManifestService to ManifestServiceChannel::Delegate. | 170 // Thin adapter from PPP_ManifestService to ManifestServiceChannel::Delegate. |
| 149 // Note that user_data is managed by the caller of LaunchSelLdr. Please see | 171 // Note that user_data is managed by the caller of LaunchSelLdr. Please see |
| 150 // also PP_ManifestService's comment for more details about resource | 172 // also PP_ManifestService's comment for more details about resource |
| 151 // management. | 173 // management. |
| 152 class ManifestServiceProxy : public ManifestServiceChannel::Delegate { | 174 class ManifestServiceProxy : public ManifestServiceChannel::Delegate { |
| 153 public: | 175 public: |
| 154 ManifestServiceProxy(const PPP_ManifestService* manifest_service, | 176 ManifestServiceProxy(PP_Instance pp_instance, |
| 177 const PPP_ManifestService* manifest_service, | |
| 155 void* user_data) | 178 void* user_data) |
| 156 : manifest_service_(*manifest_service), | 179 : pp_instance_(pp_instance), |
| 180 manifest_service_(*manifest_service), | |
| 157 user_data_(user_data) { | 181 user_data_(user_data) { |
| 158 } | 182 } |
| 159 | 183 |
| 160 virtual ~ManifestServiceProxy() { | 184 virtual ~ManifestServiceProxy() { |
| 161 Quit(); | 185 Quit(); |
| 162 } | 186 } |
| 163 | 187 |
| 164 virtual void StartupInitializationComplete() OVERRIDE { | 188 virtual void StartupInitializationComplete() OVERRIDE { |
| 165 if (!user_data_) | 189 if (!user_data_) |
| 166 return; | 190 return; |
| 167 | 191 |
| 168 if (!PP_ToBool( | 192 if (!PP_ToBool( |
| 169 manifest_service_.StartupInitializationComplete(user_data_))) { | 193 manifest_service_.StartupInitializationComplete(user_data_))) { |
| 170 user_data_ = NULL; | 194 user_data_ = NULL; |
| 171 } | 195 } |
| 172 } | 196 } |
| 173 | 197 |
| 174 virtual void OpenResource( | 198 virtual void OpenResource( |
| 175 const std::string& key, | 199 const std::string& key, |
| 176 const ManifestServiceChannel::OpenResourceCallback& callback) OVERRIDE { | 200 const ManifestServiceChannel::OpenResourceCallback& callback) OVERRIDE { |
| 201 DCHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> | |
| 202 BelongsToCurrentThread()); | |
| 203 | |
| 177 if (!user_data_) | 204 if (!user_data_) |
| 178 return; | 205 return; |
| 179 | 206 |
| 180 // The allocated callback will be freed in DidOpenResource, which is always | 207 std::string url; |
| 181 // called regardless whether OpenResource() succeeds or fails. | 208 // TODO(teravest): Clean up pnacl_options logic in JsonManifest so we don't |
| 182 if (!PP_ToBool(manifest_service_.OpenResource( | 209 // have to initialize it like this here. |
| 183 user_data_, | 210 PP_PNaClOptions pnacl_options; |
| 184 key.c_str(), | 211 pnacl_options.translate = PP_FALSE; |
| 185 DidOpenResource, | 212 pnacl_options.is_debug = PP_FALSE; |
| 186 new ManifestServiceChannel::OpenResourceCallback(callback)))) { | 213 pnacl_options.opt_level = 2; |
| 187 user_data_ = NULL; | 214 if (!ManifestResolveKey(pp_instance_, false, key, &url, &pnacl_options)) { |
| 215 base::MessageLoop::current()->PostTask( | |
| 216 FROM_HERE, | |
| 217 base::Bind(callback, PP_kInvalidFileHandle)); | |
| 218 return; | |
| 188 } | 219 } |
| 220 | |
| 221 // We have to call DidDownloadFile, even if this object is destroyed, so | |
| 222 // that the handle inside PP_NaClFileInfo isn't leaked. This means that the | |
| 223 // callback passed to this function shouldn't have a weak pointer to an | |
| 224 // object either. | |
| 225 // | |
| 226 // TODO(teravest): Make a type like PP_NaClFileInfo to use for DownloadFile | |
| 227 // that would close the file handle on destruction. | |
| 228 DownloadFile(pp_instance_, url.c_str(), | |
| 229 base::Bind(&ManifestServiceProxy::DidDownloadFile, callback)); | |
| 189 } | 230 } |
| 190 | 231 |
| 191 private: | 232 private: |
| 192 static void DidOpenResource(void* user_data, PP_FileHandle file_handle) { | 233 static void DidDownloadFile( |
| 193 scoped_ptr<ManifestServiceChannel::OpenResourceCallback> callback( | 234 ManifestServiceChannel::OpenResourceCallback callback, |
| 194 static_cast<ManifestServiceChannel::OpenResourceCallback*>(user_data)); | 235 int32_t pp_error, |
| 195 callback->Run(file_handle); | 236 const PP_NaClFileInfo& file_info) { |
| 237 if (pp_error != PP_OK) { | |
| 238 callback.Run(base::kInvalidPlatformFileValue); | |
| 239 return; | |
| 240 } | |
| 241 callback.Run(file_info.handle); | |
| 196 } | 242 } |
| 197 | 243 |
| 198 void Quit() { | 244 void Quit() { |
| 199 if (!user_data_) | 245 if (!user_data_) |
| 200 return; | 246 return; |
| 201 | 247 |
| 202 bool result = PP_ToBool(manifest_service_.Quit(user_data_)); | 248 bool result = PP_ToBool(manifest_service_.Quit(user_data_)); |
| 203 DCHECK(!result); | 249 DCHECK(!result); |
| 204 user_data_ = NULL; | 250 user_data_ = NULL; |
| 205 } | 251 } |
| 206 | 252 |
| 253 PP_Instance pp_instance_; | |
| 207 PPP_ManifestService manifest_service_; | 254 PPP_ManifestService manifest_service_; |
| 208 void* user_data_; | 255 void* user_data_; |
| 209 DISALLOW_COPY_AND_ASSIGN(ManifestServiceProxy); | 256 DISALLOW_COPY_AND_ASSIGN(ManifestServiceProxy); |
| 210 }; | 257 }; |
| 211 | 258 |
| 212 blink::WebURLLoader* CreateWebURLLoader(const blink::WebDocument& document, | 259 blink::WebURLLoader* CreateWebURLLoader(const blink::WebDocument& document, |
| 213 const GURL& gurl) { | 260 const GURL& gurl) { |
| 214 blink::WebURLLoaderOptions options; | 261 blink::WebURLLoaderOptions options; |
| 215 options.untrustedHTTP = true; | 262 options.untrustedHTTP = true; |
| 216 | 263 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 void* imc_handle, | 311 void* imc_handle, |
| 265 PP_CompletionCallback callback) { | 312 PP_CompletionCallback callback) { |
| 266 CHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> | 313 CHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> |
| 267 BelongsToCurrentThread()); | 314 BelongsToCurrentThread()); |
| 268 | 315 |
| 269 // Create the manifest service proxy here, so on error case, it will be | 316 // Create the manifest service proxy here, so on error case, it will be |
| 270 // destructed (without passing it to ManifestServiceChannel), and QUIT | 317 // destructed (without passing it to ManifestServiceChannel), and QUIT |
| 271 // will be called in its destructor so that the caller of this function | 318 // will be called in its destructor so that the caller of this function |
| 272 // can free manifest_service_user_data properly. | 319 // can free manifest_service_user_data properly. |
| 273 scoped_ptr<ManifestServiceChannel::Delegate> manifest_service_proxy( | 320 scoped_ptr<ManifestServiceChannel::Delegate> manifest_service_proxy( |
| 274 new ManifestServiceProxy(manifest_service_interface, | 321 new ManifestServiceProxy(instance, |
| 322 manifest_service_interface, | |
| 275 manifest_service_user_data)); | 323 manifest_service_user_data)); |
| 276 | 324 |
| 277 FileDescriptor result_socket; | 325 FileDescriptor result_socket; |
| 278 IPC::Sender* sender = content::RenderThread::Get(); | 326 IPC::Sender* sender = content::RenderThread::Get(); |
| 279 DCHECK(sender); | 327 DCHECK(sender); |
| 280 int routing_id = 0; | 328 int routing_id = 0; |
| 281 // If the nexe uses ppapi APIs, we need a routing ID. | 329 // If the nexe uses ppapi APIs, we need a routing ID. |
| 282 // To get the routing ID, we must be on the main thread. | 330 // To get the routing ID, we must be on the main thread. |
| 283 // Some nexes do not use ppapi and launch from the background thread, | 331 // Some nexes do not use ppapi and launch from the background thread, |
| 284 // so those nexes can skip finding a routing_id. | 332 // so those nexes can skip finding a routing_id. |
| (...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1022 if (load_manager) | 1070 if (load_manager) |
| 1023 load_manager->ReportLoadError(error_info.error, error_info.string); | 1071 load_manager->ReportLoadError(error_info.error, error_info.string); |
| 1024 return PP_FALSE; | 1072 return PP_FALSE; |
| 1025 } | 1073 } |
| 1026 | 1074 |
| 1027 bool ManifestResolveKey(PP_Instance instance, | 1075 bool ManifestResolveKey(PP_Instance instance, |
| 1028 bool is_helper_process, | 1076 bool is_helper_process, |
| 1029 const std::string& key, | 1077 const std::string& key, |
| 1030 std::string* full_url, | 1078 std::string* full_url, |
| 1031 PP_PNaClOptions* pnacl_options) { | 1079 PP_PNaClOptions* pnacl_options) { |
| 1032 // For "helper" processes (llc and ld), we resolve keys manually as there is | 1080 // For "helper" processes (llc and ld, for PNaCl translation), we resolve |
| 1033 // no existing .nmf file to parse. | 1081 // keys manually as there is no existing .nmf file to parse. |
| 1034 if (is_helper_process) { | 1082 if (is_helper_process) { |
| 1035 pnacl_options->translate = PP_FALSE; | 1083 pnacl_options->translate = PP_FALSE; |
| 1036 // We can only resolve keys in the files/ namespace. | 1084 // We can only resolve keys in the files/ namespace. |
| 1037 const std::string kFilesPrefix = "files/"; | 1085 const std::string kFilesPrefix = "files/"; |
| 1038 if (key.find(kFilesPrefix) == std::string::npos) { | 1086 if (key.find(kFilesPrefix) == std::string::npos) { |
| 1039 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 1087 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
| 1040 if (load_manager) | 1088 if (load_manager) |
| 1041 load_manager->ReportLoadError(PP_NACL_ERROR_MANIFEST_RESOLVE_URL, | 1089 load_manager->ReportLoadError(PP_NACL_ERROR_MANIFEST_RESOLVE_URL, |
| 1042 "key did not start with files/"); | 1090 "key did not start with files/"); |
| 1043 return false; | 1091 return false; |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1361 } | 1409 } |
| 1362 | 1410 |
| 1363 if (pp_error == PP_OK && target_file.IsValid()) | 1411 if (pp_error == PP_OK && target_file.IsValid()) |
| 1364 out_file_info->handle = target_file.TakePlatformFile(); | 1412 out_file_info->handle = target_file.TakePlatformFile(); |
| 1365 else | 1413 else |
| 1366 out_file_info->handle = PP_kInvalidFileHandle; | 1414 out_file_info->handle = PP_kInvalidFileHandle; |
| 1367 | 1415 |
| 1368 request.callback.func(request.callback.user_data, pp_error); | 1416 request.callback.func(request.callback.user_data, pp_error); |
| 1369 } | 1417 } |
| 1370 | 1418 |
| 1371 void DownloadFileCompletion(PP_NaClFileInfo* file_info, | 1419 void DownloadFileCompletion( |
| 1372 PP_CompletionCallback callback, | 1420 DownloadFileCallback callback, |
| 1373 FileDownloader::Status status, | 1421 FileDownloader::Status status, |
| 1374 base::File file, | 1422 base::File file, |
| 1375 int http_status) { | 1423 int http_status) { |
| 1376 int32_t pp_error = FileDownloaderToPepperError(status); | 1424 int32_t pp_error = FileDownloaderToPepperError(status); |
| 1425 PP_NaClFileInfo file_info; | |
| 1377 if (pp_error == PP_OK) { | 1426 if (pp_error == PP_OK) { |
| 1378 file_info->handle = file.TakePlatformFile(); | 1427 file_info.handle = file.TakePlatformFile(); |
| 1379 file_info->token_lo = 0; | 1428 file_info.token_lo = 0; |
| 1380 file_info->token_hi = 0; | 1429 file_info.token_hi = 0; |
| 1430 } else { | |
| 1431 file_info = MakeInvalidNaClFileInfo(); | |
| 1381 } | 1432 } |
| 1382 callback.func(callback.user_data, pp_error); | 1433 |
| 1434 callback.Run(pp_error, file_info); | |
| 1383 } | 1435 } |
| 1384 | 1436 |
| 1385 void DownloadFile(PP_Instance instance, | 1437 void DownloadFile(PP_Instance instance, |
| 1386 const char* url, | 1438 const char* url, |
| 1387 struct PP_NaClFileInfo* file_info, | 1439 DownloadFileCallback callback) { |
| 1388 struct PP_CompletionCallback callback) { | 1440 DCHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> |
| 1441 BelongsToCurrentThread()); | |
| 1389 CHECK(url); | 1442 CHECK(url); |
| 1390 CHECK(file_info); | |
| 1391 | 1443 |
| 1392 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 1444 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
| 1393 DCHECK(load_manager); | 1445 DCHECK(load_manager); |
| 1394 if (!load_manager) { | 1446 if (!load_manager) { |
| 1395 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1447 base::MessageLoop::current()->PostTask( |
| 1396 FROM_HERE, | 1448 FROM_HERE, |
| 1397 base::Bind(callback.func, callback.user_data, | 1449 base::Bind(callback, |
| 1398 static_cast<int32_t>(PP_ERROR_FAILED))); | 1450 static_cast<int32_t>(PP_ERROR_FAILED), |
| 1451 MakeInvalidNaClFileInfo())); | |
| 1399 return; | 1452 return; |
| 1400 } | 1453 } |
| 1401 | 1454 |
| 1402 // Handle special PNaCl support files which are installed on the user's | 1455 // Handle special PNaCl support files which are installed on the user's |
| 1403 // machine. | 1456 // machine. |
| 1404 std::string url_string(url); | 1457 std::string url_string(url); |
| 1405 if (url_string.find(kPNaClTranslatorBaseUrl, 0) == 0) { | 1458 if (url_string.find(kPNaClTranslatorBaseUrl, 0) == 0) { |
| 1406 PP_FileHandle handle = GetReadonlyPnaclFd(url); | 1459 PP_FileHandle handle = GetReadonlyPnaclFd(url); |
| 1407 if (handle == PP_kInvalidFileHandle) { | 1460 if (handle == PP_kInvalidFileHandle) { |
| 1408 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1461 base::MessageLoop::current()->PostTask( |
| 1409 FROM_HERE, | 1462 FROM_HERE, |
| 1410 base::Bind(callback.func, callback.user_data, | 1463 base::Bind(callback, |
| 1411 static_cast<int32_t>(PP_ERROR_FAILED))); | 1464 static_cast<int32_t>(PP_ERROR_FAILED), |
| 1465 MakeInvalidNaClFileInfo())); | |
| 1412 return; | 1466 return; |
| 1413 } | 1467 } |
| 1414 // TODO(ncbray): enable the fast loading and validation paths for this type | 1468 // TODO(ncbray): enable the fast loading and validation paths for this type |
| 1415 // of file. | 1469 // of file. |
| 1416 file_info->handle = handle; | 1470 PP_NaClFileInfo file_info; |
| 1417 file_info->token_lo = 0; | 1471 file_info.handle = handle; |
| 1418 file_info->token_hi = 0; | 1472 file_info.token_lo = 0; |
| 1419 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1473 file_info.token_hi = 0; |
| 1474 base::MessageLoop::current()->PostTask( | |
| 1420 FROM_HERE, | 1475 FROM_HERE, |
| 1421 base::Bind(callback.func, callback.user_data, | 1476 base::Bind(callback, static_cast<int32_t>(PP_OK), file_info)); |
| 1422 static_cast<int32_t>(PP_OK))); | |
| 1423 return; | 1477 return; |
| 1424 } | 1478 } |
| 1425 | 1479 |
| 1426 // We have to ensure that this url resolves relative to the plugin base url | 1480 // We have to ensure that this url resolves relative to the plugin base url |
| 1427 // before downloading it. | 1481 // before downloading it. |
| 1428 const GURL& test_gurl = load_manager->plugin_base_url().Resolve(url); | 1482 const GURL& test_gurl = load_manager->plugin_base_url().Resolve(url); |
| 1429 if (!test_gurl.is_valid()) { | 1483 if (!test_gurl.is_valid()) { |
| 1430 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1484 base::MessageLoop::current()->PostTask( |
| 1431 FROM_HERE, | 1485 FROM_HERE, |
| 1432 base::Bind(callback.func, callback.user_data, | 1486 base::Bind(callback, |
| 1433 static_cast<int32_t>(PP_ERROR_FAILED))); | 1487 static_cast<int32_t>(PP_ERROR_FAILED), |
| 1488 MakeInvalidNaClFileInfo())); | |
| 1434 return; | 1489 return; |
| 1435 } | 1490 } |
| 1436 | 1491 |
| 1437 // Try the fast path for retrieving the file first. | 1492 // Try the fast path for retrieving the file first. |
| 1438 uint64_t file_token_lo = 0; | 1493 uint64_t file_token_lo = 0; |
| 1439 uint64_t file_token_hi = 0; | 1494 uint64_t file_token_hi = 0; |
| 1440 PP_FileHandle file_handle = OpenNaClExecutable(instance, | 1495 PP_FileHandle file_handle = OpenNaClExecutable(instance, |
| 1441 url, | 1496 url, |
| 1442 &file_token_lo, | 1497 &file_token_lo, |
| 1443 &file_token_hi); | 1498 &file_token_hi); |
| 1444 if (file_handle != PP_kInvalidFileHandle) { | 1499 if (file_handle != PP_kInvalidFileHandle) { |
| 1445 file_info->handle = file_handle; | 1500 PP_NaClFileInfo file_info; |
| 1446 file_info->token_lo = file_token_lo; | 1501 file_info.handle = file_handle; |
| 1447 file_info->token_hi = file_token_hi; | 1502 file_info.token_lo = file_token_lo; |
| 1448 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1503 file_info.token_hi = file_token_hi; |
| 1504 base::MessageLoop::current()->PostTask( | |
| 1449 FROM_HERE, | 1505 FROM_HERE, |
| 1450 base::Bind(callback.func, callback.user_data, | 1506 base::Bind(callback, static_cast<int32_t>(PP_OK), file_info)); |
| 1451 static_cast<int32_t>(PP_OK))); | |
| 1452 return; | 1507 return; |
| 1453 } | 1508 } |
| 1454 | 1509 |
| 1455 // The fast path didn't work, we'll fetch the file using URLLoader and write | 1510 // The fast path didn't work, we'll fetch the file using URLLoader and write |
| 1456 // it to local storage. | 1511 // it to local storage. |
| 1457 base::File target_file(CreateTemporaryFile(instance)); | 1512 base::File target_file(CreateTemporaryFile(instance)); |
| 1458 GURL gurl(url); | 1513 GURL gurl(url); |
| 1459 | 1514 |
| 1460 content::PepperPluginInstance* plugin_instance = | 1515 content::PepperPluginInstance* plugin_instance = |
| 1461 content::PepperPluginInstance::Get(instance); | 1516 content::PepperPluginInstance::Get(instance); |
| 1462 if (!plugin_instance) { | 1517 if (!plugin_instance) { |
| 1463 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1518 base::MessageLoop::current()->PostTask( |
| 1464 FROM_HERE, | 1519 FROM_HERE, |
| 1465 base::Bind(callback.func, callback.user_data, | 1520 base::Bind(callback, |
| 1466 static_cast<int32_t>(PP_ERROR_FAILED))); | 1521 static_cast<int32_t>(PP_ERROR_FAILED), |
| 1522 MakeInvalidNaClFileInfo())); | |
| 1467 } | 1523 } |
| 1468 const blink::WebDocument& document = | 1524 const blink::WebDocument& document = |
| 1469 plugin_instance->GetContainer()->element().document(); | 1525 plugin_instance->GetContainer()->element().document(); |
| 1470 scoped_ptr<blink::WebURLLoader> url_loader( | 1526 scoped_ptr<blink::WebURLLoader> url_loader( |
| 1471 CreateWebURLLoader(document, gurl)); | 1527 CreateWebURLLoader(document, gurl)); |
| 1472 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); | 1528 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); |
| 1473 | 1529 |
| 1474 ProgressEventRateLimiter* tracker = new ProgressEventRateLimiter(instance); | 1530 ProgressEventRateLimiter* tracker = new ProgressEventRateLimiter(instance); |
| 1475 | 1531 |
| 1476 // FileDownloader deletes itself after invoking DownloadNexeCompletion. | 1532 // FileDownloader deletes itself after invoking DownloadNexeCompletion. |
| 1477 FileDownloader* file_downloader = new FileDownloader( | 1533 FileDownloader* file_downloader = new FileDownloader( |
| 1478 url_loader.Pass(), | 1534 url_loader.Pass(), |
| 1479 target_file.Pass(), | 1535 target_file.Pass(), |
| 1480 base::Bind(&DownloadFileCompletion, file_info, callback), | 1536 base::Bind(&DownloadFileCompletion, callback), |
| 1481 base::Bind(&ProgressEventRateLimiter::ReportProgress, | 1537 base::Bind(&ProgressEventRateLimiter::ReportProgress, |
| 1482 base::Owned(tracker), url)); | 1538 base::Owned(tracker), url)); |
| 1483 file_downloader->Load(url_request); | 1539 file_downloader->Load(url_request); |
| 1484 } | 1540 } |
| 1485 | 1541 |
| 1542 void ExternalDownloadFileCompletion(struct PP_NaClFileInfo* out_file_info, | |
| 1543 struct PP_CompletionCallback callback, | |
| 1544 int32_t pp_error, | |
| 1545 const PP_NaClFileInfo& file_info) { | |
| 1546 if (pp_error == PP_OK) | |
| 1547 *out_file_info = file_info; | |
| 1548 callback.func(callback.user_data, pp_error); | |
| 1549 } | |
| 1550 | |
| 1551 void ExternalDownloadFile(PP_Instance instance, | |
| 1552 const char* url, | |
| 1553 struct PP_NaClFileInfo* file_info, | |
| 1554 struct PP_CompletionCallback callback) { | |
| 1555 DCHECK(callback.func); | |
| 1556 CHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> | |
| 1557 BelongsToCurrentThread()); | |
| 1558 DownloadFile(instance, url, | |
| 1559 base::Bind(&ExternalDownloadFileCompletion, | |
| 1560 file_info, | |
| 1561 callback)); | |
| 1562 } | |
| 1563 | |
| 1486 void ReportSelLdrStatus(PP_Instance instance, | 1564 void ReportSelLdrStatus(PP_Instance instance, |
| 1487 int32_t load_status, | 1565 int32_t load_status, |
| 1488 int32_t max_status) { | 1566 int32_t max_status) { |
| 1489 HistogramEnumerate("NaCl.LoadStatus.SelLdr", load_status, max_status); | 1567 HistogramEnumerate("NaCl.LoadStatus.SelLdr", load_status, max_status); |
| 1490 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 1568 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
| 1491 DCHECK(load_manager); | 1569 DCHECK(load_manager); |
| 1492 if (!load_manager) | 1570 if (!load_manager) |
| 1493 return; | 1571 return; |
| 1494 | 1572 |
| 1495 // Gather data to see if being installed changes load outcomes. | 1573 // Gather data to see if being installed changes load outcomes. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1539 &RequestNaClManifest, | 1617 &RequestNaClManifest, |
| 1540 &GetManifestBaseURL, | 1618 &GetManifestBaseURL, |
| 1541 &ProcessNaClManifest, | 1619 &ProcessNaClManifest, |
| 1542 &DevInterfacesEnabled, | 1620 &DevInterfacesEnabled, |
| 1543 &ManifestGetProgramURL, | 1621 &ManifestGetProgramURL, |
| 1544 &ExternalManifestResolveKey, | 1622 &ExternalManifestResolveKey, |
| 1545 &GetPNaClResourceInfo, | 1623 &GetPNaClResourceInfo, |
| 1546 &GetCpuFeatureAttrs, | 1624 &GetCpuFeatureAttrs, |
| 1547 &PostMessageToJavaScript, | 1625 &PostMessageToJavaScript, |
| 1548 &DownloadNexe, | 1626 &DownloadNexe, |
| 1549 &DownloadFile, | 1627 &ExternalDownloadFile, |
| 1550 &ReportSelLdrStatus, | 1628 &ReportSelLdrStatus, |
| 1551 &LogTranslateTime | 1629 &LogTranslateTime |
| 1552 }; | 1630 }; |
| 1553 | 1631 |
| 1554 } // namespace | 1632 } // namespace |
| 1555 | 1633 |
| 1556 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1634 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
| 1557 return &nacl_interface; | 1635 return &nacl_interface; |
| 1558 } | 1636 } |
| 1559 | 1637 |
| 1560 } // namespace nacl | 1638 } // namespace nacl |
| OLD | NEW |