Chromium Code Reviews| Index: chrome/browser/ui/content_settings/content_setting_bubble_model.cc |
| diff --git a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc |
| index d06e2f0b466ad0fe43679b7f1f656fb4fa972a15..6bed9b11abc9435324f58e0726038c7c642883b9 100644 |
| --- a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc |
| +++ b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc |
| @@ -8,6 +8,7 @@ |
| #include "chrome/browser/content_settings/content_settings_utils.h" |
| #include "chrome/browser/content_settings/cookie_settings.h" |
| #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| +#include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| #include "chrome/browser/favicon/favicon_tab_helper.h" |
| #include "chrome/browser/infobars/infobar_tab_helper.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| @@ -128,6 +129,8 @@ class ContentSettingTitleAndLinkModel : public ContentSettingBubbleModel { |
| {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK}, |
| {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK}, |
| {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_LEARN_MORE}, |
| + {CONTENT_SETTINGS_TYPE_REGISTER_PROTOCOL_HANDLER, |
| + IDS_HANDLERS_BUBBLE_MANAGE_LINK} |
| }; |
| set_manage_link(l10n_util::GetStringUTF8( |
| GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); |
| @@ -540,6 +543,132 @@ class ContentSettingMixedScriptBubbleModel |
| } |
| }; |
| +class ContentSettingRPHBubbleModel : public ContentSettingTitleAndLinkModel { |
| + public: |
| + ContentSettingRPHBubbleModel(Delegate* delegate, |
| + TabContents* tab_contents, |
| + Profile* profile, |
| + ContentSettingsType content_type) |
| + : ContentSettingTitleAndLinkModel( |
| + delegate, tab_contents, profile, content_type), |
| + selected_item_(0), |
| + pending_handler_(ProtocolHandler::EmptyProtocolHandler()), |
| + previous_handler_(ProtocolHandler::EmptyProtocolHandler()) { |
| + DCHECK_EQ(CONTENT_SETTINGS_TYPE_REGISTER_PROTOCOL_HANDLER, content_type); |
| + |
| + TabSpecificContentSettings* content_settings = |
| + tab_contents->content_settings(); |
| + pending_handler_ = content_settings->GetPendingProtocolHandler(); |
| + previous_handler_ = content_settings->GetPreviousProtocolHandler(); |
| + |
| + string16 protocol = UTF8ToUTF16(pending_handler_.protocol()); |
| + if (pending_handler_.protocol() == "mailto") { |
| + protocol = l10n_util::GetStringUTF16( |
| + IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME); |
| + } |
| + if (pending_handler_.protocol() == "webcal") { |
| + protocol = l10n_util::GetStringUTF16( |
| + IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME); |
| + } |
| + if (previous_handler_.IsEmpty()) { |
| + set_title(l10n_util::GetStringFUTF8( |
| + IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM, |
| + pending_handler_.title(), UTF8ToUTF16(pending_handler_.url().host()), |
| + protocol)); |
| + } else { |
| + set_title(l10n_util::GetStringFUTF8( |
| + IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE, |
| + pending_handler_.title(), UTF8ToUTF16(pending_handler_.url().host()), |
| + protocol, previous_handler_.title())); |
| + } |
| + |
| + std::string radio_allow_label = |
| + l10n_util::GetStringFUTF8(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT, |
| + pending_handler_.title()); |
| + std::string radio_deny_label = |
| + l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_DENY); |
| + std::string radio_ignore_label = |
| + l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_IGNORE); |
| + |
| + GURL url = tab_contents->web_contents()->GetURL(); |
| + RadioGroup radio_group; |
| + radio_group.url = url; |
| + |
| + radio_group.radio_items.push_back(radio_allow_label); |
| + radio_group.radio_items.push_back(radio_deny_label); |
| + radio_group.radio_items.push_back(radio_ignore_label); |
| + ContentSetting setting = |
| + content_settings->GetPendingProtocolHandlerSetting(); |
| + if (setting == CONTENT_SETTING_ALLOW) |
| + 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.
|
| + if (setting == CONTENT_SETTING_BLOCK) |
| + radio_group.default_item = 1; |
| + else |
| + radio_group.default_item = 2; |
| + selected_item_ = radio_group.default_item; |
| + set_radio_group_enabled(true); |
| + set_radio_group(radio_group); |
| + } |
| + |
| + virtual void OnCustomLinkClicked() { |
| + RegisterProtocolHandler(); |
| + } |
| + |
| + virtual void OnRadioClicked(int radio_index) { |
| + if (selected_item_ != radio_index) { |
| + selected_item_ = radio_index; |
| + |
| + if (radio_index == 0) { |
| + RegisterProtocolHandler(); |
| + } else if (radio_index == 1) { |
| + UnregisterProtocolHandler(); |
| + } else if (radio_index == 2) { |
| + IgnoreProtocolHandler(); |
| + } |
| + } |
| + } |
| + |
| + void RegisterProtocolHandler() { |
| + profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler( |
| + pending_handler_); |
| + tab_contents()->content_settings()->SetPendingProtocolHandlerSetting( |
| + CONTENT_SETTING_ALLOW); |
| + } |
| + |
| + void UnregisterProtocolHandler() { |
| + profile()->GetProtocolHandlerRegistry()->OnDenyRegisterProtocolHandler( |
| + pending_handler_); |
| + tab_contents()->content_settings()->SetPendingProtocolHandlerSetting( |
| + CONTENT_SETTING_BLOCK); |
| + 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.
|
| + profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler( |
| + previous_handler_); |
| + } else { |
| + profile()->GetProtocolHandlerRegistry()->ClearDefault( |
| + pending_handler_.protocol()); |
| + } |
| + } |
| + |
| + void IgnoreProtocolHandler() { |
| + 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.
|
| + pending_handler_); |
| + tab_contents()->content_settings()->SetPendingProtocolHandlerSetting( |
| + CONTENT_SETTING_DEFAULT); |
| + if (!previous_handler_.IsEmpty()) { |
| + profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler( |
| + previous_handler_); |
| + } else { |
| + profile()->GetProtocolHandlerRegistry()->ClearDefault( |
| + pending_handler_.protocol()); |
| + } |
| + } |
| + |
| + private: |
| + int selected_item_; |
| + ProtocolHandler pending_handler_; |
| + ProtocolHandler previous_handler_; |
| +}; |
| + |
| // static |
| ContentSettingBubbleModel* |
| ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| @@ -567,6 +696,10 @@ ContentSettingBubbleModel* |
| return new ContentSettingMixedScriptBubbleModel(delegate, tab_contents, |
| profile, content_type); |
| } |
| + if (content_type == CONTENT_SETTINGS_TYPE_REGISTER_PROTOCOL_HANDLER) { |
| + return new ContentSettingRPHBubbleModel(delegate, tab_contents, profile, |
| + content_type); |
| + } |
| return new ContentSettingSingleRadioGroup(delegate, tab_contents, profile, |
| content_type); |
| } |