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 18 matching lines...) Expand all Loading... |
29 } | 29 } |
30 | 30 |
31 // This is where handlers for protocols registered with | 31 // This is where handlers for protocols registered with |
32 // navigator.registerProtocolHandler() are registered. Each Profile owns an | 32 // navigator.registerProtocolHandler() are registered. Each Profile owns an |
33 // instance of this class, which is initialized on browser start through | 33 // instance of this class, which is initialized on browser start through |
34 // Profile::InitRegisteredProtocolHandlers(), and they should be the only | 34 // Profile::InitRegisteredProtocolHandlers(), and they should be the only |
35 // instances of this class. | 35 // instances of this class. |
36 class ProtocolHandlerRegistry : public KeyedService { | 36 class ProtocolHandlerRegistry : public KeyedService { |
37 | 37 |
38 public: | 38 public: |
| 39 enum HandlerSource { |
| 40 USER, // The handler was installed by user |
| 41 POLICY, // The handler was installed by policy |
| 42 }; |
39 // Provides notification of when the OS level user agent settings | 43 // Provides notification of when the OS level user agent settings |
40 // are changed. | 44 // are changed. |
41 class DefaultClientObserver | 45 class DefaultClientObserver |
42 : public ShellIntegration::DefaultWebClientObserver { | 46 : public ShellIntegration::DefaultWebClientObserver { |
43 public: | 47 public: |
44 explicit DefaultClientObserver(ProtocolHandlerRegistry* registry); | 48 explicit DefaultClientObserver(ProtocolHandlerRegistry* registry); |
45 virtual ~DefaultClientObserver(); | 49 virtual ~DefaultClientObserver(); |
46 | 50 |
47 // Get response from the worker regarding whether Chrome is the default | 51 // Get response from the worker regarding whether Chrome is the default |
48 // handler for the protocol. | 52 // handler for the protocol. |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 base::Value* EncodeRegisteredHandlers(); | 284 base::Value* EncodeRegisteredHandlers(); |
281 | 285 |
282 // Returns a JSON list of ignored protocol handlers. The caller is | 286 // Returns a JSON list of ignored protocol handlers. The caller is |
283 // responsible for deleting this Value. | 287 // responsible for deleting this Value. |
284 base::Value* EncodeIgnoredHandlers(); | 288 base::Value* EncodeIgnoredHandlers(); |
285 | 289 |
286 // Sends a notification of the given type to the NotificationService. | 290 // Sends a notification of the given type to the NotificationService. |
287 void NotifyChanged(); | 291 void NotifyChanged(); |
288 | 292 |
289 // Registers a new protocol handler. | 293 // Registers a new protocol handler. |
290 void RegisterProtocolHandler(const ProtocolHandler& handler); | 294 void RegisterProtocolHandler(const ProtocolHandler& handler, |
| 295 const HandlerSource source); |
| 296 |
| 297 // Registers protocol handlers from the preference. |
| 298 void RegisterProtocolHandlersFromPref(const char* pref_name, |
| 299 const HandlerSource source); |
291 | 300 |
292 // Get the DictionaryValues stored under the given pref name that are valid | 301 // Get the DictionaryValues stored under the given pref name that are valid |
293 // ProtocolHandler values. | 302 // ProtocolHandler values. |
294 std::vector<const base::DictionaryValue*> GetHandlersFromPref( | 303 std::vector<const base::DictionaryValue*> GetHandlersFromPref( |
295 const char* pref_name) const; | 304 const char* pref_name) const; |
296 | 305 |
297 // Ignores future requests to register the given protocol handler. | 306 // Ignores future requests to register the given protocol handler. |
298 void IgnoreProtocolHandler(const ProtocolHandler& handler); | 307 void IgnoreProtocolHandler(const ProtocolHandler& handler, |
| 308 const HandlerSource source); |
| 309 |
| 310 // Ignores protocol handlers from the preference. |
| 311 void IgnoreProtocolHandlersFromPref(const char* pref_name, |
| 312 const HandlerSource source); |
| 313 |
| 314 // Verifies if the handler exists in the map. |
| 315 bool HandlerExists(const ProtocolHandler& handler, |
| 316 ProtocolHandlerMultiMap* map); |
| 317 |
| 318 // Verifies if the handler exists in the list. |
| 319 bool HandlerExists(const ProtocolHandler& handler, |
| 320 const ProtocolHandlerList& list); |
| 321 |
| 322 // Erases the handler that is guaranteed to exist from the map. |
| 323 void EraseHandler(const ProtocolHandler& handler, |
| 324 ProtocolHandlerMultiMap* map); |
| 325 |
| 326 // Erases the handler that is guaranteed to exist from the list. |
| 327 void EraseHandler(const ProtocolHandler& handler, ProtocolHandlerList* list); |
299 | 328 |
300 // Map from protocols (strings) to protocol handlers. | 329 // Map from protocols (strings) to protocol handlers. |
301 ProtocolHandlerMultiMap protocol_handlers_; | 330 ProtocolHandlerMultiMap protocol_handlers_; |
302 | 331 |
303 // Protocol handlers that the user has told us to ignore. | 332 // Protocol handlers that the user has told us to ignore. |
304 ProtocolHandlerList ignored_protocol_handlers_; | 333 ProtocolHandlerList ignored_protocol_handlers_; |
305 | 334 |
| 335 // These maps track the source of protocol handler registrations for the |
| 336 // purposes of disallowing the removal of handlers that are registered by |
| 337 // policy. Every entry in protocol_handlers_ should exist in at least one of |
| 338 // the user or policy maps. |
| 339 ProtocolHandlerMultiMap user_protocol_handlers_; |
| 340 ProtocolHandlerMultiMap policy_protocol_handlers_; |
| 341 |
| 342 // These lists track the source of protocol handlers that were ignored, for |
| 343 // the purposes of disallowing the removal of handlers that are ignored by |
| 344 // policy. Every entry in ignored_protocol_handlers_ should exist in at least |
| 345 // one of the user or policy lists. |
| 346 ProtocolHandlerList user_ignored_protocol_handlers_; |
| 347 ProtocolHandlerList policy_ignored_protocol_handlers_; |
| 348 |
306 // Protocol handlers that are the defaults for a given protocol. | 349 // Protocol handlers that are the defaults for a given protocol. |
307 ProtocolHandlerMap default_handlers_; | 350 ProtocolHandlerMap default_handlers_; |
308 | 351 |
309 // The Profile that owns this ProtocolHandlerRegistry. | 352 // The Profile that owns this ProtocolHandlerRegistry. |
310 Profile* profile_; | 353 Profile* profile_; |
311 | 354 |
312 // The Delegate that registers / deregisters external handlers on our behalf. | 355 // The Delegate that registers / deregisters external handlers on our behalf. |
313 scoped_ptr<Delegate> delegate_; | 356 scoped_ptr<Delegate> delegate_; |
314 | 357 |
315 // If false then registered protocol handlers will not be used to handle | 358 // If false then registered protocol handlers will not be used to handle |
316 // requests. | 359 // requests. |
317 bool enabled_; | 360 bool enabled_; |
318 | 361 |
319 // Whether or not we are loading. | 362 // Whether or not we are loading. |
320 bool is_loading_; | 363 bool is_loading_; |
321 | 364 |
322 // When the table gets loaded this flag will be set and any further calls to | 365 // When the table gets loaded this flag will be set and any further calls to |
323 // AddPredefinedHandler will be rejected. | 366 // AddPredefinedHandler will be rejected. |
324 bool is_loaded_; | 367 bool is_loaded_; |
325 | 368 |
326 // Copy of registry data for use on the IO thread. Changes to the registry | 369 // Copy of registry data for use on the IO thread. Changes to the registry |
327 // are posted to the IO thread where updates are applied to this object. | 370 // are posted to the IO thread where updates are applied to this object. |
328 scoped_refptr<IOThreadDelegate> io_thread_delegate_; | 371 scoped_refptr<IOThreadDelegate> io_thread_delegate_; |
329 | 372 |
330 DefaultClientObserverList default_client_observers_; | 373 DefaultClientObserverList default_client_observers_; |
331 | 374 |
332 DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistry); | 375 DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistry); |
333 }; | 376 }; |
334 #endif // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ | 377 #endif // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ |
OLD | NEW |