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

Side by Side 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: Responded to comments, prevents rph on privileged protocols. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_
6 #define CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_
7 #pragma once
8
9 #include <string>
10 #include <map>
11
12 #include "base/basictypes.h"
13 #include "base/ref_counted.h"
14 #include "base/values.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "net/url_request/url_request.h"
17 #include "net/url_request/url_request_job.h"
18
19
20 // ProtocolHandler -------------------------------------------------------------
21
22 // A single tuple of (protocol, url, title) that indicates how URLs of the
23 // given protocol should be rewritten to be handled.
24
25 class ProtocolHandler {
jam 2011/02/15 18:48:39 this class should just go into its own file
koz (OOO until 15th September) 2011/02/16 03:37:48 Done.
26 public:
27 static ProtocolHandler* CreateProtocolHandler(const std::string& protocol,
28 const GURL& url,
29 const string16& title);
30 static ProtocolHandler* CreateProtocolHandler(const DictionaryValue* value);
31
32 // Interpolates the given URL into the URL template of this handler.
33 GURL TranslateUrl(const GURL& url);
34
35 // Encodes this protocol handler as a Value. The caller is responsible for
36 // deleting the returned value.
37 Value* Encode();
38
39 std::string protocol() const { return protocol_; }
40 GURL url() const { return url_;}
41 string16 title() const { return title_; }
42
43 bool operator==(const ProtocolHandler &other) const;
44
45 private:
46 ProtocolHandler(const std::string& protocol,
47 const GURL& url,
48 const string16& title);
49 const std::string protocol_;
50 const GURL url_;
51 const string16 title_;
52 };
53
54 typedef std::map<std::string, ProtocolHandler*> ProtocolHandlerMap;
jam 2011/02/15 18:48:39 it's preferable that this typedef is inside a clas
koz (OOO until 15th September) 2011/02/16 03:37:48 Done.
55
56 // ProtocolHandlerRegistry -----------------------------------------------------
57
58 // This is where handlers for protocols registered with
59 // navigator.registerProtocolHandler() are registered. Each Profile owns an
60 // instance of this class, which is initialized on browser start through
61 // Profile::InitRegisteredProtocolHandlers(), and they should be the only
62 // instances of this class.
63
64 class ProtocolHandlerRegistry
65 : public base::RefCounted<ProtocolHandlerRegistry> {
66 public:
67 explicit ProtocolHandlerRegistry(Profile* profile);
68
69 // Called when the user accepts the registration of a given protocol handler.
70 void OnAcceptRegisterProtocolHandler(ProtocolHandler* handler);
71
72 // Called when the user denies the registration of a given protocol handler.
73 void OnDenyRegisterProtocolHandler(ProtocolHandler* handler);
74
75 // Loads a user's registered protocol handlers.
76 void Load();
77
78 // Saves a user's registered protocol handlers.
79 void Save();
80
81 // Returns the handler for this protocol.
82 ProtocolHandler* GetHandlerFor(const std::string& scheme) const;
83
84 // Returns true if we allow websites to register handlers for the given
85 // scheme.
86 bool CanSchemeBeOverridden(const std::string& scheme) const;
87
88 // Returns true if an identical protocol handler has already been registered.
89 bool IsAlreadyRegistered(const ProtocolHandler* handler) const;
90
91 // URLRequestFactory for use with URLRequest::RegisterProtocolFactory().
92 // Redirects any URLRequests for which there is a matching protocol handler.
93 static net::URLRequestJob* Factory(net::URLRequest* request,
94 const std::string& scheme);
95
96 // Registers the preferences that we store registered protocol handlers in.
97 static void RegisterPrefs(PrefService* prefService);
98
99 private:
100 // Returns a JSON dictionary of protocols to protocol handlers. The caller is
101 // responsible for deleting this Value.
102 Value* Encode();
103
104 // Registers a new protocol handler.
105 void RegisterProtocolHandler(ProtocolHandler* handler);
106
107 // Creates a URL request job for the given request if there is a matching
108 // protocol handler, returns NULL otherwise.
109 net::URLRequestJob* CreateJob(net::URLRequest* request,
110 const std::string& scheme) const;
111
112 // Registers a new protocol handler from a JSON dictionary.
113 void RegisterHandlerFromValue(const DictionaryValue* value);
114
115 // Map from protocols (strings) to protocol handlers.
116 ProtocolHandlerMap protocolHandlers_;
117
118 // The Profile that owns this ProtocolHandlerRegistry.
119 Profile* profile_;
120
121 friend class base::RefCounted<ProtocolHandlerRegistry>;
122 ~ProtocolHandlerRegistry() {}
123
124 DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistry);
125 };
126 #endif // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_
127
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698