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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 std::string* error); | 203 std::string* error); |
203 | 204 |
204 // Return the update url used by gallery/webstore extensions. | 205 // Return the update url used by gallery/webstore extensions. |
205 static GURL GalleryUpdateUrl(bool secure); | 206 static GURL GalleryUpdateUrl(bool secure); |
206 | 207 |
207 // Given two install sources, return the one which should take priority | 208 // Given two install sources, return the one which should take priority |
208 // over the other. If an extension is installed from two sources A and B, | 209 // over the other. If an extension is installed from two sources A and B, |
209 // its install source should be set to GetHigherPriorityLocation(A, B). | 210 // its install source should be set to GetHigherPriorityLocation(A, B). |
210 static Location GetHigherPriorityLocation(Location loc1, Location loc2); | 211 static Location GetHigherPriorityLocation(Location loc1, Location loc2); |
211 | 212 |
212 // Returns the full list of permission messages that this extension | |
213 // should display at install time. | |
214 ExtensionPermissionMessages GetPermissionMessages() const; | |
215 | |
216 // Returns the full list of permission messages that this extension | |
217 // should display at install time. The messages are returned as strings | |
218 // for convenience. | |
219 std::vector<string16> GetPermissionMessageStrings() const; | |
220 | |
221 // Icon sizes used by the extension system. | 213 // Icon sizes used by the extension system. |
222 static const int kIconSizes[]; | 214 static const int kIconSizes[]; |
223 | 215 |
224 // Max size (both dimensions) for browser and page actions. | 216 // Max size (both dimensions) for browser and page actions. |
225 static const int kPageActionIconMaxSize; | 217 static const int kPageActionIconMaxSize; |
226 static const int kBrowserActionIconMaxSize; | 218 static const int kBrowserActionIconMaxSize; |
227 static const int kSidebarIconMaxSize; | 219 static const int kSidebarIconMaxSize; |
228 | 220 |
229 // Valid schemes for web extent URLPatterns. | 221 // Valid schemes for web extent URLPatterns. |
230 static const int kValidWebExtentSchemes; | 222 static const int kValidWebExtentSchemes; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 // --apps-gallery-url switch. The URL returned will not contain a trailing | 360 // --apps-gallery-url switch. The URL returned will not contain a trailing |
369 // slash. Do not use this as a prefix/extent for the store. Instead see | 361 // slash. Do not use this as a prefix/extent for the store. Instead see |
370 // ExtensionService::GetWebStoreApp or | 362 // ExtensionService::GetWebStoreApp or |
371 // ExtensionService::IsDownloadFromGallery | 363 // ExtensionService::IsDownloadFromGallery |
372 static std::string ChromeStoreLaunchURL(); | 364 static std::string ChromeStoreLaunchURL(); |
373 | 365 |
374 // Adds an extension to the scripting whitelist. Used for testing only. | 366 // Adds an extension to the scripting whitelist. Used for testing only. |
375 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); | 367 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); |
376 static const ScriptingWhitelist* GetScriptingWhitelist(); | 368 static const ScriptingWhitelist* GetScriptingWhitelist(); |
377 | 369 |
| 370 // Parses the host and api permissions from the specified permission |key| |
| 371 // in the manifest |source|. |
| 372 bool ParsePermissions(const base::DictionaryValue* source, |
| 373 const char* key, |
| 374 int flags, |
| 375 std::string* error, |
| 376 ExtensionAPIPermissionSet* api_permissions, |
| 377 URLPatternSet* host_permissions); |
| 378 |
378 bool HasAPIPermission(ExtensionAPIPermission::ID permission) const; | 379 bool HasAPIPermission(ExtensionAPIPermission::ID permission) const; |
379 bool HasAPIPermission(const std::string& function_name) const; | 380 bool HasAPIPermission(const std::string& function_name) const; |
380 | 381 |
381 const URLPatternSet& GetEffectiveHostPermissions() const; | 382 const URLPatternSet& GetEffectiveHostPermissions() const; |
382 | 383 |
| 384 // Returns true if the extension can silently increase its permission level. |
| 385 // Extensions that can silently increase permissions are installed through |
| 386 // mechanisms that are implicitly trusted. |
| 387 bool CanSilentlyIncreasePermissions() const; |
| 388 |
383 // Whether or not the extension is allowed permission for a URL pattern from | 389 // Whether or not the extension is allowed permission for a URL pattern from |
384 // the manifest. http, https, and chrome://favicon/ is allowed for all | 390 // the manifest. http, https, and chrome://favicon/ is allowed for all |
385 // extensions, while component extensions are allowed access to | 391 // extensions, while component extensions are allowed access to |
386 // chrome://resources. | 392 // chrome://resources. |
387 bool CanSpecifyHostPermission(const URLPattern& pattern) const; | 393 bool CanSpecifyHostPermission(const URLPattern& pattern) const; |
388 | 394 |
389 // Whether the extension has access to the given URL. | 395 // Whether the extension has access to the given URL. |
390 bool HasHostPermission(const GURL& url) const; | 396 bool HasHostPermission(const GURL& url) const; |
391 | 397 |
392 // Whether the extension has effective access to all hosts. This is true if | 398 // Whether the extension has effective access to all hosts. This is true if |
393 // there is a content script that matches all hosts, if there is a host | 399 // there is a content script that matches all hosts, if there is a host |
394 // permission grants access to all hosts (like <all_urls>) or an api | 400 // permission grants access to all hosts (like <all_urls>) or an api |
395 // permission that effectively grants access to all hosts (e.g. proxy, | 401 // permission that effectively grants access to all hosts (e.g. proxy, |
396 // network, etc.) | 402 // network, etc.) |
397 bool HasEffectiveAccessToAllHosts() const; | 403 bool HasEffectiveAccessToAllHosts() const; |
398 | 404 |
399 // Whether the extension effectively has all permissions (for example, by | 405 // Whether the extension effectively has all permissions (for example, by |
400 // having an NPAPI plugin). | 406 // having an NPAPI plugin). |
401 bool HasFullPermissions() const; | 407 bool HasFullPermissions() const; |
402 | 408 |
| 409 // Returns the full list of permission messages that this extension |
| 410 // should display at install time. |
| 411 ExtensionPermissionMessages GetPermissionMessages() const; |
| 412 |
| 413 // Returns the full list of permission messages that this extension |
| 414 // should display at install time. The messages are returned as strings |
| 415 // for convenience. |
| 416 std::vector<string16> GetPermissionMessageStrings() const; |
| 417 |
| 418 // Sets the active |permissions|. |
| 419 void SetActivePermissions(const ExtensionPermissionSet* permissions) const; |
| 420 |
| 421 // Gets the extension's active permission set. |
| 422 scoped_refptr<const ExtensionPermissionSet> GetActivePermissions() const; |
| 423 |
403 // Whether context menu should be shown for page and browser actions. | 424 // Whether context menu should be shown for page and browser actions. |
404 bool ShowConfigureContextMenus() const; | 425 bool ShowConfigureContextMenus() const; |
405 | 426 |
406 // Returns the Homepage URL for this extension. If homepage_url was not | 427 // Returns the Homepage URL for this extension. If homepage_url was not |
407 // specified in the manifest, this returns the Google Gallery URL. For | 428 // specified in the manifest, this returns the Google Gallery URL. For |
408 // third-party extensions, this returns a blank GURL. | 429 // third-party extensions, this returns a blank GURL. |
409 GURL GetHomepageURL() const; | 430 GURL GetHomepageURL() const; |
410 | 431 |
411 // Returns a list of paths (relative to the extension dir) for images that | 432 // Returns a list of paths (relative to the extension dir) for images that |
412 // the browser might load (like themes and page action icons). | 433 // the browser might load (like themes and page action icons). |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 const std::vector<NaClModuleInfo>& nacl_modules() const { | 508 const std::vector<NaClModuleInfo>& nacl_modules() const { |
488 return nacl_modules_; | 509 return nacl_modules_; |
489 } | 510 } |
490 const std::vector<InputComponentInfo>& input_components() const { | 511 const std::vector<InputComponentInfo>& input_components() const { |
491 return input_components_; | 512 return input_components_; |
492 } | 513 } |
493 const GURL& background_url() const { return background_url_; } | 514 const GURL& background_url() const { return background_url_; } |
494 const GURL& options_url() const { return options_url_; } | 515 const GURL& options_url() const { return options_url_; } |
495 const GURL& devtools_url() const { return devtools_url_; } | 516 const GURL& devtools_url() const { return devtools_url_; } |
496 const std::vector<GURL>& toolstrips() const { return toolstrips_; } | 517 const std::vector<GURL>& toolstrips() const { return toolstrips_; } |
497 const ExtensionPermissionSet* permission_set() const { | 518 const ExtensionPermissionSet* optional_permission_set() const { |
498 return permission_set_.get(); | 519 return optional_permission_set_.get(); |
| 520 } |
| 521 const ExtensionPermissionSet* required_permission_set() const { |
| 522 return required_permission_set_.get(); |
499 } | 523 } |
500 const GURL& update_url() const { return update_url_; } | 524 const GURL& update_url() const { return update_url_; } |
501 const ExtensionIconSet& icons() const { return icons_; } | 525 const ExtensionIconSet& icons() const { return icons_; } |
502 const base::DictionaryValue* manifest_value() const { | 526 const base::DictionaryValue* manifest_value() const { |
503 return manifest_value_.get(); | 527 return manifest_value_.get(); |
504 } | 528 } |
505 const std::string default_locale() const { return default_locale_; } | 529 const std::string default_locale() const { return default_locale_; } |
506 const URLOverrideMap& GetChromeURLOverrides() const { | 530 const URLOverrideMap& GetChromeURLOverrides() const { |
507 return chrome_url_overrides_; | 531 return chrome_url_overrides_; |
508 } | 532 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 | 568 |
545 private: | 569 private: |
546 friend class base::RefCountedThreadSafe<Extension>; | 570 friend class base::RefCountedThreadSafe<Extension>; |
547 | 571 |
548 // We keep a cache of images loaded from extension resources based on their | 572 // We keep a cache of images loaded from extension resources based on their |
549 // path and a string representation of a size that may have been used to | 573 // path and a string representation of a size that may have been used to |
550 // scale it (or the empty string if the image is at its original size). | 574 // scale it (or the empty string if the image is at its original size). |
551 typedef std::pair<FilePath, std::string> ImageCacheKey; | 575 typedef std::pair<FilePath, std::string> ImageCacheKey; |
552 typedef std::map<ImageCacheKey, SkBitmap> ImageCache; | 576 typedef std::map<ImageCacheKey, SkBitmap> ImageCache; |
553 | 577 |
| 578 class RuntimeData { |
| 579 public: |
| 580 RuntimeData(); |
| 581 explicit RuntimeData(const ExtensionPermissionSet* active); |
| 582 ~RuntimeData(); |
| 583 |
| 584 void SetActivePermissions(const ExtensionPermissionSet* active); |
| 585 scoped_refptr<const ExtensionPermissionSet> GetActivePermissions() const; |
| 586 |
| 587 private: |
| 588 friend class base::RefCountedThreadSafe<RuntimeData>; |
| 589 scoped_refptr<const ExtensionPermissionSet> active_permissions_; |
| 590 }; |
| 591 |
554 // Normalize the path for use by the extension. On Windows, this will make | 592 // Normalize the path for use by the extension. On Windows, this will make |
555 // sure the drive letter is uppercase. | 593 // sure the drive letter is uppercase. |
556 static FilePath MaybeNormalizePath(const FilePath& path); | 594 static FilePath MaybeNormalizePath(const FilePath& path); |
557 | 595 |
558 // Returns true if this extension id is from a trusted provider. | 596 // Returns true if this extension id is from a trusted provider. |
559 static bool IsTrustedId(const std::string& id); | 597 static bool IsTrustedId(const std::string& id); |
560 | 598 |
561 Extension(const FilePath& path, Location location); | 599 Extension(const FilePath& path, Location location); |
562 ~Extension(); | 600 ~Extension(); |
563 | 601 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 // Default locale for fall back. Can be empty if extension is not localized. | 704 // Default locale for fall back. Can be empty if extension is not localized. |
667 std::string default_locale_; | 705 std::string default_locale_; |
668 | 706 |
669 // If true, a separate process will be used for the extension in incognito | 707 // If true, a separate process will be used for the extension in incognito |
670 // mode. | 708 // mode. |
671 bool incognito_split_mode_; | 709 bool incognito_split_mode_; |
672 | 710 |
673 // Defines the set of URLs in the extension's web content. | 711 // Defines the set of URLs in the extension's web content. |
674 URLPatternSet extent_; | 712 URLPatternSet extent_; |
675 | 713 |
676 // The set of permissions that the extension effectively has access to. | 714 // The extension runtime data. |
677 scoped_ptr<ExtensionPermissionSet> permission_set_; | 715 mutable base::Lock runtime_data_lock_; |
| 716 mutable RuntimeData runtime_data_; |
| 717 |
| 718 // The set of permissions the extension can request at runtime. |
| 719 scoped_refptr<const ExtensionPermissionSet> optional_permission_set_; |
| 720 |
| 721 // The extension's required / default set of permissions. |
| 722 scoped_refptr<const ExtensionPermissionSet> required_permission_set_; |
678 | 723 |
679 // The icons for the extension. | 724 // The icons for the extension. |
680 ExtensionIconSet icons_; | 725 ExtensionIconSet icons_; |
681 | 726 |
682 // The base extension url for the extension. | 727 // The base extension url for the extension. |
683 GURL extension_url_; | 728 GURL extension_url_; |
684 | 729 |
685 // The location the extension was loaded from. | 730 // The location the extension was loaded from. |
686 Location location_; | 731 Location location_; |
687 | 732 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 | 908 |
864 // Was the extension already disabled? | 909 // Was the extension already disabled? |
865 bool already_disabled; | 910 bool already_disabled; |
866 | 911 |
867 // The extension being unloaded - this should always be non-NULL. | 912 // The extension being unloaded - this should always be non-NULL. |
868 const Extension* extension; | 913 const Extension* extension; |
869 | 914 |
870 UnloadedExtensionInfo(const Extension* extension, Reason reason); | 915 UnloadedExtensionInfo(const Extension* extension, Reason reason); |
871 }; | 916 }; |
872 | 917 |
| 918 // The details sent for EXTENSION_PERMISSIONS_UPDATED notifications. |
| 919 struct UpdatedExtensionPermissionsInfo { |
| 920 enum Reason { |
| 921 ADDED, // The permissions were added to the extension. |
| 922 REMOVED, // The permissions were removed from the extension. |
| 923 }; |
| 924 |
| 925 Reason reason; |
| 926 |
| 927 // The extension who's permissions have changed. |
| 928 const Extension* extension; |
| 929 |
| 930 // The permissions that have changed. For Reason::ADDED, this would contain |
| 931 // only the permissions that have added, and for Reason::REMOVED, this would |
| 932 // only contain the removed permissions. |
| 933 const ExtensionPermissionSet* permissions; |
| 934 |
| 935 UpdatedExtensionPermissionsInfo( |
| 936 const Extension* extension, |
| 937 const ExtensionPermissionSet* permissions, |
| 938 Reason reason); |
| 939 }; |
| 940 |
873 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ | 941 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
OLD | NEW |