OLD | NEW |
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 std::string* utf8_error) { | 96 std::string* utf8_error) { |
97 return Extension::Create(path, | 97 return Extension::Create(path, |
98 location, | 98 location, |
99 value, | 99 value, |
100 flags, | 100 flags, |
101 std::string(), // ID is ignored if empty. | 101 std::string(), // ID is ignored if empty. |
102 utf8_error); | 102 utf8_error); |
103 } | 103 } |
104 | 104 |
105 // TODO(sungguk): Continue removing std::string errors and replacing | 105 // TODO(sungguk): Continue removing std::string errors and replacing |
106 // with string16. See http://crbug.com/71980. | 106 // with base::string16. See http://crbug.com/71980. |
107 scoped_refptr<Extension> Extension::Create(const base::FilePath& path, | 107 scoped_refptr<Extension> Extension::Create(const base::FilePath& path, |
108 Manifest::Location location, | 108 Manifest::Location location, |
109 const base::DictionaryValue& value, | 109 const base::DictionaryValue& value, |
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 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 = UTF16ToUTF8(error); |
121 return NULL; | 121 return NULL; |
122 } | 122 } |
123 | 123 |
124 std::vector<InstallWarning> install_warnings; | 124 std::vector<InstallWarning> install_warnings; |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 | 461 |
462 bool Extension::is_theme() const { | 462 bool Extension::is_theme() const { |
463 return manifest()->is_theme(); | 463 return manifest()->is_theme(); |
464 } | 464 } |
465 | 465 |
466 // static | 466 // static |
467 bool Extension::InitExtensionID(extensions::Manifest* manifest, | 467 bool Extension::InitExtensionID(extensions::Manifest* manifest, |
468 const base::FilePath& path, | 468 const base::FilePath& path, |
469 const std::string& explicit_id, | 469 const std::string& explicit_id, |
470 int creation_flags, | 470 int creation_flags, |
471 string16* error) { | 471 base::string16* error) { |
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)) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 display_in_new_tab_page_(true), | 514 display_in_new_tab_page_(true), |
515 wants_file_access_(false), | 515 wants_file_access_(false), |
516 creation_flags_(0) { | 516 creation_flags_(0) { |
517 DCHECK(path.empty() || path.IsAbsolute()); | 517 DCHECK(path.empty() || path.IsAbsolute()); |
518 path_ = id_util::MaybeNormalizePath(path); | 518 path_ = id_util::MaybeNormalizePath(path); |
519 } | 519 } |
520 | 520 |
521 Extension::~Extension() { | 521 Extension::~Extension() { |
522 } | 522 } |
523 | 523 |
524 bool Extension::InitFromValue(int flags, string16* error) { | 524 bool Extension::InitFromValue(int flags, base::string16* error) { |
525 DCHECK(error); | 525 DCHECK(error); |
526 | 526 |
527 creation_flags_ = flags; | 527 creation_flags_ = flags; |
528 | 528 |
529 // Important to load manifest version first because many other features | 529 // Important to load manifest version first because many other features |
530 // depend on its value. | 530 // depend on its value. |
531 if (!LoadManifestVersion(error)) | 531 if (!LoadManifestVersion(error)) |
532 return false; | 532 return false; |
533 | 533 |
534 if (!LoadRequiredFeatures(error)) | 534 if (!LoadRequiredFeatures(error)) |
(...skipping 23 matching lines...) Expand all Loading... |
558 return false; | 558 return false; |
559 | 559 |
560 finished_parsing_manifest_ = true; | 560 finished_parsing_manifest_ = true; |
561 | 561 |
562 permissions_data_->InitializeManifestPermissions(this); | 562 permissions_data_->InitializeManifestPermissions(this); |
563 permissions_data_->FinalizePermissions(this); | 563 permissions_data_->FinalizePermissions(this); |
564 | 564 |
565 return true; | 565 return true; |
566 } | 566 } |
567 | 567 |
568 bool Extension::LoadRequiredFeatures(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(string16* error) { | 575 bool Extension::LoadName(base::string16* error) { |
576 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 = ASCIIToUTF16(errors::kInvalidName); |
579 return false; | 579 return false; |
580 } | 580 } |
581 non_localized_name_ = UTF16ToUTF8(localized_name); | 581 non_localized_name_ = UTF16ToUTF8(localized_name); |
582 base::i18n::AdjustStringForLocaleDirection(&localized_name); | 582 base::i18n::AdjustStringForLocaleDirection(&localized_name); |
583 name_ = UTF16ToUTF8(localized_name); | 583 name_ = UTF16ToUTF8(localized_name); |
584 return true; | 584 return true; |
585 } | 585 } |
586 | 586 |
587 bool Extension::LoadVersion(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 = ASCIIToUTF16(errors::kInvalidVersion); |
591 return false; | 591 return false; |
592 } | 592 } |
593 version_.reset(new Version(version_str)); | 593 version_.reset(new 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 = 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(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 = 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 = 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 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 = ASCIIToUTF16(list_error); |
636 return false; | 636 return false; |
637 } | 637 } |
638 | 638 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 return false; | 688 return false; |
689 } | 689 } |
690 pattern.SetPath(pattern.path() + '*'); | 690 pattern.SetPath(pattern.path() + '*'); |
691 | 691 |
692 extent->AddPattern(pattern); | 692 extent->AddPattern(pattern); |
693 } | 693 } |
694 | 694 |
695 return true; | 695 return true; |
696 } | 696 } |
697 | 697 |
698 bool Extension::LoadSharedFeatures(string16* error) { | 698 bool Extension::LoadSharedFeatures(base::string16* error) { |
699 if (!LoadDescription(error) || | 699 if (!LoadDescription(error) || |
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(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 = 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(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 = 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(string16* error) { | 744 bool Extension::LoadShortName(base::string16* error) { |
745 if (manifest_->HasKey(keys::kShortName)) { | 745 if (manifest_->HasKey(keys::kShortName)) { |
746 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 = 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_ = UTF16ToUTF8(localized_short_name); |
755 } else { | 755 } else { |
756 short_name_ = name_; | 756 short_name_ = name_; |
(...skipping 30 matching lines...) Expand all Loading... |
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 |
OLD | NEW |