blob: 3a5a42cf5bb318bca8f0ff060366a78708db8889 [file] [log] [blame]
[email protected]eb75f7b2012-01-04 09:07:281// Copyright (c) 2012 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]7713d632008-12-02 07:52:337
[email protected]8629c542012-04-20 03:40:038#include <algorithm>
[email protected]18049dc2012-06-19 23:12:559#include <iosfwd>
[email protected]300cc58db2009-08-19 20:45:1410#include <map>
[email protected]facd7a7652009-06-05 23:15:0211#include <set>
[email protected]7713d632008-12-02 07:52:3312#include <string>
[email protected]58f62cf2012-03-09 10:45:1113#include <utility>
[email protected]7713d632008-12-02 07:52:3314#include <vector>
15
[email protected]6014d672008-12-05 00:38:2516#include "base/file_path.h"
[email protected]19118d52010-07-26 22:13:4217#include "base/gtest_prod_util.h"
[email protected]8f270be2011-12-21 21:15:2218#include "base/hash_tables.h"
[email protected]b6b805e92011-04-16 09:24:1419#include "base/memory/linked_ptr.h"
[email protected]3b63f8f42011-03-28 01:54:1520#include "base/memory/ref_counted.h"
21#include "base/memory/scoped_ptr.h"
[email protected]902fd7b2011-07-27 18:42:3122#include "base/synchronization/lock.h"
[email protected]65907942012-05-22 19:59:4723#include "chrome/common/extensions/command.h"
[email protected]d83a5602010-09-16 00:22:4824#include "chrome/common/extensions/extension_constants.h"
[email protected]807871f2010-09-16 01:04:4825#include "chrome/common/extensions/extension_icon_set.h"
[email protected]bebe1d02012-08-02 20:17:0926#include "chrome/common/extensions/permissions/api_permission.h"
[email protected]1d8b79a2012-08-16 20:22:5427#include "chrome/common/extensions/permissions/api_permission_set.h"
[email protected]bebe1d02012-08-02 20:17:0928#include "chrome/common/extensions/permissions/permission_message.h"
[email protected]885c0e92012-11-13 20:27:4229#include "chrome/common/extensions/user_script.h"
30#include "extensions/common/url_pattern.h"
[email protected]e9f541a2012-11-19 21:52:3131#include "extensions/common/url_pattern_set.h"
[email protected]eab9b452009-01-23 20:48:5932#include "googleurl/src/gurl.h"
[email protected]f5532472012-02-23 13:00:5533#include "ui/base/accelerators/accelerator.h"
[email protected]08397d52011-02-05 01:53:3834#include "ui/gfx/size.h"
[email protected]eab9b452009-01-23 20:48:5935
[email protected]0f34d9082012-10-08 19:16:4436class ExtensionAction;
[email protected]942690b132010-05-11 06:42:1437class ExtensionResource;
[email protected]b6b805e92011-04-16 09:24:1438class FileBrowserHandler;
[email protected]12802702010-07-09 19:43:0939class SkBitmap;
[email protected]daf66aa2010-08-06 06:24:2840class Version;
[email protected]942690b132010-05-11 06:42:1441
[email protected]f3a1c642011-07-12 19:15:0342namespace base {
43class DictionaryValue;
44class ListValue;
45}
46
[email protected]0f34d9082012-10-08 19:16:4447namespace gfx {
48class ImageSkia;
49}
50
[email protected]f0cc7242011-12-13 04:26:1751namespace webkit_glue {
52struct WebIntentServiceData;
53}
54
[email protected]1c321ee2012-05-21 03:02:3455FORWARD_DECLARE_TEST(TabStripModelTest, Apps);
56
57namespace extensions {
58
59class Manifest;
[email protected]bebe1d02012-08-02 20:17:0960class PermissionSet;
[email protected]1c321ee2012-05-21 03:02:3461
[email protected]d4a37f1c2012-07-09 21:36:1362typedef std::set<std::string> OAuth2Scopes;
63
[email protected]f0755532010-06-22 07:27:2564// Represents a Chrome extension.
[email protected]66e4eb32010-10-27 20:37:4165class Extension : public base::RefCountedThreadSafe<Extension> {
[email protected]7713d632008-12-02 07:52:3366 public:
[email protected]1e0f45a2012-06-13 00:31:0667 struct InstallWarning;
68
[email protected]d3cfa482009-10-17 13:54:5769 typedef std::map<const std::string, GURL> URLOverrideMap;
[email protected]10fb1992010-10-08 09:00:1770 typedef std::vector<std::string> ScriptingWhitelist;
[email protected]b6b805e92011-04-16 09:24:1471 typedef std::vector<linked_ptr<FileBrowserHandler> > FileBrowserHandlerList;
[email protected]1e0f45a2012-06-13 00:31:0672 typedef std::vector<InstallWarning> InstallWarningVector;
[email protected]b24d8312009-08-27 06:47:4673
[email protected]631cf822009-05-15 07:01:2574 // What an extension was loaded from.
[email protected]9b217652010-10-08 22:04:2375 // NOTE: These values are stored as integers in the preferences and used
76 // in histograms so don't remove or reorder existing items. Just append
77 // to the end.
[email protected]631cf822009-05-15 07:01:2578 enum Location {
79 INVALID,
[email protected]25b34332009-06-05 21:53:1980 INTERNAL, // A crx file from the internal Extensions directory.
81 EXTERNAL_PREF, // A crx file from an external directory (via prefs).
82 EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the
83 // registry on Windows).
[email protected]1952c7d2010-03-04 23:48:3484 LOAD, // --load-extension.
[email protected]8ef78fd2010-08-19 17:14:3285 COMPONENT, // An integral component of Chrome itself, which
86 // happens to be implemented as an extension. We don't
87 // show these in the management UI.
[email protected]4d2913e32010-11-30 00:28:5588 EXTERNAL_PREF_DOWNLOAD, // A crx file from an external directory (via
89 // prefs), installed from an update URL.
90 EXTERNAL_POLICY_DOWNLOAD, // A crx file from an external directory (via
91 // admin policies), installed from an update URL.
[email protected]04cb7542010-10-25 10:50:0692
93 NUM_LOCATIONS
[email protected]25b34332009-06-05 21:53:1994 };
95
96 enum State {
[email protected]0c6da502009-08-14 22:32:3997 DISABLED = 0,
[email protected]25b34332009-06-05 21:53:1998 ENABLED,
[email protected]79c833b52011-04-05 18:31:0199 // An external extension that the user uninstalled. We should not reinstall
100 // such extensions on startup.
101 EXTERNAL_EXTENSION_UNINSTALLED,
[email protected]0c6da502009-08-14 22:32:39102 NUM_STATES
[email protected]631cf822009-05-15 07:01:25103 };
[email protected]7713d632008-12-02 07:52:33104
[email protected]44d62b62012-04-11 00:06:03105 // Used to record the reason an extension was disabled.
[email protected]eb5e4f92012-08-15 23:33:28106 enum DeprecatedDisableReason {
107 DEPRECATED_DISABLE_UNKNOWN,
108 DEPRECATED_DISABLE_USER_ACTION,
109 DEPRECATED_DISABLE_PERMISSIONS_INCREASE,
110 DEPRECATED_DISABLE_RELOAD,
111 DEPRECATED_DISABLE_LAST, // Not used.
112 };
113
[email protected]44d62b62012-04-11 00:06:03114 enum DisableReason {
[email protected]eb5e4f92012-08-15 23:33:28115 DISABLE_NONE = 0,
116 DISABLE_USER_ACTION = 1 << 0,
117 DISABLE_PERMISSIONS_INCREASE = 1 << 1,
118 DISABLE_RELOAD = 1 << 2,
[email protected]215a7be2012-10-22 19:53:42119 DISABLE_UNSUPPORTED_REQUIREMENT = 1 << 3,
120 DISABLE_SIDELOAD_WIPEOUT = 1 << 4,
[email protected]44d62b62012-04-11 00:06:03121 };
122
[email protected]fbcc40302009-06-12 20:45:45123 enum InstallType {
[email protected]ab6f2b22009-07-28 23:28:37124 INSTALL_ERROR,
[email protected]fbcc40302009-06-12 20:45:45125 DOWNGRADE,
126 REINSTALL,
127 UPGRADE,
128 NEW_INSTALL
129 };
130
[email protected]7fa19f82010-12-21 19:40:08131 // Do not change the order of entries or remove entries in this list
132 // as this is used in UMA_HISTOGRAM_ENUMERATIONs about extensions.
133 enum Type {
[email protected]9b217652010-10-08 22:04:23134 TYPE_UNKNOWN = 0,
135 TYPE_EXTENSION,
136 TYPE_THEME,
137 TYPE_USER_SCRIPT,
138 TYPE_HOSTED_APP,
[email protected]c4f459d2012-09-28 04:40:10139 // This is marked legacy because platform apps are preferred. For
140 // backwards compatibility, we can't remove support for packaged apps
141 TYPE_LEGACY_PACKAGED_APP,
[email protected]7d3ed2f2011-11-07 23:33:19142 TYPE_PLATFORM_APP
[email protected]9b217652010-10-08 22:04:23143 };
144
[email protected]3bdba0d2011-08-23 07:17:30145 enum SyncType {
146 SYNC_TYPE_NONE = 0,
147 SYNC_TYPE_EXTENSION,
148 SYNC_TYPE_APP
149 };
150
[email protected]98270432012-09-11 20:51:24151 // Declared requirements for the extension.
152 struct Requirements {
153 Requirements();
154 ~Requirements();
155
156 bool webgl;
157 bool css3d;
158 bool npapi;
159 };
160
[email protected]92888082010-10-18 19:24:57161 // An NPAPI plugin included in the extension.
162 struct PluginInfo {
163 FilePath path; // Path to the plugin.
164 bool is_public; // False if only this extension can load this plugin.
165 };
166
[email protected]65378f52011-04-08 02:31:23167 // An NaCl module included in the extension.
168 struct NaClModuleInfo {
[email protected]84396dbc2011-04-14 06:33:42169 GURL url;
[email protected]65378f52011-04-08 02:31:23170 std::string mime_type;
171 };
172
[email protected]b0820372011-06-03 07:05:27173 enum InputComponentType {
[email protected]d45f7512011-06-21 21:18:27174 INPUT_COMPONENT_TYPE_NONE = -1,
175 INPUT_COMPONENT_TYPE_IME,
[email protected]b0820372011-06-03 07:05:27176 INPUT_COMPONENT_TYPE_COUNT
177 };
178
179 struct InputComponentInfo {
180 // Define out of line constructor/destructor to please Clang.
181 InputComponentInfo();
182 ~InputComponentInfo();
183
184 std::string name;
185 InputComponentType type;
186 std::string id;
187 std::string description;
188 std::string language;
189 std::set<std::string> layouts;
190 std::string shortcut_keycode;
191 bool shortcut_alt;
192 bool shortcut_ctrl;
193 bool shortcut_shift;
194 };
195
[email protected]a4a38c12010-12-23 16:43:56196 struct TtsVoice {
[email protected]77a3ecac2011-07-07 05:56:33197 // Define out of line constructor/destructor to please Clang.
198 TtsVoice();
199 ~TtsVoice();
200
[email protected]a4a38c12010-12-23 16:43:56201 std::string voice_name;
[email protected]c63f2b72011-07-07 05:25:00202 std::string lang;
[email protected]a4a38c12010-12-23 16:43:56203 std::string gender;
[email protected]c63f2b72011-07-07 05:25:00204 std::set<std::string> event_types;
[email protected]a4a38c12010-12-23 16:43:56205 };
206
[email protected]a79be1f2012-03-23 22:14:00207 // OAuth2 info included in the extension.
208 struct OAuth2Info {
209 OAuth2Info();
210 ~OAuth2Info();
211
[email protected]c2e66e12012-06-27 06:27:06212 OAuth2Scopes GetScopesAsSet();
[email protected]b6f38622012-04-25 03:20:19213
[email protected]a79be1f2012-03-23 22:14:00214 std::string client_id;
215 std::vector<std::string> scopes;
216 };
217
[email protected]0f34d9082012-10-08 19:16:44218 struct ActionInfo {
219 explicit ActionInfo();
220 ~ActionInfo();
221
222 // The types of extension actions.
223 enum Type {
224 TYPE_BROWSER,
225 TYPE_PAGE,
226 TYPE_SCRIPT_BADGE,
227 };
228
229 // Empty implies the key wasn't present.
230 ExtensionIconSet default_icon;
231 std::string default_title;
232 GURL default_popup_url;
233 // action id -- only used with legacy page actions API.
234 std::string id;
235 };
236
[email protected]af8dc08e2012-11-22 01:58:42237 struct FileHandlerInfo {
238 explicit FileHandlerInfo();
239 ~FileHandlerInfo();
240 std::string id;
241 std::string title;
242
243 // File extensions associated with this handler.
244 std::set<std::string> extensions;
245
246 // MIME types associated with this handler.
247 std::set<std::string> types;
248 };
249
[email protected]1e0f45a2012-06-13 00:31:06250 struct InstallWarning {
251 enum Format {
252 // IMPORTANT: Do not build HTML strings from user or developer-supplied
253 // input.
254 FORMAT_TEXT,
255 FORMAT_HTML,
256 };
257 InstallWarning(Format format, const std::string& message)
258 : format(format), message(message) {
259 }
[email protected]18049dc2012-06-19 23:12:55260 bool operator==(const InstallWarning& other) const;
[email protected]1e0f45a2012-06-13 00:31:06261 Format format;
262 std::string message;
263 };
264
[email protected]83048a22011-03-29 00:14:13265 enum InitFromValueFlags {
266 NO_FLAGS = 0,
267
268 // Usually, the id of an extension is generated by the "key" property of
269 // its manifest, but if |REQUIRE_KEY| is not set, a temporary ID will be
270 // generated based on the path.
271 REQUIRE_KEY = 1 << 0,
272
[email protected]3f53dfe2011-11-30 01:18:29273 // Requires the extension to have an up-to-date manifest version.
274 // Typically, we'll support multiple manifest versions during a version
[email protected]26367b62012-10-04 23:03:32275 // transition. This flag signals that we want to require the most modern
[email protected]3f53dfe2011-11-30 01:18:29276 // manifest version that Chrome understands.
277 REQUIRE_MODERN_MANIFEST_VERSION = 1 << 1,
278
[email protected]3aff9ad2011-04-01 20:26:48279 // |ALLOW_FILE_ACCESS| indicates that the user is allowing this extension
280 // to have file access. If it's not present, then permissions and content
281 // scripts that match file:/// URLs will be filtered out.
[email protected]ed3b9b12012-05-31 18:37:51282 ALLOW_FILE_ACCESS = 1 << 2,
[email protected]620db1762011-07-15 21:57:34283
284 // |FROM_WEBSTORE| indicates that the extension was installed from the
285 // Chrome Web Store.
[email protected]ed3b9b12012-05-31 18:37:51286 FROM_WEBSTORE = 1 << 3,
[email protected]e805baf2011-07-26 18:23:05287
288 // |FROM_BOOKMARK| indicates the extension was created using a mock App
289 // created from a bookmark.
[email protected]ed3b9b12012-05-31 18:37:51290 FROM_BOOKMARK = 1 << 4,
[email protected]3d41d432012-04-20 20:47:58291
292 // |FOLLOW_SYMLINKS_ANYWHERE| means that resources can be symlinks to
293 // anywhere in the filesystem, rather than being restricted to the
294 // extension directory.
[email protected]ed3b9b12012-05-31 18:37:51295 FOLLOW_SYMLINKS_ANYWHERE = 1 << 5,
[email protected]ab55c2b2012-06-01 23:55:03296
297 // |ERROR_ON_PRIVATE_KEY| means that private keys inside an
298 // extension should be errors rather than warnings.
299 ERROR_ON_PRIVATE_KEY = 1 << 6,
[email protected]e33bbc22012-08-27 22:05:46300
301 // |WAS_INSTALLED_BY_DEFAULT| installed by default when the profile was
302 // created.
303 WAS_INSTALLED_BY_DEFAULT = 1 << 7,
[email protected]83048a22011-03-29 00:14:13304 };
305
[email protected]66e4eb32010-10-27 20:37:41306 static scoped_refptr<Extension> Create(const FilePath& path,
307 Location location,
[email protected]f3a1c642011-07-12 19:15:03308 const base::DictionaryValue& value,
[email protected]83048a22011-03-29 00:14:13309 int flags,
[email protected]66e4eb32010-10-27 20:37:41310 std::string* error);
311
[email protected]87c655e2011-07-01 21:42:00312 // In a few special circumstances, we want to create an Extension and give it
[email protected]f5bf1842012-02-15 02:52:26313 // an explicit id. Most consumers should just use the other Create() method.
314 static scoped_refptr<Extension> Create(const FilePath& path,
[email protected]58f62cf2012-03-09 10:45:11315 Location location,
316 const base::DictionaryValue& value,
317 int flags,
318 const std::string& explicit_id,
319 std::string* error);
[email protected]87c655e2011-07-01 21:42:00320
[email protected]145a317b2011-04-12 16:03:46321 // Given two install sources, return the one which should take priority
322 // over the other. If an extension is installed from two sources A and B,
323 // its install source should be set to GetHigherPriorityLocation(A, B).
324 static Location GetHigherPriorityLocation(Location loc1, Location loc2);
325
[email protected]4c4f8192009-10-17 01:03:26326 // Max size (both dimensions) for browser and page actions.
327 static const int kPageActionIconMaxSize;
328 static const int kBrowserActionIconMaxSize;
329
[email protected]8d888c12010-11-30 00:00:25330 // Valid schemes for web extent URLPatterns.
331 static const int kValidWebExtentSchemes;
332
[email protected]f71f7e62010-12-07 03:45:33333 // Valid schemes for host permission URLPatterns.
334 static const int kValidHostPermissionSchemes;
335
[email protected]6014d672008-12-05 00:38:25336 // The name of the manifest inside an extension.
[email protected]99efb7b12009-12-18 02:39:16337 static const FilePath::CharType kManifestFilename[];
[email protected]6014d672008-12-05 00:38:25338
[email protected]300cc58db2009-08-19 20:45:14339 // The name of locale folder inside an extension.
[email protected]99efb7b12009-12-18 02:39:16340 static const FilePath::CharType kLocaleFolder[];
[email protected]300cc58db2009-08-19 20:45:14341
342 // The name of the messages file inside an extension.
[email protected]99efb7b12009-12-18 02:39:16343 static const FilePath::CharType kMessagesFilename[];
[email protected]300cc58db2009-08-19 20:45:14344
[email protected]25b34332009-06-05 21:53:19345#if defined(OS_WIN)
[email protected]9dcf8f12010-09-02 20:39:19346 static const char kExtensionRegistryPath[];
[email protected]25b34332009-06-05 21:53:19347#endif
348
[email protected]37eeb5a2009-02-26 23:36:17349 // The number of bytes in a legal id.
[email protected]fe0e7822009-02-26 23:51:48350 static const size_t kIdSize;
[email protected]37eeb5a2009-02-26 23:36:17351
[email protected]e435d6b72009-07-25 03:15:58352 // The mimetype used for extensions.
353 static const char kMimeType[];
354
[email protected]25b34332009-06-05 21:53:19355 // Checks to see if the extension has a valid ID.
356 static bool IdIsValid(const std::string& id);
357
[email protected]4ead6f72010-10-13 19:54:18358 // Generate an ID for an extension in the given path.
[email protected]28d7479b2011-03-09 21:33:27359 // Used while developing extensions, before they have a key.
[email protected]4ead6f72010-10-13 19:54:18360 static std::string GenerateIdForPath(const FilePath& file_name);
361
[email protected]e435d6b72009-07-25 03:15:58362 // Returns true if the specified file is an extension.
363 static bool IsExtension(const FilePath& file_name);
364
[email protected]25b34332009-06-05 21:53:19365 // Whether the |location| is external or not.
366 static inline bool IsExternalLocation(Location location) {
367 return location == Extension::EXTERNAL_PREF ||
[email protected]8ef78fd2010-08-19 17:14:32368 location == Extension::EXTERNAL_REGISTRY ||
[email protected]04cb7542010-10-25 10:50:06369 location == Extension::EXTERNAL_PREF_DOWNLOAD ||
370 location == Extension::EXTERNAL_POLICY_DOWNLOAD;
371 }
372
373 // Whether extensions with |location| are auto-updatable or not.
374 static inline bool IsAutoUpdateableLocation(Location location) {
375 // Only internal and external extensions can be autoupdated.
376 return location == Extension::INTERNAL ||
377 IsExternalLocation(location);
[email protected]25b34332009-06-05 21:53:19378 }
379
[email protected]65187152012-06-02 13:14:14380 // Policy-required extensions are silently auto-installed and updated, and
381 // cannot be disabled or modified by the user in any way. The same applies
382 // to internal components.
383 // This method is not generally called directly; instead, it is accessed
384 // through the ManagementPolicy held by the ExtensionSystem.
385 static inline bool IsRequired(Location location) {
386 return location == Extension::EXTERNAL_POLICY_DOWNLOAD ||
387 location == Extension::COMPONENT;
[email protected]95da88c42011-03-31 10:07:33388 }
389
[email protected]cdfca9702011-08-08 16:07:01390 // Unpacked extensions start off with file access since they are a developer
391 // feature.
392 static inline bool ShouldAlwaysAllowFileAccess(Location location) {
393 return location == Extension::LOAD;
394 }
395
[email protected]fc6b0612012-03-29 13:40:06396 // Fills the |info| dictionary with basic information about the extension.
397 // |enabled| is injected for easier testing.
398 void GetBasicInfo(bool enabled, base::DictionaryValue* info) const;
399
[email protected]7fa19f82010-12-21 19:40:08400 // See Type definition above.
401 Type GetType() const;
[email protected]9b217652010-10-08 22:04:23402
[email protected]07c00d992009-03-04 20:27:04403 // Returns an absolute url to a resource inside of an extension. The
[email protected]eab9b452009-01-23 20:48:59404 // |extension_url| argument should be the url() from an Extension object. The
405 // |relative_path| can be untrusted user input. The returned URL will either
406 // be invalid() or a child of |extension_url|.
407 // NOTE: Static so that it can be used from multiple threads.
408 static GURL GetResourceURL(const GURL& extension_url,
409 const std::string& relative_path);
[email protected]cffd7892010-08-26 17:43:28410 GURL GetResourceURL(const std::string& relative_path) const {
[email protected]3cfbd0e2009-03-18 21:26:24411 return GetResourceURL(url(), relative_path);
412 }
[email protected]eab9b452009-01-23 20:48:59413
[email protected]f59a8052012-06-20 22:25:00414 // Returns true if the resource matches a pattern in the pattern_set.
415 bool ResourceMatches(const URLPatternSet& pattern_set,
416 const std::string& resource) const;
417
[email protected]8f270be2011-12-21 21:15:22418 // Returns true if the specified resource is web accessible.
419 bool IsResourceWebAccessible(const std::string& relative_path) const;
420
[email protected]dbb24162012-06-06 01:41:22421 // Returns true if the specified page is sandboxed (served in a unique
422 // origin).
423 bool IsSandboxedPage(const std::string& relative_path) const;
424
425 // Returns the Content Security Policy that the specified resource should be
426 // served with.
427 std::string GetResourceContentSecurityPolicy(const std::string& relative_path)
428 const;
429
[email protected]8f270be2011-12-21 21:15:22430 // Returns true when 'web_accessible_resources' are defined for the extension.
431 bool HasWebAccessibleResources() const;
432
[email protected]99efb7b12009-12-18 02:39:16433 // Returns an extension resource object. |relative_path| should be UTF8
434 // encoded.
[email protected]9adb9692010-10-29 23:14:02435 ExtensionResource GetResource(const std::string& relative_path) const;
[email protected]99efb7b12009-12-18 02:39:16436
437 // As above, but with |relative_path| following the file system's encoding.
[email protected]9adb9692010-10-29 23:14:02438 ExtensionResource GetResource(const FilePath& relative_path) const;
[email protected]eab9b452009-01-23 20:48:59439
[email protected]a17f9462009-06-09 02:56:41440 // |input| is expected to be the text of an rsa public or private key. It
441 // tolerates the presence or absence of bracking header/footer like this:
442 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
443 // and may contain newlines.
444 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
445
446 // Does a simple base64 encoding of |input| into |output|.
447 static bool ProducePEM(const std::string& input, std::string* output);
448
[email protected]84ac7f32009-10-06 06:17:54449 // Generates an extension ID from arbitrary input. The same input string will
450 // always generate the same output ID.
[email protected]af9db5f2011-10-05 05:13:15451 static bool GenerateId(const std::string& input,
452 std::string* output) WARN_UNUSED_RESULT;
[email protected]fbcc40302009-06-12 20:45:45453
[email protected]a17f9462009-06-09 02:56:41454 // Expects base64 encoded |input| and formats into |output| including
455 // the appropriate header & footer.
[email protected]e0d08192011-03-29 19:02:50456 static bool FormatPEMForFileOutput(const std::string& input,
457 std::string* output,
458 bool is_public);
[email protected]a17f9462009-06-09 02:56:41459
[email protected]58f62cf2012-03-09 10:45:11460 // Given an extension, icon size, and match type, read a valid icon if present
[email protected]e3c0bc22012-02-24 01:34:15461 // and decode it into result. In the browser process, this will DCHECK if not
462 // called on the file thread. To easily load extension images on the UI
463 // thread, see ImageLoadingTracker.
464 static void DecodeIcon(const Extension* extension,
[email protected]faf87192012-08-17 00:07:59465 int icon_size,
[email protected]e3c0bc22012-02-24 01:34:15466 ExtensionIconSet::MatchType match_type,
467 scoped_ptr<SkBitmap>* result);
468
[email protected]c690a9812009-12-17 05:55:32469 // Given an extension and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23470 // result. In the browser process, this will DCHECK if not called on the
471 // file thread. To easily load extension images on the UI thread, see
472 // ImageLoadingTracker.
[email protected]9adb9692010-10-29 23:14:02473 static void DecodeIcon(const Extension* extension,
[email protected]faf87192012-08-17 00:07:59474 int icon_size,
[email protected]c690a9812009-12-17 05:55:32475 scoped_ptr<SkBitmap>* result);
476
477 // Given an icon_path and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23478 // result. In the browser process, this will DCHECK if not called on the
479 // file thread. To easily load extension images on the UI thread, see
480 // ImageLoadingTracker.
[email protected]c690a9812009-12-17 05:55:32481 static void DecodeIconFromPath(const FilePath& icon_path,
[email protected]faf87192012-08-17 00:07:59482 int icon_size,
[email protected]c690a9812009-12-17 05:55:32483 scoped_ptr<SkBitmap>* result);
484
[email protected]5349ac6d2011-04-05 22:20:17485 // Returns the default extension/app icon (for extensions or apps that don't
486 // have one).
[email protected]dd46a4ce2012-09-15 10:50:50487 static const gfx::ImageSkia& GetDefaultIcon(bool is_app);
[email protected]5349ac6d2011-04-05 22:20:17488
[email protected]a807bbe2010-04-14 10:51:19489 // Returns the base extension url for a given |extension_id|.
490 static GURL GetBaseURLFromExtensionId(const std::string& extension_id);
491
[email protected]be7e5cb2010-10-04 12:53:17492 // Adds an extension to the scripting whitelist. Used for testing only.
[email protected]10fb1992010-10-08 09:00:17493 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist);
[email protected]2a521c52011-01-26 18:45:21494 static const ScriptingWhitelist* GetScriptingWhitelist();
[email protected]be7e5cb2010-10-04 12:53:17495
[email protected]902fd7b2011-07-27 18:42:31496 // Parses the host and api permissions from the specified permission |key|
[email protected]d41e2152012-02-24 04:20:27497 // from |manifest_|.
498 bool ParsePermissions(const char* key,
[email protected]fc670822011-12-17 09:33:49499 string16* error,
[email protected]c2e66e12012-06-27 06:27:06500 APIPermissionSet* api_permissions,
[email protected]902fd7b2011-07-27 18:42:31501 URLPatternSet* host_permissions);
502
[email protected]c2e66e12012-06-27 06:27:06503 bool HasAPIPermission(APIPermission::ID permission) const;
[email protected]0d3e4a22011-06-23 19:02:52504 bool HasAPIPermission(const std::string& function_name) const;
[email protected]3d0e2262012-08-02 15:32:16505 bool HasAPIPermissionForTab(int tab_id, APIPermission::ID permission) const;
[email protected]583d45c12010-08-31 02:48:12506
[email protected]ecb9ad12012-08-21 13:02:15507 bool CheckAPIPermissionWithParam(APIPermission::ID permission,
508 const APIPermission::CheckParam* param) const;
[email protected]1d8b79a2012-08-16 20:22:54509
[email protected]0d3e4a22011-06-23 19:02:52510 const URLPatternSet& GetEffectiveHostPermissions() const;
[email protected]b24d8312009-08-27 06:47:46511
[email protected]902fd7b2011-07-27 18:42:31512 // Returns true if the extension can silently increase its permission level.
[email protected]0d904312012-01-25 23:00:16513 // Users must approve permissions for unpacked and packed extensions in the
514 // following situations:
515 // - when installing or upgrading packed extensions
516 // - when installing unpacked extensions that have NPAPI plugins
517 // - when either type of extension requests optional permissions
[email protected]902fd7b2011-07-27 18:42:31518 bool CanSilentlyIncreasePermissions() const;
519
[email protected]584b8e3f2010-04-10 00:23:37520 // Whether the extension has access to the given URL.
521 bool HasHostPermission(const GURL& url) const;
522
[email protected]0df165f2010-09-28 16:49:40523 // Whether the extension has effective access to all hosts. This is true if
524 // there is a content script that matches all hosts, if there is a host
525 // permission grants access to all hosts (like <all_urls>) or an api
526 // permission that effectively grants access to all hosts (e.g. proxy,
527 // network, etc.)
528 bool HasEffectiveAccessToAllHosts() const;
[email protected]b24d8312009-08-27 06:47:46529
[email protected]8d888c12010-11-30 00:00:25530 // Whether the extension effectively has all permissions (for example, by
531 // having an NPAPI plugin).
532 bool HasFullPermissions() const;
533
[email protected]902fd7b2011-07-27 18:42:31534 // Returns the full list of permission messages that this extension
535 // should display at install time.
[email protected]c2e66e12012-06-27 06:27:06536 PermissionMessages GetPermissionMessages() const;
[email protected]902fd7b2011-07-27 18:42:31537
538 // Returns the full list of permission messages that this extension
539 // should display at install time. The messages are returned as strings
540 // for convenience.
541 std::vector<string16> GetPermissionMessageStrings() const;
542
[email protected]b0d1d0b2012-11-02 21:19:03543 // Returns true if the extension does not require permission warnings
544 // to be displayed at install time.
545 bool ShouldSkipPermissionWarnings() const;
546
[email protected]902fd7b2011-07-27 18:42:31547 // Sets the active |permissions|.
[email protected]c2e66e12012-06-27 06:27:06548 void SetActivePermissions(const PermissionSet* permissions) const;
[email protected]902fd7b2011-07-27 18:42:31549
550 // Gets the extension's active permission set.
[email protected]c2e66e12012-06-27 06:27:06551 scoped_refptr<const PermissionSet> GetActivePermissions() const;
[email protected]902fd7b2011-07-27 18:42:31552
[email protected]5df6a5d2011-01-26 07:39:12553 // Whether context menu should be shown for page and browser actions.
554 bool ShowConfigureContextMenus() const;
555
[email protected]37cd64d2010-10-25 18:17:58556 // Returns the Homepage URL for this extension. If homepage_url was not
557 // specified in the manifest, this returns the Google Gallery URL. For
[email protected]bfa90a3a2010-04-28 15:43:23558 // third-party extensions, this returns a blank GURL.
[email protected]37cd64d2010-10-25 18:17:58559 GURL GetHomepageURL() const;
[email protected]bfa90a3a2010-04-28 15:43:23560
[email protected]facd7a7652009-06-05 23:15:02561 // Returns a list of paths (relative to the extension dir) for images that
562 // the browser might load (like themes and page action icons).
[email protected]9adb9692010-10-29 23:14:02563 std::set<FilePath> GetBrowserImages() const;
[email protected]facd7a7652009-06-05 23:15:02564
[email protected]807871f2010-09-16 01:04:48565 // Get an extension icon as a resource or URL.
[email protected]9adb9692010-10-29 23:14:02566 ExtensionResource GetIconResource(
567 int size, ExtensionIconSet::MatchType match_type) const;
568 GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const;
[email protected]f34e79632010-03-17 02:34:08569
[email protected]867a73e12010-03-19 20:45:46570 // Gets the fully resolved absolute launch URL.
571 GURL GetFullLaunchURL() const;
[email protected]2a521c52011-01-26 18:45:21572
[email protected]6f229e82010-11-02 17:47:26573 // Image cache related methods. These are only valid on the UI thread and
574 // not maintained by this class. See ImageLoadingTracker for usage. The
575 // |original_size| parameter should be the size of the image at |source|
576 // before any scaling may have been done to produce the pixels in |image|.
577 void SetCachedImage(const ExtensionResource& source,
578 const SkBitmap& image,
579 const gfx::Size& original_size) const;
580 bool HasCachedImage(const ExtensionResource& source,
581 const gfx::Size& max_size) const;
582 SkBitmap GetCachedImage(const ExtensionResource& source,
583 const gfx::Size& max_size) const;
[email protected]2a521c52011-01-26 18:45:21584
585 // Returns true if this extension can execute script on a page. If a
586 // UserScript object is passed, permission to run that specific script is
587 // checked (using its matches list). Otherwise, permission to execute script
588 // programmatically is checked (using the extension's host permission).
589 //
590 // This method is also aware of certain special pages that extensions are
591 // usually not allowed to run script on.
[email protected]78bdfd662012-08-23 05:53:18592 bool CanExecuteScriptOnPage(const GURL& document_url,
593 const GURL& top_document_url,
[email protected]fc5e65d6b2012-06-13 00:22:57594 int tab_id,
[email protected]3aff9ad2011-04-01 20:26:48595 const UserScript* script,
[email protected]2a521c52011-01-26 18:45:21596 std::string* error) const;
597
[email protected]6f229e82010-11-02 17:47:26598 // Returns true if this extension is a COMPONENT extension, or if it is
599 // on the whitelist of extensions that can script all pages.
600 bool CanExecuteScriptEverywhere() const;
601
[email protected]5efbfe012011-02-22 23:07:18602 // Returns true if this extension is allowed to obtain the contents of a
603 // page as an image. Since a page may contain sensitive information, this
604 // is restricted to the extension's host permissions as well as the
605 // extension page itself.
[email protected]fc5e65d6b2012-06-13 00:22:57606 bool CanCaptureVisiblePage(const GURL& page_url,
607 int tab_id,
608 std::string* error) const;
[email protected]5efbfe012011-02-22 23:07:18609
[email protected]a65882c2010-11-12 15:15:09610 // Returns true if this extension updates itself using the extension
611 // gallery.
612 bool UpdatesFromGallery() const;
613
[email protected]cca147172011-02-17 01:29:29614 // Returns true if this extension or app includes areas within |origin|.
615 bool OverlapsWithOrigin(const GURL& origin) const;
616
[email protected]3bdba0d2011-08-23 07:17:30617 // Returns the sync bucket to use for this extension.
618 SyncType GetSyncType() const;
619
[email protected]b873cd92012-02-09 21:51:48620 // Returns true if the extension should be synced.
621 bool IsSyncable() const;
622
[email protected]7e0f92b2012-11-09 03:51:04623 // Returns true if the extension requires a valid ordinal for sorting, e.g.,
624 // for displaying in a launcher or new tab page.
625 bool RequiresSortOrdinal() const;
626
627 // Returns true if the extension should be displayed in the app launcher.
628 bool ShouldDisplayInAppLauncher() const;
629
630 // Returns true if the extension should be displayed in the browser NTP.
631 bool ShouldDisplayInNewTabPage() const;
[email protected]b873cd92012-02-09 21:51:48632
[email protected]e0b3de72012-05-01 01:21:34633 // Returns true if the extension should be displayed in the extension
634 // settings page (i.e. chrome://extensions).
635 bool ShouldDisplayInExtensionSettings() const;
636
[email protected]4f886012012-05-19 03:51:10637 // Returns true if the extension has a content script declared at |url|.
638 bool HasContentScriptAtURL(const GURL& url) const;
639
[email protected]fc5e65d6b2012-06-13 00:22:57640 // Gets the tab-specific host permissions of |tab_id|, or NULL if there
641 // aren't any.
[email protected]3d0e2262012-08-02 15:32:16642 scoped_refptr<const PermissionSet> GetTabSpecificPermissions(int tab_id)
643 const;
[email protected]fc5e65d6b2012-06-13 00:22:57644
[email protected]3d0e2262012-08-02 15:32:16645 // Updates the tab-specific permissions of |tab_id| to include those from
646 // |permissions|.
[email protected]6144057e2012-08-02 19:02:37647 void UpdateTabSpecificPermissions(
648 int tab_id,
649 scoped_refptr<const PermissionSet> permissions) const;
[email protected]fc5e65d6b2012-06-13 00:22:57650
[email protected]3d0e2262012-08-02 15:32:16651 // Clears the tab-specific permissions of |tab_id|.
652 void ClearTabSpecificPermissions(int tab_id) const;
[email protected]fc5e65d6b2012-06-13 00:22:57653
[email protected]6f229e82010-11-02 17:47:26654 // Accessors:
655
[email protected]98270432012-09-11 20:51:24656 const Requirements& requirements() const { return requirements_; }
[email protected]6f229e82010-11-02 17:47:26657 const FilePath& path() const { return path_; }
658 const GURL& url() const { return extension_url_; }
[email protected]d41e2152012-02-24 04:20:27659 Location location() const;
660 const std::string& id() const;
[email protected]6f229e82010-11-02 17:47:26661 const Version* version() const { return version_.get(); }
662 const std::string VersionString() const;
663 const std::string& name() const { return name_; }
[email protected]701d1e82012-05-14 05:34:19664 const std::string& non_localized_name() const { return non_localized_name_; }
[email protected]200423d2012-06-05 01:16:06665 // Base64-encoded version of the key used to sign this extension.
666 // In pseudocode, returns
667 // base::Base64Encode(RSAPrivateKey(pem_file).ExportPublicKey()).
668 const std::string& public_key() const { return public_key_; }
[email protected]6f229e82010-11-02 17:47:26669 const std::string& description() const { return description_; }
[email protected]a47c8a22011-11-17 18:40:31670 int manifest_version() const { return manifest_version_; }
[email protected]6f229e82010-11-02 17:47:26671 bool converted_from_user_script() const {
672 return converted_from_user_script_;
673 }
674 const UserScriptList& content_scripts() const { return content_scripts_; }
[email protected]0f34d9082012-10-08 19:16:44675 const ActionInfo* script_badge_info() const {
676 return script_badge_info_.get();
677 }
678 const ActionInfo* page_action_info() const { return page_action_info_.get(); }
679 const ActionInfo* browser_action_info() const {
680 return browser_action_info_.get();
681 }
[email protected]5d414702012-08-28 13:03:09682 bool is_verbose_install_message() const {
683 return !omnibox_keyword().empty() ||
[email protected]0f34d9082012-10-08 19:16:44684 browser_action_info() ||
685 (page_action_info() &&
686 (page_action_command() ||
687 !page_action_info()->default_icon.empty()));
[email protected]5d414702012-08-28 13:03:09688 }
[email protected]b6b805e92011-04-16 09:24:14689 const FileBrowserHandlerList* file_browser_handlers() const {
690 return file_browser_handlers_.get();
691 }
[email protected]6f229e82010-11-02 17:47:26692 const std::vector<PluginInfo>& plugins() const { return plugins_; }
[email protected]65378f52011-04-08 02:31:23693 const std::vector<NaClModuleInfo>& nacl_modules() const {
694 return nacl_modules_;
695 }
[email protected]b0820372011-06-03 07:05:27696 const std::vector<InputComponentInfo>& input_components() const {
697 return input_components_;
698 }
[email protected]7c519ab2012-05-04 10:02:51699 // The browser action command that the extension wants to use, which is not
700 // necessarily the one it can use, as it might be inactive (see also
[email protected]d179cdd2012-08-03 08:32:52701 // GetBrowserActionCommand in CommandService).
[email protected]3fc5f6a2012-05-04 14:23:59702 const extensions::Command* browser_action_command() const {
[email protected]9c8b54d2012-04-02 10:17:30703 return browser_action_command_.get();
704 }
[email protected]7c519ab2012-05-04 10:02:51705 // The page action command that the extension wants to use, which is not
706 // necessarily the one it can use, as it might be inactive (see also
[email protected]d179cdd2012-08-03 08:32:52707 // GetPageActionCommand in CommandService).
[email protected]3fc5f6a2012-05-04 14:23:59708 const extensions::Command* page_action_command() const {
[email protected]9c8b54d2012-04-02 10:17:30709 return page_action_command_.get();
710 }
[email protected]d179cdd2012-08-03 08:32:52711 // The script badge command that the extension wants to use, which is not
712 // necessarily the one it can use, as it might be inactive (see also
713 // GetScriptBadgeCommand in CommandService).
714 const extensions::Command* script_badge_command() const {
715 return script_badge_command_.get();
716 }
[email protected]7c519ab2012-05-04 10:02:51717 // The map (of command names to commands) that the extension wants to use,
[email protected]422656932012-05-03 09:31:51718 // which is not necessarily the one it can use, as they might be inactive
[email protected]d179cdd2012-08-03 08:32:52719 // (see also GetNamedCommands in CommandService).
[email protected]3fc5f6a2012-05-04 14:23:59720 const extensions::CommandMap& named_commands() const {
[email protected]9c8b54d2012-04-02 10:17:30721 return named_commands_;
[email protected]f5532472012-02-23 13:00:55722 }
[email protected]a03d4448f2012-01-10 23:25:28723 bool has_background_page() const {
724 return background_url_.is_valid() || !background_scripts_.empty();
725 }
[email protected]7b54ca02012-03-02 18:06:53726 bool allow_background_js_access() const {
727 return allow_background_js_access_;
728 }
[email protected]a03d4448f2012-01-10 23:25:28729 const std::vector<std::string>& background_scripts() const {
730 return background_scripts_;
731 }
[email protected]d2aa06b2012-03-21 20:57:26732 bool has_persistent_background_page() const {
[email protected]dd62fa802012-04-25 18:37:00733 return has_background_page() && background_page_is_persistent_;
[email protected]d2aa06b2012-03-21 20:57:26734 }
735 bool has_lazy_background_page() const {
[email protected]dd62fa802012-04-25 18:37:00736 return has_background_page() && !background_page_is_persistent_;
[email protected]d2aa06b2012-03-21 20:57:26737 }
[email protected]6f229e82010-11-02 17:47:26738 const GURL& options_url() const { return options_url_; }
739 const GURL& devtools_url() const { return devtools_url_; }
[email protected]81ca71652012-08-23 22:28:26740 const GURL& details_url() const { return details_url_;}
[email protected]c2e66e12012-06-27 06:27:06741 const PermissionSet* optional_permission_set() const {
[email protected]902fd7b2011-07-27 18:42:31742 return optional_permission_set_.get();
743 }
[email protected]c2e66e12012-06-27 06:27:06744 const PermissionSet* required_permission_set() const {
[email protected]902fd7b2011-07-27 18:42:31745 return required_permission_set_.get();
[email protected]6f229e82010-11-02 17:47:26746 }
[email protected]ab55c2b2012-06-01 23:55:03747 // Appends |new_warnings| to install_warnings().
[email protected]1e0f45a2012-06-13 00:31:06748 void AddInstallWarnings(const InstallWarningVector& new_warnings);
749 const InstallWarningVector& install_warnings() const {
[email protected]8629c542012-04-20 03:40:03750 return install_warnings_;
751 }
[email protected]6f229e82010-11-02 17:47:26752 const GURL& update_url() const { return update_url_; }
753 const ExtensionIconSet& icons() const { return icons_; }
[email protected]953620b2011-12-04 00:55:32754 const extensions::Manifest* manifest() const {
[email protected]e9629d772012-08-06 19:44:46755 return manifest_.get();
[email protected]6f229e82010-11-02 17:47:26756 }
757 const std::string default_locale() const { return default_locale_; }
758 const URLOverrideMap& GetChromeURLOverrides() const {
759 return chrome_url_overrides_;
760 }
761 const std::string omnibox_keyword() const { return omnibox_keyword_; }
762 bool incognito_split_mode() const { return incognito_split_mode_; }
[email protected]1abdf4f2011-08-16 21:11:55763 bool offline_enabled() const { return offline_enabled_; }
[email protected]a4a38c12010-12-23 16:43:56764 const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; }
[email protected]a79be1f2012-03-23 22:14:00765 const OAuth2Info& oauth2_info() const { return oauth2_info_; }
[email protected]56624422011-11-01 22:11:27766 const std::vector<webkit_glue::WebIntentServiceData>&
767 intents_services() const {
768 return intents_services_;
769 }
[email protected]6f229e82010-11-02 17:47:26770
[email protected]3aff9ad2011-04-01 20:26:48771 bool wants_file_access() const { return wants_file_access_; }
[email protected]2af352b2011-07-22 08:21:23772 int creation_flags() const { return creation_flags_; }
773 bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; }
[email protected]e805baf2011-07-26 18:23:05774 bool from_bookmark() const { return (creation_flags_ & FROM_BOOKMARK) != 0; }
[email protected]e33bbc22012-08-27 22:05:46775 bool was_installed_by_default() const {
776 return (creation_flags_ & WAS_INSTALLED_BY_DEFAULT) != 0;
777 }
[email protected]3aff9ad2011-04-01 20:26:48778
[email protected]6f229e82010-11-02 17:47:26779 // App-related.
[email protected]953620b2011-12-04 00:55:32780 bool is_app() const {
[email protected]c4f459d2012-09-28 04:40:10781 return is_legacy_packaged_app() || is_hosted_app() || is_platform_app();
[email protected]23690872011-12-01 22:02:39782 }
[email protected]d41e2152012-02-24 04:20:27783 bool is_platform_app() const;
784 bool is_hosted_app() const;
[email protected]c4f459d2012-09-28 04:40:10785 bool is_legacy_packaged_app() const;
[email protected]605fb8102012-05-04 01:36:55786 bool is_storage_isolated() const { return is_storage_isolated_; }
[email protected]cced75a2011-05-20 08:31:12787 const URLPatternSet& web_extent() const { return extent_; }
[email protected]6f229e82010-11-02 17:47:26788 const std::string& launch_local_path() const { return launch_local_path_; }
789 const std::string& launch_web_url() const { return launch_web_url_; }
790 extension_misc::LaunchContainer launch_container() const {
791 return launch_container_;
792 }
[email protected]dc37b002012-04-23 23:02:26793 int launch_width() const { return launch_width_; }
794 int launch_height() const { return launch_height_; }
[email protected]6f229e82010-11-02 17:47:26795
[email protected]af8dc08e2012-11-22 01:58:42796 const std::vector<FileHandlerInfo>& file_handlers() const {
797 return file_handlers_;
798 }
799
[email protected]6f229e82010-11-02 17:47:26800 // Theme-related.
[email protected]d41e2152012-02-24 04:20:27801 bool is_theme() const;
[email protected]f3a1c642011-07-12 19:15:03802 base::DictionaryValue* GetThemeImages() const { return theme_images_.get(); }
803 base::DictionaryValue* GetThemeColors() const {return theme_colors_.get(); }
804 base::DictionaryValue* GetThemeTints() const { return theme_tints_.get(); }
805 base::DictionaryValue* GetThemeDisplayProperties() const {
[email protected]6f229e82010-11-02 17:47:26806 return theme_display_properties_.get();
807 }
808
[email protected]6d55bd62012-11-21 17:52:03809 // Content Security Policy!
810 const std::string& content_security_policy() const {
811 return content_security_policy_;
812 }
813
[email protected]a03d4448f2012-01-10 23:25:28814 GURL GetBackgroundURL() const;
815
[email protected]4a8d3272009-03-10 19:15:08816 private:
[email protected]66e4eb32010-10-27 20:37:41817 friend class base::RefCountedThreadSafe<Extension>;
818
[email protected]d7e9a862010-11-03 21:57:49819 // We keep a cache of images loaded from extension resources based on their
820 // path and a string representation of a size that may have been used to
821 // scale it (or the empty string if the image is at its original size).
822 typedef std::pair<FilePath, std::string> ImageCacheKey;
823 typedef std::map<ImageCacheKey, SkBitmap> ImageCache;
824
[email protected]902fd7b2011-07-27 18:42:31825 class RuntimeData {
826 public:
827 RuntimeData();
[email protected]c2e66e12012-06-27 06:27:06828 explicit RuntimeData(const PermissionSet* active);
[email protected]902fd7b2011-07-27 18:42:31829 ~RuntimeData();
830
[email protected]c2e66e12012-06-27 06:27:06831 void SetActivePermissions(const PermissionSet* active);
832 scoped_refptr<const PermissionSet> GetActivePermissions() const;
[email protected]902fd7b2011-07-27 18:42:31833
[email protected]3d0e2262012-08-02 15:32:16834 scoped_refptr<const PermissionSet> GetTabSpecificPermissions(int tab_id)
835 const;
[email protected]6144057e2012-08-02 19:02:37836 void UpdateTabSpecificPermissions(
837 int tab_id,
838 scoped_refptr<const PermissionSet> permissions);
[email protected]3d0e2262012-08-02 15:32:16839 void ClearTabSpecificPermissions(int tab_id);
[email protected]fc5e65d6b2012-06-13 00:22:57840
[email protected]902fd7b2011-07-27 18:42:31841 private:
842 friend class base::RefCountedThreadSafe<RuntimeData>;
[email protected]fc5e65d6b2012-06-13 00:22:57843
[email protected]c2e66e12012-06-27 06:27:06844 scoped_refptr<const PermissionSet> active_permissions_;
[email protected]fc5e65d6b2012-06-13 00:22:57845
[email protected]3d0e2262012-08-02 15:32:16846 typedef std::map<int, scoped_refptr<const PermissionSet> >
847 TabPermissionsMap;
848 TabPermissionsMap tab_specific_permissions_;
[email protected]902fd7b2011-07-27 18:42:31849 };
850
[email protected]d41e2152012-02-24 04:20:27851 // Chooses the extension ID for an extension based on a variety of criteria.
852 // The chosen ID will be set in |manifest|.
853 static bool InitExtensionID(extensions::Manifest* manifest,
854 const FilePath& path,
855 const std::string& explicit_id,
856 int creation_flags,
857 string16* error);
858
[email protected]4ead6f72010-10-13 19:54:18859 // Normalize the path for use by the extension. On Windows, this will make
860 // sure the drive letter is uppercase.
861 static FilePath MaybeNormalizePath(const FilePath& path);
862
[email protected]87c655e2011-07-01 21:42:00863 // Returns true if this extension id is from a trusted provider.
864 static bool IsTrustedId(const std::string& id);
865
[email protected]d41e2152012-02-24 04:20:27866 Extension(const FilePath& path, scoped_ptr<extensions::Manifest> manifest);
[email protected]66e4eb32010-10-27 20:37:41867 ~Extension();
868
869 // Initialize the extension from a parsed manifest.
[email protected]d41e2152012-02-24 04:20:27870 // TODO(aa): Rename to just Init()? There's no Value here anymore.
871 // TODO(aa): It is really weird the way this class essentially contains a copy
872 // of the underlying DictionaryValue in its members. We should decide to
873 // either wrap the DictionaryValue and go with that only, or we should parse
874 // into strong types and discard the value. But doing both is bad.
875 bool InitFromValue(int flags, string16* error);
[email protected]66e4eb32010-10-27 20:37:41876
[email protected]58f62cf2012-03-09 10:45:11877 // The following are helpers for InitFromValue to load various features of the
878 // extension from the manifest.
879
[email protected]c2e66e12012-06-27 06:27:06880 bool LoadAppIsolation(const APIPermissionSet& api_permissions,
[email protected]605fb8102012-05-04 01:36:55881 string16* error);
[email protected]58f62cf2012-03-09 10:45:11882
883 bool LoadRequiredFeatures(string16* error);
884 bool LoadName(string16* error);
885 bool LoadVersion(string16* error);
886
887 bool LoadAppFeatures(string16* error);
[email protected]d41e2152012-02-24 04:20:27888 bool LoadExtent(const char* key,
889 URLPatternSet* extent,
890 const char* list_error,
891 const char* value_error,
892 string16* error);
893 bool LoadLaunchContainer(string16* error);
894 bool LoadLaunchURL(string16* error);
[email protected]10253da2012-03-09 04:06:42895
[email protected]c2e66e12012-06-27 06:27:06896 bool LoadSharedFeatures(const APIPermissionSet& api_permissions,
[email protected]58f62cf2012-03-09 10:45:11897 string16* error);
898 bool LoadDescription(string16* error);
899 bool LoadManifestVersion(string16* error);
900 bool LoadHomepageURL(string16* error);
901 bool LoadUpdateURL(string16* error);
902 bool LoadIcons(string16* error);
903 bool LoadCommands(string16* error);
904 bool LoadPlugins(string16* error);
905 bool LoadNaClModules(string16* error);
906 bool LoadWebAccessibleResources(string16* error);
[email protected]dbb24162012-06-06 01:41:22907 bool LoadSandboxedPages(string16* error);
[email protected]98270432012-09-11 20:51:24908 // Must be called after LoadPlugins().
909 bool LoadRequirements(string16* error);
[email protected]58f62cf2012-03-09 10:45:11910 bool LoadDefaultLocale(string16* error);
911 bool LoadOfflineEnabled(string16* error);
912 bool LoadOptionsPage(string16* error);
[email protected]d41e2152012-02-24 04:20:27913 bool LoadBackgroundScripts(string16* error);
[email protected]756038532012-06-08 05:45:03914 bool LoadBackgroundScripts(const std::string& key, string16* error);
[email protected]c2e66e12012-06-27 06:27:06915 bool LoadBackgroundPage(const APIPermissionSet& api_permissions,
[email protected]d41e2152012-02-24 04:20:27916 string16* error);
[email protected]756038532012-06-08 05:45:03917 bool LoadBackgroundPage(const std::string& key,
[email protected]c2e66e12012-06-27 06:27:06918 const APIPermissionSet& api_permissions,
[email protected]756038532012-06-08 05:45:03919 string16* error);
[email protected]dd62fa802012-04-25 18:37:00920 bool LoadBackgroundPersistent(
[email protected]c2e66e12012-06-27 06:27:06921 const APIPermissionSet& api_permissions,
[email protected]d41e2152012-02-24 04:20:27922 string16* error);
[email protected]58f62cf2012-03-09 10:45:11923 bool LoadBackgroundAllowJSAccess(
[email protected]c2e66e12012-06-27 06:27:06924 const APIPermissionSet& api_permissions,
[email protected]7b54ca02012-03-02 18:06:53925 string16* error);
[email protected]58f62cf2012-03-09 10:45:11926 // Parses a single action in the manifest.
927 bool LoadWebIntentAction(const std::string& action_name,
928 const base::DictionaryValue& intent_service,
929 string16* error);
930 bool LoadWebIntentServices(string16* error);
[email protected]5446907e2012-11-02 05:46:29931 bool LoadFileHandler(const std::string& handler_id,
932 const base::DictionaryValue& handler_info,
933 string16* error);
934 bool LoadFileHandlers(string16* error);
[email protected]c2e66e12012-06-27 06:27:06935 bool LoadExtensionFeatures(const APIPermissionSet& api_permissions,
[email protected]58f62cf2012-03-09 10:45:11936 string16* error);
937 bool LoadDevToolsPage(string16* error);
[email protected]c2e66e12012-06-27 06:27:06938 bool LoadInputComponents(const APIPermissionSet& api_permissions,
[email protected]58f62cf2012-03-09 10:45:11939 string16* error);
940 bool LoadContentScripts(string16* error);
941 bool LoadPageAction(string16* error);
942 bool LoadBrowserAction(string16* error);
[email protected]18049dc2012-06-19 23:12:55943 bool LoadScriptBadge(string16* error);
[email protected]58f62cf2012-03-09 10:45:11944 bool LoadFileBrowserHandlers(string16* error);
945 // Helper method to load a FileBrowserHandlerList from the manifest.
946 FileBrowserHandlerList* LoadFileBrowserHandlersHelper(
947 const base::ListValue* extension_actions, string16* error);
948 // Helper method to load an FileBrowserHandler from manifest.
949 FileBrowserHandler* LoadFileBrowserHandler(
950 const base::DictionaryValue* file_browser_handlers, string16* error);
951 bool LoadChromeURLOverrides(string16* error);
952 bool LoadOmnibox(string16* error);
953 bool LoadTextToSpeechVoices(string16* error);
954 bool LoadIncognitoMode(string16* error);
955 bool LoadContentSecurityPolicy(string16* error);
956
957 bool LoadThemeFeatures(string16* error);
958 bool LoadThemeImages(const base::DictionaryValue* theme_value,
959 string16* error);
960 bool LoadThemeColors(const base::DictionaryValue* theme_value,
961 string16* error);
962 bool LoadThemeTints(const base::DictionaryValue* theme_value,
963 string16* error);
964 bool LoadThemeDisplayProperties(const base::DictionaryValue* theme_value,
965 string16* error);
966
967 // Helper function for implementing HasCachedImage/GetCachedImage. A return
968 // value of NULL means there is no matching image cached (we allow caching an
969 // empty SkBitmap).
970 SkBitmap* GetCachedImageImpl(const ExtensionResource& source,
971 const gfx::Size& max_size) const;
[email protected]d9ad80f2010-03-30 20:40:18972
[email protected]3cfbd0e2009-03-18 21:26:24973 // Helper method that loads a UserScript object from a
974 // dictionary in the content_script list of the manifest.
[email protected]f3a1c642011-07-12 19:15:03975 bool LoadUserScriptHelper(const base::DictionaryValue* content_script,
[email protected]3cfbd0e2009-03-18 21:26:24976 int definition_index,
[email protected]fc670822011-12-17 09:33:49977 string16* error,
[email protected]3cfbd0e2009-03-18 21:26:24978 UserScript* result);
[email protected]f7f3a5f2009-05-01 22:02:34979
[email protected]6657afa62009-11-04 02:15:20980 // Helper method that loads either the include_globs or exclude_globs list
981 // from an entry in the content_script lists of the manifest.
[email protected]f3a1c642011-07-12 19:15:03982 bool LoadGlobsHelper(const base::DictionaryValue* content_script,
[email protected]6657afa62009-11-04 02:15:20983 int content_script_index,
[email protected]e2194742010-08-12 05:54:34984 const char* globs_property_name,
[email protected]fc670822011-12-17 09:33:49985 string16* error,
[email protected]11f4857282009-11-13 19:56:17986 void(UserScript::*add_method)(const std::string& glob),
[email protected]488e6502012-09-07 14:17:34987 UserScript* instance);
[email protected]6657afa62009-11-04 02:15:20988
[email protected]5d246db22009-10-27 06:17:57989 // Helper method to load an ExtensionAction from the page_action or
[email protected]92c6f9b92009-10-24 04:35:08990 // browser_action entries in the manifest.
[email protected]0f34d9082012-10-08 19:16:44991 scoped_ptr<ActionInfo> LoadExtensionActionInfoHelper(
992 const base::DictionaryValue* manifest_section,
993 ActionInfo::Type action_type,
[email protected]18049dc2012-06-19 23:12:55994 string16* error);
[email protected]92c6f9b92009-10-24 04:35:08995
[email protected]a79be1f2012-03-23 22:14:00996 // Helper method that loads the OAuth2 info from the 'oauth2' manifest key.
997 bool LoadOAuth2Info(string16* error);
998
[email protected]2f6698b2010-10-14 00:58:21999 // Returns true if the extension has more than one "UI surface". For example,
1000 // an extension that has a browser action and a page action.
1001 bool HasMultipleUISurfaces() const;
1002
[email protected]be9d9c82011-07-13 04:17:311003 // Updates the launch URL and extents for the extension using the given
1004 // |override_url|.
1005 void OverrideLaunchUrl(const GURL& override_url);
1006
[email protected]ae655e4e2012-03-16 21:47:551007 // Custom checks for the experimental permission that can't be expressed in
1008 // _permission_features.json.
[email protected]5eddc3e2011-10-26 04:33:311009 bool CanSpecifyExperimentalPermission() const;
[email protected]5eddc3e2011-10-26 04:33:311010
1011 // Checks whether the host |pattern| is allowed for this extension, given API
1012 // permissions |permissions|.
1013 bool CanSpecifyHostPermission(const URLPattern& pattern,
[email protected]c2e66e12012-06-27 06:27:061014 const APIPermissionSet& permissions) const;
[email protected]5eddc3e2011-10-26 04:33:311015
[email protected]488e6502012-09-07 14:17:341016 bool CheckMinimumChromeVersion(string16* error) const;
[email protected]488e6502012-09-07 14:17:341017
[email protected]e92169e2012-05-04 22:49:321018 // Check that platform app features are valid. Called after InitFromValue.
[email protected]488e6502012-09-07 14:17:341019 bool CheckPlatformAppFeatures(std::string* utf8_error) const;
[email protected]e92169e2012-05-04 22:49:321020
[email protected]f1bab9c92012-05-11 21:15:101021 // Check that features don't conflict. Called after InitFromValue.
[email protected]488e6502012-09-07 14:17:341022 bool CheckConflictingFeatures(std::string* utf8_error) const;
[email protected]f1bab9c92012-05-11 21:15:101023
[email protected]d7e9a862010-11-03 21:57:491024 // Cached images for this extension. This should only be touched on the UI
1025 // thread.
1026 mutable ImageCache image_cache_;
[email protected]1e8c93f2010-02-08 22:58:311027
[email protected]6f229e82010-11-02 17:47:261028 // The extension's human-readable name. Name is used for display purpose. It
1029 // might be wrapped with unicode bidi control characters so that it is
1030 // displayed correctly in RTL context.
1031 // NOTE: Name is UTF-8 and may contain non-ascii characters.
1032 std::string name_;
1033
[email protected]701d1e82012-05-14 05:34:191034 // A non-localized version of the extension's name. This is useful for
1035 // debug output.
1036 std::string non_localized_name_;
1037
[email protected]a47c8a22011-11-17 18:40:311038 // The version of this extension's manifest. We increase the manifest
1039 // version when making breaking changes to the extension system.
1040 // Version 1 was the first manifest version (implied by a lack of a
1041 // manifest_version attribute in the extension's manifest). We initialize
1042 // this member variable to 0 to distinguish the "uninitialized" case from
1043 // the case when we know the manifest version actually is 1.
1044 int manifest_version_;
1045
[email protected]98270432012-09-11 20:51:241046 // The requirements declared in the manifest.
1047 Requirements requirements_;
1048
[email protected]d41e2152012-02-24 04:20:271049 // The absolute path to the directory the extension is stored in.
1050 FilePath path_;
1051
[email protected]6f229e82010-11-02 17:47:261052 // Default locale for fall back. Can be empty if extension is not localized.
1053 std::string default_locale_;
1054
1055 // If true, a separate process will be used for the extension in incognito
1056 // mode.
1057 bool incognito_split_mode_;
1058
[email protected]1abdf4f2011-08-16 21:11:551059 // Whether the extension or app should be enabled when offline.
1060 bool offline_enabled_;
1061
[email protected]6f229e82010-11-02 17:47:261062 // Defines the set of URLs in the extension's web content.
[email protected]cced75a2011-05-20 08:31:121063 URLPatternSet extent_;
[email protected]6f229e82010-11-02 17:47:261064
[email protected]902fd7b2011-07-27 18:42:311065 // The extension runtime data.
1066 mutable base::Lock runtime_data_lock_;
1067 mutable RuntimeData runtime_data_;
1068
1069 // The set of permissions the extension can request at runtime.
[email protected]c2e66e12012-06-27 06:27:061070 scoped_refptr<const PermissionSet> optional_permission_set_;
[email protected]902fd7b2011-07-27 18:42:311071
1072 // The extension's required / default set of permissions.
[email protected]c2e66e12012-06-27 06:27:061073 scoped_refptr<const PermissionSet> required_permission_set_;
[email protected]6f229e82010-11-02 17:47:261074
[email protected]8629c542012-04-20 03:40:031075 // Any warnings that occurred when trying to create/parse the extension.
[email protected]1e0f45a2012-06-13 00:31:061076 InstallWarningVector install_warnings_;
[email protected]8629c542012-04-20 03:40:031077
[email protected]6f229e82010-11-02 17:47:261078 // The icons for the extension.
1079 ExtensionIconSet icons_;
1080
1081 // The base extension url for the extension.
1082 GURL extension_url_;
1083
[email protected]6f229e82010-11-02 17:47:261084 // The extension's version.
1085 scoped_ptr<Version> version_;
1086
1087 // An optional longer description of the extension.
1088 std::string description_;
1089
1090 // True if the extension was generated from a user script. (We show slightly
1091 // different UI if so).
1092 bool converted_from_user_script_;
1093
1094 // Paths to the content scripts the extension contains.
1095 UserScriptList content_scripts_;
1096
1097 // The extension's page action, if any.
[email protected]0f34d9082012-10-08 19:16:441098 scoped_ptr<ActionInfo> page_action_info_;
[email protected]6f229e82010-11-02 17:47:261099
1100 // The extension's browser action, if any.
[email protected]0f34d9082012-10-08 19:16:441101 scoped_ptr<ActionInfo> browser_action_info_;
[email protected]6f229e82010-11-02 17:47:261102
[email protected]18049dc2012-06-19 23:12:551103 // The extension's script badge. Never NULL.
[email protected]0f34d9082012-10-08 19:16:441104 scoped_ptr<ActionInfo> script_badge_info_;
1105
[email protected]b6b805e92011-04-16 09:24:141106 // The extension's file browser actions, if any.
1107 scoped_ptr<FileBrowserHandlerList> file_browser_handlers_;
1108
[email protected]6f229e82010-11-02 17:47:261109 // Optional list of NPAPI plugins and associated properties.
1110 std::vector<PluginInfo> plugins_;
1111
[email protected]65378f52011-04-08 02:31:231112 // Optional list of NaCl modules and associated properties.
1113 std::vector<NaClModuleInfo> nacl_modules_;
1114
[email protected]b0820372011-06-03 07:05:271115 // Optional list of input components and associated properties.
1116 std::vector<InputComponentInfo> input_components_;
1117
[email protected]f5532472012-02-23 13:00:551118 // Optional list of commands (keyboard shortcuts).
[email protected]3fc5f6a2012-05-04 14:23:591119 scoped_ptr<extensions::Command> browser_action_command_;
1120 scoped_ptr<extensions::Command> page_action_command_;
[email protected]d179cdd2012-08-03 08:32:521121 scoped_ptr<extensions::Command> script_badge_command_;
[email protected]3fc5f6a2012-05-04 14:23:591122 extensions::CommandMap named_commands_;
[email protected]f5532472012-02-23 13:00:551123
[email protected]8f270be2011-12-21 21:15:221124 // Optional list of web accessible extension resources.
[email protected]f59a8052012-06-20 22:25:001125 URLPatternSet web_accessible_resources_;
[email protected]8f270be2011-12-21 21:15:221126
[email protected]dbb24162012-06-06 01:41:221127 // Optional list of extension pages that are sandboxed (served from a unique
1128 // origin with a different Content Security Policy).
[email protected]f59a8052012-06-20 22:25:001129 URLPatternSet sandboxed_pages_;
[email protected]dbb24162012-06-06 01:41:221130
1131 // Content Security Policy that should be used to enforce the sandbox used
1132 // by sandboxed pages (guaranteed to have the "sandbox" directive without the
1133 // "allow-same-origin" token).
1134 std::string sandboxed_pages_content_security_policy_;
1135
[email protected]6f229e82010-11-02 17:47:261136 // Optional URL to a master page of which a single instance should be always
1137 // loaded in the background.
1138 GURL background_url_;
1139
[email protected]a03d4448f2012-01-10 23:25:281140 // Optional list of scripts to use to generate a background page. If this is
1141 // present, background_url_ will be empty and generated by GetBackgroundURL().
1142 std::vector<std::string> background_scripts_;
1143
[email protected]dd62fa802012-04-25 18:37:001144 // True if the background page should stay loaded forever; false if it should
1145 // load on-demand (when it needs to handle an event). Defaults to true.
1146 bool background_page_is_persistent_;
[email protected]9e6720a2012-01-24 02:30:561147
[email protected]7b54ca02012-03-02 18:06:531148 // True if the background page can be scripted by pages of the app or
1149 // extension, in which case all such pages must run in the same process.
1150 // False if such pages are not permitted to script the background page,
1151 // allowing them to run in different processes.
1152 bool allow_background_js_access_;
1153
[email protected]6f229e82010-11-02 17:47:261154 // Optional URL to a page for setting options/preferences.
1155 GURL options_url_;
1156
1157 // Optional URL to a devtools extension page.
1158 GURL devtools_url_;
1159
[email protected]81ca71652012-08-23 22:28:261160 // URL to the webstore page of the extension.
1161 GURL details_url_;
1162
[email protected]6f229e82010-11-02 17:47:261163 // The public key used to sign the contents of the crx package.
1164 std::string public_key_;
1165
1166 // A map of resource id's to relative file paths.
[email protected]f3a1c642011-07-12 19:15:031167 scoped_ptr<base::DictionaryValue> theme_images_;
[email protected]6f229e82010-11-02 17:47:261168
1169 // A map of color names to colors.
[email protected]f3a1c642011-07-12 19:15:031170 scoped_ptr<base::DictionaryValue> theme_colors_;
[email protected]6f229e82010-11-02 17:47:261171
1172 // A map of color names to colors.
[email protected]f3a1c642011-07-12 19:15:031173 scoped_ptr<base::DictionaryValue> theme_tints_;
[email protected]6f229e82010-11-02 17:47:261174
1175 // A map of display properties.
[email protected]f3a1c642011-07-12 19:15:031176 scoped_ptr<base::DictionaryValue> theme_display_properties_;
[email protected]6f229e82010-11-02 17:47:261177
[email protected]6f229e82010-11-02 17:47:261178 // The homepage for this extension. Useful if it is not hosted by Google and
1179 // therefore does not have a Gallery URL.
1180 GURL homepage_url_;
1181
1182 // URL for fetching an update manifest
1183 GURL update_url_;
1184
[email protected]58f62cf2012-03-09 10:45:111185 // The manifest from which this extension was created.
[email protected]e9629d772012-08-06 19:44:461186 scoped_ptr<Manifest> manifest_;
[email protected]6f229e82010-11-02 17:47:261187
1188 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
1189 // which override the handling of those URLs. (see ExtensionOverrideUI).
1190 URLOverrideMap chrome_url_overrides_;
1191
[email protected]d9696672011-03-15 22:45:091192 // Whether this extension requests isolated storage.
1193 bool is_storage_isolated_;
1194
[email protected]6f229e82010-11-02 17:47:261195 // The local path inside the extension to use with the launcher.
1196 std::string launch_local_path_;
1197
1198 // A web url to use with the launcher. Note that this might be relative or
1199 // absolute. If relative, it is relative to web_origin.
1200 std::string launch_web_url_;
1201
[email protected]4e595682011-02-09 17:07:021202 // The window type that an app's manifest specifies to launch into.
1203 // This is not always the window type an app will open into, because
1204 // users can override the way each app launches. See
1205 // ExtensionPrefs::GetLaunchContainer(), which looks at a per-app pref
1206 // to decide what container an app will launch in.
[email protected]6f229e82010-11-02 17:47:261207 extension_misc::LaunchContainer launch_container_;
1208
1209 // The default size of the container when launching. Only respected for
1210 // containers like panels and windows.
1211 int launch_width_;
1212 int launch_height_;
1213
[email protected]7e0f92b2012-11-09 03:51:041214 // Should this app be shown in the app launcher.
[email protected]ed1a204f2012-09-22 00:28:441215 bool display_in_launcher_;
1216
[email protected]7e0f92b2012-11-09 03:51:041217 // Should this app be shown in the browser New Tab Page.
1218 bool display_in_new_tab_page_;
1219
[email protected]6f229e82010-11-02 17:47:261220 // The Omnibox keyword for this extension, or empty if there is none.
1221 std::string omnibox_keyword_;
1222
[email protected]a4a38c12010-12-23 16:43:561223 // List of text-to-speech voices that this extension provides, if any.
1224 std::vector<TtsVoice> tts_voices_;
1225
[email protected]a79be1f2012-03-23 22:14:001226 // The OAuth2 client id and scopes, if specified by the extension.
1227 OAuth2Info oauth2_info_;
1228
[email protected]56624422011-11-01 22:11:271229 // List of intent services that this extension provides, if any.
1230 std::vector<webkit_glue::WebIntentServiceData> intents_services_;
[email protected]be5f007862011-09-23 00:35:131231
[email protected]af8dc08e2012-11-22 01:58:421232 // List of file handlers associated with this extension, if any.
1233 std::vector<FileHandlerInfo> file_handlers_;
1234
[email protected]3aff9ad2011-04-01 20:26:481235 // Whether the extension has host permissions or user script patterns that
1236 // imply access to file:/// scheme URLs (the user may not have actually
1237 // granted it that access).
1238 bool wants_file_access_;
1239
[email protected]2af352b2011-07-22 08:21:231240 // The flags that were passed to InitFromValue.
1241 int creation_flags_;
[email protected]620db1762011-07-15 21:57:341242
[email protected]7f7b9d932011-04-20 16:13:261243 // The Content-Security-Policy for this extension. Extensions can use
1244 // Content-Security-Policies to mitigate cross-site scripting and other
1245 // vulnerabilities.
1246 std::string content_security_policy_;
1247
[email protected]19118d52010-07-26 22:13:421248 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper);
[email protected]1c321ee2012-05-21 03:02:341249 FRIEND_TEST_ALL_PREFIXES(::TabStripModelTest, Apps);
[email protected]ae7fe712009-07-02 20:33:581250
[email protected]894bb502009-05-21 22:39:571251 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:331252};
1253
[email protected]9adb9692010-10-29 23:14:021254typedef std::vector< scoped_refptr<const Extension> > ExtensionList;
[email protected]ec5b50d2010-10-09 16:35:181255typedef std::set<std::string> ExtensionIdSet;
[email protected]82590cb2012-09-28 04:14:081256typedef std::vector<std::string> ExtensionIdList;
[email protected]b1748b1d82009-11-30 20:32:561257
[email protected]18049dc2012-06-19 23:12:551258// Let gtest print InstallWarnings.
1259void PrintTo(const Extension::InstallWarning&, ::std::ostream* os);
1260
[email protected]c6d474f82009-12-16 21:11:061261// Handy struct to pass core extension info around.
1262struct ExtensionInfo {
[email protected]f3a1c642011-07-12 19:15:031263 ExtensionInfo(const base::DictionaryValue* manifest,
[email protected]c6d474f82009-12-16 21:11:061264 const std::string& id,
1265 const FilePath& path,
[email protected]3bb84992010-08-26 17:23:461266 Extension::Location location);
1267 ~ExtensionInfo();
[email protected]c6d474f82009-12-16 21:11:061268
[email protected]f3a1c642011-07-12 19:15:031269 scoped_ptr<base::DictionaryValue> extension_manifest;
[email protected]c6d474f82009-12-16 21:11:061270 std::string extension_id;
1271 FilePath extension_path;
1272 Extension::Location extension_location;
1273
1274 private:
1275 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
1276};
1277
[email protected]a9f39a312010-12-23 22:14:271278struct UnloadedExtensionInfo {
[email protected]814a7bf0f2011-08-13 05:30:591279 extension_misc::UnloadedExtensionReason reason;
[email protected]a9f39a312010-12-23 22:14:271280
1281 // Was the extension already disabled?
1282 bool already_disabled;
1283
1284 // The extension being unloaded - this should always be non-NULL.
1285 const Extension* extension;
1286
[email protected]814a7bf0f2011-08-13 05:30:591287 UnloadedExtensionInfo(
1288 const Extension* extension,
1289 extension_misc::UnloadedExtensionReason reason);
[email protected]a9f39a312010-12-23 22:14:271290};
1291
[email protected]902fd7b2011-07-27 18:42:311292// The details sent for EXTENSION_PERMISSIONS_UPDATED notifications.
1293struct UpdatedExtensionPermissionsInfo {
1294 enum Reason {
[email protected]f5532472012-02-23 13:00:551295 ADDED, // The permissions were added to the extension.
1296 REMOVED, // The permissions were removed from the extension.
[email protected]902fd7b2011-07-27 18:42:311297 };
1298
1299 Reason reason;
1300
1301 // The extension who's permissions have changed.
1302 const Extension* extension;
1303
1304 // The permissions that have changed. For Reason::ADDED, this would contain
1305 // only the permissions that have added, and for Reason::REMOVED, this would
1306 // only contain the removed permissions.
[email protected]c2e66e12012-06-27 06:27:061307 const PermissionSet* permissions;
[email protected]902fd7b2011-07-27 18:42:311308
1309 UpdatedExtensionPermissionsInfo(
1310 const Extension* extension,
[email protected]c2e66e12012-06-27 06:27:061311 const PermissionSet* permissions,
[email protected]902fd7b2011-07-27 18:42:311312 Reason reason);
1313};
1314
[email protected]488e6502012-09-07 14:17:341315} // namespace extensions
[email protected]1c321ee2012-05-21 03:02:341316
[email protected]5b1a0e22009-05-26 19:00:581317#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_