| Index: chrome/browser/content_setting_bubble_model.cc
|
| diff --git a/chrome/browser/content_setting_bubble_model.cc b/chrome/browser/content_setting_bubble_model.cc
|
| index e361b12566ce70df362df2e05cc4336e5153f638..6e61eb4ce3acf1e9d9d67f52dbcd0b6da9a89d80 100644
|
| --- a/chrome/browser/content_setting_bubble_model.cc
|
| +++ b/chrome/browser/content_setting_bubble_model.cc
|
| @@ -18,153 +18,209 @@
|
|
|
| class ContentSettingTitleAndLinkModel : public ContentSettingBubbleModel {
|
| public:
|
| - ContentSettingTitleAndLinkModel(TabContents* tab_contents, Profile* profile,
|
| - ContentSettingsType content_type)
|
| - : ContentSettingBubbleModel(tab_contents, profile, content_type) {
|
| - SetTitle();
|
| - SetManageLink();
|
| - }
|
| + ContentSettingTitleAndLinkModel(
|
| + TabContents* tab_contents, Profile* profile,
|
| + ContentSettingsType content_type);
|
|
|
| private:
|
| - void SetTitle() {
|
| - static const int kTitleIDs[CONTENT_SETTINGS_NUM_TYPES] = {
|
| - IDS_BLOCKED_COOKIES_TITLE,
|
| - IDS_BLOCKED_IMAGES_TITLE,
|
| - IDS_BLOCKED_JAVASCRIPT_TITLE,
|
| - IDS_BLOCKED_PLUGINS_TITLE,
|
| - IDS_BLOCKED_POPUPS_TITLE,
|
| - };
|
| - set_title(l10n_util::GetStringUTF8(kTitleIDs[content_type()]));
|
| - }
|
| + void SetTitle();
|
| + void SetManageLink();
|
|
|
| - void SetManageLink() {
|
| - static const int kLinkIDs[CONTENT_SETTINGS_NUM_TYPES] = {
|
| - IDS_BLOCKED_COOKIES_LINK,
|
| - IDS_BLOCKED_IMAGES_LINK,
|
| - IDS_BLOCKED_JAVASCRIPT_LINK,
|
| - IDS_BLOCKED_PLUGINS_LINK,
|
| - IDS_BLOCKED_POPUPS_LINK,
|
| - };
|
| - set_manage_link(l10n_util::GetStringUTF8(kLinkIDs[content_type()]));
|
| - }
|
| -
|
| - virtual void OnManageLinkClicked() {
|
| - if (tab_contents())
|
| - tab_contents()->delegate()->ShowContentSettingsWindow(content_type());
|
| - }
|
| + virtual void OnManageLinkClicked();
|
| };
|
|
|
| class ContentSettingSingleRadioGroup : public ContentSettingTitleAndLinkModel {
|
| public:
|
| - ContentSettingSingleRadioGroup(TabContents* tab_contents, Profile* profile,
|
| - ContentSettingsType content_type)
|
| - : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type) {
|
| - SetRadioGroups();
|
| - }
|
| + ContentSettingSingleRadioGroup(
|
| + TabContents* tab_contents, Profile* profile,
|
| + ContentSettingsType content_type);
|
|
|
| private:
|
| - void SetRadioGroups() {
|
| - GURL url = tab_contents()->GetURL();
|
| - std::wstring display_host_wide;
|
| - net::AppendFormattedHost(url,
|
| - profile()->GetPrefs()->GetString(prefs::kAcceptLanguages),
|
| - &display_host_wide, NULL, NULL);
|
| - std::string display_host(WideToUTF8(display_host_wide));
|
| -
|
| - RadioGroup radio_group;
|
| - radio_group.host = url.host();
|
| -
|
| - static const int kAllowIDs[CONTENT_SETTINGS_NUM_TYPES] = {
|
| - 0, // We don't manage cookies here.
|
| - IDS_BLOCKED_IMAGES_UNBLOCK,
|
| - IDS_BLOCKED_JAVASCRIPT_UNBLOCK,
|
| - IDS_BLOCKED_PLUGINS_UNBLOCK,
|
| - IDS_BLOCKED_POPUPS_UNBLOCK,
|
| - };
|
| - std::string radio_allow_label;
|
| - radio_allow_label = l10n_util::GetStringFUTF8(
|
| - kAllowIDs[content_type()], UTF8ToUTF16(display_host));
|
| -
|
| - static const int kBlockIDs[CONTENT_SETTINGS_NUM_TYPES] = {
|
| - 0, // We don't manage cookies here.
|
| - IDS_BLOCKED_IMAGES_NO_ACTION,
|
| - IDS_BLOCKED_JAVASCRIPT_NO_ACTION,
|
| - IDS_BLOCKED_PLUGINS_NO_ACTION,
|
| - IDS_BLOCKED_POPUPS_NO_ACTION,
|
| - };
|
| - std::string radio_block_label;
|
| - radio_block_label = l10n_util::GetStringFUTF8(
|
| - kBlockIDs[content_type()], UTF8ToUTF16(display_host));
|
| -
|
| - radio_group.radio_items.push_back(radio_allow_label);
|
| - radio_group.radio_items.push_back(radio_block_label);
|
| - radio_group.default_item =
|
| - profile()->GetHostContentSettingsMap()->GetContentSetting(url,
|
| - content_type()) == CONTENT_SETTING_ALLOW ? 0 : 1;
|
| - add_radio_group(radio_group);
|
| - }
|
| + void SetRadioGroups();
|
|
|
| - virtual void OnRadioClicked(int radio_group, int radio_index) {
|
| - profile()->GetHostContentSettingsMap()->SetContentSetting(
|
| - bubble_content().radio_groups[radio_group].host,
|
| - content_type(),
|
| - radio_index == 0 ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK);
|
| - }
|
| + virtual void OnRadioClicked(int radio_group, int radio_index);
|
| };
|
|
|
| class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup {
|
| public:
|
| - ContentSettingPopupBubbleModel(TabContents* tab_contents, Profile* profile,
|
| - ContentSettingsType content_type)
|
| - : ContentSettingSingleRadioGroup(tab_contents, profile, content_type) {
|
| - SetPopups();
|
| - }
|
| + ContentSettingPopupBubbleModel(TabContents* tab_contents, Profile* profile);
|
|
|
| private:
|
| - void SetPopups() {
|
| - BlockedPopupContainer::BlockedContents blocked_contents;
|
| - DCHECK(tab_contents()->blocked_popup_container());
|
| - tab_contents()->blocked_popup_container()->GetBlockedContents(
|
| - &blocked_contents);
|
| - for (BlockedPopupContainer::BlockedContents::const_iterator
|
| - i(blocked_contents.begin()); i != blocked_contents.end(); ++i) {
|
| - std::string title(UTF16ToUTF8((*i)->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)->GetFavIcon();
|
| - popup_item.tab_contents = (*i);
|
| - add_popup(popup_item);
|
| - }
|
| - }
|
| + void SetPopups();
|
|
|
| - virtual void OnPopupClicked(int index) {
|
| - if (tab_contents() && tab_contents()->blocked_popup_container()) {
|
| - tab_contents()->blocked_popup_container()->LaunchPopupForContents(
|
| - bubble_content().popup_items[index].tab_contents);
|
| - }
|
| - }
|
| + virtual void OnPopupClicked(int index);
|
| };
|
|
|
| -// static
|
| -ContentSettingBubbleModel*
|
| - ContentSettingBubbleModel::CreateContentSettingBubbleModel(
|
| - TabContents* tab_contents,
|
| - Profile* profile,
|
| - ContentSettingsType content_type) {
|
| - if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) {
|
| - return new ContentSettingTitleAndLinkModel(tab_contents, profile,
|
| - content_type);
|
| +class ContentSettingGeolocationModel : public ContentSettingTitleAndLinkModel {
|
| + public:
|
| + ContentSettingGeolocationModel(TabContents* tab_contents, Profile* profile);
|
| +
|
| + private:
|
| + void SetRadioGroups();
|
| +
|
| + virtual void OnRadioClicked(int radio_group, int radio_index);
|
| +};
|
| +
|
| +ContentSettingTitleAndLinkModel::ContentSettingTitleAndLinkModel(
|
| + TabContents* tab_contents, Profile* profile,
|
| + ContentSettingsType content_type)
|
| + : ContentSettingBubbleModel(tab_contents, profile, content_type) {
|
| + SetTitle();
|
| + SetManageLink();
|
| +}
|
| +
|
| +void ContentSettingTitleAndLinkModel::SetTitle() {
|
| + static const int kTitleIDs[CONTENT_SETTINGS_NUM_TYPES] = {
|
| + IDS_BLOCKED_COOKIES_TITLE,
|
| + IDS_BLOCKED_IMAGES_TITLE,
|
| + IDS_BLOCKED_JAVASCRIPT_TITLE,
|
| + IDS_BLOCKED_PLUGINS_TITLE,
|
| + IDS_BLOCKED_POPUPS_TITLE,
|
| + 0,
|
| + };
|
| + if (kTitleIDs[content_type()])
|
| + set_title(l10n_util::GetStringUTF8(kTitleIDs[content_type()]));
|
| +}
|
| +
|
| +void ContentSettingTitleAndLinkModel::SetManageLink() {
|
| + static const int kLinkIDs[CONTENT_SETTINGS_NUM_TYPES] = {
|
| + IDS_BLOCKED_COOKIES_LINK,
|
| + IDS_BLOCKED_IMAGES_LINK,
|
| + IDS_BLOCKED_JAVASCRIPT_LINK,
|
| + IDS_BLOCKED_PLUGINS_LINK,
|
| + IDS_BLOCKED_POPUPS_LINK,
|
| + IDS_GEOLOCATION_LINK,
|
| + };
|
| + set_manage_link(l10n_util::GetStringUTF8(kLinkIDs[content_type()]));
|
| +}
|
| +
|
| +void ContentSettingTitleAndLinkModel::OnManageLinkClicked() {
|
| + if (tab_contents())
|
| + tab_contents()->delegate()->ShowContentSettingsWindow(content_type());
|
| +}
|
| +
|
| + ContentSettingSingleRadioGroup::ContentSettingSingleRadioGroup(
|
| + TabContents* tab_contents, Profile* profile,
|
| + ContentSettingsType content_type)
|
| + : ContentSettingTitleAndLinkModel(tab_contents, profile, content_type) {
|
| + SetRadioGroups();
|
| +}
|
| +
|
| +void ContentSettingSingleRadioGroup::SetRadioGroups() {
|
| + GURL url = tab_contents()->GetURL();
|
| + std::wstring display_host_wide;
|
| + net::AppendFormattedHost(url,
|
| + profile()->GetPrefs()->GetString(prefs::kAcceptLanguages),
|
| + &display_host_wide, NULL, NULL);
|
| + std::string display_host(WideToUTF8(display_host_wide));
|
| +
|
| + RadioGroup radio_group;
|
| + radio_group.host = url.host();
|
| +
|
| + static const int kAllowIDs[CONTENT_SETTINGS_NUM_TYPES] = {
|
| + 0, // We don't manage cookies here.
|
| + IDS_BLOCKED_IMAGES_UNBLOCK,
|
| + IDS_BLOCKED_JAVASCRIPT_UNBLOCK,
|
| + IDS_BLOCKED_PLUGINS_UNBLOCK,
|
| + IDS_BLOCKED_POPUPS_UNBLOCK,
|
| + };
|
| + std::string radio_allow_label;
|
| + radio_allow_label = l10n_util::GetStringFUTF8(
|
| + kAllowIDs[content_type()], UTF8ToUTF16(display_host));
|
| +
|
| + static const int kBlockIDs[CONTENT_SETTINGS_NUM_TYPES] = {
|
| + 0, // We don't manage cookies here.
|
| + IDS_BLOCKED_IMAGES_NO_ACTION,
|
| + IDS_BLOCKED_JAVASCRIPT_NO_ACTION,
|
| + IDS_BLOCKED_PLUGINS_NO_ACTION,
|
| + IDS_BLOCKED_POPUPS_NO_ACTION,
|
| + };
|
| + std::string radio_block_label;
|
| + radio_block_label = l10n_util::GetStringFUTF8(
|
| + kBlockIDs[content_type()], UTF8ToUTF16(display_host));
|
| +
|
| + radio_group.radio_items.push_back(radio_allow_label);
|
| + radio_group.radio_items.push_back(radio_block_label);
|
| + radio_group.default_item =
|
| + profile()->GetHostContentSettingsMap()->GetContentSetting(url,
|
| + content_type()) == CONTENT_SETTING_ALLOW ? 0 : 1;
|
| + add_radio_group(radio_group);
|
| +}
|
| +
|
| +void ContentSettingSingleRadioGroup::OnRadioClicked(
|
| + int radio_group, int radio_index) {
|
| + profile()->GetHostContentSettingsMap()->SetContentSetting(
|
| + bubble_content().radio_groups[radio_group].host,
|
| + content_type(),
|
| + radio_index == 0 ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK);
|
| +}
|
| +
|
| +
|
| +ContentSettingPopupBubbleModel::ContentSettingPopupBubbleModel(
|
| + TabContents* tab_contents, Profile* profile)
|
| + : ContentSettingSingleRadioGroup(
|
| + tab_contents, profile, CONTENT_SETTINGS_TYPE_POPUPS) {
|
| + SetPopups();
|
| +}
|
| +
|
| +void ContentSettingPopupBubbleModel::SetPopups() {
|
| + BlockedPopupContainer::BlockedContents blocked_contents;
|
| + DCHECK(tab_contents()->blocked_popup_container());
|
| + tab_contents()->blocked_popup_container()->GetBlockedContents(
|
| + &blocked_contents);
|
| + for (BlockedPopupContainer::BlockedContents::const_iterator
|
| + i(blocked_contents.begin()); i != blocked_contents.end(); ++i) {
|
| + std::string title(UTF16ToUTF8((*i)->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)->GetFavIcon();
|
| + popup_item.tab_contents = (*i);
|
| + add_popup(popup_item);
|
| }
|
| - if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) {
|
| - return new ContentSettingPopupBubbleModel(tab_contents, profile,
|
| - content_type);
|
| +}
|
| +
|
| +void ContentSettingPopupBubbleModel::OnPopupClicked(int index) {
|
| + if (tab_contents() && tab_contents()->blocked_popup_container()) {
|
| + tab_contents()->blocked_popup_container()->LaunchPopupForContents(
|
| + bubble_content().popup_items[index].tab_contents);
|
| }
|
| - return new ContentSettingSingleRadioGroup(tab_contents, profile,
|
| - content_type);
|
| +}
|
| +
|
| +ContentSettingGeolocationModel::ContentSettingGeolocationModel(
|
| + TabContents* tab_contents, Profile* profile)
|
| + : ContentSettingTitleAndLinkModel(
|
| + tab_contents, profile, CONTENT_SETTINGS_TYPE_GEOLOCATION) {
|
| + SetRadioGroups();
|
| +}
|
| +
|
| +void ContentSettingGeolocationModel::SetRadioGroups() {
|
| + const TabContents::GeolocationContentSettings& settings =
|
| + tab_contents()->geolocation_content_settings();
|
| + for (TabContents::GeolocationContentSettings::const_iterator i =
|
| + settings.begin(); i != settings.end(); ++i) {
|
| + RadioGroup radio_group;
|
| + radio_group.host = i->first;
|
| + radio_group.title = l10n_util::GetStringFUTF8(IDS_GEOLOCATION_RADIO_TITLE,
|
| + UTF8ToUTF16(i->first));
|
| + radio_group.radio_items.push_back(
|
| + l10n_util::GetStringUTF8(IDS_GEOLOCATION_RADIO_ALLOW));
|
| + radio_group.radio_items.push_back(
|
| + l10n_util::GetStringUTF8(IDS_GEOLOCATION_RADIO_BLOCK));
|
| + radio_group.default_item = i->second == CONTENT_SETTING_ALLOW ? 0 : 1;
|
| + add_radio_group(radio_group);
|
| + }
|
| +}
|
| +
|
| +void ContentSettingGeolocationModel::OnRadioClicked(
|
| + int radio_group, int radio_index) {
|
| + profile()->GetHostContentSettingsMap()->SetContentSetting(
|
| + bubble_content().radio_groups[radio_group].host,
|
| + CONTENT_SETTINGS_TYPE_GEOLOCATION,
|
| + radio_index == 0 ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK);
|
| }
|
|
|
| ContentSettingBubbleModel::ContentSettingBubbleModel(
|
| @@ -186,3 +242,21 @@ void ContentSettingBubbleModel::Observe(NotificationType type,
|
| DCHECK(source == Source<TabContents>(tab_contents_));
|
| tab_contents_ = NULL;
|
| }
|
| +
|
| +// static
|
| +ContentSettingBubbleModel*
|
| + ContentSettingBubbleModel::CreateContentSettingBubbleModel(
|
| + TabContents* tab_contents,
|
| + Profile* profile,
|
| + ContentSettingsType content_type) {
|
| + if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) {
|
| + return new ContentSettingTitleAndLinkModel(tab_contents, profile,
|
| + content_type);
|
| + }
|
| + if (content_type == CONTENT_SETTINGS_TYPE_POPUPS)
|
| + return new ContentSettingPopupBubbleModel(tab_contents, profile);
|
| + if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION)
|
| + return new ContentSettingGeolocationModel(tab_contents, profile);
|
| + return new ContentSettingSingleRadioGroup(tab_contents, profile,
|
| + content_type);
|
| +}
|
|
|