| 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 "chrome/common/extensions/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
| 6 | 6 |
| 7 #include <ostream> | 7 #include <ostream> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/chrome_version_info.h" | 28 #include "chrome/common/chrome_version_info.h" |
| 29 #include "chrome/common/extensions/csp_validator.h" | 29 #include "chrome/common/extensions/csp_validator.h" |
| 30 #include "chrome/common/extensions/extension_manifest_constants.h" | 30 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 31 #include "chrome/common/extensions/extension_resource.h" | 31 #include "chrome/common/extensions/extension_resource.h" |
| 32 #include "chrome/common/extensions/feature_switch.h" | 32 #include "chrome/common/extensions/feature_switch.h" |
| 33 #include "chrome/common/extensions/features/base_feature_provider.h" | 33 #include "chrome/common/extensions/features/base_feature_provider.h" |
| 34 #include "chrome/common/extensions/features/feature.h" | 34 #include "chrome/common/extensions/features/feature.h" |
| 35 #include "chrome/common/extensions/manifest.h" | 35 #include "chrome/common/extensions/manifest.h" |
| 36 #include "chrome/common/extensions/manifest_handler.h" | 36 #include "chrome/common/extensions/manifest_handler.h" |
| 37 #include "chrome/common/extensions/manifest_url_handler.h" |
| 37 #include "chrome/common/extensions/permissions/permission_set.h" | 38 #include "chrome/common/extensions/permissions/permission_set.h" |
| 38 #include "chrome/common/extensions/permissions/permissions_info.h" | 39 #include "chrome/common/extensions/permissions/permissions_info.h" |
| 39 #include "chrome/common/extensions/user_script.h" | 40 #include "chrome/common/extensions/user_script.h" |
| 40 #include "chrome/common/url_constants.h" | 41 #include "chrome/common/url_constants.h" |
| 41 #include "crypto/sha2.h" | 42 #include "crypto/sha2.h" |
| 42 #include "extensions/common/constants.h" | 43 #include "extensions/common/constants.h" |
| 43 #include "extensions/common/error_utils.h" | 44 #include "extensions/common/error_utils.h" |
| 44 #include "extensions/common/url_pattern_set.h" | 45 #include "extensions/common/url_pattern_set.h" |
| 45 #include "googleurl/src/url_util.h" | 46 #include "googleurl/src/url_util.h" |
| 46 #include "grit/chromium_strings.h" | 47 #include "grit/chromium_strings.h" |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 DictionaryValue* info) const { | 464 DictionaryValue* info) const { |
| 464 info->SetString(info_keys::kIdKey, id()); | 465 info->SetString(info_keys::kIdKey, id()); |
| 465 info->SetString(info_keys::kNameKey, name()); | 466 info->SetString(info_keys::kNameKey, name()); |
| 466 info->SetBoolean(info_keys::kEnabledKey, enabled); | 467 info->SetBoolean(info_keys::kEnabledKey, enabled); |
| 467 info->SetBoolean(info_keys::kOfflineEnabledKey, offline_enabled()); | 468 info->SetBoolean(info_keys::kOfflineEnabledKey, offline_enabled()); |
| 468 info->SetString(info_keys::kVersionKey, VersionString()); | 469 info->SetString(info_keys::kVersionKey, VersionString()); |
| 469 info->SetString(info_keys::kDescriptionKey, description()); | 470 info->SetString(info_keys::kDescriptionKey, description()); |
| 470 info->SetString(info_keys::kOptionsUrlKey, | 471 info->SetString(info_keys::kOptionsUrlKey, |
| 471 options_url().possibly_invalid_spec()); | 472 options_url().possibly_invalid_spec()); |
| 472 info->SetString(info_keys::kHomepageUrlKey, | 473 info->SetString(info_keys::kHomepageUrlKey, |
| 473 GetHomepageURL().possibly_invalid_spec()); | 474 ManifestURL::GetHomepageURL(this).possibly_invalid_spec()); |
| 474 info->SetString(info_keys::kDetailsUrlKey, | 475 info->SetString(info_keys::kDetailsUrlKey, |
| 475 details_url().possibly_invalid_spec()); | 476 details_url().possibly_invalid_spec()); |
| 476 info->SetBoolean(info_keys::kPackagedAppKey, is_platform_app()); | 477 info->SetBoolean(info_keys::kPackagedAppKey, is_platform_app()); |
| 477 } | 478 } |
| 478 | 479 |
| 479 Extension::Type Extension::GetType() const { | 480 Extension::Type Extension::GetType() const { |
| 480 return converted_from_user_script() ? TYPE_USER_SCRIPT : manifest_->type(); | 481 return converted_from_user_script() ? TYPE_USER_SCRIPT : manifest_->type(); |
| 481 } | 482 } |
| 482 | 483 |
| 483 // static | 484 // static |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 } | 929 } |
| 929 | 930 |
| 930 bool Extension::ShowConfigureContextMenus() const { | 931 bool Extension::ShowConfigureContextMenus() const { |
| 931 // Don't show context menu for component extensions. We might want to show | 932 // Don't show context menu for component extensions. We might want to show |
| 932 // options for component extension button but now there is no component | 933 // options for component extension button but now there is no component |
| 933 // extension with options. All other menu items like uninstall have | 934 // extension with options. All other menu items like uninstall have |
| 934 // no sense for component extensions. | 935 // no sense for component extensions. |
| 935 return location() != Extension::COMPONENT; | 936 return location() != Extension::COMPONENT; |
| 936 } | 937 } |
| 937 | 938 |
| 938 GURL Extension::GetHomepageURL() const { | |
| 939 if (homepage_url_.is_valid()) | |
| 940 return homepage_url_; | |
| 941 | |
| 942 return UpdatesFromGallery() ? | |
| 943 GURL(extension_urls::GetWebstoreItemDetailURLPrefix() + id()) : GURL(); | |
| 944 } | |
| 945 | |
| 946 std::set<FilePath> Extension::GetBrowserImages() const { | 939 std::set<FilePath> Extension::GetBrowserImages() const { |
| 947 std::set<FilePath> image_paths; | 940 std::set<FilePath> image_paths; |
| 948 // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())| | 941 // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())| |
| 949 // indicate that we're doing something wrong. | 942 // indicate that we're doing something wrong. |
| 950 | 943 |
| 951 // Extension icons. | 944 // Extension icons. |
| 952 for (ExtensionIconSet::IconMap::const_iterator iter = icons().map().begin(); | 945 for (ExtensionIconSet::IconMap::const_iterator iter = icons().map().begin(); |
| 953 iter != icons().map().end(); ++iter) { | 946 iter != icons().map().end(); ++iter) { |
| 954 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second))); | 947 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second))); |
| 955 } | 948 } |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1617 return false; | 1610 return false; |
| 1618 | 1611 |
| 1619 if (!LoadManagedModeFeatures(error)) | 1612 if (!LoadManagedModeFeatures(error)) |
| 1620 return false; | 1613 return false; |
| 1621 | 1614 |
| 1622 if (HasMultipleUISurfaces()) { | 1615 if (HasMultipleUISurfaces()) { |
| 1623 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); | 1616 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); |
| 1624 return false; | 1617 return false; |
| 1625 } | 1618 } |
| 1626 | 1619 |
| 1620 finished_parsing_manifest_ = true; |
| 1621 |
| 1627 runtime_data_.SetActivePermissions(new PermissionSet( | 1622 runtime_data_.SetActivePermissions(new PermissionSet( |
| 1628 this, api_permissions, host_permissions)); | 1623 this, api_permissions, host_permissions)); |
| 1629 required_permission_set_ = new PermissionSet( | 1624 required_permission_set_ = new PermissionSet( |
| 1630 this, api_permissions, host_permissions); | 1625 this, api_permissions, host_permissions); |
| 1631 optional_permission_set_ = new PermissionSet( | 1626 optional_permission_set_ = new PermissionSet( |
| 1632 optional_api_permissions, optional_host_permissions, URLPatternSet()); | 1627 optional_api_permissions, optional_host_permissions, URLPatternSet()); |
| 1633 | 1628 |
| 1634 finished_parsing_manifest_ = true; | |
| 1635 | |
| 1636 return true; | 1629 return true; |
| 1637 } | 1630 } |
| 1638 | 1631 |
| 1639 bool Extension::LoadAppIsolation(const APIPermissionSet& api_permissions, | 1632 bool Extension::LoadAppIsolation(const APIPermissionSet& api_permissions, |
| 1640 string16* error) { | 1633 string16* error) { |
| 1641 // Platform apps always get isolated storage. | 1634 // Platform apps always get isolated storage. |
| 1642 if (is_platform_app()) { | 1635 if (is_platform_app()) { |
| 1643 is_storage_isolated_ = true; | 1636 is_storage_isolated_ = true; |
| 1644 return true; | 1637 return true; |
| 1645 } | 1638 } |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1964 extent_.ClearPatterns(); | 1957 extent_.ClearPatterns(); |
| 1965 } | 1958 } |
| 1966 | 1959 |
| 1967 return true; | 1960 return true; |
| 1968 } | 1961 } |
| 1969 | 1962 |
| 1970 bool Extension::LoadSharedFeatures( | 1963 bool Extension::LoadSharedFeatures( |
| 1971 const APIPermissionSet& api_permissions, | 1964 const APIPermissionSet& api_permissions, |
| 1972 string16* error) { | 1965 string16* error) { |
| 1973 if (!LoadDescription(error) || | 1966 if (!LoadDescription(error) || |
| 1974 !LoadHomepageURL(error) || | |
| 1975 !LoadUpdateURL(error) || | 1967 !LoadUpdateURL(error) || |
| 1976 !LoadIcons(error) || | 1968 !LoadIcons(error) || |
| 1977 !LoadCommands(error) || | 1969 !LoadCommands(error) || |
| 1978 !LoadPlugins(error) || | 1970 !LoadPlugins(error) || |
| 1979 !LoadNaClModules(error) || | 1971 !LoadNaClModules(error) || |
| 1980 !LoadWebAccessibleResources(error) || | 1972 !LoadWebAccessibleResources(error) || |
| 1981 !LoadSandboxedPages(error) || | 1973 !LoadSandboxedPages(error) || |
| 1982 !LoadRequirements(error) || | 1974 !LoadRequirements(error) || |
| 1983 !LoadDefaultLocale(error) || | 1975 !LoadDefaultLocale(error) || |
| 1984 !LoadOfflineEnabled(error) || | 1976 !LoadOfflineEnabled(error) || |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2022 switches::kAllowLegacyExtensionManifests)) { | 2014 switches::kAllowLegacyExtensionManifests)) { |
| 2023 *error = ErrorUtils::FormatErrorMessageUTF16( | 2015 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 2024 errors::kInvalidManifestVersionOld, | 2016 errors::kInvalidManifestVersionOld, |
| 2025 base::IntToString(kModernManifestVersion)); | 2017 base::IntToString(kModernManifestVersion)); |
| 2026 return false; | 2018 return false; |
| 2027 } | 2019 } |
| 2028 | 2020 |
| 2029 return true; | 2021 return true; |
| 2030 } | 2022 } |
| 2031 | 2023 |
| 2032 bool Extension::LoadHomepageURL(string16* error) { | |
| 2033 if (!manifest_->HasKey(keys::kHomepageURL)) | |
| 2034 return true; | |
| 2035 std::string tmp_homepage_url; | |
| 2036 if (!manifest_->GetString(keys::kHomepageURL, &tmp_homepage_url)) { | |
| 2037 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 2038 errors::kInvalidHomepageURL, ""); | |
| 2039 return false; | |
| 2040 } | |
| 2041 homepage_url_ = GURL(tmp_homepage_url); | |
| 2042 if (!homepage_url_.is_valid() || | |
| 2043 (!homepage_url_.SchemeIs("http") && | |
| 2044 !homepage_url_.SchemeIs("https"))) { | |
| 2045 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 2046 errors::kInvalidHomepageURL, tmp_homepage_url); | |
| 2047 return false; | |
| 2048 } | |
| 2049 return true; | |
| 2050 } | |
| 2051 | |
| 2052 bool Extension::LoadUpdateURL(string16* error) { | 2024 bool Extension::LoadUpdateURL(string16* error) { |
| 2053 if (!manifest_->HasKey(keys::kUpdateURL)) | 2025 if (!manifest_->HasKey(keys::kUpdateURL)) |
| 2054 return true; | 2026 return true; |
| 2055 std::string tmp_update_url; | 2027 std::string tmp_update_url; |
| 2056 if (!manifest_->GetString(keys::kUpdateURL, &tmp_update_url)) { | 2028 if (!manifest_->GetString(keys::kUpdateURL, &tmp_update_url)) { |
| 2057 *error = ErrorUtils::FormatErrorMessageUTF16( | 2029 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 2058 errors::kInvalidUpdateURL, ""); | 2030 errors::kInvalidUpdateURL, ""); |
| 2059 return false; | 2031 return false; |
| 2060 } | 2032 } |
| 2061 update_url_ = GURL(tmp_update_url); | 2033 update_url_ = GURL(tmp_update_url); |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2658 return true; | 2630 return true; |
| 2659 } | 2631 } |
| 2660 | 2632 |
| 2661 bool Extension::LoadExtensionFeatures(APIPermissionSet* api_permissions, | 2633 bool Extension::LoadExtensionFeatures(APIPermissionSet* api_permissions, |
| 2662 string16* error) { | 2634 string16* error) { |
| 2663 if (manifest_->HasKey(keys::kConvertedFromUserScript)) | 2635 if (manifest_->HasKey(keys::kConvertedFromUserScript)) |
| 2664 manifest_->GetBoolean(keys::kConvertedFromUserScript, | 2636 manifest_->GetBoolean(keys::kConvertedFromUserScript, |
| 2665 &converted_from_user_script_); | 2637 &converted_from_user_script_); |
| 2666 | 2638 |
| 2667 if (!LoadManifestHandlerFeatures(error) || | 2639 if (!LoadManifestHandlerFeatures(error) || |
| 2668 !LoadDevToolsPage(error) || | |
| 2669 !LoadContentScripts(error) || | 2640 !LoadContentScripts(error) || |
| 2670 !LoadPageAction(error) || | 2641 !LoadPageAction(error) || |
| 2671 !LoadBrowserAction(error) || | 2642 !LoadBrowserAction(error) || |
| 2672 !LoadSystemIndicator(api_permissions, error) || | 2643 !LoadSystemIndicator(api_permissions, error) || |
| 2673 !LoadScriptBadge(error) || | 2644 !LoadScriptBadge(error) || |
| 2674 !LoadChromeURLOverrides(error) || | 2645 !LoadChromeURLOverrides(error) || |
| 2675 !LoadIncognitoMode(error) || | 2646 !LoadIncognitoMode(error) || |
| 2676 !LoadFileHandlers(error) || | 2647 !LoadFileHandlers(error) || |
| 2677 !LoadContentSecurityPolicy(error)) | 2648 !LoadContentSecurityPolicy(error)) |
| 2678 return false; | 2649 return false; |
| 2679 | 2650 |
| 2680 return true; | 2651 return true; |
| 2681 } | 2652 } |
| 2682 | 2653 |
| 2683 bool Extension::LoadManifestHandlerFeatures(string16* error) { | 2654 bool Extension::LoadManifestHandlerFeatures(string16* error) { |
| 2684 std::vector<std::string> keys = ManifestHandler::GetKeys(); | 2655 std::vector<std::string> keys = ManifestHandler::GetKeys(); |
| 2685 for (size_t i = 0; i < keys.size(); ++i) { | 2656 for (size_t i = 0; i < keys.size(); ++i) { |
| 2686 Value* value = NULL; | 2657 Value* value = NULL; |
| 2687 if (!manifest_->Get(keys[i], &value)) | 2658 if (!manifest_->Get(keys[i], &value)) |
| 2688 continue; | 2659 continue; |
| 2689 if (!ManifestHandler::Get(keys[i])->Parse(value, this, error)) | 2660 if (!ManifestHandler::Get(keys[i])->Parse(value, this, error)) |
| 2690 return false; | 2661 return false; |
| 2691 } | 2662 } |
| 2692 return true; | 2663 return true; |
| 2693 } | 2664 } |
| 2694 | 2665 |
| 2695 bool Extension::LoadDevToolsPage(string16* error) { | |
| 2696 if (!manifest_->HasKey(keys::kDevToolsPage)) | |
| 2697 return true; | |
| 2698 std::string devtools_str; | |
| 2699 if (!manifest_->GetString(keys::kDevToolsPage, &devtools_str)) { | |
| 2700 *error = ASCIIToUTF16(errors::kInvalidDevToolsPage); | |
| 2701 return false; | |
| 2702 } | |
| 2703 devtools_url_ = GetResourceURL(devtools_str); | |
| 2704 return true; | |
| 2705 } | |
| 2706 | |
| 2707 bool Extension::LoadContentScripts(string16* error) { | 2666 bool Extension::LoadContentScripts(string16* error) { |
| 2708 if (!manifest_->HasKey(keys::kContentScripts)) | 2667 if (!manifest_->HasKey(keys::kContentScripts)) |
| 2709 return true; | 2668 return true; |
| 2710 ListValue* list_value; | 2669 ListValue* list_value; |
| 2711 if (!manifest_->GetList(keys::kContentScripts, &list_value)) { | 2670 if (!manifest_->GetList(keys::kContentScripts, &list_value)) { |
| 2712 *error = ASCIIToUTF16(errors::kInvalidContentScriptsList); | 2671 *error = ASCIIToUTF16(errors::kInvalidContentScriptsList); |
| 2713 return false; | 2672 return false; |
| 2714 } | 2673 } |
| 2715 | 2674 |
| 2716 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 2675 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
| (...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3703 | 3662 |
| 3704 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3663 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 3705 const Extension* extension, | 3664 const Extension* extension, |
| 3706 const PermissionSet* permissions, | 3665 const PermissionSet* permissions, |
| 3707 Reason reason) | 3666 Reason reason) |
| 3708 : reason(reason), | 3667 : reason(reason), |
| 3709 extension(extension), | 3668 extension(extension), |
| 3710 permissions(permissions) {} | 3669 permissions(permissions) {} |
| 3711 | 3670 |
| 3712 } // namespace extensions | 3671 } // namespace extensions |
| OLD | NEW |