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