[email protected] | eb75f7b | 2012-01-04 09:07:28 | [diff] [blame] | 1 | // Copyright (c) 2012 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] | 8629c54 | 2012-04-20 03:40:03 | [diff] [blame] | 9 | #include <algorithm> |
[email protected] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 10 | #include <map> |
[email protected] | facd7a765 | 2009-06-05 23:15:02 | [diff] [blame] | 11 | #include <set> |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 12 | #include <string> |
[email protected] | 58f62cf | 2012-03-09 10:45:11 | [diff] [blame] | 13 | #include <utility> |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 16 | #include "base/file_path.h" |
[email protected] | 19118d5 | 2010-07-26 22:13:42 | [diff] [blame] | 17 | #include "base/gtest_prod_util.h" |
[email protected] | 8f270be | 2011-12-21 21:15:22 | [diff] [blame] | 18 | #include "base/hash_tables.h" |
[email protected] | b6b805e9 | 2011-04-16 09:24:14 | [diff] [blame] | 19 | #include "base/memory/linked_ptr.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 20 | #include "base/memory/ref_counted.h" |
| 21 | #include "base/memory/scoped_ptr.h" |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 22 | #include "base/synchronization/lock.h" |
[email protected] | d83a560 | 2010-09-16 00:22:48 | [diff] [blame] | 23 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 807871f | 2010-09-16 01:04:48 | [diff] [blame] | 24 | #include "chrome/common/extensions/extension_icon_set.h" |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 25 | #include "chrome/common/extensions/extension_permission_set.h" |
[email protected] | 42b6f0f8 | 2009-09-18 21:07:39 | [diff] [blame] | 26 | #include "chrome/common/extensions/user_script.h" |
[email protected] | 7197f499 | 2009-03-23 05:05:49 | [diff] [blame] | 27 | #include "chrome/common/extensions/url_pattern.h" |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 28 | #include "chrome/common/extensions/url_pattern_set.h" |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 29 | #include "googleurl/src/gurl.h" |
[email protected] | f553247 | 2012-02-23 13:00:55 | [diff] [blame] | 30 | #include "ui/base/accelerators/accelerator.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 31 | #include "ui/gfx/size.h" |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 32 | |
[email protected] | 942690b13 | 2010-05-11 06:42:14 | [diff] [blame] | 33 | class ExtensionAction; |
| 34 | class ExtensionResource; |
[email protected] | b6b805e9 | 2011-04-16 09:24:14 | [diff] [blame] | 35 | class FileBrowserHandler; |
[email protected] | 1280270 | 2010-07-09 19:43:09 | [diff] [blame] | 36 | class SkBitmap; |
[email protected] | daf66aa | 2010-08-06 06:24:28 | [diff] [blame] | 37 | class Version; |
[email protected] | 942690b13 | 2010-05-11 06:42:14 | [diff] [blame] | 38 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 39 | namespace base { |
| 40 | class DictionaryValue; |
| 41 | class ListValue; |
| 42 | } |
| 43 | |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 44 | namespace extensions { |
| 45 | class Manifest; |
| 46 | } |
| 47 | |
[email protected] | f0cc724 | 2011-12-13 04:26:17 | [diff] [blame] | 48 | namespace webkit_glue { |
| 49 | struct WebIntentServiceData; |
| 50 | } |
| 51 | |
[email protected] | f075553 | 2010-06-22 07:27:25 | [diff] [blame] | 52 | // Represents a Chrome extension. |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 53 | class Extension : public base::RefCountedThreadSafe<Extension> { |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 54 | public: |
[email protected] | d3cfa48 | 2009-10-17 13:54:57 | [diff] [blame] | 55 | typedef std::map<const std::string, GURL> URLOverrideMap; |
[email protected] | 10fb199 | 2010-10-08 09:00:17 | [diff] [blame] | 56 | typedef std::vector<std::string> ScriptingWhitelist; |
[email protected] | b6b805e9 | 2011-04-16 09:24:14 | [diff] [blame] | 57 | typedef std::vector<linked_ptr<FileBrowserHandler> > FileBrowserHandlerList; |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 58 | |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 59 | // What an extension was loaded from. |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 60 | // NOTE: These values are stored as integers in the preferences and used |
| 61 | // in histograms so don't remove or reorder existing items. Just append |
| 62 | // to the end. |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 63 | enum Location { |
| 64 | INVALID, |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 65 | INTERNAL, // A crx file from the internal Extensions directory. |
| 66 | EXTERNAL_PREF, // A crx file from an external directory (via prefs). |
| 67 | EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the |
| 68 | // registry on Windows). |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 69 | LOAD, // --load-extension. |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 70 | COMPONENT, // An integral component of Chrome itself, which |
| 71 | // happens to be implemented as an extension. We don't |
| 72 | // show these in the management UI. |
[email protected] | 4d2913e3 | 2010-11-30 00:28:55 | [diff] [blame] | 73 | EXTERNAL_PREF_DOWNLOAD, // A crx file from an external directory (via |
| 74 | // prefs), installed from an update URL. |
| 75 | EXTERNAL_POLICY_DOWNLOAD, // A crx file from an external directory (via |
| 76 | // admin policies), installed from an update URL. |
[email protected] | 04cb754 | 2010-10-25 10:50:06 | [diff] [blame] | 77 | |
| 78 | NUM_LOCATIONS |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | enum State { |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 82 | DISABLED = 0, |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 83 | ENABLED, |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 84 | // An external extension that the user uninstalled. We should not reinstall |
| 85 | // such extensions on startup. |
| 86 | EXTERNAL_EXTENSION_UNINSTALLED, |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 87 | NUM_STATES |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 88 | }; |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 89 | |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 90 | // Used to record the reason an extension was disabled. |
| 91 | enum DisableReason { |
| 92 | DISABLE_UNKNOWN, |
| 93 | DISABLE_USER_ACTION, |
| 94 | DISABLE_PERMISSIONS_INCREASE, |
| 95 | DISABLE_RELOAD, |
| 96 | DISABLE_LAST, // Not used. |
| 97 | }; |
| 98 | |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 99 | enum InstallType { |
[email protected] | ab6f2b2 | 2009-07-28 23:28:37 | [diff] [blame] | 100 | INSTALL_ERROR, |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 101 | DOWNGRADE, |
| 102 | REINSTALL, |
| 103 | UPGRADE, |
| 104 | NEW_INSTALL |
| 105 | }; |
| 106 | |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 107 | // Do not change the order of entries or remove entries in this list |
| 108 | // as this is used in UMA_HISTOGRAM_ENUMERATIONs about extensions. |
| 109 | enum Type { |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 110 | TYPE_UNKNOWN = 0, |
| 111 | TYPE_EXTENSION, |
| 112 | TYPE_THEME, |
| 113 | TYPE_USER_SCRIPT, |
| 114 | TYPE_HOSTED_APP, |
[email protected] | 7d3ed2f | 2011-11-07 23:33:19 | [diff] [blame] | 115 | TYPE_PACKAGED_APP, |
| 116 | TYPE_PLATFORM_APP |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 117 | }; |
| 118 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 119 | enum SyncType { |
| 120 | SYNC_TYPE_NONE = 0, |
| 121 | SYNC_TYPE_EXTENSION, |
| 122 | SYNC_TYPE_APP |
| 123 | }; |
| 124 | |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 125 | // An NPAPI plugin included in the extension. |
| 126 | struct PluginInfo { |
| 127 | FilePath path; // Path to the plugin. |
| 128 | bool is_public; // False if only this extension can load this plugin. |
| 129 | }; |
| 130 | |
[email protected] | 65378f5 | 2011-04-08 02:31:23 | [diff] [blame] | 131 | // An NaCl module included in the extension. |
| 132 | struct NaClModuleInfo { |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 133 | GURL url; |
[email protected] | 65378f5 | 2011-04-08 02:31:23 | [diff] [blame] | 134 | std::string mime_type; |
| 135 | }; |
| 136 | |
[email protected] | b082037 | 2011-06-03 07:05:27 | [diff] [blame] | 137 | enum InputComponentType { |
[email protected] | d45f751 | 2011-06-21 21:18:27 | [diff] [blame] | 138 | INPUT_COMPONENT_TYPE_NONE = -1, |
| 139 | INPUT_COMPONENT_TYPE_IME, |
[email protected] | b082037 | 2011-06-03 07:05:27 | [diff] [blame] | 140 | INPUT_COMPONENT_TYPE_VIRTUAL_KEYBOARD, |
| 141 | INPUT_COMPONENT_TYPE_COUNT |
| 142 | }; |
| 143 | |
| 144 | struct InputComponentInfo { |
| 145 | // Define out of line constructor/destructor to please Clang. |
| 146 | InputComponentInfo(); |
| 147 | ~InputComponentInfo(); |
| 148 | |
| 149 | std::string name; |
| 150 | InputComponentType type; |
| 151 | std::string id; |
| 152 | std::string description; |
| 153 | std::string language; |
| 154 | std::set<std::string> layouts; |
| 155 | std::string shortcut_keycode; |
| 156 | bool shortcut_alt; |
| 157 | bool shortcut_ctrl; |
| 158 | bool shortcut_shift; |
| 159 | }; |
| 160 | |
[email protected] | f553247 | 2012-02-23 13:00:55 | [diff] [blame] | 161 | class ExtensionKeybinding { |
| 162 | public: |
| 163 | // Define out of line constructor/destructor to please Clang. |
| 164 | ExtensionKeybinding(); |
| 165 | ~ExtensionKeybinding(); |
| 166 | |
| 167 | // Parse the key binding. |
| 168 | bool Parse(base::DictionaryValue* command, |
| 169 | const std::string& command_name, |
| 170 | int index, |
| 171 | string16* error); |
| 172 | |
| 173 | // Accessors: |
| 174 | const std::string& command_name() const { return command_name_; } |
| 175 | const ui::Accelerator& accelerator() const { return accelerator_; } |
| 176 | const std::string& description() const { return description_; } |
| 177 | |
| 178 | private: |
[email protected] | 9c8b54d | 2012-04-02 10:17:30 | [diff] [blame] | 179 | ui::Accelerator ParseImpl(const std::string& shortcut, |
| 180 | const std::string& platform_key, |
| 181 | int index, |
| 182 | string16* error); |
[email protected] | f553247 | 2012-02-23 13:00:55 | [diff] [blame] | 183 | std::string command_name_; |
| 184 | ui::Accelerator accelerator_; |
| 185 | std::string description_; |
| 186 | }; |
| 187 | |
[email protected] | 9c8b54d | 2012-04-02 10:17:30 | [diff] [blame] | 188 | typedef std::map<std::string, ExtensionKeybinding> CommandMap; |
| 189 | |
[email protected] | a4a38c1 | 2010-12-23 16:43:56 | [diff] [blame] | 190 | struct TtsVoice { |
[email protected] | 77a3ecac | 2011-07-07 05:56:33 | [diff] [blame] | 191 | // Define out of line constructor/destructor to please Clang. |
| 192 | TtsVoice(); |
| 193 | ~TtsVoice(); |
| 194 | |
[email protected] | a4a38c1 | 2010-12-23 16:43:56 | [diff] [blame] | 195 | std::string voice_name; |
[email protected] | c63f2b7 | 2011-07-07 05:25:00 | [diff] [blame] | 196 | std::string lang; |
[email protected] | a4a38c1 | 2010-12-23 16:43:56 | [diff] [blame] | 197 | std::string gender; |
[email protected] | c63f2b7 | 2011-07-07 05:25:00 | [diff] [blame] | 198 | std::set<std::string> event_types; |
[email protected] | a4a38c1 | 2010-12-23 16:43:56 | [diff] [blame] | 199 | }; |
| 200 | |
[email protected] | a79be1f | 2012-03-23 22:14:00 | [diff] [blame] | 201 | // OAuth2 info included in the extension. |
| 202 | struct OAuth2Info { |
| 203 | OAuth2Info(); |
| 204 | ~OAuth2Info(); |
| 205 | |
[email protected] | b6f3862 | 2012-04-25 03:20:19 | [diff] [blame] | 206 | ExtensionOAuth2Scopes GetScopesAsSet(); |
| 207 | |
[email protected] | a79be1f | 2012-03-23 22:14:00 | [diff] [blame] | 208 | std::string client_id; |
| 209 | std::vector<std::string> scopes; |
| 210 | }; |
| 211 | |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 212 | enum InitFromValueFlags { |
| 213 | NO_FLAGS = 0, |
| 214 | |
| 215 | // Usually, the id of an extension is generated by the "key" property of |
| 216 | // its manifest, but if |REQUIRE_KEY| is not set, a temporary ID will be |
| 217 | // generated based on the path. |
| 218 | REQUIRE_KEY = 1 << 0, |
| 219 | |
[email protected] | 3f53dfe | 2011-11-30 01:18:29 | [diff] [blame] | 220 | // Requires the extension to have an up-to-date manifest version. |
| 221 | // Typically, we'll support multiple manifest versions during a version |
| 222 | // transition. This flag signals that we want to require the most modern |
| 223 | // manifest version that Chrome understands. |
| 224 | REQUIRE_MODERN_MANIFEST_VERSION = 1 << 1, |
| 225 | |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 226 | // |STRICT_ERROR_CHECKS| enables extra error checking, such as |
| 227 | // checks that URL patterns do not contain ports. This error |
| 228 | // checking may find an error that a previous version of |
| 229 | // Chrome did not flag. To avoid errors in installed extensions |
| 230 | // when Chrome is upgraded, strict error checking is only enabled |
| 231 | // when loading extensions as a developer would (such as loading |
| 232 | // an unpacked extension), or when loading an extension that is |
| 233 | // tied to a specific version of Chrome (such as a component |
| 234 | // extension). Most callers will set the |STRICT_ERROR_CHECKS| bit when |
| 235 | // Extension::ShouldDoStrictErrorChecking(location) returns true. |
[email protected] | 3f53dfe | 2011-11-30 01:18:29 | [diff] [blame] | 236 | STRICT_ERROR_CHECKS = 1 << 2, |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 237 | |
| 238 | // |ALLOW_FILE_ACCESS| indicates that the user is allowing this extension |
| 239 | // to have file access. If it's not present, then permissions and content |
| 240 | // scripts that match file:/// URLs will be filtered out. |
[email protected] | 3f53dfe | 2011-11-30 01:18:29 | [diff] [blame] | 241 | ALLOW_FILE_ACCESS = 1 << 3, |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 242 | |
| 243 | // |FROM_WEBSTORE| indicates that the extension was installed from the |
| 244 | // Chrome Web Store. |
[email protected] | 3f53dfe | 2011-11-30 01:18:29 | [diff] [blame] | 245 | FROM_WEBSTORE = 1 << 4, |
[email protected] | e805baf | 2011-07-26 18:23:05 | [diff] [blame] | 246 | |
| 247 | // |FROM_BOOKMARK| indicates the extension was created using a mock App |
| 248 | // created from a bookmark. |
[email protected] | 3f53dfe | 2011-11-30 01:18:29 | [diff] [blame] | 249 | FROM_BOOKMARK = 1 << 5, |
[email protected] | 3d41d43 | 2012-04-20 20:47:58 | [diff] [blame] | 250 | |
| 251 | // |FOLLOW_SYMLINKS_ANYWHERE| means that resources can be symlinks to |
| 252 | // anywhere in the filesystem, rather than being restricted to the |
| 253 | // extension directory. |
| 254 | FOLLOW_SYMLINKS_ANYWHERE = 1 << 6, |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 255 | }; |
| 256 | |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 257 | static scoped_refptr<Extension> Create(const FilePath& path, |
| 258 | Location location, |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 259 | const base::DictionaryValue& value, |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 260 | int flags, |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 261 | std::string* error); |
| 262 | |
[email protected] | 87c655e | 2011-07-01 21:42:00 | [diff] [blame] | 263 | // In a few special circumstances, we want to create an Extension and give it |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 264 | // an explicit id. Most consumers should just use the other Create() method. |
| 265 | static scoped_refptr<Extension> Create(const FilePath& path, |
[email protected] | 58f62cf | 2012-03-09 10:45:11 | [diff] [blame] | 266 | Location location, |
| 267 | const base::DictionaryValue& value, |
| 268 | int flags, |
| 269 | const std::string& explicit_id, |
| 270 | std::string* error); |
[email protected] | 87c655e | 2011-07-01 21:42:00 | [diff] [blame] | 271 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 272 | // Given two install sources, return the one which should take priority |
| 273 | // over the other. If an extension is installed from two sources A and B, |
| 274 | // its install source should be set to GetHigherPriorityLocation(A, B). |
| 275 | static Location GetHigherPriorityLocation(Location loc1, Location loc2); |
| 276 | |
[email protected] | 4c4f819 | 2009-10-17 01:03:26 | [diff] [blame] | 277 | // Max size (both dimensions) for browser and page actions. |
| 278 | static const int kPageActionIconMaxSize; |
| 279 | static const int kBrowserActionIconMaxSize; |
| 280 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 281 | // Valid schemes for web extent URLPatterns. |
| 282 | static const int kValidWebExtentSchemes; |
| 283 | |
[email protected] | f71f7e6 | 2010-12-07 03:45:33 | [diff] [blame] | 284 | // Valid schemes for host permission URLPatterns. |
| 285 | static const int kValidHostPermissionSchemes; |
| 286 | |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 287 | // The name of the manifest inside an extension. |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 288 | static const FilePath::CharType kManifestFilename[]; |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 289 | |
[email protected] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 290 | // The name of locale folder inside an extension. |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 291 | static const FilePath::CharType kLocaleFolder[]; |
[email protected] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 292 | |
| 293 | // The name of the messages file inside an extension. |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 294 | static const FilePath::CharType kMessagesFilename[]; |
[email protected] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 295 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 296 | #if defined(OS_WIN) |
[email protected] | 9dcf8f1 | 2010-09-02 20:39:19 | [diff] [blame] | 297 | static const char kExtensionRegistryPath[]; |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 298 | #endif |
| 299 | |
[email protected] | 37eeb5a | 2009-02-26 23:36:17 | [diff] [blame] | 300 | // The number of bytes in a legal id. |
[email protected] | fe0e782 | 2009-02-26 23:51:48 | [diff] [blame] | 301 | static const size_t kIdSize; |
[email protected] | 37eeb5a | 2009-02-26 23:36:17 | [diff] [blame] | 302 | |
[email protected] | e435d6b7 | 2009-07-25 03:15:58 | [diff] [blame] | 303 | // The mimetype used for extensions. |
| 304 | static const char kMimeType[]; |
| 305 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 306 | // Checks to see if the extension has a valid ID. |
| 307 | static bool IdIsValid(const std::string& id); |
| 308 | |
[email protected] | 4ead6f7 | 2010-10-13 19:54:18 | [diff] [blame] | 309 | // Generate an ID for an extension in the given path. |
[email protected] | 28d7479b | 2011-03-09 21:33:27 | [diff] [blame] | 310 | // Used while developing extensions, before they have a key. |
[email protected] | 4ead6f7 | 2010-10-13 19:54:18 | [diff] [blame] | 311 | static std::string GenerateIdForPath(const FilePath& file_name); |
| 312 | |
[email protected] | e435d6b7 | 2009-07-25 03:15:58 | [diff] [blame] | 313 | // Returns true if the specified file is an extension. |
| 314 | static bool IsExtension(const FilePath& file_name); |
| 315 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 316 | // Whether the |location| is external or not. |
| 317 | static inline bool IsExternalLocation(Location location) { |
| 318 | return location == Extension::EXTERNAL_PREF || |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 319 | location == Extension::EXTERNAL_REGISTRY || |
[email protected] | 04cb754 | 2010-10-25 10:50:06 | [diff] [blame] | 320 | location == Extension::EXTERNAL_PREF_DOWNLOAD || |
| 321 | location == Extension::EXTERNAL_POLICY_DOWNLOAD; |
| 322 | } |
| 323 | |
| 324 | // Whether extensions with |location| are auto-updatable or not. |
| 325 | static inline bool IsAutoUpdateableLocation(Location location) { |
| 326 | // Only internal and external extensions can be autoupdated. |
| 327 | return location == Extension::INTERNAL || |
| 328 | IsExternalLocation(location); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 329 | } |
| 330 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 331 | // Whether extensions with |location| can be uninstalled or not. Policy |
| 332 | // controlled extensions are silently auto-installed and updated, and cannot |
| 333 | // be disabled by the user. The same applies for internal components. |
| 334 | static inline bool UserMayDisable(Location location) { |
| 335 | return location != Extension::EXTERNAL_POLICY_DOWNLOAD && |
| 336 | location != Extension::COMPONENT; |
| 337 | } |
| 338 | |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 339 | // Whether extensions with |location| should be loaded with strict |
| 340 | // error checking. Strict error checks may flag errors older versions |
| 341 | // of chrome did not detect. To avoid breaking installed extensions, |
| 342 | // strict checks are disabled unless the location indicates that the |
| 343 | // developer is loading the extension, or the extension is a component |
| 344 | // of chrome. |
| 345 | static inline bool ShouldDoStrictErrorChecking(Location location) { |
| 346 | return location == Extension::LOAD || |
| 347 | location == Extension::COMPONENT; |
| 348 | } |
| 349 | |
[email protected] | cdfca970 | 2011-08-08 16:07:01 | [diff] [blame] | 350 | // Unpacked extensions start off with file access since they are a developer |
| 351 | // feature. |
| 352 | static inline bool ShouldAlwaysAllowFileAccess(Location location) { |
| 353 | return location == Extension::LOAD; |
| 354 | } |
| 355 | |
[email protected] | fc6b061 | 2012-03-29 13:40:06 | [diff] [blame] | 356 | // Fills the |info| dictionary with basic information about the extension. |
| 357 | // |enabled| is injected for easier testing. |
| 358 | void GetBasicInfo(bool enabled, base::DictionaryValue* info) const; |
| 359 | |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 360 | // See Type definition above. |
| 361 | Type GetType() const; |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 362 | |
[email protected] | 07c00d99 | 2009-03-04 20:27:04 | [diff] [blame] | 363 | // Returns an absolute url to a resource inside of an extension. The |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 364 | // |extension_url| argument should be the url() from an Extension object. The |
| 365 | // |relative_path| can be untrusted user input. The returned URL will either |
| 366 | // be invalid() or a child of |extension_url|. |
| 367 | // NOTE: Static so that it can be used from multiple threads. |
| 368 | static GURL GetResourceURL(const GURL& extension_url, |
| 369 | const std::string& relative_path); |
[email protected] | cffd789 | 2010-08-26 17:43:28 | [diff] [blame] | 370 | GURL GetResourceURL(const std::string& relative_path) const { |
[email protected] | 3cfbd0e | 2009-03-18 21:26:24 | [diff] [blame] | 371 | return GetResourceURL(url(), relative_path); |
| 372 | } |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 373 | |
[email protected] | 8f270be | 2011-12-21 21:15:22 | [diff] [blame] | 374 | // Returns true if the specified resource is web accessible. |
| 375 | bool IsResourceWebAccessible(const std::string& relative_path) const; |
| 376 | |
| 377 | // Returns true when 'web_accessible_resources' are defined for the extension. |
| 378 | bool HasWebAccessibleResources() const; |
| 379 | |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 380 | // Returns an extension resource object. |relative_path| should be UTF8 |
| 381 | // encoded. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 382 | ExtensionResource GetResource(const std::string& relative_path) const; |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 383 | |
| 384 | // As above, but with |relative_path| following the file system's encoding. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 385 | ExtensionResource GetResource(const FilePath& relative_path) const; |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 386 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 387 | // |input| is expected to be the text of an rsa public or private key. It |
| 388 | // tolerates the presence or absence of bracking header/footer like this: |
| 389 | // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY----- |
| 390 | // and may contain newlines. |
| 391 | static bool ParsePEMKeyBytes(const std::string& input, std::string* output); |
| 392 | |
| 393 | // Does a simple base64 encoding of |input| into |output|. |
| 394 | static bool ProducePEM(const std::string& input, std::string* output); |
| 395 | |
[email protected] | 84ac7f3 | 2009-10-06 06:17:54 | [diff] [blame] | 396 | // Generates an extension ID from arbitrary input. The same input string will |
| 397 | // always generate the same output ID. |
[email protected] | af9db5f | 2011-10-05 05:13:15 | [diff] [blame] | 398 | static bool GenerateId(const std::string& input, |
| 399 | std::string* output) WARN_UNUSED_RESULT; |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 400 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 401 | // Expects base64 encoded |input| and formats into |output| including |
| 402 | // the appropriate header & footer. |
[email protected] | e0d0819 | 2011-03-29 19:02:50 | [diff] [blame] | 403 | static bool FormatPEMForFileOutput(const std::string& input, |
| 404 | std::string* output, |
| 405 | bool is_public); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 406 | |
[email protected] | 58f62cf | 2012-03-09 10:45:11 | [diff] [blame] | 407 | // Given an extension, icon size, and match type, read a valid icon if present |
[email protected] | e3c0bc2 | 2012-02-24 01:34:15 | [diff] [blame] | 408 | // and decode it into result. In the browser process, this will DCHECK if not |
| 409 | // called on the file thread. To easily load extension images on the UI |
| 410 | // thread, see ImageLoadingTracker. |
| 411 | static void DecodeIcon(const Extension* extension, |
| 412 | ExtensionIconSet::Icons icon_size, |
| 413 | ExtensionIconSet::MatchType match_type, |
| 414 | scoped_ptr<SkBitmap>* result); |
| 415 | |
[email protected] | c690a981 | 2009-12-17 05:55:32 | [diff] [blame] | 416 | // 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] | 417 | // result. In the browser process, this will DCHECK if not called on the |
| 418 | // file thread. To easily load extension images on the UI thread, see |
| 419 | // ImageLoadingTracker. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 420 | static void DecodeIcon(const Extension* extension, |
[email protected] | e3c0bc2 | 2012-02-24 01:34:15 | [diff] [blame] | 421 | ExtensionIconSet::Icons icon_size, |
[email protected] | c690a981 | 2009-12-17 05:55:32 | [diff] [blame] | 422 | scoped_ptr<SkBitmap>* result); |
| 423 | |
| 424 | // 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] | 425 | // result. In the browser process, this will DCHECK if not called on the |
| 426 | // file thread. To easily load extension images on the UI thread, see |
| 427 | // ImageLoadingTracker. |
[email protected] | c690a981 | 2009-12-17 05:55:32 | [diff] [blame] | 428 | static void DecodeIconFromPath(const FilePath& icon_path, |
[email protected] | e3c0bc2 | 2012-02-24 01:34:15 | [diff] [blame] | 429 | ExtensionIconSet::Icons icon_size, |
[email protected] | c690a981 | 2009-12-17 05:55:32 | [diff] [blame] | 430 | scoped_ptr<SkBitmap>* result); |
| 431 | |
[email protected] | 5349ac6d | 2011-04-05 22:20:17 | [diff] [blame] | 432 | // Returns the default extension/app icon (for extensions or apps that don't |
| 433 | // have one). |
| 434 | static const SkBitmap& GetDefaultIcon(bool is_app); |
| 435 | |
[email protected] | a807bbe | 2010-04-14 10:51:19 | [diff] [blame] | 436 | // Returns the base extension url for a given |extension_id|. |
| 437 | static GURL GetBaseURLFromExtensionId(const std::string& extension_id); |
| 438 | |
[email protected] | be7e5cb | 2010-10-04 12:53:17 | [diff] [blame] | 439 | // Adds an extension to the scripting whitelist. Used for testing only. |
[email protected] | 10fb199 | 2010-10-08 09:00:17 | [diff] [blame] | 440 | static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); |
[email protected] | 2a521c5 | 2011-01-26 18:45:21 | [diff] [blame] | 441 | static const ScriptingWhitelist* GetScriptingWhitelist(); |
[email protected] | be7e5cb | 2010-10-04 12:53:17 | [diff] [blame] | 442 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 443 | // Parses the host and api permissions from the specified permission |key| |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 444 | // from |manifest_|. |
| 445 | bool ParsePermissions(const char* key, |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 446 | string16* error, |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 447 | ExtensionAPIPermissionSet* api_permissions, |
| 448 | URLPatternSet* host_permissions); |
| 449 | |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 450 | bool HasAPIPermission(ExtensionAPIPermission::ID permission) const; |
| 451 | bool HasAPIPermission(const std::string& function_name) const; |
[email protected] | 583d45c1 | 2010-08-31 02:48:12 | [diff] [blame] | 452 | |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 453 | const URLPatternSet& GetEffectiveHostPermissions() const; |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 454 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 455 | // Returns true if the extension can silently increase its permission level. |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 456 | // Users must approve permissions for unpacked and packed extensions in the |
| 457 | // following situations: |
| 458 | // - when installing or upgrading packed extensions |
| 459 | // - when installing unpacked extensions that have NPAPI plugins |
| 460 | // - when either type of extension requests optional permissions |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 461 | bool CanSilentlyIncreasePermissions() const; |
| 462 | |
[email protected] | 584b8e3f | 2010-04-10 00:23:37 | [diff] [blame] | 463 | // Whether the extension has access to the given URL. |
| 464 | bool HasHostPermission(const GURL& url) const; |
| 465 | |
[email protected] | 0df165f | 2010-09-28 16:49:40 | [diff] [blame] | 466 | // Whether the extension has effective access to all hosts. This is true if |
| 467 | // there is a content script that matches all hosts, if there is a host |
| 468 | // permission grants access to all hosts (like <all_urls>) or an api |
| 469 | // permission that effectively grants access to all hosts (e.g. proxy, |
| 470 | // network, etc.) |
| 471 | bool HasEffectiveAccessToAllHosts() const; |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 472 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 473 | // Whether the extension effectively has all permissions (for example, by |
| 474 | // having an NPAPI plugin). |
| 475 | bool HasFullPermissions() const; |
| 476 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 477 | // Returns the full list of permission messages that this extension |
| 478 | // should display at install time. |
| 479 | ExtensionPermissionMessages GetPermissionMessages() const; |
| 480 | |
| 481 | // Returns the full list of permission messages that this extension |
| 482 | // should display at install time. The messages are returned as strings |
| 483 | // for convenience. |
| 484 | std::vector<string16> GetPermissionMessageStrings() const; |
| 485 | |
| 486 | // Sets the active |permissions|. |
| 487 | void SetActivePermissions(const ExtensionPermissionSet* permissions) const; |
| 488 | |
| 489 | // Gets the extension's active permission set. |
| 490 | scoped_refptr<const ExtensionPermissionSet> GetActivePermissions() const; |
| 491 | |
[email protected] | 5df6a5d | 2011-01-26 07:39:12 | [diff] [blame] | 492 | // Whether context menu should be shown for page and browser actions. |
| 493 | bool ShowConfigureContextMenus() const; |
| 494 | |
[email protected] | 37cd64d | 2010-10-25 18:17:58 | [diff] [blame] | 495 | // Returns the Homepage URL for this extension. If homepage_url was not |
| 496 | // specified in the manifest, this returns the Google Gallery URL. For |
[email protected] | bfa90a3a | 2010-04-28 15:43:23 | [diff] [blame] | 497 | // third-party extensions, this returns a blank GURL. |
[email protected] | 37cd64d | 2010-10-25 18:17:58 | [diff] [blame] | 498 | GURL GetHomepageURL() const; |
[email protected] | bfa90a3a | 2010-04-28 15:43:23 | [diff] [blame] | 499 | |
[email protected] | facd7a765 | 2009-06-05 23:15:02 | [diff] [blame] | 500 | // Returns a list of paths (relative to the extension dir) for images that |
| 501 | // the browser might load (like themes and page action icons). |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 502 | std::set<FilePath> GetBrowserImages() const; |
[email protected] | facd7a765 | 2009-06-05 23:15:02 | [diff] [blame] | 503 | |
[email protected] | 807871f | 2010-09-16 01:04:48 | [diff] [blame] | 504 | // Get an extension icon as a resource or URL. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 505 | ExtensionResource GetIconResource( |
| 506 | int size, ExtensionIconSet::MatchType match_type) const; |
| 507 | GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const; |
[email protected] | f34e7963 | 2010-03-17 02:34:08 | [diff] [blame] | 508 | |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 509 | // Gets the fully resolved absolute launch URL. |
| 510 | GURL GetFullLaunchURL() const; |
[email protected] | 2a521c5 | 2011-01-26 18:45:21 | [diff] [blame] | 511 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 512 | // Image cache related methods. These are only valid on the UI thread and |
| 513 | // not maintained by this class. See ImageLoadingTracker for usage. The |
| 514 | // |original_size| parameter should be the size of the image at |source| |
| 515 | // before any scaling may have been done to produce the pixels in |image|. |
| 516 | void SetCachedImage(const ExtensionResource& source, |
| 517 | const SkBitmap& image, |
| 518 | const gfx::Size& original_size) const; |
| 519 | bool HasCachedImage(const ExtensionResource& source, |
| 520 | const gfx::Size& max_size) const; |
| 521 | SkBitmap GetCachedImage(const ExtensionResource& source, |
| 522 | const gfx::Size& max_size) const; |
[email protected] | 2a521c5 | 2011-01-26 18:45:21 | [diff] [blame] | 523 | |
| 524 | // Returns true if this extension can execute script on a page. If a |
| 525 | // UserScript object is passed, permission to run that specific script is |
| 526 | // checked (using its matches list). Otherwise, permission to execute script |
| 527 | // programmatically is checked (using the extension's host permission). |
| 528 | // |
| 529 | // This method is also aware of certain special pages that extensions are |
| 530 | // usually not allowed to run script on. |
| 531 | bool CanExecuteScriptOnPage(const GURL& page_url, |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 532 | const UserScript* script, |
[email protected] | 2a521c5 | 2011-01-26 18:45:21 | [diff] [blame] | 533 | std::string* error) const; |
| 534 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 535 | // Returns true if this extension is a COMPONENT extension, or if it is |
| 536 | // on the whitelist of extensions that can script all pages. |
| 537 | bool CanExecuteScriptEverywhere() const; |
| 538 | |
[email protected] | 5efbfe01 | 2011-02-22 23:07:18 | [diff] [blame] | 539 | // Returns true if this extension is allowed to obtain the contents of a |
| 540 | // page as an image. Since a page may contain sensitive information, this |
| 541 | // is restricted to the extension's host permissions as well as the |
| 542 | // extension page itself. |
| 543 | bool CanCaptureVisiblePage(const GURL& page_url, std::string* error) const; |
| 544 | |
[email protected] | a65882c | 2010-11-12 15:15:09 | [diff] [blame] | 545 | // Returns true if this extension updates itself using the extension |
| 546 | // gallery. |
| 547 | bool UpdatesFromGallery() const; |
| 548 | |
[email protected] | cca14717 | 2011-02-17 01:29:29 | [diff] [blame] | 549 | // Returns true if this extension or app includes areas within |origin|. |
| 550 | bool OverlapsWithOrigin(const GURL& origin) const; |
| 551 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 552 | // Returns the sync bucket to use for this extension. |
| 553 | SyncType GetSyncType() const; |
| 554 | |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 555 | // Returns true if the extension should be synced. |
| 556 | bool IsSyncable() const; |
| 557 | |
| 558 | // Returns true if the extension should be displayed in the launcher. |
| 559 | bool ShouldDisplayInLauncher() const; |
| 560 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 561 | // Accessors: |
| 562 | |
| 563 | const FilePath& path() const { return path_; } |
| 564 | const GURL& url() const { return extension_url_; } |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 565 | Location location() const; |
| 566 | const std::string& id() const; |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 567 | const Version* version() const { return version_.get(); } |
| 568 | const std::string VersionString() const; |
| 569 | const std::string& name() const { return name_; } |
[email protected] | 715ffe4 | 2012-04-17 05:13:45 | [diff] [blame] | 570 | const std::string& non_localized_name() const { return non_localized_name_; } |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 571 | const std::string public_key() const { return public_key_; } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 572 | const std::string& description() const { return description_; } |
[email protected] | a47c8a2 | 2011-11-17 18:40:31 | [diff] [blame] | 573 | int manifest_version() const { return manifest_version_; } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 574 | bool converted_from_user_script() const { |
| 575 | return converted_from_user_script_; |
| 576 | } |
| 577 | const UserScriptList& content_scripts() const { return content_scripts_; } |
| 578 | ExtensionAction* page_action() const { return page_action_.get(); } |
| 579 | ExtensionAction* browser_action() const { return browser_action_.get(); } |
[email protected] | b6b805e9 | 2011-04-16 09:24:14 | [diff] [blame] | 580 | const FileBrowserHandlerList* file_browser_handlers() const { |
| 581 | return file_browser_handlers_.get(); |
| 582 | } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 583 | const std::vector<PluginInfo>& plugins() const { return plugins_; } |
[email protected] | 65378f5 | 2011-04-08 02:31:23 | [diff] [blame] | 584 | const std::vector<NaClModuleInfo>& nacl_modules() const { |
| 585 | return nacl_modules_; |
| 586 | } |
[email protected] | b082037 | 2011-06-03 07:05:27 | [diff] [blame] | 587 | const std::vector<InputComponentInfo>& input_components() const { |
| 588 | return input_components_; |
| 589 | } |
[email protected] | 9c8b54d | 2012-04-02 10:17:30 | [diff] [blame] | 590 | const ExtensionKeybinding* browser_action_command() const { |
| 591 | return browser_action_command_.get(); |
| 592 | } |
| 593 | const ExtensionKeybinding* page_action_command() const { |
| 594 | return page_action_command_.get(); |
| 595 | } |
| 596 | const CommandMap& named_commands() const { |
| 597 | return named_commands_; |
[email protected] | f553247 | 2012-02-23 13:00:55 | [diff] [blame] | 598 | } |
[email protected] | a03d4448f | 2012-01-10 23:25:28 | [diff] [blame] | 599 | bool has_background_page() const { |
| 600 | return background_url_.is_valid() || !background_scripts_.empty(); |
| 601 | } |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 602 | bool allow_background_js_access() const { |
| 603 | return allow_background_js_access_; |
| 604 | } |
[email protected] | a03d4448f | 2012-01-10 23:25:28 | [diff] [blame] | 605 | const std::vector<std::string>& background_scripts() const { |
| 606 | return background_scripts_; |
| 607 | } |
[email protected] | d2aa06b | 2012-03-21 20:57:26 | [diff] [blame] | 608 | bool has_persistent_background_page() const { |
[email protected] | dd62fa80 | 2012-04-25 18:37:00 | [diff] [blame^] | 609 | return has_background_page() && background_page_is_persistent_; |
[email protected] | d2aa06b | 2012-03-21 20:57:26 | [diff] [blame] | 610 | } |
| 611 | bool has_lazy_background_page() const { |
[email protected] | dd62fa80 | 2012-04-25 18:37:00 | [diff] [blame^] | 612 | return has_background_page() && !background_page_is_persistent_; |
[email protected] | d2aa06b | 2012-03-21 20:57:26 | [diff] [blame] | 613 | } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 614 | const GURL& options_url() const { return options_url_; } |
| 615 | const GURL& devtools_url() const { return devtools_url_; } |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 616 | const ExtensionPermissionSet* optional_permission_set() const { |
| 617 | return optional_permission_set_.get(); |
| 618 | } |
| 619 | const ExtensionPermissionSet* required_permission_set() const { |
| 620 | return required_permission_set_.get(); |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 621 | } |
[email protected] | 8629c54 | 2012-04-20 03:40:03 | [diff] [blame] | 622 | const std::vector<std::string>& install_warnings() const { |
| 623 | return install_warnings_; |
| 624 | } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 625 | const GURL& update_url() const { return update_url_; } |
| 626 | const ExtensionIconSet& icons() const { return icons_; } |
[email protected] | 953620b | 2011-12-04 00:55:32 | [diff] [blame] | 627 | const extensions::Manifest* manifest() const { |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 628 | return manifest_; |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 629 | } |
| 630 | const std::string default_locale() const { return default_locale_; } |
| 631 | const URLOverrideMap& GetChromeURLOverrides() const { |
| 632 | return chrome_url_overrides_; |
| 633 | } |
| 634 | const std::string omnibox_keyword() const { return omnibox_keyword_; } |
| 635 | bool incognito_split_mode() const { return incognito_split_mode_; } |
[email protected] | 1abdf4f | 2011-08-16 21:11:55 | [diff] [blame] | 636 | bool offline_enabled() const { return offline_enabled_; } |
[email protected] | a4a38c1 | 2010-12-23 16:43:56 | [diff] [blame] | 637 | const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; } |
[email protected] | a79be1f | 2012-03-23 22:14:00 | [diff] [blame] | 638 | const OAuth2Info& oauth2_info() const { return oauth2_info_; } |
[email protected] | 5662442 | 2011-11-01 22:11:27 | [diff] [blame] | 639 | const std::vector<webkit_glue::WebIntentServiceData>& |
| 640 | intents_services() const { |
| 641 | return intents_services_; |
| 642 | } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 643 | |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 644 | bool wants_file_access() const { return wants_file_access_; } |
[email protected] | 2af352b | 2011-07-22 08:21:23 | [diff] [blame] | 645 | int creation_flags() const { return creation_flags_; } |
| 646 | bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; } |
[email protected] | e805baf | 2011-07-26 18:23:05 | [diff] [blame] | 647 | bool from_bookmark() const { return (creation_flags_ & FROM_BOOKMARK) != 0; } |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 648 | |
[email protected] | 7f7b9d93 | 2011-04-20 16:13:26 | [diff] [blame] | 649 | const std::string& content_security_policy() const { |
| 650 | return content_security_policy_; |
| 651 | } |
| 652 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 653 | // App-related. |
[email protected] | 953620b | 2011-12-04 00:55:32 | [diff] [blame] | 654 | bool is_app() const { |
| 655 | return is_packaged_app() || is_hosted_app() || is_platform_app(); |
[email protected] | 2369087 | 2011-12-01 22:02:39 | [diff] [blame] | 656 | } |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 657 | bool is_platform_app() const; |
| 658 | bool is_hosted_app() const; |
| 659 | bool is_packaged_app() const; |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 660 | bool is_storage_isolated() const { return is_app() && is_storage_isolated_; } |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 661 | const URLPatternSet& web_extent() const { return extent_; } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 662 | const std::string& launch_local_path() const { return launch_local_path_; } |
| 663 | const std::string& launch_web_url() const { return launch_web_url_; } |
| 664 | extension_misc::LaunchContainer launch_container() const { |
| 665 | return launch_container_; |
| 666 | } |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 667 | int launch_width() const { return launch_width_; } |
| 668 | int launch_height() const { return launch_height_; } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 669 | |
| 670 | // Theme-related. |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 671 | bool is_theme() const; |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 672 | base::DictionaryValue* GetThemeImages() const { return theme_images_.get(); } |
| 673 | base::DictionaryValue* GetThemeColors() const {return theme_colors_.get(); } |
| 674 | base::DictionaryValue* GetThemeTints() const { return theme_tints_.get(); } |
| 675 | base::DictionaryValue* GetThemeDisplayProperties() const { |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 676 | return theme_display_properties_.get(); |
| 677 | } |
| 678 | |
[email protected] | a03d4448f | 2012-01-10 23:25:28 | [diff] [blame] | 679 | GURL GetBackgroundURL() const; |
| 680 | |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 681 | private: |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 682 | friend class base::RefCountedThreadSafe<Extension>; |
| 683 | |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 684 | // We keep a cache of images loaded from extension resources based on their |
| 685 | // path and a string representation of a size that may have been used to |
| 686 | // scale it (or the empty string if the image is at its original size). |
| 687 | typedef std::pair<FilePath, std::string> ImageCacheKey; |
| 688 | typedef std::map<ImageCacheKey, SkBitmap> ImageCache; |
| 689 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 690 | class RuntimeData { |
| 691 | public: |
| 692 | RuntimeData(); |
| 693 | explicit RuntimeData(const ExtensionPermissionSet* active); |
| 694 | ~RuntimeData(); |
| 695 | |
| 696 | void SetActivePermissions(const ExtensionPermissionSet* active); |
| 697 | scoped_refptr<const ExtensionPermissionSet> GetActivePermissions() const; |
| 698 | |
| 699 | private: |
| 700 | friend class base::RefCountedThreadSafe<RuntimeData>; |
| 701 | scoped_refptr<const ExtensionPermissionSet> active_permissions_; |
| 702 | }; |
| 703 | |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 704 | // Chooses the extension ID for an extension based on a variety of criteria. |
| 705 | // The chosen ID will be set in |manifest|. |
| 706 | static bool InitExtensionID(extensions::Manifest* manifest, |
| 707 | const FilePath& path, |
| 708 | const std::string& explicit_id, |
| 709 | int creation_flags, |
| 710 | string16* error); |
| 711 | |
[email protected] | 4ead6f7 | 2010-10-13 19:54:18 | [diff] [blame] | 712 | // Normalize the path for use by the extension. On Windows, this will make |
| 713 | // sure the drive letter is uppercase. |
| 714 | static FilePath MaybeNormalizePath(const FilePath& path); |
| 715 | |
[email protected] | 87c655e | 2011-07-01 21:42:00 | [diff] [blame] | 716 | // Returns true if this extension id is from a trusted provider. |
| 717 | static bool IsTrustedId(const std::string& id); |
| 718 | |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 719 | Extension(const FilePath& path, scoped_ptr<extensions::Manifest> manifest); |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 720 | ~Extension(); |
| 721 | |
| 722 | // Initialize the extension from a parsed manifest. |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 723 | // TODO(aa): Rename to just Init()? There's no Value here anymore. |
| 724 | // TODO(aa): It is really weird the way this class essentially contains a copy |
| 725 | // of the underlying DictionaryValue in its members. We should decide to |
| 726 | // either wrap the DictionaryValue and go with that only, or we should parse |
| 727 | // into strong types and discard the value. But doing both is bad. |
| 728 | bool InitFromValue(int flags, string16* error); |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 729 | |
[email protected] | 58f62cf | 2012-03-09 10:45:11 | [diff] [blame] | 730 | // The following are helpers for InitFromValue to load various features of the |
| 731 | // extension from the manifest. |
| 732 | |
| 733 | bool CheckMinimumChromeVersion(string16* error); |
| 734 | bool LoadAppIsolation(string16* error); |
| 735 | |
| 736 | bool LoadRequiredFeatures(string16* error); |
| 737 | bool LoadName(string16* error); |
| 738 | bool LoadVersion(string16* error); |
| 739 | |
| 740 | bool LoadAppFeatures(string16* error); |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 741 | bool LoadExtent(const char* key, |
| 742 | URLPatternSet* extent, |
| 743 | const char* list_error, |
| 744 | const char* value_error, |
| 745 | string16* error); |
| 746 | bool LoadLaunchContainer(string16* error); |
| 747 | bool LoadLaunchURL(string16* error); |
[email protected] | 10253da | 2012-03-09 04:06:42 | [diff] [blame] | 748 | |
[email protected] | 58f62cf | 2012-03-09 10:45:11 | [diff] [blame] | 749 | bool LoadSharedFeatures(const ExtensionAPIPermissionSet& api_permissions, |
| 750 | string16* error); |
| 751 | bool LoadDescription(string16* error); |
| 752 | bool LoadManifestVersion(string16* error); |
| 753 | bool LoadHomepageURL(string16* error); |
| 754 | bool LoadUpdateURL(string16* error); |
| 755 | bool LoadIcons(string16* error); |
| 756 | bool LoadCommands(string16* error); |
| 757 | bool LoadPlugins(string16* error); |
| 758 | bool LoadNaClModules(string16* error); |
| 759 | bool LoadWebAccessibleResources(string16* error); |
| 760 | bool CheckRequirements(string16* error); |
| 761 | bool LoadDefaultLocale(string16* error); |
| 762 | bool LoadOfflineEnabled(string16* error); |
| 763 | bool LoadOptionsPage(string16* error); |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 764 | bool LoadBackgroundScripts(string16* error); |
| 765 | bool LoadBackgroundPage(const ExtensionAPIPermissionSet& api_permissions, |
| 766 | string16* error); |
[email protected] | dd62fa80 | 2012-04-25 18:37:00 | [diff] [blame^] | 767 | bool LoadBackgroundPersistent( |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 768 | const ExtensionAPIPermissionSet& api_permissions, |
| 769 | string16* error); |
[email protected] | 58f62cf | 2012-03-09 10:45:11 | [diff] [blame] | 770 | bool LoadBackgroundAllowJSAccess( |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 771 | const ExtensionAPIPermissionSet& api_permissions, |
| 772 | string16* error); |
[email protected] | 58f62cf | 2012-03-09 10:45:11 | [diff] [blame] | 773 | // Parses a single action in the manifest. |
| 774 | bool LoadWebIntentAction(const std::string& action_name, |
| 775 | const base::DictionaryValue& intent_service, |
| 776 | string16* error); |
| 777 | bool LoadWebIntentServices(string16* error); |
| 778 | bool LoadExtensionFeatures(const ExtensionAPIPermissionSet& api_permissions, |
| 779 | string16* error); |
| 780 | bool LoadDevToolsPage(string16* error); |
| 781 | bool LoadInputComponents(const ExtensionAPIPermissionSet& api_permissions, |
| 782 | string16* error); |
| 783 | bool LoadContentScripts(string16* error); |
| 784 | bool LoadPageAction(string16* error); |
| 785 | bool LoadBrowserAction(string16* error); |
| 786 | bool LoadFileBrowserHandlers(string16* error); |
| 787 | // Helper method to load a FileBrowserHandlerList from the manifest. |
| 788 | FileBrowserHandlerList* LoadFileBrowserHandlersHelper( |
| 789 | const base::ListValue* extension_actions, string16* error); |
| 790 | // Helper method to load an FileBrowserHandler from manifest. |
| 791 | FileBrowserHandler* LoadFileBrowserHandler( |
| 792 | const base::DictionaryValue* file_browser_handlers, string16* error); |
| 793 | bool LoadChromeURLOverrides(string16* error); |
| 794 | bool LoadOmnibox(string16* error); |
| 795 | bool LoadTextToSpeechVoices(string16* error); |
| 796 | bool LoadIncognitoMode(string16* error); |
| 797 | bool LoadContentSecurityPolicy(string16* error); |
| 798 | |
| 799 | bool LoadThemeFeatures(string16* error); |
| 800 | bool LoadThemeImages(const base::DictionaryValue* theme_value, |
| 801 | string16* error); |
| 802 | bool LoadThemeColors(const base::DictionaryValue* theme_value, |
| 803 | string16* error); |
| 804 | bool LoadThemeTints(const base::DictionaryValue* theme_value, |
| 805 | string16* error); |
| 806 | bool LoadThemeDisplayProperties(const base::DictionaryValue* theme_value, |
| 807 | string16* error); |
| 808 | |
| 809 | // Helper function for implementing HasCachedImage/GetCachedImage. A return |
| 810 | // value of NULL means there is no matching image cached (we allow caching an |
| 811 | // empty SkBitmap). |
| 812 | SkBitmap* GetCachedImageImpl(const ExtensionResource& source, |
| 813 | const gfx::Size& max_size) const; |
[email protected] | d9ad80f | 2010-03-30 20:40:18 | [diff] [blame] | 814 | |
[email protected] | 3cfbd0e | 2009-03-18 21:26:24 | [diff] [blame] | 815 | // Helper method that loads a UserScript object from a |
| 816 | // dictionary in the content_script list of the manifest. |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 817 | bool LoadUserScriptHelper(const base::DictionaryValue* content_script, |
[email protected] | 3cfbd0e | 2009-03-18 21:26:24 | [diff] [blame] | 818 | int definition_index, |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 819 | string16* error, |
[email protected] | 3cfbd0e | 2009-03-18 21:26:24 | [diff] [blame] | 820 | UserScript* result); |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 821 | |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 822 | // Helper method that loads either the include_globs or exclude_globs list |
| 823 | // from an entry in the content_script lists of the manifest. |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 824 | bool LoadGlobsHelper(const base::DictionaryValue* content_script, |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 825 | int content_script_index, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 826 | const char* globs_property_name, |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 827 | string16* error, |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 828 | void(UserScript::*add_method)(const std::string& glob), |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 829 | UserScript *instance); |
| 830 | |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 831 | // Helper method to load an ExtensionAction from the page_action or |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 832 | // browser_action entries in the manifest. |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 833 | ExtensionAction* LoadExtensionActionHelper( |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 834 | const base::DictionaryValue* extension_action, string16* error); |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 835 | |
[email protected] | a79be1f | 2012-03-23 22:14:00 | [diff] [blame] | 836 | // Helper method that loads the OAuth2 info from the 'oauth2' manifest key. |
| 837 | bool LoadOAuth2Info(string16* error); |
| 838 | |
[email protected] | 2f6698b | 2010-10-14 00:58:21 | [diff] [blame] | 839 | // Returns true if the extension has more than one "UI surface". For example, |
| 840 | // an extension that has a browser action and a page action. |
| 841 | bool HasMultipleUISurfaces() const; |
| 842 | |
[email protected] | be9d9c8 | 2011-07-13 04:17:31 | [diff] [blame] | 843 | // Updates the launch URL and extents for the extension using the given |
| 844 | // |override_url|. |
| 845 | void OverrideLaunchUrl(const GURL& override_url); |
| 846 | |
[email protected] | ae655e4e | 2012-03-16 21:47:55 | [diff] [blame] | 847 | // Custom checks for the experimental permission that can't be expressed in |
| 848 | // _permission_features.json. |
[email protected] | 5eddc3e | 2011-10-26 04:33:31 | [diff] [blame] | 849 | bool CanSpecifyExperimentalPermission() const; |
[email protected] | 5eddc3e | 2011-10-26 04:33:31 | [diff] [blame] | 850 | |
| 851 | // Checks whether the host |pattern| is allowed for this extension, given API |
| 852 | // permissions |permissions|. |
| 853 | bool CanSpecifyHostPermission(const URLPattern& pattern, |
| 854 | const ExtensionAPIPermissionSet& permissions) const; |
| 855 | |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 856 | // Cached images for this extension. This should only be touched on the UI |
| 857 | // thread. |
| 858 | mutable ImageCache image_cache_; |
[email protected] | 1e8c93f | 2010-02-08 22:58:31 | [diff] [blame] | 859 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 860 | // The extension's human-readable name. Name is used for display purpose. It |
| 861 | // might be wrapped with unicode bidi control characters so that it is |
| 862 | // displayed correctly in RTL context. |
| 863 | // NOTE: Name is UTF-8 and may contain non-ascii characters. |
| 864 | std::string name_; |
| 865 | |
[email protected] | 715ffe4 | 2012-04-17 05:13:45 | [diff] [blame] | 866 | // A non-localized version of the extension's name. This is useful for |
| 867 | // debug output. |
| 868 | std::string non_localized_name_; |
| 869 | |
[email protected] | a47c8a2 | 2011-11-17 18:40:31 | [diff] [blame] | 870 | // The version of this extension's manifest. We increase the manifest |
| 871 | // version when making breaking changes to the extension system. |
| 872 | // Version 1 was the first manifest version (implied by a lack of a |
| 873 | // manifest_version attribute in the extension's manifest). We initialize |
| 874 | // this member variable to 0 to distinguish the "uninitialized" case from |
| 875 | // the case when we know the manifest version actually is 1. |
| 876 | int manifest_version_; |
| 877 | |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 878 | // The absolute path to the directory the extension is stored in. |
| 879 | FilePath path_; |
| 880 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 881 | // Default locale for fall back. Can be empty if extension is not localized. |
| 882 | std::string default_locale_; |
| 883 | |
| 884 | // If true, a separate process will be used for the extension in incognito |
| 885 | // mode. |
| 886 | bool incognito_split_mode_; |
| 887 | |
[email protected] | 1abdf4f | 2011-08-16 21:11:55 | [diff] [blame] | 888 | // Whether the extension or app should be enabled when offline. |
| 889 | bool offline_enabled_; |
| 890 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 891 | // Defines the set of URLs in the extension's web content. |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 892 | URLPatternSet extent_; |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 893 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 894 | // The extension runtime data. |
| 895 | mutable base::Lock runtime_data_lock_; |
| 896 | mutable RuntimeData runtime_data_; |
| 897 | |
| 898 | // The set of permissions the extension can request at runtime. |
| 899 | scoped_refptr<const ExtensionPermissionSet> optional_permission_set_; |
| 900 | |
| 901 | // The extension's required / default set of permissions. |
| 902 | scoped_refptr<const ExtensionPermissionSet> required_permission_set_; |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 903 | |
[email protected] | 8629c54 | 2012-04-20 03:40:03 | [diff] [blame] | 904 | // Any warnings that occurred when trying to create/parse the extension. |
| 905 | std::vector<std::string> install_warnings_; |
| 906 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 907 | // The icons for the extension. |
| 908 | ExtensionIconSet icons_; |
| 909 | |
| 910 | // The base extension url for the extension. |
| 911 | GURL extension_url_; |
| 912 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 913 | // The extension's version. |
| 914 | scoped_ptr<Version> version_; |
| 915 | |
| 916 | // An optional longer description of the extension. |
| 917 | std::string description_; |
| 918 | |
| 919 | // True if the extension was generated from a user script. (We show slightly |
| 920 | // different UI if so). |
| 921 | bool converted_from_user_script_; |
| 922 | |
| 923 | // Paths to the content scripts the extension contains. |
| 924 | UserScriptList content_scripts_; |
| 925 | |
| 926 | // The extension's page action, if any. |
| 927 | scoped_ptr<ExtensionAction> page_action_; |
| 928 | |
| 929 | // The extension's browser action, if any. |
| 930 | scoped_ptr<ExtensionAction> browser_action_; |
| 931 | |
[email protected] | b6b805e9 | 2011-04-16 09:24:14 | [diff] [blame] | 932 | // The extension's file browser actions, if any. |
| 933 | scoped_ptr<FileBrowserHandlerList> file_browser_handlers_; |
| 934 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 935 | // Optional list of NPAPI plugins and associated properties. |
| 936 | std::vector<PluginInfo> plugins_; |
| 937 | |
[email protected] | 65378f5 | 2011-04-08 02:31:23 | [diff] [blame] | 938 | // Optional list of NaCl modules and associated properties. |
| 939 | std::vector<NaClModuleInfo> nacl_modules_; |
| 940 | |
[email protected] | b082037 | 2011-06-03 07:05:27 | [diff] [blame] | 941 | // Optional list of input components and associated properties. |
| 942 | std::vector<InputComponentInfo> input_components_; |
| 943 | |
[email protected] | f553247 | 2012-02-23 13:00:55 | [diff] [blame] | 944 | // Optional list of commands (keyboard shortcuts). |
[email protected] | 9c8b54d | 2012-04-02 10:17:30 | [diff] [blame] | 945 | scoped_ptr<ExtensionKeybinding> browser_action_command_; |
| 946 | scoped_ptr<ExtensionKeybinding> page_action_command_; |
| 947 | CommandMap named_commands_; |
[email protected] | f553247 | 2012-02-23 13:00:55 | [diff] [blame] | 948 | |
[email protected] | 8f270be | 2011-12-21 21:15:22 | [diff] [blame] | 949 | // Optional list of web accessible extension resources. |
| 950 | base::hash_set<std::string> web_accessible_resources_; |
| 951 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 952 | // Optional URL to a master page of which a single instance should be always |
| 953 | // loaded in the background. |
| 954 | GURL background_url_; |
| 955 | |
[email protected] | a03d4448f | 2012-01-10 23:25:28 | [diff] [blame] | 956 | // Optional list of scripts to use to generate a background page. If this is |
| 957 | // present, background_url_ will be empty and generated by GetBackgroundURL(). |
| 958 | std::vector<std::string> background_scripts_; |
| 959 | |
[email protected] | dd62fa80 | 2012-04-25 18:37:00 | [diff] [blame^] | 960 | // True if the background page should stay loaded forever; false if it should |
| 961 | // load on-demand (when it needs to handle an event). Defaults to true. |
| 962 | bool background_page_is_persistent_; |
[email protected] | 9e6720a | 2012-01-24 02:30:56 | [diff] [blame] | 963 | |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 964 | // True if the background page can be scripted by pages of the app or |
| 965 | // extension, in which case all such pages must run in the same process. |
| 966 | // False if such pages are not permitted to script the background page, |
| 967 | // allowing them to run in different processes. |
| 968 | bool allow_background_js_access_; |
| 969 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 970 | // Optional URL to a page for setting options/preferences. |
| 971 | GURL options_url_; |
| 972 | |
| 973 | // Optional URL to a devtools extension page. |
| 974 | GURL devtools_url_; |
| 975 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 976 | // The public key used to sign the contents of the crx package. |
| 977 | std::string public_key_; |
| 978 | |
| 979 | // A map of resource id's to relative file paths. |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 980 | scoped_ptr<base::DictionaryValue> theme_images_; |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 981 | |
| 982 | // A map of color names to colors. |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 983 | scoped_ptr<base::DictionaryValue> theme_colors_; |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 984 | |
| 985 | // A map of color names to colors. |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 986 | scoped_ptr<base::DictionaryValue> theme_tints_; |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 987 | |
| 988 | // A map of display properties. |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 989 | scoped_ptr<base::DictionaryValue> theme_display_properties_; |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 990 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 991 | // The homepage for this extension. Useful if it is not hosted by Google and |
| 992 | // therefore does not have a Gallery URL. |
| 993 | GURL homepage_url_; |
| 994 | |
| 995 | // URL for fetching an update manifest |
| 996 | GURL update_url_; |
| 997 | |
[email protected] | 58f62cf | 2012-03-09 10:45:11 | [diff] [blame] | 998 | // The manifest from which this extension was created. |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 999 | // |
| 1000 | // NOTE: This is an owned pointer, but can't use scoped_ptr because that would |
| 1001 | // require manifest.h, which would in turn create a circulate dependency |
| 1002 | // between extension.h and manifest.h. |
| 1003 | // |
| 1004 | // TODO(aa): Pull Extension::Type and Extension::Location out into their own |
| 1005 | // files so that manifest.h can rely on them and not get all of extension.h |
| 1006 | // too, and then change this back to a scoped_ptr. |
| 1007 | extensions::Manifest* manifest_; |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 1008 | |
| 1009 | // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs |
| 1010 | // which override the handling of those URLs. (see ExtensionOverrideUI). |
| 1011 | URLOverrideMap chrome_url_overrides_; |
| 1012 | |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 1013 | // Whether this extension requests isolated storage. |
| 1014 | bool is_storage_isolated_; |
| 1015 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 1016 | // The local path inside the extension to use with the launcher. |
| 1017 | std::string launch_local_path_; |
| 1018 | |
| 1019 | // A web url to use with the launcher. Note that this might be relative or |
| 1020 | // absolute. If relative, it is relative to web_origin. |
| 1021 | std::string launch_web_url_; |
| 1022 | |
[email protected] | 4e59568 | 2011-02-09 17:07:02 | [diff] [blame] | 1023 | // The window type that an app's manifest specifies to launch into. |
| 1024 | // This is not always the window type an app will open into, because |
| 1025 | // users can override the way each app launches. See |
| 1026 | // ExtensionPrefs::GetLaunchContainer(), which looks at a per-app pref |
| 1027 | // to decide what container an app will launch in. |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 1028 | extension_misc::LaunchContainer launch_container_; |
| 1029 | |
| 1030 | // The default size of the container when launching. Only respected for |
| 1031 | // containers like panels and windows. |
| 1032 | int launch_width_; |
| 1033 | int launch_height_; |
| 1034 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 1035 | // The Omnibox keyword for this extension, or empty if there is none. |
| 1036 | std::string omnibox_keyword_; |
| 1037 | |
[email protected] | a4a38c1 | 2010-12-23 16:43:56 | [diff] [blame] | 1038 | // List of text-to-speech voices that this extension provides, if any. |
| 1039 | std::vector<TtsVoice> tts_voices_; |
| 1040 | |
[email protected] | a79be1f | 2012-03-23 22:14:00 | [diff] [blame] | 1041 | // The OAuth2 client id and scopes, if specified by the extension. |
| 1042 | OAuth2Info oauth2_info_; |
| 1043 | |
[email protected] | 5662442 | 2011-11-01 22:11:27 | [diff] [blame] | 1044 | // List of intent services that this extension provides, if any. |
| 1045 | std::vector<webkit_glue::WebIntentServiceData> intents_services_; |
[email protected] | be5f00786 | 2011-09-23 00:35:13 | [diff] [blame] | 1046 | |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 1047 | // Whether the extension has host permissions or user script patterns that |
| 1048 | // imply access to file:/// scheme URLs (the user may not have actually |
| 1049 | // granted it that access). |
| 1050 | bool wants_file_access_; |
| 1051 | |
[email protected] | 2af352b | 2011-07-22 08:21:23 | [diff] [blame] | 1052 | // The flags that were passed to InitFromValue. |
| 1053 | int creation_flags_; |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 1054 | |
[email protected] | 7f7b9d93 | 2011-04-20 16:13:26 | [diff] [blame] | 1055 | // The Content-Security-Policy for this extension. Extensions can use |
| 1056 | // Content-Security-Policies to mitigate cross-site scripting and other |
| 1057 | // vulnerabilities. |
| 1058 | std::string content_security_policy_; |
| 1059 | |
[email protected] | 19118d5 | 2010-07-26 22:13:42 | [diff] [blame] | 1060 | FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper); |
| 1061 | FRIEND_TEST_ALL_PREFIXES(TabStripModelTest, Apps); |
[email protected] | ae7fe71 | 2009-07-02 20:33:58 | [diff] [blame] | 1062 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1063 | DISALLOW_COPY_AND_ASSIGN(Extension); |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 1064 | }; |
| 1065 | |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1066 | typedef std::vector< scoped_refptr<const Extension> > ExtensionList; |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 1067 | typedef std::set<std::string> ExtensionIdSet; |
[email protected] | b1748b1d8 | 2009-11-30 20:32:56 | [diff] [blame] | 1068 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1069 | // Handy struct to pass core extension info around. |
| 1070 | struct ExtensionInfo { |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 1071 | ExtensionInfo(const base::DictionaryValue* manifest, |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1072 | const std::string& id, |
| 1073 | const FilePath& path, |
[email protected] | 3bb8499 | 2010-08-26 17:23:46 | [diff] [blame] | 1074 | Extension::Location location); |
| 1075 | ~ExtensionInfo(); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1076 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 1077 | scoped_ptr<base::DictionaryValue> extension_manifest; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1078 | std::string extension_id; |
| 1079 | FilePath extension_path; |
| 1080 | Extension::Location extension_location; |
| 1081 | |
| 1082 | private: |
| 1083 | DISALLOW_COPY_AND_ASSIGN(ExtensionInfo); |
| 1084 | }; |
| 1085 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1086 | struct UnloadedExtensionInfo { |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1087 | extension_misc::UnloadedExtensionReason reason; |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1088 | |
| 1089 | // Was the extension already disabled? |
| 1090 | bool already_disabled; |
| 1091 | |
| 1092 | // The extension being unloaded - this should always be non-NULL. |
| 1093 | const Extension* extension; |
| 1094 | |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1095 | UnloadedExtensionInfo( |
| 1096 | const Extension* extension, |
| 1097 | extension_misc::UnloadedExtensionReason reason); |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1098 | }; |
| 1099 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1100 | // The details sent for EXTENSION_PERMISSIONS_UPDATED notifications. |
| 1101 | struct UpdatedExtensionPermissionsInfo { |
| 1102 | enum Reason { |
[email protected] | f553247 | 2012-02-23 13:00:55 | [diff] [blame] | 1103 | ADDED, // The permissions were added to the extension. |
| 1104 | REMOVED, // The permissions were removed from the extension. |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1105 | }; |
| 1106 | |
| 1107 | Reason reason; |
| 1108 | |
| 1109 | // The extension who's permissions have changed. |
| 1110 | const Extension* extension; |
| 1111 | |
| 1112 | // The permissions that have changed. For Reason::ADDED, this would contain |
| 1113 | // only the permissions that have added, and for Reason::REMOVED, this would |
| 1114 | // only contain the removed permissions. |
| 1115 | const ExtensionPermissionSet* permissions; |
| 1116 | |
| 1117 | UpdatedExtensionPermissionsInfo( |
| 1118 | const Extension* extension, |
| 1119 | const ExtensionPermissionSet* permissions, |
| 1120 | Reason reason); |
| 1121 | }; |
| 1122 | |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 1123 | #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |