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" |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 const ProtocolHandler& handler) const { | 526 const ProtocolHandler& handler) const { |
527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
528 const ProtocolHandlerList* handlers = GetHandlerList(handler.protocol()); | 528 const ProtocolHandlerList* handlers = GetHandlerList(handler.protocol()); |
529 if (!handlers) { | 529 if (!handlers) { |
530 return false; | 530 return false; |
531 } | 531 } |
532 return std::find(handlers->begin(), handlers->end(), handler) != | 532 return std::find(handlers->begin(), handlers->end(), handler) != |
533 handlers->end(); | 533 handlers->end(); |
534 } | 534 } |
535 | 535 |
| 536 bool ProtocolHandlerRegistry::IsRegisteredByUser( |
| 537 const ProtocolHandler& handler) { |
| 538 return HandlerExists(handler, &user_protocol_handlers_); |
| 539 } |
| 540 |
| 541 bool ProtocolHandlerRegistry::HasPolicyRegisteredHandler( |
| 542 const std::string& scheme) { |
| 543 return (policy_protocol_handlers_.find(scheme) != |
| 544 policy_protocol_handlers_.end()); |
| 545 } |
| 546 |
536 bool ProtocolHandlerRegistry::IsIgnored(const ProtocolHandler& handler) const { | 547 bool ProtocolHandlerRegistry::IsIgnored(const ProtocolHandler& handler) const { |
537 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
538 ProtocolHandlerList::const_iterator i; | 549 ProtocolHandlerList::const_iterator i; |
539 for (i = ignored_protocol_handlers_.begin(); | 550 for (i = ignored_protocol_handlers_.begin(); |
540 i != ignored_protocol_handlers_.end(); ++i) { | 551 i != ignored_protocol_handlers_.end(); ++i) { |
541 if (*i == handler) { | 552 if (*i == handler) { |
542 return true; | 553 return true; |
543 } | 554 } |
544 } | 555 } |
545 return false; | 556 return false; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 } | 609 } |
599 | 610 |
600 void ProtocolHandlerRegistry::RemoveHandler( | 611 void ProtocolHandlerRegistry::RemoveHandler( |
601 const ProtocolHandler& handler) { | 612 const ProtocolHandler& handler) { |
602 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 613 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
603 ProtocolHandlerList& handlers = protocol_handlers_[handler.protocol()]; | 614 ProtocolHandlerList& handlers = protocol_handlers_[handler.protocol()]; |
604 bool erase_success = false; | 615 bool erase_success = false; |
605 if (HandlerExists(handler, handlers) && | 616 if (HandlerExists(handler, handlers) && |
606 HandlerExists(handler, &user_protocol_handlers_)) { | 617 HandlerExists(handler, &user_protocol_handlers_)) { |
607 EraseHandler(handler, &user_protocol_handlers_); | 618 EraseHandler(handler, &user_protocol_handlers_); |
608 if (!HandlerExists(handler, &policy_protocol_handlers_)) { | 619 erase_success = true; |
609 erase_success = true; | 620 if (!HandlerExists(handler, &policy_protocol_handlers_)) |
610 EraseHandler(handler, &protocol_handlers_); | 621 EraseHandler(handler, &protocol_handlers_); |
611 } | |
612 } | 622 } |
613 ProtocolHandlerMap::iterator q = default_handlers_.find(handler.protocol()); | 623 ProtocolHandlerMap::iterator q = default_handlers_.find(handler.protocol()); |
614 if (erase_success && q != default_handlers_.end() && q->second == handler) { | 624 if (erase_success && q != default_handlers_.end() && q->second == handler) { |
615 // Make the new top handler in the list the default. | 625 // Make the new top handler in the list the default. |
616 if (!handlers.empty()) { | 626 if (!handlers.empty()) { |
617 // NOTE We pass a copy because SetDefault() modifies handlers. | 627 // NOTE We pass a copy because SetDefault() modifies handlers. |
618 SetDefault(ProtocolHandler(handlers[0])); | 628 SetDefault(ProtocolHandler(handlers[0])); |
619 } else { | 629 } else { |
620 BrowserThread::PostTask( | 630 BrowserThread::PostTask( |
621 BrowserThread::IO, FROM_HERE, | 631 BrowserThread::IO, FROM_HERE, |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 | 954 |
945 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 955 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
946 ProtocolHandlerRegistry::CreateJobInterceptorFactory() { | 956 ProtocolHandlerRegistry::CreateJobInterceptorFactory() { |
947 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 957 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
948 // this is always created on the UI thread (in profile_io's | 958 // this is always created on the UI thread (in profile_io's |
949 // InitializeOnUIThread. Any method calls must be done | 959 // InitializeOnUIThread. Any method calls must be done |
950 // on the IO thread (this is checked). | 960 // on the IO thread (this is checked). |
951 return scoped_ptr<JobInterceptorFactory>( | 961 return scoped_ptr<JobInterceptorFactory>( |
952 new JobInterceptorFactory(io_thread_delegate_.get())); | 962 new JobInterceptorFactory(io_thread_delegate_.get())); |
953 } | 963 } |
OLD | NEW |