diff options
author | jbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-19 15:45:49 +0000 |
---|---|---|
committer | jbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-19 15:45:49 +0000 |
commit | 5d4451ebf298d9d71f716cc0135f465cec41fcd0 (patch) | |
tree | 4b7c389798e5f13614e603e2e8e310cb424a46d1 /chrome/browser/ui/content_settings | |
parent | c8d0c9e77e84c2aaa7f772b253c20c04450dc06b (diff) | |
download | chromium_src-5d4451ebf298d9d71f716cc0135f465cec41fcd0.zip chromium_src-5d4451ebf298d9d71f716cc0135f465cec41fcd0.tar.gz chromium_src-5d4451ebf298d9d71f716cc0135f465cec41fcd0.tar.bz2 |
Roll ANGLE r704:r705
BUG=
TEST=try
Review URL: http://codereview.chromium.org/7375016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93026 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/content_settings')
8 files changed, 0 insertions, 1330 deletions
diff --git a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc deleted file mode 100644 index 3c51731..0000000 --- a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc +++ /dev/null @@ -1,554 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" - -#include "base/command_line.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/content_settings/host_content_settings_map.h" -#include "chrome/browser/content_settings/tab_specific_content_settings.h" -#include "chrome/browser/favicon/favicon_tab_helper.h" -#include "chrome/browser/geolocation/geolocation_content_settings_map.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" -#include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/collected_cookies_infobar_delegate.h" -#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "chrome/common/chrome_notification_types.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/render_messages.h" -#include "content/browser/renderer_host/render_view_host.h" -#include "content/browser/tab_contents/tab_contents.h" -#include "content/browser/tab_contents/tab_contents_delegate.h" -#include "content/browser/user_metrics.h" -#include "content/common/notification_service.h" -#include "grit/generated_resources.h" -#include "net/base/net_util.h" -#include "ui/base/l10n/l10n_util.h" - -namespace { - -struct ContentSettingsTypeIdEntry { - ContentSettingsType type; - int id; -}; - -int GetIdForContentType(const ContentSettingsTypeIdEntry* entries, - size_t num_entries, - ContentSettingsType type) { - for (size_t i = 0; i < num_entries; ++i) { - if (entries[i].type == type) - return entries[i].id; - } - return 0; -} - -} - -class ContentSettingTitleAndLinkModel : public ContentSettingBubbleModel { - public: - ContentSettingTitleAndLinkModel(Browser* browser, - TabContentsWrapper* tab_contents, - Profile* profile, - ContentSettingsType content_type) - : ContentSettingBubbleModel(tab_contents, profile, content_type), - browser_(browser) { - // Notifications do not have a bubble. - DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); - SetBlockedResources(); - SetTitle(); - SetManageLink(); - } - - virtual ~ContentSettingTitleAndLinkModel() {} - Browser* browser() const { return browser_; } - - 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); - } - } - - 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}, - }; - // 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 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}, - }; - set_manage_link(l10n_util::GetStringUTF8( - GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); - } - - virtual void OnManageLinkClicked() { - if (browser_) - browser_->ShowContentSettingsPage(content_type()); - } - - Browser* browser_; -}; - -class ContentSettingTitleLinkAndCustomModel - : public ContentSettingTitleAndLinkModel { - public: - ContentSettingTitleLinkAndCustomModel(Browser* browser, - TabContentsWrapper* tab_contents, - Profile* profile, - ContentSettingsType content_type) - : ContentSettingTitleAndLinkModel( - browser, tab_contents, profile, content_type) { - SetCustomLink(); - } - - 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}, - }; - int custom_link_id = - GetIdForContentType(kCustomIDs, arraysize(kCustomIDs), content_type()); - if (custom_link_id) - set_custom_link(l10n_util::GetStringUTF8(custom_link_id)); - } - - virtual void OnCustomLinkClicked() {} -}; - - -class ContentSettingSingleRadioGroup - : public ContentSettingTitleLinkAndCustomModel { - public: - ContentSettingSingleRadioGroup(Browser* browser, - TabContentsWrapper* tab_contents, - Profile* profile, - ContentSettingsType content_type) - : ContentSettingTitleLinkAndCustomModel(browser, 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); - } - } - } - } - - protected: - bool settings_changed() const { - return selected_item_ != bubble_content().radio_group.default_item; - } - - private: - 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()->tab_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(); - ContentSetting mostRestrictiveSetting; - if (resources.empty()) { - mostRestrictiveSetting = - content_type() == CONTENT_SETTINGS_TYPE_COOKIES ? - map->GetCookieContentSetting(url, url, true) : - map->GetContentSetting(url, url, content_type(), std::string()); - } else { - mostRestrictiveSetting = CONTENT_SETTING_ALLOW; - for (std::set<std::string>::const_iterator it = resources.begin(); - it != resources.end(); ++it) { - ContentSetting setting = map->GetContentSetting(url, - url, - content_type(), - *it); - if (setting == CONTENT_SETTING_BLOCK) { - mostRestrictiveSetting = CONTENT_SETTING_BLOCK; - break; - } - if (setting == CONTENT_SETTING_ASK) - mostRestrictiveSetting = CONTENT_SETTING_ASK; - } - } - if (mostRestrictiveSetting == 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_ = mostRestrictiveSetting; - } - 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); - } - } - - virtual void OnRadioClicked(int radio_index) { - selected_item_ = radio_index; - } -}; - -class ContentSettingCookiesBubbleModel : public ContentSettingSingleRadioGroup { - public: - ContentSettingCookiesBubbleModel(Browser* browser, - TabContentsWrapper* tab_contents, - Profile* profile, - ContentSettingsType content_type) - : ContentSettingSingleRadioGroup( - browser, tab_contents, profile, content_type) { - DCHECK_EQ(CONTENT_SETTINGS_TYPE_COOKIES, content_type); - set_custom_link_enabled(true); - } - - virtual ~ContentSettingCookiesBubbleModel() { - if (settings_changed()) { - tab_contents()->AddInfoBar( - new CollectedCookiesInfoBarDelegate(tab_contents()->tab_contents())); - } - } - - private: - virtual void OnCustomLinkClicked() OVERRIDE { - if (!tab_contents()) - return; - NotificationService::current()->Notify( - chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, - Source<TabSpecificContentSettings>(tab_contents()->content_settings()), - NotificationService::NoDetails()); - browser()->ShowCollectedCookiesDialog(tab_contents()->tab_contents()); - } -}; - -class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup { - public: - ContentSettingPluginBubbleModel(Browser* browser, - TabContentsWrapper* tab_contents, - Profile* profile, - ContentSettingsType content_type) - : ContentSettingSingleRadioGroup( - browser, 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()); - } - - virtual ~ContentSettingPluginBubbleModel() {} - - private: - virtual void OnCustomLinkClicked() OVERRIDE { - UserMetrics::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble")); - DCHECK(tab_contents()); - RenderViewHost* host = tab_contents()->render_view_host(); - host->Send(new ViewMsg_LoadBlockedPlugins(host->routing_id())); - set_custom_link_enabled(false); - tab_contents()->content_settings()->set_load_plugins_link_enabled(false); - } -}; - -class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup { - public: - ContentSettingPopupBubbleModel(Browser* browser, - TabContentsWrapper* tab_contents, - Profile* profile, - ContentSettingsType content_type) - : ContentSettingSingleRadioGroup( - browser, tab_contents, profile, content_type) { - SetPopups(); - } - - virtual ~ContentSettingPopupBubbleModel() {} - - private: - void SetPopups() { - std::vector<TabContentsWrapper*> blocked_contents; - tab_contents()->blocked_content_tab_helper()-> - GetBlockedContents(&blocked_contents); - for (std::vector<TabContentsWrapper*>::const_iterator - i = blocked_contents.begin(); i != blocked_contents.end(); ++i) { - std::string title(UTF16ToUTF8((*i)->tab_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); - } - } -}; - -class ContentSettingDomainListBubbleModel - : public ContentSettingTitleAndLinkModel { - public: - ContentSettingDomainListBubbleModel(Browser* browser, - TabContentsWrapper* tab_contents, - Profile* profile, - ContentSettingsType content_type) - : ContentSettingTitleAndLinkModel( - browser, tab_contents, profile, content_type) { - DCHECK_EQ(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type) << - "SetDomains currently only supports geolocation content type"; - SetDomainsAndCustomLink(); - } - - 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 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()->tab_contents()->GetURL(); - TabSpecificContentSettings* content_settings = - tab_contents()->content_settings(); - const GeolocationSettingsState::StateMap& state_map = - content_settings->geolocation_settings_state().state_map(); - GeolocationContentSettingsMap* settings_map = - profile()->GetGeolocationContentSettingsMap(); - for (GeolocationSettingsState::StateMap::const_iterator it = - state_map.begin(); it != state_map.end(); ++it) { - settings_map->SetContentSetting(it->first, embedder_url, - CONTENT_SETTING_DEFAULT); - } - } -}; - -// static -ContentSettingBubbleModel* - ContentSettingBubbleModel::CreateContentSettingBubbleModel( - Browser* browser, - TabContentsWrapper* tab_contents, - Profile* profile, - ContentSettingsType content_type) { - if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { - return new ContentSettingCookiesBubbleModel(browser, tab_contents, profile, - content_type); - } - if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { - return new ContentSettingPopupBubbleModel(browser, tab_contents, profile, - content_type); - } - if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { - return new ContentSettingDomainListBubbleModel(browser, tab_contents, - profile, content_type); - } - if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { - return new ContentSettingPluginBubbleModel(browser, tab_contents, profile, - content_type); - } - return new ContentSettingSingleRadioGroup(browser, tab_contents, profile, - content_type); -} - -ContentSettingBubbleModel::ContentSettingBubbleModel( - TabContentsWrapper* tab_contents, - Profile* profile, - ContentSettingsType content_type) - : tab_contents_(tab_contents), - profile_(profile), - content_type_(content_type) { - registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, - Source<TabContents>(tab_contents->tab_contents())); - registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, - Source<Profile>(profile_)); -} - -ContentSettingBubbleModel::~ContentSettingBubbleModel() { -} - -ContentSettingBubbleModel::RadioGroup::RadioGroup() : default_item(0) {} - -ContentSettingBubbleModel::RadioGroup::~RadioGroup() {} - -ContentSettingBubbleModel::DomainList::DomainList() {} - -ContentSettingBubbleModel::DomainList::~DomainList() {} - -ContentSettingBubbleModel::BubbleContent::BubbleContent() - : custom_link_enabled(false) { -} - -ContentSettingBubbleModel::BubbleContent::~BubbleContent() {} - - -void ContentSettingBubbleModel::AddBlockedResource( - const std::string& resource_identifier) { - bubble_content_.resource_identifiers.insert(resource_identifier); -} - -void ContentSettingBubbleModel::Observe(int type, - const NotificationSource& source, - const NotificationDetails& details) { - switch (type) { - case content::NOTIFICATION_TAB_CONTENTS_DESTROYED: - DCHECK(source == Source<TabContents>(tab_contents_->tab_contents())); - tab_contents_ = NULL; - break; - case chrome::NOTIFICATION_PROFILE_DESTROYED: - DCHECK(source == Source<Profile>(profile_)); - profile_ = NULL; - break; - default: - NOTREACHED(); - } -} diff --git a/chrome/browser/ui/content_settings/content_setting_bubble_model.h b/chrome/browser/ui/content_settings/content_setting_bubble_model.h deleted file mode 100644 index ba99a0e..0000000 --- a/chrome/browser/ui/content_settings/content_setting_bubble_model.h +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_BUBBLE_MODEL_H_ -#define CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_BUBBLE_MODEL_H_ -#pragma once - -#include <set> -#include <string> -#include <vector> - -#include "chrome/common/content_settings.h" -#include "content/common/notification_observer.h" -#include "content/common/notification_registrar.h" -#include "googleurl/src/gurl.h" -#include "third_party/skia/include/core/SkBitmap.h" - -class Browser; -class Profile; -class SkBitmap; -class TabContentsWrapper; - -// This model provides data for ContentSettingBubble, and also controls -// the action triggered when the allow / block radio buttons are triggered. -class ContentSettingBubbleModel : public NotificationObserver { - public: - virtual ~ContentSettingBubbleModel(); - - static ContentSettingBubbleModel* CreateContentSettingBubbleModel( - Browser* browser, - TabContentsWrapper* tab_contents, - Profile* profile, - ContentSettingsType content_type); - - ContentSettingsType content_type() const { return content_type_; } - - struct PopupItem { - SkBitmap bitmap; - std::string title; - TabContentsWrapper* tab_contents; - }; - typedef std::vector<PopupItem> PopupItems; - - typedef std::vector<std::string> RadioItems; - struct RadioGroup { - RadioGroup(); - ~RadioGroup(); - - GURL url; - std::string title; - RadioItems radio_items; - int default_item; - }; - - struct DomainList { - DomainList(); - ~DomainList(); - - std::string title; - std::set<std::string> hosts; - }; - - struct BubbleContent { - BubbleContent(); - ~BubbleContent(); - - std::string title; - PopupItems popup_items; - RadioGroup radio_group; - std::vector<DomainList> domain_lists; - std::set<std::string> resource_identifiers; - std::string custom_link; - bool custom_link_enabled; - std::string manage_link; - - private: - DISALLOW_COPY_AND_ASSIGN(BubbleContent); - }; - - const BubbleContent& bubble_content() const { return bubble_content_; } - - // NotificationObserver: - virtual void Observe(int type, - const NotificationSource& source, - const NotificationDetails& details); - - virtual void OnRadioClicked(int radio_index) {} - virtual void OnPopupClicked(int index) {} - virtual void OnCustomLinkClicked() {} - virtual void OnManageLinkClicked() {} - - protected: - ContentSettingBubbleModel(TabContentsWrapper* tab_contents, Profile* profile, - ContentSettingsType content_type); - - TabContentsWrapper* tab_contents() const { return tab_contents_; } - Profile* profile() const { return profile_; } - - void set_title(const std::string& title) { bubble_content_.title = title; } - void add_popup(const PopupItem& popup) { - bubble_content_.popup_items.push_back(popup); - } - void set_radio_group(const RadioGroup& radio_group) { - bubble_content_.radio_group = radio_group; - } - void add_domain_list(const DomainList& domain_list) { - bubble_content_.domain_lists.push_back(domain_list); - } - void set_custom_link(const std::string& link) { - bubble_content_.custom_link = link; - } - void set_custom_link_enabled(bool enabled) { - bubble_content_.custom_link_enabled = enabled; - } - void set_manage_link(const std::string& link) { - bubble_content_.manage_link = link; - } - void AddBlockedResource(const std::string& resource_identifier); - - private: - TabContentsWrapper* tab_contents_; - Profile* profile_; - ContentSettingsType content_type_; - BubbleContent bubble_content_; - // A registrar for listening for TAB_CONTENTS_DESTROYED notifications. - NotificationRegistrar registrar_; -}; - -#endif // CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_BUBBLE_MODEL_H_ diff --git a/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc b/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc deleted file mode 100644 index 01b2ebf..0000000 --- a/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc +++ /dev/null @@ -1,217 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/auto_reset.h" -#include "base/command_line.h" -#include "chrome/browser/content_settings/host_content_settings_map.h" -#include "chrome/browser/content_settings/tab_specific_content_settings.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/geolocation/geolocation_content_settings_map.h" -#include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" -#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/test/testing_profile.h" -#include "content/browser/browser_thread.h" -#include "content/browser/tab_contents/test_tab_contents.h" -#include "testing/gtest/include/gtest/gtest.h" - -class ContentSettingBubbleModelTest : public TabContentsWrapperTestHarness { - protected: - ContentSettingBubbleModelTest() - : ui_thread_(BrowserThread::UI, MessageLoop::current()) { - } - - void CheckGeolocationBubble(size_t expected_domains, - bool expect_clear_link, - bool expect_reload_hint) { - scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( - ContentSettingBubbleModel::CreateContentSettingBubbleModel( - NULL, contents_wrapper(), profile_.get(), - CONTENT_SETTINGS_TYPE_GEOLOCATION)); - const ContentSettingBubbleModel::BubbleContent& bubble_content = - content_setting_bubble_model->bubble_content(); - EXPECT_TRUE(bubble_content.title.empty()); - EXPECT_TRUE(bubble_content.radio_group.radio_items.empty()); - EXPECT_TRUE(bubble_content.popup_items.empty()); - EXPECT_EQ(expected_domains, bubble_content.domain_lists.size()); - EXPECT_NE(expect_clear_link || expect_reload_hint, - bubble_content.custom_link.empty()); - EXPECT_EQ(expect_clear_link, bubble_content.custom_link_enabled); - EXPECT_FALSE(bubble_content.manage_link.empty()); - } - - BrowserThread ui_thread_; -}; - -TEST_F(ContentSettingBubbleModelTest, ImageRadios) { - TabSpecificContentSettings* content_settings = - contents_wrapper()->content_settings(); - content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, - std::string()); - - scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( - ContentSettingBubbleModel::CreateContentSettingBubbleModel( - NULL, contents_wrapper(), profile_.get(), - CONTENT_SETTINGS_TYPE_IMAGES)); - const ContentSettingBubbleModel::BubbleContent& bubble_content = - content_setting_bubble_model->bubble_content(); - EXPECT_FALSE(bubble_content.title.empty()); - EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); - EXPECT_EQ(0, bubble_content.radio_group.default_item); - EXPECT_TRUE(bubble_content.custom_link.empty()); - EXPECT_FALSE(bubble_content.manage_link.empty()); -} - -TEST_F(ContentSettingBubbleModelTest, Cookies) { - TabSpecificContentSettings* content_settings = - contents_wrapper()->content_settings(); - content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, - std::string()); - - scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( - ContentSettingBubbleModel::CreateContentSettingBubbleModel( - NULL, contents_wrapper(), profile_.get(), - CONTENT_SETTINGS_TYPE_COOKIES)); - const ContentSettingBubbleModel::BubbleContent& bubble_content = - content_setting_bubble_model->bubble_content(); - EXPECT_FALSE(bubble_content.title.empty()); - EXPECT_FALSE(bubble_content.radio_group.radio_items.empty()); - EXPECT_FALSE(bubble_content.custom_link.empty()); - EXPECT_TRUE(bubble_content.custom_link_enabled); - EXPECT_FALSE(bubble_content.manage_link.empty()); -} - -TEST_F(ContentSettingBubbleModelTest, Plugins) { - TabSpecificContentSettings* content_settings = - contents_wrapper()->content_settings(); - content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS, - std::string()); - - scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( - ContentSettingBubbleModel::CreateContentSettingBubbleModel( - NULL, contents_wrapper(), profile_.get(), - CONTENT_SETTINGS_TYPE_PLUGINS)); - const ContentSettingBubbleModel::BubbleContent& bubble_content = - content_setting_bubble_model->bubble_content(); - EXPECT_FALSE(bubble_content.title.empty()); - EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); - EXPECT_FALSE(bubble_content.custom_link.empty()); - EXPECT_TRUE(bubble_content.custom_link_enabled); - EXPECT_FALSE(bubble_content.manage_link.empty()); -} - -TEST_F(ContentSettingBubbleModelTest, MultiplePlugins) { - CommandLine* cmd = CommandLine::ForCurrentProcess(); - AutoReset<CommandLine> auto_reset(cmd, *cmd); - cmd->AppendSwitch(switches::kEnableResourceContentSettings); - cmd->AppendSwitch(switches::kEnableClickToPlay); - - HostContentSettingsMap* map = profile_->GetHostContentSettingsMap(); - std::string fooPlugin = "foo"; - std::string barPlugin = "bar"; - - // Navigating to some sample url prevents the GetURL method from returning an - // invalid empty URL. - contents()->NavigateAndCommit(GURL("http://www.example.com")); - GURL url = contents()->GetURL(); - map->AddExceptionForURL(url, - url, - CONTENT_SETTINGS_TYPE_PLUGINS, - fooPlugin, - CONTENT_SETTING_ALLOW); - map->AddExceptionForURL(url, - url, - CONTENT_SETTINGS_TYPE_PLUGINS, - barPlugin, - CONTENT_SETTING_ASK); - - TabSpecificContentSettings* content_settings = - contents_wrapper()->content_settings(); - content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS, - fooPlugin); - content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS, - barPlugin); - - scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( - ContentSettingBubbleModel::CreateContentSettingBubbleModel( - NULL, contents_wrapper(), profile_.get(), - CONTENT_SETTINGS_TYPE_PLUGINS)); - const ContentSettingBubbleModel::BubbleContent& bubble_content = - content_setting_bubble_model->bubble_content(); - EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); - EXPECT_EQ(1, bubble_content.radio_group.default_item); - - content_setting_bubble_model->OnRadioClicked(0); - // Nothing should have changed. - EXPECT_EQ(CONTENT_SETTING_ALLOW, - map->GetContentSetting(url, - url, - CONTENT_SETTINGS_TYPE_PLUGINS, - fooPlugin)); - EXPECT_EQ(CONTENT_SETTING_ASK, - map->GetContentSetting(url, - url, - CONTENT_SETTINGS_TYPE_PLUGINS, - barPlugin)); - - content_setting_bubble_model.reset(); - // Both plug-ins should be click-to-play now. - EXPECT_EQ(CONTENT_SETTING_ALLOW, - map->GetContentSetting(url, - url, - CONTENT_SETTINGS_TYPE_PLUGINS, - fooPlugin)); - EXPECT_EQ(CONTENT_SETTING_ALLOW, - map->GetContentSetting(url, - url, - CONTENT_SETTINGS_TYPE_PLUGINS, - barPlugin)); -} - -TEST_F(ContentSettingBubbleModelTest, Geolocation) { - const GURL page_url("http://toplevel.example/"); - const GURL frame1_url("http://host1.example/"); - const GURL frame2_url("http://host2.example:999/"); - - NavigateAndCommit(page_url); - TabSpecificContentSettings* content_settings = - contents_wrapper()->content_settings(); - - // One permitted frame, but not in the content map: requires reload. - content_settings->OnGeolocationPermissionSet(frame1_url, true); - CheckGeolocationBubble(1, false, true); - - // Add it to the content map, should now have a clear link. - GeolocationContentSettingsMap* setting_map = - profile_->GetGeolocationContentSettingsMap(); - setting_map->SetContentSetting(frame1_url, page_url, CONTENT_SETTING_ALLOW); - CheckGeolocationBubble(1, true, false); - - // Change the default to allow: no message needed. - profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( - CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_ALLOW); - CheckGeolocationBubble(1, false, false); - - // Second frame denied, but not stored in the content map: requires reload. - content_settings->OnGeolocationPermissionSet(frame2_url, false); - CheckGeolocationBubble(2, false, true); - - // Change the default to block: offer a clear link for the persisted frame 1. - profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( - CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_BLOCK); - CheckGeolocationBubble(2, true, false); -} - -TEST_F(ContentSettingBubbleModelTest, FileURL) { - std::string file_url("file:///tmp/test.html"); - NavigateAndCommit(GURL(file_url)); - scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( - ContentSettingBubbleModel::CreateContentSettingBubbleModel( - NULL, contents_wrapper(), profile_.get(), - CONTENT_SETTINGS_TYPE_IMAGES)); - std::string title = - content_setting_bubble_model->bubble_content().radio_group.radio_items[0]; - ASSERT_NE(std::string::npos, title.find(file_url)); -} diff --git a/chrome/browser/ui/content_settings/content_setting_combo_model.cc b/chrome/browser/ui/content_settings/content_setting_combo_model.cc deleted file mode 100644 index a6dd38e..0000000 --- a/chrome/browser/ui/content_settings/content_setting_combo_model.cc +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/content_settings/content_setting_combo_model.h" - -#include "base/command_line.h" -#include "base/string16.h" -#include "chrome/common/chrome_switches.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" - -namespace { - -// The settings shown in the combobox if show_session_ is false; -const ContentSetting kNoSessionSettings[] = { CONTENT_SETTING_ALLOW, - CONTENT_SETTING_BLOCK }; - -// The settings shown in the combobox if show_session_ is true; -const ContentSetting kSessionSettings[] = { CONTENT_SETTING_ALLOW, - CONTENT_SETTING_SESSION_ONLY, - CONTENT_SETTING_BLOCK }; - -// The settings shown in the combobox for plug-ins; -const ContentSetting kAskSettings[] = { CONTENT_SETTING_ALLOW, - CONTENT_SETTING_ASK, - CONTENT_SETTING_BLOCK }; - -} // namespace - -ContentSettingComboModel::ContentSettingComboModel(ContentSettingsType type) - : content_type_(type) { -} - -ContentSettingComboModel::~ContentSettingComboModel() { -} - -int ContentSettingComboModel::GetItemCount() { - if (content_type_ == CONTENT_SETTINGS_TYPE_PLUGINS && - CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableClickToPlay)) - return arraysize(kAskSettings); - if (content_type_ == CONTENT_SETTINGS_TYPE_COOKIES) - return arraysize(kSessionSettings); - return arraysize(kNoSessionSettings); -} - -string16 ContentSettingComboModel::GetItemAt(int index) { - switch (SettingForIndex(index)) { - case CONTENT_SETTING_ALLOW: - return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ALLOW_BUTTON); - case CONTENT_SETTING_BLOCK: - return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON); - case CONTENT_SETTING_ASK: - return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ASK_BUTTON); - case CONTENT_SETTING_SESSION_ONLY: - return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_SESSION_ONLY_BUTTON); - default: - NOTREACHED(); - } - return string16(); -} - -ContentSetting ContentSettingComboModel::SettingForIndex(int index) { - if (content_type_ == CONTENT_SETTINGS_TYPE_PLUGINS && - CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableClickToPlay)) - return kAskSettings[index]; - if (content_type_ == CONTENT_SETTINGS_TYPE_COOKIES) - return kSessionSettings[index]; - return kNoSessionSettings[index]; -} - -int ContentSettingComboModel::IndexForSetting(ContentSetting setting) { - for (int i = 0; i < GetItemCount(); ++i) - if (SettingForIndex(i) == setting) - return i; - NOTREACHED(); - return 0; -} diff --git a/chrome/browser/ui/content_settings/content_setting_combo_model.h b/chrome/browser/ui/content_settings/content_setting_combo_model.h deleted file mode 100644 index 2502188..0000000 --- a/chrome/browser/ui/content_settings/content_setting_combo_model.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_COMBO_MODEL_H_ -#define CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_COMBO_MODEL_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/string16.h" -#include "chrome/common/content_settings.h" -#include "ui/base/models/combobox_model.h" - -class ContentSettingComboModel : public ui::ComboboxModel { - public: - explicit ContentSettingComboModel(ContentSettingsType content_type); - virtual ~ContentSettingComboModel(); - - virtual int GetItemCount(); - virtual string16 GetItemAt(int index); - - ContentSetting SettingForIndex(int index); - - int IndexForSetting(ContentSetting); - - private: - const ContentSettingsType content_type_; - - DISALLOW_COPY_AND_ASSIGN(ContentSettingComboModel); -}; - -#endif // CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_COMBO_MODEL_H_ diff --git a/chrome/browser/ui/content_settings/content_setting_image_model.cc b/chrome/browser/ui/content_settings/content_setting_image_model.cc deleted file mode 100644 index 80eaf8a..0000000 --- a/chrome/browser/ui/content_settings/content_setting_image_model.cc +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/content_settings/content_setting_image_model.h" - -#include "base/command_line.h" -#include "chrome/browser/content_settings/host_content_settings_map.h" -#include "chrome/browser/content_settings/tab_specific_content_settings.h" -#include "chrome/browser/prerender/prerender_manager.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "content/browser/tab_contents/tab_contents.h" -#include "grit/generated_resources.h" -#include "grit/theme_resources.h" -#include "grit/theme_resources_standard.h" -#include "ui/base/l10n/l10n_util.h" - -class ContentSettingBlockedImageModel : public ContentSettingImageModel { - public: - explicit ContentSettingBlockedImageModel( - ContentSettingsType content_settings_type); - - virtual void UpdateFromTabContents(TabContents* tab_contents); - - private: - static const int kAccessedIconIDs[]; - static const int kBlockedIconIDs[]; - static const int kBlockedExplanatoryTextIDs[]; - static const int kAccessedExplanatoryTextIDs[]; - static const int kAccessedTooltipIDs[]; - static const int kBlockedTooltipIDs[]; -}; - -class ContentSettingGeolocationImageModel : public ContentSettingImageModel { - public: - ContentSettingGeolocationImageModel(); - - virtual void UpdateFromTabContents(TabContents* tab_contents) OVERRIDE; -}; - -class ContentSettingNotificationsImageModel : public ContentSettingImageModel { - public: - ContentSettingNotificationsImageModel(); - - virtual void UpdateFromTabContents(TabContents* tab_contents) OVERRIDE; -}; - -const int ContentSettingBlockedImageModel::kBlockedIconIDs[] = { - IDR_BLOCKED_COOKIES, - IDR_BLOCKED_IMAGES, - IDR_BLOCKED_JAVASCRIPT, - IDR_BLOCKED_PLUGINS, - IDR_BLOCKED_POPUPS, -}; - -const int ContentSettingBlockedImageModel::kAccessedIconIDs[] = { - IDR_ACCESSED_COOKIES, - 0, - 0, - 0, - 0, -}; - -const int ContentSettingBlockedImageModel::kBlockedExplanatoryTextIDs[] = { - 0, - 0, - 0, - 0, - IDS_BLOCKED_POPUPS_EXPLANATORY_TEXT, -}; - -const int ContentSettingBlockedImageModel::kAccessedExplanatoryTextIDs[] = { - 0, - 0, - 0, - 0, - 0, -}; - - -const int ContentSettingBlockedImageModel::kBlockedTooltipIDs[] = { - IDS_BLOCKED_COOKIES_TITLE, - IDS_BLOCKED_IMAGES_TITLE, - IDS_BLOCKED_JAVASCRIPT_TITLE, - IDS_BLOCKED_PLUGINS_MESSAGE, - IDS_BLOCKED_POPUPS_TOOLTIP, -}; - -const int ContentSettingBlockedImageModel::kAccessedTooltipIDs[] = { - IDS_ACCESSED_COOKIES_TITLE, - 0, - 0, - 0, - 0, -}; - -ContentSettingBlockedImageModel::ContentSettingBlockedImageModel( - ContentSettingsType content_settings_type) - : ContentSettingImageModel(content_settings_type) { -} - -void ContentSettingBlockedImageModel::UpdateFromTabContents( - TabContents* tab_contents) { - set_visible(false); - if (!tab_contents) - return; - - const int* icon_ids = kBlockedIconIDs; - const int* tooltip_ids = kBlockedTooltipIDs; - const int* explanatory_string_ids = kBlockedExplanatoryTextIDs; - // If a content type is blocked by default and was accessed, display the - // accessed icon. - TabSpecificContentSettings* content_settings = - TabContentsWrapper::GetCurrentWrapperForContents(tab_contents)-> - content_settings(); - if (!content_settings->IsContentBlocked(get_content_settings_type())) { - if (!content_settings->IsContentAccessed(get_content_settings_type()) || - (tab_contents->profile()->GetHostContentSettingsMap()-> - GetDefaultContentSetting(get_content_settings_type()) != - CONTENT_SETTING_BLOCK)) - return; - icon_ids = kAccessedIconIDs; - tooltip_ids = kAccessedTooltipIDs; - explanatory_string_ids = kAccessedExplanatoryTextIDs; - } - set_visible(true); - set_icon(icon_ids[get_content_settings_type()]); - set_explanatory_string_id( - explanatory_string_ids[get_content_settings_type()]); - set_tooltip( - l10n_util::GetStringUTF8(tooltip_ids[get_content_settings_type()])); -} - -ContentSettingGeolocationImageModel::ContentSettingGeolocationImageModel() - : ContentSettingImageModel(CONTENT_SETTINGS_TYPE_GEOLOCATION) { -} - -void ContentSettingGeolocationImageModel::UpdateFromTabContents( - TabContents* tab_contents) { - set_visible(false); - if (!tab_contents) - return; - TabSpecificContentSettings* content_settings = - TabContentsWrapper::GetCurrentWrapperForContents(tab_contents)-> - content_settings(); - const GeolocationSettingsState& settings_state = content_settings-> - geolocation_settings_state(); - if (settings_state.state_map().empty()) - return; - set_visible(true); - - // If any embedded site has access the allowed icon takes priority over the - // blocked icon. - unsigned int tab_state_flags = 0; - settings_state.GetDetailedInfo(NULL, &tab_state_flags); - bool allowed = - !!(tab_state_flags & GeolocationSettingsState::TABSTATE_HAS_ANY_ALLOWED); - set_icon(allowed ? IDR_GEOLOCATION_ALLOWED_LOCATIONBAR_ICON : - IDR_GEOLOCATION_DENIED_LOCATIONBAR_ICON); - set_tooltip(l10n_util::GetStringUTF8(allowed ? - IDS_GEOLOCATION_ALLOWED_TOOLTIP : IDS_GEOLOCATION_BLOCKED_TOOLTIP)); -} - -ContentSettingNotificationsImageModel::ContentSettingNotificationsImageModel() - : ContentSettingImageModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { -} - -void ContentSettingNotificationsImageModel::UpdateFromTabContents( - TabContents* tab_contents) { - // Notifications do not have a bubble. - set_visible(false); -} - -ContentSettingImageModel::ContentSettingImageModel( - ContentSettingsType content_settings_type) - : content_settings_type_(content_settings_type), - is_visible_(false), - icon_(0), - explanatory_string_id_(0) { -} - -// static -ContentSettingImageModel* - ContentSettingImageModel::CreateContentSettingImageModel( - ContentSettingsType content_settings_type) { - switch (content_settings_type) { - case CONTENT_SETTINGS_TYPE_GEOLOCATION: - return new ContentSettingGeolocationImageModel(); - case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: - return new ContentSettingNotificationsImageModel(); - default: - return new ContentSettingBlockedImageModel(content_settings_type); - } -} diff --git a/chrome/browser/ui/content_settings/content_setting_image_model.h b/chrome/browser/ui/content_settings/content_setting_image_model.h deleted file mode 100644 index 686ab07..0000000 --- a/chrome/browser/ui/content_settings/content_setting_image_model.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_IMAGE_MODEL_H_ -#define CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_IMAGE_MODEL_H_ -#pragma once - -#include <string> - -#include "chrome/common/content_settings_types.h" - -class TabContents; - -// This model provides data (icon ids and tooltip) for the content setting icons -// that are displayed in the location bar. -class ContentSettingImageModel { - public: - virtual ~ContentSettingImageModel() {} - - // Factory function. - static ContentSettingImageModel* CreateContentSettingImageModel( - ContentSettingsType content_settings_type); - - // Notifies this model that its setting might have changed and it may need to - // update its visibility, icon and tooltip. - virtual void UpdateFromTabContents(TabContents* tab_contents) = 0; - - ContentSettingsType get_content_settings_type() const { - return content_settings_type_; - } - bool is_visible() const { return is_visible_; } - int get_icon() const { return icon_; } - // Returns the resource ID of a string to show when the icon appears, or 0 if - // we don't wish to show anything. - int explanatory_string_id() const { return explanatory_string_id_; } - std::string get_tooltip() const { return tooltip_; } - - protected: - explicit ContentSettingImageModel(ContentSettingsType content_settings_type); - void set_visible(bool visible) { is_visible_ = visible; } - void set_icon(int icon) { icon_ = icon; } - void set_explanatory_string_id(int text_id) { - explanatory_string_id_ = text_id; - } - void set_tooltip(const std::string& tooltip) { tooltip_ = tooltip; } - - private: - const ContentSettingsType content_settings_type_; - bool is_visible_; - int icon_; - int explanatory_string_id_; - std::string tooltip_; -}; - -#endif // CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_IMAGE_MODEL_H_ diff --git a/chrome/browser/ui/content_settings/content_setting_image_model_unittest.cc b/chrome/browser/ui/content_settings/content_setting_image_model_unittest.cc deleted file mode 100644 index 1357793..0000000 --- a/chrome/browser/ui/content_settings/content_setting_image_model_unittest.cc +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/content_settings/host_content_settings_map.h" -#include "chrome/browser/content_settings/tab_specific_content_settings.h" -#include "chrome/browser/prerender/prerender_manager.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/content_settings/content_setting_image_model.h" -#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" -#include "chrome/test/testing_profile.h" -#include "content/browser/browser_thread.h" -#include "content/browser/renderer_host/test_render_view_host.h" -#include "content/browser/tab_contents/test_tab_contents.h" -#include "net/base/cookie_options.h" -#include "testing/gtest/include/gtest/gtest.h" - -class ContentSettingImageModelTest : public TabContentsWrapperTestHarness { - public: - ContentSettingImageModelTest() - : ui_thread_(BrowserThread::UI, &message_loop_) {} - - private: - BrowserThread ui_thread_; - - DISALLOW_COPY_AND_ASSIGN(ContentSettingImageModelTest); -}; - -TEST_F(ContentSettingImageModelTest, UpdateFromTabContents) { - TabSpecificContentSettings* content_settings = - contents_wrapper()->content_settings(); - scoped_ptr<ContentSettingImageModel> content_setting_image_model( - ContentSettingImageModel::CreateContentSettingImageModel( - CONTENT_SETTINGS_TYPE_IMAGES)); - EXPECT_FALSE(content_setting_image_model->is_visible()); - EXPECT_EQ(0, content_setting_image_model->get_icon()); - EXPECT_TRUE(content_setting_image_model->get_tooltip().empty()); - - content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, - std::string()); - content_setting_image_model->UpdateFromTabContents(contents()); - - EXPECT_TRUE(content_setting_image_model->is_visible()); - EXPECT_NE(0, content_setting_image_model->get_icon()); - EXPECT_FALSE(content_setting_image_model->get_tooltip().empty()); -} - -TEST_F(ContentSettingImageModelTest, CookieAccessed) { - TabSpecificContentSettings* content_settings = - contents_wrapper()->content_settings(); - profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( - CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); - scoped_ptr<ContentSettingImageModel> content_setting_image_model( - ContentSettingImageModel::CreateContentSettingImageModel( - CONTENT_SETTINGS_TYPE_COOKIES)); - EXPECT_FALSE(content_setting_image_model->is_visible()); - EXPECT_EQ(0, content_setting_image_model->get_icon()); - EXPECT_TRUE(content_setting_image_model->get_tooltip().empty()); - - net::CookieOptions options; - content_settings->OnCookieChanged( - GURL("http://google.com"), "A=B", options, false); - content_setting_image_model->UpdateFromTabContents(contents()); - EXPECT_TRUE(content_setting_image_model->is_visible()); - EXPECT_NE(0, content_setting_image_model->get_icon()); - EXPECT_FALSE(content_setting_image_model->get_tooltip().empty()); -} |