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

Side by Side Diff: chrome/browser/content_settings/host_content_settings_map.cc

Issue 6542048: Add content_settings::PolicyProvider and a set of new policies to managed content settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 make_linked_ptr(new content_settings::PolicyProvider(profile)));
105 content_settings_providers_.push_back(
106 make_linked_ptr(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)
155 IsDefaultContentSettingManaged(content_type)) {
156 return GetDefaultContentSetting(content_type); 158 return GetDefaultContentSetting(content_type);
157 }
158 return setting; 159 return setting;
159 } 160 }
160 161
161 ContentSetting HostContentSettingsMap::GetNonDefaultContentSetting( 162 ContentSetting HostContentSettingsMap::GetNonDefaultContentSetting(
162 const GURL& url, 163 const GURL& url,
163 ContentSettingsType content_type, 164 ContentSettingsType content_type,
164 const std::string& resource_identifier) const { 165 const std::string& resource_identifier) const {
165 if (ShouldAllowAllContent(url)) 166 if (ShouldAllowAllContent(url))
166 return CONTENT_SETTING_ALLOW; 167 return CONTENT_SETTING_ALLOW;
167 168
168 // Iterate through the list of providers and break when the first non default 169 // Iterate through the list of providers and break when the first non default
169 // setting is found. 170 // setting is found.
170 ContentSetting provided_setting(CONTENT_SETTING_DEFAULT); 171 ContentSetting provided_setting(CONTENT_SETTING_DEFAULT);
171 for (ConstProviderIterator provider = content_settings_providers_.begin(); 172 for (ConstProviderIterator provider = content_settings_providers_.begin();
172 provider != content_settings_providers_.end(); 173 provider != content_settings_providers_.end();
173 ++provider) { 174 ++provider) {
174 provided_setting = (*provider)->GetContentSetting( 175 provided_setting = (*provider)->GetContentSetting(
175 url, url, content_type, resource_identifier); 176 url, url, content_type, resource_identifier);
176 if (provided_setting != CONTENT_SETTING_DEFAULT) 177 bool isManaged = (*provider)->ContentSettingsTypeIsManaged(content_type);
177 break; 178 if (provided_setting != CONTENT_SETTING_DEFAULT || isManaged)
179 return provided_setting;
178 } 180 }
179 return provided_setting; 181 return provided_setting;
180 } 182 }
181 183
182 ContentSettings HostContentSettingsMap::GetContentSettings( 184 ContentSettings HostContentSettingsMap::GetContentSettings(
183 const GURL& url) const { 185 const GURL& url) const {
184 ContentSettings output = GetNonDefaultContentSettings(url); 186 ContentSettings output = GetNonDefaultContentSettings(url);
185 187
186 // If we require a resource identifier, set the content settings to default, 188 // If we require a resource identifier, set the content settings to default,
187 // otherwise make the defaults explicit. 189 // otherwise make the defaults explicit.
188 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { 190 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) {
189 // A managed default content setting has the highest priority and hence 191 // A managed default content setting has the highest priority and hence
190 // will overwrite any previously set value. 192 // will overwrite any previously set value.
191 if ((output.settings[j] == CONTENT_SETTING_DEFAULT && 193 if (output.settings[j] == CONTENT_SETTING_DEFAULT &&
192 j != CONTENT_SETTINGS_TYPE_PLUGINS) || 194 j != CONTENT_SETTINGS_TYPE_PLUGINS) {
193 IsDefaultContentSettingManaged(ContentSettingsType(j))) {
194 output.settings[j] = GetDefaultContentSetting(ContentSettingsType(j)); 195 output.settings[j] = GetDefaultContentSetting(ContentSettingsType(j));
195 } 196 }
196 } 197 }
197 return output; 198 return output;
198 } 199 }
199 200
200 ContentSettings HostContentSettingsMap::GetNonDefaultContentSettings( 201 ContentSettings HostContentSettingsMap::GetNonDefaultContentSettings(
201 const GURL& url) const { 202 const GURL& url) const {
202 if (ShouldAllowAllContent(url)) 203 if (ShouldAllowAllContent(url))
203 return ContentSettings(CONTENT_SETTING_ALLOW); 204 return ContentSettings(CONTENT_SETTING_ALLOW);
(...skipping 14 matching lines...) Expand all
218 settings->clear(); 219 settings->clear();
219 220
220 // Collect content_settings::Rules for the given content_type and 221 // Collect content_settings::Rules for the given content_type and
221 // resource_identifier from the content settings providers. 222 // resource_identifier from the content settings providers.
222 Rules content_settings_rules; 223 Rules content_settings_rules;
223 for (ConstProviderIterator provider = content_settings_providers_.begin(); 224 for (ConstProviderIterator provider = content_settings_providers_.begin();
224 provider != content_settings_providers_.end(); 225 provider != content_settings_providers_.end();
225 ++provider) { 226 ++provider) {
226 // TODO(markusheintz): Only the rules that are applied should be collected. 227 // TODO(markusheintz): Only the rules that are applied should be collected.
227 // Merge rules. 228 // Merge rules.
229 // TODO(markusheintz): GetAllContentSettingsRules should maybe not clear the
230 // passed vector in case rule sets are just unified.
231 Rules rules;
228 (*provider)->GetAllContentSettingsRules( 232 (*provider)->GetAllContentSettingsRules(
229 content_type, resource_identifier, &content_settings_rules); 233 content_type, resource_identifier, &rules);
234 content_settings_rules.insert(content_settings_rules.end(),
235 rules.begin(),
236 rules.end());
230 } 237 }
231 238
232 // convert Rules to SettingsForOneType 239 // convert Rules to SettingsForOneType
233 for (const_rules_iterator rule_iterator = 240 for (const_rules_iterator rule_iterator =
234 content_settings_rules.begin(); 241 content_settings_rules.begin();
235 rule_iterator != content_settings_rules.end(); 242 rule_iterator != content_settings_rules.end();
236 ++rule_iterator) { 243 ++rule_iterator) {
237 settings->push_back(std::make_pair(ContentSettingsPattern( 244 settings->push_back(std::make_pair(ContentSettingsPattern(
238 rule_iterator->requesting_url_pattern), 245 rule_iterator->requesting_url_pattern),
239 rule_iterator->content_setting)); 246 rule_iterator->content_setting));
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, 471 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES,
465 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? 472 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ?
466 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); 473 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW);
467 } 474 }
468 if (!prefs->HasPrefPath(prefs::kBlockThirdPartyCookies)) { 475 if (!prefs->HasPrefPath(prefs::kBlockThirdPartyCookies)) {
469 SetBlockThirdPartyCookies(cookie_behavior == 476 SetBlockThirdPartyCookies(cookie_behavior ==
470 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); 477 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES);
471 } 478 }
472 } 479 }
473 } 480 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698