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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } | 145 } |
146 } | 146 } |
147 | 147 |
148 // The method GetDefaultContentSetting always has to return an explicit | 148 // The method GetDefaultContentSetting always has to return an explicit |
149 // value that is to be used as default. We here rely on the | 149 // value that is to be used as default. We here rely on the |
150 // DefaultProvider to always provide a value. | 150 // DefaultProvider to always provide a value. |
151 NOTREACHED(); | 151 NOTREACHED(); |
152 return CONTENT_SETTING_DEFAULT; | 152 return CONTENT_SETTING_DEFAULT; |
153 } | 153 } |
154 | 154 |
155 ContentSettings HostContentSettingsMap::GetDefaultContentSettings() const { | |
156 ContentSettings output(CONTENT_SETTING_DEFAULT); | |
157 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | |
158 if (!ContentTypeHasCompoundValue(ContentSettingsType(i))) | |
159 output.settings[i] = GetDefaultContentSetting(ContentSettingsType(i), | |
160 NULL); | |
161 } | |
162 return output; | |
163 } | |
164 | |
165 ContentSetting HostContentSettingsMap::GetContentSetting( | 155 ContentSetting HostContentSettingsMap::GetContentSetting( |
166 const GURL& primary_url, | 156 const GURL& primary_url, |
167 const GURL& secondary_url, | 157 const GURL& secondary_url, |
168 ContentSettingsType content_type, | 158 ContentSettingsType content_type, |
169 const std::string& resource_identifier) const { | 159 const std::string& resource_identifier) const { |
170 scoped_ptr<base::Value> value(GetContentSettingValue( | 160 scoped_ptr<base::Value> value(GetContentSettingValue( |
171 primary_url, secondary_url, content_type, resource_identifier, | 161 primary_url, secondary_url, content_type, resource_identifier, |
172 NULL, NULL)); | 162 NULL, NULL)); |
173 return content_settings::ValueToContentSetting(value.get()); | 163 return content_settings::ValueToContentSetting(value.get()); |
174 } | 164 } |
(...skipping 20 matching lines...) Expand all Loading... |
195 base::Value* value = content_settings::GetContentSettingValueAndPatterns( | 185 base::Value* value = content_settings::GetContentSettingValueAndPatterns( |
196 provider->second, primary_url, secondary_url, content_type, | 186 provider->second, primary_url, secondary_url, content_type, |
197 resource_identifier, is_off_the_record_, | 187 resource_identifier, is_off_the_record_, |
198 primary_pattern, secondary_pattern); | 188 primary_pattern, secondary_pattern); |
199 if (value) | 189 if (value) |
200 return value; | 190 return value; |
201 } | 191 } |
202 return NULL; | 192 return NULL; |
203 } | 193 } |
204 | 194 |
205 ContentSettings HostContentSettingsMap::GetContentSettings( | |
206 const GURL& primary_url) const { | |
207 ContentSettings output; | |
208 // If we require a resource identifier, set the content settings to default, | |
209 // otherwise make the defaults explicit. Values for content type | |
210 // CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE can't be mapped to the type | |
211 // |ContentSetting|. So we ignore them here. | |
212 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { | |
213 ContentSettingsType type = ContentSettingsType(j); | |
214 if (!ContentTypeHasCompoundValue(type)) { | |
215 output.settings[j] = GetContentSetting( | |
216 primary_url, primary_url, ContentSettingsType(j), std::string()); | |
217 } | |
218 } | |
219 return output; | |
220 } | |
221 | |
222 void HostContentSettingsMap::GetSettingsForOneType( | 195 void HostContentSettingsMap::GetSettingsForOneType( |
223 ContentSettingsType content_type, | 196 ContentSettingsType content_type, |
224 const std::string& resource_identifier, | 197 const std::string& resource_identifier, |
225 ContentSettingsForOneType* settings) const { | 198 ContentSettingsForOneType* settings) const { |
226 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || | 199 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || |
227 resource_identifier.empty()); | 200 resource_identifier.empty()); |
228 DCHECK(settings); | 201 DCHECK(settings); |
229 | 202 |
230 settings->clear(); | 203 settings->clear(); |
231 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 204 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) | 384 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) |
412 return false; | 385 return false; |
413 if (primary_url.SchemeIs(chrome::kExtensionScheme)) { | 386 if (primary_url.SchemeIs(chrome::kExtensionScheme)) { |
414 return content_type != CONTENT_SETTINGS_TYPE_COOKIES || | 387 return content_type != CONTENT_SETTINGS_TYPE_COOKIES || |
415 secondary_url.SchemeIs(chrome::kExtensionScheme); | 388 secondary_url.SchemeIs(chrome::kExtensionScheme); |
416 } | 389 } |
417 return primary_url.SchemeIs(chrome::kChromeDevToolsScheme) || | 390 return primary_url.SchemeIs(chrome::kChromeDevToolsScheme) || |
418 primary_url.SchemeIs(chrome::kChromeInternalScheme) || | 391 primary_url.SchemeIs(chrome::kChromeInternalScheme) || |
419 primary_url.SchemeIs(chrome::kChromeUIScheme); | 392 primary_url.SchemeIs(chrome::kChromeUIScheme); |
420 } | 393 } |
OLD | NEW |