Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/content_settings/host_content_settings_map.h" | 5 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 } | 93 } |
| 94 is_block_third_party_cookies_managed_ = | 94 is_block_third_party_cookies_managed_ = |
| 95 prefs->IsManagedPreference(prefs::kBlockThirdPartyCookies); | 95 prefs->IsManagedPreference(prefs::kBlockThirdPartyCookies); |
| 96 block_nonsandboxed_plugins_ = | 96 block_nonsandboxed_plugins_ = |
| 97 prefs->GetBoolean(prefs::kBlockNonsandboxedPlugins); | 97 prefs->GetBoolean(prefs::kBlockNonsandboxedPlugins); |
| 98 | 98 |
| 99 // User defined non default content settings are provided by the PrefProvider. | 99 // User defined non default content settings are provided by the PrefProvider. |
| 100 // The order in which the content settings providers are created is critical, | 100 // The order in which the content settings providers are created is critical, |
| 101 // as providers that are further up in the list (i.e. added earlier) override | 101 // as providers that are further up in the list (i.e. added earlier) override |
| 102 // providers further down. | 102 // providers further down. |
| 103 content_settings_providers_.push_back(ProviderPtr( | 103 content_settings_providers_.push_back( |
| 104 new content_settings::PrefProvider(profile))); | 104 ProviderPtr(new content_settings::PolicyProvider(profile))); |
|
Bernhard Bauer
2011/02/23 13:18:53
I think you could just use |make_linked_ptr| inste
markusheintz_
2011/02/23 18:42:09
ABSOLUTELY!!! DONE
But having the ProviderPtr typ
| |
| 105 content_settings_providers_.push_back( | |
| 106 ProviderPtr(new content_settings::PrefProvider(profile))); | |
| 105 | 107 |
| 106 pref_change_registrar_.Init(prefs); | 108 pref_change_registrar_.Init(prefs); |
| 107 pref_change_registrar_.Add(prefs::kBlockThirdPartyCookies, this); | 109 pref_change_registrar_.Add(prefs::kBlockThirdPartyCookies, this); |
| 108 pref_change_registrar_.Add(prefs::kBlockNonsandboxedPlugins, this); | 110 pref_change_registrar_.Add(prefs::kBlockNonsandboxedPlugins, this); |
| 109 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 111 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, |
| 110 Source<Profile>(profile_)); | 112 Source<Profile>(profile_)); |
| 111 } | 113 } |
| 112 | 114 |
| 113 // static | 115 // static |
| 114 void HostContentSettingsMap::RegisterUserPrefs(PrefService* prefs) { | 116 void HostContentSettingsMap::RegisterUserPrefs(PrefService* prefs) { |
| 115 prefs->RegisterBooleanPref(prefs::kBlockThirdPartyCookies, false); | 117 prefs->RegisterBooleanPref(prefs::kBlockThirdPartyCookies, false); |
| 116 prefs->RegisterBooleanPref(prefs::kBlockNonsandboxedPlugins, false); | 118 prefs->RegisterBooleanPref(prefs::kBlockNonsandboxedPlugins, false); |
| 117 prefs->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); | 119 prefs->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); |
| 118 | 120 |
| 119 // Obsolete prefs, for migration: | 121 // Obsolete prefs, for migration: |
| 120 prefs->RegisterIntegerPref(prefs::kCookieBehavior, | 122 prefs->RegisterIntegerPref(prefs::kCookieBehavior, |
| 121 net::StaticCookiePolicy::ALLOW_ALL_COOKIES); | 123 net::StaticCookiePolicy::ALLOW_ALL_COOKIES); |
| 122 | 124 |
| 123 // Register the prefs for the content settings providers. | 125 // Register the prefs for the content settings providers. |
| 124 content_settings::PrefDefaultProvider::RegisterUserPrefs(prefs); | 126 content_settings::PrefDefaultProvider::RegisterUserPrefs(prefs); |
| 125 content_settings::PolicyDefaultProvider::RegisterUserPrefs(prefs); | 127 content_settings::PolicyDefaultProvider::RegisterUserPrefs(prefs); |
| 126 content_settings::PrefProvider::RegisterUserPrefs(prefs); | 128 content_settings::PrefProvider::RegisterUserPrefs(prefs); |
| 129 content_settings::PolicyProvider::RegisterUserPrefs(prefs); | |
| 127 } | 130 } |
| 128 | 131 |
| 129 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( | 132 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( |
| 130 ContentSettingsType content_type) const { | 133 ContentSettingsType content_type) const { |
| 131 ContentSetting setting = CONTENT_SETTING_DEFAULT; | 134 ContentSetting setting = CONTENT_SETTING_DEFAULT; |
| 132 for (ConstDefaultProviderIterator provider = | 135 for (ConstDefaultProviderIterator provider = |
| 133 default_content_settings_providers_.begin(); | 136 default_content_settings_providers_.begin(); |
| 134 provider != default_content_settings_providers_.end(); ++provider) { | 137 provider != default_content_settings_providers_.end(); ++provider) { |
| 135 ContentSetting provided_setting = | 138 ContentSetting provided_setting = |
| 136 (*provider)->ProvideDefaultSetting(content_type); | 139 (*provider)->ProvideDefaultSetting(content_type); |
| 137 if (provided_setting != CONTENT_SETTING_DEFAULT) | 140 if (provided_setting != CONTENT_SETTING_DEFAULT) |
| 138 setting = provided_setting; | 141 setting = provided_setting; |
| 139 } | 142 } |
| 140 // The method GetDefaultContentSetting always has to return an explicit | 143 // The method GetDefaultContentSetting always has to return an explicit |
| 141 // value that is to be used as default. We here rely on the | 144 // value that is to be used as default. We here rely on the |
| 142 // PrefContentSettingProvider to always provide a value. | 145 // PrefContentSettingProvider to always provide a value. |
| 143 CHECK_NE(CONTENT_SETTING_DEFAULT, setting); | 146 CHECK_NE(CONTENT_SETTING_DEFAULT, setting); |
| 144 return setting; | 147 return setting; |
| 145 } | 148 } |
| 146 | 149 |
| 147 ContentSetting HostContentSettingsMap::GetContentSetting( | 150 ContentSetting HostContentSettingsMap::GetContentSetting( |
| 148 const GURL& url, | 151 const GURL& url, |
| 149 ContentSettingsType content_type, | 152 ContentSettingsType content_type, |
| 150 const std::string& resource_identifier) const { | 153 const std::string& resource_identifier) const { |
| 151 ContentSetting setting = GetNonDefaultContentSetting(url, | 154 ContentSetting setting = GetNonDefaultContentSetting(url, |
| 152 content_type, | 155 content_type, |
| 153 resource_identifier); | 156 resource_identifier); |
| 154 if (setting == CONTENT_SETTING_DEFAULT || | 157 if (setting == CONTENT_SETTING_DEFAULT) { |
|
Bernhard Bauer
2011/02/23 13:18:53
You could get rid of the braces, but personally I
markusheintz_
2011/02/23 18:42:09
Don't care much either. Flipped a coin and deleted
| |
| 155 IsDefaultContentSettingManaged(content_type)) { | |
| 156 return GetDefaultContentSetting(content_type); | 158 return GetDefaultContentSetting(content_type); |
| 157 } | 159 } |
| 158 return setting; | 160 return setting; |
| 159 } | 161 } |
| 160 | 162 |
| 161 ContentSetting HostContentSettingsMap::GetNonDefaultContentSetting( | 163 ContentSetting HostContentSettingsMap::GetNonDefaultContentSetting( |
| 162 const GURL& url, | 164 const GURL& url, |
| 163 ContentSettingsType content_type, | 165 ContentSettingsType content_type, |
| 164 const std::string& resource_identifier) const { | 166 const std::string& resource_identifier) const { |
| 165 if (ShouldAllowAllContent(url)) | 167 if (ShouldAllowAllContent(url)) |
| 166 return CONTENT_SETTING_ALLOW; | 168 return CONTENT_SETTING_ALLOW; |
| 167 | 169 |
| 168 // Iterate through the list of providers and break when the first non default | 170 // Iterate through the list of providers and break when the first non default |
| 169 // setting is found. | 171 // setting is found. |
| 170 ContentSetting provided_setting(CONTENT_SETTING_DEFAULT); | 172 ContentSetting provided_setting(CONTENT_SETTING_DEFAULT); |
| 171 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 173 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
| 172 provider != content_settings_providers_.end(); | 174 provider != content_settings_providers_.end(); |
| 173 ++provider) { | 175 ++provider) { |
| 174 provided_setting = (*provider)->GetContentSetting( | 176 provided_setting = (*provider)->GetContentSetting( |
| 175 url, url, content_type, resource_identifier); | 177 url, url, content_type, resource_identifier); |
| 176 if (provided_setting != CONTENT_SETTING_DEFAULT) | 178 bool isManaged = (*provider)->ContentSettingsTypeIsManaged(content_type); |
| 177 break; | 179 if (provided_setting != CONTENT_SETTING_DEFAULT || |
| 180 isManaged) | |
|
Bernhard Bauer
2011/02/23 13:18:53
Doesn't this fit on one line?
markusheintz_
2011/02/23 18:42:09
Done.
| |
| 181 return provided_setting; | |
| 178 } | 182 } |
| 179 return provided_setting; | 183 return provided_setting; |
| 180 } | 184 } |
| 181 | 185 |
| 182 ContentSettings HostContentSettingsMap::GetContentSettings( | 186 ContentSettings HostContentSettingsMap::GetContentSettings( |
| 183 const GURL& url) const { | 187 const GURL& url) const { |
| 184 ContentSettings output = GetNonDefaultContentSettings(url); | 188 ContentSettings output = GetNonDefaultContentSettings(url); |
| 185 | 189 |
| 186 // If we require a resource identifier, set the content settings to default, | 190 // If we require a resource identifier, set the content settings to default, |
| 187 // otherwise make the defaults explicit. | 191 // otherwise make the defaults explicit. |
| 188 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { | 192 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { |
| 189 // A managed default content setting has the highest priority and hence | 193 // A managed default content setting has the highest priority and hence |
| 190 // will overwrite any previously set value. | 194 // will overwrite any previously set value. |
| 191 if ((output.settings[j] == CONTENT_SETTING_DEFAULT && | 195 if (output.settings[j] == CONTENT_SETTING_DEFAULT && |
| 192 j != CONTENT_SETTINGS_TYPE_PLUGINS) || | 196 j != CONTENT_SETTINGS_TYPE_PLUGINS) { |
| 193 IsDefaultContentSettingManaged(ContentSettingsType(j))) { | |
| 194 output.settings[j] = GetDefaultContentSetting(ContentSettingsType(j)); | 197 output.settings[j] = GetDefaultContentSetting(ContentSettingsType(j)); |
| 195 } | 198 } |
| 196 } | 199 } |
| 197 return output; | 200 return output; |
| 198 } | 201 } |
| 199 | 202 |
| 200 ContentSettings HostContentSettingsMap::GetNonDefaultContentSettings( | 203 ContentSettings HostContentSettingsMap::GetNonDefaultContentSettings( |
| 201 const GURL& url) const { | 204 const GURL& url) const { |
| 202 if (ShouldAllowAllContent(url)) | 205 if (ShouldAllowAllContent(url)) |
| 203 return ContentSettings(CONTENT_SETTING_ALLOW); | 206 return ContentSettings(CONTENT_SETTING_ALLOW); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 218 settings->clear(); | 221 settings->clear(); |
| 219 | 222 |
| 220 // Collect content_settings::Rules for the given content_type and | 223 // Collect content_settings::Rules for the given content_type and |
| 221 // resource_identifier from the content settings providers. | 224 // resource_identifier from the content settings providers. |
| 222 Rules content_settings_rules; | 225 Rules content_settings_rules; |
| 223 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 226 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
| 224 provider != content_settings_providers_.end(); | 227 provider != content_settings_providers_.end(); |
| 225 ++provider) { | 228 ++provider) { |
| 226 // TODO(markusheintz): Only the rules that are applied should be collected. | 229 // TODO(markusheintz): Only the rules that are applied should be collected. |
| 227 // Merge rules. | 230 // Merge rules. |
| 231 // TODO(markusheintz): GetAllContentSettingsRules should maybe not clear the | |
| 232 // passed vector in case rule sets are just unified. | |
| 233 Rules rules; | |
| 228 (*provider)->GetAllContentSettingsRules( | 234 (*provider)->GetAllContentSettingsRules( |
| 229 content_type, resource_identifier, &content_settings_rules); | 235 content_type, resource_identifier, &rules); |
| 236 content_settings_rules.insert(content_settings_rules.end(), | |
| 237 rules.begin(), | |
| 238 rules.end()); | |
| 230 } | 239 } |
| 231 | 240 |
| 232 // convert Rules to SettingsForOneType | 241 // convert Rules to SettingsForOneType |
| 233 for (const_rules_iterator rule_iterator = | 242 for (const_rules_iterator rule_iterator = |
| 234 content_settings_rules.begin(); | 243 content_settings_rules.begin(); |
| 235 rule_iterator != content_settings_rules.end(); | 244 rule_iterator != content_settings_rules.end(); |
| 236 ++rule_iterator) { | 245 ++rule_iterator) { |
| 237 settings->push_back(std::make_pair(ContentSettingsPattern( | 246 settings->push_back(std::make_pair(ContentSettingsPattern( |
| 238 rule_iterator->requesting_url_pattern), | 247 rule_iterator->requesting_url_pattern), |
| 239 rule_iterator->content_setting)); | 248 rule_iterator->content_setting)); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, | 473 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, |
| 465 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? | 474 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? |
| 466 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); | 475 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); |
| 467 } | 476 } |
| 468 if (!prefs->HasPrefPath(prefs::kBlockThirdPartyCookies)) { | 477 if (!prefs->HasPrefPath(prefs::kBlockThirdPartyCookies)) { |
| 469 SetBlockThirdPartyCookies(cookie_behavior == | 478 SetBlockThirdPartyCookies(cookie_behavior == |
| 470 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); | 479 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); |
| 471 } | 480 } |
| 472 } | 481 } |
| 473 } | 482 } |
| OLD | NEW |