diff options
author | koz@chromium.org <koz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-06 21:24:16 +0000 |
---|---|---|
committer | koz@chromium.org <koz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-06 21:24:16 +0000 |
commit | ccec4706b7e6f2c145e71f95ebc9544a1e3092d2 (patch) | |
tree | f6658305a1a5b30430277c092b5eeff6e674c189 /chrome/browser/custom_handlers/protocol_handler_registry.h | |
parent | c0f7082fdc8b239027b196a777180899bf7f5ce3 (diff) | |
download | chromium_src-ccec4706b7e6f2c145e71f95ebc9544a1e3092d2.zip chromium_src-ccec4706b7e6f2c145e71f95ebc9544a1e3092d2.tar.gz chromium_src-ccec4706b7e6f2c145e71f95ebc9544a1e3092d2.tar.bz2 |
Add the abililty to have multiple handlers and default handlers for a protocol.
R=tony
TEST=Unit tests included.
Review URL: http://codereview.chromium.org/6927040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84505 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/custom_handlers/protocol_handler_registry.h')
-rw-r--r-- | chrome/browser/custom_handlers/protocol_handler_registry.h | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/chrome/browser/custom_handlers/protocol_handler_registry.h b/chrome/browser/custom_handlers/protocol_handler_registry.h index 3380626..4844f44 100644 --- a/chrome/browser/custom_handlers/protocol_handler_registry.h +++ b/chrome/browser/custom_handlers/protocol_handler_registry.h @@ -13,14 +13,14 @@ #include "base/basictypes.h" #include "base/memory/ref_counted.h" #include "base/values.h" +#include "chrome/browser/custom_handlers/protocol_handler.h" #include "chrome/browser/profiles/profile.h" #include "net/url_request/url_request.h" #include "net/url_request/url_request_job.h" -class ProtocolHandler; - typedef std::map<std::string, ProtocolHandler> ProtocolHandlerMap; typedef std::vector<ProtocolHandler> ProtocolHandlerList; +typedef std::map<std::string, ProtocolHandlerList> ProtocolHandlerMultiMap; // This is where handlers for protocols registered with // navigator.registerProtocolHandler() are registered. Each Profile owns an @@ -46,17 +46,31 @@ class ProtocolHandlerRegistry // given protocol handler again. void OnIgnoreRegisterProtocolHandler(const ProtocolHandler& handler); + // Makes this ProtocolHandler the default handler for its protocol. + void SetDefault(const ProtocolHandler& handler); + + // Clears the default for the provided protocol. + void ClearDefault(const std::string& scheme); + + // Returns true if this handler is the default handler for its protocol. + bool IsDefault(const ProtocolHandler& handler) const; + + // Returns true if the given protocol has a default handler associated with + // it. + const bool HasDefault(const std::string& scheme) const; + + // Returns true if there is a handler registered for the given protocol. + bool HasHandler(const std::string& scheme); + // Loads a user's registered protocol handlers. void Load(); // Saves a user's registered protocol handlers. void Save(); - // Returns true if there is a handler registered for the given protocol. - bool HandlerExistsFor(const std::string& scheme) const; - - // Returns the handler for this protocol. - ProtocolHandler GetHandlerFor(const std::string& scheme) const; + // Returns the default handler for this protocol, or an empty handler if none + // exists. + const ProtocolHandler& GetHandlerFor(const std::string& scheme) const; // Yields a list of the protocols handled by this registry. void GetHandledProtocols(std::vector<std::string>* output) const; @@ -66,7 +80,7 @@ class ProtocolHandlerRegistry bool CanSchemeBeOverridden(const std::string& scheme) const; // Returns true if an identical protocol handler has already been registered. - bool IsRegistered(const ProtocolHandler& handler) const; + bool IsRegistered(const ProtocolHandler& handler); // Returns true if the protocol handler is being ignored. bool IsIgnored(const ProtocolHandler& handler) const; @@ -74,8 +88,8 @@ class ProtocolHandlerRegistry // Returns true if the protocol has a registered protocol handler. bool IsHandledProtocol(const std::string& scheme) const; - // Removes any existing protocol handler for the given protocol. - void RemoveHandlerFor(const std::string& scheme); + // Removes the given protocol handler from the registry. + void RemoveHandler(const ProtocolHandler& handler); // Causes the given protocol handler to not be ignored anymore. void RemoveIgnoredHandler(const ProtocolHandler& handler); @@ -125,9 +139,10 @@ class ProtocolHandlerRegistry // Registers a new protocol handler. void RegisterProtocolHandler(const ProtocolHandler& handler); - // Get the ProtocolHandlers stored under the given pref name. The caller owns - // the returned ProtocolHandlers and is responsible for deleting them. - ProtocolHandlerList GetHandlersFromPref(const char* pref_name); + // Get the DictionaryValues stored under the given pref name that are valid + // ProtocolHandler values. + std::vector<const DictionaryValue*> GetHandlersFromPref( + const char* pref_name); // Ignores future requests to register the given protocol handler. void IgnoreProtocolHandler(const ProtocolHandler& handler); @@ -138,12 +153,17 @@ class ProtocolHandlerRegistry // Register void IgnoreHandlerFromValue(const DictionaryValue* value); + ProtocolHandlerList& GetHandlerListFor(const std::string& scheme); + // Map from protocols (strings) to protocol handlers. - ProtocolHandlerMap protocol_handlers_; + ProtocolHandlerMultiMap protocol_handlers_; // Protocol handlers that the user has told us to ignore. ProtocolHandlerList ignored_protocol_handlers_; + // Protocol handlers that are the defaults for a given protocol. + ProtocolHandlerMap default_handlers_; + // The Profile that owns this ProtocolHandlerRegistry. Profile* profile_; @@ -154,6 +174,9 @@ class ProtocolHandlerRegistry // requests. bool enabled_; + // Whether or not we are loading. + bool is_loading_; + DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistry); }; #endif // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ |