blob: 13a86b74e560e49d2d6b007ae21946e45092cd24 [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]300cc58db2009-08-19 20:45:148#include <map>
[email protected]facd7a7652009-06-05 23:15:029#include <set>
[email protected]7713d632008-12-02 07:52:3310#include <string>
[email protected]7713d632008-12-02 07:52:3311#include <vector>
12
[email protected]57999812013-02-24 05:40:5213#include "base/files/file_path.h"
avi2d124c02015-12-23 06:36:4214#include "base/macros.h"
[email protected]b6b805e92011-04-16 09:24:1415#include "base/memory/linked_ptr.h"
[email protected]3b63f8f42011-03-28 01:54:1516#include "base/memory/ref_counted.h"
17#include "base/memory/scoped_ptr.h"
[email protected]7eeab9ec2013-01-15 04:08:3318#include "base/threading/thread_checker.h"
[email protected]993da5e2013-03-23 21:25:1619#include "extensions/common/extension_resource.h"
[email protected]1d5e58b2013-01-31 08:41:4020#include "extensions/common/install_warning.h"
[email protected]d42c11152013-08-22 19:36:3221#include "extensions/common/manifest.h"
[email protected]e9f541a2012-11-19 21:52:3122#include "extensions/common/url_pattern_set.h"
[email protected]5f5ef802013-07-04 16:11:1323#include "url/gurl.h"
[email protected]eab9b452009-01-23 20:48:5924
thestig52a87b3b2014-10-23 22:02:3825#if !defined(ENABLE_EXTENSIONS)
26#error "Extensions must be enabled"
27#endif
28
[email protected]f3a1c642011-07-12 19:15:0329namespace base {
30class DictionaryValue;
[email protected]1f04ef42013-04-22 07:35:5031class Version;
[email protected]f3a1c642011-07-12 19:15:0332}
33
[email protected]1c321ee2012-05-21 03:02:3434namespace extensions {
[email protected]bebe1d02012-08-02 20:17:0935class PermissionSet;
[email protected]d695bb12014-06-05 16:16:3036class PermissionsData;
37class PermissionsParser;
[email protected]1c321ee2012-05-21 03:02:3438
[email protected]53d5f0f462014-03-07 09:15:2039// Uniquely identifies an Extension, using 32 characters from the alphabet
40// 'a'-'p'. An empty string represents "no extension".
41//
42// Note: If this gets used heavily in files that don't otherwise need to include
43// extension.h, we should pull it into a dedicated header.
44typedef std::string ExtensionId;
45
[email protected]f0755532010-06-22 07:27:2546// Represents a Chrome extension.
[email protected]5cd56342013-04-03 19:50:4747// Once created, an Extension object is immutable, with the exception of its
48// RuntimeData. This makes it safe to use on any thread, since access to the
49// RuntimeData is protected by a lock.
[email protected]66e4eb32010-10-27 20:37:4150class Extension : public base::RefCountedThreadSafe<Extension> {
[email protected]7713d632008-12-02 07:52:3351 public:
[email protected]25b34332009-06-05 21:53:1952 enum State {
[email protected]0c6da502009-08-14 22:32:3953 DISABLED = 0,
[email protected]25b34332009-06-05 21:53:1954 ENABLED,
[email protected]79c833b52011-04-05 18:31:0155 // An external extension that the user uninstalled. We should not reinstall
56 // such extensions on startup.
57 EXTERNAL_EXTENSION_UNINSTALLED,
[email protected]9ae73962014-08-14 16:53:4158 // DEPRECATED: Special state for component extensions.
59 // Maintained as a placeholder since states may be stored to disk.
60 ENABLED_COMPONENT_DEPRECATED,
mlerman6a37b6a42014-11-26 22:10:5361 // Add new states here as this enum is stored in prefs.
[email protected]0c6da502009-08-14 22:32:3962 NUM_STATES
[email protected]631cf822009-05-15 07:01:2563 };
[email protected]7713d632008-12-02 07:52:3364
[email protected]ef5a9992014-07-25 21:45:2465 // Reasons an extension may be disabled. These are used in histograms, so do
66 // not remove/reorder entries - only add at the end just before
67 // DISABLE_REASON_LAST (and update the shift value for it). Also remember to
68 // update the enum listing in tools/metrics/histograms.xml.
treib29e1b9b12015-11-11 08:50:5669 // Also carefully consider if your reason should sync to other devices, and if
70 // so, add it to kKnownSyncableDisableReasons in extension_sync_service.cc.
[email protected]44d62b62012-04-11 00:06:0371 enum DisableReason {
[email protected]eb5e4f92012-08-15 23:33:2872 DISABLE_NONE = 0,
73 DISABLE_USER_ACTION = 1 << 0,
74 DISABLE_PERMISSIONS_INCREASE = 1 << 1,
75 DISABLE_RELOAD = 1 << 2,
[email protected]215a7be2012-10-22 19:53:4276 DISABLE_UNSUPPORTED_REQUIREMENT = 1 << 3,
77 DISABLE_SIDELOAD_WIPEOUT = 1 << 4,
treib3b91e9f2015-11-04 11:29:4178 DEPRECATED_DISABLE_UNKNOWN_FROM_SYNC = 1 << 5,
[email protected]367d077d2014-06-23 20:38:1779 // DISABLE_PERMISSIONS_CONSENT = 1 << 6, // Deprecated.
80 // DISABLE_KNOWN_DISABLED = 1 << 7, // Deprecated.
[email protected]2d19eb6e2014-01-27 17:30:0081 DISABLE_NOT_VERIFIED = 1 << 8, // Disabled because we could not verify
82 // the install.
[email protected]e1e2da32014-05-05 13:11:3783 DISABLE_GREYLIST = 1 << 9,
84 DISABLE_CORRUPTED = 1 << 10,
[email protected]ef5a9992014-07-25 21:45:2485 DISABLE_REMOTE_INSTALL = 1 << 11,
benwells1dd4acd2015-12-09 02:20:2486 // DISABLE_INACTIVE_EPHEMERAL_APP = 1 << 12, // Deprecated.
87 DISABLE_EXTERNAL_EXTENSION = 1 << 13, // External extensions might be
88 // disabled for user prompting.
binjin8e3d0182014-12-04 16:44:2889 DISABLE_UPDATE_REQUIRED_BY_POLICY = 1 << 14, // Doesn't meet minimum
90 // version requirement.
91 DISABLE_REASON_LAST = 1 << 15, // This should always be the last value
[email protected]44d62b62012-04-11 00:06:0392 };
93
[email protected]d356c982012-12-12 19:32:5594 // A base class for parsed manifest data that APIs want to store on
95 // the extension. Related to base::SupportsUserData, but with an immutable
96 // thread-safe interface to match Extension.
97 struct ManifestData {
98 virtual ~ManifestData() {}
99 };
100
[email protected]f9c5d392014-05-13 05:34:18101 // Do not change the order of entries or remove entries in this list
102 // as this is used in UMA_HISTOGRAM_ENUMERATIONs about extensions.
[email protected]83048a22011-03-29 00:14:13103 enum InitFromValueFlags {
104 NO_FLAGS = 0,
105
106 // Usually, the id of an extension is generated by the "key" property of
107 // its manifest, but if |REQUIRE_KEY| is not set, a temporary ID will be
108 // generated based on the path.
109 REQUIRE_KEY = 1 << 0,
110
[email protected]3f53dfe2011-11-30 01:18:29111 // Requires the extension to have an up-to-date manifest version.
112 // Typically, we'll support multiple manifest versions during a version
[email protected]26367b62012-10-04 23:03:32113 // transition. This flag signals that we want to require the most modern
[email protected]3f53dfe2011-11-30 01:18:29114 // manifest version that Chrome understands.
115 REQUIRE_MODERN_MANIFEST_VERSION = 1 << 1,
116
[email protected]3aff9ad2011-04-01 20:26:48117 // |ALLOW_FILE_ACCESS| indicates that the user is allowing this extension
118 // to have file access. If it's not present, then permissions and content
119 // scripts that match file:/// URLs will be filtered out.
[email protected]ed3b9b12012-05-31 18:37:51120 ALLOW_FILE_ACCESS = 1 << 2,
[email protected]620db1762011-07-15 21:57:34121
122 // |FROM_WEBSTORE| indicates that the extension was installed from the
123 // Chrome Web Store.
[email protected]ed3b9b12012-05-31 18:37:51124 FROM_WEBSTORE = 1 << 3,
[email protected]e805baf2011-07-26 18:23:05125
[email protected]46601462014-02-04 11:08:50126 // |FROM_BOOKMARK| indicates the extension is a bookmark app which has been
127 // generated from a web page. Bookmark apps have no permissions or extent
128 // and launch the web page they are created from when run.
[email protected]ed3b9b12012-05-31 18:37:51129 FROM_BOOKMARK = 1 << 4,
[email protected]3d41d432012-04-20 20:47:58130
131 // |FOLLOW_SYMLINKS_ANYWHERE| means that resources can be symlinks to
132 // anywhere in the filesystem, rather than being restricted to the
133 // extension directory.
[email protected]ed3b9b12012-05-31 18:37:51134 FOLLOW_SYMLINKS_ANYWHERE = 1 << 5,
[email protected]ab55c2b2012-06-01 23:55:03135
136 // |ERROR_ON_PRIVATE_KEY| means that private keys inside an
137 // extension should be errors rather than warnings.
138 ERROR_ON_PRIVATE_KEY = 1 << 6,
[email protected]e33bbc22012-08-27 22:05:46139
140 // |WAS_INSTALLED_BY_DEFAULT| installed by default when the profile was
141 // created.
142 WAS_INSTALLED_BY_DEFAULT = 1 << 7,
[email protected]aa5a5472013-10-04 03:41:04143
[email protected]1b563df2013-10-30 16:49:36144 // Unused - was part of an abandoned experiment.
[email protected]aa5a5472013-10-04 03:41:04145 REQUIRE_PERMISSIONS_CONSENT = 1 << 8,
[email protected]ce35418b2013-11-25 01:22:33146
[email protected]411f8ae2014-05-22 11:12:23147 // Unused - this flag has been moved to ExtensionPrefs.
[email protected]ce35418b2013-11-25 01:22:33148 IS_EPHEMERAL = 1 << 9,
[email protected]acc3c7c22014-03-19 06:23:39149
150 // |WAS_INSTALLED_BY_OEM| installed by an OEM (e.g on Chrome OS) and should
151 // be placed in a special OEM folder in the App Launcher. Note: OEM apps are
152 // also installed by Default (i.e. WAS_INSTALLED_BY_DEFAULT is also true).
153 WAS_INSTALLED_BY_OEM = 1 << 10,
[email protected]f9c5d392014-05-13 05:34:18154
[email protected]6338fa32014-07-16 21:41:59155 // |WAS_INSTALLED_BY_CUSTODIAN| means this extension was installed by the
156 // custodian of a supervised user.
157 WAS_INSTALLED_BY_CUSTODIAN = 1 << 11,
158
[email protected]2b6a5802014-08-16 07:58:08159 // |MAY_BE_UNTRUSTED| indicates that this extension came from a potentially
160 // unsafe source (e.g., sideloaded from a local CRX file via the Windows
161 // registry). Such extensions may be subjected to additional constraints
162 // before they are fully installed and enabled.
163 MAY_BE_UNTRUSTED = 1 << 12,
164
[email protected]f9c5d392014-05-13 05:34:18165 // When adding new flags, make sure to update kInitFromValueFlagBits.
[email protected]83048a22011-03-29 00:14:13166 };
167
[email protected]f9c5d392014-05-13 05:34:18168 // This is the highest bit index of the flags defined above.
169 static const int kInitFromValueFlagBits;
170
[email protected]a7329162013-02-07 19:21:48171 static scoped_refptr<Extension> Create(const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:40172 Manifest::Location location,
[email protected]f3a1c642011-07-12 19:15:03173 const base::DictionaryValue& value,
[email protected]83048a22011-03-29 00:14:13174 int flags,
[email protected]66e4eb32010-10-27 20:37:41175 std::string* error);
176
[email protected]87c655e2011-07-01 21:42:00177 // In a few special circumstances, we want to create an Extension and give it
[email protected]f5bf1842012-02-15 02:52:26178 // an explicit id. Most consumers should just use the other Create() method.
[email protected]a7329162013-02-07 19:21:48179 static scoped_refptr<Extension> Create(const base::FilePath& path,
[email protected]2cb5e302013-05-09 05:00:06180 Manifest::Location location,
181 const base::DictionaryValue& value,
182 int flags,
[email protected]53d5f0f462014-03-07 09:15:20183 const ExtensionId& explicit_id,
[email protected]2cb5e302013-05-09 05:00:06184 std::string* error);
[email protected]87c655e2011-07-01 21:42:00185
[email protected]8d888c12010-11-30 00:00:25186 // Valid schemes for web extent URLPatterns.
187 static const int kValidWebExtentSchemes;
188
dominickn0bdf6c732015-08-25 06:13:46189 // Valid schemes for bookmark app installs.
190 static const int kValidBookmarkAppSchemes;
191
[email protected]f71f7e62010-12-07 03:45:33192 // Valid schemes for host permission URLPatterns.
193 static const int kValidHostPermissionSchemes;
194
[email protected]e435d6b72009-07-25 03:15:58195 // The mimetype used for extensions.
196 static const char kMimeType[];
197
[email protected]1d5e58b2013-01-31 08:41:40198 // See Type definition in Manifest.
199 Manifest::Type GetType() const;
[email protected]9b217652010-10-08 22:04:23200
[email protected]07c00d992009-03-04 20:27:04201 // Returns an absolute url to a resource inside of an extension. The
[email protected]eab9b452009-01-23 20:48:59202 // |extension_url| argument should be the url() from an Extension object. The
203 // |relative_path| can be untrusted user input. The returned URL will either
204 // be invalid() or a child of |extension_url|.
205 // NOTE: Static so that it can be used from multiple threads.
206 static GURL GetResourceURL(const GURL& extension_url,
207 const std::string& relative_path);
[email protected]cffd7892010-08-26 17:43:28208 GURL GetResourceURL(const std::string& relative_path) const {
[email protected]3cfbd0e2009-03-18 21:26:24209 return GetResourceURL(url(), relative_path);
210 }
[email protected]eab9b452009-01-23 20:48:59211
[email protected]f59a8052012-06-20 22:25:00212 // Returns true if the resource matches a pattern in the pattern_set.
213 bool ResourceMatches(const URLPatternSet& pattern_set,
214 const std::string& resource) const;
215
[email protected]99efb7b12009-12-18 02:39:16216 // Returns an extension resource object. |relative_path| should be UTF8
217 // encoded.
[email protected]9adb9692010-10-29 23:14:02218 ExtensionResource GetResource(const std::string& relative_path) const;
[email protected]99efb7b12009-12-18 02:39:16219
220 // As above, but with |relative_path| following the file system's encoding.
[email protected]a7329162013-02-07 19:21:48221 ExtensionResource GetResource(const base::FilePath& relative_path) const;
[email protected]eab9b452009-01-23 20:48:59222
[email protected]a17f9462009-06-09 02:56:41223 // |input| is expected to be the text of an rsa public or private key. It
224 // tolerates the presence or absence of bracking header/footer like this:
225 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
226 // and may contain newlines.
227 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
228
229 // Does a simple base64 encoding of |input| into |output|.
230 static bool ProducePEM(const std::string& input, std::string* output);
231
232 // Expects base64 encoded |input| and formats into |output| including
233 // the appropriate header & footer.
[email protected]e0d08192011-03-29 19:02:50234 static bool FormatPEMForFileOutput(const std::string& input,
235 std::string* output,
236 bool is_public);
[email protected]a17f9462009-06-09 02:56:41237
[email protected]a807bbe2010-04-14 10:51:19238 // Returns the base extension url for a given |extension_id|.
[email protected]53d5f0f462014-03-07 09:15:20239 static GURL GetBaseURLFromExtensionId(const ExtensionId& extension_id);
[email protected]a807bbe2010-04-14 10:51:19240
[email protected]5df6a5d2011-01-26 07:39:12241 // Whether context menu should be shown for page and browser actions.
242 bool ShowConfigureContextMenus() const;
243
[email protected]cca147172011-02-17 01:29:29244 // Returns true if this extension or app includes areas within |origin|.
245 bool OverlapsWithOrigin(const GURL& origin) const;
246
[email protected]7e0f92b2012-11-09 03:51:04247 // Returns true if the extension requires a valid ordinal for sorting, e.g.,
248 // for displaying in a launcher or new tab page.
249 bool RequiresSortOrdinal() const;
250
251 // Returns true if the extension should be displayed in the app launcher.
252 bool ShouldDisplayInAppLauncher() const;
253
254 // Returns true if the extension should be displayed in the browser NTP.
255 bool ShouldDisplayInNewTabPage() const;
[email protected]b873cd92012-02-09 21:51:48256
[email protected]e0b3de72012-05-01 01:21:34257 // Returns true if the extension should be displayed in the extension
258 // settings page (i.e. chrome://extensions).
259 bool ShouldDisplayInExtensionSettings() const;
260
[email protected]624e63d0c2013-08-16 00:09:50261 // Returns true if the extension should not be shown anywhere. This is
262 // mostly the same as the extension being a component extension, but also
263 // includes non-component apps that are hidden from the app launcher and ntp.
264 bool ShouldNotBeVisible() const;
265
[email protected]d356c982012-12-12 19:32:55266 // Get the manifest data associated with the key, or NULL if there is none.
267 // Can only be called after InitValue is finished.
268 ManifestData* GetManifestData(const std::string& key) const;
269
270 // Sets |data| to be associated with the key. Takes ownership of |data|.
271 // Can only be called before InitValue is finished. Not thread-safe;
272 // all SetManifestData calls should be on only one thread.
273 void SetManifestData(const std::string& key, ManifestData* data);
274
[email protected]6f229e82010-11-02 17:47:26275 // Accessors:
276
[email protected]a7329162013-02-07 19:21:48277 const base::FilePath& path() const { return path_; }
[email protected]6f229e82010-11-02 17:47:26278 const GURL& url() const { return extension_url_; }
[email protected]1d5e58b2013-01-31 08:41:40279 Manifest::Location location() const;
[email protected]53d5f0f462014-03-07 09:15:20280 const ExtensionId& id() const;
[email protected]1f04ef42013-04-22 07:35:50281 const base::Version* version() const { return version_.get(); }
limasdfc8a11872016-01-21 05:24:50282 const std::string& version_name() const { return version_name_; }
[email protected]6f229e82010-11-02 17:47:26283 const std::string VersionString() const;
elijahtaylor89b02d72014-12-05 00:42:20284 const std::string GetVersionForDisplay() const;
[email protected]6f229e82010-11-02 17:47:26285 const std::string& name() const { return name_; }
[email protected]680eaa672013-08-27 10:25:08286 const std::string& short_name() const { return short_name_; }
[email protected]701d1e82012-05-14 05:34:19287 const std::string& non_localized_name() const { return non_localized_name_; }
[email protected]200423d2012-06-05 01:16:06288 // Base64-encoded version of the key used to sign this extension.
289 // In pseudocode, returns
290 // base::Base64Encode(RSAPrivateKey(pem_file).ExportPublicKey()).
291 const std::string& public_key() const { return public_key_; }
[email protected]6f229e82010-11-02 17:47:26292 const std::string& description() const { return description_; }
[email protected]a47c8a22011-11-17 18:40:31293 int manifest_version() const { return manifest_version_; }
[email protected]6f229e82010-11-02 17:47:26294 bool converted_from_user_script() const {
295 return converted_from_user_script_;
296 }
[email protected]d695bb12014-06-05 16:16:30297 PermissionsParser* permissions_parser() { return permissions_parser_.get(); }
298 const PermissionsParser* permissions_parser() const {
299 return permissions_parser_.get();
300 }
301
[email protected]2cb5e302013-05-09 05:00:06302 const PermissionsData* permissions_data() const {
303 return permissions_data_.get();
[email protected]902fd7b2011-07-27 18:42:31304 }
[email protected]2cb5e302013-05-09 05:00:06305
[email protected]23b3c0a2013-01-16 23:36:36306 // Appends |new_warning[s]| to install_warnings_.
307 void AddInstallWarning(const InstallWarning& new_warning);
[email protected]1d5e58b2013-01-31 08:41:40308 void AddInstallWarnings(const std::vector<InstallWarning>& new_warnings);
309 const std::vector<InstallWarning>& install_warnings() const {
[email protected]8629c542012-04-20 03:40:03310 return install_warnings_;
311 }
[email protected]953620b2011-12-04 00:55:32312 const extensions::Manifest* manifest() const {
[email protected]e9629d772012-08-06 19:44:46313 return manifest_.get();
[email protected]6f229e82010-11-02 17:47:26314 }
[email protected]3aff9ad2011-04-01 20:26:48315 bool wants_file_access() const { return wants_file_access_; }
[email protected]334ec0a2013-03-24 01:36:16316 // TODO(rdevlin.cronin): This is needed for ContentScriptsHandler, and should
317 // be moved out as part of crbug.com/159265. This should not be used anywhere
318 // else.
319 void set_wants_file_access(bool wants_file_access) {
320 wants_file_access_ = wants_file_access;
321 }
[email protected]2af352b2011-07-22 08:21:23322 int creation_flags() const { return creation_flags_; }
323 bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; }
[email protected]e805baf2011-07-26 18:23:05324 bool from_bookmark() const { return (creation_flags_ & FROM_BOOKMARK) != 0; }
proberge834697132015-10-21 21:04:49325 bool may_be_untrusted() const {
326 return (creation_flags_ & MAY_BE_UNTRUSTED) != 0;
327 }
[email protected]e33bbc22012-08-27 22:05:46328 bool was_installed_by_default() const {
329 return (creation_flags_ & WAS_INSTALLED_BY_DEFAULT) != 0;
330 }
[email protected]acc3c7c22014-03-19 06:23:39331 bool was_installed_by_oem() const {
332 return (creation_flags_ & WAS_INSTALLED_BY_OEM) != 0;
333 }
[email protected]6338fa32014-07-16 21:41:59334 bool was_installed_by_custodian() const {
335 return (creation_flags_ & WAS_INSTALLED_BY_CUSTODIAN) != 0;
336 }
[email protected]3aff9ad2011-04-01 20:26:48337
[email protected]b86960e2014-07-18 05:35:09338 // Type-related queries.
[email protected]21c01042013-03-10 23:41:14339 bool is_app() const;
[email protected]d41e2152012-02-24 04:20:27340 bool is_platform_app() const;
341 bool is_hosted_app() const;
[email protected]c4f459d2012-09-28 04:40:10342 bool is_legacy_packaged_app() const;
[email protected]ff05a4b102012-12-19 00:12:06343 bool is_extension() const;
[email protected]b86960e2014-07-18 05:35:09344 bool is_shared_module() const;
345 bool is_theme() const;
346
[email protected]636ee43282013-01-12 15:58:00347 void AddWebExtentPattern(const URLPattern& pattern);
[email protected]cced75a2011-05-20 08:31:12348 const URLPatternSet& web_extent() const { return extent_; }
[email protected]6f229e82010-11-02 17:47:26349
[email protected]4a8d3272009-03-10 19:15:08350 private:
[email protected]66e4eb32010-10-27 20:37:41351 friend class base::RefCountedThreadSafe<Extension>;
352
[email protected]d41e2152012-02-24 04:20:27353 // Chooses the extension ID for an extension based on a variety of criteria.
354 // The chosen ID will be set in |manifest|.
355 static bool InitExtensionID(extensions::Manifest* manifest,
[email protected]a7329162013-02-07 19:21:48356 const base::FilePath& path,
[email protected]53d5f0f462014-03-07 09:15:20357 const ExtensionId& explicit_id,
[email protected]d41e2152012-02-24 04:20:27358 int creation_flags,
[email protected]0d163dc2013-12-20 23:48:36359 base::string16* error);
[email protected]d41e2152012-02-24 04:20:27360
[email protected]a7329162013-02-07 19:21:48361 Extension(const base::FilePath& path,
362 scoped_ptr<extensions::Manifest> manifest);
[email protected]d356c982012-12-12 19:32:55363 virtual ~Extension();
[email protected]66e4eb32010-10-27 20:37:41364
365 // Initialize the extension from a parsed manifest.
[email protected]d41e2152012-02-24 04:20:27366 // TODO(aa): Rename to just Init()? There's no Value here anymore.
367 // TODO(aa): It is really weird the way this class essentially contains a copy
368 // of the underlying DictionaryValue in its members. We should decide to
369 // either wrap the DictionaryValue and go with that only, or we should parse
370 // into strong types and discard the value. But doing both is bad.
[email protected]0d163dc2013-12-20 23:48:36371 bool InitFromValue(int flags, base::string16* error);
[email protected]66e4eb32010-10-27 20:37:41372
[email protected]58f62cf2012-03-09 10:45:11373 // The following are helpers for InitFromValue to load various features of the
374 // extension from the manifest.
375
[email protected]0d163dc2013-12-20 23:48:36376 bool LoadRequiredFeatures(base::string16* error);
377 bool LoadName(base::string16* error);
378 bool LoadVersion(base::string16* error);
[email protected]58f62cf2012-03-09 10:45:11379
[email protected]0d163dc2013-12-20 23:48:36380 bool LoadAppFeatures(base::string16* error);
[email protected]d41e2152012-02-24 04:20:27381 bool LoadExtent(const char* key,
382 URLPatternSet* extent,
383 const char* list_error,
384 const char* value_error,
[email protected]0d163dc2013-12-20 23:48:36385 base::string16* error);
[email protected]10253da2012-03-09 04:06:42386
[email protected]0d163dc2013-12-20 23:48:36387 bool LoadSharedFeatures(base::string16* error);
388 bool LoadDescription(base::string16* error);
389 bool LoadManifestVersion(base::string16* error);
390 bool LoadShortName(base::string16* error);
[email protected]66008002013-01-08 09:09:13391
[email protected]0d163dc2013-12-20 23:48:36392 bool CheckMinimumChromeVersion(base::string16* error) const;
[email protected]488e6502012-09-07 14:17:34393
[email protected]6f229e82010-11-02 17:47:26394 // The extension's human-readable name. Name is used for display purpose. It
395 // might be wrapped with unicode bidi control characters so that it is
396 // displayed correctly in RTL context.
397 // NOTE: Name is UTF-8 and may contain non-ascii characters.
398 std::string name_;
399
[email protected]701d1e82012-05-14 05:34:19400 // A non-localized version of the extension's name. This is useful for
401 // debug output.
402 std::string non_localized_name_;
403
[email protected]680eaa672013-08-27 10:25:08404 // A short version of the extension's name. This can be used as an alternative
405 // to the name where there is insufficient space to display the full name. If
406 // an extension has not explicitly specified a short name, the value of this
407 // member variable will be the full name rather than an empty string.
408 std::string short_name_;
409
[email protected]a47c8a22011-11-17 18:40:31410 // The version of this extension's manifest. We increase the manifest
411 // version when making breaking changes to the extension system.
412 // Version 1 was the first manifest version (implied by a lack of a
413 // manifest_version attribute in the extension's manifest). We initialize
414 // this member variable to 0 to distinguish the "uninitialized" case from
415 // the case when we know the manifest version actually is 1.
416 int manifest_version_;
417
[email protected]d41e2152012-02-24 04:20:27418 // The absolute path to the directory the extension is stored in.
[email protected]a7329162013-02-07 19:21:48419 base::FilePath path_;
[email protected]d41e2152012-02-24 04:20:27420
[email protected]6f229e82010-11-02 17:47:26421 // Defines the set of URLs in the extension's web content.
[email protected]cced75a2011-05-20 08:31:12422 URLPatternSet extent_;
[email protected]6f229e82010-11-02 17:47:26423
[email protected]d695bb12014-06-05 16:16:30424 // The parser for the manifest's permissions. This is NULL anytime not during
425 // initialization.
426 // TODO(rdevlin.cronin): This doesn't really belong here.
427 scoped_ptr<PermissionsParser> permissions_parser_;
428
429 // The active permissions for the extension.
[email protected]2cb5e302013-05-09 05:00:06430 scoped_ptr<PermissionsData> permissions_data_;
[email protected]6f229e82010-11-02 17:47:26431
[email protected]8629c542012-04-20 03:40:03432 // Any warnings that occurred when trying to create/parse the extension.
[email protected]1d5e58b2013-01-31 08:41:40433 std::vector<InstallWarning> install_warnings_;
[email protected]8629c542012-04-20 03:40:03434
[email protected]6f229e82010-11-02 17:47:26435 // The base extension url for the extension.
436 GURL extension_url_;
437
[email protected]6f229e82010-11-02 17:47:26438 // The extension's version.
[email protected]1f04ef42013-04-22 07:35:50439 scoped_ptr<base::Version> version_;
[email protected]6f229e82010-11-02 17:47:26440
elijahtaylor89b02d72014-12-05 00:42:20441 // The extension's user visible version name.
442 std::string version_name_;
443
[email protected]6f229e82010-11-02 17:47:26444 // An optional longer description of the extension.
445 std::string description_;
446
447 // True if the extension was generated from a user script. (We show slightly
448 // different UI if so).
449 bool converted_from_user_script_;
450
[email protected]6f229e82010-11-02 17:47:26451 // The public key used to sign the contents of the crx package.
452 std::string public_key_;
453
[email protected]58f62cf2012-03-09 10:45:11454 // The manifest from which this extension was created.
[email protected]e9629d772012-08-06 19:44:46455 scoped_ptr<Manifest> manifest_;
[email protected]6f229e82010-11-02 17:47:26456
[email protected]d356c982012-12-12 19:32:55457 // Stored parsed manifest data.
treib2eab429f2016-02-02 15:02:14458 using ManifestDataMap = std::map<std::string, scoped_ptr<ManifestData>>;
[email protected]d356c982012-12-12 19:32:55459 ManifestDataMap manifest_data_;
460
461 // Set to true at the end of InitValue when initialization is finished.
462 bool finished_parsing_manifest_;
463
[email protected]7eeab9ec2013-01-15 04:08:33464 // Ensures that any call to GetManifestData() prior to finishing
465 // initialization happens from the same thread (this can happen when certain
466 // parts of the initialization process need information from previous parts).
467 base::ThreadChecker thread_checker_;
468
[email protected]7e0f92b2012-11-09 03:51:04469 // Should this app be shown in the app launcher.
[email protected]ed1a204f2012-09-22 00:28:44470 bool display_in_launcher_;
471
[email protected]7e0f92b2012-11-09 03:51:04472 // Should this app be shown in the browser New Tab Page.
473 bool display_in_new_tab_page_;
474
[email protected]3aff9ad2011-04-01 20:26:48475 // Whether the extension has host permissions or user script patterns that
476 // imply access to file:/// scheme URLs (the user may not have actually
477 // granted it that access).
478 bool wants_file_access_;
479
[email protected]2af352b2011-07-22 08:21:23480 // The flags that were passed to InitFromValue.
481 int creation_flags_;
[email protected]620db1762011-07-15 21:57:34482
[email protected]894bb502009-05-21 22:39:57483 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:33484};
485
[email protected]bc151cf92013-02-12 04:57:26486typedef std::vector<scoped_refptr<const Extension> > ExtensionList;
[email protected]53d5f0f462014-03-07 09:15:20487typedef std::set<ExtensionId> ExtensionIdSet;
488typedef std::vector<ExtensionId> ExtensionIdList;
[email protected]b1748b1d82009-11-30 20:32:56489
[email protected]c6d474f82009-12-16 21:11:06490// Handy struct to pass core extension info around.
491struct ExtensionInfo {
[email protected]f3a1c642011-07-12 19:15:03492 ExtensionInfo(const base::DictionaryValue* manifest,
[email protected]53d5f0f462014-03-07 09:15:20493 const ExtensionId& id,
[email protected]a7329162013-02-07 19:21:48494 const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:40495 Manifest::Location location);
[email protected]3bb84992010-08-26 17:23:46496 ~ExtensionInfo();
[email protected]c6d474f82009-12-16 21:11:06497
[email protected]f3a1c642011-07-12 19:15:03498 scoped_ptr<base::DictionaryValue> extension_manifest;
[email protected]53d5f0f462014-03-07 09:15:20499 ExtensionId extension_id;
[email protected]a7329162013-02-07 19:21:48500 base::FilePath extension_path;
[email protected]1d5e58b2013-01-31 08:41:40501 Manifest::Location extension_location;
[email protected]c6d474f82009-12-16 21:11:06502
503 private:
504 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
505};
506
[email protected]41bb80bd2013-05-03 10:56:02507struct InstalledExtensionInfo {
508 // The extension being installed - this should always be non-NULL.
509 const Extension* extension;
510
511 // True if the extension is being updated; false if it is being installed.
512 bool is_update;
513
[email protected]760f743b2014-05-28 13:52:02514 // True if the extension was previously installed ephemerally and is now
515 // a regular installed extension.
516 bool from_ephemeral;
517
[email protected]e7554c3f2013-05-29 00:36:56518 // The name of the extension prior to this update. Will be empty if
519 // |is_update| is false.
520 std::string old_name;
521
522 InstalledExtensionInfo(const Extension* extension,
523 bool is_update,
[email protected]760f743b2014-05-28 13:52:02524 bool from_ephemeral,
[email protected]e7554c3f2013-05-29 00:36:56525 const std::string& old_name);
[email protected]41bb80bd2013-05-03 10:56:02526};
527
[email protected]a9f39a312010-12-23 22:14:27528struct UnloadedExtensionInfo {
[email protected]e51232f32014-04-18 20:05:36529 // TODO(DHNishi): Move this enum to ExtensionRegistryObserver.
[email protected]b0af4792013-10-23 09:12:13530 enum Reason {
[email protected]ebe07772014-05-22 04:16:06531 REASON_UNDEFINED, // Undefined state used to initialize variables.
532 REASON_DISABLE, // Extension is being disabled.
533 REASON_UPDATE, // Extension is being updated to a newer version.
534 REASON_UNINSTALL, // Extension is being uninstalled.
535 REASON_TERMINATE, // Extension has terminated.
536 REASON_BLACKLIST, // Extension has been blacklisted.
537 REASON_PROFILE_SHUTDOWN, // Profile is being shut down.
mlerman6a37b6a42014-11-26 22:10:53538 REASON_LOCK_ALL, // All extensions for the profile are blocked.
mfoltz96f329c2016-01-13 18:16:58539 REASON_MIGRATED_TO_COMPONENT, // Extension is being migrated to a component
540 // action.
[email protected]b0af4792013-10-23 09:12:13541 };
542
543 Reason reason;
[email protected]a9f39a312010-12-23 22:14:27544
[email protected]a9f39a312010-12-23 22:14:27545 // The extension being unloaded - this should always be non-NULL.
546 const Extension* extension;
547
[email protected]b0af4792013-10-23 09:12:13548 UnloadedExtensionInfo(const Extension* extension, Reason reason);
[email protected]a9f39a312010-12-23 22:14:27549};
550
[email protected]902fd7b2011-07-27 18:42:31551// The details sent for EXTENSION_PERMISSIONS_UPDATED notifications.
552struct UpdatedExtensionPermissionsInfo {
553 enum Reason {
[email protected]f5532472012-02-23 13:00:55554 ADDED, // The permissions were added to the extension.
555 REMOVED, // The permissions were removed from the extension.
[email protected]902fd7b2011-07-27 18:42:31556 };
557
558 Reason reason;
559
560 // The extension who's permissions have changed.
561 const Extension* extension;
562
563 // The permissions that have changed. For Reason::ADDED, this would contain
564 // only the permissions that have added, and for Reason::REMOVED, this would
565 // only contain the removed permissions.
rdevlin.cronine2d0fd02015-09-24 22:35:49566 const PermissionSet& permissions;
[email protected]902fd7b2011-07-27 18:42:31567
rdevlin.cronine2d0fd02015-09-24 22:35:49568 UpdatedExtensionPermissionsInfo(const Extension* extension,
569 const PermissionSet& permissions,
570 Reason reason);
[email protected]902fd7b2011-07-27 18:42:31571};
572
[email protected]488e6502012-09-07 14:17:34573} // namespace extensions
[email protected]1c321ee2012-05-21 03:02:34574
[email protected]e4452d32013-11-15 23:07:41575#endif // EXTENSIONS_COMMON_EXTENSION_H_