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