Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: chrome/browser/ui/content_settings/content_setting_bubble_model.cc

Issue 10546083: Convert ProtocolHandlerRegistry to be a ProfileKeyedService. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add missing include. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/ui/content_settings/content_setting_bubble_model.h" 5 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/content_settings/content_settings_utils.h" 8 #include "chrome/browser/content_settings/content_settings_utils.h"
9 #include "chrome/browser/content_settings/cookie_settings.h" 9 #include "chrome/browser/content_settings/cookie_settings.h"
10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
11 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 11 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
12 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
12 #include "chrome/browser/favicon/favicon_tab_helper.h" 13 #include "chrome/browser/favicon/favicon_tab_helper.h"
13 #include "chrome/browser/infobars/infobar_tab_helper.h" 14 #include "chrome/browser/infobars/infobar_tab_helper.h"
14 #include "chrome/browser/prefs/pref_service.h" 15 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" 17 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
17 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate. h" 18 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate. h"
18 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" 19 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h"
19 #include "chrome/browser/ui/content_settings/content_setting_bubble_model_delega te.h" 20 #include "chrome/browser/ui/content_settings/content_setting_bubble_model_delega te.h"
20 #include "chrome/browser/ui/tab_contents/tab_contents.h" 21 #include "chrome/browser/ui/tab_contents/tab_contents.h"
21 #include "chrome/common/chrome_notification_types.h" 22 #include "chrome/common/chrome_notification_types.h"
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 content::RenderViewHost* host = 600 content::RenderViewHost* host =
600 tab_contents()->web_contents()->GetRenderViewHost(); 601 tab_contents()->web_contents()->GetRenderViewHost();
601 host->Send(new ChromeViewMsg_SetAllowRunningInsecureContent( 602 host->Send(new ChromeViewMsg_SetAllowRunningInsecureContent(
602 host->GetRoutingID(), true)); 603 host->GetRoutingID(), true));
603 } 604 }
604 605
605 ContentSettingRPHBubbleModel::ContentSettingRPHBubbleModel( 606 ContentSettingRPHBubbleModel::ContentSettingRPHBubbleModel(
606 Delegate* delegate, 607 Delegate* delegate,
607 TabContents* tab_contents, 608 TabContents* tab_contents,
608 Profile* profile, 609 Profile* profile,
610 ProtocolHandlerRegistry* registry,
611 ContentSettingsType content_type)
612 : ContentSettingTitleAndLinkModel(
613 delegate, tab_contents, profile, content_type),
614 selected_item_(0),
615 registry_(registry),
616 pending_handler_(ProtocolHandler::EmptyProtocolHandler()),
617 previous_handler_(ProtocolHandler::EmptyProtocolHandler()) {
618 Init();
619 }
620
621 ContentSettingRPHBubbleModel::ContentSettingRPHBubbleModel(
622 Delegate* delegate,
623 TabContents* tab_contents,
624 Profile* profile,
609 ContentSettingsType content_type) 625 ContentSettingsType content_type)
610 : ContentSettingTitleAndLinkModel( 626 : ContentSettingTitleAndLinkModel(
611 delegate, tab_contents, profile, content_type), 627 delegate, tab_contents, profile, content_type),
612 selected_item_(0), 628 selected_item_(0),
629 registry_(ProtocolHandlerRegistryFactory::GetForProfile(profile)),
613 pending_handler_(ProtocolHandler::EmptyProtocolHandler()), 630 pending_handler_(ProtocolHandler::EmptyProtocolHandler()),
614 previous_handler_(ProtocolHandler::EmptyProtocolHandler()) { 631 previous_handler_(ProtocolHandler::EmptyProtocolHandler()) {
615 DCHECK_EQ(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, content_type); 632 Init();
633 }
634
635 void ContentSettingRPHBubbleModel::Init() {
636 DCHECK_EQ(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, content_type());
616 637
617 TabSpecificContentSettings* content_settings = 638 TabSpecificContentSettings* content_settings =
618 tab_contents->content_settings(); 639 tab_contents()->content_settings();
619 pending_handler_ = content_settings->pending_protocol_handler(); 640 pending_handler_ = content_settings->pending_protocol_handler();
620 previous_handler_ = content_settings->previous_protocol_handler(); 641 previous_handler_ = content_settings->previous_protocol_handler();
621 642
622 string16 protocol; 643 string16 protocol;
623 if (pending_handler_.protocol() == "mailto") { 644 if (pending_handler_.protocol() == "mailto") {
624 protocol = l10n_util::GetStringUTF16( 645 protocol = l10n_util::GetStringUTF16(
625 IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME); 646 IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME);
626 } else if (pending_handler_.protocol() == "webcal") { 647 } else if (pending_handler_.protocol() == "webcal") {
627 protocol = l10n_util::GetStringUTF16( 648 protocol = l10n_util::GetStringUTF16(
628 IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME); 649 IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME);
(...skipping 14 matching lines...) Expand all
643 } 664 }
644 665
645 std::string radio_allow_label = 666 std::string radio_allow_label =
646 l10n_util::GetStringFUTF8(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT, 667 l10n_util::GetStringFUTF8(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT,
647 pending_handler_.title()); 668 pending_handler_.title());
648 std::string radio_deny_label = 669 std::string radio_deny_label =
649 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_DENY); 670 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_DENY);
650 std::string radio_ignore_label = 671 std::string radio_ignore_label =
651 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_IGNORE); 672 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_IGNORE);
652 673
653 GURL url = tab_contents->web_contents()->GetURL(); 674 GURL url = tab_contents()->web_contents()->GetURL();
654 RadioGroup radio_group; 675 RadioGroup radio_group;
655 radio_group.url = url; 676 radio_group.url = url;
656 677
657 radio_group.radio_items.push_back(radio_allow_label); 678 radio_group.radio_items.push_back(radio_allow_label);
658 radio_group.radio_items.push_back(radio_deny_label); 679 radio_group.radio_items.push_back(radio_deny_label);
659 radio_group.radio_items.push_back(radio_ignore_label); 680 radio_group.radio_items.push_back(radio_ignore_label);
660 ContentSetting setting = 681 ContentSetting setting =
661 content_settings->pending_protocol_handler_setting(); 682 content_settings->pending_protocol_handler_setting();
662 if (setting == CONTENT_SETTING_ALLOW) 683 if (setting == CONTENT_SETTING_ALLOW)
663 radio_group.default_item = RPH_ALLOW; 684 radio_group.default_item = RPH_ALLOW;
(...skipping 19 matching lines...) Expand all
683 UnregisterProtocolHandler(); 704 UnregisterProtocolHandler();
684 else if (radio_index == RPH_IGNORE) 705 else if (radio_index == RPH_IGNORE)
685 IgnoreProtocolHandler(); 706 IgnoreProtocolHandler();
686 else 707 else
687 NOTREACHED(); 708 NOTREACHED();
688 } 709 }
689 710
690 void ContentSettingRPHBubbleModel::RegisterProtocolHandler() { 711 void ContentSettingRPHBubbleModel::RegisterProtocolHandler() {
691 // A no-op if the handler hasn't been ignored, but needed in case the user 712 // A no-op if the handler hasn't been ignored, but needed in case the user
692 // selects sequences like register/ignore/register. 713 // selects sequences like register/ignore/register.
693 profile()->GetProtocolHandlerRegistry()->RemoveIgnoredHandler( 714 registry_->RemoveIgnoredHandler(pending_handler_);
694 pending_handler_);
695 715
696 profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler( 716 registry_->OnAcceptRegisterProtocolHandler(pending_handler_);
697 pending_handler_);
698 tab_contents()->content_settings()->set_pending_protocol_handler_setting( 717 tab_contents()->content_settings()->set_pending_protocol_handler_setting(
699 CONTENT_SETTING_ALLOW); 718 CONTENT_SETTING_ALLOW);
700 } 719 }
701 720
702 void ContentSettingRPHBubbleModel::UnregisterProtocolHandler() { 721 void ContentSettingRPHBubbleModel::UnregisterProtocolHandler() {
703 profile()->GetProtocolHandlerRegistry()->OnDenyRegisterProtocolHandler( 722 registry_->OnDenyRegisterProtocolHandler(pending_handler_);
704 pending_handler_);
705 tab_contents()->content_settings()->set_pending_protocol_handler_setting( 723 tab_contents()->content_settings()->set_pending_protocol_handler_setting(
706 CONTENT_SETTING_BLOCK); 724 CONTENT_SETTING_BLOCK);
707 ClearOrSetPreviousHandler(); 725 ClearOrSetPreviousHandler();
708 } 726 }
709 727
710 void ContentSettingRPHBubbleModel::IgnoreProtocolHandler() { 728 void ContentSettingRPHBubbleModel::IgnoreProtocolHandler() {
711 profile()->GetProtocolHandlerRegistry()->OnIgnoreRegisterProtocolHandler( 729 registry_->OnIgnoreRegisterProtocolHandler(pending_handler_);
712 pending_handler_);
713 tab_contents()->content_settings()->set_pending_protocol_handler_setting( 730 tab_contents()->content_settings()->set_pending_protocol_handler_setting(
714 CONTENT_SETTING_DEFAULT); 731 CONTENT_SETTING_DEFAULT);
715 ClearOrSetPreviousHandler(); 732 ClearOrSetPreviousHandler();
716 } 733 }
717 734
718 void ContentSettingRPHBubbleModel::ClearOrSetPreviousHandler() { 735 void ContentSettingRPHBubbleModel::ClearOrSetPreviousHandler() {
719 if (previous_handler_.IsEmpty()) { 736 if (previous_handler_.IsEmpty()) {
720 profile()->GetProtocolHandlerRegistry()->ClearDefault( 737 registry_->ClearDefault(pending_handler_.protocol());
721 pending_handler_.protocol());
722 } else { 738 } else {
723 profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler( 739 registry_->OnAcceptRegisterProtocolHandler(previous_handler_);
724 previous_handler_);
725 } 740 }
726 } 741 }
727 742
728 // static 743 // static
729 ContentSettingBubbleModel* 744 ContentSettingBubbleModel*
730 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 745 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
731 Delegate* delegate, 746 Delegate* delegate,
732 TabContents* tab_contents, 747 TabContents* tab_contents,
733 Profile* profile, 748 Profile* profile,
734 ContentSettingsType content_type) { 749 ContentSettingsType content_type) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 const content::NotificationDetails& details) { 818 const content::NotificationDetails& details) {
804 if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) { 819 if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) {
805 DCHECK_EQ(tab_contents_, content::Source<TabContents>(source).ptr()); 820 DCHECK_EQ(tab_contents_, content::Source<TabContents>(source).ptr());
806 tab_contents_ = NULL; 821 tab_contents_ = NULL;
807 } else { 822 } else {
808 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); 823 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type);
809 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); 824 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr());
810 profile_ = NULL; 825 profile_ = NULL;
811 } 826 }
812 } 827 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698