| 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_info.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 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 DictionaryValue* info) const { | 477 DictionaryValue* info) const { |
| 477 info->SetString(info_keys::kIdKey, id()); | 478 info->SetString(info_keys::kIdKey, id()); |
| 478 info->SetString(info_keys::kNameKey, name()); | 479 info->SetString(info_keys::kNameKey, name()); |
| 479 info->SetBoolean(info_keys::kEnabledKey, enabled); | 480 info->SetBoolean(info_keys::kEnabledKey, enabled); |
| 480 info->SetBoolean(info_keys::kOfflineEnabledKey, offline_enabled()); | 481 info->SetBoolean(info_keys::kOfflineEnabledKey, offline_enabled()); |
| 481 info->SetString(info_keys::kVersionKey, VersionString()); | 482 info->SetString(info_keys::kVersionKey, VersionString()); |
| 482 info->SetString(info_keys::kDescriptionKey, description()); | 483 info->SetString(info_keys::kDescriptionKey, description()); |
| 483 info->SetString(info_keys::kOptionsUrlKey, | 484 info->SetString(info_keys::kOptionsUrlKey, |
| 484 options_url().possibly_invalid_spec()); | 485 options_url().possibly_invalid_spec()); |
| 485 info->SetString(info_keys::kHomepageUrlKey, | 486 info->SetString(info_keys::kHomepageUrlKey, |
| 486 GetHomepageURL().possibly_invalid_spec()); | 487 ManifestURLInfo::GetHomepageURL(this).possibly_invalid_spec()); |
| 487 info->SetString(info_keys::kDetailsUrlKey, | 488 info->SetString(info_keys::kDetailsUrlKey, |
| 488 details_url().possibly_invalid_spec()); | 489 details_url().possibly_invalid_spec()); |
| 489 info->SetBoolean(info_keys::kPackagedAppKey, is_platform_app()); | 490 info->SetBoolean(info_keys::kPackagedAppKey, is_platform_app()); |
| 490 } | 491 } |
| 491 | 492 |
| 492 Extension::Type Extension::GetType() const { | 493 Extension::Type Extension::GetType() const { |
| 493 return converted_from_user_script() ? TYPE_USER_SCRIPT : manifest_->type(); | 494 return converted_from_user_script() ? TYPE_USER_SCRIPT : manifest_->type(); |
| 494 } | 495 } |
| 495 | 496 |
| 496 // static | 497 // static |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 } | 942 } |
| 942 | 943 |
| 943 bool Extension::ShowConfigureContextMenus() const { | 944 bool Extension::ShowConfigureContextMenus() const { |
| 944 // Don't show context menu for component extensions. We might want to show | 945 // Don't show context menu for component extensions. We might want to show |
| 945 // options for component extension button but now there is no component | 946 // options for component extension button but now there is no component |
| 946 // extension with options. All other menu items like uninstall have | 947 // extension with options. All other menu items like uninstall have |
| 947 // no sense for component extensions. | 948 // no sense for component extensions. |
| 948 return location() != Extension::COMPONENT; | 949 return location() != Extension::COMPONENT; |
| 949 } | 950 } |
| 950 | 951 |
| 951 GURL Extension::GetHomepageURL() const { | |
| 952 if (homepage_url_.is_valid()) | |
| 953 return homepage_url_; | |
| 954 | |
| 955 return UpdatesFromGallery() ? | |
| 956 GURL(extension_urls::GetWebstoreItemDetailURLPrefix() + id()) : GURL(); | |
| 957 } | |
| 958 | |
| 959 std::set<FilePath> Extension::GetBrowserImages() const { | 952 std::set<FilePath> Extension::GetBrowserImages() const { |
| 960 std::set<FilePath> image_paths; | 953 std::set<FilePath> image_paths; |
| 961 // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())| | 954 // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())| |
| 962 // indicate that we're doing something wrong. | 955 // indicate that we're doing something wrong. |
| 963 | 956 |
| 964 // Extension icons. | 957 // Extension icons. |
| 965 for (ExtensionIconSet::IconMap::const_iterator iter = icons().map().begin(); | 958 for (ExtensionIconSet::IconMap::const_iterator iter = icons().map().begin(); |
| 966 iter != icons().map().end(); ++iter) { | 959 iter != icons().map().end(); ++iter) { |
| 967 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second))); | 960 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second))); |
| 968 } | 961 } |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1579 return false; | 1572 return false; |
| 1580 | 1573 |
| 1581 if (!LoadThemeFeatures(error)) | 1574 if (!LoadThemeFeatures(error)) |
| 1582 return false; | 1575 return false; |
| 1583 | 1576 |
| 1584 if (HasMultipleUISurfaces()) { | 1577 if (HasMultipleUISurfaces()) { |
| 1585 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); | 1578 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); |
| 1586 return false; | 1579 return false; |
| 1587 } | 1580 } |
| 1588 | 1581 |
| 1582 finished_parsing_manifest_ = true; |
| 1583 |
| 1589 runtime_data_.SetActivePermissions(new PermissionSet( | 1584 runtime_data_.SetActivePermissions(new PermissionSet( |
| 1590 this, api_permissions, host_permissions)); | 1585 this, api_permissions, host_permissions)); |
| 1591 required_permission_set_ = new PermissionSet( | 1586 required_permission_set_ = new PermissionSet( |
| 1592 this, api_permissions, host_permissions); | 1587 this, api_permissions, host_permissions); |
| 1593 optional_permission_set_ = new PermissionSet( | 1588 optional_permission_set_ = new PermissionSet( |
| 1594 optional_api_permissions, optional_host_permissions, URLPatternSet()); | 1589 optional_api_permissions, optional_host_permissions, URLPatternSet()); |
| 1595 | 1590 |
| 1596 finished_parsing_manifest_ = true; | |
| 1597 | |
| 1598 return true; | 1591 return true; |
| 1599 } | 1592 } |
| 1600 | 1593 |
| 1601 bool Extension::LoadAppIsolation(const APIPermissionSet& api_permissions, | 1594 bool Extension::LoadAppIsolation(const APIPermissionSet& api_permissions, |
| 1602 string16* error) { | 1595 string16* error) { |
| 1603 // Platform apps always get isolated storage. | 1596 // Platform apps always get isolated storage. |
| 1604 if (is_platform_app()) { | 1597 if (is_platform_app()) { |
| 1605 is_storage_isolated_ = true; | 1598 is_storage_isolated_ = true; |
| 1606 return true; | 1599 return true; |
| 1607 } | 1600 } |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1926 extent_.ClearPatterns(); | 1919 extent_.ClearPatterns(); |
| 1927 } | 1920 } |
| 1928 | 1921 |
| 1929 return true; | 1922 return true; |
| 1930 } | 1923 } |
| 1931 | 1924 |
| 1932 bool Extension::LoadSharedFeatures( | 1925 bool Extension::LoadSharedFeatures( |
| 1933 const APIPermissionSet& api_permissions, | 1926 const APIPermissionSet& api_permissions, |
| 1934 string16* error) { | 1927 string16* error) { |
| 1935 if (!LoadDescription(error) || | 1928 if (!LoadDescription(error) || |
| 1936 !LoadHomepageURL(error) || | |
| 1937 !LoadUpdateURL(error) || | 1929 !LoadUpdateURL(error) || |
| 1938 !LoadIcons(error) || | 1930 !LoadIcons(error) || |
| 1939 !LoadCommands(error) || | 1931 !LoadCommands(error) || |
| 1940 !LoadPlugins(error) || | 1932 !LoadPlugins(error) || |
| 1941 !LoadNaClModules(error) || | 1933 !LoadNaClModules(error) || |
| 1942 !LoadWebAccessibleResources(error) || | 1934 !LoadWebAccessibleResources(error) || |
| 1943 !LoadSandboxedPages(error) || | 1935 !LoadSandboxedPages(error) || |
| 1944 !LoadRequirements(error) || | 1936 !LoadRequirements(error) || |
| 1945 !LoadDefaultLocale(error) || | 1937 !LoadDefaultLocale(error) || |
| 1946 !LoadOfflineEnabled(error) || | 1938 !LoadOfflineEnabled(error) || |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1985 switches::kAllowLegacyExtensionManifests)) { | 1977 switches::kAllowLegacyExtensionManifests)) { |
| 1986 *error = ErrorUtils::FormatErrorMessageUTF16( | 1978 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 1987 errors::kInvalidManifestVersionOld, | 1979 errors::kInvalidManifestVersionOld, |
| 1988 base::IntToString(kModernManifestVersion)); | 1980 base::IntToString(kModernManifestVersion)); |
| 1989 return false; | 1981 return false; |
| 1990 } | 1982 } |
| 1991 | 1983 |
| 1992 return true; | 1984 return true; |
| 1993 } | 1985 } |
| 1994 | 1986 |
| 1995 bool Extension::LoadHomepageURL(string16* error) { | |
| 1996 if (!manifest_->HasKey(keys::kHomepageURL)) | |
| 1997 return true; | |
| 1998 std::string tmp_homepage_url; | |
| 1999 if (!manifest_->GetString(keys::kHomepageURL, &tmp_homepage_url)) { | |
| 2000 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 2001 errors::kInvalidHomepageURL, ""); | |
| 2002 return false; | |
| 2003 } | |
| 2004 homepage_url_ = GURL(tmp_homepage_url); | |
| 2005 if (!homepage_url_.is_valid() || | |
| 2006 (!homepage_url_.SchemeIs("http") && | |
| 2007 !homepage_url_.SchemeIs("https"))) { | |
| 2008 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 2009 errors::kInvalidHomepageURL, tmp_homepage_url); | |
| 2010 return false; | |
| 2011 } | |
| 2012 return true; | |
| 2013 } | |
| 2014 | |
| 2015 bool Extension::LoadUpdateURL(string16* error) { | 1987 bool Extension::LoadUpdateURL(string16* error) { |
| 2016 if (!manifest_->HasKey(keys::kUpdateURL)) | 1988 if (!manifest_->HasKey(keys::kUpdateURL)) |
| 2017 return true; | 1989 return true; |
| 2018 std::string tmp_update_url; | 1990 std::string tmp_update_url; |
| 2019 if (!manifest_->GetString(keys::kUpdateURL, &tmp_update_url)) { | 1991 if (!manifest_->GetString(keys::kUpdateURL, &tmp_update_url)) { |
| 2020 *error = ErrorUtils::FormatErrorMessageUTF16( | 1992 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 2021 errors::kInvalidUpdateURL, ""); | 1993 errors::kInvalidUpdateURL, ""); |
| 2022 return false; | 1994 return false; |
| 2023 } | 1995 } |
| 2024 update_url_ = GURL(tmp_update_url); | 1996 update_url_ = GURL(tmp_update_url); |
| (...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2783 return true; | 2755 return true; |
| 2784 } | 2756 } |
| 2785 | 2757 |
| 2786 bool Extension::LoadExtensionFeatures(APIPermissionSet* api_permissions, | 2758 bool Extension::LoadExtensionFeatures(APIPermissionSet* api_permissions, |
| 2787 string16* error) { | 2759 string16* error) { |
| 2788 if (manifest_->HasKey(keys::kConvertedFromUserScript)) | 2760 if (manifest_->HasKey(keys::kConvertedFromUserScript)) |
| 2789 manifest_->GetBoolean(keys::kConvertedFromUserScript, | 2761 manifest_->GetBoolean(keys::kConvertedFromUserScript, |
| 2790 &converted_from_user_script_); | 2762 &converted_from_user_script_); |
| 2791 | 2763 |
| 2792 if (!LoadManifestHandlerFeatures(error) || | 2764 if (!LoadManifestHandlerFeatures(error) || |
| 2793 !LoadDevToolsPage(error) || | |
| 2794 !LoadInputComponents(*api_permissions, error) || | 2765 !LoadInputComponents(*api_permissions, error) || |
| 2795 !LoadContentScripts(error) || | 2766 !LoadContentScripts(error) || |
| 2796 !LoadPageAction(error) || | 2767 !LoadPageAction(error) || |
| 2797 !LoadBrowserAction(error) || | 2768 !LoadBrowserAction(error) || |
| 2798 !LoadSystemIndicator(api_permissions, error) || | 2769 !LoadSystemIndicator(api_permissions, error) || |
| 2799 !LoadScriptBadge(error) || | 2770 !LoadScriptBadge(error) || |
| 2800 !LoadChromeURLOverrides(error) || | 2771 !LoadChromeURLOverrides(error) || |
| 2801 !LoadTextToSpeechVoices(error) || | 2772 !LoadTextToSpeechVoices(error) || |
| 2802 !LoadIncognitoMode(error) || | 2773 !LoadIncognitoMode(error) || |
| 2803 !LoadFileHandlers(error) || | 2774 !LoadFileHandlers(error) || |
| 2804 !LoadContentSecurityPolicy(error)) | 2775 !LoadContentSecurityPolicy(error)) |
| 2805 return false; | 2776 return false; |
| 2806 | 2777 |
| 2807 return true; | 2778 return true; |
| 2808 } | 2779 } |
| 2809 | 2780 |
| 2810 bool Extension::LoadManifestHandlerFeatures(string16* error) { | 2781 bool Extension::LoadManifestHandlerFeatures(string16* error) { |
| 2811 std::vector<std::string> keys = ManifestHandler::GetKeys(); | 2782 std::vector<std::string> keys = ManifestHandler::GetKeys(); |
| 2812 for (size_t i = 0; i < keys.size(); ++i) { | 2783 for (size_t i = 0; i < keys.size(); ++i) { |
| 2813 Value* value = NULL; | 2784 Value* value = NULL; |
| 2814 if (!manifest_->Get(keys[i], &value)) | 2785 if (!manifest_->Get(keys[i], &value)) |
| 2815 continue; | 2786 continue; |
| 2816 if (!ManifestHandler::Get(keys[i])->Parse(value, this, error)) | 2787 if (!ManifestHandler::Get(keys[i])->Parse(value, this, error)) |
| 2817 return false; | 2788 return false; |
| 2818 } | 2789 } |
| 2819 return true; | 2790 return true; |
| 2820 } | 2791 } |
| 2821 | 2792 |
| 2822 bool Extension::LoadDevToolsPage(string16* error) { | |
| 2823 if (!manifest_->HasKey(keys::kDevToolsPage)) | |
| 2824 return true; | |
| 2825 std::string devtools_str; | |
| 2826 if (!manifest_->GetString(keys::kDevToolsPage, &devtools_str)) { | |
| 2827 *error = ASCIIToUTF16(errors::kInvalidDevToolsPage); | |
| 2828 return false; | |
| 2829 } | |
| 2830 devtools_url_ = GetResourceURL(devtools_str); | |
| 2831 return true; | |
| 2832 } | |
| 2833 | |
| 2834 bool Extension::LoadInputComponents(const APIPermissionSet& api_permissions, | 2793 bool Extension::LoadInputComponents(const APIPermissionSet& api_permissions, |
| 2835 string16* error) { | 2794 string16* error) { |
| 2836 if (!manifest_->HasKey(keys::kInputComponents)) | 2795 if (!manifest_->HasKey(keys::kInputComponents)) |
| 2837 return true; | 2796 return true; |
| 2838 ListValue* list_value = NULL; | 2797 ListValue* list_value = NULL; |
| 2839 if (!manifest_->GetList(keys::kInputComponents, &list_value)) { | 2798 if (!manifest_->GetList(keys::kInputComponents, &list_value)) { |
| 2840 *error = ASCIIToUTF16(errors::kInvalidInputComponents); | 2799 *error = ASCIIToUTF16(errors::kInvalidInputComponents); |
| 2841 return false; | 2800 return false; |
| 2842 } | 2801 } |
| 2843 | 2802 |
| (...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4048 | 4007 |
| 4049 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 4008 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 4050 const Extension* extension, | 4009 const Extension* extension, |
| 4051 const PermissionSet* permissions, | 4010 const PermissionSet* permissions, |
| 4052 Reason reason) | 4011 Reason reason) |
| 4053 : reason(reason), | 4012 : reason(reason), |
| 4054 extension(extension), | 4013 extension(extension), |
| 4055 permissions(permissions) {} | 4014 permissions(permissions) {} |
| 4056 | 4015 |
| 4057 } // namespace extensions | 4016 } // namespace extensions |
| OLD | NEW |