[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] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 8 | |
[email protected] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 9 | #include <map> |
[email protected] | facd7a765 | 2009-06-05 23:15:02 | [diff] [blame] | 10 | #include <set> |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 11 | #include <string> |
| 12 | #include <vector> |
| 13 | |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 14 | #include "base/file_path.h" |
[email protected] | 19118d5 | 2010-07-26 22:13:42 | [diff] [blame] | 15 | #include "base/gtest_prod_util.h" |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 16 | #include "base/scoped_ptr.h" |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 17 | #include "base/ref_counted.h" |
[email protected] | d83a560 | 2010-09-16 00:22:48 | [diff] [blame] | 18 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 19 | #include "chrome/common/extensions/extension_extent.h" |
[email protected] | 807871f | 2010-09-16 01:04:48 | [diff] [blame] | 20 | #include "chrome/common/extensions/extension_icon_set.h" |
[email protected] | 42b6f0f8 | 2009-09-18 21:07:39 | [diff] [blame] | 21 | #include "chrome/common/extensions/user_script.h" |
[email protected] | 7197f499 | 2009-03-23 05:05:49 | [diff] [blame] | 22 | #include "chrome/common/extensions/url_pattern.h" |
[email protected] | 052c9270 | 2010-06-25 07:25:52 | [diff] [blame] | 23 | #include "gfx/size.h" |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 24 | #include "googleurl/src/gurl.h" |
| 25 | |
[email protected] | 3bb8499 | 2010-08-26 17:23:46 | [diff] [blame] | 26 | class DictionaryValue; |
[email protected] | 942690b13 | 2010-05-11 06:42:14 | [diff] [blame] | 27 | class ExtensionAction; |
| 28 | class ExtensionResource; |
[email protected] | 1280270 | 2010-07-09 19:43:09 | [diff] [blame] | 29 | class SkBitmap; |
[email protected] | daf66aa | 2010-08-06 06:24:28 | [diff] [blame] | 30 | class Version; |
[email protected] | 942690b13 | 2010-05-11 06:42:14 | [diff] [blame] | 31 | |
[email protected] | f075553 | 2010-06-22 07:27:25 | [diff] [blame] | 32 | // Represents a Chrome extension. |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 33 | class Extension { |
| 34 | public: |
[email protected] | d3cfa48 | 2009-10-17 13:54:57 | [diff] [blame] | 35 | typedef std::map<const std::string, GURL> URLOverrideMap; |
[email protected] | 10fb199 | 2010-10-08 09:00:17 | [diff] [blame] | 36 | typedef std::vector<std::string> ScriptingWhitelist; |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 37 | |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 38 | // What an extension was loaded from. |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 39 | // NOTE: These values are stored as integers in the preferences and used |
| 40 | // in histograms so don't remove or reorder existing items. Just append |
| 41 | // to the end. |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 42 | enum Location { |
| 43 | INVALID, |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 44 | INTERNAL, // A crx file from the internal Extensions directory. |
| 45 | EXTERNAL_PREF, // A crx file from an external directory (via prefs). |
| 46 | EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the |
| 47 | // registry on Windows). |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 48 | LOAD, // --load-extension. |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 49 | COMPONENT, // An integral component of Chrome itself, which |
| 50 | // happens to be implemented as an extension. We don't |
| 51 | // show these in the management UI. |
[email protected] | 04cb754 | 2010-10-25 10:50:06 | [diff] [blame] | 52 | EXTERNAL_PREF_DOWNLOAD, // A crx file from an external directory (via |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 53 | // prefs), installed from an update URL. |
[email protected] | 04cb754 | 2010-10-25 10:50:06 | [diff] [blame] | 54 | EXTERNAL_POLICY_DOWNLOAD, // A crx file from an external directory (via |
| 55 | // admin policies), installed from an update URL. |
| 56 | |
| 57 | NUM_LOCATIONS |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | enum State { |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 61 | DISABLED = 0, |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 62 | ENABLED, |
| 63 | KILLBIT, // Don't install/upgrade (applies to external extensions only). |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 64 | |
| 65 | NUM_STATES |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 66 | }; |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 67 | |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 68 | enum InstallType { |
[email protected] | ab6f2b2 | 2009-07-28 23:28:37 | [diff] [blame] | 69 | INSTALL_ERROR, |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 70 | DOWNGRADE, |
| 71 | REINSTALL, |
| 72 | UPGRADE, |
| 73 | NEW_INSTALL |
| 74 | }; |
| 75 | |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 76 | // NOTE: If you change this list, you should also change kIconSizes in the cc |
| 77 | // file. |
| 78 | enum Icons { |
| 79 | EXTENSION_ICON_LARGE = 128, |
| 80 | EXTENSION_ICON_MEDIUM = 48, |
| 81 | EXTENSION_ICON_SMALL = 32, |
[email protected] | 3938294 | 2010-03-23 15:57:09 | [diff] [blame] | 82 | EXTENSION_ICON_SMALLISH = 24, |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 83 | EXTENSION_ICON_BITTY = 16, |
| 84 | }; |
| 85 | |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 86 | // Type used for UMA_HISTOGRAM_ENUMERATION about extensions. |
| 87 | // Do not change the order of entries or remove entries in this list. |
| 88 | enum HistogramType { |
| 89 | TYPE_UNKNOWN = 0, |
| 90 | TYPE_EXTENSION, |
| 91 | TYPE_THEME, |
| 92 | TYPE_USER_SCRIPT, |
| 93 | TYPE_HOSTED_APP, |
| 94 | TYPE_PACKAGED_APP |
| 95 | }; |
| 96 | |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 97 | // An NPAPI plugin included in the extension. |
| 98 | struct PluginInfo { |
| 99 | FilePath path; // Path to the plugin. |
| 100 | bool is_public; // False if only this extension can load this plugin. |
| 101 | }; |
| 102 | |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 103 | // Contains a subset of the extension's data that doesn't change once |
| 104 | // initialized, and therefore shareable across threads without locking. |
| 105 | struct StaticData : public base::RefCountedThreadSafe<StaticData> { |
| 106 | StaticData(); |
| 107 | |
| 108 | // TODO(mpcomplete): RefCountedThreadSafe does not allow AddRef/Release on |
| 109 | // const objects. I think that is a mistake. Until we can fix that, here's |
| 110 | // a workaround. |
| 111 | void AddRef() const { |
| 112 | const_cast<StaticData*>(this)-> |
| 113 | base::RefCountedThreadSafe<StaticData>::AddRef(); |
| 114 | } |
| 115 | void Release() const { |
| 116 | const_cast<StaticData*>(this)-> |
| 117 | base::RefCountedThreadSafe<StaticData>::Release(); |
| 118 | } |
| 119 | |
| 120 | // A persistent, globally unique ID. An extension's ID is used in things |
| 121 | // like directory structures and URLs, and is expected to not change across |
| 122 | // versions. It is generated as a SHA-256 hash of the extension's public |
| 123 | // key, or as a hash of the path in the case of unpacked extensions. |
| 124 | std::string id; |
| 125 | |
| 126 | // The extension's human-readable name. Name is used for display purpose. It |
| 127 | // might be wrapped with unicode bidi control characters so that it is |
| 128 | // displayed correctly in RTL context. |
| 129 | // NOTE: Name is UTF-8 and may contain non-ascii characters. |
| 130 | std::string name; |
| 131 | |
| 132 | // The absolute path to the directory the extension is stored in. |
| 133 | FilePath path; |
| 134 | |
| 135 | // Default locale for fall back. Can be empty if extension is not localized. |
| 136 | std::string default_locale; |
| 137 | |
| 138 | // If true, a separate process will be used for the extension in incognito |
| 139 | // mode. |
| 140 | bool incognito_split_mode; |
| 141 | |
| 142 | // Defines the set of URLs in the extension's web content. |
| 143 | ExtensionExtent extent; |
| 144 | |
[email protected] | 11540af | 2010-10-14 14:38:00 | [diff] [blame] | 145 | // The set of host permissions that the extension effectively has access to, |
| 146 | // which is a merge of host_permissions_ and all of the match patterns in |
| 147 | // any content scripts the extension has. This is used to determine which |
| 148 | // URLs have the ability to load an extension's resources via embedded |
| 149 | // chrome-extension: URLs (see extension_protocols.cc). |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 150 | ExtensionExtent effective_host_permissions; |
| 151 | |
| 152 | // The set of module-level APIs this extension can use. |
| 153 | std::set<std::string> api_permissions; |
| 154 | |
| 155 | // The icons for the extension. |
| 156 | ExtensionIconSet icons; |
| 157 | |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 158 | // The base extension url for the extension. |
| 159 | GURL extension_url; |
| 160 | |
| 161 | // The location the extension was loaded from. |
| 162 | Location location; |
| 163 | |
| 164 | // The extension's version. |
| 165 | scoped_ptr<Version> version; |
| 166 | |
| 167 | // An optional longer description of the extension. |
| 168 | std::string description; |
| 169 | |
| 170 | // True if the extension was generated from a user script. (We show slightly |
| 171 | // different UI if so). |
| 172 | bool converted_from_user_script; |
| 173 | |
| 174 | // Paths to the content scripts the extension contains. |
| 175 | UserScriptList content_scripts; |
| 176 | |
| 177 | // The extension's page action, if any. |
| 178 | scoped_ptr<ExtensionAction> page_action; |
| 179 | |
| 180 | // The extension's browser action, if any. |
| 181 | scoped_ptr<ExtensionAction> browser_action; |
| 182 | |
| 183 | // Optional list of NPAPI plugins and associated properties. |
| 184 | std::vector<PluginInfo> plugins; |
| 185 | |
| 186 | // Optional URL to a master page of which a single instance should be always |
| 187 | // loaded in the background. |
| 188 | GURL background_url; |
| 189 | |
| 190 | // Optional URL to a page for setting options/preferences. |
| 191 | GURL options_url; |
| 192 | |
| 193 | // Optional URL to a devtools extension page. |
| 194 | GURL devtools_url; |
| 195 | |
| 196 | // Optional list of toolstrips and associated properties. |
| 197 | std::vector<GURL> toolstrips; |
| 198 | |
| 199 | // The public key used to sign the contents of the crx package. |
| 200 | std::string public_key; |
| 201 | |
| 202 | // A map of resource id's to relative file paths. |
| 203 | scoped_ptr<DictionaryValue> theme_images; |
| 204 | |
| 205 | // A map of color names to colors. |
| 206 | scoped_ptr<DictionaryValue> theme_colors; |
| 207 | |
| 208 | // A map of color names to colors. |
| 209 | scoped_ptr<DictionaryValue> theme_tints; |
| 210 | |
| 211 | // A map of display properties. |
| 212 | scoped_ptr<DictionaryValue> theme_display_properties; |
| 213 | |
| 214 | // Whether the extension is a theme. |
| 215 | bool is_theme; |
| 216 | |
| 217 | // The sites this extension has permission to talk to (using XHR, etc). |
| 218 | URLPatternList host_permissions; |
| 219 | |
[email protected] | 37cd64d | 2010-10-25 18:17:58 | [diff] [blame^] | 220 | // The homepage for this extension. Useful if it is not hosted by Google and |
| 221 | // therefore does not have a Gallery URL. |
| 222 | GURL homepage_url; |
| 223 | |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 224 | // URL for fetching an update manifest |
| 225 | GURL update_url; |
| 226 | |
| 227 | // A copy of the manifest that this extension was created from. |
| 228 | scoped_ptr<DictionaryValue> manifest_value; |
| 229 | |
| 230 | // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs |
| 231 | // which override the handling of those URLs. |
| 232 | URLOverrideMap chrome_url_overrides; |
| 233 | |
| 234 | // Whether this extension uses app features. |
| 235 | bool is_app; |
| 236 | |
| 237 | // The local path inside the extension to use with the launcher. |
| 238 | std::string launch_local_path; |
| 239 | |
| 240 | // A web url to use with the launcher. Note that this might be relative or |
| 241 | // absolute. If relative, it is relative to web_origin. |
| 242 | std::string launch_web_url; |
| 243 | |
| 244 | // The type of container to launch into. |
| 245 | extension_misc::LaunchContainer launch_container; |
| 246 | |
| 247 | // The default size of the container when launching. Only respected for |
| 248 | // containers like panels and windows. |
| 249 | int launch_width; |
| 250 | int launch_height; |
| 251 | |
| 252 | // The Omnibox keyword for this extension, or empty if there is none. |
| 253 | std::string omnibox_keyword; |
| 254 | |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 255 | protected: |
| 256 | friend class base::RefCountedThreadSafe<StaticData>; |
| 257 | ~StaticData(); |
| 258 | }; |
| 259 | |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 260 | // Contains the subset of the extension's (private) data that can be modified |
| 261 | // after initialization. This class should only be accessed on the UI thread. |
| 262 | struct RuntimeData { |
| 263 | // We keep a cache of images loaded from extension resources based on their |
| 264 | // path and a string representation of a size that may have been used to |
| 265 | // scale it (or the empty string if the image is at its original size). |
| 266 | typedef std::pair<FilePath, std::string> ImageCacheKey; |
| 267 | typedef std::map<ImageCacheKey, SkBitmap> ImageCache; |
| 268 | |
| 269 | RuntimeData(); |
| 270 | ~RuntimeData(); |
| 271 | |
| 272 | // True if the background page is ready. |
| 273 | bool background_page_ready; |
| 274 | |
| 275 | // True while the extension is being upgraded. |
| 276 | bool being_upgraded; |
| 277 | |
| 278 | // Cached images for this extension. |
| 279 | ImageCache image_cache_; |
| 280 | }; |
| 281 | |
[email protected] | 0df165f | 2010-09-28 16:49:40 | [diff] [blame] | 282 | // A permission is defined by its |name| (what is used in the manifest), |
| 283 | // and the |message_id| that's used by install/update UI. |
| 284 | struct Permission { |
| 285 | const char* const name; |
| 286 | const int message_id; |
| 287 | }; |
| 288 | |
| 289 | // The install message id for |permission|. Returns 0 if none exists. |
| 290 | static int GetPermissionMessageId(const std::string& permission); |
| 291 | |
[email protected] | a2a098d | 2010-09-29 19:42:55 | [diff] [blame] | 292 | // Returns the full list of permission messages that this extension |
| 293 | // should display at install time. |
| 294 | std::vector<string16> GetPermissionMessages(); |
| 295 | |
| 296 | // Returns the distinct hosts that should be displayed in the install UI. This |
| 297 | // discards some of the detail that is present in the manifest to make it as |
| 298 | // easy as possible to process by users. In particular we disregard the scheme |
| 299 | // and path components of URLPatterns and de-dupe the result. |
| 300 | static std::vector<std::string> GetDistinctHosts( |
| 301 | const URLPatternList& host_patterns); |
| 302 | std::vector<std::string> GetDistinctHosts(); |
[email protected] | 0df165f | 2010-09-28 16:49:40 | [diff] [blame] | 303 | |
[email protected] | c3e3def74 | 2009-07-17 07:51:06 | [diff] [blame] | 304 | // Icon sizes used by the extension system. |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 305 | static const int kIconSizes[]; |
[email protected] | c3e3def74 | 2009-07-17 07:51:06 | [diff] [blame] | 306 | |
[email protected] | 4c4f819 | 2009-10-17 01:03:26 | [diff] [blame] | 307 | // Max size (both dimensions) for browser and page actions. |
| 308 | static const int kPageActionIconMaxSize; |
| 309 | static const int kBrowserActionIconMaxSize; |
| 310 | |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 311 | // Each permission is a module that the extension is permitted to use. |
[email protected] | 218990c | 2010-06-26 01:21:07 | [diff] [blame] | 312 | // |
[email protected] | 0df165f | 2010-09-28 16:49:40 | [diff] [blame] | 313 | // NOTE: To add a new permission, define it here, and add an entry to |
| 314 | // Extension::kPermissions. |
[email protected] | 9dcf8f1 | 2010-09-02 20:39:19 | [diff] [blame] | 315 | static const char kBackgroundPermission[]; |
| 316 | static const char kBookmarkPermission[]; |
| 317 | static const char kContextMenusPermission[]; |
| 318 | static const char kCookiePermission[]; |
| 319 | static const char kExperimentalPermission[]; |
| 320 | static const char kGeolocationPermission[]; |
| 321 | static const char kHistoryPermission[]; |
| 322 | static const char kIdlePermission[]; |
[email protected] | eb25577 | 2010-10-04 22:10:46 | [diff] [blame] | 323 | static const char kManagementPermission[]; |
[email protected] | 9dcf8f1 | 2010-09-02 20:39:19 | [diff] [blame] | 324 | static const char kNotificationPermission[]; |
| 325 | static const char kProxyPermission[]; |
| 326 | static const char kTabPermission[]; |
| 327 | static const char kUnlimitedStoragePermission[]; |
[email protected] | 9dcf8f1 | 2010-09-02 20:39:19 | [diff] [blame] | 328 | static const char kWebstorePrivatePermission[]; |
[email protected] | aeb53b3 | 2009-10-29 07:34:45 | [diff] [blame] | 329 | |
[email protected] | 0df165f | 2010-09-28 16:49:40 | [diff] [blame] | 330 | static const Permission kPermissions[]; |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 331 | static const size_t kNumPermissions; |
[email protected] | 9dcf8f1 | 2010-09-02 20:39:19 | [diff] [blame] | 332 | static const char* const kHostedAppPermissionNames[]; |
[email protected] | b746f37 | 2010-08-29 21:39:32 | [diff] [blame] | 333 | static const size_t kNumHostedAppPermissions; |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 334 | |
[email protected] | 03b612f | 2010-08-13 21:09:21 | [diff] [blame] | 335 | // The old name for the unlimited storage permission, which is deprecated but |
| 336 | // still accepted as meaning the same thing as kUnlimitedStoragePermission. |
[email protected] | 9dcf8f1 | 2010-09-02 20:39:19 | [diff] [blame] | 337 | static const char kOldUnlimitedStoragePermission[]; |
[email protected] | 03b612f | 2010-08-13 21:09:21 | [diff] [blame] | 338 | |
[email protected] | b746f37 | 2010-08-29 21:39:32 | [diff] [blame] | 339 | // Returns true if the string is one of the known hosted app permissions (see |
| 340 | // kHostedAppPermissionNames). |
| 341 | static bool IsHostedAppPermission(const std::string& permission); |
| 342 | |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 343 | // The name of the manifest inside an extension. |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 344 | static const FilePath::CharType kManifestFilename[]; |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 345 | |
[email protected] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 346 | // The name of locale folder inside an extension. |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 347 | static const FilePath::CharType kLocaleFolder[]; |
[email protected] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 348 | |
| 349 | // The name of the messages file inside an extension. |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 350 | static const FilePath::CharType kMessagesFilename[]; |
[email protected] | 300cc58db | 2009-08-19 20:45:14 | [diff] [blame] | 351 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 352 | #if defined(OS_WIN) |
[email protected] | 9dcf8f1 | 2010-09-02 20:39:19 | [diff] [blame] | 353 | static const char kExtensionRegistryPath[]; |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 354 | #endif |
| 355 | |
[email protected] | 37eeb5a | 2009-02-26 23:36:17 | [diff] [blame] | 356 | // The number of bytes in a legal id. |
[email protected] | fe0e782 | 2009-02-26 23:51:48 | [diff] [blame] | 357 | static const size_t kIdSize; |
[email protected] | 37eeb5a | 2009-02-26 23:36:17 | [diff] [blame] | 358 | |
[email protected] | e435d6b7 | 2009-07-25 03:15:58 | [diff] [blame] | 359 | // The mimetype used for extensions. |
| 360 | static const char kMimeType[]; |
| 361 | |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 362 | explicit Extension(const FilePath& path); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 363 | virtual ~Extension(); |
| 364 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 365 | // Checks to see if the extension has a valid ID. |
| 366 | static bool IdIsValid(const std::string& id); |
| 367 | |
[email protected] | 4ead6f7 | 2010-10-13 19:54:18 | [diff] [blame] | 368 | // Generate an ID for an extension in the given path. |
| 369 | static std::string GenerateIdForPath(const FilePath& file_name); |
| 370 | |
[email protected] | e435d6b7 | 2009-07-25 03:15:58 | [diff] [blame] | 371 | // Returns true if the specified file is an extension. |
| 372 | static bool IsExtension(const FilePath& file_name); |
| 373 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 374 | // Whether the |location| is external or not. |
| 375 | static inline bool IsExternalLocation(Location location) { |
| 376 | return location == Extension::EXTERNAL_PREF || |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 377 | location == Extension::EXTERNAL_REGISTRY || |
[email protected] | 04cb754 | 2010-10-25 10:50:06 | [diff] [blame] | 378 | location == Extension::EXTERNAL_PREF_DOWNLOAD || |
| 379 | location == Extension::EXTERNAL_POLICY_DOWNLOAD; |
| 380 | } |
| 381 | |
| 382 | // Whether extensions with |location| are auto-updatable or not. |
| 383 | static inline bool IsAutoUpdateableLocation(Location location) { |
| 384 | // Only internal and external extensions can be autoupdated. |
| 385 | return location == Extension::INTERNAL || |
| 386 | IsExternalLocation(location); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 387 | } |
| 388 | |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 389 | // See HistogramType definition above. |
| 390 | HistogramType GetHistogramType(); |
| 391 | |
[email protected] | 07c00d99 | 2009-03-04 20:27:04 | [diff] [blame] | 392 | // Returns an absolute url to a resource inside of an extension. The |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 393 | // |extension_url| argument should be the url() from an Extension object. The |
| 394 | // |relative_path| can be untrusted user input. The returned URL will either |
| 395 | // be invalid() or a child of |extension_url|. |
| 396 | // NOTE: Static so that it can be used from multiple threads. |
| 397 | static GURL GetResourceURL(const GURL& extension_url, |
| 398 | const std::string& relative_path); |
[email protected] | cffd789 | 2010-08-26 17:43:28 | [diff] [blame] | 399 | GURL GetResourceURL(const std::string& relative_path) const { |
[email protected] | 3cfbd0e | 2009-03-18 21:26:24 | [diff] [blame] | 400 | return GetResourceURL(url(), relative_path); |
| 401 | } |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 402 | |
[email protected] | 99efb7b1 | 2009-12-18 02:39:16 | [diff] [blame] | 403 | // Returns an extension resource object. |relative_path| should be UTF8 |
| 404 | // encoded. |
| 405 | ExtensionResource GetResource(const std::string& relative_path); |
| 406 | |
| 407 | // As above, but with |relative_path| following the file system's encoding. |
| 408 | ExtensionResource GetResource(const FilePath& relative_path); |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 409 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 410 | // |input| is expected to be the text of an rsa public or private key. It |
| 411 | // tolerates the presence or absence of bracking header/footer like this: |
| 412 | // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY----- |
| 413 | // and may contain newlines. |
| 414 | static bool ParsePEMKeyBytes(const std::string& input, std::string* output); |
| 415 | |
| 416 | // Does a simple base64 encoding of |input| into |output|. |
| 417 | static bool ProducePEM(const std::string& input, std::string* output); |
| 418 | |
[email protected] | 84ac7f3 | 2009-10-06 06:17:54 | [diff] [blame] | 419 | // Generates an extension ID from arbitrary input. The same input string will |
| 420 | // always generate the same output ID. |
| 421 | static bool GenerateId(const std::string& input, std::string* output); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 422 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 423 | // Expects base64 encoded |input| and formats into |output| including |
| 424 | // the appropriate header & footer. |
| 425 | static bool FormatPEMForFileOutput(const std::string input, |
| 426 | std::string* output, bool is_public); |
| 427 | |
[email protected] | 2a40953 | 2009-08-28 19:39:44 | [diff] [blame] | 428 | // Determine whether |new_extension| has increased privileges compared to |
| 429 | // |old_extension|. |
| 430 | static bool IsPrivilegeIncrease(Extension* old_extension, |
| 431 | Extension* new_extension); |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 432 | |
[email protected] | c690a981 | 2009-12-17 05:55:32 | [diff] [blame] | 433 | // 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] | 434 | // result. In the browser process, this will DCHECK if not called on the |
| 435 | // file thread. To easily load extension images on the UI thread, see |
| 436 | // ImageLoadingTracker. |
[email protected] | c690a981 | 2009-12-17 05:55:32 | [diff] [blame] | 437 | static void DecodeIcon(Extension* extension, |
| 438 | Icons icon_size, |
| 439 | scoped_ptr<SkBitmap>* result); |
| 440 | |
| 441 | // 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] | 442 | // result. In the browser process, this will DCHECK if not called on the |
| 443 | // file thread. To easily load extension images on the UI thread, see |
| 444 | // ImageLoadingTracker. |
[email protected] | c690a981 | 2009-12-17 05:55:32 | [diff] [blame] | 445 | static void DecodeIconFromPath(const FilePath& icon_path, |
| 446 | Icons icon_size, |
| 447 | scoped_ptr<SkBitmap>* result); |
| 448 | |
[email protected] | a807bbe | 2010-04-14 10:51:19 | [diff] [blame] | 449 | // Returns the base extension url for a given |extension_id|. |
| 450 | static GURL GetBaseURLFromExtensionId(const std::string& extension_id); |
| 451 | |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 452 | // Returns the url prefix for the extension/apps gallery. Can be set via the |
[email protected] | ce3eb7b6 | 2010-09-14 13:57:44 | [diff] [blame] | 453 | // --apps-gallery-url switch. The URL returned will not contain a trailing |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 454 | // slash. Do not use this as a prefix/extent for the store. Instead see |
| 455 | // ExtensionsService::GetWebStoreApp or |
| 456 | // ExtensionsService::IsDownloadFromGallery |
| 457 | static std::string ChromeStoreLaunchURL(); |
[email protected] | a0cf04a | 2010-06-23 03:29:55 | [diff] [blame] | 458 | |
[email protected] | be7e5cb | 2010-10-04 12:53:17 | [diff] [blame] | 459 | // Helper function that consolidates the check for whether the script can |
| 460 | // execute into one location. |page_url| is the page that is the candidate |
| 461 | // for running the script, |can_execute_script_everywhere| specifies whether |
| 462 | // the extension is on the whitelist, |allowed_pages| is a vector of |
| 463 | // URLPatterns, listing what access the extension has, |script| is the script |
| 464 | // pointer (if content script) and |error| is an optional parameter, which |
| 465 | // will receive the error string listing why access was denied. |
| 466 | static bool CanExecuteScriptOnPage( |
| 467 | const GURL& page_url, |
| 468 | bool can_execute_script_everywhere, |
| 469 | const std::vector<URLPattern>* allowed_pages, |
| 470 | UserScript* script, |
| 471 | std::string* error); |
| 472 | |
| 473 | // Adds an extension to the scripting whitelist. Used for testing only. |
[email protected] | 10fb199 | 2010-10-08 09:00:17 | [diff] [blame] | 474 | static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); |
[email protected] | be7e5cb | 2010-10-04 12:53:17 | [diff] [blame] | 475 | |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 476 | // Initialize the extension from a parsed manifest. |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 477 | // Usually, the id of an extension is generated by the "key" property of |
| 478 | // its manifest, but if |require_key| is |false|, a temporary ID will be |
| 479 | // generated based on the path. |
| 480 | bool InitFromValue(const DictionaryValue& value, bool require_key, |
[email protected] | 5bfb1eb0a | 2009-04-08 18:33:30 | [diff] [blame] | 481 | std::string* error); |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 482 | |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 483 | const StaticData* static_data() const { return static_data_; } |
| 484 | |
| 485 | const FilePath& path() const { return static_data_->path; } |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 486 | const GURL& url() const { return static_data_->extension_url; } |
| 487 | Location location() const { return static_data_->location; } |
| 488 | void set_location(Location location) { |
| 489 | mutable_static_data_->location = location; |
| 490 | } |
| 491 | |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 492 | const std::string& id() const { return static_data_->id; } |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 493 | const Version* version() const { return static_data_->version.get(); } |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 494 | // String representation of the version number. |
| 495 | const std::string VersionString() const; |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 496 | const std::string& name() const { return static_data_->name; } |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 497 | const std::string& public_key() const { return static_data_->public_key; } |
| 498 | const std::string& description() const { return static_data_->description; } |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 499 | bool converted_from_user_script() const { |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 500 | return static_data_->converted_from_user_script; |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 501 | } |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 502 | const UserScriptList& content_scripts() const { |
| 503 | return static_data_->content_scripts; |
| 504 | } |
| 505 | ExtensionAction* page_action() const { |
| 506 | return static_data_->page_action.get(); |
| 507 | } |
| 508 | ExtensionAction* browser_action() const { |
| 509 | return static_data_->browser_action.get(); |
| 510 | } |
| 511 | const std::vector<PluginInfo>& plugins() const { |
| 512 | return static_data_->plugins; |
| 513 | } |
| 514 | const GURL& background_url() const { return static_data_->background_url; } |
| 515 | const GURL& options_url() const { return static_data_->options_url; } |
| 516 | const GURL& devtools_url() const { return static_data_->devtools_url; } |
| 517 | const std::vector<GURL>& toolstrips() const { |
| 518 | return static_data_->toolstrips; |
| 519 | } |
[email protected] | 0df165f | 2010-09-28 16:49:40 | [diff] [blame] | 520 | const std::set<std::string>& api_permissions() const { |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 521 | return static_data_->api_permissions; |
[email protected] | 3550635 | 2009-08-07 18:58:19 | [diff] [blame] | 522 | } |
[email protected] | b30e0dd | 2010-01-29 23:33:21 | [diff] [blame] | 523 | const URLPatternList& host_permissions() const { |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 524 | return static_data_->host_permissions; |
[email protected] | c7ad50f | 2009-09-11 06:28:15 | [diff] [blame] | 525 | } |
| 526 | |
[email protected] | aeb53b3 | 2009-10-29 07:34:45 | [diff] [blame] | 527 | // Returns true if the extension has the specified API permission. |
[email protected] | 0df165f | 2010-09-28 16:49:40 | [diff] [blame] | 528 | static bool HasApiPermission(const std::set<std::string>& api_permissions, |
[email protected] | 246c05f | 2010-09-10 09:12:11 | [diff] [blame] | 529 | const std::string& function_name); |
[email protected] | 583d45c1 | 2010-08-31 02:48:12 | [diff] [blame] | 530 | |
[email protected] | 246c05f | 2010-09-10 09:12:11 | [diff] [blame] | 531 | bool HasApiPermission(const std::string& function_name) const { |
| 532 | return HasApiPermission(this->api_permissions(), function_name); |
[email protected] | aeb53b3 | 2009-10-29 07:34:45 | [diff] [blame] | 533 | } |
| 534 | |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 535 | const ExtensionExtent& GetEffectiveHostPermissions() const { |
| 536 | return static_data_->effective_host_permissions; |
| 537 | } |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 538 | |
[email protected] | fbd17cf | 2010-04-28 23:52:56 | [diff] [blame] | 539 | // Whether or not the extension is allowed permission for a URL pattern from |
| 540 | // the manifest. http, https, and chrome://favicon/ is allowed for all |
| 541 | // extensions, while component extensions are allowed access to |
| 542 | // chrome://resources. |
[email protected] | be7e5cb | 2010-10-04 12:53:17 | [diff] [blame] | 543 | bool CanSpecifyHostPermission(const URLPattern pattern) const; |
[email protected] | fbd17cf | 2010-04-28 23:52:56 | [diff] [blame] | 544 | |
[email protected] | 584b8e3f | 2010-04-10 00:23:37 | [diff] [blame] | 545 | // Whether the extension has access to the given URL. |
| 546 | bool HasHostPermission(const GURL& url) const; |
| 547 | |
[email protected] | 0df165f | 2010-09-28 16:49:40 | [diff] [blame] | 548 | // Whether the extension has effective access to all hosts. This is true if |
| 549 | // there is a content script that matches all hosts, if there is a host |
| 550 | // permission grants access to all hosts (like <all_urls>) or an api |
| 551 | // permission that effectively grants access to all hosts (e.g. proxy, |
| 552 | // network, etc.) |
| 553 | bool HasEffectiveAccessToAllHosts() const; |
[email protected] | b24d831 | 2009-08-27 06:47:46 | [diff] [blame] | 554 | |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 555 | const GURL& update_url() const { return static_data_->update_url; } |
[email protected] | 807871f | 2010-09-16 01:04:48 | [diff] [blame] | 556 | |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 557 | const ExtensionIconSet& icons() const { |
| 558 | return static_data_->icons; |
| 559 | } |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 560 | |
[email protected] | 37cd64d | 2010-10-25 18:17:58 | [diff] [blame^] | 561 | // Returns the Homepage URL for this extension. If homepage_url was not |
| 562 | // specified in the manifest, this returns the Google Gallery URL. For |
[email protected] | bfa90a3a | 2010-04-28 15:43:23 | [diff] [blame] | 563 | // third-party extensions, this returns a blank GURL. |
[email protected] | 37cd64d | 2010-10-25 18:17:58 | [diff] [blame^] | 564 | GURL GetHomepageURL() const; |
[email protected] | bfa90a3a | 2010-04-28 15:43:23 | [diff] [blame] | 565 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 566 | // Theme-related. |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 567 | DictionaryValue* GetThemeImages() const { |
| 568 | return static_data_->theme_images.get(); |
[email protected] | 7895ea2 | 2009-06-02 20:53:50 | [diff] [blame] | 569 | } |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 570 | DictionaryValue* GetThemeColors() const { |
| 571 | return static_data_->theme_colors.get(); |
| 572 | } |
| 573 | DictionaryValue* GetThemeTints() const { |
| 574 | return static_data_->theme_tints.get(); |
| 575 | } |
| 576 | DictionaryValue* GetThemeDisplayProperties() const { |
| 577 | return static_data_->theme_display_properties.get(); |
| 578 | } |
| 579 | bool is_theme() const { return static_data_->is_theme; } |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 580 | |
[email protected] | facd7a765 | 2009-06-05 23:15:02 | [diff] [blame] | 581 | // Returns a list of paths (relative to the extension dir) for images that |
| 582 | // the browser might load (like themes and page action icons). |
| 583 | std::set<FilePath> GetBrowserImages(); |
| 584 | |
[email protected] | 807871f | 2010-09-16 01:04:48 | [diff] [blame] | 585 | // Get an extension icon as a resource or URL. |
| 586 | ExtensionResource GetIconResource(int size, |
| 587 | ExtensionIconSet::MatchType match_type); |
| 588 | GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type); |
[email protected] | f34e7963 | 2010-03-17 02:34:08 | [diff] [blame] | 589 | |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 590 | const DictionaryValue* manifest_value() const { |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 591 | return static_data_->manifest_value.get(); |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 592 | } |
| 593 | |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 594 | const std::string default_locale() const { |
| 595 | return static_data_->default_locale; |
| 596 | } |
[email protected] | 9428edc | 2009-11-18 18:02:47 | [diff] [blame] | 597 | |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 598 | // Chrome URL overrides (see ExtensionOverrideUI). |
[email protected] | d3cfa48 | 2009-10-17 13:54:57 | [diff] [blame] | 599 | const URLOverrideMap& GetChromeURLOverrides() const { |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 600 | return static_data_->chrome_url_overrides; |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 601 | } |
| 602 | |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 603 | const std::string omnibox_keyword() const { |
| 604 | return static_data_->omnibox_keyword; |
| 605 | } |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 606 | |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 607 | bool is_app() const { return static_data_->is_app; } |
| 608 | const ExtensionExtent& web_extent() const { |
| 609 | return static_data_->extent; |
| 610 | } |
| 611 | const std::string& launch_local_path() const { |
| 612 | return static_data_->launch_local_path; |
| 613 | } |
| 614 | const std::string& launch_web_url() const { |
| 615 | return static_data_->launch_web_url; |
[email protected] | fe13bf6 | 2010-08-26 14:33:19 | [diff] [blame] | 616 | } |
[email protected] | d83a560 | 2010-09-16 00:22:48 | [diff] [blame] | 617 | extension_misc::LaunchContainer launch_container() const { |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 618 | return static_data_->launch_container; |
[email protected] | d83a560 | 2010-09-16 00:22:48 | [diff] [blame] | 619 | } |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 620 | int launch_width() const { return static_data_->launch_width; } |
| 621 | int launch_height() const { return static_data_->launch_height; } |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 622 | bool incognito_split_mode() const { |
| 623 | return static_data_->incognito_split_mode; |
| 624 | } |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 625 | |
| 626 | // Gets the fully resolved absolute launch URL. |
| 627 | GURL GetFullLaunchURL() const; |
[email protected] | ceefd3d | 2010-03-12 09:10:29 | [diff] [blame] | 628 | |
[email protected] | e95ad33 | 2009-08-03 19:44:25 | [diff] [blame] | 629 | // Whether the background page, if any, is ready. We don't load other |
| 630 | // components until then. If there is no background page, we consider it to |
| 631 | // be ready. |
| 632 | bool GetBackgroundPageReady(); |
| 633 | void SetBackgroundPageReady(); |
| 634 | |
[email protected] | 1e8c93f | 2010-02-08 22:58:31 | [diff] [blame] | 635 | // Getter and setter for the flag that specifies whether the extension is |
| 636 | // being upgraded. |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 637 | bool being_upgraded() const { return GetRuntimeData()->being_upgraded; } |
| 638 | void set_being_upgraded(bool value) { |
| 639 | GetRuntimeData()->being_upgraded = value; |
| 640 | } |
[email protected] | 1e8c93f | 2010-02-08 22:58:31 | [diff] [blame] | 641 | |
[email protected] | d9ad80f | 2010-03-30 20:40:18 | [diff] [blame] | 642 | // Image cache related methods. These are only valid on the UI thread and |
[email protected] | 052c9270 | 2010-06-25 07:25:52 | [diff] [blame] | 643 | // not maintained by this class. See ImageLoadingTracker for usage. The |
| 644 | // |original_size| parameter should be the size of the image at |source| |
| 645 | // before any scaling may have been done to produce the pixels in |image|. |
[email protected] | d9ad80f | 2010-03-30 20:40:18 | [diff] [blame] | 646 | void SetCachedImage(const ExtensionResource& source, |
[email protected] | 052c9270 | 2010-06-25 07:25:52 | [diff] [blame] | 647 | const SkBitmap& image, |
| 648 | const gfx::Size& original_size); |
| 649 | bool HasCachedImage(const ExtensionResource& source, |
| 650 | const gfx::Size& max_size); |
| 651 | SkBitmap GetCachedImage(const ExtensionResource& source, |
| 652 | const gfx::Size& max_size); |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 653 | bool is_hosted_app() const { return is_app() && !web_extent().is_empty(); } |
| 654 | bool is_packaged_app() const { return is_app() && web_extent().is_empty(); } |
| 655 | |
[email protected] | be7e5cb | 2010-10-04 12:53:17 | [diff] [blame] | 656 | // Returns true if this extension is a COMPONENT extension, or if it is |
| 657 | // on the whitelist of extensions that can script all pages. |
| 658 | bool CanExecuteScriptEverywhere() const; |
| 659 | |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 660 | private: |
[email protected] | 4ead6f7 | 2010-10-13 19:54:18 | [diff] [blame] | 661 | // Normalize the path for use by the extension. On Windows, this will make |
| 662 | // sure the drive letter is uppercase. |
| 663 | static FilePath MaybeNormalizePath(const FilePath& path); |
| 664 | |
[email protected] | 052c9270 | 2010-06-25 07:25:52 | [diff] [blame] | 665 | // Helper function for implementing HasCachedImage/GetCachedImage. A return |
| 666 | // value of NULL means there is no matching image cached (we allow caching an |
| 667 | // empty SkBitmap). |
| 668 | SkBitmap* GetCachedImageImpl(const ExtensionResource& source, |
| 669 | const gfx::Size& max_size); |
[email protected] | d9ad80f | 2010-03-30 20:40:18 | [diff] [blame] | 670 | |
[email protected] | 3cfbd0e | 2009-03-18 21:26:24 | [diff] [blame] | 671 | // Helper method that loads a UserScript object from a |
| 672 | // dictionary in the content_script list of the manifest. |
| 673 | bool LoadUserScriptHelper(const DictionaryValue* content_script, |
| 674 | int definition_index, |
| 675 | std::string* error, |
| 676 | UserScript* result); |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 677 | |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 678 | // Helper method that loads either the include_globs or exclude_globs list |
| 679 | // from an entry in the content_script lists of the manifest. |
| 680 | bool LoadGlobsHelper(const DictionaryValue* content_script, |
| 681 | int content_script_index, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 682 | const char* globs_property_name, |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 683 | std::string* error, |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 684 | void(UserScript::*add_method)(const std::string& glob), |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 685 | UserScript *instance); |
| 686 | |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 687 | // Helpers to load various chunks of the manifest. |
[email protected] | 3ba0fd3 | 2010-06-19 05:39:10 | [diff] [blame] | 688 | bool LoadIsApp(const DictionaryValue* manifest, std::string* error); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 689 | bool LoadExtent(const DictionaryValue* manifest, const char* key, |
[email protected] | 4fdbc149 | 2010-07-01 01:20:59 | [diff] [blame] | 690 | ExtensionExtent* extent, const char* list_error, |
| 691 | const char* value_error, std::string* error); |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 692 | bool LoadLaunchContainer(const DictionaryValue* manifest, std::string* error); |
| 693 | bool LoadLaunchURL(const DictionaryValue* manifest, std::string* error); |
[email protected] | cbf4d191 | 2010-08-12 18:24:57 | [diff] [blame] | 694 | bool EnsureNotHybridApp(const DictionaryValue* manifest, std::string* error); |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 695 | |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 696 | // Helper method to load an ExtensionAction from the page_action or |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 697 | // browser_action entries in the manifest. |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 698 | ExtensionAction* LoadExtensionActionHelper( |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 699 | const DictionaryValue* extension_action, std::string* error); |
| 700 | |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 701 | // Calculates the effective host permissions from the permissions and content |
| 702 | // script petterns. |
| 703 | void InitEffectiveHostPermissions(); |
| 704 | |
[email protected] | 2f6698b | 2010-10-14 00:58:21 | [diff] [blame] | 705 | // Returns true if the extension has more than one "UI surface". For example, |
| 706 | // an extension that has a browser action and a page action. |
| 707 | bool HasMultipleUISurfaces() const; |
| 708 | |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 709 | // Figures out if a source contains keys not associated with themes - we |
| 710 | // don't want to allow scripts and such to be bundled with themes. |
| 711 | bool ContainsNonThemeKeys(const DictionaryValue& source); |
| 712 | |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 713 | // Returns true if the string is one of the known api permissions (see |
[email protected] | 0df165f | 2010-09-28 16:49:40 | [diff] [blame] | 714 | // kPermissions). |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 715 | bool IsAPIPermission(const std::string& permission); |
| 716 | |
[email protected] | a2a098d | 2010-09-29 19:42:55 | [diff] [blame] | 717 | // The set of unique API install messages that the extension has. |
| 718 | // NOTE: This only includes messages related to permissions declared in the |
| 719 | // "permissions" key in the manifest. Permissions implied from other features |
| 720 | // of the manifest, like plugins and content scripts are not included. |
| 721 | std::set<string16> GetSimplePermissionMessages(); |
| 722 | |
| 723 | // The permission message displayed related to the host permissions for |
| 724 | // this extension. |
| 725 | string16 GetHostPermissionMessage(); |
| 726 | |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 727 | // Returns a mutable pointer to our runtime data. Can only be called on |
| 728 | // the UI thread. |
| 729 | RuntimeData* GetRuntimeData() const; |
| 730 | |
[email protected] | 4361c7c | 2010-09-30 21:57:53 | [diff] [blame] | 731 | // Collection of extension data that doesn't change doesn't change once an |
| 732 | // Extension object has been initialized. The mutable version is valid only |
| 733 | // until InitFromValue finishes, to ensure we don't accidentally modify it |
| 734 | // post-initialization. |
| 735 | StaticData* mutable_static_data_; |
| 736 | scoped_refptr<const StaticData> static_data_; |
[email protected] | 4a8d327 | 2009-03-10 19:15:08 | [diff] [blame] | 737 | |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 738 | // Runtime data. |
| 739 | scoped_ptr<const RuntimeData> runtime_data_; |
[email protected] | 1e8c93f | 2010-02-08 22:58:31 | [diff] [blame] | 740 | |
[email protected] | 19118d5 | 2010-07-26 22:13:42 | [diff] [blame] | 741 | FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper); |
| 742 | FRIEND_TEST_ALL_PREFIXES(TabStripModelTest, Apps); |
[email protected] | ae7fe71 | 2009-07-02 20:33:58 | [diff] [blame] | 743 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 744 | DISALLOW_COPY_AND_ASSIGN(Extension); |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 745 | }; |
| 746 | |
[email protected] | b1748b1d8 | 2009-11-30 20:32:56 | [diff] [blame] | 747 | typedef std::vector<Extension*> ExtensionList; |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 748 | typedef std::set<std::string> ExtensionIdSet; |
[email protected] | b1748b1d8 | 2009-11-30 20:32:56 | [diff] [blame] | 749 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 750 | // Handy struct to pass core extension info around. |
| 751 | struct ExtensionInfo { |
| 752 | ExtensionInfo(const DictionaryValue* manifest, |
| 753 | const std::string& id, |
| 754 | const FilePath& path, |
[email protected] | 3bb8499 | 2010-08-26 17:23:46 | [diff] [blame] | 755 | Extension::Location location); |
| 756 | ~ExtensionInfo(); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 757 | |
| 758 | scoped_ptr<DictionaryValue> extension_manifest; |
| 759 | std::string extension_id; |
| 760 | FilePath extension_path; |
| 761 | Extension::Location extension_location; |
| 762 | |
| 763 | private: |
| 764 | DISALLOW_COPY_AND_ASSIGN(ExtensionInfo); |
| 765 | }; |
| 766 | |
[email protected] | 21103034 | 2010-09-30 18:41:06 | [diff] [blame] | 767 | // Struct used for the details of the EXTENSION_UNINSTALLED |
| 768 | // notification. |
| 769 | struct UninstalledExtensionInfo { |
| 770 | explicit UninstalledExtensionInfo(const Extension& extension); |
[email protected] | 9b2331d9 | 2010-10-04 23:11:19 | [diff] [blame] | 771 | ~UninstalledExtensionInfo(); |
[email protected] | 21103034 | 2010-09-30 18:41:06 | [diff] [blame] | 772 | |
| 773 | std::string extension_id; |
| 774 | std::set<std::string> extension_api_permissions; |
[email protected] | 76c2511 | 2010-10-01 22:37:21 | [diff] [blame] | 775 | // TODO(akalin): Once we have a unified ExtensionType, replace the |
| 776 | // below member variables with a member of that type. |
| 777 | bool is_theme; |
| 778 | bool is_app; |
| 779 | bool converted_from_user_script; |
| 780 | GURL update_url; |
[email protected] | 21103034 | 2010-09-30 18:41:06 | [diff] [blame] | 781 | }; |
| 782 | |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 783 | #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |