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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1780 errors::kInvalidBackgroundScript, base::IntToString(i)); | 1781 errors::kInvalidBackgroundScript, base::IntToString(i)); |
1781 return false; | 1782 return false; |
1782 } | 1783 } |
1783 background_scripts_.push_back(script); | 1784 background_scripts_.push_back(script); |
1784 } | 1785 } |
1785 | 1786 |
1786 return true; | 1787 return true; |
1787 } | 1788 } |
1788 | 1789 |
1789 bool Extension::LoadBackgroundPage( | 1790 bool Extension::LoadBackgroundPage( |
1790 const ExtensionAPIPermissionSet& api_permissions, | 1791 const APIPermissionSet& api_permissions, |
1791 string16* error) { | 1792 string16* error) { |
1792 if (is_platform_app()) { | 1793 if (is_platform_app()) { |
1793 return LoadBackgroundPage( | 1794 return LoadBackgroundPage( |
1794 keys::kPlatformAppBackgroundPage, api_permissions, error); | 1795 keys::kPlatformAppBackgroundPage, api_permissions, error); |
1795 } | 1796 } |
1796 | 1797 |
1797 if (!LoadBackgroundPage(keys::kBackgroundPage, api_permissions, error)) | 1798 if (!LoadBackgroundPage(keys::kBackgroundPage, api_permissions, error)) |
1798 return false; | 1799 return false; |
1799 if (background_url_.is_empty()) | 1800 if (background_url_.is_empty()) |
1800 return LoadBackgroundPage( | 1801 return LoadBackgroundPage( |
1801 keys::kBackgroundPageLegacy, api_permissions, error); | 1802 keys::kBackgroundPageLegacy, api_permissions, error); |
1802 return true; | 1803 return true; |
1803 } | 1804 } |
1804 | 1805 |
1805 bool Extension::LoadBackgroundPage( | 1806 bool Extension::LoadBackgroundPage( |
1806 const std::string& key, | 1807 const std::string& key, |
1807 const ExtensionAPIPermissionSet& api_permissions, | 1808 const APIPermissionSet& api_permissions, |
1808 string16* error) { | 1809 string16* error) { |
1809 base::Value* background_page_value = NULL; | 1810 base::Value* background_page_value = NULL; |
1810 if (!manifest_->Get(key, &background_page_value)) | 1811 if (!manifest_->Get(key, &background_page_value)) |
1811 return true; | 1812 return true; |
1812 | 1813 |
1813 if (!background_scripts_.empty()) { | 1814 if (!background_scripts_.empty()) { |
1814 *error = ASCIIToUTF16(errors::kInvalidBackgroundCombination); | 1815 *error = ASCIIToUTF16(errors::kInvalidBackgroundCombination); |
1815 return false; | 1816 return false; |
1816 } | 1817 } |
1817 | 1818 |
1818 | 1819 |
1819 std::string background_str; | 1820 std::string background_str; |
1820 if (!background_page_value->GetAsString(&background_str)) { | 1821 if (!background_page_value->GetAsString(&background_str)) { |
1821 *error = ASCIIToUTF16(errors::kInvalidBackground); | 1822 *error = ASCIIToUTF16(errors::kInvalidBackground); |
1822 return false; | 1823 return false; |
1823 } | 1824 } |
1824 | 1825 |
1825 if (is_hosted_app()) { | 1826 if (is_hosted_app()) { |
1826 background_url_ = GURL(background_str); | 1827 background_url_ = GURL(background_str); |
1827 | 1828 |
1828 // Make sure "background" permission is set. | 1829 // Make sure "background" permission is set. |
1829 if (!api_permissions.count(ExtensionAPIPermission::kBackground)) { | 1830 if (!api_permissions.count(APIPermission::kBackground)) { |
1830 *error = ASCIIToUTF16(errors::kBackgroundPermissionNeeded); | 1831 *error = ASCIIToUTF16(errors::kBackgroundPermissionNeeded); |
1831 return false; | 1832 return false; |
1832 } | 1833 } |
1833 // Hosted apps require an absolute URL. | 1834 // Hosted apps require an absolute URL. |
1834 if (!background_url_.is_valid()) { | 1835 if (!background_url_.is_valid()) { |
1835 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp); | 1836 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp); |
1836 return false; | 1837 return false; |
1837 } | 1838 } |
1838 | 1839 |
1839 if (!(background_url_.SchemeIs("https") || | 1840 if (!(background_url_.SchemeIs("https") || |
1840 (CommandLine::ForCurrentProcess()->HasSwitch( | 1841 (CommandLine::ForCurrentProcess()->HasSwitch( |
1841 switches::kAllowHTTPBackgroundPage) && | 1842 switches::kAllowHTTPBackgroundPage) && |
1842 background_url_.SchemeIs("http")))) { | 1843 background_url_.SchemeIs("http")))) { |
1843 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp); | 1844 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp); |
1844 return false; | 1845 return false; |
1845 } | 1846 } |
1846 } else { | 1847 } else { |
1847 background_url_ = GetResourceURL(background_str); | 1848 background_url_ = GetResourceURL(background_str); |
1848 } | 1849 } |
1849 | 1850 |
1850 return true; | 1851 return true; |
1851 } | 1852 } |
1852 | 1853 |
1853 bool Extension::LoadBackgroundPersistent( | 1854 bool Extension::LoadBackgroundPersistent( |
1854 const ExtensionAPIPermissionSet& api_permissions, | 1855 const APIPermissionSet& api_permissions, |
1855 string16* error) { | 1856 string16* error) { |
1856 if (is_platform_app()) { | 1857 if (is_platform_app()) { |
1857 background_page_is_persistent_ = false; | 1858 background_page_is_persistent_ = false; |
1858 return true; | 1859 return true; |
1859 } | 1860 } |
1860 | 1861 |
1861 Value* background_persistent = NULL; | 1862 Value* background_persistent = NULL; |
1862 if (!manifest_->Get(keys::kBackgroundPersistent, &background_persistent)) | 1863 if (!manifest_->Get(keys::kBackgroundPersistent, &background_persistent)) |
1863 return true; | 1864 return true; |
1864 | 1865 |
1865 if (!background_persistent->GetAsBoolean(&background_page_is_persistent_)) { | 1866 if (!background_persistent->GetAsBoolean(&background_page_is_persistent_)) { |
1866 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistent); | 1867 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistent); |
1867 return false; | 1868 return false; |
1868 } | 1869 } |
1869 | 1870 |
1870 if (!has_background_page()) { | 1871 if (!has_background_page()) { |
1871 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistentNoPage); | 1872 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistentNoPage); |
1872 return false; | 1873 return false; |
1873 } | 1874 } |
1874 | 1875 |
1875 return true; | 1876 return true; |
1876 } | 1877 } |
1877 | 1878 |
1878 bool Extension::LoadBackgroundAllowJSAccess( | 1879 bool Extension::LoadBackgroundAllowJSAccess( |
1879 const ExtensionAPIPermissionSet& api_permissions, | 1880 const APIPermissionSet& api_permissions, |
1880 string16* error) { | 1881 string16* error) { |
1881 Value* allow_js_access = NULL; | 1882 Value* allow_js_access = NULL; |
1882 if (!manifest_->Get(keys::kBackgroundAllowJsAccess, &allow_js_access)) | 1883 if (!manifest_->Get(keys::kBackgroundAllowJsAccess, &allow_js_access)) |
1883 return true; | 1884 return true; |
1884 | 1885 |
1885 if (!allow_js_access->IsType(Value::TYPE_BOOLEAN) || | 1886 if (!allow_js_access->IsType(Value::TYPE_BOOLEAN) || |
1886 !allow_js_access->GetAsBoolean(&allow_background_js_access_)) { | 1887 !allow_js_access->GetAsBoolean(&allow_background_js_access_)) { |
1887 *error = ASCIIToUTF16(errors::kInvalidBackgroundAllowJsAccess); | 1888 *error = ASCIIToUTF16(errors::kInvalidBackgroundAllowJsAccess); |
1888 return false; | 1889 return false; |
1889 } | 1890 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2046 *error = ASCIIToUTF16(errors::kInvalidIntent); | 2047 *error = ASCIIToUTF16(errors::kInvalidIntent); |
2047 return false; | 2048 return false; |
2048 } | 2049 } |
2049 if (!LoadWebIntentAction(*iter, *one_service, error)) | 2050 if (!LoadWebIntentAction(*iter, *one_service, error)) |
2050 return false; | 2051 return false; |
2051 } | 2052 } |
2052 } | 2053 } |
2053 return true; | 2054 return true; |
2054 } | 2055 } |
2055 bool Extension::LoadExtensionFeatures( | 2056 bool Extension::LoadExtensionFeatures( |
2056 const ExtensionAPIPermissionSet& api_permissions, | 2057 const APIPermissionSet& api_permissions, |
2057 string16* error) { | 2058 string16* error) { |
2058 if (manifest_->HasKey(keys::kConvertedFromUserScript)) | 2059 if (manifest_->HasKey(keys::kConvertedFromUserScript)) |
2059 manifest_->GetBoolean(keys::kConvertedFromUserScript, | 2060 manifest_->GetBoolean(keys::kConvertedFromUserScript, |
2060 &converted_from_user_script_); | 2061 &converted_from_user_script_); |
2061 | 2062 |
2062 if (!LoadDevToolsPage(error) || | 2063 if (!LoadDevToolsPage(error) || |
2063 !LoadInputComponents(api_permissions, error) || | 2064 !LoadInputComponents(api_permissions, error) || |
2064 !LoadContentScripts(error) || | 2065 !LoadContentScripts(error) || |
2065 !LoadPageAction(error) || | 2066 !LoadPageAction(error) || |
2066 !LoadBrowserAction(error) || | 2067 !LoadBrowserAction(error) || |
(...skipping 15 matching lines...) Expand all Loading... |
2082 std::string devtools_str; | 2083 std::string devtools_str; |
2083 if (!manifest_->GetString(keys::kDevToolsPage, &devtools_str)) { | 2084 if (!manifest_->GetString(keys::kDevToolsPage, &devtools_str)) { |
2084 *error = ASCIIToUTF16(errors::kInvalidDevToolsPage); | 2085 *error = ASCIIToUTF16(errors::kInvalidDevToolsPage); |
2085 return false; | 2086 return false; |
2086 } | 2087 } |
2087 devtools_url_ = GetResourceURL(devtools_str); | 2088 devtools_url_ = GetResourceURL(devtools_str); |
2088 return true; | 2089 return true; |
2089 } | 2090 } |
2090 | 2091 |
2091 bool Extension::LoadInputComponents( | 2092 bool Extension::LoadInputComponents( |
2092 const ExtensionAPIPermissionSet& api_permissions, | 2093 const APIPermissionSet& api_permissions, |
2093 string16* error) { | 2094 string16* error) { |
2094 if (!manifest_->HasKey(keys::kInputComponents)) | 2095 if (!manifest_->HasKey(keys::kInputComponents)) |
2095 return true; | 2096 return true; |
2096 ListValue* list_value = NULL; | 2097 ListValue* list_value = NULL; |
2097 if (!manifest_->GetList(keys::kInputComponents, &list_value)) { | 2098 if (!manifest_->GetList(keys::kInputComponents, &list_value)) { |
2098 *error = ASCIIToUTF16(errors::kInvalidInputComponents); | 2099 *error = ASCIIToUTF16(errors::kInvalidInputComponents); |
2099 return false; | 2100 return false; |
2100 } | 2101 } |
2101 | 2102 |
2102 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 2103 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2708 // default Content-Security-Policy? | 2709 // default Content-Security-Policy? |
2709 content_security_policy_ = is_platform_app() ? | 2710 content_security_policy_ = is_platform_app() ? |
2710 kDefaultPlatformAppContentSecurityPolicy : | 2711 kDefaultPlatformAppContentSecurityPolicy : |
2711 kDefaultContentSecurityPolicy; | 2712 kDefaultContentSecurityPolicy; |
2712 CHECK(ContentSecurityPolicyIsSecure(content_security_policy_)); | 2713 CHECK(ContentSecurityPolicyIsSecure(content_security_policy_)); |
2713 } | 2714 } |
2714 return true; | 2715 return true; |
2715 } | 2716 } |
2716 | 2717 |
2717 bool Extension::LoadAppIsolation( | 2718 bool Extension::LoadAppIsolation( |
2718 const ExtensionAPIPermissionSet& api_permissions, string16* error) { | 2719 const APIPermissionSet& api_permissions, string16* error) { |
2719 // Platform apps always get isolated storage. | 2720 // Platform apps always get isolated storage. |
2720 if (is_platform_app()) { | 2721 if (is_platform_app()) { |
2721 is_storage_isolated_ = true; | 2722 is_storage_isolated_ = true; |
2722 return true; | 2723 return true; |
2723 } | 2724 } |
2724 | 2725 |
2725 // Other apps only get it if it is requested _and_ experimental APIs are | 2726 // Other apps only get it if it is requested _and_ experimental APIs are |
2726 // enabled. | 2727 // enabled. |
2727 if (!api_permissions.count(ExtensionAPIPermission::kExperimental) || | 2728 if (!api_permissions.count(APIPermission::kExperimental) || |
2728 !is_app()) { | 2729 !is_app()) { |
2729 return true; | 2730 return true; |
2730 } | 2731 } |
2731 | 2732 |
2732 Value* temp = NULL; | 2733 Value* temp = NULL; |
2733 if (!manifest_->Get(keys::kIsolation, &temp)) | 2734 if (!manifest_->Get(keys::kIsolation, &temp)) |
2734 return true; | 2735 return true; |
2735 | 2736 |
2736 if (temp->GetType() != Value::TYPE_LIST) { | 2737 if (temp->GetType() != Value::TYPE_LIST) { |
2737 *error = ASCIIToUTF16(errors::kInvalidIsolation); | 2738 *error = ASCIIToUTF16(errors::kInvalidIsolation); |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3059 return GURL(std::string(chrome::kExtensionScheme) + | 3060 return GURL(std::string(chrome::kExtensionScheme) + |
3060 content::kStandardSchemeSeparator + extension_id + "/"); | 3061 content::kStandardSchemeSeparator + extension_id + "/"); |
3061 } | 3062 } |
3062 | 3063 |
3063 bool Extension::InitFromValue(int flags, string16* error) { | 3064 bool Extension::InitFromValue(int flags, string16* error) { |
3064 DCHECK(error); | 3065 DCHECK(error); |
3065 | 3066 |
3066 base::AutoLock auto_lock(runtime_data_lock_); | 3067 base::AutoLock auto_lock(runtime_data_lock_); |
3067 | 3068 |
3068 // Initialize permissions with an empty, default permission set. | 3069 // Initialize permissions with an empty, default permission set. |
3069 runtime_data_.SetActivePermissions(new ExtensionPermissionSet()); | 3070 runtime_data_.SetActivePermissions(new PermissionSet()); |
3070 optional_permission_set_ = new ExtensionPermissionSet(); | 3071 optional_permission_set_ = new PermissionSet(); |
3071 required_permission_set_ = new ExtensionPermissionSet(); | 3072 required_permission_set_ = new PermissionSet(); |
3072 | 3073 |
3073 creation_flags_ = flags; | 3074 creation_flags_ = flags; |
3074 | 3075 |
3075 // Important to load manifest version first because many other features | 3076 // Important to load manifest version first because many other features |
3076 // depend on its value. | 3077 // depend on its value. |
3077 if (!LoadManifestVersion(error)) | 3078 if (!LoadManifestVersion(error)) |
3078 return false; | 3079 return false; |
3079 | 3080 |
3080 // Validate minimum Chrome version. We don't need to store this, since the | 3081 // Validate minimum Chrome version. We don't need to store this, since the |
3081 // extension is not valid if it is incorrect | 3082 // extension is not valid if it is incorrect |
3082 if (!CheckMinimumChromeVersion(error)) | 3083 if (!CheckMinimumChromeVersion(error)) |
3083 return false; | 3084 return false; |
3084 | 3085 |
3085 if (!LoadRequiredFeatures(error)) | 3086 if (!LoadRequiredFeatures(error)) |
3086 return false; | 3087 return false; |
3087 | 3088 |
3088 // We don't ned to validate because InitExtensionID already did that. | 3089 // We don't ned to validate because InitExtensionID already did that. |
3089 manifest_->GetString(keys::kPublicKey, &public_key_); | 3090 manifest_->GetString(keys::kPublicKey, &public_key_); |
3090 | 3091 |
3091 extension_url_ = Extension::GetBaseURLFromExtensionId(id()); | 3092 extension_url_ = Extension::GetBaseURLFromExtensionId(id()); |
3092 | 3093 |
3093 // Load App settings. LoadExtent at least has to be done before | 3094 // Load App settings. LoadExtent at least has to be done before |
3094 // ParsePermissions(), because the valid permissions depend on what type of | 3095 // ParsePermissions(), because the valid permissions depend on what type of |
3095 // package this is. | 3096 // package this is. |
3096 if (is_app() && !LoadAppFeatures(error)) | 3097 if (is_app() && !LoadAppFeatures(error)) |
3097 return false; | 3098 return false; |
3098 | 3099 |
3099 ExtensionAPIPermissionSet api_permissions; | 3100 APIPermissionSet api_permissions; |
3100 URLPatternSet host_permissions; | 3101 URLPatternSet host_permissions; |
3101 if (!ParsePermissions(keys::kPermissions, | 3102 if (!ParsePermissions(keys::kPermissions, |
3102 error, | 3103 error, |
3103 &api_permissions, | 3104 &api_permissions, |
3104 &host_permissions)) { | 3105 &host_permissions)) { |
3105 return false; | 3106 return false; |
3106 } | 3107 } |
3107 | 3108 |
3108 // TODO(jeremya/kalman) do this via the features system by exposing the | 3109 // TODO(jeremya/kalman) do this via the features system by exposing the |
3109 // appWindow API to platform apps, with no dependency on any permissions. | 3110 // appWindow API to platform apps, with no dependency on any permissions. |
3110 // See http://crbug.com/120069. | 3111 // See http://crbug.com/120069. |
3111 if (is_platform_app()) | 3112 if (is_platform_app()) |
3112 api_permissions.insert(ExtensionAPIPermission::kAppWindow); | 3113 api_permissions.insert(APIPermission::kAppWindow); |
3113 | 3114 |
3114 ExtensionAPIPermissionSet optional_api_permissions; | 3115 APIPermissionSet optional_api_permissions; |
3115 URLPatternSet optional_host_permissions; | 3116 URLPatternSet optional_host_permissions; |
3116 if (!ParsePermissions(keys::kOptionalPermissions, | 3117 if (!ParsePermissions(keys::kOptionalPermissions, |
3117 error, | 3118 error, |
3118 &optional_api_permissions, | 3119 &optional_api_permissions, |
3119 &optional_host_permissions)) { | 3120 &optional_host_permissions)) { |
3120 return false; | 3121 return false; |
3121 } | 3122 } |
3122 | 3123 |
3123 if (!LoadAppIsolation(api_permissions, error)) | 3124 if (!LoadAppIsolation(api_permissions, error)) |
3124 return false; | 3125 return false; |
3125 | 3126 |
3126 if (!LoadSharedFeatures(api_permissions, error)) | 3127 if (!LoadSharedFeatures(api_permissions, error)) |
3127 return false; | 3128 return false; |
3128 | 3129 |
3129 if (!LoadExtensionFeatures(api_permissions, error)) | 3130 if (!LoadExtensionFeatures(api_permissions, error)) |
3130 return false; | 3131 return false; |
3131 | 3132 |
3132 if (!LoadThemeFeatures(error)) | 3133 if (!LoadThemeFeatures(error)) |
3133 return false; | 3134 return false; |
3134 | 3135 |
3135 if (HasMultipleUISurfaces()) { | 3136 if (HasMultipleUISurfaces()) { |
3136 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); | 3137 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); |
3137 return false; | 3138 return false; |
3138 } | 3139 } |
3139 | 3140 |
3140 runtime_data_.SetActivePermissions(new ExtensionPermissionSet( | 3141 runtime_data_.SetActivePermissions(new PermissionSet( |
3141 this, api_permissions, host_permissions, oauth2_info_.GetScopesAsSet())); | 3142 this, api_permissions, host_permissions, oauth2_info_.GetScopesAsSet())); |
3142 required_permission_set_ = new ExtensionPermissionSet( | 3143 required_permission_set_ = new PermissionSet( |
3143 this, api_permissions, host_permissions, oauth2_info_.GetScopesAsSet()); | 3144 this, api_permissions, host_permissions, oauth2_info_.GetScopesAsSet()); |
3144 optional_permission_set_ = new ExtensionPermissionSet( | 3145 optional_permission_set_ = new PermissionSet( |
3145 optional_api_permissions, optional_host_permissions, URLPatternSet()); | 3146 optional_api_permissions, optional_host_permissions, URLPatternSet()); |
3146 | 3147 |
3147 return true; | 3148 return true; |
3148 } | 3149 } |
3149 | 3150 |
3150 GURL Extension::GetHomepageURL() const { | 3151 GURL Extension::GetHomepageURL() const { |
3151 if (homepage_url_.is_valid()) | 3152 if (homepage_url_.is_valid()) |
3152 return homepage_url_; | 3153 return homepage_url_; |
3153 | 3154 |
3154 if (!UpdatesFromGallery()) | 3155 if (!UpdatesFromGallery()) |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3294 ExtensionIconSet::MatchType match_type) const { | 3295 ExtensionIconSet::MatchType match_type) const { |
3295 std::string path = icons().Get(size, match_type); | 3296 std::string path = icons().Get(size, match_type); |
3296 if (path.empty()) | 3297 if (path.empty()) |
3297 return GURL(); | 3298 return GURL(); |
3298 else | 3299 else |
3299 return GetResourceURL(path); | 3300 return GetResourceURL(path); |
3300 } | 3301 } |
3301 | 3302 |
3302 bool Extension::ParsePermissions(const char* key, | 3303 bool Extension::ParsePermissions(const char* key, |
3303 string16* error, | 3304 string16* error, |
3304 ExtensionAPIPermissionSet* api_permissions, | 3305 APIPermissionSet* api_permissions, |
3305 URLPatternSet* host_permissions) { | 3306 URLPatternSet* host_permissions) { |
3306 if (manifest_->HasKey(key)) { | 3307 if (manifest_->HasKey(key)) { |
3307 ListValue* permissions = NULL; | 3308 ListValue* permissions = NULL; |
3308 if (!manifest_->GetList(key, &permissions)) { | 3309 if (!manifest_->GetList(key, &permissions)) { |
3309 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 3310 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
3310 errors::kInvalidPermissions, ""); | 3311 errors::kInvalidPermissions, ""); |
3311 return false; | 3312 return false; |
3312 } | 3313 } |
3313 | 3314 |
3314 for (size_t i = 0; i < permissions->GetSize(); ++i) { | 3315 for (size_t i = 0; i < permissions->GetSize(); ++i) { |
3315 std::string permission_str; | 3316 std::string permission_str; |
3316 if (!permissions->GetString(i, &permission_str)) { | 3317 if (!permissions->GetString(i, &permission_str)) { |
3317 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 3318 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
3318 errors::kInvalidPermission, base::IntToString(i)); | 3319 errors::kInvalidPermission, base::IntToString(i)); |
3319 return false; | 3320 return false; |
3320 } | 3321 } |
3321 | 3322 |
3322 // NOTE: We need to get the ExtensionAPIPermission before the Feature | 3323 // NOTE: We need to get the APIPermission before the Feature |
3323 // object because the feature system does not know about aliases. | 3324 // object because the feature system does not know about aliases. |
3324 ExtensionAPIPermission* permission = | 3325 APIPermission* permission = |
3325 ExtensionPermissionsInfo::GetInstance()->GetByName(permission_str); | 3326 PermissionsInfo::GetInstance()->GetByName(permission_str); |
3326 if (permission) { | 3327 if (permission) { |
3327 extensions::SimpleFeatureProvider* permission_features = | 3328 extensions::SimpleFeatureProvider* permission_features = |
3328 extensions::SimpleFeatureProvider::GetPermissionFeatures(); | 3329 extensions::SimpleFeatureProvider::GetPermissionFeatures(); |
3329 extensions::Feature* feature = | 3330 extensions::Feature* feature = |
3330 permission_features->GetFeature(permission->name()); | 3331 permission_features->GetFeature(permission->name()); |
3331 | 3332 |
3332 // The feature should exist since we just got an ExtensionAPIPermission | 3333 // The feature should exist since we just got an APIPermission |
3333 // for it. The two systems should be updated together whenever a | 3334 // for it. The two systems should be updated together whenever a |
3334 // permission is added. | 3335 // permission is added. |
3335 CHECK(feature); | 3336 CHECK(feature); |
3336 | 3337 |
3337 extensions::Feature::Availability availability = | 3338 extensions::Feature::Availability availability = |
3338 feature->IsAvailableToManifest( | 3339 feature->IsAvailableToManifest( |
3339 id(), | 3340 id(), |
3340 GetType(), | 3341 GetType(), |
3341 extensions::Feature::ConvertLocation(location()), | 3342 extensions::Feature::ConvertLocation(location()), |
3342 manifest_version()); | 3343 manifest_version()); |
3343 if (availability != extensions::Feature::IS_AVAILABLE) { | 3344 if (availability != extensions::Feature::IS_AVAILABLE) { |
3344 // Don't fail, but warn the developer that the manifest contains | 3345 // Don't fail, but warn the developer that the manifest contains |
3345 // unrecognized permissions. This may happen legitimately if the | 3346 // unrecognized permissions. This may happen legitimately if the |
3346 // extensions requests platform- or channel-specific permissions. | 3347 // extensions requests platform- or channel-specific permissions. |
3347 install_warnings_.push_back( | 3348 install_warnings_.push_back( |
3348 InstallWarning(InstallWarning::FORMAT_TEXT, | 3349 InstallWarning(InstallWarning::FORMAT_TEXT, |
3349 feature->GetErrorMessage(availability))); | 3350 feature->GetErrorMessage(availability))); |
3350 continue; | 3351 continue; |
3351 } | 3352 } |
3352 | 3353 |
3353 if (permission->id() == ExtensionAPIPermission::kExperimental) { | 3354 if (permission->id() == APIPermission::kExperimental) { |
3354 if (!CanSpecifyExperimentalPermission()) { | 3355 if (!CanSpecifyExperimentalPermission()) { |
3355 *error = ASCIIToUTF16(errors::kExperimentalFlagRequired); | 3356 *error = ASCIIToUTF16(errors::kExperimentalFlagRequired); |
3356 return false; | 3357 return false; |
3357 } | 3358 } |
3358 } | 3359 } |
3359 | 3360 |
3360 api_permissions->insert(permission->id()); | 3361 api_permissions->insert(permission->id()); |
3361 continue; | 3362 continue; |
3362 } | 3363 } |
3363 | 3364 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3400 } | 3401 } |
3401 } | 3402 } |
3402 return true; | 3403 return true; |
3403 } | 3404 } |
3404 | 3405 |
3405 bool Extension::CanSilentlyIncreasePermissions() const { | 3406 bool Extension::CanSilentlyIncreasePermissions() const { |
3406 return location() != INTERNAL; | 3407 return location() != INTERNAL; |
3407 } | 3408 } |
3408 | 3409 |
3409 bool Extension::CanSpecifyHostPermission(const URLPattern& pattern, | 3410 bool Extension::CanSpecifyHostPermission(const URLPattern& pattern, |
3410 const ExtensionAPIPermissionSet& permissions) const { | 3411 const APIPermissionSet& permissions) const { |
3411 if (!pattern.match_all_urls() && | 3412 if (!pattern.match_all_urls() && |
3412 pattern.MatchesScheme(chrome::kChromeUIScheme)) { | 3413 pattern.MatchesScheme(chrome::kChromeUIScheme)) { |
3413 // Regular extensions are only allowed access to chrome://favicon. | 3414 // Regular extensions are only allowed access to chrome://favicon. |
3414 if (pattern.host() == chrome::kChromeUIFaviconHost) | 3415 if (pattern.host() == chrome::kChromeUIFaviconHost) |
3415 return true; | 3416 return true; |
3416 | 3417 |
3417 // Experimental extensions are also allowed chrome://thumb. | 3418 // Experimental extensions are also allowed chrome://thumb. |
3418 if (pattern.host() == chrome::kChromeUIThumbnailHost) { | 3419 if (pattern.host() == chrome::kChromeUIThumbnailHost) { |
3419 return permissions.find(ExtensionAPIPermission::kExperimental) != | 3420 return permissions.find(APIPermission::kExperimental) != |
3420 permissions.end(); | 3421 permissions.end(); |
3421 } | 3422 } |
3422 | 3423 |
3423 // Component extensions can have access to all of chrome://*. | 3424 // Component extensions can have access to all of chrome://*. |
3424 if (CanExecuteScriptEverywhere()) | 3425 if (CanExecuteScriptEverywhere()) |
3425 return true; | 3426 return true; |
3426 | 3427 |
3427 return false; | 3428 return false; |
3428 } | 3429 } |
3429 | 3430 |
3430 // Otherwise, the valid schemes were handled by URLPattern. | 3431 // Otherwise, the valid schemes were handled by URLPattern. |
3431 return true; | 3432 return true; |
3432 } | 3433 } |
3433 | 3434 |
3434 bool Extension::HasAPIPermission( | 3435 bool Extension::HasAPIPermission( |
3435 ExtensionAPIPermission::ID permission) const { | 3436 APIPermission::ID permission) const { |
3436 base::AutoLock auto_lock(runtime_data_lock_); | 3437 base::AutoLock auto_lock(runtime_data_lock_); |
3437 return runtime_data_.GetActivePermissions()->HasAPIPermission(permission); | 3438 return runtime_data_.GetActivePermissions()->HasAPIPermission(permission); |
3438 } | 3439 } |
3439 | 3440 |
3440 bool Extension::HasAPIPermission( | 3441 bool Extension::HasAPIPermission( |
3441 const std::string& function_name) const { | 3442 const std::string& function_name) const { |
3442 base::AutoLock auto_lock(runtime_data_lock_); | 3443 base::AutoLock auto_lock(runtime_data_lock_); |
3443 return runtime_data_.GetActivePermissions()-> | 3444 return runtime_data_.GetActivePermissions()-> |
3444 HasAccessToFunction(function_name); | 3445 HasAccessToFunction(function_name); |
3445 } | 3446 } |
(...skipping 19 matching lines...) Expand all Loading... |
3465 bool Extension::HasEffectiveAccessToAllHosts() const { | 3466 bool Extension::HasEffectiveAccessToAllHosts() const { |
3466 base::AutoLock auto_lock(runtime_data_lock_); | 3467 base::AutoLock auto_lock(runtime_data_lock_); |
3467 return runtime_data_.GetActivePermissions()->HasEffectiveAccessToAllHosts(); | 3468 return runtime_data_.GetActivePermissions()->HasEffectiveAccessToAllHosts(); |
3468 } | 3469 } |
3469 | 3470 |
3470 bool Extension::HasFullPermissions() const { | 3471 bool Extension::HasFullPermissions() const { |
3471 base::AutoLock auto_lock(runtime_data_lock_); | 3472 base::AutoLock auto_lock(runtime_data_lock_); |
3472 return runtime_data_.GetActivePermissions()->HasEffectiveFullAccess(); | 3473 return runtime_data_.GetActivePermissions()->HasEffectiveFullAccess(); |
3473 } | 3474 } |
3474 | 3475 |
3475 ExtensionPermissionMessages Extension::GetPermissionMessages() const { | 3476 PermissionMessages Extension::GetPermissionMessages() const { |
3476 base::AutoLock auto_lock(runtime_data_lock_); | 3477 base::AutoLock auto_lock(runtime_data_lock_); |
3477 if (IsTrustedId(id())) | 3478 if (IsTrustedId(id())) |
3478 return ExtensionPermissionMessages(); | 3479 return PermissionMessages(); |
3479 else | 3480 else |
3480 return runtime_data_.GetActivePermissions()->GetPermissionMessages(); | 3481 return runtime_data_.GetActivePermissions()->GetPermissionMessages(); |
3481 } | 3482 } |
3482 | 3483 |
3483 std::vector<string16> Extension::GetPermissionMessageStrings() const { | 3484 std::vector<string16> Extension::GetPermissionMessageStrings() const { |
3484 base::AutoLock auto_lock(runtime_data_lock_); | 3485 base::AutoLock auto_lock(runtime_data_lock_); |
3485 if (IsTrustedId(id())) | 3486 if (IsTrustedId(id())) |
3486 return std::vector<string16>(); | 3487 return std::vector<string16>(); |
3487 else | 3488 else |
3488 return runtime_data_.GetActivePermissions()->GetWarningMessages(); | 3489 return runtime_data_.GetActivePermissions()->GetWarningMessages(); |
3489 } | 3490 } |
3490 | 3491 |
3491 void Extension::SetActivePermissions( | 3492 void Extension::SetActivePermissions( |
3492 const ExtensionPermissionSet* permissions) const { | 3493 const PermissionSet* permissions) const { |
3493 base::AutoLock auto_lock(runtime_data_lock_); | 3494 base::AutoLock auto_lock(runtime_data_lock_); |
3494 runtime_data_.SetActivePermissions(permissions); | 3495 runtime_data_.SetActivePermissions(permissions); |
3495 } | 3496 } |
3496 | 3497 |
3497 scoped_refptr<const ExtensionPermissionSet> | 3498 scoped_refptr<const PermissionSet> |
3498 Extension::GetActivePermissions() const { | 3499 Extension::GetActivePermissions() const { |
3499 base::AutoLock auto_lock(runtime_data_lock_); | 3500 base::AutoLock auto_lock(runtime_data_lock_); |
3500 return runtime_data_.GetActivePermissions(); | 3501 return runtime_data_.GetActivePermissions(); |
3501 } | 3502 } |
3502 | 3503 |
3503 bool Extension::HasMultipleUISurfaces() const { | 3504 bool Extension::HasMultipleUISurfaces() const { |
3504 int num_surfaces = 0; | 3505 int num_surfaces = 0; |
3505 | 3506 |
3506 if (page_action()) | 3507 if (page_action()) |
3507 ++num_surfaces; | 3508 ++num_surfaces; |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3801 if (!has_background_page()) { | 3802 if (!has_background_page()) { |
3802 *utf8_error = errors::kBackgroundRequiredForPlatformApps; | 3803 *utf8_error = errors::kBackgroundRequiredForPlatformApps; |
3803 return false; | 3804 return false; |
3804 } | 3805 } |
3805 | 3806 |
3806 return true; | 3807 return true; |
3807 } | 3808 } |
3808 | 3809 |
3809 bool Extension::CheckConflictingFeatures(std::string* utf8_error) { | 3810 bool Extension::CheckConflictingFeatures(std::string* utf8_error) { |
3810 if (has_lazy_background_page() && | 3811 if (has_lazy_background_page() && |
3811 HasAPIPermission(ExtensionAPIPermission::kWebRequest)) { | 3812 HasAPIPermission(APIPermission::kWebRequest)) { |
3812 *utf8_error = errors::kWebRequestConflictsWithLazyBackground; | 3813 *utf8_error = errors::kWebRequestConflictsWithLazyBackground; |
3813 return false; | 3814 return false; |
3814 } | 3815 } |
3815 | 3816 |
3816 return true; | 3817 return true; |
3817 } | 3818 } |
3818 | 3819 |
3819 ExtensionInfo::~ExtensionInfo() {} | 3820 ExtensionInfo::~ExtensionInfo() {} |
3820 | 3821 |
3821 Extension::RuntimeData::RuntimeData() {} | 3822 Extension::RuntimeData::RuntimeData() {} |
3822 Extension::RuntimeData::RuntimeData(const ExtensionPermissionSet* active) | 3823 Extension::RuntimeData::RuntimeData(const PermissionSet* active) |
3823 : active_permissions_(active) {} | 3824 : active_permissions_(active) {} |
3824 Extension::RuntimeData::~RuntimeData() {} | 3825 Extension::RuntimeData::~RuntimeData() {} |
3825 | 3826 |
3826 scoped_refptr<const ExtensionPermissionSet> | 3827 scoped_refptr<const PermissionSet> |
3827 Extension::RuntimeData::GetActivePermissions() const { | 3828 Extension::RuntimeData::GetActivePermissions() const { |
3828 return active_permissions_; | 3829 return active_permissions_; |
3829 } | 3830 } |
3830 | 3831 |
3831 void Extension::RuntimeData::SetActivePermissions( | 3832 void Extension::RuntimeData::SetActivePermissions( |
3832 const ExtensionPermissionSet* active) { | 3833 const PermissionSet* active) { |
3833 active_permissions_ = active; | 3834 active_permissions_ = active; |
3834 } | 3835 } |
3835 | 3836 |
3836 const URLPatternSet* | 3837 const URLPatternSet* |
3837 Extension::RuntimeData::GetTabSpecificHostPermissions(int tab_id) const { | 3838 Extension::RuntimeData::GetTabSpecificHostPermissions(int tab_id) const { |
3838 CHECK_GE(tab_id, 0); | 3839 CHECK_GE(tab_id, 0); |
3839 TabHostPermissionsMap::const_iterator it = | 3840 TabHostPermissionsMap::const_iterator it = |
3840 tab_specific_host_permissions_.find(tab_id); | 3841 tab_specific_host_permissions_.find(tab_id); |
3841 return (it != tab_specific_host_permissions_.end()) ? it->second.get() : NULL; | 3842 return (it != tab_specific_host_permissions_.end()) ? it->second.get() : NULL; |
3842 } | 3843 } |
(...skipping 13 matching lines...) Expand all Loading... |
3856 | 3857 |
3857 UnloadedExtensionInfo::UnloadedExtensionInfo( | 3858 UnloadedExtensionInfo::UnloadedExtensionInfo( |
3858 const Extension* extension, | 3859 const Extension* extension, |
3859 extension_misc::UnloadedExtensionReason reason) | 3860 extension_misc::UnloadedExtensionReason reason) |
3860 : reason(reason), | 3861 : reason(reason), |
3861 already_disabled(false), | 3862 already_disabled(false), |
3862 extension(extension) {} | 3863 extension(extension) {} |
3863 | 3864 |
3864 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3865 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
3865 const Extension* extension, | 3866 const Extension* extension, |
3866 const ExtensionPermissionSet* permissions, | 3867 const PermissionSet* permissions, |
3867 Reason reason) | 3868 Reason reason) |
3868 : reason(reason), | 3869 : reason(reason), |
3869 extension(extension), | 3870 extension(extension), |
3870 permissions(permissions) {} | 3871 permissions(permissions) {} |
3871 | 3872 |
3872 } // namespace extensions | 3873 } // namespace extensions |
OLD | NEW |