| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/common/chrome_constants.h" | 25 #include "chrome/common/chrome_constants.h" |
| 26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/chrome_version_info.h" | 27 #include "chrome/common/chrome_version_info.h" |
| 28 #include "chrome/common/extensions/extension_action.h" | 28 #include "chrome/common/extensions/extension_action.h" |
| 29 #include "chrome/common/extensions/extension_constants.h" | 29 #include "chrome/common/extensions/extension_constants.h" |
| 30 #include "chrome/common/extensions/extension_error_utils.h" | 30 #include "chrome/common/extensions/extension_error_utils.h" |
| 31 #include "chrome/common/extensions/extension_l10n_util.h" | 31 #include "chrome/common/extensions/extension_l10n_util.h" |
| 32 #include "chrome/common/extensions/extension_resource.h" | 32 #include "chrome/common/extensions/extension_resource.h" |
| 33 #include "chrome/common/extensions/extension_sidebar_defaults.h" | 33 #include "chrome/common/extensions/extension_sidebar_defaults.h" |
| 34 #include "chrome/common/extensions/extension_sidebar_utils.h" | 34 #include "chrome/common/extensions/extension_sidebar_utils.h" |
| 35 #include "chrome/common/extensions/file_browser_handler.h" |
| 35 #include "chrome/common/extensions/user_script.h" | 36 #include "chrome/common/extensions/user_script.h" |
| 36 #include "chrome/common/url_constants.h" | 37 #include "chrome/common/url_constants.h" |
| 37 #include "googleurl/src/url_util.h" | 38 #include "googleurl/src/url_util.h" |
| 38 #include "grit/chromium_strings.h" | 39 #include "grit/chromium_strings.h" |
| 39 #include "grit/generated_resources.h" | 40 #include "grit/generated_resources.h" |
| 40 #include "grit/theme_resources.h" | 41 #include "grit/theme_resources.h" |
| 41 #include "net/base/registry_controlled_domain.h" | 42 #include "net/base/registry_controlled_domain.h" |
| 42 #include "third_party/skia/include/core/SkBitmap.h" | 43 #include "third_party/skia/include/core/SkBitmap.h" |
| 43 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
| 44 #include "ui/base/resource/resource_bundle.h" | 45 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 // Explicit permissions -- permission declaration required. | 259 // Explicit permissions -- permission declaration required. |
| 259 const char Extension::kBackgroundPermission[] = "background"; | 260 const char Extension::kBackgroundPermission[] = "background"; |
| 260 const char Extension::kBookmarkPermission[] = "bookmarks"; | 261 const char Extension::kBookmarkPermission[] = "bookmarks"; |
| 261 const char Extension::kContextMenusPermission[] = "contextMenus"; | 262 const char Extension::kContextMenusPermission[] = "contextMenus"; |
| 262 const char Extension::kContentSettingsPermission[] = "contentSettings"; | 263 const char Extension::kContentSettingsPermission[] = "contentSettings"; |
| 263 const char Extension::kCookiePermission[] = "cookies"; | 264 const char Extension::kCookiePermission[] = "cookies"; |
| 264 const char Extension::kChromeosInfoPrivatePermissions[] = "chromeosInfoPrivate"; | 265 const char Extension::kChromeosInfoPrivatePermissions[] = "chromeosInfoPrivate"; |
| 265 const char Extension::kDebuggerPermission[] = "debugger"; | 266 const char Extension::kDebuggerPermission[] = "debugger"; |
| 266 const char Extension::kExperimentalPermission[] = "experimental"; | 267 const char Extension::kExperimentalPermission[] = "experimental"; |
| 267 const char Extension::kFileBrowserHandlerPermission[] = "fileBrowserHandler"; | 268 const char Extension::kFileBrowserHandlerPermission[] = "fileBrowserHandler"; |
| 268 const char Extension::kFileSystemPermission[] = "fileSystem"; | |
| 269 const char Extension::kFileBrowserPrivatePermission[] = "fileBrowserPrivate"; | 269 const char Extension::kFileBrowserPrivatePermission[] = "fileBrowserPrivate"; |
| 270 const char Extension::kGeolocationPermission[] = "geolocation"; | 270 const char Extension::kGeolocationPermission[] = "geolocation"; |
| 271 const char Extension::kHistoryPermission[] = "history"; | 271 const char Extension::kHistoryPermission[] = "history"; |
| 272 const char Extension::kIdlePermission[] = "idle"; | 272 const char Extension::kIdlePermission[] = "idle"; |
| 273 const char Extension::kManagementPermission[] = "management"; | 273 const char Extension::kManagementPermission[] = "management"; |
| 274 const char Extension::kNotificationPermission[] = "notifications"; | 274 const char Extension::kNotificationPermission[] = "notifications"; |
| 275 const char Extension::kProxyPermission[] = "proxy"; | 275 const char Extension::kProxyPermission[] = "proxy"; |
| 276 const char Extension::kTabPermission[] = "tabs"; | 276 const char Extension::kTabPermission[] = "tabs"; |
| 277 const char Extension::kUnlimitedStoragePermission[] = "unlimitedStorage"; | 277 const char Extension::kUnlimitedStoragePermission[] = "unlimitedStorage"; |
| 278 const char Extension::kWebstorePrivatePermission[] = "webstorePrivate"; | 278 const char Extension::kWebstorePrivatePermission[] = "webstorePrivate"; |
| 279 | 279 |
| 280 // In general, all permissions should have an install message. | 280 // In general, all permissions should have an install message. |
| 281 // See ExtensionsTest.PermissionMessages for an explanation of each | 281 // See ExtensionsTest.PermissionMessages for an explanation of each |
| 282 // exception. | 282 // exception. |
| 283 const Extension::Permission Extension::kPermissions[] = { | 283 const Extension::Permission Extension::kPermissions[] = { |
| 284 { kBackgroundPermission, 0 }, | 284 { kBackgroundPermission, 0 }, |
| 285 { kBookmarkPermission, IDS_EXTENSION_PROMPT_WARNING_BOOKMARKS }, | 285 { kBookmarkPermission, IDS_EXTENSION_PROMPT_WARNING_BOOKMARKS }, |
| 286 { kChromeosInfoPrivatePermissions, 0}, | 286 { kChromeosInfoPrivatePermissions, 0}, |
| 287 { kContentSettingsPermission, 0 }, | 287 { kContentSettingsPermission, 0 }, |
| 288 { kContextMenusPermission, 0 }, | 288 { kContextMenusPermission, 0 }, |
| 289 { kCookiePermission, 0 }, | 289 { kCookiePermission, 0 }, |
| 290 { kDebuggerPermission, IDS_EXTENSION_PROMPT_WARNING_DEBUGGER }, | 290 { kDebuggerPermission, IDS_EXTENSION_PROMPT_WARNING_DEBUGGER }, |
| 291 { kExperimentalPermission, 0 }, | 291 { kExperimentalPermission, 0 }, |
| 292 { kFileBrowserHandlerPermission, 0 }, | 292 { kFileBrowserHandlerPermission, 0 }, |
| 293 { kFileSystemPermission, 0 }, | |
| 294 { kFileBrowserPrivatePermission, 0 }, | 293 { kFileBrowserPrivatePermission, 0 }, |
| 295 { kGeolocationPermission, IDS_EXTENSION_PROMPT_WARNING_GEOLOCATION }, | 294 { kGeolocationPermission, IDS_EXTENSION_PROMPT_WARNING_GEOLOCATION }, |
| 296 { kIdlePermission, 0 }, | 295 { kIdlePermission, 0 }, |
| 297 { kHistoryPermission, IDS_EXTENSION_PROMPT_WARNING_BROWSING_HISTORY }, | 296 { kHistoryPermission, IDS_EXTENSION_PROMPT_WARNING_BROWSING_HISTORY }, |
| 298 { kManagementPermission, IDS_EXTENSION_PROMPT_WARNING_MANAGEMENT }, | 297 { kManagementPermission, IDS_EXTENSION_PROMPT_WARNING_MANAGEMENT }, |
| 299 { kNotificationPermission, 0 }, | 298 { kNotificationPermission, 0 }, |
| 300 { kProxyPermission, 0 }, | 299 { kProxyPermission, 0 }, |
| 301 { kTabPermission, IDS_EXTENSION_PROMPT_WARNING_TABS }, | 300 { kTabPermission, IDS_EXTENSION_PROMPT_WARNING_TABS }, |
| 302 { kUnlimitedStoragePermission, 0 }, | 301 { kUnlimitedStoragePermission, 0 }, |
| 303 { kWebstorePrivatePermission, 0 }, | 302 { kWebstorePrivatePermission, 0 }, |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 result->SetPopupUrl(ExtensionAction::kDefaultTabId, url); | 944 result->SetPopupUrl(ExtensionAction::kDefaultTabId, url); |
| 946 } else { | 945 } else { |
| 947 DCHECK(!result->HasPopup(ExtensionAction::kDefaultTabId)) | 946 DCHECK(!result->HasPopup(ExtensionAction::kDefaultTabId)) |
| 948 << "Shouldn't be posible for the popup to be set."; | 947 << "Shouldn't be posible for the popup to be set."; |
| 949 } | 948 } |
| 950 } | 949 } |
| 951 | 950 |
| 952 return result.release(); | 951 return result.release(); |
| 953 } | 952 } |
| 954 | 953 |
| 954 Extension::FileBrowserHandlerList* Extension::LoadFileBrowserHandlers( |
| 955 const ListValue* extension_actions, std::string* error) { |
| 956 scoped_ptr<FileBrowserHandlerList> result( |
| 957 new FileBrowserHandlerList()); |
| 958 for (ListValue::const_iterator iter = extension_actions->begin(); |
| 959 iter != extension_actions->end(); |
| 960 ++iter) { |
| 961 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) { |
| 962 *error = errors::kInvalidFileBrowserHandler; |
| 963 return NULL; |
| 964 } |
| 965 scoped_ptr<FileBrowserHandler> action( |
| 966 LoadFileBrowserHandler( |
| 967 reinterpret_cast<DictionaryValue*>(*iter), error)); |
| 968 if (!action.get()) |
| 969 return NULL; // Failed to parse file browser action definition. |
| 970 result->push_back(linked_ptr<FileBrowserHandler>(action.release())); |
| 971 } |
| 972 return result.release(); |
| 973 } |
| 974 |
| 975 FileBrowserHandler* Extension::LoadFileBrowserHandler( |
| 976 const DictionaryValue* file_browser_handler, std::string* error) { |
| 977 scoped_ptr<FileBrowserHandler> result( |
| 978 new FileBrowserHandler()); |
| 979 result->set_extension_id(id()); |
| 980 |
| 981 std::string id; |
| 982 // Read the file action |id| (mandatory). |
| 983 if (!file_browser_handler->HasKey(keys::kPageActionId) || |
| 984 !file_browser_handler->GetString(keys::kPageActionId, &id)) { |
| 985 *error = errors::kInvalidPageActionId; |
| 986 return NULL; |
| 987 } |
| 988 result->set_id(id); |
| 989 |
| 990 // Read the page action title from |default_title| (mandatory). |
| 991 std::string title; |
| 992 if (!file_browser_handler->HasKey(keys::kPageActionDefaultTitle) || |
| 993 !file_browser_handler->GetString(keys::kPageActionDefaultTitle, &title)) { |
| 994 *error = errors::kInvalidPageActionDefaultTitle; |
| 995 return NULL; |
| 996 } |
| 997 result->set_title(title); |
| 998 |
| 999 // Initialize file filters (mandatory). |
| 1000 ListValue* list_value = NULL; |
| 1001 if (!file_browser_handler->HasKey(keys::kFileFilters) || |
| 1002 !file_browser_handler->GetList(keys::kFileFilters, &list_value) || |
| 1003 list_value->empty()) { |
| 1004 *error = errors::kInvalidFileFiltersList; |
| 1005 return NULL; |
| 1006 } |
| 1007 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
| 1008 std::string filter; |
| 1009 if (!list_value->GetString(i, &filter)) { |
| 1010 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 1011 errors::kInvalidFileFilterValue, base::IntToString(i)); |
| 1012 return NULL; |
| 1013 } |
| 1014 URLPattern pattern(URLPattern::SCHEME_FILESYSTEM); |
| 1015 if (URLPattern::PARSE_SUCCESS != pattern.Parse(filter, |
| 1016 URLPattern::PARSE_STRICT)) { |
| 1017 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 1018 errors::kInvalidURLPatternError, filter); |
| 1019 return NULL; |
| 1020 } |
| 1021 result->AddPattern(pattern); |
| 1022 } |
| 1023 |
| 1024 std::string default_icon; |
| 1025 // Read the file browser action |default_icon| (optional). |
| 1026 if (file_browser_handler->HasKey(keys::kPageActionDefaultIcon)) { |
| 1027 if (!file_browser_handler->GetString( |
| 1028 keys::kPageActionDefaultIcon,&default_icon) || |
| 1029 default_icon.empty()) { |
| 1030 *error = errors::kInvalidPageActionIconPath; |
| 1031 return NULL; |
| 1032 } |
| 1033 result->set_icon_path(default_icon); |
| 1034 } |
| 1035 |
| 1036 return result.release(); |
| 1037 } |
| 1038 |
| 955 ExtensionSidebarDefaults* Extension::LoadExtensionSidebarDefaults( | 1039 ExtensionSidebarDefaults* Extension::LoadExtensionSidebarDefaults( |
| 956 const DictionaryValue* extension_sidebar, std::string* error) { | 1040 const DictionaryValue* extension_sidebar, std::string* error) { |
| 957 scoped_ptr<ExtensionSidebarDefaults> result(new ExtensionSidebarDefaults()); | 1041 scoped_ptr<ExtensionSidebarDefaults> result(new ExtensionSidebarDefaults()); |
| 958 | 1042 |
| 959 std::string default_icon; | 1043 std::string default_icon; |
| 960 // Read sidebar's |default_icon| (optional). | 1044 // Read sidebar's |default_icon| (optional). |
| 961 if (extension_sidebar->HasKey(keys::kSidebarDefaultIcon)) { | 1045 if (extension_sidebar->HasKey(keys::kSidebarDefaultIcon)) { |
| 962 if (!extension_sidebar->GetString(keys::kSidebarDefaultIcon, | 1046 if (!extension_sidebar->GetString(keys::kSidebarDefaultIcon, |
| 963 &default_icon) || | 1047 &default_icon) || |
| 964 default_icon.empty()) { | 1048 default_icon.empty()) { |
| (...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1968 *error = errors::kInvalidBrowserAction; | 2052 *error = errors::kInvalidBrowserAction; |
| 1969 return false; | 2053 return false; |
| 1970 } | 2054 } |
| 1971 | 2055 |
| 1972 browser_action_.reset( | 2056 browser_action_.reset( |
| 1973 LoadExtensionActionHelper(browser_action_value, error)); | 2057 LoadExtensionActionHelper(browser_action_value, error)); |
| 1974 if (!browser_action_.get()) | 2058 if (!browser_action_.get()) |
| 1975 return false; // Failed to parse browser action definition. | 2059 return false; // Failed to parse browser action definition. |
| 1976 } | 2060 } |
| 1977 | 2061 |
| 2062 // Initialize file browser actions (optional). |
| 2063 if (source.HasKey(keys::kFileBrowserHandlers)) { |
| 2064 ListValue* file_browser_handlers_value = NULL; |
| 2065 if (!source.GetList(keys::kFileBrowserHandlers, |
| 2066 &file_browser_handlers_value)) { |
| 2067 *error = errors::kInvalidFileBrowserHandler; |
| 2068 return false; |
| 2069 } |
| 2070 |
| 2071 file_browser_handlers_.reset( |
| 2072 LoadFileBrowserHandlers(file_browser_handlers_value, error)); |
| 2073 if (!file_browser_handlers_.get()) |
| 2074 return false; // Failed to parse file browser actions definition. |
| 2075 } |
| 2076 |
| 1978 // Load App settings. | 2077 // Load App settings. |
| 1979 if (!LoadIsApp(manifest_value_.get(), error) || | 2078 if (!LoadIsApp(manifest_value_.get(), error) || |
| 1980 !LoadExtent(manifest_value_.get(), keys::kWebURLs, | 2079 !LoadExtent(manifest_value_.get(), keys::kWebURLs, |
| 1981 &extent_, | 2080 &extent_, |
| 1982 errors::kInvalidWebURLs, errors::kInvalidWebURL, | 2081 errors::kInvalidWebURLs, errors::kInvalidWebURL, |
| 1983 parse_strictness, error) || | 2082 parse_strictness, error) || |
| 1984 !EnsureNotHybridApp(manifest_value_.get(), error) || | 2083 !EnsureNotHybridApp(manifest_value_.get(), error) || |
| 1985 !LoadLaunchURL(manifest_value_.get(), error) || | 2084 !LoadLaunchURL(manifest_value_.get(), error) || |
| 1986 !LoadLaunchContainer(manifest_value_.get(), error) || | 2085 !LoadLaunchContainer(manifest_value_.get(), error) || |
| 1987 !LoadAppIsolation(manifest_value_.get(), error)) { | 2086 !LoadAppIsolation(manifest_value_.get(), error)) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2033 std::string permission_str; | 2132 std::string permission_str; |
| 2034 if (!permissions->GetString(i, &permission_str)) { | 2133 if (!permissions->GetString(i, &permission_str)) { |
| 2035 *error = ExtensionErrorUtils::FormatErrorMessage( | 2134 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 2036 errors::kInvalidPermission, base::IntToString(i)); | 2135 errors::kInvalidPermission, base::IntToString(i)); |
| 2037 return false; | 2136 return false; |
| 2038 } | 2137 } |
| 2039 | 2138 |
| 2040 // Only COMPONENT extensions can use private APIs. | 2139 // Only COMPONENT extensions can use private APIs. |
| 2041 // TODO(asargent) - We want a more general purpose mechanism for this, | 2140 // TODO(asargent) - We want a more general purpose mechanism for this, |
| 2042 // and better error messages. (http://crbug.com/54013) | 2141 // and better error messages. (http://crbug.com/54013) |
| 2043 if (!IsComponentOnlyPermission(permission_str)) { | 2142 if (!IsComponentOnlyPermission(permission_str) |
| 2143 #ifndef NDEBUG |
| 2144 && !CommandLine::ForCurrentProcess()->HasSwitch( |
| 2145 switches::kExposePrivateExtensionApi) |
| 2146 #endif |
| 2147 ) { |
| 2044 continue; | 2148 continue; |
| 2045 } | 2149 } |
| 2046 | 2150 |
| 2047 // Remap the old unlimited storage permission name. | 2151 // Remap the old unlimited storage permission name. |
| 2048 if (permission_str == kOldUnlimitedStoragePermission) | 2152 if (permission_str == kOldUnlimitedStoragePermission) |
| 2049 permission_str = kUnlimitedStoragePermission; | 2153 permission_str = kUnlimitedStoragePermission; |
| 2050 | 2154 |
| 2051 if (web_extent().is_empty() || location() == Extension::COMPONENT) { | 2155 if (web_extent().is_empty() || location() == Extension::COMPONENT) { |
| 2052 // Check if it's a module permission. If so, enable that permission. | 2156 // Check if it's a module permission. If so, enable that permission. |
| 2053 if (IsAPIPermission(permission_str)) { | 2157 if (IsAPIPermission(permission_str)) { |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2665 bool Extension::IsAPIPermission(const std::string& str) const { | 2769 bool Extension::IsAPIPermission(const std::string& str) const { |
| 2666 for (size_t i = 0; i < Extension::kNumPermissions; ++i) { | 2770 for (size_t i = 0; i < Extension::kNumPermissions; ++i) { |
| 2667 if (str == Extension::kPermissions[i].name) { | 2771 if (str == Extension::kPermissions[i].name) { |
| 2668 return true; | 2772 return true; |
| 2669 } | 2773 } |
| 2670 } | 2774 } |
| 2671 return false; | 2775 return false; |
| 2672 } | 2776 } |
| 2673 | 2777 |
| 2674 bool Extension::CanExecuteScriptEverywhere() const { | 2778 bool Extension::CanExecuteScriptEverywhere() const { |
| 2675 if (location() == Extension::COMPONENT) | 2779 if (location() == Extension::COMPONENT |
| 2780 #ifndef NDEBUG |
| 2781 || CommandLine::ForCurrentProcess()->HasSwitch( |
| 2782 switches::kExposePrivateExtensionApi) |
| 2783 #endif |
| 2784 ) |
| 2676 return true; | 2785 return true; |
| 2677 | 2786 |
| 2678 ScriptingWhitelist* whitelist = | 2787 ScriptingWhitelist* whitelist = |
| 2679 ExtensionConfig::GetInstance()->whitelist(); | 2788 ExtensionConfig::GetInstance()->whitelist(); |
| 2680 | 2789 |
| 2681 for (ScriptingWhitelist::const_iterator it = whitelist->begin(); | 2790 for (ScriptingWhitelist::const_iterator it = whitelist->begin(); |
| 2682 it != whitelist->end(); ++it) { | 2791 it != whitelist->end(); ++it) { |
| 2683 if (id() == *it) { | 2792 if (id() == *it) { |
| 2684 return true; | 2793 return true; |
| 2685 } | 2794 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2747 | 2856 |
| 2748 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} | 2857 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} |
| 2749 | 2858 |
| 2750 | 2859 |
| 2751 UnloadedExtensionInfo::UnloadedExtensionInfo( | 2860 UnloadedExtensionInfo::UnloadedExtensionInfo( |
| 2752 const Extension* extension, | 2861 const Extension* extension, |
| 2753 Reason reason) | 2862 Reason reason) |
| 2754 : reason(reason), | 2863 : reason(reason), |
| 2755 already_disabled(false), | 2864 already_disabled(false), |
| 2756 extension(extension) {} | 2865 extension(extension) {} |
| OLD | NEW |