blob: 47f85f33ff942bd704b47558d45061217ebb2148 [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]e9f541a2012-11-19 21:52:3126#include "extensions/common/url_pattern_set.h"
[email protected]f5532472012-02-23 13:00:5527#include "ui/base/accelerators/accelerator.h"
[email protected]08397d52011-02-05 01:53:3828#include "ui/gfx/size.h"
[email protected]5f5ef802013-07-04 16:11:1329#include "url/gurl.h"
[email protected]eab9b452009-01-23 20:48:5930
[email protected]f3a1c642011-07-12 19:15:0331namespace base {
32class DictionaryValue;
[email protected]1f04ef42013-04-22 07:35:5033class Version;
[email protected]f3a1c642011-07-12 19:15:0334}
35
[email protected]1c321ee2012-05-21 03:02:3436namespace extensions {
[email protected]bebe1d02012-08-02 20:17:0937class PermissionSet;
[email protected]d695bb12014-06-05 16:16:3038class PermissionsData;
39class PermissionsParser;
[email protected]1c321ee2012-05-21 03:02:3440
[email protected]53d5f0f462014-03-07 09:15:2041// Uniquely identifies an Extension, using 32 characters from the alphabet
42// 'a'-'p'. An empty string represents "no extension".
43//
44// Note: If this gets used heavily in files that don't otherwise need to include
45// extension.h, we should pull it into a dedicated header.
46typedef std::string ExtensionId;
47
[email protected]f0755532010-06-22 07:27:2548// Represents a Chrome extension.
[email protected]5cd56342013-04-03 19:50:4749// Once created, an Extension object is immutable, with the exception of its
50// RuntimeData. This makes it safe to use on any thread, since access to the
51// RuntimeData is protected by a lock.
[email protected]66e4eb32010-10-27 20:37:4152class Extension : public base::RefCountedThreadSafe<Extension> {
[email protected]7713d632008-12-02 07:52:3353 public:
[email protected]d356c982012-12-12 19:32:5554 struct ManifestData;
[email protected]1e0f45a2012-06-13 00:31:0655
[email protected]d356c982012-12-12 19:32:5556 typedef std::map<const std::string, linked_ptr<ManifestData> >
57 ManifestDataMap;
[email protected]b24d8312009-08-27 06:47:4658
[email protected]25b34332009-06-05 21:53:1959 enum State {
[email protected]0c6da502009-08-14 22:32:3960 DISABLED = 0,
[email protected]25b34332009-06-05 21:53:1961 ENABLED,
[email protected]79c833b52011-04-05 18:31:0162 // An external extension that the user uninstalled. We should not reinstall
63 // such extensions on startup.
64 EXTERNAL_EXTENSION_UNINSTALLED,
[email protected]9ae73962014-08-14 16:53:4165 // DEPRECATED: Special state for component extensions.
66 // Maintained as a placeholder since states may be stored to disk.
67 ENABLED_COMPONENT_DEPRECATED,
[email protected]0c6da502009-08-14 22:32:3968 NUM_STATES
[email protected]631cf822009-05-15 07:01:2569 };
[email protected]7713d632008-12-02 07:52:3370
[email protected]44d62b62012-04-11 00:06:0371 // Used to record the reason an extension was disabled.
[email protected]eb5e4f92012-08-15 23:33:2872 enum DeprecatedDisableReason {
73 DEPRECATED_DISABLE_UNKNOWN,
74 DEPRECATED_DISABLE_USER_ACTION,
75 DEPRECATED_DISABLE_PERMISSIONS_INCREASE,
76 DEPRECATED_DISABLE_RELOAD,
77 DEPRECATED_DISABLE_LAST, // Not used.
78 };
79
[email protected]ef5a9992014-07-25 21:45:2480 // Reasons an extension may be disabled. These are used in histograms, so do
81 // not remove/reorder entries - only add at the end just before
82 // DISABLE_REASON_LAST (and update the shift value for it). Also remember to
83 // update the enum listing in tools/metrics/histograms.xml.
[email protected]44d62b62012-04-11 00:06:0384 enum DisableReason {
[email protected]eb5e4f92012-08-15 23:33:2885 DISABLE_NONE = 0,
86 DISABLE_USER_ACTION = 1 << 0,
87 DISABLE_PERMISSIONS_INCREASE = 1 << 1,
88 DISABLE_RELOAD = 1 << 2,
[email protected]215a7be2012-10-22 19:53:4289 DISABLE_UNSUPPORTED_REQUIREMENT = 1 << 3,
90 DISABLE_SIDELOAD_WIPEOUT = 1 << 4,
[email protected]f56c65ea62012-12-10 22:57:2191 DISABLE_UNKNOWN_FROM_SYNC = 1 << 5,
[email protected]367d077d2014-06-23 20:38:1792 // DISABLE_PERMISSIONS_CONSENT = 1 << 6, // Deprecated.
93 // DISABLE_KNOWN_DISABLED = 1 << 7, // Deprecated.
[email protected]2d19eb6e2014-01-27 17:30:0094 DISABLE_NOT_VERIFIED = 1 << 8, // Disabled because we could not verify
95 // the install.
[email protected]e1e2da32014-05-05 13:11:3796 DISABLE_GREYLIST = 1 << 9,
97 DISABLE_CORRUPTED = 1 << 10,
[email protected]ef5a9992014-07-25 21:45:2498 DISABLE_REMOTE_INSTALL = 1 << 11,
[email protected]8f959f522014-08-06 06:26:2899 DISABLE_INACTIVE_EPHEMERAL_APP = 1 << 12, // Cached ephemeral apps are
100 // disabled to prevent activity.
101 DISABLE_REASON_LAST = 1 << 13, // This should always be the last value
[email protected]44d62b62012-04-11 00:06:03102 };
103
[email protected]d356c982012-12-12 19:32:55104 // A base class for parsed manifest data that APIs want to store on
105 // the extension. Related to base::SupportsUserData, but with an immutable
106 // thread-safe interface to match Extension.
107 struct ManifestData {
108 virtual ~ManifestData() {}
109 };
110
[email protected]f9c5d392014-05-13 05:34:18111 // Do not change the order of entries or remove entries in this list
112 // as this is used in UMA_HISTOGRAM_ENUMERATIONs about extensions.
[email protected]83048a22011-03-29 00:14:13113 enum InitFromValueFlags {
114 NO_FLAGS = 0,
115
116 // Usually, the id of an extension is generated by the "key" property of
117 // its manifest, but if |REQUIRE_KEY| is not set, a temporary ID will be
118 // generated based on the path.
119 REQUIRE_KEY = 1 << 0,
120
[email protected]3f53dfe2011-11-30 01:18:29121 // Requires the extension to have an up-to-date manifest version.
122 // Typically, we'll support multiple manifest versions during a version
[email protected]26367b62012-10-04 23:03:32123 // transition. This flag signals that we want to require the most modern
[email protected]3f53dfe2011-11-30 01:18:29124 // manifest version that Chrome understands.
125 REQUIRE_MODERN_MANIFEST_VERSION = 1 << 1,
126
[email protected]3aff9ad2011-04-01 20:26:48127 // |ALLOW_FILE_ACCESS| indicates that the user is allowing this extension
128 // to have file access. If it's not present, then permissions and content
129 // scripts that match file:/// URLs will be filtered out.
[email protected]ed3b9b12012-05-31 18:37:51130 ALLOW_FILE_ACCESS = 1 << 2,
[email protected]620db1762011-07-15 21:57:34131
132 // |FROM_WEBSTORE| indicates that the extension was installed from the
133 // Chrome Web Store.
[email protected]ed3b9b12012-05-31 18:37:51134 FROM_WEBSTORE = 1 << 3,
[email protected]e805baf2011-07-26 18:23:05135
[email protected]46601462014-02-04 11:08:50136 // |FROM_BOOKMARK| indicates the extension is a bookmark app which has been
137 // generated from a web page. Bookmark apps have no permissions or extent
138 // and launch the web page they are created from when run.
[email protected]ed3b9b12012-05-31 18:37:51139 FROM_BOOKMARK = 1 << 4,
[email protected]3d41d432012-04-20 20:47:58140
141 // |FOLLOW_SYMLINKS_ANYWHERE| means that resources can be symlinks to
142 // anywhere in the filesystem, rather than being restricted to the
143 // extension directory.
[email protected]ed3b9b12012-05-31 18:37:51144 FOLLOW_SYMLINKS_ANYWHERE = 1 << 5,
[email protected]ab55c2b2012-06-01 23:55:03145
146 // |ERROR_ON_PRIVATE_KEY| means that private keys inside an
147 // extension should be errors rather than warnings.
148 ERROR_ON_PRIVATE_KEY = 1 << 6,
[email protected]e33bbc22012-08-27 22:05:46149
150 // |WAS_INSTALLED_BY_DEFAULT| installed by default when the profile was
151 // created.
152 WAS_INSTALLED_BY_DEFAULT = 1 << 7,
[email protected]aa5a5472013-10-04 03:41:04153
[email protected]1b563df2013-10-30 16:49:36154 // Unused - was part of an abandoned experiment.
[email protected]aa5a5472013-10-04 03:41:04155 REQUIRE_PERMISSIONS_CONSENT = 1 << 8,
[email protected]ce35418b2013-11-25 01:22:33156
[email protected]411f8ae2014-05-22 11:12:23157 // Unused - this flag has been moved to ExtensionPrefs.
[email protected]ce35418b2013-11-25 01:22:33158 IS_EPHEMERAL = 1 << 9,
[email protected]acc3c7c22014-03-19 06:23:39159
160 // |WAS_INSTALLED_BY_OEM| installed by an OEM (e.g on Chrome OS) and should
161 // be placed in a special OEM folder in the App Launcher. Note: OEM apps are
162 // also installed by Default (i.e. WAS_INSTALLED_BY_DEFAULT is also true).
163 WAS_INSTALLED_BY_OEM = 1 << 10,
[email protected]f9c5d392014-05-13 05:34:18164
[email protected]6338fa32014-07-16 21:41:59165 // |WAS_INSTALLED_BY_CUSTODIAN| means this extension was installed by the
166 // custodian of a supervised user.
167 WAS_INSTALLED_BY_CUSTODIAN = 1 << 11,
168
[email protected]f9c5d392014-05-13 05:34:18169 // When adding new flags, make sure to update kInitFromValueFlagBits.
[email protected]83048a22011-03-29 00:14:13170 };
171
[email protected]f9c5d392014-05-13 05:34:18172 // This is the highest bit index of the flags defined above.
173 static const int kInitFromValueFlagBits;
174
[email protected]a7329162013-02-07 19:21:48175 static scoped_refptr<Extension> Create(const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:40176 Manifest::Location location,
[email protected]f3a1c642011-07-12 19:15:03177 const base::DictionaryValue& value,
[email protected]83048a22011-03-29 00:14:13178 int flags,
[email protected]66e4eb32010-10-27 20:37:41179 std::string* error);
180
[email protected]87c655e2011-07-01 21:42:00181 // In a few special circumstances, we want to create an Extension and give it
[email protected]f5bf1842012-02-15 02:52:26182 // an explicit id. Most consumers should just use the other Create() method.
[email protected]a7329162013-02-07 19:21:48183 static scoped_refptr<Extension> Create(const base::FilePath& path,
[email protected]2cb5e302013-05-09 05:00:06184 Manifest::Location location,
185 const base::DictionaryValue& value,
186 int flags,
[email protected]53d5f0f462014-03-07 09:15:20187 const ExtensionId& explicit_id,
[email protected]2cb5e302013-05-09 05:00:06188 std::string* error);
[email protected]87c655e2011-07-01 21:42:00189
[email protected]8d888c12010-11-30 00:00:25190 // Valid schemes for web extent URLPatterns.
191 static const int kValidWebExtentSchemes;
192
[email protected]f71f7e62010-12-07 03:45:33193 // Valid schemes for host permission URLPatterns.
194 static const int kValidHostPermissionSchemes;
195
[email protected]e435d6b72009-07-25 03:15:58196 // The mimetype used for extensions.
197 static const char kMimeType[];
198
[email protected]25b34332009-06-05 21:53:19199 // Checks to see if the extension has a valid ID.
200 static bool IdIsValid(const std::string& id);
201
[email protected]1d5e58b2013-01-31 08:41:40202 // See Type definition in Manifest.
203 Manifest::Type GetType() const;
[email protected]9b217652010-10-08 22:04:23204
[email protected]07c00d992009-03-04 20:27:04205 // Returns an absolute url to a resource inside of an extension. The
[email protected]eab9b452009-01-23 20:48:59206 // |extension_url| argument should be the url() from an Extension object. The
207 // |relative_path| can be untrusted user input. The returned URL will either
208 // be invalid() or a child of |extension_url|.
209 // NOTE: Static so that it can be used from multiple threads.
210 static GURL GetResourceURL(const GURL& extension_url,
211 const std::string& relative_path);
[email protected]cffd7892010-08-26 17:43:28212 GURL GetResourceURL(const std::string& relative_path) const {
[email protected]3cfbd0e2009-03-18 21:26:24213 return GetResourceURL(url(), relative_path);
214 }
[email protected]eab9b452009-01-23 20:48:59215
[email protected]f59a8052012-06-20 22:25:00216 // Returns true if the resource matches a pattern in the pattern_set.
217 bool ResourceMatches(const URLPatternSet& pattern_set,
218 const std::string& resource) const;
219
[email protected]99efb7b12009-12-18 02:39:16220 // Returns an extension resource object. |relative_path| should be UTF8
221 // encoded.
[email protected]9adb9692010-10-29 23:14:02222 ExtensionResource GetResource(const std::string& relative_path) const;
[email protected]99efb7b12009-12-18 02:39:16223
224 // As above, but with |relative_path| following the file system's encoding.
[email protected]a7329162013-02-07 19:21:48225 ExtensionResource GetResource(const base::FilePath& relative_path) const;
[email protected]eab9b452009-01-23 20:48:59226
[email protected]a17f9462009-06-09 02:56:41227 // |input| is expected to be the text of an rsa public or private key. It
228 // tolerates the presence or absence of bracking header/footer like this:
229 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
230 // and may contain newlines.
231 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
232
233 // Does a simple base64 encoding of |input| into |output|.
234 static bool ProducePEM(const std::string& input, std::string* output);
235
236 // Expects base64 encoded |input| and formats into |output| including
237 // the appropriate header & footer.
[email protected]e0d08192011-03-29 19:02:50238 static bool FormatPEMForFileOutput(const std::string& input,
239 std::string* output,
240 bool is_public);
[email protected]a17f9462009-06-09 02:56:41241
[email protected]a807bbe2010-04-14 10:51:19242 // Returns the base extension url for a given |extension_id|.
[email protected]53d5f0f462014-03-07 09:15:20243 static GURL GetBaseURLFromExtensionId(const ExtensionId& extension_id);
[email protected]a807bbe2010-04-14 10:51:19244
[email protected]5df6a5d2011-01-26 07:39:12245 // Whether context menu should be shown for page and browser actions.
246 bool ShowConfigureContextMenus() const;
247
[email protected]cca147172011-02-17 01:29:29248 // Returns true if this extension or app includes areas within |origin|.
249 bool OverlapsWithOrigin(const GURL& origin) const;
250
[email protected]7e0f92b2012-11-09 03:51:04251 // Returns true if the extension requires a valid ordinal for sorting, e.g.,
252 // for displaying in a launcher or new tab page.
253 bool RequiresSortOrdinal() const;
254
255 // Returns true if the extension should be displayed in the app launcher.
256 bool ShouldDisplayInAppLauncher() const;
257
258 // Returns true if the extension should be displayed in the browser NTP.
259 bool ShouldDisplayInNewTabPage() const;
[email protected]b873cd92012-02-09 21:51:48260
[email protected]e0b3de72012-05-01 01:21:34261 // Returns true if the extension should be displayed in the extension
262 // settings page (i.e. chrome://extensions).
263 bool ShouldDisplayInExtensionSettings() const;
264
[email protected]624e63d0c2013-08-16 00:09:50265 // Returns true if the extension should not be shown anywhere. This is
266 // mostly the same as the extension being a component extension, but also
267 // includes non-component apps that are hidden from the app launcher and ntp.
268 bool ShouldNotBeVisible() const;
269
[email protected]d356c982012-12-12 19:32:55270 // Get the manifest data associated with the key, or NULL if there is none.
271 // Can only be called after InitValue is finished.
272 ManifestData* GetManifestData(const std::string& key) const;
273
274 // Sets |data| to be associated with the key. Takes ownership of |data|.
275 // Can only be called before InitValue is finished. Not thread-safe;
276 // all SetManifestData calls should be on only one thread.
277 void SetManifestData(const std::string& key, ManifestData* data);
278
[email protected]6f229e82010-11-02 17:47:26279 // Accessors:
280
[email protected]a7329162013-02-07 19:21:48281 const base::FilePath& path() const { return path_; }
[email protected]6f229e82010-11-02 17:47:26282 const GURL& url() const { return extension_url_; }
[email protected]1d5e58b2013-01-31 08:41:40283 Manifest::Location location() const;
[email protected]53d5f0f462014-03-07 09:15:20284 const ExtensionId& id() const;
[email protected]1f04ef42013-04-22 07:35:50285 const base::Version* version() const { return version_.get(); }
[email protected]6f229e82010-11-02 17:47:26286 const std::string VersionString() const;
287 const std::string& name() const { return name_; }
[email protected]680eaa672013-08-27 10:25:08288 const std::string& short_name() const { return short_name_; }
[email protected]701d1e82012-05-14 05:34:19289 const std::string& non_localized_name() const { return non_localized_name_; }
[email protected]200423d2012-06-05 01:16:06290 // Base64-encoded version of the key used to sign this extension.
291 // In pseudocode, returns
292 // base::Base64Encode(RSAPrivateKey(pem_file).ExportPublicKey()).
293 const std::string& public_key() const { return public_key_; }
[email protected]6f229e82010-11-02 17:47:26294 const std::string& description() const { return description_; }
[email protected]a47c8a22011-11-17 18:40:31295 int manifest_version() const { return manifest_version_; }
[email protected]6f229e82010-11-02 17:47:26296 bool converted_from_user_script() const {
297 return converted_from_user_script_;
298 }
[email protected]d695bb12014-06-05 16:16:30299 PermissionsParser* permissions_parser() { return permissions_parser_.get(); }
300 const PermissionsParser* permissions_parser() const {
301 return permissions_parser_.get();
302 }
303
[email protected]2cb5e302013-05-09 05:00:06304 const PermissionsData* permissions_data() const {
305 return permissions_data_.get();
[email protected]902fd7b2011-07-27 18:42:31306 }
[email protected]2cb5e302013-05-09 05:00:06307
[email protected]23b3c0a2013-01-16 23:36:36308 // Appends |new_warning[s]| to install_warnings_.
309 void AddInstallWarning(const InstallWarning& new_warning);
[email protected]1d5e58b2013-01-31 08:41:40310 void AddInstallWarnings(const std::vector<InstallWarning>& new_warnings);
311 const std::vector<InstallWarning>& install_warnings() const {
[email protected]8629c542012-04-20 03:40:03312 return install_warnings_;
313 }
[email protected]953620b2011-12-04 00:55:32314 const extensions::Manifest* manifest() const {
[email protected]e9629d772012-08-06 19:44:46315 return manifest_.get();
[email protected]6f229e82010-11-02 17:47:26316 }
[email protected]3aff9ad2011-04-01 20:26:48317 bool wants_file_access() const { return wants_file_access_; }
[email protected]334ec0a2013-03-24 01:36:16318 // TODO(rdevlin.cronin): This is needed for ContentScriptsHandler, and should
319 // be moved out as part of crbug.com/159265. This should not be used anywhere
320 // else.
321 void set_wants_file_access(bool wants_file_access) {
322 wants_file_access_ = wants_file_access;
323 }
[email protected]2af352b2011-07-22 08:21:23324 int creation_flags() const { return creation_flags_; }
325 bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; }
[email protected]e805baf2011-07-26 18:23:05326 bool from_bookmark() const { return (creation_flags_ & FROM_BOOKMARK) != 0; }
[email protected]e33bbc22012-08-27 22:05:46327 bool was_installed_by_default() const {
328 return (creation_flags_ & WAS_INSTALLED_BY_DEFAULT) != 0;
329 }
[email protected]acc3c7c22014-03-19 06:23:39330 bool was_installed_by_oem() const {
331 return (creation_flags_ & WAS_INSTALLED_BY_OEM) != 0;
332 }
[email protected]6338fa32014-07-16 21:41:59333 bool was_installed_by_custodian() const {
334 return (creation_flags_ & WAS_INSTALLED_BY_CUSTODIAN) != 0;
335 }
[email protected]3aff9ad2011-04-01 20:26:48336
[email protected]b86960e2014-07-18 05:35:09337 // Type-related queries.
[email protected]21c01042013-03-10 23:41:14338 bool is_app() const;
[email protected]d41e2152012-02-24 04:20:27339 bool is_platform_app() const;
340 bool is_hosted_app() const;
[email protected]c4f459d2012-09-28 04:40:10341 bool is_legacy_packaged_app() const;
[email protected]ff05a4b102012-12-19 00:12:06342 bool is_extension() const;
[email protected]b86960e2014-07-18 05:35:09343 bool is_shared_module() const;
344 bool is_theme() const;
345
[email protected]cdc7b1f42012-12-07 19:39:48346 bool can_be_incognito_enabled() const;
[email protected]6b414c232013-06-05 07:53:34347
[email protected]636ee43282013-01-12 15:58:00348 void AddWebExtentPattern(const URLPattern& pattern);
[email protected]cced75a2011-05-20 08:31:12349 const URLPatternSet& web_extent() const { return extent_; }
[email protected]6f229e82010-11-02 17:47:26350
[email protected]4a8d3272009-03-10 19:15:08351 private:
[email protected]66e4eb32010-10-27 20:37:41352 friend class base::RefCountedThreadSafe<Extension>;
353
[email protected]d41e2152012-02-24 04:20:27354 // Chooses the extension ID for an extension based on a variety of criteria.
355 // The chosen ID will be set in |manifest|.
356 static bool InitExtensionID(extensions::Manifest* manifest,
[email protected]a7329162013-02-07 19:21:48357 const base::FilePath& path,
[email protected]53d5f0f462014-03-07 09:15:20358 const ExtensionId& explicit_id,
[email protected]d41e2152012-02-24 04:20:27359 int creation_flags,
[email protected]0d163dc2013-12-20 23:48:36360 base::string16* error);
[email protected]d41e2152012-02-24 04:20:27361
[email protected]a7329162013-02-07 19:21:48362 Extension(const base::FilePath& path,
363 scoped_ptr<extensions::Manifest> manifest);
[email protected]d356c982012-12-12 19:32:55364 virtual ~Extension();
[email protected]66e4eb32010-10-27 20:37:41365
366 // Initialize the extension from a parsed manifest.
[email protected]d41e2152012-02-24 04:20:27367 // TODO(aa): Rename to just Init()? There's no Value here anymore.
368 // TODO(aa): It is really weird the way this class essentially contains a copy
369 // of the underlying DictionaryValue in its members. We should decide to
370 // either wrap the DictionaryValue and go with that only, or we should parse
371 // into strong types and discard the value. But doing both is bad.
[email protected]0d163dc2013-12-20 23:48:36372 bool InitFromValue(int flags, base::string16* error);
[email protected]66e4eb32010-10-27 20:37:41373
[email protected]58f62cf2012-03-09 10:45:11374 // The following are helpers for InitFromValue to load various features of the
375 // extension from the manifest.
376
[email protected]0d163dc2013-12-20 23:48:36377 bool LoadRequiredFeatures(base::string16* error);
378 bool LoadName(base::string16* error);
379 bool LoadVersion(base::string16* error);
[email protected]58f62cf2012-03-09 10:45:11380
[email protected]0d163dc2013-12-20 23:48:36381 bool LoadAppFeatures(base::string16* error);
[email protected]d41e2152012-02-24 04:20:27382 bool LoadExtent(const char* key,
383 URLPatternSet* extent,
384 const char* list_error,
385 const char* value_error,
[email protected]0d163dc2013-12-20 23:48:36386 base::string16* error);
[email protected]10253da2012-03-09 04:06:42387
[email protected]0d163dc2013-12-20 23:48:36388 bool LoadSharedFeatures(base::string16* error);
389 bool LoadDescription(base::string16* error);
390 bool LoadManifestVersion(base::string16* error);
391 bool LoadShortName(base::string16* error);
[email protected]66008002013-01-08 09:09:13392
[email protected]0d163dc2013-12-20 23:48:36393 bool CheckMinimumChromeVersion(base::string16* error) const;
[email protected]488e6502012-09-07 14:17:34394
[email protected]6f229e82010-11-02 17:47:26395 // The extension's human-readable name. Name is used for display purpose. It
396 // might be wrapped with unicode bidi control characters so that it is
397 // displayed correctly in RTL context.
398 // NOTE: Name is UTF-8 and may contain non-ascii characters.
399 std::string name_;
400
[email protected]701d1e82012-05-14 05:34:19401 // A non-localized version of the extension's name. This is useful for
402 // debug output.
403 std::string non_localized_name_;
404
[email protected]680eaa672013-08-27 10:25:08405 // A short version of the extension's name. This can be used as an alternative
406 // to the name where there is insufficient space to display the full name. If
407 // an extension has not explicitly specified a short name, the value of this
408 // member variable will be the full name rather than an empty string.
409 std::string short_name_;
410
[email protected]a47c8a22011-11-17 18:40:31411 // The version of this extension's manifest. We increase the manifest
412 // version when making breaking changes to the extension system.
413 // Version 1 was the first manifest version (implied by a lack of a
414 // manifest_version attribute in the extension's manifest). We initialize
415 // this member variable to 0 to distinguish the "uninitialized" case from
416 // the case when we know the manifest version actually is 1.
417 int manifest_version_;
418
[email protected]d41e2152012-02-24 04:20:27419 // The absolute path to the directory the extension is stored in.
[email protected]a7329162013-02-07 19:21:48420 base::FilePath path_;
[email protected]d41e2152012-02-24 04:20:27421
[email protected]6f229e82010-11-02 17:47:26422 // Defines the set of URLs in the extension's web content.
[email protected]cced75a2011-05-20 08:31:12423 URLPatternSet extent_;
[email protected]6f229e82010-11-02 17:47:26424
[email protected]d695bb12014-06-05 16:16:30425 // The parser for the manifest's permissions. This is NULL anytime not during
426 // initialization.
427 // TODO(rdevlin.cronin): This doesn't really belong here.
428 scoped_ptr<PermissionsParser> permissions_parser_;
429
430 // The active permissions for the extension.
[email protected]2cb5e302013-05-09 05:00:06431 scoped_ptr<PermissionsData> permissions_data_;
[email protected]6f229e82010-11-02 17:47:26432
[email protected]8629c542012-04-20 03:40:03433 // Any warnings that occurred when trying to create/parse the extension.
[email protected]1d5e58b2013-01-31 08:41:40434 std::vector<InstallWarning> install_warnings_;
[email protected]8629c542012-04-20 03:40:03435
[email protected]6f229e82010-11-02 17:47:26436 // The base extension url for the extension.
437 GURL extension_url_;
438
[email protected]6f229e82010-11-02 17:47:26439 // The extension's version.
[email protected]1f04ef42013-04-22 07:35:50440 scoped_ptr<base::Version> version_;
[email protected]6f229e82010-11-02 17:47:26441
442 // An optional longer description of the extension.
443 std::string description_;
444
445 // True if the extension was generated from a user script. (We show slightly
446 // different UI if so).
447 bool converted_from_user_script_;
448
[email protected]6f229e82010-11-02 17:47:26449 // The public key used to sign the contents of the crx package.
450 std::string public_key_;
451
[email protected]58f62cf2012-03-09 10:45:11452 // The manifest from which this extension was created.
[email protected]e9629d772012-08-06 19:44:46453 scoped_ptr<Manifest> manifest_;
[email protected]6f229e82010-11-02 17:47:26454
[email protected]d356c982012-12-12 19:32:55455 // Stored parsed manifest data.
456 ManifestDataMap manifest_data_;
457
458 // Set to true at the end of InitValue when initialization is finished.
459 bool finished_parsing_manifest_;
460
[email protected]7eeab9ec2013-01-15 04:08:33461 // Ensures that any call to GetManifestData() prior to finishing
462 // initialization happens from the same thread (this can happen when certain
463 // parts of the initialization process need information from previous parts).
464 base::ThreadChecker thread_checker_;
465
[email protected]7e0f92b2012-11-09 03:51:04466 // Should this app be shown in the app launcher.
[email protected]ed1a204f2012-09-22 00:28:44467 bool display_in_launcher_;
468
[email protected]7e0f92b2012-11-09 03:51:04469 // Should this app be shown in the browser New Tab Page.
470 bool display_in_new_tab_page_;
471
[email protected]3aff9ad2011-04-01 20:26:48472 // Whether the extension has host permissions or user script patterns that
473 // imply access to file:/// scheme URLs (the user may not have actually
474 // granted it that access).
475 bool wants_file_access_;
476
[email protected]2af352b2011-07-22 08:21:23477 // The flags that were passed to InitFromValue.
478 int creation_flags_;
[email protected]620db1762011-07-15 21:57:34479
[email protected]894bb502009-05-21 22:39:57480 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:33481};
482
[email protected]bc151cf92013-02-12 04:57:26483typedef std::vector<scoped_refptr<const Extension> > ExtensionList;
[email protected]53d5f0f462014-03-07 09:15:20484typedef std::set<ExtensionId> ExtensionIdSet;
485typedef std::vector<ExtensionId> ExtensionIdList;
[email protected]b1748b1d82009-11-30 20:32:56486
[email protected]c6d474f82009-12-16 21:11:06487// Handy struct to pass core extension info around.
488struct ExtensionInfo {
[email protected]f3a1c642011-07-12 19:15:03489 ExtensionInfo(const base::DictionaryValue* manifest,
[email protected]53d5f0f462014-03-07 09:15:20490 const ExtensionId& id,
[email protected]a7329162013-02-07 19:21:48491 const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:40492 Manifest::Location location);
[email protected]3bb84992010-08-26 17:23:46493 ~ExtensionInfo();
[email protected]c6d474f82009-12-16 21:11:06494
[email protected]f3a1c642011-07-12 19:15:03495 scoped_ptr<base::DictionaryValue> extension_manifest;
[email protected]53d5f0f462014-03-07 09:15:20496 ExtensionId extension_id;
[email protected]a7329162013-02-07 19:21:48497 base::FilePath extension_path;
[email protected]1d5e58b2013-01-31 08:41:40498 Manifest::Location extension_location;
[email protected]c6d474f82009-12-16 21:11:06499
500 private:
501 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
502};
503
[email protected]41bb80bd2013-05-03 10:56:02504struct InstalledExtensionInfo {
505 // The extension being installed - this should always be non-NULL.
506 const Extension* extension;
507
508 // True if the extension is being updated; false if it is being installed.
509 bool is_update;
510
[email protected]760f743b2014-05-28 13:52:02511 // True if the extension was previously installed ephemerally and is now
512 // a regular installed extension.
513 bool from_ephemeral;
514
[email protected]e7554c3f2013-05-29 00:36:56515 // The name of the extension prior to this update. Will be empty if
516 // |is_update| is false.
517 std::string old_name;
518
519 InstalledExtensionInfo(const Extension* extension,
520 bool is_update,
[email protected]760f743b2014-05-28 13:52:02521 bool from_ephemeral,
[email protected]e7554c3f2013-05-29 00:36:56522 const std::string& old_name);
[email protected]41bb80bd2013-05-03 10:56:02523};
524
[email protected]a9f39a312010-12-23 22:14:27525struct UnloadedExtensionInfo {
[email protected]e51232f32014-04-18 20:05:36526 // TODO(DHNishi): Move this enum to ExtensionRegistryObserver.
[email protected]b0af4792013-10-23 09:12:13527 enum Reason {
[email protected]ebe07772014-05-22 04:16:06528 REASON_UNDEFINED, // Undefined state used to initialize variables.
529 REASON_DISABLE, // Extension is being disabled.
530 REASON_UPDATE, // Extension is being updated to a newer version.
531 REASON_UNINSTALL, // Extension is being uninstalled.
532 REASON_TERMINATE, // Extension has terminated.
533 REASON_BLACKLIST, // Extension has been blacklisted.
534 REASON_PROFILE_SHUTDOWN, // Profile is being shut down.
[email protected]b0af4792013-10-23 09:12:13535 };
536
537 Reason reason;
[email protected]a9f39a312010-12-23 22:14:27538
[email protected]a9f39a312010-12-23 22:14:27539 // The extension being unloaded - this should always be non-NULL.
540 const Extension* extension;
541
[email protected]b0af4792013-10-23 09:12:13542 UnloadedExtensionInfo(const Extension* extension, Reason reason);
[email protected]a9f39a312010-12-23 22:14:27543};
544
[email protected]902fd7b2011-07-27 18:42:31545// The details sent for EXTENSION_PERMISSIONS_UPDATED notifications.
546struct UpdatedExtensionPermissionsInfo {
547 enum Reason {
[email protected]f5532472012-02-23 13:00:55548 ADDED, // The permissions were added to the extension.
549 REMOVED, // The permissions were removed from the extension.
[email protected]902fd7b2011-07-27 18:42:31550 };
551
552 Reason reason;
553
554 // The extension who's permissions have changed.
555 const Extension* extension;
556
557 // The permissions that have changed. For Reason::ADDED, this would contain
558 // only the permissions that have added, and for Reason::REMOVED, this would
559 // only contain the removed permissions.
[email protected]c2e66e12012-06-27 06:27:06560 const PermissionSet* permissions;
[email protected]902fd7b2011-07-27 18:42:31561
562 UpdatedExtensionPermissionsInfo(
563 const Extension* extension,
[email protected]c2e66e12012-06-27 06:27:06564 const PermissionSet* permissions,
[email protected]902fd7b2011-07-27 18:42:31565 Reason reason);
566};
567
[email protected]488e6502012-09-07 14:17:34568} // namespace extensions
[email protected]1c321ee2012-05-21 03:02:34569
[email protected]e4452d32013-11-15 23:07:41570#endif // EXTENSIONS_COMMON_EXTENSION_H_