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

Unified Diff: chrome/browser/custom_handlers/protocol_handler_registry.h

Issue 6410115: Adds navigator.registerProtocolHandler. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 10 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/custom_handlers/protocol_handler_registry.h
diff --git a/chrome/browser/custom_handlers/protocol_handler_registry.h b/chrome/browser/custom_handlers/protocol_handler_registry.h
new file mode 100644
index 0000000000000000000000000000000000000000..9cd0bcb587769cc9ac4146549917231e7378b0bd
--- /dev/null
+++ b/chrome/browser/custom_handlers/protocol_handler_registry.h
@@ -0,0 +1,94 @@
+#ifndef CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_
+#define CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_
+#pragma once
+
+#include "base/ref_counted.h"
+#include "chrome/browser/profiles/profile.h"
+#include "net/url_request/url_request_job.h"
+#include "net/url_request/url_request.h"
+#include "base/values.h"
+
+#include <string>
+#include <iostream>
+#include <map>
+
+
+// ProtocolHandler -------------------------------------------------------------
+
+// A single tuple of (protocol, url, title) that indicates how URLs of the
+// given protocol should be rewritten to be handled.
+
+class ProtocolHandler {
+public:
tony 2011/02/07 20:51:45 Nit: one space indent
koz (OOO until 15th September) 2011/02/13 22:33:48 Done.
+ static ProtocolHandler* CreateProtocolHandler(const std::string& protocol, const std::string& url, const std::string& title);
tony 2011/02/07 20:51:45 Nit: 80 cols and lots of other style violations.
koz (OOO until 15th September) 2011/02/13 22:33:48 Done.
+ static ProtocolHandler* CreateProtocolHandler(const DictionaryValue* value);
+ GURL TranslateUrl(const GURL& url);
+ Value* Encode();
+ const std::string& protocol() { return protocol_; }
tony 2011/02/07 20:51:45 Nit: I am skeptical of the benefits of returning r
koz (OOO until 15th September) 2011/02/13 22:33:48 Done.
+ const std::string& url() { return url_;}
+ const std::string& title() { return title_; }
+private:
+ ProtocolHandler(const std::string& protocol, const std::string& url, const std::string& title);
+ std::string SpliceInto(const std::string& templ, const std::string& value);
+ const std::string protocol_;
+ const std::string url_;
+ const std::string title_;
+};
+
+typedef std::map<std::string, ProtocolHandler*> ProtocolHandlerMap;
+
+// ProtocolHandlerRegistry -----------------------------------------------------
+
+// This is where handlers for protocols registered with
+// navigator.registerProtocolHandler() are registered. Each Profile owns an
+// instance of this class, which is initialized on browser start through
+// Profile::InitRegisteredProtocolHandlers(), and they should be the only
+// instances of this class.
+
+class ProtocolHandlerRegistry : public base::RefCounted<ProtocolHandlerRegistry> {
+public:
+ ProtocolHandlerRegistry(Profile* profile);
+
+ // Called when the user accepts the registration of a given protocol handler.
+ void OnAcceptRegisterProtocolHandler(ProtocolHandler* handler);
+
+ // Called when the user denies the registration of a given protocol handler.
+ void OnDenyRegisterProtocolHandler(ProtocolHandler* handler);
+
+ // Loads a user's registered protocol handlers.
+ void Load();
+
+ // Saves a user's registered protocol handlers.
+ void Save();
+
+ // URLRequestFactory for use with URLRequest::RegisterProtocolFactory().
+ // Redirects any URLRequests for which there is a matching protocol handler.
+ static net::URLRequestJob* Factory(net::URLRequest* request, const std::string& scheme);
+
+ // Registers the preferences that we store registered protocol handlers in.
+ static void RegisterPrefs(PrefService* prefService);
+
+private:
+ // Returns a JSON dictionary of protocols to protocol handlers.
tony 2011/02/07 20:51:45 Nit: Maybe mention that the caller is responsible
koz (OOO until 15th September) 2011/02/13 22:33:48 Done.
+ Value* Encode();
+
+ // Registers a new protocol handler.
+ void RegisterProtocolHandler(ProtocolHandler* handler);
+
+ // Creates a URL request job for the given request if there is a matching
+ // protocol handler, returns NULL otherwise.
+ net::URLRequestJob* CreateJob(net::URLRequest* request, const std::string& scheme) const;
+
+ // Registers a new protocol handler from a JSON dictionary.
+ void RegisterHandlerFromValue(const DictionaryValue* value);
+
+ // Map from protocols (strings) to protocol handlers.
+ ProtocolHandlerMap protocolHandlers_;
+
+ // The Profile that owns this ProtocolHandlerRegistry.
+ Profile* profile_;
+
+ friend class base::RefCounted<ProtocolHandlerRegistry>;
+ ~ProtocolHandlerRegistry() {};
tony 2011/02/07 20:51:45 DISALLOW_COPY_AND_ASSIGN?
koz (OOO until 15th September) 2011/02/13 22:33:48 Done.
+};
+#endif // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_

Powered by Google App Engine
This is Rietveld 408576698