[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 1 | // Copyright (c) 2009 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] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 17 | #include "chrome/browser/extensions/user_script_master.h" |
[email protected] | ba69a7d | 2009-09-28 21:09:56 | [diff] [blame] | 18 | #include "chrome/common/extensions/extension_action.h" |
[email protected] | ecabe6ee | 2009-10-07 22:49:10 | [diff] [blame] | 19 | #include "chrome/common/extensions/extension_resource.h" |
[email protected] | 42b6f0f8 | 2009-09-18 21:07:39 | [diff] [blame] | 20 | #include "chrome/common/extensions/user_script.h" |
[email protected] | 7197f499 | 2009-03-23 05:05:49 | [diff] [blame] | 21 | #include "chrome/common/extensions/url_pattern.h" |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 22 | #include "googleurl/src/gurl.h" |
| 23 | |
[email protected] | c533bb2 | 2009-06-03 19:06:11 | [diff] [blame] | 24 | // Represents a Chrome extension. |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 25 | class Extension { |
| 26 | public: |
[email protected] | b30e0dd | 2010-01-29 23:33:21 | [diff] [blame^] | 27 | typedef std::vector<URLPattern> URLPatternList; |
[email protected] | d3cfa48 | 2009-10-17 13:54:57 | [diff] [blame] | 28 | typedef std::map<const std::string, GURL> URLOverrideMap; |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 29 | |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 30 | // What an extension was loaded from. |
| 31 | enum Location { |
| 32 | INVALID, |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 33 | INTERNAL, // A crx file from the internal Extensions directory. |
| 34 | EXTERNAL_PREF, // A crx file from an external directory (via prefs). |
| 35 | EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the |
| 36 | // registry on Windows). |
| 37 | LOAD // --load-extension. |
| 38 | }; |
| 39 | |
| 40 | enum State { |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 41 | DISABLED = 0, |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 42 | ENABLED, |
| 43 | KILLBIT, // Don't install/upgrade (applies to external extensions only). |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 44 | |
| 45 | NUM_STATES |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 46 | }; |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 47 | |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 48 | enum InstallType { |
[email protected] | ab6f2b2 | 2009-07-28 23:28:37 | [diff] [blame] | 49 | INSTALL_ERROR, |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 50 | DOWNGRADE, |
| 51 | REINSTALL, |
| 52 | UPGRADE, |
| 53 | NEW_INSTALL |
| 54 | }; |
| 55 | |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 56 | // NOTE: If you change this list, you should also change kIconSizes in the cc |
| 57 | // file. |
| 58 | enum Icons { |
| 59 | EXTENSION_ICON_LARGE = 128, |
| 60 | EXTENSION_ICON_MEDIUM = 48, |
| 61 | EXTENSION_ICON_SMALL = 32, |
| 62 | EXTENSION_ICON_BITTY = 16, |
| 63 | }; |
| 64 | |
[email protected] | c3e3def74 | 2009-07-17 07:51:06 | [diff] [blame] | 65 | // Icon sizes used by the extension system. |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 66 | static const int kIconSizes[]; |
[email protected] | c3e3def74 | 2009-07-17 07:51:06 | [diff] [blame] | 67 | |
[email protected] | 4c4f819 | 2009-10-17 01:03:26 | [diff] [blame] | 68 | // Max size (both dimensions) for browser and page actions. |
| 69 | static const int kPageActionIconMaxSize; |
| 70 | static const int kBrowserActionIconMaxSize; |
| 71 | |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 72 | // Each permission is a module that the extension is permitted to use. |
[email protected] | aeb53b3 | 2009-10-29 07:34:45 | [diff] [blame] | 73 | static const char* kTabPermission; |
| 74 | static const char* kBookmarkPermission; |
[email protected] | 0faf2aa8 | 2009-11-24 22:10:49 | [diff] [blame] | 75 | static const char* kNotificationPermission; |
[email protected] | ea99c3a | 2010-01-07 00:40:19 | [diff] [blame] | 76 | static const char* kExperimentalPermission; |
[email protected] | aeb53b3 | 2009-10-29 07:34:45 | [diff] [blame] | 77 | |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 78 | static const char* kPermissionNames[]; |
| 79 | static const size_t kNumPermissions; |
| 80 | |
[email protected] | c533bb2 | 2009-06-03 19:06:11 | [diff] [blame] | 81 | // An NPAPI plugin included in the extension. |
| 82 | struct PluginInfo { |
| 83 | FilePath path; // Path to the plugin. |
| 84 | bool is_public; // False if only this extension can load this plugin. |
| 85 | }; |
| 86 | |
[email protected] | bbc94554 | 2009-07-26 00:11:42 | [diff] [blame] | 87 | // A toolstrip and its associated mole. |
| 88 | struct ToolstripInfo { |
| 89 | ToolstripInfo() : mole_height(0) {} |
| 90 | |
| 91 | GURL toolstrip; |
| 92 | GURL mole; |
| 93 | int mole_height; |
| 94 | }; |
| 95 | |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 96 | // The name of the manifest inside an extension. |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 97 | static const FilePath::CharType kManifestFilename[]; |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 98 | |
[email protected] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 99 | // The name of locale folder inside an extension. |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 100 | static const FilePath::CharType kLocaleFolder[]; |
[email protected] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 101 | |
| 102 | // The name of the messages file inside an extension. |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 103 | static const FilePath::CharType kMessagesFilename[]; |
[email protected] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 104 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 105 | #if defined(OS_WIN) |
| 106 | static const char* kExtensionRegistryPath; |
| 107 | #endif |
| 108 | |
[email protected] | 37eeb5a | 2009-02-26 23:36:17 | [diff] [blame] | 109 | // The number of bytes in a legal id. |
[email protected] | fe0e782 | 2009-02-26 23:51:48 | [diff] [blame] | 110 | static const size_t kIdSize; |
[email protected] | 37eeb5a | 2009-02-26 23:36:17 | [diff] [blame] | 111 | |
[email protected] | e435d6b7 | 2009-07-25 03:15:58 | [diff] [blame] | 112 | // The mimetype used for extensions. |
| 113 | static const char kMimeType[]; |
| 114 | |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 115 | explicit Extension(const FilePath& path); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 116 | virtual ~Extension(); |
| 117 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 118 | // Checks to see if the extension has a valid ID. |
| 119 | static bool IdIsValid(const std::string& id); |
| 120 | |
[email protected] | e435d6b7 | 2009-07-25 03:15:58 | [diff] [blame] | 121 | // Returns true if the specified file is an extension. |
| 122 | static bool IsExtension(const FilePath& file_name); |
| 123 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 124 | // Whether the |location| is external or not. |
| 125 | static inline bool IsExternalLocation(Location location) { |
| 126 | return location == Extension::EXTERNAL_PREF || |
| 127 | location == Extension::EXTERNAL_REGISTRY; |
| 128 | } |
| 129 | |
[email protected] | 07c00d99 | 2009-03-04 20:27:04 | [diff] [blame] | 130 | // Returns an absolute url to a resource inside of an extension. The |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 131 | // |extension_url| argument should be the url() from an Extension object. The |
| 132 | // |relative_path| can be untrusted user input. The returned URL will either |
| 133 | // be invalid() or a child of |extension_url|. |
| 134 | // NOTE: Static so that it can be used from multiple threads. |
| 135 | static GURL GetResourceURL(const GURL& extension_url, |
| 136 | const std::string& relative_path); |
[email protected] | 3cfbd0e | 2009-03-18 21:26:24 | [diff] [blame] | 137 | GURL GetResourceURL(const std::string& relative_path) { |
| 138 | return GetResourceURL(url(), relative_path); |
| 139 | } |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 140 | |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 141 | // Returns an extension resource object. |relative_path| should be UTF8 |
| 142 | // encoded. |
| 143 | ExtensionResource GetResource(const std::string& relative_path); |
| 144 | |
| 145 | // As above, but with |relative_path| following the file system's encoding. |
| 146 | ExtensionResource GetResource(const FilePath& relative_path); |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 147 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 148 | // |input| is expected to be the text of an rsa public or private key. It |
| 149 | // tolerates the presence or absence of bracking header/footer like this: |
| 150 | // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY----- |
| 151 | // and may contain newlines. |
| 152 | static bool ParsePEMKeyBytes(const std::string& input, std::string* output); |
| 153 | |
| 154 | // Does a simple base64 encoding of |input| into |output|. |
| 155 | static bool ProducePEM(const std::string& input, std::string* output); |
| 156 | |
[email protected] | 84ac7f3 | 2009-10-06 06:17:54 | [diff] [blame] | 157 | // Generates an extension ID from arbitrary input. The same input string will |
| 158 | // always generate the same output ID. |
| 159 | static bool GenerateId(const std::string& input, std::string* output); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 160 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 161 | // Expects base64 encoded |input| and formats into |output| including |
| 162 | // the appropriate header & footer. |
| 163 | static bool FormatPEMForFileOutput(const std::string input, |
| 164 | std::string* output, bool is_public); |
| 165 | |
[email protected] | 2a40953 | 2009-08-28 19:39:44 | [diff] [blame] | 166 | // Determine whether |new_extension| has increased privileges compared to |
| 167 | // |old_extension|. |
| 168 | static bool IsPrivilegeIncrease(Extension* old_extension, |
| 169 | Extension* new_extension); |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 170 | |
[email protected] | c690a981 | 2009-12-17 05:55:32 | [diff] [blame] | 171 | // Given an extension and icon size, read it if present and decode it into |
| 172 | // result. |
| 173 | static void DecodeIcon(Extension* extension, |
| 174 | Icons icon_size, |
| 175 | scoped_ptr<SkBitmap>* result); |
| 176 | |
| 177 | // Given an icon_path and icon size, read it if present and decode it into |
| 178 | // result. |
| 179 | static void DecodeIconFromPath(const FilePath& icon_path, |
| 180 | Icons icon_size, |
| 181 | scoped_ptr<SkBitmap>* result); |
| 182 | |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 183 | // Initialize the extension from a parsed manifest. |
[email protected] | 5bfb1eb0a | 2009-04-08 18:33:30 | [diff] [blame] | 184 | // If |require_id| is true, will return an error if the "id" key is missing |
| 185 | // from the value. |
| 186 | bool InitFromValue(const DictionaryValue& value, bool require_id, |
| 187 | std::string* error); |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 188 | |
[email protected] | 8289126 | 2008-12-24 00:21:26 | [diff] [blame] | 189 | const FilePath& path() const { return path_; } |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 190 | void set_path(const FilePath& path) { path_ = path; } |
[email protected] | 5bfb1eb0a | 2009-04-08 18:33:30 | [diff] [blame] | 191 | const GURL& url() const { return extension_url_; } |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 192 | const Location location() const { return location_; } |
| 193 | void set_location(Location location) { location_ = location; } |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 194 | const std::string& id() const { return id_; } |
| 195 | const Version* version() const { return version_.get(); } |
| 196 | // String representation of the version number. |
| 197 | const std::string VersionString() const; |
| 198 | const std::string& name() const { return name_; } |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 199 | const std::string& public_key() const { return public_key_; } |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 200 | const std::string& description() const { return description_; } |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 201 | bool converted_from_user_script() const { |
| 202 | return converted_from_user_script_; |
| 203 | } |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 204 | const UserScriptList& content_scripts() const { return content_scripts_; } |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 205 | ExtensionAction* page_action() const { return page_action_.get(); } |
| 206 | ExtensionAction* browser_action() const { return browser_action_.get(); } |
[email protected] | c533bb2 | 2009-06-03 19:06:11 | [diff] [blame] | 207 | const std::vector<PluginInfo>& plugins() const { return plugins_; } |
[email protected] | c6463165 | 2009-04-29 22:24:31 | [diff] [blame] | 208 | const GURL& background_url() const { return background_url_; } |
[email protected] | 43919ac9 | 2009-10-16 18:34:28 | [diff] [blame] | 209 | const GURL& options_url() const { return options_url_; } |
[email protected] | bbc94554 | 2009-07-26 00:11:42 | [diff] [blame] | 210 | const std::vector<ToolstripInfo>& toolstrips() const { return toolstrips_; } |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 211 | const std::vector<std::string>& api_permissions() const { |
| 212 | return api_permissions_; |
| 213 | } |
[email protected] | b30e0dd | 2010-01-29 23:33:21 | [diff] [blame^] | 214 | const URLPatternList& host_permissions() const { |
[email protected] | c7ad50f | 2009-09-11 06:28:15 | [diff] [blame] | 215 | return host_permissions_; |
| 216 | } |
| 217 | |
| 218 | // Returns true if the extension has permission to access the host for the |
| 219 | // specified URL. |
| 220 | bool CanAccessHost(const GURL& url) const; |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 221 | |
[email protected] | aeb53b3 | 2009-10-29 07:34:45 | [diff] [blame] | 222 | // Returns true if the extension has the specified API permission. |
| 223 | bool HasApiPermission(const std::string& permission) const { |
| 224 | return std::find(api_permissions_.begin(), api_permissions_.end(), |
| 225 | permission) != api_permissions_.end(); |
| 226 | } |
| 227 | |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 228 | // Returns the set of hosts that the extension effectively has access to. This |
| 229 | // is used in the permissions UI and is a combination of the hosts accessible |
| 230 | // through content scripts and the hosts accessible through XHR. |
| 231 | const std::set<std::string> GetEffectiveHostPermissions() const; |
| 232 | |
| 233 | // Whether the extension has access to all hosts. This is true if there is |
| 234 | // a content script that matches all hosts, or if there is a host permission |
| 235 | // for all hosts. |
| 236 | bool HasAccessToAllHosts() const; |
| 237 | |
[email protected] | b29682ba2 | 2009-06-18 19:53:56 | [diff] [blame] | 238 | const GURL& update_url() const { return update_url_; } |
[email protected] | 0cb5f50 | 2009-10-21 21:35:47 | [diff] [blame] | 239 | const std::map<int, std::string>& icons() const { return icons_; } |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 240 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 241 | // Returns the origin of this extension. This function takes a |registry_path| |
| 242 | // so that the registry location can be overwritten during testing. |
| 243 | Location ExternalExtensionInstallType(std::string registry_path); |
| 244 | |
| 245 | // Theme-related. |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 246 | DictionaryValue* GetThemeImages() const { return theme_images_.get(); } |
| 247 | DictionaryValue* GetThemeColors() const { return theme_colors_.get(); } |
| 248 | DictionaryValue* GetThemeTints() const { return theme_tints_.get(); } |
[email protected] | 7895ea2 | 2009-06-02 20:53:50 | [diff] [blame] | 249 | DictionaryValue* GetThemeDisplayProperties() const { |
| 250 | return theme_display_properties_.get(); |
| 251 | } |
[email protected] | 66da08b | 2009-10-19 22:27:00 | [diff] [blame] | 252 | bool IsTheme() const { return is_theme_; } |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 253 | |
[email protected] | facd7a765 | 2009-06-05 23:15:02 | [diff] [blame] | 254 | // Returns a list of paths (relative to the extension dir) for images that |
| 255 | // the browser might load (like themes and page action icons). |
| 256 | std::set<FilePath> GetBrowserImages(); |
| 257 | |
[email protected] | 86693068 | 2009-08-18 22:53:47 | [diff] [blame] | 258 | // Returns an absolute path to the given icon inside of the extension. Returns |
| 259 | // an empty FilePath if the extension does not have that icon. |
[email protected] | ecabe6ee | 2009-10-07 22:49:10 | [diff] [blame] | 260 | ExtensionResource GetIconPath(Icons icon); |
[email protected] | 86693068 | 2009-08-18 22:53:47 | [diff] [blame] | 261 | |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 262 | const DictionaryValue* manifest_value() const { |
| 263 | return manifest_value_.get(); |
| 264 | } |
| 265 | |
[email protected] | 9428edc | 2009-11-18 18:02:47 | [diff] [blame] | 266 | const std::string default_locale() const { return default_locale_; } |
| 267 | |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 268 | // Chrome URL overrides (see ExtensionOverrideUI). |
[email protected] | d3cfa48 | 2009-10-17 13:54:57 | [diff] [blame] | 269 | const URLOverrideMap& GetChromeURLOverrides() const { |
| 270 | return chrome_url_overrides_; |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 271 | } |
| 272 | |
[email protected] | e95ad33 | 2009-08-03 19:44:25 | [diff] [blame] | 273 | // Runtime data: |
| 274 | // Put dynamic data about the state of a running extension below. |
| 275 | |
| 276 | // Whether the background page, if any, is ready. We don't load other |
| 277 | // components until then. If there is no background page, we consider it to |
| 278 | // be ready. |
| 279 | bool GetBackgroundPageReady(); |
| 280 | void SetBackgroundPageReady(); |
| 281 | |
[email protected] | 92bcd16 | 2010-01-15 08:47:48 | [diff] [blame] | 282 | // App stuff. |
[email protected] | b30e0dd | 2010-01-29 23:33:21 | [diff] [blame^] | 283 | const URLPatternList& app_extent() const { return app_extent_; } |
[email protected] | 92bcd16 | 2010-01-15 08:47:48 | [diff] [blame] | 284 | const GURL& app_launch_url() const { return app_launch_url_; } |
| 285 | bool IsApp() const { return !app_launch_url_.is_empty(); } |
[email protected] | 581b0ad | 2010-01-12 21:54:38 | [diff] [blame] | 286 | |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 287 | private: |
[email protected] | 3cfbd0e | 2009-03-18 21:26:24 | [diff] [blame] | 288 | // Helper method that loads a UserScript object from a |
| 289 | // dictionary in the content_script list of the manifest. |
| 290 | bool LoadUserScriptHelper(const DictionaryValue* content_script, |
| 291 | int definition_index, |
| 292 | std::string* error, |
| 293 | UserScript* result); |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 294 | |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 295 | // Helper method that loads either the include_globs or exclude_globs list |
| 296 | // from an entry in the content_script lists of the manifest. |
| 297 | bool LoadGlobsHelper(const DictionaryValue* content_script, |
| 298 | int content_script_index, |
| 299 | const wchar_t* globs_property_name, |
| 300 | std::string* error, |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 301 | void(UserScript::*add_method)(const std::string& glob), |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 302 | UserScript *instance); |
| 303 | |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 304 | // Helper method to load an ExtensionAction from the page_action or |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 305 | // browser_action entries in the manifest. |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 306 | ExtensionAction* LoadExtensionActionHelper( |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 307 | const DictionaryValue* extension_action, std::string* error); |
| 308 | |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 309 | // Figures out if a source contains keys not associated with themes - we |
| 310 | // don't want to allow scripts and such to be bundled with themes. |
| 311 | bool ContainsNonThemeKeys(const DictionaryValue& source); |
| 312 | |
[email protected] | 581b0ad | 2010-01-12 21:54:38 | [diff] [blame] | 313 | // Apps don't have access to all extension features. This enforces those |
| 314 | // restrictions. |
| 315 | bool ContainsNonAppKeys(const DictionaryValue& source); |
| 316 | |
| 317 | // Helper method to verify the app section of the manifest. |
| 318 | bool LoadAppHelper(const DictionaryValue* app, std::string* error); |
| 319 | |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 320 | // The absolute path to the directory the extension is stored in. |
| 321 | FilePath path_; |
| 322 | |
| 323 | // The base extension url for the extension. |
| 324 | GURL extension_url_; |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 325 | |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 326 | // The location the extension was loaded from. |
| 327 | Location location_; |
| 328 | |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 329 | // A human-readable ID for the extension. The convention is to use something |
| 330 | // like 'com.example.myextension', but this is not currently enforced. An |
| 331 | // extension's ID is used in things like directory structures and URLs, and |
| 332 | // is expected to not change across versions. In the case of conflicts, |
| 333 | // updates will only be allowed if the extension can be validated using the |
| 334 | // previous version's update key. |
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 335 | std::string id_; |
[email protected] | 8289126 | 2008-12-24 00:21:26 | [diff] [blame] | 336 | |
[email protected] | 64a02b80 | 2009-01-12 19:36:42 | [diff] [blame] | 337 | // The extension's version. |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 338 | scoped_ptr<Version> version_; |
[email protected] | 64a02b80 | 2009-01-12 19:36:42 | [diff] [blame] | 339 | |
[email protected] | 8289126 | 2008-12-24 00:21:26 | [diff] [blame] | 340 | // The extension's human-readable name. |
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 341 | std::string name_; |
[email protected] | 8289126 | 2008-12-24 00:21:26 | [diff] [blame] | 342 | |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 343 | // An optional longer description of the extension. |
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 344 | std::string description_; |
[email protected] | 8289126 | 2008-12-24 00:21:26 | [diff] [blame] | 345 | |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 346 | // True if the extension was generated from a user script. (We show slightly |
| 347 | // different UI if so). |
| 348 | bool converted_from_user_script_; |
| 349 | |
[email protected] | 8289126 | 2008-12-24 00:21:26 | [diff] [blame] | 350 | // Paths to the content scripts the extension contains. |
[email protected] | 34aa8dc | 2009-02-19 07:03:05 | [diff] [blame] | 351 | UserScriptList content_scripts_; |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 352 | |
[email protected] | 37e960e | 2009-10-13 23:17:50 | [diff] [blame] | 353 | // The extension's page action, if any. |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 354 | scoped_ptr<ExtensionAction> page_action_; |
[email protected] | 671e6c1ce | 2009-09-26 03:18:46 | [diff] [blame] | 355 | |
| 356 | // The extension's browser action, if any. |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 357 | scoped_ptr<ExtensionAction> browser_action_; |
[email protected] | ec9ac0df | 2009-10-01 18:06:47 | [diff] [blame] | 358 | |
[email protected] | c533bb2 | 2009-06-03 19:06:11 | [diff] [blame] | 359 | // Optional list of NPAPI plugins and associated properties. |
| 360 | std::vector<PluginInfo> plugins_; |
[email protected] | 367230c5 | 2009-02-21 01:44:30 | [diff] [blame] | 361 | |
[email protected] | c6463165 | 2009-04-29 22:24:31 | [diff] [blame] | 362 | // Optional URL to a master page of which a single instance should be always |
| 363 | // loaded in the background. |
| 364 | GURL background_url_; |
| 365 | |
[email protected] | 43919ac9 | 2009-10-16 18:34:28 | [diff] [blame] | 366 | // Optional URL to a page for setting options/preferences. |
| 367 | GURL options_url_; |
| 368 | |
[email protected] | bbc94554 | 2009-07-26 00:11:42 | [diff] [blame] | 369 | // Optional list of toolstrips_ and associated properties. |
| 370 | std::vector<ToolstripInfo> toolstrips_; |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 371 | |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 372 | // The public key ('key' in the manifest) used to sign the contents of the |
| 373 | // crx package ('signature' in the manifest) |
| 374 | std::string public_key_; |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 375 | |
[email protected] | 07c00d99 | 2009-03-04 20:27:04 | [diff] [blame] | 376 | // A map of resource id's to relative file paths. |
[email protected] | bbb436f | 2009-05-09 16:51:07 | [diff] [blame] | 377 | scoped_ptr<DictionaryValue> theme_images_; |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 378 | |
| 379 | // A map of color names to colors. |
[email protected] | bbb436f | 2009-05-09 16:51:07 | [diff] [blame] | 380 | scoped_ptr<DictionaryValue> theme_colors_; |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 381 | |
| 382 | // A map of color names to colors. |
[email protected] | bbb436f | 2009-05-09 16:51:07 | [diff] [blame] | 383 | scoped_ptr<DictionaryValue> theme_tints_; |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 384 | |
[email protected] | 7895ea2 | 2009-06-02 20:53:50 | [diff] [blame] | 385 | // A map of display properties. |
| 386 | scoped_ptr<DictionaryValue> theme_display_properties_; |
| 387 | |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 388 | // Whether the extension is a theme - if it is, certain things are disabled. |
| 389 | bool is_theme_; |
[email protected] | 07c00d99 | 2009-03-04 20:27:04 | [diff] [blame] | 390 | |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 391 | // The set of module-level APIs this extension can use. |
| 392 | std::vector<std::string> api_permissions_; |
| 393 | |
[email protected] | c6463165 | 2009-04-29 22:24:31 | [diff] [blame] | 394 | // The sites this extension has permission to talk to (using XHR, etc). |
[email protected] | b30e0dd | 2010-01-29 23:33:21 | [diff] [blame^] | 395 | URLPatternList host_permissions_; |
[email protected] | 7197f499 | 2009-03-23 05:05:49 | [diff] [blame] | 396 | |
[email protected] | c3e3def74 | 2009-07-17 07:51:06 | [diff] [blame] | 397 | // The paths to the icons the extension contains mapped by their width. |
| 398 | std::map<int, std::string> icons_; |
| 399 | |
[email protected] | b29682ba2 | 2009-06-18 19:53:56 | [diff] [blame] | 400 | // URL for fetching an update manifest |
| 401 | GURL update_url_; |
[email protected] | d6336a9 | 2009-08-13 17:25:12 | [diff] [blame] | 402 | |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 403 | // A copy of the manifest that this extension was created from. |
| 404 | scoped_ptr<DictionaryValue> manifest_value_; |
| 405 | |
[email protected] | 9428edc | 2009-11-18 18:02:47 | [diff] [blame] | 406 | // Default locale for fall back. Can be empty if extension is not localized. |
| 407 | std::string default_locale_; |
| 408 | |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 409 | // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs |
| 410 | // which override the handling of those URLs. |
[email protected] | d3cfa48 | 2009-10-17 13:54:57 | [diff] [blame] | 411 | URLOverrideMap chrome_url_overrides_; |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 412 | |
[email protected] | b30e0dd | 2010-01-29 23:33:21 | [diff] [blame^] | 413 | // Describes the space of URLs that are displayed in the app's custom frame. |
| 414 | URLPatternList app_extent_; |
[email protected] | 581b0ad | 2010-01-12 21:54:38 | [diff] [blame] | 415 | |
[email protected] | 92bcd16 | 2010-01-15 08:47:48 | [diff] [blame] | 416 | // The URL an app should launch to. |
| 417 | GURL app_launch_url_; |
| 418 | |
[email protected] | 581b0ad | 2010-01-12 21:54:38 | [diff] [blame] | 419 | |
[email protected] | e95ad33 | 2009-08-03 19:44:25 | [diff] [blame] | 420 | // Runtime data: |
| 421 | |
| 422 | // True if the background page is ready. |
| 423 | bool background_page_ready_; |
[email protected] | b29682ba2 | 2009-06-18 19:53:56 | [diff] [blame] | 424 | |
[email protected] | ae7fe71 | 2009-07-02 20:33:58 | [diff] [blame] | 425 | FRIEND_TEST(ExtensionTest, LoadPageActionHelper); |
| 426 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 427 | DISALLOW_COPY_AND_ASSIGN(Extension); |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 428 | }; |
| 429 | |
[email protected] | b1748b1d8 | 2009-11-30 20:32:56 | [diff] [blame] | 430 | typedef std::vector<Extension*> ExtensionList; |
| 431 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 432 | // Handy struct to pass core extension info around. |
| 433 | struct ExtensionInfo { |
| 434 | ExtensionInfo(const DictionaryValue* manifest, |
| 435 | const std::string& id, |
| 436 | const FilePath& path, |
| 437 | Extension::Location location) |
| 438 | : extension_id(id), |
| 439 | extension_path(path), |
| 440 | extension_location(location) { |
| 441 | if (manifest) |
| 442 | extension_manifest.reset( |
| 443 | static_cast<DictionaryValue*>(manifest->DeepCopy())); |
| 444 | } |
| 445 | |
| 446 | scoped_ptr<DictionaryValue> extension_manifest; |
| 447 | std::string extension_id; |
| 448 | FilePath extension_path; |
| 449 | Extension::Location extension_location; |
| 450 | |
| 451 | private: |
| 452 | DISALLOW_COPY_AND_ASSIGN(ExtensionInfo); |
| 453 | }; |
| 454 | |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 455 | #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |