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..29cf5991211dadce1e7936e184518410076eb9e6 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} |
|
Bernhard Bauer
2012/06/25 16:52:20
Nit: Indent three more spaces?
Peter Kasting
2012/06/25 23:55:30
I'd do two more.
Greg Billock
2012/06/26 19:17:04
Done.
|
| }; |
| set_manage_link(l10n_util::GetStringUTF8( |
| GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); |
| @@ -540,6 +543,141 @@ class ContentSettingMixedScriptBubbleModel |
| } |
| }; |
| +class ContentSettingRPHBubbleModel : public ContentSettingTitleAndLinkModel { |
| + public: |
| + ContentSettingRPHBubbleModel(Delegate* delegate, |
|
Peter Kasting
2012/06/25 23:55:30
Nit: For consistency, people should de-inline clas
Greg Billock
2012/06/26 19:17:04
Fixed up me and one neighbor. :-)
On 2012/06/25 2
|
| + 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") { |
|
Peter Kasting
2012/06/25 23:55:30
Nit: For clarity I'd make this "else if" and put t
Greg Billock
2012/06/26 19:17:04
Done.
|
| + 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 = RPH_ALLOW; |
| + if (setting == CONTENT_SETTING_BLOCK) |
|
Bernhard Bauer
2012/06/25 16:52:20
Nit: else if?
Peter Kasting
2012/06/25 23:55:30
Not just a nit -- all "allow"s will get set to RPH
Greg Billock
2012/06/26 19:17:04
Done.
|
| + radio_group.default_item = RPH_BLOCK; |
| + else |
| + radio_group.default_item = RPH_IGNORE; |
| + 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 == RPH_ALLOW) { |
|
Bernhard Bauer
2012/06/25 16:52:20
You can either leave out the braces or leave them
Greg Billock
2012/06/26 19:17:04
Done.
|
| + RegisterProtocolHandler(); |
| + } else if (radio_index == RPH_BLOCK) { |
| + UnregisterProtocolHandler(); |
| + } else if (radio_index == RPH_IGNORE) { |
| + IgnoreProtocolHandler(); |
| + } |
| + } |
| + } |
| + |
| + void RegisterProtocolHandler() { |
| + // A no-op if the handler hasn't been ignored, but needed in case the user |
| + // selects sequences like register/ignore/register. |
| + profile()->GetProtocolHandlerRegistry()->RemoveIgnoredHandler( |
| + pending_handler_); |
| + |
| + 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); |
| + ClearOrSetPreviousHandler(); |
| + } |
| + |
| + void IgnoreProtocolHandler() { |
| + profile()->GetProtocolHandlerRegistry()->OnIgnoreRegisterProtocolHandler( |
| + pending_handler_); |
| + tab_contents()->content_settings()->SetPendingProtocolHandlerSetting( |
| + CONTENT_SETTING_DEFAULT); |
| + ClearOrSetPreviousHandler(); |
| + } |
| + |
| + void ClearOrSetPreviousHandler() { |
| + if (previous_handler_.IsEmpty()) { |
| + profile()->GetProtocolHandlerRegistry()->ClearDefault( |
| + pending_handler_.protocol()); |
| + } else { |
| + profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler( |
| + previous_handler_); |
| + } |
| + } |
| + |
| + private: |
| + enum RPHState { |
| + RPH_ALLOW = 0, |
| + RPH_BLOCK, |
| + RPH_IGNORE, |
| + }; |
| + |
| + int selected_item_; |
| + ProtocolHandler pending_handler_; |
| + ProtocolHandler previous_handler_; |
| +}; |
| + |
| // static |
| ContentSettingBubbleModel* |
| ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| @@ -567,6 +705,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); |
| } |