Chromium Code Reviews| 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> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/sequenced_task_runner_helpers.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 #include "net/url_request/url_request_job_factory.h" | 24 #include "net/url_request/url_request_job_factory.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 virtual ShellIntegration::DefaultProtocolClientWorker* CreateShellWorker( | 78 virtual ShellIntegration::DefaultProtocolClientWorker* CreateShellWorker( |
| 78 ShellIntegration::DefaultWebClientObserver* observer, | 79 ShellIntegration::DefaultWebClientObserver* observer, |
| 79 const std::string& protocol); | 80 const std::string& protocol); |
| 80 virtual DefaultClientObserver* CreateShellObserver( | 81 virtual DefaultClientObserver* CreateShellObserver( |
| 81 ProtocolHandlerRegistry* registry); | 82 ProtocolHandlerRegistry* registry); |
| 82 virtual void RegisterWithOSAsDefaultClient( | 83 virtual void RegisterWithOSAsDefaultClient( |
| 83 const std::string& protocol, | 84 const std::string& protocol, |
| 84 ProtocolHandlerRegistry* registry); | 85 ProtocolHandlerRegistry* registry); |
| 85 }; | 86 }; |
| 86 | 87 |
| 88 // Forward declaration of the internal implementation class. | |
| 89 class Core; | |
| 90 | |
| 91 class JobInterceptorFactory : public net::URLRequestJobFactory { | |
|
mmenke
2013/01/03 18:49:38
One other thing...We should have a description of
| |
| 92 public: | |
| 93 explicit JobInterceptorFactory(Core* core); | |
| 94 virtual ~JobInterceptorFactory(); | |
| 95 | |
| 96 // Set the URLRequestJobFactory where requests are passed if JobFactory | |
| 97 // decides to pass on them. | |
| 98 void Chain(scoped_ptr<net::URLRequestJobFactory> job_factory); | |
| 99 | |
| 100 // URLRequestJobFactory implementation | |
| 101 virtual bool SetProtocolHandler(const std::string& scheme, | |
| 102 ProtocolHandler* protocol_handler) OVERRIDE; | |
| 103 virtual void AddInterceptor(Interceptor* interceptor) OVERRIDE; | |
| 104 virtual net::URLRequestJob* MaybeCreateJobWithInterceptor( | |
| 105 net::URLRequest* request, | |
| 106 net::NetworkDelegate* network_delegate) const OVERRIDE; | |
| 107 virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler( | |
| 108 const std::string& scheme, | |
| 109 net::URLRequest* request, | |
| 110 net::NetworkDelegate* network_delegate) const OVERRIDE; | |
| 111 virtual net::URLRequestJob* MaybeInterceptRedirect( | |
| 112 const GURL& location, | |
| 113 net::URLRequest* request, | |
| 114 net::NetworkDelegate* network_delegate) const OVERRIDE; | |
| 115 virtual net::URLRequestJob* MaybeInterceptResponse( | |
| 116 net::URLRequest* request, | |
| 117 net::NetworkDelegate* network_delegate) const OVERRIDE; | |
| 118 virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE; | |
| 119 virtual bool IsHandledURL(const GURL& url) const OVERRIDE; | |
| 120 | |
| 121 private: | |
| 122 scoped_ptr<URLRequestJobFactory> job_factory_; | |
| 123 scoped_refptr<Core> core_; | |
| 124 | |
| 125 DISALLOW_COPY_AND_ASSIGN(JobInterceptorFactory); | |
| 126 }; | |
| 127 | |
| 87 typedef std::map<std::string, ProtocolHandler> ProtocolHandlerMap; | 128 typedef std::map<std::string, ProtocolHandler> ProtocolHandlerMap; |
| 88 typedef std::vector<ProtocolHandler> ProtocolHandlerList; | 129 typedef std::vector<ProtocolHandler> ProtocolHandlerList; |
| 89 typedef std::map<std::string, ProtocolHandlerList> ProtocolHandlerMultiMap; | 130 typedef std::map<std::string, ProtocolHandlerList> ProtocolHandlerMultiMap; |
| 90 typedef std::vector<DefaultClientObserver*> DefaultClientObserverList; | 131 typedef std::vector<DefaultClientObserver*> DefaultClientObserverList; |
| 91 | 132 |
| 92 // Creates a new instance. Assumes ownership of |delegate|. | 133 // Creates a new instance. Assumes ownership of |delegate|. |
| 93 ProtocolHandlerRegistry(Profile* profile, Delegate* delegate); | 134 ProtocolHandlerRegistry(Profile* profile, Delegate* delegate); |
| 94 virtual ~ProtocolHandlerRegistry(); | 135 virtual ~ProtocolHandlerRegistry(); |
| 95 | 136 |
| 96 // Returns a net::URLRequestJobFactory::Interceptor suitable | 137 // Returns a net::URLRequestJobFactory suitable for use on the IO thread, but |
| 97 // for use on the IO thread, but is initialized on the UI thread. | 138 // is initialized on the UI thread. |
| 98 // Callers assume responsibility for deleting this object. | 139 scoped_ptr<JobInterceptorFactory> CreateJobInterceptorFactory(); |
| 99 net::URLRequestJobFactory::Interceptor* CreateURLInterceptor(); | |
| 100 | 140 |
| 101 // Called when a site tries to register as a protocol handler. If the request | 141 // Called when a site tries to register as a protocol handler. If the request |
| 102 // can be handled silently by the registry - either to ignore the request | 142 // can be handled silently by the registry - either to ignore the request |
| 103 // or to update an existing handler - the request will succeed. If this | 143 // or to update an existing handler - the request will succeed. If this |
| 104 // function returns false the user needs to be prompted for confirmation. | 144 // function returns false the user needs to be prompted for confirmation. |
| 105 bool SilentlyHandleRegisterHandlerRequest(const ProtocolHandler& handler); | 145 bool SilentlyHandleRegisterHandlerRequest(const ProtocolHandler& handler); |
| 106 | 146 |
| 107 // Called when the user accepts the registration of a given protocol handler. | 147 // Called when the user accepts the registration of a given protocol handler. |
| 108 void OnAcceptRegisterProtocolHandler(const ProtocolHandler& handler); | 148 void OnAcceptRegisterProtocolHandler(const ProtocolHandler& handler); |
| 109 | 149 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 friend class base::DeleteHelper<ProtocolHandlerRegistry>; | 245 friend class base::DeleteHelper<ProtocolHandlerRegistry>; |
| 206 friend struct content::BrowserThread::DeleteOnThread< | 246 friend struct content::BrowserThread::DeleteOnThread< |
| 207 content::BrowserThread::IO>; | 247 content::BrowserThread::IO>; |
| 208 | 248 |
| 209 // for access to InstallDefaultsForChromeOS | 249 // for access to InstallDefaultsForChromeOS |
| 210 friend class ProtocolHandlerRegistryFactory; | 250 friend class ProtocolHandlerRegistryFactory; |
| 211 | 251 |
| 212 friend class ProtocolHandlerRegistryTest; | 252 friend class ProtocolHandlerRegistryTest; |
| 213 friend class RegisterProtocolHandlerBrowserTest; | 253 friend class RegisterProtocolHandlerBrowserTest; |
| 214 | 254 |
| 215 // Forward declaration of the internal implementation classes. | |
| 216 class Core; | |
| 217 class URLInterceptor; | |
| 218 | |
| 219 // Puts the given handler at the top of the list of handlers for its | 255 // Puts the given handler at the top of the list of handlers for its |
| 220 // protocol. | 256 // protocol. |
| 221 void PromoteHandler(const ProtocolHandler& handler); | 257 void PromoteHandler(const ProtocolHandler& handler); |
| 222 | 258 |
| 223 // Saves a user's registered protocol handlers. | 259 // Saves a user's registered protocol handlers. |
| 224 void Save(); | 260 void Save(); |
| 225 | 261 |
| 226 // Returns a pointer to the list of handlers registered for the given scheme, | 262 // Returns a pointer to the list of handlers registered for the given scheme, |
| 227 // or NULL if there are none. | 263 // or NULL if there are none. |
| 228 const ProtocolHandlerList* GetHandlerList(const std::string& scheme) const; | 264 const ProtocolHandlerList* GetHandlerList(const std::string& scheme) const; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 | 323 |
| 288 // Copy of registry data for use on the IO thread. Changes to the registry | 324 // Copy of registry data for use on the IO thread. Changes to the registry |
| 289 // are posted to the IO thread where updates are applied to this object. | 325 // are posted to the IO thread where updates are applied to this object. |
| 290 scoped_refptr<Core> core_; | 326 scoped_refptr<Core> core_; |
| 291 | 327 |
| 292 DefaultClientObserverList default_client_observers_; | 328 DefaultClientObserverList default_client_observers_; |
| 293 | 329 |
| 294 DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistry); | 330 DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistry); |
| 295 }; | 331 }; |
| 296 #endif // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ | 332 #endif // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ |
| OLD | NEW |