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 "native_client/src/trusted/plugin/pnacl_coordinator.h" | 5 #include "native_client/src/trusted/plugin/pnacl_coordinator.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "native_client/src/include/checked_cast.h" | 10 #include "native_client/src/include/checked_cast.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 namespace { | 26 namespace { |
27 const char kPnaclTempDir[] = "/.pnacl"; | 27 const char kPnaclTempDir[] = "/.pnacl"; |
28 const uint32_t kCopyBufSize = 512 << 10; | 28 const uint32_t kCopyBufSize = 512 << 10; |
29 } | 29 } |
30 | 30 |
31 namespace plugin { | 31 namespace plugin { |
32 | 32 |
33 ////////////////////////////////////////////////////////////////////// | 33 ////////////////////////////////////////////////////////////////////// |
34 // Pnacl-specific manifest support. | 34 // Pnacl-specific manifest support. |
35 ////////////////////////////////////////////////////////////////////// | 35 ////////////////////////////////////////////////////////////////////// |
36 class ExtensionManifest : public Manifest { | 36 |
| 37 class PnaclManifest : public Manifest { |
37 public: | 38 public: |
38 explicit ExtensionManifest(const pp::URLUtil_Dev* url_util) | 39 PnaclManifest(const pp::URLUtil_Dev* url_util, bool use_extension) |
39 : url_util_(url_util), | 40 : url_util_(url_util), |
40 manifest_base_url_(PnaclUrls::GetExtensionUrl()) { } | 41 manifest_base_url_(PnaclUrls::GetBaseUrl(use_extension)) { |
41 virtual ~ExtensionManifest() { } | 42 // TODO(jvoung): get rid of use_extension when we no longer rely |
| 43 // on the chrome webstore extension. Most of this Manifest stuff |
| 44 // can also be simplified then. |
| 45 } |
| 46 virtual ~PnaclManifest() { } |
42 | 47 |
43 virtual bool GetProgramURL(nacl::string* full_url, | 48 virtual bool GetProgramURL(nacl::string* full_url, |
44 nacl::string* cache_identity, | 49 nacl::string* cache_identity, |
45 ErrorInfo* error_info, | 50 ErrorInfo* error_info, |
46 bool* pnacl_translate) const { | 51 bool* pnacl_translate) const { |
47 // Does not contain program urls. | 52 // Does not contain program urls. |
48 UNREFERENCED_PARAMETER(full_url); | 53 UNREFERENCED_PARAMETER(full_url); |
49 UNREFERENCED_PARAMETER(cache_identity); | 54 UNREFERENCED_PARAMETER(cache_identity); |
50 UNREFERENCED_PARAMETER(error_info); | 55 UNREFERENCED_PARAMETER(error_info); |
51 UNREFERENCED_PARAMETER(pnacl_translate); | 56 UNREFERENCED_PARAMETER(pnacl_translate); |
52 PLUGIN_PRINTF(("ExtensionManifest does not contain a program\n")); | 57 PLUGIN_PRINTF(("PnaclManifest does not contain a program\n")); |
53 error_info->SetReport(ERROR_MANIFEST_GET_NEXE_URL, | 58 error_info->SetReport(ERROR_MANIFEST_GET_NEXE_URL, |
54 "pnacl manifest does not contain a program."); | 59 "pnacl manifest does not contain a program."); |
55 return false; | 60 return false; |
56 } | 61 } |
57 | 62 |
58 virtual bool ResolveURL(const nacl::string& relative_url, | 63 virtual bool ResolveURL(const nacl::string& relative_url, |
59 nacl::string* full_url, | 64 nacl::string* full_url, |
60 ErrorInfo* error_info) const { | 65 ErrorInfo* error_info) const { |
61 // Does not do general URL resolution, simply appends relative_url to | 66 // Does not do general URL resolution, simply appends relative_url to |
62 // the end of manifest_base_url_. | 67 // the end of manifest_base_url_. |
63 UNREFERENCED_PARAMETER(error_info); | 68 UNREFERENCED_PARAMETER(error_info); |
64 *full_url = manifest_base_url_ + relative_url; | 69 *full_url = manifest_base_url_ + relative_url; |
65 return true; | 70 return true; |
66 } | 71 } |
67 | 72 |
68 virtual bool GetFileKeys(std::set<nacl::string>* keys) const { | 73 virtual bool GetFileKeys(std::set<nacl::string>* keys) const { |
69 // Does not support enumeration. | 74 // Does not support enumeration. |
70 PLUGIN_PRINTF(("ExtensionManifest does not support key enumeration\n")); | 75 PLUGIN_PRINTF(("PnaclManifest does not support key enumeration\n")); |
71 UNREFERENCED_PARAMETER(keys); | 76 UNREFERENCED_PARAMETER(keys); |
72 return false; | 77 return false; |
73 } | 78 } |
74 | 79 |
75 virtual bool ResolveKey(const nacl::string& key, | 80 virtual bool ResolveKey(const nacl::string& key, |
76 nacl::string* full_url, | 81 nacl::string* full_url, |
77 nacl::string* cache_identity, | 82 nacl::string* cache_identity, |
78 ErrorInfo* error_info, | 83 ErrorInfo* error_info, |
79 bool* pnacl_translate) const { | 84 bool* pnacl_translate) const { |
80 // All of the extension files are native (do not require pnacl translate). | 85 // All of the extension files are native (do not require pnacl translate). |
81 *pnacl_translate = false; | 86 *pnacl_translate = false; |
82 // Do not cache these entries. | 87 // Do not cache these entries. |
83 *cache_identity = ""; | 88 *cache_identity = ""; |
84 // We can only resolve keys in the files/ namespace. | 89 // We can only resolve keys in the files/ namespace. |
85 const nacl::string kFilesPrefix = "files/"; | 90 const nacl::string kFilesPrefix = "files/"; |
86 size_t files_prefix_pos = key.find(kFilesPrefix); | 91 size_t files_prefix_pos = key.find(kFilesPrefix); |
87 if (files_prefix_pos == nacl::string::npos) { | 92 if (files_prefix_pos == nacl::string::npos) { |
88 error_info->SetReport(ERROR_MANIFEST_RESOLVE_URL, | 93 error_info->SetReport(ERROR_MANIFEST_RESOLVE_URL, |
89 "key did not start with files/"); | 94 "key did not start with files/"); |
90 return false; | 95 return false; |
91 } | 96 } |
92 // Append what follows files to the pnacl URL prefix. | 97 // Append what follows files to the pnacl URL prefix. |
93 nacl::string key_basename = key.substr(kFilesPrefix.length()); | 98 nacl::string key_basename = key.substr(kFilesPrefix.length()); |
94 return ResolveURL(key_basename, full_url, error_info); | 99 return ResolveURL(key_basename, full_url, error_info); |
95 } | 100 } |
96 | 101 |
97 private: | 102 private: |
98 NACL_DISALLOW_COPY_AND_ASSIGN(ExtensionManifest); | 103 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclManifest); |
99 | 104 |
100 const pp::URLUtil_Dev* url_util_; | 105 const pp::URLUtil_Dev* url_util_; |
101 nacl::string manifest_base_url_; | 106 nacl::string manifest_base_url_; |
102 }; | 107 }; |
103 | 108 |
104 // TEMPORARY: ld needs to look up dynamic libraries in the nexe's manifest | 109 // TEMPORARY: ld needs to look up dynamic libraries in the nexe's manifest |
105 // until metadata is complete in pexes. This manifest lookup allows looking | 110 // until metadata is complete in pexes. This manifest lookup allows looking |
106 // for whether a resource requested by ld is in the nexe manifest first, and | 111 // for whether a resource requested by ld is in the nexe manifest first, and |
107 // if not, then consults the extension manifest. | 112 // if not, then consults the extension manifest. |
108 // TODO(sehr,jvoung,pdox): remove this when metadata is correct. | 113 // TODO(sehr,jvoung,pdox): remove this when metadata is correct. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 pp::CompletionCallback resources_cb = | 203 pp::CompletionCallback resources_cb = |
199 coordinator->callback_factory_.NewCallback( | 204 coordinator->callback_factory_.NewCallback( |
200 &PnaclCoordinator::ResourcesDidLoad); | 205 &PnaclCoordinator::ResourcesDidLoad); |
201 coordinator->resources_.reset( | 206 coordinator->resources_.reset( |
202 new PnaclResources(plugin, | 207 new PnaclResources(plugin, |
203 coordinator, | 208 coordinator, |
204 coordinator->manifest_.get(), | 209 coordinator->manifest_.get(), |
205 resource_urls, | 210 resource_urls, |
206 resources_cb)); | 211 resources_cb)); |
207 CHECK(coordinator->resources_ != NULL); | 212 CHECK(coordinator->resources_ != NULL); |
208 coordinator->resources_->StartDownloads(); | 213 coordinator->resources_->StartLoad(); |
209 // ResourcesDidLoad will be invoked when all resources have been received. | 214 // ResourcesDidLoad will be invoked when all resources have been received. |
210 return coordinator; | 215 return coordinator; |
211 } | 216 } |
212 | 217 |
213 int32_t PnaclCoordinator::GetLoadedFileDesc(int32_t pp_error, | 218 int32_t PnaclCoordinator::GetLoadedFileDesc(int32_t pp_error, |
214 const nacl::string& url, | 219 const nacl::string& url, |
215 const nacl::string& component) { | 220 const nacl::string& component) { |
216 PLUGIN_PRINTF(("PnaclCoordinator::GetLoadedFileDesc (pp_error=%" | 221 PLUGIN_PRINTF(("PnaclCoordinator::GetLoadedFileDesc (pp_error=%" |
217 NACL_PRId32", url=%s, component=%s)\n", pp_error, | 222 NACL_PRId32", url=%s, component=%s)\n", pp_error, |
218 url.c_str(), component.c_str())); | 223 url.c_str(), component.c_str())); |
(...skipping 12 matching lines...) Expand all Loading... |
231 | 236 |
232 PnaclCoordinator::PnaclCoordinator( | 237 PnaclCoordinator::PnaclCoordinator( |
233 Plugin* plugin, | 238 Plugin* plugin, |
234 const nacl::string& pexe_url, | 239 const nacl::string& pexe_url, |
235 const nacl::string& cache_identity, | 240 const nacl::string& cache_identity, |
236 const pp::CompletionCallback& translate_notify_callback) | 241 const pp::CompletionCallback& translate_notify_callback) |
237 : translate_finish_error_(PP_OK), | 242 : translate_finish_error_(PP_OK), |
238 plugin_(plugin), | 243 plugin_(plugin), |
239 translate_notify_callback_(translate_notify_callback), | 244 translate_notify_callback_(translate_notify_callback), |
240 file_system_(new pp::FileSystem(plugin, PP_FILESYSTEMTYPE_LOCALTEMPORARY)), | 245 file_system_(new pp::FileSystem(plugin, PP_FILESYSTEMTYPE_LOCALTEMPORARY)), |
241 manifest_(new ExtensionManifest(plugin->url_util())), | 246 manifest_(new PnaclManifest( |
| 247 plugin->url_util(), |
| 248 plugin::PnaclUrls::UsePnaclExtension(plugin))), |
242 pexe_url_(pexe_url), | 249 pexe_url_(pexe_url), |
243 cache_identity_(cache_identity), | 250 cache_identity_(cache_identity), |
244 error_already_reported_(false), | 251 error_already_reported_(false), |
245 off_the_record_(false) { | 252 off_the_record_(false) { |
246 PLUGIN_PRINTF(("PnaclCoordinator::PnaclCoordinator (this=%p, plugin=%p)\n", | 253 PLUGIN_PRINTF(("PnaclCoordinator::PnaclCoordinator (this=%p, plugin=%p)\n", |
247 static_cast<void*>(this), static_cast<void*>(plugin))); | 254 static_cast<void*>(this), static_cast<void*>(plugin))); |
248 callback_factory_.Initialize(this); | 255 callback_factory_.Initialize(this); |
249 ld_manifest_.reset(new PnaclLDManifest(plugin_->manifest(), manifest_.get())); | 256 ld_manifest_.reset(new PnaclLDManifest(plugin_->manifest(), manifest_.get())); |
250 } | 257 } |
251 | 258 |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 manifest_.get(), | 626 manifest_.get(), |
620 ld_manifest_.get(), | 627 ld_manifest_.get(), |
621 obj_file_.get(), | 628 obj_file_.get(), |
622 temp_nexe_file_.get(), | 629 temp_nexe_file_.get(), |
623 &error_info_, | 630 &error_info_, |
624 resources_.get(), | 631 resources_.get(), |
625 plugin_); | 632 plugin_); |
626 } | 633 } |
627 | 634 |
628 } // namespace plugin | 635 } // namespace plugin |
OLD | NEW |