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

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: Merge to head. Created 8 years, 6 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_REGISTER_PROTOCOL_HANDLER,
133 IDS_HANDLERS_BUBBLE_MANAGE_LINK}
131 }; 134 };
132 set_manage_link(l10n_util::GetStringUTF8( 135 set_manage_link(l10n_util::GetStringUTF8(
133 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); 136 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type())));
134 } 137 }
135 138
136 virtual void OnManageLinkClicked() { 139 virtual void OnManageLinkClicked() {
137 if (delegate_) 140 if (delegate_)
138 delegate_->ShowContentSettingsPage(content_type()); 141 delegate_->ShowContentSettingsPage(content_type());
139 } 142 }
140 143
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 virtual void OnCustomLinkClicked() OVERRIDE { 536 virtual void OnCustomLinkClicked() OVERRIDE {
534 content::RecordAction(UserMetricsAction("MixedScript_LoadAnyway_Bubble")); 537 content::RecordAction(UserMetricsAction("MixedScript_LoadAnyway_Bubble"));
535 DCHECK(tab_contents()); 538 DCHECK(tab_contents());
536 content::RenderViewHost* host = 539 content::RenderViewHost* host =
537 tab_contents()->web_contents()->GetRenderViewHost(); 540 tab_contents()->web_contents()->GetRenderViewHost();
538 host->Send(new ChromeViewMsg_SetAllowRunningInsecureContent( 541 host->Send(new ChromeViewMsg_SetAllowRunningInsecureContent(
539 host->GetRoutingID(), true)); 542 host->GetRoutingID(), true));
540 } 543 }
541 }; 544 };
542 545
546 class ContentSettingRPHBubbleModel : public ContentSettingTitleAndLinkModel {
547 public:
548 ContentSettingRPHBubbleModel(Delegate* delegate,
549 TabContents* tab_contents,
550 Profile* profile,
551 ContentSettingsType content_type)
552 : ContentSettingTitleAndLinkModel(
553 delegate, tab_contents, profile, content_type),
554 selected_item_(0),
555 pending_handler_(ProtocolHandler::EmptyProtocolHandler()),
556 previous_handler_(ProtocolHandler::EmptyProtocolHandler()) {
557 DCHECK_EQ(CONTENT_SETTINGS_TYPE_REGISTER_PROTOCOL_HANDLER, content_type);
558
559 TabSpecificContentSettings* content_settings =
560 tab_contents->content_settings();
561 pending_handler_ = content_settings->GetPendingProtocolHandler();
562 previous_handler_ = content_settings->GetPreviousProtocolHandler();
563
564 string16 protocol = UTF8ToUTF16(pending_handler_.protocol());
565 if (pending_handler_.protocol() == "mailto") {
566 protocol = l10n_util::GetStringUTF16(
567 IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME);
568 }
569 if (pending_handler_.protocol() == "webcal") {
570 protocol = l10n_util::GetStringUTF16(
571 IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME);
572 }
573 if (previous_handler_.IsEmpty()) {
574 set_title(l10n_util::GetStringFUTF8(
575 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM,
576 pending_handler_.title(), UTF8ToUTF16(pending_handler_.url().host()),
577 protocol));
578 } else {
579 set_title(l10n_util::GetStringFUTF8(
580 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE,
581 pending_handler_.title(), UTF8ToUTF16(pending_handler_.url().host()),
582 protocol, previous_handler_.title()));
583 }
584
585 std::string radio_allow_label =
586 l10n_util::GetStringFUTF8(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT,
587 pending_handler_.title());
588 std::string radio_deny_label =
589 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_DENY);
590 std::string radio_ignore_label =
591 l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_IGNORE);
592
593 GURL url = tab_contents->web_contents()->GetURL();
594 RadioGroup radio_group;
595 radio_group.url = url;
596
597 radio_group.radio_items.push_back(radio_allow_label);
598 radio_group.radio_items.push_back(radio_deny_label);
599 radio_group.radio_items.push_back(radio_ignore_label);
600 ContentSetting setting =
601 content_settings->GetPendingProtocolHandlerSetting();
602 if (setting == CONTENT_SETTING_ALLOW)
603 radio_group.default_item = 0;
koz (OOO until 15th September) 2012/06/22 00:41:14 Lift these into constants?
Greg Billock 2012/06/22 19:45:40 Done.
604 if (setting == CONTENT_SETTING_BLOCK)
605 radio_group.default_item = 1;
606 else
607 radio_group.default_item = 2;
608 selected_item_ = radio_group.default_item;
609 set_radio_group_enabled(true);
610 set_radio_group(radio_group);
611 }
612
613 virtual void OnCustomLinkClicked() {
614 RegisterProtocolHandler();
615 }
616
617 virtual void OnRadioClicked(int radio_index) {
618 if (selected_item_ != radio_index) {
619 selected_item_ = radio_index;
620
621 if (radio_index == 0) {
622 RegisterProtocolHandler();
623 } else if (radio_index == 1) {
624 UnregisterProtocolHandler();
625 } else if (radio_index == 2) {
626 IgnoreProtocolHandler();
627 }
628 }
629 }
630
631 void RegisterProtocolHandler() {
632 profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler(
633 pending_handler_);
634 tab_contents()->content_settings()->SetPendingProtocolHandlerSetting(
635 CONTENT_SETTING_ALLOW);
636 }
637
638 void UnregisterProtocolHandler() {
639 profile()->GetProtocolHandlerRegistry()->OnDenyRegisterProtocolHandler(
640 pending_handler_);
641 tab_contents()->content_settings()->SetPendingProtocolHandlerSetting(
642 CONTENT_SETTING_BLOCK);
643 if (!previous_handler_.IsEmpty()) {
koz (OOO until 15th September) 2012/06/22 00:41:14 nit: swap the if and the else clause here (same wi
Greg Billock 2012/06/22 19:45:40 Done.
644 profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler(
645 previous_handler_);
646 } else {
647 profile()->GetProtocolHandlerRegistry()->ClearDefault(
648 pending_handler_.protocol());
649 }
650 }
651
652 void IgnoreProtocolHandler() {
653 profile()->GetProtocolHandlerRegistry()->OnIgnoreRegisterProtocolHandler(
koz (OOO until 15th September) 2012/06/22 00:41:14 If the user clicks "ignore" and then "add" that wi
Greg Billock 2012/06/22 19:45:40 Fixed this up and augmented the test.
654 pending_handler_);
655 tab_contents()->content_settings()->SetPendingProtocolHandlerSetting(
656 CONTENT_SETTING_DEFAULT);
657 if (!previous_handler_.IsEmpty()) {
658 profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler(
659 previous_handler_);
660 } else {
661 profile()->GetProtocolHandlerRegistry()->ClearDefault(
662 pending_handler_.protocol());
663 }
664 }
665
666 private:
667 int selected_item_;
668 ProtocolHandler pending_handler_;
669 ProtocolHandler previous_handler_;
670 };
671
543 // static 672 // static
544 ContentSettingBubbleModel* 673 ContentSettingBubbleModel*
545 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 674 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
546 Delegate* delegate, 675 Delegate* delegate,
547 TabContents* tab_contents, 676 TabContents* tab_contents,
548 Profile* profile, 677 Profile* profile,
549 ContentSettingsType content_type) { 678 ContentSettingsType content_type) {
550 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { 679 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) {
551 return new ContentSettingCookiesBubbleModel(delegate, tab_contents, profile, 680 return new ContentSettingCookiesBubbleModel(delegate, tab_contents, profile,
552 content_type); 681 content_type);
553 } 682 }
554 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { 683 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) {
555 return new ContentSettingPopupBubbleModel(delegate, tab_contents, profile, 684 return new ContentSettingPopupBubbleModel(delegate, tab_contents, profile,
556 content_type); 685 content_type);
557 } 686 }
558 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { 687 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
559 return new ContentSettingDomainListBubbleModel(delegate, tab_contents, 688 return new ContentSettingDomainListBubbleModel(delegate, tab_contents,
560 profile, content_type); 689 profile, content_type);
561 } 690 }
562 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { 691 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) {
563 return new ContentSettingPluginBubbleModel(delegate, tab_contents, profile, 692 return new ContentSettingPluginBubbleModel(delegate, tab_contents, profile,
564 content_type); 693 content_type);
565 } 694 }
566 if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { 695 if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) {
567 return new ContentSettingMixedScriptBubbleModel(delegate, tab_contents, 696 return new ContentSettingMixedScriptBubbleModel(delegate, tab_contents,
568 profile, content_type); 697 profile, content_type);
569 } 698 }
699 if (content_type == CONTENT_SETTINGS_TYPE_REGISTER_PROTOCOL_HANDLER) {
700 return new ContentSettingRPHBubbleModel(delegate, tab_contents, profile,
701 content_type);
702 }
570 return new ContentSettingSingleRadioGroup(delegate, tab_contents, profile, 703 return new ContentSettingSingleRadioGroup(delegate, tab_contents, profile,
571 content_type); 704 content_type);
572 } 705 }
573 706
574 ContentSettingBubbleModel::ContentSettingBubbleModel( 707 ContentSettingBubbleModel::ContentSettingBubbleModel(
575 TabContents* tab_contents, 708 TabContents* tab_contents,
576 Profile* profile, 709 Profile* profile,
577 ContentSettingsType content_type) 710 ContentSettingsType content_type)
578 : tab_contents_(tab_contents), 711 : tab_contents_(tab_contents),
579 profile_(profile), 712 profile_(profile),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 const content::NotificationDetails& details) { 747 const content::NotificationDetails& details) {
615 if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) { 748 if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) {
616 DCHECK_EQ(tab_contents_, content::Source<TabContents>(source).ptr()); 749 DCHECK_EQ(tab_contents_, content::Source<TabContents>(source).ptr());
617 tab_contents_ = NULL; 750 tab_contents_ = NULL;
618 } else { 751 } else {
619 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); 752 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type);
620 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); 753 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr());
621 profile_ = NULL; 754 profile_ = NULL;
622 } 755 }
623 } 756 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698