Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: chrome/common/extensions/extension.h

Issue 11446034: SupportsUserData and manifest handlers for Extension; use them for the Omnibox API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase + manifestdata Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <iosfwd> 9 #include <iosfwd>
10 #include <map> 10 #include <map>
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 class Manifest; 59 class Manifest;
60 class PermissionSet; 60 class PermissionSet;
61 61
62 typedef std::set<std::string> OAuth2Scopes; 62 typedef std::set<std::string> OAuth2Scopes;
63 63
64 // Represents a Chrome extension. 64 // Represents a Chrome extension.
65 class Extension : public base::RefCountedThreadSafe<Extension> { 65 class Extension : public base::RefCountedThreadSafe<Extension> {
66 public: 66 public:
67 struct InstallWarning; 67 struct InstallWarning;
68 struct ManifestData;
68 69
69 typedef std::map<const std::string, GURL> URLOverrideMap; 70 typedef std::map<const std::string, GURL> URLOverrideMap;
70 typedef std::vector<std::string> ScriptingWhitelist; 71 typedef std::vector<std::string> ScriptingWhitelist;
71 typedef std::vector<linked_ptr<FileBrowserHandler> > FileBrowserHandlerList; 72 typedef std::vector<linked_ptr<FileBrowserHandler> > FileBrowserHandlerList;
72 typedef std::vector<InstallWarning> InstallWarningVector; 73 typedef std::vector<InstallWarning> InstallWarningVector;
74 typedef std::map<const std::string, linked_ptr<ManifestData> >
75 ManifestDataMap;
73 76
74 // What an extension was loaded from. 77 // What an extension was loaded from.
75 // NOTE: These values are stored as integers in the preferences and used 78 // NOTE: These values are stored as integers in the preferences and used
76 // in histograms so don't remove or reorder existing items. Just append 79 // in histograms so don't remove or reorder existing items. Just append
77 // to the end. 80 // to the end.
78 enum Location { 81 enum Location {
79 INVALID, 82 INVALID,
80 INTERNAL, // A crx file from the internal Extensions directory. 83 INTERNAL, // A crx file from the internal Extensions directory.
81 EXTERNAL_PREF, // A crx file from an external directory (via prefs). 84 EXTERNAL_PREF, // A crx file from an external directory (via prefs).
82 EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the 85 EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 FORMAT_HTML, 263 FORMAT_HTML,
261 }; 264 };
262 InstallWarning(Format format, const std::string& message) 265 InstallWarning(Format format, const std::string& message)
263 : format(format), message(message) { 266 : format(format), message(message) {
264 } 267 }
265 bool operator==(const InstallWarning& other) const; 268 bool operator==(const InstallWarning& other) const;
266 Format format; 269 Format format;
267 std::string message; 270 std::string message;
268 }; 271 };
269 272
273 // A base class for parsed manifest data that APIs want to store on
274 // the extension. Related to base::SupportsUserData, but with an immutable
275 // thread-safe interface to match Extension.
276 struct ManifestData {
277 virtual ~ManifestData() {}
278 };
279
270 enum InitFromValueFlags { 280 enum InitFromValueFlags {
271 NO_FLAGS = 0, 281 NO_FLAGS = 0,
272 282
273 // Usually, the id of an extension is generated by the "key" property of 283 // Usually, the id of an extension is generated by the "key" property of
274 // its manifest, but if |REQUIRE_KEY| is not set, a temporary ID will be 284 // its manifest, but if |REQUIRE_KEY| is not set, a temporary ID will be
275 // generated based on the path. 285 // generated based on the path.
276 REQUIRE_KEY = 1 << 0, 286 REQUIRE_KEY = 1 << 0,
277 287
278 // Requires the extension to have an up-to-date manifest version. 288 // Requires the extension to have an up-to-date manifest version.
279 // Typically, we'll support multiple manifest versions during a version 289 // Typically, we'll support multiple manifest versions during a version
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 659
650 // Updates the tab-specific permissions of |tab_id| to include those from 660 // Updates the tab-specific permissions of |tab_id| to include those from
651 // |permissions|. 661 // |permissions|.
652 void UpdateTabSpecificPermissions( 662 void UpdateTabSpecificPermissions(
653 int tab_id, 663 int tab_id,
654 scoped_refptr<const PermissionSet> permissions) const; 664 scoped_refptr<const PermissionSet> permissions) const;
655 665
656 // Clears the tab-specific permissions of |tab_id|. 666 // Clears the tab-specific permissions of |tab_id|.
657 void ClearTabSpecificPermissions(int tab_id) const; 667 void ClearTabSpecificPermissions(int tab_id) const;
658 668
669 // Get the manifest data associated with the key, or NULL if there is none.
670 // Can only be called after InitValue is finished.
671 ManifestData* GetManifestData(const std::string& key) const;
672
673 // Sets |data| to be associated with the key. Takes ownership of |data|.
674 // Can only be called before InitValue is finished. Not thread-safe;
675 // all SetManifestData calls should be on only one thread.
676 void SetManifestData(const std::string& key, ManifestData* data);
677
659 // Accessors: 678 // Accessors:
660 679
661 const Requirements& requirements() const { return requirements_; } 680 const Requirements& requirements() const { return requirements_; }
662 const FilePath& path() const { return path_; } 681 const FilePath& path() const { return path_; }
663 const GURL& url() const { return extension_url_; } 682 const GURL& url() const { return extension_url_; }
664 Location location() const; 683 Location location() const;
665 const std::string& id() const; 684 const std::string& id() const;
666 const Version* version() const { return version_.get(); } 685 const Version* version() const { return version_.get(); }
667 const std::string VersionString() const; 686 const std::string VersionString() const;
668 const std::string& name() const { return name_; } 687 const std::string& name() const { return name_; }
(...skipping 11 matching lines...) Expand all
680 const ActionInfo* script_badge_info() const { 699 const ActionInfo* script_badge_info() const {
681 return script_badge_info_.get(); 700 return script_badge_info_.get();
682 } 701 }
683 const ActionInfo* page_action_info() const { return page_action_info_.get(); } 702 const ActionInfo* page_action_info() const { return page_action_info_.get(); }
684 const ActionInfo* browser_action_info() const { 703 const ActionInfo* browser_action_info() const {
685 return browser_action_info_.get(); 704 return browser_action_info_.get();
686 } 705 }
687 const ActionInfo* system_indicator_info() const { 706 const ActionInfo* system_indicator_info() const {
688 return system_indicator_info_.get(); 707 return system_indicator_info_.get();
689 } 708 }
690 bool is_verbose_install_message() const {
691 return !omnibox_keyword().empty() ||
692 browser_action_info() ||
693 (page_action_info() &&
694 (page_action_command() ||
695 !page_action_info()->default_icon.empty()));
696 }
697 const FileBrowserHandlerList* file_browser_handlers() const { 709 const FileBrowserHandlerList* file_browser_handlers() const {
698 return file_browser_handlers_.get(); 710 return file_browser_handlers_.get();
699 } 711 }
700 const std::vector<PluginInfo>& plugins() const { return plugins_; } 712 const std::vector<PluginInfo>& plugins() const { return plugins_; }
701 const std::vector<NaClModuleInfo>& nacl_modules() const { 713 const std::vector<NaClModuleInfo>& nacl_modules() const {
702 return nacl_modules_; 714 return nacl_modules_;
703 } 715 }
704 const std::vector<InputComponentInfo>& input_components() const { 716 const std::vector<InputComponentInfo>& input_components() const {
705 return input_components_; 717 return input_components_;
706 } 718 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 } 771 }
760 const GURL& update_url() const { return update_url_; } 772 const GURL& update_url() const { return update_url_; }
761 const ExtensionIconSet& icons() const { return icons_; } 773 const ExtensionIconSet& icons() const { return icons_; }
762 const extensions::Manifest* manifest() const { 774 const extensions::Manifest* manifest() const {
763 return manifest_.get(); 775 return manifest_.get();
764 } 776 }
765 const std::string default_locale() const { return default_locale_; } 777 const std::string default_locale() const { return default_locale_; }
766 const URLOverrideMap& GetChromeURLOverrides() const { 778 const URLOverrideMap& GetChromeURLOverrides() const {
767 return chrome_url_overrides_; 779 return chrome_url_overrides_;
768 } 780 }
769 const std::string omnibox_keyword() const { return omnibox_keyword_; }
770 bool incognito_split_mode() const { return incognito_split_mode_; } 781 bool incognito_split_mode() const { return incognito_split_mode_; }
771 bool offline_enabled() const { return offline_enabled_; } 782 bool offline_enabled() const { return offline_enabled_; }
772 const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; } 783 const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; }
773 const OAuth2Info& oauth2_info() const { return oauth2_info_; } 784 const OAuth2Info& oauth2_info() const { return oauth2_info_; }
774 const std::vector<webkit_glue::WebIntentServiceData>& 785 const std::vector<webkit_glue::WebIntentServiceData>&
775 intents_services() const { 786 intents_services() const {
776 return intents_services_; 787 return intents_services_;
777 } 788 }
778 789
779 bool wants_file_access() const { return wants_file_access_; } 790 bool wants_file_access() const { return wants_file_access_; }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 string16* error); 877 string16* error);
867 878
868 // Normalize the path for use by the extension. On Windows, this will make 879 // Normalize the path for use by the extension. On Windows, this will make
869 // sure the drive letter is uppercase. 880 // sure the drive letter is uppercase.
870 static FilePath MaybeNormalizePath(const FilePath& path); 881 static FilePath MaybeNormalizePath(const FilePath& path);
871 882
872 // Returns true if this extension id is from a trusted provider. 883 // Returns true if this extension id is from a trusted provider.
873 static bool IsTrustedId(const std::string& id); 884 static bool IsTrustedId(const std::string& id);
874 885
875 Extension(const FilePath& path, scoped_ptr<extensions::Manifest> manifest); 886 Extension(const FilePath& path, scoped_ptr<extensions::Manifest> manifest);
876 ~Extension(); 887 virtual ~Extension();
877 888
878 // Initialize the extension from a parsed manifest. 889 // Initialize the extension from a parsed manifest.
879 // TODO(aa): Rename to just Init()? There's no Value here anymore. 890 // TODO(aa): Rename to just Init()? There's no Value here anymore.
880 // TODO(aa): It is really weird the way this class essentially contains a copy 891 // TODO(aa): It is really weird the way this class essentially contains a copy
881 // of the underlying DictionaryValue in its members. We should decide to 892 // of the underlying DictionaryValue in its members. We should decide to
882 // either wrap the DictionaryValue and go with that only, or we should parse 893 // either wrap the DictionaryValue and go with that only, or we should parse
883 // into strong types and discard the value. But doing both is bad. 894 // into strong types and discard the value. But doing both is bad.
884 bool InitFromValue(int flags, string16* error); 895 bool InitFromValue(int flags, string16* error);
885 896
886 // The following are helpers for InitFromValue to load various features of the 897 // The following are helpers for InitFromValue to load various features of the
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 bool LoadWebIntentAction(const std::string& action_name, 947 bool LoadWebIntentAction(const std::string& action_name,
937 const base::DictionaryValue& intent_service, 948 const base::DictionaryValue& intent_service,
938 string16* error); 949 string16* error);
939 bool LoadWebIntentServices(string16* error); 950 bool LoadWebIntentServices(string16* error);
940 bool LoadFileHandler(const std::string& handler_id, 951 bool LoadFileHandler(const std::string& handler_id,
941 const base::DictionaryValue& handler_info, 952 const base::DictionaryValue& handler_info,
942 string16* error); 953 string16* error);
943 bool LoadFileHandlers(string16* error); 954 bool LoadFileHandlers(string16* error);
944 bool LoadExtensionFeatures(APIPermissionSet* api_permissions, 955 bool LoadExtensionFeatures(APIPermissionSet* api_permissions,
945 string16* error); 956 string16* error);
957 bool LoadManifestHandlerFeatures(string16* error);
946 bool LoadDevToolsPage(string16* error); 958 bool LoadDevToolsPage(string16* error);
947 bool LoadInputComponents(const APIPermissionSet& api_permissions, 959 bool LoadInputComponents(const APIPermissionSet& api_permissions,
948 string16* error); 960 string16* error);
949 bool LoadContentScripts(string16* error); 961 bool LoadContentScripts(string16* error);
950 bool LoadPageAction(string16* error); 962 bool LoadPageAction(string16* error);
951 bool LoadBrowserAction(string16* error); 963 bool LoadBrowserAction(string16* error);
952 bool LoadScriptBadge(string16* error); 964 bool LoadScriptBadge(string16* error);
953 bool LoadSystemIndicator(APIPermissionSet* api_permissions, string16* error); 965 bool LoadSystemIndicator(APIPermissionSet* api_permissions, string16* error);
954 bool LoadFileBrowserHandlers(string16* error); 966 bool LoadFileBrowserHandlers(string16* error);
955 // Helper method to load a FileBrowserHandlerList from the manifest. 967 // Helper method to load a FileBrowserHandlerList from the manifest.
956 FileBrowserHandlerList* LoadFileBrowserHandlersHelper( 968 FileBrowserHandlerList* LoadFileBrowserHandlersHelper(
957 const base::ListValue* extension_actions, string16* error); 969 const base::ListValue* extension_actions, string16* error);
958 // Helper method to load an FileBrowserHandler from manifest. 970 // Helper method to load an FileBrowserHandler from manifest.
959 FileBrowserHandler* LoadFileBrowserHandler( 971 FileBrowserHandler* LoadFileBrowserHandler(
960 const base::DictionaryValue* file_browser_handlers, string16* error); 972 const base::DictionaryValue* file_browser_handlers, string16* error);
961 bool LoadChromeURLOverrides(string16* error); 973 bool LoadChromeURLOverrides(string16* error);
962 bool LoadOmnibox(string16* error);
963 bool LoadTextToSpeechVoices(string16* error); 974 bool LoadTextToSpeechVoices(string16* error);
964 bool LoadIncognitoMode(string16* error); 975 bool LoadIncognitoMode(string16* error);
965 bool LoadContentSecurityPolicy(string16* error); 976 bool LoadContentSecurityPolicy(string16* error);
966 977
967 bool LoadThemeFeatures(string16* error); 978 bool LoadThemeFeatures(string16* error);
968 bool LoadThemeImages(const base::DictionaryValue* theme_value, 979 bool LoadThemeImages(const base::DictionaryValue* theme_value,
969 string16* error); 980 string16* error);
970 bool LoadThemeColors(const base::DictionaryValue* theme_value, 981 bool LoadThemeColors(const base::DictionaryValue* theme_value,
971 string16* error); 982 string16* error);
972 bool LoadThemeTints(const base::DictionaryValue* theme_value, 983 bool LoadThemeTints(const base::DictionaryValue* theme_value,
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 // The homepage for this extension. Useful if it is not hosted by Google and 1202 // The homepage for this extension. Useful if it is not hosted by Google and
1192 // therefore does not have a Gallery URL. 1203 // therefore does not have a Gallery URL.
1193 GURL homepage_url_; 1204 GURL homepage_url_;
1194 1205
1195 // URL for fetching an update manifest 1206 // URL for fetching an update manifest
1196 GURL update_url_; 1207 GURL update_url_;
1197 1208
1198 // The manifest from which this extension was created. 1209 // The manifest from which this extension was created.
1199 scoped_ptr<Manifest> manifest_; 1210 scoped_ptr<Manifest> manifest_;
1200 1211
1212 // Stored parsed manifest data.
1213 ManifestDataMap manifest_data_;
1214
1215 // Set to true at the end of InitValue when initialization is finished.
1216 bool finished_parsing_manifest_;
1217
1201 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs 1218 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
1202 // which override the handling of those URLs. (see ExtensionOverrideUI). 1219 // which override the handling of those URLs. (see ExtensionOverrideUI).
1203 URLOverrideMap chrome_url_overrides_; 1220 URLOverrideMap chrome_url_overrides_;
1204 1221
1205 // Whether this extension requests isolated storage. 1222 // Whether this extension requests isolated storage.
1206 bool is_storage_isolated_; 1223 bool is_storage_isolated_;
1207 1224
1208 // The local path inside the extension to use with the launcher. 1225 // The local path inside the extension to use with the launcher.
1209 std::string launch_local_path_; 1226 std::string launch_local_path_;
1210 1227
(...skipping 12 matching lines...) Expand all
1223 // containers like panels and windows. 1240 // containers like panels and windows.
1224 int launch_width_; 1241 int launch_width_;
1225 int launch_height_; 1242 int launch_height_;
1226 1243
1227 // Should this app be shown in the app launcher. 1244 // Should this app be shown in the app launcher.
1228 bool display_in_launcher_; 1245 bool display_in_launcher_;
1229 1246
1230 // Should this app be shown in the browser New Tab Page. 1247 // Should this app be shown in the browser New Tab Page.
1231 bool display_in_new_tab_page_; 1248 bool display_in_new_tab_page_;
1232 1249
1233 // The Omnibox keyword for this extension, or empty if there is none.
1234 std::string omnibox_keyword_;
1235
1236 // List of text-to-speech voices that this extension provides, if any. 1250 // List of text-to-speech voices that this extension provides, if any.
1237 std::vector<TtsVoice> tts_voices_; 1251 std::vector<TtsVoice> tts_voices_;
1238 1252
1239 // The OAuth2 client id and scopes, if specified by the extension. 1253 // The OAuth2 client id and scopes, if specified by the extension.
1240 OAuth2Info oauth2_info_; 1254 OAuth2Info oauth2_info_;
1241 1255
1242 // List of intent services that this extension provides, if any. 1256 // List of intent services that this extension provides, if any.
1243 std::vector<webkit_glue::WebIntentServiceData> intents_services_; 1257 std::vector<webkit_glue::WebIntentServiceData> intents_services_;
1244 1258
1245 // List of file handlers associated with this extension, if any. 1259 // List of file handlers associated with this extension, if any.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 1335
1322 UpdatedExtensionPermissionsInfo( 1336 UpdatedExtensionPermissionsInfo(
1323 const Extension* extension, 1337 const Extension* extension,
1324 const PermissionSet* permissions, 1338 const PermissionSet* permissions,
1325 Reason reason); 1339 Reason reason);
1326 }; 1340 };
1327 1341
1328 } // namespace extensions 1342 } // namespace extensions
1329 1343
1330 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ 1344 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/omnibox/omnibox_handler.cc ('k') | chrome/common/extensions/extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698