summaryrefslogtreecommitdiffstats
path: root/chrome/browser/custom_handlers/protocol_handler_registry.h
diff options
context:
space:
mode:
authorkoz@chromium.org <koz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-02 18:54:49 +0000
committerkoz@chromium.org <koz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-02 18:54:49 +0000
commitfd8ca5208c2035467253b5f8613c46745688d655 (patch)
tree2b9eb7d357027f3bf2ca99d462b39bcf83bb696a /chrome/browser/custom_handlers/protocol_handler_registry.h
parent695b5bbbd76715aec3a3310529f4aeb4c8b32f43 (diff)
downloadchromium_src-fd8ca5208c2035467253b5f8613c46745688d655.zip
chromium_src-fd8ca5208c2035467253b5f8613c46745688d655.tar.gz
chromium_src-fd8ca5208c2035467253b5f8613c46745688d655.tar.bz2
Add unit test and 'ignore' functionality to ProtocolHandlerRegistry.
When we change the infobar to make use of this functionality it will make it feasible for sites to make registerProtocolHandler calls on load, instead of in response to a user action. BUG= TEST=Unit test provided. Review URL: http://codereview.chromium.org/6878094 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83751 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.h83
1 files changed, 74 insertions, 9 deletions
diff --git a/chrome/browser/custom_handlers/protocol_handler_registry.h b/chrome/browser/custom_handlers/protocol_handler_registry.h
index 9ae3cfc..868bd2b 100644
--- a/chrome/browser/custom_handlers/protocol_handler_registry.h
+++ b/chrome/browser/custom_handlers/protocol_handler_registry.h
@@ -6,18 +6,21 @@
#define CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_
#pragma once
-#include <string>
#include <map>
+#include <string>
+#include <vector>
#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;
// This is where handlers for protocols registered with
// navigator.registerProtocolHandler() are registered. Each Profile owns an
@@ -28,7 +31,10 @@
class ProtocolHandlerRegistry
: public base::RefCountedThreadSafe<ProtocolHandlerRegistry> {
public:
- explicit ProtocolHandlerRegistry(Profile* profile);
+ class Delegate;
+
+ ProtocolHandlerRegistry(Profile* profile, Delegate* delegate);
+ ~ProtocolHandlerRegistry();
// Called when the user accepts the registration of a given protocol handler.
void OnAcceptRegisterProtocolHandler(ProtocolHandler* handler);
@@ -36,6 +42,10 @@ class ProtocolHandlerRegistry
// Called when the user denies the registration of a given protocol handler.
void OnDenyRegisterProtocolHandler(ProtocolHandler* handler);
+ // Called when the user indicates that they don't want to be asked about the
+ // given protocol handler again.
+ void OnIgnoreRegisterProtocolHandler(ProtocolHandler* handler);
+
// Loads a user's registered protocol handlers.
void Load();
@@ -45,12 +55,27 @@ class ProtocolHandlerRegistry
// Returns the handler for this protocol.
ProtocolHandler* GetHandlerFor(const std::string& scheme) const;
+ // Yields a list of the protocols handled by this registry.
+ void GetHandledProtocols(std::vector<std::string>* output);
+
// Returns true if we allow websites to register handlers for the given
// scheme.
bool CanSchemeBeOverridden(const std::string& scheme) const;
// Returns true if an identical protocol handler has already been registered.
- bool IsAlreadyRegistered(const ProtocolHandler* handler) const;
+ bool IsRegistered(const ProtocolHandler* handler) const;
+
+ // Returns true if the protocol handler is being ignored.
+ bool IsIgnored(const ProtocolHandler* handler) const;
+
+ // 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);
+
+ // Causes the given protocol handler to not be ignored anymore.
+ void RemoveIgnoredHandler(ProtocolHandler* handler);
// URLRequestFactory for use with URLRequest::RegisterProtocolFactory().
// Redirects any URLRequests for which there is a matching protocol handler.
@@ -64,28 +89,68 @@ class ProtocolHandlerRegistry
// protocol handler, returns NULL otherwise.
net::URLRequestJob* MaybeCreateJob(net::URLRequest* request) const;
+ // Puts this registry in the enabled state - registered protocol handlers
+ // will handle requests.
+ void Enable();
+
+ // Puts this registry in the disabled state - registered protocol handlers
+ // will not handle requests.
+ void Disable();
+
+ bool enabled() { return enabled_; }
+
+ class Delegate {
+ public:
+ virtual ~Delegate();
+ virtual void RegisterExternalHandler(const std::string& protocol);
+ virtual void DeregisterExternalHandler(const std::string& protocol);
+ virtual bool IsExternalHandlerRegistered(const std::string& protocol);
+ };
+
private:
- typedef std::map<std::string, ProtocolHandler*> ProtocolHandlerMap;
friend class base::RefCountedThreadSafe<ProtocolHandlerRegistry>;
- ~ProtocolHandlerRegistry();
- // Returns a JSON dictionary of protocols to protocol handlers. The caller is
+ // Returns a JSON list of protocol handlers. The caller is responsible for
+ // deleting this Value.
+ Value* EncodeRegisteredHandlers();
+
+ // Returns a JSON list of ignored protocol handlers. The caller is
// responsible for deleting this Value.
- Value* Encode();
+ Value* EncodeIgnoredHandlers();
// Registers a new protocol handler.
void RegisterProtocolHandler(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);
+
+ // Ignores future requests to register the given protocol handler.
+ void IgnoreProtocolHandler(ProtocolHandler* handler);
+
// Registers a new protocol handler from a JSON dictionary.
void RegisterHandlerFromValue(const DictionaryValue* value);
+ // Register
+ void IgnoreHandlerFromValue(const DictionaryValue* value);
+
// Map from protocols (strings) to protocol handlers.
- ProtocolHandlerMap protocolHandlers_;
+ ProtocolHandlerMap protocol_handlers_;
+
+ // Protocol handlers that the user has told us to ignore.
+ ProtocolHandlerList ignored_protocol_handlers_;
// The Profile that owns this ProtocolHandlerRegistry.
Profile* profile_;
+ // The Delegate that registers / deregisters external handlers on our behalf.
+ scoped_ptr<Delegate> delegate_;
+
+ // If false then registered protocol handlers will not be used to handle
+ // requests.
+ bool enabled_;
+
DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistry);
};
#endif // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_