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