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 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 is_loading_ = true; | 437 is_loading_ = true; |
438 | 438 |
439 PrefService* prefs = profile_->GetPrefs(); | 439 PrefService* prefs = profile_->GetPrefs(); |
440 if (prefs->HasPrefPath(prefs::kCustomHandlersEnabled)) { | 440 if (prefs->HasPrefPath(prefs::kCustomHandlersEnabled)) { |
441 if (prefs->GetBoolean(prefs::kCustomHandlersEnabled)) { | 441 if (prefs->GetBoolean(prefs::kCustomHandlersEnabled)) { |
442 Enable(); | 442 Enable(); |
443 } else { | 443 } else { |
444 Disable(); | 444 Disable(); |
445 } | 445 } |
446 } | 446 } |
447 std::vector<const DictionaryValue*> registered_handlers = | 447 std::vector<const base::DictionaryValue*> registered_handlers = |
448 GetHandlersFromPref(prefs::kRegisteredProtocolHandlers); | 448 GetHandlersFromPref(prefs::kRegisteredProtocolHandlers); |
449 for (std::vector<const DictionaryValue*>::const_iterator p = | 449 for (std::vector<const base::DictionaryValue*>::const_iterator p = |
450 registered_handlers.begin(); | 450 registered_handlers.begin(); |
451 p != registered_handlers.end(); ++p) { | 451 p != registered_handlers.end(); ++p) { |
452 ProtocolHandler handler = ProtocolHandler::CreateProtocolHandler(*p); | 452 ProtocolHandler handler = ProtocolHandler::CreateProtocolHandler(*p); |
453 RegisterProtocolHandler(handler); | 453 RegisterProtocolHandler(handler); |
454 bool is_default = false; | 454 bool is_default = false; |
455 if ((*p)->GetBoolean("default", &is_default) && is_default) { | 455 if ((*p)->GetBoolean("default", &is_default) && is_default) { |
456 SetDefault(handler); | 456 SetDefault(handler); |
457 } | 457 } |
458 } | 458 } |
459 std::vector<const DictionaryValue*> ignored_handlers = | 459 std::vector<const base::DictionaryValue*> ignored_handlers = |
460 GetHandlersFromPref(prefs::kIgnoredProtocolHandlers); | 460 GetHandlersFromPref(prefs::kIgnoredProtocolHandlers); |
461 for (std::vector<const DictionaryValue*>::const_iterator p = | 461 for (std::vector<const base::DictionaryValue*>::const_iterator p = |
462 ignored_handlers.begin(); | 462 ignored_handlers.begin(); |
463 p != ignored_handlers.end(); ++p) { | 463 p != ignored_handlers.end(); ++p) { |
464 IgnoreProtocolHandler(ProtocolHandler::CreateProtocolHandler(*p)); | 464 IgnoreProtocolHandler(ProtocolHandler::CreateProtocolHandler(*p)); |
465 } | 465 } |
466 is_loading_ = false; | 466 is_loading_ = false; |
467 | 467 |
468 // For each default protocol handler, check that we are still registered | 468 // For each default protocol handler, check that we are still registered |
469 // with the OS as the default application. | 469 // with the OS as the default application. |
470 if (ShouldRemoveHandlersNotInOS()) { | 470 if (ShouldRemoveHandlersNotInOS()) { |
471 for (ProtocolHandlerMap::const_iterator p = default_handlers_.begin(); | 471 for (ProtocolHandlerMap::const_iterator p = default_handlers_.begin(); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 ProtocolHandlerList& list = p->second; | 732 ProtocolHandlerList& list = p->second; |
733 list.erase(std::find(list.begin(), list.end(), handler)); | 733 list.erase(std::find(list.begin(), list.end(), handler)); |
734 list.insert(list.begin(), handler); | 734 list.insert(list.begin(), handler); |
735 } | 735 } |
736 | 736 |
737 void ProtocolHandlerRegistry::Save() { | 737 void ProtocolHandlerRegistry::Save() { |
738 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 738 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
739 if (is_loading_) { | 739 if (is_loading_) { |
740 return; | 740 return; |
741 } | 741 } |
742 scoped_ptr<Value> registered_protocol_handlers(EncodeRegisteredHandlers()); | 742 scoped_ptr<base::Value> registered_protocol_handlers( |
743 scoped_ptr<Value> ignored_protocol_handlers(EncodeIgnoredHandlers()); | 743 EncodeRegisteredHandlers()); |
744 scoped_ptr<Value> enabled(Value::CreateBooleanValue(enabled_)); | 744 scoped_ptr<base::Value> ignored_protocol_handlers(EncodeIgnoredHandlers()); |
| 745 scoped_ptr<base::Value> enabled(base::Value::CreateBooleanValue(enabled_)); |
745 profile_->GetPrefs()->Set(prefs::kRegisteredProtocolHandlers, | 746 profile_->GetPrefs()->Set(prefs::kRegisteredProtocolHandlers, |
746 *registered_protocol_handlers); | 747 *registered_protocol_handlers); |
747 profile_->GetPrefs()->Set(prefs::kIgnoredProtocolHandlers, | 748 profile_->GetPrefs()->Set(prefs::kIgnoredProtocolHandlers, |
748 *ignored_protocol_handlers); | 749 *ignored_protocol_handlers); |
749 profile_->GetPrefs()->Set(prefs::kCustomHandlersEnabled, *enabled); | 750 profile_->GetPrefs()->Set(prefs::kCustomHandlersEnabled, *enabled); |
750 } | 751 } |
751 | 752 |
752 const ProtocolHandlerRegistry::ProtocolHandlerList* | 753 const ProtocolHandlerRegistry::ProtocolHandlerList* |
753 ProtocolHandlerRegistry::GetHandlerList( | 754 ProtocolHandlerRegistry::GetHandlerList( |
754 const std::string& scheme) const { | 755 const std::string& scheme) const { |
(...skipping 30 matching lines...) Expand all Loading... |
785 if (p != protocol_handlers_.end()) { | 786 if (p != protocol_handlers_.end()) { |
786 p->second.push_back(handler); | 787 p->second.push_back(handler); |
787 return; | 788 return; |
788 } | 789 } |
789 | 790 |
790 ProtocolHandlerList new_list; | 791 ProtocolHandlerList new_list; |
791 new_list.push_back(handler); | 792 new_list.push_back(handler); |
792 protocol_handlers_[handler.protocol()] = new_list; | 793 protocol_handlers_[handler.protocol()] = new_list; |
793 } | 794 } |
794 | 795 |
795 Value* ProtocolHandlerRegistry::EncodeRegisteredHandlers() { | 796 base::Value* ProtocolHandlerRegistry::EncodeRegisteredHandlers() { |
796 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 797 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
797 ListValue* protocol_handlers = new ListValue(); | 798 base::ListValue* protocol_handlers = new base::ListValue(); |
798 for (ProtocolHandlerMultiMap::iterator i = protocol_handlers_.begin(); | 799 for (ProtocolHandlerMultiMap::iterator i = protocol_handlers_.begin(); |
799 i != protocol_handlers_.end(); ++i) { | 800 i != protocol_handlers_.end(); ++i) { |
800 for (ProtocolHandlerList::iterator j = i->second.begin(); | 801 for (ProtocolHandlerList::iterator j = i->second.begin(); |
801 j != i->second.end(); ++j) { | 802 j != i->second.end(); ++j) { |
802 DictionaryValue* encoded = j->Encode(); | 803 base::DictionaryValue* encoded = j->Encode(); |
803 if (IsDefault(*j)) { | 804 if (IsDefault(*j)) { |
804 encoded->Set("default", Value::CreateBooleanValue(true)); | 805 encoded->Set("default", base::Value::CreateBooleanValue(true)); |
805 } | 806 } |
806 protocol_handlers->Append(encoded); | 807 protocol_handlers->Append(encoded); |
807 } | 808 } |
808 } | 809 } |
809 return protocol_handlers; | 810 return protocol_handlers; |
810 } | 811 } |
811 | 812 |
812 Value* ProtocolHandlerRegistry::EncodeIgnoredHandlers() { | 813 base::Value* ProtocolHandlerRegistry::EncodeIgnoredHandlers() { |
813 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 814 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
814 ListValue* handlers = new ListValue(); | 815 base::ListValue* handlers = new base::ListValue(); |
815 for (ProtocolHandlerList::iterator i = ignored_protocol_handlers_.begin(); | 816 for (ProtocolHandlerList::iterator i = ignored_protocol_handlers_.begin(); |
816 i != ignored_protocol_handlers_.end(); ++i) { | 817 i != ignored_protocol_handlers_.end(); ++i) { |
817 handlers->Append(i->Encode()); | 818 handlers->Append(i->Encode()); |
818 } | 819 } |
819 return handlers; | 820 return handlers; |
820 } | 821 } |
821 | 822 |
822 void ProtocolHandlerRegistry::NotifyChanged() { | 823 void ProtocolHandlerRegistry::NotifyChanged() { |
823 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 824 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
824 content::NotificationService::current()->Notify( | 825 content::NotificationService::current()->Notify( |
825 chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, | 826 chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, |
826 content::Source<Profile>(profile_), | 827 content::Source<Profile>(profile_), |
827 content::NotificationService::NoDetails()); | 828 content::NotificationService::NoDetails()); |
828 } | 829 } |
829 | 830 |
830 void ProtocolHandlerRegistry::RegisterProtocolHandler( | 831 void ProtocolHandlerRegistry::RegisterProtocolHandler( |
831 const ProtocolHandler& handler) { | 832 const ProtocolHandler& handler) { |
832 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 833 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
833 DCHECK(CanSchemeBeOverridden(handler.protocol())); | 834 DCHECK(CanSchemeBeOverridden(handler.protocol())); |
834 DCHECK(!handler.IsEmpty()); | 835 DCHECK(!handler.IsEmpty()); |
835 if (IsRegistered(handler)) { | 836 if (IsRegistered(handler)) { |
836 return; | 837 return; |
837 } | 838 } |
838 if (enabled_ && !delegate_->IsExternalHandlerRegistered(handler.protocol())) | 839 if (enabled_ && !delegate_->IsExternalHandlerRegistered(handler.protocol())) |
839 delegate_->RegisterExternalHandler(handler.protocol()); | 840 delegate_->RegisterExternalHandler(handler.protocol()); |
840 InsertHandler(handler); | 841 InsertHandler(handler); |
841 } | 842 } |
842 | 843 |
843 std::vector<const DictionaryValue*> | 844 std::vector<const base::DictionaryValue*> |
844 ProtocolHandlerRegistry::GetHandlersFromPref(const char* pref_name) const { | 845 ProtocolHandlerRegistry::GetHandlersFromPref(const char* pref_name) const { |
845 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 846 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
846 std::vector<const DictionaryValue*> result; | 847 std::vector<const base::DictionaryValue*> result; |
847 PrefService* prefs = profile_->GetPrefs(); | 848 PrefService* prefs = profile_->GetPrefs(); |
848 if (!prefs->HasPrefPath(pref_name)) { | 849 if (!prefs->HasPrefPath(pref_name)) { |
849 return result; | 850 return result; |
850 } | 851 } |
851 | 852 |
852 const ListValue* handlers = prefs->GetList(pref_name); | 853 const base::ListValue* handlers = prefs->GetList(pref_name); |
853 if (handlers) { | 854 if (handlers) { |
854 for (size_t i = 0; i < handlers->GetSize(); ++i) { | 855 for (size_t i = 0; i < handlers->GetSize(); ++i) { |
855 const DictionaryValue* dict; | 856 const base::DictionaryValue* dict; |
856 if (!handlers->GetDictionary(i, &dict)) | 857 if (!handlers->GetDictionary(i, &dict)) |
857 continue; | 858 continue; |
858 if (ProtocolHandler::IsValidDict(dict)) { | 859 if (ProtocolHandler::IsValidDict(dict)) { |
859 result.push_back(dict); | 860 result.push_back(dict); |
860 } | 861 } |
861 } | 862 } |
862 } | 863 } |
863 return result; | 864 return result; |
864 } | 865 } |
865 | 866 |
(...skipping 12 matching lines...) Expand all Loading... |
878 | 879 |
879 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> | 880 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> |
880 ProtocolHandlerRegistry::CreateJobInterceptorFactory() { | 881 ProtocolHandlerRegistry::CreateJobInterceptorFactory() { |
881 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 882 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
882 // this is always created on the UI thread (in profile_io's | 883 // this is always created on the UI thread (in profile_io's |
883 // InitializeOnUIThread. Any method calls must be done | 884 // InitializeOnUIThread. Any method calls must be done |
884 // on the IO thread (this is checked). | 885 // on the IO thread (this is checked). |
885 return scoped_ptr<JobInterceptorFactory>( | 886 return scoped_ptr<JobInterceptorFactory>( |
886 new JobInterceptorFactory(io_thread_delegate_.get())); | 887 new JobInterceptorFactory(io_thread_delegate_.get())); |
887 } | 888 } |
OLD | NEW |