blob: 4d3b310f86553cc7d3568e679b37a249f5b8d16b [file] [log] [blame]
[email protected]7eeab9ec2013-01-15 04:08:331// Copyright (c) 2013 The Chromium Authors. All rights reserved.
[email protected]7713d632008-12-02 07:52:332// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]5b1a0e22009-05-26 19:00:585#ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_H_
6#define CHROME_COMMON_EXTENSIONS_EXTENSION_H_
[email protected]7713d632008-12-02 07:52:337
[email protected]8629c542012-04-20 03:40:038#include <algorithm>
[email protected]18049dc2012-06-19 23:12:559#include <iosfwd>
[email protected]300cc58db2009-08-19 20:45:1410#include <map>
[email protected]facd7a7652009-06-05 23:15:0211#include <set>
[email protected]7713d632008-12-02 07:52:3312#include <string>
[email protected]58f62cf2012-03-09 10:45:1113#include <utility>
[email protected]7713d632008-12-02 07:52:3314#include <vector>
15
[email protected]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]d83a5602010-09-16 00:22:4823#include "chrome/common/extensions/extension_constants.h"
[email protected]bebe1d02012-08-02 20:17:0924#include "chrome/common/extensions/permissions/api_permission.h"
[email protected]993da5e2013-03-23 21:25:1625#include "extensions/common/extension_resource.h"
[email protected]1d5e58b2013-01-31 08:41:4026#include "extensions/common/install_warning.h"
[email protected]d42c11152013-08-22 19:36:3227#include "extensions/common/manifest.h"
[email protected]885c0e92012-11-13 20:27:4228#include "extensions/common/url_pattern.h"
[email protected]e9f541a2012-11-19 21:52:3129#include "extensions/common/url_pattern_set.h"
[email protected]f5532472012-02-23 13:00:5530#include "ui/base/accelerators/accelerator.h"
[email protected]08397d52011-02-05 01:53:3831#include "ui/gfx/size.h"
[email protected]5f5ef802013-07-04 16:11:1332#include "url/gurl.h"
[email protected]eab9b452009-01-23 20:48:5933
[email protected]0f34d9082012-10-08 19:16:4434class ExtensionAction;
[email protected]12802702010-07-09 19:43:0935class SkBitmap;
[email protected]942690b132010-05-11 06:42:1436
[email protected]f3a1c642011-07-12 19:15:0337namespace base {
38class DictionaryValue;
[email protected]1f04ef42013-04-22 07:35:5039class Version;
[email protected]f3a1c642011-07-12 19:15:0340}
41
[email protected]0f34d9082012-10-08 19:16:4442namespace gfx {
43class ImageSkia;
44}
45
[email protected]1c321ee2012-05-21 03:02:3446namespace extensions {
[email protected]2cb5e302013-05-09 05:00:0647class PermissionsData;
[email protected]465594632013-02-15 19:50:2848class APIPermissionSet;
[email protected]bebe1d02012-08-02 20:17:0949class PermissionSet;
[email protected]1c321ee2012-05-21 03:02:3450
[email protected]f0755532010-06-22 07:27:2551// Represents a Chrome extension.
[email protected]5cd56342013-04-03 19:50:4752// Once created, an Extension object is immutable, with the exception of its
53// RuntimeData. This makes it safe to use on any thread, since access to the
54// RuntimeData is protected by a lock.
[email protected]66e4eb32010-10-27 20:37:4155class Extension : public base::RefCountedThreadSafe<Extension> {
[email protected]7713d632008-12-02 07:52:3356 public:
[email protected]d356c982012-12-12 19:32:5557 struct ManifestData;
[email protected]1e0f45a2012-06-13 00:31:0658
[email protected]10fb1992010-10-08 09:00:1759 typedef std::vector<std::string> ScriptingWhitelist;
[email protected]d356c982012-12-12 19:32:5560 typedef std::map<const std::string, linked_ptr<ManifestData> >
61 ManifestDataMap;
[email protected]b24d8312009-08-27 06:47:4662
[email protected]25b34332009-06-05 21:53:1963 enum State {
[email protected]0c6da502009-08-14 22:32:3964 DISABLED = 0,
[email protected]25b34332009-06-05 21:53:1965 ENABLED,
[email protected]79c833b52011-04-05 18:31:0166 // An external extension that the user uninstalled. We should not reinstall
67 // such extensions on startup.
68 EXTERNAL_EXTENSION_UNINSTALLED,
[email protected]8c484b742012-11-29 06:05:3669 // Special state for component extensions, since they are always loaded by
70 // the component loader, and should never be auto-installed on startup.
71 ENABLED_COMPONENT,
[email protected]0c6da502009-08-14 22:32:3972 NUM_STATES
[email protected]631cf822009-05-15 07:01:2573 };
[email protected]7713d632008-12-02 07:52:3374
[email protected]44d62b62012-04-11 00:06:0375 // Used to record the reason an extension was disabled.
[email protected]eb5e4f92012-08-15 23:33:2876 enum DeprecatedDisableReason {
77 DEPRECATED_DISABLE_UNKNOWN,
78 DEPRECATED_DISABLE_USER_ACTION,
79 DEPRECATED_DISABLE_PERMISSIONS_INCREASE,
80 DEPRECATED_DISABLE_RELOAD,
81 DEPRECATED_DISABLE_LAST, // Not used.
82 };
83
[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]44d62b62012-04-11 00:06:0392 };
93
[email protected]fbcc40302009-06-12 20:45:4594 enum InstallType {
[email protected]ab6f2b22009-07-28 23:28:3795 INSTALL_ERROR,
[email protected]fbcc40302009-06-12 20:45:4596 DOWNGRADE,
97 REINSTALL,
98 UPGRADE,
99 NEW_INSTALL
100 };
101
[email protected]d356c982012-12-12 19:32:55102 // A base class for parsed manifest data that APIs want to store on
103 // the extension. Related to base::SupportsUserData, but with an immutable
104 // thread-safe interface to match Extension.
105 struct ManifestData {
106 virtual ~ManifestData() {}
107 };
108
[email protected]83048a22011-03-29 00:14:13109 enum InitFromValueFlags {
110 NO_FLAGS = 0,
111
112 // Usually, the id of an extension is generated by the "key" property of
113 // its manifest, but if |REQUIRE_KEY| is not set, a temporary ID will be
114 // generated based on the path.
115 REQUIRE_KEY = 1 << 0,
116
[email protected]3f53dfe2011-11-30 01:18:29117 // Requires the extension to have an up-to-date manifest version.
118 // Typically, we'll support multiple manifest versions during a version
[email protected]26367b62012-10-04 23:03:32119 // transition. This flag signals that we want to require the most modern
[email protected]3f53dfe2011-11-30 01:18:29120 // manifest version that Chrome understands.
121 REQUIRE_MODERN_MANIFEST_VERSION = 1 << 1,
122
[email protected]3aff9ad2011-04-01 20:26:48123 // |ALLOW_FILE_ACCESS| indicates that the user is allowing this extension
124 // to have file access. If it's not present, then permissions and content
125 // scripts that match file:/// URLs will be filtered out.
[email protected]ed3b9b12012-05-31 18:37:51126 ALLOW_FILE_ACCESS = 1 << 2,
[email protected]620db1762011-07-15 21:57:34127
128 // |FROM_WEBSTORE| indicates that the extension was installed from the
129 // Chrome Web Store.
[email protected]ed3b9b12012-05-31 18:37:51130 FROM_WEBSTORE = 1 << 3,
[email protected]e805baf2011-07-26 18:23:05131
132 // |FROM_BOOKMARK| indicates the extension was created using a mock App
133 // created from a bookmark.
[email protected]ed3b9b12012-05-31 18:37:51134 FROM_BOOKMARK = 1 << 4,
[email protected]3d41d432012-04-20 20:47:58135
136 // |FOLLOW_SYMLINKS_ANYWHERE| means that resources can be symlinks to
137 // anywhere in the filesystem, rather than being restricted to the
138 // extension directory.
[email protected]ed3b9b12012-05-31 18:37:51139 FOLLOW_SYMLINKS_ANYWHERE = 1 << 5,
[email protected]ab55c2b2012-06-01 23:55:03140
141 // |ERROR_ON_PRIVATE_KEY| means that private keys inside an
142 // extension should be errors rather than warnings.
143 ERROR_ON_PRIVATE_KEY = 1 << 6,
[email protected]e33bbc22012-08-27 22:05:46144
145 // |WAS_INSTALLED_BY_DEFAULT| installed by default when the profile was
146 // created.
147 WAS_INSTALLED_BY_DEFAULT = 1 << 7,
[email protected]83048a22011-03-29 00:14:13148 };
149
[email protected]a7329162013-02-07 19:21:48150 static scoped_refptr<Extension> Create(const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:40151 Manifest::Location location,
[email protected]f3a1c642011-07-12 19:15:03152 const base::DictionaryValue& value,
[email protected]83048a22011-03-29 00:14:13153 int flags,
[email protected]66e4eb32010-10-27 20:37:41154 std::string* error);
155
[email protected]87c655e2011-07-01 21:42:00156 // In a few special circumstances, we want to create an Extension and give it
[email protected]f5bf1842012-02-15 02:52:26157 // an explicit id. Most consumers should just use the other Create() method.
[email protected]a7329162013-02-07 19:21:48158 static scoped_refptr<Extension> Create(const base::FilePath& path,
[email protected]2cb5e302013-05-09 05:00:06159 Manifest::Location location,
160 const base::DictionaryValue& value,
161 int flags,
162 const std::string& explicit_id,
163 std::string* error);
[email protected]87c655e2011-07-01 21:42:00164
[email protected]8d888c12010-11-30 00:00:25165 // Valid schemes for web extent URLPatterns.
166 static const int kValidWebExtentSchemes;
167
[email protected]f71f7e62010-12-07 03:45:33168 // Valid schemes for host permission URLPatterns.
169 static const int kValidHostPermissionSchemes;
170
[email protected]25b34332009-06-05 21:53:19171#if defined(OS_WIN)
[email protected]9dcf8f12010-09-02 20:39:19172 static const char kExtensionRegistryPath[];
[email protected]25b34332009-06-05 21:53:19173#endif
174
[email protected]e435d6b72009-07-25 03:15:58175 // The mimetype used for extensions.
176 static const char kMimeType[];
177
[email protected]25b34332009-06-05 21:53:19178 // Checks to see if the extension has a valid ID.
179 static bool IdIsValid(const std::string& id);
180
[email protected]1d5e58b2013-01-31 08:41:40181 // See Type definition in Manifest.
182 Manifest::Type GetType() const;
[email protected]9b217652010-10-08 22:04:23183
[email protected]07c00d992009-03-04 20:27:04184 // Returns an absolute url to a resource inside of an extension. The
[email protected]eab9b452009-01-23 20:48:59185 // |extension_url| argument should be the url() from an Extension object. The
186 // |relative_path| can be untrusted user input. The returned URL will either
187 // be invalid() or a child of |extension_url|.
188 // NOTE: Static so that it can be used from multiple threads.
189 static GURL GetResourceURL(const GURL& extension_url,
190 const std::string& relative_path);
[email protected]cffd7892010-08-26 17:43:28191 GURL GetResourceURL(const std::string& relative_path) const {
[email protected]3cfbd0e2009-03-18 21:26:24192 return GetResourceURL(url(), relative_path);
193 }
[email protected]eab9b452009-01-23 20:48:59194
[email protected]f59a8052012-06-20 22:25:00195 // Returns true if the resource matches a pattern in the pattern_set.
196 bool ResourceMatches(const URLPatternSet& pattern_set,
197 const std::string& resource) const;
198
[email protected]99efb7b12009-12-18 02:39:16199 // Returns an extension resource object. |relative_path| should be UTF8
200 // encoded.
[email protected]9adb9692010-10-29 23:14:02201 ExtensionResource GetResource(const std::string& relative_path) const;
[email protected]99efb7b12009-12-18 02:39:16202
203 // As above, but with |relative_path| following the file system's encoding.
[email protected]a7329162013-02-07 19:21:48204 ExtensionResource GetResource(const base::FilePath& relative_path) const;
[email protected]eab9b452009-01-23 20:48:59205
[email protected]a17f9462009-06-09 02:56:41206 // |input| is expected to be the text of an rsa public or private key. It
207 // tolerates the presence or absence of bracking header/footer like this:
208 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY-----
209 // and may contain newlines.
210 static bool ParsePEMKeyBytes(const std::string& input, std::string* output);
211
212 // Does a simple base64 encoding of |input| into |output|.
213 static bool ProducePEM(const std::string& input, std::string* output);
214
215 // Expects base64 encoded |input| and formats into |output| including
216 // the appropriate header & footer.
[email protected]e0d08192011-03-29 19:02:50217 static bool FormatPEMForFileOutput(const std::string& input,
218 std::string* output,
219 bool is_public);
[email protected]a17f9462009-06-09 02:56:41220
[email protected]a807bbe2010-04-14 10:51:19221 // Returns the base extension url for a given |extension_id|.
222 static GURL GetBaseURLFromExtensionId(const std::string& extension_id);
223
[email protected]be7e5cb2010-10-04 12:53:17224 // Adds an extension to the scripting whitelist. Used for testing only.
[email protected]10fb1992010-10-08 09:00:17225 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist);
[email protected]2a521c52011-01-26 18:45:21226 static const ScriptingWhitelist* GetScriptingWhitelist();
[email protected]be7e5cb2010-10-04 12:53:17227
[email protected]13c68b62013-05-17 11:29:05228 // DEPRECATED: These methods have been moved to PermissionsData.
229 // TODO(rdevlin.cronin): remove these once all calls have been updated.
[email protected]c2e66e12012-06-27 06:27:06230 bool HasAPIPermission(APIPermission::ID permission) const;
[email protected]b5b26b72013-08-02 00:25:11231 bool HasAPIPermission(const std::string& permission_name) const;
[email protected]c2e66e12012-06-27 06:27:06232 scoped_refptr<const PermissionSet> GetActivePermissions() const;
[email protected]902fd7b2011-07-27 18:42:31233
[email protected]5df6a5d2011-01-26 07:39:12234 // Whether context menu should be shown for page and browser actions.
235 bool ShowConfigureContextMenus() const;
236
[email protected]cca147172011-02-17 01:29:29237 // Returns true if this extension or app includes areas within |origin|.
238 bool OverlapsWithOrigin(const GURL& origin) const;
239
[email protected]7e0f92b2012-11-09 03:51:04240 // Returns true if the extension requires a valid ordinal for sorting, e.g.,
241 // for displaying in a launcher or new tab page.
242 bool RequiresSortOrdinal() const;
243
244 // Returns true if the extension should be displayed in the app launcher.
245 bool ShouldDisplayInAppLauncher() const;
246
247 // Returns true if the extension should be displayed in the browser NTP.
248 bool ShouldDisplayInNewTabPage() const;
[email protected]b873cd92012-02-09 21:51:48249
[email protected]e0b3de72012-05-01 01:21:34250 // Returns true if the extension should be displayed in the extension
251 // settings page (i.e. chrome://extensions).
252 bool ShouldDisplayInExtensionSettings() const;
253
[email protected]624e63d0c2013-08-16 00:09:50254 // Returns true if the extension should not be shown anywhere. This is
255 // mostly the same as the extension being a component extension, but also
256 // includes non-component apps that are hidden from the app launcher and ntp.
257 bool ShouldNotBeVisible() const;
258
[email protected]d356c982012-12-12 19:32:55259 // Get the manifest data associated with the key, or NULL if there is none.
260 // Can only be called after InitValue is finished.
261 ManifestData* GetManifestData(const std::string& key) const;
262
263 // Sets |data| to be associated with the key. Takes ownership of |data|.
264 // Can only be called before InitValue is finished. Not thread-safe;
265 // all SetManifestData calls should be on only one thread.
266 void SetManifestData(const std::string& key, ManifestData* data);
267
[email protected]6f229e82010-11-02 17:47:26268 // Accessors:
269
[email protected]a7329162013-02-07 19:21:48270 const base::FilePath& path() const { return path_; }
[email protected]6f229e82010-11-02 17:47:26271 const GURL& url() const { return extension_url_; }
[email protected]1d5e58b2013-01-31 08:41:40272 Manifest::Location location() const;
[email protected]d41e2152012-02-24 04:20:27273 const std::string& id() const;
[email protected]1f04ef42013-04-22 07:35:50274 const base::Version* version() const { return version_.get(); }
[email protected]6f229e82010-11-02 17:47:26275 const std::string VersionString() const;
276 const std::string& name() const { return name_; }
[email protected]701d1e82012-05-14 05:34:19277 const std::string& non_localized_name() const { return non_localized_name_; }
[email protected]200423d2012-06-05 01:16:06278 // Base64-encoded version of the key used to sign this extension.
279 // In pseudocode, returns
280 // base::Base64Encode(RSAPrivateKey(pem_file).ExportPublicKey()).
281 const std::string& public_key() const { return public_key_; }
[email protected]6f229e82010-11-02 17:47:26282 const std::string& description() const { return description_; }
[email protected]a47c8a22011-11-17 18:40:31283 int manifest_version() const { return manifest_version_; }
[email protected]6f229e82010-11-02 17:47:26284 bool converted_from_user_script() const {
285 return converted_from_user_script_;
286 }
[email protected]2cb5e302013-05-09 05:00:06287 PermissionsData* permissions_data() { return permissions_data_.get(); }
288 const PermissionsData* permissions_data() const {
289 return permissions_data_.get();
[email protected]902fd7b2011-07-27 18:42:31290 }
[email protected]2cb5e302013-05-09 05:00:06291
[email protected]23b3c0a2013-01-16 23:36:36292 // Appends |new_warning[s]| to install_warnings_.
293 void AddInstallWarning(const InstallWarning& new_warning);
[email protected]1d5e58b2013-01-31 08:41:40294 void AddInstallWarnings(const std::vector<InstallWarning>& new_warnings);
295 const std::vector<InstallWarning>& install_warnings() const {
[email protected]8629c542012-04-20 03:40:03296 return install_warnings_;
297 }
[email protected]953620b2011-12-04 00:55:32298 const extensions::Manifest* manifest() const {
[email protected]e9629d772012-08-06 19:44:46299 return manifest_.get();
[email protected]6f229e82010-11-02 17:47:26300 }
[email protected]3aff9ad2011-04-01 20:26:48301 bool wants_file_access() const { return wants_file_access_; }
[email protected]334ec0a2013-03-24 01:36:16302 // TODO(rdevlin.cronin): This is needed for ContentScriptsHandler, and should
303 // be moved out as part of crbug.com/159265. This should not be used anywhere
304 // else.
305 void set_wants_file_access(bool wants_file_access) {
306 wants_file_access_ = wants_file_access;
307 }
[email protected]2af352b2011-07-22 08:21:23308 int creation_flags() const { return creation_flags_; }
309 bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; }
[email protected]e805baf2011-07-26 18:23:05310 bool from_bookmark() const { return (creation_flags_ & FROM_BOOKMARK) != 0; }
[email protected]e33bbc22012-08-27 22:05:46311 bool was_installed_by_default() const {
312 return (creation_flags_ & WAS_INSTALLED_BY_DEFAULT) != 0;
313 }
[email protected]3aff9ad2011-04-01 20:26:48314
[email protected]6f229e82010-11-02 17:47:26315 // App-related.
[email protected]21c01042013-03-10 23:41:14316 bool is_app() const;
[email protected]d41e2152012-02-24 04:20:27317 bool is_platform_app() const;
318 bool is_hosted_app() const;
[email protected]c4f459d2012-09-28 04:40:10319 bool is_legacy_packaged_app() const;
[email protected]ff05a4b102012-12-19 00:12:06320 bool is_extension() const;
[email protected]cdc7b1f42012-12-07 19:39:48321 bool can_be_incognito_enabled() const;
[email protected]fc05749a2013-07-10 06:59:11322 bool force_incognito_enabled() const;
[email protected]6b414c232013-06-05 07:53:34323
[email protected]636ee43282013-01-12 15:58:00324 void AddWebExtentPattern(const URLPattern& pattern);
[email protected]cced75a2011-05-20 08:31:12325 const URLPatternSet& web_extent() const { return extent_; }
[email protected]6f229e82010-11-02 17:47:26326
327 // Theme-related.
[email protected]d41e2152012-02-24 04:20:27328 bool is_theme() const;
[email protected]6f229e82010-11-02 17:47:26329
[email protected]4a8d3272009-03-10 19:15:08330 private:
[email protected]66e4eb32010-10-27 20:37:41331 friend class base::RefCountedThreadSafe<Extension>;
332
[email protected]d41e2152012-02-24 04:20:27333 // Chooses the extension ID for an extension based on a variety of criteria.
334 // The chosen ID will be set in |manifest|.
335 static bool InitExtensionID(extensions::Manifest* manifest,
[email protected]a7329162013-02-07 19:21:48336 const base::FilePath& path,
[email protected]d41e2152012-02-24 04:20:27337 const std::string& explicit_id,
338 int creation_flags,
339 string16* error);
340
[email protected]a7329162013-02-07 19:21:48341 Extension(const base::FilePath& path,
342 scoped_ptr<extensions::Manifest> manifest);
[email protected]d356c982012-12-12 19:32:55343 virtual ~Extension();
[email protected]66e4eb32010-10-27 20:37:41344
345 // Initialize the extension from a parsed manifest.
[email protected]d41e2152012-02-24 04:20:27346 // TODO(aa): Rename to just Init()? There's no Value here anymore.
347 // TODO(aa): It is really weird the way this class essentially contains a copy
348 // of the underlying DictionaryValue in its members. We should decide to
349 // either wrap the DictionaryValue and go with that only, or we should parse
350 // into strong types and discard the value. But doing both is bad.
351 bool InitFromValue(int flags, string16* error);
[email protected]66e4eb32010-10-27 20:37:41352
[email protected]58f62cf2012-03-09 10:45:11353 // The following are helpers for InitFromValue to load various features of the
354 // extension from the manifest.
355
[email protected]58f62cf2012-03-09 10:45:11356 bool LoadRequiredFeatures(string16* error);
357 bool LoadName(string16* error);
358 bool LoadVersion(string16* error);
359
360 bool LoadAppFeatures(string16* error);
[email protected]d41e2152012-02-24 04:20:27361 bool LoadExtent(const char* key,
362 URLPatternSet* extent,
363 const char* list_error,
364 const char* value_error,
365 string16* error);
[email protected]10253da2012-03-09 04:06:42366
[email protected]465594632013-02-15 19:50:28367 bool LoadSharedFeatures(string16* error);
[email protected]58f62cf2012-03-09 10:45:11368 bool LoadDescription(string16* error);
369 bool LoadManifestVersion(string16* error);
[email protected]66008002013-01-08 09:09:13370
[email protected]488e6502012-09-07 14:17:34371 bool CheckMinimumChromeVersion(string16* error) const;
[email protected]488e6502012-09-07 14:17:34372
[email protected]6f229e82010-11-02 17:47:26373 // The extension's human-readable name. Name is used for display purpose. It
374 // might be wrapped with unicode bidi control characters so that it is
375 // displayed correctly in RTL context.
376 // NOTE: Name is UTF-8 and may contain non-ascii characters.
377 std::string name_;
378
[email protected]701d1e82012-05-14 05:34:19379 // A non-localized version of the extension's name. This is useful for
380 // debug output.
381 std::string non_localized_name_;
382
[email protected]a47c8a22011-11-17 18:40:31383 // The version of this extension's manifest. We increase the manifest
384 // version when making breaking changes to the extension system.
385 // Version 1 was the first manifest version (implied by a lack of a
386 // manifest_version attribute in the extension's manifest). We initialize
387 // this member variable to 0 to distinguish the "uninitialized" case from
388 // the case when we know the manifest version actually is 1.
389 int manifest_version_;
390
[email protected]d41e2152012-02-24 04:20:27391 // The absolute path to the directory the extension is stored in.
[email protected]a7329162013-02-07 19:21:48392 base::FilePath path_;
[email protected]d41e2152012-02-24 04:20:27393
[email protected]6f229e82010-11-02 17:47:26394 // Defines the set of URLs in the extension's web content.
[email protected]cced75a2011-05-20 08:31:12395 URLPatternSet extent_;
[email protected]6f229e82010-11-02 17:47:26396
[email protected]2cb5e302013-05-09 05:00:06397 scoped_ptr<PermissionsData> permissions_data_;
[email protected]6f229e82010-11-02 17:47:26398
[email protected]8629c542012-04-20 03:40:03399 // Any warnings that occurred when trying to create/parse the extension.
[email protected]1d5e58b2013-01-31 08:41:40400 std::vector<InstallWarning> install_warnings_;
[email protected]8629c542012-04-20 03:40:03401
[email protected]6f229e82010-11-02 17:47:26402 // The base extension url for the extension.
403 GURL extension_url_;
404
[email protected]6f229e82010-11-02 17:47:26405 // The extension's version.
[email protected]1f04ef42013-04-22 07:35:50406 scoped_ptr<base::Version> version_;
[email protected]6f229e82010-11-02 17:47:26407
408 // An optional longer description of the extension.
409 std::string description_;
410
411 // True if the extension was generated from a user script. (We show slightly
412 // different UI if so).
413 bool converted_from_user_script_;
414
[email protected]6f229e82010-11-02 17:47:26415 // The public key used to sign the contents of the crx package.
416 std::string public_key_;
417
[email protected]58f62cf2012-03-09 10:45:11418 // The manifest from which this extension was created.
[email protected]e9629d772012-08-06 19:44:46419 scoped_ptr<Manifest> manifest_;
[email protected]6f229e82010-11-02 17:47:26420
[email protected]d356c982012-12-12 19:32:55421 // Stored parsed manifest data.
422 ManifestDataMap manifest_data_;
423
424 // Set to true at the end of InitValue when initialization is finished.
425 bool finished_parsing_manifest_;
426
[email protected]7eeab9ec2013-01-15 04:08:33427 // Ensures that any call to GetManifestData() prior to finishing
428 // initialization happens from the same thread (this can happen when certain
429 // parts of the initialization process need information from previous parts).
430 base::ThreadChecker thread_checker_;
431
[email protected]7e0f92b2012-11-09 03:51:04432 // Should this app be shown in the app launcher.
[email protected]ed1a204f2012-09-22 00:28:44433 bool display_in_launcher_;
434
[email protected]7e0f92b2012-11-09 03:51:04435 // Should this app be shown in the browser New Tab Page.
436 bool display_in_new_tab_page_;
437
[email protected]3aff9ad2011-04-01 20:26:48438 // Whether the extension has host permissions or user script patterns that
439 // imply access to file:/// scheme URLs (the user may not have actually
440 // granted it that access).
441 bool wants_file_access_;
442
[email protected]2af352b2011-07-22 08:21:23443 // The flags that were passed to InitFromValue.
444 int creation_flags_;
[email protected]620db1762011-07-15 21:57:34445
[email protected]894bb502009-05-21 22:39:57446 DISALLOW_COPY_AND_ASSIGN(Extension);
[email protected]7713d632008-12-02 07:52:33447};
448
[email protected]bc151cf92013-02-12 04:57:26449typedef std::vector<scoped_refptr<const Extension> > ExtensionList;
[email protected]ec5b50d2010-10-09 16:35:18450typedef std::set<std::string> ExtensionIdSet;
[email protected]82590cb2012-09-28 04:14:08451typedef std::vector<std::string> ExtensionIdList;
[email protected]b1748b1d82009-11-30 20:32:56452
[email protected]c6d474f82009-12-16 21:11:06453// Handy struct to pass core extension info around.
454struct ExtensionInfo {
[email protected]f3a1c642011-07-12 19:15:03455 ExtensionInfo(const base::DictionaryValue* manifest,
[email protected]c6d474f82009-12-16 21:11:06456 const std::string& id,
[email protected]a7329162013-02-07 19:21:48457 const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:40458 Manifest::Location location);
[email protected]3bb84992010-08-26 17:23:46459 ~ExtensionInfo();
[email protected]c6d474f82009-12-16 21:11:06460
[email protected]f3a1c642011-07-12 19:15:03461 scoped_ptr<base::DictionaryValue> extension_manifest;
[email protected]c6d474f82009-12-16 21:11:06462 std::string extension_id;
[email protected]a7329162013-02-07 19:21:48463 base::FilePath extension_path;
[email protected]1d5e58b2013-01-31 08:41:40464 Manifest::Location extension_location;
[email protected]c6d474f82009-12-16 21:11:06465
466 private:
467 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
468};
469
[email protected]41bb80bd2013-05-03 10:56:02470struct InstalledExtensionInfo {
471 // The extension being installed - this should always be non-NULL.
472 const Extension* extension;
473
474 // True if the extension is being updated; false if it is being installed.
475 bool is_update;
476
[email protected]e7554c3f2013-05-29 00:36:56477 // The name of the extension prior to this update. Will be empty if
478 // |is_update| is false.
479 std::string old_name;
480
481 InstalledExtensionInfo(const Extension* extension,
482 bool is_update,
483 const std::string& old_name);
[email protected]41bb80bd2013-05-03 10:56:02484};
485
[email protected]a9f39a312010-12-23 22:14:27486struct UnloadedExtensionInfo {
[email protected]814a7bf0f2011-08-13 05:30:59487 extension_misc::UnloadedExtensionReason reason;
[email protected]a9f39a312010-12-23 22:14:27488
[email protected]a9f39a312010-12-23 22:14:27489 // The extension being unloaded - this should always be non-NULL.
490 const Extension* extension;
491
[email protected]814a7bf0f2011-08-13 05:30:59492 UnloadedExtensionInfo(
493 const Extension* extension,
494 extension_misc::UnloadedExtensionReason reason);
[email protected]a9f39a312010-12-23 22:14:27495};
496
[email protected]902fd7b2011-07-27 18:42:31497// The details sent for EXTENSION_PERMISSIONS_UPDATED notifications.
498struct UpdatedExtensionPermissionsInfo {
499 enum Reason {
[email protected]f5532472012-02-23 13:00:55500 ADDED, // The permissions were added to the extension.
501 REMOVED, // The permissions were removed from the extension.
[email protected]902fd7b2011-07-27 18:42:31502 };
503
504 Reason reason;
505
506 // The extension who's permissions have changed.
507 const Extension* extension;
508
509 // The permissions that have changed. For Reason::ADDED, this would contain
510 // only the permissions that have added, and for Reason::REMOVED, this would
511 // only contain the removed permissions.
[email protected]c2e66e12012-06-27 06:27:06512 const PermissionSet* permissions;
[email protected]902fd7b2011-07-27 18:42:31513
514 UpdatedExtensionPermissionsInfo(
515 const Extension* extension,
[email protected]c2e66e12012-06-27 06:27:06516 const PermissionSet* permissions,
[email protected]902fd7b2011-07-27 18:42:31517 Reason reason);
518};
519
[email protected]488e6502012-09-07 14:17:34520} // namespace extensions
[email protected]1c321ee2012-05-21 03:02:34521
[email protected]5b1a0e22009-05-26 19:00:58522#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_