[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame^] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 5 | #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
| 6 | #define CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 8 | |
[email protected] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 9 | #include <map> |
[email protected] | facd7a765 | 2009-06-05 23:15:02 | [diff] [blame] | 10 | #include <set> |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 11 | #include <string> |
| 12 | #include <vector> |
| 13 | |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 14 | #include "base/file_path.h" |
[email protected] | 19118d5 | 2010-07-26 22:13:42 | [diff] [blame] | 15 | #include "base/gtest_prod_util.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame^] | 16 | #include "base/memory/ref_counted.h" |
| 17 | #include "base/memory/scoped_ptr.h" |
[email protected] | d83a560 | 2010-09-16 00:22:48 | [diff] [blame] | 18 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 19 | #include "chrome/common/extensions/extension_extent.h" |
[email protected] | 807871f | 2010-09-16 01:04:48 | [diff] [blame] | 20 | #include "chrome/common/extensions/extension_icon_set.h" |
[email protected] | 42b6f0f8 | 2009-09-18 21:07:39 | [diff] [blame] | 21 | #include "chrome/common/extensions/user_script.h" |
[email protected] | 7197f499 | 2009-03-23 05:05:49 | [diff] [blame] | 22 | #include "chrome/common/extensions/url_pattern.h" |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 23 | #include "googleurl/src/gurl.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 24 | #include "ui/gfx/size.h" |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 25 | |
[email protected] | 3bb8499 | 2010-08-26 17:23:46 | [diff] [blame] | 26 | class DictionaryValue; |
[email protected] | 942690b13 | 2010-05-11 06:42:14 | [diff] [blame] | 27 | class ExtensionAction; |
| 28 | class ExtensionResource; |
[email protected] | e2dffe0 | 2011-01-20 20:30:06 | [diff] [blame] | 29 | class ExtensionSidebarDefaults; |
[email protected] | 1280270 | 2010-07-09 19:43:09 | [diff] [blame] | 30 | class SkBitmap; |
[email protected] | daf66aa | 2010-08-06 06:24:28 | [diff] [blame] | 31 | class Version; |
[email protected] | 942690b13 | 2010-05-11 06:42:14 | [diff] [blame] | 32 | |
[email protected] | f075553 | 2010-06-22 07:27:25 | [diff] [blame] | 33 | // Represents a Chrome extension. |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 34 | class Extension : public base::RefCountedThreadSafe<Extension> { |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 35 | public: |
[email protected] | d3cfa48 | 2009-10-17 13:54:57 | [diff] [blame] | 36 | typedef std::map<const std::string, GURL> URLOverrideMap; |
[email protected] | 10fb199 | 2010-10-08 09:00:17 | [diff] [blame] | 37 | typedef std::vector<std::string> ScriptingWhitelist; |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 38 | |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 39 | // What an extension was loaded from. |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 40 | // NOTE: These values are stored as integers in the preferences and used |
| 41 | // in histograms so don't remove or reorder existing items. Just append |
| 42 | // to the end. |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 43 | enum Location { |
| 44 | INVALID, |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 45 | INTERNAL, // A crx file from the internal Extensions directory. |
| 46 | EXTERNAL_PREF, // A crx file from an external directory (via prefs). |
| 47 | EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the |
| 48 | // registry on Windows). |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 49 | LOAD, // --load-extension. |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 50 | COMPONENT, // An integral component of Chrome itself, which |
| 51 | // happens to be implemented as an extension. We don't |
| 52 | // show these in the management UI. |
[email protected] | 4d2913e3 | 2010-11-30 00:28:55 | [diff] [blame] | 53 | EXTERNAL_PREF_DOWNLOAD, // A crx file from an external directory (via |
| 54 | // prefs), installed from an update URL. |
| 55 | EXTERNAL_POLICY_DOWNLOAD, // A crx file from an external directory (via |
| 56 | // admin policies), installed from an update URL. |
[email protected] | 04cb754 | 2010-10-25 10:50:06 | [diff] [blame] | 57 | |
| 58 | NUM_LOCATIONS |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | enum State { |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 62 | DISABLED = 0, |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 63 | ENABLED, |
| 64 | KILLBIT, // Don't install/upgrade (applies to external extensions only). |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 65 | |
| 66 | NUM_STATES |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 67 | }; |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 68 | |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 69 | enum InstallType { |
[email protected] | ab6f2b2 | 2009-07-28 23:28:37 | [diff] [blame] | 70 | INSTALL_ERROR, |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 71 | DOWNGRADE, |
| 72 | REINSTALL, |
| 73 | UPGRADE, |
| 74 | NEW_INSTALL |
| 75 | }; |
| 76 | |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 77 | // NOTE: If you change this list, you should also change kIconSizes in the cc |
| 78 | // file. |
| 79 | enum Icons { |
| 80 | EXTENSION_ICON_LARGE = 128, |
| 81 | EXTENSION_ICON_MEDIUM = 48, |
| 82 | EXTENSION_ICON_SMALL = 32, |
[email protected] | 3938294 | 2010-03-23 15:57:09 | [diff] [blame] | 83 | EXTENSION_ICON_SMALLISH = 24, |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 84 | EXTENSION_ICON_BITTY = 16, |
| 85 | }; |
| 86 | |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 87 | // Do not change the order of entries or remove entries in this list |
| 88 | // as this is used in UMA_HISTOGRAM_ENUMERATIONs about extensions. |
| 89 | enum Type { |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 90 | TYPE_UNKNOWN = 0, |
| 91 | TYPE_EXTENSION, |
| 92 | TYPE_THEME, |
| 93 | TYPE_USER_SCRIPT, |
| 94 | TYPE_HOSTED_APP, |
| 95 | TYPE_PACKAGED_APP |
| 96 | }; |
| 97 | |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 98 | // An NPAPI plugin included in the extension. |
| 99 | struct PluginInfo { |
| 100 | FilePath path; // Path to the plugin. |
| 101 | bool is_public; // False if only this extension can load this plugin. |
| 102 | }; |
| 103 | |
[email protected] | a4a38c1 | 2010-12-23 16:43:56 | [diff] [blame] | 104 | struct TtsVoice { |
| 105 | std::string voice_name; |
| 106 | std::string locale; |
| 107 | std::string gender; |
| 108 | }; |
| 109 | |
[email protected] | 0df165f | 2010-09-28 16:49:40 | [diff] [blame] | 110 | // A permission is defined by its |name| (what is used in the manifest), |
| 111 | // and the |message_id| that's used by install/update UI. |
| 112 | struct Permission { |
| 113 | const char* const name; |
| 114 | const int message_id; |
| 115 | }; |
| 116 | |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 117 | // |strict_error_checks| enables extra error checking, such as |
| 118 | // checks that URL patterns do not contain ports. This error |
| 119 | // checking may find an error that a previous version of |
| 120 | // chrome did not flag. To avoid errors in installed extensions |
| 121 | // when chrome is upgraded, strict error checking is only enabled |
| 122 | // when loading extensions as a developer would (such as loading |
| 123 | // an unpacked extension), or when loading an extension that is |
| 124 | // tied to a specific version of chrome (such as a component |
| 125 | // extension). Most callers will set |strict_error_checks| to |
| 126 | // Extension::ShouldDoStrictErrorChecking(location). |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 127 | static scoped_refptr<Extension> Create(const FilePath& path, |
| 128 | Location location, |
| 129 | const DictionaryValue& value, |
| 130 | bool require_key, |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 131 | bool strict_error_checks, |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 132 | std::string* error); |
| 133 | |
[email protected] | 4d2913e3 | 2010-11-30 00:28:55 | [diff] [blame] | 134 | // Return the update url used by gallery/webstore extensions. |
| 135 | static GURL GalleryUpdateUrl(bool secure); |
| 136 | |
[email protected] | 0df165f | 2010-09-28 16:49:40 | [diff] [blame] | 137 | // The install message id for |permission|. Returns 0 if none exists. |
| 138 | static int GetPermissionMessageId(const std::string& permission); |
| 139 | |
[email protected] | a2a098d | 2010-09-29 19:42:55 | [diff] [blame] | 140 | // Returns the full list of permission messages that this extension |
| 141 | // should display at install time. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 142 | std::vector<string16> GetPermissionMessages() const; |
[email protected] | a2a098d | 2010-09-29 19:42:55 | [diff] [blame] | 143 | |
[email protected] | d6a5c78c | 2010-12-07 05:18:15 | [diff] [blame] | 144 | // Returns the distinct hosts that should be displayed in the install UI |
| 145 | // for the URL patterns |list|. This discards some of the detail that is |
| 146 | // present in the manifest to make it as easy as possible to process by |
| 147 | // users. In particular we disregard the scheme and path components of |
| 148 | // URLPatterns and de-dupe the result, which includes filtering out common |
[email protected] | d7d4a40 | 2011-03-08 18:27:51 | [diff] [blame] | 149 | // hosts with differing RCDs (aka Registry Controlled Domains, most of which |
| 150 | // are Top Level Domains but also include exceptions like co.uk). |
| 151 | // NOTE: when de-duping hosts the preferred RCD will be returned, given this |
| 152 | // order of preference: .com, .net, .org, first in list. |
[email protected] | d6a5c78c | 2010-12-07 05:18:15 | [diff] [blame] | 153 | static std::vector<std::string> GetDistinctHostsForDisplay( |
| 154 | const URLPatternList& list); |
| 155 | |
| 156 | // Compares two URLPatternLists for security equality by returning whether |
| 157 | // the URL patterns in |new_list| contain additional distinct hosts compared |
| 158 | // to |old_list|. |
| 159 | static bool IsElevatedHostList( |
| 160 | const URLPatternList& old_list, const URLPatternList& new_list); |
[email protected] | 0df165f | 2010-09-28 16:49:40 | [diff] [blame] | 161 | |
[email protected] | c3e3def74 | 2009-07-17 07:51:06 | [diff] [blame] | 162 | // Icon sizes used by the extension system. |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 163 | static const int kIconSizes[]; |
[email protected] | c3e3def74 | 2009-07-17 07:51:06 | [diff] [blame] | 164 | |
[email protected] | 4c4f819 | 2009-10-17 01:03:26 | [diff] [blame] | 165 | // Max size (both dimensions) for browser and page actions. |
| 166 | static const int kPageActionIconMaxSize; |
| 167 | static const int kBrowserActionIconMaxSize; |
[email protected] | e2dffe0 | 2011-01-20 20:30:06 | [diff] [blame] | 168 | static const int kSidebarIconMaxSize; |
[email protected] | 4c4f819 | 2009-10-17 01:03:26 | [diff] [blame] | 169 | |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 170 | // Each permission is a module that the extension is permitted to use. |
[email protected] | 218990c | 2010-06-26 01:21:07 | [diff] [blame] | 171 | // |
[email protected] | 0df165f | 2010-09-28 16:49:40 | [diff] [blame] | 172 | // NOTE: To add a new permission, define it here, and add an entry to |
| 173 | // Extension::kPermissions. |
[email protected] | 9dcf8f1 | 2010-09-02 20:39:19 | [diff] [blame] | 174 | static const char kBackgroundPermission[]; |
| 175 | static const char kBookmarkPermission[]; |
[email protected] | 598bbcc | 2011-02-24 10:03:25 | [diff] [blame] | 176 | static const char kContentSettingsPermission[]; |
[email protected] | 9dcf8f1 | 2010-09-02 20:39:19 | [diff] [blame] | 177 | static const char kContextMenusPermission[]; |
| 178 | static const char kCookiePermission[]; |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 179 | static const char kChromeosInfoPrivatePermissions[]; |
[email protected] | 91ba331 | 2011-03-17 20:39:22 | [diff] [blame] | 180 | static const char kDebuggerPermission[]; |
[email protected] | 9dcf8f1 | 2010-09-02 20:39:19 | [diff] [blame] | 181 | static const char kExperimentalPermission[]; |
[email protected] | 55d9bed | 2011-03-25 20:37:59 | [diff] [blame] | 182 | static const char kFileSystemPermission[]; |
| 183 | static const char kFileBrowserPrivatePermission[]; |
[email protected] | 9dcf8f1 | 2010-09-02 20:39:19 | [diff] [blame] | 184 | static const char kGeolocationPermission[]; |
| 185 | static const char kHistoryPermission[]; |
| 186 | static const char kIdlePermission[]; |
[email protected] | eb25577 | 2010-10-04 22:10:46 | [diff] [blame] | 187 | static const char kManagementPermission[]; |
[email protected] | 9dcf8f1 | 2010-09-02 20:39:19 | [diff] [blame] | 188 | static const char kNotificationPermission[]; |
| 189 | static const char kProxyPermission[]; |
| 190 | static const char kTabPermission[]; |
| 191 | static const char kUnlimitedStoragePermission[]; |
[email protected] | 9dcf8f1 | 2010-09-02 20:39:19 | [diff] [blame] | 192 | static const char kWebstorePrivatePermission[]; |
[email protected] | aeb53b3 | 2009-10-29 07:34:45 | [diff] [blame] | 193 | |
[email protected] | 0df165f | 2010-09-28 16:49:40 | [diff] [blame] | 194 | static const Permission kPermissions[]; |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 195 | static const size_t kNumPermissions; |
[email protected] | 9dcf8f1 | 2010-09-02 20:39:19 | [diff] [blame] | 196 | static const char* const kHostedAppPermissionNames[]; |
[email protected] | b746f37 | 2010-08-29 21:39:32 | [diff] [blame] | 197 | static const size_t kNumHostedAppPermissions; |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 198 | |
[email protected] | 03b612f | 2010-08-13 21:09:21 | [diff] [blame] | 199 | // The old name for the unlimited storage permission, which is deprecated but |
| 200 | // still accepted as meaning the same thing as kUnlimitedStoragePermission. |
[email protected] | 9dcf8f1 | 2010-09-02 20:39:19 | [diff] [blame] | 201 | static const char kOldUnlimitedStoragePermission[]; |
[email protected] | 03b612f | 2010-08-13 21:09:21 | [diff] [blame] | 202 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 203 | // Valid schemes for web extent URLPatterns. |
| 204 | static const int kValidWebExtentSchemes; |
| 205 | |
[email protected] | f71f7e6 | 2010-12-07 03:45:33 | [diff] [blame] | 206 | // Valid schemes for host permission URLPatterns. |
| 207 | static const int kValidHostPermissionSchemes; |
| 208 | |
[email protected] | b746f37 | 2010-08-29 21:39:32 | [diff] [blame] | 209 | // Returns true if the string is one of the known hosted app permissions (see |
| 210 | // kHostedAppPermissionNames). |
| 211 | static bool IsHostedAppPermission(const std::string& permission); |
| 212 | |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 213 | // The name of the manifest inside an extension. |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 214 | static const FilePath::CharType kManifestFilename[]; |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 215 | |
[email protected] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 216 | // The name of locale folder inside an extension. |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 217 | static const FilePath::CharType kLocaleFolder[]; |
[email protected] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 218 | |
| 219 | // The name of the messages file inside an extension. |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 220 | static const FilePath::CharType kMessagesFilename[]; |
[email protected] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 221 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 222 | #if defined(OS_WIN) |
[email protected] | 9dcf8f1 | 2010-09-02 20:39:19 | [diff] [blame] | 223 | static const char kExtensionRegistryPath[]; |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 224 | #endif |
| 225 | |
[email protected] | 37eeb5a | 2009-02-26 23:36:17 | [diff] [blame] | 226 | // The number of bytes in a legal id. |
[email protected] | fe0e782 | 2009-02-26 23:51:48 | [diff] [blame] | 227 | static const size_t kIdSize; |
[email protected] | 37eeb5a | 2009-02-26 23:36:17 | [diff] [blame] | 228 | |
[email protected] | e435d6b7 | 2009-07-25 03:15:58 | [diff] [blame] | 229 | // The mimetype used for extensions. |
| 230 | static const char kMimeType[]; |
| 231 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 232 | // Checks to see if the extension has a valid ID. |
| 233 | static bool IdIsValid(const std::string& id); |
| 234 | |
[email protected] | 4ead6f7 | 2010-10-13 19:54:18 | [diff] [blame] | 235 | // Generate an ID for an extension in the given path. |
[email protected] | 28d7479b | 2011-03-09 21:33:27 | [diff] [blame] | 236 | // Used while developing extensions, before they have a key. |
[email protected] | 4ead6f7 | 2010-10-13 19:54:18 | [diff] [blame] | 237 | static std::string GenerateIdForPath(const FilePath& file_name); |
| 238 | |
[email protected] | e435d6b7 | 2009-07-25 03:15:58 | [diff] [blame] | 239 | // Returns true if the specified file is an extension. |
| 240 | static bool IsExtension(const FilePath& file_name); |
| 241 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 242 | // Whether the |location| is external or not. |
| 243 | static inline bool IsExternalLocation(Location location) { |
| 244 | return location == Extension::EXTERNAL_PREF || |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 245 | location == Extension::EXTERNAL_REGISTRY || |
[email protected] | 04cb754 | 2010-10-25 10:50:06 | [diff] [blame] | 246 | location == Extension::EXTERNAL_PREF_DOWNLOAD || |
| 247 | location == Extension::EXTERNAL_POLICY_DOWNLOAD; |
| 248 | } |
| 249 | |
| 250 | // Whether extensions with |location| are auto-updatable or not. |
| 251 | static inline bool IsAutoUpdateableLocation(Location location) { |
| 252 | // Only internal and external extensions can be autoupdated. |
| 253 | return location == Extension::INTERNAL || |
| 254 | IsExternalLocation(location); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 255 | } |
| 256 | |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 257 | // Whether extensions with |location| should be loaded with strict |
| 258 | // error checking. Strict error checks may flag errors older versions |
| 259 | // of chrome did not detect. To avoid breaking installed extensions, |
| 260 | // strict checks are disabled unless the location indicates that the |
| 261 | // developer is loading the extension, or the extension is a component |
| 262 | // of chrome. |
| 263 | static inline bool ShouldDoStrictErrorChecking(Location location) { |
| 264 | return location == Extension::LOAD || |
| 265 | location == Extension::COMPONENT; |
| 266 | } |
| 267 | |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 268 | // See Type definition above. |
| 269 | Type GetType() const; |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 270 | |
[email protected] | 07c00d99 | 2009-03-04 20:27:04 | [diff] [blame] | 271 | // Returns an absolute url to a resource inside of an extension. The |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 272 | // |extension_url| argument should be the url() from an Extension object. The |
| 273 | // |relative_path| can be untrusted user input. The returned URL will either |
| 274 | // be invalid() or a child of |extension_url|. |
| 275 | // NOTE: Static so that it can be used from multiple threads. |
| 276 | static GURL GetResourceURL(const GURL& extension_url, |
| 277 | const std::string& relative_path); |
[email protected] | cffd789 | 2010-08-26 17:43:28 | [diff] [blame] | 278 | GURL GetResourceURL(const std::string& relative_path) const { |
[email protected] | 3cfbd0e | 2009-03-18 21:26:24 | [diff] [blame] | 279 | return GetResourceURL(url(), relative_path); |
| 280 | } |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 281 | |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 282 | // Returns an extension resource object. |relative_path| should be UTF8 |
| 283 | // encoded. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 284 | ExtensionResource GetResource(const std::string& relative_path) const; |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 285 | |
| 286 | // As above, but with |relative_path| following the file system's encoding. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 287 | ExtensionResource GetResource(const FilePath& relative_path) const; |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 288 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 289 | // |input| is expected to be the text of an rsa public or private key. It |
| 290 | // tolerates the presence or absence of bracking header/footer like this: |
| 291 | // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY----- |
| 292 | // and may contain newlines. |
| 293 | static bool ParsePEMKeyBytes(const std::string& input, std::string* output); |
| 294 | |
| 295 | // Does a simple base64 encoding of |input| into |output|. |
| 296 | static bool ProducePEM(const std::string& input, std::string* output); |
| 297 | |
[email protected] | 84ac7f3 | 2009-10-06 06:17:54 | [diff] [blame] | 298 | // Generates an extension ID from arbitrary input. The same input string will |
| 299 | // always generate the same output ID. |
| 300 | static bool GenerateId(const std::string& input, std::string* output); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 301 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 302 | // Expects base64 encoded |input| and formats into |output| including |
| 303 | // the appropriate header & footer. |
| 304 | static bool FormatPEMForFileOutput(const std::string input, |
| 305 | std::string* output, bool is_public); |
| 306 | |
[email protected] | 2a40953 | 2009-08-28 19:39:44 | [diff] [blame] | 307 | // Determine whether |new_extension| has increased privileges compared to |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 308 | // its previously granted permissions, specified by |granted_apis|, |
| 309 | // |granted_extent| and |granted_full_access|. |
| 310 | static bool IsPrivilegeIncrease(const bool granted_full_access, |
| 311 | const std::set<std::string>& granted_apis, |
| 312 | const ExtensionExtent& granted_extent, |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 313 | const Extension* new_extension); |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 314 | |
[email protected] | c690a981 | 2009-12-17 05:55:32 | [diff] [blame] | 315 | // Given an extension and icon size, read it if present and decode it into |
[email protected] | ae2e0f9 | 2010-04-06 20:32:23 | [diff] [blame] | 316 | // result. In the browser process, this will DCHECK if not called on the |
| 317 | // file thread. To easily load extension images on the UI thread, see |
| 318 | // ImageLoadingTracker. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 319 | static void DecodeIcon(const Extension* extension, |
[email protected] | c690a981 | 2009-12-17 05:55:32 | [diff] [blame] | 320 | Icons icon_size, |
| 321 | scoped_ptr<SkBitmap>* result); |
| 322 | |
| 323 | // Given an icon_path and icon size, read it if present and decode it into |
[email protected] | ae2e0f9 | 2010-04-06 20:32:23 | [diff] [blame] | 324 | // result. In the browser process, this will DCHECK if not called on the |
| 325 | // file thread. To easily load extension images on the UI thread, see |
| 326 | // ImageLoadingTracker. |
[email protected] | c690a981 | 2009-12-17 05:55:32 | [diff] [blame] | 327 | static void DecodeIconFromPath(const FilePath& icon_path, |
| 328 | Icons icon_size, |
| 329 | scoped_ptr<SkBitmap>* result); |
| 330 | |
[email protected] | a807bbe | 2010-04-14 10:51:19 | [diff] [blame] | 331 | // Returns the base extension url for a given |extension_id|. |
| 332 | static GURL GetBaseURLFromExtensionId(const std::string& extension_id); |
| 333 | |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 334 | // Returns the url prefix for the extension/apps gallery. Can be set via the |
[email protected] | ce3eb7b6 | 2010-09-14 13:57:44 | [diff] [blame] | 335 | // --apps-gallery-url switch. The URL returned will not contain a trailing |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 336 | // slash. Do not use this as a prefix/extent for the store. Instead see |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 337 | // ExtensionService::GetWebStoreApp or |
| 338 | // ExtensionService::IsDownloadFromGallery |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 339 | static std::string ChromeStoreLaunchURL(); |
[email protected] | a0cf04a | 2010-06-23 03:29:55 | [diff] [blame] | 340 | |
[email protected] | be7e5cb | 2010-10-04 12:53:17 | [diff] [blame] | 341 | // Adds an extension to the scripting whitelist. Used for testing only. |
[email protected] | 10fb199 | 2010-10-08 09:00:17 | [diff] [blame] | 342 | static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); |
[email protected] | 2a521c5 | 2011-01-26 18:45:21 | [diff] [blame] | 343 | static const ScriptingWhitelist* GetScriptingWhitelist(); |
[email protected] | be7e5cb | 2010-10-04 12:53:17 | [diff] [blame] | 344 | |
[email protected] | aeb53b3 | 2009-10-29 07:34:45 | [diff] [blame] | 345 | // Returns true if the extension has the specified API permission. |
[email protected] | 0df165f | 2010-09-28 16:49:40 | [diff] [blame] | 346 | static bool HasApiPermission(const std::set<std::string>& api_permissions, |
[email protected] | 246c05f | 2010-09-10 09:12:11 | [diff] [blame] | 347 | const std::string& function_name); |
[email protected] | 583d45c1 | 2010-08-31 02:48:12 | [diff] [blame] | 348 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 349 | // Whether the |effective_host_permissions| and |api_permissions| include |
| 350 | // effective access to all hosts. See the non-static version of the method |
| 351 | // for more details. |
| 352 | static bool HasEffectiveAccessToAllHosts( |
| 353 | const ExtensionExtent& effective_host_permissions, |
| 354 | const std::set<std::string>& api_permissions); |
| 355 | |
[email protected] | 246c05f | 2010-09-10 09:12:11 | [diff] [blame] | 356 | bool HasApiPermission(const std::string& function_name) const { |
| 357 | return HasApiPermission(this->api_permissions(), function_name); |
[email protected] | aeb53b3 | 2009-10-29 07:34:45 | [diff] [blame] | 358 | } |
| 359 | |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 360 | const ExtensionExtent& GetEffectiveHostPermissions() const { |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 361 | return effective_host_permissions_; |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 362 | } |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 363 | |
[email protected] | fbd17cf | 2010-04-28 23:52:56 | [diff] [blame] | 364 | // Whether or not the extension is allowed permission for a URL pattern from |
| 365 | // the manifest. http, https, and chrome://favicon/ is allowed for all |
| 366 | // extensions, while component extensions are allowed access to |
| 367 | // chrome://resources. |
[email protected] | a3caa82 | 2010-10-26 18:10:00 | [diff] [blame] | 368 | bool CanSpecifyHostPermission(const URLPattern& pattern) const; |
[email protected] | fbd17cf | 2010-04-28 23:52:56 | [diff] [blame] | 369 | |
[email protected] | 584b8e3f | 2010-04-10 00:23:37 | [diff] [blame] | 370 | // Whether the extension has access to the given URL. |
| 371 | bool HasHostPermission(const GURL& url) const; |
| 372 | |
[email protected] | 0df165f | 2010-09-28 16:49:40 | [diff] [blame] | 373 | // Whether the extension has effective access to all hosts. This is true if |
| 374 | // there is a content script that matches all hosts, if there is a host |
| 375 | // permission grants access to all hosts (like <all_urls>) or an api |
| 376 | // permission that effectively grants access to all hosts (e.g. proxy, |
| 377 | // network, etc.) |
| 378 | bool HasEffectiveAccessToAllHosts() const; |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 379 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 380 | // Whether the extension effectively has all permissions (for example, by |
| 381 | // having an NPAPI plugin). |
| 382 | bool HasFullPermissions() const; |
| 383 | |
[email protected] | 5df6a5d | 2011-01-26 07:39:12 | [diff] [blame] | 384 | // Whether context menu should be shown for page and browser actions. |
| 385 | bool ShowConfigureContextMenus() const; |
| 386 | |
[email protected] | 37cd64d | 2010-10-25 18:17:58 | [diff] [blame] | 387 | // Returns the Homepage URL for this extension. If homepage_url was not |
| 388 | // specified in the manifest, this returns the Google Gallery URL. For |
[email protected] | bfa90a3a | 2010-04-28 15:43:23 | [diff] [blame] | 389 | // third-party extensions, this returns a blank GURL. |
[email protected] | 37cd64d | 2010-10-25 18:17:58 | [diff] [blame] | 390 | GURL GetHomepageURL() const; |
[email protected] | bfa90a3a | 2010-04-28 15:43:23 | [diff] [blame] | 391 | |
[email protected] | facd7a765 | 2009-06-05 23:15:02 | [diff] [blame] | 392 | // Returns a list of paths (relative to the extension dir) for images that |
| 393 | // the browser might load (like themes and page action icons). |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 394 | std::set<FilePath> GetBrowserImages() const; |
[email protected] | facd7a765 | 2009-06-05 23:15:02 | [diff] [blame] | 395 | |
[email protected] | 807871f | 2010-09-16 01:04:48 | [diff] [blame] | 396 | // Get an extension icon as a resource or URL. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 397 | ExtensionResource GetIconResource( |
| 398 | int size, ExtensionIconSet::MatchType match_type) const; |
| 399 | GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const; |
[email protected] | f34e7963 | 2010-03-17 02:34:08 | [diff] [blame] | 400 | |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 401 | // Gets the fully resolved absolute launch URL. |
| 402 | GURL GetFullLaunchURL() const; |
[email protected] | 2a521c5 | 2011-01-26 18:45:21 | [diff] [blame] | 403 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 404 | // Image cache related methods. These are only valid on the UI thread and |
| 405 | // not maintained by this class. See ImageLoadingTracker for usage. The |
| 406 | // |original_size| parameter should be the size of the image at |source| |
| 407 | // before any scaling may have been done to produce the pixels in |image|. |
| 408 | void SetCachedImage(const ExtensionResource& source, |
| 409 | const SkBitmap& image, |
| 410 | const gfx::Size& original_size) const; |
| 411 | bool HasCachedImage(const ExtensionResource& source, |
| 412 | const gfx::Size& max_size) const; |
| 413 | SkBitmap GetCachedImage(const ExtensionResource& source, |
| 414 | const gfx::Size& max_size) const; |
[email protected] | 2a521c5 | 2011-01-26 18:45:21 | [diff] [blame] | 415 | |
| 416 | // Returns true if this extension can execute script on a page. If a |
| 417 | // UserScript object is passed, permission to run that specific script is |
| 418 | // checked (using its matches list). Otherwise, permission to execute script |
| 419 | // programmatically is checked (using the extension's host permission). |
| 420 | // |
| 421 | // This method is also aware of certain special pages that extensions are |
| 422 | // usually not allowed to run script on. |
| 423 | bool CanExecuteScriptOnPage(const GURL& page_url, |
| 424 | UserScript* script, |
| 425 | std::string* error) const; |
| 426 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 427 | // Returns true if this extension is a COMPONENT extension, or if it is |
| 428 | // on the whitelist of extensions that can script all pages. |
| 429 | bool CanExecuteScriptEverywhere() const; |
| 430 | |
[email protected] | 5efbfe01 | 2011-02-22 23:07:18 | [diff] [blame] | 431 | // Returns true if this extension is allowed to obtain the contents of a |
| 432 | // page as an image. Since a page may contain sensitive information, this |
| 433 | // is restricted to the extension's host permissions as well as the |
| 434 | // extension page itself. |
| 435 | bool CanCaptureVisiblePage(const GURL& page_url, std::string* error) const; |
| 436 | |
[email protected] | a65882c | 2010-11-12 15:15:09 | [diff] [blame] | 437 | // Returns true if this extension updates itself using the extension |
| 438 | // gallery. |
| 439 | bool UpdatesFromGallery() const; |
| 440 | |
[email protected] | cca14717 | 2011-02-17 01:29:29 | [diff] [blame] | 441 | // Returns true if this extension or app includes areas within |origin|. |
| 442 | bool OverlapsWithOrigin(const GURL& origin) const; |
| 443 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 444 | // Accessors: |
| 445 | |
| 446 | const FilePath& path() const { return path_; } |
| 447 | const GURL& url() const { return extension_url_; } |
| 448 | Location location() const { return location_; } |
| 449 | const std::string& id() const { return id_; } |
| 450 | const Version* version() const { return version_.get(); } |
| 451 | const std::string VersionString() const; |
| 452 | const std::string& name() const { return name_; } |
| 453 | const std::string& public_key() const { return public_key_; } |
| 454 | const std::string& description() const { return description_; } |
| 455 | bool converted_from_user_script() const { |
| 456 | return converted_from_user_script_; |
| 457 | } |
| 458 | const UserScriptList& content_scripts() const { return content_scripts_; } |
| 459 | ExtensionAction* page_action() const { return page_action_.get(); } |
| 460 | ExtensionAction* browser_action() const { return browser_action_.get(); } |
[email protected] | e2dffe0 | 2011-01-20 20:30:06 | [diff] [blame] | 461 | ExtensionSidebarDefaults* sidebar_defaults() const { |
| 462 | return sidebar_defaults_.get(); |
| 463 | } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 464 | const std::vector<PluginInfo>& plugins() const { return plugins_; } |
| 465 | const GURL& background_url() const { return background_url_; } |
| 466 | const GURL& options_url() const { return options_url_; } |
| 467 | const GURL& devtools_url() const { return devtools_url_; } |
| 468 | const std::vector<GURL>& toolstrips() const { return toolstrips_; } |
| 469 | const std::set<std::string>& api_permissions() const { |
| 470 | return api_permissions_; |
| 471 | } |
| 472 | const URLPatternList& host_permissions() const { return host_permissions_; } |
| 473 | const GURL& update_url() const { return update_url_; } |
| 474 | const ExtensionIconSet& icons() const { return icons_; } |
| 475 | const DictionaryValue* manifest_value() const { |
| 476 | return manifest_value_.get(); |
| 477 | } |
| 478 | const std::string default_locale() const { return default_locale_; } |
| 479 | const URLOverrideMap& GetChromeURLOverrides() const { |
| 480 | return chrome_url_overrides_; |
| 481 | } |
| 482 | const std::string omnibox_keyword() const { return omnibox_keyword_; } |
| 483 | bool incognito_split_mode() const { return incognito_split_mode_; } |
[email protected] | a4a38c1 | 2010-12-23 16:43:56 | [diff] [blame] | 484 | const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 485 | |
| 486 | // App-related. |
| 487 | bool is_app() const { return is_app_; } |
| 488 | bool is_hosted_app() const { return is_app() && !web_extent().is_empty(); } |
| 489 | bool is_packaged_app() const { return is_app() && web_extent().is_empty(); } |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 490 | bool is_storage_isolated() const { return is_app() && is_storage_isolated_; } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 491 | const ExtensionExtent& web_extent() const { return extent_; } |
| 492 | const std::string& launch_local_path() const { return launch_local_path_; } |
| 493 | const std::string& launch_web_url() const { return launch_web_url_; } |
| 494 | extension_misc::LaunchContainer launch_container() const { |
| 495 | return launch_container_; |
| 496 | } |
| 497 | int launch_width() const { return launch_width_; } |
| 498 | int launch_height() const { return launch_height_; } |
| 499 | |
| 500 | // Theme-related. |
| 501 | bool is_theme() const { return is_theme_; } |
| 502 | DictionaryValue* GetThemeImages() const { return theme_images_.get(); } |
| 503 | DictionaryValue* GetThemeColors() const {return theme_colors_.get(); } |
| 504 | DictionaryValue* GetThemeTints() const { return theme_tints_.get(); } |
| 505 | DictionaryValue* GetThemeDisplayProperties() const { |
| 506 | return theme_display_properties_.get(); |
| 507 | } |
| 508 | |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 509 | private: |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 510 | friend class base::RefCountedThreadSafe<Extension>; |
| 511 | |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 512 | // We keep a cache of images loaded from extension resources based on their |
| 513 | // path and a string representation of a size that may have been used to |
| 514 | // scale it (or the empty string if the image is at its original size). |
| 515 | typedef std::pair<FilePath, std::string> ImageCacheKey; |
| 516 | typedef std::map<ImageCacheKey, SkBitmap> ImageCache; |
| 517 | |
[email protected] | 4ead6f7 | 2010-10-13 19:54:18 | [diff] [blame] | 518 | // Normalize the path for use by the extension. On Windows, this will make |
| 519 | // sure the drive letter is uppercase. |
| 520 | static FilePath MaybeNormalizePath(const FilePath& path); |
| 521 | |
[email protected] | d6a5c78c | 2010-12-07 05:18:15 | [diff] [blame] | 522 | // Returns the distinct hosts that can be displayed in the install UI or be |
| 523 | // used for privilege comparisons. This discards some of the detail that is |
| 524 | // present in the manifest to make it as easy as possible to process by users. |
| 525 | // In particular we disregard the scheme and path components of URLPatterns |
| 526 | // and de-dupe the result, which includes filtering out common hosts with |
| 527 | // differing RCDs. If |include_rcd| is true, then the de-duped result |
| 528 | // will be the first full entry, including its RCD. So if the list was |
| 529 | // "*.google.co.uk" and "*.google.com", the returned value would just be |
| 530 | // "*.google.co.uk". Keeping the RCD in the result is useful for display |
| 531 | // purposes when you want to show the user one sample hostname from the list. |
| 532 | // If you need to compare two URLPatternLists for security equality, then set |
| 533 | // |include_rcd| to false, which will return a result like "*.google.", |
| 534 | // regardless of the order of the patterns. |
| 535 | static std::vector<std::string> GetDistinctHosts( |
| 536 | const URLPatternList& host_patterns, bool include_rcd); |
| 537 | |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 538 | Extension(const FilePath& path, Location location); |
| 539 | ~Extension(); |
| 540 | |
| 541 | // Initialize the extension from a parsed manifest. |
| 542 | // Usually, the id of an extension is generated by the "key" property of |
| 543 | // its manifest, but if |require_key| is |false|, a temporary ID will be |
| 544 | // generated based on the path. |
| 545 | bool InitFromValue(const DictionaryValue& value, bool require_key, |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 546 | bool strict_error_checks, std::string* error); |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 547 | |
[email protected] | 052c9270 | 2010-06-25 07:25:52 | [diff] [blame] | 548 | // Helper function for implementing HasCachedImage/GetCachedImage. A return |
| 549 | // value of NULL means there is no matching image cached (we allow caching an |
| 550 | // empty SkBitmap). |
| 551 | SkBitmap* GetCachedImageImpl(const ExtensionResource& source, |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 552 | const gfx::Size& max_size) const; |
[email protected] | d9ad80f | 2010-03-30 20:40:18 | [diff] [blame] | 553 | |
[email protected] | 3cfbd0e | 2009-03-18 21:26:24 | [diff] [blame] | 554 | // Helper method that loads a UserScript object from a |
| 555 | // dictionary in the content_script list of the manifest. |
| 556 | bool LoadUserScriptHelper(const DictionaryValue* content_script, |
| 557 | int definition_index, |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 558 | URLPattern::ParseOption parse_strictness, |
[email protected] | 3cfbd0e | 2009-03-18 21:26:24 | [diff] [blame] | 559 | std::string* error, |
| 560 | UserScript* result); |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 561 | |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 562 | // Helper method that loads either the include_globs or exclude_globs list |
| 563 | // from an entry in the content_script lists of the manifest. |
| 564 | bool LoadGlobsHelper(const DictionaryValue* content_script, |
| 565 | int content_script_index, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 566 | const char* globs_property_name, |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 567 | std::string* error, |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 568 | void(UserScript::*add_method)(const std::string& glob), |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 569 | UserScript *instance); |
| 570 | |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 571 | // Helpers to load various chunks of the manifest. |
[email protected] | 3ba0fd3 | 2010-06-19 05:39:10 | [diff] [blame] | 572 | bool LoadIsApp(const DictionaryValue* manifest, std::string* error); |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 573 | bool LoadExtent(const DictionaryValue* manifest, |
| 574 | const char* key, |
| 575 | ExtensionExtent* extent, |
| 576 | const char* list_error, |
| 577 | const char* value_error, |
| 578 | URLPattern::ParseOption parse_strictness, |
| 579 | std::string* error); |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 580 | bool LoadLaunchContainer(const DictionaryValue* manifest, std::string* error); |
| 581 | bool LoadLaunchURL(const DictionaryValue* manifest, std::string* error); |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 582 | bool LoadAppIsolation(const DictionaryValue* manifest, std::string* error); |
[email protected] | cbf4d191 | 2010-08-12 18:24:57 | [diff] [blame] | 583 | bool EnsureNotHybridApp(const DictionaryValue* manifest, std::string* error); |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 584 | |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 585 | // Helper method to load an ExtensionAction from the page_action or |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 586 | // browser_action entries in the manifest. |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 587 | ExtensionAction* LoadExtensionActionHelper( |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 588 | const DictionaryValue* extension_action, std::string* error); |
| 589 | |
[email protected] | e2dffe0 | 2011-01-20 20:30:06 | [diff] [blame] | 590 | // Helper method to load an ExtensionSidebarDefaults from the sidebar manifest |
| 591 | // entry. |
| 592 | ExtensionSidebarDefaults* LoadExtensionSidebarDefaults( |
| 593 | const DictionaryValue* sidebar, std::string* error); |
| 594 | |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 595 | // Calculates the effective host permissions from the permissions and content |
| 596 | // script petterns. |
| 597 | void InitEffectiveHostPermissions(); |
| 598 | |
[email protected] | 2f6698b | 2010-10-14 00:58:21 | [diff] [blame] | 599 | // Returns true if the extension has more than one "UI surface". For example, |
| 600 | // an extension that has a browser action and a page action. |
| 601 | bool HasMultipleUISurfaces() const; |
| 602 | |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 603 | // Figures out if a source contains keys not associated with themes - we |
| 604 | // don't want to allow scripts and such to be bundled with themes. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 605 | bool ContainsNonThemeKeys(const DictionaryValue& source) const; |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 606 | |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 607 | // Returns true if the string is one of the known api permissions (see |
[email protected] | 0df165f | 2010-09-28 16:49:40 | [diff] [blame] | 608 | // kPermissions). |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 609 | bool IsAPIPermission(const std::string& permission) const; |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 610 | |
[email protected] | a2a098d | 2010-09-29 19:42:55 | [diff] [blame] | 611 | // The set of unique API install messages that the extension has. |
| 612 | // NOTE: This only includes messages related to permissions declared in the |
| 613 | // "permissions" key in the manifest. Permissions implied from other features |
| 614 | // of the manifest, like plugins and content scripts are not included. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 615 | std::set<string16> GetSimplePermissionMessages() const; |
[email protected] | a2a098d | 2010-09-29 19:42:55 | [diff] [blame] | 616 | |
| 617 | // The permission message displayed related to the host permissions for |
| 618 | // this extension. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 619 | string16 GetHostPermissionMessage() const; |
[email protected] | a2a098d | 2010-09-29 19:42:55 | [diff] [blame] | 620 | |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 621 | // Cached images for this extension. This should only be touched on the UI |
| 622 | // thread. |
| 623 | mutable ImageCache image_cache_; |
[email protected] | 1e8c93f | 2010-02-08 22:58:31 | [diff] [blame] | 624 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 625 | // A persistent, globally unique ID. An extension's ID is used in things |
| 626 | // like directory structures and URLs, and is expected to not change across |
| 627 | // versions. It is generated as a SHA-256 hash of the extension's public |
| 628 | // key, or as a hash of the path in the case of unpacked extensions. |
| 629 | std::string id_; |
| 630 | |
| 631 | // The extension's human-readable name. Name is used for display purpose. It |
| 632 | // might be wrapped with unicode bidi control characters so that it is |
| 633 | // displayed correctly in RTL context. |
| 634 | // NOTE: Name is UTF-8 and may contain non-ascii characters. |
| 635 | std::string name_; |
| 636 | |
| 637 | // The absolute path to the directory the extension is stored in. |
| 638 | FilePath path_; |
| 639 | |
| 640 | // Default locale for fall back. Can be empty if extension is not localized. |
| 641 | std::string default_locale_; |
| 642 | |
| 643 | // If true, a separate process will be used for the extension in incognito |
| 644 | // mode. |
| 645 | bool incognito_split_mode_; |
| 646 | |
| 647 | // Defines the set of URLs in the extension's web content. |
| 648 | ExtensionExtent extent_; |
| 649 | |
| 650 | // The set of host permissions that the extension effectively has access to, |
| 651 | // which is a merge of host_permissions_ and all of the match patterns in |
| 652 | // any content scripts the extension has. This is used to determine which |
| 653 | // URLs have the ability to load an extension's resources via embedded |
| 654 | // chrome-extension: URLs (see extension_protocols.cc). |
| 655 | ExtensionExtent effective_host_permissions_; |
| 656 | |
| 657 | // The set of module-level APIs this extension can use. |
| 658 | std::set<std::string> api_permissions_; |
| 659 | |
| 660 | // The icons for the extension. |
| 661 | ExtensionIconSet icons_; |
| 662 | |
| 663 | // The base extension url for the extension. |
| 664 | GURL extension_url_; |
| 665 | |
| 666 | // The location the extension was loaded from. |
| 667 | Location location_; |
| 668 | |
| 669 | // The extension's version. |
| 670 | scoped_ptr<Version> version_; |
| 671 | |
| 672 | // An optional longer description of the extension. |
| 673 | std::string description_; |
| 674 | |
| 675 | // True if the extension was generated from a user script. (We show slightly |
| 676 | // different UI if so). |
| 677 | bool converted_from_user_script_; |
| 678 | |
| 679 | // Paths to the content scripts the extension contains. |
| 680 | UserScriptList content_scripts_; |
| 681 | |
| 682 | // The extension's page action, if any. |
| 683 | scoped_ptr<ExtensionAction> page_action_; |
| 684 | |
| 685 | // The extension's browser action, if any. |
| 686 | scoped_ptr<ExtensionAction> browser_action_; |
| 687 | |
[email protected] | e2dffe0 | 2011-01-20 20:30:06 | [diff] [blame] | 688 | // The extension's sidebar, if any. |
| 689 | scoped_ptr<ExtensionSidebarDefaults> sidebar_defaults_; |
| 690 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 691 | // Optional list of NPAPI plugins and associated properties. |
| 692 | std::vector<PluginInfo> plugins_; |
| 693 | |
| 694 | // Optional URL to a master page of which a single instance should be always |
| 695 | // loaded in the background. |
| 696 | GURL background_url_; |
| 697 | |
| 698 | // Optional URL to a page for setting options/preferences. |
| 699 | GURL options_url_; |
| 700 | |
| 701 | // Optional URL to a devtools extension page. |
| 702 | GURL devtools_url_; |
| 703 | |
| 704 | // Optional list of toolstrips and associated properties. |
| 705 | std::vector<GURL> toolstrips_; |
| 706 | |
| 707 | // The public key used to sign the contents of the crx package. |
| 708 | std::string public_key_; |
| 709 | |
| 710 | // A map of resource id's to relative file paths. |
| 711 | scoped_ptr<DictionaryValue> theme_images_; |
| 712 | |
| 713 | // A map of color names to colors. |
| 714 | scoped_ptr<DictionaryValue> theme_colors_; |
| 715 | |
| 716 | // A map of color names to colors. |
| 717 | scoped_ptr<DictionaryValue> theme_tints_; |
| 718 | |
| 719 | // A map of display properties. |
| 720 | scoped_ptr<DictionaryValue> theme_display_properties_; |
| 721 | |
| 722 | // Whether the extension is a theme. |
| 723 | bool is_theme_; |
| 724 | |
| 725 | // The sites this extension has permission to talk to (using XHR, etc). |
| 726 | URLPatternList host_permissions_; |
| 727 | |
| 728 | // The homepage for this extension. Useful if it is not hosted by Google and |
| 729 | // therefore does not have a Gallery URL. |
| 730 | GURL homepage_url_; |
| 731 | |
| 732 | // URL for fetching an update manifest |
| 733 | GURL update_url_; |
| 734 | |
| 735 | // A copy of the manifest that this extension was created from. |
| 736 | scoped_ptr<DictionaryValue> manifest_value_; |
| 737 | |
| 738 | // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs |
| 739 | // which override the handling of those URLs. (see ExtensionOverrideUI). |
| 740 | URLOverrideMap chrome_url_overrides_; |
| 741 | |
| 742 | // Whether this extension uses app features. |
| 743 | bool is_app_; |
| 744 | |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 745 | // Whether this extension requests isolated storage. |
| 746 | bool is_storage_isolated_; |
| 747 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 748 | // The local path inside the extension to use with the launcher. |
| 749 | std::string launch_local_path_; |
| 750 | |
| 751 | // A web url to use with the launcher. Note that this might be relative or |
| 752 | // absolute. If relative, it is relative to web_origin. |
| 753 | std::string launch_web_url_; |
| 754 | |
[email protected] | 4e59568 | 2011-02-09 17:07:02 | [diff] [blame] | 755 | // The window type that an app's manifest specifies to launch into. |
| 756 | // This is not always the window type an app will open into, because |
| 757 | // users can override the way each app launches. See |
| 758 | // ExtensionPrefs::GetLaunchContainer(), which looks at a per-app pref |
| 759 | // to decide what container an app will launch in. |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 760 | extension_misc::LaunchContainer launch_container_; |
| 761 | |
| 762 | // The default size of the container when launching. Only respected for |
| 763 | // containers like panels and windows. |
| 764 | int launch_width_; |
| 765 | int launch_height_; |
| 766 | |
| 767 | // The Omnibox keyword for this extension, or empty if there is none. |
| 768 | std::string omnibox_keyword_; |
| 769 | |
[email protected] | a4a38c1 | 2010-12-23 16:43:56 | [diff] [blame] | 770 | // List of text-to-speech voices that this extension provides, if any. |
| 771 | std::vector<TtsVoice> tts_voices_; |
| 772 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 773 | FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 774 | UpdateExtensionPreservesLocation); |
[email protected] | 19118d5 | 2010-07-26 22:13:42 | [diff] [blame] | 775 | FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper); |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 776 | FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueInvalid); |
| 777 | FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueValid); |
| 778 | FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueValidNameInRTL); |
[email protected] | 19118d5 | 2010-07-26 22:13:42 | [diff] [blame] | 779 | FRIEND_TEST_ALL_PREFIXES(TabStripModelTest, Apps); |
[email protected] | ae7fe71 | 2009-07-02 20:33:58 | [diff] [blame] | 780 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 781 | DISALLOW_COPY_AND_ASSIGN(Extension); |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 782 | }; |
| 783 | |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 784 | typedef std::vector< scoped_refptr<const Extension> > ExtensionList; |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 785 | typedef std::set<std::string> ExtensionIdSet; |
[email protected] | b1748b1d8 | 2009-11-30 20:32:56 | [diff] [blame] | 786 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 787 | // Handy struct to pass core extension info around. |
| 788 | struct ExtensionInfo { |
| 789 | ExtensionInfo(const DictionaryValue* manifest, |
| 790 | const std::string& id, |
| 791 | const FilePath& path, |
[email protected] | 3bb8499 | 2010-08-26 17:23:46 | [diff] [blame] | 792 | Extension::Location location); |
| 793 | ~ExtensionInfo(); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 794 | |
| 795 | scoped_ptr<DictionaryValue> extension_manifest; |
| 796 | std::string extension_id; |
| 797 | FilePath extension_path; |
| 798 | Extension::Location extension_location; |
| 799 | |
| 800 | private: |
| 801 | DISALLOW_COPY_AND_ASSIGN(ExtensionInfo); |
| 802 | }; |
| 803 | |
[email protected] | 21103034 | 2010-09-30 18:41:06 | [diff] [blame] | 804 | // Struct used for the details of the EXTENSION_UNINSTALLED |
| 805 | // notification. |
| 806 | struct UninstalledExtensionInfo { |
| 807 | explicit UninstalledExtensionInfo(const Extension& extension); |
[email protected] | 9b2331d9 | 2010-10-04 23:11:19 | [diff] [blame] | 808 | ~UninstalledExtensionInfo(); |
[email protected] | 21103034 | 2010-09-30 18:41:06 | [diff] [blame] | 809 | |
| 810 | std::string extension_id; |
| 811 | std::set<std::string> extension_api_permissions; |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 812 | Extension::Type extension_type; |
[email protected] | 76c2511 | 2010-10-01 22:37:21 | [diff] [blame] | 813 | GURL update_url; |
[email protected] | 21103034 | 2010-09-30 18:41:06 | [diff] [blame] | 814 | }; |
| 815 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 816 | struct UnloadedExtensionInfo { |
| 817 | enum Reason { |
| 818 | DISABLE, // The extension is being disabled. |
| 819 | UPDATE, // The extension is being updated to a newer version. |
| 820 | UNINSTALL, // The extension is being uninstalled. |
| 821 | }; |
| 822 | |
| 823 | Reason reason; |
| 824 | |
| 825 | // Was the extension already disabled? |
| 826 | bool already_disabled; |
| 827 | |
| 828 | // The extension being unloaded - this should always be non-NULL. |
| 829 | const Extension* extension; |
| 830 | |
| 831 | UnloadedExtensionInfo(const Extension* extension, Reason reason); |
| 832 | }; |
| 833 | |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 834 | #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |