Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #ifndef CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ | |
| 2 #define CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ | |
| 3 #pragma once | |
| 4 | |
| 5 #include "base/ref_counted.h" | |
| 6 #include "chrome/browser/profiles/profile.h" | |
| 7 #include "net/url_request/url_request_job.h" | |
| 8 #include "net/url_request/url_request.h" | |
| 9 #include "base/values.h" | |
| 10 | |
| 11 #include <string> | |
| 12 #include <iostream> | |
| 13 #include <map> | |
| 14 | |
| 15 | |
| 16 // ProtocolHandler ------------------------------------------------------------- | |
| 17 | |
| 18 // A single tuple of (protocol, url, title) that indicates how URLs of the | |
| 19 // given protocol should be rewritten to be handled. | |
| 20 | |
| 21 class ProtocolHandler { | |
| 22 public: | |
|
tony
2011/02/07 20:51:45
Nit: one space indent
koz (OOO until 15th September)
2011/02/13 22:33:48
Done.
| |
| 23 static ProtocolHandler* CreateProtocolHandler(const std::string& protocol, con st 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.
| |
| 24 static ProtocolHandler* CreateProtocolHandler(const DictionaryValue* value); | |
| 25 GURL TranslateUrl(const GURL& url); | |
| 26 Value* Encode(); | |
| 27 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.
| |
| 28 const std::string& url() { return url_;} | |
| 29 const std::string& title() { return title_; } | |
| 30 private: | |
| 31 ProtocolHandler(const std::string& protocol, const std::string& url, const std ::string& title); | |
| 32 std::string SpliceInto(const std::string& templ, const std::string& value); | |
| 33 const std::string protocol_; | |
| 34 const std::string url_; | |
| 35 const std::string title_; | |
| 36 }; | |
| 37 | |
| 38 typedef std::map<std::string, ProtocolHandler*> ProtocolHandlerMap; | |
| 39 | |
| 40 // ProtocolHandlerRegistry ----------------------------------------------------- | |
| 41 | |
| 42 // This is where handlers for protocols registered with | |
| 43 // navigator.registerProtocolHandler() are registered. Each Profile owns an | |
| 44 // instance of this class, which is initialized on browser start through | |
| 45 // Profile::InitRegisteredProtocolHandlers(), and they should be the only | |
| 46 // instances of this class. | |
| 47 | |
| 48 class ProtocolHandlerRegistry : public base::RefCounted<ProtocolHandlerRegistry> { | |
| 49 public: | |
| 50 ProtocolHandlerRegistry(Profile* profile); | |
| 51 | |
| 52 // Called when the user accepts the registration of a given protocol handler. | |
| 53 void OnAcceptRegisterProtocolHandler(ProtocolHandler* handler); | |
| 54 | |
| 55 // Called when the user denies the registration of a given protocol handler. | |
| 56 void OnDenyRegisterProtocolHandler(ProtocolHandler* handler); | |
| 57 | |
| 58 // Loads a user's registered protocol handlers. | |
| 59 void Load(); | |
| 60 | |
| 61 // Saves a user's registered protocol handlers. | |
| 62 void Save(); | |
| 63 | |
| 64 // URLRequestFactory for use with URLRequest::RegisterProtocolFactory(). | |
| 65 // Redirects any URLRequests for which there is a matching protocol handler. | |
| 66 static net::URLRequestJob* Factory(net::URLRequest* request, const std::string & scheme); | |
| 67 | |
| 68 // Registers the preferences that we store registered protocol handlers in. | |
| 69 static void RegisterPrefs(PrefService* prefService); | |
| 70 | |
| 71 private: | |
| 72 // 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.
| |
| 73 Value* Encode(); | |
| 74 | |
| 75 // Registers a new protocol handler. | |
| 76 void RegisterProtocolHandler(ProtocolHandler* handler); | |
| 77 | |
| 78 // Creates a URL request job for the given request if there is a matching | |
| 79 // protocol handler, returns NULL otherwise. | |
| 80 net::URLRequestJob* CreateJob(net::URLRequest* request, const std::string& sch eme) const; | |
| 81 | |
| 82 // Registers a new protocol handler from a JSON dictionary. | |
| 83 void RegisterHandlerFromValue(const DictionaryValue* value); | |
| 84 | |
| 85 // Map from protocols (strings) to protocol handlers. | |
| 86 ProtocolHandlerMap protocolHandlers_; | |
| 87 | |
| 88 // The Profile that owns this ProtocolHandlerRegistry. | |
| 89 Profile* profile_; | |
| 90 | |
| 91 friend class base::RefCounted<ProtocolHandlerRegistry>; | |
| 92 ~ProtocolHandlerRegistry() {}; | |
|
tony
2011/02/07 20:51:45
DISALLOW_COPY_AND_ASSIGN?
koz (OOO until 15th September)
2011/02/13 22:33:48
Done.
| |
| 93 }; | |
| 94 #endif // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ | |
| OLD | NEW |