diff options
author | markusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-08 19:08:32 +0000 |
---|---|---|
committer | markusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-08 19:08:32 +0000 |
commit | 1cf786aad88dbf7a4f4565f5c5288cdd160d1f16 (patch) | |
tree | 17b8452fe27a4b1e197a3fd32e4314b7b4c6d5e0 /chrome | |
parent | 042e95f1309e6bd8dc77d4bce184d9aa2f5f6619 (diff) | |
download | chromium_src-1cf786aad88dbf7a4f4565f5c5288cdd160d1f16.zip chromium_src-1cf786aad88dbf7a4f4565f5c5288cdd160d1f16.tar.gz chromium_src-1cf786aad88dbf7a4f4565f5c5288cdd160d1f16.tar.bz2 |
Lock the GTK UI of the content settings bubble if the corresponding content settings type is managed.
BUG=98029
TEST=HostContentSettingsMap*
Review URL: http://codereview.chromium.org/8493013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109068 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
11 files changed, 172 insertions, 83 deletions
diff --git a/chrome/browser/content_settings/cookie_settings.cc b/chrome/browser/content_settings/cookie_settings.cc index 4a345d6..8ff471a 100644 --- a/chrome/browser/content_settings/cookie_settings.cc +++ b/chrome/browser/content_settings/cookie_settings.cc @@ -69,7 +69,7 @@ CookieSettings::Factory* CookieSettings::Factory::GetInstance() { CookieSettingsWrapper* CookieSettings::Factory::GetWrapperForProfile( Profile* profile) { return static_cast<CookieSettingsWrapper*>( - GetServiceForProfile(profile,true)); + GetServiceForProfile(profile, true)); } CookieSettings::Factory::Factory() @@ -122,18 +122,18 @@ CookieSettings::GetDefaultCookieSetting(std::string* provider_id) const { bool CookieSettings::IsReadingCookieAllowed(const GURL& url, const GURL& first_party_url) const { - ContentSetting setting = GetCookieSetting(url, first_party_url, false); + ContentSetting setting = GetCookieSetting(url, first_party_url, false, NULL); return IsAllowed(setting); } bool CookieSettings::IsSettingCookieAllowed(const GURL& url, const GURL& first_party_url) const { - ContentSetting setting = GetCookieSetting(url, first_party_url, true); + ContentSetting setting = GetCookieSetting(url, first_party_url, true, NULL); return IsAllowed(setting); } bool CookieSettings::IsCookieSessionOnly(const GURL& origin) const { - ContentSetting setting = GetCookieSetting(origin, origin, true); + ContentSetting setting = GetCookieSetting(origin, origin, true, NULL); DCHECK(IsValidSetting(setting)); return (setting == CONTENT_SETTING_SESSION_ONLY); } @@ -200,23 +200,24 @@ void CookieSettings::ShutdownOnUIThread() { ContentSetting CookieSettings::GetCookieSetting( const GURL& url, const GURL& first_party_url, - bool setting_cookie) const { + bool setting_cookie, + content_settings::SettingSource* source) const { if (HostContentSettingsMap::ShouldAllowAllContent( url, first_party_url, CONTENT_SETTINGS_TYPE_COOKIES)) return CONTENT_SETTING_ALLOW; - ContentSettingsPattern primary_pattern; - ContentSettingsPattern secondary_pattern; // First get any host-specific settings. + content_settings::SettingInfo info; scoped_ptr<base::Value> value( - host_content_settings_map_->GetContentSettingValue( - url, first_party_url, CONTENT_SETTINGS_TYPE_COOKIES, "", - &primary_pattern, &secondary_pattern)); + host_content_settings_map_->GetWebsiteSetting( + url, first_party_url, CONTENT_SETTINGS_TYPE_COOKIES, "", &info)); + if (source) + *source = info.source; // If no explicit exception has been made and third-party cookies are blocked // by default, apply that rule. - if (primary_pattern == ContentSettingsPattern::Wildcard() && - secondary_pattern == ContentSettingsPattern::Wildcard() && + if (info.primary_pattern == ContentSettingsPattern::Wildcard() && + info.secondary_pattern == ContentSettingsPattern::Wildcard() && ShouldBlockThirdPartyCookies() && !first_party_url.SchemeIs(chrome::kExtensionScheme)) { bool not_strict = CommandLine::ForCurrentProcess()->HasSwitch( diff --git a/chrome/browser/content_settings/cookie_settings.h b/chrome/browser/content_settings/cookie_settings.h index 1ad491c..394d7b6 100644 --- a/chrome/browser/content_settings/cookie_settings.h +++ b/chrome/browser/content_settings/cookie_settings.h @@ -109,9 +109,11 @@ class CookieSettings void ShutdownOnUIThread(); // A helper for applying third party cookie blocking rules. - ContentSetting GetCookieSetting(const GURL& url, - const GURL& first_party_url, - bool setting_cookie) const; + ContentSetting GetCookieSetting( + const GURL& url, + const GURL& first_party_url, + bool setting_cookie, + content_settings::SettingSource* source) const; static void RegisterUserPrefs(PrefService* prefs); diff --git a/chrome/browser/content_settings/host_content_settings_map.cc b/chrome/browser/content_settings/host_content_settings_map.cc index 13da43c..6aa63b0 100644 --- a/chrome/browser/content_settings/host_content_settings_map.cc +++ b/chrome/browser/content_settings/host_content_settings_map.cc @@ -6,6 +6,7 @@ #include <utility> +#include "base/basictypes.h" #include "base/command_line.h" #include "base/stl_util.h" #include "base/string_util.h" @@ -50,6 +51,16 @@ const char* kProviderNames[] = { "default" }; +content_settings::SettingSource kProviderSourceMap[] = { + content_settings::SETTING_SOURCE_POLICY, + content_settings::SETTING_SOURCE_EXTENSION, + content_settings::SETTING_SOURCE_USER, + content_settings::SETTING_SOURCE_USER, +}; +COMPILE_ASSERT(arraysize(kProviderSourceMap) == + HostContentSettingsMap::NUM_PROVIDER_TYPES, + kProviderSourceMap_has_incorrect_size); + bool ContentTypeHasCompoundValue(ContentSettingsType type) { // Values for content type CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE are // of type dictionary/map. Compound types like dictionaries can't be mapped to @@ -167,41 +178,11 @@ ContentSetting HostContentSettingsMap::GetContentSetting( const GURL& secondary_url, ContentSettingsType content_type, const std::string& resource_identifier) const { - scoped_ptr<base::Value> value(GetContentSettingValue( - primary_url, secondary_url, content_type, resource_identifier, - NULL, NULL)); + scoped_ptr<base::Value> value(GetWebsiteSetting( + primary_url, secondary_url, content_type, resource_identifier, NULL)); return content_settings::ValueToContentSetting(value.get()); } -base::Value* HostContentSettingsMap::GetContentSettingValue( - const GURL& primary_url, - const GURL& secondary_url, - ContentSettingsType content_type, - const std::string& resource_identifier, - ContentSettingsPattern* primary_pattern, - ContentSettingsPattern* secondary_pattern) const { - DCHECK(content_settings::SupportsResourceIdentifier(content_type) || - resource_identifier.empty()); - - // Check if the scheme of the requesting url is whitelisted. - if (ShouldAllowAllContent(primary_url, secondary_url, content_type)) - return Value::CreateIntegerValue(CONTENT_SETTING_ALLOW); - - // The list of |content_settings_providers_| is ordered according to their - // precedence. - for (ConstProviderIterator provider = content_settings_providers_.begin(); - provider != content_settings_providers_.end(); - ++provider) { - base::Value* value = content_settings::GetContentSettingValueAndPatterns( - provider->second, primary_url, secondary_url, content_type, - resource_identifier, is_off_the_record_, - primary_pattern, secondary_pattern); - if (value) - return value; - } - return NULL; -} - ContentSettings HostContentSettingsMap::GetContentSettings( const GURL& primary_url) const { ContentSettings output; @@ -418,3 +399,53 @@ bool HostContentSettingsMap::ShouldAllowAllContent( primary_url.SchemeIs(chrome::kChromeInternalScheme) || primary_url.SchemeIs(chrome::kChromeUIScheme); } + +base::Value* HostContentSettingsMap::GetWebsiteSetting( + const GURL& primary_url, + const GURL& secondary_url, + ContentSettingsType content_type, + const std::string& resource_identifier, + content_settings::SettingInfo* info) const { + DCHECK(content_settings::SupportsResourceIdentifier(content_type) || + resource_identifier.empty()); + + // Check if the scheme of the requesting url is whitelisted. + if (ShouldAllowAllContent(primary_url, secondary_url, content_type)) { + if (info) { + info->source = content_settings::SETTING_SOURCE_WHITELIST; + info->primary_pattern = ContentSettingsPattern::Wildcard(); + info->secondary_pattern = ContentSettingsPattern::Wildcard(); + } + return Value::CreateIntegerValue(CONTENT_SETTING_ALLOW); + } + + ContentSettingsPattern* primary_pattern = NULL; + ContentSettingsPattern* secondary_pattern = NULL; + if (info) { + primary_pattern = &info->primary_pattern; + secondary_pattern = &info->secondary_pattern; + } + + // The list of |content_settings_providers_| is ordered according to their + // precedence. + for (ConstProviderIterator provider = content_settings_providers_.begin(); + provider != content_settings_providers_.end(); + ++provider) { + base::Value* value = content_settings::GetContentSettingValueAndPatterns( + provider->second, primary_url, secondary_url, content_type, + resource_identifier, is_off_the_record_, + primary_pattern, secondary_pattern); + if (value) { + if (info) + info->source = kProviderSourceMap[provider->first]; + return value; + } + } + + if (info) { + info->source = content_settings::SETTING_SOURCE_NONE; + info->primary_pattern = ContentSettingsPattern(); + info->secondary_pattern = ContentSettingsPattern(); + } + return NULL; +} diff --git a/chrome/browser/content_settings/host_content_settings_map.h b/chrome/browser/content_settings/host_content_settings_map.h index 6945e6d..7c91008 100644 --- a/chrome/browser/content_settings/host_content_settings_map.h +++ b/chrome/browser/content_settings/host_content_settings_map.h @@ -79,20 +79,24 @@ class HostContentSettingsMap const std::string& resource_identifier) const; // Returns a single content setting |Value| which applies to the given URLs. - // If |primary_pattern| and |secondary_pattern| are not NULL, they are set to - // the patterns of the applying rule. - // Note that certain internal schemes are whitelisted. - // If there is no content setting, returns NULL and leaves |primary_pattern| - // and |secondary_pattern| unchanged. - // Otherwise transfers ownership of the resulting |Value| to the caller. + // If |info| is not NULL, then the |source| field of |info| is set to the + // source of the returned |Value| (POLICY, EXTENSION, USER, ...) and the + // |primary_pattern| and the |secondary_pattern| fields of |info| are set to + // the patterns of the applying rule. Note that certain internal schemes are + // whitelisted. For whitelisted schemes the |source| field of |info| is set + // the |SETTING_SOURCE_WHITELIST| and the |primary_pattern| and + // |secondary_pattern| are set to a wildcard pattern. If there is no content + // setting, NULL is returned and the |source| field of |info| is set to + // |SETTING_SOURCE_NONE|. The pattern fiels of |info| are set to empty + // patterns. + // The ownership of the resulting |Value| is transfered to the caller. // May be called on any thread. - base::Value* GetContentSettingValue( + base::Value* GetWebsiteSetting( const GURL& primary_url, const GURL& secondary_url, ContentSettingsType content_type, const std::string& resource_identifier, - ContentSettingsPattern* primary_pattern, - ContentSettingsPattern* secondary_pattern) const; + content_settings::SettingInfo* info) const; // Returns all ContentSettings which apply to the given |primary_url|. For // content setting types that require an additional resource identifier, the diff --git a/chrome/browser/extensions/extension_content_settings_api.cc b/chrome/browser/extensions/extension_content_settings_api.cc index eb819f4..859306f 100644 --- a/chrome/browser/extensions/extension_content_settings_api.cc +++ b/chrome/browser/extensions/extension_content_settings_api.cc @@ -152,7 +152,7 @@ bool GetContentSettingFunction::RunImpl() { // TODO(jochen): Do we return the value for setting or for reading cookies? bool setting_cookie = false; setting = cookie_settings->GetCookieSetting(primary_url, secondary_url, - setting_cookie); + setting_cookie, NULL); } else { setting = map->GetContentSetting(primary_url, secondary_url, content_type, resource_identifier); diff --git a/chrome/browser/renderer_host/plugin_info_message_filter.cc b/chrome/browser/renderer_host/plugin_info_message_filter.cc index 740e49a..b261085 100644 --- a/chrome/browser/renderer_host/plugin_info_message_filter.cc +++ b/chrome/browser/renderer_host/plugin_info_message_filter.cc @@ -10,6 +10,7 @@ #include "chrome/browser/content_settings/content_settings_utils.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/common/content_settings.h" #include "chrome/common/chrome_content_client.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" @@ -249,32 +250,30 @@ void PluginInfoMessageFilter::GetPluginContentSetting( const std::string& resource, ContentSetting* setting, bool* uses_default_content_setting) const { - ContentSettingsPattern primary_pattern; - ContentSettingsPattern secondary_pattern; - // Treat Native Client invocations like Javascript. bool is_nacl_plugin = (plugin->name == ASCIIToUTF16( chrome::ChromeContentClient::kNaClPluginName)); scoped_ptr<base::Value> value; + content_settings::SettingInfo info; if (is_nacl_plugin) { value.reset( - host_content_settings_map_->GetContentSettingValue( + host_content_settings_map_->GetWebsiteSetting( policy_url, policy_url, CONTENT_SETTINGS_TYPE_JAVASCRIPT, - std::string(), &primary_pattern, &secondary_pattern)); + std::string(), &info)); } else { value.reset( - host_content_settings_map_->GetContentSettingValue( + host_content_settings_map_->GetWebsiteSetting( policy_url, plugin_url, CONTENT_SETTINGS_TYPE_PLUGINS, resource, - &primary_pattern, &secondary_pattern)); + &info)); if (!value.get()) { - value.reset(host_content_settings_map_->GetContentSettingValue( + value.reset(host_content_settings_map_->GetWebsiteSetting( policy_url, plugin_url, CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), - &primary_pattern, &secondary_pattern)); + &info)); } } *setting = content_settings::ValueToContentSetting(value.get()); *uses_default_content_setting = - (primary_pattern == ContentSettingsPattern::Wildcard() && - secondary_pattern == ContentSettingsPattern::Wildcard()); + (info.primary_pattern == ContentSettingsPattern::Wildcard() && + info.secondary_pattern == ContentSettingsPattern::Wildcard()); } diff --git a/chrome/browser/tab_contents/tab_contents_ssl_helper.cc b/chrome/browser/tab_contents/tab_contents_ssl_helper.cc index 2b35346..3e838b4 100644 --- a/chrome/browser/tab_contents/tab_contents_ssl_helper.cc +++ b/chrome/browser/tab_contents/tab_contents_ssl_helper.cc @@ -213,11 +213,10 @@ void TabContentsSSLHelper::SelectClientCertificate( HostContentSettingsMap* map = tab_contents_->profile()->GetHostContentSettingsMap(); - scoped_ptr<Value> filter(map->GetContentSettingValue( + scoped_ptr<Value> filter(map->GetWebsiteSetting( requesting_url, requesting_url, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, - std::string(), - NULL, NULL)); + std::string(), NULL)); scoped_refptr<net::X509Certificate> selected_cert; if (filter.get()) { 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 344e201..ba5b356 100644 --- a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc +++ b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc @@ -5,8 +5,8 @@ #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/content_settings/content_settings_utils.h" #include "chrome/browser/content_settings/cookie_settings.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/infobars/infobar_tab_helper.h" @@ -17,6 +17,7 @@ #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/content_settings.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" @@ -29,8 +30,11 @@ #include "net/base/net_util.h" #include "ui/base/l10n/l10n_util.h" -namespace { +using content_settings::SettingInfo; +using content_settings::SettingSource; +using content_settings::SETTING_SOURCE_USER; +namespace { struct ContentSettingsTypeIdEntry { ContentSettingsType type; int id; @@ -256,25 +260,38 @@ class ContentSettingSingleRadioGroup HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); CookieSettings* cookie_settings = CookieSettings::GetForProfile(profile()); ContentSetting most_restrictive_setting; + SettingSource most_restrictive_setting_source; + if (resources.empty()) { - most_restrictive_setting = - content_type() == CONTENT_SETTINGS_TYPE_COOKIES ? - cookie_settings->GetCookieSetting(url, url, true) : - map->GetContentSetting(url, url, content_type(), std::string()); + 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; + } } else { most_restrictive_setting = 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); + 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) + if (setting == CONTENT_SETTING_ASK) { most_restrictive_setting = CONTENT_SETTING_ASK; + most_restrictive_setting_source = info.source; + } } } if (most_restrictive_setting == CONTENT_SETTING_ALLOW) { @@ -284,6 +301,11 @@ class ContentSettingSingleRadioGroup 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); } diff --git a/chrome/browser/ui/content_settings/content_setting_bubble_model.h b/chrome/browser/ui/content_settings/content_setting_bubble_model.h index ff787fb..eabc97b 100644 --- a/chrome/browser/ui/content_settings/content_setting_bubble_model.h +++ b/chrome/browser/ui/content_settings/content_setting_bubble_model.h @@ -68,6 +68,7 @@ class ContentSettingBubbleModel : public content::NotificationObserver { std::string title; PopupItems popup_items; RadioGroup radio_group; + bool radio_group_enabled; std::vector<DomainList> domain_lists; std::set<std::string> resource_identifiers; std::string custom_link; @@ -104,6 +105,9 @@ class ContentSettingBubbleModel : public content::NotificationObserver { void set_radio_group(const RadioGroup& radio_group) { bubble_content_.radio_group = radio_group; } + void set_radio_group_enabled(bool enabled) { + bubble_content_.radio_group_enabled = enabled; + } void add_domain_list(const DomainList& domain_list) { bubble_content_.domain_lists.push_back(domain_list); } diff --git a/chrome/browser/ui/gtk/content_setting_bubble_gtk.cc b/chrome/browser/ui/gtk/content_setting_bubble_gtk.cc index b414230..3205daf 100644 --- a/chrome/browser/ui/gtk/content_setting_bubble_gtk.cc +++ b/chrome/browser/ui/gtk/content_setting_bubble_gtk.cc @@ -183,6 +183,8 @@ void ContentSettingBubbleGtk::BuildBubble() { // or pain occurs. gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE); } + if (!content.radio_group_enabled) + gtk_widget_set_sensitive(radio, FALSE); radio_group_gtk_.push_back(radio); } for (std::vector<GtkWidget*>::const_iterator i = radio_group_gtk_.begin(); diff --git a/chrome/common/content_settings.h b/chrome/common/content_settings.h index 2c7e5c2..ec500b6 100644 --- a/chrome/common/content_settings.h +++ b/chrome/common/content_settings.h @@ -13,7 +13,7 @@ #include "chrome/common/content_settings_types.h" // Different settings that can be assigned for a particular content type. We -// give the user the ability to set these on a global and per-host basis. +// give the user the ability to set these on a global and per-origin basis. enum ContentSetting { CONTENT_SETTING_DEFAULT = 0, CONTENT_SETTING_ALLOW, @@ -51,4 +51,29 @@ struct ContentSettingPatternSource { typedef std::vector<ContentSettingPatternSource> ContentSettingsForOneType; +namespace content_settings { + +// Enum containing the various source for content settings. Settings can be +// set by policy, extension or the user. Certain (internal) schemes are +// whilelisted. For whilelisted schemes the source is +// |SETTING_SOURCE_WHITELIST|. +enum SettingSource { + SETTING_SOURCE_NONE, + SETTING_SOURCE_POLICY, + SETTING_SOURCE_EXTENSION, + SETTING_SOURCE_USER, + SETTING_SOURCE_WHITELIST, +}; + +// |SettingInfo| provides meta data for content setting values. |source| +// contains the source of a value. |primary_pattern| and |secondary_pattern| +// contains the patterns of the appling rule. +struct SettingInfo { + SettingSource source; + ContentSettingsPattern primary_pattern; + ContentSettingsPattern secondary_pattern; +}; + +} // namespace content_settings + #endif // CHROME_COMMON_CONTENT_SETTINGS_H_ |