blob: 1423adb7be57dda3fe1c4ac8c52d560cb201c311 [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]e4452d32013-11-15 23:07:415#ifndef EXTENSIONS_COMMON_EXTENSION_H_
6#define EXTENSIONS_COMMON_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]14c1c232013-06-11 17:52:4416#include "base/containers/hash_tables.h"
[email protected]57999812013-02-24 05:40:5217#include "base/files/file_path.h"
[email protected]b6b805e92011-04-16 09:24:1418#include "base/memory/linked_ptr.h"
[email protected]3b63f8f42011-03-28 01:54:1519#include "base/memory/ref_counted.h"
20#include "base/memory/scoped_ptr.h"
[email protected]902fd7b2011-07-27 18:42:3121#include "base/synchronization/lock.h"
[email protected]7eeab9ec2013-01-15 04:08:3322#include "base/threading/thread_checker.h"
[email protected]993da5e2013-03-23 21:25:1623#include "extensions/common/extension_resource.h"
[email protected]1d5e58b2013-01-31 08:41:4024#include "extensions/common/install_warning.h"
[email protected]d42c11152013-08-22 19:36:3225#include "extensions/common/manifest.h"
[email protected]793964a2013-10-08 00:47:1926#include "extensions/common/permissions/api_permission.h"
[email protected]885c0e92012-11-13 20:27:4227#include "extensions/common/url_pattern.h"
[email protected]e9f541a2012-11-19 21:52:3128#include "extensions/common/url_pattern_set.h"
[email protected]f5532472012-02-23 13:00:5529#include "ui/base/accelerators/accelerator.h"
[email protected]08397d52011-02-05 01:53:3830#include "ui/gfx/size.h"
[email protected]5f5ef802013-07-04 16:11:1331#include "url/gurl.h"
[email protected]eab9b452009-01-23 20:48:5932
[email protected]0f34d9082012-10-08 19:16:4433class ExtensionAction;
[email protected]12802702010-07-09 19:43:0934class SkBitmap;
[email protected]942690b132010-05-11 06:42:1435
[email protected]f3a1c642011-07-12 19:15:0336namespace base {
37class DictionaryValue;
[email protected]1f04ef42013-04-22 07:35:5038class Version;
[email protected]f3a1c642011-07-12 19:15:0339}
40
[email protected]0f34d9082012-10-08 19:16:4441namespace gfx {
42class ImageSkia;
43}
44
[email protected]1c321ee2012-05-21 03:02:3445namespace extensions {
[email protected]465594632013-02-15 19:50:2846class APIPermissionSet;
[email protected]e737c442013-11-15 15:55:2447class ManifestPermissionSet;
[email protected]bebe1d02012-08-02 20:17:0948class PermissionSet;
[email protected]d695bb12014-06-05 16:16:3049class PermissionsData;
50class PermissionsParser;
[email protected]1c321ee2012-05-21 03:02:3451
[email protected]53d5f0f462014-03-07 09:15:2052// Uniquely identifies an Extension, using 32 characters from the alphabet
53// 'a'-'p'. An empty string represents "no extension".
54//
55// Note: If this gets used heavily in files that don't otherwise need to include
56// extension.h, we should pull it into a dedicated header.
57typedef std::string ExtensionId;
58
[email protected]f0755532010-06-22 07:27:2559// Represents a Chrome extension.
[email protected]5cd56342013-04-03 19:50:4760// Once created, an Extension object is immutable, with the exception of its
61// RuntimeData. This makes it safe to use on any thread, since access to the
62// RuntimeData is protected by a lock.
[email protected]66e4eb32010-10-27 20:37:4163class Extension : public base::RefCountedThreadSafe<Extension> {
[email protected]7713d632008-12-02 07:52:3364 public:
[email protected]d356c982012-12-12 19:32:5565 struct ManifestData;
[email protected]1e0f45a2012-06-13 00:31:0666
[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]1b563df2013-10-30 16:49:3699 DISABLE_PERMISSIONS_CONSENT = 1 << 6, // Unused - abandoned experiment.
[email protected]59ee99d2013-10-11 15:46:16100 DISABLE_KNOWN_DISABLED = 1 << 7,
[email protected]2d19eb6e2014-01-27 17:30:00101 DISABLE_NOT_VERIFIED = 1 << 8, // Disabled because we could not verify
102 // the install.
[email protected]e1e2da32014-05-05 13:11:37103 DISABLE_GREYLIST = 1 << 9,
104 DISABLE_CORRUPTED = 1 << 10,
[email protected]21db9ef2014-05-16 02:06:27105 DISABLE_REMOTE_INSTALL = 1 << 11
[email protected]44d62b62012-04-11 00:06:03106 };
107
[email protected]fbcc40302009-06-12 20:45:45108 enum InstallType {
[email protected]ab6f2b22009-07-28 23:28:37109 INSTALL_ERROR,
[email protected]fbcc40302009-06-12 20:45:45110 DOWNGRADE,
111 REINSTALL,
112 UPGRADE,
113 NEW_INSTALL
114 };
115
[email protected]d356c982012-12-12 19:32:55116 // A base class for parsed manifest data that APIs want to store on
117 // the extension. Related to base::SupportsUserData, but with an immutable
118 // thread-safe interface to match Extension.
119 struct ManifestData {
120 virtual ~ManifestData() {}
121 };
122
[email protected]f9c5d392014-05-13 05:34:18123 // Do not change the order of entries or remove entries in this list
124 // as this is used in UMA_HISTOGRAM_ENUMERATIONs about extensions.
[email protected]83048a22011-03-29 00:14:13125 enum InitFromValueFlags {
126 NO_FLAGS = 0,
127
128 // Usually, the id of an extension is generated by the "key" property of
129 // its manifest, but if |REQUIRE_KEY| is not set, a temporary ID will be
130 // generated based on the path.
131 REQUIRE_KEY = 1 << 0,
132
[email protected]3f53dfe2011-11-30 01:18:29133 // Requires the extension to have an up-to-date manifest version.
134 // Typically, we'll support multiple manifest versions during a version
[email protected]26367b62012-10-04 23:03:32135 // transition. This flag signals that we want to require the most modern
[email protected]3f53dfe2011-11-30 01:18:29136 // manifest version that Chrome understands.
137 REQUIRE_MODERN_MANIFEST_VERSION = 1 << 1,
138
[email protected]3aff9ad2011-04-01 20:26:48139 // |ALLOW_FILE_ACCESS| indicates that the user is allowing this extension
140 // to have file access. If it's not present, then permissions and content
141 // scripts that match file:/// URLs will be filtered out.
[email protected]ed3b9b12012-05-31 18:37:51142 ALLOW_FILE_ACCESS = 1 << 2,
[email protected]620db1762011-07-15 21:57:34143
144 // |FROM_WEBSTORE| indicates that the extension was installed from the
145 // Chrome Web Store.
[email protected]ed3b9b12012-05-31 18:37:51146 FROM_WEBSTORE = 1 << 3,
[email protected]e805baf2011-07-26 18:23:05147
[email protected]46601462014-02-04 11:08:50148 // |FROM_BOOKMARK| indicates the extension is a bookmark app which has been
149 // generated from a web page. Bookmark apps have no permissions or extent
150 // and launch the web page they are created from when run.
[email protected]ed3b9b12012-05-31 18:37:51151 FROM_BOOKMARK = 1 << 4,
[email protected]3d41d432012-04-20 20:47:58152
153 // |FOLLOW_SYMLINKS_ANYWHERE| means that resources can be symlinks to
154 // anywhere in the filesystem, rather than being restricted to the
155 // extension directory.
[email protected]ed3b9b12012-05-31 18:37:51156 FOLLOW_SYMLINKS_ANYWHERE = 1 << 5,
[email protected]ab55c2b2012-06-01 23:55:03157
158 // |ERROR_ON_PRIVATE_KEY| means that private keys inside an
159 // extension should be errors rather than warnings.
160 ERROR_ON_PRIVATE_KEY = 1 << 6,
[email protected]e33bbc22012-08-27 22:05:46161
162 // |WAS_INSTALLED_BY_DEFAULT| installed by default when the profile was
163 // created.
164 WAS_INSTALLED_BY_DEFAULT = 1 << 7,
[email protected]aa5a5472013-10-04 03:41:04165
[email protected]1b563df2013-10-30 16:49:36166 // Unused - was part of an abandoned experiment.
[email protected]aa5a5472013-10-04 03:41:04167 REQUIRE_PERMISSIONS_CONSENT = 1 << 8,
[email protected]ce35418b2013-11-25 01:22:33168
[email protected]411f8ae2014-05-22 11:12:23169 // Unused - this flag has been moved to ExtensionPrefs.
[email protected]ce35418b2013-11-25 01:22:33170 IS_EPHEMERAL = 1 << 9,
[email protected]acc3c7c22014-03-19 06:23:39171
172 // |WAS_INSTALLED_BY_OEM| installed by an OEM (e.g on Chrome OS) and should
173 // be placed in a special OEM folder in the App Launcher. Note: OEM apps are
174 // also installed by Default (i.e. WAS_INSTALLED_BY_DEFAULT is also true).
175 WAS_INSTALLED_BY_OEM = 1 << 10,
[email protected]f9c5d392014-05-13 05:34:18176
177 // When adding new flags, make sure to update kInitFromValueFlagBits.
[email protected]83048a22011-03-29 00:14:13178 };
179
[email protected]f9c5d392014-05-13 05:34:18180 // This is the highest bit index of the flags defined above.
181 static const int kInitFromValueFlagBits;
182
[email protected]a7329162013-02-07 19:21:48183 static scoped_refptr<Extension> Create(const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:40184 Manifest::Location location,
[email protected]f3a1c642011-07-12 19:15:03185 const base::DictionaryValue& value,
[email protected]83048a22011-03-29 00:14:13186 int flags,
[email protected]66e4eb32010-10-27 20:37:41187 std::string* error);
188
[email protected]87c655e2011-07-01 21:42:00189 // In a few special circumstances, we want to create an Extension and give it
[email protected]f5bf1842012-02-15 02:52:26190 // an explicit id. Most consumers should just use the other Create() method.
[email protected]a7329162013-02-07 19:21:48191 static scoped_refptr<Extension> Create(const base::FilePath& path,
[email protected]2cb5e302013-05-09 05:00:06192 Manifest::Location location,
193 const base::DictionaryValue& value,
194 int flags,
[email protected]53d5f0f462014-03-07 09:15:20195 const ExtensionId& explicit_id,
[email protected]2cb5e302013-05-09 05:00:06196 std::string* error);
[email protected]87c655e2011-07-01 21:42:00197
[email protected]8d888c12010-11-30 00:00:25198 // Valid schemes for web extent URLPatterns.
199 static const int kValidWebExtentSchemes;
200
[email protected]f71f7e62010-12-07 03:45:33201 // Valid schemes for host permission URLPatterns.
202 static const int kValidHostPermissionSchemes;
203
[email protected]e435d6b72009-07-25 03:15:58204 // The mimetype used for extensions.
205 static const char kMimeType[];
206
[email protected]25b34332009-06-05 21:53:19207 // Checks to see if the extension has a valid ID.
208 static bool IdIsValid(const std::string& id);
209
[email protected]1d5e58b2013-01-31 08:41:40210 // See Type definition in Manifest.
211 Manifest::Type GetType() const;
[email protected]9b217652010-10-08 22:04:23212
[email protected]07c00d992009-03-04 20:27:04213 // Returns an absolute url to a resource inside of an extension. The
[email protected]eab9b452009-01-23 20:48:59214 // |extension_url| argument should be the url() from an Extension object. The
215 // |relative_path| can be untrusted user input. The returned URL will either
216 // be invalid() or a child of |extension_url|.
217 // NOTE: Static so that it can be used from multiple threads.
218 static GURL GetResourceURL(const GURL& extension_url,
219 const std::string& relative_path);
[email protected]cffd7892010-08-26 17:43:28220 GURL GetResourceURL(const std::string& relative_path) const {
[email protected]3cfbd0e2009-03-18 21:26:24221 return GetResourceURL(url(), relative_path);
222 }
[email protected]eab9b452009-01-23 20:48:59223
[email protected]f59a8052012-06-20 22:25:00224 // Returns true if the resource matches a pattern in the pattern_set.
225 bool ResourceMatches(const URLPatternSet& pattern_set,
226 const std::string& resource) const;
227
[email protected]99efb7b12009-12-18 02:39:16228 // Returns an extension resource object. |relative_path| should be UTF8
229 // encoded.
[email protected]9adb9692010-10-29 23:14:02230 ExtensionResource GetResource(const std::string& relative_path) const;
[email protected]99efb7b12009-12-18 02:39:16231
232 // As above, but with |relative_path| following the file system's encoding.
[email protected]a7329162013-02-07 19:21:48233 ExtensionResource GetResource(const base::FilePath& relative_path) const;
[email protected]eab9b452009-01-23 20:48:59234
[email protected]a17f9462009-06-09 02:56:41235 // |input| is expected to be the text of an rsa public or private key. It
236 // tolerates the presence or absence of bracking header/footer like this:
237 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
238 // and may contain newlines.
239 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
240
241 // Does a simple base64 encoding of |input| into |output|.
242 static bool ProducePEM(const std::string& input, std::string* output);
243
244 // Expects base64 encoded |input| and formats into |output| including
245 // the appropriate header & footer.
[email protected]e0d08192011-03-29 19:02:50246 static bool FormatPEMForFileOutput(const std::string& input,
247 std::string* output,
248 bool is_public);
[email protected]a17f9462009-06-09 02:56:41249
[email protected]a807bbe2010-04-14 10:51:19250 // Returns the base extension url for a given |extension_id|.
[email protected]53d5f0f462014-03-07 09:15:20251 static GURL GetBaseURLFromExtensionId(const ExtensionId& extension_id);
[email protected]a807bbe2010-04-14 10:51:19252
[email protected]13c68b62013-05-17 11:29:05253 // DEPRECATED: These methods have been moved to PermissionsData.
254 // TODO(rdevlin.cronin): remove these once all calls have been updated.
[email protected]c2e66e12012-06-27 06:27:06255 bool HasAPIPermission(APIPermission::ID permission) const;
[email protected]b5b26b72013-08-02 00:25:11256 bool HasAPIPermission(const std::string& permission_name) const;
[email protected]c2e66e12012-06-27 06:27:06257 scoped_refptr<const PermissionSet> GetActivePermissions() const;
[email protected]902fd7b2011-07-27 18:42:31258
[email protected]5df6a5d2011-01-26 07:39:12259 // Whether context menu should be shown for page and browser actions.
260 bool ShowConfigureContextMenus() const;
261
[email protected]cca147172011-02-17 01:29:29262 // Returns true if this extension or app includes areas within |origin|.
263 bool OverlapsWithOrigin(const GURL& origin) const;
264
[email protected]7e0f92b2012-11-09 03:51:04265 // Returns true if the extension requires a valid ordinal for sorting, e.g.,
266 // for displaying in a launcher or new tab page.
267 bool RequiresSortOrdinal() const;
268
269 // Returns true if the extension should be displayed in the app launcher.
270 bool ShouldDisplayInAppLauncher() const;
271
272 // Returns true if the extension should be displayed in the browser NTP.
273 bool ShouldDisplayInNewTabPage() const;
[email protected]b873cd92012-02-09 21:51:48274
[email protected]e0b3de72012-05-01 01:21:34275 // Returns true if the extension should be displayed in the extension
276 // settings page (i.e. chrome://extensions).
277 bool ShouldDisplayInExtensionSettings() const;
278
[email protected]624e63d0c2013-08-16 00:09:50279 // Returns true if the extension should not be shown anywhere. This is
280 // mostly the same as the extension being a component extension, but also
281 // includes non-component apps that are hidden from the app launcher and ntp.
282 bool ShouldNotBeVisible() const;
283
[email protected]d356c982012-12-12 19:32:55284 // Get the manifest data associated with the key, or NULL if there is none.
285 // Can only be called after InitValue is finished.
286 ManifestData* GetManifestData(const std::string& key) const;
287
288 // Sets |data| to be associated with the key. Takes ownership of |data|.
289 // Can only be called before InitValue is finished. Not thread-safe;
290 // all SetManifestData calls should be on only one thread.
291 void SetManifestData(const std::string& key, ManifestData* data);
292
[email protected]6f229e82010-11-02 17:47:26293 // Accessors:
294
[email protected]a7329162013-02-07 19:21:48295 const base::FilePath& path() const { return path_; }
[email protected]6f229e82010-11-02 17:47:26296 const GURL& url() const { return extension_url_; }
[email protected]1d5e58b2013-01-31 08:41:40297 Manifest::Location location() const;
[email protected]53d5f0f462014-03-07 09:15:20298 const ExtensionId& id() const;
[email protected]1f04ef42013-04-22 07:35:50299 const base::Version* version() const { return version_.get(); }
[email protected]6f229e82010-11-02 17:47:26300 const std::string VersionString() const;
301 const std::string& name() const { return name_; }
[email protected]680eaa672013-08-27 10:25:08302 const std::string& short_name() const { return short_name_; }
[email protected]701d1e82012-05-14 05:34:19303 const std::string& non_localized_name() const { return non_localized_name_; }
[email protected]200423d2012-06-05 01:16:06304 // Base64-encoded version of the key used to sign this extension.
305 // In pseudocode, returns
306 // base::Base64Encode(RSAPrivateKey(pem_file).ExportPublicKey()).
307 const std::string& public_key() const { return public_key_; }
[email protected]6f229e82010-11-02 17:47:26308 const std::string& description() const { return description_; }
[email protected]a47c8a22011-11-17 18:40:31309 int manifest_version() const { return manifest_version_; }
[email protected]6f229e82010-11-02 17:47:26310 bool converted_from_user_script() const {
311 return converted_from_user_script_;
312 }
[email protected]d695bb12014-06-05 16:16:30313 PermissionsParser* permissions_parser() { return permissions_parser_.get(); }
314 const PermissionsParser* permissions_parser() const {
315 return permissions_parser_.get();
316 }
317
[email protected]2cb5e302013-05-09 05:00:06318 const PermissionsData* permissions_data() const {
319 return permissions_data_.get();
[email protected]902fd7b2011-07-27 18:42:31320 }
[email protected]2cb5e302013-05-09 05:00:06321
[email protected]23b3c0a2013-01-16 23:36:36322 // Appends |new_warning[s]| to install_warnings_.
323 void AddInstallWarning(const InstallWarning& new_warning);
[email protected]1d5e58b2013-01-31 08:41:40324 void AddInstallWarnings(const std::vector<InstallWarning>& new_warnings);
325 const std::vector<InstallWarning>& install_warnings() const {
[email protected]8629c542012-04-20 03:40:03326 return install_warnings_;
327 }
[email protected]953620b2011-12-04 00:55:32328 const extensions::Manifest* manifest() const {
[email protected]e9629d772012-08-06 19:44:46329 return manifest_.get();
[email protected]6f229e82010-11-02 17:47:26330 }
[email protected]3aff9ad2011-04-01 20:26:48331 bool wants_file_access() const { return wants_file_access_; }
[email protected]334ec0a2013-03-24 01:36:16332 // TODO(rdevlin.cronin): This is needed for ContentScriptsHandler, and should
333 // be moved out as part of crbug.com/159265. This should not be used anywhere
334 // else.
335 void set_wants_file_access(bool wants_file_access) {
336 wants_file_access_ = wants_file_access;
337 }
[email protected]2af352b2011-07-22 08:21:23338 int creation_flags() const { return creation_flags_; }
339 bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; }
[email protected]e805baf2011-07-26 18:23:05340 bool from_bookmark() const { return (creation_flags_ & FROM_BOOKMARK) != 0; }
[email protected]e33bbc22012-08-27 22:05:46341 bool was_installed_by_default() const {
342 return (creation_flags_ & WAS_INSTALLED_BY_DEFAULT) != 0;
343 }
[email protected]acc3c7c22014-03-19 06:23:39344 bool was_installed_by_oem() const {
345 return (creation_flags_ & WAS_INSTALLED_BY_OEM) != 0;
346 }
[email protected]3aff9ad2011-04-01 20:26:48347
[email protected]6f229e82010-11-02 17:47:26348 // App-related.
[email protected]21c01042013-03-10 23:41:14349 bool is_app() const;
[email protected]d41e2152012-02-24 04:20:27350 bool is_platform_app() const;
351 bool is_hosted_app() const;
[email protected]c4f459d2012-09-28 04:40:10352 bool is_legacy_packaged_app() const;
[email protected]ff05a4b102012-12-19 00:12:06353 bool is_extension() const;
[email protected]cdc7b1f42012-12-07 19:39:48354 bool can_be_incognito_enabled() const;
[email protected]6b414c232013-06-05 07:53:34355
[email protected]636ee43282013-01-12 15:58:00356 void AddWebExtentPattern(const URLPattern& pattern);
[email protected]cced75a2011-05-20 08:31:12357 const URLPatternSet& web_extent() const { return extent_; }
[email protected]6f229e82010-11-02 17:47:26358
359 // Theme-related.
[email protected]d41e2152012-02-24 04:20:27360 bool is_theme() const;
[email protected]6f229e82010-11-02 17:47:26361
[email protected]4a8d3272009-03-10 19:15:08362 private:
[email protected]66e4eb32010-10-27 20:37:41363 friend class base::RefCountedThreadSafe<Extension>;
364
[email protected]d41e2152012-02-24 04:20:27365 // Chooses the extension ID for an extension based on a variety of criteria.
366 // The chosen ID will be set in |manifest|.
367 static bool InitExtensionID(extensions::Manifest* manifest,
[email protected]a7329162013-02-07 19:21:48368 const base::FilePath& path,
[email protected]53d5f0f462014-03-07 09:15:20369 const ExtensionId& explicit_id,
[email protected]d41e2152012-02-24 04:20:27370 int creation_flags,
[email protected]0d163dc2013-12-20 23:48:36371 base::string16* error);
[email protected]d41e2152012-02-24 04:20:27372
[email protected]a7329162013-02-07 19:21:48373 Extension(const base::FilePath& path,
374 scoped_ptr<extensions::Manifest> manifest);
[email protected]d356c982012-12-12 19:32:55375 virtual ~Extension();
[email protected]66e4eb32010-10-27 20:37:41376
377 // Initialize the extension from a parsed manifest.
[email protected]d41e2152012-02-24 04:20:27378 // TODO(aa): Rename to just Init()? There's no Value here anymore.
379 // TODO(aa): It is really weird the way this class essentially contains a copy
380 // of the underlying DictionaryValue in its members. We should decide to
381 // either wrap the DictionaryValue and go with that only, or we should parse
382 // into strong types and discard the value. But doing both is bad.
[email protected]0d163dc2013-12-20 23:48:36383 bool InitFromValue(int flags, base::string16* error);
[email protected]66e4eb32010-10-27 20:37:41384
[email protected]58f62cf2012-03-09 10:45:11385 // The following are helpers for InitFromValue to load various features of the
386 // extension from the manifest.
387
[email protected]0d163dc2013-12-20 23:48:36388 bool LoadRequiredFeatures(base::string16* error);
389 bool LoadName(base::string16* error);
390 bool LoadVersion(base::string16* error);
[email protected]58f62cf2012-03-09 10:45:11391
[email protected]0d163dc2013-12-20 23:48:36392 bool LoadAppFeatures(base::string16* error);
[email protected]d41e2152012-02-24 04:20:27393 bool LoadExtent(const char* key,
394 URLPatternSet* extent,
395 const char* list_error,
396 const char* value_error,
[email protected]0d163dc2013-12-20 23:48:36397 base::string16* error);
[email protected]10253da2012-03-09 04:06:42398
[email protected]0d163dc2013-12-20 23:48:36399 bool LoadSharedFeatures(base::string16* error);
400 bool LoadDescription(base::string16* error);
401 bool LoadManifestVersion(base::string16* error);
402 bool LoadShortName(base::string16* error);
[email protected]66008002013-01-08 09:09:13403
[email protected]0d163dc2013-12-20 23:48:36404 bool CheckMinimumChromeVersion(base::string16* error) const;
[email protected]488e6502012-09-07 14:17:34405
[email protected]6f229e82010-11-02 17:47:26406 // The extension's human-readable name. Name is used for display purpose. It
407 // might be wrapped with unicode bidi control characters so that it is
408 // displayed correctly in RTL context.
409 // NOTE: Name is UTF-8 and may contain non-ascii characters.
410 std::string name_;
411
[email protected]701d1e82012-05-14 05:34:19412 // A non-localized version of the extension's name. This is useful for
413 // debug output.
414 std::string non_localized_name_;
415
[email protected]680eaa672013-08-27 10:25:08416 // A short version of the extension's name. This can be used as an alternative
417 // to the name where there is insufficient space to display the full name. If
418 // an extension has not explicitly specified a short name, the value of this
419 // member variable will be the full name rather than an empty string.
420 std::string short_name_;
421
[email protected]a47c8a22011-11-17 18:40:31422 // The version of this extension's manifest. We increase the manifest
423 // version when making breaking changes to the extension system.
424 // Version 1 was the first manifest version (implied by a lack of a
425 // manifest_version attribute in the extension's manifest). We initialize
426 // this member variable to 0 to distinguish the "uninitialized" case from
427 // the case when we know the manifest version actually is 1.
428 int manifest_version_;
429
[email protected]d41e2152012-02-24 04:20:27430 // The absolute path to the directory the extension is stored in.
[email protected]a7329162013-02-07 19:21:48431 base::FilePath path_;
[email protected]d41e2152012-02-24 04:20:27432
[email protected]6f229e82010-11-02 17:47:26433 // Defines the set of URLs in the extension's web content.
[email protected]cced75a2011-05-20 08:31:12434 URLPatternSet extent_;
[email protected]6f229e82010-11-02 17:47:26435
[email protected]d695bb12014-06-05 16:16:30436 // The parser for the manifest's permissions. This is NULL anytime not during
437 // initialization.
438 // TODO(rdevlin.cronin): This doesn't really belong here.
439 scoped_ptr<PermissionsParser> permissions_parser_;
440
441 // The active permissions for the extension.
[email protected]2cb5e302013-05-09 05:00:06442 scoped_ptr<PermissionsData> permissions_data_;
[email protected]6f229e82010-11-02 17:47:26443
[email protected]8629c542012-04-20 03:40:03444 // Any warnings that occurred when trying to create/parse the extension.
[email protected]1d5e58b2013-01-31 08:41:40445 std::vector<InstallWarning> install_warnings_;
[email protected]8629c542012-04-20 03:40:03446
[email protected]6f229e82010-11-02 17:47:26447 // The base extension url for the extension.
448 GURL extension_url_;
449
[email protected]6f229e82010-11-02 17:47:26450 // The extension's version.
[email protected]1f04ef42013-04-22 07:35:50451 scoped_ptr<base::Version> version_;
[email protected]6f229e82010-11-02 17:47:26452
453 // An optional longer description of the extension.
454 std::string description_;
455
456 // True if the extension was generated from a user script. (We show slightly
457 // different UI if so).
458 bool converted_from_user_script_;
459
[email protected]6f229e82010-11-02 17:47:26460 // The public key used to sign the contents of the crx package.
461 std::string public_key_;
462
[email protected]58f62cf2012-03-09 10:45:11463 // The manifest from which this extension was created.
[email protected]e9629d772012-08-06 19:44:46464 scoped_ptr<Manifest> manifest_;
[email protected]6f229e82010-11-02 17:47:26465
[email protected]d356c982012-12-12 19:32:55466 // Stored parsed manifest data.
467 ManifestDataMap manifest_data_;
468
469 // Set to true at the end of InitValue when initialization is finished.
470 bool finished_parsing_manifest_;
471
[email protected]7eeab9ec2013-01-15 04:08:33472 // Ensures that any call to GetManifestData() prior to finishing
473 // initialization happens from the same thread (this can happen when certain
474 // parts of the initialization process need information from previous parts).
475 base::ThreadChecker thread_checker_;
476
[email protected]7e0f92b2012-11-09 03:51:04477 // Should this app be shown in the app launcher.
[email protected]ed1a204f2012-09-22 00:28:44478 bool display_in_launcher_;
479
[email protected]7e0f92b2012-11-09 03:51:04480 // Should this app be shown in the browser New Tab Page.
481 bool display_in_new_tab_page_;
482
[email protected]3aff9ad2011-04-01 20:26:48483 // Whether the extension has host permissions or user script patterns that
484 // imply access to file:/// scheme URLs (the user may not have actually
485 // granted it that access).
486 bool wants_file_access_;
487
[email protected]2af352b2011-07-22 08:21:23488 // The flags that were passed to InitFromValue.
489 int creation_flags_;
[email protected]620db1762011-07-15 21:57:34490
[email protected]894bb502009-05-21 22:39:57491 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:33492};
493
[email protected]bc151cf92013-02-12 04:57:26494typedef std::vector<scoped_refptr<const Extension> > ExtensionList;
[email protected]53d5f0f462014-03-07 09:15:20495typedef std::set<ExtensionId> ExtensionIdSet;
496typedef std::vector<ExtensionId> ExtensionIdList;
[email protected]b1748b1d82009-11-30 20:32:56497
[email protected]c6d474f82009-12-16 21:11:06498// Handy struct to pass core extension info around.
499struct ExtensionInfo {
[email protected]f3a1c642011-07-12 19:15:03500 ExtensionInfo(const base::DictionaryValue* manifest,
[email protected]53d5f0f462014-03-07 09:15:20501 const ExtensionId& id,
[email protected]a7329162013-02-07 19:21:48502 const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:40503 Manifest::Location location);
[email protected]3bb84992010-08-26 17:23:46504 ~ExtensionInfo();
[email protected]c6d474f82009-12-16 21:11:06505
[email protected]f3a1c642011-07-12 19:15:03506 scoped_ptr<base::DictionaryValue> extension_manifest;
[email protected]53d5f0f462014-03-07 09:15:20507 ExtensionId extension_id;
[email protected]a7329162013-02-07 19:21:48508 base::FilePath extension_path;
[email protected]1d5e58b2013-01-31 08:41:40509 Manifest::Location extension_location;
[email protected]c6d474f82009-12-16 21:11:06510
511 private:
512 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
513};
514
[email protected]41bb80bd2013-05-03 10:56:02515struct InstalledExtensionInfo {
516 // The extension being installed - this should always be non-NULL.
517 const Extension* extension;
518
519 // True if the extension is being updated; false if it is being installed.
520 bool is_update;
521
[email protected]760f743b2014-05-28 13:52:02522 // True if the extension was previously installed ephemerally and is now
523 // a regular installed extension.
524 bool from_ephemeral;
525
[email protected]e7554c3f2013-05-29 00:36:56526 // The name of the extension prior to this update. Will be empty if
527 // |is_update| is false.
528 std::string old_name;
529
530 InstalledExtensionInfo(const Extension* extension,
531 bool is_update,
[email protected]760f743b2014-05-28 13:52:02532 bool from_ephemeral,
[email protected]e7554c3f2013-05-29 00:36:56533 const std::string& old_name);
[email protected]41bb80bd2013-05-03 10:56:02534};
535
[email protected]a9f39a312010-12-23 22:14:27536struct UnloadedExtensionInfo {
[email protected]e51232f32014-04-18 20:05:36537 // TODO(DHNishi): Move this enum to ExtensionRegistryObserver.
[email protected]b0af4792013-10-23 09:12:13538 enum Reason {
[email protected]ebe07772014-05-22 04:16:06539 REASON_UNDEFINED, // Undefined state used to initialize variables.
540 REASON_DISABLE, // Extension is being disabled.
541 REASON_UPDATE, // Extension is being updated to a newer version.
542 REASON_UNINSTALL, // Extension is being uninstalled.
543 REASON_TERMINATE, // Extension has terminated.
544 REASON_BLACKLIST, // Extension has been blacklisted.
545 REASON_PROFILE_SHUTDOWN, // Profile is being shut down.
[email protected]b0af4792013-10-23 09:12:13546 };
547
548 Reason reason;
[email protected]a9f39a312010-12-23 22:14:27549
[email protected]a9f39a312010-12-23 22:14:27550 // The extension being unloaded - this should always be non-NULL.
551 const Extension* extension;
552
[email protected]b0af4792013-10-23 09:12:13553 UnloadedExtensionInfo(const Extension* extension, Reason reason);
[email protected]a9f39a312010-12-23 22:14:27554};
555
[email protected]902fd7b2011-07-27 18:42:31556// The details sent for EXTENSION_PERMISSIONS_UPDATED notifications.
557struct UpdatedExtensionPermissionsInfo {
558 enum Reason {
[email protected]f5532472012-02-23 13:00:55559 ADDED, // The permissions were added to the extension.
560 REMOVED, // The permissions were removed from the extension.
[email protected]902fd7b2011-07-27 18:42:31561 };
562
563 Reason reason;
564
565 // The extension who's permissions have changed.
566 const Extension* extension;
567
568 // The permissions that have changed. For Reason::ADDED, this would contain
569 // only the permissions that have added, and for Reason::REMOVED, this would
570 // only contain the removed permissions.
[email protected]c2e66e12012-06-27 06:27:06571 const PermissionSet* permissions;
[email protected]902fd7b2011-07-27 18:42:31572
573 UpdatedExtensionPermissionsInfo(
574 const Extension* extension,
[email protected]c2e66e12012-06-27 06:27:06575 const PermissionSet* permissions,
[email protected]902fd7b2011-07-27 18:42:31576 Reason reason);
577};
578
[email protected]488e6502012-09-07 14:17:34579} // namespace extensions
[email protected]1c321ee2012-05-21 03:02:34580
[email protected]e4452d32013-11-15 23:07:41581#endif // EXTENSIONS_COMMON_EXTENSION_H_