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 namespace { |
| 21 const PPB_NaCl_Private* GetNaClInterface() { |
| 22 pp::Module *module = pp::Module::Get(); |
| 23 CHECK(module); |
| 24 return static_cast<const PPB_NaCl_Private*>( |
| 25 module->GetBrowserInterface(PPB_NACL_PRIVATE_INTERFACE)); |
| 26 } |
| 27 } // namespace |
20 | 28 |
21 static const char kPnaclBaseUrl[] = "chrome://pnacl-translator/"; | 29 static const char kPnaclBaseUrl[] = "chrome://pnacl-translator/"; |
22 const char PnaclUrls::kResourceInfoUrl[] = "pnacl.json"; | 30 const char PnaclUrls::kResourceInfoUrl[] = "pnacl.json"; |
23 | 31 |
24 nacl::string PnaclUrls::GetBaseUrl() { | 32 nacl::string PnaclUrls::GetBaseUrl() { |
25 return nacl::string(kPnaclBaseUrl); | 33 return nacl::string(kPnaclBaseUrl); |
26 } | 34 } |
27 | 35 |
28 nacl::string PnaclUrls::PrependPlatformPrefix(const nacl::string& url) { | |
29 return nacl::string(GetSandboxISA()) + "/" + url; | |
30 } | |
31 | |
32 // Determine if a URL is for a pnacl-component file, or if it is some other | 36 // 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://). | 37 // type of URL (e.g., http://, https://, chrome-extension://). |
34 // The URL could be one of the other variants for shared libraries | 38 // The URL could be one of the other variants for shared libraries |
35 // served from the web. | 39 // served from the web. |
36 bool PnaclUrls::IsPnaclComponent(const nacl::string& full_url) { | 40 bool PnaclUrls::IsPnaclComponent(const nacl::string& full_url) { |
37 return full_url.find(kPnaclBaseUrl, 0) == 0; | 41 return full_url.find(kPnaclBaseUrl, 0) == 0; |
38 } | 42 } |
39 | 43 |
40 // Convert a URL to a filename accepted by GetReadonlyPnaclFd. | 44 // Convert a URL to a filename accepted by GetReadonlyPnaclFd. |
41 // Must be kept in sync with chrome/browser/nacl_host/nacl_file_host. | 45 // Must be kept in sync with chrome/browser/nacl_host/nacl_file_host. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 Json::Value json_name = json_data["pnacl-ld-name"]; | 185 Json::Value json_name = json_data["pnacl-ld-name"]; |
182 if (json_name.isString()) { | 186 if (json_name.isString()) { |
183 ld_tool_name = json_name.asString(); | 187 ld_tool_name = json_name.asString(); |
184 PLUGIN_PRINTF(("Set ld_tool_name=%s\n", ld_tool_name.c_str())); | 188 PLUGIN_PRINTF(("Set ld_tool_name=%s\n", ld_tool_name.c_str())); |
185 } | 189 } |
186 } | 190 } |
187 | 191 |
188 return true; | 192 return true; |
189 } | 193 } |
190 | 194 |
191 nacl::string PnaclResources::GetFullUrl(const nacl::string& partial_url) const { | 195 nacl::string PnaclResources::GetFullUrl( |
| 196 const nacl::string& partial_url, const nacl::string& sandbox_arch) const { |
192 nacl::string full_url; | 197 nacl::string full_url; |
193 ErrorInfo error_info; | 198 ErrorInfo error_info; |
194 const nacl::string& url_with_platform_prefix = | 199 const nacl::string& url_with_platform_prefix = |
195 PnaclUrls::PrependPlatformPrefix(partial_url); | 200 sandbox_arch + "/" + partial_url; |
196 if (!manifest_->ResolveURL(url_with_platform_prefix, &full_url, | 201 if (!manifest_->ResolveURL(url_with_platform_prefix, |
| 202 &full_url, |
197 &error_info)) { | 203 &error_info)) { |
198 PLUGIN_PRINTF(("PnaclResources::GetFullUrl failed: %s.\n", | 204 PLUGIN_PRINTF(("PnaclResources::GetFullUrl failed: %s.\n", |
199 error_info.message().c_str())); | 205 error_info.message().c_str())); |
200 return ""; | 206 return ""; |
201 } | 207 } |
202 return full_url; | 208 return full_url; |
203 } | 209 } |
204 | 210 |
205 void PnaclResources::StartLoad( | 211 void PnaclResources::StartLoad( |
206 const pp::CompletionCallback& all_loaded_callback) { | 212 const pp::CompletionCallback& all_loaded_callback) { |
207 PLUGIN_PRINTF(("PnaclResources::StartLoad\n")); | 213 PLUGIN_PRINTF(("PnaclResources::StartLoad\n")); |
208 | 214 |
209 std::vector<nacl::string> resource_urls; | 215 std::vector<nacl::string> resource_urls; |
210 resource_urls.push_back(GetLlcUrl()); | 216 resource_urls.push_back(GetLlcUrl()); |
211 resource_urls.push_back(GetLdUrl()); | 217 resource_urls.push_back(GetLdUrl()); |
212 | 218 |
213 PLUGIN_PRINTF(("PnaclResources::StartLoad -- local install of PNaCl.\n")); | 219 PLUGIN_PRINTF(("PnaclResources::StartLoad -- local install of PNaCl.\n")); |
214 // Do a blocking load of each of the resources. | 220 // Do a blocking load of each of the resources. |
215 int32_t result = PP_OK; | 221 int32_t result = PP_OK; |
216 for (size_t i = 0; i < resource_urls.size(); ++i) { | 222 for (size_t i = 0; i < resource_urls.size(); ++i) { |
217 nacl::string full_url = GetFullUrl(resource_urls[i]); | 223 nacl::string full_url = GetFullUrl( |
| 224 resource_urls[i], plugin_->nacl_interface()->GetSandboxArch()); |
218 if (full_url == "") { | 225 if (full_url == "") { |
219 coordinator_->ReportNonPpapiError( | 226 coordinator_->ReportNonPpapiError( |
220 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | 227 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
221 nacl::string("failed to resolve ") + resource_urls[i] + "."); | 228 nacl::string("failed to resolve ") + resource_urls[i] + "."); |
222 break; | 229 break; |
223 } | 230 } |
224 nacl::string filename = PnaclUrls::PnaclComponentURLToFilename(full_url); | 231 nacl::string filename = PnaclUrls::PnaclComponentURLToFilename(full_url); |
225 | 232 |
226 int32_t fd = PnaclResources::GetPnaclFD(plugin_, filename.c_str()); | 233 int32_t fd = PnaclResources::GetPnaclFD(plugin_, filename.c_str()); |
227 if (fd < 0) { | 234 if (fd < 0) { |
(...skipping 11 matching lines...) Expand all Loading... |
239 resource_wrappers_[resource_urls[i]] = | 246 resource_wrappers_[resource_urls[i]] = |
240 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY); | 247 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY); |
241 } | 248 } |
242 } | 249 } |
243 // We're done! Queue the callback. | 250 // We're done! Queue the callback. |
244 pp::Core* core = pp::Module::Get()->core(); | 251 pp::Core* core = pp::Module::Get()->core(); |
245 core->CallOnMainThread(0, all_loaded_callback, result); | 252 core->CallOnMainThread(0, all_loaded_callback, result); |
246 } | 253 } |
247 | 254 |
248 } // namespace plugin | 255 } // namespace plugin |
OLD | NEW |