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 19 matching lines...) Expand all Loading... |
30 #include "chrome/common/extensions/csp_validator.h" | 30 #include "chrome/common/extensions/csp_validator.h" |
31 #include "chrome/common/extensions/extension_action.h" | 31 #include "chrome/common/extensions/extension_action.h" |
32 #include "chrome/common/extensions/extension_error_utils.h" | 32 #include "chrome/common/extensions/extension_error_utils.h" |
33 #include "chrome/common/extensions/extension_manifest_constants.h" | 33 #include "chrome/common/extensions/extension_manifest_constants.h" |
34 #include "chrome/common/extensions/extension_resource.h" | 34 #include "chrome/common/extensions/extension_resource.h" |
35 #include "chrome/common/extensions/extension_switch_utils.h" | 35 #include "chrome/common/extensions/extension_switch_utils.h" |
36 #include "chrome/common/extensions/features/feature.h" | 36 #include "chrome/common/extensions/features/feature.h" |
37 #include "chrome/common/extensions/features/simple_feature_provider.h" | 37 #include "chrome/common/extensions/features/simple_feature_provider.h" |
38 #include "chrome/common/extensions/file_browser_handler.h" | 38 #include "chrome/common/extensions/file_browser_handler.h" |
39 #include "chrome/common/extensions/manifest.h" | 39 #include "chrome/common/extensions/manifest.h" |
| 40 #include "chrome/common/extensions/permissions/permissions_info.h" |
40 #include "chrome/common/extensions/url_pattern_set.h" | 41 #include "chrome/common/extensions/url_pattern_set.h" |
41 #include "chrome/common/extensions/user_script.h" | 42 #include "chrome/common/extensions/user_script.h" |
42 #include "chrome/common/url_constants.h" | 43 #include "chrome/common/url_constants.h" |
43 #include "crypto/sha2.h" | 44 #include "crypto/sha2.h" |
44 #include "googleurl/src/url_util.h" | 45 #include "googleurl/src/url_util.h" |
45 #include "grit/chromium_strings.h" | 46 #include "grit/chromium_strings.h" |
46 #include "grit/generated_resources.h" | 47 #include "grit/generated_resources.h" |
47 #include "grit/theme_resources_standard.h" | 48 #include "grit/theme_resources_standard.h" |
48 #include "net/base/registry_controlled_domain.h" | 49 #include "net/base/registry_controlled_domain.h" |
49 #include "third_party/skia/include/core/SkBitmap.h" | 50 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 } | 275 } |
275 | 276 |
276 Extension::InputComponentInfo::~InputComponentInfo() {} | 277 Extension::InputComponentInfo::~InputComponentInfo() {} |
277 | 278 |
278 Extension::TtsVoice::TtsVoice() {} | 279 Extension::TtsVoice::TtsVoice() {} |
279 Extension::TtsVoice::~TtsVoice() {} | 280 Extension::TtsVoice::~TtsVoice() {} |
280 | 281 |
281 Extension::OAuth2Info::OAuth2Info() {} | 282 Extension::OAuth2Info::OAuth2Info() {} |
282 Extension::OAuth2Info::~OAuth2Info() {} | 283 Extension::OAuth2Info::~OAuth2Info() {} |
283 | 284 |
284 ExtensionOAuth2Scopes Extension::OAuth2Info::GetScopesAsSet() { | 285 OAuth2Scopes Extension::OAuth2Info::GetScopesAsSet() { |
285 ExtensionOAuth2Scopes result; | 286 OAuth2Scopes result; |
286 std::copy(scopes.begin(), scopes.end(), | 287 std::copy(scopes.begin(), scopes.end(), |
287 std::inserter(result, result.begin())); | 288 std::inserter(result, result.begin())); |
288 return result; | 289 return result; |
289 } | 290 } |
290 | 291 |
291 // | 292 // |
292 // Extension | 293 // Extension |
293 // | 294 // |
294 | 295 |
295 // static | 296 // static |
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1299 keys::kLaunchHeight, | 1300 keys::kLaunchHeight, |
1300 &launch_height_, | 1301 &launch_height_, |
1301 can_specify_initial_size, | 1302 can_specify_initial_size, |
1302 error)) | 1303 error)) |
1303 return false; | 1304 return false; |
1304 | 1305 |
1305 return true; | 1306 return true; |
1306 } | 1307 } |
1307 | 1308 |
1308 bool Extension::LoadSharedFeatures( | 1309 bool Extension::LoadSharedFeatures( |
1309 const ExtensionAPIPermissionSet& api_permissions, | 1310 const APIPermissionSet& api_permissions, |
1310 string16* error) { | 1311 string16* error) { |
1311 if (!LoadDescription(error) || | 1312 if (!LoadDescription(error) || |
1312 !LoadHomepageURL(error) || | 1313 !LoadHomepageURL(error) || |
1313 !LoadUpdateURL(error) || | 1314 !LoadUpdateURL(error) || |
1314 !LoadIcons(error) || | 1315 !LoadIcons(error) || |
1315 !LoadCommands(error) || | 1316 !LoadCommands(error) || |
1316 !LoadPlugins(error) || | 1317 !LoadPlugins(error) || |
1317 !LoadNaClModules(error) || | 1318 !LoadNaClModules(error) || |
1318 !LoadWebAccessibleResources(error) || | 1319 !LoadWebAccessibleResources(error) || |
1319 !LoadSandboxedPages(error) || | 1320 !LoadSandboxedPages(error) || |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1777 errors::kInvalidBackgroundScript, base::IntToString(i)); | 1778 errors::kInvalidBackgroundScript, base::IntToString(i)); |
1778 return false; | 1779 return false; |
1779 } | 1780 } |
1780 background_scripts_.push_back(script); | 1781 background_scripts_.push_back(script); |
1781 } | 1782 } |
1782 | 1783 |
1783 return true; | 1784 return true; |
1784 } | 1785 } |
1785 | 1786 |
1786 bool Extension::LoadBackgroundPage( | 1787 bool Extension::LoadBackgroundPage( |
1787 const ExtensionAPIPermissionSet& api_permissions, | 1788 const APIPermissionSet& api_permissions, |
1788 string16* error) { | 1789 string16* error) { |
1789 if (is_platform_app()) { | 1790 if (is_platform_app()) { |
1790 return LoadBackgroundPage( | 1791 return LoadBackgroundPage( |
1791 keys::kPlatformAppBackgroundPage, api_permissions, error); | 1792 keys::kPlatformAppBackgroundPage, api_permissions, error); |
1792 } | 1793 } |
1793 | 1794 |
1794 if (!LoadBackgroundPage(keys::kBackgroundPage, api_permissions, error)) | 1795 if (!LoadBackgroundPage(keys::kBackgroundPage, api_permissions, error)) |
1795 return false; | 1796 return false; |
1796 if (background_url_.is_empty()) | 1797 if (background_url_.is_empty()) |
1797 return LoadBackgroundPage( | 1798 return LoadBackgroundPage( |
1798 keys::kBackgroundPageLegacy, api_permissions, error); | 1799 keys::kBackgroundPageLegacy, api_permissions, error); |
1799 return true; | 1800 return true; |
1800 } | 1801 } |
1801 | 1802 |
1802 bool Extension::LoadBackgroundPage( | 1803 bool Extension::LoadBackgroundPage( |
1803 const std::string& key, | 1804 const std::string& key, |
1804 const ExtensionAPIPermissionSet& api_permissions, | 1805 const APIPermissionSet& api_permissions, |
1805 string16* error) { | 1806 string16* error) { |
1806 base::Value* background_page_value = NULL; | 1807 base::Value* background_page_value = NULL; |
1807 if (!manifest_->Get(key, &background_page_value)) | 1808 if (!manifest_->Get(key, &background_page_value)) |
1808 return true; | 1809 return true; |
1809 | 1810 |
1810 if (!background_scripts_.empty()) { | 1811 if (!background_scripts_.empty()) { |
1811 *error = ASCIIToUTF16(errors::kInvalidBackgroundCombination); | 1812 *error = ASCIIToUTF16(errors::kInvalidBackgroundCombination); |
1812 return false; | 1813 return false; |
1813 } | 1814 } |
1814 | 1815 |
1815 | 1816 |
1816 std::string background_str; | 1817 std::string background_str; |
1817 if (!background_page_value->GetAsString(&background_str)) { | 1818 if (!background_page_value->GetAsString(&background_str)) { |
1818 *error = ASCIIToUTF16(errors::kInvalidBackground); | 1819 *error = ASCIIToUTF16(errors::kInvalidBackground); |
1819 return false; | 1820 return false; |
1820 } | 1821 } |
1821 | 1822 |
1822 if (is_hosted_app()) { | 1823 if (is_hosted_app()) { |
1823 background_url_ = GURL(background_str); | 1824 background_url_ = GURL(background_str); |
1824 | 1825 |
1825 // Make sure "background" permission is set. | 1826 // Make sure "background" permission is set. |
1826 if (!api_permissions.count(ExtensionAPIPermission::kBackground)) { | 1827 if (!api_permissions.count(APIPermission::kBackground)) { |
1827 *error = ASCIIToUTF16(errors::kBackgroundPermissionNeeded); | 1828 *error = ASCIIToUTF16(errors::kBackgroundPermissionNeeded); |
1828 return false; | 1829 return false; |
1829 } | 1830 } |
1830 // Hosted apps require an absolute URL. | 1831 // Hosted apps require an absolute URL. |
1831 if (!background_url_.is_valid()) { | 1832 if (!background_url_.is_valid()) { |
1832 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp); | 1833 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp); |
1833 return false; | 1834 return false; |
1834 } | 1835 } |
1835 | 1836 |
1836 if (!(background_url_.SchemeIs("https") || | 1837 if (!(background_url_.SchemeIs("https") || |
1837 (CommandLine::ForCurrentProcess()->HasSwitch( | 1838 (CommandLine::ForCurrentProcess()->HasSwitch( |
1838 switches::kAllowHTTPBackgroundPage) && | 1839 switches::kAllowHTTPBackgroundPage) && |
1839 background_url_.SchemeIs("http")))) { | 1840 background_url_.SchemeIs("http")))) { |
1840 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp); | 1841 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp); |
1841 return false; | 1842 return false; |
1842 } | 1843 } |
1843 } else { | 1844 } else { |
1844 background_url_ = GetResourceURL(background_str); | 1845 background_url_ = GetResourceURL(background_str); |
1845 } | 1846 } |
1846 | 1847 |
1847 return true; | 1848 return true; |
1848 } | 1849 } |
1849 | 1850 |
1850 bool Extension::LoadBackgroundPersistent( | 1851 bool Extension::LoadBackgroundPersistent( |
1851 const ExtensionAPIPermissionSet& api_permissions, | 1852 const APIPermissionSet& api_permissions, |
1852 string16* error) { | 1853 string16* error) { |
1853 if (is_platform_app()) { | 1854 if (is_platform_app()) { |
1854 background_page_is_persistent_ = false; | 1855 background_page_is_persistent_ = false; |
1855 return true; | 1856 return true; |
1856 } | 1857 } |
1857 | 1858 |
1858 Value* background_persistent = NULL; | 1859 Value* background_persistent = NULL; |
1859 if (!manifest_->Get(keys::kBackgroundPersistent, &background_persistent)) | 1860 if (!manifest_->Get(keys::kBackgroundPersistent, &background_persistent)) |
1860 return true; | 1861 return true; |
1861 | 1862 |
1862 if (!background_persistent->GetAsBoolean(&background_page_is_persistent_)) { | 1863 if (!background_persistent->GetAsBoolean(&background_page_is_persistent_)) { |
1863 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistent); | 1864 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistent); |
1864 return false; | 1865 return false; |
1865 } | 1866 } |
1866 | 1867 |
1867 if (!has_background_page()) { | 1868 if (!has_background_page()) { |
1868 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistentNoPage); | 1869 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistentNoPage); |
1869 return false; | 1870 return false; |
1870 } | 1871 } |
1871 | 1872 |
1872 return true; | 1873 return true; |
1873 } | 1874 } |
1874 | 1875 |
1875 bool Extension::LoadBackgroundAllowJSAccess( | 1876 bool Extension::LoadBackgroundAllowJSAccess( |
1876 const ExtensionAPIPermissionSet& api_permissions, | 1877 const APIPermissionSet& api_permissions, |
1877 string16* error) { | 1878 string16* error) { |
1878 Value* allow_js_access = NULL; | 1879 Value* allow_js_access = NULL; |
1879 if (!manifest_->Get(keys::kBackgroundAllowJsAccess, &allow_js_access)) | 1880 if (!manifest_->Get(keys::kBackgroundAllowJsAccess, &allow_js_access)) |
1880 return true; | 1881 return true; |
1881 | 1882 |
1882 if (!allow_js_access->IsType(Value::TYPE_BOOLEAN) || | 1883 if (!allow_js_access->IsType(Value::TYPE_BOOLEAN) || |
1883 !allow_js_access->GetAsBoolean(&allow_background_js_access_)) { | 1884 !allow_js_access->GetAsBoolean(&allow_background_js_access_)) { |
1884 *error = ASCIIToUTF16(errors::kInvalidBackgroundAllowJsAccess); | 1885 *error = ASCIIToUTF16(errors::kInvalidBackgroundAllowJsAccess); |
1885 return false; | 1886 return false; |
1886 } | 1887 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2043 *error = ASCIIToUTF16(errors::kInvalidIntent); | 2044 *error = ASCIIToUTF16(errors::kInvalidIntent); |
2044 return false; | 2045 return false; |
2045 } | 2046 } |
2046 if (!LoadWebIntentAction(*iter, *one_service, error)) | 2047 if (!LoadWebIntentAction(*iter, *one_service, error)) |
2047 return false; | 2048 return false; |
2048 } | 2049 } |
2049 } | 2050 } |
2050 return true; | 2051 return true; |
2051 } | 2052 } |
2052 bool Extension::LoadExtensionFeatures( | 2053 bool Extension::LoadExtensionFeatures( |
2053 const ExtensionAPIPermissionSet& api_permissions, | 2054 const APIPermissionSet& api_permissions, |
2054 string16* error) { | 2055 string16* error) { |
2055 if (manifest_->HasKey(keys::kConvertedFromUserScript)) | 2056 if (manifest_->HasKey(keys::kConvertedFromUserScript)) |
2056 manifest_->GetBoolean(keys::kConvertedFromUserScript, | 2057 manifest_->GetBoolean(keys::kConvertedFromUserScript, |
2057 &converted_from_user_script_); | 2058 &converted_from_user_script_); |
2058 | 2059 |
2059 if (!LoadDevToolsPage(error) || | 2060 if (!LoadDevToolsPage(error) || |
2060 !LoadInputComponents(api_permissions, error) || | 2061 !LoadInputComponents(api_permissions, error) || |
2061 !LoadContentScripts(error) || | 2062 !LoadContentScripts(error) || |
2062 !LoadPageAction(error) || | 2063 !LoadPageAction(error) || |
2063 !LoadBrowserAction(error) || | 2064 !LoadBrowserAction(error) || |
(...skipping 15 matching lines...) Expand all Loading... |
2079 std::string devtools_str; | 2080 std::string devtools_str; |
2080 if (!manifest_->GetString(keys::kDevToolsPage, &devtools_str)) { | 2081 if (!manifest_->GetString(keys::kDevToolsPage, &devtools_str)) { |
2081 *error = ASCIIToUTF16(errors::kInvalidDevToolsPage); | 2082 *error = ASCIIToUTF16(errors::kInvalidDevToolsPage); |
2082 return false; | 2083 return false; |
2083 } | 2084 } |
2084 devtools_url_ = GetResourceURL(devtools_str); | 2085 devtools_url_ = GetResourceURL(devtools_str); |
2085 return true; | 2086 return true; |
2086 } | 2087 } |
2087 | 2088 |
2088 bool Extension::LoadInputComponents( | 2089 bool Extension::LoadInputComponents( |
2089 const ExtensionAPIPermissionSet& api_permissions, | 2090 const APIPermissionSet& api_permissions, |
2090 string16* error) { | 2091 string16* error) { |
2091 if (!manifest_->HasKey(keys::kInputComponents)) | 2092 if (!manifest_->HasKey(keys::kInputComponents)) |
2092 return true; | 2093 return true; |
2093 ListValue* list_value = NULL; | 2094 ListValue* list_value = NULL; |
2094 if (!manifest_->GetList(keys::kInputComponents, &list_value)) { | 2095 if (!manifest_->GetList(keys::kInputComponents, &list_value)) { |
2095 *error = ASCIIToUTF16(errors::kInvalidInputComponents); | 2096 *error = ASCIIToUTF16(errors::kInvalidInputComponents); |
2096 return false; | 2097 return false; |
2097 } | 2098 } |
2098 | 2099 |
2099 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 2100 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2705 // default Content-Security-Policy? | 2706 // default Content-Security-Policy? |
2706 content_security_policy_ = is_platform_app() ? | 2707 content_security_policy_ = is_platform_app() ? |
2707 kDefaultPlatformAppContentSecurityPolicy : | 2708 kDefaultPlatformAppContentSecurityPolicy : |
2708 kDefaultContentSecurityPolicy; | 2709 kDefaultContentSecurityPolicy; |
2709 CHECK(ContentSecurityPolicyIsSecure(content_security_policy_)); | 2710 CHECK(ContentSecurityPolicyIsSecure(content_security_policy_)); |
2710 } | 2711 } |
2711 return true; | 2712 return true; |
2712 } | 2713 } |
2713 | 2714 |
2714 bool Extension::LoadAppIsolation( | 2715 bool Extension::LoadAppIsolation( |
2715 const ExtensionAPIPermissionSet& api_permissions, string16* error) { | 2716 const APIPermissionSet& api_permissions, string16* error) { |
2716 // Platform apps always get isolated storage. | 2717 // Platform apps always get isolated storage. |
2717 if (is_platform_app()) { | 2718 if (is_platform_app()) { |
2718 is_storage_isolated_ = true; | 2719 is_storage_isolated_ = true; |
2719 return true; | 2720 return true; |
2720 } | 2721 } |
2721 | 2722 |
2722 // Other apps only get it if it is requested _and_ experimental APIs are | 2723 // Other apps only get it if it is requested _and_ experimental APIs are |
2723 // enabled. | 2724 // enabled. |
2724 if (!api_permissions.count(ExtensionAPIPermission::kExperimental) || | 2725 if (!api_permissions.count(APIPermission::kExperimental) || |
2725 !is_app()) { | 2726 !is_app()) { |
2726 return true; | 2727 return true; |
2727 } | 2728 } |
2728 | 2729 |
2729 Value* temp = NULL; | 2730 Value* temp = NULL; |
2730 if (!manifest_->Get(keys::kIsolation, &temp)) | 2731 if (!manifest_->Get(keys::kIsolation, &temp)) |
2731 return true; | 2732 return true; |
2732 | 2733 |
2733 if (temp->GetType() != Value::TYPE_LIST) { | 2734 if (temp->GetType() != Value::TYPE_LIST) { |
2734 *error = ASCIIToUTF16(errors::kInvalidIsolation); | 2735 *error = ASCIIToUTF16(errors::kInvalidIsolation); |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3056 return GURL(std::string(chrome::kExtensionScheme) + | 3057 return GURL(std::string(chrome::kExtensionScheme) + |
3057 content::kStandardSchemeSeparator + extension_id + "/"); | 3058 content::kStandardSchemeSeparator + extension_id + "/"); |
3058 } | 3059 } |
3059 | 3060 |
3060 bool Extension::InitFromValue(int flags, string16* error) { | 3061 bool Extension::InitFromValue(int flags, string16* error) { |
3061 DCHECK(error); | 3062 DCHECK(error); |
3062 | 3063 |
3063 base::AutoLock auto_lock(runtime_data_lock_); | 3064 base::AutoLock auto_lock(runtime_data_lock_); |
3064 | 3065 |
3065 // Initialize permissions with an empty, default permission set. | 3066 // Initialize permissions with an empty, default permission set. |
3066 runtime_data_.SetActivePermissions(new ExtensionPermissionSet()); | 3067 runtime_data_.SetActivePermissions(new PermissionSet()); |
3067 optional_permission_set_ = new ExtensionPermissionSet(); | 3068 optional_permission_set_ = new PermissionSet(); |
3068 required_permission_set_ = new ExtensionPermissionSet(); | 3069 required_permission_set_ = new PermissionSet(); |
3069 | 3070 |
3070 creation_flags_ = flags; | 3071 creation_flags_ = flags; |
3071 | 3072 |
3072 // Important to load manifest version first because many other features | 3073 // Important to load manifest version first because many other features |
3073 // depend on its value. | 3074 // depend on its value. |
3074 if (!LoadManifestVersion(error)) | 3075 if (!LoadManifestVersion(error)) |
3075 return false; | 3076 return false; |
3076 | 3077 |
3077 // Validate minimum Chrome version. We don't need to store this, since the | 3078 // Validate minimum Chrome version. We don't need to store this, since the |
3078 // extension is not valid if it is incorrect | 3079 // extension is not valid if it is incorrect |
3079 if (!CheckMinimumChromeVersion(error)) | 3080 if (!CheckMinimumChromeVersion(error)) |
3080 return false; | 3081 return false; |
3081 | 3082 |
3082 if (!LoadRequiredFeatures(error)) | 3083 if (!LoadRequiredFeatures(error)) |
3083 return false; | 3084 return false; |
3084 | 3085 |
3085 // We don't ned to validate because InitExtensionID already did that. | 3086 // We don't ned to validate because InitExtensionID already did that. |
3086 manifest_->GetString(keys::kPublicKey, &public_key_); | 3087 manifest_->GetString(keys::kPublicKey, &public_key_); |
3087 | 3088 |
3088 extension_url_ = Extension::GetBaseURLFromExtensionId(id()); | 3089 extension_url_ = Extension::GetBaseURLFromExtensionId(id()); |
3089 | 3090 |
3090 // Load App settings. LoadExtent at least has to be done before | 3091 // Load App settings. LoadExtent at least has to be done before |
3091 // ParsePermissions(), because the valid permissions depend on what type of | 3092 // ParsePermissions(), because the valid permissions depend on what type of |
3092 // package this is. | 3093 // package this is. |
3093 if (is_app() && !LoadAppFeatures(error)) | 3094 if (is_app() && !LoadAppFeatures(error)) |
3094 return false; | 3095 return false; |
3095 | 3096 |
3096 ExtensionAPIPermissionSet api_permissions; | 3097 APIPermissionSet api_permissions; |
3097 URLPatternSet host_permissions; | 3098 URLPatternSet host_permissions; |
3098 if (!ParsePermissions(keys::kPermissions, | 3099 if (!ParsePermissions(keys::kPermissions, |
3099 error, | 3100 error, |
3100 &api_permissions, | 3101 &api_permissions, |
3101 &host_permissions)) { | 3102 &host_permissions)) { |
3102 return false; | 3103 return false; |
3103 } | 3104 } |
3104 | 3105 |
3105 ExtensionAPIPermissionSet optional_api_permissions; | 3106 APIPermissionSet optional_api_permissions; |
3106 URLPatternSet optional_host_permissions; | 3107 URLPatternSet optional_host_permissions; |
3107 if (!ParsePermissions(keys::kOptionalPermissions, | 3108 if (!ParsePermissions(keys::kOptionalPermissions, |
3108 error, | 3109 error, |
3109 &optional_api_permissions, | 3110 &optional_api_permissions, |
3110 &optional_host_permissions)) { | 3111 &optional_host_permissions)) { |
3111 return false; | 3112 return false; |
3112 } | 3113 } |
3113 | 3114 |
3114 if (!LoadAppIsolation(api_permissions, error)) | 3115 if (!LoadAppIsolation(api_permissions, error)) |
3115 return false; | 3116 return false; |
3116 | 3117 |
3117 if (!LoadSharedFeatures(api_permissions, error)) | 3118 if (!LoadSharedFeatures(api_permissions, error)) |
3118 return false; | 3119 return false; |
3119 | 3120 |
3120 if (!LoadExtensionFeatures(api_permissions, error)) | 3121 if (!LoadExtensionFeatures(api_permissions, error)) |
3121 return false; | 3122 return false; |
3122 | 3123 |
3123 if (!LoadThemeFeatures(error)) | 3124 if (!LoadThemeFeatures(error)) |
3124 return false; | 3125 return false; |
3125 | 3126 |
3126 if (HasMultipleUISurfaces()) { | 3127 if (HasMultipleUISurfaces()) { |
3127 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); | 3128 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); |
3128 return false; | 3129 return false; |
3129 } | 3130 } |
3130 | 3131 |
3131 runtime_data_.SetActivePermissions(new ExtensionPermissionSet( | 3132 runtime_data_.SetActivePermissions(new PermissionSet( |
3132 this, api_permissions, host_permissions, oauth2_info_.GetScopesAsSet())); | 3133 this, api_permissions, host_permissions, oauth2_info_.GetScopesAsSet())); |
3133 required_permission_set_ = new ExtensionPermissionSet( | 3134 required_permission_set_ = new PermissionSet( |
3134 this, api_permissions, host_permissions, oauth2_info_.GetScopesAsSet()); | 3135 this, api_permissions, host_permissions, oauth2_info_.GetScopesAsSet()); |
3135 optional_permission_set_ = new ExtensionPermissionSet( | 3136 optional_permission_set_ = new PermissionSet( |
3136 optional_api_permissions, optional_host_permissions, URLPatternSet()); | 3137 optional_api_permissions, optional_host_permissions, URLPatternSet()); |
3137 | 3138 |
3138 return true; | 3139 return true; |
3139 } | 3140 } |
3140 | 3141 |
3141 GURL Extension::GetHomepageURL() const { | 3142 GURL Extension::GetHomepageURL() const { |
3142 if (homepage_url_.is_valid()) | 3143 if (homepage_url_.is_valid()) |
3143 return homepage_url_; | 3144 return homepage_url_; |
3144 | 3145 |
3145 if (!UpdatesFromGallery()) | 3146 if (!UpdatesFromGallery()) |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3285 ExtensionIconSet::MatchType match_type) const { | 3286 ExtensionIconSet::MatchType match_type) const { |
3286 std::string path = icons().Get(size, match_type); | 3287 std::string path = icons().Get(size, match_type); |
3287 if (path.empty()) | 3288 if (path.empty()) |
3288 return GURL(); | 3289 return GURL(); |
3289 else | 3290 else |
3290 return GetResourceURL(path); | 3291 return GetResourceURL(path); |
3291 } | 3292 } |
3292 | 3293 |
3293 bool Extension::ParsePermissions(const char* key, | 3294 bool Extension::ParsePermissions(const char* key, |
3294 string16* error, | 3295 string16* error, |
3295 ExtensionAPIPermissionSet* api_permissions, | 3296 APIPermissionSet* api_permissions, |
3296 URLPatternSet* host_permissions) { | 3297 URLPatternSet* host_permissions) { |
3297 if (manifest_->HasKey(key)) { | 3298 if (manifest_->HasKey(key)) { |
3298 ListValue* permissions = NULL; | 3299 ListValue* permissions = NULL; |
3299 if (!manifest_->GetList(key, &permissions)) { | 3300 if (!manifest_->GetList(key, &permissions)) { |
3300 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 3301 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
3301 errors::kInvalidPermissions, ""); | 3302 errors::kInvalidPermissions, ""); |
3302 return false; | 3303 return false; |
3303 } | 3304 } |
3304 | 3305 |
3305 for (size_t i = 0; i < permissions->GetSize(); ++i) { | 3306 for (size_t i = 0; i < permissions->GetSize(); ++i) { |
3306 std::string permission_str; | 3307 std::string permission_str; |
3307 if (!permissions->GetString(i, &permission_str)) { | 3308 if (!permissions->GetString(i, &permission_str)) { |
3308 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 3309 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
3309 errors::kInvalidPermission, base::IntToString(i)); | 3310 errors::kInvalidPermission, base::IntToString(i)); |
3310 return false; | 3311 return false; |
3311 } | 3312 } |
3312 | 3313 |
3313 // NOTE: We need to get the ExtensionAPIPermission before the Feature | 3314 // NOTE: We need to get the APIPermission before the Feature |
3314 // object because the feature system does not know about aliases. | 3315 // object because the feature system does not know about aliases. |
3315 ExtensionAPIPermission* permission = | 3316 APIPermission* permission = |
3316 ExtensionPermissionsInfo::GetInstance()->GetByName(permission_str); | 3317 PermissionsInfo::GetInstance()->GetByName(permission_str); |
3317 if (permission) { | 3318 if (permission) { |
3318 extensions::SimpleFeatureProvider* permission_features = | 3319 extensions::SimpleFeatureProvider* permission_features = |
3319 extensions::SimpleFeatureProvider::GetPermissionFeatures(); | 3320 extensions::SimpleFeatureProvider::GetPermissionFeatures(); |
3320 extensions::Feature* feature = | 3321 extensions::Feature* feature = |
3321 permission_features->GetFeature(permission->name()); | 3322 permission_features->GetFeature(permission->name()); |
3322 | 3323 |
3323 // The feature should exist since we just got an ExtensionAPIPermission | 3324 // The feature should exist since we just got an APIPermission |
3324 // for it. The two systems should be updated together whenever a | 3325 // for it. The two systems should be updated together whenever a |
3325 // permission is added. | 3326 // permission is added. |
3326 CHECK(feature); | 3327 CHECK(feature); |
3327 | 3328 |
3328 extensions::Feature::Availability availability = | 3329 extensions::Feature::Availability availability = |
3329 feature->IsAvailableToManifest( | 3330 feature->IsAvailableToManifest( |
3330 id(), | 3331 id(), |
3331 GetType(), | 3332 GetType(), |
3332 extensions::Feature::ConvertLocation(location()), | 3333 extensions::Feature::ConvertLocation(location()), |
3333 manifest_version()); | 3334 manifest_version()); |
3334 if (availability != extensions::Feature::IS_AVAILABLE) { | 3335 if (availability != extensions::Feature::IS_AVAILABLE) { |
3335 // Don't fail, but warn the developer that the manifest contains | 3336 // Don't fail, but warn the developer that the manifest contains |
3336 // unrecognized permissions. This may happen legitimately if the | 3337 // unrecognized permissions. This may happen legitimately if the |
3337 // extensions requests platform- or channel-specific permissions. | 3338 // extensions requests platform- or channel-specific permissions. |
3338 install_warnings_.push_back( | 3339 install_warnings_.push_back( |
3339 InstallWarning(InstallWarning::FORMAT_TEXT, | 3340 InstallWarning(InstallWarning::FORMAT_TEXT, |
3340 feature->GetErrorMessage(availability))); | 3341 feature->GetErrorMessage(availability))); |
3341 continue; | 3342 continue; |
3342 } | 3343 } |
3343 | 3344 |
3344 if (permission->id() == ExtensionAPIPermission::kExperimental) { | 3345 if (permission->id() == APIPermission::kExperimental) { |
3345 if (!CanSpecifyExperimentalPermission()) { | 3346 if (!CanSpecifyExperimentalPermission()) { |
3346 *error = ASCIIToUTF16(errors::kExperimentalFlagRequired); | 3347 *error = ASCIIToUTF16(errors::kExperimentalFlagRequired); |
3347 return false; | 3348 return false; |
3348 } | 3349 } |
3349 } | 3350 } |
3350 | 3351 |
3351 api_permissions->insert(permission->id()); | 3352 api_permissions->insert(permission->id()); |
3352 continue; | 3353 continue; |
3353 } | 3354 } |
3354 | 3355 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3391 } | 3392 } |
3392 } | 3393 } |
3393 return true; | 3394 return true; |
3394 } | 3395 } |
3395 | 3396 |
3396 bool Extension::CanSilentlyIncreasePermissions() const { | 3397 bool Extension::CanSilentlyIncreasePermissions() const { |
3397 return location() != INTERNAL; | 3398 return location() != INTERNAL; |
3398 } | 3399 } |
3399 | 3400 |
3400 bool Extension::CanSpecifyHostPermission(const URLPattern& pattern, | 3401 bool Extension::CanSpecifyHostPermission(const URLPattern& pattern, |
3401 const ExtensionAPIPermissionSet& permissions) const { | 3402 const APIPermissionSet& permissions) const { |
3402 if (!pattern.match_all_urls() && | 3403 if (!pattern.match_all_urls() && |
3403 pattern.MatchesScheme(chrome::kChromeUIScheme)) { | 3404 pattern.MatchesScheme(chrome::kChromeUIScheme)) { |
3404 // Regular extensions are only allowed access to chrome://favicon. | 3405 // Regular extensions are only allowed access to chrome://favicon. |
3405 if (pattern.host() == chrome::kChromeUIFaviconHost) | 3406 if (pattern.host() == chrome::kChromeUIFaviconHost) |
3406 return true; | 3407 return true; |
3407 | 3408 |
3408 // Experimental extensions are also allowed chrome://thumb. | 3409 // Experimental extensions are also allowed chrome://thumb. |
3409 if (pattern.host() == chrome::kChromeUIThumbnailHost) { | 3410 if (pattern.host() == chrome::kChromeUIThumbnailHost) { |
3410 return permissions.find(ExtensionAPIPermission::kExperimental) != | 3411 return permissions.find(APIPermission::kExperimental) != |
3411 permissions.end(); | 3412 permissions.end(); |
3412 } | 3413 } |
3413 | 3414 |
3414 // Component extensions can have access to all of chrome://*. | 3415 // Component extensions can have access to all of chrome://*. |
3415 if (CanExecuteScriptEverywhere()) | 3416 if (CanExecuteScriptEverywhere()) |
3416 return true; | 3417 return true; |
3417 | 3418 |
3418 return false; | 3419 return false; |
3419 } | 3420 } |
3420 | 3421 |
3421 // Otherwise, the valid schemes were handled by URLPattern. | 3422 // Otherwise, the valid schemes were handled by URLPattern. |
3422 return true; | 3423 return true; |
3423 } | 3424 } |
3424 | 3425 |
3425 bool Extension::HasAPIPermission( | 3426 bool Extension::HasAPIPermission( |
3426 ExtensionAPIPermission::ID permission) const { | 3427 APIPermission::ID permission) const { |
3427 base::AutoLock auto_lock(runtime_data_lock_); | 3428 base::AutoLock auto_lock(runtime_data_lock_); |
3428 return runtime_data_.GetActivePermissions()->HasAPIPermission(permission); | 3429 return runtime_data_.GetActivePermissions()->HasAPIPermission(permission); |
3429 } | 3430 } |
3430 | 3431 |
3431 bool Extension::HasAPIPermission( | 3432 bool Extension::HasAPIPermission( |
3432 const std::string& function_name) const { | 3433 const std::string& function_name) const { |
3433 base::AutoLock auto_lock(runtime_data_lock_); | 3434 base::AutoLock auto_lock(runtime_data_lock_); |
3434 return runtime_data_.GetActivePermissions()-> | 3435 return runtime_data_.GetActivePermissions()-> |
3435 HasAccessToFunction(function_name); | 3436 HasAccessToFunction(function_name); |
3436 } | 3437 } |
(...skipping 19 matching lines...) Expand all Loading... |
3456 bool Extension::HasEffectiveAccessToAllHosts() const { | 3457 bool Extension::HasEffectiveAccessToAllHosts() const { |
3457 base::AutoLock auto_lock(runtime_data_lock_); | 3458 base::AutoLock auto_lock(runtime_data_lock_); |
3458 return runtime_data_.GetActivePermissions()->HasEffectiveAccessToAllHosts(); | 3459 return runtime_data_.GetActivePermissions()->HasEffectiveAccessToAllHosts(); |
3459 } | 3460 } |
3460 | 3461 |
3461 bool Extension::HasFullPermissions() const { | 3462 bool Extension::HasFullPermissions() const { |
3462 base::AutoLock auto_lock(runtime_data_lock_); | 3463 base::AutoLock auto_lock(runtime_data_lock_); |
3463 return runtime_data_.GetActivePermissions()->HasEffectiveFullAccess(); | 3464 return runtime_data_.GetActivePermissions()->HasEffectiveFullAccess(); |
3464 } | 3465 } |
3465 | 3466 |
3466 ExtensionPermissionMessages Extension::GetPermissionMessages() const { | 3467 PermissionMessages Extension::GetPermissionMessages() const { |
3467 base::AutoLock auto_lock(runtime_data_lock_); | 3468 base::AutoLock auto_lock(runtime_data_lock_); |
3468 if (IsTrustedId(id())) | 3469 if (IsTrustedId(id())) |
3469 return ExtensionPermissionMessages(); | 3470 return PermissionMessages(); |
3470 else | 3471 else |
3471 return runtime_data_.GetActivePermissions()->GetPermissionMessages(); | 3472 return runtime_data_.GetActivePermissions()->GetPermissionMessages(); |
3472 } | 3473 } |
3473 | 3474 |
3474 std::vector<string16> Extension::GetPermissionMessageStrings() const { | 3475 std::vector<string16> Extension::GetPermissionMessageStrings() const { |
3475 base::AutoLock auto_lock(runtime_data_lock_); | 3476 base::AutoLock auto_lock(runtime_data_lock_); |
3476 if (IsTrustedId(id())) | 3477 if (IsTrustedId(id())) |
3477 return std::vector<string16>(); | 3478 return std::vector<string16>(); |
3478 else | 3479 else |
3479 return runtime_data_.GetActivePermissions()->GetWarningMessages(); | 3480 return runtime_data_.GetActivePermissions()->GetWarningMessages(); |
3480 } | 3481 } |
3481 | 3482 |
3482 void Extension::SetActivePermissions( | 3483 void Extension::SetActivePermissions( |
3483 const ExtensionPermissionSet* permissions) const { | 3484 const PermissionSet* permissions) const { |
3484 base::AutoLock auto_lock(runtime_data_lock_); | 3485 base::AutoLock auto_lock(runtime_data_lock_); |
3485 runtime_data_.SetActivePermissions(permissions); | 3486 runtime_data_.SetActivePermissions(permissions); |
3486 } | 3487 } |
3487 | 3488 |
3488 scoped_refptr<const ExtensionPermissionSet> | 3489 scoped_refptr<const PermissionSet> |
3489 Extension::GetActivePermissions() const { | 3490 Extension::GetActivePermissions() const { |
3490 base::AutoLock auto_lock(runtime_data_lock_); | 3491 base::AutoLock auto_lock(runtime_data_lock_); |
3491 return runtime_data_.GetActivePermissions(); | 3492 return runtime_data_.GetActivePermissions(); |
3492 } | 3493 } |
3493 | 3494 |
3494 bool Extension::HasMultipleUISurfaces() const { | 3495 bool Extension::HasMultipleUISurfaces() const { |
3495 int num_surfaces = 0; | 3496 int num_surfaces = 0; |
3496 | 3497 |
3497 if (page_action()) | 3498 if (page_action()) |
3498 ++num_surfaces; | 3499 ++num_surfaces; |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3792 if (!has_background_page()) { | 3793 if (!has_background_page()) { |
3793 *utf8_error = errors::kBackgroundRequiredForPlatformApps; | 3794 *utf8_error = errors::kBackgroundRequiredForPlatformApps; |
3794 return false; | 3795 return false; |
3795 } | 3796 } |
3796 | 3797 |
3797 return true; | 3798 return true; |
3798 } | 3799 } |
3799 | 3800 |
3800 bool Extension::CheckConflictingFeatures(std::string* utf8_error) { | 3801 bool Extension::CheckConflictingFeatures(std::string* utf8_error) { |
3801 if (has_lazy_background_page() && | 3802 if (has_lazy_background_page() && |
3802 HasAPIPermission(ExtensionAPIPermission::kWebRequest)) { | 3803 HasAPIPermission(APIPermission::kWebRequest)) { |
3803 *utf8_error = errors::kWebRequestConflictsWithLazyBackground; | 3804 *utf8_error = errors::kWebRequestConflictsWithLazyBackground; |
3804 return false; | 3805 return false; |
3805 } | 3806 } |
3806 | 3807 |
3807 return true; | 3808 return true; |
3808 } | 3809 } |
3809 | 3810 |
3810 ExtensionInfo::~ExtensionInfo() {} | 3811 ExtensionInfo::~ExtensionInfo() {} |
3811 | 3812 |
3812 Extension::RuntimeData::RuntimeData() {} | 3813 Extension::RuntimeData::RuntimeData() {} |
3813 Extension::RuntimeData::RuntimeData(const ExtensionPermissionSet* active) | 3814 Extension::RuntimeData::RuntimeData(const PermissionSet* active) |
3814 : active_permissions_(active) {} | 3815 : active_permissions_(active) {} |
3815 Extension::RuntimeData::~RuntimeData() {} | 3816 Extension::RuntimeData::~RuntimeData() {} |
3816 | 3817 |
3817 scoped_refptr<const ExtensionPermissionSet> | 3818 scoped_refptr<const PermissionSet> |
3818 Extension::RuntimeData::GetActivePermissions() const { | 3819 Extension::RuntimeData::GetActivePermissions() const { |
3819 return active_permissions_; | 3820 return active_permissions_; |
3820 } | 3821 } |
3821 | 3822 |
3822 void Extension::RuntimeData::SetActivePermissions( | 3823 void Extension::RuntimeData::SetActivePermissions( |
3823 const ExtensionPermissionSet* active) { | 3824 const PermissionSet* active) { |
3824 active_permissions_ = active; | 3825 active_permissions_ = active; |
3825 } | 3826 } |
3826 | 3827 |
3827 const URLPatternSet* | 3828 const URLPatternSet* |
3828 Extension::RuntimeData::GetTabSpecificHostPermissions(int tab_id) const { | 3829 Extension::RuntimeData::GetTabSpecificHostPermissions(int tab_id) const { |
3829 CHECK_GE(tab_id, 0); | 3830 CHECK_GE(tab_id, 0); |
3830 TabHostPermissionsMap::const_iterator it = | 3831 TabHostPermissionsMap::const_iterator it = |
3831 tab_specific_host_permissions_.find(tab_id); | 3832 tab_specific_host_permissions_.find(tab_id); |
3832 return (it != tab_specific_host_permissions_.end()) ? it->second.get() : NULL; | 3833 return (it != tab_specific_host_permissions_.end()) ? it->second.get() : NULL; |
3833 } | 3834 } |
(...skipping 13 matching lines...) Expand all Loading... |
3847 | 3848 |
3848 UnloadedExtensionInfo::UnloadedExtensionInfo( | 3849 UnloadedExtensionInfo::UnloadedExtensionInfo( |
3849 const Extension* extension, | 3850 const Extension* extension, |
3850 extension_misc::UnloadedExtensionReason reason) | 3851 extension_misc::UnloadedExtensionReason reason) |
3851 : reason(reason), | 3852 : reason(reason), |
3852 already_disabled(false), | 3853 already_disabled(false), |
3853 extension(extension) {} | 3854 extension(extension) {} |
3854 | 3855 |
3855 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3856 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
3856 const Extension* extension, | 3857 const Extension* extension, |
3857 const ExtensionPermissionSet* permissions, | 3858 const PermissionSet* permissions, |
3858 Reason reason) | 3859 Reason reason) |
3859 : reason(reason), | 3860 : reason(reason), |
3860 extension(extension), | 3861 extension(extension), |
3861 permissions(permissions) {} | 3862 permissions(permissions) {} |
3862 | 3863 |
3863 } // namespace extensions | 3864 } // namespace extensions |
OLD | NEW |