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

Side by Side Diff: extensions/common/extension.cc

Issue 112963005: Update uses of UTF conversions in courgette/, device/, extensions/, google_apis/, gpu/, ipc/, media… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 12 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
« no previous file with comments | « extensions/common/error_utils.cc ('k') | extensions/common/manifest_handler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "extensions/common/extension.h" 5 #include "extensions/common/extension.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 int flags, 110 int flags,
111 const std::string& explicit_id, 111 const std::string& explicit_id,
112 std::string* utf8_error) { 112 std::string* utf8_error) {
113 DCHECK(utf8_error); 113 DCHECK(utf8_error);
114 base::string16 error; 114 base::string16 error;
115 scoped_ptr<extensions::Manifest> manifest( 115 scoped_ptr<extensions::Manifest> manifest(
116 new extensions::Manifest( 116 new extensions::Manifest(
117 location, scoped_ptr<base::DictionaryValue>(value.DeepCopy()))); 117 location, scoped_ptr<base::DictionaryValue>(value.DeepCopy())));
118 118
119 if (!InitExtensionID(manifest.get(), path, explicit_id, flags, &error)) { 119 if (!InitExtensionID(manifest.get(), path, explicit_id, flags, &error)) {
120 *utf8_error = UTF16ToUTF8(error); 120 *utf8_error = base::UTF16ToUTF8(error);
121 return NULL; 121 return NULL;
122 } 122 }
123 123
124 std::vector<InstallWarning> install_warnings; 124 std::vector<InstallWarning> install_warnings;
125 if (!manifest->ValidateManifest(utf8_error, &install_warnings)) { 125 if (!manifest->ValidateManifest(utf8_error, &install_warnings)) {
126 return NULL; 126 return NULL;
127 } 127 }
128 128
129 scoped_refptr<Extension> extension = new Extension(path, manifest.Pass()); 129 scoped_refptr<Extension> extension = new Extension(path, manifest.Pass());
130 extension->install_warnings_.swap(install_warnings); 130 extension->install_warnings_.swap(install_warnings);
131 131
132 if (!extension->InitFromValue(flags, &error)) { 132 if (!extension->InitFromValue(flags, &error)) {
133 *utf8_error = UTF16ToUTF8(error); 133 *utf8_error = base::UTF16ToUTF8(error);
134 return NULL; 134 return NULL;
135 } 135 }
136 136
137 return extension; 137 return extension;
138 } 138 }
139 139
140 // static 140 // static
141 bool Extension::IdIsValid(const std::string& id) { 141 bool Extension::IdIsValid(const std::string& id) {
142 // Verify that the id is legal. 142 // Verify that the id is legal.
143 if (id.size() != (id_util::kIdSize * 2)) 143 if (id.size() != (id_util::kIdSize * 2))
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 if (!explicit_id.empty()) { 472 if (!explicit_id.empty()) {
473 manifest->set_extension_id(explicit_id); 473 manifest->set_extension_id(explicit_id);
474 return true; 474 return true;
475 } 475 }
476 476
477 if (manifest->HasKey(keys::kPublicKey)) { 477 if (manifest->HasKey(keys::kPublicKey)) {
478 std::string public_key; 478 std::string public_key;
479 std::string public_key_bytes; 479 std::string public_key_bytes;
480 if (!manifest->GetString(keys::kPublicKey, &public_key) || 480 if (!manifest->GetString(keys::kPublicKey, &public_key) ||
481 !ParsePEMKeyBytes(public_key, &public_key_bytes)) { 481 !ParsePEMKeyBytes(public_key, &public_key_bytes)) {
482 *error = ASCIIToUTF16(errors::kInvalidKey); 482 *error = base::ASCIIToUTF16(errors::kInvalidKey);
483 return false; 483 return false;
484 } 484 }
485 std::string extension_id = id_util::GenerateId(public_key_bytes); 485 std::string extension_id = id_util::GenerateId(public_key_bytes);
486 manifest->set_extension_id(extension_id); 486 manifest->set_extension_id(extension_id);
487 return true; 487 return true;
488 } 488 }
489 489
490 if (creation_flags & REQUIRE_KEY) { 490 if (creation_flags & REQUIRE_KEY) {
491 *error = ASCIIToUTF16(errors::kInvalidKey); 491 *error = base::ASCIIToUTF16(errors::kInvalidKey);
492 return false; 492 return false;
493 } else { 493 } else {
494 // If there is a path, we generate the ID from it. This is useful for 494 // If there is a path, we generate the ID from it. This is useful for
495 // development mode, because it keeps the ID stable across restarts and 495 // development mode, because it keeps the ID stable across restarts and
496 // reloading the extension. 496 // reloading the extension.
497 std::string extension_id = id_util::GenerateIdForPath(path); 497 std::string extension_id = id_util::GenerateIdForPath(path);
498 if (extension_id.empty()) { 498 if (extension_id.empty()) {
499 NOTREACHED() << "Could not create ID from path."; 499 NOTREACHED() << "Could not create ID from path.";
500 return false; 500 return false;
501 } 501 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 bool Extension::LoadRequiredFeatures(base::string16* error) { 568 bool Extension::LoadRequiredFeatures(base::string16* error) {
569 if (!LoadName(error) || 569 if (!LoadName(error) ||
570 !LoadVersion(error)) 570 !LoadVersion(error))
571 return false; 571 return false;
572 return true; 572 return true;
573 } 573 }
574 574
575 bool Extension::LoadName(base::string16* error) { 575 bool Extension::LoadName(base::string16* error) {
576 base::string16 localized_name; 576 base::string16 localized_name;
577 if (!manifest_->GetString(keys::kName, &localized_name)) { 577 if (!manifest_->GetString(keys::kName, &localized_name)) {
578 *error = ASCIIToUTF16(errors::kInvalidName); 578 *error = base::ASCIIToUTF16(errors::kInvalidName);
579 return false; 579 return false;
580 } 580 }
581 non_localized_name_ = UTF16ToUTF8(localized_name); 581 non_localized_name_ = base::UTF16ToUTF8(localized_name);
582 base::i18n::AdjustStringForLocaleDirection(&localized_name); 582 base::i18n::AdjustStringForLocaleDirection(&localized_name);
583 name_ = UTF16ToUTF8(localized_name); 583 name_ = base::UTF16ToUTF8(localized_name);
584 return true; 584 return true;
585 } 585 }
586 586
587 bool Extension::LoadVersion(base::string16* error) { 587 bool Extension::LoadVersion(base::string16* error) {
588 std::string version_str; 588 std::string version_str;
589 if (!manifest_->GetString(keys::kVersion, &version_str)) { 589 if (!manifest_->GetString(keys::kVersion, &version_str)) {
590 *error = ASCIIToUTF16(errors::kInvalidVersion); 590 *error = base::ASCIIToUTF16(errors::kInvalidVersion);
591 return false; 591 return false;
592 } 592 }
593 version_.reset(new base::Version(version_str)); 593 version_.reset(new base::Version(version_str));
594 if (!version_->IsValid() || version_->components().size() > 4) { 594 if (!version_->IsValid() || version_->components().size() > 4) {
595 *error = ASCIIToUTF16(errors::kInvalidVersion); 595 *error = base::ASCIIToUTF16(errors::kInvalidVersion);
596 return false; 596 return false;
597 } 597 }
598 return true; 598 return true;
599 } 599 }
600 600
601 bool Extension::LoadAppFeatures(base::string16* error) { 601 bool Extension::LoadAppFeatures(base::string16* error) {
602 if (!LoadExtent(keys::kWebURLs, &extent_, 602 if (!LoadExtent(keys::kWebURLs, &extent_,
603 errors::kInvalidWebURLs, errors::kInvalidWebURL, error)) { 603 errors::kInvalidWebURLs, errors::kInvalidWebURL, error)) {
604 return false; 604 return false;
605 } 605 }
606 if (manifest_->HasKey(keys::kDisplayInLauncher) && 606 if (manifest_->HasKey(keys::kDisplayInLauncher) &&
607 !manifest_->GetBoolean(keys::kDisplayInLauncher, &display_in_launcher_)) { 607 !manifest_->GetBoolean(keys::kDisplayInLauncher, &display_in_launcher_)) {
608 *error = ASCIIToUTF16(errors::kInvalidDisplayInLauncher); 608 *error = base::ASCIIToUTF16(errors::kInvalidDisplayInLauncher);
609 return false; 609 return false;
610 } 610 }
611 if (manifest_->HasKey(keys::kDisplayInNewTabPage)) { 611 if (manifest_->HasKey(keys::kDisplayInNewTabPage)) {
612 if (!manifest_->GetBoolean(keys::kDisplayInNewTabPage, 612 if (!manifest_->GetBoolean(keys::kDisplayInNewTabPage,
613 &display_in_new_tab_page_)) { 613 &display_in_new_tab_page_)) {
614 *error = ASCIIToUTF16(errors::kInvalidDisplayInNewTabPage); 614 *error = base::ASCIIToUTF16(errors::kInvalidDisplayInNewTabPage);
615 return false; 615 return false;
616 } 616 }
617 } else { 617 } else {
618 // Inherit default from display_in_launcher property. 618 // Inherit default from display_in_launcher property.
619 display_in_new_tab_page_ = display_in_launcher_; 619 display_in_new_tab_page_ = display_in_launcher_;
620 } 620 }
621 return true; 621 return true;
622 } 622 }
623 623
624 bool Extension::LoadExtent(const char* key, 624 bool Extension::LoadExtent(const char* key,
625 URLPatternSet* extent, 625 URLPatternSet* extent,
626 const char* list_error, 626 const char* list_error,
627 const char* value_error, 627 const char* value_error,
628 base::string16* error) { 628 base::string16* error) {
629 const base::Value* temp_pattern_value = NULL; 629 const base::Value* temp_pattern_value = NULL;
630 if (!manifest_->Get(key, &temp_pattern_value)) 630 if (!manifest_->Get(key, &temp_pattern_value))
631 return true; 631 return true;
632 632
633 const base::ListValue* pattern_list = NULL; 633 const base::ListValue* pattern_list = NULL;
634 if (!temp_pattern_value->GetAsList(&pattern_list)) { 634 if (!temp_pattern_value->GetAsList(&pattern_list)) {
635 *error = ASCIIToUTF16(list_error); 635 *error = base::ASCIIToUTF16(list_error);
636 return false; 636 return false;
637 } 637 }
638 638
639 for (size_t i = 0; i < pattern_list->GetSize(); ++i) { 639 for (size_t i = 0; i < pattern_list->GetSize(); ++i) {
640 std::string pattern_string; 640 std::string pattern_string;
641 if (!pattern_list->GetString(i, &pattern_string)) { 641 if (!pattern_list->GetString(i, &pattern_string)) {
642 *error = ErrorUtils::FormatErrorMessageUTF16(value_error, 642 *error = ErrorUtils::FormatErrorMessageUTF16(value_error,
643 base::UintToString(i), 643 base::UintToString(i),
644 errors::kExpectString); 644 errors::kExpectString);
645 return false; 645 return false;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 !ManifestHandler::ParseExtension(this, error) || 700 !ManifestHandler::ParseExtension(this, error) ||
701 !LoadShortName(error)) 701 !LoadShortName(error))
702 return false; 702 return false;
703 703
704 return true; 704 return true;
705 } 705 }
706 706
707 bool Extension::LoadDescription(base::string16* error) { 707 bool Extension::LoadDescription(base::string16* error) {
708 if (manifest_->HasKey(keys::kDescription) && 708 if (manifest_->HasKey(keys::kDescription) &&
709 !manifest_->GetString(keys::kDescription, &description_)) { 709 !manifest_->GetString(keys::kDescription, &description_)) {
710 *error = ASCIIToUTF16(errors::kInvalidDescription); 710 *error = base::ASCIIToUTF16(errors::kInvalidDescription);
711 return false; 711 return false;
712 } 712 }
713 return true; 713 return true;
714 } 714 }
715 715
716 bool Extension::LoadManifestVersion(base::string16* error) { 716 bool Extension::LoadManifestVersion(base::string16* error) {
717 // Get the original value out of the dictionary so that we can validate it 717 // Get the original value out of the dictionary so that we can validate it
718 // more strictly. 718 // more strictly.
719 if (manifest_->value()->HasKey(keys::kManifestVersion)) { 719 if (manifest_->value()->HasKey(keys::kManifestVersion)) {
720 int manifest_version = 1; 720 int manifest_version = 1;
721 if (!manifest_->GetInteger(keys::kManifestVersion, &manifest_version) || 721 if (!manifest_->GetInteger(keys::kManifestVersion, &manifest_version) ||
722 manifest_version < 1) { 722 manifest_version < 1) {
723 *error = ASCIIToUTF16(errors::kInvalidManifestVersion); 723 *error = base::ASCIIToUTF16(errors::kInvalidManifestVersion);
724 return false; 724 return false;
725 } 725 }
726 } 726 }
727 727
728 manifest_version_ = manifest_->GetManifestVersion(); 728 manifest_version_ = manifest_->GetManifestVersion();
729 if (manifest_version_ < kModernManifestVersion && 729 if (manifest_version_ < kModernManifestVersion &&
730 ((creation_flags_ & REQUIRE_MODERN_MANIFEST_VERSION && 730 ((creation_flags_ & REQUIRE_MODERN_MANIFEST_VERSION &&
731 !CommandLine::ForCurrentProcess()->HasSwitch( 731 !CommandLine::ForCurrentProcess()->HasSwitch(
732 switches::kAllowLegacyExtensionManifests)) || 732 switches::kAllowLegacyExtensionManifests)) ||
733 GetType() == Manifest::TYPE_PLATFORM_APP)) { 733 GetType() == Manifest::TYPE_PLATFORM_APP)) {
734 *error = ErrorUtils::FormatErrorMessageUTF16( 734 *error = ErrorUtils::FormatErrorMessageUTF16(
735 errors::kInvalidManifestVersionOld, 735 errors::kInvalidManifestVersionOld,
736 base::IntToString(kModernManifestVersion), 736 base::IntToString(kModernManifestVersion),
737 is_platform_app() ? "apps" : "extensions"); 737 is_platform_app() ? "apps" : "extensions");
738 return false; 738 return false;
739 } 739 }
740 740
741 return true; 741 return true;
742 } 742 }
743 743
744 bool Extension::LoadShortName(base::string16* error) { 744 bool Extension::LoadShortName(base::string16* error) {
745 if (manifest_->HasKey(keys::kShortName)) { 745 if (manifest_->HasKey(keys::kShortName)) {
746 base::string16 localized_short_name; 746 base::string16 localized_short_name;
747 if (!manifest_->GetString(keys::kShortName, &localized_short_name) || 747 if (!manifest_->GetString(keys::kShortName, &localized_short_name) ||
748 localized_short_name.empty()) { 748 localized_short_name.empty()) {
749 *error = ASCIIToUTF16(errors::kInvalidShortName); 749 *error = base::ASCIIToUTF16(errors::kInvalidShortName);
750 return false; 750 return false;
751 } 751 }
752 752
753 base::i18n::AdjustStringForLocaleDirection(&localized_short_name); 753 base::i18n::AdjustStringForLocaleDirection(&localized_short_name);
754 short_name_ = UTF16ToUTF8(localized_short_name); 754 short_name_ = base::UTF16ToUTF8(localized_short_name);
755 } else { 755 } else {
756 short_name_ = name_; 756 short_name_ = name_;
757 } 757 }
758 return true; 758 return true;
759 } 759 }
760 760
761 ExtensionInfo::ExtensionInfo(const base::DictionaryValue* manifest, 761 ExtensionInfo::ExtensionInfo(const base::DictionaryValue* manifest,
762 const std::string& id, 762 const std::string& id,
763 const base::FilePath& path, 763 const base::FilePath& path,
764 Manifest::Location location) 764 Manifest::Location location)
(...skipping 22 matching lines...) Expand all
787 787
788 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 788 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
789 const Extension* extension, 789 const Extension* extension,
790 const PermissionSet* permissions, 790 const PermissionSet* permissions,
791 Reason reason) 791 Reason reason)
792 : reason(reason), 792 : reason(reason),
793 extension(extension), 793 extension(extension),
794 permissions(permissions) {} 794 permissions(permissions) {}
795 795
796 } // namespace extensions 796 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/error_utils.cc ('k') | extensions/common/manifest_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698