blob: bbcfb26864fa537060374c231b6bd542395fd974 [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]7713d632008-12-02 07:52:332// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]5b1a0e22009-05-26 19:00:585#ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_H_
6#define CHROME_COMMON_EXTENSIONS_EXTENSION_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]7713d632008-12-02 07:52:338
[email protected]300cc58db2009-08-19 20:45:149#include <map>
[email protected]facd7a7652009-06-05 23:15:0210#include <set>
[email protected]7713d632008-12-02 07:52:3311#include <string>
12#include <vector>
13
[email protected]6014d672008-12-05 00:38:2514#include "base/file_path.h"
[email protected]19118d52010-07-26 22:13:4215#include "base/gtest_prod_util.h"
[email protected]b6b805e92011-04-16 09:24:1416#include "base/memory/linked_ptr.h"
[email protected]3b63f8f42011-03-28 01:54:1517#include "base/memory/ref_counted.h"
18#include "base/memory/scoped_ptr.h"
[email protected]d83a5602010-09-16 00:22:4819#include "chrome/common/extensions/extension_constants.h"
[email protected]807871f2010-09-16 01:04:4820#include "chrome/common/extensions/extension_icon_set.h"
[email protected]42b6f0f82009-09-18 21:07:3921#include "chrome/common/extensions/user_script.h"
[email protected]7197f4992009-03-23 05:05:4922#include "chrome/common/extensions/url_pattern.h"
[email protected]cced75a2011-05-20 08:31:1223#include "chrome/common/extensions/url_pattern_set.h"
[email protected]eab9b452009-01-23 20:48:5924#include "googleurl/src/gurl.h"
[email protected]08397d52011-02-05 01:53:3825#include "ui/gfx/size.h"
[email protected]eab9b452009-01-23 20:48:5926
[email protected]3bb84992010-08-26 17:23:4627class DictionaryValue;
[email protected]942690b132010-05-11 06:42:1428class ExtensionAction;
29class ExtensionResource;
[email protected]e2dffe02011-01-20 20:30:0630class ExtensionSidebarDefaults;
[email protected]b6b805e92011-04-16 09:24:1431class FileBrowserHandler;
32class ListValue;
[email protected]12802702010-07-09 19:43:0933class SkBitmap;
[email protected]daf66aa2010-08-06 06:24:2834class Version;
[email protected]942690b132010-05-11 06:42:1435
[email protected]f0755532010-06-22 07:27:2536// Represents a Chrome extension.
[email protected]66e4eb32010-10-27 20:37:4137class Extension : public base::RefCountedThreadSafe<Extension> {
[email protected]7713d632008-12-02 07:52:3338 public:
[email protected]d3cfa482009-10-17 13:54:5739 typedef std::map<const std::string, GURL> URLOverrideMap;
[email protected]10fb1992010-10-08 09:00:1740 typedef std::vector<std::string> ScriptingWhitelist;
[email protected]b6b805e92011-04-16 09:24:1441 typedef std::vector<linked_ptr<FileBrowserHandler> > FileBrowserHandlerList;
[email protected]b24d8312009-08-27 06:47:4642
[email protected]631cf822009-05-15 07:01:2543 // What an extension was loaded from.
[email protected]9b217652010-10-08 22:04:2344 // 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]631cf822009-05-15 07:01:2547 enum Location {
48 INVALID,
[email protected]25b34332009-06-05 21:53:1949 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]1952c7d2010-03-04 23:48:3453 LOAD, // --load-extension.
[email protected]8ef78fd2010-08-19 17:14:3254 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]4d2913e32010-11-30 00:28:5557 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]04cb7542010-10-25 10:50:0661
62 NUM_LOCATIONS
[email protected]25b34332009-06-05 21:53:1963 };
64
65 enum State {
[email protected]0c6da502009-08-14 22:32:3966 DISABLED = 0,
[email protected]25b34332009-06-05 21:53:1967 ENABLED,
[email protected]79c833b52011-04-05 18:31:0168 // An external extension that the user uninstalled. We should not reinstall
69 // such extensions on startup.
70 EXTERNAL_EXTENSION_UNINSTALLED,
[email protected]0c6da502009-08-14 22:32:3971 NUM_STATES
[email protected]631cf822009-05-15 07:01:2572 };
[email protected]7713d632008-12-02 07:52:3373
[email protected]fbcc40302009-06-12 20:45:4574 enum InstallType {
[email protected]ab6f2b22009-07-28 23:28:3775 INSTALL_ERROR,
[email protected]fbcc40302009-06-12 20:45:4576 DOWNGRADE,
77 REINSTALL,
78 UPGRADE,
79 NEW_INSTALL
80 };
81
[email protected]d2817012009-08-04 06:46:2182 // 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]39382942010-03-23 15:57:0988 EXTENSION_ICON_SMALLISH = 24,
[email protected]d2817012009-08-04 06:46:2189 EXTENSION_ICON_BITTY = 16,
90 };
91
[email protected]7fa19f82010-12-21 19:40:0892 // 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]9b217652010-10-08 22:04:2395 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]92888082010-10-18 19:24:57103 // 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]65378f52011-04-08 02:31:23109 // An NaCl module included in the extension.
110 struct NaClModuleInfo {
[email protected]84396dbc2011-04-14 06:33:42111 GURL url;
[email protected]65378f52011-04-08 02:31:23112 std::string mime_type;
113 };
114
[email protected]b0820372011-06-03 07:05:27115 enum InputComponentType {
116 INPUT_COMPONENT_TYPE_IME = 0,
117 INPUT_COMPONENT_TYPE_VIRTUAL_KEYBOARD,
118 INPUT_COMPONENT_TYPE_COUNT
119 };
120
121 struct InputComponentInfo {
122 // Define out of line constructor/destructor to please Clang.
123 InputComponentInfo();
124 ~InputComponentInfo();
125
126 std::string name;
127 InputComponentType type;
128 std::string id;
129 std::string description;
130 std::string language;
131 std::set<std::string> layouts;
132 std::string shortcut_keycode;
133 bool shortcut_alt;
134 bool shortcut_ctrl;
135 bool shortcut_shift;
136 };
137
[email protected]a4a38c12010-12-23 16:43:56138 struct TtsVoice {
139 std::string voice_name;
140 std::string locale;
141 std::string gender;
142 };
143
[email protected]fe2dd7742011-04-19 22:52:49144 // When prompting the user to install or approve permissions, we display
145 // messages describing the effects of the permissions and not the permissions
146 // themselves. Each PermissionMessage represents one of the messages that is
147 // shown to the user.
148 class PermissionMessage {
149 public:
150 // Do not reorder or add new enumerations in this list. If you need to add a
151 // new enum, add it just prior to ID_ENUM_BOUNDARY and enter its l10n
152 // message in kMessageIds.
153 enum MessageId {
154 ID_UNKNOWN,
155 ID_NONE,
156 ID_BOOKMARKS,
157 ID_GEOLOCATION,
158 ID_BROWSING_HISTORY,
159 ID_TABS,
160 ID_MANAGEMENT,
161 ID_DEBUGGER,
162 ID_HOSTS_1,
163 ID_HOSTS_2,
164 ID_HOSTS_3,
165 ID_HOSTS_4_OR_MORE,
166 ID_HOSTS_ALL,
167 ID_FULL_ACCESS,
[email protected]4f9fa242011-05-15 00:14:13168 ID_CLIPBOARD,
[email protected]fe2dd7742011-04-19 22:52:49169 ID_ENUM_BOUNDARY
170 };
171
172 // Creates a permission message with the given |message_id| and initializes
173 // its message to the appropriate value.
174 static PermissionMessage CreateFromMessageId(MessageId message_id);
175
176 // Creates the corresponding permission message for a list of hosts. This
177 // method exists because the hosts are presented as one message that depends
178 // on what and how many hosts there are.
179 static PermissionMessage CreateFromHostList(
180 const std::vector<std::string> hosts);
181
182 // Gets the id of the permission message, which can be used in UMA
183 // histograms.
184 MessageId message_id() const { return message_id_; }
185
186 // Gets a localized message describing this permission. Please note that
187 // the message will be empty for message types TYPE_NONE and TYPE_UNKNOWN.
188 const string16& message() const { return message_; }
189
190 // Comparator to work with std::set.
191 bool operator<(const PermissionMessage& that) const {
192 return message_id_ < that.message_id_;
193 }
194
195 private:
196 PermissionMessage(MessageId message_id, string16 message_);
197
198 // The index of the id in the array is its enum value. The first two values
199 // are non-existent message ids to act as placeholders for "unknown" and
200 // "none".
201 // Note: Do not change the order of the items in this list since they
202 // are used in a histogram. The order must match the MessageId order.
203 static const int kMessageIds[];
204
205 MessageId message_id_;
206 string16 message_;
207 };
208
209 typedef std::vector<PermissionMessage> PermissionMessages;
210
[email protected]0df165f2010-09-28 16:49:40211 // A permission is defined by its |name| (what is used in the manifest),
212 // and the |message_id| that's used by install/update UI.
213 struct Permission {
214 const char* const name;
[email protected]fe2dd7742011-04-19 22:52:49215 const PermissionMessage::MessageId message_id;
[email protected]0df165f2010-09-28 16:49:40216 };
217
[email protected]83048a22011-03-29 00:14:13218 enum InitFromValueFlags {
219 NO_FLAGS = 0,
220
221 // Usually, the id of an extension is generated by the "key" property of
222 // its manifest, but if |REQUIRE_KEY| is not set, a temporary ID will be
223 // generated based on the path.
224 REQUIRE_KEY = 1 << 0,
225
226 // |STRICT_ERROR_CHECKS| enables extra error checking, such as
227 // checks that URL patterns do not contain ports. This error
228 // checking may find an error that a previous version of
229 // Chrome did not flag. To avoid errors in installed extensions
230 // when Chrome is upgraded, strict error checking is only enabled
231 // when loading extensions as a developer would (such as loading
232 // an unpacked extension), or when loading an extension that is
233 // tied to a specific version of Chrome (such as a component
234 // extension). Most callers will set the |STRICT_ERROR_CHECKS| bit when
235 // Extension::ShouldDoStrictErrorChecking(location) returns true.
236 STRICT_ERROR_CHECKS = 1 << 1,
[email protected]3aff9ad2011-04-01 20:26:48237
238 // |ALLOW_FILE_ACCESS| indicates that the user is allowing this extension
239 // to have file access. If it's not present, then permissions and content
240 // scripts that match file:/// URLs will be filtered out.
241 ALLOW_FILE_ACCESS = 1 << 2,
[email protected]83048a22011-03-29 00:14:13242 };
243
[email protected]66e4eb32010-10-27 20:37:41244 static scoped_refptr<Extension> Create(const FilePath& path,
245 Location location,
246 const DictionaryValue& value,
[email protected]83048a22011-03-29 00:14:13247 int flags,
[email protected]66e4eb32010-10-27 20:37:41248 std::string* error);
249
[email protected]4d2913e32010-11-30 00:28:55250 // Return the update url used by gallery/webstore extensions.
251 static GURL GalleryUpdateUrl(bool secure);
252
[email protected]145a317b2011-04-12 16:03:46253 // Given two install sources, return the one which should take priority
254 // over the other. If an extension is installed from two sources A and B,
255 // its install source should be set to GetHigherPriorityLocation(A, B).
256 static Location GetHigherPriorityLocation(Location loc1, Location loc2);
257
[email protected]fe2dd7742011-04-19 22:52:49258 // Get's the install message id for |permission|. Returns
259 // MessageId::TYPE_NONE if none exists.
260 static PermissionMessage::MessageId GetPermissionMessageId(
261 const std::string& permission);
262
[email protected]a2a098d2010-09-29 19:42:55263 // Returns the full list of permission messages that this extension
264 // should display at install time.
[email protected]fe2dd7742011-04-19 22:52:49265 PermissionMessages GetPermissionMessages() const;
266
267 // Returns the full list of permission messages that this extension
268 // should display at install time. The messages are returned as strings
269 // for convenience.
270 std::vector<string16> GetPermissionMessageStrings() const;
[email protected]a2a098d2010-09-29 19:42:55271
[email protected]d6a5c78c2010-12-07 05:18:15272 // Returns the distinct hosts that should be displayed in the install UI
273 // for the URL patterns |list|. This discards some of the detail that is
274 // present in the manifest to make it as easy as possible to process by
275 // users. In particular we disregard the scheme and path components of
276 // URLPatterns and de-dupe the result, which includes filtering out common
[email protected]d7d4a402011-03-08 18:27:51277 // hosts with differing RCDs (aka Registry Controlled Domains, most of which
278 // are Top Level Domains but also include exceptions like co.uk).
279 // NOTE: when de-duping hosts the preferred RCD will be returned, given this
280 // order of preference: .com, .net, .org, first in list.
[email protected]d6a5c78c2010-12-07 05:18:15281 static std::vector<std::string> GetDistinctHostsForDisplay(
282 const URLPatternList& list);
283
284 // Compares two URLPatternLists for security equality by returning whether
285 // the URL patterns in |new_list| contain additional distinct hosts compared
286 // to |old_list|.
287 static bool IsElevatedHostList(
288 const URLPatternList& old_list, const URLPatternList& new_list);
[email protected]0df165f2010-09-28 16:49:40289
[email protected]c3e3def742009-07-17 07:51:06290 // Icon sizes used by the extension system.
[email protected]d2817012009-08-04 06:46:21291 static const int kIconSizes[];
[email protected]c3e3def742009-07-17 07:51:06292
[email protected]4c4f8192009-10-17 01:03:26293 // Max size (both dimensions) for browser and page actions.
294 static const int kPageActionIconMaxSize;
295 static const int kBrowserActionIconMaxSize;
[email protected]e2dffe02011-01-20 20:30:06296 static const int kSidebarIconMaxSize;
[email protected]4c4f8192009-10-17 01:03:26297
[email protected]35506352009-08-07 18:58:19298 // Each permission is a module that the extension is permitted to use.
[email protected]218990c2010-06-26 01:21:07299 //
[email protected]0df165f2010-09-28 16:49:40300 // NOTE: To add a new permission, define it here, and add an entry to
301 // Extension::kPermissions.
[email protected]9dcf8f12010-09-02 20:39:19302 static const char kBackgroundPermission[];
303 static const char kBookmarkPermission[];
[email protected]ab2eb9f2011-05-03 23:02:37304 static const char kClipboardReadPermission[];
305 static const char kClipboardWritePermission[];
[email protected]598bbcc2011-02-24 10:03:25306 static const char kContentSettingsPermission[];
[email protected]9dcf8f12010-09-02 20:39:19307 static const char kContextMenusPermission[];
308 static const char kCookiePermission[];
[email protected]c29ecd72011-05-20 14:17:56309 static const char kChromePrivatePermission[];
[email protected]c6e584c2011-05-18 11:58:44310 static const char kChromeosInfoPrivatePermission[];
[email protected]91ba3312011-03-17 20:39:22311 static const char kDebuggerPermission[];
[email protected]9dcf8f12010-09-02 20:39:19312 static const char kExperimentalPermission[];
[email protected]b777b332011-04-16 04:01:08313 static const char kFileBrowserHandlerPermission[];
[email protected]55d9bed2011-03-25 20:37:59314 static const char kFileBrowserPrivatePermission[];
[email protected]9dcf8f12010-09-02 20:39:19315 static const char kGeolocationPermission[];
316 static const char kHistoryPermission[];
317 static const char kIdlePermission[];
[email protected]eb255772010-10-04 22:10:46318 static const char kManagementPermission[];
[email protected]ce9802042011-05-27 10:11:40319 static const char kMediaPlayerPrivatePermission[];
[email protected]9dcf8f12010-09-02 20:39:19320 static const char kNotificationPermission[];
321 static const char kProxyPermission[];
322 static const char kTabPermission[];
323 static const char kUnlimitedStoragePermission[];
[email protected]9dcf8f12010-09-02 20:39:19324 static const char kWebstorePrivatePermission[];
[email protected]c6e584c2011-05-18 11:58:44325 static const char kWebSocketProxyPrivatePermission[];
[email protected]aeb53b32009-10-29 07:34:45326
[email protected]0df165f2010-09-28 16:49:40327 static const Permission kPermissions[];
[email protected]35506352009-08-07 18:58:19328 static const size_t kNumPermissions;
[email protected]9dcf8f12010-09-02 20:39:19329 static const char* const kHostedAppPermissionNames[];
[email protected]b746f372010-08-29 21:39:32330 static const size_t kNumHostedAppPermissions;
[email protected]9d4c2c52011-04-07 18:53:10331 static const char* const kComponentPrivatePermissionNames[];
332 static const size_t kNumComponentPrivatePermissions;
[email protected]35506352009-08-07 18:58:19333
[email protected]03b612f2010-08-13 21:09:21334 // The old name for the unlimited storage permission, which is deprecated but
335 // still accepted as meaning the same thing as kUnlimitedStoragePermission.
[email protected]9dcf8f12010-09-02 20:39:19336 static const char kOldUnlimitedStoragePermission[];
[email protected]03b612f2010-08-13 21:09:21337
[email protected]8d888c12010-11-30 00:00:25338 // Valid schemes for web extent URLPatterns.
339 static const int kValidWebExtentSchemes;
340
[email protected]f71f7e62010-12-07 03:45:33341 // Valid schemes for host permission URLPatterns.
342 static const int kValidHostPermissionSchemes;
343
[email protected]b746f372010-08-29 21:39:32344 // Returns true if the string is one of the known hosted app permissions (see
345 // kHostedAppPermissionNames).
346 static bool IsHostedAppPermission(const std::string& permission);
347
[email protected]6014d672008-12-05 00:38:25348 // The name of the manifest inside an extension.
[email protected]99efb7b12009-12-18 02:39:16349 static const FilePath::CharType kManifestFilename[];
[email protected]6014d672008-12-05 00:38:25350
[email protected]300cc58db2009-08-19 20:45:14351 // The name of locale folder inside an extension.
[email protected]99efb7b12009-12-18 02:39:16352 static const FilePath::CharType kLocaleFolder[];
[email protected]300cc58db2009-08-19 20:45:14353
354 // The name of the messages file inside an extension.
[email protected]99efb7b12009-12-18 02:39:16355 static const FilePath::CharType kMessagesFilename[];
[email protected]300cc58db2009-08-19 20:45:14356
[email protected]25b34332009-06-05 21:53:19357#if defined(OS_WIN)
[email protected]9dcf8f12010-09-02 20:39:19358 static const char kExtensionRegistryPath[];
[email protected]25b34332009-06-05 21:53:19359#endif
360
[email protected]37eeb5a2009-02-26 23:36:17361 // The number of bytes in a legal id.
[email protected]fe0e7822009-02-26 23:51:48362 static const size_t kIdSize;
[email protected]37eeb5a2009-02-26 23:36:17363
[email protected]e435d6b72009-07-25 03:15:58364 // The mimetype used for extensions.
365 static const char kMimeType[];
366
[email protected]25b34332009-06-05 21:53:19367 // Checks to see if the extension has a valid ID.
368 static bool IdIsValid(const std::string& id);
369
[email protected]4ead6f72010-10-13 19:54:18370 // Generate an ID for an extension in the given path.
[email protected]28d7479b2011-03-09 21:33:27371 // Used while developing extensions, before they have a key.
[email protected]4ead6f72010-10-13 19:54:18372 static std::string GenerateIdForPath(const FilePath& file_name);
373
[email protected]e435d6b72009-07-25 03:15:58374 // Returns true if the specified file is an extension.
375 static bool IsExtension(const FilePath& file_name);
376
[email protected]25b34332009-06-05 21:53:19377 // Whether the |location| is external or not.
378 static inline bool IsExternalLocation(Location location) {
379 return location == Extension::EXTERNAL_PREF ||
[email protected]8ef78fd2010-08-19 17:14:32380 location == Extension::EXTERNAL_REGISTRY ||
[email protected]04cb7542010-10-25 10:50:06381 location == Extension::EXTERNAL_PREF_DOWNLOAD ||
382 location == Extension::EXTERNAL_POLICY_DOWNLOAD;
383 }
384
385 // Whether extensions with |location| are auto-updatable or not.
386 static inline bool IsAutoUpdateableLocation(Location location) {
387 // Only internal and external extensions can be autoupdated.
388 return location == Extension::INTERNAL ||
389 IsExternalLocation(location);
[email protected]25b34332009-06-05 21:53:19390 }
391
[email protected]95da88c42011-03-31 10:07:33392 // Whether extensions with |location| can be uninstalled or not. Policy
393 // controlled extensions are silently auto-installed and updated, and cannot
394 // be disabled by the user. The same applies for internal components.
395 static inline bool UserMayDisable(Location location) {
396 return location != Extension::EXTERNAL_POLICY_DOWNLOAD &&
397 location != Extension::COMPONENT;
398 }
399
[email protected]542258c2011-03-04 21:25:31400 // Whether extensions with |location| should be loaded with strict
401 // error checking. Strict error checks may flag errors older versions
402 // of chrome did not detect. To avoid breaking installed extensions,
403 // strict checks are disabled unless the location indicates that the
404 // developer is loading the extension, or the extension is a component
405 // of chrome.
406 static inline bool ShouldDoStrictErrorChecking(Location location) {
407 return location == Extension::LOAD ||
408 location == Extension::COMPONENT;
409 }
410
[email protected]3aff9ad2011-04-01 20:26:48411 // Unpacked extensions start off with file access since they are a developer
412 // feature.
413 static inline bool ShouldAlwaysAllowFileAccess(Location location) {
414 return location == Extension::LOAD;
415 }
416
[email protected]7fa19f82010-12-21 19:40:08417 // See Type definition above.
418 Type GetType() const;
[email protected]9b217652010-10-08 22:04:23419
[email protected]07c00d992009-03-04 20:27:04420 // Returns an absolute url to a resource inside of an extension. The
[email protected]eab9b452009-01-23 20:48:59421 // |extension_url| argument should be the url() from an Extension object. The
422 // |relative_path| can be untrusted user input. The returned URL will either
423 // be invalid() or a child of |extension_url|.
424 // NOTE: Static so that it can be used from multiple threads.
425 static GURL GetResourceURL(const GURL& extension_url,
426 const std::string& relative_path);
[email protected]cffd7892010-08-26 17:43:28427 GURL GetResourceURL(const std::string& relative_path) const {
[email protected]3cfbd0e2009-03-18 21:26:24428 return GetResourceURL(url(), relative_path);
429 }
[email protected]eab9b452009-01-23 20:48:59430
[email protected]99efb7b12009-12-18 02:39:16431 // Returns an extension resource object. |relative_path| should be UTF8
432 // encoded.
[email protected]9adb9692010-10-29 23:14:02433 ExtensionResource GetResource(const std::string& relative_path) const;
[email protected]99efb7b12009-12-18 02:39:16434
435 // As above, but with |relative_path| following the file system's encoding.
[email protected]9adb9692010-10-29 23:14:02436 ExtensionResource GetResource(const FilePath& relative_path) const;
[email protected]eab9b452009-01-23 20:48:59437
[email protected]a17f9462009-06-09 02:56:41438 // |input| is expected to be the text of an rsa public or private key. It
439 // tolerates the presence or absence of bracking header/footer like this:
440 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
441 // and may contain newlines.
442 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
443
444 // Does a simple base64 encoding of |input| into |output|.
445 static bool ProducePEM(const std::string& input, std::string* output);
446
[email protected]84ac7f32009-10-06 06:17:54447 // Generates an extension ID from arbitrary input. The same input string will
448 // always generate the same output ID.
449 static bool GenerateId(const std::string& input, std::string* output);
[email protected]fbcc40302009-06-12 20:45:45450
[email protected]a17f9462009-06-09 02:56:41451 // Expects base64 encoded |input| and formats into |output| including
452 // the appropriate header & footer.
[email protected]e0d08192011-03-29 19:02:50453 static bool FormatPEMForFileOutput(const std::string& input,
454 std::string* output,
455 bool is_public);
[email protected]a17f9462009-06-09 02:56:41456
[email protected]2a409532009-08-28 19:39:44457 // Determine whether |new_extension| has increased privileges compared to
[email protected]8d888c12010-11-30 00:00:25458 // its previously granted permissions, specified by |granted_apis|,
459 // |granted_extent| and |granted_full_access|.
460 static bool IsPrivilegeIncrease(const bool granted_full_access,
461 const std::set<std::string>& granted_apis,
[email protected]cced75a2011-05-20 08:31:12462 const URLPatternSet& granted_extent,
[email protected]9adb9692010-10-29 23:14:02463 const Extension* new_extension);
[email protected]b24d8312009-08-27 06:47:46464
[email protected]c690a9812009-12-17 05:55:32465 // Given an extension and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23466 // result. In the browser process, this will DCHECK if not called on the
467 // file thread. To easily load extension images on the UI thread, see
468 // ImageLoadingTracker.
[email protected]9adb9692010-10-29 23:14:02469 static void DecodeIcon(const Extension* extension,
[email protected]c690a9812009-12-17 05:55:32470 Icons icon_size,
471 scoped_ptr<SkBitmap>* result);
472
473 // Given an icon_path and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23474 // result. In the browser process, this will DCHECK if not called on the
475 // file thread. To easily load extension images on the UI thread, see
476 // ImageLoadingTracker.
[email protected]c690a9812009-12-17 05:55:32477 static void DecodeIconFromPath(const FilePath& icon_path,
478 Icons icon_size,
479 scoped_ptr<SkBitmap>* result);
480
[email protected]5349ac6d2011-04-05 22:20:17481 // Returns the default extension/app icon (for extensions or apps that don't
482 // have one).
483 static const SkBitmap& GetDefaultIcon(bool is_app);
484
[email protected]a807bbe2010-04-14 10:51:19485 // Returns the base extension url for a given |extension_id|.
486 static GURL GetBaseURLFromExtensionId(const std::string& extension_id);
487
[email protected]ec5b50d2010-10-09 16:35:18488 // Returns the url prefix for the extension/apps gallery. Can be set via the
[email protected]ce3eb7b62010-09-14 13:57:44489 // --apps-gallery-url switch. The URL returned will not contain a trailing
[email protected]d3071992010-10-08 15:24:07490 // slash. Do not use this as a prefix/extent for the store. Instead see
[email protected]eaa7dd182010-12-14 11:09:00491 // ExtensionService::GetWebStoreApp or
492 // ExtensionService::IsDownloadFromGallery
[email protected]d3071992010-10-08 15:24:07493 static std::string ChromeStoreLaunchURL();
[email protected]a0cf04a2010-06-23 03:29:55494
[email protected]be7e5cb2010-10-04 12:53:17495 // Adds an extension to the scripting whitelist. Used for testing only.
[email protected]10fb1992010-10-08 09:00:17496 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist);
[email protected]2a521c52011-01-26 18:45:21497 static const ScriptingWhitelist* GetScriptingWhitelist();
[email protected]be7e5cb2010-10-04 12:53:17498
[email protected]aeb53b32009-10-29 07:34:45499 // Returns true if the extension has the specified API permission.
[email protected]0df165f2010-09-28 16:49:40500 static bool HasApiPermission(const std::set<std::string>& api_permissions,
[email protected]246c05f2010-09-10 09:12:11501 const std::string& function_name);
[email protected]583d45c12010-08-31 02:48:12502
[email protected]8d888c12010-11-30 00:00:25503 // Whether the |effective_host_permissions| and |api_permissions| include
504 // effective access to all hosts. See the non-static version of the method
505 // for more details.
506 static bool HasEffectiveAccessToAllHosts(
[email protected]cced75a2011-05-20 08:31:12507 const URLPatternSet& effective_host_permissions,
[email protected]8d888c12010-11-30 00:00:25508 const std::set<std::string>& api_permissions);
509
[email protected]246c05f2010-09-10 09:12:11510 bool HasApiPermission(const std::string& function_name) const {
511 return HasApiPermission(this->api_permissions(), function_name);
[email protected]aeb53b32009-10-29 07:34:45512 }
513
[email protected]cced75a2011-05-20 08:31:12514 const URLPatternSet& GetEffectiveHostPermissions() const {
[email protected]6f229e82010-11-02 17:47:26515 return effective_host_permissions_;
[email protected]4361c7c2010-09-30 21:57:53516 }
[email protected]b24d8312009-08-27 06:47:46517
[email protected]fbd17cf2010-04-28 23:52:56518 // Whether or not the extension is allowed permission for a URL pattern from
519 // the manifest. http, https, and chrome://favicon/ is allowed for all
520 // extensions, while component extensions are allowed access to
521 // chrome://resources.
[email protected]a3caa822010-10-26 18:10:00522 bool CanSpecifyHostPermission(const URLPattern& pattern) const;
[email protected]fbd17cf2010-04-28 23:52:56523
[email protected]584b8e3f2010-04-10 00:23:37524 // Whether the extension has access to the given URL.
525 bool HasHostPermission(const GURL& url) const;
526
[email protected]0df165f2010-09-28 16:49:40527 // Whether the extension has effective access to all hosts. This is true if
528 // there is a content script that matches all hosts, if there is a host
529 // permission grants access to all hosts (like <all_urls>) or an api
530 // permission that effectively grants access to all hosts (e.g. proxy,
531 // network, etc.)
532 bool HasEffectiveAccessToAllHosts() const;
[email protected]b24d8312009-08-27 06:47:46533
[email protected]8d888c12010-11-30 00:00:25534 // Whether the extension effectively has all permissions (for example, by
535 // having an NPAPI plugin).
536 bool HasFullPermissions() const;
537
[email protected]5df6a5d2011-01-26 07:39:12538 // Whether context menu should be shown for page and browser actions.
539 bool ShowConfigureContextMenus() const;
540
[email protected]37cd64d2010-10-25 18:17:58541 // Returns the Homepage URL for this extension. If homepage_url was not
542 // specified in the manifest, this returns the Google Gallery URL. For
[email protected]bfa90a3a2010-04-28 15:43:23543 // third-party extensions, this returns a blank GURL.
[email protected]37cd64d2010-10-25 18:17:58544 GURL GetHomepageURL() const;
[email protected]bfa90a3a2010-04-28 15:43:23545
[email protected]facd7a7652009-06-05 23:15:02546 // Returns a list of paths (relative to the extension dir) for images that
547 // the browser might load (like themes and page action icons).
[email protected]9adb9692010-10-29 23:14:02548 std::set<FilePath> GetBrowserImages() const;
[email protected]facd7a7652009-06-05 23:15:02549
[email protected]807871f2010-09-16 01:04:48550 // Get an extension icon as a resource or URL.
[email protected]9adb9692010-10-29 23:14:02551 ExtensionResource GetIconResource(
552 int size, ExtensionIconSet::MatchType match_type) const;
553 GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const;
[email protected]f34e79632010-03-17 02:34:08554
[email protected]867a73e12010-03-19 20:45:46555 // Gets the fully resolved absolute launch URL.
556 GURL GetFullLaunchURL() const;
[email protected]2a521c52011-01-26 18:45:21557
[email protected]6f229e82010-11-02 17:47:26558 // Image cache related methods. These are only valid on the UI thread and
559 // not maintained by this class. See ImageLoadingTracker for usage. The
560 // |original_size| parameter should be the size of the image at |source|
561 // before any scaling may have been done to produce the pixels in |image|.
562 void SetCachedImage(const ExtensionResource& source,
563 const SkBitmap& image,
564 const gfx::Size& original_size) const;
565 bool HasCachedImage(const ExtensionResource& source,
566 const gfx::Size& max_size) const;
567 SkBitmap GetCachedImage(const ExtensionResource& source,
568 const gfx::Size& max_size) const;
[email protected]2a521c52011-01-26 18:45:21569
570 // Returns true if this extension can execute script on a page. If a
571 // UserScript object is passed, permission to run that specific script is
572 // checked (using its matches list). Otherwise, permission to execute script
573 // programmatically is checked (using the extension's host permission).
574 //
575 // This method is also aware of certain special pages that extensions are
576 // usually not allowed to run script on.
577 bool CanExecuteScriptOnPage(const GURL& page_url,
[email protected]3aff9ad2011-04-01 20:26:48578 const UserScript* script,
[email protected]2a521c52011-01-26 18:45:21579 std::string* error) const;
580
[email protected]6f229e82010-11-02 17:47:26581 // Returns true if this extension is a COMPONENT extension, or if it is
582 // on the whitelist of extensions that can script all pages.
583 bool CanExecuteScriptEverywhere() const;
584
[email protected]5efbfe012011-02-22 23:07:18585 // Returns true if this extension is allowed to obtain the contents of a
586 // page as an image. Since a page may contain sensitive information, this
587 // is restricted to the extension's host permissions as well as the
588 // extension page itself.
589 bool CanCaptureVisiblePage(const GURL& page_url, std::string* error) const;
590
[email protected]a65882c2010-11-12 15:15:09591 // Returns true if this extension updates itself using the extension
592 // gallery.
593 bool UpdatesFromGallery() const;
594
[email protected]cca147172011-02-17 01:29:29595 // Returns true if this extension or app includes areas within |origin|.
596 bool OverlapsWithOrigin(const GURL& origin) const;
597
[email protected]6f229e82010-11-02 17:47:26598 // Accessors:
599
600 const FilePath& path() const { return path_; }
601 const GURL& url() const { return extension_url_; }
602 Location location() const { return location_; }
603 const std::string& id() const { return id_; }
604 const Version* version() const { return version_.get(); }
605 const std::string VersionString() const;
606 const std::string& name() const { return name_; }
607 const std::string& public_key() const { return public_key_; }
608 const std::string& description() const { return description_; }
609 bool converted_from_user_script() const {
610 return converted_from_user_script_;
611 }
612 const UserScriptList& content_scripts() const { return content_scripts_; }
613 ExtensionAction* page_action() const { return page_action_.get(); }
614 ExtensionAction* browser_action() const { return browser_action_.get(); }
[email protected]e2dffe02011-01-20 20:30:06615 ExtensionSidebarDefaults* sidebar_defaults() const {
616 return sidebar_defaults_.get();
617 }
[email protected]b6b805e92011-04-16 09:24:14618 const FileBrowserHandlerList* file_browser_handlers() const {
619 return file_browser_handlers_.get();
620 }
[email protected]6f229e82010-11-02 17:47:26621 const std::vector<PluginInfo>& plugins() const { return plugins_; }
[email protected]65378f52011-04-08 02:31:23622 const std::vector<NaClModuleInfo>& nacl_modules() const {
623 return nacl_modules_;
624 }
[email protected]b0820372011-06-03 07:05:27625 const std::vector<InputComponentInfo>& input_components() const {
626 return input_components_;
627 }
[email protected]6f229e82010-11-02 17:47:26628 const GURL& background_url() const { return background_url_; }
629 const GURL& options_url() const { return options_url_; }
630 const GURL& devtools_url() const { return devtools_url_; }
631 const std::vector<GURL>& toolstrips() const { return toolstrips_; }
632 const std::set<std::string>& api_permissions() const {
633 return api_permissions_;
634 }
635 const URLPatternList& host_permissions() const { return host_permissions_; }
636 const GURL& update_url() const { return update_url_; }
637 const ExtensionIconSet& icons() const { return icons_; }
638 const DictionaryValue* manifest_value() const {
639 return manifest_value_.get();
640 }
641 const std::string default_locale() const { return default_locale_; }
642 const URLOverrideMap& GetChromeURLOverrides() const {
643 return chrome_url_overrides_;
644 }
645 const std::string omnibox_keyword() const { return omnibox_keyword_; }
646 bool incognito_split_mode() const { return incognito_split_mode_; }
[email protected]a4a38c12010-12-23 16:43:56647 const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; }
[email protected]6f229e82010-11-02 17:47:26648
[email protected]3aff9ad2011-04-01 20:26:48649 bool wants_file_access() const { return wants_file_access_; }
650
[email protected]7f7b9d932011-04-20 16:13:26651 const std::string& content_security_policy() const {
652 return content_security_policy_;
653 }
654
[email protected]6f229e82010-11-02 17:47:26655 // App-related.
656 bool is_app() const { return is_app_; }
657 bool is_hosted_app() const { return is_app() && !web_extent().is_empty(); }
658 bool is_packaged_app() const { return is_app() && web_extent().is_empty(); }
[email protected]d9696672011-03-15 22:45:09659 bool is_storage_isolated() const { return is_app() && is_storage_isolated_; }
[email protected]cced75a2011-05-20 08:31:12660 const URLPatternSet& web_extent() const { return extent_; }
[email protected]6f229e82010-11-02 17:47:26661 const std::string& launch_local_path() const { return launch_local_path_; }
662 const std::string& launch_web_url() const { return launch_web_url_; }
663 extension_misc::LaunchContainer launch_container() const {
664 return launch_container_;
665 }
666 int launch_width() const { return launch_width_; }
667 int launch_height() const { return launch_height_; }
668
669 // Theme-related.
670 bool is_theme() const { return is_theme_; }
671 DictionaryValue* GetThemeImages() const { return theme_images_.get(); }
672 DictionaryValue* GetThemeColors() const {return theme_colors_.get(); }
673 DictionaryValue* GetThemeTints() const { return theme_tints_.get(); }
674 DictionaryValue* GetThemeDisplayProperties() const {
675 return theme_display_properties_.get();
676 }
677
[email protected]4a8d3272009-03-10 19:15:08678 private:
[email protected]66e4eb32010-10-27 20:37:41679 friend class base::RefCountedThreadSafe<Extension>;
680
[email protected]d7e9a862010-11-03 21:57:49681 // We keep a cache of images loaded from extension resources based on their
682 // path and a string representation of a size that may have been used to
683 // scale it (or the empty string if the image is at its original size).
684 typedef std::pair<FilePath, std::string> ImageCacheKey;
685 typedef std::map<ImageCacheKey, SkBitmap> ImageCache;
686
[email protected]4ead6f72010-10-13 19:54:18687 // Normalize the path for use by the extension. On Windows, this will make
688 // sure the drive letter is uppercase.
689 static FilePath MaybeNormalizePath(const FilePath& path);
690
[email protected]d6a5c78c2010-12-07 05:18:15691 // Returns the distinct hosts that can be displayed in the install UI or be
692 // used for privilege comparisons. This discards some of the detail that is
693 // present in the manifest to make it as easy as possible to process by users.
694 // In particular we disregard the scheme and path components of URLPatterns
695 // and de-dupe the result, which includes filtering out common hosts with
696 // differing RCDs. If |include_rcd| is true, then the de-duped result
697 // will be the first full entry, including its RCD. So if the list was
698 // "*.google.co.uk" and "*.google.com", the returned value would just be
699 // "*.google.co.uk". Keeping the RCD in the result is useful for display
700 // purposes when you want to show the user one sample hostname from the list.
701 // If you need to compare two URLPatternLists for security equality, then set
702 // |include_rcd| to false, which will return a result like "*.google.",
703 // regardless of the order of the patterns.
704 static std::vector<std::string> GetDistinctHosts(
705 const URLPatternList& host_patterns, bool include_rcd);
706
[email protected]66e4eb32010-10-27 20:37:41707 Extension(const FilePath& path, Location location);
708 ~Extension();
709
710 // Initialize the extension from a parsed manifest.
[email protected]83048a22011-03-29 00:14:13711 bool InitFromValue(const DictionaryValue& value, int flags,
712 std::string* error);
[email protected]66e4eb32010-10-27 20:37:41713
[email protected]052c92702010-06-25 07:25:52714 // Helper function for implementing HasCachedImage/GetCachedImage. A return
715 // value of NULL means there is no matching image cached (we allow caching an
716 // empty SkBitmap).
717 SkBitmap* GetCachedImageImpl(const ExtensionResource& source,
[email protected]9adb9692010-10-29 23:14:02718 const gfx::Size& max_size) const;
[email protected]d9ad80f2010-03-30 20:40:18719
[email protected]3cfbd0e2009-03-18 21:26:24720 // Helper method that loads a UserScript object from a
721 // dictionary in the content_script list of the manifest.
722 bool LoadUserScriptHelper(const DictionaryValue* content_script,
723 int definition_index,
[email protected]3aff9ad2011-04-01 20:26:48724 int flags,
[email protected]3cfbd0e2009-03-18 21:26:24725 std::string* error,
726 UserScript* result);
[email protected]f7f3a5f2009-05-01 22:02:34727
[email protected]6657afa62009-11-04 02:15:20728 // Helper method that loads either the include_globs or exclude_globs list
729 // from an entry in the content_script lists of the manifest.
730 bool LoadGlobsHelper(const DictionaryValue* content_script,
731 int content_script_index,
[email protected]e2194742010-08-12 05:54:34732 const char* globs_property_name,
[email protected]6657afa62009-11-04 02:15:20733 std::string* error,
[email protected]11f4857282009-11-13 19:56:17734 void(UserScript::*add_method)(const std::string& glob),
[email protected]6657afa62009-11-04 02:15:20735 UserScript *instance);
736
[email protected]867a73e12010-03-19 20:45:46737 // Helpers to load various chunks of the manifest.
[email protected]3ba0fd32010-06-19 05:39:10738 bool LoadIsApp(const DictionaryValue* manifest, std::string* error);
[email protected]542258c2011-03-04 21:25:31739 bool LoadExtent(const DictionaryValue* manifest,
740 const char* key,
[email protected]cced75a2011-05-20 08:31:12741 URLPatternSet* extent,
[email protected]542258c2011-03-04 21:25:31742 const char* list_error,
743 const char* value_error,
744 URLPattern::ParseOption parse_strictness,
745 std::string* error);
[email protected]867a73e12010-03-19 20:45:46746 bool LoadLaunchContainer(const DictionaryValue* manifest, std::string* error);
747 bool LoadLaunchURL(const DictionaryValue* manifest, std::string* error);
[email protected]d9696672011-03-15 22:45:09748 bool LoadAppIsolation(const DictionaryValue* manifest, std::string* error);
[email protected]cbf4d1912010-08-12 18:24:57749 bool EnsureNotHybridApp(const DictionaryValue* manifest, std::string* error);
[email protected]867a73e12010-03-19 20:45:46750
[email protected]5d246db22009-10-27 06:17:57751 // Helper method to load an ExtensionAction from the page_action or
[email protected]92c6f9b92009-10-24 04:35:08752 // browser_action entries in the manifest.
[email protected]5d246db22009-10-27 06:17:57753 ExtensionAction* LoadExtensionActionHelper(
[email protected]92c6f9b92009-10-24 04:35:08754 const DictionaryValue* extension_action, std::string* error);
755
[email protected]b6b805e92011-04-16 09:24:14756 // Helper method to load an FileBrowserHandlerList from the manifest.
757 FileBrowserHandlerList* LoadFileBrowserHandlers(
758 const ListValue* extension_actions, std::string* error);
759 // Helper method to load an FileBrowserHandler from manifest.
760 FileBrowserHandler* LoadFileBrowserHandler(
761 const DictionaryValue* file_browser_handlers, std::string* error);
762
[email protected]e2dffe02011-01-20 20:30:06763 // Helper method to load an ExtensionSidebarDefaults from the sidebar manifest
764 // entry.
765 ExtensionSidebarDefaults* LoadExtensionSidebarDefaults(
766 const DictionaryValue* sidebar, std::string* error);
767
[email protected]4361c7c2010-09-30 21:57:53768 // Calculates the effective host permissions from the permissions and content
769 // script petterns.
770 void InitEffectiveHostPermissions();
771
[email protected]2f6698b2010-10-14 00:58:21772 // Returns true if the extension has more than one "UI surface". For example,
773 // an extension that has a browser action and a page action.
774 bool HasMultipleUISurfaces() const;
775
[email protected]e2eb43112009-05-29 21:19:54776 // Figures out if a source contains keys not associated with themes - we
777 // don't want to allow scripts and such to be bundled with themes.
[email protected]9adb9692010-10-29 23:14:02778 bool ContainsNonThemeKeys(const DictionaryValue& source) const;
[email protected]e2eb43112009-05-29 21:19:54779
[email protected]311e4cc12011-06-07 01:40:40780 // Only allow the experimental API permission if the command line
781 // flag is present.
782 bool IsDisallowedExperimentalPermission(const std::string& permission) const;
783
[email protected]1952c7d2010-03-04 23:48:34784 // Returns true if the string is one of the known api permissions (see
[email protected]0df165f2010-09-28 16:49:40785 // kPermissions).
[email protected]9adb9692010-10-29 23:14:02786 bool IsAPIPermission(const std::string& permission) const;
[email protected]1952c7d2010-03-04 23:48:34787
[email protected]9d4c2c52011-04-07 18:53:10788 // Returns true if this is a component, or we are not attempting to access a
789 // component-private permission.
790 bool IsComponentOnlyPermission(const std::string& permission) const;
791
[email protected]a2a098d2010-09-29 19:42:55792 // The set of unique API install messages that the extension has.
793 // NOTE: This only includes messages related to permissions declared in the
794 // "permissions" key in the manifest. Permissions implied from other features
795 // of the manifest, like plugins and content scripts are not included.
[email protected]fe2dd7742011-04-19 22:52:49796 std::set<PermissionMessage> GetSimplePermissionMessages() const;
[email protected]a2a098d2010-09-29 19:42:55797
[email protected]d7e9a862010-11-03 21:57:49798 // Cached images for this extension. This should only be touched on the UI
799 // thread.
800 mutable ImageCache image_cache_;
[email protected]1e8c93f2010-02-08 22:58:31801
[email protected]6f229e82010-11-02 17:47:26802 // A persistent, globally unique ID. An extension's ID is used in things
803 // like directory structures and URLs, and is expected to not change across
804 // versions. It is generated as a SHA-256 hash of the extension's public
805 // key, or as a hash of the path in the case of unpacked extensions.
806 std::string id_;
807
808 // The extension's human-readable name. Name is used for display purpose. It
809 // might be wrapped with unicode bidi control characters so that it is
810 // displayed correctly in RTL context.
811 // NOTE: Name is UTF-8 and may contain non-ascii characters.
812 std::string name_;
813
814 // The absolute path to the directory the extension is stored in.
815 FilePath path_;
816
817 // Default locale for fall back. Can be empty if extension is not localized.
818 std::string default_locale_;
819
820 // If true, a separate process will be used for the extension in incognito
821 // mode.
822 bool incognito_split_mode_;
823
824 // Defines the set of URLs in the extension's web content.
[email protected]cced75a2011-05-20 08:31:12825 URLPatternSet extent_;
[email protected]6f229e82010-11-02 17:47:26826
827 // The set of host permissions that the extension effectively has access to,
828 // which is a merge of host_permissions_ and all of the match patterns in
829 // any content scripts the extension has. This is used to determine which
830 // URLs have the ability to load an extension's resources via embedded
831 // chrome-extension: URLs (see extension_protocols.cc).
[email protected]cced75a2011-05-20 08:31:12832 URLPatternSet effective_host_permissions_;
[email protected]6f229e82010-11-02 17:47:26833
834 // The set of module-level APIs this extension can use.
835 std::set<std::string> api_permissions_;
836
837 // The icons for the extension.
838 ExtensionIconSet icons_;
839
840 // The base extension url for the extension.
841 GURL extension_url_;
842
843 // The location the extension was loaded from.
844 Location location_;
845
846 // The extension's version.
847 scoped_ptr<Version> version_;
848
849 // An optional longer description of the extension.
850 std::string description_;
851
852 // True if the extension was generated from a user script. (We show slightly
853 // different UI if so).
854 bool converted_from_user_script_;
855
856 // Paths to the content scripts the extension contains.
857 UserScriptList content_scripts_;
858
859 // The extension's page action, if any.
860 scoped_ptr<ExtensionAction> page_action_;
861
862 // The extension's browser action, if any.
863 scoped_ptr<ExtensionAction> browser_action_;
864
[email protected]b6b805e92011-04-16 09:24:14865 // The extension's file browser actions, if any.
866 scoped_ptr<FileBrowserHandlerList> file_browser_handlers_;
867
[email protected]e2dffe02011-01-20 20:30:06868 // The extension's sidebar, if any.
869 scoped_ptr<ExtensionSidebarDefaults> sidebar_defaults_;
870
[email protected]6f229e82010-11-02 17:47:26871 // Optional list of NPAPI plugins and associated properties.
872 std::vector<PluginInfo> plugins_;
873
[email protected]65378f52011-04-08 02:31:23874 // Optional list of NaCl modules and associated properties.
875 std::vector<NaClModuleInfo> nacl_modules_;
876
[email protected]b0820372011-06-03 07:05:27877 // Optional list of input components and associated properties.
878 std::vector<InputComponentInfo> input_components_;
879
[email protected]6f229e82010-11-02 17:47:26880 // Optional URL to a master page of which a single instance should be always
881 // loaded in the background.
882 GURL background_url_;
883
884 // Optional URL to a page for setting options/preferences.
885 GURL options_url_;
886
887 // Optional URL to a devtools extension page.
888 GURL devtools_url_;
889
890 // Optional list of toolstrips and associated properties.
891 std::vector<GURL> toolstrips_;
892
893 // The public key used to sign the contents of the crx package.
894 std::string public_key_;
895
896 // A map of resource id's to relative file paths.
897 scoped_ptr<DictionaryValue> theme_images_;
898
899 // A map of color names to colors.
900 scoped_ptr<DictionaryValue> theme_colors_;
901
902 // A map of color names to colors.
903 scoped_ptr<DictionaryValue> theme_tints_;
904
905 // A map of display properties.
906 scoped_ptr<DictionaryValue> theme_display_properties_;
907
908 // Whether the extension is a theme.
909 bool is_theme_;
910
911 // The sites this extension has permission to talk to (using XHR, etc).
912 URLPatternList host_permissions_;
913
914 // The homepage for this extension. Useful if it is not hosted by Google and
915 // therefore does not have a Gallery URL.
916 GURL homepage_url_;
917
918 // URL for fetching an update manifest
919 GURL update_url_;
920
921 // A copy of the manifest that this extension was created from.
922 scoped_ptr<DictionaryValue> manifest_value_;
923
924 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
925 // which override the handling of those URLs. (see ExtensionOverrideUI).
926 URLOverrideMap chrome_url_overrides_;
927
928 // Whether this extension uses app features.
929 bool is_app_;
930
[email protected]d9696672011-03-15 22:45:09931 // Whether this extension requests isolated storage.
932 bool is_storage_isolated_;
933
[email protected]6f229e82010-11-02 17:47:26934 // The local path inside the extension to use with the launcher.
935 std::string launch_local_path_;
936
937 // A web url to use with the launcher. Note that this might be relative or
938 // absolute. If relative, it is relative to web_origin.
939 std::string launch_web_url_;
940
[email protected]4e595682011-02-09 17:07:02941 // The window type that an app's manifest specifies to launch into.
942 // This is not always the window type an app will open into, because
943 // users can override the way each app launches. See
944 // ExtensionPrefs::GetLaunchContainer(), which looks at a per-app pref
945 // to decide what container an app will launch in.
[email protected]6f229e82010-11-02 17:47:26946 extension_misc::LaunchContainer launch_container_;
947
948 // The default size of the container when launching. Only respected for
949 // containers like panels and windows.
950 int launch_width_;
951 int launch_height_;
952
953 // The Omnibox keyword for this extension, or empty if there is none.
954 std::string omnibox_keyword_;
955
[email protected]a4a38c12010-12-23 16:43:56956 // List of text-to-speech voices that this extension provides, if any.
957 std::vector<TtsVoice> tts_voices_;
958
[email protected]3aff9ad2011-04-01 20:26:48959 // Whether the extension has host permissions or user script patterns that
960 // imply access to file:/// scheme URLs (the user may not have actually
961 // granted it that access).
962 bool wants_file_access_;
963
[email protected]7f7b9d932011-04-20 16:13:26964 // The Content-Security-Policy for this extension. Extensions can use
965 // Content-Security-Policies to mitigate cross-site scripting and other
966 // vulnerabilities.
967 std::string content_security_policy_;
968
[email protected]eaa7dd182010-12-14 11:09:00969 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
[email protected]5eb375e92010-11-26 07:50:41970 UpdateExtensionPreservesLocation);
[email protected]19118d52010-07-26 22:13:42971 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper);
[email protected]66e4eb32010-10-27 20:37:41972 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueInvalid);
973 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueValid);
974 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueValidNameInRTL);
[email protected]19118d52010-07-26 22:13:42975 FRIEND_TEST_ALL_PREFIXES(TabStripModelTest, Apps);
[email protected]ae7fe712009-07-02 20:33:58976
[email protected]894bb502009-05-21 22:39:57977 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:33978};
979
[email protected]9adb9692010-10-29 23:14:02980typedef std::vector< scoped_refptr<const Extension> > ExtensionList;
[email protected]ec5b50d2010-10-09 16:35:18981typedef std::set<std::string> ExtensionIdSet;
[email protected]b1748b1d82009-11-30 20:32:56982
[email protected]c6d474f82009-12-16 21:11:06983// Handy struct to pass core extension info around.
984struct ExtensionInfo {
985 ExtensionInfo(const DictionaryValue* manifest,
986 const std::string& id,
987 const FilePath& path,
[email protected]3bb84992010-08-26 17:23:46988 Extension::Location location);
989 ~ExtensionInfo();
[email protected]c6d474f82009-12-16 21:11:06990
991 scoped_ptr<DictionaryValue> extension_manifest;
992 std::string extension_id;
993 FilePath extension_path;
994 Extension::Location extension_location;
995
996 private:
997 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
998};
999
[email protected]211030342010-09-30 18:41:061000// Struct used for the details of the EXTENSION_UNINSTALLED
1001// notification.
[email protected]b05fb9ff2011-04-23 00:07:561002//
1003// TODO(akalin): Now that sync doesn't need to listen to
1004// EXTENSION_UNINSTALLED, everything but |extension_id| can be
1005// removed.
[email protected]211030342010-09-30 18:41:061006struct UninstalledExtensionInfo {
1007 explicit UninstalledExtensionInfo(const Extension& extension);
[email protected]9b2331d92010-10-04 23:11:191008 ~UninstalledExtensionInfo();
[email protected]211030342010-09-30 18:41:061009
1010 std::string extension_id;
1011 std::set<std::string> extension_api_permissions;
[email protected]7fa19f82010-12-21 19:40:081012 Extension::Type extension_type;
[email protected]76c25112010-10-01 22:37:211013 GURL update_url;
[email protected]211030342010-09-30 18:41:061014};
1015
[email protected]a9f39a312010-12-23 22:14:271016struct UnloadedExtensionInfo {
1017 enum Reason {
1018 DISABLE, // The extension is being disabled.
1019 UPDATE, // The extension is being updated to a newer version.
1020 UNINSTALL, // The extension is being uninstalled.
1021 };
1022
1023 Reason reason;
1024
1025 // Was the extension already disabled?
1026 bool already_disabled;
1027
1028 // The extension being unloaded - this should always be non-NULL.
1029 const Extension* extension;
1030
1031 UnloadedExtensionInfo(const Extension* extension, Reason reason);
1032};
1033
[email protected]5b1a0e22009-05-26 19:00:581034#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_