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

Side by Side Diff: ppapi/native_client/src/trusted/plugin/pnacl_resources.cc

Issue 301743003: Pepper: PnaclResources cleanup. (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 | « ppapi/native_client/src/trusted/plugin/pnacl_resources.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ppapi/native_client/src/trusted/plugin/pnacl_resources.h" 5 #include "ppapi/native_client/src/trusted/plugin/pnacl_resources.h"
6 6
7 #include "native_client/src/include/portability_io.h" 7 #include "native_client/src/include/portability_io.h"
8 #include "native_client/src/shared/platform/nacl_check.h" 8 #include "native_client/src/shared/platform/nacl_check.h"
9 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" 9 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/native_client/src/trusted/plugin/plugin.h" 11 #include "ppapi/native_client/src/trusted/plugin/plugin.h"
12 #include "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h" 12 #include "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h"
13 #include "ppapi/native_client/src/trusted/plugin/utility.h" 13 #include "ppapi/native_client/src/trusted/plugin/utility.h"
14 14
15 namespace plugin { 15 namespace plugin {
16 16
17 namespace { 17 namespace {
18 18
19 static const char kPnaclBaseUrl[] = "chrome://pnacl-translator/";
20
19 nacl::string GetFullUrl(const nacl::string& partial_url) { 21 nacl::string GetFullUrl(const nacl::string& partial_url) {
20 return PnaclUrls::GetBaseUrl() + GetNaClInterface()->GetSandboxArch() + "/" + 22 return nacl::string(kPnaclBaseUrl) + GetNaClInterface()->GetSandboxArch() +
21 partial_url; 23 "/" + partial_url;
22 } 24 }
23 25
24 } // namespace 26 } // namespace
25 27
26 static const char kPnaclBaseUrl[] = "chrome://pnacl-translator/";
27
28 nacl::string PnaclUrls::GetBaseUrl() {
29 return nacl::string(kPnaclBaseUrl);
30 }
31
32 // Determine if a URL is for a pnacl-component file, or if it is some other 28 // Determine if a URL is for a pnacl-component file, or if it is some other
33 // type of URL (e.g., http://, https://, chrome-extension://). 29 // type of URL (e.g., http://, https://, chrome-extension://).
34 // The URL could be one of the other variants for shared libraries 30 // The URL could be one of the other variants for shared libraries
35 // served from the web. 31 // served from the web.
36 bool PnaclUrls::IsPnaclComponent(const nacl::string& full_url) { 32 bool PnaclUrls::IsPnaclComponent(const nacl::string& full_url) {
37 return full_url.find(kPnaclBaseUrl, 0) == 0; 33 return full_url.find(kPnaclBaseUrl, 0) == 0;
38 } 34 }
39 35
40 // Convert a URL to a filename accepted by GetReadonlyPnaclFd. 36 // Convert a URL to a filename accepted by GetReadonlyPnaclFd.
41 // Must be kept in sync with chrome/browser/nacl_host/nacl_file_host. 37 // Must be kept in sync with chrome/browser/nacl_host/nacl_file_host.
42 nacl::string PnaclUrls::PnaclComponentURLToFilename( 38 nacl::string PnaclUrls::PnaclComponentURLToFilename(
43 const nacl::string& full_url) { 39 const nacl::string& full_url) {
44 // strip component scheme. 40 // strip component scheme.
45 nacl::string r = full_url.substr(nacl::string(kPnaclBaseUrl).length()); 41 nacl::string r = full_url.substr(nacl::string(kPnaclBaseUrl).length());
46 42
47 // Use white-listed-chars. 43 // Use white-listed-chars.
48 size_t replace_pos; 44 size_t replace_pos;
49 static const char* white_list = "abcdefghijklmnopqrstuvwxyz0123456789_"; 45 static const char* white_list = "abcdefghijklmnopqrstuvwxyz0123456789_";
50 replace_pos = r.find_first_not_of(white_list); 46 replace_pos = r.find_first_not_of(white_list);
51 while(replace_pos != nacl::string::npos) { 47 while(replace_pos != nacl::string::npos) {
52 r = r.replace(replace_pos, 1, "_"); 48 r = r.replace(replace_pos, 1, "_");
53 replace_pos = r.find_first_not_of(white_list); 49 replace_pos = r.find_first_not_of(white_list);
54 } 50 }
55 return r; 51 return r;
56 } 52 }
57 53
58 nacl::string PnaclUrls::GetResourceInfoUrl() {
59 return "pnacl.json";
60 }
61
62 ////////////////////////////////////////////////////////////////////// 54 //////////////////////////////////////////////////////////////////////
63 55
64 PnaclResources::~PnaclResources() { 56 PnaclResources::~PnaclResources() {
65 if (llc_file_handle_ != PP_kInvalidFileHandle) 57 if (llc_file_handle_ != PP_kInvalidFileHandle)
66 CloseFileHandle(llc_file_handle_); 58 CloseFileHandle(llc_file_handle_);
67 if (ld_file_handle_ != PP_kInvalidFileHandle) 59 if (ld_file_handle_ != PP_kInvalidFileHandle)
68 CloseFileHandle(ld_file_handle_); 60 CloseFileHandle(ld_file_handle_);
69 } 61 }
70 62
71 void PnaclResources::ReadResourceInfo( 63 void PnaclResources::ReadResourceInfo(
72 const nacl::string& resource_info_url,
73 const pp::CompletionCallback& resource_info_read_cb) { 64 const pp::CompletionCallback& resource_info_read_cb) {
74 PLUGIN_PRINTF(("PnaclResources::ReadResourceInfo\n")); 65 nacl::string full_url = "chrome://pnacl-translator/pnacl.json";
bbudge 2014/05/27 20:54:07 Could we use kPnaclBaseUrl here?
bbudge 2014/05/27 21:00:25 Or define a string constant above for the path sin
75
76 nacl::string full_url = PnaclUrls::GetBaseUrl() + resource_info_url;
77 PLUGIN_PRINTF(("Resolved resources info url: %s\n", full_url.c_str()));
78 nacl::string resource_info_filename = 66 nacl::string resource_info_filename =
79 PnaclUrls::PnaclComponentURLToFilename(full_url); 67 PnaclUrls::PnaclComponentURLToFilename(full_url);
80 68
81 PLUGIN_PRINTF(("Pnacl-converted resources info url: %s\n", 69 PLUGIN_PRINTF(("Pnacl-converted resources info url: %s\n",
82 resource_info_filename.c_str())); 70 resource_info_filename.c_str()));
83
84 PP_Var pp_llc_tool_name_var; 71 PP_Var pp_llc_tool_name_var;
85 PP_Var pp_ld_tool_name_var; 72 PP_Var pp_ld_tool_name_var;
86 if (!plugin_->nacl_interface()->GetPnaclResourceInfo( 73 if (!plugin_->nacl_interface()->GetPnaclResourceInfo(
87 plugin_->pp_instance(), 74 plugin_->pp_instance(),
88 resource_info_filename.c_str(), 75 resource_info_filename.c_str(),
89 &pp_llc_tool_name_var, 76 &pp_llc_tool_name_var,
90 &pp_ld_tool_name_var)) { 77 &pp_ld_tool_name_var)) {
91 coordinator_->ExitWithError(); 78 coordinator_->ExitWithError();
92 } 79 }
93 80
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, 122 PP_NACL_ERROR_PNACL_RESOURCE_FETCH,
136 nacl::string("The Portable Native Client (pnacl) component is not " 123 nacl::string("The Portable Native Client (pnacl) component is not "
137 "installed. Please consult chrome://components for more " 124 "installed. Please consult chrome://components for more "
138 "information.")); 125 "information."));
139 result = PP_ERROR_FILENOTFOUND; 126 result = PP_ERROR_FILENOTFOUND;
140 } 127 }
141 pp::Module::Get()->core()->CallOnMainThread(0, all_loaded_callback, result); 128 pp::Module::Get()->core()->CallOnMainThread(0, all_loaded_callback, result);
142 } 129 }
143 130
144 } // namespace plugin 131 } // namespace plugin
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/pnacl_resources.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698