Chromium Code Reviews| Index: chrome/browser/content_settings/content_settings_override_provider.cc |
| diff --git a/chrome/browser/content_settings/content_settings_override_provider.cc b/chrome/browser/content_settings/content_settings_override_provider.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dd61c010b9170546c109bb673be02721a143597f |
| --- /dev/null |
| +++ b/chrome/browser/content_settings/content_settings_override_provider.cc |
| @@ -0,0 +1,94 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/content_settings/content_settings_override_provider.h" |
| + |
| +#include <string> |
| + |
| +#include "base/auto_reset.h" |
| +#include "base/prefs/pref_service.h" |
| +#include "base/prefs/scoped_user_pref_update.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/content_settings/content_settings_utils.h" |
| +#include "chrome/common/content_settings.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "components/pref_registry/pref_registry_syncable.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +using content::BrowserThread; |
| + |
| +namespace content_settings { |
| + |
| +// static |
| +void OverrideProvider::RegisterProfilePrefs( |
| + user_prefs::PrefRegistrySyncable* registry) { |
| + base::DictionaryValue* override_content_settings = |
|
Bernhard Bauer
2014/09/10 09:07:17
Inline this?
Actually, there is a version of Regi
Daniel Nishi
2014/09/10 16:38:28
Using the empty dictionary version.
|
| + new base::DictionaryValue(); |
| + registry->RegisterDictionaryPref( |
| + prefs::kOverrideContentSettings, |
| + override_content_settings, |
| + user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| +} |
| + |
| +OverrideProvider::OverrideProvider(PrefService* prefs, bool incognito) |
| + : prefs_(prefs), is_incognito_(incognito) { |
| + DCHECK(prefs_); |
| + |
| + // Read global overrides. |
| + ReadOverrideSettings(); |
| +} |
| + |
| +OverrideProvider::~OverrideProvider() { |
| +} |
| + |
| +void OverrideProvider::SetContentSetting(ContentSettingsType content_type, |
| + bool is_enabled) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + DCHECK(prefs_); |
| + |
| + if (is_incognito_) |
|
Bernhard Bauer
2014/09/10 09:07:17
So, in incognito, settings are silently immutable?
Daniel Nishi
2014/09/10 16:38:28
The only way to modify it right now would be throu
Bernhard Bauer
2014/09/10 17:44:53
Right... I think I'm okay with not having the abil
Daniel Nishi
2014/09/10 23:30:20
Done.
|
| + return; |
| + |
| + DictionaryPrefUpdate update(prefs_, prefs::kOverrideContentSettings); |
| + base::DictionaryValue* default_settings_dictionary = update.Get(); |
| + base::AutoLock lock(lock_); |
| + override_settings_[content_type] = is_enabled; |
| + default_settings_dictionary->SetWithoutPathExpansion( |
| + GetTypeName(content_type), new base::FundamentalValue(is_enabled)); |
| +} |
| + |
| +bool OverrideProvider::IsEnabled(ContentSettingsType content_type) const { |
|
Bernhard Bauer
2014/09/10 09:07:17
There is of course another way: You could make thi
Daniel Nishi
2014/09/10 16:38:28
Would taking this path with some special cases for
Bernhard Bauer
2014/09/10 17:44:53
I think so... if there aren't too many special cas
Daniel Nishi
2014/09/10 17:55:52
It mainly comes from the distinction of trying to
Bernhard Bauer
2014/09/11 16:49:56
Hm... I think in the content settings UI we get ar
|
| + std::map<ContentSettingsType, bool>::const_iterator it = |
| + override_settings_.find(content_type); |
| + if (it == override_settings_.end()) |
| + return true; |
| + |
| + return it->second; |
| +} |
| + |
| +void OverrideProvider::ReadOverrideSettings() { |
| + base::AutoLock lock(lock_); |
|
Bernhard Bauer
2014/09/10 09:07:17
If this method is only called during construction,
Daniel Nishi
2014/09/10 16:38:28
Done.
|
| + const base::DictionaryValue* override_settings_dictionary = |
| + prefs_->GetDictionary(prefs::kOverrideContentSettings); |
| + |
| + override_settings_.clear(); |
| + |
| + if (override_settings_dictionary) { |
| + for (base::DictionaryValue::Iterator i(*override_settings_dictionary); |
| + !i.IsAtEnd(); |
| + i.Advance()) { |
| + const std::string& content_type(i.key()); |
| + for (size_t type = 0; type < CONTENT_SETTINGS_NUM_TYPES; ++type) { |
| + if (content_type == GetTypeName(ContentSettingsType(type))) { |
| + bool bool_value = true; |
| + bool rv = i.value().GetAsBoolean(&bool_value); |
| + DCHECK(rv); |
| + override_settings_[ContentSettingsType(type)] = bool_value; |
| + break; |
| + } |
| + } |
| + } |
| + } |
| +} |
| +} // namespace content_settings |