extension.h revision 201ade2fbba22bfb27ae029f4d23fca6ded109a0
1// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_H_ 6#define CHROME_COMMON_EXTENSIONS_EXTENSION_H_ 7#pragma once 8 9#include <map> 10#include <set> 11#include <string> 12#include <vector> 13 14#include "base/file_path.h" 15#include "base/gtest_prod_util.h" 16#include "base/scoped_ptr.h" 17#include "base/ref_counted.h" 18#include "chrome/common/extensions/extension_constants.h" 19#include "chrome/common/extensions/extension_extent.h" 20#include "chrome/common/extensions/extension_icon_set.h" 21#include "chrome/common/extensions/user_script.h" 22#include "chrome/common/extensions/url_pattern.h" 23#include "gfx/size.h" 24#include "googleurl/src/gurl.h" 25 26class DictionaryValue; 27class ExtensionAction; 28class ExtensionResource; 29class SkBitmap; 30class Version; 31 32// Represents a Chrome extension. 33class Extension : public base::RefCountedThreadSafe<Extension> { 34 public: 35 typedef std::map<const std::string, GURL> URLOverrideMap; 36 typedef std::vector<std::string> ScriptingWhitelist; 37 38 // What an extension was loaded from. 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. 42 enum Location { 43 INVALID, 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). 48 LOAD, // --load-extension. 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. 52 EXTERNAL_PREF_DOWNLOAD, // A crx file from an external directory (via 53 // prefs), installed from an update URL. 54 EXTERNAL_POLICY_DOWNLOAD, // A crx file from an external directory (via 55 // admin policies), installed from an update URL. 56 57 NUM_LOCATIONS 58 }; 59 60 enum State { 61 DISABLED = 0, 62 ENABLED, 63 KILLBIT, // Don't install/upgrade (applies to external extensions only). 64 65 NUM_STATES 66 }; 67 68 enum InstallType { 69 INSTALL_ERROR, 70 DOWNGRADE, 71 REINSTALL, 72 UPGRADE, 73 NEW_INSTALL 74 }; 75 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, 82 EXTENSION_ICON_SMALLISH = 24, 83 EXTENSION_ICON_BITTY = 16, 84 }; 85 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 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 103 // A permission is defined by its |name| (what is used in the manifest), 104 // and the |message_id| that's used by install/update UI. 105 struct Permission { 106 const char* const name; 107 const int message_id; 108 }; 109 110 static scoped_refptr<Extension> Create(const FilePath& path, 111 Location location, 112 const DictionaryValue& value, 113 bool require_key, 114 std::string* error); 115 116 // Return the update url used by gallery/webstore extensions. 117 static GURL GalleryUpdateUrl(bool secure); 118 119 // The install message id for |permission|. Returns 0 if none exists. 120 static int GetPermissionMessageId(const std::string& permission); 121 122 // Returns the full list of permission messages that this extension 123 // should display at install time. 124 std::vector<string16> GetPermissionMessages() const; 125 126 // Returns the distinct hosts that should be displayed in the install UI 127 // for the URL patterns |list|. This discards some of the detail that is 128 // present in the manifest to make it as easy as possible to process by 129 // users. In particular we disregard the scheme and path components of 130 // URLPatterns and de-dupe the result, which includes filtering out common 131 // hosts with differing RCDs. (NOTE: when de-duping hosts with common RCDs, 132 // the first pattern is returned and the rest discarded) 133 static std::vector<std::string> GetDistinctHostsForDisplay( 134 const URLPatternList& list); 135 136 // Compares two URLPatternLists for security equality by returning whether 137 // the URL patterns in |new_list| contain additional distinct hosts compared 138 // to |old_list|. 139 static bool IsElevatedHostList( 140 const URLPatternList& old_list, const URLPatternList& new_list); 141 142 // Icon sizes used by the extension system. 143 static const int kIconSizes[]; 144 145 // Max size (both dimensions) for browser and page actions. 146 static const int kPageActionIconMaxSize; 147 static const int kBrowserActionIconMaxSize; 148 149 // Each permission is a module that the extension is permitted to use. 150 // 151 // NOTE: To add a new permission, define it here, and add an entry to 152 // Extension::kPermissions. 153 static const char kBackgroundPermission[]; 154 static const char kBookmarkPermission[]; 155 static const char kContextMenusPermission[]; 156 static const char kCookiePermission[]; 157 static const char kExperimentalPermission[]; 158 static const char kGeolocationPermission[]; 159 static const char kHistoryPermission[]; 160 static const char kIdlePermission[]; 161 static const char kManagementPermission[]; 162 static const char kNotificationPermission[]; 163 static const char kProxyPermission[]; 164 static const char kTabPermission[]; 165 static const char kUnlimitedStoragePermission[]; 166 static const char kWebstorePrivatePermission[]; 167 168 static const Permission kPermissions[]; 169 static const size_t kNumPermissions; 170 static const char* const kHostedAppPermissionNames[]; 171 static const size_t kNumHostedAppPermissions; 172 173 // The old name for the unlimited storage permission, which is deprecated but 174 // still accepted as meaning the same thing as kUnlimitedStoragePermission. 175 static const char kOldUnlimitedStoragePermission[]; 176 177 // Valid schemes for web extent URLPatterns. 178 static const int kValidWebExtentSchemes; 179 180 // Valid schemes for host permission URLPatterns. 181 static const int kValidHostPermissionSchemes; 182 183 // Returns true if the string is one of the known hosted app permissions (see 184 // kHostedAppPermissionNames). 185 static bool IsHostedAppPermission(const std::string& permission); 186 187 // The name of the manifest inside an extension. 188 static const FilePath::CharType kManifestFilename[]; 189 190 // The name of locale folder inside an extension. 191 static const FilePath::CharType kLocaleFolder[]; 192 193 // The name of the messages file inside an extension. 194 static const FilePath::CharType kMessagesFilename[]; 195 196#if defined(OS_WIN) 197 static const char kExtensionRegistryPath[]; 198#endif 199 200 // The number of bytes in a legal id. 201 static const size_t kIdSize; 202 203 // The mimetype used for extensions. 204 static const char kMimeType[]; 205 206 // Checks to see if the extension has a valid ID. 207 static bool IdIsValid(const std::string& id); 208 209 // Generate an ID for an extension in the given path. 210 static std::string GenerateIdForPath(const FilePath& file_name); 211 212 // Returns true if the specified file is an extension. 213 static bool IsExtension(const FilePath& file_name); 214 215 // Whether the |location| is external or not. 216 static inline bool IsExternalLocation(Location location) { 217 return location == Extension::EXTERNAL_PREF || 218 location == Extension::EXTERNAL_REGISTRY || 219 location == Extension::EXTERNAL_PREF_DOWNLOAD || 220 location == Extension::EXTERNAL_POLICY_DOWNLOAD; 221 } 222 223 // Whether extensions with |location| are auto-updatable or not. 224 static inline bool IsAutoUpdateableLocation(Location location) { 225 // Only internal and external extensions can be autoupdated. 226 return location == Extension::INTERNAL || 227 IsExternalLocation(location); 228 } 229 230 // See HistogramType definition above. 231 HistogramType GetHistogramType() const; 232 233 // Returns an absolute url to a resource inside of an extension. The 234 // |extension_url| argument should be the url() from an Extension object. The 235 // |relative_path| can be untrusted user input. The returned URL will either 236 // be invalid() or a child of |extension_url|. 237 // NOTE: Static so that it can be used from multiple threads. 238 static GURL GetResourceURL(const GURL& extension_url, 239 const std::string& relative_path); 240 GURL GetResourceURL(const std::string& relative_path) const { 241 return GetResourceURL(url(), relative_path); 242 } 243 244 // Returns an extension resource object. |relative_path| should be UTF8 245 // encoded. 246 ExtensionResource GetResource(const std::string& relative_path) const; 247 248 // As above, but with |relative_path| following the file system's encoding. 249 ExtensionResource GetResource(const FilePath& relative_path) const; 250 251 // |input| is expected to be the text of an rsa public or private key. It 252 // tolerates the presence or absence of bracking header/footer like this: 253 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY----- 254 // and may contain newlines. 255 static bool ParsePEMKeyBytes(const std::string& input, std::string* output); 256 257 // Does a simple base64 encoding of |input| into |output|. 258 static bool ProducePEM(const std::string& input, std::string* output); 259 260 // Generates an extension ID from arbitrary input. The same input string will 261 // always generate the same output ID. 262 static bool GenerateId(const std::string& input, std::string* output); 263 264 // Expects base64 encoded |input| and formats into |output| including 265 // the appropriate header & footer. 266 static bool FormatPEMForFileOutput(const std::string input, 267 std::string* output, bool is_public); 268 269 // Determine whether |new_extension| has increased privileges compared to 270 // its previously granted permissions, specified by |granted_apis|, 271 // |granted_extent| and |granted_full_access|. 272 static bool IsPrivilegeIncrease(const bool granted_full_access, 273 const std::set<std::string>& granted_apis, 274 const ExtensionExtent& granted_extent, 275 const Extension* new_extension); 276 277 // Given an extension and icon size, read it if present and decode it into 278 // result. In the browser process, this will DCHECK if not called on the 279 // file thread. To easily load extension images on the UI thread, see 280 // ImageLoadingTracker. 281 static void DecodeIcon(const Extension* extension, 282 Icons icon_size, 283 scoped_ptr<SkBitmap>* result); 284 285 // Given an icon_path and icon size, read it if present and decode it into 286 // result. In the browser process, this will DCHECK if not called on the 287 // file thread. To easily load extension images on the UI thread, see 288 // ImageLoadingTracker. 289 static void DecodeIconFromPath(const FilePath& icon_path, 290 Icons icon_size, 291 scoped_ptr<SkBitmap>* result); 292 293 // Returns the base extension url for a given |extension_id|. 294 static GURL GetBaseURLFromExtensionId(const std::string& extension_id); 295 296 // Returns the url prefix for the extension/apps gallery. Can be set via the 297 // --apps-gallery-url switch. The URL returned will not contain a trailing 298 // slash. Do not use this as a prefix/extent for the store. Instead see 299 // ExtensionsService::GetWebStoreApp or 300 // ExtensionsService::IsDownloadFromGallery 301 static std::string ChromeStoreLaunchURL(); 302 303 // Helper function that consolidates the check for whether the script can 304 // execute into one location. |page_url| is the page that is the candidate 305 // for running the script, |can_execute_script_everywhere| specifies whether 306 // the extension is on the whitelist, |allowed_pages| is a vector of 307 // URLPatterns, listing what access the extension has, |script| is the script 308 // pointer (if content script) and |error| is an optional parameter, which 309 // will receive the error string listing why access was denied. 310 static bool CanExecuteScriptOnPage( 311 const GURL& page_url, 312 bool can_execute_script_everywhere, 313 const std::vector<URLPattern>* allowed_pages, 314 UserScript* script, 315 std::string* error); 316 317 // Adds an extension to the scripting whitelist. Used for testing only. 318 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); 319 320 // Returns true if the extension has the specified API permission. 321 static bool HasApiPermission(const std::set<std::string>& api_permissions, 322 const std::string& function_name); 323 324 // Whether the |effective_host_permissions| and |api_permissions| include 325 // effective access to all hosts. See the non-static version of the method 326 // for more details. 327 static bool HasEffectiveAccessToAllHosts( 328 const ExtensionExtent& effective_host_permissions, 329 const std::set<std::string>& api_permissions); 330 331 bool HasApiPermission(const std::string& function_name) const { 332 return HasApiPermission(this->api_permissions(), function_name); 333 } 334 335 const ExtensionExtent& GetEffectiveHostPermissions() const { 336 return effective_host_permissions_; 337 } 338 339 // Whether or not the extension is allowed permission for a URL pattern from 340 // the manifest. http, https, and chrome://favicon/ is allowed for all 341 // extensions, while component extensions are allowed access to 342 // chrome://resources. 343 bool CanSpecifyHostPermission(const URLPattern& pattern) const; 344 345 // Whether the extension has access to the given URL. 346 bool HasHostPermission(const GURL& url) const; 347 348 // Whether the extension has effective access to all hosts. This is true if 349 // there is a content script that matches all hosts, if there is a host 350 // permission grants access to all hosts (like <all_urls>) or an api 351 // permission that effectively grants access to all hosts (e.g. proxy, 352 // network, etc.) 353 bool HasEffectiveAccessToAllHosts() const; 354 355 // Whether the extension effectively has all permissions (for example, by 356 // having an NPAPI plugin). 357 bool HasFullPermissions() const; 358 359 // Returns the Homepage URL for this extension. If homepage_url was not 360 // specified in the manifest, this returns the Google Gallery URL. For 361 // third-party extensions, this returns a blank GURL. 362 GURL GetHomepageURL() const; 363 364 // Returns a list of paths (relative to the extension dir) for images that 365 // the browser might load (like themes and page action icons). 366 std::set<FilePath> GetBrowserImages() const; 367 368 // Get an extension icon as a resource or URL. 369 ExtensionResource GetIconResource( 370 int size, ExtensionIconSet::MatchType match_type) const; 371 GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const; 372 373 // Gets the fully resolved absolute launch URL. 374 GURL GetFullLaunchURL() const; 375 // Image cache related methods. These are only valid on the UI thread and 376 // not maintained by this class. See ImageLoadingTracker for usage. The 377 // |original_size| parameter should be the size of the image at |source| 378 // before any scaling may have been done to produce the pixels in |image|. 379 void SetCachedImage(const ExtensionResource& source, 380 const SkBitmap& image, 381 const gfx::Size& original_size) const; 382 bool HasCachedImage(const ExtensionResource& source, 383 const gfx::Size& max_size) const; 384 SkBitmap GetCachedImage(const ExtensionResource& source, 385 const gfx::Size& max_size) const; 386 // Returns true if this extension is a COMPONENT extension, or if it is 387 // on the whitelist of extensions that can script all pages. 388 bool CanExecuteScriptEverywhere() const; 389 390 // Returns true if this extension updates itself using the extension 391 // gallery. 392 bool UpdatesFromGallery() const; 393 394 // Accessors: 395 396 const FilePath& path() const { return path_; } 397 const GURL& url() const { return extension_url_; } 398 Location location() const { return location_; } 399 const std::string& id() const { return id_; } 400 const Version* version() const { return version_.get(); } 401 const std::string VersionString() const; 402 const std::string& name() const { return name_; } 403 const std::string& public_key() const { return public_key_; } 404 const std::string& description() const { return description_; } 405 bool converted_from_user_script() const { 406 return converted_from_user_script_; 407 } 408 const UserScriptList& content_scripts() const { return content_scripts_; } 409 ExtensionAction* page_action() const { return page_action_.get(); } 410 ExtensionAction* browser_action() const { return browser_action_.get(); } 411 const std::vector<PluginInfo>& plugins() const { return plugins_; } 412 const GURL& background_url() const { return background_url_; } 413 const GURL& options_url() const { return options_url_; } 414 const GURL& devtools_url() const { return devtools_url_; } 415 const std::vector<GURL>& toolstrips() const { return toolstrips_; } 416 const std::set<std::string>& api_permissions() const { 417 return api_permissions_; 418 } 419 const URLPatternList& host_permissions() const { return host_permissions_; } 420 const GURL& update_url() const { return update_url_; } 421 const ExtensionIconSet& icons() const { return icons_; } 422 const DictionaryValue* manifest_value() const { 423 return manifest_value_.get(); 424 } 425 const std::string default_locale() const { return default_locale_; } 426 const URLOverrideMap& GetChromeURLOverrides() const { 427 return chrome_url_overrides_; 428 } 429 const std::string omnibox_keyword() const { return omnibox_keyword_; } 430 bool incognito_split_mode() const { return incognito_split_mode_; } 431 432 // App-related. 433 bool is_app() const { return is_app_; } 434 bool is_hosted_app() const { return is_app() && !web_extent().is_empty(); } 435 bool is_packaged_app() const { return is_app() && web_extent().is_empty(); } 436 const ExtensionExtent& web_extent() const { return extent_; } 437 const std::string& launch_local_path() const { return launch_local_path_; } 438 const std::string& launch_web_url() const { return launch_web_url_; } 439 extension_misc::LaunchContainer launch_container() const { 440 return launch_container_; 441 } 442 int launch_width() const { return launch_width_; } 443 int launch_height() const { return launch_height_; } 444 445 // Theme-related. 446 bool is_theme() const { return is_theme_; } 447 DictionaryValue* GetThemeImages() const { return theme_images_.get(); } 448 DictionaryValue* GetThemeColors() const {return theme_colors_.get(); } 449 DictionaryValue* GetThemeTints() const { return theme_tints_.get(); } 450 DictionaryValue* GetThemeDisplayProperties() const { 451 return theme_display_properties_.get(); 452 } 453 454 private: 455 friend class base::RefCountedThreadSafe<Extension>; 456 457 // We keep a cache of images loaded from extension resources based on their 458 // path and a string representation of a size that may have been used to 459 // scale it (or the empty string if the image is at its original size). 460 typedef std::pair<FilePath, std::string> ImageCacheKey; 461 typedef std::map<ImageCacheKey, SkBitmap> ImageCache; 462 463 // Normalize the path for use by the extension. On Windows, this will make 464 // sure the drive letter is uppercase. 465 static FilePath MaybeNormalizePath(const FilePath& path); 466 467 // Returns the distinct hosts that can be displayed in the install UI or be 468 // used for privilege comparisons. This discards some of the detail that is 469 // present in the manifest to make it as easy as possible to process by users. 470 // In particular we disregard the scheme and path components of URLPatterns 471 // and de-dupe the result, which includes filtering out common hosts with 472 // differing RCDs. If |include_rcd| is true, then the de-duped result 473 // will be the first full entry, including its RCD. So if the list was 474 // "*.google.co.uk" and "*.google.com", the returned value would just be 475 // "*.google.co.uk". Keeping the RCD in the result is useful for display 476 // purposes when you want to show the user one sample hostname from the list. 477 // If you need to compare two URLPatternLists for security equality, then set 478 // |include_rcd| to false, which will return a result like "*.google.", 479 // regardless of the order of the patterns. 480 static std::vector<std::string> GetDistinctHosts( 481 const URLPatternList& host_patterns, bool include_rcd); 482 483 Extension(const FilePath& path, Location location); 484 ~Extension(); 485 486 // Initialize the extension from a parsed manifest. 487 // Usually, the id of an extension is generated by the "key" property of 488 // its manifest, but if |require_key| is |false|, a temporary ID will be 489 // generated based on the path. 490 bool InitFromValue(const DictionaryValue& value, bool require_key, 491 std::string* error); 492 493 // Helper function for implementing HasCachedImage/GetCachedImage. A return 494 // value of NULL means there is no matching image cached (we allow caching an 495 // empty SkBitmap). 496 SkBitmap* GetCachedImageImpl(const ExtensionResource& source, 497 const gfx::Size& max_size) const; 498 499 // Helper method that loads a UserScript object from a 500 // dictionary in the content_script list of the manifest. 501 bool LoadUserScriptHelper(const DictionaryValue* content_script, 502 int definition_index, 503 std::string* error, 504 UserScript* result); 505 506 // Helper method that loads either the include_globs or exclude_globs list 507 // from an entry in the content_script lists of the manifest. 508 bool LoadGlobsHelper(const DictionaryValue* content_script, 509 int content_script_index, 510 const char* globs_property_name, 511 std::string* error, 512 void(UserScript::*add_method)(const std::string& glob), 513 UserScript *instance); 514 515 // Helpers to load various chunks of the manifest. 516 bool LoadIsApp(const DictionaryValue* manifest, std::string* error); 517 bool LoadExtent(const DictionaryValue* manifest, const char* key, 518 ExtensionExtent* extent, const char* list_error, 519 const char* value_error, std::string* error); 520 bool LoadLaunchContainer(const DictionaryValue* manifest, std::string* error); 521 bool LoadLaunchURL(const DictionaryValue* manifest, std::string* error); 522 bool EnsureNotHybridApp(const DictionaryValue* manifest, std::string* error); 523 524 // Helper method to load an ExtensionAction from the page_action or 525 // browser_action entries in the manifest. 526 ExtensionAction* LoadExtensionActionHelper( 527 const DictionaryValue* extension_action, std::string* error); 528 529 // Calculates the effective host permissions from the permissions and content 530 // script petterns. 531 void InitEffectiveHostPermissions(); 532 533 // Returns true if the extension has more than one "UI surface". For example, 534 // an extension that has a browser action and a page action. 535 bool HasMultipleUISurfaces() const; 536 537 // Figures out if a source contains keys not associated with themes - we 538 // don't want to allow scripts and such to be bundled with themes. 539 bool ContainsNonThemeKeys(const DictionaryValue& source) const; 540 541 // Returns true if the string is one of the known api permissions (see 542 // kPermissions). 543 bool IsAPIPermission(const std::string& permission) const; 544 545 // The set of unique API install messages that the extension has. 546 // NOTE: This only includes messages related to permissions declared in the 547 // "permissions" key in the manifest. Permissions implied from other features 548 // of the manifest, like plugins and content scripts are not included. 549 std::set<string16> GetSimplePermissionMessages() const; 550 551 // The permission message displayed related to the host permissions for 552 // this extension. 553 string16 GetHostPermissionMessage() const; 554 555 // Cached images for this extension. This should only be touched on the UI 556 // thread. 557 mutable ImageCache image_cache_; 558 559 // A persistent, globally unique ID. An extension's ID is used in things 560 // like directory structures and URLs, and is expected to not change across 561 // versions. It is generated as a SHA-256 hash of the extension's public 562 // key, or as a hash of the path in the case of unpacked extensions. 563 std::string id_; 564 565 // The extension's human-readable name. Name is used for display purpose. It 566 // might be wrapped with unicode bidi control characters so that it is 567 // displayed correctly in RTL context. 568 // NOTE: Name is UTF-8 and may contain non-ascii characters. 569 std::string name_; 570 571 // The absolute path to the directory the extension is stored in. 572 FilePath path_; 573 574 // Default locale for fall back. Can be empty if extension is not localized. 575 std::string default_locale_; 576 577 // If true, a separate process will be used for the extension in incognito 578 // mode. 579 bool incognito_split_mode_; 580 581 // Defines the set of URLs in the extension's web content. 582 ExtensionExtent extent_; 583 584 // The set of host permissions that the extension effectively has access to, 585 // which is a merge of host_permissions_ and all of the match patterns in 586 // any content scripts the extension has. This is used to determine which 587 // URLs have the ability to load an extension's resources via embedded 588 // chrome-extension: URLs (see extension_protocols.cc). 589 ExtensionExtent effective_host_permissions_; 590 591 // The set of module-level APIs this extension can use. 592 std::set<std::string> api_permissions_; 593 594 // The icons for the extension. 595 ExtensionIconSet icons_; 596 597 // The base extension url for the extension. 598 GURL extension_url_; 599 600 // The location the extension was loaded from. 601 Location location_; 602 603 // The extension's version. 604 scoped_ptr<Version> version_; 605 606 // An optional longer description of the extension. 607 std::string description_; 608 609 // True if the extension was generated from a user script. (We show slightly 610 // different UI if so). 611 bool converted_from_user_script_; 612 613 // Paths to the content scripts the extension contains. 614 UserScriptList content_scripts_; 615 616 // The extension's page action, if any. 617 scoped_ptr<ExtensionAction> page_action_; 618 619 // The extension's browser action, if any. 620 scoped_ptr<ExtensionAction> browser_action_; 621 622 // Optional list of NPAPI plugins and associated properties. 623 std::vector<PluginInfo> plugins_; 624 625 // Optional URL to a master page of which a single instance should be always 626 // loaded in the background. 627 GURL background_url_; 628 629 // Optional URL to a page for setting options/preferences. 630 GURL options_url_; 631 632 // Optional URL to a devtools extension page. 633 GURL devtools_url_; 634 635 // Optional list of toolstrips and associated properties. 636 std::vector<GURL> toolstrips_; 637 638 // The public key used to sign the contents of the crx package. 639 std::string public_key_; 640 641 // A map of resource id's to relative file paths. 642 scoped_ptr<DictionaryValue> theme_images_; 643 644 // A map of color names to colors. 645 scoped_ptr<DictionaryValue> theme_colors_; 646 647 // A map of color names to colors. 648 scoped_ptr<DictionaryValue> theme_tints_; 649 650 // A map of display properties. 651 scoped_ptr<DictionaryValue> theme_display_properties_; 652 653 // Whether the extension is a theme. 654 bool is_theme_; 655 656 // The sites this extension has permission to talk to (using XHR, etc). 657 URLPatternList host_permissions_; 658 659 // The homepage for this extension. Useful if it is not hosted by Google and 660 // therefore does not have a Gallery URL. 661 GURL homepage_url_; 662 663 // URL for fetching an update manifest 664 GURL update_url_; 665 666 // A copy of the manifest that this extension was created from. 667 scoped_ptr<DictionaryValue> manifest_value_; 668 669 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs 670 // which override the handling of those URLs. (see ExtensionOverrideUI). 671 URLOverrideMap chrome_url_overrides_; 672 673 // Whether this extension uses app features. 674 bool is_app_; 675 676 // The local path inside the extension to use with the launcher. 677 std::string launch_local_path_; 678 679 // A web url to use with the launcher. Note that this might be relative or 680 // absolute. If relative, it is relative to web_origin. 681 std::string launch_web_url_; 682 683 // The type of container to launch into. 684 extension_misc::LaunchContainer launch_container_; 685 686 // The default size of the container when launching. Only respected for 687 // containers like panels and windows. 688 int launch_width_; 689 int launch_height_; 690 691 // The Omnibox keyword for this extension, or empty if there is none. 692 std::string omnibox_keyword_; 693 694 FRIEND_TEST_ALL_PREFIXES(ExtensionsServiceTest, 695 UpdateExtensionPreservesLocation); 696 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper); 697 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueInvalid); 698 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueValid); 699 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueValidNameInRTL); 700 FRIEND_TEST_ALL_PREFIXES(TabStripModelTest, Apps); 701 702 DISALLOW_COPY_AND_ASSIGN(Extension); 703}; 704 705typedef std::vector< scoped_refptr<const Extension> > ExtensionList; 706typedef std::set<std::string> ExtensionIdSet; 707 708// Handy struct to pass core extension info around. 709struct ExtensionInfo { 710 ExtensionInfo(const DictionaryValue* manifest, 711 const std::string& id, 712 const FilePath& path, 713 Extension::Location location); 714 ~ExtensionInfo(); 715 716 scoped_ptr<DictionaryValue> extension_manifest; 717 std::string extension_id; 718 FilePath extension_path; 719 Extension::Location extension_location; 720 721 private: 722 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo); 723}; 724 725// Struct used for the details of the EXTENSION_UNINSTALLED 726// notification. 727struct UninstalledExtensionInfo { 728 explicit UninstalledExtensionInfo(const Extension& extension); 729 ~UninstalledExtensionInfo(); 730 731 std::string extension_id; 732 std::set<std::string> extension_api_permissions; 733 // TODO(akalin): Once we have a unified ExtensionType, replace the 734 // below member variables with a member of that type. 735 bool is_theme; 736 bool is_app; 737 bool converted_from_user_script; 738 GURL update_url; 739}; 740 741#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ 742