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

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

Issue 235983020: Pepper: Move PnaclOptions outside trusted plugin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: another build fix Created 6 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ppapi/native_client/src/trusted/plugin/json_manifest.h" 9 #include "ppapi/native_client/src/trusted/plugin/json_manifest.h"
10 10
11 #include <stdlib.h> 11 #include <stdlib.h>
12 12
13 #include "native_client/src/include/nacl_base.h" 13 #include "native_client/src/include/nacl_base.h"
14 #include "native_client/src/include/nacl_macros.h" 14 #include "native_client/src/include/nacl_macros.h"
15 #include "native_client/src/include/nacl_string.h" 15 #include "native_client/src/include/nacl_string.h"
16 #include "native_client/src/include/portability.h" 16 #include "native_client/src/include/portability.h"
17 #include "native_client/src/shared/platform/nacl_check.h" 17 #include "native_client/src/shared/platform/nacl_check.h"
18 #include "ppapi/c/private/ppb_nacl_private.h"
18 #include "ppapi/cpp/dev/url_util_dev.h" 19 #include "ppapi/cpp/dev/url_util_dev.h"
19 #include "ppapi/cpp/var.h" 20 #include "ppapi/cpp/var.h"
20 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" 21 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h"
21 #include "ppapi/native_client/src/trusted/plugin/pnacl_options.h"
22 #include "ppapi/native_client/src/trusted/plugin/utility.h" 22 #include "ppapi/native_client/src/trusted/plugin/utility.h"
23 #include "third_party/jsoncpp/source/include/json/reader.h" 23 #include "third_party/jsoncpp/source/include/json/reader.h"
24 24
25 namespace plugin { 25 namespace plugin {
26 26
27 namespace { 27 namespace {
28 // Top-level section name keys 28 // Top-level section name keys
29 const char* const kProgramKey = "program"; 29 const char* const kProgramKey = "program";
30 const char* const kInterpreterKey = "interpreter"; 30 const char* const kInterpreterKey = "interpreter";
31 const char* const kFilesKey = "files"; 31 const char* const kFilesKey = "files";
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 PP_NACL_ERROR_MANIFEST_PROGRAM_MISSING_ARCH, 374 PP_NACL_ERROR_MANIFEST_PROGRAM_MISSING_ARCH,
375 nacl::string("manifest: no version of ") + parent_key + 375 nacl::string("manifest: no version of ") + parent_key +
376 " given for current arch and no portable version found."); 376 " given for current arch and no portable version found.");
377 return false; 377 return false;
378 } 378 }
379 } 379 }
380 380
381 return true; 381 return true;
382 } 382 }
383 383
384 void GrabUrlAndPnaclOptions(const Json::Value& url_spec, 384 void GrabUrlAndPP_PNaClOptions(const Json::Value& url_spec,
dmichael (off chromium) 2014/04/15 23:15:04 I think you can keep the old name... this looks a
385 nacl::string* url, 385 nacl::string* url,
386 PnaclOptions* pnacl_options) { 386 PP_PNaClOptions* pnacl_options) {
387 *url = url_spec[kUrlKey].asString(); 387 *url = url_spec[kUrlKey].asString();
388 pnacl_options->set_translate(true); 388 pnacl_options->translate = PP_TRUE;
389 if (url_spec.isMember(kOptLevelKey)) { 389 if (url_spec.isMember(kOptLevelKey)) {
390 int32_t opt_raw = url_spec[kOptLevelKey].asInt(); 390 int32_t opt_raw = url_spec[kOptLevelKey].asInt();
391 // set_opt_level will normalize the values. 391 int32_t opt_level;
392 pnacl_options->set_opt_level(opt_raw); 392 if (opt_raw <= 0)
393 opt_level = 0;
394 else
395 opt_level = 2;
dmichael (off chromium) 2014/04/15 23:15:04 Maybe duplicate the comment from pnacl_options.cc,
396 pnacl_options->opt_level = opt_level;
393 } 397 }
394 } 398 }
395 399
396 } // namespace 400 } // namespace
397 401
398 bool JsonManifest::Init(const nacl::string& manifest_json, 402 bool JsonManifest::Init(const nacl::string& manifest_json,
399 ErrorInfo* error_info) { 403 ErrorInfo* error_info) {
400 if (error_info == NULL) { 404 if (error_info == NULL) {
401 return false; 405 return false;
402 } 406 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 } 500 }
497 } 501 }
498 } 502 }
499 503
500 return true; 504 return true;
501 } 505 }
502 506
503 bool JsonManifest::GetURLFromISADictionary(const Json::Value& dictionary, 507 bool JsonManifest::GetURLFromISADictionary(const Json::Value& dictionary,
504 const nacl::string& parent_key, 508 const nacl::string& parent_key,
505 nacl::string* url, 509 nacl::string* url,
506 PnaclOptions* pnacl_options, 510 PP_PNaClOptions* pnacl_options,
507 bool* uses_nonsfi_mode, 511 bool* uses_nonsfi_mode,
508 ErrorInfo* error_info) const { 512 ErrorInfo* error_info) const {
509 DCHECK(url != NULL && pnacl_options != NULL && error_info != NULL); 513 DCHECK(url != NULL && pnacl_options != NULL && error_info != NULL);
510 514
511 // When the application actually requests a resolved URL, we must have 515 // When the application actually requests a resolved URL, we must have
512 // a matching entry (sandbox_isa_ or portable) for NaCl. 516 // a matching entry (sandbox_isa_ or portable) for NaCl.
513 if (!IsValidISADictionary(dictionary, parent_key, sandbox_isa_, true, 517 if (!IsValidISADictionary(dictionary, parent_key, sandbox_isa_, true,
514 nonsfi_enabled_, error_info)) { 518 nonsfi_enabled_, error_info)) {
515 error_info->SetReport(PP_NACL_ERROR_MANIFEST_RESOLVE_URL, 519 error_info->SetReport(PP_NACL_ERROR_MANIFEST_RESOLVE_URL,
516 "architecture " + sandbox_isa_ + 520 "architecture " + sandbox_isa_ +
(...skipping 22 matching lines...) Expand all
539 // call checked that the manifest covers the current architecture. 543 // call checked that the manifest covers the current architecture.
540 DCHECK(false); 544 DCHECK(false);
541 } 545 }
542 } 546 }
543 547
544 const Json::Value& isa_spec = dictionary[chosen_isa]; 548 const Json::Value& isa_spec = dictionary[chosen_isa];
545 // If the PNaCl debug flag is turned on, look for pnacl-debug entries first. 549 // If the PNaCl debug flag is turned on, look for pnacl-debug entries first.
546 // If found, mark that it is a debug URL. Otherwise, fall back to 550 // If found, mark that it is a debug URL. Otherwise, fall back to
547 // checking for pnacl-translate URLs, etc. and don't mark it as a debug URL. 551 // checking for pnacl-translate URLs, etc. and don't mark it as a debug URL.
548 if (pnacl_debug_ && isa_spec.isMember(kPnaclDebugKey)) { 552 if (pnacl_debug_ && isa_spec.isMember(kPnaclDebugKey)) {
549 GrabUrlAndPnaclOptions(isa_spec[kPnaclDebugKey], url, pnacl_options); 553 GrabUrlAndPP_PNaClOptions(isa_spec[kPnaclDebugKey], url, pnacl_options);
550 pnacl_options->set_debug(true); 554 pnacl_options->is_debug = PP_TRUE;
551 } else if (isa_spec.isMember(kPnaclTranslateKey)) { 555 } else if (isa_spec.isMember(kPnaclTranslateKey)) {
552 GrabUrlAndPnaclOptions(isa_spec[kPnaclTranslateKey], url, pnacl_options); 556 GrabUrlAndPP_PNaClOptions(isa_spec[kPnaclTranslateKey], url, pnacl_options);
553 } else { 557 } else {
554 // NaCl 558 // NaCl
555 *url = isa_spec[kUrlKey].asString(); 559 *url = isa_spec[kUrlKey].asString();
556 pnacl_options->set_translate(false); 560 pnacl_options->translate = PP_FALSE;
557 } 561 }
558 562
559 return true; 563 return true;
560 } 564 }
561 565
562 bool JsonManifest::GetKeyUrl(const Json::Value& dictionary, 566 bool JsonManifest::GetKeyUrl(const Json::Value& dictionary,
563 const nacl::string& key, 567 const nacl::string& key,
564 nacl::string* full_url, 568 nacl::string* full_url,
565 PnaclOptions* pnacl_options, 569 PP_PNaClOptions* pnacl_options,
566 ErrorInfo* error_info) const { 570 ErrorInfo* error_info) const {
567 DCHECK(full_url != NULL && pnacl_options != NULL && error_info != NULL); 571 DCHECK(full_url != NULL && pnacl_options != NULL && error_info != NULL);
568 if (!dictionary.isMember(key)) { 572 if (!dictionary.isMember(key)) {
569 error_info->SetReport(PP_NACL_ERROR_MANIFEST_RESOLVE_URL, 573 error_info->SetReport(PP_NACL_ERROR_MANIFEST_RESOLVE_URL,
570 "file key not found in manifest"); 574 "file key not found in manifest");
571 return false; 575 return false;
572 } 576 }
573 const Json::Value& isa_dict = dictionary[key]; 577 const Json::Value& isa_dict = dictionary[key];
574 nacl::string relative_url; 578 nacl::string relative_url;
575 bool uses_nonsfi_mode; 579 bool uses_nonsfi_mode;
576 if (!GetURLFromISADictionary(isa_dict, key, &relative_url, 580 if (!GetURLFromISADictionary(isa_dict, key, &relative_url,
577 pnacl_options, &uses_nonsfi_mode, error_info)) { 581 pnacl_options, &uses_nonsfi_mode, error_info)) {
578 return false; 582 return false;
579 } 583 }
580 return ResolveURL(relative_url, full_url, error_info); 584 return ResolveURL(relative_url, full_url, error_info);
581 } 585 }
582 586
583 bool JsonManifest::GetProgramURL(nacl::string* full_url, 587 bool JsonManifest::GetProgramURL(nacl::string* full_url,
584 PnaclOptions* pnacl_options, 588 PP_PNaClOptions* pnacl_options,
585 bool* uses_nonsfi_mode, 589 bool* uses_nonsfi_mode,
586 ErrorInfo* error_info) const { 590 ErrorInfo* error_info) const {
587 if (full_url == NULL || pnacl_options == NULL || error_info == NULL) 591 if (full_url == NULL || pnacl_options == NULL || error_info == NULL)
588 return false; 592 return false;
589 593
590 const Json::Value& program = dictionary_[kProgramKey]; 594 const Json::Value& program = dictionary_[kProgramKey];
591 595
592 nacl::string nexe_url; 596 nacl::string nexe_url;
593 nacl::string error_string; 597 nacl::string error_string;
594 598
(...skipping 18 matching lines...) Expand all
613 CHECK(files.isObject()); 617 CHECK(files.isObject());
614 Json::Value::Members members = files.getMemberNames(); 618 Json::Value::Members members = files.getMemberNames();
615 for (size_t i = 0; i < members.size(); ++i) { 619 for (size_t i = 0; i < members.size(); ++i) {
616 keys->insert(members[i]); 620 keys->insert(members[i]);
617 } 621 }
618 return true; 622 return true;
619 } 623 }
620 624
621 bool JsonManifest::ResolveKey(const nacl::string& key, 625 bool JsonManifest::ResolveKey(const nacl::string& key,
622 nacl::string* full_url, 626 nacl::string* full_url,
623 PnaclOptions* pnacl_options, 627 PP_PNaClOptions* pnacl_options,
624 ErrorInfo* error_info) const { 628 ErrorInfo* error_info) const {
625 NaClLog(3, "JsonManifest::ResolveKey(%s)\n", key.c_str()); 629 NaClLog(3, "JsonManifest::ResolveKey(%s)\n", key.c_str());
626 // key must be one of kProgramKey or kFileKey '/' file-section-key 630 // key must be one of kProgramKey or kFileKey '/' file-section-key
627 631
628 if (full_url == NULL || pnacl_options == NULL || error_info == NULL) 632 if (full_url == NULL || pnacl_options == NULL || error_info == NULL)
629 return false; 633 return false;
630 634
631 if (key == kProgramKey) { 635 if (key == kProgramKey) {
632 return GetKeyUrl(dictionary_, key, full_url, pnacl_options, error_info); 636 return GetKeyUrl(dictionary_, key, full_url, pnacl_options, error_info);
633 } 637 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 "could not resolve url '" + relative_url + 684 "could not resolve url '" + relative_url +
681 "' relative to manifest base url '" + manifest_base_url_.c_str() + 685 "' relative to manifest base url '" + manifest_base_url_.c_str() +
682 "'."); 686 "'.");
683 return false; 687 return false;
684 } 688 }
685 *full_url = resolved_url.AsString(); 689 *full_url = resolved_url.AsString();
686 return true; 690 return true;
687 } 691 }
688 692
689 } // namespace plugin 693 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698