| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 } | 231 } |
| 232 | 232 |
| 233 // Delegate -------------------------------------------------------------------- | 233 // Delegate -------------------------------------------------------------------- |
| 234 | 234 |
| 235 ProtocolHandlerRegistry::Delegate::~Delegate() {} | 235 ProtocolHandlerRegistry::Delegate::~Delegate() {} |
| 236 | 236 |
| 237 void ProtocolHandlerRegistry::Delegate::RegisterExternalHandler( | 237 void ProtocolHandlerRegistry::Delegate::RegisterExternalHandler( |
| 238 const std::string& protocol) { | 238 const std::string& protocol) { |
| 239 ChildProcessSecurityPolicy* policy = | 239 ChildProcessSecurityPolicy* policy = |
| 240 ChildProcessSecurityPolicy::GetInstance(); | 240 ChildProcessSecurityPolicy::GetInstance(); |
| 241 CHECK(CanSchemeBeOverridden(protocol)); |
| 241 if (!policy->IsWebSafeScheme(protocol)) { | 242 if (!policy->IsWebSafeScheme(protocol)) { |
| 242 policy->RegisterWebSafeScheme(protocol); | 243 policy->RegisterWebSafeScheme(protocol); |
| 243 } | 244 } |
| 244 } | 245 } |
| 245 | 246 |
| 246 void ProtocolHandlerRegistry::Delegate::DeregisterExternalHandler( | 247 void ProtocolHandlerRegistry::Delegate::DeregisterExternalHandler( |
| 247 const std::string& protocol) { | 248 const std::string& protocol) { |
| 248 } | 249 } |
| 249 | 250 |
| 250 bool ProtocolHandlerRegistry::Delegate::IsExternalHandlerRegistered( | 251 bool ProtocolHandlerRegistry::Delegate::CanSchemeBeOverridden( |
| 251 const std::string& protocol) { | 252 const std::string& protocol) { |
| 252 // NOTE(koz): This function is safe to call from any thread, despite living | 253 // NOTE(koz): This function is safe to call from any thread, despite living |
| 253 // in ProfileIOData. | 254 // in ProfileIOData. |
| 254 return ProfileIOData::IsHandledProtocol(protocol); | 255 return !ProfileIOData::IsBuiltInProtocol(protocol); |
| 255 } | 256 } |
| 256 | 257 |
| 257 scoped_refptr<shell_integration::DefaultProtocolClientWorker> | 258 scoped_refptr<shell_integration::DefaultProtocolClientWorker> |
| 258 ProtocolHandlerRegistry::Delegate::CreateShellWorker( | 259 ProtocolHandlerRegistry::Delegate::CreateShellWorker( |
| 259 const shell_integration::DefaultWebClientWorkerCallback& callback, | 260 const shell_integration::DefaultWebClientWorkerCallback& callback, |
| 260 const std::string& protocol) { | 261 const std::string& protocol) { |
| 261 return new shell_integration::DefaultProtocolClientWorker(callback, protocol); | 262 return new shell_integration::DefaultProtocolClientWorker(callback, protocol); |
| 262 } | 263 } |
| 263 | 264 |
| 264 void ProtocolHandlerRegistry::Delegate::RegisterWithOSAsDefaultClient( | 265 void ProtocolHandlerRegistry::Delegate::RegisterWithOSAsDefaultClient( |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 ProtocolHandlerMultiMap::const_iterator p; | 474 ProtocolHandlerMultiMap::const_iterator p; |
| 474 for (p = protocol_handlers_.begin(); p != protocol_handlers_.end(); ++p) { | 475 for (p = protocol_handlers_.begin(); p != protocol_handlers_.end(); ++p) { |
| 475 if (!p->second.empty()) | 476 if (!p->second.empty()) |
| 476 output->push_back(p->first); | 477 output->push_back(p->first); |
| 477 } | 478 } |
| 478 } | 479 } |
| 479 | 480 |
| 480 bool ProtocolHandlerRegistry::CanSchemeBeOverridden( | 481 bool ProtocolHandlerRegistry::CanSchemeBeOverridden( |
| 481 const std::string& scheme) const { | 482 const std::string& scheme) const { |
| 482 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 483 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 483 const ProtocolHandlerList* handlers = GetHandlerList(scheme); | 484 |
| 484 // If we already have a handler for this scheme, we can add more. | 485 // Don't override a scheme if it has an built-in handler (http, https, chrome- |
| 485 if (handlers != NULL && !handlers->empty()) | 486 // extension, etc). |
| 486 return true; | 487 return delegate_->CanSchemeBeOverridden(scheme); |
| 487 // Don't override a scheme if it already has an external handler. | |
| 488 return !delegate_->IsExternalHandlerRegistered(scheme); | |
| 489 } | 488 } |
| 490 | 489 |
| 491 bool ProtocolHandlerRegistry::IsRegistered( | 490 bool ProtocolHandlerRegistry::IsRegistered( |
| 492 const ProtocolHandler& handler) const { | 491 const ProtocolHandler& handler) const { |
| 493 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 492 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 494 const ProtocolHandlerList* handlers = GetHandlerList(handler.protocol()); | 493 const ProtocolHandlerList* handlers = GetHandlerList(handler.protocol()); |
| 495 if (!handlers) { | 494 if (!handlers) { |
| 496 return false; | 495 return false; |
| 497 } | 496 } |
| 498 return std::find(handlers->begin(), handlers->end(), handler) != | 497 return std::find(handlers->begin(), handlers->end(), handler) != |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 content::NotificationService::current()->Notify( | 787 content::NotificationService::current()->Notify( |
| 789 chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, | 788 chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, |
| 790 content::Source<content::BrowserContext>(context_), | 789 content::Source<content::BrowserContext>(context_), |
| 791 content::NotificationService::NoDetails()); | 790 content::NotificationService::NoDetails()); |
| 792 } | 791 } |
| 793 | 792 |
| 794 void ProtocolHandlerRegistry::RegisterProtocolHandler( | 793 void ProtocolHandlerRegistry::RegisterProtocolHandler( |
| 795 const ProtocolHandler& handler, | 794 const ProtocolHandler& handler, |
| 796 const HandlerSource source) { | 795 const HandlerSource source) { |
| 797 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 796 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 798 DCHECK(CanSchemeBeOverridden(handler.protocol())); | 797 if (!CanSchemeBeOverridden(handler.protocol())) { |
| 798 NOTREACHED(); |
| 799 return; |
| 800 } |
| 801 |
| 799 DCHECK(!handler.IsEmpty()); | 802 DCHECK(!handler.IsEmpty()); |
| 800 ProtocolHandlerMultiMap& map = | 803 ProtocolHandlerMultiMap& map = |
| 801 (source == POLICY) ? policy_protocol_handlers_ : user_protocol_handlers_; | 804 (source == POLICY) ? policy_protocol_handlers_ : user_protocol_handlers_; |
| 802 ProtocolHandlerList& list = map[handler.protocol()]; | 805 ProtocolHandlerList& list = map[handler.protocol()]; |
| 803 if (!HandlerExists(handler, list)) | 806 if (!HandlerExists(handler, list)) |
| 804 list.push_back(handler); | 807 list.push_back(handler); |
| 805 if (IsRegistered(handler)) { | 808 if (IsRegistered(handler)) { |
| 806 return; | 809 return; |
| 807 } | 810 } |
| 808 if (enabled_ && !delegate_->IsExternalHandlerRegistered(handler.protocol())) | 811 if (enabled_) |
| 809 delegate_->RegisterExternalHandler(handler.protocol()); | 812 delegate_->RegisterExternalHandler(handler.protocol()); |
| 810 InsertHandler(handler); | 813 InsertHandler(handler); |
| 811 } | 814 } |
| 812 | 815 |
| 813 std::vector<const base::DictionaryValue*> | 816 std::vector<const base::DictionaryValue*> |
| 814 ProtocolHandlerRegistry::GetHandlersFromPref(const char* pref_name) const { | 817 ProtocolHandlerRegistry::GetHandlersFromPref(const char* pref_name) const { |
| 815 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 818 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 816 std::vector<const base::DictionaryValue*> result; | 819 std::vector<const base::DictionaryValue*> result; |
| 817 PrefService* prefs = user_prefs::UserPrefs::Get(context_); | 820 PrefService* prefs = user_prefs::UserPrefs::Get(context_); |
| 818 if (!prefs->HasPrefPath(pref_name)) { | 821 if (!prefs->HasPrefPath(pref_name)) { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 | 927 |
| 925 std::unique_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 928 std::unique_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
| 926 ProtocolHandlerRegistry::CreateJobInterceptorFactory() { | 929 ProtocolHandlerRegistry::CreateJobInterceptorFactory() { |
| 927 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 930 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 928 // this is always created on the UI thread (in profile_io's | 931 // this is always created on the UI thread (in profile_io's |
| 929 // InitializeOnUIThread. Any method calls must be done | 932 // InitializeOnUIThread. Any method calls must be done |
| 930 // on the IO thread (this is checked). | 933 // on the IO thread (this is checked). |
| 931 return std::unique_ptr<JobInterceptorFactory>( | 934 return std::unique_ptr<JobInterceptorFactory>( |
| 932 new JobInterceptorFactory(io_thread_delegate_.get())); | 935 new JobInterceptorFactory(io_thread_delegate_.get())); |
| 933 } | 936 } |
| OLD | NEW |