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

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

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

Powered by Google App Engine
This is Rietveld 408576698