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