OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/sequenced_task_runner_helpers.h" |
15 #include "base/values.h" | 16 #include "base/values.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/shell_integration.h" | 18 #include "chrome/browser/shell_integration.h" |
18 #include "chrome/common/custom_handlers/protocol_handler.h" | 19 #include "chrome/common/custom_handlers/protocol_handler.h" |
19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
21 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
22 #include "net/url_request/url_request_job.h" | 23 #include "net/url_request/url_request_job.h" |
23 | 24 |
24 // This is where handlers for protocols registered with | 25 // This is where handlers for protocols registered with |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 const std::string& protocol, | 78 const std::string& protocol, |
78 ProtocolHandlerRegistry* registry); | 79 ProtocolHandlerRegistry* registry); |
79 }; | 80 }; |
80 | 81 |
81 typedef std::map<std::string, ProtocolHandler> ProtocolHandlerMap; | 82 typedef std::map<std::string, ProtocolHandler> ProtocolHandlerMap; |
82 typedef std::vector<ProtocolHandler> ProtocolHandlerList; | 83 typedef std::vector<ProtocolHandler> ProtocolHandlerList; |
83 typedef std::map<std::string, ProtocolHandlerList> ProtocolHandlerMultiMap; | 84 typedef std::map<std::string, ProtocolHandlerList> ProtocolHandlerMultiMap; |
84 typedef std::vector<DefaultClientObserver*> DefaultClientObserverList; | 85 typedef std::vector<DefaultClientObserver*> DefaultClientObserverList; |
85 | 86 |
86 ProtocolHandlerRegistry(Profile* profile, Delegate* delegate); | 87 ProtocolHandlerRegistry(Profile* profile, Delegate* delegate); |
87 ~ProtocolHandlerRegistry(); | |
88 | 88 |
89 // Called when a site tries to register as a protocol handler. If the request | 89 // Called when a site tries to register as a protocol handler. If the request |
90 // can be handled silently by the registry - either to ignore the request | 90 // can be handled silently by the registry - either to ignore the request |
91 // or to update an existing handler - the request will succeed. If this | 91 // or to update an existing handler - the request will succeed. If this |
92 // function returns false the user needs to be prompted for confirmation. | 92 // function returns false the user needs to be prompted for confirmation. |
93 bool SilentlyHandleRegisterHandlerRequest(const ProtocolHandler& handler); | 93 bool SilentlyHandleRegisterHandlerRequest(const ProtocolHandler& handler); |
94 | 94 |
95 // Called when the user accepts the registration of a given protocol handler. | 95 // Called when the user accepts the registration of a given protocol handler. |
96 void OnAcceptRegisterProtocolHandler(const ProtocolHandler& handler); | 96 void OnAcceptRegisterProtocolHandler(const ProtocolHandler& handler); |
97 | 97 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 // This is called by the UI thread when the system is shutting down. This | 185 // This is called by the UI thread when the system is shutting down. This |
186 // does finalization which must be done on the UI thread. | 186 // does finalization which must be done on the UI thread. |
187 void Finalize(); | 187 void Finalize(); |
188 | 188 |
189 // Registers the preferences that we store registered protocol handlers in. | 189 // Registers the preferences that we store registered protocol handlers in. |
190 static void RegisterPrefs(PrefService* prefService); | 190 static void RegisterPrefs(PrefService* prefService); |
191 | 191 |
192 bool enabled() const { return enabled_; } | 192 bool enabled() const { return enabled_; } |
193 | 193 |
194 private: | 194 private: |
195 friend class base::RefCountedThreadSafe<ProtocolHandlerRegistry>; | 195 friend class base::DeleteHelper<ProtocolHandlerRegistry>; |
| 196 friend struct content::BrowserThread::DeleteOnThread< |
| 197 content::BrowserThread::IO>; |
| 198 friend class ProtocolHandlerRegistryTest; |
| 199 friend class RegisterProtocolHandlerBrowserTest; |
| 200 |
| 201 ~ProtocolHandlerRegistry(); |
196 | 202 |
197 // Puts the given handler at the top of the list of handlers for its | 203 // Puts the given handler at the top of the list of handlers for its |
198 // protocol. | 204 // protocol. |
199 void PromoteHandler(const ProtocolHandler& handler); | 205 void PromoteHandler(const ProtocolHandler& handler); |
200 | 206 |
201 // Clears the default for the provided protocol. | 207 // Clears the default for the provided protocol. |
202 // Should be called only from the IO thread. | 208 // Should be called only from the IO thread. |
203 void ClearDefaultIO(const std::string& scheme); | 209 void ClearDefaultIO(const std::string& scheme); |
204 | 210 |
205 // Makes this ProtocolHandler the default handler for its protocol. | 211 // Makes this ProtocolHandler the default handler for its protocol. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 void RegisterProtocolHandler(const ProtocolHandler& handler); | 248 void RegisterProtocolHandler(const ProtocolHandler& handler); |
243 | 249 |
244 // Get the DictionaryValues stored under the given pref name that are valid | 250 // Get the DictionaryValues stored under the given pref name that are valid |
245 // ProtocolHandler values. | 251 // ProtocolHandler values. |
246 std::vector<const DictionaryValue*> GetHandlersFromPref( | 252 std::vector<const DictionaryValue*> GetHandlersFromPref( |
247 const char* pref_name) const; | 253 const char* pref_name) const; |
248 | 254 |
249 // Ignores future requests to register the given protocol handler. | 255 // Ignores future requests to register the given protocol handler. |
250 void IgnoreProtocolHandler(const ProtocolHandler& handler); | 256 void IgnoreProtocolHandler(const ProtocolHandler& handler); |
251 | 257 |
252 // Register | |
253 void IgnoreHandlerFromValue(const DictionaryValue* value); | |
254 | |
255 // Map from protocols (strings) to protocol handlers. | 258 // Map from protocols (strings) to protocol handlers. |
256 ProtocolHandlerMultiMap protocol_handlers_; | 259 ProtocolHandlerMultiMap protocol_handlers_; |
257 | 260 |
258 // Protocol handlers that the user has told us to ignore. | 261 // Protocol handlers that the user has told us to ignore. |
259 ProtocolHandlerList ignored_protocol_handlers_; | 262 ProtocolHandlerList ignored_protocol_handlers_; |
260 | 263 |
261 // Protocol handlers that are the defaults for a given protocol. | 264 // Protocol handlers that are the defaults for a given protocol. |
262 ProtocolHandlerMap default_handlers_; | 265 ProtocolHandlerMap default_handlers_; |
263 | 266 |
264 // The Profile that owns this ProtocolHandlerRegistry. | 267 // The Profile that owns this ProtocolHandlerRegistry. |
(...skipping 10 matching lines...) Expand all Loading... |
275 bool enabled_io_; | 278 bool enabled_io_; |
276 | 279 |
277 // Whether or not we are loading. | 280 // Whether or not we are loading. |
278 bool is_loading_; | 281 bool is_loading_; |
279 | 282 |
280 DefaultClientObserverList default_client_observers_; | 283 DefaultClientObserverList default_client_observers_; |
281 | 284 |
282 // Copy of default_handlers_ that is only accessed on the IO thread. | 285 // Copy of default_handlers_ that is only accessed on the IO thread. |
283 ProtocolHandlerMap default_handlers_io_; | 286 ProtocolHandlerMap default_handlers_io_; |
284 | 287 |
285 friend class ProtocolHandlerRegistryTest; | |
286 friend class RegisterProtocolHandlerBrowserTest; | |
287 | |
288 DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistry); | 288 DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistry); |
289 }; | 289 }; |
290 #endif // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ | 290 #endif // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ |
OLD | NEW |