[email protected] | 225c8f5 | 2010-02-05 22:23:20 | [diff] [blame] | 1 | // Copyright (c) 2010 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] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 8 | #include <map> |
[email protected] | facd7a765 | 2009-06-05 23:15:02 | [diff] [blame] | 9 | #include <set> |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 10 | #include <string> |
| 11 | #include <vector> |
| 12 | |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 13 | #include "base/file_path.h" |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 14 | #include "base/scoped_ptr.h" |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 15 | #include "base/values.h" |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 16 | #include "base/version.h" |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 17 | #include "chrome/common/extensions/extension_extent.h" |
[email protected] | 42b6f0f8 | 2009-09-18 21:07:39 | [diff] [blame] | 18 | #include "chrome/common/extensions/user_script.h" |
[email protected] | 7197f499 | 2009-03-23 05:05:49 | [diff] [blame] | 19 | #include "chrome/common/extensions/url_pattern.h" |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 20 | #include "googleurl/src/gurl.h" |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 21 | #include "testing/gtest/include/gtest/gtest_prod.h" |
[email protected] | d9ad80f | 2010-03-30 20:40:18 | [diff] [blame] | 22 | #include "third_party/skia/include/core/SkBitmap.h" |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 23 | |
[email protected] | 942690b13 | 2010-05-11 06:42:14 | [diff] [blame] | 24 | class ExtensionAction; |
| 25 | class ExtensionResource; |
| 26 | |
[email protected] | c533bb2 | 2009-06-03 19:06:11 | [diff] [blame] | 27 | // Represents a Chrome extension. |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 28 | class Extension { |
| 29 | public: |
[email protected] | b30e0dd | 2010-01-29 23:33:21 | [diff] [blame] | 30 | typedef std::vector<URLPattern> URLPatternList; |
[email protected] | d3cfa48 | 2009-10-17 13:54:57 | [diff] [blame] | 31 | typedef std::map<const std::string, GURL> URLOverrideMap; |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 32 | |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 33 | // What an extension was loaded from. |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 34 | // NOTE: These values are stored as integers in the preferences, so you |
| 35 | // really don't want to change any existing ones. |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 36 | enum Location { |
| 37 | INVALID, |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 38 | INTERNAL, // A crx file from the internal Extensions directory. |
| 39 | EXTERNAL_PREF, // A crx file from an external directory (via prefs). |
| 40 | EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the |
| 41 | // registry on Windows). |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 42 | LOAD, // --load-extension. |
| 43 | COMPONENT // An integral component of Chrome itself, which happens |
| 44 | // to be implemented as an extension. We don't show |
| 45 | // these in the management UI. |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | enum State { |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 49 | DISABLED = 0, |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 50 | ENABLED, |
| 51 | KILLBIT, // Don't install/upgrade (applies to external extensions only). |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 52 | |
| 53 | NUM_STATES |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 54 | }; |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 55 | |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 56 | enum InstallType { |
[email protected] | ab6f2b2 | 2009-07-28 23:28:37 | [diff] [blame] | 57 | INSTALL_ERROR, |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 58 | DOWNGRADE, |
| 59 | REINSTALL, |
| 60 | UPGRADE, |
| 61 | NEW_INSTALL |
| 62 | }; |
| 63 | |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 64 | // NOTE: If you change this list, you should also change kIconSizes in the cc |
| 65 | // file. |
| 66 | enum Icons { |
| 67 | EXTENSION_ICON_LARGE = 128, |
| 68 | EXTENSION_ICON_MEDIUM = 48, |
| 69 | EXTENSION_ICON_SMALL = 32, |
[email protected] | 3938294 | 2010-03-23 15:57:09 | [diff] [blame] | 70 | EXTENSION_ICON_SMALLISH = 24, |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 71 | EXTENSION_ICON_BITTY = 16, |
| 72 | }; |
| 73 | |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 74 | enum LaunchContainer { |
[email protected] | c28071ad | 2010-03-12 17:28:56 | [diff] [blame] | 75 | LAUNCH_WINDOW, |
| 76 | LAUNCH_PANEL, |
| 77 | LAUNCH_TAB |
[email protected] | 28375ae | 2010-02-05 04:45:50 | [diff] [blame] | 78 | }; |
| 79 | |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 80 | bool apps_enabled() const { return apps_enabled_; } |
| 81 | void set_apps_enabled(bool val) { apps_enabled_ = val; } |
| 82 | |
[email protected] | c3e3def74 | 2009-07-17 07:51:06 | [diff] [blame] | 83 | // Icon sizes used by the extension system. |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 84 | static const int kIconSizes[]; |
[email protected] | c3e3def74 | 2009-07-17 07:51:06 | [diff] [blame] | 85 | |
[email protected] | 4c4f819 | 2009-10-17 01:03:26 | [diff] [blame] | 86 | // Max size (both dimensions) for browser and page actions. |
| 87 | static const int kPageActionIconMaxSize; |
| 88 | static const int kBrowserActionIconMaxSize; |
| 89 | |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 90 | // Each permission is a module that the extension is permitted to use. |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 91 | static const char* kBackgroundPermission; |
[email protected] | aeb53b3 | 2009-10-29 07:34:45 | [diff] [blame] | 92 | static const char* kBookmarkPermission; |
[email protected] | ea99c3a | 2010-01-07 00:40:19 | [diff] [blame] | 93 | static const char* kExperimentalPermission; |
[email protected] | 5ab79b0 | 2010-04-26 16:47:11 | [diff] [blame] | 94 | static const char* kGeolocationPermission; |
[email protected] | bb0a6a0 | 2010-04-01 21:17:00 | [diff] [blame] | 95 | static const char* kHistoryPermission; |
[email protected] | 5ab79b0 | 2010-04-26 16:47:11 | [diff] [blame] | 96 | static const char* kNotificationPermission; |
| 97 | static const char* kTabPermission; |
| 98 | static const char* kUnlimitedStoragePermission; |
[email protected] | aeb53b3 | 2009-10-29 07:34:45 | [diff] [blame] | 99 | |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 100 | static const char* kPermissionNames[]; |
| 101 | static const size_t kNumPermissions; |
| 102 | |
[email protected] | c533bb2 | 2009-06-03 19:06:11 | [diff] [blame] | 103 | // An NPAPI plugin included in the extension. |
| 104 | struct PluginInfo { |
| 105 | FilePath path; // Path to the plugin. |
| 106 | bool is_public; // False if only this extension can load this plugin. |
| 107 | }; |
| 108 | |
[email protected] | bbc94554 | 2009-07-26 00:11:42 | [diff] [blame] | 109 | // A toolstrip and its associated mole. |
| 110 | struct ToolstripInfo { |
| 111 | ToolstripInfo() : mole_height(0) {} |
| 112 | |
| 113 | GURL toolstrip; |
| 114 | GURL mole; |
| 115 | int mole_height; |
| 116 | }; |
| 117 | |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 118 | // The name of the manifest inside an extension. |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 119 | static const FilePath::CharType kManifestFilename[]; |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 120 | |
[email protected] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 121 | // The name of locale folder inside an extension. |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 122 | static const FilePath::CharType kLocaleFolder[]; |
[email protected] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 123 | |
| 124 | // The name of the messages file inside an extension. |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 125 | static const FilePath::CharType kMessagesFilename[]; |
[email protected] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 126 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 127 | #if defined(OS_WIN) |
| 128 | static const char* kExtensionRegistryPath; |
| 129 | #endif |
| 130 | |
[email protected] | 37eeb5a | 2009-02-26 23:36:17 | [diff] [blame] | 131 | // The number of bytes in a legal id. |
[email protected] | fe0e782 | 2009-02-26 23:51:48 | [diff] [blame] | 132 | static const size_t kIdSize; |
[email protected] | 37eeb5a | 2009-02-26 23:36:17 | [diff] [blame] | 133 | |
[email protected] | e435d6b7 | 2009-07-25 03:15:58 | [diff] [blame] | 134 | // The mimetype used for extensions. |
| 135 | static const char kMimeType[]; |
| 136 | |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 137 | explicit Extension(const FilePath& path); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 138 | virtual ~Extension(); |
| 139 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 140 | // Checks to see if the extension has a valid ID. |
| 141 | static bool IdIsValid(const std::string& id); |
| 142 | |
[email protected] | e435d6b7 | 2009-07-25 03:15:58 | [diff] [blame] | 143 | // Returns true if the specified file is an extension. |
| 144 | static bool IsExtension(const FilePath& file_name); |
| 145 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 146 | // Whether the |location| is external or not. |
| 147 | static inline bool IsExternalLocation(Location location) { |
| 148 | return location == Extension::EXTERNAL_PREF || |
| 149 | location == Extension::EXTERNAL_REGISTRY; |
| 150 | } |
| 151 | |
[email protected] | 07c00d99 | 2009-03-04 20:27:04 | [diff] [blame] | 152 | // Returns an absolute url to a resource inside of an extension. The |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 153 | // |extension_url| argument should be the url() from an Extension object. The |
| 154 | // |relative_path| can be untrusted user input. The returned URL will either |
| 155 | // be invalid() or a child of |extension_url|. |
| 156 | // NOTE: Static so that it can be used from multiple threads. |
| 157 | static GURL GetResourceURL(const GURL& extension_url, |
| 158 | const std::string& relative_path); |
[email protected] | 3cfbd0e | 2009-03-18 21:26:24 | [diff] [blame] | 159 | GURL GetResourceURL(const std::string& relative_path) { |
| 160 | return GetResourceURL(url(), relative_path); |
| 161 | } |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 162 | |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 163 | // Returns an extension resource object. |relative_path| should be UTF8 |
| 164 | // encoded. |
| 165 | ExtensionResource GetResource(const std::string& relative_path); |
| 166 | |
| 167 | // As above, but with |relative_path| following the file system's encoding. |
| 168 | ExtensionResource GetResource(const FilePath& relative_path); |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 169 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 170 | // |input| is expected to be the text of an rsa public or private key. It |
| 171 | // tolerates the presence or absence of bracking header/footer like this: |
| 172 | // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY----- |
| 173 | // and may contain newlines. |
| 174 | static bool ParsePEMKeyBytes(const std::string& input, std::string* output); |
| 175 | |
| 176 | // Does a simple base64 encoding of |input| into |output|. |
| 177 | static bool ProducePEM(const std::string& input, std::string* output); |
| 178 | |
[email protected] | 84ac7f3 | 2009-10-06 06:17:54 | [diff] [blame] | 179 | // Generates an extension ID from arbitrary input. The same input string will |
| 180 | // always generate the same output ID. |
| 181 | static bool GenerateId(const std::string& input, std::string* output); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 182 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 183 | // Expects base64 encoded |input| and formats into |output| including |
| 184 | // the appropriate header & footer. |
| 185 | static bool FormatPEMForFileOutput(const std::string input, |
| 186 | std::string* output, bool is_public); |
| 187 | |
[email protected] | 2a40953 | 2009-08-28 19:39:44 | [diff] [blame] | 188 | // Determine whether |new_extension| has increased privileges compared to |
| 189 | // |old_extension|. |
| 190 | static bool IsPrivilegeIncrease(Extension* old_extension, |
| 191 | Extension* new_extension); |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 192 | |
[email protected] | c690a981 | 2009-12-17 05:55:32 | [diff] [blame] | 193 | // Given an extension and icon size, read it if present and decode it into |
[email protected] | ae2e0f9 | 2010-04-06 20:32:23 | [diff] [blame] | 194 | // result. In the browser process, this will DCHECK if not called on the |
| 195 | // file thread. To easily load extension images on the UI thread, see |
| 196 | // ImageLoadingTracker. |
[email protected] | c690a981 | 2009-12-17 05:55:32 | [diff] [blame] | 197 | static void DecodeIcon(Extension* extension, |
| 198 | Icons icon_size, |
| 199 | scoped_ptr<SkBitmap>* result); |
| 200 | |
| 201 | // Given an icon_path and icon size, read it if present and decode it into |
[email protected] | ae2e0f9 | 2010-04-06 20:32:23 | [diff] [blame] | 202 | // result. In the browser process, this will DCHECK if not called on the |
| 203 | // file thread. To easily load extension images on the UI thread, see |
| 204 | // ImageLoadingTracker. |
[email protected] | c690a981 | 2009-12-17 05:55:32 | [diff] [blame] | 205 | static void DecodeIconFromPath(const FilePath& icon_path, |
| 206 | Icons icon_size, |
| 207 | scoped_ptr<SkBitmap>* result); |
| 208 | |
[email protected] | a807bbe | 2010-04-14 10:51:19 | [diff] [blame] | 209 | // Returns the base extension url for a given |extension_id|. |
| 210 | static GURL GetBaseURLFromExtensionId(const std::string& extension_id); |
| 211 | |
[email protected] | 596c6aa | 2010-05-25 15:56:26 | [diff] [blame] | 212 | // Returns whether the browser has apps enabled (either as the default or if |
| 213 | // it was explictly turned on via a command line switch). |
| 214 | static bool AppsAreEnabled(); |
| 215 | |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 216 | // Initialize the extension from a parsed manifest. |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 217 | // Usually, the id of an extension is generated by the "key" property of |
| 218 | // its manifest, but if |require_key| is |false|, a temporary ID will be |
| 219 | // generated based on the path. |
| 220 | bool InitFromValue(const DictionaryValue& value, bool require_key, |
[email protected] | 5bfb1eb0a | 2009-04-08 18:33:30 | [diff] [blame] | 221 | std::string* error); |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 222 | |
[email protected] | 8289126 | 2008-12-24 00:21:26 | [diff] [blame] | 223 | const FilePath& path() const { return path_; } |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 224 | void set_path(const FilePath& path) { path_ = path; } |
[email protected] | 5bfb1eb0a | 2009-04-08 18:33:30 | [diff] [blame] | 225 | const GURL& url() const { return extension_url_; } |
[email protected] | 225c8f5 | 2010-02-05 22:23:20 | [diff] [blame] | 226 | Location location() const { return location_; } |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 227 | void set_location(Location location) { location_ = location; } |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 228 | const std::string& id() const { return id_; } |
| 229 | const Version* version() const { return version_.get(); } |
| 230 | // String representation of the version number. |
| 231 | const std::string VersionString() const; |
| 232 | const std::string& name() const { return name_; } |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 233 | const std::string& public_key() const { return public_key_; } |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 234 | const std::string& description() const { return description_; } |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 235 | bool converted_from_user_script() const { |
| 236 | return converted_from_user_script_; |
| 237 | } |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 238 | const UserScriptList& content_scripts() const { return content_scripts_; } |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 239 | ExtensionAction* page_action() const { return page_action_.get(); } |
| 240 | ExtensionAction* browser_action() const { return browser_action_.get(); } |
[email protected] | c533bb2 | 2009-06-03 19:06:11 | [diff] [blame] | 241 | const std::vector<PluginInfo>& plugins() const { return plugins_; } |
[email protected] | c6463165 | 2009-04-29 22:24:31 | [diff] [blame] | 242 | const GURL& background_url() const { return background_url_; } |
[email protected] | 43919ac9 | 2009-10-16 18:34:28 | [diff] [blame] | 243 | const GURL& options_url() const { return options_url_; } |
[email protected] | bbc94554 | 2009-07-26 00:11:42 | [diff] [blame] | 244 | const std::vector<ToolstripInfo>& toolstrips() const { return toolstrips_; } |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 245 | const std::vector<std::string>& api_permissions() const { |
| 246 | return api_permissions_; |
| 247 | } |
[email protected] | b30e0dd | 2010-01-29 23:33:21 | [diff] [blame] | 248 | const URLPatternList& host_permissions() const { |
[email protected] | c7ad50f | 2009-09-11 06:28:15 | [diff] [blame] | 249 | return host_permissions_; |
| 250 | } |
| 251 | |
[email protected] | e9303b94 | 2010-02-20 08:21:19 | [diff] [blame] | 252 | // Returns true if the extension has permission to execute script on a |
| 253 | // particular host. |
| 254 | // TODO(aa): Also use this in the renderer, for normal content script |
| 255 | // injection. Currently, that has its own copy of this code. |
| 256 | bool CanExecuteScriptOnHost(const GURL& url, std::string* error) const; |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 257 | |
[email protected] | aeb53b3 | 2009-10-29 07:34:45 | [diff] [blame] | 258 | // Returns true if the extension has the specified API permission. |
| 259 | bool HasApiPermission(const std::string& permission) const { |
| 260 | return std::find(api_permissions_.begin(), api_permissions_.end(), |
| 261 | permission) != api_permissions_.end(); |
| 262 | } |
| 263 | |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 264 | // Returns the set of hosts that the extension effectively has access to. This |
| 265 | // is used in the permissions UI and is a combination of the hosts accessible |
| 266 | // through content scripts and the hosts accessible through XHR. |
| 267 | const std::set<std::string> GetEffectiveHostPermissions() const; |
| 268 | |
[email protected] | fbd17cf | 2010-04-28 23:52:56 | [diff] [blame] | 269 | // Whether or not the extension is allowed permission for a URL pattern from |
| 270 | // the manifest. http, https, and chrome://favicon/ is allowed for all |
| 271 | // extensions, while component extensions are allowed access to |
| 272 | // chrome://resources. |
| 273 | bool CanAccessURL(const URLPattern pattern) const; |
| 274 | |
[email protected] | 584b8e3f | 2010-04-10 00:23:37 | [diff] [blame] | 275 | // Whether the extension has access to the given URL. |
| 276 | bool HasHostPermission(const GURL& url) const; |
| 277 | |
[email protected] | 215160af | 2010-04-03 06:02:34 | [diff] [blame] | 278 | // Returns true if the extension effectively has access to the user's browsing |
| 279 | // history. There are several permissions that we group together into this |
| 280 | // bucket. For example: tabs, bookmarks, and history. |
| 281 | bool HasEffectiveBrowsingHistoryPermission() const; |
| 282 | |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 283 | // Whether the extension has access to all hosts. This is true if there is |
| 284 | // a content script that matches all hosts, or if there is a host permission |
| 285 | // for all hosts. |
| 286 | bool HasAccessToAllHosts() const; |
| 287 | |
[email protected] | b29682ba2 | 2009-06-18 19:53:56 | [diff] [blame] | 288 | const GURL& update_url() const { return update_url_; } |
[email protected] | 0cb5f50 | 2009-10-21 21:35:47 | [diff] [blame] | 289 | const std::map<int, std::string>& icons() const { return icons_; } |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 290 | |
[email protected] | bfa90a3a | 2010-04-28 15:43:23 | [diff] [blame] | 291 | // Returns the Google Gallery URL for this extension, if one exists. For |
| 292 | // third-party extensions, this returns a blank GURL. |
| 293 | GURL GalleryUrl() const; |
| 294 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 295 | // Theme-related. |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 296 | DictionaryValue* GetThemeImages() const { return theme_images_.get(); } |
| 297 | DictionaryValue* GetThemeColors() const { return theme_colors_.get(); } |
| 298 | DictionaryValue* GetThemeTints() const { return theme_tints_.get(); } |
[email protected] | 7895ea2 | 2009-06-02 20:53:50 | [diff] [blame] | 299 | DictionaryValue* GetThemeDisplayProperties() const { |
| 300 | return theme_display_properties_.get(); |
| 301 | } |
[email protected] | 66da08b | 2009-10-19 22:27:00 | [diff] [blame] | 302 | bool IsTheme() const { return is_theme_; } |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 303 | |
[email protected] | facd7a765 | 2009-06-05 23:15:02 | [diff] [blame] | 304 | // Returns a list of paths (relative to the extension dir) for images that |
| 305 | // the browser might load (like themes and page action icons). |
| 306 | std::set<FilePath> GetBrowserImages(); |
| 307 | |
[email protected] | 86693068 | 2009-08-18 22:53:47 | [diff] [blame] | 308 | // Returns an absolute path to the given icon inside of the extension. Returns |
| 309 | // an empty FilePath if the extension does not have that icon. |
[email protected] | ecabe6ee | 2009-10-07 22:49:10 | [diff] [blame] | 310 | ExtensionResource GetIconPath(Icons icon); |
[email protected] | 86693068 | 2009-08-18 22:53:47 | [diff] [blame] | 311 | |
[email protected] | f34e7963 | 2010-03-17 02:34:08 | [diff] [blame] | 312 | // Looks for an extension icon of dimension |icon|. If not found, checks if |
| 313 | // the next larger size exists (until one is found or the end is reached). If |
| 314 | // an icon is found, the path is returned in |resource| and the dimension |
| 315 | // found is returned to the caller (as function return value). |
| 316 | // NOTE: |resource| is not guaranteed to be non-empty. |
| 317 | Icons GetIconPathAllowLargerSize(ExtensionResource* resource, Icons icon); |
| 318 | |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 319 | const DictionaryValue* manifest_value() const { |
| 320 | return manifest_value_.get(); |
| 321 | } |
| 322 | |
[email protected] | 9428edc | 2009-11-18 18:02:47 | [diff] [blame] | 323 | const std::string default_locale() const { return default_locale_; } |
| 324 | |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 325 | // Chrome URL overrides (see ExtensionOverrideUI). |
[email protected] | d3cfa48 | 2009-10-17 13:54:57 | [diff] [blame] | 326 | const URLOverrideMap& GetChromeURLOverrides() const { |
| 327 | return chrome_url_overrides_; |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 328 | } |
| 329 | |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 330 | const std::string omnibox_keyword() const { return omnibox_keyword_; } |
| 331 | |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 332 | bool web_content_enabled() const { return web_content_enabled_; } |
| 333 | const ExtensionExtent& web_extent() const { return web_extent_; } |
| 334 | |
| 335 | const std::string& launch_local_path() const { return launch_local_path_; } |
| 336 | const std::string& launch_web_url() const { return launch_web_url_; } |
[email protected] | 98254d2 | 2010-03-26 00:03:50 | [diff] [blame] | 337 | LaunchContainer launch_container() const { return launch_container_; } |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 338 | bool launch_fullscreen() const { return launch_fullscreen_; } |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 339 | |
| 340 | // Gets the fully resolved absolute launch URL. |
| 341 | GURL GetFullLaunchURL() const; |
[email protected] | ceefd3d | 2010-03-12 09:10:29 | [diff] [blame] | 342 | |
[email protected] | e95ad33 | 2009-08-03 19:44:25 | [diff] [blame] | 343 | // Runtime data: |
| 344 | // Put dynamic data about the state of a running extension below. |
| 345 | |
| 346 | // Whether the background page, if any, is ready. We don't load other |
| 347 | // components until then. If there is no background page, we consider it to |
| 348 | // be ready. |
| 349 | bool GetBackgroundPageReady(); |
| 350 | void SetBackgroundPageReady(); |
| 351 | |
[email protected] | 1e8c93f | 2010-02-08 22:58:31 | [diff] [blame] | 352 | // Getter and setter for the flag that specifies whether the extension is |
| 353 | // being upgraded. |
| 354 | bool being_upgraded() const { return being_upgraded_; } |
| 355 | void set_being_upgraded(bool value) { being_upgraded_ = value; } |
| 356 | |
[email protected] | d9ad80f | 2010-03-30 20:40:18 | [diff] [blame] | 357 | // Image cache related methods. These are only valid on the UI thread and |
| 358 | // not maintained by this class. See ImageLoadingTracker for usage. |
| 359 | void SetCachedImage(const ExtensionResource& source, |
| 360 | const SkBitmap& image); |
| 361 | bool HasCachedImage(const ExtensionResource& source); |
| 362 | SkBitmap GetCachedImage(const ExtensionResource& source); |
| 363 | |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 364 | private: |
[email protected] | d9ad80f | 2010-03-30 20:40:18 | [diff] [blame] | 365 | typedef std::map<FilePath, SkBitmap> ImageCache; |
| 366 | |
[email protected] | 3cfbd0e | 2009-03-18 21:26:24 | [diff] [blame] | 367 | // Helper method that loads a UserScript object from a |
| 368 | // dictionary in the content_script list of the manifest. |
| 369 | bool LoadUserScriptHelper(const DictionaryValue* content_script, |
| 370 | int definition_index, |
| 371 | std::string* error, |
| 372 | UserScript* result); |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 373 | |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 374 | // Helper method that loads either the include_globs or exclude_globs list |
| 375 | // from an entry in the content_script lists of the manifest. |
| 376 | bool LoadGlobsHelper(const DictionaryValue* content_script, |
| 377 | int content_script_index, |
| 378 | const wchar_t* globs_property_name, |
| 379 | std::string* error, |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 380 | void(UserScript::*add_method)(const std::string& glob), |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 381 | UserScript *instance); |
| 382 | |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 383 | // Checks that apps features are enabled if the manifest tries to use any of |
| 384 | // them. |
| 385 | bool CheckAppsAreEnabled(const DictionaryValue* manifest, std::string* error); |
| 386 | |
| 387 | // Helpers to load various chunks of the manifest. |
| 388 | bool LoadWebContentEnabled(const DictionaryValue* manifest, |
| 389 | std::string* error); |
| 390 | bool LoadWebOrigin(const DictionaryValue* manifest, std::string* error); |
| 391 | bool LoadWebPaths(const DictionaryValue* manifest, std::string* error); |
| 392 | bool LoadLaunchContainer(const DictionaryValue* manifest, std::string* error); |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 393 | bool LoadLaunchFullscreen(const DictionaryValue* manifest, |
| 394 | std::string* error); |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 395 | bool LoadLaunchURL(const DictionaryValue* manifest, std::string* error); |
| 396 | |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 397 | // Helper method to load an ExtensionAction from the page_action or |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 398 | // browser_action entries in the manifest. |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 399 | ExtensionAction* LoadExtensionActionHelper( |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 400 | const DictionaryValue* extension_action, std::string* error); |
| 401 | |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 402 | // Figures out if a source contains keys not associated with themes - we |
| 403 | // don't want to allow scripts and such to be bundled with themes. |
| 404 | bool ContainsNonThemeKeys(const DictionaryValue& source); |
| 405 | |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 406 | // Returns true if the string is one of the known api permissions (see |
| 407 | // kPermissionNames). |
| 408 | bool IsAPIPermission(const std::string& permission); |
| 409 | |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 410 | // The absolute path to the directory the extension is stored in. |
| 411 | FilePath path_; |
| 412 | |
| 413 | // The base extension url for the extension. |
| 414 | GURL extension_url_; |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 415 | |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 416 | // The location the extension was loaded from. |
| 417 | Location location_; |
| 418 | |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 419 | // A human-readable ID for the extension. The convention is to use something |
| 420 | // like 'com.example.myextension', but this is not currently enforced. An |
| 421 | // extension's ID is used in things like directory structures and URLs, and |
| 422 | // is expected to not change across versions. In the case of conflicts, |
| 423 | // updates will only be allowed if the extension can be validated using the |
| 424 | // previous version's update key. |
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 425 | std::string id_; |
[email protected] | 8289126 | 2008-12-24 00:21:26 | [diff] [blame] | 426 | |
[email protected] | 64a02b80 | 2009-01-12 19:36:42 | [diff] [blame] | 427 | // The extension's version. |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 428 | scoped_ptr<Version> version_; |
[email protected] | 64a02b80 | 2009-01-12 19:36:42 | [diff] [blame] | 429 | |
[email protected] | 49a7c77 | 2010-05-21 18:32:35 | [diff] [blame] | 430 | // The extension's human-readable name. Name is used for display purpose. It |
| 431 | // might be wrapped with unicode bidi control characters so that it is |
| 432 | // displayed correctly in RTL context. |
| 433 | // NOTE: Name is UTF-8 and may contain non-ascii characters. |
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 434 | std::string name_; |
[email protected] | 8289126 | 2008-12-24 00:21:26 | [diff] [blame] | 435 | |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 436 | // An optional longer description of the extension. |
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 437 | std::string description_; |
[email protected] | 8289126 | 2008-12-24 00:21:26 | [diff] [blame] | 438 | |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 439 | // True if the extension was generated from a user script. (We show slightly |
| 440 | // different UI if so). |
| 441 | bool converted_from_user_script_; |
| 442 | |
[email protected] | 8289126 | 2008-12-24 00:21:26 | [diff] [blame] | 443 | // Paths to the content scripts the extension contains. |
[email protected] | 34aa8dc | 2009-02-19 07:03:05 | [diff] [blame] | 444 | UserScriptList content_scripts_; |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 445 | |
[email protected] | 37e960e | 2009-10-13 23:17:50 | [diff] [blame] | 446 | // The extension's page action, if any. |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 447 | scoped_ptr<ExtensionAction> page_action_; |
[email protected] | 671e6c1ce | 2009-09-26 03:18:46 | [diff] [blame] | 448 | |
| 449 | // The extension's browser action, if any. |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 450 | scoped_ptr<ExtensionAction> browser_action_; |
[email protected] | ec9ac0df | 2009-10-01 18:06:47 | [diff] [blame] | 451 | |
[email protected] | c533bb2 | 2009-06-03 19:06:11 | [diff] [blame] | 452 | // Optional list of NPAPI plugins and associated properties. |
| 453 | std::vector<PluginInfo> plugins_; |
[email protected] | 367230c5 | 2009-02-21 01:44:30 | [diff] [blame] | 454 | |
[email protected] | c6463165 | 2009-04-29 22:24:31 | [diff] [blame] | 455 | // Optional URL to a master page of which a single instance should be always |
| 456 | // loaded in the background. |
| 457 | GURL background_url_; |
| 458 | |
[email protected] | 43919ac9 | 2009-10-16 18:34:28 | [diff] [blame] | 459 | // Optional URL to a page for setting options/preferences. |
| 460 | GURL options_url_; |
| 461 | |
[email protected] | bbc94554 | 2009-07-26 00:11:42 | [diff] [blame] | 462 | // Optional list of toolstrips_ and associated properties. |
| 463 | std::vector<ToolstripInfo> toolstrips_; |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 464 | |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 465 | // The public key ('key' in the manifest) used to sign the contents of the |
| 466 | // crx package ('signature' in the manifest) |
| 467 | std::string public_key_; |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 468 | |
[email protected] | 07c00d99 | 2009-03-04 20:27:04 | [diff] [blame] | 469 | // A map of resource id's to relative file paths. |
[email protected] | bbb436f | 2009-05-09 16:51:07 | [diff] [blame] | 470 | scoped_ptr<DictionaryValue> theme_images_; |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 471 | |
| 472 | // A map of color names to colors. |
[email protected] | bbb436f | 2009-05-09 16:51:07 | [diff] [blame] | 473 | scoped_ptr<DictionaryValue> theme_colors_; |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 474 | |
| 475 | // A map of color names to colors. |
[email protected] | bbb436f | 2009-05-09 16:51:07 | [diff] [blame] | 476 | scoped_ptr<DictionaryValue> theme_tints_; |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 477 | |
[email protected] | 7895ea2 | 2009-06-02 20:53:50 | [diff] [blame] | 478 | // A map of display properties. |
| 479 | scoped_ptr<DictionaryValue> theme_display_properties_; |
| 480 | |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 481 | // Whether the extension is a theme - if it is, certain things are disabled. |
| 482 | bool is_theme_; |
[email protected] | 07c00d99 | 2009-03-04 20:27:04 | [diff] [blame] | 483 | |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 484 | // The set of module-level APIs this extension can use. |
| 485 | std::vector<std::string> api_permissions_; |
| 486 | |
[email protected] | c6463165 | 2009-04-29 22:24:31 | [diff] [blame] | 487 | // The sites this extension has permission to talk to (using XHR, etc). |
[email protected] | b30e0dd | 2010-01-29 23:33:21 | [diff] [blame] | 488 | URLPatternList host_permissions_; |
[email protected] | 7197f499 | 2009-03-23 05:05:49 | [diff] [blame] | 489 | |
[email protected] | c3e3def74 | 2009-07-17 07:51:06 | [diff] [blame] | 490 | // The paths to the icons the extension contains mapped by their width. |
| 491 | std::map<int, std::string> icons_; |
| 492 | |
[email protected] | b29682ba2 | 2009-06-18 19:53:56 | [diff] [blame] | 493 | // URL for fetching an update manifest |
| 494 | GURL update_url_; |
[email protected] | d6336a9 | 2009-08-13 17:25:12 | [diff] [blame] | 495 | |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 496 | // A copy of the manifest that this extension was created from. |
| 497 | scoped_ptr<DictionaryValue> manifest_value_; |
| 498 | |
[email protected] | 9428edc | 2009-11-18 18:02:47 | [diff] [blame] | 499 | // Default locale for fall back. Can be empty if extension is not localized. |
| 500 | std::string default_locale_; |
| 501 | |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 502 | // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs |
| 503 | // which override the handling of those URLs. |
[email protected] | d3cfa48 | 2009-10-17 13:54:57 | [diff] [blame] | 504 | URLOverrideMap chrome_url_overrides_; |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 505 | |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 506 | // Whether apps-related features can be parsed during InitFromValue(). |
| 507 | // Defaults to the value from --enable-extension-apps. |
| 508 | bool apps_enabled_; |
[email protected] | 581b0ad | 2010-01-12 21:54:38 | [diff] [blame] | 509 | |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 510 | // Whether the extension can contain live web content. Defaults to false. |
| 511 | bool web_content_enabled_; |
[email protected] | 3b35564 | 2010-02-05 16:01:49 | [diff] [blame] | 512 | |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 513 | // Defines the set of URLs in the extension's web content. |
| 514 | ExtensionExtent web_extent_; |
[email protected] | 3b35564 | 2010-02-05 16:01:49 | [diff] [blame] | 515 | |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 516 | // The local path inside the extension to use with the launcher. |
| 517 | std::string launch_local_path_; |
| 518 | |
| 519 | // A web url to use with the launcher. Note that this might be relative or |
| 520 | // absolute. If relative, it is relative to web_origin_. |
| 521 | std::string launch_web_url_; |
| 522 | |
| 523 | // The type of container to launch into. |
| 524 | LaunchContainer launch_container_; |
| 525 | |
[email protected] | bbadaa78 | 2010-04-28 21:21:53 | [diff] [blame] | 526 | // Launch full screen by default. |
| 527 | bool launch_fullscreen_; |
| 528 | |
[email protected] | d9ad80f | 2010-03-30 20:40:18 | [diff] [blame] | 529 | // Cached images for this extension. This maps from the relative_path of the |
| 530 | // resource to the cached image. |
| 531 | ImageCache image_cache_; |
[email protected] | ceefd3d | 2010-03-12 09:10:29 | [diff] [blame] | 532 | |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 533 | // The omnibox keyword for this extension, or empty if there is none. |
| 534 | std::string omnibox_keyword_; |
| 535 | |
[email protected] | e95ad33 | 2009-08-03 19:44:25 | [diff] [blame] | 536 | // Runtime data: |
| 537 | |
| 538 | // True if the background page is ready. |
| 539 | bool background_page_ready_; |
[email protected] | b29682ba2 | 2009-06-18 19:53:56 | [diff] [blame] | 540 | |
[email protected] | 1e8c93f | 2010-02-08 22:58:31 | [diff] [blame] | 541 | // True while the extension is being upgraded. |
| 542 | bool being_upgraded_; |
| 543 | |
[email protected] | ae7fe71 | 2009-07-02 20:33:58 | [diff] [blame] | 544 | FRIEND_TEST(ExtensionTest, LoadPageActionHelper); |
[email protected] | 3b35564 | 2010-02-05 16:01:49 | [diff] [blame] | 545 | FRIEND_TEST(TabStripModelTest, Apps); |
[email protected] | 4488e65f | 2010-06-06 04:49:53 | [diff] [blame^] | 546 | FRIEND_TEST(TabStripModelTest, ToolbarVisibility); |
[email protected] | ae7fe71 | 2009-07-02 20:33:58 | [diff] [blame] | 547 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 548 | DISALLOW_COPY_AND_ASSIGN(Extension); |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 549 | }; |
| 550 | |
[email protected] | b1748b1d8 | 2009-11-30 20:32:56 | [diff] [blame] | 551 | typedef std::vector<Extension*> ExtensionList; |
| 552 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 553 | // Handy struct to pass core extension info around. |
| 554 | struct ExtensionInfo { |
| 555 | ExtensionInfo(const DictionaryValue* manifest, |
| 556 | const std::string& id, |
| 557 | const FilePath& path, |
| 558 | Extension::Location location) |
| 559 | : extension_id(id), |
| 560 | extension_path(path), |
| 561 | extension_location(location) { |
| 562 | if (manifest) |
| 563 | extension_manifest.reset( |
| 564 | static_cast<DictionaryValue*>(manifest->DeepCopy())); |
| 565 | } |
| 566 | |
| 567 | scoped_ptr<DictionaryValue> extension_manifest; |
| 568 | std::string extension_id; |
| 569 | FilePath extension_path; |
| 570 | Extension::Location extension_location; |
| 571 | |
| 572 | private: |
| 573 | DISALLOW_COPY_AND_ASSIGN(ExtensionInfo); |
| 574 | }; |
| 575 | |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 576 | #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |