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