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 2acc49698b1cf1f11cbe5ec009093b2ccdbdab24..47c47db20852991dd13c8e2dbb270bb40d5e6228 100644 |
| --- a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc |
| +++ b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc |
| @@ -95,6 +95,7 @@ ContentSettingTitleAndLinkModel::ContentSettingTitleAndLinkModel( |
| DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| SetTitle(); |
| SetManageLink(); |
| + SetLearnMoreLink(); |
| } |
| void ContentSettingTitleAndLinkModel::SetTitle() { |
| @@ -156,6 +157,22 @@ void ContentSettingTitleAndLinkModel::OnManageLinkClicked() { |
| delegate_->ShowContentSettingsPage(content_type()); |
| } |
| +void ContentSettingTitleAndLinkModel::SetLearnMoreLink() { |
| + static const ContentSettingsTypeIdEntry kLearnMoreIDs[] = { |
| + {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_LEARN_MORE}, |
| + }; |
| + int learn_more_id = |
| + GetIdForContentType(kLearnMoreIDs, arraysize(kLearnMoreIDs), |
| + content_type()); |
| + if (learn_more_id) |
|
felt
2014/06/12 01:44:33
are there situations in which learn_more_id might
radhikabhar
2014/06/12 16:21:45
DCHECK will crash chrome if we try to click on the
|
| + set_learn_more_link(l10n_util::GetStringUTF8(learn_more_id)); |
| +} |
| + |
| +void ContentSettingTitleAndLinkModel::OnLearnMoreLinkClicked() { |
| + if (delegate_) |
| + delegate_->ShowLearnMorePage(content_type()); |
| +} |
| + |
| class ContentSettingTitleLinkAndCustomModel |
| : public ContentSettingTitleAndLinkModel { |
| public: |
| @@ -183,7 +200,6 @@ ContentSettingTitleLinkAndCustomModel::ContentSettingTitleLinkAndCustomModel( |
| void ContentSettingTitleLinkAndCustomModel::SetCustomLink() { |
| static const ContentSettingsTypeIdEntry kCustomIDs[] = { |
| {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_INFO}, |
| - {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LOAD_ALL}, |
| {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_ALLOW_INSECURE_CONTENT_BUTTON}, |
| }; |
| int custom_link_id = |
| @@ -267,7 +283,6 @@ void ContentSettingSingleRadioGroup::SetRadioGroup() { |
| {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK}, |
| {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_UNBLOCK}, |
| {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_UNBLOCK}, |
| - {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK_ALL}, |
| {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_UNBLOCK}, |
| {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_UNBLOCK}, |
| {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_UNBLOCK}, |
| @@ -299,7 +314,6 @@ void ContentSettingSingleRadioGroup::SetRadioGroup() { |
| {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION}, |
| {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_NO_ACTION}, |
| {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_NO_ACTION}, |
| - {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_NO_ACTION}, |
| {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_NO_ACTION}, |
| {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_NO_ACTION}, |
| {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_NO_ACTION}, |
| @@ -329,7 +343,6 @@ void ContentSettingSingleRadioGroup::SetRadioGroup() { |
| radio_group.radio_items.push_back(radio_block_label); |
| ContentSetting setting; |
| SettingSource setting_source = SETTING_SOURCE_NONE; |
| - bool setting_is_wildcard = false; |
| if (content_type() == CONTENT_SETTINGS_TYPE_COOKIES) { |
| CookieSettings* cookie_settings = |
| @@ -343,19 +356,9 @@ void ContentSettingSingleRadioGroup::SetRadioGroup() { |
| url, url, content_type(), std::string(), &info)); |
| setting = content_settings::ValueToContentSetting(value.get()); |
| setting_source = info.source; |
| - setting_is_wildcard = |
| - info.primary_pattern == ContentSettingsPattern::Wildcard() && |
| - info.secondary_pattern == ContentSettingsPattern::Wildcard(); |
| } |
| - if (content_type() == CONTENT_SETTINGS_TYPE_PLUGINS && |
| - setting == CONTENT_SETTING_ALLOW && |
| - setting_is_wildcard) { |
| - // In the corner case of unrecognized plugins (which are now blocked by |
| - // default) we indicate the blocked state in the UI and allow the user to |
| - // whitelist. |
| - radio_group.default_item = 1; |
| - } else if (setting == CONTENT_SETTING_ALLOW) { |
| + if (setting == CONTENT_SETTING_ALLOW) { |
| radio_group.default_item = kAllowButtonIndex; |
| // |block_setting_| is already set to |CONTENT_SETTING_BLOCK|. |
| } else { |
| @@ -431,7 +434,7 @@ void ContentSettingCookiesBubbleModel::OnCustomLinkClicked() { |
| delegate()->ShowCollectedCookiesDialog(web_contents()); |
| } |
| -class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup { |
| +class ContentSettingPluginBubbleModel : public ContentSettingTitleAndLinkModel { |
| public: |
| ContentSettingPluginBubbleModel(Delegate* delegate, |
| WebContents* web_contents, |
| @@ -441,7 +444,20 @@ class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup { |
| virtual ~ContentSettingPluginBubbleModel(); |
| private: |
| - virtual void OnCustomLinkClicked() OVERRIDE; |
| + void SetRadioGroup(); |
| + |
| + // Cookie bubble implementation. |
| + virtual void OnRadioClicked(int radio_index) OVERRIDE; |
| + |
| + // Function to load plugins. |
| + void OnRunPlugins(); |
| + |
| + bool settings_changed() const; |
| + int selected_item() const { return selected_item_; } |
| + |
| + ContentSetting block_setting_; |
| + int selected_item_; |
| + int kAllowOnceButtonIndex; |
| }; |
| ContentSettingPluginBubbleModel::ContentSettingPluginBubbleModel( |
| @@ -449,27 +465,112 @@ ContentSettingPluginBubbleModel::ContentSettingPluginBubbleModel( |
| WebContents* web_contents, |
| Profile* profile, |
| ContentSettingsType content_type) |
| - : ContentSettingSingleRadioGroup( |
| - delegate, web_contents, profile, content_type) { |
| + : ContentSettingTitleAndLinkModel( |
| + delegate, web_contents, profile, content_type), |
| + block_setting_(CONTENT_SETTING_BLOCK), |
|
felt
2014/06/12 01:44:33
indent lines 470-472 by 2 so that they line up wit
radhikabhar
2014/06/12 16:21:45
Done.
|
| + selected_item_(0), |
| + kAllowOnceButtonIndex(1) { |
| DCHECK_EQ(content_type, 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. |
| - set_custom_link_enabled(!setting_is_managed() && |
| - web_contents && |
| - TabSpecificContentSettings::FromWebContents( |
| - web_contents)->load_plugins_link_enabled()); |
| + SetRadioGroup(); |
| } |
| ContentSettingPluginBubbleModel::~ContentSettingPluginBubbleModel() { |
| + // If the user elected to allow all plugins then run plugins at this time. |
| if (settings_changed()) { |
|
felt
2014/06/12 01:44:33
again here, simpler to do:
if (!settings_changed(
radhikabhar
2014/06/12 16:21:45
Done.
|
| - // If the user elected to allow all plugins then run plugins at this time. |
| - if (selected_item() == kAllowButtonIndex) |
| - OnCustomLinkClicked(); |
| + ContentSetting setting; |
|
felt
2014/06/12 01:44:33
why is this outside of the if-statement, but ti's
radhikabhar
2014/06/12 16:21:45
Removed the if statement - it is not needed.
|
| + if (content_type() == CONTENT_SETTINGS_TYPE_PLUGINS) { |
| + if (selected_item_ == kAllowButtonIndex) { |
| + setting = CONTENT_SETTING_ALLOW; |
| + OnRunPlugins(); |
| + } else if (selected_item_ == kAllowOnceButtonIndex) { |
| + setting = CONTENT_SETTING_DEFAULT; |
| + OnRunPlugins(); |
| + } else { |
| + setting = block_setting_; |
| + } |
| + TabSpecificContentSettings::FromWebContents(web_contents())-> |
| + set_plugin_bubble_setting(setting); |
| + if (profile()) { |
| + profile()->GetHostContentSettingsMap()->AddExceptionForURL( |
| + bubble_content().radio_group.url, |
| + bubble_content().radio_group.url, |
| + content_type(), |
| + setting); |
| + } |
| + } |
| } |
| } |
| -void ContentSettingPluginBubbleModel::OnCustomLinkClicked() { |
| +bool ContentSettingPluginBubbleModel::settings_changed() const { |
| + return selected_item_ != bubble_content().radio_group.default_item; |
| +} |
| + |
| +void ContentSettingPluginBubbleModel::OnRadioClicked(int radio_index) { |
| + selected_item_ = radio_index; |
| +} |
| + |
| +void ContentSettingPluginBubbleModel::SetRadioGroup() { |
| + GURL url = web_contents()->GetURL(); |
| + TabSpecificContentSettings* content_settings = |
| + TabSpecificContentSettings::FromWebContents(web_contents()); |
| + bool allowed = |
| + !content_settings->IsContentBlocked(content_type()); |
| + DCHECK(!allowed || |
| + content_settings->IsContentAllowed(content_type())); |
| + RadioGroup radio_group; |
| + radio_group.url = url; |
| + |
| + std::string radio_allow_label = |
| + l10n_util::GetStringUTF8(IDS_BLOCKED_PLUGINS_UNBLOCK_ALL); |
| + std::string radio_allow_once_label = |
| + l10n_util::GetStringUTF8(IDS_BLOCKED_PLUGINS_LOAD_ALL); |
| + std::string radio_block_label = |
| + l10n_util::GetStringUTF8(IDS_BLOCKED_PLUGINS_NO_ACTION); |
| + |
| + radio_group.radio_items.push_back(radio_allow_label); |
| + radio_group.radio_items.push_back(radio_allow_once_label); |
| + radio_group.radio_items.push_back(radio_block_label); |
| + |
| + ContentSetting setting; |
| + SettingSource setting_source = SETTING_SOURCE_NONE; |
| + bool setting_is_wildcard = false; |
| + SettingInfo info; |
| + HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); |
| + scoped_ptr<base::Value> value(map->GetWebsiteSetting( |
| + url, url, content_type(), std::string(), &info)); |
| + setting = content_settings->plugin_bubble_setting(); |
| + setting_source = info.source; |
| + setting_is_wildcard = |
| + info.primary_pattern == ContentSettingsPattern::Wildcard() && |
| + info.secondary_pattern == ContentSettingsPattern::Wildcard(); |
| + |
| + if (setting == CONTENT_SETTING_ALLOW && |
| + setting_is_wildcard) { |
|
felt
2014/06/12 01:44:33
^ is that really over 80 chars?
radhikabhar
2014/06/12 16:21:45
No it's not over 80 characters. Fixed it.
|
| + // In the corner case of unrecognized plugins (which are now blocked by |
| + // default) we indicate the blocked state in the UI and allow the user to |
| + // whitelist. |
| + radio_group.default_item = 2; |
| + } else if ( setting == CONTENT_SETTING_ALLOW) { |
|
felt
2014/06/12 01:44:33
get rid of the unneeded space
radhikabhar
2014/06/12 16:21:45
Done.
|
| + radio_group.default_item = kAllowButtonIndex; |
| + } else if (setting == CONTENT_SETTING_DEFAULT) { |
| + radio_group.default_item = kAllowOnceButtonIndex; |
| + // |block_setting_| is already set to |CONTENT_SETTING_BLOCK|. |
| + } else { |
| + radio_group.default_item = 2; |
| + block_setting_ = setting; |
| + } |
| + |
| + set_setting_is_managed(setting_source != SETTING_SOURCE_USER); |
| + if (setting_source != SETTING_SOURCE_USER) { |
| + set_radio_group_enabled(false); |
| + } else { |
| + set_radio_group_enabled(true); |
| + } |
| + selected_item_ = radio_group.default_item; |
| + set_radio_group(radio_group); |
| +} |
| + |
| +void ContentSettingPluginBubbleModel::OnRunPlugins() { |
| content::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble")); |
| DCHECK(web_contents()); |
| #if defined(ENABLE_PLUGINS) |
| @@ -477,9 +578,6 @@ void ContentSettingPluginBubbleModel::OnCustomLinkClicked() { |
| ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( |
| web_contents(), true, std::string()); |
| #endif |
| - set_custom_link_enabled(false); |
| - TabSpecificContentSettings::FromWebContents(web_contents())-> |
| - set_load_plugins_link_enabled(false); |
| } |
| class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup { |