OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ | 5 #ifndef CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ |
6 #define CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ | 6 #define CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 28 matching lines...) Expand all Loading... |
39 enum HandlerSource { | 39 enum HandlerSource { |
40 USER, // The handler was installed by user | 40 USER, // The handler was installed by user |
41 POLICY, // The handler was installed by policy | 41 POLICY, // The handler was installed by policy |
42 }; | 42 }; |
43 // Provides notification of when the OS level user agent settings | 43 // Provides notification of when the OS level user agent settings |
44 // are changed. | 44 // are changed. |
45 class DefaultClientObserver | 45 class DefaultClientObserver |
46 : public ShellIntegration::DefaultWebClientObserver { | 46 : public ShellIntegration::DefaultWebClientObserver { |
47 public: | 47 public: |
48 explicit DefaultClientObserver(ProtocolHandlerRegistry* registry); | 48 explicit DefaultClientObserver(ProtocolHandlerRegistry* registry); |
49 virtual ~DefaultClientObserver(); | 49 ~DefaultClientObserver() override; |
50 | 50 |
51 // Get response from the worker regarding whether Chrome is the default | 51 // Get response from the worker regarding whether Chrome is the default |
52 // handler for the protocol. | 52 // handler for the protocol. |
53 virtual void SetDefaultWebClientUIState( | 53 void SetDefaultWebClientUIState( |
54 ShellIntegration::DefaultWebClientUIState state) override; | 54 ShellIntegration::DefaultWebClientUIState state) override; |
55 | 55 |
56 virtual bool IsInteractiveSetDefaultPermitted() override; | 56 bool IsInteractiveSetDefaultPermitted() override; |
57 | 57 |
58 // Give the observer a handle to the worker, so we can find out the protocol | 58 // Give the observer a handle to the worker, so we can find out the protocol |
59 // when we're called and also tell the worker if we get deleted. | 59 // when we're called and also tell the worker if we get deleted. |
60 void SetWorker(ShellIntegration::DefaultProtocolClientWorker* worker); | 60 void SetWorker(ShellIntegration::DefaultProtocolClientWorker* worker); |
61 | 61 |
62 protected: | 62 protected: |
63 ShellIntegration::DefaultProtocolClientWorker* worker_; | 63 ShellIntegration::DefaultProtocolClientWorker* worker_; |
64 | 64 |
65 private: | 65 private: |
66 virtual bool IsOwnedByWorker() override; | 66 bool IsOwnedByWorker() override; |
67 | 67 |
68 // This is a raw pointer, not reference counted, intentionally. In general | 68 // This is a raw pointer, not reference counted, intentionally. In general |
69 // subclasses of DefaultWebClientObserver are not able to be refcounted | 69 // subclasses of DefaultWebClientObserver are not able to be refcounted |
70 // e.g. the browser options page | 70 // e.g. the browser options page |
71 ProtocolHandlerRegistry* registry_; | 71 ProtocolHandlerRegistry* registry_; |
72 | 72 |
73 DISALLOW_COPY_AND_ASSIGN(DefaultClientObserver); | 73 DISALLOW_COPY_AND_ASSIGN(DefaultClientObserver); |
74 }; | 74 }; |
75 | 75 |
76 // |Delegate| provides an interface for interacting asynchronously | 76 // |Delegate| provides an interface for interacting asynchronously |
(...skipping 21 matching lines...) Expand all Loading... |
98 // JobInterceptorFactory intercepts URLRequestJob creation for URLRequests the | 98 // JobInterceptorFactory intercepts URLRequestJob creation for URLRequests the |
99 // ProtocolHandlerRegistry is registered to handle. When no handler is | 99 // ProtocolHandlerRegistry is registered to handle. When no handler is |
100 // registered, the URLRequest is passed along to the chained | 100 // registered, the URLRequest is passed along to the chained |
101 // URLRequestJobFactory (set with |JobInterceptorFactory::Chain|). | 101 // URLRequestJobFactory (set with |JobInterceptorFactory::Chain|). |
102 // JobInterceptorFactory's are created via | 102 // JobInterceptorFactory's are created via |
103 // |ProtocolHandlerRegistry::CreateJobInterceptorFactory|. | 103 // |ProtocolHandlerRegistry::CreateJobInterceptorFactory|. |
104 class JobInterceptorFactory : public net::URLRequestJobFactory { | 104 class JobInterceptorFactory : public net::URLRequestJobFactory { |
105 public: | 105 public: |
106 // |io_thread_delegate| is used to perform actual job creation work. | 106 // |io_thread_delegate| is used to perform actual job creation work. |
107 explicit JobInterceptorFactory(IOThreadDelegate* io_thread_delegate); | 107 explicit JobInterceptorFactory(IOThreadDelegate* io_thread_delegate); |
108 virtual ~JobInterceptorFactory(); | 108 ~JobInterceptorFactory() override; |
109 | 109 |
110 // |job_factory| is set as the URLRequestJobFactory where requests are | 110 // |job_factory| is set as the URLRequestJobFactory where requests are |
111 // forwarded if JobInterceptorFactory decides to pass on them. | 111 // forwarded if JobInterceptorFactory decides to pass on them. |
112 void Chain(scoped_ptr<net::URLRequestJobFactory> job_factory); | 112 void Chain(scoped_ptr<net::URLRequestJobFactory> job_factory); |
113 | 113 |
114 // URLRequestJobFactory implementation. | 114 // URLRequestJobFactory implementation. |
115 virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler( | 115 net::URLRequestJob* MaybeCreateJobWithProtocolHandler( |
116 const std::string& scheme, | 116 const std::string& scheme, |
117 net::URLRequest* request, | 117 net::URLRequest* request, |
118 net::NetworkDelegate* network_delegate) const override; | 118 net::NetworkDelegate* network_delegate) const override; |
119 virtual bool IsHandledProtocol(const std::string& scheme) const override; | 119 bool IsHandledProtocol(const std::string& scheme) const override; |
120 virtual bool IsHandledURL(const GURL& url) const override; | 120 bool IsHandledURL(const GURL& url) const override; |
121 virtual bool IsSafeRedirectTarget(const GURL& location) const override; | 121 bool IsSafeRedirectTarget(const GURL& location) const override; |
122 | 122 |
123 private: | 123 private: |
124 // When JobInterceptorFactory decides to pass on particular requests, | 124 // When JobInterceptorFactory decides to pass on particular requests, |
125 // they're forwarded to the chained URLRequestJobFactory, |job_factory_|. | 125 // they're forwarded to the chained URLRequestJobFactory, |job_factory_|. |
126 scoped_ptr<URLRequestJobFactory> job_factory_; | 126 scoped_ptr<URLRequestJobFactory> job_factory_; |
127 // |io_thread_delegate_| performs the actual job creation decisions by | 127 // |io_thread_delegate_| performs the actual job creation decisions by |
128 // mirroring the ProtocolHandlerRegistry on the IO thread. | 128 // mirroring the ProtocolHandlerRegistry on the IO thread. |
129 scoped_refptr<IOThreadDelegate> io_thread_delegate_; | 129 scoped_refptr<IOThreadDelegate> io_thread_delegate_; |
130 | 130 |
131 DISALLOW_COPY_AND_ASSIGN(JobInterceptorFactory); | 131 DISALLOW_COPY_AND_ASSIGN(JobInterceptorFactory); |
132 }; | 132 }; |
133 | 133 |
134 typedef std::map<std::string, ProtocolHandler> ProtocolHandlerMap; | 134 typedef std::map<std::string, ProtocolHandler> ProtocolHandlerMap; |
135 typedef std::vector<ProtocolHandler> ProtocolHandlerList; | 135 typedef std::vector<ProtocolHandler> ProtocolHandlerList; |
136 typedef std::map<std::string, ProtocolHandlerList> ProtocolHandlerMultiMap; | 136 typedef std::map<std::string, ProtocolHandlerList> ProtocolHandlerMultiMap; |
137 typedef std::vector<DefaultClientObserver*> DefaultClientObserverList; | 137 typedef std::vector<DefaultClientObserver*> DefaultClientObserverList; |
138 | 138 |
139 // Creates a new instance. Assumes ownership of |delegate|. | 139 // Creates a new instance. Assumes ownership of |delegate|. |
140 ProtocolHandlerRegistry(content::BrowserContext* context, Delegate* delegate); | 140 ProtocolHandlerRegistry(content::BrowserContext* context, Delegate* delegate); |
141 virtual ~ProtocolHandlerRegistry(); | 141 ~ProtocolHandlerRegistry() override; |
142 | 142 |
143 // Returns a net::URLRequestJobFactory suitable for use on the IO thread, but | 143 // Returns a net::URLRequestJobFactory suitable for use on the IO thread, but |
144 // is initialized on the UI thread. | 144 // is initialized on the UI thread. |
145 scoped_ptr<JobInterceptorFactory> CreateJobInterceptorFactory(); | 145 scoped_ptr<JobInterceptorFactory> CreateJobInterceptorFactory(); |
146 | 146 |
147 // Called when a site tries to register as a protocol handler. If the request | 147 // Called when a site tries to register as a protocol handler. If the request |
148 // can be handled silently by the registry - either to ignore the request | 148 // can be handled silently by the registry - either to ignore the request |
149 // or to update an existing handler - the request will succeed. If this | 149 // or to update an existing handler - the request will succeed. If this |
150 // function returns false the user needs to be prompted for confirmation. | 150 // function returns false the user needs to be prompted for confirmation. |
151 bool SilentlyHandleRegisterHandlerRequest(const ProtocolHandler& handler); | 151 bool SilentlyHandleRegisterHandlerRequest(const ProtocolHandler& handler); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 // Puts this registry in the enabled state - registered protocol handlers | 237 // Puts this registry in the enabled state - registered protocol handlers |
238 // will handle requests. | 238 // will handle requests. |
239 void Enable(); | 239 void Enable(); |
240 | 240 |
241 // Puts this registry in the disabled state - registered protocol handlers | 241 // Puts this registry in the disabled state - registered protocol handlers |
242 // will not handle requests. | 242 // will not handle requests. |
243 void Disable(); | 243 void Disable(); |
244 | 244 |
245 // This is called by the UI thread when the system is shutting down. This | 245 // This is called by the UI thread when the system is shutting down. This |
246 // does finalization which must be done on the UI thread. | 246 // does finalization which must be done on the UI thread. |
247 virtual void Shutdown() override; | 247 void Shutdown() override; |
248 | 248 |
249 // Registers the preferences that we store registered protocol handlers in. | 249 // Registers the preferences that we store registered protocol handlers in. |
250 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 250 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
251 | 251 |
252 bool enabled() const { return enabled_; } | 252 bool enabled() const { return enabled_; } |
253 | 253 |
254 // Add a predefined protocol handler. This has to be called before the first | 254 // Add a predefined protocol handler. This has to be called before the first |
255 // load command was issued, otherwise the command will be ignored. | 255 // load command was issued, otherwise the command will be ignored. |
256 void AddPredefinedHandler(const ProtocolHandler& handler); | 256 void AddPredefinedHandler(const ProtocolHandler& handler); |
257 | 257 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 | 376 |
377 // Copy of registry data for use on the IO thread. Changes to the registry | 377 // Copy of registry data for use on the IO thread. Changes to the registry |
378 // are posted to the IO thread where updates are applied to this object. | 378 // are posted to the IO thread where updates are applied to this object. |
379 scoped_refptr<IOThreadDelegate> io_thread_delegate_; | 379 scoped_refptr<IOThreadDelegate> io_thread_delegate_; |
380 | 380 |
381 DefaultClientObserverList default_client_observers_; | 381 DefaultClientObserverList default_client_observers_; |
382 | 382 |
383 DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistry); | 383 DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistry); |
384 }; | 384 }; |
385 #endif // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ | 385 #endif // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ |
OLD | NEW |