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