[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] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 5 | #ifndef EXTENSIONS_COMMON_EXTENSION_H_ |
| 6 | #define EXTENSIONS_COMMON_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] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 23 | #include "extensions/common/extension_resource.h" |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 24 | #include "extensions/common/install_warning.h" |
[email protected] | d42c1115 | 2013-08-22 19:36:32 | [diff] [blame] | 25 | #include "extensions/common/manifest.h" |
[email protected] | e9f541a | 2012-11-19 21:52:31 | [diff] [blame] | 26 | #include "extensions/common/url_pattern_set.h" |
[email protected] | f553247 | 2012-02-23 13:00:55 | [diff] [blame] | 27 | #include "ui/base/accelerators/accelerator.h" |
[email protected] | 5f5ef80 | 2013-07-04 16:11:13 | [diff] [blame] | 28 | #include "url/gurl.h" |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 29 | |
thestig | 52a87b3b | 2014-10-23 22:02:38 | [diff] [blame] | 30 | #if !defined(ENABLE_EXTENSIONS) |
| 31 | #error "Extensions must be enabled" |
| 32 | #endif |
| 33 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 34 | namespace base { |
| 35 | class DictionaryValue; |
[email protected] | 1f04ef4 | 2013-04-22 07:35:50 | [diff] [blame] | 36 | class Version; |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 37 | } |
| 38 | |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 39 | namespace extensions { |
[email protected] | bebe1d0 | 2012-08-02 20:17:09 | [diff] [blame] | 40 | class PermissionSet; |
[email protected] | d695bb1 | 2014-06-05 16:16:30 | [diff] [blame] | 41 | class PermissionsData; |
| 42 | class PermissionsParser; |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 43 | |
[email protected] | 53d5f0f46 | 2014-03-07 09:15:20 | [diff] [blame] | 44 | // Uniquely identifies an Extension, using 32 characters from the alphabet |
| 45 | // 'a'-'p'. An empty string represents "no extension". |
| 46 | // |
| 47 | // Note: If this gets used heavily in files that don't otherwise need to include |
| 48 | // extension.h, we should pull it into a dedicated header. |
| 49 | typedef std::string ExtensionId; |
| 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] | d356c98 | 2012-12-12 19:32:55 | [diff] [blame] | 59 | typedef std::map<const std::string, linked_ptr<ManifestData> > |
| 60 | ManifestDataMap; |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 61 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 62 | enum State { |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 63 | DISABLED = 0, |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 64 | ENABLED, |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 65 | // An external extension that the user uninstalled. We should not reinstall |
| 66 | // such extensions on startup. |
| 67 | EXTERNAL_EXTENSION_UNINSTALLED, |
[email protected] | 9ae7396 | 2014-08-14 16:53:41 | [diff] [blame] | 68 | // DEPRECATED: Special state for component extensions. |
| 69 | // Maintained as a placeholder since states may be stored to disk. |
| 70 | ENABLED_COMPONENT_DEPRECATED, |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 71 | // Add new states here as this enum is stored in prefs. |
[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] | ef5a999 | 2014-07-25 21:45:24 | [diff] [blame] | 84 | // Reasons an extension may be disabled. These are used in histograms, so do |
| 85 | // not remove/reorder entries - only add at the end just before |
| 86 | // DISABLE_REASON_LAST (and update the shift value for it). Also remember to |
| 87 | // update the enum listing in tools/metrics/histograms.xml. |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 88 | enum DisableReason { |
[email protected] | eb5e4f9 | 2012-08-15 23:33:28 | [diff] [blame] | 89 | DISABLE_NONE = 0, |
| 90 | DISABLE_USER_ACTION = 1 << 0, |
| 91 | DISABLE_PERMISSIONS_INCREASE = 1 << 1, |
| 92 | DISABLE_RELOAD = 1 << 2, |
[email protected] | 215a7be | 2012-10-22 19:53:42 | [diff] [blame] | 93 | DISABLE_UNSUPPORTED_REQUIREMENT = 1 << 3, |
| 94 | DISABLE_SIDELOAD_WIPEOUT = 1 << 4, |
[email protected] | f56c65ea6 | 2012-12-10 22:57:21 | [diff] [blame] | 95 | DISABLE_UNKNOWN_FROM_SYNC = 1 << 5, |
[email protected] | 367d077d | 2014-06-23 20:38:17 | [diff] [blame] | 96 | // DISABLE_PERMISSIONS_CONSENT = 1 << 6, // Deprecated. |
| 97 | // DISABLE_KNOWN_DISABLED = 1 << 7, // Deprecated. |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 98 | DISABLE_NOT_VERIFIED = 1 << 8, // Disabled because we could not verify |
| 99 | // the install. |
[email protected] | e1e2da3 | 2014-05-05 13:11:37 | [diff] [blame] | 100 | DISABLE_GREYLIST = 1 << 9, |
| 101 | DISABLE_CORRUPTED = 1 << 10, |
[email protected] | ef5a999 | 2014-07-25 21:45:24 | [diff] [blame] | 102 | DISABLE_REMOTE_INSTALL = 1 << 11, |
[email protected] | 8f959f52 | 2014-08-06 06:26:28 | [diff] [blame] | 103 | DISABLE_INACTIVE_EPHEMERAL_APP = 1 << 12, // Cached ephemeral apps are |
| 104 | // disabled to prevent activity. |
binjin | 47947f84 | 2014-11-18 12:10:24 | [diff] [blame] | 105 | DISABLE_EXTERNAL_EXTENSION = 1 << 13, // External extensions might be |
| 106 | // disabled for user prompting. |
binjin | 8e3d018 | 2014-12-04 16:44:28 | [diff] [blame] | 107 | DISABLE_UPDATE_REQUIRED_BY_POLICY = 1 << 14, // Doesn't meet minimum |
| 108 | // version requirement. |
| 109 | DISABLE_REASON_LAST = 1 << 15, // This should always be the last value |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 110 | }; |
| 111 | |
[email protected] | d356c98 | 2012-12-12 19:32:55 | [diff] [blame] | 112 | // A base class for parsed manifest data that APIs want to store on |
| 113 | // the extension. Related to base::SupportsUserData, but with an immutable |
| 114 | // thread-safe interface to match Extension. |
| 115 | struct ManifestData { |
| 116 | virtual ~ManifestData() {} |
| 117 | }; |
| 118 | |
[email protected] | f9c5d39 | 2014-05-13 05:34:18 | [diff] [blame] | 119 | // Do not change the order of entries or remove entries in this list |
| 120 | // as this is used in UMA_HISTOGRAM_ENUMERATIONs about extensions. |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 121 | enum InitFromValueFlags { |
| 122 | NO_FLAGS = 0, |
| 123 | |
| 124 | // Usually, the id of an extension is generated by the "key" property of |
| 125 | // its manifest, but if |REQUIRE_KEY| is not set, a temporary ID will be |
| 126 | // generated based on the path. |
| 127 | REQUIRE_KEY = 1 << 0, |
| 128 | |
[email protected] | 3f53dfe | 2011-11-30 01:18:29 | [diff] [blame] | 129 | // Requires the extension to have an up-to-date manifest version. |
| 130 | // Typically, we'll support multiple manifest versions during a version |
[email protected] | 26367b6 | 2012-10-04 23:03:32 | [diff] [blame] | 131 | // transition. This flag signals that we want to require the most modern |
[email protected] | 3f53dfe | 2011-11-30 01:18:29 | [diff] [blame] | 132 | // manifest version that Chrome understands. |
| 133 | REQUIRE_MODERN_MANIFEST_VERSION = 1 << 1, |
| 134 | |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 135 | // |ALLOW_FILE_ACCESS| indicates that the user is allowing this extension |
| 136 | // to have file access. If it's not present, then permissions and content |
| 137 | // scripts that match file:/// URLs will be filtered out. |
[email protected] | ed3b9b1 | 2012-05-31 18:37:51 | [diff] [blame] | 138 | ALLOW_FILE_ACCESS = 1 << 2, |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 139 | |
| 140 | // |FROM_WEBSTORE| indicates that the extension was installed from the |
| 141 | // Chrome Web Store. |
[email protected] | ed3b9b1 | 2012-05-31 18:37:51 | [diff] [blame] | 142 | FROM_WEBSTORE = 1 << 3, |
[email protected] | e805baf | 2011-07-26 18:23:05 | [diff] [blame] | 143 | |
[email protected] | 4660146 | 2014-02-04 11:08:50 | [diff] [blame] | 144 | // |FROM_BOOKMARK| indicates the extension is a bookmark app which has been |
| 145 | // generated from a web page. Bookmark apps have no permissions or extent |
| 146 | // and launch the web page they are created from when run. |
[email protected] | ed3b9b1 | 2012-05-31 18:37:51 | [diff] [blame] | 147 | FROM_BOOKMARK = 1 << 4, |
[email protected] | 3d41d43 | 2012-04-20 20:47:58 | [diff] [blame] | 148 | |
| 149 | // |FOLLOW_SYMLINKS_ANYWHERE| means that resources can be symlinks to |
| 150 | // anywhere in the filesystem, rather than being restricted to the |
| 151 | // extension directory. |
[email protected] | ed3b9b1 | 2012-05-31 18:37:51 | [diff] [blame] | 152 | FOLLOW_SYMLINKS_ANYWHERE = 1 << 5, |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 153 | |
| 154 | // |ERROR_ON_PRIVATE_KEY| means that private keys inside an |
| 155 | // extension should be errors rather than warnings. |
| 156 | ERROR_ON_PRIVATE_KEY = 1 << 6, |
[email protected] | e33bbc2 | 2012-08-27 22:05:46 | [diff] [blame] | 157 | |
| 158 | // |WAS_INSTALLED_BY_DEFAULT| installed by default when the profile was |
| 159 | // created. |
| 160 | WAS_INSTALLED_BY_DEFAULT = 1 << 7, |
[email protected] | aa5a547 | 2013-10-04 03:41:04 | [diff] [blame] | 161 | |
[email protected] | 1b563df | 2013-10-30 16:49:36 | [diff] [blame] | 162 | // Unused - was part of an abandoned experiment. |
[email protected] | aa5a547 | 2013-10-04 03:41:04 | [diff] [blame] | 163 | REQUIRE_PERMISSIONS_CONSENT = 1 << 8, |
[email protected] | ce35418b | 2013-11-25 01:22:33 | [diff] [blame] | 164 | |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 165 | // Unused - this flag has been moved to ExtensionPrefs. |
[email protected] | ce35418b | 2013-11-25 01:22:33 | [diff] [blame] | 166 | IS_EPHEMERAL = 1 << 9, |
[email protected] | acc3c7c2 | 2014-03-19 06:23:39 | [diff] [blame] | 167 | |
| 168 | // |WAS_INSTALLED_BY_OEM| installed by an OEM (e.g on Chrome OS) and should |
| 169 | // be placed in a special OEM folder in the App Launcher. Note: OEM apps are |
| 170 | // also installed by Default (i.e. WAS_INSTALLED_BY_DEFAULT is also true). |
| 171 | WAS_INSTALLED_BY_OEM = 1 << 10, |
[email protected] | f9c5d39 | 2014-05-13 05:34:18 | [diff] [blame] | 172 | |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 173 | // |WAS_INSTALLED_BY_CUSTODIAN| means this extension was installed by the |
| 174 | // custodian of a supervised user. |
| 175 | WAS_INSTALLED_BY_CUSTODIAN = 1 << 11, |
| 176 | |
[email protected] | 2b6a580 | 2014-08-16 07:58:08 | [diff] [blame] | 177 | // |MAY_BE_UNTRUSTED| indicates that this extension came from a potentially |
| 178 | // unsafe source (e.g., sideloaded from a local CRX file via the Windows |
| 179 | // registry). Such extensions may be subjected to additional constraints |
| 180 | // before they are fully installed and enabled. |
| 181 | MAY_BE_UNTRUSTED = 1 << 12, |
| 182 | |
[email protected] | f9c5d39 | 2014-05-13 05:34:18 | [diff] [blame] | 183 | // When adding new flags, make sure to update kInitFromValueFlagBits. |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 184 | }; |
| 185 | |
[email protected] | f9c5d39 | 2014-05-13 05:34:18 | [diff] [blame] | 186 | // This is the highest bit index of the flags defined above. |
| 187 | static const int kInitFromValueFlagBits; |
| 188 | |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 189 | static scoped_refptr<Extension> Create(const base::FilePath& path, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 190 | Manifest::Location location, |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 191 | const base::DictionaryValue& value, |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 192 | int flags, |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 193 | std::string* error); |
| 194 | |
[email protected] | 87c655e | 2011-07-01 21:42:00 | [diff] [blame] | 195 | // 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] | 196 | // an explicit id. Most consumers should just use the other Create() method. |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 197 | static scoped_refptr<Extension> Create(const base::FilePath& path, |
[email protected] | 2cb5e30 | 2013-05-09 05:00:06 | [diff] [blame] | 198 | Manifest::Location location, |
| 199 | const base::DictionaryValue& value, |
| 200 | int flags, |
[email protected] | 53d5f0f46 | 2014-03-07 09:15:20 | [diff] [blame] | 201 | const ExtensionId& explicit_id, |
[email protected] | 2cb5e30 | 2013-05-09 05:00:06 | [diff] [blame] | 202 | std::string* error); |
[email protected] | 87c655e | 2011-07-01 21:42:00 | [diff] [blame] | 203 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 204 | // Valid schemes for web extent URLPatterns. |
| 205 | static const int kValidWebExtentSchemes; |
| 206 | |
dominickn | 0bdf6c73 | 2015-08-25 06:13:46 | [diff] [blame] | 207 | // Valid schemes for bookmark app installs. |
| 208 | static const int kValidBookmarkAppSchemes; |
| 209 | |
[email protected] | f71f7e6 | 2010-12-07 03:45:33 | [diff] [blame] | 210 | // Valid schemes for host permission URLPatterns. |
| 211 | static const int kValidHostPermissionSchemes; |
| 212 | |
[email protected] | e435d6b7 | 2009-07-25 03:15:58 | [diff] [blame] | 213 | // The mimetype used for extensions. |
| 214 | static const char kMimeType[]; |
| 215 | |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 216 | // See Type definition in Manifest. |
| 217 | Manifest::Type GetType() const; |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 218 | |
[email protected] | 07c00d99 | 2009-03-04 20:27:04 | [diff] [blame] | 219 | // Returns an absolute url to a resource inside of an extension. The |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 220 | // |extension_url| argument should be the url() from an Extension object. The |
| 221 | // |relative_path| can be untrusted user input. The returned URL will either |
| 222 | // be invalid() or a child of |extension_url|. |
| 223 | // NOTE: Static so that it can be used from multiple threads. |
| 224 | static GURL GetResourceURL(const GURL& extension_url, |
| 225 | const std::string& relative_path); |
[email protected] | cffd789 | 2010-08-26 17:43:28 | [diff] [blame] | 226 | GURL GetResourceURL(const std::string& relative_path) const { |
[email protected] | 3cfbd0e | 2009-03-18 21:26:24 | [diff] [blame] | 227 | return GetResourceURL(url(), relative_path); |
| 228 | } |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 229 | |
[email protected] | f59a805 | 2012-06-20 22:25:00 | [diff] [blame] | 230 | // Returns true if the resource matches a pattern in the pattern_set. |
| 231 | bool ResourceMatches(const URLPatternSet& pattern_set, |
| 232 | const std::string& resource) const; |
| 233 | |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 234 | // Returns an extension resource object. |relative_path| should be UTF8 |
| 235 | // encoded. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 236 | ExtensionResource GetResource(const std::string& relative_path) const; |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 237 | |
| 238 | // As above, but with |relative_path| following the file system's encoding. |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 239 | ExtensionResource GetResource(const base::FilePath& relative_path) const; |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 240 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 241 | // |input| is expected to be the text of an rsa public or private key. It |
| 242 | // tolerates the presence or absence of bracking header/footer like this: |
| 243 | // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY----- |
| 244 | // and may contain newlines. |
| 245 | static bool ParsePEMKeyBytes(const std::string& input, std::string* output); |
| 246 | |
| 247 | // Does a simple base64 encoding of |input| into |output|. |
| 248 | static bool ProducePEM(const std::string& input, std::string* output); |
| 249 | |
| 250 | // Expects base64 encoded |input| and formats into |output| including |
| 251 | // the appropriate header & footer. |
[email protected] | e0d0819 | 2011-03-29 19:02:50 | [diff] [blame] | 252 | static bool FormatPEMForFileOutput(const std::string& input, |
| 253 | std::string* output, |
| 254 | bool is_public); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 255 | |
[email protected] | a807bbe | 2010-04-14 10:51:19 | [diff] [blame] | 256 | // Returns the base extension url for a given |extension_id|. |
[email protected] | 53d5f0f46 | 2014-03-07 09:15:20 | [diff] [blame] | 257 | static GURL GetBaseURLFromExtensionId(const ExtensionId& extension_id); |
[email protected] | a807bbe | 2010-04-14 10:51:19 | [diff] [blame] | 258 | |
[email protected] | 5df6a5d | 2011-01-26 07:39:12 | [diff] [blame] | 259 | // Whether context menu should be shown for page and browser actions. |
| 260 | bool ShowConfigureContextMenus() const; |
| 261 | |
[email protected] | cca14717 | 2011-02-17 01:29:29 | [diff] [blame] | 262 | // Returns true if this extension or app includes areas within |origin|. |
| 263 | bool OverlapsWithOrigin(const GURL& origin) const; |
| 264 | |
[email protected] | 7e0f92b | 2012-11-09 03:51:04 | [diff] [blame] | 265 | // Returns true if the extension requires a valid ordinal for sorting, e.g., |
| 266 | // for displaying in a launcher or new tab page. |
| 267 | bool RequiresSortOrdinal() const; |
| 268 | |
| 269 | // Returns true if the extension should be displayed in the app launcher. |
| 270 | bool ShouldDisplayInAppLauncher() const; |
| 271 | |
| 272 | // Returns true if the extension should be displayed in the browser NTP. |
| 273 | bool ShouldDisplayInNewTabPage() const; |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 274 | |
[email protected] | e0b3de7 | 2012-05-01 01:21:34 | [diff] [blame] | 275 | // Returns true if the extension should be displayed in the extension |
| 276 | // settings page (i.e. chrome://extensions). |
| 277 | bool ShouldDisplayInExtensionSettings() const; |
| 278 | |
[email protected] | 624e63d0c | 2013-08-16 00:09:50 | [diff] [blame] | 279 | // Returns true if the extension should not be shown anywhere. This is |
| 280 | // mostly the same as the extension being a component extension, but also |
| 281 | // includes non-component apps that are hidden from the app launcher and ntp. |
| 282 | bool ShouldNotBeVisible() const; |
| 283 | |
[email protected] | d356c98 | 2012-12-12 19:32:55 | [diff] [blame] | 284 | // Get the manifest data associated with the key, or NULL if there is none. |
| 285 | // Can only be called after InitValue is finished. |
| 286 | ManifestData* GetManifestData(const std::string& key) const; |
| 287 | |
| 288 | // Sets |data| to be associated with the key. Takes ownership of |data|. |
| 289 | // Can only be called before InitValue is finished. Not thread-safe; |
| 290 | // all SetManifestData calls should be on only one thread. |
| 291 | void SetManifestData(const std::string& key, ManifestData* data); |
| 292 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 293 | // Accessors: |
| 294 | |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 295 | const base::FilePath& path() const { return path_; } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 296 | const GURL& url() const { return extension_url_; } |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 297 | Manifest::Location location() const; |
[email protected] | 53d5f0f46 | 2014-03-07 09:15:20 | [diff] [blame] | 298 | const ExtensionId& id() const; |
[email protected] | 1f04ef4 | 2013-04-22 07:35:50 | [diff] [blame] | 299 | const base::Version* version() const { return version_.get(); } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 300 | const std::string VersionString() const; |
elijahtaylor | 89b02d7 | 2014-12-05 00:42:20 | [diff] [blame] | 301 | const std::string GetVersionForDisplay() const; |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 302 | const std::string& name() const { return name_; } |
[email protected] | 680eaa67 | 2013-08-27 10:25:08 | [diff] [blame] | 303 | const std::string& short_name() const { return short_name_; } |
[email protected] | 701d1e8 | 2012-05-14 05:34:19 | [diff] [blame] | 304 | const std::string& non_localized_name() const { return non_localized_name_; } |
[email protected] | 200423d | 2012-06-05 01:16:06 | [diff] [blame] | 305 | // Base64-encoded version of the key used to sign this extension. |
| 306 | // In pseudocode, returns |
| 307 | // base::Base64Encode(RSAPrivateKey(pem_file).ExportPublicKey()). |
| 308 | const std::string& public_key() const { return public_key_; } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 309 | const std::string& description() const { return description_; } |
[email protected] | a47c8a2 | 2011-11-17 18:40:31 | [diff] [blame] | 310 | int manifest_version() const { return manifest_version_; } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 311 | bool converted_from_user_script() const { |
| 312 | return converted_from_user_script_; |
| 313 | } |
[email protected] | d695bb1 | 2014-06-05 16:16:30 | [diff] [blame] | 314 | PermissionsParser* permissions_parser() { return permissions_parser_.get(); } |
| 315 | const PermissionsParser* permissions_parser() const { |
| 316 | return permissions_parser_.get(); |
| 317 | } |
| 318 | |
[email protected] | 2cb5e30 | 2013-05-09 05:00:06 | [diff] [blame] | 319 | const PermissionsData* permissions_data() const { |
| 320 | return permissions_data_.get(); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 321 | } |
[email protected] | 2cb5e30 | 2013-05-09 05:00:06 | [diff] [blame] | 322 | |
[email protected] | 23b3c0a | 2013-01-16 23:36:36 | [diff] [blame] | 323 | // Appends |new_warning[s]| to install_warnings_. |
| 324 | void AddInstallWarning(const InstallWarning& new_warning); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 325 | void AddInstallWarnings(const std::vector<InstallWarning>& new_warnings); |
| 326 | const std::vector<InstallWarning>& install_warnings() const { |
[email protected] | 8629c54 | 2012-04-20 03:40:03 | [diff] [blame] | 327 | return install_warnings_; |
| 328 | } |
[email protected] | 953620b | 2011-12-04 00:55:32 | [diff] [blame] | 329 | const extensions::Manifest* manifest() const { |
[email protected] | e9629d77 | 2012-08-06 19:44:46 | [diff] [blame] | 330 | return manifest_.get(); |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 331 | } |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 332 | bool wants_file_access() const { return wants_file_access_; } |
[email protected] | 334ec0a | 2013-03-24 01:36:16 | [diff] [blame] | 333 | // TODO(rdevlin.cronin): This is needed for ContentScriptsHandler, and should |
| 334 | // be moved out as part of crbug.com/159265. This should not be used anywhere |
| 335 | // else. |
| 336 | void set_wants_file_access(bool wants_file_access) { |
| 337 | wants_file_access_ = wants_file_access; |
| 338 | } |
[email protected] | 2af352b | 2011-07-22 08:21:23 | [diff] [blame] | 339 | int creation_flags() const { return creation_flags_; } |
| 340 | bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; } |
[email protected] | e805baf | 2011-07-26 18:23:05 | [diff] [blame] | 341 | bool from_bookmark() const { return (creation_flags_ & FROM_BOOKMARK) != 0; } |
proberge | 83469713 | 2015-10-21 21:04:49 | [diff] [blame^] | 342 | bool may_be_untrusted() const { |
| 343 | return (creation_flags_ & MAY_BE_UNTRUSTED) != 0; |
| 344 | } |
[email protected] | e33bbc2 | 2012-08-27 22:05:46 | [diff] [blame] | 345 | bool was_installed_by_default() const { |
| 346 | return (creation_flags_ & WAS_INSTALLED_BY_DEFAULT) != 0; |
| 347 | } |
[email protected] | acc3c7c2 | 2014-03-19 06:23:39 | [diff] [blame] | 348 | bool was_installed_by_oem() const { |
| 349 | return (creation_flags_ & WAS_INSTALLED_BY_OEM) != 0; |
| 350 | } |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 351 | bool was_installed_by_custodian() const { |
| 352 | return (creation_flags_ & WAS_INSTALLED_BY_CUSTODIAN) != 0; |
| 353 | } |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 354 | |
[email protected] | b86960e | 2014-07-18 05:35:09 | [diff] [blame] | 355 | // Type-related queries. |
[email protected] | 21c0104 | 2013-03-10 23:41:14 | [diff] [blame] | 356 | bool is_app() const; |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 357 | bool is_platform_app() const; |
| 358 | bool is_hosted_app() const; |
[email protected] | c4f459d | 2012-09-28 04:40:10 | [diff] [blame] | 359 | bool is_legacy_packaged_app() const; |
[email protected] | ff05a4b10 | 2012-12-19 00:12:06 | [diff] [blame] | 360 | bool is_extension() const; |
[email protected] | b86960e | 2014-07-18 05:35:09 | [diff] [blame] | 361 | bool is_shared_module() const; |
| 362 | bool is_theme() const; |
| 363 | |
[email protected] | 636ee4328 | 2013-01-12 15:58:00 | [diff] [blame] | 364 | void AddWebExtentPattern(const URLPattern& pattern); |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 365 | const URLPatternSet& web_extent() const { return extent_; } |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 366 | |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 367 | private: |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 368 | friend class base::RefCountedThreadSafe<Extension>; |
| 369 | |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 370 | // Chooses the extension ID for an extension based on a variety of criteria. |
| 371 | // The chosen ID will be set in |manifest|. |
| 372 | static bool InitExtensionID(extensions::Manifest* manifest, |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 373 | const base::FilePath& path, |
[email protected] | 53d5f0f46 | 2014-03-07 09:15:20 | [diff] [blame] | 374 | const ExtensionId& explicit_id, |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 375 | int creation_flags, |
[email protected] | 0d163dc | 2013-12-20 23:48:36 | [diff] [blame] | 376 | base::string16* error); |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 377 | |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 378 | Extension(const base::FilePath& path, |
| 379 | scoped_ptr<extensions::Manifest> manifest); |
[email protected] | d356c98 | 2012-12-12 19:32:55 | [diff] [blame] | 380 | virtual ~Extension(); |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 381 | |
| 382 | // Initialize the extension from a parsed manifest. |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 383 | // TODO(aa): Rename to just Init()? There's no Value here anymore. |
| 384 | // TODO(aa): It is really weird the way this class essentially contains a copy |
| 385 | // of the underlying DictionaryValue in its members. We should decide to |
| 386 | // either wrap the DictionaryValue and go with that only, or we should parse |
| 387 | // into strong types and discard the value. But doing both is bad. |
[email protected] | 0d163dc | 2013-12-20 23:48:36 | [diff] [blame] | 388 | bool InitFromValue(int flags, base::string16* error); |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 389 | |
[email protected] | 58f62cf | 2012-03-09 10:45:11 | [diff] [blame] | 390 | // The following are helpers for InitFromValue to load various features of the |
| 391 | // extension from the manifest. |
| 392 | |
[email protected] | 0d163dc | 2013-12-20 23:48:36 | [diff] [blame] | 393 | bool LoadRequiredFeatures(base::string16* error); |
| 394 | bool LoadName(base::string16* error); |
| 395 | bool LoadVersion(base::string16* error); |
[email protected] | 58f62cf | 2012-03-09 10:45:11 | [diff] [blame] | 396 | |
[email protected] | 0d163dc | 2013-12-20 23:48:36 | [diff] [blame] | 397 | bool LoadAppFeatures(base::string16* error); |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 398 | bool LoadExtent(const char* key, |
| 399 | URLPatternSet* extent, |
| 400 | const char* list_error, |
| 401 | const char* value_error, |
[email protected] | 0d163dc | 2013-12-20 23:48:36 | [diff] [blame] | 402 | base::string16* error); |
[email protected] | 10253da | 2012-03-09 04:06:42 | [diff] [blame] | 403 | |
[email protected] | 0d163dc | 2013-12-20 23:48:36 | [diff] [blame] | 404 | bool LoadSharedFeatures(base::string16* error); |
| 405 | bool LoadDescription(base::string16* error); |
| 406 | bool LoadManifestVersion(base::string16* error); |
| 407 | bool LoadShortName(base::string16* error); |
[email protected] | 6600800 | 2013-01-08 09:09:13 | [diff] [blame] | 408 | |
[email protected] | 0d163dc | 2013-12-20 23:48:36 | [diff] [blame] | 409 | bool CheckMinimumChromeVersion(base::string16* error) const; |
[email protected] | 488e650 | 2012-09-07 14:17:34 | [diff] [blame] | 410 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 411 | // The extension's human-readable name. Name is used for display purpose. It |
| 412 | // might be wrapped with unicode bidi control characters so that it is |
| 413 | // displayed correctly in RTL context. |
| 414 | // NOTE: Name is UTF-8 and may contain non-ascii characters. |
| 415 | std::string name_; |
| 416 | |
[email protected] | 701d1e8 | 2012-05-14 05:34:19 | [diff] [blame] | 417 | // A non-localized version of the extension's name. This is useful for |
| 418 | // debug output. |
| 419 | std::string non_localized_name_; |
| 420 | |
[email protected] | 680eaa67 | 2013-08-27 10:25:08 | [diff] [blame] | 421 | // A short version of the extension's name. This can be used as an alternative |
| 422 | // to the name where there is insufficient space to display the full name. If |
| 423 | // an extension has not explicitly specified a short name, the value of this |
| 424 | // member variable will be the full name rather than an empty string. |
| 425 | std::string short_name_; |
| 426 | |
[email protected] | a47c8a2 | 2011-11-17 18:40:31 | [diff] [blame] | 427 | // The version of this extension's manifest. We increase the manifest |
| 428 | // version when making breaking changes to the extension system. |
| 429 | // Version 1 was the first manifest version (implied by a lack of a |
| 430 | // manifest_version attribute in the extension's manifest). We initialize |
| 431 | // this member variable to 0 to distinguish the "uninitialized" case from |
| 432 | // the case when we know the manifest version actually is 1. |
| 433 | int manifest_version_; |
| 434 | |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 435 | // The absolute path to the directory the extension is stored in. |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 436 | base::FilePath path_; |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 437 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 438 | // Defines the set of URLs in the extension's web content. |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 439 | URLPatternSet extent_; |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 440 | |
[email protected] | d695bb1 | 2014-06-05 16:16:30 | [diff] [blame] | 441 | // The parser for the manifest's permissions. This is NULL anytime not during |
| 442 | // initialization. |
| 443 | // TODO(rdevlin.cronin): This doesn't really belong here. |
| 444 | scoped_ptr<PermissionsParser> permissions_parser_; |
| 445 | |
| 446 | // The active permissions for the extension. |
[email protected] | 2cb5e30 | 2013-05-09 05:00:06 | [diff] [blame] | 447 | scoped_ptr<PermissionsData> permissions_data_; |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 448 | |
[email protected] | 8629c54 | 2012-04-20 03:40:03 | [diff] [blame] | 449 | // Any warnings that occurred when trying to create/parse the extension. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 450 | std::vector<InstallWarning> install_warnings_; |
[email protected] | 8629c54 | 2012-04-20 03:40:03 | [diff] [blame] | 451 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 452 | // The base extension url for the extension. |
| 453 | GURL extension_url_; |
| 454 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 455 | // The extension's version. |
[email protected] | 1f04ef4 | 2013-04-22 07:35:50 | [diff] [blame] | 456 | scoped_ptr<base::Version> version_; |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 457 | |
elijahtaylor | 89b02d7 | 2014-12-05 00:42:20 | [diff] [blame] | 458 | // The extension's user visible version name. |
| 459 | std::string version_name_; |
| 460 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 461 | // An optional longer description of the extension. |
| 462 | std::string description_; |
| 463 | |
| 464 | // True if the extension was generated from a user script. (We show slightly |
| 465 | // different UI if so). |
| 466 | bool converted_from_user_script_; |
| 467 | |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 468 | // The public key used to sign the contents of the crx package. |
| 469 | std::string public_key_; |
| 470 | |
[email protected] | 58f62cf | 2012-03-09 10:45:11 | [diff] [blame] | 471 | // The manifest from which this extension was created. |
[email protected] | e9629d77 | 2012-08-06 19:44:46 | [diff] [blame] | 472 | scoped_ptr<Manifest> manifest_; |
[email protected] | 6f229e8 | 2010-11-02 17:47:26 | [diff] [blame] | 473 | |
[email protected] | d356c98 | 2012-12-12 19:32:55 | [diff] [blame] | 474 | // Stored parsed manifest data. |
| 475 | ManifestDataMap manifest_data_; |
| 476 | |
| 477 | // Set to true at the end of InitValue when initialization is finished. |
| 478 | bool finished_parsing_manifest_; |
| 479 | |
[email protected] | 7eeab9ec | 2013-01-15 04:08:33 | [diff] [blame] | 480 | // Ensures that any call to GetManifestData() prior to finishing |
| 481 | // initialization happens from the same thread (this can happen when certain |
| 482 | // parts of the initialization process need information from previous parts). |
| 483 | base::ThreadChecker thread_checker_; |
| 484 | |
[email protected] | 7e0f92b | 2012-11-09 03:51:04 | [diff] [blame] | 485 | // Should this app be shown in the app launcher. |
[email protected] | ed1a204f | 2012-09-22 00:28:44 | [diff] [blame] | 486 | bool display_in_launcher_; |
| 487 | |
[email protected] | 7e0f92b | 2012-11-09 03:51:04 | [diff] [blame] | 488 | // Should this app be shown in the browser New Tab Page. |
| 489 | bool display_in_new_tab_page_; |
| 490 | |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 491 | // Whether the extension has host permissions or user script patterns that |
| 492 | // imply access to file:/// scheme URLs (the user may not have actually |
| 493 | // granted it that access). |
| 494 | bool wants_file_access_; |
| 495 | |
[email protected] | 2af352b | 2011-07-22 08:21:23 | [diff] [blame] | 496 | // The flags that were passed to InitFromValue. |
| 497 | int creation_flags_; |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 498 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 499 | DISALLOW_COPY_AND_ASSIGN(Extension); |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 500 | }; |
| 501 | |
[email protected] | bc151cf9 | 2013-02-12 04:57:26 | [diff] [blame] | 502 | typedef std::vector<scoped_refptr<const Extension> > ExtensionList; |
[email protected] | 53d5f0f46 | 2014-03-07 09:15:20 | [diff] [blame] | 503 | typedef std::set<ExtensionId> ExtensionIdSet; |
| 504 | typedef std::vector<ExtensionId> ExtensionIdList; |
[email protected] | b1748b1d8 | 2009-11-30 20:32:56 | [diff] [blame] | 505 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 506 | // Handy struct to pass core extension info around. |
| 507 | struct ExtensionInfo { |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 508 | ExtensionInfo(const base::DictionaryValue* manifest, |
[email protected] | 53d5f0f46 | 2014-03-07 09:15:20 | [diff] [blame] | 509 | const ExtensionId& id, |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 510 | const base::FilePath& path, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 511 | Manifest::Location location); |
[email protected] | 3bb8499 | 2010-08-26 17:23:46 | [diff] [blame] | 512 | ~ExtensionInfo(); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 513 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 514 | scoped_ptr<base::DictionaryValue> extension_manifest; |
[email protected] | 53d5f0f46 | 2014-03-07 09:15:20 | [diff] [blame] | 515 | ExtensionId extension_id; |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 516 | base::FilePath extension_path; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 517 | Manifest::Location extension_location; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 518 | |
| 519 | private: |
| 520 | DISALLOW_COPY_AND_ASSIGN(ExtensionInfo); |
| 521 | }; |
| 522 | |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 523 | struct InstalledExtensionInfo { |
| 524 | // The extension being installed - this should always be non-NULL. |
| 525 | const Extension* extension; |
| 526 | |
| 527 | // True if the extension is being updated; false if it is being installed. |
| 528 | bool is_update; |
| 529 | |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 530 | // True if the extension was previously installed ephemerally and is now |
| 531 | // a regular installed extension. |
| 532 | bool from_ephemeral; |
| 533 | |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 534 | // The name of the extension prior to this update. Will be empty if |
| 535 | // |is_update| is false. |
| 536 | std::string old_name; |
| 537 | |
| 538 | InstalledExtensionInfo(const Extension* extension, |
| 539 | bool is_update, |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 540 | bool from_ephemeral, |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 541 | const std::string& old_name); |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 542 | }; |
| 543 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 544 | struct UnloadedExtensionInfo { |
[email protected] | e51232f3 | 2014-04-18 20:05:36 | [diff] [blame] | 545 | // TODO(DHNishi): Move this enum to ExtensionRegistryObserver. |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 546 | enum Reason { |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 547 | REASON_UNDEFINED, // Undefined state used to initialize variables. |
| 548 | REASON_DISABLE, // Extension is being disabled. |
| 549 | REASON_UPDATE, // Extension is being updated to a newer version. |
| 550 | REASON_UNINSTALL, // Extension is being uninstalled. |
| 551 | REASON_TERMINATE, // Extension has terminated. |
| 552 | REASON_BLACKLIST, // Extension has been blacklisted. |
| 553 | REASON_PROFILE_SHUTDOWN, // Profile is being shut down. |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 554 | REASON_LOCK_ALL, // All extensions for the profile are blocked. |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 555 | }; |
| 556 | |
| 557 | Reason reason; |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 558 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 559 | // The extension being unloaded - this should always be non-NULL. |
| 560 | const Extension* extension; |
| 561 | |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 562 | UnloadedExtensionInfo(const Extension* extension, Reason reason); |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 563 | }; |
| 564 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 565 | // The details sent for EXTENSION_PERMISSIONS_UPDATED notifications. |
| 566 | struct UpdatedExtensionPermissionsInfo { |
| 567 | enum Reason { |
[email protected] | f553247 | 2012-02-23 13:00:55 | [diff] [blame] | 568 | ADDED, // The permissions were added to the extension. |
| 569 | REMOVED, // The permissions were removed from the extension. |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 570 | }; |
| 571 | |
| 572 | Reason reason; |
| 573 | |
| 574 | // The extension who's permissions have changed. |
| 575 | const Extension* extension; |
| 576 | |
| 577 | // The permissions that have changed. For Reason::ADDED, this would contain |
| 578 | // only the permissions that have added, and for Reason::REMOVED, this would |
| 579 | // only contain the removed permissions. |
rdevlin.cronin | e2d0fd0 | 2015-09-24 22:35:49 | [diff] [blame] | 580 | const PermissionSet& permissions; |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 581 | |
rdevlin.cronin | e2d0fd0 | 2015-09-24 22:35:49 | [diff] [blame] | 582 | UpdatedExtensionPermissionsInfo(const Extension* extension, |
| 583 | const PermissionSet& permissions, |
| 584 | Reason reason); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 585 | }; |
| 586 | |
[email protected] | 488e650 | 2012-09-07 14:17:34 | [diff] [blame] | 587 | } // namespace extensions |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 588 | |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 589 | #endif // EXTENSIONS_COMMON_EXTENSION_H_ |