summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authormarkusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-19 14:50:08 +0000
committermarkusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-19 14:50:08 +0000
commit3c2e12d927c4bb559bd4eb3824c4e1fa43a44baf (patch)
tree5bbac630f80f7137783e6e771802c06731887491 /chrome
parent964361c7ca8d3db84751130de8825550fcfd5025 (diff)
downloadchromium_src-3c2e12d927c4bb559bd4eb3824c4e1fa43a44baf.zip
chromium_src-3c2e12d927c4bb559bd4eb3824c4e1fa43a44baf.tar.gz
chromium_src-3c2e12d927c4bb559bd4eb3824c4e1fa43a44baf.tar.bz2
Migrate default geolocation content setting to host content settings map.
BUG=TODO TEST=geolocation_content_settings_map_unittest.cc, content_settings_pref_provider_unittest.cc, host_content_settings_map_unittest.cc Review URL: http://codereview.chromium.org/7328018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93018 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/content_settings/content_settings_policy_provider.cc8
-rw-r--r--chrome/browser/content_settings/content_settings_policy_provider_unittest.cc38
-rw-r--r--chrome/browser/content_settings/content_settings_pref_provider.cc39
-rw-r--r--chrome/browser/content_settings/content_settings_pref_provider.h1
-rw-r--r--chrome/browser/content_settings/content_settings_pref_provider_unittest.cc40
-rw-r--r--chrome/browser/geolocation/geolocation_content_settings_map.cc58
-rw-r--r--chrome/browser/geolocation/geolocation_content_settings_map.h16
-rw-r--r--chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc35
-rw-r--r--chrome/browser/geolocation/geolocation_settings_state.cc8
-rw-r--r--chrome/browser/policy/configuration_policy_pref_store.cc2
-rw-r--r--chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc6
-rw-r--r--chrome/browser/ui/webui/options/content_settings_handler.cc23
-rw-r--r--chrome/common/pref_names.cc2
-rw-r--r--chrome/common/pref_names.h1
14 files changed, 171 insertions, 106 deletions
diff --git a/chrome/browser/content_settings/content_settings_policy_provider.cc b/chrome/browser/content_settings/content_settings_policy_provider.cc
index 5274b1a..f2f9bd1 100644
--- a/chrome/browser/content_settings/content_settings_policy_provider.cc
+++ b/chrome/browser/content_settings/content_settings_policy_provider.cc
@@ -35,7 +35,7 @@ const char* kPrefToManageType[CONTENT_SETTINGS_NUM_TYPES] = {
prefs::kManagedDefaultJavaScriptSetting,
prefs::kManagedDefaultPluginsSetting,
prefs::kManagedDefaultPopupsSetting,
- NULL, // Not used for Geolocation
+ prefs::kManagedDefaultGeolocationSetting,
NULL, // Not used for Notifications
};
@@ -118,6 +118,7 @@ PolicyDefaultProvider::PolicyDefaultProvider(PrefService* prefs)
pref_change_registrar_.Add(prefs::kManagedDefaultJavaScriptSetting, this);
pref_change_registrar_.Add(prefs::kManagedDefaultPluginsSetting, this);
pref_change_registrar_.Add(prefs::kManagedDefaultPopupsSetting, this);
+ pref_change_registrar_.Add(prefs::kManagedDefaultGeolocationSetting, this);
}
PolicyDefaultProvider::~PolicyDefaultProvider() {
@@ -164,6 +165,8 @@ void PolicyDefaultProvider::Observe(int type,
UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_PLUGINS);
} else if (*name == prefs::kManagedDefaultPopupsSetting) {
UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_POPUPS);
+ } else if (*name == prefs::kManagedDefaultGeolocationSetting) {
+ UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION);
} else {
NOTREACHED() << "Unexpected preference observed";
return;
@@ -229,6 +232,9 @@ void PolicyDefaultProvider::RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterIntegerPref(prefs::kManagedDefaultPopupsSetting,
CONTENT_SETTING_DEFAULT,
PrefService::UNSYNCABLE_PREF);
+ prefs->RegisterIntegerPref(prefs::kManagedDefaultGeolocationSetting,
+ CONTENT_SETTING_DEFAULT,
+ PrefService::UNSYNCABLE_PREF);
}
// ////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/content_settings/content_settings_policy_provider_unittest.cc b/chrome/browser/content_settings/content_settings_policy_provider_unittest.cc
index c827f188..5415254 100644
--- a/chrome/browser/content_settings/content_settings_policy_provider_unittest.cc
+++ b/chrome/browser/content_settings/content_settings_policy_provider_unittest.cc
@@ -58,6 +58,44 @@ TEST_F(PolicyDefaultProviderTest, DefaultValues) {
provider.ShutdownOnUIThread();
}
+TEST_F(PolicyDefaultProviderTest, DefaultGeolocationContentSetting) {
+ TestingProfile profile;
+ TestingPrefService* prefs = profile.GetTestingPrefService();
+ PolicyDefaultProvider provider(prefs);
+
+ // By default, policies should be off.
+ EXPECT_FALSE(
+ provider.DefaultSettingIsManaged(CONTENT_SETTINGS_TYPE_GEOLOCATION));
+ EXPECT_EQ(CONTENT_SETTING_DEFAULT,
+ provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION));
+
+ prefs->SetInteger(prefs::kGeolocationDefaultContentSetting,
+ CONTENT_SETTING_ALLOW);
+ EXPECT_FALSE(
+ provider.DefaultSettingIsManaged(CONTENT_SETTINGS_TYPE_GEOLOCATION));
+ EXPECT_EQ(CONTENT_SETTING_DEFAULT,
+ provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION));
+
+ //
+ prefs->SetManagedPref(prefs::kGeolocationDefaultContentSetting,
+ Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
+ EXPECT_FALSE(
+ provider.DefaultSettingIsManaged(CONTENT_SETTINGS_TYPE_GEOLOCATION));
+ EXPECT_EQ(CONTENT_SETTING_DEFAULT,
+ provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION));
+
+ // Change the managed value of the default geolocation setting
+ prefs->SetManagedPref(prefs::kManagedDefaultGeolocationSetting,
+ Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
+
+ EXPECT_TRUE(
+ provider.DefaultSettingIsManaged(CONTENT_SETTINGS_TYPE_GEOLOCATION));
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION));
+
+ provider.ShutdownOnUIThread();
+}
+
// When a default-content-setting is set to a managed setting a
// CONTENT_SETTINGS_CHANGED notification should be fired. The same should happen
// if the managed setting is removed.
diff --git a/chrome/browser/content_settings/content_settings_pref_provider.cc b/chrome/browser/content_settings/content_settings_pref_provider.cc
index 2658887..f35f92e 100644
--- a/chrome/browser/content_settings/content_settings_pref_provider.cc
+++ b/chrome/browser/content_settings/content_settings_pref_provider.cc
@@ -51,7 +51,7 @@ const ContentSetting kDefaultSettings[] = {
CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_JAVASCRIPT
CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_PLUGINS
CONTENT_SETTING_BLOCK, // CONTENT_SETTINGS_TYPE_POPUPS
- CONTENT_SETTING_ASK, // Not used for Geolocation
+ CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_GEOLOCATION
CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_NOTIFICATIONS
};
COMPILE_ASSERT(arraysize(kDefaultSettings) == CONTENT_SETTINGS_NUM_TYPES,
@@ -64,9 +64,9 @@ const char* kTypeNames[] = {
"javascript",
"plugins",
"popups",
- NULL, // Not used for Geolocation
// TODO(markusheintz): Refactoring in progress. Content settings exceptions
- // for notifications will be added next.
+ // for notifications and geolocation will be added next.
+ "geolocation", // Only used for default Geolocation settings
"notifications", // Only used for default Notifications settings.
};
COMPILE_ASSERT(arraysize(kTypeNames) == CONTENT_SETTINGS_NUM_TYPES,
@@ -155,6 +155,7 @@ PrefDefaultProvider::PrefDefaultProvider(PrefService* prefs,
updating_preferences_(false) {
DCHECK(prefs_);
MigrateObsoleteNotificationPref();
+ MigrateObsoleteGeolocationPref();
// Read global defaults.
DCHECK_EQ(arraysize(kTypeNames),
@@ -171,6 +172,7 @@ PrefDefaultProvider::PrefDefaultProvider(PrefService* prefs,
pref_change_registrar_.Init(prefs_);
pref_change_registrar_.Add(prefs::kDefaultContentSettings, this);
+ pref_change_registrar_.Add(prefs::kGeolocationDefaultContentSetting, this);
}
PrefDefaultProvider::~PrefDefaultProvider() {
@@ -188,7 +190,7 @@ void PrefDefaultProvider::UpdateDefaultSetting(
ContentSetting setting) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(prefs_);
- DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation.
+ DCHECK(kTypeNames[content_type] != NULL);
// The default settings may not be directly modified for OTR sessions.
// Instead, they are synced to the main profile's setting.
@@ -212,6 +214,14 @@ void PrefDefaultProvider::UpdateDefaultSetting(
default_settings_dictionary->SetWithoutPathExpansion(
dictionary_path, Value::CreateIntegerValue(setting));
}
+
+ // Keep the obsolete pref in sync as long as backwards compatibility is
+ // required. This is required to keep sync working correctly.
+ if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
+ prefs_->SetInteger(prefs::kGeolocationDefaultContentSetting,
+ setting == CONTENT_SETTING_DEFAULT ?
+ kDefaultSettings[content_type] : setting);
+ }
}
NotifyObservers(ContentSettingsPattern(),
@@ -238,6 +248,12 @@ void PrefDefaultProvider::Observe(int type,
std::string* name = Details<std::string>(details).ptr();
if (*name == prefs::kDefaultContentSettings) {
ReadDefaultSettings(true);
+ } else if (*name == prefs::kGeolocationDefaultContentSetting) {
+ MigrateObsoleteGeolocationPref();
+ // Return and don't send a notifications. Migrating the obsolete
+ // geolocation pref will change the prefs::kDefaultContentSettings and
+ // cause the notification to be fired.
+ return;
} else {
NOTREACHED() << "Unexpected preference observed";
return;
@@ -323,6 +339,16 @@ void PrefDefaultProvider::MigrateObsoleteNotificationPref() {
}
}
+void PrefDefaultProvider::MigrateObsoleteGeolocationPref() {
+ if (prefs_->HasPrefPath(prefs::kGeolocationDefaultContentSetting)) {
+ ContentSetting setting = IntToContentSetting(
+ prefs_->GetInteger(prefs::kGeolocationDefaultContentSetting));
+ UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION, setting);
+ // Do not clear the old preference yet as long as we need to maintain
+ // backward compatibility.
+ }
+}
+
// static
void PrefDefaultProvider::RegisterUserPrefs(PrefService* prefs) {
// The registration of the preference prefs::kDefaultContentSettings should
@@ -342,6 +368,10 @@ void PrefDefaultProvider::RegisterUserPrefs(PrefService* prefs) {
prefs::kDesktopNotificationDefaultContentSetting,
kDefaultSettings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS],
PrefService::SYNCABLE_PREF);
+ prefs->RegisterIntegerPref(
+ prefs::kGeolocationDefaultContentSetting,
+ kDefaultSettings[CONTENT_SETTINGS_TYPE_GEOLOCATION],
+ PrefService::UNSYNCABLE_PREF);
}
// ////////////////////////////////////////////////////////////////////////////
@@ -386,7 +416,6 @@ PrefProvider::PrefProvider(PrefService* prefs,
}
if (prefs_->GetInteger(prefs::kContentSettingsVersion) >
ContentSettingsPattern::kContentSettingsPatternVersion) {
- LOG(ERROR) << "Unknown content settings version in preferences.";
return;
}
diff --git a/chrome/browser/content_settings/content_settings_pref_provider.h b/chrome/browser/content_settings/content_settings_pref_provider.h
index 59ce76d..9c717a2 100644
--- a/chrome/browser/content_settings/content_settings_pref_provider.h
+++ b/chrome/browser/content_settings/content_settings_pref_provider.h
@@ -70,6 +70,7 @@ class PrefDefaultProvider : public ObservableDefaultProvider,
void ReadDefaultSettings(bool overwrite);
void MigrateObsoleteNotificationPref();
+ void MigrateObsoleteGeolocationPref();
// Copies of the pref data, so that we can read it on the IO thread.
ContentSettings default_content_settings_;
diff --git a/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc b/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc
index c05422c..f42c792 100644
--- a/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc
+++ b/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc
@@ -55,6 +55,13 @@ TEST_F(PrefDefaultProviderTest, DefaultValues) {
CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
provider_.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
+
+ EXPECT_EQ(CONTENT_SETTING_ASK,
+ provider_.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION));
+ provider_.UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ CONTENT_SETTING_BLOCK);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ provider_.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION));
}
TEST_F(PrefDefaultProviderTest, Observer) {
@@ -68,6 +75,12 @@ TEST_F(PrefDefaultProviderTest, Observer) {
provider_.UpdateDefaultSetting(
CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
+
+ EXPECT_CALL(mock_observer,
+ OnContentSettingChanged(
+ _, _, CONTENT_SETTINGS_TYPE_GEOLOCATION, ""));
+ provider_.UpdateDefaultSetting(
+ CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_BLOCK);
}
TEST_F(PrefDefaultProviderTest, ObserveDefaultPref) {
@@ -126,6 +139,33 @@ TEST_F(PrefDefaultProviderTest, OffTheRecord) {
otr_provider.ShutdownOnUIThread();
}
+TEST_F(PrefDefaultProviderTest, MigrateDefaultGeolocationContentSetting) {
+ TestingProfile profile;
+ TestingPrefService* prefs = profile.GetTestingPrefService();
+
+ // Set obsolete preference and test if it is migrated correctly.
+ prefs->SetInteger(prefs::kGeolocationDefaultContentSetting,
+ CONTENT_SETTING_ALLOW);
+ PrefDefaultProvider provider(prefs, false);
+
+ MockObserver mock_observer;
+ EXPECT_CALL(mock_observer,
+ OnContentSettingChanged(
+ _, _, CONTENT_SETTINGS_TYPE_GEOLOCATION, ""));
+ provider.AddObserver(&mock_observer);
+
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION));
+
+ // Change obsolete preference and test if it migrated correctly.
+ prefs->SetInteger(prefs::kGeolocationDefaultContentSetting,
+ CONTENT_SETTING_BLOCK);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION));
+
+ provider.ShutdownOnUIThread();
+}
+
// ////////////////////////////////////////////////////////////////////////////
// PrefProviderTest
//
diff --git a/chrome/browser/geolocation/geolocation_content_settings_map.cc b/chrome/browser/geolocation/geolocation_content_settings_map.cc
index 7c90c58..5620421 100644
--- a/chrome/browser/geolocation/geolocation_content_settings_map.cc
+++ b/chrome/browser/geolocation/geolocation_content_settings_map.cc
@@ -21,6 +21,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/content_settings/content_settings_details.h"
#include "chrome/browser/content_settings/content_settings_pattern.h"
+#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/profiles/profile.h"
@@ -33,50 +34,25 @@
#include "net/base/dns_util.h"
#include "net/base/static_cookie_policy.h"
-// static
-const ContentSetting
- GeolocationContentSettingsMap::kDefaultSetting = CONTENT_SETTING_ASK;
-
GeolocationContentSettingsMap::GeolocationContentSettingsMap(Profile* profile)
: profile_(profile) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
prefs_registrar_.Init(profile_->GetPrefs());
- prefs_registrar_.Add(prefs::kGeolocationDefaultContentSetting, this);
prefs_registrar_.Add(prefs::kGeolocationContentSettings, this);
notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
Source<Profile>(profile_));
+ notification_registrar_.Add(
+ this,
+ chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED,
+ Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()));
}
// static
void GeolocationContentSettingsMap::RegisterUserPrefs(PrefService* prefs) {
- prefs->RegisterIntegerPref(prefs::kGeolocationDefaultContentSetting,
- CONTENT_SETTING_ASK,
- PrefService::SYNCABLE_PREF);
prefs->RegisterDictionaryPref(prefs::kGeolocationContentSettings,
PrefService::SYNCABLE_PREF);
}
-ContentSetting GeolocationContentSettingsMap::GetDefaultContentSetting() const {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- // If the profile is destroyed (and set to NULL) return CONTENT_SETTING_BLOCK.
- if (!profile_)
- return CONTENT_SETTING_BLOCK;
- const PrefService* prefs = profile_->GetPrefs();
- const ContentSetting default_content_setting = IntToContentSetting(
- prefs->GetInteger(prefs::kGeolocationDefaultContentSetting));
- return default_content_setting == CONTENT_SETTING_DEFAULT ?
- kDefaultSetting : default_content_setting;
-}
-
-bool GeolocationContentSettingsMap::IsDefaultContentSettingManaged() const {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- // If the profile is destroyed (and set to NULL) return true.
- if (!profile_)
- return true;
- return profile_->GetPrefs()->IsManagedPreference(
- prefs::kGeolocationDefaultContentSetting);
-}
-
ContentSetting GeolocationContentSettingsMap::GetContentSetting(
const GURL& requesting_url,
const GURL& embedding_url) const {
@@ -106,7 +82,8 @@ ContentSetting GeolocationContentSettingsMap::GetContentSetting(
return IntToContentSetting(setting);
}
}
- return GetDefaultContentSetting();
+ return profile_->GetHostContentSettingsMap()->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_GEOLOCATION);
}
GeolocationContentSettingsMap::AllOriginsSettings
@@ -137,16 +114,6 @@ GeolocationContentSettingsMap::AllOriginsSettings
return content_settings;
}
-void GeolocationContentSettingsMap::SetDefaultContentSetting(
- ContentSetting setting) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (!profile_)
- return;
- profile_->GetPrefs()->SetInteger(prefs::kGeolocationDefaultContentSetting,
- setting == CONTENT_SETTING_DEFAULT ?
- kDefaultSetting : setting);
-}
-
void GeolocationContentSettingsMap::SetContentSetting(
const GURL& requesting_url,
const GURL& embedding_url,
@@ -192,8 +159,9 @@ void GeolocationContentSettingsMap::ResetToDefault() {
if (!profile_)
return;
PrefService* prefs = profile_->GetPrefs();
- prefs->ClearPref(prefs::kGeolocationDefaultContentSetting);
prefs->ClearPref(prefs::kGeolocationContentSettings);
+ profile_->GetHostContentSettingsMap()->SetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_DEFAULT);
}
void GeolocationContentSettingsMap::NotifyObservers(
@@ -209,8 +177,10 @@ void GeolocationContentSettingsMap::Observe(
const NotificationSource& source,
const NotificationDetails& details) {
if (type == chrome::NOTIFICATION_PREF_CHANGED) {
- const std::string& name = *Details<std::string>(details).ptr();
- if (name == prefs::kGeolocationDefaultContentSetting) {
+ } else if (type == chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED) {
+ const ContentSettingsType& content_type =
+ Details<ContentSettingsDetails>(details).ptr()->type();
+ if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
ContentSettingsDetails details(ContentSettingsPattern(),
ContentSettingsPattern(),
CONTENT_SETTINGS_TYPE_DEFAULT,
@@ -245,7 +215,7 @@ void GeolocationContentSettingsMap::GetOneOriginSettingsFromDictionary(
for (DictionaryValue::key_iterator i(dictionary->begin_keys());
i != dictionary->end_keys(); ++i) {
const std::string& target(*i);
- int setting = kDefaultSetting;
+ int setting = 0;
bool found = dictionary->GetIntegerWithoutPathExpansion(target, &setting);
DCHECK(found);
GURL target_url(target);
diff --git a/chrome/browser/geolocation/geolocation_content_settings_map.h b/chrome/browser/geolocation/geolocation_content_settings_map.h
index 640ae96..286e1f9 100644
--- a/chrome/browser/geolocation/geolocation_content_settings_map.h
+++ b/chrome/browser/geolocation/geolocation_content_settings_map.h
@@ -44,14 +44,6 @@ class GeolocationContentSettingsMap
static void RegisterUserPrefs(PrefService* prefs);
- // Returns the default setting.
- //
- // This should only be called on the UI thread.
- ContentSetting GetDefaultContentSetting() const;
-
- // Returns true if the content setting is managed (set by a policy).
- bool IsDefaultContentSettingManaged() const;
-
// Returns a single ContentSetting which applies to the given |requesting_url|
// when embedded in a top-level page from |embedding_url|. To determine the
// setting for a top-level page, as opposed to a frame embedded in a page,
@@ -67,11 +59,6 @@ class GeolocationContentSettingsMap
// This should only be called on the UI thread.
AllOriginsSettings GetAllOriginsSettings() const;
- // Sets the default setting.
- //
- // This should only be called on the UI thread.
- void SetDefaultContentSetting(ContentSetting setting);
-
// Sets the content setting for a particular (requesting origin, embedding
// origin) pair. If the embedding origin is the same as the requesting
// origin, this represents the setting used when the requesting origin is
@@ -101,9 +88,6 @@ class GeolocationContentSettingsMap
private:
friend class base::RefCountedThreadSafe<GeolocationContentSettingsMap>;
- // The default setting.
- static const ContentSetting kDefaultSetting;
-
// Sends a CONTENT_SETTINGS_CHANGED notification.
void NotifyObservers(const ContentSettingsDetails& details);
diff --git a/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc b/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc
index af6bec9..b99abe7 100644
--- a/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc
+++ b/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc
@@ -4,6 +4,7 @@
#include "base/message_loop.h"
#include "chrome/browser/content_settings/content_settings_details.h"
+#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
@@ -69,17 +70,6 @@ class GeolocationContentSettingsMapTests : public testing::Test {
BrowserThread ui_thread_;
};
-TEST_F(GeolocationContentSettingsMapTests, DefaultValues) {
- TestingProfile profile;
- GeolocationContentSettingsMap* map =
- profile.GetGeolocationContentSettingsMap();
-
- // Check setting defaults.
- EXPECT_EQ(CONTENT_SETTING_ASK, map->GetDefaultContentSetting());
- map->SetDefaultContentSetting(CONTENT_SETTING_BLOCK);
- EXPECT_EQ(CONTENT_SETTING_BLOCK, map->GetDefaultContentSetting());
-}
-
TEST_F(GeolocationContentSettingsMapTests, Embedder) {
TestingProfile profile;
GeolocationContentSettingsMap* map =
@@ -243,7 +233,8 @@ TEST_F(GeolocationContentSettingsMapTests, WildCardForEmptyEmbedder) {
// Change the wildcard behavior.
map->SetContentSetting(requester_0, embedder_0, CONTENT_SETTING_ALLOW);
map->SetContentSetting(requester_0, empty_url, CONTENT_SETTING_BLOCK);
- map->SetDefaultContentSetting(CONTENT_SETTING_ALLOW);
+ profile.GetHostContentSettingsMap()->SetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_ALLOW);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
map->GetContentSetting(requester_0, embedder_0));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
@@ -270,7 +261,9 @@ TEST_F(GeolocationContentSettingsMapTests, IgnoreInvalidURLsInPrefs) {
GeolocationContentSettingsMap* map =
profile.GetGeolocationContentSettingsMap();
- EXPECT_EQ(CONTENT_SETTING_ASK, map->GetDefaultContentSetting());
+ EXPECT_EQ(CONTENT_SETTING_ASK,
+ profile.GetHostContentSettingsMap()->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_GEOLOCATION));
// Check the valid entry was read OK.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
@@ -293,7 +286,9 @@ TEST_F(GeolocationContentSettingsMapTests, Observe) {
profile.GetGeolocationContentSettingsMap();
MockGeolocationSettingsObserver observer;
- EXPECT_EQ(CONTENT_SETTING_ASK, map->GetDefaultContentSetting());
+ EXPECT_EQ(CONTENT_SETTING_ASK,
+ profile.GetHostContentSettingsMap()->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_GEOLOCATION));
// Test if a GEOLOCATION_SETTINGS_CHANGED notification is sent after
// the geolocation default content setting was changed through calling the
@@ -301,18 +296,22 @@ TEST_F(GeolocationContentSettingsMapTests, Observe) {
EXPECT_CALL(
observer,
OnContentSettingsChanged(map, CONTENT_SETTINGS_TYPE_DEFAULT));
- map->SetDefaultContentSetting(CONTENT_SETTING_BLOCK);
+ profile.GetHostContentSettingsMap()->SetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_BLOCK);
::testing::Mock::VerifyAndClearExpectations(&observer);
- // Test if a GEOLOCATION_SETTINGS_CHANGED notification is sent after
- // the preference kGeolocationDefaultContentSetting was changed.
+ // Test if a GEOLOCATION_SETTINGS_CHANGED notification is sent after the
+ // obsolete preference kGeolocationDefaultContentSetting was changed.
PrefService* prefs = profile.GetPrefs();
EXPECT_CALL(
observer,
OnContentSettingsChanged(map, CONTENT_SETTINGS_TYPE_DEFAULT));
prefs->SetInteger(prefs::kGeolocationDefaultContentSetting,
CONTENT_SETTING_ALLOW);
- EXPECT_EQ(CONTENT_SETTING_ALLOW, map->GetDefaultContentSetting());
+
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ profile.GetHostContentSettingsMap()->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_GEOLOCATION));
}
} // namespace
diff --git a/chrome/browser/geolocation/geolocation_settings_state.cc b/chrome/browser/geolocation/geolocation_settings_state.cc
index 751904e..b07436e 100644
--- a/chrome/browser/geolocation/geolocation_settings_state.cc
+++ b/chrome/browser/geolocation/geolocation_settings_state.cc
@@ -4,8 +4,11 @@
#include "chrome/browser/geolocation/geolocation_settings_state.h"
+#include <string>
+
#include "base/string_piece.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
@@ -54,8 +57,9 @@ void GeolocationSettingsState::GetDetailedInfo(
unsigned int* tab_state_flags) const {
DCHECK(tab_state_flags);
DCHECK(embedder_url_.is_valid());
- const ContentSetting default_setting =
- profile_->GetGeolocationContentSettingsMap()->GetDefaultContentSetting();
+ ContentSetting default_setting =
+ profile_->GetHostContentSettingsMap()->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_GEOLOCATION);
std::set<std::string> formatted_hosts;
std::set<std::string> repeated_formatted_hosts;
diff --git a/chrome/browser/policy/configuration_policy_pref_store.cc b/chrome/browser/policy/configuration_policy_pref_store.cc
index 7291544..9cfdb62 100644
--- a/chrome/browser/policy/configuration_policy_pref_store.cc
+++ b/chrome/browser/policy/configuration_policy_pref_store.cc
@@ -236,7 +236,7 @@ const ConfigurationPolicyPrefKeeper::PolicyToPreferenceMapEntry
{ Value::TYPE_INTEGER, kPolicyDefaultNotificationSetting,
prefs::kDesktopNotificationDefaultContentSetting },
{ Value::TYPE_INTEGER, kPolicyDefaultGeolocationSetting,
- prefs::kGeolocationDefaultContentSetting },
+ prefs::kManagedDefaultGeolocationSetting },
{ Value::TYPE_STRING, kPolicyAuthSchemes,
prefs::kAuthSchemes },
{ Value::TYPE_BOOLEAN, kPolicyDisableAuthNegotiateCnameLookup,
diff --git a/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc b/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc
index 65e2c0f..01b2ebf 100644
--- a/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc
+++ b/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc
@@ -190,7 +190,8 @@ TEST_F(ContentSettingBubbleModelTest, Geolocation) {
CheckGeolocationBubble(1, true, false);
// Change the default to allow: no message needed.
- setting_map->SetDefaultContentSetting(CONTENT_SETTING_ALLOW);
+ profile_->GetHostContentSettingsMap()->SetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_ALLOW);
CheckGeolocationBubble(1, false, false);
// Second frame denied, but not stored in the content map: requires reload.
@@ -198,7 +199,8 @@ TEST_F(ContentSettingBubbleModelTest, Geolocation) {
CheckGeolocationBubble(2, false, true);
// Change the default to block: offer a clear link for the persisted frame 1.
- setting_map->SetDefaultContentSetting(CONTENT_SETTING_BLOCK);
+ profile_->GetHostContentSettingsMap()->SetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_BLOCK);
CheckGeolocationBubble(2, true, false);
}
diff --git a/chrome/browser/ui/webui/options/content_settings_handler.cc b/chrome/browser/ui/webui/options/content_settings_handler.cc
index ccb51dc..cb4b0b6 100644
--- a/chrome/browser/ui/webui/options/content_settings_handler.cc
+++ b/chrome/browser/ui/webui/options/content_settings_handler.cc
@@ -292,7 +292,6 @@ void ContentSettingsHandler::Initialize() {
PrefService* prefs = web_ui_->GetProfile()->GetPrefs();
pref_change_registrar_.Init(prefs);
- pref_change_registrar_.Add(prefs::kGeolocationDefaultContentSetting, this);
pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this);
}
@@ -328,9 +327,7 @@ void ContentSettingsHandler::Observe(int type,
case chrome::NOTIFICATION_PREF_CHANGED: {
const std::string& pref_name = *Details<std::string>(details).ptr();
- if (pref_name == prefs::kGeolocationDefaultContentSetting)
- UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION);
- else if (pref_name == prefs::kGeolocationContentSettings)
+ if (pref_name == prefs::kGeolocationContentSettings)
UpdateGeolocationExceptionsView();
break;
}
@@ -370,14 +367,12 @@ void ContentSettingsHandler::UpdateSettingDefaultFromModel(
std::string ContentSettingsHandler::GetSettingDefaultFromModel(
ContentSettingsType type) {
ContentSetting default_setting;
- if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
- default_setting = web_ui_->GetProfile()->
- GetGeolocationContentSettingsMap()->GetDefaultContentSetting();
- } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
+ if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
default_setting = DesktopNotificationServiceFactory::GetForProfile(
web_ui_->GetProfile())->GetDefaultContentSetting();
} else {
- default_setting = GetContentSettingsMap()->GetDefaultContentSetting(type);
+ default_setting = web_ui_->GetProfile()->
+ GetHostContentSettingsMap()->GetDefaultContentSetting(type);
}
return ContentSettingToString(default_setting);
@@ -385,10 +380,7 @@ std::string ContentSettingsHandler::GetSettingDefaultFromModel(
bool ContentSettingsHandler::GetDefaultSettingManagedFromModel(
ContentSettingsType type) {
- if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
- return web_ui_->GetProfile()->
- GetGeolocationContentSettingsMap()->IsDefaultContentSettingManaged();
- } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
+ if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
return DesktopNotificationServiceFactory::GetForProfile(
web_ui_->GetProfile())->IsDefaultContentSettingManaged();
} else {
@@ -587,10 +579,7 @@ void ContentSettingsHandler::SetContentFilter(const ListValue* args) {
ContentSetting default_setting = ContentSettingFromString(setting);
ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group);
- if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
- web_ui_->GetProfile()->GetGeolocationContentSettingsMap()->
- SetDefaultContentSetting(default_setting);
- } else if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
+ if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
DesktopNotificationServiceFactory::GetForProfile(web_ui_->GetProfile())->
SetDefaultContentSetting(default_setting);
} else {
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index 25d54d8..2d6d4ab 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -1353,6 +1353,8 @@ const char kManagedDefaultPluginsSetting[] =
"profile.managed_default_content_settings.plugins";
const char kManagedDefaultPopupsSetting[] =
"profile.managed_default_content_settings.popups";
+const char kManagedDefaultGeolocationSetting[] =
+ "profile.managed_default_content_settings.geolocation";
// Preferences that are exclusively used to store managed
// content settings patterns.
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 7458130..6dd2468 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -470,6 +470,7 @@ extern const char kManagedDefaultImagesSetting[];
extern const char kManagedDefaultJavaScriptSetting[];
extern const char kManagedDefaultPluginsSetting[];
extern const char kManagedDefaultPopupsSetting[];
+extern const char kManagedDefaultGeolocationSetting[];
extern const char kManagedCookiesAllowedForUrls[];
extern const char kManagedCookiesBlockedForUrls[];