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

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

Issue 10584042: Bring up a content settings icon for ungestured registerProtocolHandler call. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Repair merge to head 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 | Annotate | Revision Log
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/favicon/favicon_tab_helper.h" 12 #include "chrome/browser/favicon/favicon_tab_helper.h"
12 #include "chrome/browser/infobars/infobar_tab_helper.h" 13 #include "chrome/browser/infobars/infobar_tab_helper.h"
13 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" 16 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
16 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate. h" 17 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate. h"
17 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" 18 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h"
18 #include "chrome/browser/ui/content_settings/content_setting_bubble_model_delega te.h" 19 #include "chrome/browser/ui/content_settings/content_setting_bubble_model_delega te.h"
19 #include "chrome/browser/ui/tab_contents/tab_contents.h" 20 #include "chrome/browser/ui/tab_contents/tab_contents.h"
20 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 122
122 void SetManageLink() { 123 void SetManageLink() {
123 static const ContentSettingsTypeIdEntry kLinkIDs[] = { 124 static const ContentSettingsTypeIdEntry kLinkIDs[] = {
124 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK}, 125 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK},
125 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK}, 126 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK},
126 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK}, 127 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK},
127 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK}, 128 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK},
128 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK}, 129 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK},
129 {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK}, 130 {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK},
130 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_LEARN_MORE}, 131 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_LEARN_MORE},
132 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, IDS_HANDLERS_BUBBLE_MANAGE_LINK}
131 }; 133 };
132 set_manage_link(l10n_util::GetStringUTF8( 134 set_manage_link(l10n_util::GetStringUTF8(
133 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); 135 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type())));
134 } 136 }
135 137
136 virtual void OnManageLinkClicked() { 138 virtual void OnManageLinkClicked() {
137 if (delegate_) 139 if (delegate_)
138 delegate_->ShowContentSettingsPage(content_type()); 140 delegate_->ShowContentSettingsPage(content_type());
139 } 141 }
140 142
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 } 515 }
514 } 516 }
515 }; 517 };
516 518
517 class ContentSettingMixedScriptBubbleModel 519 class ContentSettingMixedScriptBubbleModel
518 : public ContentSettingTitleLinkAndCustomModel { 520 : public ContentSettingTitleLinkAndCustomModel {
519 public: 521 public:
520 ContentSettingMixedScriptBubbleModel(Delegate* delegate, 522 ContentSettingMixedScriptBubbleModel(Delegate* delegate,
521 TabContents* tab_contents, 523 TabContents* tab_contents,
522 Profile* profile, 524 Profile* profile,
523 ContentSettingsType content_type) 525 ContentSettingsType content_type);
524 : ContentSettingTitleLinkAndCustomModel(
525 delegate, tab_contents, profile, content_type) {
526 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_MIXEDSCRIPT);
527 set_custom_link_enabled(true);
528 }
529 526
530 virtual ~ContentSettingMixedScriptBubbleModel() {} 527 virtual ~ContentSettingMixedScriptBubbleModel() {}
531 528
532 private: 529 private:
533 virtual void OnCustomLinkClicked() OVERRIDE { 530 virtual void OnCustomLinkClicked() OVERRIDE;
534 content::RecordAction(UserMetricsAction("MixedScript_LoadAnyway_Bubble")); 531 };
535 DCHECK(tab_contents()); 532
536 content::RenderViewHost* host = 533 ContentSettingMixedScriptBubbleModel::ContentSettingMixedScriptBubbleModel(
537 tab_contents()->web_contents()->GetRenderViewHost(); 534 Delegate* delegate,
538 host->Send(new ChromeViewMsg_SetAllowRunningInsecureContent( 535 TabContents* tab_contents,
539 host->GetRoutingID(), true)); 536 Profile* profile,
537 ContentSettingsType content_type)
538 : ContentSettingTitleLinkAndCustomModel(
539 delegate, tab_contents, profile, content_type) {
540 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_MIXEDSCRIPT);
541 set_custom_link_enabled(true);
542 }
543
544 void ContentSettingMixedScriptBubbleModel::OnCustomLinkClicked() {
545 content::RecordAction(UserMetricsAction("MixedScript_LoadAnyway_Bubble"));
546 DCHECK(tab_contents());
547 content::RenderViewHost* host =
548 tab_contents()->web_contents()->GetRenderViewHost();
549 host->Send(new ChromeViewMsg_SetAllowRunningInsecureContent(
550 host->GetRoutingID(), true));
551 }
552
553 class ContentSettingRPHBubbleModel : public ContentSettingTitleAndLinkModel {
554 public:
555 ContentSettingRPHBubbleModel(Delegate* delegate,
556 TabContents* tab_contents,
557 Profile* profile,
558 ContentSettingsType content_type);
559
560 virtual void OnCustomLinkClicked();
Bernhard Bauer 2012/07/02 23:13:15 Nit: add "override"?
Greg Billock 2012/07/03 20:33:03 Done.
561 virtual void OnRadioClicked(int radio_index);
562
563 private:
564 // These states must match the order of appearance of the radio buttons
565 // in the XIB file for the Mac port.
566 enum RPHState {
567 RPH_ALLOW = 0,
568 RPH_BLOCK,
569 RPH_IGNORE,
570 };
571
572 void RegisterProtocolHandler();
573 void UnregisterProtocolHandler();
574 void IgnoreProtocolHandler();
575 void ClearOrSetPreviousHandler();
576
577 int selected_item_;
578 ProtocolHandler pending_handler_;
579 ProtocolHandler previous_handler_;
580 };
581
582 ContentSettingRPHBubbleModel::ContentSettingRPHBubbleModel(
583 Delegate* delegate,
584 TabContents* tab_contents,
585 Profile* profile,
586 ContentSettingsType content_type)
587 : ContentSettingTitleAndLinkModel(
588 delegate, tab_contents, profile, content_type),
589 selected_item_(0),
590 pending_handler_(ProtocolHandler::EmptyProtocolHandler()),
591 previous_handler_(ProtocolHandler::EmptyProtocolHandler()) {
592 DCHECK_EQ(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, content_type);
593
594 TabSpecificContentSettings* content_settings =
595 tab_contents->content_settings();
596 pending_handler_ = content_settings->pending_protocol_handler();
597 previous_handler_ = content_settings->previous_protocol_handler();
598
599 string16 protocol;
600 if (pending_handler_.protocol() == "mailto") {
601 protocol = l10n_util::GetStringUTF16(
602 IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME);
603 } else if (pending_handler_.protocol() == "webcal") {
604 protocol = l10n_util::GetStringUTF16(
605 IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME);
606 } else {
607 protocol = UTF8ToUTF16(pending_handler_.protocol());
540 } 608 }
541 }; 609
610 if (previous_handler_.IsEmpty()) {
611 set_title(l10n_util::GetStringFUTF8(
612 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM,
613 pending_handler_.title(), UTF8ToUTF16(pending_handler_.url().host()),
614 protocol));
615 } else {
616 set_title(l10n_util::GetStringFUTF8(
617 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE,
618 pending_handler_.title(), UTF8ToUTF16(pending_handler_.url().host()),
619 protocol, previous_handler_.title()));
620 }
621
622 std::string radio_allow_label =
623 l10n_util::GetStringFUTF8(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT,
624 pending_handler_.title());
625 std::string radio_deny_label =
626 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_DENY);
627 std::string radio_ignore_label =
628 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_IGNORE);
629
630 GURL url = tab_contents->web_contents()->GetURL();
631 RadioGroup radio_group;
632 radio_group.url = url;
633
634 radio_group.radio_items.push_back(radio_allow_label);
635 radio_group.radio_items.push_back(radio_deny_label);
636 radio_group.radio_items.push_back(radio_ignore_label);
637 ContentSetting setting =
638 content_settings->pending_protocol_handler_setting();
639 if (setting == CONTENT_SETTING_ALLOW)
640 radio_group.default_item = RPH_ALLOW;
641 else if (setting == CONTENT_SETTING_BLOCK)
642 radio_group.default_item = RPH_BLOCK;
643 else
644 radio_group.default_item = RPH_IGNORE;
645
646 selected_item_ = radio_group.default_item;
647 set_radio_group_enabled(true);
648 set_radio_group(radio_group);
649 }
650
651 void ContentSettingRPHBubbleModel::OnCustomLinkClicked() {
652 RegisterProtocolHandler();
Bernhard Bauer 2012/07/02 23:13:15 I think this method isn't called?
Greg Billock 2012/07/03 20:33:03 Done.
653 }
654
655 void ContentSettingRPHBubbleModel::OnRadioClicked(int radio_index) {
656 if (selected_item_ == radio_index)
657 return;
658
659 selected_item_ = radio_index;
660
661 if (radio_index == RPH_ALLOW)
662 RegisterProtocolHandler();
663 else if (radio_index == RPH_BLOCK)
664 UnregisterProtocolHandler();
665 else if (radio_index == RPH_IGNORE)
666 IgnoreProtocolHandler();
667 else
668 NOTREACHED();
669 }
670
671 void ContentSettingRPHBubbleModel::RegisterProtocolHandler() {
672 // A no-op if the handler hasn't been ignored, but needed in case the user
673 // selects sequences like register/ignore/register.
674 profile()->GetProtocolHandlerRegistry()->RemoveIgnoredHandler(
675 pending_handler_);
676
677 profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler(
678 pending_handler_);
679 tab_contents()->content_settings()->set_pending_protocol_handler_setting(
680 CONTENT_SETTING_ALLOW);
681 }
682
683 void ContentSettingRPHBubbleModel::UnregisterProtocolHandler() {
684 profile()->GetProtocolHandlerRegistry()->OnDenyRegisterProtocolHandler(
685 pending_handler_);
686 tab_contents()->content_settings()->set_pending_protocol_handler_setting(
687 CONTENT_SETTING_BLOCK);
688 ClearOrSetPreviousHandler();
689 }
690
691 void ContentSettingRPHBubbleModel::IgnoreProtocolHandler() {
692 profile()->GetProtocolHandlerRegistry()->OnIgnoreRegisterProtocolHandler(
693 pending_handler_);
694 tab_contents()->content_settings()->set_pending_protocol_handler_setting(
695 CONTENT_SETTING_DEFAULT);
696 ClearOrSetPreviousHandler();
697 }
698
699 void ContentSettingRPHBubbleModel::ClearOrSetPreviousHandler() {
700 if (previous_handler_.IsEmpty()) {
701 profile()->GetProtocolHandlerRegistry()->ClearDefault(
702 pending_handler_.protocol());
703 } else {
704 profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler(
705 previous_handler_);
706 }
707 }
542 708
543 // static 709 // static
544 ContentSettingBubbleModel* 710 ContentSettingBubbleModel*
545 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 711 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
546 Delegate* delegate, 712 Delegate* delegate,
547 TabContents* tab_contents, 713 TabContents* tab_contents,
548 Profile* profile, 714 Profile* profile,
549 ContentSettingsType content_type) { 715 ContentSettingsType content_type) {
550 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { 716 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) {
551 return new ContentSettingCookiesBubbleModel(delegate, tab_contents, profile, 717 return new ContentSettingCookiesBubbleModel(delegate, tab_contents, profile,
552 content_type); 718 content_type);
553 } 719 }
554 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { 720 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) {
555 return new ContentSettingPopupBubbleModel(delegate, tab_contents, profile, 721 return new ContentSettingPopupBubbleModel(delegate, tab_contents, profile,
556 content_type); 722 content_type);
557 } 723 }
558 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { 724 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
559 return new ContentSettingDomainListBubbleModel(delegate, tab_contents, 725 return new ContentSettingDomainListBubbleModel(delegate, tab_contents,
560 profile, content_type); 726 profile, content_type);
561 } 727 }
562 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { 728 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) {
563 return new ContentSettingPluginBubbleModel(delegate, tab_contents, profile, 729 return new ContentSettingPluginBubbleModel(delegate, tab_contents, profile,
564 content_type); 730 content_type);
565 } 731 }
566 if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { 732 if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) {
567 return new ContentSettingMixedScriptBubbleModel(delegate, tab_contents, 733 return new ContentSettingMixedScriptBubbleModel(delegate, tab_contents,
568 profile, content_type); 734 profile, content_type);
569 } 735 }
736 if (content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) {
737 return new ContentSettingRPHBubbleModel(delegate, tab_contents, profile,
738 content_type);
739 }
570 return new ContentSettingSingleRadioGroup(delegate, tab_contents, profile, 740 return new ContentSettingSingleRadioGroup(delegate, tab_contents, profile,
571 content_type); 741 content_type);
572 } 742 }
573 743
574 ContentSettingBubbleModel::ContentSettingBubbleModel( 744 ContentSettingBubbleModel::ContentSettingBubbleModel(
575 TabContents* tab_contents, 745 TabContents* tab_contents,
576 Profile* profile, 746 Profile* profile,
577 ContentSettingsType content_type) 747 ContentSettingsType content_type)
578 : tab_contents_(tab_contents), 748 : tab_contents_(tab_contents),
579 profile_(profile), 749 profile_(profile),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 const content::NotificationDetails& details) { 784 const content::NotificationDetails& details) {
615 if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) { 785 if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) {
616 DCHECK_EQ(tab_contents_, content::Source<TabContents>(source).ptr()); 786 DCHECK_EQ(tab_contents_, content::Source<TabContents>(source).ptr());
617 tab_contents_ = NULL; 787 tab_contents_ = NULL;
618 } else { 788 } else {
619 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); 789 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type);
620 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); 790 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr());
621 profile_ = NULL; 791 profile_ = NULL;
622 } 792 }
623 } 793 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698