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