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

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: Sync'd, disallow non-same origin rph, adds hostname to the infobar. 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/custom_handlers/protocol_handler.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "net/url_request/url_request.h"
18 #include "net/url_request/url_request_job.h"
19
20
21
22 // This is where handlers for protocols registered with
23 // navigator.registerProtocolHandler() are registered. Each Profile owns an
24 // instance of this class, which is initialized on browser start through
25 // Profile::InitRegisteredProtocolHandlers(), and they should be the only
26 // instances of this class.
27
28 class ProtocolHandlerRegistry
29 : public base::RefCounted<ProtocolHandlerRegistry> {
30 public:
31 explicit ProtocolHandlerRegistry(Profile* profile);
32
33 // Called when the user accepts the registration of a given protocol handler.
34 void OnAcceptRegisterProtocolHandler(ProtocolHandler* handler);
35
36 // Called when the user denies the registration of a given protocol handler.
37 void OnDenyRegisterProtocolHandler(ProtocolHandler* handler);
38
39 // Loads a user's registered protocol handlers.
40 void Load();
41
42 // Saves a user's registered protocol handlers.
43 void Save();
44
45 // Returns the handler for this protocol.
46 ProtocolHandler* GetHandlerFor(const std::string& scheme) const;
47
48 // Returns true if we allow websites to register handlers for the given
49 // scheme.
50 bool CanSchemeBeOverridden(const std::string& scheme) const;
51
52 // Returns true if an identical protocol handler has already been registered.
53 bool IsAlreadyRegistered(const ProtocolHandler* handler) const;
54
55 // URLRequestFactory for use with URLRequest::RegisterProtocolFactory().
56 // Redirects any URLRequests for which there is a matching protocol handler.
57 static net::URLRequestJob* Factory(net::URLRequest* request,
58 const std::string& scheme);
59
60 // Registers the preferences that we store registered protocol handlers in.
61 static void RegisterPrefs(PrefService* prefService);
62
63 private:
64 typedef std::map<std::string, ProtocolHandler*> ProtocolHandlerMap;
65
66 // Returns a JSON dictionary of protocols to protocol handlers. The caller is
67 // responsible for deleting this Value.
68 Value* Encode();
69
70 // Registers a new protocol handler.
71 void RegisterProtocolHandler(ProtocolHandler* handler);
72
73 // Creates a URL request job for the given request if there is a matching
74 // protocol handler, returns NULL otherwise.
75 net::URLRequestJob* CreateJob(net::URLRequest* request,
76 const std::string& scheme) const;
77
78 // Registers a new protocol handler from a JSON dictionary.
79 void RegisterHandlerFromValue(const DictionaryValue* value);
80
81 // Map from protocols (strings) to protocol handlers.
82 ProtocolHandlerMap protocolHandlers_;
83
84 // The Profile that owns this ProtocolHandlerRegistry.
85 Profile* profile_;
86
87 friend class base::RefCounted<ProtocolHandlerRegistry>;
88 ~ProtocolHandlerRegistry() {}
89
90 DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistry);
91 };
92 #endif // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_
93
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698