| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <utility> |
| 12 #include <vector> | 13 #include <vector> |
| 13 #include <algorithm> | 14 #include <algorithm> |
| 14 | 15 |
| 15 #include "base/file_path.h" | 16 #include "base/file_path.h" |
| 16 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 17 #include "base/hash_tables.h" | 18 #include "base/hash_tables.h" |
| 18 #include "base/memory/linked_ptr.h" | 19 #include "base/memory/linked_ptr.h" |
| 19 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
| 20 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
| 21 #include "base/synchronization/lock.h" | 22 #include "base/synchronization/lock.h" |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 225 |
| 225 static scoped_refptr<Extension> Create(const FilePath& path, | 226 static scoped_refptr<Extension> Create(const FilePath& path, |
| 226 Location location, | 227 Location location, |
| 227 const base::DictionaryValue& value, | 228 const base::DictionaryValue& value, |
| 228 int flags, | 229 int flags, |
| 229 std::string* error); | 230 std::string* error); |
| 230 | 231 |
| 231 // In a few special circumstances, we want to create an Extension and give it | 232 // In a few special circumstances, we want to create an Extension and give it |
| 232 // an explicit id. Most consumers should just use the other Create() method. | 233 // an explicit id. Most consumers should just use the other Create() method. |
| 233 static scoped_refptr<Extension> Create(const FilePath& path, | 234 static scoped_refptr<Extension> Create(const FilePath& path, |
| 234 Location location, | 235 Location location, |
| 235 const base::DictionaryValue& value, | 236 const base::DictionaryValue& value, |
| 236 int flags, | 237 int flags, |
| 237 const std::string& explicit_id, | 238 const std::string& explicit_id, |
| 238 std::string* error); | 239 std::string* error); |
| 239 | 240 |
| 240 // Given two install sources, return the one which should take priority | 241 // Given two install sources, return the one which should take priority |
| 241 // over the other. If an extension is installed from two sources A and B, | 242 // over the other. If an extension is installed from two sources A and B, |
| 242 // its install source should be set to GetHigherPriorityLocation(A, B). | 243 // its install source should be set to GetHigherPriorityLocation(A, B). |
| 243 static Location GetHigherPriorityLocation(Location loc1, Location loc2); | 244 static Location GetHigherPriorityLocation(Location loc1, Location loc2); |
| 244 | 245 |
| 245 // Max size (both dimensions) for browser and page actions. | 246 // Max size (both dimensions) for browser and page actions. |
| 246 static const int kPageActionIconMaxSize; | 247 static const int kPageActionIconMaxSize; |
| 247 static const int kBrowserActionIconMaxSize; | 248 static const int kBrowserActionIconMaxSize; |
| 248 | 249 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 // always generate the same output ID. | 362 // always generate the same output ID. |
| 362 static bool GenerateId(const std::string& input, | 363 static bool GenerateId(const std::string& input, |
| 363 std::string* output) WARN_UNUSED_RESULT; | 364 std::string* output) WARN_UNUSED_RESULT; |
| 364 | 365 |
| 365 // Expects base64 encoded |input| and formats into |output| including | 366 // Expects base64 encoded |input| and formats into |output| including |
| 366 // the appropriate header & footer. | 367 // the appropriate header & footer. |
| 367 static bool FormatPEMForFileOutput(const std::string& input, | 368 static bool FormatPEMForFileOutput(const std::string& input, |
| 368 std::string* output, | 369 std::string* output, |
| 369 bool is_public); | 370 bool is_public); |
| 370 | 371 |
| 371 // Given an extension, icon size and match type, read a valid icon if present | 372 // Given an extension, icon size, and match type, read a valid icon if present |
| 372 // and decode it into result. In the browser process, this will DCHECK if not | 373 // and decode it into result. In the browser process, this will DCHECK if not |
| 373 // called on the file thread. To easily load extension images on the UI | 374 // called on the file thread. To easily load extension images on the UI |
| 374 // thread, see ImageLoadingTracker. | 375 // thread, see ImageLoadingTracker. |
| 375 static void DecodeIcon(const Extension* extension, | 376 static void DecodeIcon(const Extension* extension, |
| 376 ExtensionIconSet::Icons icon_size, | 377 ExtensionIconSet::Icons icon_size, |
| 377 ExtensionIconSet::MatchType match_type, | 378 ExtensionIconSet::MatchType match_type, |
| 378 scoped_ptr<SkBitmap>* result); | 379 scoped_ptr<SkBitmap>* result); |
| 379 | 380 |
| 380 // Given an extension and icon size, read it if present and decode it into | 381 // Given an extension and icon size, read it if present and decode it into |
| 381 // result. In the browser process, this will DCHECK if not called on the | 382 // result. In the browser process, this will DCHECK if not called on the |
| (...skipping 18 matching lines...) Expand all Loading... |
| 400 // Returns the base extension url for a given |extension_id|. | 401 // Returns the base extension url for a given |extension_id|. |
| 401 static GURL GetBaseURLFromExtensionId(const std::string& extension_id); | 402 static GURL GetBaseURLFromExtensionId(const std::string& extension_id); |
| 402 | 403 |
| 403 // Adds an extension to the scripting whitelist. Used for testing only. | 404 // Adds an extension to the scripting whitelist. Used for testing only. |
| 404 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); | 405 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); |
| 405 static const ScriptingWhitelist* GetScriptingWhitelist(); | 406 static const ScriptingWhitelist* GetScriptingWhitelist(); |
| 406 | 407 |
| 407 // Parses the host and api permissions from the specified permission |key| | 408 // Parses the host and api permissions from the specified permission |key| |
| 408 // from |manifest_|. | 409 // from |manifest_|. |
| 409 bool ParsePermissions(const char* key, | 410 bool ParsePermissions(const char* key, |
| 410 int flags, | |
| 411 string16* error, | 411 string16* error, |
| 412 ExtensionAPIPermissionSet* api_permissions, | 412 ExtensionAPIPermissionSet* api_permissions, |
| 413 URLPatternSet* host_permissions); | 413 URLPatternSet* host_permissions); |
| 414 | 414 |
| 415 bool HasAPIPermission(ExtensionAPIPermission::ID permission) const; | 415 bool HasAPIPermission(ExtensionAPIPermission::ID permission) const; |
| 416 bool HasAPIPermission(const std::string& function_name) const; | 416 bool HasAPIPermission(const std::string& function_name) const; |
| 417 | 417 |
| 418 const URLPatternSet& GetEffectiveHostPermissions() const; | 418 const URLPatternSet& GetEffectiveHostPermissions() const; |
| 419 | 419 |
| 420 // Returns true if the extension can silently increase its permission level. | 420 // Returns true if the extension can silently increase its permission level. |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 ~Extension(); | 683 ~Extension(); |
| 684 | 684 |
| 685 // Initialize the extension from a parsed manifest. | 685 // Initialize the extension from a parsed manifest. |
| 686 // TODO(aa): Rename to just Init()? There's no Value here anymore. | 686 // TODO(aa): Rename to just Init()? There's no Value here anymore. |
| 687 // TODO(aa): It is really weird the way this class essentially contains a copy | 687 // TODO(aa): It is really weird the way this class essentially contains a copy |
| 688 // of the underlying DictionaryValue in its members. We should decide to | 688 // of the underlying DictionaryValue in its members. We should decide to |
| 689 // either wrap the DictionaryValue and go with that only, or we should parse | 689 // either wrap the DictionaryValue and go with that only, or we should parse |
| 690 // into strong types and discard the value. But doing both is bad. | 690 // into strong types and discard the value. But doing both is bad. |
| 691 bool InitFromValue(int flags, string16* error); | 691 bool InitFromValue(int flags, string16* error); |
| 692 | 692 |
| 693 // Helpers to load various chunks of the manifest. | 693 // The following are helpers for InitFromValue to load various features of the |
| 694 bool LoadManifestVersion(string16* error); | 694 // extension from the manifest. |
| 695 |
| 696 bool CheckMinimumChromeVersion(string16* error); |
| 697 bool LoadAppIsolation(string16* error); |
| 698 |
| 699 bool LoadRequiredFeatures(string16* error); |
| 700 bool LoadName(string16* error); |
| 701 bool LoadVersion(string16* error); |
| 702 |
| 703 bool LoadAppFeatures(string16* error); |
| 695 bool LoadExtent(const char* key, | 704 bool LoadExtent(const char* key, |
| 696 URLPatternSet* extent, | 705 URLPatternSet* extent, |
| 697 const char* list_error, | 706 const char* list_error, |
| 698 const char* value_error, | 707 const char* value_error, |
| 699 string16* error); | 708 string16* error); |
| 700 bool LoadLaunchContainer(string16* error); | 709 bool LoadLaunchContainer(string16* error); |
| 701 bool LoadLaunchURL(string16* error); | 710 bool LoadLaunchURL(string16* error); |
| 702 bool LoadAppIsolation(string16* error); | 711 |
| 703 bool LoadWebIntentServices(string16* error); | 712 bool LoadSharedFeatures(const ExtensionAPIPermissionSet& api_permissions, |
| 713 string16* error); |
| 714 bool LoadDescription(string16* error); |
| 715 bool LoadManifestVersion(string16* error); |
| 716 bool LoadHomepageURL(string16* error); |
| 717 bool LoadUpdateURL(string16* error); |
| 718 bool LoadIcons(string16* error); |
| 719 bool LoadCommands(string16* error); |
| 720 bool LoadPlugins(string16* error); |
| 721 bool LoadNaClModules(string16* error); |
| 722 bool LoadWebAccessibleResources(string16* error); |
| 723 bool CheckRequirements(string16* error); |
| 724 bool LoadDefaultLocale(string16* error); |
| 725 bool LoadOfflineEnabled(string16* error); |
| 726 bool LoadOptionsPage(string16* error); |
| 704 bool LoadBackgroundScripts(string16* error); | 727 bool LoadBackgroundScripts(string16* error); |
| 705 bool LoadBackgroundPage(const ExtensionAPIPermissionSet& api_permissions, | 728 bool LoadBackgroundPage(const ExtensionAPIPermissionSet& api_permissions, |
| 706 string16* error); | 729 string16* error); |
| 707 bool LoadBackgroundPersistent( | 730 bool LoadBackgroundPersistent( |
| 708 const ExtensionAPIPermissionSet& api_permissions, | 731 const ExtensionAPIPermissionSet& api_permissions, |
| 709 string16* error); | 732 string16* error); |
| 710 bool LoadBackgroundAllowJsAccess( | 733 bool LoadBackgroundAllowJsAccess( |
| 711 const ExtensionAPIPermissionSet& api_permissions, | 734 const ExtensionAPIPermissionSet& api_permissions, |
| 712 string16* error); | 735 string16* error); |
| 736 bool LoadWebIntentServices(string16* error); |
| 737 |
| 738 bool LoadExtensionFeatures(const ExtensionAPIPermissionSet& api_permissions, |
| 739 string16* error); |
| 740 bool LoadDevToolsPage(string16* error); |
| 741 bool LoadInputComponents(const ExtensionAPIPermissionSet& api_permissions, |
| 742 string16* error); |
| 743 bool LoadContentScripts(string16* error); |
| 744 bool LoadPageAction(string16* error); |
| 745 bool LoadBrowserAction(string16* error); |
| 746 bool LoadFileBrowserHandlers(string16* error); |
| 747 // Helper method to load a FileBrowserHandlerList from the manifest. |
| 748 FileBrowserHandlerList* LoadFileBrowserHandlersHelper( |
| 749 const base::ListValue* extension_actions, string16* error); |
| 750 // Helper method to load an FileBrowserHandler from manifest. |
| 751 FileBrowserHandler* LoadFileBrowserHandler( |
| 752 const base::DictionaryValue* file_browser_handlers, string16* error); |
| 753 bool LoadChromeURLOverrides(string16* error); |
| 754 bool LoadOmnibox(string16* error); |
| 755 bool LoadTextToSpeechVoices(string16* error); |
| 756 bool LoadIncognitoMode(string16* error); |
| 757 bool LoadContentSecurityPolicy(string16* error); |
| 758 |
| 759 bool LoadThemeFeatures(string16* error); |
| 760 bool LoadThemeImages(const base::DictionaryValue* theme_value, |
| 761 string16* error); |
| 762 bool LoadThemeColors(const base::DictionaryValue* theme_value, |
| 763 string16* error); |
| 764 bool LoadThemeTints(const base::DictionaryValue* theme_value, |
| 765 string16* error); |
| 766 bool LoadThemeDisplayProperties(const base::DictionaryValue* theme_value, |
| 767 string16* error); |
| 768 |
| 769 // Helper function for implementing HasCachedImage/GetCachedImage. A return |
| 770 // value of NULL means there is no matching image cached (we allow caching an |
| 771 // empty SkBitmap). |
| 772 SkBitmap* GetCachedImageImpl(const ExtensionResource& source, |
| 773 const gfx::Size& max_size) const; |
| 713 | 774 |
| 714 // Helper method that loads a UserScript object from a | 775 // Helper method that loads a UserScript object from a |
| 715 // dictionary in the content_script list of the manifest. | 776 // dictionary in the content_script list of the manifest. |
| 716 bool LoadUserScriptHelper(const base::DictionaryValue* content_script, | 777 bool LoadUserScriptHelper(const base::DictionaryValue* content_script, |
| 717 int definition_index, | 778 int definition_index, |
| 718 int flags, | |
| 719 string16* error, | 779 string16* error, |
| 720 UserScript* result); | 780 UserScript* result); |
| 721 | 781 |
| 722 // Helper method that loads either the include_globs or exclude_globs list | 782 // Helper method that loads either the include_globs or exclude_globs list |
| 723 // from an entry in the content_script lists of the manifest. | 783 // from an entry in the content_script lists of the manifest. |
| 724 bool LoadGlobsHelper(const base::DictionaryValue* content_script, | 784 bool LoadGlobsHelper(const base::DictionaryValue* content_script, |
| 725 int content_script_index, | 785 int content_script_index, |
| 726 const char* globs_property_name, | 786 const char* globs_property_name, |
| 727 string16* error, | 787 string16* error, |
| 728 void(UserScript::*add_method)(const std::string& glob), | 788 void(UserScript::*add_method)(const std::string& glob), |
| 729 UserScript *instance); | 789 UserScript *instance); |
| 730 | 790 |
| 731 // Helper method to load an ExtensionAction from the page_action or | 791 // Helper method to load an ExtensionAction from the page_action or |
| 732 // browser_action entries in the manifest. | 792 // browser_action entries in the manifest. |
| 733 ExtensionAction* LoadExtensionActionHelper( | 793 ExtensionAction* LoadExtensionActionHelper( |
| 734 const base::DictionaryValue* extension_action, string16* error); | 794 const base::DictionaryValue* extension_action, string16* error); |
| 735 | 795 |
| 736 // Helper method to load an FileBrowserHandlerList from the manifest. | |
| 737 FileBrowserHandlerList* LoadFileBrowserHandlers( | |
| 738 const base::ListValue* extension_actions, string16* error); | |
| 739 // Helper method to load an FileBrowserHandler from manifest. | |
| 740 FileBrowserHandler* LoadFileBrowserHandler( | |
| 741 const base::DictionaryValue* file_browser_handlers, string16* error); | |
| 742 | |
| 743 // Returns true if the extension has more than one "UI surface". For example, | 796 // Returns true if the extension has more than one "UI surface". For example, |
| 744 // an extension that has a browser action and a page action. | 797 // an extension that has a browser action and a page action. |
| 745 bool HasMultipleUISurfaces() const; | 798 bool HasMultipleUISurfaces() const; |
| 746 | 799 |
| 747 // Updates the launch URL and extents for the extension using the given | 800 // Updates the launch URL and extents for the extension using the given |
| 748 // |override_url|. | 801 // |override_url|. |
| 749 void OverrideLaunchUrl(const GURL& override_url); | 802 void OverrideLaunchUrl(const GURL& override_url); |
| 750 | 803 |
| 751 // Returns true if this extension can specify |api|. | 804 // Returns true if this extension can specify |api|. |
| 752 bool CanSpecifyAPIPermission(const ExtensionAPIPermission* api, | 805 bool CanSpecifyAPIPermission(const ExtensionAPIPermission* api, |
| 753 string16* error) const; | 806 string16* error) const; |
| 754 bool CanSpecifyExperimentalPermission() const; | 807 bool CanSpecifyExperimentalPermission() const; |
| 755 | 808 |
| 756 // Checks whether the host |pattern| is allowed for this extension, given API | 809 // Checks whether the host |pattern| is allowed for this extension, given API |
| 757 // permissions |permissions|. | 810 // permissions |permissions|. |
| 758 bool CanSpecifyHostPermission(const URLPattern& pattern, | 811 bool CanSpecifyHostPermission(const URLPattern& pattern, |
| 759 const ExtensionAPIPermissionSet& permissions) const; | 812 const ExtensionAPIPermissionSet& permissions) const; |
| 760 | 813 |
| 761 // Helper function for implementing HasCachedImage/GetCachedImage. A return | |
| 762 // value of NULL means there is no matching image cached (we allow caching an | |
| 763 // empty SkBitmap). | |
| 764 SkBitmap* GetCachedImageImpl(const ExtensionResource& source, | |
| 765 const gfx::Size& max_size) const; | |
| 766 | |
| 767 // Cached images for this extension. This should only be touched on the UI | 814 // Cached images for this extension. This should only be touched on the UI |
| 768 // thread. | 815 // thread. |
| 769 mutable ImageCache image_cache_; | 816 mutable ImageCache image_cache_; |
| 770 | 817 |
| 771 // The extension's human-readable name. Name is used for display purpose. It | 818 // The extension's human-readable name. Name is used for display purpose. It |
| 772 // might be wrapped with unicode bidi control characters so that it is | 819 // might be wrapped with unicode bidi control characters so that it is |
| 773 // displayed correctly in RTL context. | 820 // displayed correctly in RTL context. |
| 774 // NOTE: Name is UTF-8 and may contain non-ascii characters. | 821 // NOTE: Name is UTF-8 and may contain non-ascii characters. |
| 775 std::string name_; | 822 std::string name_; |
| 776 | 823 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 // A map of display properties. | 937 // A map of display properties. |
| 891 scoped_ptr<base::DictionaryValue> theme_display_properties_; | 938 scoped_ptr<base::DictionaryValue> theme_display_properties_; |
| 892 | 939 |
| 893 // The homepage for this extension. Useful if it is not hosted by Google and | 940 // The homepage for this extension. Useful if it is not hosted by Google and |
| 894 // therefore does not have a Gallery URL. | 941 // therefore does not have a Gallery URL. |
| 895 GURL homepage_url_; | 942 GURL homepage_url_; |
| 896 | 943 |
| 897 // URL for fetching an update manifest | 944 // URL for fetching an update manifest |
| 898 GURL update_url_; | 945 GURL update_url_; |
| 899 | 946 |
| 900 // The manifest that this extension was created from. | 947 // The manifest from which this extension was created. |
| 901 // | 948 // |
| 902 // NOTE: This is an owned pointer, but can't use scoped_ptr because that would | 949 // NOTE: This is an owned pointer, but can't use scoped_ptr because that would |
| 903 // require manifest.h, which would in turn create a circulate dependency | 950 // require manifest.h, which would in turn create a circulate dependency |
| 904 // between extension.h and manifest.h. | 951 // between extension.h and manifest.h. |
| 905 // | 952 // |
| 906 // TODO(aa): Pull Extension::Type and Extension::Location out into their own | 953 // TODO(aa): Pull Extension::Type and Extension::Location out into their own |
| 907 // files so that manifest.h can rely on them and not get all of extension.h | 954 // files so that manifest.h can rely on them and not get all of extension.h |
| 908 // too, and then change this back to a scoped_ptr. | 955 // too, and then change this back to a scoped_ptr. |
| 909 extensions::Manifest* manifest_; | 956 extensions::Manifest* manifest_; |
| 910 | 957 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 // only contain the removed permissions. | 1067 // only contain the removed permissions. |
| 1021 const ExtensionPermissionSet* permissions; | 1068 const ExtensionPermissionSet* permissions; |
| 1022 | 1069 |
| 1023 UpdatedExtensionPermissionsInfo( | 1070 UpdatedExtensionPermissionsInfo( |
| 1024 const Extension* extension, | 1071 const Extension* extension, |
| 1025 const ExtensionPermissionSet* permissions, | 1072 const ExtensionPermissionSet* permissions, |
| 1026 Reason reason); | 1073 Reason reason); |
| 1027 }; | 1074 }; |
| 1028 | 1075 |
| 1029 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ | 1076 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
| OLD | NEW |