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

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

Issue 8974020: Change pnacl to read all resources from the extension. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/portability_io.h" 10 #include "native_client/src/include/portability_io.h"
(...skipping 15 matching lines...) Expand all
26 26
27 namespace plugin { 27 namespace plugin {
28 28
29 class Plugin; 29 class Plugin;
30 30
31 namespace { 31 namespace {
32 32
33 const char kLlcUrl[] = "llc"; 33 const char kLlcUrl[] = "llc";
34 const char kLdUrl[] = "ld"; 34 const char kLdUrl[] = "ld";
35 35
36 nacl::string ResourceBaseUrl() { 36 nacl::string ExtensionUrl() {
37 return nacl::string("pnacl_support/") + GetSandboxISA() + "/"; 37 const nacl::string kPnaclExtensionOrigin =
38 "chrome-extension://gcodniebolpnpaiggndmcmmfpldlknih/";
elijahtaylor (use chromium) 2011/12/19 21:42:52 Hard-coded extension string seems a bit fragile...
sehr (please use chromium) 2011/12/20 01:48:38 I agree that we need to have a better way to refer
39 return kPnaclExtensionOrigin + GetSandboxISA() + "/";
38 } 40 }
39 41
40 nacl::string Random32CharHexString(struct NaClDescRng* rng) { 42 nacl::string Random32CharHexString(struct NaClDescRng* rng) {
41 struct NaClDesc* desc = reinterpret_cast<struct NaClDesc*>(rng); 43 struct NaClDesc* desc = reinterpret_cast<struct NaClDesc*>(rng);
42 const struct NaClDescVtbl* vtbl = 44 const struct NaClDescVtbl* vtbl =
43 reinterpret_cast<const struct NaClDescVtbl*>(desc->base.vtbl); 45 reinterpret_cast<const struct NaClDescVtbl*>(desc->base.vtbl);
44 46
45 nacl::string hex_string; 47 nacl::string hex_string;
46 const int32_t kTempFileNameWords = 4; 48 const int32_t kTempFileNameWords = 4;
47 for (int32_t i = 0; i < kTempFileNameWords; ++i) { 49 for (int32_t i = 0; i < kTempFileNameWords; ++i) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // Run the client's completion callback. 167 // Run the client's completion callback.
166 pp::Core* core = pp::Module::Get()->core(); 168 pp::Core* core = pp::Module::Get()->core();
167 core->CallOnMainThread(0, done_callback_, PP_OK); 169 core->CallOnMainThread(0, done_callback_, PP_OK);
168 } 170 }
169 171
170 ////////////////////////////////////////////////////////////////////// 172 //////////////////////////////////////////////////////////////////////
171 // Pnacl-specific manifest support. 173 // Pnacl-specific manifest support.
172 ////////////////////////////////////////////////////////////////////// 174 //////////////////////////////////////////////////////////////////////
173 class PnaclManifest : public Manifest { 175 class PnaclManifest : public Manifest {
174 public: 176 public:
175 PnaclManifest(const pp::URLUtil_Dev* url_util, 177 PnaclManifest(const pp::URLUtil_Dev* url_util)
176 const nacl::string& manifest_base_url) 178 : Manifest(url_util, ExtensionUrl(), GetSandboxISA(), false) {
177 : Manifest(url_util, manifest_base_url, GetSandboxISA(), false) {
178 size_t last_slash_pos = manifest_base_url_.rfind("/");
179 CHECK(last_slash_pos != nacl::string::npos);
180 // url_prefix contains everything in manifest_base_url up to and including
181 // the last slash.
182 url_prefix_ =
183 manifest_base_url_.substr(0, last_slash_pos + 1) + ResourceBaseUrl();
184 } 179 }
185 virtual ~PnaclManifest() { } 180 virtual ~PnaclManifest() { }
186 181
187 virtual bool GetProgramURL(nacl::string* full_url, 182 virtual bool GetProgramURL(nacl::string* full_url,
188 ErrorInfo* error_info, 183 ErrorInfo* error_info,
189 bool* is_portable) { 184 bool* is_portable) {
190 // Does not contain program urls. 185 // Does not contain program urls.
191 UNREFERENCED_PARAMETER(full_url); 186 UNREFERENCED_PARAMETER(full_url);
192 UNREFERENCED_PARAMETER(error_info); 187 UNREFERENCED_PARAMETER(error_info);
193 UNREFERENCED_PARAMETER(is_portable); 188 UNREFERENCED_PARAMETER(is_portable);
194 PLUGIN_PRINTF(("PnaclManifest does not contain a program\n")); 189 PLUGIN_PRINTF(("PnaclManifest does not contain a program\n"));
195 error_info->SetReport(ERROR_MANIFEST_GET_NEXE_URL, 190 error_info->SetReport(ERROR_MANIFEST_GET_NEXE_URL,
196 "pnacl manifest does not contain a program"); 191 "pnacl manifest does not contain a program");
197 return false; 192 return false;
198 } 193 }
199 194
200 virtual bool ResolveURL(const nacl::string& relative_url, 195 virtual bool ResolveURL(const nacl::string& relative_url,
201 nacl::string* full_url, 196 nacl::string* full_url,
202 ErrorInfo* error_info) const { 197 ErrorInfo* error_info) const {
203 // Does not do general URL resolution, simply appends relative_url to 198 // Does not do general URL resolution, simply appends relative_url to
204 // the end of url_prefix_. 199 // the end of manifest_base_url_.
205 UNREFERENCED_PARAMETER(error_info); 200 UNREFERENCED_PARAMETER(error_info);
206 *full_url = url_prefix_ + relative_url; 201 *full_url = manifest_base_url_ + relative_url;
207 return true; 202 return true;
208 } 203 }
209 204
210 virtual bool GetFileKeys(std::set<nacl::string>* keys) const { 205 virtual bool GetFileKeys(std::set<nacl::string>* keys) const {
211 // Does not support enumeration. 206 // Does not support enumeration.
212 PLUGIN_PRINTF(("PnaclManifest does not support key enumeration\n")); 207 PLUGIN_PRINTF(("PnaclManifest does not support key enumeration\n"));
213 UNREFERENCED_PARAMETER(keys); 208 UNREFERENCED_PARAMETER(keys);
214 return false; 209 return false;
215 } 210 }
216 211
217 virtual bool ResolveKey(const nacl::string& key, 212 virtual bool ResolveKey(const nacl::string& key,
218 nacl::string* full_url, 213 nacl::string* full_url,
219 ErrorInfo* error_info, 214 ErrorInfo* error_info,
220 bool* is_portable) const { 215 bool* is_portable) const {
221 *is_portable = false; 216 *is_portable = false;
222 // We can only resolve keys in the files/ namespace. 217 // We can only resolve keys in the files/ namespace.
223 const nacl::string kFilesPrefix = "files/"; 218 const nacl::string kFilesPrefix = "files/";
224 size_t files_prefix_pos = key.find(kFilesPrefix); 219 size_t files_prefix_pos = key.find(kFilesPrefix);
225 if (files_prefix_pos == nacl::string::npos) { 220 if (files_prefix_pos == nacl::string::npos) {
226 error_info->SetReport(ERROR_MANIFEST_RESOLVE_URL, 221 error_info->SetReport(ERROR_MANIFEST_RESOLVE_URL,
227 "key did not start with files/"); 222 "key did not start with files/");
228 return false; 223 return false;
229 } 224 }
230 // Append what follows files to the pnacl URL prefix. 225 // Append what follows files to the pnacl URL prefix.
231 nacl::string key_basename = key.substr(kFilesPrefix.length()); 226 nacl::string key_basename = key.substr(kFilesPrefix.length());
232 return ResolveURL(key_basename, full_url, error_info); 227 return ResolveURL(key_basename, full_url, error_info);
233 } 228 }
234 229
235 private: 230 // Since the pnacl coordinator manifest is in a base in the chrome extension
236 nacl::string url_prefix_; 231 // scheme, lookups will need to access resources in their extension origin.
232 virtual bool PermitsExtensionUrls() const {
233 return true;
234 }
237 }; 235 };
238 236
239 ////////////////////////////////////////////////////////////////////// 237 //////////////////////////////////////////////////////////////////////
240 // The coordinator class. 238 // The coordinator class.
241 ////////////////////////////////////////////////////////////////////// 239 //////////////////////////////////////////////////////////////////////
242 PnaclCoordinator* PnaclCoordinator::BitcodeToNative( 240 PnaclCoordinator* PnaclCoordinator::BitcodeToNative(
243 Plugin* plugin, 241 Plugin* plugin,
244 const nacl::string& pexe_url, 242 const nacl::string& pexe_url,
245 const pp::CompletionCallback& translate_notify_callback) { 243 const pp::CompletionCallback& translate_notify_callback) {
246 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n", 244 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n",
247 static_cast<void*>(plugin), pexe_url.c_str())); 245 static_cast<void*>(plugin), pexe_url.c_str()));
248 PnaclCoordinator* coordinator = 246 PnaclCoordinator* coordinator =
249 new PnaclCoordinator(plugin, 247 new PnaclCoordinator(plugin, pexe_url, translate_notify_callback);
250 pexe_url, 248 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (manifest=%p)\n",
251 translate_notify_callback, 249 reinterpret_cast<const void*>(coordinator->manifest_)));
252 ResourceBaseUrl());
253 // Load llc and ld. 250 // Load llc and ld.
254 std::vector<nacl::string> resource_urls; 251 std::vector<nacl::string> resource_urls;
255 resource_urls.push_back(kLlcUrl); 252 resource_urls.push_back(kLlcUrl);
256 resource_urls.push_back(kLdUrl); 253 resource_urls.push_back(kLdUrl);
257 pp::CompletionCallback resources_cb = 254 pp::CompletionCallback resources_cb =
258 coordinator->callback_factory_.NewCallback( 255 coordinator->callback_factory_.NewCallback(
259 &PnaclCoordinator::ResourcesDidLoad); 256 &PnaclCoordinator::ResourcesDidLoad);
260 coordinator->resources_.reset( 257 coordinator->resources_.reset(
261 new PnaclResources(plugin, 258 new PnaclResources(plugin,
262 coordinator, 259 coordinator,
263 coordinator->resource_base_url_, 260 coordinator->manifest_,
264 resource_urls, 261 resource_urls,
265 resources_cb)); 262 resources_cb));
266 CHECK(coordinator->resources_ != NULL); 263 CHECK(coordinator->resources_ != NULL);
267 coordinator->resources_->StartDownloads(); 264 coordinator->resources_->StartDownloads();
268 // ResourcesDidLoad will be invoked when all resources have been received. 265 // ResourcesDidLoad will be invoked when all resources have been received.
269 return coordinator; 266 return coordinator;
270 } 267 }
271 268
272 int32_t PnaclCoordinator::GetLoadedFileDesc(int32_t pp_error, 269 int32_t PnaclCoordinator::GetLoadedFileDesc(int32_t pp_error,
273 const nacl::string& url, 270 const nacl::string& url,
(...skipping 16 matching lines...) Expand all
290 if (file_desc_ok_to_close == NACL_NO_FILE_DESC) { 287 if (file_desc_ok_to_close == NACL_NO_FILE_DESC) {
291 ReportPpapiError(PP_ERROR_FAILED, component + " could not dup fd.\n"); 288 ReportPpapiError(PP_ERROR_FAILED, component + " could not dup fd.\n");
292 return -1; 289 return -1;
293 } 290 }
294 return file_desc_ok_to_close; 291 return file_desc_ok_to_close;
295 } 292 }
296 293
297 PnaclCoordinator::PnaclCoordinator( 294 PnaclCoordinator::PnaclCoordinator(
298 Plugin* plugin, 295 Plugin* plugin,
299 const nacl::string& pexe_url, 296 const nacl::string& pexe_url,
300 const pp::CompletionCallback& translate_notify_callback, 297 const pp::CompletionCallback& translate_notify_callback)
301 const nacl::string& resource_base_url)
302 : plugin_(plugin), 298 : plugin_(plugin),
303 translate_notify_callback_(translate_notify_callback), 299 translate_notify_callback_(translate_notify_callback),
304 resource_base_url_(resource_base_url),
305 llc_subprocess_(NULL), 300 llc_subprocess_(NULL),
306 ld_subprocess_(NULL), 301 ld_subprocess_(NULL),
307 subprocesses_should_die_(false), 302 subprocesses_should_die_(false),
308 file_system_(new pp::FileSystem(plugin, PP_FILESYSTEMTYPE_LOCALTEMPORARY)), 303 file_system_(new pp::FileSystem(plugin, PP_FILESYSTEMTYPE_LOCALTEMPORARY)),
309 // TODO(sehr,jvoung): change base url to pnacl extension/testing url. 304 // TODO(sehr,jvoung): change base url to pnacl extension/testing url.
jvoung - send to chromium... 2011/12/19 21:37:08 TODO can be removed now =)
elijahtaylor (use chromium) 2011/12/19 21:42:52 Time to remove TODO?
sehr (please use chromium) 2011/12/20 01:48:38 Done.
sehr (please use chromium) 2011/12/20 01:48:38 Done.
310 manifest_(new PnaclManifest(plugin->url_util(), 305 manifest_(new PnaclManifest(plugin->url_util())),
311 plugin->manifest_base_url())),
312 pexe_url_(pexe_url) { 306 pexe_url_(pexe_url) {
313 PLUGIN_PRINTF(("PnaclCoordinator::PnaclCoordinator (this=%p, plugin=%p)\n", 307 PLUGIN_PRINTF(("PnaclCoordinator::PnaclCoordinator (this=%p, plugin=%p)\n",
314 static_cast<void*>(this), static_cast<void*>(plugin))); 308 static_cast<void*>(this), static_cast<void*>(plugin)));
315 callback_factory_.Initialize(this); 309 callback_factory_.Initialize(this);
316 NaClXMutexCtor(&subprocess_mu_); 310 NaClXMutexCtor(&subprocess_mu_);
317 // Check the temporary file system.
318 CHECK(file_system_ != NULL);
elijahtaylor (use chromium) 2011/12/19 21:42:52 Why did you delete this check?
sehr (please use chromium) 2011/12/20 01:48:38 In chrome, new throws rather than returning null,
319 } 311 }
320 312
321 PnaclCoordinator::~PnaclCoordinator() { 313 PnaclCoordinator::~PnaclCoordinator() {
322 PLUGIN_PRINTF(("PnaclCoordinator::~PnaclCoordinator (this=%p)\n", 314 PLUGIN_PRINTF(("PnaclCoordinator::~PnaclCoordinator (this=%p)\n",
323 static_cast<void*>(this))); 315 static_cast<void*>(this)));
324 // Join helper thread which will block the page from refreshing while a 316 // Join helper thread which will block the page from refreshing while a
325 // translation is happening. 317 // translation is happening.
326 if (translate_thread_.get() != NULL) { 318 if (translate_thread_.get() != NULL) {
327 SetSubprocessesShouldDie(true); 319 SetSubprocessesShouldDie(true);
328 NaClThreadJoin(translate_thread_.get()); 320 NaClThreadJoin(translate_thread_.get());
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 PLUGIN_PRINTF(("PnaclCoordinator::NexePairDidOpen (pp_error=%" 418 PLUGIN_PRINTF(("PnaclCoordinator::NexePairDidOpen (pp_error=%"
427 NACL_PRId32")\n", pp_error)); 419 NACL_PRId32")\n", pp_error));
428 if (pp_error != PP_OK) { 420 if (pp_error != PP_OK) {
429 ReportPpapiError(pp_error); 421 ReportPpapiError(pp_error);
430 return; 422 return;
431 } 423 }
432 // Load the pexe file and get the translation started. 424 // Load the pexe file and get the translation started.
433 pp::CompletionCallback cb = 425 pp::CompletionCallback cb =
434 callback_factory_.NewCallback(&PnaclCoordinator::RunTranslate); 426 callback_factory_.NewCallback(&PnaclCoordinator::RunTranslate);
435 427
436 if (!plugin_->StreamAsFile(pexe_url_, cb.pp_completion_callback())) { 428 if (!plugin_->StreamAsFile(pexe_url_,
429 manifest_->PermitsExtensionUrls(),
430 cb.pp_completion_callback())) {
437 ReportNonPpapiError(nacl::string("failed to download ") + pexe_url_ + "\n"); 431 ReportNonPpapiError(nacl::string("failed to download ") + pexe_url_ + "\n");
438 } 432 }
439 } 433 }
440 434
441 void PnaclCoordinator::RunTranslate(int32_t pp_error) { 435 void PnaclCoordinator::RunTranslate(int32_t pp_error) {
442 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" 436 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%"
443 NACL_PRId32")\n", pp_error)); 437 NACL_PRId32")\n", pp_error));
444 int32_t fd = GetLoadedFileDesc(pp_error, pexe_url_, "pexe"); 438 int32_t fd = GetLoadedFileDesc(pp_error, pexe_url_, "pexe");
445 if (fd < 0) { 439 if (fd < 0) {
446 return; 440 return;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 nacl::MutexLocker ml(&subprocess_mu_); 549 nacl::MutexLocker ml(&subprocess_mu_);
556 return subprocesses_should_die_; 550 return subprocesses_should_die_;
557 } 551 }
558 552
559 void PnaclCoordinator::SetSubprocessesShouldDie(bool subprocesses_should_die) { 553 void PnaclCoordinator::SetSubprocessesShouldDie(bool subprocesses_should_die) {
560 nacl::MutexLocker ml(&subprocess_mu_); 554 nacl::MutexLocker ml(&subprocess_mu_);
561 subprocesses_should_die_ = subprocesses_should_die; 555 subprocesses_should_die_ = subprocesses_should_die;
562 } 556 }
563 557
564 } // namespace plugin 558 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698