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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 | 275 |
276 blink::WebURLRequest CreateWebURLRequest(const blink::WebDocument& document, | 276 blink::WebURLRequest CreateWebURLRequest(const blink::WebDocument& document, |
277 const GURL& gurl) { | 277 const GURL& gurl) { |
278 blink::WebURLRequest request; | 278 blink::WebURLRequest request; |
279 request.initialize(); | 279 request.initialize(); |
280 request.setURL(gurl); | 280 request.setURL(gurl); |
281 request.setFirstPartyForCookies(document.firstPartyForCookies()); | 281 request.setFirstPartyForCookies(document.firstPartyForCookies()); |
282 return request; | 282 return request; |
283 } | 283 } |
284 | 284 |
285 int32_t FileDownloaderToPepperError(FileDownloader::Status status) { | |
286 switch (status) { | |
287 case FileDownloader::SUCCESS: | |
288 return PP_OK; | |
289 case FileDownloader::ACCESS_DENIED: | |
290 return PP_ERROR_NOACCESS; | |
291 case FileDownloader::FAILED: | |
292 return PP_ERROR_FAILED; | |
293 default: | |
bbudge
2014/05/22 17:14:16
Leave out the default and it will catch if someone
| |
294 NOTREACHED(); | |
295 return PP_ERROR_FAILED; | |
296 } | |
297 } | |
298 | |
285 // Launch NaCl's sel_ldr process. | 299 // Launch NaCl's sel_ldr process. |
286 void LaunchSelLdr(PP_Instance instance, | 300 void LaunchSelLdr(PP_Instance instance, |
287 PP_Bool main_service_runtime, | 301 PP_Bool main_service_runtime, |
288 const char* alleged_url, | 302 const char* alleged_url, |
289 PP_Bool uses_irt, | 303 PP_Bool uses_irt, |
290 PP_Bool uses_ppapi, | 304 PP_Bool uses_ppapi, |
291 PP_Bool uses_nonsfi_mode, | 305 PP_Bool uses_nonsfi_mode, |
292 PP_Bool enable_ppapi_dev, | 306 PP_Bool enable_ppapi_dev, |
293 PP_Bool enable_dyncode_syscalls, | 307 PP_Bool enable_dyncode_syscalls, |
294 PP_Bool enable_exception_handling, | 308 PP_Bool enable_exception_handling, |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
879 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 893 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
880 DCHECK(load_manager); | 894 DCHECK(load_manager); |
881 if (!load_manager) | 895 if (!load_manager) |
882 return PP_MakeUndefined(); | 896 return PP_MakeUndefined(); |
883 const GURL& gurl = load_manager->manifest_base_url(); | 897 const GURL& gurl = load_manager->manifest_base_url(); |
884 if (!gurl.is_valid()) | 898 if (!gurl.is_valid()) |
885 return PP_MakeUndefined(); | 899 return PP_MakeUndefined(); |
886 return ppapi::StringVar::StringToPPVar(gurl.spec()); | 900 return ppapi::StringVar::StringToPPVar(gurl.spec()); |
887 } | 901 } |
888 | 902 |
889 PP_Bool ResolvesRelativeToPluginBaseURL(PP_Instance instance, | |
890 const char *url) { | |
891 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | |
892 DCHECK(load_manager); | |
893 if (!load_manager) | |
894 return PP_FALSE; | |
895 const GURL& gurl = load_manager->plugin_base_url().Resolve(url); | |
896 if (!gurl.is_valid()) | |
897 return PP_FALSE; | |
898 return PP_TRUE; | |
899 } | |
900 | |
901 void ProcessNaClManifest(PP_Instance instance, const char* program_url) { | 903 void ProcessNaClManifest(PP_Instance instance, const char* program_url) { |
902 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 904 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
903 if (load_manager) | 905 if (load_manager) |
904 load_manager->ProcessNaClManifest(program_url); | 906 load_manager->ProcessNaClManifest(program_url); |
905 } | 907 } |
906 | 908 |
907 PP_Var GetManifestURLArgument(PP_Instance instance) { | 909 PP_Var GetManifestURLArgument(PP_Instance instance) { |
908 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 910 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
909 if (load_manager) { | 911 if (load_manager) { |
910 return ppapi::StringVar::StringToPPVar( | 912 return ppapi::StringVar::StringToPPVar( |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1380 base::Bind(&ProgressEventRateLimiter::ReportProgress, | 1382 base::Bind(&ProgressEventRateLimiter::ReportProgress, |
1381 base::Owned(tracker), url)); | 1383 base::Owned(tracker), url)); |
1382 file_downloader->Load(url_request); | 1384 file_downloader->Load(url_request); |
1383 } | 1385 } |
1384 | 1386 |
1385 void DownloadNexeCompletion(const DownloadNexeRequest& request, | 1387 void DownloadNexeCompletion(const DownloadNexeRequest& request, |
1386 base::PlatformFile target_file, | 1388 base::PlatformFile target_file, |
1387 PP_FileHandle* out_handle, | 1389 PP_FileHandle* out_handle, |
1388 FileDownloader::Status status, | 1390 FileDownloader::Status status, |
1389 int http_status) { | 1391 int http_status) { |
1390 int32_t pp_error; | 1392 int32_t pp_error = FileDownloaderToPepperError(status); |
1391 switch (status) { | 1393 if (pp_error == PP_OK) |
1392 case FileDownloader::SUCCESS: | 1394 *out_handle = target_file; |
1393 *out_handle = target_file; | |
1394 pp_error = PP_OK; | |
1395 break; | |
1396 case FileDownloader::ACCESS_DENIED: | |
1397 pp_error = PP_ERROR_NOACCESS; | |
1398 break; | |
1399 case FileDownloader::FAILED: | |
1400 pp_error = PP_ERROR_FAILED; | |
1401 break; | |
1402 default: | |
1403 NOTREACHED(); | |
1404 return; | |
1405 } | |
1406 | 1395 |
1407 int64_t bytes_read = -1; | 1396 int64_t bytes_read = -1; |
1408 if (pp_error == PP_OK && target_file != base::kInvalidPlatformFileValue) { | 1397 if (pp_error == PP_OK && target_file != base::kInvalidPlatformFileValue) { |
1409 base::PlatformFileInfo info; | 1398 base::PlatformFileInfo info; |
1410 if (GetPlatformFileInfo(target_file, &info)) | 1399 if (GetPlatformFileInfo(target_file, &info)) |
1411 bytes_read = info.size; | 1400 bytes_read = info.size; |
1412 } | 1401 } |
1413 | 1402 |
1414 if (bytes_read == -1) { | 1403 if (bytes_read == -1) { |
1415 base::ClosePlatformFile(target_file); | 1404 base::ClosePlatformFile(target_file); |
1416 pp_error = PP_ERROR_FAILED; | 1405 pp_error = PP_ERROR_FAILED; |
1417 } | 1406 } |
1418 | 1407 |
1419 base::TimeDelta download_time = base::Time::Now() - request.start_time; | 1408 base::TimeDelta download_time = base::Time::Now() - request.start_time; |
1420 | 1409 |
1421 NexeLoadManager* load_manager = GetNexeLoadManager(request.instance); | 1410 NexeLoadManager* load_manager = GetNexeLoadManager(request.instance); |
1422 if (load_manager) { | 1411 if (load_manager) { |
1423 load_manager->NexeFileDidOpen(pp_error, | 1412 load_manager->NexeFileDidOpen(pp_error, |
1424 target_file, | 1413 target_file, |
1425 http_status, | 1414 http_status, |
1426 bytes_read, | 1415 bytes_read, |
1427 request.url, | 1416 request.url, |
1428 download_time); | 1417 download_time); |
1429 } | 1418 } |
1430 | 1419 |
1431 request.callback.func(request.callback.user_data, pp_error); | 1420 request.callback.func(request.callback.user_data, pp_error); |
1432 } | 1421 } |
1433 | 1422 |
1423 void DownloadFileCompletion(base::PlatformFile file, | |
1424 PP_NaClFileInfo* file_info, | |
1425 PP_CompletionCallback callback, | |
1426 FileDownloader::Status status, | |
1427 int http_status); | |
1428 | |
1429 void DownloadFile(PP_Instance instance, | |
1430 const char* url, | |
1431 struct PP_NaClFileInfo* file_info, | |
1432 struct PP_CompletionCallback callback) { | |
1433 CHECK(url); | |
1434 CHECK(file_info); | |
1435 | |
1436 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | |
1437 DCHECK(load_manager); | |
1438 if (!load_manager) { | |
1439 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | |
1440 FROM_HERE, | |
1441 base::Bind(callback.func, callback.user_data, | |
1442 static_cast<int32_t>(PP_ERROR_FAILED))); | |
1443 return; | |
1444 } | |
1445 | |
1446 // We have to ensure that this url resolves relative to the plugin base url | |
1447 // before downloading it. | |
1448 const GURL& test_gurl = load_manager->plugin_base_url().Resolve(url); | |
1449 if (!test_gurl.is_valid()) { | |
1450 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | |
1451 FROM_HERE, | |
1452 base::Bind(callback.func, callback.user_data, | |
1453 static_cast<int32_t>(PP_ERROR_FAILED))); | |
1454 return; | |
1455 } | |
1456 | |
1457 // Try the fast path for retrieving the file first. | |
1458 uint64_t file_token_lo = 0; | |
1459 uint64_t file_token_hi = 0; | |
1460 PP_FileHandle file_handle = OpenNaClExecutable(instance, | |
1461 url, | |
1462 &file_token_lo, | |
1463 &file_token_hi); | |
1464 if (file_handle != PP_kInvalidFileHandle) { | |
1465 file_info->handle = file_handle; | |
1466 file_info->token_lo = file_token_lo; | |
1467 file_info->token_hi = file_token_hi; | |
1468 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | |
1469 FROM_HERE, | |
1470 base::Bind(callback.func, callback.user_data, | |
1471 static_cast<int32_t>(PP_OK))); | |
1472 return; | |
1473 } | |
1474 | |
1475 // The fast path didn't work, we'll fetch the file using URLLoader and write | |
1476 // it to local storage. | |
1477 base::PlatformFile target_file = CreateTemporaryFile(instance); | |
1478 GURL gurl(url); | |
1479 | |
1480 content::PepperPluginInstance* plugin_instance = | |
1481 content::PepperPluginInstance::Get(instance); | |
1482 if (!plugin_instance) { | |
1483 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | |
1484 FROM_HERE, | |
1485 base::Bind(callback.func, callback.user_data, | |
1486 static_cast<int32_t>(PP_ERROR_FAILED))); | |
1487 } | |
1488 const blink::WebDocument& document = | |
1489 plugin_instance->GetContainer()->element().document(); | |
1490 scoped_ptr<blink::WebURLLoader> url_loader( | |
1491 CreateWebURLLoader(document, gurl)); | |
1492 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); | |
1493 | |
1494 ProgressEventRateLimiter* tracker = new ProgressEventRateLimiter(instance); | |
1495 | |
1496 // FileDownloader deletes itself after invoking DownloadNexeCompletion. | |
1497 FileDownloader* file_downloader = new FileDownloader( | |
1498 url_loader.Pass(), | |
1499 target_file, | |
1500 base::Bind(&DownloadFileCompletion, target_file, file_info, callback), | |
1501 base::Bind(&ProgressEventRateLimiter::ReportProgress, | |
1502 base::Owned(tracker), url)); | |
1503 file_downloader->Load(url_request); | |
1504 } | |
1505 | |
1506 void DownloadFileCompletion(base::PlatformFile file, | |
1507 PP_NaClFileInfo* file_info, | |
1508 PP_CompletionCallback callback, | |
1509 FileDownloader::Status status, | |
1510 int http_status) { | |
1511 int32_t pp_error = FileDownloaderToPepperError(status); | |
1512 if (pp_error == PP_OK) { | |
1513 file_info->handle = file; | |
1514 file_info->token_lo = 0; | |
1515 file_info->token_hi = 0; | |
1516 } | |
1517 callback.func(callback.user_data, pp_error); | |
1518 } | |
1519 | |
1434 const PPB_NaCl_Private nacl_interface = { | 1520 const PPB_NaCl_Private nacl_interface = { |
1435 &LaunchSelLdr, | 1521 &LaunchSelLdr, |
1436 &StartPpapiProxy, | 1522 &StartPpapiProxy, |
1437 &UrandomFD, | 1523 &UrandomFD, |
1438 &Are3DInterfacesDisabled, | 1524 &Are3DInterfacesDisabled, |
1439 &BrokerDuplicateHandle, | 1525 &BrokerDuplicateHandle, |
1440 &GetReadonlyPnaclFD, | 1526 &GetReadonlyPnaclFD, |
1441 &CreateTemporaryFile, | 1527 &CreateTemporaryFile, |
1442 &GetNumberOfProcessors, | 1528 &GetNumberOfProcessors, |
1443 &PPIsNonSFIModeEnabled, | 1529 &PPIsNonSFIModeEnabled, |
1444 &GetNexeFd, | 1530 &GetNexeFd, |
1445 &ReportTranslationFinished, | 1531 &ReportTranslationFinished, |
1446 &OpenNaClExecutable, | |
1447 &DispatchEvent, | 1532 &DispatchEvent, |
1448 &ReportLoadSuccess, | 1533 &ReportLoadSuccess, |
1449 &ReportLoadError, | 1534 &ReportLoadError, |
1450 &ReportLoadAbort, | 1535 &ReportLoadAbort, |
1451 &NexeDidCrash, | 1536 &NexeDidCrash, |
1452 &InstanceCreated, | 1537 &InstanceCreated, |
1453 &InstanceDestroyed, | 1538 &InstanceDestroyed, |
1454 &NaClDebugEnabledForURL, | 1539 &NaClDebugEnabledForURL, |
1455 &GetSandboxArch, | 1540 &GetSandboxArch, |
1456 &LogToConsole, | 1541 &LogToConsole, |
1457 &GetNaClReadyState, | 1542 &GetNaClReadyState, |
1458 &GetIsInstalled, | 1543 &GetIsInstalled, |
1459 &GetExitStatus, | 1544 &GetExitStatus, |
1460 &SetExitStatus, | 1545 &SetExitStatus, |
1461 &Vlog, | 1546 &Vlog, |
1462 &InitializePlugin, | 1547 &InitializePlugin, |
1463 &GetNexeSize, | 1548 &GetNexeSize, |
1464 &RequestNaClManifest, | 1549 &RequestNaClManifest, |
1465 &GetManifestBaseURL, | 1550 &GetManifestBaseURL, |
1466 &ResolvesRelativeToPluginBaseURL, | |
1467 &ProcessNaClManifest, | 1551 &ProcessNaClManifest, |
1468 &GetManifestURLArgument, | 1552 &GetManifestURLArgument, |
1469 &DevInterfacesEnabled, | 1553 &DevInterfacesEnabled, |
1470 &CreatePNaClManifest, | 1554 &CreatePNaClManifest, |
1471 &DestroyManifest, | 1555 &DestroyManifest, |
1472 &ManifestGetProgramURL, | 1556 &ManifestGetProgramURL, |
1473 &ManifestResolveKey, | 1557 &ManifestResolveKey, |
1474 &GetPNaClResourceInfo, | 1558 &GetPNaClResourceInfo, |
1475 &GetCpuFeatureAttrs, | 1559 &GetCpuFeatureAttrs, |
1476 &PostMessageToJavaScript, | 1560 &PostMessageToJavaScript, |
1477 &DownloadNexe | 1561 &DownloadNexe, |
1562 &DownloadFile | |
1478 }; | 1563 }; |
1479 | 1564 |
1480 } // namespace | 1565 } // namespace |
1481 | 1566 |
1482 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1567 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
1483 return &nacl_interface; | 1568 return &nacl_interface; |
1484 } | 1569 } |
1485 | 1570 |
1486 } // namespace nacl | 1571 } // namespace nacl |
OLD | NEW |