Chromium Code Reviews| 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 672 ~Extension(); | 672 ~Extension(); |
| 673 | 673 |
| 674 // Initialize the extension from a parsed manifest. | 674 // Initialize the extension from a parsed manifest. |
| 675 // TODO(aa): Rename to just Init()? There's no Value here anymore. | 675 // TODO(aa): Rename to just Init()? There's no Value here anymore. |
| 676 // TODO(aa): It is really weird the way this class essentially contains a copy | 676 // TODO(aa): It is really weird the way this class essentially contains a copy |
| 677 // of the underlying DictionaryValue in its members. We should decide to | 677 // of the underlying DictionaryValue in its members. We should decide to |
| 678 // either wrap the DictionaryValue and go with that only, or we should parse | 678 // either wrap the DictionaryValue and go with that only, or we should parse |
| 679 // into strong types and discard the value. But doing both is bad. | 679 // into strong types and discard the value. But doing both is bad. |
| 680 bool InitFromValue(int flags, string16* error); | 680 bool InitFromValue(int flags, string16* error); |
| 681 | 681 |
| 682 // Helpers to load various chunks of the manifest. | 682 // The following are helpers for InitFromValue to load various features of the |
| 683 // extension. | |
|
Yoyo Zhou
2012/03/01 01:17:25
...from the manifest
Devlin
2012/03/02 17:31:04
Done.
| |
| 684 | |
| 685 bool LoadSharedFeatures(const int& flags, | |
| 686 string16* error); | |
| 687 bool LoadName(string16* error); | |
| 688 bool LoadDescription(string16* error); | |
| 689 bool LoadVersion(string16* error); | |
| 690 bool LoadMinimumChromeVersion(string16* error); | |
| 683 bool LoadManifestVersion(string16* error); | 691 bool LoadManifestVersion(string16* error); |
| 692 bool LoadPublicKey(const int& flags, | |
| 693 string16* error); | |
| 694 bool LoadHomepageURL(string16* error); | |
| 695 bool LoadUpdateURL(string16* error); | |
| 696 bool LoadExtensionFeatures(const int& flags, | |
| 697 const ExtensionAPIPermissionSet& api_permissions, | |
| 698 string16* error); | |
| 699 bool LoadOptionsPage(string16* error); | |
| 700 bool LoadDevToolsPage(string16* error); | |
| 701 bool LoadInputComponents(const ExtensionAPIPermissionSet& api_permissions, | |
| 702 string16* error); | |
| 703 bool LoadCommands(string16* error); | |
| 704 bool LoadIcons(string16* error); | |
| 705 bool LoadPlugins(string16* error); | |
| 706 bool LoadNaClModules(string16* error); | |
| 707 bool LoadContentScripts(const int& flags, | |
| 708 string16* error); | |
| 709 bool LoadWebAccessibleResources(string16* error); | |
| 710 bool LoadPageAction(string16* error); | |
| 711 bool LoadBrowserAction(string16* error); | |
| 712 bool LoadFileBrowserHandlers(string16* error); | |
| 713 // Helper method to load a FileBrowserHandlerList from the manifest. | |
| 714 FileBrowserHandlerList* LoadFileBrowserHandlersHelper( | |
| 715 const base::ListValue* extension_actions, string16* error); | |
| 716 // Helper method to load an FileBrowserHandler from manifest. | |
| 717 FileBrowserHandler* LoadFileBrowserHandler( | |
| 718 const base::DictionaryValue* file_browser_handlers, string16* error); | |
| 719 bool LoadChromeURLOverrides(string16* error); | |
| 720 bool LoadOmnibox(string16* error); | |
| 721 bool LoadTextToSpeechVoices(string16* error); | |
| 722 bool LoadWebIntentServices(string16* error); | |
| 723 bool LoadRequirements(string16* error); | |
| 724 bool LoadDefaultLocale(string16* error); | |
| 725 bool LoadOfflineEnabled(string16* error); | |
| 726 bool LoadIncognito(string16* error); | |
| 727 bool LoadBackgroundScripts(string16* error); | |
| 728 bool LoadBackgroundPage(const ExtensionAPIPermissionSet& api_permissions, | |
| 729 string16* error); | |
| 730 bool LoadBackgroundPersistent( | |
| 731 const ExtensionAPIPermissionSet& api_permissions, | |
| 732 string16* error); | |
| 733 bool LoadContentSecurityPolicy(string16* error); | |
| 734 bool LoadAppFeatures(string16* error); | |
| 684 bool LoadExtent(const char* key, | 735 bool LoadExtent(const char* key, |
| 685 URLPatternSet* extent, | 736 URLPatternSet* extent, |
| 686 const char* list_error, | 737 const char* list_error, |
| 687 const char* value_error, | 738 const char* value_error, |
| 688 string16* error); | 739 string16* error); |
| 689 bool LoadLaunchContainer(string16* error); | 740 bool LoadLaunchContainer(string16* error); |
| 690 bool LoadLaunchURL(string16* error); | 741 bool LoadLaunchURL(string16* error); |
| 691 bool LoadAppIsolation(string16* error); | 742 bool LoadAppIsolation(string16* error); |
| 692 bool LoadWebIntentServices(string16* error); | 743 bool LoadThemeFeatures(string16* error); |
| 693 bool LoadBackgroundScripts(string16* error); | 744 bool LoadThemeImages(const base::DictionaryValue* theme_value, |
| 694 bool LoadBackgroundPage(const ExtensionAPIPermissionSet& api_permissions, | 745 string16* error); |
| 695 string16* error); | 746 bool LoadThemeColors(const base::DictionaryValue* theme_value, |
| 696 bool LoadBackgroundPersistent( | 747 string16* error); |
| 697 const ExtensionAPIPermissionSet& api_permissions, | 748 bool LoadThemeTints(const base::DictionaryValue* theme_value, |
| 698 string16* error); | 749 string16* error); |
| 750 bool LoadThemeDisplayProperties(const base::DictionaryValue* theme_value, | |
| 751 string16* error); | |
| 752 | |
| 753 // Helper function for implementing HasCachedImage/GetCachedImage. A return | |
| 754 // value of NULL means there is no matching image cached (we allow caching an | |
| 755 // empty SkBitmap). | |
| 756 SkBitmap* GetCachedImageImpl(const ExtensionResource& source, | |
| 757 const gfx::Size& max_size) const; | |
| 699 | 758 |
| 700 // Helper method that loads a UserScript object from a | 759 // Helper method that loads a UserScript object from a |
| 701 // dictionary in the content_script list of the manifest. | 760 // dictionary in the content_script list of the manifest. |
| 702 bool LoadUserScriptHelper(const base::DictionaryValue* content_script, | 761 bool LoadUserScriptHelper(const base::DictionaryValue* content_script, |
| 703 int definition_index, | 762 int definition_index, |
| 704 int flags, | 763 int flags, |
| 705 string16* error, | 764 string16* error, |
| 706 UserScript* result); | 765 UserScript* result); |
| 707 | 766 |
| 708 // Helper method that loads either the include_globs or exclude_globs list | 767 // Helper method that loads either the include_globs or exclude_globs list |
| 709 // from an entry in the content_script lists of the manifest. | 768 // from an entry in the content_script lists of the manifest. |
| 710 bool LoadGlobsHelper(const base::DictionaryValue* content_script, | 769 bool LoadGlobsHelper(const base::DictionaryValue* content_script, |
| 711 int content_script_index, | 770 int content_script_index, |
| 712 const char* globs_property_name, | 771 const char* globs_property_name, |
| 713 string16* error, | 772 string16* error, |
| 714 void(UserScript::*add_method)(const std::string& glob), | 773 void(UserScript::*add_method)(const std::string& glob), |
| 715 UserScript *instance); | 774 UserScript *instance); |
| 716 | 775 |
| 717 // Helper method to load an ExtensionAction from the page_action or | 776 // Helper method to load an ExtensionAction from the page_action or |
| 718 // browser_action entries in the manifest. | 777 // browser_action entries in the manifest. |
| 719 ExtensionAction* LoadExtensionActionHelper( | 778 ExtensionAction* LoadExtensionActionHelper( |
| 720 const base::DictionaryValue* extension_action, string16* error); | 779 const base::DictionaryValue* extension_action, string16* error); |
| 721 | 780 |
| 722 // Helper method to load an FileBrowserHandlerList from the manifest. | |
| 723 FileBrowserHandlerList* LoadFileBrowserHandlers( | |
| 724 const base::ListValue* extension_actions, string16* error); | |
| 725 // Helper method to load an FileBrowserHandler from manifest. | |
| 726 FileBrowserHandler* LoadFileBrowserHandler( | |
| 727 const base::DictionaryValue* file_browser_handlers, string16* error); | |
| 728 | |
| 729 // Returns true if the extension has more than one "UI surface". For example, | 781 // Returns true if the extension has more than one "UI surface". For example, |
| 730 // an extension that has a browser action and a page action. | 782 // an extension that has a browser action and a page action. |
| 731 bool HasMultipleUISurfaces() const; | 783 bool HasMultipleUISurfaces() const; |
| 732 | 784 |
| 733 // Updates the launch URL and extents for the extension using the given | 785 // Updates the launch URL and extents for the extension using the given |
| 734 // |override_url|. | 786 // |override_url|. |
| 735 void OverrideLaunchUrl(const GURL& override_url); | 787 void OverrideLaunchUrl(const GURL& override_url); |
| 736 | 788 |
| 737 // Returns true if this extension can specify |api|. | 789 // Returns true if this extension can specify |api|. |
| 738 bool CanSpecifyAPIPermission(const ExtensionAPIPermission* api, | 790 bool CanSpecifyAPIPermission(const ExtensionAPIPermission* api, |
| 739 string16* error) const; | 791 string16* error) const; |
| 740 bool CanSpecifyExperimentalPermission() const; | 792 bool CanSpecifyExperimentalPermission() const; |
| 741 | 793 |
| 742 // Checks whether the host |pattern| is allowed for this extension, given API | 794 // Checks whether the host |pattern| is allowed for this extension, given API |
| 743 // permissions |permissions|. | 795 // permissions |permissions|. |
| 744 bool CanSpecifyHostPermission(const URLPattern& pattern, | 796 bool CanSpecifyHostPermission(const URLPattern& pattern, |
| 745 const ExtensionAPIPermissionSet& permissions) const; | 797 const ExtensionAPIPermissionSet& permissions) const; |
| 746 | 798 |
| 747 // Helper function for implementing HasCachedImage/GetCachedImage. A return | |
| 748 // value of NULL means there is no matching image cached (we allow caching an | |
| 749 // empty SkBitmap). | |
| 750 SkBitmap* GetCachedImageImpl(const ExtensionResource& source, | |
| 751 const gfx::Size& max_size) const; | |
| 752 | |
| 753 // Cached images for this extension. This should only be touched on the UI | 799 // Cached images for this extension. This should only be touched on the UI |
| 754 // thread. | 800 // thread. |
| 755 mutable ImageCache image_cache_; | 801 mutable ImageCache image_cache_; |
| 756 | 802 |
| 757 // The extension's human-readable name. Name is used for display purpose. It | 803 // The extension's human-readable name. Name is used for display purpose. It |
| 758 // might be wrapped with unicode bidi control characters so that it is | 804 // might be wrapped with unicode bidi control characters so that it is |
| 759 // displayed correctly in RTL context. | 805 // displayed correctly in RTL context. |
| 760 // NOTE: Name is UTF-8 and may contain non-ascii characters. | 806 // NOTE: Name is UTF-8 and may contain non-ascii characters. |
| 761 std::string name_; | 807 std::string name_; |
| 762 | 808 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 870 // A map of display properties. | 916 // A map of display properties. |
| 871 scoped_ptr<base::DictionaryValue> theme_display_properties_; | 917 scoped_ptr<base::DictionaryValue> theme_display_properties_; |
| 872 | 918 |
| 873 // The homepage for this extension. Useful if it is not hosted by Google and | 919 // The homepage for this extension. Useful if it is not hosted by Google and |
| 874 // therefore does not have a Gallery URL. | 920 // therefore does not have a Gallery URL. |
| 875 GURL homepage_url_; | 921 GURL homepage_url_; |
| 876 | 922 |
| 877 // URL for fetching an update manifest | 923 // URL for fetching an update manifest |
| 878 GURL update_url_; | 924 GURL update_url_; |
| 879 | 925 |
| 880 // The manifest that this extension was created from. | 926 // The manifest from which this extension was created. |
| 881 // | 927 // |
| 882 // NOTE: This is an owned pointer, but can't use scoped_ptr because that would | 928 // NOTE: This is an owned pointer, but can't use scoped_ptr because that would |
| 883 // require manifest.h, which would in turn create a circulate dependency | 929 // require manifest.h, which would in turn create a circulate dependency |
| 884 // between extension.h and manifest.h. | 930 // between extension.h and manifest.h. |
| 885 // | 931 // |
| 886 // TODO(aa): Pull Extension::Type and Extension::Location out into their own | 932 // TODO(aa): Pull Extension::Type and Extension::Location out into their own |
| 887 // files so that manifest.h can rely on them and not get all of extension.h | 933 // files so that manifest.h can rely on them and not get all of extension.h |
| 888 // too, and then change this back to a scoped_ptr. | 934 // too, and then change this back to a scoped_ptr. |
| 889 extensions::Manifest* manifest_; | 935 extensions::Manifest* manifest_; |
| 890 | 936 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 997 // only contain the removed permissions. | 1043 // only contain the removed permissions. |
| 998 const ExtensionPermissionSet* permissions; | 1044 const ExtensionPermissionSet* permissions; |
| 999 | 1045 |
| 1000 UpdatedExtensionPermissionsInfo( | 1046 UpdatedExtensionPermissionsInfo( |
| 1001 const Extension* extension, | 1047 const Extension* extension, |
| 1002 const ExtensionPermissionSet* permissions, | 1048 const ExtensionPermissionSet* permissions, |
| 1003 Reason reason); | 1049 Reason reason); |
| 1004 }; | 1050 }; |
| 1005 | 1051 |
| 1006 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ | 1052 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
| OLD | NEW |