| 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 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 5 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg
ate.h" | 12 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg
ate.h" |
| 15 #include "chrome/browser/net/chrome_url_request_context.h" | 13 #include "chrome/browser/net/chrome_url_request_context.h" |
| 16 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 17 #include "chrome/browser/profiles/profile_io_data.h" | 15 #include "chrome/browser/profiles/profile_io_data.h" |
| 18 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 19 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/custom_handlers/protocol_handler.h" | 18 #include "chrome/common/custom_handlers/protocol_handler.h" |
| 21 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 22 #include "content/public/browser/browser_thread.h" | |
| 23 #include "content/public/browser/child_process_security_policy.h" | 20 #include "content/public/browser/child_process_security_policy.h" |
| 24 #include "content/public/browser/notification_service.h" | |
| 25 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
| 26 #include "net/base/network_delegate.h" | 22 #include "net/base/network_delegate.h" |
| 27 #include "net/url_request/url_request.h" | |
| 28 #include "net/url_request/url_request_job.h" | |
| 29 #include "net/url_request/url_request_redirect_job.h" | 23 #include "net/url_request/url_request_redirect_job.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 31 | 25 |
| 32 using content::BrowserThread; | 26 using content::BrowserThread; |
| 33 using content::ChildProcessSecurityPolicy; | 27 using content::ChildProcessSecurityPolicy; |
| 34 | 28 |
| 35 namespace { | 29 namespace { |
| 36 | 30 |
| 37 const ProtocolHandler& LookupHandler( | 31 const ProtocolHandler& LookupHandler( |
| 38 const ProtocolHandlerRegistry::ProtocolHandlerMap& handler_map, | 32 const ProtocolHandlerRegistry::ProtocolHandlerMap& handler_map, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 56 // difference (http://crbug.com/88255). | 50 // difference (http://crbug.com/88255). |
| 57 return false; | 51 return false; |
| 58 #else | 52 #else |
| 59 return ShellIntegration::CanSetAsDefaultProtocolClient() != | 53 return ShellIntegration::CanSetAsDefaultProtocolClient() != |
| 60 ShellIntegration::SET_DEFAULT_NOT_ALLOWED; | 54 ShellIntegration::SET_DEFAULT_NOT_ALLOWED; |
| 61 #endif | 55 #endif |
| 62 } | 56 } |
| 63 | 57 |
| 64 } // namespace | 58 } // namespace |
| 65 | 59 |
| 66 // Core ------------------------------------------------------------------------ | 60 // IOThreadDelegate ------------------------------------------------------------ |
| 67 | 61 |
| 68 // Core is an IO thread specific object. Access to the class should all | 62 // IOThreadDelegate is an IO thread specific object. Access to the class should |
| 69 // be done via the IO thread. The registry living on the UI thread makes | 63 // all be done via the IO thread. The registry living on the UI thread makes |
| 70 // a best effort to update the IO object after local updates are completed. | 64 // a best effort to update the IO object after local updates are completed. |
| 71 class ProtocolHandlerRegistry::Core | 65 class ProtocolHandlerRegistry::IOThreadDelegate |
| 72 : public base::RefCountedThreadSafe<ProtocolHandlerRegistry::Core> { | 66 : public base::RefCountedThreadSafe< |
| 67 ProtocolHandlerRegistry::IOThreadDelegate> { |
| 73 public: | 68 public: |
| 74 | 69 |
| 75 // Creates a new instance. If |enabled| is true the registry is considered | 70 // Creates a new instance. If |enabled| is true the registry is considered |
| 76 // enabled on the IO thread. | 71 // enabled on the IO thread. |
| 77 explicit Core(bool enabled); | 72 explicit IOThreadDelegate(bool enabled); |
| 78 | 73 |
| 79 // Returns true if the protocol has a default protocol handler. | 74 // Returns true if the protocol has a default protocol handler. |
| 80 // Should be called only from the IO thread. | 75 // Should be called only from the IO thread. |
| 81 bool IsHandledProtocol(const std::string& scheme) const; | 76 bool IsHandledProtocol(const std::string& scheme) const; |
| 82 | 77 |
| 83 // Clears the default for the provided protocol. | 78 // Clears the default for the provided protocol. |
| 84 // Should be called only from the IO thread. | 79 // Should be called only from the IO thread. |
| 85 void ClearDefault(const std::string& scheme); | 80 void ClearDefault(const std::string& scheme); |
| 86 | 81 |
| 87 // Makes this ProtocolHandler the default handler for its protocol. | 82 // Makes this ProtocolHandler the default handler for its protocol. |
| 88 // Should be called only from the IO thread. | 83 // Should be called only from the IO thread. |
| 89 void SetDefault(const ProtocolHandler& handler); | 84 void SetDefault(const ProtocolHandler& handler); |
| 90 | 85 |
| 91 // Creates a URL request job for the given request if there is a matching | 86 // Creates a URL request job for the given request if there is a matching |
| 92 // protocol handler, returns NULL otherwise. | 87 // protocol handler, returns NULL otherwise. |
| 93 net::URLRequestJob* MaybeCreateJob( | 88 net::URLRequestJob* MaybeCreateJob( |
| 94 net::URLRequest* request, net::NetworkDelegate* network_delegate) const; | 89 net::URLRequest* request, net::NetworkDelegate* network_delegate) const; |
| 95 | 90 |
| 96 // Indicate that the registry has been enabled in the IO thread's | 91 // Indicate that the registry has been enabled in the IO thread's |
| 97 // copy of the data. | 92 // copy of the data. |
| 98 void Enable() { enabled_ = true; } | 93 void Enable() { enabled_ = true; } |
| 99 | 94 |
| 100 // Indicate that the registry has been disabled in the IO thread's copy of | 95 // Indicate that the registry has been disabled in the IO thread's copy of |
| 101 // the data. | 96 // the data. |
| 102 void Disable() { enabled_ = false; } | 97 void Disable() { enabled_ = false; } |
| 103 | 98 |
| 104 private: | 99 private: |
| 105 friend class base::RefCountedThreadSafe<Core>; | 100 friend class base::RefCountedThreadSafe<IOThreadDelegate>; |
| 106 virtual ~Core(); | 101 virtual ~IOThreadDelegate(); |
| 107 | 102 |
| 108 // Copy of protocol handlers use only on the IO thread. | 103 // Copy of protocol handlers use only on the IO thread. |
| 109 ProtocolHandlerRegistry::ProtocolHandlerMap default_handlers_; | 104 ProtocolHandlerRegistry::ProtocolHandlerMap default_handlers_; |
| 110 | 105 |
| 111 // Is the registry enabled on the IO thread. | 106 // Is the registry enabled on the IO thread. |
| 112 bool enabled_; | 107 bool enabled_; |
| 113 | 108 |
| 114 DISALLOW_COPY_AND_ASSIGN(Core); | 109 DISALLOW_COPY_AND_ASSIGN(IOThreadDelegate); |
| 115 }; | 110 }; |
| 116 | 111 |
| 117 ProtocolHandlerRegistry::Core::Core(bool) : enabled_(true) {} | 112 ProtocolHandlerRegistry::IOThreadDelegate::IOThreadDelegate(bool) |
| 118 ProtocolHandlerRegistry::Core::~Core() {} | 113 : enabled_(true) {} |
| 114 ProtocolHandlerRegistry::IOThreadDelegate::~IOThreadDelegate() {} |
| 119 | 115 |
| 120 bool ProtocolHandlerRegistry::Core::IsHandledProtocol( | 116 bool ProtocolHandlerRegistry::IOThreadDelegate::IsHandledProtocol( |
| 121 const std::string& scheme) const { | 117 const std::string& scheme) const { |
| 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 123 return enabled_ && !LookupHandler(default_handlers_, scheme).IsEmpty(); | 119 return enabled_ && !LookupHandler(default_handlers_, scheme).IsEmpty(); |
| 124 } | 120 } |
| 125 | 121 |
| 126 void ProtocolHandlerRegistry::Core::ClearDefault(const std::string& scheme) { | 122 void ProtocolHandlerRegistry::IOThreadDelegate::ClearDefault( |
| 123 const std::string& scheme) { |
| 127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 128 default_handlers_.erase(scheme); | 125 default_handlers_.erase(scheme); |
| 129 } | 126 } |
| 130 | 127 |
| 131 void ProtocolHandlerRegistry::Core::SetDefault(const ProtocolHandler& handler) { | 128 void ProtocolHandlerRegistry::IOThreadDelegate::SetDefault( |
| 129 const ProtocolHandler& handler) { |
| 132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 133 ClearDefault(handler.protocol()); | 131 ClearDefault(handler.protocol()); |
| 134 default_handlers_.insert(std::make_pair(handler.protocol(), handler)); | 132 default_handlers_.insert(std::make_pair(handler.protocol(), handler)); |
| 135 } | 133 } |
| 136 | 134 |
| 137 // Create a new job for the supplied |URLRequest| if a default handler | 135 // Create a new job for the supplied |URLRequest| if a default handler |
| 138 // is registered and the associated handler is able to interpret | 136 // is registered and the associated handler is able to interpret |
| 139 // the url from |request|. | 137 // the url from |request|. |
| 140 net::URLRequestJob* ProtocolHandlerRegistry::Core::MaybeCreateJob( | 138 net::URLRequestJob* ProtocolHandlerRegistry::IOThreadDelegate::MaybeCreateJob( |
| 141 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { | 139 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { |
| 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 143 | 141 |
| 144 ProtocolHandler handler = LookupHandler(default_handlers_, | 142 ProtocolHandler handler = LookupHandler(default_handlers_, |
| 145 request->url().scheme()); | 143 request->url().scheme()); |
| 146 if (handler.IsEmpty()) | 144 if (handler.IsEmpty()) |
| 147 return NULL; | 145 return NULL; |
| 148 | 146 |
| 149 GURL translated_url(handler.TranslateUrl(request->url())); | 147 GURL translated_url(handler.TranslateUrl(request->url())); |
| 150 if (!translated_url.is_valid()) | 148 if (!translated_url.is_valid()) |
| 151 return NULL; | 149 return NULL; |
| 152 | 150 |
| 153 return new net::URLRequestRedirectJob( | 151 return new net::URLRequestRedirectJob( |
| 154 request, network_delegate, translated_url, | 152 request, network_delegate, translated_url, |
| 155 net::URLRequestRedirectJob::REDIRECT_302_FOUND); | 153 net::URLRequestRedirectJob::REDIRECT_302_FOUND); |
| 156 } | 154 } |
| 157 | 155 |
| 158 // URLInterceptor ------------------------------------------------------------ | 156 // JobInterceptorFactory ------------------------------------------------------- |
| 159 | 157 |
| 160 // Instances of this class are produced for ownership by the IO | 158 // Instances of JobInterceptorFactory are produced for ownership by the IO |
| 161 // thread where it handler URL requests. We should never hold | 159 // thread where it handler URL requests. We should never hold |
| 162 // any pointers on this class, only produce them in response to | 160 // any pointers on this class, only produce them in response to |
| 163 // requests via |ProtocolHandlerRegistry::CreateURLInterceptor|. | 161 // requests via |ProtocolHandlerRegistry::CreateJobInterceptorFactory|. |
| 164 class ProtocolHandlerRegistry::URLInterceptor | 162 ProtocolHandlerRegistry::JobInterceptorFactory::JobInterceptorFactory( |
| 165 : public net::URLRequestJobFactory::Interceptor { | 163 IOThreadDelegate* io_thread_delegate) |
| 166 public: | 164 : io_thread_delegate_(io_thread_delegate) { |
| 167 explicit URLInterceptor(Core* core); | 165 DCHECK(io_thread_delegate_); |
| 168 virtual ~URLInterceptor(); | 166 DetachFromThread(); |
| 169 | |
| 170 virtual net::URLRequestJob* MaybeIntercept( | |
| 171 net::URLRequest* request, | |
| 172 net::NetworkDelegate* network_delegate) const OVERRIDE; | |
| 173 | |
| 174 virtual bool WillHandleProtocol(const std::string& protocol) const OVERRIDE; | |
| 175 | |
| 176 virtual net::URLRequestJob* MaybeInterceptRedirect( | |
| 177 const GURL& url, | |
| 178 net::URLRequest* request, | |
| 179 net::NetworkDelegate* network_delegate) const OVERRIDE { | |
| 180 return NULL; | |
| 181 } | |
| 182 | |
| 183 virtual net::URLRequestJob* MaybeInterceptResponse( | |
| 184 net::URLRequest* request, | |
| 185 net::NetworkDelegate* network_delegate) const OVERRIDE { | |
| 186 return NULL; | |
| 187 } | |
| 188 | |
| 189 private: | |
| 190 scoped_refptr<Core> core_; | |
| 191 DISALLOW_COPY_AND_ASSIGN(URLInterceptor); | |
| 192 }; | |
| 193 | |
| 194 ProtocolHandlerRegistry::URLInterceptor::URLInterceptor(Core* core) | |
| 195 : core_(core) { | |
| 196 DCHECK(core_); | |
| 197 } | 167 } |
| 198 | 168 |
| 199 ProtocolHandlerRegistry::URLInterceptor::~URLInterceptor() { | 169 ProtocolHandlerRegistry::JobInterceptorFactory::~JobInterceptorFactory() { |
| 200 } | 170 } |
| 201 | 171 |
| 202 net::URLRequestJob* ProtocolHandlerRegistry::URLInterceptor::MaybeIntercept( | 172 void ProtocolHandlerRegistry::JobInterceptorFactory::Chain( |
| 203 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { | 173 scoped_ptr<net::URLRequestJobFactory> job_factory) { |
| 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 174 job_factory_ = job_factory.Pass(); |
| 205 | |
| 206 return core_->MaybeCreateJob(request, network_delegate); | |
| 207 } | 175 } |
| 208 | 176 |
| 209 bool ProtocolHandlerRegistry::URLInterceptor::WillHandleProtocol( | 177 bool ProtocolHandlerRegistry::JobInterceptorFactory::SetProtocolHandler( |
| 210 const std::string& protocol) const { | 178 const std::string& scheme, ProtocolHandler* protocol_handler) { |
| 179 return job_factory_->SetProtocolHandler(scheme, protocol_handler); |
| 180 } |
| 181 |
| 182 void ProtocolHandlerRegistry::JobInterceptorFactory::AddInterceptor( |
| 183 Interceptor* interceptor) { |
| 184 return job_factory_->AddInterceptor(interceptor); |
| 185 } |
| 186 |
| 187 net::URLRequestJob* |
| 188 ProtocolHandlerRegistry::JobInterceptorFactory::MaybeCreateJobWithInterceptor( |
| 189 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { |
| 190 return job_factory_->MaybeCreateJobWithInterceptor(request, network_delegate); |
| 191 } |
| 192 |
| 193 net::URLRequestJob* |
| 194 ProtocolHandlerRegistry::JobInterceptorFactory:: |
| 195 MaybeCreateJobWithProtocolHandler( |
| 196 const std::string& scheme, |
| 197 net::URLRequest* request, |
| 198 net::NetworkDelegate* network_delegate) const { |
| 211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 200 net::URLRequestJob* job = io_thread_delegate_->MaybeCreateJob( |
| 201 request, network_delegate); |
| 202 if (job) |
| 203 return job; |
| 204 return job_factory_->MaybeCreateJobWithProtocolHandler( |
| 205 scheme, request, network_delegate); |
| 206 } |
| 212 | 207 |
| 213 return core_->IsHandledProtocol(protocol); | 208 net::URLRequestJob* |
| 209 ProtocolHandlerRegistry::JobInterceptorFactory::MaybeInterceptRedirect( |
| 210 const GURL& location, |
| 211 net::URLRequest* request, |
| 212 net::NetworkDelegate* network_delegate) const { |
| 213 return job_factory_->MaybeInterceptRedirect( |
| 214 location, request, network_delegate); |
| 215 } |
| 216 |
| 217 net::URLRequestJob* |
| 218 ProtocolHandlerRegistry::JobInterceptorFactory::MaybeInterceptResponse( |
| 219 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { |
| 220 return job_factory_->MaybeInterceptResponse(request, network_delegate); |
| 221 } |
| 222 |
| 223 bool ProtocolHandlerRegistry::JobInterceptorFactory::IsHandledProtocol( |
| 224 const std::string& scheme) const { |
| 225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 226 return io_thread_delegate_->IsHandledProtocol(scheme) || |
| 227 job_factory_->IsHandledProtocol(scheme); |
| 228 } |
| 229 |
| 230 bool ProtocolHandlerRegistry::JobInterceptorFactory::IsHandledURL( |
| 231 const GURL& url) const { |
| 232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 233 return (url.is_valid() && |
| 234 io_thread_delegate_->IsHandledProtocol(url.scheme())) || |
| 235 job_factory_->IsHandledURL(url); |
| 214 } | 236 } |
| 215 | 237 |
| 216 // DefaultClientObserver ------------------------------------------------------ | 238 // DefaultClientObserver ------------------------------------------------------ |
| 217 | 239 |
| 218 ProtocolHandlerRegistry::DefaultClientObserver::DefaultClientObserver( | 240 ProtocolHandlerRegistry::DefaultClientObserver::DefaultClientObserver( |
| 219 ProtocolHandlerRegistry* registry) | 241 ProtocolHandlerRegistry* registry) |
| 220 : worker_(NULL), | 242 : worker_(NULL), |
| 221 registry_(registry) { | 243 registry_(registry) { |
| 222 DCHECK(registry_); | 244 DCHECK(registry_); |
| 223 } | 245 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 332 |
| 311 // ProtocolHandlerRegistry ----------------------------------------------------- | 333 // ProtocolHandlerRegistry ----------------------------------------------------- |
| 312 | 334 |
| 313 ProtocolHandlerRegistry::ProtocolHandlerRegistry(Profile* profile, | 335 ProtocolHandlerRegistry::ProtocolHandlerRegistry(Profile* profile, |
| 314 Delegate* delegate) | 336 Delegate* delegate) |
| 315 : profile_(profile), | 337 : profile_(profile), |
| 316 delegate_(delegate), | 338 delegate_(delegate), |
| 317 enabled_(true), | 339 enabled_(true), |
| 318 is_loading_(false), | 340 is_loading_(false), |
| 319 is_loaded_(false), | 341 is_loaded_(false), |
| 320 core_(new Core(enabled_)){ | 342 io_thread_delegate_(new IOThreadDelegate(enabled_)){ |
| 321 } | 343 } |
| 322 | 344 |
| 323 bool ProtocolHandlerRegistry::SilentlyHandleRegisterHandlerRequest( | 345 bool ProtocolHandlerRegistry::SilentlyHandleRegisterHandlerRequest( |
| 324 const ProtocolHandler& handler) { | 346 const ProtocolHandler& handler) { |
| 325 if (handler.IsEmpty() || !CanSchemeBeOverridden(handler.protocol())) | 347 if (handler.IsEmpty() || !CanSchemeBeOverridden(handler.protocol())) |
| 326 return true; | 348 return true; |
| 327 | 349 |
| 328 if (!enabled() || IsRegistered(handler) || HasIgnoredEquivalent(handler)) | 350 if (!enabled() || IsRegistered(handler) || HasIgnoredEquivalent(handler)) |
| 329 return true; | 351 return true; |
| 330 | 352 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 return replaced_handlers; | 417 return replaced_handlers; |
| 396 } | 418 } |
| 397 | 419 |
| 398 void ProtocolHandlerRegistry::ClearDefault(const std::string& scheme) { | 420 void ProtocolHandlerRegistry::ClearDefault(const std::string& scheme) { |
| 399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 421 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 400 | 422 |
| 401 default_handlers_.erase(scheme); | 423 default_handlers_.erase(scheme); |
| 402 BrowserThread::PostTask( | 424 BrowserThread::PostTask( |
| 403 BrowserThread::IO, | 425 BrowserThread::IO, |
| 404 FROM_HERE, | 426 FROM_HERE, |
| 405 base::Bind(&Core::ClearDefault, core_, scheme)); | 427 base::Bind(&IOThreadDelegate::ClearDefault, io_thread_delegate_, scheme)); |
| 406 Save(); | 428 Save(); |
| 407 NotifyChanged(); | 429 NotifyChanged(); |
| 408 } | 430 } |
| 409 | 431 |
| 410 bool ProtocolHandlerRegistry::IsDefault( | 432 bool ProtocolHandlerRegistry::IsDefault( |
| 411 const ProtocolHandler& handler) const { | 433 const ProtocolHandler& handler) const { |
| 412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 413 return GetHandlerFor(handler.protocol()) == handler; | 435 return GetHandlerFor(handler.protocol()) == handler; |
| 414 } | 436 } |
| 415 | 437 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 } | 645 } |
| 624 ProtocolHandlerMap::iterator q = default_handlers_.find(handler.protocol()); | 646 ProtocolHandlerMap::iterator q = default_handlers_.find(handler.protocol()); |
| 625 if (q != default_handlers_.end() && q->second == handler) { | 647 if (q != default_handlers_.end() && q->second == handler) { |
| 626 // Make the new top handler in the list the default. | 648 // Make the new top handler in the list the default. |
| 627 if (!handlers.empty()) { | 649 if (!handlers.empty()) { |
| 628 // NOTE We pass a copy because SetDefault() modifies handlers. | 650 // NOTE We pass a copy because SetDefault() modifies handlers. |
| 629 SetDefault(ProtocolHandler(handlers[0])); | 651 SetDefault(ProtocolHandler(handlers[0])); |
| 630 } else { | 652 } else { |
| 631 BrowserThread::PostTask( | 653 BrowserThread::PostTask( |
| 632 BrowserThread::IO, FROM_HERE, | 654 BrowserThread::IO, FROM_HERE, |
| 633 base::Bind(&Core::ClearDefault, core_, q->second.protocol())); | 655 base::Bind(&IOThreadDelegate::ClearDefault, io_thread_delegate_, |
| 656 q->second.protocol())); |
| 634 | 657 |
| 635 default_handlers_.erase(q); | 658 default_handlers_.erase(q); |
| 636 } | 659 } |
| 637 } | 660 } |
| 638 | 661 |
| 639 if (!IsHandledProtocol(handler.protocol())) { | 662 if (!IsHandledProtocol(handler.protocol())) { |
| 640 delegate_->DeregisterExternalHandler(handler.protocol()); | 663 delegate_->DeregisterExternalHandler(handler.protocol()); |
| 641 } | 664 } |
| 642 Save(); | 665 Save(); |
| 643 NotifyChanged(); | 666 NotifyChanged(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 658 | 681 |
| 659 void ProtocolHandlerRegistry::Enable() { | 682 void ProtocolHandlerRegistry::Enable() { |
| 660 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 683 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 661 if (enabled_) { | 684 if (enabled_) { |
| 662 return; | 685 return; |
| 663 } | 686 } |
| 664 enabled_ = true; | 687 enabled_ = true; |
| 665 BrowserThread::PostTask( | 688 BrowserThread::PostTask( |
| 666 BrowserThread::IO, | 689 BrowserThread::IO, |
| 667 FROM_HERE, | 690 FROM_HERE, |
| 668 base::Bind(&Core::Enable, core_)); | 691 base::Bind(&IOThreadDelegate::Enable, io_thread_delegate_)); |
| 669 | 692 |
| 670 ProtocolHandlerMap::const_iterator p; | 693 ProtocolHandlerMap::const_iterator p; |
| 671 for (p = default_handlers_.begin(); p != default_handlers_.end(); ++p) { | 694 for (p = default_handlers_.begin(); p != default_handlers_.end(); ++p) { |
| 672 delegate_->RegisterExternalHandler(p->first); | 695 delegate_->RegisterExternalHandler(p->first); |
| 673 } | 696 } |
| 674 Save(); | 697 Save(); |
| 675 NotifyChanged(); | 698 NotifyChanged(); |
| 676 } | 699 } |
| 677 | 700 |
| 678 void ProtocolHandlerRegistry::Disable() { | 701 void ProtocolHandlerRegistry::Disable() { |
| 679 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 702 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 680 if (!enabled_) { | 703 if (!enabled_) { |
| 681 return; | 704 return; |
| 682 } | 705 } |
| 683 enabled_ = false; | 706 enabled_ = false; |
| 684 BrowserThread::PostTask( | 707 BrowserThread::PostTask( |
| 685 BrowserThread::IO, | 708 BrowserThread::IO, |
| 686 FROM_HERE, | 709 FROM_HERE, |
| 687 base::Bind(&Core::Disable, core_)); | 710 base::Bind(&IOThreadDelegate::Disable, io_thread_delegate_)); |
| 688 | 711 |
| 689 ProtocolHandlerMap::const_iterator p; | 712 ProtocolHandlerMap::const_iterator p; |
| 690 for (p = default_handlers_.begin(); p != default_handlers_.end(); ++p) { | 713 for (p = default_handlers_.begin(); p != default_handlers_.end(); ++p) { |
| 691 delegate_->DeregisterExternalHandler(p->first); | 714 delegate_->DeregisterExternalHandler(p->first); |
| 692 } | 715 } |
| 693 Save(); | 716 Save(); |
| 694 NotifyChanged(); | 717 NotifyChanged(); |
| 695 } | 718 } |
| 696 | 719 |
| 697 void ProtocolHandlerRegistry::Shutdown() { | 720 void ProtocolHandlerRegistry::Shutdown() { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 // If we're not loading, and we are setting a default for a new protocol, | 789 // If we're not loading, and we are setting a default for a new protocol, |
| 767 // register with the OS. | 790 // register with the OS. |
| 768 if (!is_loading_ && p == default_handlers_.end()) | 791 if (!is_loading_ && p == default_handlers_.end()) |
| 769 delegate_->RegisterWithOSAsDefaultClient(handler.protocol(), this); | 792 delegate_->RegisterWithOSAsDefaultClient(handler.protocol(), this); |
| 770 default_handlers_.erase(handler.protocol()); | 793 default_handlers_.erase(handler.protocol()); |
| 771 default_handlers_.insert(std::make_pair(handler.protocol(), handler)); | 794 default_handlers_.insert(std::make_pair(handler.protocol(), handler)); |
| 772 PromoteHandler(handler); | 795 PromoteHandler(handler); |
| 773 BrowserThread::PostTask( | 796 BrowserThread::PostTask( |
| 774 BrowserThread::IO, | 797 BrowserThread::IO, |
| 775 FROM_HERE, | 798 FROM_HERE, |
| 776 base::Bind(&Core::SetDefault, core_, handler)); | 799 base::Bind(&IOThreadDelegate::SetDefault, io_thread_delegate_, handler)); |
| 777 } | 800 } |
| 778 | 801 |
| 779 void ProtocolHandlerRegistry::InsertHandler(const ProtocolHandler& handler) { | 802 void ProtocolHandlerRegistry::InsertHandler(const ProtocolHandler& handler) { |
| 780 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 803 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 781 ProtocolHandlerMultiMap::iterator p = | 804 ProtocolHandlerMultiMap::iterator p = |
| 782 protocol_handlers_.find(handler.protocol()); | 805 protocol_handlers_.find(handler.protocol()); |
| 783 | 806 |
| 784 if (p != protocol_handlers_.end()) { | 807 if (p != protocol_handlers_.end()) { |
| 785 p->second.push_back(handler); | 808 p->second.push_back(handler); |
| 786 return; | 809 return; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 ignored_protocol_handlers_.push_back(handler); | 891 ignored_protocol_handlers_.push_back(handler); |
| 869 } | 892 } |
| 870 | 893 |
| 871 void ProtocolHandlerRegistry::AddPredefinedHandler( | 894 void ProtocolHandlerRegistry::AddPredefinedHandler( |
| 872 const ProtocolHandler& handler) { | 895 const ProtocolHandler& handler) { |
| 873 DCHECK(!is_loaded_); // Must be called prior InitProtocolSettings. | 896 DCHECK(!is_loaded_); // Must be called prior InitProtocolSettings. |
| 874 RegisterProtocolHandler(handler); | 897 RegisterProtocolHandler(handler); |
| 875 SetDefault(handler); | 898 SetDefault(handler); |
| 876 } | 899 } |
| 877 | 900 |
| 878 net::URLRequestJobFactory::Interceptor* | 901 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 879 ProtocolHandlerRegistry::CreateURLInterceptor() { | 902 ProtocolHandlerRegistry::CreateJobInterceptorFactory() { |
| 880 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 903 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 881 // this is always created on the UI thread (in profile_io's | 904 // this is always created on the UI thread (in profile_io's |
| 882 // InitializeOnUIThread. Any method calls must be done | 905 // InitializeOnUIThread. Any method calls must be done |
| 883 // on the IO thread (this is checked). | 906 // on the IO thread (this is checked). |
| 884 return new URLInterceptor(core_); | 907 return scoped_ptr<JobInterceptorFactory>(new JobInterceptorFactory( |
| 908 io_thread_delegate_)); |
| 885 } | 909 } |
| OLD | NEW |