| OLD | NEW |
| 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/file_utils.h" | 11 #include "ppapi/native_client/src/trusted/plugin/file_utils.h" |
| 12 #include "ppapi/native_client/src/trusted/plugin/manifest.h" | 12 #include "ppapi/native_client/src/trusted/plugin/manifest.h" |
| 13 #include "ppapi/native_client/src/trusted/plugin/plugin.h" | 13 #include "ppapi/native_client/src/trusted/plugin/plugin.h" |
| 14 #include "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h" | 14 #include "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h" |
| 15 #include "ppapi/native_client/src/trusted/plugin/utility.h" | 15 #include "ppapi/native_client/src/trusted/plugin/utility.h" |
| 16 #include "third_party/jsoncpp/source/include/json/reader.h" | 16 #include "third_party/jsoncpp/source/include/json/reader.h" |
| 17 #include "third_party/jsoncpp/source/include/json/value.h" | 17 #include "third_party/jsoncpp/source/include/json/value.h" |
| 18 | 18 |
| 19 namespace plugin { | 19 namespace plugin { |
| 20 | 20 |
| 21 static const char kPnaclComponentScheme[] = "pnacl-component://"; | 21 static const char kPnaclBaseUrl[] = "chrome://pnacl-translator/"; |
| 22 const char PnaclUrls::kResourceInfoUrl[] = "pnacl.json"; | 22 const char PnaclUrls::kResourceInfoUrl[] = "pnacl.json"; |
| 23 | 23 |
| 24 nacl::string PnaclUrls::GetBaseUrl() { | 24 nacl::string PnaclUrls::GetBaseUrl() { |
| 25 return nacl::string(kPnaclComponentScheme); | 25 return nacl::string(kPnaclBaseUrl); |
| 26 } | 26 } |
| 27 | 27 |
| 28 nacl::string PnaclUrls::PrependPlatformPrefix(const nacl::string& url) { | 28 nacl::string PnaclUrls::PrependPlatformPrefix(const nacl::string& url) { |
| 29 return nacl::string(GetSandboxISA()) + "/" + url; | 29 return nacl::string(GetSandboxISA()) + "/" + url; |
| 30 } | 30 } |
| 31 | 31 |
| 32 // Determine if a URL is for a pnacl-component file, or if it is some other | 32 // 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://). | 33 // type of URL (e.g., http://, https://, chrome-extension://). |
| 34 // The URL could be one of the other variants for shared libraries | 34 // The URL could be one of the other variants for shared libraries |
| 35 // served from the web. | 35 // served from the web. |
| 36 bool PnaclUrls::IsPnaclComponent(const nacl::string& full_url) { | 36 bool PnaclUrls::IsPnaclComponent(const nacl::string& full_url) { |
| 37 return full_url.find(kPnaclComponentScheme, 0) == 0; | 37 return full_url.find(kPnaclBaseUrl, 0) == 0; |
| 38 } | 38 } |
| 39 | 39 |
| 40 // Convert a URL to a filename accepted by GetReadonlyPnaclFd. | 40 // Convert a URL to a filename accepted by GetReadonlyPnaclFd. |
| 41 // Must be kept in sync with chrome/browser/nacl_host/nacl_file_host. | 41 // Must be kept in sync with chrome/browser/nacl_host/nacl_file_host. |
| 42 nacl::string PnaclUrls::PnaclComponentURLToFilename( | 42 nacl::string PnaclUrls::PnaclComponentURLToFilename( |
| 43 const nacl::string& full_url) { | 43 const nacl::string& full_url) { |
| 44 // strip component scheme. | 44 // strip component scheme. |
| 45 nacl::string r = full_url.substr( | 45 nacl::string r = full_url.substr(nacl::string(kPnaclBaseUrl).length()); |
| 46 nacl::string(kPnaclComponentScheme).length()); | |
| 47 | 46 |
| 48 // Use white-listed-chars. | 47 // Use white-listed-chars. |
| 49 size_t replace_pos; | 48 size_t replace_pos; |
| 50 static const char* white_list = "abcdefghijklmnopqrstuvwxyz0123456789_"; | 49 static const char* white_list = "abcdefghijklmnopqrstuvwxyz0123456789_"; |
| 51 replace_pos = r.find_first_not_of(white_list); | 50 replace_pos = r.find_first_not_of(white_list); |
| 52 while(replace_pos != nacl::string::npos) { | 51 while(replace_pos != nacl::string::npos) { |
| 53 r = r.replace(replace_pos, 1, "_"); | 52 r = r.replace(replace_pos, 1, "_"); |
| 54 replace_pos = r.find_first_not_of(white_list); | 53 replace_pos = r.find_first_not_of(white_list); |
| 55 } | 54 } |
| 56 return r; | 55 return r; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 Json::Value json_name = json_data["pnacl-ld-name"]; | 181 Json::Value json_name = json_data["pnacl-ld-name"]; |
| 183 if (json_name.isString()) { | 182 if (json_name.isString()) { |
| 184 ld_tool_name = json_name.asString(); | 183 ld_tool_name = json_name.asString(); |
| 185 PLUGIN_PRINTF(("Set ld_tool_name=%s\n", ld_tool_name.c_str())); | 184 PLUGIN_PRINTF(("Set ld_tool_name=%s\n", ld_tool_name.c_str())); |
| 186 } | 185 } |
| 187 } | 186 } |
| 188 | 187 |
| 189 return true; | 188 return true; |
| 190 } | 189 } |
| 191 | 190 |
| 191 nacl::string PnaclResources::GetFullUrl(const nacl::string& partial_url) const { |
| 192 nacl::string full_url; |
| 193 ErrorInfo error_info; |
| 194 const nacl::string& url_with_platform_prefix = |
| 195 PnaclUrls::PrependPlatformPrefix(partial_url); |
| 196 if (!manifest_->ResolveURL(url_with_platform_prefix, &full_url, |
| 197 &error_info)) { |
| 198 PLUGIN_PRINTF(("PnaclResources::GetFullUrl failed: %s.\n", |
| 199 error_info.message().c_str())); |
| 200 return ""; |
| 201 } |
| 202 return full_url; |
| 203 } |
| 204 |
| 192 void PnaclResources::StartLoad( | 205 void PnaclResources::StartLoad( |
| 193 const pp::CompletionCallback& all_loaded_callback) { | 206 const pp::CompletionCallback& all_loaded_callback) { |
| 194 PLUGIN_PRINTF(("PnaclResources::StartLoad\n")); | 207 PLUGIN_PRINTF(("PnaclResources::StartLoad\n")); |
| 195 | 208 |
| 196 std::vector<nacl::string> resource_urls; | 209 std::vector<nacl::string> resource_urls; |
| 197 resource_urls.push_back(GetLlcUrl()); | 210 resource_urls.push_back(GetLlcUrl()); |
| 198 resource_urls.push_back(GetLdUrl()); | 211 resource_urls.push_back(GetLdUrl()); |
| 199 | 212 |
| 200 PLUGIN_PRINTF(("PnaclResources::StartLoad -- local install of PNaCl.\n")); | 213 PLUGIN_PRINTF(("PnaclResources::StartLoad -- local install of PNaCl.\n")); |
| 201 // Do a blocking load of each of the resources. | 214 // Do a blocking load of each of the resources. |
| 202 int32_t result = PP_OK; | 215 int32_t result = PP_OK; |
| 203 for (size_t i = 0; i < resource_urls.size(); ++i) { | 216 for (size_t i = 0; i < resource_urls.size(); ++i) { |
| 204 const nacl::string& url_with_platform_prefix = | 217 nacl::string full_url = GetFullUrl(resource_urls[i]); |
| 205 PnaclUrls::PrependPlatformPrefix(resource_urls[i]); | 218 if (full_url == "") { |
| 206 nacl::string full_url; | |
| 207 ErrorInfo error_info; | |
| 208 if (!manifest_->ResolveURL(url_with_platform_prefix, &full_url, | |
| 209 &error_info)) { | |
| 210 coordinator_->ReportNonPpapiError( | 219 coordinator_->ReportNonPpapiError( |
| 211 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | 220 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
| 212 nacl::string("failed to resolve ") + | 221 nacl::string("failed to resolve ") + resource_urls[i] + "."); |
| 213 url_with_platform_prefix + ": " + | |
| 214 error_info.message() + "."); | |
| 215 break; | 222 break; |
| 216 } | 223 } |
| 217 nacl::string filename = PnaclUrls::PnaclComponentURLToFilename(full_url); | 224 nacl::string filename = PnaclUrls::PnaclComponentURLToFilename(full_url); |
| 218 | 225 |
| 219 int32_t fd = PnaclResources::GetPnaclFD(plugin_, filename.c_str()); | 226 int32_t fd = PnaclResources::GetPnaclFD(plugin_, filename.c_str()); |
| 220 if (fd < 0) { | 227 if (fd < 0) { |
| 221 // File-open failed. Assume this means that the file is | 228 // File-open failed. Assume this means that the file is |
| 222 // not actually installed. This shouldn't actually occur since | 229 // not actually installed. This shouldn't actually occur since |
| 223 // ReadResourceInfo() should happen first, and error out. | 230 // ReadResourceInfo() should happen first, and error out. |
| 224 coordinator_->ReportNonPpapiError( | 231 coordinator_->ReportNonPpapiError( |
| 225 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | 232 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
| 226 nacl::string("The Portable Native Client (pnacl) component is not " | 233 nacl::string("The Portable Native Client (pnacl) component is not " |
| 227 "installed. Please consult chrome://components for more " | 234 "installed. Please consult chrome://components for more " |
| 228 "information.")); | 235 "information.")); |
| 229 result = PP_ERROR_FILENOTFOUND; | 236 result = PP_ERROR_FILENOTFOUND; |
| 230 break; | 237 break; |
| 231 } else { | 238 } else { |
| 232 resource_wrappers_[resource_urls[i]] = | 239 resource_wrappers_[resource_urls[i]] = |
| 233 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY); | 240 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY); |
| 234 } | 241 } |
| 235 } | 242 } |
| 236 // We're done! Queue the callback. | 243 // We're done! Queue the callback. |
| 237 pp::Core* core = pp::Module::Get()->core(); | 244 pp::Core* core = pp::Module::Get()->core(); |
| 238 core->CallOnMainThread(0, all_loaded_callback, result); | 245 core->CallOnMainThread(0, all_loaded_callback, result); |
| 239 } | 246 } |
| 240 | 247 |
| 241 } // namespace plugin | 248 } // namespace plugin |
| OLD | NEW |