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 f7006a56ae0d1c154aff9ab6edb4e2530cebcda5..a5780a10f9ec1e87f75020628ac94afbd1a085ac 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" |
| @@ -125,6 +126,8 @@ class ContentSettingTitleAndLinkModel : public ContentSettingBubbleModel { |
| {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK}, |
| {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK}, |
| {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK}, |
| + {CONTENT_SETTINGS_TYPE_REGISTER_PROTOCOL_HANDLER, |
| + IDS_HANDLERS_BUBBLE_MANAGE_LINK} |
| }; |
| set_manage_link(l10n_util::GetStringUTF8( |
| GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); |
| @@ -510,6 +513,110 @@ class ContentSettingDomainListBubbleModel |
| } |
| }; |
| +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); |
| + 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_); |
| + } |
| + |
| + void UnregisterProtocolHandler() { |
| + profile()->GetProtocolHandlerRegistry()->OnDenyRegisterProtocolHandler( |
| + pending_handler_); |
| + if (!previous_handler_.IsEmpty()) { |
|
koz (OOO until 15th September)
2012/06/21 23:03:50
There's still a subtle bug here. If the user click
Greg Billock
2012/06/21 23:10:59
I found this as well. Also added a tracker to make
|
| + profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler( |
| + previous_handler_); |
| + } |
| + } |
| + |
| + void IgnoreProtocolHandler() { |
| + profile()->GetProtocolHandlerRegistry()->OnIgnoreRegisterProtocolHandler( |
| + pending_handler_); |
| + } |
| + |
| + private: |
| + int selected_item_; |
| + ProtocolHandler pending_handler_; |
| + ProtocolHandler previous_handler_; |
| +}; |
| + |
| + |
| // static |
| ContentSettingBubbleModel* |
| ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| @@ -533,6 +640,10 @@ ContentSettingBubbleModel* |
| return new ContentSettingPluginBubbleModel(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); |
| } |