blob: ebe669c38467b09e6f5d5965508e0ea6535faabe [file] [log] [blame]
[email protected]7eeab9ec2013-01-15 04:08:331// Copyright (c) 2013 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]57999812013-02-24 05:40:5216#include "base/files/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]7eeab9ec2013-01-15 04:08:3323#include "base/threading/thread_checker.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]1d5e58b2013-01-31 08:41:4026#include "chrome/common/extensions/manifest.h"
[email protected]bebe1d02012-08-02 20:17:0927#include "chrome/common/extensions/permissions/api_permission.h"
28#include "chrome/common/extensions/permissions/permission_message.h"
[email protected]885c0e92012-11-13 20:27:4229#include "chrome/common/extensions/user_script.h"
[email protected]1d5e58b2013-01-31 08:41:4030#include "extensions/common/install_warning.h"
[email protected]885c0e92012-11-13 20:27:4231#include "extensions/common/url_pattern.h"
[email protected]e9f541a2012-11-19 21:52:3132#include "extensions/common/url_pattern_set.h"
[email protected]eab9b452009-01-23 20:48:5933#include "googleurl/src/gurl.h"
[email protected]f5532472012-02-23 13:00:5534#include "ui/base/accelerators/accelerator.h"
[email protected]08397d52011-02-05 01:53:3835#include "ui/gfx/size.h"
[email protected]eab9b452009-01-23 20:48:5936
[email protected]0f34d9082012-10-08 19:16:4437class ExtensionAction;
[email protected]942690b132010-05-11 06:42:1438class ExtensionResource;
[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]1c321ee2012-05-21 03:02:3451FORWARD_DECLARE_TEST(TabStripModelTest, Apps);
52
53namespace extensions {
[email protected]972b02f2013-01-28 20:38:1454struct ActionInfo;
[email protected]465594632013-02-15 19:50:2855class APIPermissionSet;
[email protected]bebe1d02012-08-02 20:17:0956class PermissionSet;
[email protected]1c321ee2012-05-21 03:02:3457
[email protected]f0755532010-06-22 07:27:2558// Represents a Chrome extension.
[email protected]512b8772013-02-23 01:20:2459// Once created, an Extension object is immutable, with the exception of its
60// RuntimeData. This makes it safe to use on any thread, since access to the
61// RuntimeData is protected by a lock.
[email protected]66e4eb32010-10-27 20:37:4162class Extension : public base::RefCountedThreadSafe<Extension> {
[email protected]7713d632008-12-02 07:52:3363 public:
[email protected]d356c982012-12-12 19:32:5564 struct ManifestData;
[email protected]1e0f45a2012-06-13 00:31:0665
[email protected]10fb1992010-10-08 09:00:1766 typedef std::vector<std::string> ScriptingWhitelist;
[email protected]d356c982012-12-12 19:32:5567 typedef std::map<const std::string, linked_ptr<ManifestData> >
68 ManifestDataMap;
[email protected]b24d8312009-08-27 06:47:4669
[email protected]25b34332009-06-05 21:53:1970 enum State {
[email protected]0c6da502009-08-14 22:32:3971 DISABLED = 0,
[email protected]25b34332009-06-05 21:53:1972 ENABLED,
[email protected]79c833b52011-04-05 18:31:0173 // An external extension that the user uninstalled. We should not reinstall
74 // such extensions on startup.
75 EXTERNAL_EXTENSION_UNINSTALLED,
[email protected]8c484b742012-11-29 06:05:3676 // Special state for component extensions, since they are always loaded by
77 // the component loader, and should never be auto-installed on startup.
78 ENABLED_COMPONENT,
[email protected]0c6da502009-08-14 22:32:3979 NUM_STATES
[email protected]631cf822009-05-15 07:01:2580 };
[email protected]7713d632008-12-02 07:52:3381
[email protected]44d62b62012-04-11 00:06:0382 // Used to record the reason an extension was disabled.
[email protected]eb5e4f92012-08-15 23:33:2883 enum DeprecatedDisableReason {
84 DEPRECATED_DISABLE_UNKNOWN,
85 DEPRECATED_DISABLE_USER_ACTION,
86 DEPRECATED_DISABLE_PERMISSIONS_INCREASE,
87 DEPRECATED_DISABLE_RELOAD,
88 DEPRECATED_DISABLE_LAST, // Not used.
89 };
90
[email protected]44d62b62012-04-11 00:06:0391 enum DisableReason {
[email protected]eb5e4f92012-08-15 23:33:2892 DISABLE_NONE = 0,
93 DISABLE_USER_ACTION = 1 << 0,
94 DISABLE_PERMISSIONS_INCREASE = 1 << 1,
95 DISABLE_RELOAD = 1 << 2,
[email protected]215a7be2012-10-22 19:53:4296 DISABLE_UNSUPPORTED_REQUIREMENT = 1 << 3,
97 DISABLE_SIDELOAD_WIPEOUT = 1 << 4,
[email protected]f56c65ea62012-12-10 22:57:2198 DISABLE_UNKNOWN_FROM_SYNC = 1 << 5,
[email protected]44d62b62012-04-11 00:06:0399 };
100
[email protected]fbcc40302009-06-12 20:45:45101 enum InstallType {
[email protected]ab6f2b22009-07-28 23:28:37102 INSTALL_ERROR,
[email protected]fbcc40302009-06-12 20:45:45103 DOWNGRADE,
104 REINSTALL,
105 UPGRADE,
106 NEW_INSTALL
107 };
108
[email protected]3bdba0d2011-08-23 07:17:30109 enum SyncType {
110 SYNC_TYPE_NONE = 0,
111 SYNC_TYPE_EXTENSION,
112 SYNC_TYPE_APP
113 };
114
[email protected]98270432012-09-11 20:51:24115 // Declared requirements for the extension.
116 struct Requirements {
117 Requirements();
118 ~Requirements();
119
120 bool webgl;
121 bool css3d;
122 bool npapi;
123 };
124
[email protected]92888082010-10-18 19:24:57125 // An NPAPI plugin included in the extension.
126 struct PluginInfo {
[email protected]a7329162013-02-07 19:21:48127 base::FilePath path; // Path to the plugin.
[email protected]92888082010-10-18 19:24:57128 bool is_public; // False if only this extension can load this plugin.
129 };
130
[email protected]65378f52011-04-08 02:31:23131 // An NaCl module included in the extension.
132 struct NaClModuleInfo {
[email protected]84396dbc2011-04-14 06:33:42133 GURL url;
[email protected]65378f52011-04-08 02:31:23134 std::string mime_type;
135 };
136
[email protected]d356c982012-12-12 19:32:55137 // A base class for parsed manifest data that APIs want to store on
138 // the extension. Related to base::SupportsUserData, but with an immutable
139 // thread-safe interface to match Extension.
140 struct ManifestData {
141 virtual ~ManifestData() {}
142 };
143
[email protected]83048a22011-03-29 00:14:13144 enum InitFromValueFlags {
145 NO_FLAGS = 0,
146
147 // Usually, the id of an extension is generated by the "key" property of
148 // its manifest, but if |REQUIRE_KEY| is not set, a temporary ID will be
149 // generated based on the path.
150 REQUIRE_KEY = 1 << 0,
151
[email protected]3f53dfe2011-11-30 01:18:29152 // Requires the extension to have an up-to-date manifest version.
153 // Typically, we'll support multiple manifest versions during a version
[email protected]26367b62012-10-04 23:03:32154 // transition. This flag signals that we want to require the most modern
[email protected]3f53dfe2011-11-30 01:18:29155 // manifest version that Chrome understands.
156 REQUIRE_MODERN_MANIFEST_VERSION = 1 << 1,
157
[email protected]3aff9ad2011-04-01 20:26:48158 // |ALLOW_FILE_ACCESS| indicates that the user is allowing this extension
159 // to have file access. If it's not present, then permissions and content
160 // scripts that match file:/// URLs will be filtered out.
[email protected]ed3b9b12012-05-31 18:37:51161 ALLOW_FILE_ACCESS = 1 << 2,
[email protected]620db1762011-07-15 21:57:34162
163 // |FROM_WEBSTORE| indicates that the extension was installed from the
164 // Chrome Web Store.
[email protected]ed3b9b12012-05-31 18:37:51165 FROM_WEBSTORE = 1 << 3,
[email protected]e805baf2011-07-26 18:23:05166
167 // |FROM_BOOKMARK| indicates the extension was created using a mock App
168 // created from a bookmark.
[email protected]ed3b9b12012-05-31 18:37:51169 FROM_BOOKMARK = 1 << 4,
[email protected]3d41d432012-04-20 20:47:58170
171 // |FOLLOW_SYMLINKS_ANYWHERE| means that resources can be symlinks to
172 // anywhere in the filesystem, rather than being restricted to the
173 // extension directory.
[email protected]ed3b9b12012-05-31 18:37:51174 FOLLOW_SYMLINKS_ANYWHERE = 1 << 5,
[email protected]ab55c2b2012-06-01 23:55:03175
176 // |ERROR_ON_PRIVATE_KEY| means that private keys inside an
177 // extension should be errors rather than warnings.
178 ERROR_ON_PRIVATE_KEY = 1 << 6,
[email protected]e33bbc22012-08-27 22:05:46179
180 // |WAS_INSTALLED_BY_DEFAULT| installed by default when the profile was
181 // created.
182 WAS_INSTALLED_BY_DEFAULT = 1 << 7,
[email protected]83048a22011-03-29 00:14:13183 };
184
[email protected]a7329162013-02-07 19:21:48185 static scoped_refptr<Extension> Create(const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:40186 Manifest::Location location,
[email protected]f3a1c642011-07-12 19:15:03187 const base::DictionaryValue& value,
[email protected]83048a22011-03-29 00:14:13188 int flags,
[email protected]66e4eb32010-10-27 20:37:41189 std::string* error);
190
[email protected]87c655e2011-07-01 21:42:00191 // In a few special circumstances, we want to create an Extension and give it
[email protected]f5bf1842012-02-15 02:52:26192 // an explicit id. Most consumers should just use the other Create() method.
[email protected]a7329162013-02-07 19:21:48193 static scoped_refptr<Extension> Create(const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:40194 Manifest::Location location,
[email protected]58f62cf2012-03-09 10:45:11195 const base::DictionaryValue& value,
196 int flags,
197 const std::string& explicit_id,
198 std::string* error);
[email protected]87c655e2011-07-01 21:42:00199
[email protected]4c4f8192009-10-17 01:03:26200 // Max size (both dimensions) for browser and page actions.
201 static const int kPageActionIconMaxSize;
202 static const int kBrowserActionIconMaxSize;
203
[email protected]8d888c12010-11-30 00:00:25204 // Valid schemes for web extent URLPatterns.
205 static const int kValidWebExtentSchemes;
206
[email protected]f71f7e62010-12-07 03:45:33207 // Valid schemes for host permission URLPatterns.
208 static const int kValidHostPermissionSchemes;
209
[email protected]6014d672008-12-05 00:38:25210 // The name of the manifest inside an extension.
[email protected]a7329162013-02-07 19:21:48211 static const base::FilePath::CharType kManifestFilename[];
[email protected]6014d672008-12-05 00:38:25212
[email protected]300cc58db2009-08-19 20:45:14213 // The name of locale folder inside an extension.
[email protected]a7329162013-02-07 19:21:48214 static const base::FilePath::CharType kLocaleFolder[];
[email protected]300cc58db2009-08-19 20:45:14215
216 // The name of the messages file inside an extension.
[email protected]a7329162013-02-07 19:21:48217 static const base::FilePath::CharType kMessagesFilename[];
[email protected]300cc58db2009-08-19 20:45:14218
[email protected]25b34332009-06-05 21:53:19219#if defined(OS_WIN)
[email protected]9dcf8f12010-09-02 20:39:19220 static const char kExtensionRegistryPath[];
[email protected]25b34332009-06-05 21:53:19221#endif
222
[email protected]37eeb5a2009-02-26 23:36:17223 // The number of bytes in a legal id.
[email protected]fe0e7822009-02-26 23:51:48224 static const size_t kIdSize;
[email protected]37eeb5a2009-02-26 23:36:17225
[email protected]e435d6b72009-07-25 03:15:58226 // The mimetype used for extensions.
227 static const char kMimeType[];
228
[email protected]25b34332009-06-05 21:53:19229 // Checks to see if the extension has a valid ID.
230 static bool IdIsValid(const std::string& id);
231
[email protected]4ead6f72010-10-13 19:54:18232 // Generate an ID for an extension in the given path.
[email protected]28d7479b2011-03-09 21:33:27233 // Used while developing extensions, before they have a key.
[email protected]a7329162013-02-07 19:21:48234 static std::string GenerateIdForPath(const base::FilePath& file_name);
[email protected]4ead6f72010-10-13 19:54:18235
[email protected]e435d6b72009-07-25 03:15:58236 // Returns true if the specified file is an extension.
[email protected]a7329162013-02-07 19:21:48237 static bool IsExtension(const base::FilePath& file_name);
[email protected]e435d6b72009-07-25 03:15:58238
[email protected]fc6b0612012-03-29 13:40:06239 // Fills the |info| dictionary with basic information about the extension.
240 // |enabled| is injected for easier testing.
241 void GetBasicInfo(bool enabled, base::DictionaryValue* info) const;
242
[email protected]1d5e58b2013-01-31 08:41:40243 // See Type definition in Manifest.
244 Manifest::Type GetType() const;
[email protected]9b217652010-10-08 22:04:23245
[email protected]07c00d992009-03-04 20:27:04246 // Returns an absolute url to a resource inside of an extension. The
[email protected]eab9b452009-01-23 20:48:59247 // |extension_url| argument should be the url() from an Extension object. The
248 // |relative_path| can be untrusted user input. The returned URL will either
249 // be invalid() or a child of |extension_url|.
250 // NOTE: Static so that it can be used from multiple threads.
251 static GURL GetResourceURL(const GURL& extension_url,
252 const std::string& relative_path);
[email protected]cffd7892010-08-26 17:43:28253 GURL GetResourceURL(const std::string& relative_path) const {
[email protected]3cfbd0e2009-03-18 21:26:24254 return GetResourceURL(url(), relative_path);
255 }
[email protected]eab9b452009-01-23 20:48:59256
[email protected]f59a8052012-06-20 22:25:00257 // Returns true if the resource matches a pattern in the pattern_set.
258 bool ResourceMatches(const URLPatternSet& pattern_set,
259 const std::string& resource) const;
260
[email protected]dbb24162012-06-06 01:41:22261 // Returns true if the specified page is sandboxed (served in a unique
262 // origin).
263 bool IsSandboxedPage(const std::string& relative_path) const;
264
265 // Returns the Content Security Policy that the specified resource should be
266 // served with.
267 std::string GetResourceContentSecurityPolicy(const std::string& relative_path)
268 const;
269
[email protected]99efb7b12009-12-18 02:39:16270 // Returns an extension resource object. |relative_path| should be UTF8
271 // encoded.
[email protected]9adb9692010-10-29 23:14:02272 ExtensionResource GetResource(const std::string& relative_path) const;
[email protected]99efb7b12009-12-18 02:39:16273
274 // As above, but with |relative_path| following the file system's encoding.
[email protected]a7329162013-02-07 19:21:48275 ExtensionResource GetResource(const base::FilePath& relative_path) const;
[email protected]eab9b452009-01-23 20:48:59276
[email protected]a17f9462009-06-09 02:56:41277 // |input| is expected to be the text of an rsa public or private key. It
278 // tolerates the presence or absence of bracking header/footer like this:
279 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
280 // and may contain newlines.
281 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
282
283 // Does a simple base64 encoding of |input| into |output|.
284 static bool ProducePEM(const std::string& input, std::string* output);
285
[email protected]84ac7f32009-10-06 06:17:54286 // Generates an extension ID from arbitrary input. The same input string will
287 // always generate the same output ID.
[email protected]af9db5f2011-10-05 05:13:15288 static bool GenerateId(const std::string& input,
289 std::string* output) WARN_UNUSED_RESULT;
[email protected]fbcc40302009-06-12 20:45:45290
[email protected]a17f9462009-06-09 02:56:41291 // Expects base64 encoded |input| and formats into |output| including
292 // the appropriate header & footer.
[email protected]e0d08192011-03-29 19:02:50293 static bool FormatPEMForFileOutput(const std::string& input,
294 std::string* output,
295 bool is_public);
[email protected]a17f9462009-06-09 02:56:41296
[email protected]58f62cf2012-03-09 10:45:11297 // Given an extension, icon size, and match type, read a valid icon if present
[email protected]e3c0bc22012-02-24 01:34:15298 // and decode it into result. In the browser process, this will DCHECK if not
299 // called on the file thread. To easily load extension images on the UI
[email protected]75b91fd2013-02-12 22:14:25300 // thread, see ImageLoader.
[email protected]e3c0bc22012-02-24 01:34:15301 static void DecodeIcon(const Extension* extension,
[email protected]faf87192012-08-17 00:07:59302 int icon_size,
[email protected]e3c0bc22012-02-24 01:34:15303 ExtensionIconSet::MatchType match_type,
304 scoped_ptr<SkBitmap>* result);
305
[email protected]c690a9812009-12-17 05:55:32306 // Given an extension and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23307 // result. In the browser process, this will DCHECK if not called on the
308 // file thread. To easily load extension images on the UI thread, see
[email protected]75b91fd2013-02-12 22:14:25309 // ImageLoader.
[email protected]9adb9692010-10-29 23:14:02310 static void DecodeIcon(const Extension* extension,
[email protected]faf87192012-08-17 00:07:59311 int icon_size,
[email protected]c690a9812009-12-17 05:55:32312 scoped_ptr<SkBitmap>* result);
313
314 // Given an icon_path and icon size, read it if present and decode it into
[email protected]ae2e0f92010-04-06 20:32:23315 // result. In the browser process, this will DCHECK if not called on the
316 // file thread. To easily load extension images on the UI thread, see
[email protected]75b91fd2013-02-12 22:14:25317 // ImageLoader.
[email protected]a7329162013-02-07 19:21:48318 static void DecodeIconFromPath(const base::FilePath& icon_path,
[email protected]faf87192012-08-17 00:07:59319 int icon_size,
[email protected]c690a9812009-12-17 05:55:32320 scoped_ptr<SkBitmap>* result);
321
[email protected]5349ac6d2011-04-05 22:20:17322 // Returns the default extension/app icon (for extensions or apps that don't
323 // have one).
[email protected]dd46a4ce2012-09-15 10:50:50324 static const gfx::ImageSkia& GetDefaultIcon(bool is_app);
[email protected]5349ac6d2011-04-05 22:20:17325
[email protected]a807bbe2010-04-14 10:51:19326 // Returns the base extension url for a given |extension_id|.
327 static GURL GetBaseURLFromExtensionId(const std::string& extension_id);
328
[email protected]be7e5cb2010-10-04 12:53:17329 // Adds an extension to the scripting whitelist. Used for testing only.
[email protected]10fb1992010-10-08 09:00:17330 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist);
[email protected]2a521c52011-01-26 18:45:21331 static const ScriptingWhitelist* GetScriptingWhitelist();
[email protected]be7e5cb2010-10-04 12:53:17332
[email protected]902fd7b2011-07-27 18:42:31333 // Parses the host and api permissions from the specified permission |key|
[email protected]d41e2152012-02-24 04:20:27334 // from |manifest_|.
335 bool ParsePermissions(const char* key,
[email protected]fc670822011-12-17 09:33:49336 string16* error,
[email protected]c2e66e12012-06-27 06:27:06337 APIPermissionSet* api_permissions,
[email protected]902fd7b2011-07-27 18:42:31338 URLPatternSet* host_permissions);
339
[email protected]d624b0b2012-12-12 04:05:19340 // Returns true if this extension has the given permission. Prefer
341 // IsExtensionWithPermissionOrSuggestInConsole when developers may be using an
342 // api that requires a permission they didn't know about, e.g. open web apis.
[email protected]c2e66e12012-06-27 06:27:06343 bool HasAPIPermission(APIPermission::ID permission) const;
[email protected]0d3e4a22011-06-23 19:02:52344 bool HasAPIPermission(const std::string& function_name) const;
[email protected]3d0e2262012-08-02 15:32:16345 bool HasAPIPermissionForTab(int tab_id, APIPermission::ID permission) const;
[email protected]583d45c12010-08-31 02:48:12346
[email protected]ecb9ad12012-08-21 13:02:15347 bool CheckAPIPermissionWithParam(APIPermission::ID permission,
348 const APIPermission::CheckParam* param) const;
[email protected]1d8b79a2012-08-16 20:22:54349
[email protected]0d3e4a22011-06-23 19:02:52350 const URLPatternSet& GetEffectiveHostPermissions() const;
[email protected]b24d8312009-08-27 06:47:46351
[email protected]902fd7b2011-07-27 18:42:31352 // Returns true if the extension can silently increase its permission level.
[email protected]0d904312012-01-25 23:00:16353 // Users must approve permissions for unpacked and packed extensions in the
354 // following situations:
355 // - when installing or upgrading packed extensions
356 // - when installing unpacked extensions that have NPAPI plugins
357 // - when either type of extension requests optional permissions
[email protected]902fd7b2011-07-27 18:42:31358 bool CanSilentlyIncreasePermissions() const;
359
[email protected]584b8e3f2010-04-10 00:23:37360 // Whether the extension has access to the given URL.
361 bool HasHostPermission(const GURL& url) const;
362
[email protected]0df165f2010-09-28 16:49:40363 // Whether the extension has effective access to all hosts. This is true if
364 // there is a content script that matches all hosts, if there is a host
365 // permission grants access to all hosts (like <all_urls>) or an api
366 // permission that effectively grants access to all hosts (e.g. proxy,
367 // network, etc.)
368 bool HasEffectiveAccessToAllHosts() const;
[email protected]b24d8312009-08-27 06:47:46369
[email protected]8d888c12010-11-30 00:00:25370 // Whether the extension effectively has all permissions (for example, by
371 // having an NPAPI plugin).
372 bool HasFullPermissions() const;
373
[email protected]902fd7b2011-07-27 18:42:31374 // Returns the full list of permission messages that this extension
375 // should display at install time.
[email protected]c2e66e12012-06-27 06:27:06376 PermissionMessages GetPermissionMessages() const;
[email protected]902fd7b2011-07-27 18:42:31377
378 // Returns the full list of permission messages that this extension
379 // should display at install time. The messages are returned as strings
380 // for convenience.
381 std::vector<string16> GetPermissionMessageStrings() const;
382
[email protected]b0d1d0b2012-11-02 21:19:03383 // Returns true if the extension does not require permission warnings
384 // to be displayed at install time.
385 bool ShouldSkipPermissionWarnings() const;
386
[email protected]902fd7b2011-07-27 18:42:31387 // Sets the active |permissions|.
[email protected]c2e66e12012-06-27 06:27:06388 void SetActivePermissions(const PermissionSet* permissions) const;
[email protected]902fd7b2011-07-27 18:42:31389
390 // Gets the extension's active permission set.
[email protected]c2e66e12012-06-27 06:27:06391 scoped_refptr<const PermissionSet> GetActivePermissions() const;
[email protected]902fd7b2011-07-27 18:42:31392
[email protected]5df6a5d2011-01-26 07:39:12393 // Whether context menu should be shown for page and browser actions.
394 bool ShowConfigureContextMenus() const;
395
[email protected]facd7a7652009-06-05 23:15:02396 // Returns a list of paths (relative to the extension dir) for images that
397 // the browser might load (like themes and page action icons).
[email protected]a7329162013-02-07 19:21:48398 std::set<base::FilePath> GetBrowserImages() const;
[email protected]facd7a7652009-06-05 23:15:02399
[email protected]807871f2010-09-16 01:04:48400 // Get an extension icon as a resource or URL.
[email protected]9adb9692010-10-29 23:14:02401 ExtensionResource GetIconResource(
402 int size, ExtensionIconSet::MatchType match_type) const;
403 GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const;
[email protected]f34e79632010-03-17 02:34:08404
[email protected]867a73e12010-03-19 20:45:46405 // Gets the fully resolved absolute launch URL.
406 GURL GetFullLaunchURL() const;
[email protected]2a521c52011-01-26 18:45:21407
[email protected]2a521c52011-01-26 18:45:21408 // Returns true if this extension can execute script on a page. If a
409 // UserScript object is passed, permission to run that specific script is
410 // checked (using its matches list). Otherwise, permission to execute script
411 // programmatically is checked (using the extension's host permission).
412 //
413 // This method is also aware of certain special pages that extensions are
414 // usually not allowed to run script on.
[email protected]78bdfd662012-08-23 05:53:18415 bool CanExecuteScriptOnPage(const GURL& document_url,
416 const GURL& top_document_url,
[email protected]fc5e65d6b2012-06-13 00:22:57417 int tab_id,
[email protected]3aff9ad2011-04-01 20:26:48418 const UserScript* script,
[email protected]2a521c52011-01-26 18:45:21419 std::string* error) const;
420
[email protected]6f229e82010-11-02 17:47:26421 // Returns true if this extension is a COMPONENT extension, or if it is
422 // on the whitelist of extensions that can script all pages.
423 bool CanExecuteScriptEverywhere() const;
424
[email protected]5efbfe012011-02-22 23:07:18425 // Returns true if this extension is allowed to obtain the contents of a
426 // page as an image. Since a page may contain sensitive information, this
427 // is restricted to the extension's host permissions as well as the
428 // extension page itself.
[email protected]fc5e65d6b2012-06-13 00:22:57429 bool CanCaptureVisiblePage(const GURL& page_url,
430 int tab_id,
431 std::string* error) const;
[email protected]5efbfe012011-02-22 23:07:18432
[email protected]a65882c2010-11-12 15:15:09433 // Returns true if this extension updates itself using the extension
434 // gallery.
435 bool UpdatesFromGallery() const;
436
[email protected]cca147172011-02-17 01:29:29437 // Returns true if this extension or app includes areas within |origin|.
438 bool OverlapsWithOrigin(const GURL& origin) const;
439
[email protected]3bdba0d2011-08-23 07:17:30440 // Returns the sync bucket to use for this extension.
441 SyncType GetSyncType() const;
442
[email protected]b873cd92012-02-09 21:51:48443 // Returns true if the extension should be synced.
444 bool IsSyncable() const;
445
[email protected]7e0f92b2012-11-09 03:51:04446 // Returns true if the extension requires a valid ordinal for sorting, e.g.,
447 // for displaying in a launcher or new tab page.
448 bool RequiresSortOrdinal() const;
449
450 // Returns true if the extension should be displayed in the app launcher.
451 bool ShouldDisplayInAppLauncher() const;
452
453 // Returns true if the extension should be displayed in the browser NTP.
454 bool ShouldDisplayInNewTabPage() const;
[email protected]b873cd92012-02-09 21:51:48455
[email protected]e0b3de72012-05-01 01:21:34456 // Returns true if the extension should be displayed in the extension
457 // settings page (i.e. chrome://extensions).
458 bool ShouldDisplayInExtensionSettings() const;
459
[email protected]4f886012012-05-19 03:51:10460 // Returns true if the extension has a content script declared at |url|.
461 bool HasContentScriptAtURL(const GURL& url) const;
462
[email protected]fc5e65d6b2012-06-13 00:22:57463 // Gets the tab-specific host permissions of |tab_id|, or NULL if there
464 // aren't any.
[email protected]3d0e2262012-08-02 15:32:16465 scoped_refptr<const PermissionSet> GetTabSpecificPermissions(int tab_id)
466 const;
[email protected]fc5e65d6b2012-06-13 00:22:57467
[email protected]3d0e2262012-08-02 15:32:16468 // Updates the tab-specific permissions of |tab_id| to include those from
469 // |permissions|.
[email protected]6144057e2012-08-02 19:02:37470 void UpdateTabSpecificPermissions(
471 int tab_id,
472 scoped_refptr<const PermissionSet> permissions) const;
[email protected]fc5e65d6b2012-06-13 00:22:57473
[email protected]3d0e2262012-08-02 15:32:16474 // Clears the tab-specific permissions of |tab_id|.
475 void ClearTabSpecificPermissions(int tab_id) const;
[email protected]fc5e65d6b2012-06-13 00:22:57476
[email protected]d356c982012-12-12 19:32:55477 // Get the manifest data associated with the key, or NULL if there is none.
478 // Can only be called after InitValue is finished.
479 ManifestData* GetManifestData(const std::string& key) const;
480
481 // Sets |data| to be associated with the key. Takes ownership of |data|.
482 // Can only be called before InitValue is finished. Not thread-safe;
483 // all SetManifestData calls should be on only one thread.
484 void SetManifestData(const std::string& key, ManifestData* data);
485
[email protected]6f229e82010-11-02 17:47:26486 // Accessors:
487
[email protected]98270432012-09-11 20:51:24488 const Requirements& requirements() const { return requirements_; }
[email protected]a7329162013-02-07 19:21:48489 const base::FilePath& path() const { return path_; }
[email protected]6f229e82010-11-02 17:47:26490 const GURL& url() const { return extension_url_; }
[email protected]1d5e58b2013-01-31 08:41:40491 Manifest::Location location() const;
[email protected]d41e2152012-02-24 04:20:27492 const std::string& id() const;
[email protected]6f229e82010-11-02 17:47:26493 const Version* version() const { return version_.get(); }
494 const std::string VersionString() const;
495 const std::string& name() const { return name_; }
[email protected]701d1e82012-05-14 05:34:19496 const std::string& non_localized_name() const { return non_localized_name_; }
[email protected]200423d2012-06-05 01:16:06497 // Base64-encoded version of the key used to sign this extension.
498 // In pseudocode, returns
499 // base::Base64Encode(RSAPrivateKey(pem_file).ExportPublicKey()).
500 const std::string& public_key() const { return public_key_; }
[email protected]6f229e82010-11-02 17:47:26501 const std::string& description() const { return description_; }
[email protected]a47c8a22011-11-17 18:40:31502 int manifest_version() const { return manifest_version_; }
[email protected]6f229e82010-11-02 17:47:26503 bool converted_from_user_script() const {
504 return converted_from_user_script_;
505 }
506 const UserScriptList& content_scripts() const { return content_scripts_; }
[email protected]ad12b6b2012-11-28 23:21:15507 const ActionInfo* system_indicator_info() const {
508 return system_indicator_info_.get();
509 }
[email protected]6f229e82010-11-02 17:47:26510 const std::vector<PluginInfo>& plugins() const { return plugins_; }
[email protected]65378f52011-04-08 02:31:23511 const std::vector<NaClModuleInfo>& nacl_modules() const {
512 return nacl_modules_;
513 }
[email protected]a03d4448f2012-01-10 23:25:28514 bool has_background_page() const {
515 return background_url_.is_valid() || !background_scripts_.empty();
516 }
[email protected]7b54ca02012-03-02 18:06:53517 bool allow_background_js_access() const {
518 return allow_background_js_access_;
519 }
[email protected]a03d4448f2012-01-10 23:25:28520 const std::vector<std::string>& background_scripts() const {
521 return background_scripts_;
522 }
[email protected]d2aa06b2012-03-21 20:57:26523 bool has_persistent_background_page() const {
[email protected]dd62fa802012-04-25 18:37:00524 return has_background_page() && background_page_is_persistent_;
[email protected]d2aa06b2012-03-21 20:57:26525 }
526 bool has_lazy_background_page() const {
[email protected]dd62fa802012-04-25 18:37:00527 return has_background_page() && !background_page_is_persistent_;
[email protected]d2aa06b2012-03-21 20:57:26528 }
[email protected]c2e66e12012-06-27 06:27:06529 const PermissionSet* optional_permission_set() const {
[email protected]902fd7b2011-07-27 18:42:31530 return optional_permission_set_.get();
531 }
[email protected]c2e66e12012-06-27 06:27:06532 const PermissionSet* required_permission_set() const {
[email protected]902fd7b2011-07-27 18:42:31533 return required_permission_set_.get();
[email protected]6f229e82010-11-02 17:47:26534 }
[email protected]465594632013-02-15 19:50:28535 // Returns the temporary APIPermissionSet used in initialization.
536 // (NULL after initialization is completed.)
537 APIPermissionSet* initial_api_permissions() {
538 return initial_api_permissions_.get();
539 }
[email protected]23b3c0a2013-01-16 23:36:36540 // Appends |new_warning[s]| to install_warnings_.
541 void AddInstallWarning(const InstallWarning& new_warning);
[email protected]1d5e58b2013-01-31 08:41:40542 void AddInstallWarnings(const std::vector<InstallWarning>& new_warnings);
543 const std::vector<InstallWarning>& install_warnings() const {
[email protected]8629c542012-04-20 03:40:03544 return install_warnings_;
545 }
[email protected]6f229e82010-11-02 17:47:26546 const ExtensionIconSet& icons() const { return icons_; }
[email protected]953620b2011-12-04 00:55:32547 const extensions::Manifest* manifest() const {
[email protected]e9629d772012-08-06 19:44:46548 return manifest_.get();
[email protected]6f229e82010-11-02 17:47:26549 }
[email protected]6f229e82010-11-02 17:47:26550 bool incognito_split_mode() const { return incognito_split_mode_; }
[email protected]1abdf4f2011-08-16 21:11:55551 bool offline_enabled() const { return offline_enabled_; }
[email protected]3aff9ad2011-04-01 20:26:48552 bool wants_file_access() const { return wants_file_access_; }
[email protected]2af352b2011-07-22 08:21:23553 int creation_flags() const { return creation_flags_; }
554 bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; }
[email protected]e805baf2011-07-26 18:23:05555 bool from_bookmark() const { return (creation_flags_ & FROM_BOOKMARK) != 0; }
[email protected]e33bbc22012-08-27 22:05:46556 bool was_installed_by_default() const {
557 return (creation_flags_ & WAS_INSTALLED_BY_DEFAULT) != 0;
558 }
[email protected]3aff9ad2011-04-01 20:26:48559
[email protected]6f229e82010-11-02 17:47:26560 // App-related.
[email protected]953620b2011-12-04 00:55:32561 bool is_app() const {
[email protected]c4f459d2012-09-28 04:40:10562 return is_legacy_packaged_app() || is_hosted_app() || is_platform_app();
[email protected]23690872011-12-01 22:02:39563 }
[email protected]d41e2152012-02-24 04:20:27564 bool is_platform_app() const;
565 bool is_hosted_app() const;
[email protected]c4f459d2012-09-28 04:40:10566 bool is_legacy_packaged_app() const;
[email protected]ff05a4b102012-12-19 00:12:06567 bool is_extension() const;
[email protected]605fb8102012-05-04 01:36:55568 bool is_storage_isolated() const { return is_storage_isolated_; }
[email protected]cdc7b1f42012-12-07 19:39:48569 bool can_be_incognito_enabled() const;
[email protected]636ee43282013-01-12 15:58:00570 void AddWebExtentPattern(const URLPattern& pattern);
[email protected]cced75a2011-05-20 08:31:12571 const URLPatternSet& web_extent() const { return extent_; }
[email protected]6f229e82010-11-02 17:47:26572 const std::string& launch_local_path() const { return launch_local_path_; }
573 const std::string& launch_web_url() const { return launch_web_url_; }
574 extension_misc::LaunchContainer launch_container() const {
575 return launch_container_;
576 }
[email protected]dc37b002012-04-23 23:02:26577 int launch_width() const { return launch_width_; }
578 int launch_height() const { return launch_height_; }
[email protected]6f229e82010-11-02 17:47:26579
580 // Theme-related.
[email protected]d41e2152012-02-24 04:20:27581 bool is_theme() const;
[email protected]6f229e82010-11-02 17:47:26582
[email protected]66008002013-01-08 09:09:13583 // Content pack related.
[email protected]fbb620832013-01-25 17:20:35584 bool is_content_pack() const;
[email protected]66008002013-01-08 09:09:13585 ExtensionResource GetContentPackSiteList() const;
586
[email protected]a03d4448f2012-01-10 23:25:28587 GURL GetBackgroundURL() const;
588
[email protected]4a8d3272009-03-10 19:15:08589 private:
[email protected]66e4eb32010-10-27 20:37:41590 friend class base::RefCountedThreadSafe<Extension>;
591
[email protected]902fd7b2011-07-27 18:42:31592 class RuntimeData {
593 public:
594 RuntimeData();
[email protected]c2e66e12012-06-27 06:27:06595 explicit RuntimeData(const PermissionSet* active);
[email protected]902fd7b2011-07-27 18:42:31596 ~RuntimeData();
597
[email protected]c2e66e12012-06-27 06:27:06598 void SetActivePermissions(const PermissionSet* active);
599 scoped_refptr<const PermissionSet> GetActivePermissions() const;
[email protected]902fd7b2011-07-27 18:42:31600
[email protected]3d0e2262012-08-02 15:32:16601 scoped_refptr<const PermissionSet> GetTabSpecificPermissions(int tab_id)
602 const;
[email protected]6144057e2012-08-02 19:02:37603 void UpdateTabSpecificPermissions(
604 int tab_id,
605 scoped_refptr<const PermissionSet> permissions);
[email protected]3d0e2262012-08-02 15:32:16606 void ClearTabSpecificPermissions(int tab_id);
[email protected]fc5e65d6b2012-06-13 00:22:57607
[email protected]902fd7b2011-07-27 18:42:31608 private:
609 friend class base::RefCountedThreadSafe<RuntimeData>;
[email protected]fc5e65d6b2012-06-13 00:22:57610
[email protected]c2e66e12012-06-27 06:27:06611 scoped_refptr<const PermissionSet> active_permissions_;
[email protected]fc5e65d6b2012-06-13 00:22:57612
[email protected]3d0e2262012-08-02 15:32:16613 typedef std::map<int, scoped_refptr<const PermissionSet> >
614 TabPermissionsMap;
615 TabPermissionsMap tab_specific_permissions_;
[email protected]902fd7b2011-07-27 18:42:31616 };
617
[email protected]d41e2152012-02-24 04:20:27618 // Chooses the extension ID for an extension based on a variety of criteria.
619 // The chosen ID will be set in |manifest|.
620 static bool InitExtensionID(extensions::Manifest* manifest,
[email protected]a7329162013-02-07 19:21:48621 const base::FilePath& path,
[email protected]d41e2152012-02-24 04:20:27622 const std::string& explicit_id,
623 int creation_flags,
624 string16* error);
625
[email protected]4ead6f72010-10-13 19:54:18626 // Normalize the path for use by the extension. On Windows, this will make
627 // sure the drive letter is uppercase.
[email protected]a7329162013-02-07 19:21:48628 static base::FilePath MaybeNormalizePath(const base::FilePath& path);
[email protected]4ead6f72010-10-13 19:54:18629
[email protected]87c655e2011-07-01 21:42:00630 // Returns true if this extension id is from a trusted provider.
631 static bool IsTrustedId(const std::string& id);
632
[email protected]a7329162013-02-07 19:21:48633 Extension(const base::FilePath& path,
634 scoped_ptr<extensions::Manifest> manifest);
[email protected]d356c982012-12-12 19:32:55635 virtual ~Extension();
[email protected]66e4eb32010-10-27 20:37:41636
637 // Initialize the extension from a parsed manifest.
[email protected]d41e2152012-02-24 04:20:27638 // TODO(aa): Rename to just Init()? There's no Value here anymore.
639 // TODO(aa): It is really weird the way this class essentially contains a copy
640 // of the underlying DictionaryValue in its members. We should decide to
641 // either wrap the DictionaryValue and go with that only, or we should parse
642 // into strong types and discard the value. But doing both is bad.
643 bool InitFromValue(int flags, string16* error);
[email protected]66e4eb32010-10-27 20:37:41644
[email protected]58f62cf2012-03-09 10:45:11645 // The following are helpers for InitFromValue to load various features of the
646 // extension from the manifest.
647
[email protected]465594632013-02-15 19:50:28648 bool LoadAppIsolation(string16* error);
[email protected]58f62cf2012-03-09 10:45:11649
650 bool LoadRequiredFeatures(string16* error);
651 bool LoadName(string16* error);
652 bool LoadVersion(string16* error);
653
654 bool LoadAppFeatures(string16* error);
[email protected]d41e2152012-02-24 04:20:27655 bool LoadExtent(const char* key,
656 URLPatternSet* extent,
657 const char* list_error,
658 const char* value_error,
659 string16* error);
660 bool LoadLaunchContainer(string16* error);
661 bool LoadLaunchURL(string16* error);
[email protected]10253da2012-03-09 04:06:42662
[email protected]465594632013-02-15 19:50:28663 bool LoadSharedFeatures(string16* error);
[email protected]58f62cf2012-03-09 10:45:11664 bool LoadDescription(string16* error);
665 bool LoadManifestVersion(string16* error);
[email protected]58f62cf2012-03-09 10:45:11666 bool LoadIcons(string16* error);
[email protected]58f62cf2012-03-09 10:45:11667 bool LoadPlugins(string16* error);
668 bool LoadNaClModules(string16* error);
[email protected]dbb24162012-06-06 01:41:22669 bool LoadSandboxedPages(string16* error);
[email protected]98270432012-09-11 20:51:24670 // Must be called after LoadPlugins().
671 bool LoadRequirements(string16* error);
[email protected]58f62cf2012-03-09 10:45:11672 bool LoadOfflineEnabled(string16* error);
[email protected]d41e2152012-02-24 04:20:27673 bool LoadBackgroundScripts(string16* error);
[email protected]756038532012-06-08 05:45:03674 bool LoadBackgroundScripts(const std::string& key, string16* error);
[email protected]465594632013-02-15 19:50:28675 bool LoadBackgroundPage(string16* error);
[email protected]756038532012-06-08 05:45:03676 bool LoadBackgroundPage(const std::string& key,
[email protected]756038532012-06-08 05:45:03677 string16* error);
[email protected]465594632013-02-15 19:50:28678 bool LoadBackgroundPersistent(string16* error);
679 bool LoadBackgroundAllowJSAccess(string16* error);
680 bool LoadExtensionFeatures(string16* error);
[email protected]58f62cf2012-03-09 10:45:11681 bool LoadContentScripts(string16* error);
[email protected]58f62cf2012-03-09 10:45:11682 bool LoadBrowserAction(string16* error);
[email protected]465594632013-02-15 19:50:28683 bool LoadSystemIndicator(string16* error);
[email protected]58f62cf2012-03-09 10:45:11684 bool LoadTextToSpeechVoices(string16* error);
685 bool LoadIncognitoMode(string16* error);
[email protected]66008002013-01-08 09:09:13686 bool LoadManagedModeFeatures(string16* error);
687 bool LoadManagedModeSites(
688 const base::DictionaryValue* content_pack_value,
689 string16* error);
690 bool LoadManagedModeConfigurations(
691 const base::DictionaryValue* content_pack_value,
692 string16* error);
693
[email protected]3cfbd0e2009-03-18 21:26:24694 // Helper method that loads a UserScript object from a
695 // dictionary in the content_script list of the manifest.
[email protected]f3a1c642011-07-12 19:15:03696 bool LoadUserScriptHelper(const base::DictionaryValue* content_script,
[email protected]3cfbd0e2009-03-18 21:26:24697 int definition_index,
[email protected]fc670822011-12-17 09:33:49698 string16* error,
[email protected]3cfbd0e2009-03-18 21:26:24699 UserScript* result);
[email protected]f7f3a5f2009-05-01 22:02:34700
[email protected]6657afa62009-11-04 02:15:20701 // Helper method that loads either the include_globs or exclude_globs list
702 // from an entry in the content_script lists of the manifest.
[email protected]f3a1c642011-07-12 19:15:03703 bool LoadGlobsHelper(const base::DictionaryValue* content_script,
[email protected]6657afa62009-11-04 02:15:20704 int content_script_index,
[email protected]e2194742010-08-12 05:54:34705 const char* globs_property_name,
[email protected]fc670822011-12-17 09:33:49706 string16* error,
[email protected]11f4857282009-11-13 19:56:17707 void(UserScript::*add_method)(const std::string& glob),
[email protected]488e6502012-09-07 14:17:34708 UserScript* instance);
[email protected]6657afa62009-11-04 02:15:20709
[email protected]2f6698b2010-10-14 00:58:21710 // Returns true if the extension has more than one "UI surface". For example,
711 // an extension that has a browser action and a page action.
712 bool HasMultipleUISurfaces() const;
713
[email protected]be9d9c82011-07-13 04:17:31714 // Updates the launch URL and extents for the extension using the given
715 // |override_url|.
716 void OverrideLaunchUrl(const GURL& override_url);
717
[email protected]ae655e4e2012-03-16 21:47:55718 // Custom checks for the experimental permission that can't be expressed in
719 // _permission_features.json.
[email protected]5eddc3e2011-10-26 04:33:31720 bool CanSpecifyExperimentalPermission() const;
[email protected]5eddc3e2011-10-26 04:33:31721
722 // Checks whether the host |pattern| is allowed for this extension, given API
723 // permissions |permissions|.
724 bool CanSpecifyHostPermission(const URLPattern& pattern,
[email protected]465594632013-02-15 19:50:28725 const APIPermissionSet& permissions) const;
[email protected]5eddc3e2011-10-26 04:33:31726
[email protected]488e6502012-09-07 14:17:34727 bool CheckMinimumChromeVersion(string16* error) const;
[email protected]488e6502012-09-07 14:17:34728
[email protected]e92169e2012-05-04 22:49:32729 // Check that platform app features are valid. Called after InitFromValue.
[email protected]488e6502012-09-07 14:17:34730 bool CheckPlatformAppFeatures(std::string* utf8_error) const;
[email protected]e92169e2012-05-04 22:49:32731
[email protected]f1bab9c92012-05-11 21:15:10732 // Check that features don't conflict. Called after InitFromValue.
[email protected]488e6502012-09-07 14:17:34733 bool CheckConflictingFeatures(std::string* utf8_error) const;
[email protected]f1bab9c92012-05-11 21:15:10734
[email protected]6f229e82010-11-02 17:47:26735 // The extension's human-readable name. Name is used for display purpose. It
736 // might be wrapped with unicode bidi control characters so that it is
737 // displayed correctly in RTL context.
738 // NOTE: Name is UTF-8 and may contain non-ascii characters.
739 std::string name_;
740
[email protected]701d1e82012-05-14 05:34:19741 // A non-localized version of the extension's name. This is useful for
742 // debug output.
743 std::string non_localized_name_;
744
[email protected]a47c8a22011-11-17 18:40:31745 // The version of this extension's manifest. We increase the manifest
746 // version when making breaking changes to the extension system.
747 // Version 1 was the first manifest version (implied by a lack of a
748 // manifest_version attribute in the extension's manifest). We initialize
749 // this member variable to 0 to distinguish the "uninitialized" case from
750 // the case when we know the manifest version actually is 1.
751 int manifest_version_;
752
[email protected]98270432012-09-11 20:51:24753 // The requirements declared in the manifest.
754 Requirements requirements_;
755
[email protected]d41e2152012-02-24 04:20:27756 // The absolute path to the directory the extension is stored in.
[email protected]a7329162013-02-07 19:21:48757 base::FilePath path_;
[email protected]d41e2152012-02-24 04:20:27758
[email protected]6f229e82010-11-02 17:47:26759 // If true, a separate process will be used for the extension in incognito
760 // mode.
761 bool incognito_split_mode_;
762
[email protected]1abdf4f2011-08-16 21:11:55763 // Whether the extension or app should be enabled when offline.
764 bool offline_enabled_;
765
[email protected]6f229e82010-11-02 17:47:26766 // Defines the set of URLs in the extension's web content.
[email protected]cced75a2011-05-20 08:31:12767 URLPatternSet extent_;
[email protected]6f229e82010-11-02 17:47:26768
[email protected]902fd7b2011-07-27 18:42:31769 // The extension runtime data.
770 mutable base::Lock runtime_data_lock_;
771 mutable RuntimeData runtime_data_;
772
[email protected]465594632013-02-15 19:50:28773 // The API permission set; used during extension initialization.
774 // Cleared after permissions are finalized by SetActivePermissions.
775 scoped_ptr<APIPermissionSet> initial_api_permissions_;
776
[email protected]902fd7b2011-07-27 18:42:31777 // The set of permissions the extension can request at runtime.
[email protected]c2e66e12012-06-27 06:27:06778 scoped_refptr<const PermissionSet> optional_permission_set_;
[email protected]902fd7b2011-07-27 18:42:31779
780 // The extension's required / default set of permissions.
[email protected]c2e66e12012-06-27 06:27:06781 scoped_refptr<const PermissionSet> required_permission_set_;
[email protected]6f229e82010-11-02 17:47:26782
[email protected]8629c542012-04-20 03:40:03783 // Any warnings that occurred when trying to create/parse the extension.
[email protected]1d5e58b2013-01-31 08:41:40784 std::vector<InstallWarning> install_warnings_;
[email protected]8629c542012-04-20 03:40:03785
[email protected]6f229e82010-11-02 17:47:26786 // The icons for the extension.
787 ExtensionIconSet icons_;
788
789 // The base extension url for the extension.
790 GURL extension_url_;
791
[email protected]6f229e82010-11-02 17:47:26792 // The extension's version.
793 scoped_ptr<Version> version_;
794
795 // An optional longer description of the extension.
796 std::string description_;
797
798 // True if the extension was generated from a user script. (We show slightly
799 // different UI if so).
800 bool converted_from_user_script_;
801
802 // Paths to the content scripts the extension contains.
803 UserScriptList content_scripts_;
804
[email protected]ad12b6b2012-11-28 23:21:15805 // The extension's system indicator, if any.
806 scoped_ptr<ActionInfo> system_indicator_info_;
807
[email protected]6f229e82010-11-02 17:47:26808 // Optional list of NPAPI plugins and associated properties.
809 std::vector<PluginInfo> plugins_;
810
[email protected]65378f52011-04-08 02:31:23811 // Optional list of NaCl modules and associated properties.
812 std::vector<NaClModuleInfo> nacl_modules_;
813
[email protected]dbb24162012-06-06 01:41:22814 // Optional list of extension pages that are sandboxed (served from a unique
815 // origin with a different Content Security Policy).
[email protected]f59a8052012-06-20 22:25:00816 URLPatternSet sandboxed_pages_;
[email protected]dbb24162012-06-06 01:41:22817
818 // Content Security Policy that should be used to enforce the sandbox used
819 // by sandboxed pages (guaranteed to have the "sandbox" directive without the
820 // "allow-same-origin" token).
821 std::string sandboxed_pages_content_security_policy_;
822
[email protected]6f229e82010-11-02 17:47:26823 // Optional URL to a master page of which a single instance should be always
824 // loaded in the background.
825 GURL background_url_;
826
[email protected]a03d4448f2012-01-10 23:25:28827 // Optional list of scripts to use to generate a background page. If this is
828 // present, background_url_ will be empty and generated by GetBackgroundURL().
829 std::vector<std::string> background_scripts_;
830
[email protected]dd62fa802012-04-25 18:37:00831 // True if the background page should stay loaded forever; false if it should
832 // load on-demand (when it needs to handle an event). Defaults to true.
833 bool background_page_is_persistent_;
[email protected]9e6720a2012-01-24 02:30:56834
[email protected]7b54ca02012-03-02 18:06:53835 // True if the background page can be scripted by pages of the app or
836 // extension, in which case all such pages must run in the same process.
837 // False if such pages are not permitted to script the background page,
838 // allowing them to run in different processes.
839 bool allow_background_js_access_;
840
[email protected]6f229e82010-11-02 17:47:26841 // The public key used to sign the contents of the crx package.
842 std::string public_key_;
843
[email protected]66008002013-01-08 09:09:13844 // A file containing a list of sites for Managed Mode.
[email protected]a7329162013-02-07 19:21:48845 base::FilePath content_pack_site_list_;
[email protected]66008002013-01-08 09:09:13846
[email protected]58f62cf2012-03-09 10:45:11847 // The manifest from which this extension was created.
[email protected]e9629d772012-08-06 19:44:46848 scoped_ptr<Manifest> manifest_;
[email protected]6f229e82010-11-02 17:47:26849
[email protected]d356c982012-12-12 19:32:55850 // Stored parsed manifest data.
851 ManifestDataMap manifest_data_;
852
853 // Set to true at the end of InitValue when initialization is finished.
854 bool finished_parsing_manifest_;
855
[email protected]7eeab9ec2013-01-15 04:08:33856 // Ensures that any call to GetManifestData() prior to finishing
857 // initialization happens from the same thread (this can happen when certain
858 // parts of the initialization process need information from previous parts).
859 base::ThreadChecker thread_checker_;
860
[email protected]d9696672011-03-15 22:45:09861 // Whether this extension requests isolated storage.
862 bool is_storage_isolated_;
863
[email protected]6f229e82010-11-02 17:47:26864 // The local path inside the extension to use with the launcher.
865 std::string launch_local_path_;
866
867 // A web url to use with the launcher. Note that this might be relative or
868 // absolute. If relative, it is relative to web_origin.
869 std::string launch_web_url_;
870
[email protected]4e595682011-02-09 17:07:02871 // The window type that an app's manifest specifies to launch into.
872 // This is not always the window type an app will open into, because
873 // users can override the way each app launches. See
874 // ExtensionPrefs::GetLaunchContainer(), which looks at a per-app pref
875 // to decide what container an app will launch in.
[email protected]6f229e82010-11-02 17:47:26876 extension_misc::LaunchContainer launch_container_;
877
878 // The default size of the container when launching. Only respected for
879 // containers like panels and windows.
880 int launch_width_;
881 int launch_height_;
882
[email protected]7e0f92b2012-11-09 03:51:04883 // Should this app be shown in the app launcher.
[email protected]ed1a204f2012-09-22 00:28:44884 bool display_in_launcher_;
885
[email protected]7e0f92b2012-11-09 03:51:04886 // Should this app be shown in the browser New Tab Page.
887 bool display_in_new_tab_page_;
888
[email protected]3aff9ad2011-04-01 20:26:48889 // Whether the extension has host permissions or user script patterns that
890 // imply access to file:/// scheme URLs (the user may not have actually
891 // granted it that access).
892 bool wants_file_access_;
893
[email protected]2af352b2011-07-22 08:21:23894 // The flags that were passed to InitFromValue.
895 int creation_flags_;
[email protected]620db1762011-07-15 21:57:34896
[email protected]1c321ee2012-05-21 03:02:34897 FRIEND_TEST_ALL_PREFIXES(::TabStripModelTest, Apps);
[email protected]ae7fe712009-07-02 20:33:58898
[email protected]894bb502009-05-21 22:39:57899 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:33900};
901
[email protected]bc151cf92013-02-12 04:57:26902typedef std::vector<scoped_refptr<const Extension> > ExtensionList;
[email protected]ec5b50d2010-10-09 16:35:18903typedef std::set<std::string> ExtensionIdSet;
[email protected]82590cb2012-09-28 04:14:08904typedef std::vector<std::string> ExtensionIdList;
[email protected]b1748b1d82009-11-30 20:32:56905
[email protected]c6d474f82009-12-16 21:11:06906// Handy struct to pass core extension info around.
907struct ExtensionInfo {
[email protected]f3a1c642011-07-12 19:15:03908 ExtensionInfo(const base::DictionaryValue* manifest,
[email protected]c6d474f82009-12-16 21:11:06909 const std::string& id,
[email protected]a7329162013-02-07 19:21:48910 const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:40911 Manifest::Location location);
[email protected]3bb84992010-08-26 17:23:46912 ~ExtensionInfo();
[email protected]c6d474f82009-12-16 21:11:06913
[email protected]f3a1c642011-07-12 19:15:03914 scoped_ptr<base::DictionaryValue> extension_manifest;
[email protected]c6d474f82009-12-16 21:11:06915 std::string extension_id;
[email protected]a7329162013-02-07 19:21:48916 base::FilePath extension_path;
[email protected]1d5e58b2013-01-31 08:41:40917 Manifest::Location extension_location;
[email protected]c6d474f82009-12-16 21:11:06918
919 private:
920 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
921};
922
[email protected]a9f39a312010-12-23 22:14:27923struct UnloadedExtensionInfo {
[email protected]814a7bf0f2011-08-13 05:30:59924 extension_misc::UnloadedExtensionReason reason;
[email protected]a9f39a312010-12-23 22:14:27925
926 // Was the extension already disabled?
927 bool already_disabled;
928
929 // The extension being unloaded - this should always be non-NULL.
930 const Extension* extension;
931
[email protected]814a7bf0f2011-08-13 05:30:59932 UnloadedExtensionInfo(
933 const Extension* extension,
934 extension_misc::UnloadedExtensionReason reason);
[email protected]a9f39a312010-12-23 22:14:27935};
936
[email protected]902fd7b2011-07-27 18:42:31937// The details sent for EXTENSION_PERMISSIONS_UPDATED notifications.
938struct UpdatedExtensionPermissionsInfo {
939 enum Reason {
[email protected]f5532472012-02-23 13:00:55940 ADDED, // The permissions were added to the extension.
941 REMOVED, // The permissions were removed from the extension.
[email protected]902fd7b2011-07-27 18:42:31942 };
943
944 Reason reason;
945
946 // The extension who's permissions have changed.
947 const Extension* extension;
948
949 // The permissions that have changed. For Reason::ADDED, this would contain
950 // only the permissions that have added, and for Reason::REMOVED, this would
951 // only contain the removed permissions.
[email protected]c2e66e12012-06-27 06:27:06952 const PermissionSet* permissions;
[email protected]902fd7b2011-07-27 18:42:31953
954 UpdatedExtensionPermissionsInfo(
955 const Extension* extension,
[email protected]c2e66e12012-06-27 06:27:06956 const PermissionSet* permissions,
[email protected]902fd7b2011-07-27 18:42:31957 Reason reason);
958};
959
[email protected]488e6502012-09-07 14:17:34960} // namespace extensions
[email protected]1c321ee2012-05-21 03:02:34961
[email protected]5b1a0e22009-05-26 19:00:58962#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_