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

Unified Diff: chrome/browser/content_settings/content_settings_policy_provider.cc

Issue 7828022: Add a method to the HostContentSettings map to return the |Value| of a content setting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed & Removed default auto select cert setting. Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/content_settings/content_settings_policy_provider.cc
diff --git a/chrome/browser/content_settings/content_settings_policy_provider.cc b/chrome/browser/content_settings/content_settings_policy_provider.cc
index 8015b56589c258beaf2258e365b55635c9bf1220..55cebee482fa97d5960990591e309a76c7d35ad5 100644
--- a/chrome/browser/content_settings/content_settings_policy_provider.cc
+++ b/chrome/browser/content_settings/content_settings_policy_provider.cc
@@ -8,6 +8,7 @@
#include <vector>
#include "base/command_line.h"
+#include "base/json/json_reader.h"
#include "chrome/browser/content_settings/content_settings_pattern.h"
#include "chrome/browser/content_settings/content_settings_utils.h"
#include "chrome/browser/prefs/pref_service.h"
@@ -33,7 +34,7 @@ const char* kPrefToManageType[CONTENT_SETTINGS_NUM_TYPES] = {
prefs::kManagedDefaultGeolocationSetting,
prefs::kManagedDefaultNotificationsSetting,
NULL,
- prefs::kManagedDefaultAutoSelectCertificateSetting,
+ NULL,
wtc 2011/09/02 18:53:22 Just wanted to make sure you do want a NULL entry
markusheintz_ 2011/09/02 19:39:12 Yes I really want a NULL entry here bc the size ha
};
struct PrefsForManagedContentSettingsMapEntry {
@@ -45,10 +46,6 @@ struct PrefsForManagedContentSettingsMapEntry {
const PrefsForManagedContentSettingsMapEntry
kPrefsForManagedContentSettingsMap[] = {
{
- prefs::kManagedAutoSelectCertificateForUrls,
- CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
- CONTENT_SETTING_ALLOW
- }, {
prefs::kManagedCookiesAllowedForUrls,
CONTENT_SETTINGS_TYPE_COOKIES,
CONTENT_SETTING_ALLOW
@@ -121,8 +118,6 @@ PolicyDefaultProvider::PolicyDefaultProvider(PrefService* prefs)
pref_change_registrar_.Add(prefs::kManagedDefaultPopupsSetting, this);
pref_change_registrar_.Add(prefs::kManagedDefaultGeolocationSetting, this);
pref_change_registrar_.Add(prefs::kManagedDefaultNotificationsSetting, this);
- pref_change_registrar_.Add(
- prefs::kManagedDefaultAutoSelectCertificateSetting, this);
}
PolicyDefaultProvider::~PolicyDefaultProvider() {
@@ -173,9 +168,6 @@ void PolicyDefaultProvider::Observe(int type,
UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION);
} else if (*name == prefs::kManagedDefaultNotificationsSetting) {
UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
- } else if (*name == prefs::kManagedDefaultAutoSelectCertificateSetting) {
- UpdateManagedDefaultSetting(
- CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE);
} else {
NOTREACHED() << "Unexpected preference observed";
return;
@@ -247,9 +239,6 @@ void PolicyDefaultProvider::RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterIntegerPref(prefs::kManagedDefaultNotificationsSetting,
CONTENT_SETTING_DEFAULT,
PrefService::UNSYNCABLE_PREF);
- prefs->RegisterIntegerPref(prefs::kManagedDefaultAutoSelectCertificateSetting,
- CONTENT_SETTING_ASK,
- PrefService::UNSYNCABLE_PREF);
}
// ////////////////////////////////////////////////////////////////////////////
@@ -341,6 +330,7 @@ void PolicyProvider::GetContentSettingsFromPreferences(
ContentSettingsType content_type =
kPrefsForManagedContentSettingsMap[i].content_type;
+ DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE);
// If only one pattern was defined auto expand it to a pattern pair.
ContentSettingsPattern secondary_pattern =
!pattern_pair.second.IsValid() ? ContentSettingsPattern::Wildcard()
@@ -355,6 +345,76 @@ void PolicyProvider::GetContentSettingsFromPreferences(
}
}
+void PolicyProvider::GetAutoSelectCertificateSettingsFromPreferences(
+ OriginIdentifierValueMap* value_map) {
+ const char* pref_name = prefs::kManagedAutoSelectCertificateForUrls;
+
+ if (!prefs_->HasPrefPath(pref_name)) {
+ VLOG(2) << "Skipping unset preference: " << pref_name;
+ return;
+ }
+
+ const PrefService::Preference* pref = prefs_->FindPreference(pref_name);
+ DCHECK(pref);
+ DCHECK(pref->IsManaged());
+
+ const ListValue* pattern_filter_str_list = NULL;
+ if (!pref->GetValue()->GetAsList(&pattern_filter_str_list)) {
+ NOTREACHED();
+ return;
+ }
+
+ // Parse the list of pattern filter strings. A pattern filter string has the
+ // following format:
+ //
+ // PATTERN_FILTER_STRING ::= CONTENT_SETTINGS_PATTERN_STRING '|' FILTER_STRING
+ // FILTER_STRING ::= JSON_STRING
+ //
+ // e.g. "[*.]example.com|{\"ISSUER\":{\"CN\":\"some name\"}}"
Mattias Nissler (ping if slow) 2011/09/02 15:06:21 can we maybe just make the pattern also part of th
markusheintz_ 2011/09/02 19:39:12 Done.
+ // '"' characters are escaped with a '\' in this example so the '\' characters
+ // are not part of the string.
+ //
+ // As the pipe symbol can not occure in a content settings pattern string it
+ // is used to separate the content settings pattern string from the JSON
+ // string.
+ for (size_t j = 0; j < pattern_filter_str_list->GetSize(); ++j) {
+ std::string pattern_filter_str;
+ pattern_filter_str_list->GetString(j, &pattern_filter_str);
+
+ size_t separator_pos = pattern_filter_str.find('|');
+ if (separator_pos == std::string::npos) {
+ VLOG(1) << "No filter string found. Ignoring list entry: "
+ << pattern_filter_str;
+ continue;
+ }
+ std::string pattern_str = pattern_filter_str.substr(0, separator_pos);
+ std::string filter_str = pattern_filter_str.substr(separator_pos + 1);
+
+ ContentSettingsPattern pattern =
+ ContentSettingsPattern::FromString(pattern_str);
+ // Ignore invalid patterns.
+ if (!pattern.IsValid()) {
+ VLOG(1) << "Invalid content settings pattern: " << pattern_str
+ << ". Ignoring list entry: " << pattern_filter_str;
+ continue;
+ }
+
+ // Allow trailing commas to be more fault tolerant.
+ scoped_ptr<Value> filter_value(base::JSONReader::Read(filter_str, true));
+ if (!filter_value.get()) {
+ VLOG(1) << "Invalid JSON string: " << filter_str
+ << ". Ignoring list entry: " << pattern_filter_str;
+ continue;
+ }
+ DCHECK(filter_value->IsType(Value::TYPE_DICTIONARY));
+ value_map->SetValue(pattern,
+ ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
+ std::string(),
+ filter_value.release());
+ }
+}
+
void PolicyProvider::ReadManagedContentSettings(bool overwrite) {
ContentSettingsRules rules;
GetContentSettingsFromPreferences(&rules);
@@ -371,6 +431,7 @@ void PolicyProvider::ReadManagedContentSettings(bool overwrite) {
rule->d,
Value::CreateIntegerValue(rule->e));
}
+ GetAutoSelectCertificateSettingsFromPreferences(&value_map_);
}
}
@@ -389,6 +450,7 @@ ContentSetting PolicyProvider::GetContentSetting(
const GURL& secondary_url,
ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier) const {
+ DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE);
// Resource identifier are not supported by policies as long as the feature is
// behind a flag. So resource identifiers are simply ignored.
scoped_ptr<Value> value(GetContentSettingValue(primary_url,

Powered by Google App Engine
This is Rietveld 408576698