[email protected] | 7eeab9ec | 2013-01-15 04:08:33 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 5 | #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
| 6 | #define CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 7 | |
[email protected] | 8629c54 | 2012-04-20 03:40:03 | [diff] [blame] | 8 | #include <algorithm> |
[email protected] | 18049dc | 2012-06-19 23:12:55 | [diff] [blame] | 9 | #include <iosfwd> |
[email protected] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 10 | #include <map> |
[email protected] | facd7a765 | 2009-06-05 23:15:02 | [diff] [blame] | 11 | #include <set> |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 12 | #include <string> |
[email protected] | 58f62cf | 2012-03-09 10:45:11 | [diff] [blame] | 13 | #include <utility> |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
[email protected] | 14c1c23 | 2013-06-11 17:52:44 | [diff] [blame] | 16 | #include "base/containers/hash_tables.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 17 | #include "base/files/file_path.h" |
[email protected] | b6b805e9 | 2011-04-16 09:24:14 | [diff] [blame] | 18 | #include "base/memory/linked_ptr.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 19 | #include "base/memory/ref_counted.h" |
| 20 | #include "base/memory/scoped_ptr.h" |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 21 | #include "base/synchronization/lock.h" |
[email protected] | 7eeab9ec | 2013-01-15 04:08:33 | [diff] [blame] | 22 | #include "base/threading/thread_checker.h" |
[email protected] | d83a560 | 2010-09-16 00:22:48 | [diff] [blame] | 23 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 24 | #include "extensions/common/extension_resource.h" |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 25 | #include "extensions/common/install_warning.h" |
[email protected] | d42c1115 | 2013-08-22 19:36:32 | [diff] [blame] | 26 | #include "extensions/common/manifest.h" |
[email protected] | 793964a | 2013-10-08 00:47:19 | [diff] [blame] | 27 | #include "extensions/common/permissions/api_permission.h" |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 28 | #include "extensions/common/url_pattern.h" |
[email protected] | e9f541a | 2012-11-19 21:52:31 | [diff] [blame] | 29 | #include "extensions/common/url_pattern_set.h" |
[email protected] | f553247 | 2012-02-23 13:00:55 | [diff] [blame] | 30 | #include "ui/base/accelerators/accelerator.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 31 | #include "ui/gfx/size.h" |
[email protected] | 5f5ef80 | 2013-07-04 16:11:13 | [diff] [blame] | 32 | #include "url/gurl.h" |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 33 | |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 34 | class ExtensionAction; |
[email protected] | 1280270 | 2010-07-09 19:43:09 | [diff] [blame] | 35 | class SkBitmap; |
[email protected] | 942690b13 | 2010-05-11 06:42:14 | [diff] [blame] | 36 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 37 | namespace base { |
| 38 | class DictionaryValue; |
[email protected] | 1f04ef4 | 2013-04-22 07:35:50 | [diff] [blame] | 39 | class Version; |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 40 | } |
| 41 | |
[email protected] | 0f34d908 | 2012-10-08 19:16:44 | [diff] [blame] | 42 | namespace gfx { |
| 43 | class ImageSkia; |
| 44 | } |
| 45 | |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 46 | namespace extensions { |
[email protected] | 2cb5e30 | 2013-05-09 05:00:06 | [diff] [blame] | 47 | class PermissionsData; |
[email protected] | 46559463 | 2013-02-15 19:50:28 | [diff] [blame] | 48 | class APIPermissionSet; |
[email protected] | bebe1d0 | 2012-08-02 20:17:09 | [diff] [blame] | 49 | class PermissionSet; |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 50 | |
[email protected] | f075553 | 2010-06-22 07:27:25 | [diff] [blame] | 51 | // Represents a Chrome extension. |
[email protected] | 5cd5634 | 2013-04-03 19:50:47 | [diff] [blame] | 52 | // 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] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 55 | class Extension : public base::RefCountedThreadSafe<Extension> { |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 56 | public: |
[email protected] | d356c98 | 2012-12-12 19:32:55 | [diff] [blame] | 57 | struct ManifestData; |
[email protected] | 1e0f45a | 2012-06-13 00:31:06 | [diff] [blame] | 58 | |
[email protected] | 10fb199 | 2010-10-08 09:00:17 | [diff] [blame] | 59 | typedef std::vector<std::string> ScriptingWhitelist; |
[email protected] | d356c98 | 2012-12-12 19:32:55 | [diff] [blame] | 60 | typedef std::map<const std::string, linked_ptr<ManifestData> > |
| 61 | ManifestDataMap; |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 62 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 63 | enum State { |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 64 | DISABLED = 0, |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 65 | ENABLED, |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 66 | // An external extension that the user uninstalled. We should not reinstall |
| 67 | // such extensions on startup. |
| 68 | EXTERNAL_EXTENSION_UNINSTALLED, |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 69 | // 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] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 72 | NUM_STATES |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 73 | }; |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 74 | |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 75 | // Used to record the reason an extension was disabled. |
[email protected] | eb5e4f9 | 2012-08-15 23:33:28 | [diff] [blame] | 76 | 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] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 84 | enum DisableReason { |
[email protected] | eb5e4f9 | 2012-08-15 23:33:28 | [diff] [blame] | 85 | DISABLE_NONE = 0, |
| 86 | DISABLE_USER_ACTION = 1 << 0, |
| 87 | DISABLE_PERMISSIONS_INCREASE = 1 << 1, |
| 88 | DISABLE_RELOAD = 1 << 2, |
[email protected] | 215a7be | 2012-10-22 19:53:42 | [diff] [blame] | 89 | DISABLE_UNSUPPORTED_REQUIREMENT = 1 << 3, |
| 90 | DISABLE_SIDELOAD_WIPEOUT = 1 << 4, |
[email protected] | f56c65ea6 | 2012-12-10 22:57:21 | [diff] [blame] | 91 | DISABLE_UNKNOWN_FROM_SYNC = 1 << 5, |
[email protected] | aa5a547 | 2013-10-04 03:41:04 | [diff] [blame] | 92 | // Disabled because the user has not yet consented to the permissions, |
| 93 | // for instance for a default installed item. |
| 94 | DISABLE_PERMISSIONS_CONSENT = 1 << 6, |
[email protected] | 59ee99d | 2013-10-11 15:46:16 | [diff] [blame^] | 95 | DISABLE_KNOWN_DISABLED = 1 << 7, |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 96 | }; |
| 97 | |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 98 | enum InstallType { |
[email protected] | ab6f2b2 | 2009-07-28 23:28:37 | [diff] [blame] | 99 | INSTALL_ERROR, |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 100 | DOWNGRADE, |
| 101 | REINSTALL, |
| 102 | UPGRADE, |
| 103 | NEW_INSTALL |
| 104 | }; |
| 105 | |
[email protected] | d356c98 | 2012-12-12 19:32:55 | [diff] [blame] | 106 | // A base class for parsed manifest data that APIs want to store on |
| 107 | // the extension. Related to base::SupportsUserData, but with an immutable |
| 108 | // thread-safe interface to match Extension. |
| 109 | struct ManifestData { |
| 110 | virtual ~ManifestData() {} |
| 111 | }; |
| 112 | |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 113 | 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] | 3f53dfe | 2011-11-30 01:18:29 | [diff] [blame] | 121 | // Requires the extension to have an up-to-date manifest version. |
| 122 | // Typically, we'll support multiple manifest versions during a version |
[email protected] | 26367b6 | 2012-10-04 23:03:32 | [diff] [blame] | 123 | // transition. This flag signals that we want to require the most modern |
[email protected] | 3f53dfe | 2011-11-30 01:18:29 | [diff] [blame] | 124 | // manifest version that Chrome understands. |
| 125 | REQUIRE_MODERN_MANIFEST_VERSION = 1 << 1, |
| 126 | |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 127 | // |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] | ed3b9b1 | 2012-05-31 18:37:51 | [diff] [blame] | 130 | ALLOW_FILE_ACCESS = 1 << 2, |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 131 | |
| 132 | // |FROM_WEBSTORE| indicates that the extension was installed from the |
| 133 | // Chrome Web Store. |
[email protected] | ed3b9b1 | 2012-05-31 18:37:51 | [diff] [blame] | 134 | FROM_WEBSTORE = 1 << 3, |
[email protected] | e805baf | 2011-07-26 18:23:05 | [diff] [blame] | 135 | |
| 136 | // |FROM_BOOKMARK| indicates the extension was created using a mock App |
| 137 | // created from a bookmark. |
[email protected] | ed3b9b1 | 2012-05-31 18:37:51 | [diff] [blame] | 138 | FROM_BOOKMARK = 1 << 4, |
[email protected] | 3d41d43 | 2012-04-20 20:47:58 | [diff] [blame] | 139 | |
| 140 | // |FOLLOW_SYMLINKS_ANYWHERE| means that resources can be symlinks to |
| 141 | // anywhere in the filesystem, rather than being restricted to the |
| 142 | // extension directory. |
[email protected] | ed3b9b1 | 2012-05-31 18:37:51 | [diff] [blame] | 143 | FOLLOW_SYMLINKS_ANYWHERE = 1 << 5, |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 144 | |
| 145 | // |ERROR_ON_PRIVATE_KEY| means that private keys inside an |
| 146 | // extension should be errors rather than warnings. |
| 147 | ERROR_ON_PRIVATE_KEY = 1 << 6, |
[email protected] | e33bbc2 | 2012-08-27 22:05:46 | [diff] [blame] | 148 | |
| 149 | // |WAS_INSTALLED_BY_DEFAULT| installed by default when the profile was |
| 150 | // created. |
| 151 | WAS_INSTALLED_BY_DEFAULT = 1 << 7, |
[email protected] | aa5a547 | 2013-10-04 03:41:04 | [diff] [blame] | 152 | |
| 153 | // |REQUIRE_PERMISSIONS_CONSENT| means that user needs to accept permissions |
| 154 | // before running the app even if it is marked as |WAS_INSTALLED_BY_DEFAULT| |
| 155 | // and |FROM_WEBSTORE|. |
| 156 | REQUIRE_PERMISSIONS_CONSENT = 1 << 8, |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 157 | }; |
| 158 | |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 159 | static scoped_refptr<Extension> Create(const base::FilePath& path, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 160 | Manifest::Location location, |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 161 | const base::DictionaryValue& value, |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 162 | int flags, |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 163 | std::string* error); |
| 164 | |
[email protected] | 87c655e | 2011-07-01 21:42:00 | [diff] [blame] | 165 | // In a few special circumstances, we want to create an Extension and give it |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 166 | // an explicit id. Most consumers should just use the other Create() method. |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 167 | static scoped_refptr<Extension> Create(const base::FilePath& path, |
[email protected] | 2cb5e30 | 2013-05-09 05:00:06 | [diff] [blame] | 168 | Manifest::Location location, |
| 169 | const base::DictionaryValue& value, |
| 170 | int flags, |
| 171 | const std::string& explicit_id, |
| 172 | std::string* error); |
[email protected] | 87c655e | 2011-07-01 21:42:00 | [diff] [blame] | 173 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 174 | // Valid schemes for web extent URLPatterns. |
| 175 | static const int kValidWebExtentSchemes; |
| 176 | |
[email protected] | f71f7e6 | 2010-12-07 03:45:33 | [diff] [blame] | 177 | // Valid schemes for host permission URLPatterns. |
| 178 | static const int kValidHostPermissionSchemes; |
| 179 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 180 | #if defined(OS_WIN) |
[email protected] | 9dcf8f1 | 2010-09-02 20:39:19 | [diff] [blame] | 181 | static const char kExtensionRegistryPath[]; |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 182 | #endif |
| 183 | |
[email protected] | e435d6b7 | 2009-07-25 03:15:58 | [diff] [blame] | 184 | // The mimetype used for extensions. |
| 185 | static const char kMimeType[]; |
| 186 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 187 | // Checks to see if the extension has a valid ID. |
| 188 | static bool IdIsValid(const std::string& id); |
| 189 | |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 190 | // See Type definition in Manifest. |
| 191 | Manifest::Type GetType() const; |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 192 | |
[email protected] | 07c00d99 | 2009-03-04 20:27:04 | [diff] [blame] | 193 | // Returns an absolute url to a resource inside of an extension. The |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 194 | // |extension_url| argument should be the url() from an Extension object. The |
| 195 | // |relative_path| can be untrusted user input. The returned URL will either |
| 196 | // be invalid() or a child of |extension_url|. |
| 197 | // NOTE: Static so that it can be used from multiple threads. |
| 198 | static GURL GetResourceURL(const GURL& extension_url, |
| 199 | const std::string& relative_path); |
[email protected] | cffd789 | 2010-08-26 17:43:28 | [diff] [blame] | 200 | GURL GetResourceURL(const std::string& relative_path) const { |
[email protected] | 3cfbd0e | 2009-03-18 21:26:24 | [diff] [blame] | 201 | return GetResourceURL(url(), relative_path); |
| 202 | } |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 203 | |
[email protected] | f59a805 | 2012-06-20 22:25:00 | [diff] [blame] | 204 | // Returns true if the resource matches a pattern in the pattern_set. |
| 205 | bool ResourceMatches(const URLPatternSet& pattern_set, |
| 206 | const std::string& resource) const; |
| 207 | |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 208 | // Returns an extension resource object. |relative_path| should be UTF8 |
| 209 | // encoded. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 210 | ExtensionResource GetResource(const std::string& relative_path) const; |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 211 | |
| 212 | // As above, but with |relative_path| following the file system's encoding. |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 213 | ExtensionResource GetResource(const base::FilePath& relative_path) const; |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 214 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 215 | // |input| is expected to be the text of an rsa public or private key. It |
| 216 | // tolerates the presence or absence of bracking header/footer like this: |
| 217 | // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY----- |
| 218 | // and may contain newlines. |
| 219 | static bool ParsePEMKeyBytes(const std::string& input, std::string* output); |
| 220 | |
| 221 | // Does a simple base64 encoding of |input| into |output|. |
| 222 | static bool ProducePEM(const std::string& input, std::string* output); |
| 223 | |
| 224 | // Expects base64 encoded |input| and formats into |output| including |
| 225 | // the appropriate header & footer. |
[email protected] | e0d0819 | 2011-03-29 19:02:50 | [diff] [blame] | 226 | static bool FormatPEMForFileOutput(const std::string& input, |
| 227 | std::string* output, |
| 228 | bool is_public); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 229 | |
[email protected] | a807bbe | 2010-04-14 10:51:19 | [diff] [blame] | 230 | // Returns the base extension url for a given |extension_id|. |
| 231 | static GURL GetBaseURLFromExtensionId(const std::string& extension_id); |
| 232 | |
[email protected] | be7e5cb | 2010-10-04 12:53:17 | [diff] [blame] | 233 | // Adds an extension to the scripting whitelist. Used for testing only. |
[email protected] | 10fb199 | 2010-10-08 09:00:17 | [diff] [blame] | 234 | static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); |
[email protected] | 2a521c5 | 2011-01-26 18:45:21 | [diff] [blame] | 235 | static const ScriptingWhitelist* GetScriptingWhitelist(); |
[email protected] | be7e5cb | 2010-10-04 12:53:17 | [diff] [blame] | 236 | |
[email protected] | 13c68b6 | 2013-05-17 11:29:05 | [diff] [blame] | 237 | // DEPRECATED: These methods have been moved to PermissionsData. |
| 238 | // TODO(rdevlin.cronin): remove these once all calls have been updated. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 239 | bool HasAPIPermission(APIPermission::ID permission) const; |
[email protected] | b5b26b7 | 2013-08-02 00:25:11 | [diff] [blame] | 240 | bool HasAPIPermission(const std::string& permission_name) const; |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 241 | scoped_refptr<const PermissionSet> GetActivePermissions() const; |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 242 | |
[email protected] | 5df6a5d | 2011-01-26 07:39:12 | [diff] [blame] | 243 | // Whether context menu should be shown for page and browser actions. |
| 244 | bool ShowConfigureContextMenus() const; |
| 245 | |
[email protected] | cca14717 | 2011-02-17 01:29:29 | [diff] [blame] | 246 | // Returns true if this extension or app includes areas within |origin|. |
| 247 | bool OverlapsWithOrigin(const GURL& origin) const; |
| 248 | |
[email protected] | 7e0f92b | 2012-11-09 03:51:04 | [diff] [blame] | 249 | // Returns true if the extension requires a valid ordinal for sorting, e.g., |
| 250 | // for displaying in a launcher or new tab page. |
| 251 | bool RequiresSortOrdinal() const; |
| 252 | |
| 253 | // Returns true if the extension should be displayed in the app launcher. |
| 254 | bool ShouldDisplayInAppLauncher() const; |
| 255 | |
| 256 | // Returns true if the extension should be displayed in the browser NTP. |
| 257 | bool ShouldDisplayInNewTabPage() const; |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 258 | |
[email protected] | e0b3de7 | 2012-05-01 01:21:34 | [diff] [blame] | 259 | // Returns true if the extension should be displayed in the extension |
| 260 | // settings page (i.e. chrome://extensions). |
| 261 | bool ShouldDisplayInExtensionSettings() const; |
| 262 | |
[email protected] | 624e63d0c | 2013-08-16 00:09:50 | [diff] [blame] | 263 | // Returns true if the extension should not be shown anywhere. This is |
| 264 | // mostly the same as the extension being a component extension, but also |
| 265 | // includes non-component apps that are hidden from the app launcher and ntp. |
| 266 | bool ShouldNotBeVisible() const; |
| 267 | |
[email protected] | d356c98 | 2012-12-12 19:32:55 | [diff] [blame] | 268 | // Get the manifest data associated with the key, or NULL if there is none. |
| 269 | // Can only be called after InitValue is finished. |
| 270 | ManifestData* GetManifestData(const std::string& key) const; |
| 271 | |
| 272 | // Sets |data| to be associated with the key. Takes ownership of |data|. |
| 273 | // Can only be called before InitValue is finished. Not thread-safe; |
| 274 | // all SetManifestData calls should be on only one thread. |
| 275 | void SetManifestData(const std::string& key, ManifestData* data); |
| 276 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 277 | // Accessors: |
| 278 | |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 279 | const base::FilePath& path() const { return path_; } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 280 | const GURL& url() const { return extension_url_; } |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 281 | Manifest::Location location() const; |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 282 | const std::string& id() const; |
[email protected] | 1f04ef4 | 2013-04-22 07:35:50 | [diff] [blame] | 283 | const base::Version* version() const { return version_.get(); } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 284 | const std::string VersionString() const; |
| 285 | const std::string& name() const { return name_; } |
[email protected] | 680eaa67 | 2013-08-27 10:25:08 | [diff] [blame] | 286 | const std::string& short_name() const { return short_name_; } |
[email protected] | 701d1e8 | 2012-05-14 05:34:19 | [diff] [blame] | 287 | const std::string& non_localized_name() const { return non_localized_name_; } |
[email protected] | 200423d | 2012-06-05 01:16:06 | [diff] [blame] | 288 | // 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] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 292 | const std::string& description() const { return description_; } |
[email protected] | a47c8a2 | 2011-11-17 18:40:31 | [diff] [blame] | 293 | int manifest_version() const { return manifest_version_; } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 294 | bool converted_from_user_script() const { |
| 295 | return converted_from_user_script_; |
| 296 | } |
[email protected] | 2cb5e30 | 2013-05-09 05:00:06 | [diff] [blame] | 297 | PermissionsData* permissions_data() { return permissions_data_.get(); } |
| 298 | const PermissionsData* permissions_data() const { |
| 299 | return permissions_data_.get(); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 300 | } |
[email protected] | 2cb5e30 | 2013-05-09 05:00:06 | [diff] [blame] | 301 | |
[email protected] | 23b3c0a | 2013-01-16 23:36:36 | [diff] [blame] | 302 | // Appends |new_warning[s]| to install_warnings_. |
| 303 | void AddInstallWarning(const InstallWarning& new_warning); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 304 | void AddInstallWarnings(const std::vector<InstallWarning>& new_warnings); |
| 305 | const std::vector<InstallWarning>& install_warnings() const { |
[email protected] | 8629c54 | 2012-04-20 03:40:03 | [diff] [blame] | 306 | return install_warnings_; |
| 307 | } |
[email protected] | 953620b | 2011-12-04 00:55:32 | [diff] [blame] | 308 | const extensions::Manifest* manifest() const { |
[email protected] | e9629d77 | 2012-08-06 19:44:46 | [diff] [blame] | 309 | return manifest_.get(); |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 310 | } |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 311 | bool wants_file_access() const { return wants_file_access_; } |
[email protected] | 334ec0a | 2013-03-24 01:36:16 | [diff] [blame] | 312 | // TODO(rdevlin.cronin): This is needed for ContentScriptsHandler, and should |
| 313 | // be moved out as part of crbug.com/159265. This should not be used anywhere |
| 314 | // else. |
| 315 | void set_wants_file_access(bool wants_file_access) { |
| 316 | wants_file_access_ = wants_file_access; |
| 317 | } |
[email protected] | 2af352b | 2011-07-22 08:21:23 | [diff] [blame] | 318 | int creation_flags() const { return creation_flags_; } |
| 319 | bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; } |
[email protected] | e805baf | 2011-07-26 18:23:05 | [diff] [blame] | 320 | bool from_bookmark() const { return (creation_flags_ & FROM_BOOKMARK) != 0; } |
[email protected] | e33bbc2 | 2012-08-27 22:05:46 | [diff] [blame] | 321 | bool was_installed_by_default() const { |
| 322 | return (creation_flags_ & WAS_INSTALLED_BY_DEFAULT) != 0; |
| 323 | } |
[email protected] | aa5a547 | 2013-10-04 03:41:04 | [diff] [blame] | 324 | bool requires_permissions_consent() const { |
| 325 | return (creation_flags_ & REQUIRE_PERMISSIONS_CONSENT) != 0; |
| 326 | } |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 327 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 328 | // App-related. |
[email protected] | 21c0104 | 2013-03-10 23:41:14 | [diff] [blame] | 329 | bool is_app() const; |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 330 | bool is_platform_app() const; |
| 331 | bool is_hosted_app() const; |
[email protected] | c4f459d | 2012-09-28 04:40:10 | [diff] [blame] | 332 | bool is_legacy_packaged_app() const; |
[email protected] | ff05a4b10 | 2012-12-19 00:12:06 | [diff] [blame] | 333 | bool is_extension() const; |
[email protected] | cdc7b1f4 | 2012-12-07 19:39:48 | [diff] [blame] | 334 | bool can_be_incognito_enabled() const; |
[email protected] | fc05749a | 2013-07-10 06:59:11 | [diff] [blame] | 335 | bool force_incognito_enabled() const; |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 336 | |
[email protected] | 636ee4328 | 2013-01-12 15:58:00 | [diff] [blame] | 337 | void AddWebExtentPattern(const URLPattern& pattern); |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 338 | const URLPatternSet& web_extent() const { return extent_; } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 339 | |
| 340 | // Theme-related. |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 341 | bool is_theme() const; |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 342 | |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 343 | private: |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 344 | friend class base::RefCountedThreadSafe<Extension>; |
| 345 | |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 346 | // Chooses the extension ID for an extension based on a variety of criteria. |
| 347 | // The chosen ID will be set in |manifest|. |
| 348 | static bool InitExtensionID(extensions::Manifest* manifest, |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 349 | const base::FilePath& path, |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 350 | const std::string& explicit_id, |
| 351 | int creation_flags, |
| 352 | string16* error); |
| 353 | |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 354 | Extension(const base::FilePath& path, |
| 355 | scoped_ptr<extensions::Manifest> manifest); |
[email protected] | d356c98 | 2012-12-12 19:32:55 | [diff] [blame] | 356 | virtual ~Extension(); |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 357 | |
| 358 | // Initialize the extension from a parsed manifest. |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 359 | // TODO(aa): Rename to just Init()? There's no Value here anymore. |
| 360 | // TODO(aa): It is really weird the way this class essentially contains a copy |
| 361 | // of the underlying DictionaryValue in its members. We should decide to |
| 362 | // either wrap the DictionaryValue and go with that only, or we should parse |
| 363 | // into strong types and discard the value. But doing both is bad. |
| 364 | bool InitFromValue(int flags, string16* error); |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 365 | |
[email protected] | 58f62cf | 2012-03-09 10:45:11 | [diff] [blame] | 366 | // The following are helpers for InitFromValue to load various features of the |
| 367 | // extension from the manifest. |
| 368 | |
[email protected] | 58f62cf | 2012-03-09 10:45:11 | [diff] [blame] | 369 | bool LoadRequiredFeatures(string16* error); |
| 370 | bool LoadName(string16* error); |
| 371 | bool LoadVersion(string16* error); |
| 372 | |
| 373 | bool LoadAppFeatures(string16* error); |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 374 | bool LoadExtent(const char* key, |
| 375 | URLPatternSet* extent, |
| 376 | const char* list_error, |
| 377 | const char* value_error, |
| 378 | string16* error); |
[email protected] | 10253da | 2012-03-09 04:06:42 | [diff] [blame] | 379 | |
[email protected] | 46559463 | 2013-02-15 19:50:28 | [diff] [blame] | 380 | bool LoadSharedFeatures(string16* error); |
[email protected] | 58f62cf | 2012-03-09 10:45:11 | [diff] [blame] | 381 | bool LoadDescription(string16* error); |
| 382 | bool LoadManifestVersion(string16* error); |
[email protected] | 680eaa67 | 2013-08-27 10:25:08 | [diff] [blame] | 383 | bool LoadShortName(string16* error); |
[email protected] | 6600800 | 2013-01-08 09:09:13 | [diff] [blame] | 384 | |
[email protected] | 488e650 | 2012-09-07 14:17:34 | [diff] [blame] | 385 | bool CheckMinimumChromeVersion(string16* error) const; |
[email protected] | 488e650 | 2012-09-07 14:17:34 | [diff] [blame] | 386 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 387 | // The extension's human-readable name. Name is used for display purpose. It |
| 388 | // might be wrapped with unicode bidi control characters so that it is |
| 389 | // displayed correctly in RTL context. |
| 390 | // NOTE: Name is UTF-8 and may contain non-ascii characters. |
| 391 | std::string name_; |
| 392 | |
[email protected] | 701d1e8 | 2012-05-14 05:34:19 | [diff] [blame] | 393 | // A non-localized version of the extension's name. This is useful for |
| 394 | // debug output. |
| 395 | std::string non_localized_name_; |
| 396 | |
[email protected] | 680eaa67 | 2013-08-27 10:25:08 | [diff] [blame] | 397 | // A short version of the extension's name. This can be used as an alternative |
| 398 | // to the name where there is insufficient space to display the full name. If |
| 399 | // an extension has not explicitly specified a short name, the value of this |
| 400 | // member variable will be the full name rather than an empty string. |
| 401 | std::string short_name_; |
| 402 | |
[email protected] | a47c8a2 | 2011-11-17 18:40:31 | [diff] [blame] | 403 | // The version of this extension's manifest. We increase the manifest |
| 404 | // version when making breaking changes to the extension system. |
| 405 | // Version 1 was the first manifest version (implied by a lack of a |
| 406 | // manifest_version attribute in the extension's manifest). We initialize |
| 407 | // this member variable to 0 to distinguish the "uninitialized" case from |
| 408 | // the case when we know the manifest version actually is 1. |
| 409 | int manifest_version_; |
| 410 | |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 411 | // The absolute path to the directory the extension is stored in. |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 412 | base::FilePath path_; |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 413 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 414 | // Defines the set of URLs in the extension's web content. |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 415 | URLPatternSet extent_; |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 416 | |
[email protected] | 2cb5e30 | 2013-05-09 05:00:06 | [diff] [blame] | 417 | scoped_ptr<PermissionsData> permissions_data_; |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 418 | |
[email protected] | 8629c54 | 2012-04-20 03:40:03 | [diff] [blame] | 419 | // Any warnings that occurred when trying to create/parse the extension. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 420 | std::vector<InstallWarning> install_warnings_; |
[email protected] | 8629c54 | 2012-04-20 03:40:03 | [diff] [blame] | 421 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 422 | // The base extension url for the extension. |
| 423 | GURL extension_url_; |
| 424 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 425 | // The extension's version. |
[email protected] | 1f04ef4 | 2013-04-22 07:35:50 | [diff] [blame] | 426 | scoped_ptr<base::Version> version_; |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 427 | |
| 428 | // An optional longer description of the extension. |
| 429 | std::string description_; |
| 430 | |
| 431 | // True if the extension was generated from a user script. (We show slightly |
| 432 | // different UI if so). |
| 433 | bool converted_from_user_script_; |
| 434 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 435 | // The public key used to sign the contents of the crx package. |
| 436 | std::string public_key_; |
| 437 | |
[email protected] | 58f62cf | 2012-03-09 10:45:11 | [diff] [blame] | 438 | // The manifest from which this extension was created. |
[email protected] | e9629d77 | 2012-08-06 19:44:46 | [diff] [blame] | 439 | scoped_ptr<Manifest> manifest_; |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 440 | |
[email protected] | d356c98 | 2012-12-12 19:32:55 | [diff] [blame] | 441 | // Stored parsed manifest data. |
| 442 | ManifestDataMap manifest_data_; |
| 443 | |
| 444 | // Set to true at the end of InitValue when initialization is finished. |
| 445 | bool finished_parsing_manifest_; |
| 446 | |
[email protected] | 7eeab9ec | 2013-01-15 04:08:33 | [diff] [blame] | 447 | // Ensures that any call to GetManifestData() prior to finishing |
| 448 | // initialization happens from the same thread (this can happen when certain |
| 449 | // parts of the initialization process need information from previous parts). |
| 450 | base::ThreadChecker thread_checker_; |
| 451 | |
[email protected] | 7e0f92b | 2012-11-09 03:51:04 | [diff] [blame] | 452 | // Should this app be shown in the app launcher. |
[email protected] | ed1a204f | 2012-09-22 00:28:44 | [diff] [blame] | 453 | bool display_in_launcher_; |
| 454 | |
[email protected] | 7e0f92b | 2012-11-09 03:51:04 | [diff] [blame] | 455 | // Should this app be shown in the browser New Tab Page. |
| 456 | bool display_in_new_tab_page_; |
| 457 | |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 458 | // Whether the extension has host permissions or user script patterns that |
| 459 | // imply access to file:/// scheme URLs (the user may not have actually |
| 460 | // granted it that access). |
| 461 | bool wants_file_access_; |
| 462 | |
[email protected] | 2af352b | 2011-07-22 08:21:23 | [diff] [blame] | 463 | // The flags that were passed to InitFromValue. |
| 464 | int creation_flags_; |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 465 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 466 | DISALLOW_COPY_AND_ASSIGN(Extension); |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 467 | }; |
| 468 | |
[email protected] | bc151cf9 | 2013-02-12 04:57:26 | [diff] [blame] | 469 | typedef std::vector<scoped_refptr<const Extension> > ExtensionList; |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 470 | typedef std::set<std::string> ExtensionIdSet; |
[email protected] | 82590cb | 2012-09-28 04:14:08 | [diff] [blame] | 471 | typedef std::vector<std::string> ExtensionIdList; |
[email protected] | b1748b1d8 | 2009-11-30 20:32:56 | [diff] [blame] | 472 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 473 | // Handy struct to pass core extension info around. |
| 474 | struct ExtensionInfo { |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 475 | ExtensionInfo(const base::DictionaryValue* manifest, |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 476 | const std::string& id, |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 477 | const base::FilePath& path, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 478 | Manifest::Location location); |
[email protected] | 3bb8499 | 2010-08-26 17:23:46 | [diff] [blame] | 479 | ~ExtensionInfo(); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 480 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 481 | scoped_ptr<base::DictionaryValue> extension_manifest; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 482 | std::string extension_id; |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 483 | base::FilePath extension_path; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 484 | Manifest::Location extension_location; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 485 | |
| 486 | private: |
| 487 | DISALLOW_COPY_AND_ASSIGN(ExtensionInfo); |
| 488 | }; |
| 489 | |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 490 | struct InstalledExtensionInfo { |
| 491 | // The extension being installed - this should always be non-NULL. |
| 492 | const Extension* extension; |
| 493 | |
| 494 | // True if the extension is being updated; false if it is being installed. |
| 495 | bool is_update; |
| 496 | |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 497 | // The name of the extension prior to this update. Will be empty if |
| 498 | // |is_update| is false. |
| 499 | std::string old_name; |
| 500 | |
| 501 | InstalledExtensionInfo(const Extension* extension, |
| 502 | bool is_update, |
| 503 | const std::string& old_name); |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 504 | }; |
| 505 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 506 | struct UnloadedExtensionInfo { |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 507 | extension_misc::UnloadedExtensionReason reason; |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 508 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 509 | // The extension being unloaded - this should always be non-NULL. |
| 510 | const Extension* extension; |
| 511 | |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 512 | UnloadedExtensionInfo( |
| 513 | const Extension* extension, |
| 514 | extension_misc::UnloadedExtensionReason reason); |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 515 | }; |
| 516 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 517 | // The details sent for EXTENSION_PERMISSIONS_UPDATED notifications. |
| 518 | struct UpdatedExtensionPermissionsInfo { |
| 519 | enum Reason { |
[email protected] | f553247 | 2012-02-23 13:00:55 | [diff] [blame] | 520 | ADDED, // The permissions were added to the extension. |
| 521 | REMOVED, // The permissions were removed from the extension. |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 522 | }; |
| 523 | |
| 524 | Reason reason; |
| 525 | |
| 526 | // The extension who's permissions have changed. |
| 527 | const Extension* extension; |
| 528 | |
| 529 | // The permissions that have changed. For Reason::ADDED, this would contain |
| 530 | // only the permissions that have added, and for Reason::REMOVED, this would |
| 531 | // only contain the removed permissions. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 532 | const PermissionSet* permissions; |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 533 | |
| 534 | UpdatedExtensionPermissionsInfo( |
| 535 | const Extension* extension, |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 536 | const PermissionSet* permissions, |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 537 | Reason reason); |
| 538 | }; |
| 539 | |
[email protected] | 488e650 | 2012-09-07 14:17:34 | [diff] [blame] | 540 | } // namespace extensions |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 541 | |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 542 | #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |