Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(768)

Unified Diff: chrome/browser/ui/content_settings/content_setting_bubble_model.cc

Issue 10546083: Convert ProtocolHandlerRegistry to be a ProfileKeyedService. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Update content_setting_bubble_model tests to use injected ProtocolHandlerRegistry (integrating Greg… Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 c20024f7472f541106a961f8ba035c24511244ec..98a0c12d19c2933f6cd5c773ade07c6aed3fa573 100644
--- a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc
+++ b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc
@@ -56,92 +56,84 @@ int GetIdForContentType(const ContentSettingsTypeIdEntry* entries,
} // namespace
-class ContentSettingTitleAndLinkModel : public ContentSettingBubbleModel {
- public:
- ContentSettingTitleAndLinkModel(Delegate* delegate,
- TabContents* tab_contents,
- Profile* profile,
- ContentSettingsType content_type)
- : ContentSettingBubbleModel(tab_contents, profile, content_type),
+ContentSettingTitleAndLinkModel::ContentSettingTitleAndLinkModel(
+ Delegate* delegate,
+ TabContents* tab_contents,
+ Profile* profile,
+ ContentSettingsType content_type)
+ : ContentSettingBubbleModel(tab_contents, profile, content_type),
delegate_(delegate) {
- // Notifications do not have a bubble.
- DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
- SetBlockedResources();
- SetTitle();
- SetManageLink();
- }
-
- virtual ~ContentSettingTitleAndLinkModel() {}
- Delegate* delegate() const { return delegate_; }
-
- private:
- void SetBlockedResources() {
- TabSpecificContentSettings* settings = tab_contents()->content_settings();
- const std::set<std::string>& resources = settings->BlockedResourcesForType(
- content_type());
- for (std::set<std::string>::const_iterator it = resources.begin();
- it != resources.end(); ++it) {
- AddBlockedResource(*it);
- }
- }
+ // Notifications do not have a bubble.
+ DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
+ SetBlockedResources();
+ SetTitle();
+ SetManageLink();
+}
- void SetTitle() {
- static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = {
- {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE},
- {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE},
- {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE},
- {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_MESSAGE},
- {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TITLE},
- {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT,
- IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT},
- };
- // Fields as for kBlockedTitleIDs, above.
- static const ContentSettingsTypeIdEntry
- kResourceSpecificBlockedTitleIDs[] = {
- {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_TITLE},
- };
- static const ContentSettingsTypeIdEntry kAccessedTitleIDs[] = {
- {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ACCESSED_COOKIES_TITLE},
- };
- const ContentSettingsTypeIdEntry *title_ids = kBlockedTitleIDs;
- size_t num_title_ids = arraysize(kBlockedTitleIDs);
- if (tab_contents() && tab_contents()->content_settings()->
- IsContentAccessed(content_type()) &&
- !tab_contents()->content_settings()->IsContentBlocked(content_type())) {
- title_ids = kAccessedTitleIDs;
- num_title_ids = arraysize(kAccessedTitleIDs);
- } else if (!bubble_content().resource_identifiers.empty()) {
- title_ids = kResourceSpecificBlockedTitleIDs;
- num_title_ids = arraysize(kResourceSpecificBlockedTitleIDs);
- }
- int title_id =
- GetIdForContentType(title_ids, num_title_ids, content_type());
- if (title_id)
- set_title(l10n_util::GetStringUTF8(title_id));
+void ContentSettingTitleAndLinkModel::SetBlockedResources() {
+ TabSpecificContentSettings* settings = tab_contents()->content_settings();
+ const std::set<std::string>& resources = settings->BlockedResourcesForType(
+ content_type());
+ for (std::set<std::string>::const_iterator it = resources.begin();
+ it != resources.end(); ++it) {
+ AddBlockedResource(*it);
}
+}
- void SetManageLink() {
- static const ContentSettingsTypeIdEntry kLinkIDs[] = {
- {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK},
- {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK},
- {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK},
- {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_MIXEDSCRIPT, IDS_LEARN_MORE},
- {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, IDS_HANDLERS_BUBBLE_MANAGE_LINK}
- };
- set_manage_link(l10n_util::GetStringUTF8(
- GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type())));
- }
+void ContentSettingTitleAndLinkModel::SetTitle() {
+ static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = {
+ {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE},
+ {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE},
+ {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE},
+ {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_MESSAGE},
+ {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TITLE},
+ {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT,
+ IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT},
+ };
+ // Fields as for kBlockedTitleIDs, above.
+ static const ContentSettingsTypeIdEntry
+ kResourceSpecificBlockedTitleIDs[] = {
+ {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_TITLE},
+ };
+ static const ContentSettingsTypeIdEntry kAccessedTitleIDs[] = {
+ {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ACCESSED_COOKIES_TITLE},
+ };
+ const ContentSettingsTypeIdEntry *title_ids = kBlockedTitleIDs;
+ size_t num_title_ids = arraysize(kBlockedTitleIDs);
+ if (tab_contents() && tab_contents()->content_settings()->
+ IsContentAccessed(content_type()) &&
+ !tab_contents()->content_settings()->IsContentBlocked(content_type())) {
+ title_ids = kAccessedTitleIDs;
+ num_title_ids = arraysize(kAccessedTitleIDs);
+ } else if (!bubble_content().resource_identifiers.empty()) {
+ title_ids = kResourceSpecificBlockedTitleIDs;
+ num_title_ids = arraysize(kResourceSpecificBlockedTitleIDs);
+ }
+ int title_id =
+ GetIdForContentType(title_ids, num_title_ids, content_type());
+ if (title_id)
+ set_title(l10n_util::GetStringUTF8(title_id));
+}
- virtual void OnManageLinkClicked() {
- if (delegate_)
- delegate_->ShowContentSettingsPage(content_type());
- }
+void ContentSettingTitleAndLinkModel::SetManageLink() {
+ static const ContentSettingsTypeIdEntry kLinkIDs[] = {
+ {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK},
+ {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK},
+ {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK},
+ {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_MIXEDSCRIPT, IDS_LEARN_MORE},
+ {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, IDS_HANDLERS_BUBBLE_MANAGE_LINK}
+ };
+ set_manage_link(l10n_util::GetStringUTF8(
+ GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type())));
+}
- Delegate* delegate_;
-};
+void ContentSettingTitleAndLinkModel::OnManageLinkClicked() {
+ if (delegate_)
+ delegate_->ShowContentSettingsPage(content_type());
+}
class ContentSettingTitleLinkAndCustomModel
: public ContentSettingTitleAndLinkModel {
@@ -149,30 +141,35 @@ class ContentSettingTitleLinkAndCustomModel
ContentSettingTitleLinkAndCustomModel(Delegate* delegate,
TabContents* tab_contents,
Profile* profile,
- ContentSettingsType content_type)
- : ContentSettingTitleAndLinkModel(
- delegate, tab_contents, profile, content_type) {
- SetCustomLink();
- }
-
+ ContentSettingsType content_type);
virtual ~ContentSettingTitleLinkAndCustomModel() {}
private:
- void 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 =
- GetIdForContentType(kCustomIDs, arraysize(kCustomIDs), content_type());
- if (custom_link_id)
- set_custom_link(l10n_util::GetStringUTF8(custom_link_id));
- }
-
+ void SetCustomLink();
virtual void OnCustomLinkClicked() {}
};
+ContentSettingTitleLinkAndCustomModel::ContentSettingTitleLinkAndCustomModel(
+ Delegate* delegate,
+ TabContents* tab_contents,
+ Profile* profile,
+ ContentSettingsType content_type)
+ : ContentSettingTitleAndLinkModel(
+ delegate, tab_contents, profile, content_type) {
+ SetCustomLink();
+}
+
+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 =
+ GetIdForContentType(kCustomIDs, arraysize(kCustomIDs), content_type());
+ if (custom_link_id)
+ set_custom_link(l10n_util::GetStringUTF8(custom_link_id));
+}
class ContentSettingSingleRadioGroup
: public ContentSettingTitleLinkAndCustomModel {
@@ -180,265 +177,308 @@ class ContentSettingSingleRadioGroup
ContentSettingSingleRadioGroup(Delegate* delegate,
TabContents* tab_contents,
Profile* profile,
- ContentSettingsType content_type)
- : ContentSettingTitleLinkAndCustomModel(delegate, tab_contents, profile,
- content_type),
- block_setting_(CONTENT_SETTING_BLOCK),
- selected_item_(0) {
- SetRadioGroup();
- }
-
- virtual ~ContentSettingSingleRadioGroup() {
- if (settings_changed()) {
- ContentSetting setting =
- selected_item_ == 0 ? CONTENT_SETTING_ALLOW : block_setting_;
- const std::set<std::string>& resources =
- bubble_content().resource_identifiers;
- if (resources.empty()) {
- AddException(setting, std::string());
- } else {
- for (std::set<std::string>::const_iterator it = resources.begin();
- it != resources.end(); ++it) {
- AddException(setting, *it);
- }
- }
- }
- }
+ ContentSettingsType content_type);
+ virtual ~ContentSettingSingleRadioGroup();
protected:
- bool settings_changed() const {
- return selected_item_ != bubble_content().radio_group.default_item;
- }
+ bool settings_changed() const;
private:
+ void SetRadioGroup();
+ void AddException(ContentSetting setting,
+ const std::string& resource_identifier);
+ virtual void OnRadioClicked(int radio_index);
+
ContentSetting block_setting_;
int selected_item_;
+};
- // Initialize the radio group by setting the appropriate labels for the
- // content type and setting the default value based on the content setting.
- void SetRadioGroup() {
- GURL url = tab_contents()->web_contents()->GetURL();
- string16 display_host_utf16;
- net::AppendFormattedHost(url,
- profile()->GetPrefs()->GetString(prefs::kAcceptLanguages),
- &display_host_utf16);
- std::string display_host(UTF16ToUTF8(display_host_utf16));
-
- if (display_host.empty())
- display_host = url.spec();
+ContentSettingSingleRadioGroup::ContentSettingSingleRadioGroup(
+ Delegate* delegate,
+ TabContents* tab_contents,
+ Profile* profile,
+ ContentSettingsType content_type)
+ : ContentSettingTitleLinkAndCustomModel(delegate, tab_contents, profile,
+ content_type),
+ block_setting_(CONTENT_SETTING_BLOCK),
+ selected_item_(0) {
+ SetRadioGroup();
+}
+ContentSettingSingleRadioGroup::~ContentSettingSingleRadioGroup() {
+ if (settings_changed()) {
+ ContentSetting setting =
+ selected_item_ == 0 ? CONTENT_SETTING_ALLOW : block_setting_;
const std::set<std::string>& resources =
bubble_content().resource_identifiers;
-
- RadioGroup radio_group;
- radio_group.url = url;
-
- static const ContentSettingsTypeIdEntry kAllowIDs[] = {
- {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},
- };
- // Fields as for kAllowIDs, above.
- static const ContentSettingsTypeIdEntry kResourceSpecificAllowIDs[] = {
- {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK},
- };
- std::string radio_allow_label;
- const ContentSettingsTypeIdEntry* allow_ids = resources.empty() ?
- kAllowIDs : kResourceSpecificAllowIDs;
- size_t num_allow_ids = resources.empty() ?
- arraysize(kAllowIDs) : arraysize(kResourceSpecificAllowIDs);
- radio_allow_label = l10n_util::GetStringFUTF8(
- GetIdForContentType(allow_ids, num_allow_ids, content_type()),
- UTF8ToUTF16(display_host));
-
- static const ContentSettingsTypeIdEntry kBlockIDs[] = {
- {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},
- };
- std::string radio_block_label;
- radio_block_label = l10n_util::GetStringUTF8(
- GetIdForContentType(kBlockIDs, arraysize(kBlockIDs), content_type()));
-
- radio_group.radio_items.push_back(radio_allow_label);
- radio_group.radio_items.push_back(radio_block_label);
- HostContentSettingsMap* map = profile()->GetHostContentSettingsMap();
- CookieSettings* cookie_settings =
- CookieSettings::Factory::GetForProfile(profile());
- ContentSetting most_restrictive_setting;
- SettingSource most_restrictive_setting_source = SETTING_SOURCE_NONE;
-
if (resources.empty()) {
- if (content_type() == CONTENT_SETTINGS_TYPE_COOKIES) {
- most_restrictive_setting = cookie_settings->GetCookieSetting(
- url, url, true, &most_restrictive_setting_source);
- } else {
- SettingInfo info;
- scoped_ptr<Value> value(map->GetWebsiteSetting(
- url, url, content_type(), std::string(), &info));
- most_restrictive_setting =
- content_settings::ValueToContentSetting(value.get());
- most_restrictive_setting_source = info.source;
- }
+ AddException(setting, std::string());
} else {
- most_restrictive_setting = CONTENT_SETTING_ALLOW;
for (std::set<std::string>::const_iterator it = resources.begin();
it != resources.end(); ++it) {
- SettingInfo info;
- scoped_ptr<Value> value(map->GetWebsiteSetting(
- url, url, content_type(), *it, &info));
- ContentSetting setting =
- content_settings::ValueToContentSetting(value.get());
- if (setting == CONTENT_SETTING_BLOCK) {
- most_restrictive_setting = CONTENT_SETTING_BLOCK;
- most_restrictive_setting_source = info.source;
- break;
- }
- if (setting == CONTENT_SETTING_ASK) {
- most_restrictive_setting = CONTENT_SETTING_ASK;
- most_restrictive_setting_source = info.source;
- }
+ AddException(setting, *it);
}
}
- if (most_restrictive_setting == CONTENT_SETTING_ALLOW) {
- radio_group.default_item = 0;
- // |block_setting_| is already set to |CONTENT_SETTING_BLOCK|.
+ }
+}
+
+bool ContentSettingSingleRadioGroup::settings_changed() const {
+ return selected_item_ != bubble_content().radio_group.default_item;
+}
+
+// Initialize the radio group by setting the appropriate labels for the
+// content type and setting the default value based on the content setting.
+void ContentSettingSingleRadioGroup::SetRadioGroup() {
+ GURL url = tab_contents()->web_contents()->GetURL();
+ string16 display_host_utf16;
+ net::AppendFormattedHost(
+ url,
+ profile()->GetPrefs()->GetString(prefs::kAcceptLanguages),
+ &display_host_utf16);
+ std::string display_host(UTF16ToUTF8(display_host_utf16));
+
+ if (display_host.empty())
+ display_host = url.spec();
+
+ const std::set<std::string>& resources =
+ bubble_content().resource_identifiers;
+
+ RadioGroup radio_group;
+ radio_group.url = url;
+
+ static const ContentSettingsTypeIdEntry kAllowIDs[] = {
+ {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},
+ };
+ // Fields as for kAllowIDs, above.
+ static const ContentSettingsTypeIdEntry kResourceSpecificAllowIDs[] = {
+ {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK},
+ };
+ std::string radio_allow_label;
+ const ContentSettingsTypeIdEntry* allow_ids = resources.empty() ?
+ kAllowIDs : kResourceSpecificAllowIDs;
+ size_t num_allow_ids = resources.empty() ?
+ arraysize(kAllowIDs) : arraysize(kResourceSpecificAllowIDs);
+ radio_allow_label = l10n_util::GetStringFUTF8(
+ GetIdForContentType(allow_ids, num_allow_ids, content_type()),
+ UTF8ToUTF16(display_host));
+
+ static const ContentSettingsTypeIdEntry kBlockIDs[] = {
+ {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},
+ };
+ std::string radio_block_label;
+ radio_block_label = l10n_util::GetStringUTF8(
+ GetIdForContentType(kBlockIDs, arraysize(kBlockIDs), content_type()));
+
+ radio_group.radio_items.push_back(radio_allow_label);
+ radio_group.radio_items.push_back(radio_block_label);
+ HostContentSettingsMap* map = profile()->GetHostContentSettingsMap();
+ CookieSettings* cookie_settings =
+ CookieSettings::Factory::GetForProfile(profile());
+ ContentSetting most_restrictive_setting;
+ SettingSource most_restrictive_setting_source = SETTING_SOURCE_NONE;
+
+ if (resources.empty()) {
+ if (content_type() == CONTENT_SETTINGS_TYPE_COOKIES) {
+ most_restrictive_setting = cookie_settings->GetCookieSetting(
+ url, url, true, &most_restrictive_setting_source);
} else {
- radio_group.default_item = 1;
- block_setting_ = most_restrictive_setting;
+ SettingInfo info;
+ scoped_ptr<Value> value(map->GetWebsiteSetting(
+ url, url, content_type(), std::string(), &info));
+ most_restrictive_setting =
+ content_settings::ValueToContentSetting(value.get());
+ most_restrictive_setting_source = info.source;
}
- if (most_restrictive_setting_source != SETTING_SOURCE_USER) {
- set_radio_group_enabled(false);
- } else {
- set_radio_group_enabled(true);
+ } else {
+ most_restrictive_setting = CONTENT_SETTING_ALLOW;
+ for (std::set<std::string>::const_iterator it = resources.begin();
+ it != resources.end(); ++it) {
+ SettingInfo info;
+ scoped_ptr<Value> value(map->GetWebsiteSetting(
+ url, url, content_type(), *it, &info));
+ ContentSetting setting =
+ content_settings::ValueToContentSetting(value.get());
+ if (setting == CONTENT_SETTING_BLOCK) {
+ most_restrictive_setting = CONTENT_SETTING_BLOCK;
+ most_restrictive_setting_source = info.source;
+ break;
+ }
+ if (setting == CONTENT_SETTING_ASK) {
+ most_restrictive_setting = CONTENT_SETTING_ASK;
+ most_restrictive_setting_source = info.source;
+ }
}
- selected_item_ = radio_group.default_item;
- set_radio_group(radio_group);
}
-
- void AddException(ContentSetting setting,
- const std::string& resource_identifier) {
- if (profile()) {
- profile()->GetHostContentSettingsMap()->AddExceptionForURL(
- bubble_content().radio_group.url,
- bubble_content().radio_group.url,
- content_type(),
- resource_identifier,
- setting);
- }
+ if (most_restrictive_setting == CONTENT_SETTING_ALLOW) {
+ radio_group.default_item = 0;
+ // |block_setting_| is already set to |CONTENT_SETTING_BLOCK|.
+ } else {
+ radio_group.default_item = 1;
+ block_setting_ = most_restrictive_setting;
}
+ if (most_restrictive_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);
+}
- virtual void OnRadioClicked(int radio_index) {
- selected_item_ = radio_index;
+void ContentSettingSingleRadioGroup::AddException(
+ ContentSetting setting,
+ const std::string& resource_identifier) {
+ if (profile()) {
+ profile()->GetHostContentSettingsMap()->AddExceptionForURL(
+ bubble_content().radio_group.url,
+ bubble_content().radio_group.url,
+ content_type(),
+ resource_identifier,
+ setting);
}
-};
+}
+
+void ContentSettingSingleRadioGroup::OnRadioClicked(int radio_index) {
+ selected_item_ = radio_index;
+}
class ContentSettingCookiesBubbleModel : public ContentSettingSingleRadioGroup {
public:
ContentSettingCookiesBubbleModel(Delegate* delegate,
TabContents* tab_contents,
Profile* profile,
- ContentSettingsType content_type)
- : ContentSettingSingleRadioGroup(
- delegate, tab_contents, profile, content_type) {
- DCHECK_EQ(CONTENT_SETTINGS_TYPE_COOKIES, content_type);
- set_custom_link_enabled(true);
- }
+ ContentSettingsType content_type);
- virtual ~ContentSettingCookiesBubbleModel() {
- if (settings_changed()) {
- InfoBarTabHelper* infobar_helper = tab_contents()->infobar_tab_helper();
- infobar_helper->AddInfoBar(
- new CollectedCookiesInfoBarDelegate(infobar_helper));
- }
- }
+ virtual ~ContentSettingCookiesBubbleModel();
private:
- virtual void OnCustomLinkClicked() OVERRIDE {
- if (!tab_contents())
- return;
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN,
- content::Source<TabSpecificContentSettings>(
- tab_contents()->content_settings()),
- content::NotificationService::NoDetails());
- delegate()->ShowCollectedCookiesDialog(tab_contents());
- }
+ virtual void OnCustomLinkClicked() OVERRIDE;
};
+ContentSettingCookiesBubbleModel::ContentSettingCookiesBubbleModel(
+ Delegate* delegate,
+ TabContents* tab_contents,
+ Profile* profile,
+ ContentSettingsType content_type)
+ : ContentSettingSingleRadioGroup(
+ delegate, tab_contents, profile, content_type) {
+ DCHECK_EQ(CONTENT_SETTINGS_TYPE_COOKIES, content_type);
+ set_custom_link_enabled(true);
+}
+
+ContentSettingCookiesBubbleModel::~ContentSettingCookiesBubbleModel() {
+ if (settings_changed()) {
+ InfoBarTabHelper* infobar_helper = tab_contents()->infobar_tab_helper();
+ infobar_helper->AddInfoBar(
+ new CollectedCookiesInfoBarDelegate(infobar_helper));
+ }
+}
+
+void ContentSettingCookiesBubbleModel::OnCustomLinkClicked() {
+ if (!tab_contents())
+ return;
+ content::NotificationService::current()->Notify(
+ chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN,
+ content::Source<TabSpecificContentSettings>(
+ tab_contents()->content_settings()),
+ content::NotificationService::NoDetails());
+ delegate()->ShowCollectedCookiesDialog(tab_contents());
+}
+
class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup {
public:
ContentSettingPluginBubbleModel(Delegate* delegate,
TabContents* tab_contents,
Profile* profile,
- ContentSettingsType content_type)
- : ContentSettingSingleRadioGroup(
- delegate, tab_contents, profile, content_type) {
- DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS);
- set_custom_link_enabled(tab_contents && tab_contents->content_settings()->
- load_plugins_link_enabled());
- }
+ ContentSettingsType content_type);
virtual ~ContentSettingPluginBubbleModel() {}
private:
- virtual void OnCustomLinkClicked() OVERRIDE {
- content::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble"));
- DCHECK(tab_contents());
- content::RenderViewHost* host =
- tab_contents()->web_contents()->GetRenderViewHost();
- // TODO(bauerb): We should send the identifiers of blocked plug-ins here.
- host->Send(new ChromeViewMsg_LoadBlockedPlugins(host->GetRoutingID(),
- std::string()));
- set_custom_link_enabled(false);
- tab_contents()->content_settings()->set_load_plugins_link_enabled(false);
- }
+ virtual void OnCustomLinkClicked() OVERRIDE;
};
+ContentSettingPluginBubbleModel::ContentSettingPluginBubbleModel(
+ Delegate* delegate,
+ TabContents* tab_contents,
+ Profile* profile,
+ ContentSettingsType content_type)
+ : ContentSettingSingleRadioGroup(
+ delegate, tab_contents, profile, content_type) {
+ DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS);
+ set_custom_link_enabled(tab_contents && tab_contents->content_settings()->
+ load_plugins_link_enabled());
+}
+
+void ContentSettingPluginBubbleModel::OnCustomLinkClicked() {
+ content::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble"));
+ DCHECK(tab_contents());
+ content::RenderViewHost* host =
+ tab_contents()->web_contents()->GetRenderViewHost();
+ // TODO(bauerb): We should send the identifiers of blocked plug-ins here.
+ host->Send(new ChromeViewMsg_LoadBlockedPlugins(host->GetRoutingID(),
+ std::string()));
+ set_custom_link_enabled(false);
+ tab_contents()->content_settings()->set_load_plugins_link_enabled(false);
+}
+
class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup {
public:
ContentSettingPopupBubbleModel(Delegate* delegate,
TabContents* tab_contents,
Profile* profile,
- ContentSettingsType content_type)
- : ContentSettingSingleRadioGroup(
- delegate, tab_contents, profile, content_type) {
- SetPopups();
- }
-
+ ContentSettingsType content_type);
virtual ~ContentSettingPopupBubbleModel() {}
private:
- void SetPopups() {
- std::vector<TabContents*> blocked_contents;
- tab_contents()->blocked_content_tab_helper()->
- GetBlockedContents(&blocked_contents);
- for (std::vector<TabContents*>::const_iterator
- i = blocked_contents.begin(); i != blocked_contents.end(); ++i) {
- std::string title(UTF16ToUTF8((*i)->web_contents()->GetTitle()));
- // The popup may not have committed a load yet, in which case it won't
- // have a URL or title.
- if (title.empty())
- title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE);
- PopupItem popup_item;
- popup_item.title = title;
- popup_item.bitmap = (*i)->favicon_tab_helper()->GetFavicon();
- popup_item.tab_contents = (*i);
- add_popup(popup_item);
- }
+ void SetPopups();
+ virtual void OnPopupClicked(int index);
+};
+
+ContentSettingPopupBubbleModel::ContentSettingPopupBubbleModel(
+ Delegate* delegate,
+ TabContents* tab_contents,
+ Profile* profile,
+ ContentSettingsType content_type)
+ : ContentSettingSingleRadioGroup(
+ delegate, tab_contents, profile, content_type) {
+ SetPopups();
+}
+
+
+void ContentSettingPopupBubbleModel::SetPopups() {
+ std::vector<TabContents*> blocked_contents;
+ tab_contents()->blocked_content_tab_helper()->
+ GetBlockedContents(&blocked_contents);
+ for (std::vector<TabContents*>::const_iterator
+ i = blocked_contents.begin(); i != blocked_contents.end(); ++i) {
+ std::string title(UTF16ToUTF8((*i)->web_contents()->GetTitle()));
+ // The popup may not have committed a load yet, in which case it won't
+ // have a URL or title.
+ if (title.empty())
+ title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE);
+ PopupItem popup_item;
+ popup_item.title = title;
+ popup_item.bitmap = (*i)->favicon_tab_helper()->GetFavicon();
+ popup_item.tab_contents = (*i);
+ add_popup(popup_item);
}
+}
- virtual void OnPopupClicked(int index) {
- if (tab_contents()) {
- tab_contents()->blocked_content_tab_helper()->
- LaunchForContents(bubble_content().popup_items[index].tab_contents);
- }
+void ContentSettingPopupBubbleModel::OnPopupClicked(int index) {
+ if (tab_contents()) {
+ tab_contents()->blocked_content_tab_helper()->
+ LaunchForContents(bubble_content().popup_items[index].tab_contents);
}
-};
+}
class ContentSettingDomainListBubbleModel
: public ContentSettingTitleAndLinkModel {
@@ -446,75 +486,87 @@ class ContentSettingDomainListBubbleModel
ContentSettingDomainListBubbleModel(Delegate* delegate,
TabContents* tab_contents,
Profile* profile,
- ContentSettingsType content_type)
- : ContentSettingTitleAndLinkModel(
- delegate, tab_contents, profile, content_type) {
- DCHECK_EQ(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type) <<
- "SetDomains currently only supports geolocation content type";
- SetDomainsAndCustomLink();
- }
-
+ ContentSettingsType content_type);
virtual ~ContentSettingDomainListBubbleModel() {}
private:
- void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id) {
- if (!hosts.empty()) {
- DomainList domain_list;
- domain_list.title = l10n_util::GetStringUTF8(title_id);
- domain_list.hosts = hosts;
- add_domain_list(domain_list);
- }
+ void MaybeAddDomainList(const std::set<std::string>& hosts, int title_id);
+ void SetDomainsAndCustomLink();
+ virtual void OnCustomLinkClicked() OVERRIDE;
+};
+
+ContentSettingDomainListBubbleModel::ContentSettingDomainListBubbleModel(
+ Delegate* delegate,
+ TabContents* tab_contents,
+ Profile* profile,
+ ContentSettingsType content_type)
+ : ContentSettingTitleAndLinkModel(
+ delegate, tab_contents, profile, content_type) {
+ DCHECK_EQ(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type) <<
+ "SetDomains currently only supports geolocation content type";
+ SetDomainsAndCustomLink();
+}
+
+void ContentSettingDomainListBubbleModel::MaybeAddDomainList(
+ const std::set<std::string>& hosts, int title_id) {
+ if (!hosts.empty()) {
+ DomainList domain_list;
+ domain_list.title = l10n_util::GetStringUTF8(title_id);
+ domain_list.hosts = hosts;
+ add_domain_list(domain_list);
}
- void SetDomainsAndCustomLink() {
- TabSpecificContentSettings* content_settings =
- tab_contents()->content_settings();
- const GeolocationSettingsState& settings =
- content_settings->geolocation_settings_state();
- GeolocationSettingsState::FormattedHostsPerState formatted_hosts_per_state;
- unsigned int tab_state_flags = 0;
- settings.GetDetailedInfo(&formatted_hosts_per_state, &tab_state_flags);
- // Divide the tab's current geolocation users into sets according to their
- // permission state.
- MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_ALLOW],
- IDS_GEOLOCATION_BUBBLE_SECTION_ALLOWED);
-
- MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_BLOCK],
- IDS_GEOLOCATION_BUBBLE_SECTION_DENIED);
-
- if (tab_state_flags & GeolocationSettingsState::TABSTATE_HAS_EXCEPTION) {
- set_custom_link(l10n_util::GetStringUTF8(
- IDS_GEOLOCATION_BUBBLE_CLEAR_LINK));
- set_custom_link_enabled(true);
- } else if (tab_state_flags &
- GeolocationSettingsState::TABSTATE_HAS_CHANGED) {
- set_custom_link(l10n_util::GetStringUTF8(
- IDS_GEOLOCATION_BUBBLE_REQUIRE_RELOAD_TO_CLEAR));
- }
+}
+
+void ContentSettingDomainListBubbleModel::SetDomainsAndCustomLink() {
+ TabSpecificContentSettings* content_settings =
+ tab_contents()->content_settings();
+ const GeolocationSettingsState& settings =
+ content_settings->geolocation_settings_state();
+ GeolocationSettingsState::FormattedHostsPerState formatted_hosts_per_state;
+ unsigned int tab_state_flags = 0;
+ settings.GetDetailedInfo(&formatted_hosts_per_state, &tab_state_flags);
+ // Divide the tab's current geolocation users into sets according to their
+ // permission state.
+ MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_ALLOW],
+ IDS_GEOLOCATION_BUBBLE_SECTION_ALLOWED);
+
+ MaybeAddDomainList(formatted_hosts_per_state[CONTENT_SETTING_BLOCK],
+ IDS_GEOLOCATION_BUBBLE_SECTION_DENIED);
+
+ if (tab_state_flags & GeolocationSettingsState::TABSTATE_HAS_EXCEPTION) {
+ set_custom_link(l10n_util::GetStringUTF8(
+ IDS_GEOLOCATION_BUBBLE_CLEAR_LINK));
+ set_custom_link_enabled(true);
+ } else if (tab_state_flags &
+ GeolocationSettingsState::TABSTATE_HAS_CHANGED) {
+ set_custom_link(l10n_util::GetStringUTF8(
+ IDS_GEOLOCATION_BUBBLE_REQUIRE_RELOAD_TO_CLEAR));
}
- virtual void OnCustomLinkClicked() OVERRIDE {
- if (!tab_contents())
- return;
- // Reset this embedder's entry to default for each of the requesting
- // origins currently on the page.
- const GURL& embedder_url = tab_contents()->web_contents()->GetURL();
- TabSpecificContentSettings* content_settings =
- tab_contents()->content_settings();
- const GeolocationSettingsState::StateMap& state_map =
- content_settings->geolocation_settings_state().state_map();
- HostContentSettingsMap* settings_map =
- profile()->GetHostContentSettingsMap();
-
- for (GeolocationSettingsState::StateMap::const_iterator it =
- state_map.begin(); it != state_map.end(); ++it) {
- settings_map->SetContentSetting(
- ContentSettingsPattern::FromURLNoWildcard(it->first),
- ContentSettingsPattern::FromURLNoWildcard(embedder_url),
- CONTENT_SETTINGS_TYPE_GEOLOCATION,
- std::string(),
- CONTENT_SETTING_DEFAULT);
- }
+}
+
+void ContentSettingDomainListBubbleModel::OnCustomLinkClicked() {
+ if (!tab_contents())
+ return;
+ // Reset this embedder's entry to default for each of the requesting
+ // origins currently on the page.
+ const GURL& embedder_url = tab_contents()->web_contents()->GetURL();
+ TabSpecificContentSettings* content_settings =
+ tab_contents()->content_settings();
+ const GeolocationSettingsState::StateMap& state_map =
+ content_settings->geolocation_settings_state().state_map();
+ HostContentSettingsMap* settings_map =
+ profile()->GetHostContentSettingsMap();
+
+ for (GeolocationSettingsState::StateMap::const_iterator it =
+ state_map.begin(); it != state_map.end(); ++it) {
+ settings_map->SetContentSetting(
+ ContentSettingsPattern::FromURLNoWildcard(it->first),
+ ContentSettingsPattern::FromURLNoWildcard(embedder_url),
+ CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ std::string(),
+ CONTENT_SETTING_DEFAULT);
}
-};
+}
class ContentSettingMixedScriptBubbleModel
: public ContentSettingTitleLinkAndCustomModel {
@@ -550,33 +602,20 @@ void ContentSettingMixedScriptBubbleModel::OnCustomLinkClicked() {
host->GetRoutingID(), true));
}
-class ContentSettingRPHBubbleModel : public ContentSettingTitleAndLinkModel {
- public:
- ContentSettingRPHBubbleModel(Delegate* delegate,
- TabContents* tab_contents,
- Profile* profile,
- ContentSettingsType content_type);
-
- virtual void OnRadioClicked(int radio_index) OVERRIDE;
-
- private:
- // These states must match the order of appearance of the radio buttons
- // in the XIB file for the Mac port.
- enum RPHState {
- RPH_ALLOW = 0,
- RPH_BLOCK,
- RPH_IGNORE,
- };
-
- void RegisterProtocolHandler();
- void UnregisterProtocolHandler();
- void IgnoreProtocolHandler();
- void ClearOrSetPreviousHandler();
-
- int selected_item_;
- ProtocolHandler pending_handler_;
- ProtocolHandler previous_handler_;
-};
+ContentSettingRPHBubbleModel::ContentSettingRPHBubbleModel(
+ Delegate* delegate,
+ TabContents* tab_contents,
+ Profile* profile,
+ ProtocolHandlerRegistry* registry,
+ ContentSettingsType content_type)
+ : ContentSettingTitleAndLinkModel(
+ delegate, tab_contents, profile, content_type),
+ selected_item_(0),
+ registry_(registry),
+ pending_handler_(ProtocolHandler::EmptyProtocolHandler()),
+ previous_handler_(ProtocolHandler::EmptyProtocolHandler()) {
+ Init();
+}
ContentSettingRPHBubbleModel::ContentSettingRPHBubbleModel(
Delegate* delegate,
@@ -586,12 +625,17 @@ ContentSettingRPHBubbleModel::ContentSettingRPHBubbleModel(
: ContentSettingTitleAndLinkModel(
delegate, tab_contents, profile, content_type),
selected_item_(0),
+ registry_(profile->GetProtocolHandlerRegistry()),
Greg Billock 2012/07/19 14:49:57 This needs to use the PKS factory, right?
Steve McKay 2012/07/19 16:59:55 Ah. Yeah. I was thinking since this is deprecated
pending_handler_(ProtocolHandler::EmptyProtocolHandler()),
previous_handler_(ProtocolHandler::EmptyProtocolHandler()) {
- DCHECK_EQ(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, content_type);
+ Init();
+}
+
+void ContentSettingRPHBubbleModel::Init() {
+ DCHECK_EQ(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, content_type());
TabSpecificContentSettings* content_settings =
- tab_contents->content_settings();
+ tab_contents()->content_settings();
pending_handler_ = content_settings->pending_protocol_handler();
previous_handler_ = content_settings->previous_protocol_handler();
@@ -626,7 +670,7 @@ ContentSettingRPHBubbleModel::ContentSettingRPHBubbleModel(
std::string radio_ignore_label =
l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_IGNORE);
- GURL url = tab_contents->web_contents()->GetURL();
+ GURL url = tab_contents()->web_contents()->GetURL();
RadioGroup radio_group;
radio_group.url = url;
@@ -666,26 +710,22 @@ void ContentSettingRPHBubbleModel::OnRadioClicked(int radio_index) {
void ContentSettingRPHBubbleModel::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_);
+ registry_->RemoveIgnoredHandler(pending_handler_);
- profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler(
- pending_handler_);
+ registry_->OnAcceptRegisterProtocolHandler(pending_handler_);
tab_contents()->content_settings()->set_pending_protocol_handler_setting(
CONTENT_SETTING_ALLOW);
}
void ContentSettingRPHBubbleModel::UnregisterProtocolHandler() {
- profile()->GetProtocolHandlerRegistry()->OnDenyRegisterProtocolHandler(
- pending_handler_);
+ registry_->OnDenyRegisterProtocolHandler(pending_handler_);
tab_contents()->content_settings()->set_pending_protocol_handler_setting(
CONTENT_SETTING_BLOCK);
ClearOrSetPreviousHandler();
}
void ContentSettingRPHBubbleModel::IgnoreProtocolHandler() {
- profile()->GetProtocolHandlerRegistry()->OnIgnoreRegisterProtocolHandler(
- pending_handler_);
+ registry_->OnIgnoreRegisterProtocolHandler(pending_handler_);
tab_contents()->content_settings()->set_pending_protocol_handler_setting(
CONTENT_SETTING_DEFAULT);
ClearOrSetPreviousHandler();
@@ -693,11 +733,9 @@ void ContentSettingRPHBubbleModel::IgnoreProtocolHandler() {
void ContentSettingRPHBubbleModel::ClearOrSetPreviousHandler() {
if (previous_handler_.IsEmpty()) {
- profile()->GetProtocolHandlerRegistry()->ClearDefault(
- pending_handler_.protocol());
+ registry_->ClearDefault(pending_handler_.protocol());
} else {
- profile()->GetProtocolHandlerRegistry()->OnAcceptRegisterProtocolHandler(
- previous_handler_);
+ registry_->OnAcceptRegisterProtocolHandler(previous_handler_);
}
}

Powered by Google App Engine
This is Rietveld 408576698