OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_H_ | 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "base/memory/linked_ptr.h" | 16 #include "base/memory/linked_ptr.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/synchronization/lock.h" |
19 #include "chrome/common/extensions/extension_constants.h" | 20 #include "chrome/common/extensions/extension_constants.h" |
20 #include "chrome/common/extensions/extension_icon_set.h" | 21 #include "chrome/common/extensions/extension_icon_set.h" |
21 #include "chrome/common/extensions/extension_permission_set.h" | 22 #include "chrome/common/extensions/extension_permission_set.h" |
22 #include "chrome/common/extensions/user_script.h" | 23 #include "chrome/common/extensions/user_script.h" |
23 #include "chrome/common/extensions/url_pattern.h" | 24 #include "chrome/common/extensions/url_pattern.h" |
24 #include "chrome/common/extensions/url_pattern_set.h" | 25 #include "chrome/common/extensions/url_pattern_set.h" |
25 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
26 #include "ui/gfx/size.h" | 27 #include "ui/gfx/size.h" |
27 | 28 |
28 class ExtensionAction; | 29 class ExtensionAction; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 std::string* error); | 199 std::string* error); |
199 | 200 |
200 // Return the update url used by gallery/webstore extensions. | 201 // Return the update url used by gallery/webstore extensions. |
201 static GURL GalleryUpdateUrl(bool secure); | 202 static GURL GalleryUpdateUrl(bool secure); |
202 | 203 |
203 // Given two install sources, return the one which should take priority | 204 // Given two install sources, return the one which should take priority |
204 // over the other. If an extension is installed from two sources A and B, | 205 // over the other. If an extension is installed from two sources A and B, |
205 // its install source should be set to GetHigherPriorityLocation(A, B). | 206 // its install source should be set to GetHigherPriorityLocation(A, B). |
206 static Location GetHigherPriorityLocation(Location loc1, Location loc2); | 207 static Location GetHigherPriorityLocation(Location loc1, Location loc2); |
207 | 208 |
208 // Returns the full list of permission messages that this extension | |
209 // should display at install time. | |
210 ExtensionPermissionMessages GetPermissionMessages() const; | |
211 | |
212 // Returns the full list of permission messages that this extension | |
213 // should display at install time. The messages are returned as strings | |
214 // for convenience. | |
215 std::vector<string16> GetPermissionMessageStrings() const; | |
216 | |
217 // Icon sizes used by the extension system. | 209 // Icon sizes used by the extension system. |
218 static const int kIconSizes[]; | 210 static const int kIconSizes[]; |
219 | 211 |
220 // Max size (both dimensions) for browser and page actions. | 212 // Max size (both dimensions) for browser and page actions. |
221 static const int kPageActionIconMaxSize; | 213 static const int kPageActionIconMaxSize; |
222 static const int kBrowserActionIconMaxSize; | 214 static const int kBrowserActionIconMaxSize; |
223 static const int kSidebarIconMaxSize; | 215 static const int kSidebarIconMaxSize; |
224 | 216 |
225 // Valid schemes for web extent URLPatterns. | 217 // Valid schemes for web extent URLPatterns. |
226 static const int kValidWebExtentSchemes; | 218 static const int kValidWebExtentSchemes; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 // --apps-gallery-url switch. The URL returned will not contain a trailing | 356 // --apps-gallery-url switch. The URL returned will not contain a trailing |
365 // slash. Do not use this as a prefix/extent for the store. Instead see | 357 // slash. Do not use this as a prefix/extent for the store. Instead see |
366 // ExtensionService::GetWebStoreApp or | 358 // ExtensionService::GetWebStoreApp or |
367 // ExtensionService::IsDownloadFromGallery | 359 // ExtensionService::IsDownloadFromGallery |
368 static std::string ChromeStoreLaunchURL(); | 360 static std::string ChromeStoreLaunchURL(); |
369 | 361 |
370 // Adds an extension to the scripting whitelist. Used for testing only. | 362 // Adds an extension to the scripting whitelist. Used for testing only. |
371 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); | 363 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); |
372 static const ScriptingWhitelist* GetScriptingWhitelist(); | 364 static const ScriptingWhitelist* GetScriptingWhitelist(); |
373 | 365 |
| 366 // Parses the host and api permissions from the specified permission |key| |
| 367 // in the manifest |source|. |
| 368 bool ParsePermissions(const base::DictionaryValue* source, |
| 369 const char* key, |
| 370 int flags, |
| 371 std::string* error, |
| 372 ExtensionAPIPermissionSet* api_permissions, |
| 373 URLPatternSet* host_permissions); |
| 374 |
374 bool HasAPIPermission(ExtensionAPIPermission::ID permission) const; | 375 bool HasAPIPermission(ExtensionAPIPermission::ID permission) const; |
375 bool HasAPIPermission(const std::string& function_name) const; | 376 bool HasAPIPermission(const std::string& function_name) const; |
376 | 377 |
377 const URLPatternSet& GetEffectiveHostPermissions() const; | 378 const URLPatternSet& GetEffectiveHostPermissions() const; |
378 | 379 |
379 // Whether or not the extension is allowed permission for a URL pattern from | 380 // Whether or not the extension is allowed permission for a URL pattern from |
380 // the manifest. http, https, and chrome://favicon/ is allowed for all | 381 // the manifest. http, https, and chrome://favicon/ is allowed for all |
381 // extensions, while component extensions are allowed access to | 382 // extensions, while component extensions are allowed access to |
382 // chrome://resources. | 383 // chrome://resources. |
383 bool CanSpecifyHostPermission(const URLPattern& pattern) const; | 384 bool CanSpecifyHostPermission(const URLPattern& pattern) const; |
384 | 385 |
385 // Whether the extension has access to the given URL. | 386 // Whether the extension has access to the given URL. |
386 bool HasHostPermission(const GURL& url) const; | 387 bool HasHostPermission(const GURL& url) const; |
387 | 388 |
388 // Whether the extension has effective access to all hosts. This is true if | 389 // Whether the extension has effective access to all hosts. This is true if |
389 // there is a content script that matches all hosts, if there is a host | 390 // there is a content script that matches all hosts, if there is a host |
390 // permission grants access to all hosts (like <all_urls>) or an api | 391 // permission grants access to all hosts (like <all_urls>) or an api |
391 // permission that effectively grants access to all hosts (e.g. proxy, | 392 // permission that effectively grants access to all hosts (e.g. proxy, |
392 // network, etc.) | 393 // network, etc.) |
393 bool HasEffectiveAccessToAllHosts() const; | 394 bool HasEffectiveAccessToAllHosts() const; |
394 | 395 |
395 // Whether the extension effectively has all permissions (for example, by | 396 // Whether the extension effectively has all permissions (for example, by |
396 // having an NPAPI plugin). | 397 // having an NPAPI plugin). |
397 bool HasFullPermissions() const; | 398 bool HasFullPermissions() const; |
398 | 399 |
| 400 // Returns the full list of permission messages that this extension |
| 401 // should display at install time. |
| 402 ExtensionPermissionMessages GetPermissionMessages() const; |
| 403 |
| 404 // Returns the full list of permission messages that this extension |
| 405 // should display at install time. The messages are returned as strings |
| 406 // for convenience. |
| 407 std::vector<string16> GetPermissionMessageStrings() const; |
| 408 |
| 409 // Sets the active |permissions|. |
| 410 void SetActivePermissions(const ExtensionPermissionSet* permissions) const; |
| 411 |
| 412 // Gets the extension's active permission set. |
| 413 scoped_refptr<const ExtensionPermissionSet> GetActivePermissions() const; |
| 414 |
399 // Whether context menu should be shown for page and browser actions. | 415 // Whether context menu should be shown for page and browser actions. |
400 bool ShowConfigureContextMenus() const; | 416 bool ShowConfigureContextMenus() const; |
401 | 417 |
402 // Returns the Homepage URL for this extension. If homepage_url was not | 418 // Returns the Homepage URL for this extension. If homepage_url was not |
403 // specified in the manifest, this returns the Google Gallery URL. For | 419 // specified in the manifest, this returns the Google Gallery URL. For |
404 // third-party extensions, this returns a blank GURL. | 420 // third-party extensions, this returns a blank GURL. |
405 GURL GetHomepageURL() const; | 421 GURL GetHomepageURL() const; |
406 | 422 |
407 // Returns a list of paths (relative to the extension dir) for images that | 423 // Returns a list of paths (relative to the extension dir) for images that |
408 // the browser might load (like themes and page action icons). | 424 // the browser might load (like themes and page action icons). |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 const std::vector<NaClModuleInfo>& nacl_modules() const { | 499 const std::vector<NaClModuleInfo>& nacl_modules() const { |
484 return nacl_modules_; | 500 return nacl_modules_; |
485 } | 501 } |
486 const std::vector<InputComponentInfo>& input_components() const { | 502 const std::vector<InputComponentInfo>& input_components() const { |
487 return input_components_; | 503 return input_components_; |
488 } | 504 } |
489 const GURL& background_url() const { return background_url_; } | 505 const GURL& background_url() const { return background_url_; } |
490 const GURL& options_url() const { return options_url_; } | 506 const GURL& options_url() const { return options_url_; } |
491 const GURL& devtools_url() const { return devtools_url_; } | 507 const GURL& devtools_url() const { return devtools_url_; } |
492 const std::vector<GURL>& toolstrips() const { return toolstrips_; } | 508 const std::vector<GURL>& toolstrips() const { return toolstrips_; } |
493 const ExtensionPermissionSet* permission_set() const { | 509 const ExtensionPermissionSet* optional_permission_set() const { |
494 return permission_set_.get(); | 510 return optional_permission_set_.get(); |
| 511 } |
| 512 const ExtensionPermissionSet* required_permission_set() const { |
| 513 return required_permission_set_.get(); |
495 } | 514 } |
496 const GURL& update_url() const { return update_url_; } | 515 const GURL& update_url() const { return update_url_; } |
497 const ExtensionIconSet& icons() const { return icons_; } | 516 const ExtensionIconSet& icons() const { return icons_; } |
498 const base::DictionaryValue* manifest_value() const { | 517 const base::DictionaryValue* manifest_value() const { |
499 return manifest_value_.get(); | 518 return manifest_value_.get(); |
500 } | 519 } |
501 const std::string default_locale() const { return default_locale_; } | 520 const std::string default_locale() const { return default_locale_; } |
502 const URLOverrideMap& GetChromeURLOverrides() const { | 521 const URLOverrideMap& GetChromeURLOverrides() const { |
503 return chrome_url_overrides_; | 522 return chrome_url_overrides_; |
504 } | 523 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 | 558 |
540 private: | 559 private: |
541 friend class base::RefCountedThreadSafe<Extension>; | 560 friend class base::RefCountedThreadSafe<Extension>; |
542 | 561 |
543 // We keep a cache of images loaded from extension resources based on their | 562 // We keep a cache of images loaded from extension resources based on their |
544 // path and a string representation of a size that may have been used to | 563 // path and a string representation of a size that may have been used to |
545 // scale it (or the empty string if the image is at its original size). | 564 // scale it (or the empty string if the image is at its original size). |
546 typedef std::pair<FilePath, std::string> ImageCacheKey; | 565 typedef std::pair<FilePath, std::string> ImageCacheKey; |
547 typedef std::map<ImageCacheKey, SkBitmap> ImageCache; | 566 typedef std::map<ImageCacheKey, SkBitmap> ImageCache; |
548 | 567 |
| 568 class RuntimeData { |
| 569 public: |
| 570 RuntimeData(); |
| 571 explicit RuntimeData(const ExtensionPermissionSet* active); |
| 572 ~RuntimeData(); |
| 573 |
| 574 void SetActivePermissions(const ExtensionPermissionSet* active); |
| 575 scoped_refptr<const ExtensionPermissionSet> GetActivePermissions() const; |
| 576 |
| 577 private: |
| 578 friend class base::RefCountedThreadSafe<RuntimeData>; |
| 579 scoped_refptr<const ExtensionPermissionSet> active_permissions_; |
| 580 }; |
| 581 |
549 // Normalize the path for use by the extension. On Windows, this will make | 582 // Normalize the path for use by the extension. On Windows, this will make |
550 // sure the drive letter is uppercase. | 583 // sure the drive letter is uppercase. |
551 static FilePath MaybeNormalizePath(const FilePath& path); | 584 static FilePath MaybeNormalizePath(const FilePath& path); |
552 | 585 |
553 // Returns true if this extension id is from a trusted provider. | 586 // Returns true if this extension id is from a trusted provider. |
554 static bool IsTrustedId(const std::string& id); | 587 static bool IsTrustedId(const std::string& id); |
555 | 588 |
556 Extension(const FilePath& path, Location location); | 589 Extension(const FilePath& path, Location location); |
557 ~Extension(); | 590 ~Extension(); |
558 | 591 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 // Default locale for fall back. Can be empty if extension is not localized. | 694 // Default locale for fall back. Can be empty if extension is not localized. |
662 std::string default_locale_; | 695 std::string default_locale_; |
663 | 696 |
664 // If true, a separate process will be used for the extension in incognito | 697 // If true, a separate process will be used for the extension in incognito |
665 // mode. | 698 // mode. |
666 bool incognito_split_mode_; | 699 bool incognito_split_mode_; |
667 | 700 |
668 // Defines the set of URLs in the extension's web content. | 701 // Defines the set of URLs in the extension's web content. |
669 URLPatternSet extent_; | 702 URLPatternSet extent_; |
670 | 703 |
671 // The set of permissions that the extension effectively has access to. | 704 // The extension runtime data. |
672 scoped_ptr<ExtensionPermissionSet> permission_set_; | 705 mutable base::Lock runtime_data_lock_; |
| 706 mutable RuntimeData runtime_data_; |
| 707 |
| 708 // The set of permissions the extension can request at runtime. |
| 709 scoped_ptr<const ExtensionPermissionSet> optional_permission_set_; |
| 710 |
| 711 // The extension's required / default set of permissions. |
| 712 scoped_ptr<const ExtensionPermissionSet> required_permission_set_; |
673 | 713 |
674 // The icons for the extension. | 714 // The icons for the extension. |
675 ExtensionIconSet icons_; | 715 ExtensionIconSet icons_; |
676 | 716 |
677 // The base extension url for the extension. | 717 // The base extension url for the extension. |
678 GURL extension_url_; | 718 GURL extension_url_; |
679 | 719 |
680 // The location the extension was loaded from. | 720 // The location the extension was loaded from. |
681 Location location_; | 721 Location location_; |
682 | 722 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 | 898 |
859 // Was the extension already disabled? | 899 // Was the extension already disabled? |
860 bool already_disabled; | 900 bool already_disabled; |
861 | 901 |
862 // The extension being unloaded - this should always be non-NULL. | 902 // The extension being unloaded - this should always be non-NULL. |
863 const Extension* extension; | 903 const Extension* extension; |
864 | 904 |
865 UnloadedExtensionInfo(const Extension* extension, Reason reason); | 905 UnloadedExtensionInfo(const Extension* extension, Reason reason); |
866 }; | 906 }; |
867 | 907 |
| 908 // The details sent for EXTENSION_PERMISSIONS_UPDATED notifications. |
| 909 struct UpdatedExtensionPermissionsInfo { |
| 910 enum Reason { |
| 911 ADDED, // The permissions were added to the extension. |
| 912 REMOVED, // The permissions were removed from the extension. |
| 913 }; |
| 914 |
| 915 Reason reason; |
| 916 |
| 917 // The extension who's permissions have changed. |
| 918 const Extension* extension; |
| 919 |
| 920 // The permissions that have changed. For Reason::ADDED, this would contain |
| 921 // only the permissions that have added, and for Reason::REMOVED, this would |
| 922 // only contain the removed permissions. |
| 923 const ExtensionPermissionSet* permissions; |
| 924 |
| 925 UpdatedExtensionPermissionsInfo( |
| 926 const Extension* extension, |
| 927 const ExtensionPermissionSet* permissions, |
| 928 Reason reason); |
| 929 }; |
| 930 |
868 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ | 931 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
OLD | NEW |