Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: components/nacl/renderer/ppb_nacl_private_impl.cc

Issue 307933005: Pepper: Refactor PNaCl OpenManifestEntry logic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ppapi/api/private/ppb_nacl_private.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h" 59 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h"
60 #include "third_party/jsoncpp/source/include/json/reader.h" 60 #include "third_party/jsoncpp/source/include/json/reader.h"
61 #include "third_party/jsoncpp/source/include/json/value.h" 61 #include "third_party/jsoncpp/source/include/json/value.h"
62 62
63 namespace nacl { 63 namespace nacl {
64 namespace { 64 namespace {
65 65
66 // The pseudo-architecture used to indicate portable native client. 66 // The pseudo-architecture used to indicate portable native client.
67 const char* const kPortableArch = "portable"; 67 const char* const kPortableArch = "portable";
68 68
69 // The base URL for resources used by the PNaCl translator processes.
70 const char* kPNaClTranslatorBaseUrl = "chrome://pnacl-translator/";
71
69 base::LazyInstance<scoped_refptr<PnaclTranslationResourceHost> > 72 base::LazyInstance<scoped_refptr<PnaclTranslationResourceHost> >
70 g_pnacl_resource_host = LAZY_INSTANCE_INITIALIZER; 73 g_pnacl_resource_host = LAZY_INSTANCE_INITIALIZER;
71 74
72 bool InitializePnaclResourceHost() { 75 bool InitializePnaclResourceHost() {
73 // Must run on the main thread. 76 // Must run on the main thread.
74 content::RenderThread* render_thread = content::RenderThread::Get(); 77 content::RenderThread* render_thread = content::RenderThread::Get();
75 if (!render_thread) 78 if (!render_thread)
76 return false; 79 return false;
77 if (!g_pnacl_resource_host.Get()) { 80 if (!g_pnacl_resource_host.Get()) {
78 g_pnacl_resource_host.Get() = new PnaclTranslationResourceHost( 81 g_pnacl_resource_host.Get() = new PnaclTranslationResourceHost(
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 uint32_t options) { 516 uint32_t options) {
514 #if defined(OS_WIN) 517 #if defined(OS_WIN)
515 return content::BrokerDuplicateHandle(source_handle, process_id, 518 return content::BrokerDuplicateHandle(source_handle, process_id,
516 target_handle, desired_access, 519 target_handle, desired_access,
517 options); 520 options);
518 #else 521 #else
519 return 0; 522 return 0;
520 #endif 523 #endif
521 } 524 }
522 525
523 PP_FileHandle GetReadonlyPnaclFD(const char* filename) { 526 // Convert a URL to a filename for GetReadonlyPnaclFd.
527 // Must be kept in sync with PnaclCanOpenFile() in
528 // components/nacl/browser/nacl_file_host.cc.
529 std::string PnaclComponentURLToFilename(const std::string& url) {
530 // strip component scheme.
bbudge 2014/05/30 17:57:56 Since we're in chrome now, can you use GURL to par
531 std::string r = url.substr(
532 std::string(kPNaClTranslatorBaseUrl).length());
533
534 // Use white-listed-chars.
bbudge 2014/05/30 20:04:57 If we're generating these, why do we have to do th
teravest 2014/05/30 20:09:05 We depend on this translation happening for some f
bbudge 2014/05/30 20:17:13 Could you add a short comment to that effect here,
535 size_t replace_pos;
536 static const char* white_list = "abcdefghijklmnopqrstuvwxyz0123456789_";
537 replace_pos = r.find_first_not_of(white_list);
538 while(replace_pos != std::string::npos) {
539 r = r.replace(replace_pos, 1, "_");
540 replace_pos = r.find_first_not_of(white_list);
541 }
542 return r;
543 }
544
545 PP_FileHandle GetReadonlyPnaclFd(const char* url) {
546 std::string filename = PnaclComponentURLToFilename(url);
524 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit(); 547 IPC::PlatformFileForTransit out_fd = IPC::InvalidPlatformFileForTransit();
525 IPC::Sender* sender = content::RenderThread::Get(); 548 IPC::Sender* sender = content::RenderThread::Get();
526 DCHECK(sender); 549 DCHECK(sender);
527 if (!sender->Send(new NaClHostMsg_GetReadonlyPnaclFD( 550 if (!sender->Send(new NaClHostMsg_GetReadonlyPnaclFD(
528 std::string(filename), 551 std::string(filename),
529 &out_fd))) { 552 &out_fd))) {
530 return base::kInvalidPlatformFileValue; 553 return base::kInvalidPlatformFileValue;
531 } 554 }
532 if (out_fd == IPC::InvalidPlatformFileForTransit()) { 555 if (out_fd == IPC::InvalidPlatformFileForTransit()) {
533 return base::kInvalidPlatformFileValue; 556 return base::kInvalidPlatformFileValue;
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 std::string key_string(key); 1091 std::string key_string(key);
1069 if (key_string.find(kFilesPrefix) == std::string::npos) { 1092 if (key_string.find(kFilesPrefix) == std::string::npos) {
1070 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance); 1093 nacl::NexeLoadManager* load_manager = GetNexeLoadManager(instance);
1071 if (load_manager) 1094 if (load_manager)
1072 load_manager->ReportLoadError(PP_NACL_ERROR_MANIFEST_RESOLVE_URL, 1095 load_manager->ReportLoadError(PP_NACL_ERROR_MANIFEST_RESOLVE_URL,
1073 "key did not start with files/"); 1096 "key did not start with files/");
1074 return PP_FALSE; 1097 return PP_FALSE;
1075 } 1098 }
1076 std::string key_basename = key_string.substr(kFilesPrefix.length()); 1099 std::string key_basename = key_string.substr(kFilesPrefix.length());
1077 std::string pnacl_url = 1100 std::string pnacl_url =
1078 std::string("chrome://pnacl-translator/") + GetSandboxArch() + "/" + 1101 std::string(kPNaClTranslatorBaseUrl) + GetSandboxArch() + "/" +
1079 key_basename; 1102 key_basename;
1080 *pp_full_url = ppapi::StringVar::StringToPPVar(pnacl_url); 1103 *pp_full_url = ppapi::StringVar::StringToPPVar(pnacl_url);
1081 return PP_TRUE; 1104 return PP_TRUE;
1082 } 1105 }
1083 1106
1084 JsonManifestMap::iterator it = g_manifest_map.Get().find(instance); 1107 JsonManifestMap::iterator it = g_manifest_map.Get().find(instance);
1085 if (it == g_manifest_map.Get().end()) 1108 if (it == g_manifest_map.Get().end())
1086 return PP_FALSE; 1109 return PP_FALSE;
1087 1110
1088 std::string full_url; 1111 std::string full_url;
1089 bool ok = it->second->ResolveKey(key, &full_url, pnacl_options); 1112 bool ok = it->second->ResolveKey(key, &full_url, pnacl_options);
1090 if (ok) 1113 if (ok)
1091 *pp_full_url = ppapi::StringVar::StringToPPVar(full_url); 1114 *pp_full_url = ppapi::StringVar::StringToPPVar(full_url);
1092 return PP_FromBool(ok); 1115 return PP_FromBool(ok);
1093 } 1116 }
1094 1117
1095 PP_Bool GetPNaClResourceInfo(PP_Instance instance, 1118 PP_Bool GetPNaClResourceInfo(PP_Instance instance,
1096 const char* filename, 1119 const char* filename,
1097 PP_Var* llc_tool_name, 1120 PP_Var* llc_tool_name,
1098 PP_Var* ld_tool_name) { 1121 PP_Var* ld_tool_name) {
1099 NexeLoadManager* load_manager = GetNexeLoadManager(instance); 1122 NexeLoadManager* load_manager = GetNexeLoadManager(instance);
1100 DCHECK(load_manager); 1123 DCHECK(load_manager);
1101 if (!load_manager) 1124 if (!load_manager)
1102 return PP_FALSE; 1125 return PP_FALSE;
1103 1126
1104 base::PlatformFile file = GetReadonlyPnaclFD(filename); 1127 base::PlatformFile file = GetReadonlyPnaclFd(filename);
1105 if (file == base::kInvalidPlatformFileValue) { 1128 if (file == base::kInvalidPlatformFileValue) {
1106 load_manager->ReportLoadError( 1129 load_manager->ReportLoadError(
1107 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, 1130 PP_NACL_ERROR_PNACL_RESOURCE_FETCH,
1108 "The Portable Native Client (pnacl) component is not " 1131 "The Portable Native Client (pnacl) component is not "
1109 "installed. Please consult chrome://components for more " 1132 "installed. Please consult chrome://components for more "
1110 "information."); 1133 "information.");
1111 return PP_FALSE; 1134 return PP_FALSE;
1112 } 1135 }
1113 1136
1114 base::PlatformFileInfo file_info; 1137 base::PlatformFileInfo file_info;
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 NexeLoadManager* load_manager = GetNexeLoadManager(instance); 1434 NexeLoadManager* load_manager = GetNexeLoadManager(instance);
1412 DCHECK(load_manager); 1435 DCHECK(load_manager);
1413 if (!load_manager) { 1436 if (!load_manager) {
1414 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( 1437 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
1415 FROM_HERE, 1438 FROM_HERE,
1416 base::Bind(callback.func, callback.user_data, 1439 base::Bind(callback.func, callback.user_data,
1417 static_cast<int32_t>(PP_ERROR_FAILED))); 1440 static_cast<int32_t>(PP_ERROR_FAILED)));
1418 return; 1441 return;
1419 } 1442 }
1420 1443
1444 // Handle special PNaCl support files which are installed on the user's
1445 // machine.
1446 std::string url_string(url);
1447 if (url_string.find(kPNaClTranslatorBaseUrl, 0) == 0) {
1448 PP_FileHandle handle = GetReadonlyPnaclFd(url);
1449 if (handle == PP_kInvalidFileHandle) {
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 // TODO(ncbray): enable the fast loading and validation paths for this type
1457 // of file.
1458 file_info->handle = handle;
1459 file_info->token_lo = 0;
1460 file_info->token_hi = 0;
1461 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
1462 FROM_HERE,
1463 base::Bind(callback.func, callback.user_data,
1464 static_cast<int32_t>(PP_OK)));
1465 return;
1466 }
1467
1421 // We have to ensure that this url resolves relative to the plugin base url 1468 // We have to ensure that this url resolves relative to the plugin base url
1422 // before downloading it. 1469 // before downloading it.
1423 const GURL& test_gurl = load_manager->plugin_base_url().Resolve(url); 1470 const GURL& test_gurl = load_manager->plugin_base_url().Resolve(url);
1424 if (!test_gurl.is_valid()) { 1471 if (!test_gurl.is_valid()) {
1425 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( 1472 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
1426 FROM_HERE, 1473 FROM_HERE,
1427 base::Bind(callback.func, callback.user_data, 1474 base::Bind(callback.func, callback.user_data,
1428 static_cast<int32_t>(PP_ERROR_FAILED))); 1475 static_cast<int32_t>(PP_ERROR_FAILED)));
1429 return; 1476 return;
1430 } 1477 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 base::Owned(tracker), url)); 1524 base::Owned(tracker), url));
1478 file_downloader->Load(url_request); 1525 file_downloader->Load(url_request);
1479 } 1526 }
1480 1527
1481 const PPB_NaCl_Private nacl_interface = { 1528 const PPB_NaCl_Private nacl_interface = {
1482 &LaunchSelLdr, 1529 &LaunchSelLdr,
1483 &StartPpapiProxy, 1530 &StartPpapiProxy,
1484 &UrandomFD, 1531 &UrandomFD,
1485 &Are3DInterfacesDisabled, 1532 &Are3DInterfacesDisabled,
1486 &BrokerDuplicateHandle, 1533 &BrokerDuplicateHandle,
1487 &GetReadonlyPnaclFD, 1534 &GetReadonlyPnaclFd,
1488 &CreateTemporaryFile, 1535 &CreateTemporaryFile,
1489 &GetNumberOfProcessors, 1536 &GetNumberOfProcessors,
1490 &PPIsNonSFIModeEnabled, 1537 &PPIsNonSFIModeEnabled,
1491 &GetNexeFd, 1538 &GetNexeFd,
1492 &ReportTranslationFinished, 1539 &ReportTranslationFinished,
1493 &DispatchEvent, 1540 &DispatchEvent,
1494 &ReportLoadSuccess, 1541 &ReportLoadSuccess,
1495 &ReportLoadError, 1542 &ReportLoadError,
1496 &ReportLoadAbort, 1543 &ReportLoadAbort,
1497 &NexeDidCrash, 1544 &NexeDidCrash,
(...skipping 23 matching lines...) Expand all
1521 &DownloadFile 1568 &DownloadFile
1522 }; 1569 };
1523 1570
1524 } // namespace 1571 } // namespace
1525 1572
1526 const PPB_NaCl_Private* GetNaClPrivateInterface() { 1573 const PPB_NaCl_Private* GetNaClPrivateInterface() {
1527 return &nacl_interface; 1574 return &nacl_interface;
1528 } 1575 }
1529 1576
1530 } // namespace nacl 1577 } // namespace nacl
OLDNEW
« no previous file with comments | « no previous file | ppapi/api/private/ppb_nacl_private.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698