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

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 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();
561 virtual void OnRadioClicked(int radio_index);
562
563 private:
564 void RegisterProtocolHandler();
565 void UnregisterProtocolHandler();
566 void IgnoreProtocolHandler();
567 void ClearOrSetPreviousHandler();
568
569 enum RPHState {
Peter Kasting 2012/06/26 21:31:56 Nit: This goes above the methods. Also, if you fr
Greg Billock 2012/06/26 22:03:40 Moved.
570 RPH_ALLOW = 0,
571 RPH_BLOCK,
572 RPH_IGNORE,
573 };
574
575 int selected_item_;
576 ProtocolHandler pending_handler_;
577 ProtocolHandler previous_handler_;
578 };
579
580 ContentSettingRPHBubbleModel::ContentSettingRPHBubbleModel(
581 Delegate* delegate,
582 TabContents* tab_contents,
583 Profile* profile,
584 ContentSettingsType content_type)
585 : ContentSettingTitleAndLinkModel(
586 delegate, tab_contents, profile, content_type),
Peter Kasting 2012/06/26 19:53:00 Nit: Indent 4
Greg Billock 2012/06/26 20:31:41 Not sure what you mean. These lines are all at ind
Peter Kasting 2012/06/26 20:35:17 I meant: : ContentSettingTitleAndLinkModel(
Greg Billock 2012/06/26 20:42:49 Ah, ok. Will do.
587 selected_item_(0),
588 pending_handler_(ProtocolHandler::EmptyProtocolHandler()),
589 previous_handler_(ProtocolHandler::EmptyProtocolHandler()) {
590 DCHECK_EQ(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, content_type);
591
592 TabSpecificContentSettings* content_settings =
593 tab_contents->content_settings();
594 pending_handler_ = content_settings->pending_protocol_handler();
595 previous_handler_ = content_settings->previous_protocol_handler();
596
597 string16 protocol;
598 if (pending_handler_.protocol() == "mailto") {
599 protocol = l10n_util::GetStringUTF16(
600 IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME);
601 } else if (pending_handler_.protocol() == "webcal") {
602 protocol = l10n_util::GetStringUTF16(
603 IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME);
604 } else {
605 protocol = UTF8ToUTF16(pending_handler_.protocol());
540 } 606 }
541 }; 607
608 if (previous_handler_.IsEmpty()) {
609 set_title(l10n_util::GetStringFUTF8(
610 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM,
611 pending_handler_.title(), UTF8ToUTF16(pending_handler_.url().host()),
612 protocol));
613 } else {
614 set_title(l10n_util::GetStringFUTF8(
615 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE,
616 pending_handler_.title(), UTF8ToUTF16(pending_handler_.url().host()),
617 protocol, previous_handler_.title()));
618 }
619
620 std::string radio_allow_label =
621 l10n_util::GetStringFUTF8(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT,
622 pending_handler_.title());
623 std::string radio_deny_label =
624 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_DENY);
625 std::string radio_ignore_label =
626 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_IGNORE);
627
628 GURL url = tab_contents->web_contents()->GetURL();
629 RadioGroup radio_group;
630 radio_group.url = url;
631
632 radio_group.radio_items.push_back(radio_allow_label);
633 radio_group.radio_items.push_back(radio_deny_label);
634 radio_group.radio_items.push_back(radio_ignore_label);
635 ContentSetting setting =
636 content_settings->pending_protocol_handler_setting();
637 if (setting == CONTENT_SETTING_ALLOW)
638 radio_group.default_item = RPH_ALLOW;
639 else if (setting == CONTENT_SETTING_BLOCK)
640 radio_group.default_item = RPH_BLOCK;
641 else
642 radio_group.default_item = RPH_IGNORE;
643
644 selected_item_ = radio_group.default_item;
645 set_radio_group_enabled(true);
646 set_radio_group(radio_group);
647 }
648
649 void ContentSettingRPHBubbleModel::OnCustomLinkClicked() {
650 RegisterProtocolHandler();
651 }
652
653 void ContentSettingRPHBubbleModel::OnRadioClicked(int radio_index) {
654 if (selected_item_ == radio_index)
655 return;
656
657 selected_item_ = radio_index;
658
659 if (radio_index == RPH_ALLOW)
660 RegisterProtocolHandler();
661 else if (radio_index == RPH_BLOCK)
662 UnregisterProtocolHandler();
663 else if (radio_index == RPH_IGNORE)
664 IgnoreProtocolHandler();
Bernhard Bauer 2012/06/26 20:17:49 Could you add an `else NOTREACHED()`?
Peter Kasting 2012/06/26 20:28:52 Urgh, I hate those :/
Greg Billock 2012/06/26 20:31:41 Done.
Bernhard Bauer 2012/06/26 21:06:28 Could you explain why? The problem is that we're n
Peter Kasting 2012/06/26 21:31:56 It's fine in this instance. Never mind my comment
665 }
666
667 void ContentSettingRPHBubbleModel::RegisterProtocolHandler() {
668 // A no-op if the handler hasn't been ignored, but needed in case the user
669 // selects sequences like register/ignore/register.
670 profile()->GetProtocolHandlerRegistry()->RemoveIgnoredHandler(
671 pending_handler_);
672
673 profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler(
674 pending_handler_);
675 tab_contents()->content_settings()->set_pending_protocol_handler_setting(
676 CONTENT_SETTING_ALLOW);
677 }
678
679 void ContentSettingRPHBubbleModel::UnregisterProtocolHandler() {
680 profile()->GetProtocolHandlerRegistry()->OnDenyRegisterProtocolHandler(
681 pending_handler_);
682 tab_contents()->content_settings()->set_pending_protocol_handler_setting(
683 CONTENT_SETTING_BLOCK);
684 ClearOrSetPreviousHandler();
685 }
686
687 void ContentSettingRPHBubbleModel::IgnoreProtocolHandler() {
688 profile()->GetProtocolHandlerRegistry()->OnIgnoreRegisterProtocolHandler(
689 pending_handler_);
690 tab_contents()->content_settings()->set_pending_protocol_handler_setting(
691 CONTENT_SETTING_DEFAULT);
692 ClearOrSetPreviousHandler();
693 }
694
695 void ContentSettingRPHBubbleModel::ClearOrSetPreviousHandler() {
696 if (previous_handler_.IsEmpty()) {
697 profile()->GetProtocolHandlerRegistry()->ClearDefault(
698 pending_handler_.protocol());
699 } else {
700 profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler(
701 previous_handler_);
702 }
703 }
542 704
543 // static 705 // static
544 ContentSettingBubbleModel* 706 ContentSettingBubbleModel*
545 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 707 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
546 Delegate* delegate, 708 Delegate* delegate,
547 TabContents* tab_contents, 709 TabContents* tab_contents,
548 Profile* profile, 710 Profile* profile,
549 ContentSettingsType content_type) { 711 ContentSettingsType content_type) {
550 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { 712 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) {
551 return new ContentSettingCookiesBubbleModel(delegate, tab_contents, profile, 713 return new ContentSettingCookiesBubbleModel(delegate, tab_contents, profile,
552 content_type); 714 content_type);
553 } 715 }
554 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { 716 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) {
555 return new ContentSettingPopupBubbleModel(delegate, tab_contents, profile, 717 return new ContentSettingPopupBubbleModel(delegate, tab_contents, profile,
556 content_type); 718 content_type);
557 } 719 }
558 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { 720 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
559 return new ContentSettingDomainListBubbleModel(delegate, tab_contents, 721 return new ContentSettingDomainListBubbleModel(delegate, tab_contents,
560 profile, content_type); 722 profile, content_type);
561 } 723 }
562 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { 724 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) {
563 return new ContentSettingPluginBubbleModel(delegate, tab_contents, profile, 725 return new ContentSettingPluginBubbleModel(delegate, tab_contents, profile,
564 content_type); 726 content_type);
565 } 727 }
566 if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { 728 if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) {
567 return new ContentSettingMixedScriptBubbleModel(delegate, tab_contents, 729 return new ContentSettingMixedScriptBubbleModel(delegate, tab_contents,
568 profile, content_type); 730 profile, content_type);
569 } 731 }
732 if (content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) {
733 return new ContentSettingRPHBubbleModel(delegate, tab_contents, profile,
734 content_type);
735 }
570 return new ContentSettingSingleRadioGroup(delegate, tab_contents, profile, 736 return new ContentSettingSingleRadioGroup(delegate, tab_contents, profile,
571 content_type); 737 content_type);
572 } 738 }
573 739
574 ContentSettingBubbleModel::ContentSettingBubbleModel( 740 ContentSettingBubbleModel::ContentSettingBubbleModel(
575 TabContents* tab_contents, 741 TabContents* tab_contents,
576 Profile* profile, 742 Profile* profile,
577 ContentSettingsType content_type) 743 ContentSettingsType content_type)
578 : tab_contents_(tab_contents), 744 : tab_contents_(tab_contents),
579 profile_(profile), 745 profile_(profile),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 const content::NotificationDetails& details) { 780 const content::NotificationDetails& details) {
615 if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) { 781 if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) {
616 DCHECK_EQ(tab_contents_, content::Source<TabContents>(source).ptr()); 782 DCHECK_EQ(tab_contents_, content::Source<TabContents>(source).ptr());
617 tab_contents_ = NULL; 783 tab_contents_ = NULL;
618 } else { 784 } else {
619 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); 785 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type);
620 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); 786 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr());
621 profile_ = NULL; 787 profile_ = NULL;
622 } 788 }
623 } 789 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698