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 8154cb2a5df90a083944b0263fa001ccc6e4467c..8f09213e8970596bfe7e2d96b9368af3073204b7 100644 |
| --- a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc |
| +++ b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc |
| @@ -36,6 +36,7 @@ |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/browser/web_contents_delegate.h" |
| #include "grit/components_strings.h" |
| +#include "grit/theme_resources.h" |
| #include "net/base/net_util.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/resource/resource_bundle.h" |
| @@ -114,11 +115,6 @@ void ContentSettingTitleAndLinkModel::SetTitle() { |
| TabSpecificContentSettings::FromWebContents(web_contents()); |
| } |
| - if (content_type() == CONTENT_SETTINGS_TYPE_PLUGINS && content_settings && |
| - content_settings->IsContentBlocked(content_type())) { |
| - set_plugin_names(content_settings->GetBlockedPluginNames()); |
| - } |
| - |
| static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = { |
| {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE}, |
| {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE}, |
| @@ -425,8 +421,7 @@ class ContentSettingCookiesBubbleModel : public ContentSettingSingleRadioGroup { |
| public: |
| ContentSettingCookiesBubbleModel(Delegate* delegate, |
| WebContents* web_contents, |
| - Profile* profile, |
| - ContentSettingsType content_type); |
| + Profile* profile); |
| ~ContentSettingCookiesBubbleModel() override; |
| @@ -437,11 +432,11 @@ class ContentSettingCookiesBubbleModel : public ContentSettingSingleRadioGroup { |
| ContentSettingCookiesBubbleModel::ContentSettingCookiesBubbleModel( |
| Delegate* delegate, |
| WebContents* web_contents, |
| - Profile* profile, |
| - ContentSettingsType content_type) |
| - : ContentSettingSingleRadioGroup( |
| - delegate, web_contents, profile, content_type) { |
| - DCHECK_EQ(CONTENT_SETTINGS_TYPE_COOKIES, content_type); |
| + Profile* profile) |
| + : ContentSettingSingleRadioGroup(delegate, |
|
msw
2015/03/21 00:25:19
nit: un-wrap "delegate, web_contents, profile," he
meacer
2015/03/23 18:19:40
Did you mean the formatting? This is the |git cl f
|
| + web_contents, |
| + profile, |
| + CONTENT_SETTINGS_TYPE_COOKIES) { |
| set_custom_link_enabled(true); |
| } |
| @@ -465,27 +460,27 @@ void ContentSettingCookiesBubbleModel::OnCustomLinkClicked() { |
| delegate()->ShowCollectedCookiesDialog(web_contents()); |
| } |
| -class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup { |
| +class PluginBubbleModel : public ContentSettingSingleRadioGroup { |
| public: |
| - ContentSettingPluginBubbleModel(Delegate* delegate, |
| - WebContents* web_contents, |
| - Profile* profile, |
| - ContentSettingsType content_type); |
| + PluginBubbleModel(Delegate* delegate, |
| + WebContents* web_contents, |
| + Profile* profile); |
| - ~ContentSettingPluginBubbleModel() override; |
| + ~PluginBubbleModel() override; |
| private: |
| void OnCustomLinkClicked() override; |
| + |
| + void SetListItems(); |
| }; |
| -ContentSettingPluginBubbleModel::ContentSettingPluginBubbleModel( |
| - Delegate* delegate, |
| - WebContents* web_contents, |
| - Profile* profile, |
| - ContentSettingsType content_type) |
| - : ContentSettingSingleRadioGroup( |
| - delegate, web_contents, profile, content_type) { |
| - DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS); |
| +PluginBubbleModel::PluginBubbleModel(Delegate* delegate, |
| + WebContents* web_contents, |
| + Profile* profile) |
| + : ContentSettingSingleRadioGroup(delegate, |
| + web_contents, |
| + profile, |
| + CONTENT_SETTINGS_TYPE_PLUGINS) { |
| // Disable the "Run all plugins this time" link if the setting is managed and |
| // can't be controlled by the user or if the user already clicked on the link |
| // and ran all plugins. |
| @@ -493,9 +488,10 @@ ContentSettingPluginBubbleModel::ContentSettingPluginBubbleModel( |
| web_contents && |
| TabSpecificContentSettings::FromWebContents( |
| web_contents)->load_plugins_link_enabled()); |
| + SetListItems(); |
|
msw
2015/03/21 00:25:19
nit: inline this?
meacer
2015/03/23 18:19:40
Done.
|
| } |
| -ContentSettingPluginBubbleModel::~ContentSettingPluginBubbleModel() { |
| +PluginBubbleModel::~PluginBubbleModel() { |
| if (settings_changed()) { |
| // If the user elected to allow all plugins then run plugins at this time. |
| if (selected_item() == kAllowButtonIndex) |
| @@ -503,7 +499,25 @@ ContentSettingPluginBubbleModel::~ContentSettingPluginBubbleModel() { |
| } |
| } |
| -void ContentSettingPluginBubbleModel::OnCustomLinkClicked() { |
| +void PluginBubbleModel::SetListItems() { |
| + if (!web_contents()) |
| + return; |
| + TabSpecificContentSettings* content_settings = |
| + TabSpecificContentSettings::FromWebContents(web_contents()); |
| + |
| + const std::vector<base::string16>& blocked_plugins = |
| + content_settings->blocked_plugin_names(); |
| + for (auto iter = blocked_plugins.begin(); iter != blocked_plugins.end(); |
| + ++iter) { |
| + // TODO(meacer): Link to chrome://plugins#plugin_id from here. |
| + ListItem plugin_item(ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| + IDR_BLOCKED_PLUGINS), |
| + base::UTF16ToUTF8(*iter), false, 0); |
| + add_list_item(plugin_item); |
| + } |
| +} |
| + |
| +void PluginBubbleModel::OnCustomLinkClicked() { |
| content::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble")); |
| // Web contents can be NULL if the tab was closed while the plugins |
| // settings bubble is visible. |
| @@ -519,54 +533,54 @@ void ContentSettingPluginBubbleModel::OnCustomLinkClicked() { |
| set_load_plugins_link_enabled(false); |
| } |
| -class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup { |
| +class PopupBubbleModel : public ContentSettingSingleRadioGroup { |
| public: |
| - ContentSettingPopupBubbleModel(Delegate* delegate, |
| - WebContents* web_contents, |
| - Profile* profile, |
| - ContentSettingsType content_type); |
| - ~ContentSettingPopupBubbleModel() override {} |
| + PopupBubbleModel(Delegate* delegate, |
| + WebContents* web_contents, |
| + Profile* profile); |
| + ~PopupBubbleModel() override {} |
| private: |
| - void SetPopups(); |
| - void OnPopupClicked(int index) override; |
| + void OnListItemClicked(int index) override; |
| + |
| + void SetListItems(); |
| + |
| + int32 item_id_from_item_index(int index) const { |
| + return bubble_content().list_items[index].item_id; |
| + } |
| }; |
| -ContentSettingPopupBubbleModel::ContentSettingPopupBubbleModel( |
| - Delegate* delegate, |
| - WebContents* web_contents, |
| - Profile* profile, |
| - ContentSettingsType content_type) |
| - : ContentSettingSingleRadioGroup( |
| - delegate, web_contents, profile, content_type) { |
| - SetPopups(); |
| +PopupBubbleModel::PopupBubbleModel(Delegate* delegate, |
| + WebContents* web_contents, |
| + Profile* profile) |
| + : ContentSettingSingleRadioGroup(delegate, |
| + web_contents, |
| + profile, |
| + CONTENT_SETTINGS_TYPE_POPUPS) { |
| + SetListItems(); |
| } |
| - |
| -void ContentSettingPopupBubbleModel::SetPopups() { |
| +void PopupBubbleModel::SetListItems() { |
|
msw
2015/03/21 00:25:19
ditto nit: inline this?
meacer
2015/03/23 18:19:40
Done.
|
| std::map<int32, GURL> blocked_popups = |
| PopupBlockerTabHelper::FromWebContents(web_contents()) |
| ->GetBlockedPopupRequests(); |
| - for (std::map<int32, GURL>::const_iterator iter = blocked_popups.begin(); |
| - iter != blocked_popups.end(); |
| + for (auto iter = blocked_popups.begin(); iter != blocked_popups.end(); |
| ++iter) { |
| std::string title(iter->second.spec()); |
| // The popup may not have a valid URL. |
| if (title.empty()) |
| title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE); |
| - PopupItem popup_item( |
| - ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| - IDR_DEFAULT_FAVICON), |
| - title, |
| - iter->first); |
| - add_popup(popup_item); |
| + ListItem popup_item(ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| + IDR_DEFAULT_FAVICON), |
| + title, true, iter->first); |
| + add_list_item(popup_item); |
| } |
| } |
| -void ContentSettingPopupBubbleModel::OnPopupClicked(int index) { |
| +void PopupBubbleModel::OnListItemClicked(int index) { |
| if (web_contents()) { |
| - PopupBlockerTabHelper::FromWebContents(web_contents())-> |
| - ShowBlockedPopup(bubble_content().popup_items[index].popup_id); |
| + PopupBlockerTabHelper::FromWebContents(web_contents()) |
| + ->ShowBlockedPopup(item_id_from_item_index(index)); |
| } |
| } |
| @@ -968,8 +982,7 @@ class ContentSettingMixedScriptBubbleModel |
| public: |
| ContentSettingMixedScriptBubbleModel(Delegate* delegate, |
| WebContents* web_contents, |
| - Profile* profile, |
| - ContentSettingsType content_type); |
| + Profile* profile); |
| ~ContentSettingMixedScriptBubbleModel() override {} |
| @@ -980,11 +993,11 @@ class ContentSettingMixedScriptBubbleModel |
| ContentSettingMixedScriptBubbleModel::ContentSettingMixedScriptBubbleModel( |
| Delegate* delegate, |
| WebContents* web_contents, |
| - Profile* profile, |
| - ContentSettingsType content_type) |
| - : ContentSettingTitleLinkAndCustomModel( |
| - delegate, web_contents, profile, content_type) { |
| - DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_MIXEDSCRIPT); |
| + Profile* profile) |
| + : ContentSettingTitleLinkAndCustomModel(delegate, |
| + web_contents, |
| + profile, |
| + CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { |
| content_settings::RecordMixedScriptAction( |
| content_settings::MIXED_SCRIPT_ACTION_DISPLAYED_BUBBLE); |
| set_custom_link_enabled(true); |
| @@ -1004,16 +1017,15 @@ ContentSettingRPHBubbleModel::ContentSettingRPHBubbleModel( |
| Delegate* delegate, |
| WebContents* web_contents, |
| Profile* profile, |
| - ProtocolHandlerRegistry* registry, |
| - ContentSettingsType content_type) |
| - : ContentSettingTitleAndLinkModel( |
| - delegate, web_contents, profile, content_type), |
| + ProtocolHandlerRegistry* registry) |
| + : ContentSettingTitleAndLinkModel(delegate, |
| + web_contents, |
| + profile, |
| + CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS), |
| selected_item_(0), |
| registry_(registry), |
| pending_handler_(ProtocolHandler::EmptyProtocolHandler()), |
| previous_handler_(ProtocolHandler::EmptyProtocolHandler()) { |
| - DCHECK_EQ(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, content_type); |
| - |
| TabSpecificContentSettings* content_settings = |
| TabSpecificContentSettings::FromWebContents(web_contents); |
| pending_handler_ = content_settings->pending_protocol_handler(); |
| @@ -1136,8 +1148,7 @@ class ContentSettingMidiSysExBubbleModel |
| public: |
| ContentSettingMidiSysExBubbleModel(Delegate* delegate, |
| WebContents* web_contents, |
| - Profile* profile, |
| - ContentSettingsType content_type); |
| + Profile* profile); |
| ~ContentSettingMidiSysExBubbleModel() override {} |
| private: |
| @@ -1149,11 +1160,11 @@ class ContentSettingMidiSysExBubbleModel |
| ContentSettingMidiSysExBubbleModel::ContentSettingMidiSysExBubbleModel( |
| Delegate* delegate, |
| WebContents* web_contents, |
| - Profile* profile, |
| - ContentSettingsType content_type) |
| - : ContentSettingTitleAndLinkModel( |
| - delegate, web_contents, profile, content_type) { |
| - DCHECK_EQ(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, content_type); |
| + Profile* profile) |
| + : ContentSettingTitleAndLinkModel(delegate, |
| + web_contents, |
| + profile, |
| + CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { |
| SetDomainsAndCustomLink(); |
| } |
| @@ -1226,12 +1237,11 @@ ContentSettingBubbleModel* |
| Profile* profile, |
| ContentSettingsType content_type) { |
| if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { |
| - return new ContentSettingCookiesBubbleModel(delegate, web_contents, profile, |
| - content_type); |
| + return new ContentSettingCookiesBubbleModel(delegate, web_contents, |
| + profile); |
| } |
| if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { |
| - return new ContentSettingPopupBubbleModel(delegate, web_contents, profile, |
| - content_type); |
| + return new PopupBubbleModel(delegate, web_contents, profile); |
| } |
| if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
| return new ContentSettingDomainListBubbleModel(delegate, web_contents, |
| @@ -1242,22 +1252,21 @@ ContentSettingBubbleModel* |
| profile); |
| } |
| if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { |
| - return new ContentSettingPluginBubbleModel(delegate, web_contents, profile, |
| - content_type); |
| + return new PluginBubbleModel(delegate, web_contents, profile); |
| } |
| if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { |
| return new ContentSettingMixedScriptBubbleModel(delegate, web_contents, |
| - profile, content_type); |
| + profile); |
| } |
| if (content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { |
| ProtocolHandlerRegistry* registry = |
| ProtocolHandlerRegistryFactory::GetForBrowserContext(profile); |
| return new ContentSettingRPHBubbleModel(delegate, web_contents, profile, |
| - registry, content_type); |
| + registry); |
| } |
| if (content_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { |
| return new ContentSettingMidiSysExBubbleModel(delegate, web_contents, |
| - profile, content_type); |
| + profile); |
| } |
| return new ContentSettingSingleRadioGroup(delegate, web_contents, profile, |
| content_type); |