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