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; | |
|
James Hawkins
2013/01/07 18:57:49
nit: Make this class name a bit more descriptive.
pauljensen
2013/01/07 20:48:58
I could rename it IOThreadDelegate? I wanted to c
| |
| 90 | |
| 91 // JobInterceptorFactory intercepts URLRequestJob creation for URLRequests the | |
| 92 // ProtocolHandlerRegistry is registered to handle. When no handler is | |
| 93 // registered the URLRequest is passed along to the chained | |
|
James Hawkins
2013/01/07 18:57:49
nit: 'registered, the'
| |
| 94 // URLRequestJobFactory (set with |JobInterceptorFactory::Chain|). | |
| 95 // JobInterceptorFactory's are created via | |
| 96 // |ProtocolHandlerRegistry::CreateJobInterceptorFactory|. | |
| 97 class JobInterceptorFactory : public net::URLRequestJobFactory { | |
| 98 public: | |
| 99 explicit JobInterceptorFactory(Core* core); | |
|
James Hawkins
2013/01/07 18:57:49
nit: Document |core|.
| |
| 100 virtual ~JobInterceptorFactory(); | |
| 101 | |
| 102 // Set the URLRequestJobFactory where requests are passed if | |
| 103 // JobInterceptorFactory decides to pass on them. | |
| 104 void Chain(scoped_ptr<net::URLRequestJobFactory> job_factory); | |
|
James Hawkins
2013/01/07 18:57:49
nit: Document |job_factory|.
| |
| 105 | |
| 106 // URLRequestJobFactory implementation | |
|
James Hawkins
2013/01/07 18:57:49
nit: Add missing period at end of comment.
| |
| 107 virtual bool SetProtocolHandler(const std::string& scheme, | |
| 108 ProtocolHandler* protocol_handler) OVERRIDE; | |
| 109 virtual void AddInterceptor(Interceptor* interceptor) OVERRIDE; | |
| 110 virtual net::URLRequestJob* MaybeCreateJobWithInterceptor( | |
|
James Hawkins
2013/01/07 18:57:49
ugh. Methods that have the word 'maybe' in it are
| |
| 111 net::URLRequest* request, | |
| 112 net::NetworkDelegate* network_delegate) const OVERRIDE; | |
| 113 virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler( | |
| 114 const std::string& scheme, | |
| 115 net::URLRequest* request, | |
| 116 net::NetworkDelegate* network_delegate) const OVERRIDE; | |
| 117 virtual net::URLRequestJob* MaybeInterceptRedirect( | |
| 118 const GURL& location, | |
| 119 net::URLRequest* request, | |
| 120 net::NetworkDelegate* network_delegate) const OVERRIDE; | |
| 121 virtual net::URLRequestJob* MaybeInterceptResponse( | |
| 122 net::URLRequest* request, | |
| 123 net::NetworkDelegate* network_delegate) const OVERRIDE; | |
| 124 virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE; | |
| 125 virtual bool IsHandledURL(const GURL& url) const OVERRIDE; | |
| 126 | |
| 127 private: | |
| 128 scoped_ptr<URLRequestJobFactory> job_factory_; | |
|
James Hawkins
2013/01/07 18:57:49
nit: Document member variables.
| |
| 129 scoped_refptr<Core> core_; | |
| 130 | |
| 131 DISALLOW_COPY_AND_ASSIGN(JobInterceptorFactory); | |
| 132 }; | |
| 133 | |
| 87 typedef std::map<std::string, ProtocolHandler> ProtocolHandlerMap; | 134 typedef std::map<std::string, ProtocolHandler> ProtocolHandlerMap; |
| 88 typedef std::vector<ProtocolHandler> ProtocolHandlerList; | 135 typedef std::vector<ProtocolHandler> ProtocolHandlerList; |
| 89 typedef std::map<std::string, ProtocolHandlerList> ProtocolHandlerMultiMap; | 136 typedef std::map<std::string, ProtocolHandlerList> ProtocolHandlerMultiMap; |
| 90 typedef std::vector<DefaultClientObserver*> DefaultClientObserverList; | 137 typedef std::vector<DefaultClientObserver*> DefaultClientObserverList; |
| 91 | 138 |
| 92 // Creates a new instance. Assumes ownership of |delegate|. | 139 // Creates a new instance. Assumes ownership of |delegate|. |
| 93 ProtocolHandlerRegistry(Profile* profile, Delegate* delegate); | 140 ProtocolHandlerRegistry(Profile* profile, Delegate* delegate); |
| 94 virtual ~ProtocolHandlerRegistry(); | 141 virtual ~ProtocolHandlerRegistry(); |
| 95 | 142 |
| 96 // Returns a net::URLRequestJobFactory::Interceptor suitable | 143 // 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. | 144 // is initialized on the UI thread. |
| 98 // Callers assume responsibility for deleting this object. | 145 scoped_ptr<JobInterceptorFactory> CreateJobInterceptorFactory(); |
| 99 net::URLRequestJobFactory::Interceptor* CreateURLInterceptor(); | |
| 100 | 146 |
| 101 // 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 |
| 102 // 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 |
| 103 // 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 |
| 104 // function returns false the user needs to be prompted for confirmation. | 150 // function returns false the user needs to be prompted for confirmation. |
| 105 bool SilentlyHandleRegisterHandlerRequest(const ProtocolHandler& handler); | 151 bool SilentlyHandleRegisterHandlerRequest(const ProtocolHandler& handler); |
| 106 | 152 |
| 107 // Called when the user accepts the registration of a given protocol handler. | 153 // Called when the user accepts the registration of a given protocol handler. |
| 108 void OnAcceptRegisterProtocolHandler(const ProtocolHandler& handler); | 154 void OnAcceptRegisterProtocolHandler(const ProtocolHandler& handler); |
| 109 | 155 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 friend class base::DeleteHelper<ProtocolHandlerRegistry>; | 251 friend class base::DeleteHelper<ProtocolHandlerRegistry>; |
| 206 friend struct content::BrowserThread::DeleteOnThread< | 252 friend struct content::BrowserThread::DeleteOnThread< |
| 207 content::BrowserThread::IO>; | 253 content::BrowserThread::IO>; |
| 208 | 254 |
| 209 // for access to InstallDefaultsForChromeOS | 255 // for access to InstallDefaultsForChromeOS |
| 210 friend class ProtocolHandlerRegistryFactory; | 256 friend class ProtocolHandlerRegistryFactory; |
| 211 | 257 |
| 212 friend class ProtocolHandlerRegistryTest; | 258 friend class ProtocolHandlerRegistryTest; |
| 213 friend class RegisterProtocolHandlerBrowserTest; | 259 friend class RegisterProtocolHandlerBrowserTest; |
| 214 | 260 |
| 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 | 261 // Puts the given handler at the top of the list of handlers for its |
| 220 // protocol. | 262 // protocol. |
| 221 void PromoteHandler(const ProtocolHandler& handler); | 263 void PromoteHandler(const ProtocolHandler& handler); |
| 222 | 264 |
| 223 // Saves a user's registered protocol handlers. | 265 // Saves a user's registered protocol handlers. |
| 224 void Save(); | 266 void Save(); |
| 225 | 267 |
| 226 // Returns a pointer to the list of handlers registered for the given scheme, | 268 // Returns a pointer to the list of handlers registered for the given scheme, |
| 227 // or NULL if there are none. | 269 // or NULL if there are none. |
| 228 const ProtocolHandlerList* GetHandlerList(const std::string& scheme) const; | 270 const ProtocolHandlerList* GetHandlerList(const std::string& scheme) const; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 | 329 |
| 288 // Copy of registry data for use on the IO thread. Changes to the registry | 330 // 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. | 331 // are posted to the IO thread where updates are applied to this object. |
| 290 scoped_refptr<Core> core_; | 332 scoped_refptr<Core> core_; |
| 291 | 333 |
| 292 DefaultClientObserverList default_client_observers_; | 334 DefaultClientObserverList default_client_observers_; |
| 293 | 335 |
| 294 DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistry); | 336 DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistry); |
| 295 }; | 337 }; |
| 296 #endif // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ | 338 #endif // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_REGISTRY_H_ |
| OLD | NEW |