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

Unified Diff: chrome/browser/geolocation/geolocation_content_settings_map.cc

Issue 5398001: Allow default desktop content settings to be managed via policy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 10 years 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/geolocation/geolocation_content_settings_map.cc
diff --git a/chrome/browser/geolocation/geolocation_content_settings_map.cc b/chrome/browser/geolocation/geolocation_content_settings_map.cc
index 2eb2f747760b08cf4b410c373beaa1468a82dc73..cdbe1a840fe8104c0aa805f8d0de4f2e452043db 100644
--- a/chrome/browser/geolocation/geolocation_content_settings_map.cc
+++ b/chrome/browser/geolocation/geolocation_content_settings_map.cc
@@ -18,10 +18,13 @@
#include "base/string_piece.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/content_settings/content_settings_details.h"
+#include "chrome/browser/content_settings/content_settings_pattern.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/scoped_pref_update.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/notification_service.h"
+#include "chrome/common/notification_source.h"
#include "chrome/common/notification_type.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
@@ -35,6 +38,11 @@ const ContentSetting
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, NotificationType::PROFILE_DESTROYED,
+ Source<Profile>(profile_));
}
// static
@@ -46,6 +54,9 @@ void GeolocationContentSettingsMap::RegisterUserPrefs(PrefService* prefs) {
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));
@@ -53,6 +64,15 @@ ContentSetting GeolocationContentSettingsMap::GetDefaultContentSetting() const {
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 {
@@ -61,7 +81,9 @@ ContentSetting GeolocationContentSettingsMap::GetContentSetting(
GURL requesting_origin(requesting_url.GetOrigin());
GURL embedding_origin(embedding_url.GetOrigin());
DCHECK(requesting_origin.is_valid() && embedding_origin.is_valid());
-
+ // If the profile is destroyed (and set to NULL) return true.
jochen (gone - plz use gerrit) 2010/12/09 14:36:28 true -> CONTENT_SETTING_BLOCK
markusheintz_ 2010/12/15 12:15:58 Done.
+ if (!profile_)
+ return CONTENT_SETTING_BLOCK;
const DictionaryValue* all_settings_dictionary =
profile_->GetPrefs()->GetDictionary(prefs::kGeolocationContentSettings);
// Careful: The returned value could be NULL if the pref has never been set.
@@ -114,6 +136,8 @@ GeolocationContentSettingsMap::AllOriginsSettings
void GeolocationContentSettingsMap::SetDefaultContentSetting(
ContentSetting setting) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (!profile_)
+ return;
profile_->GetPrefs()->SetInteger(prefs::kGeolocationDefaultContentSetting,
setting == CONTENT_SETTING_DEFAULT ?
kDefaultSetting : setting);
@@ -130,6 +154,8 @@ void GeolocationContentSettingsMap::SetContentSetting(
GURL embedding_origin(embedding_url.GetOrigin());
DCHECK(requesting_origin.is_valid());
DCHECK(embedding_origin.is_valid() || embedding_url.is_empty());
+ if (!profile_)
+ return;
PrefService* prefs = profile_->GetPrefs();
DictionaryValue* all_settings_dictionary = prefs->GetMutableDictionary(
prefs::kGeolocationContentSettings);
@@ -154,20 +180,59 @@ void GeolocationContentSettingsMap::SetContentSetting(
requesting_origin.spec(), requesting_origin_settings_dictionary);
}
DCHECK(requesting_origin_settings_dictionary);
- requesting_origin_settings_dictionary->SetWithoutPathExpansion(
+ requesting_origin_settings_dictionary->SetWithoutPathExpansion(
jochen (gone - plz use gerrit) 2010/12/09 14:36:28 no indent
markusheintz_ 2010/12/15 12:15:58 Done.
embedding_origin.spec(), Value::CreateIntegerValue(setting));
}
}
void GeolocationContentSettingsMap::ResetToDefault() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
+ if (!profile_)
+ return;
PrefService* prefs = profile_->GetPrefs();
prefs->ClearPref(prefs::kGeolocationDefaultContentSetting);
prefs->ClearPref(prefs::kGeolocationContentSettings);
}
+void GeolocationContentSettingsMap::NotifyObservers(
+ const ContentSettingsDetails& details) {
+ NotificationService::current()->Notify(
+ NotificationType::CONTENT_SETTINGS_CHANGED,
jochen (gone - plz use gerrit) 2010/12/09 14:36:28 hum, now that I see this (and ran into a similar b
markusheintz_ 2010/12/15 12:15:58 Done.
+ Source<GeolocationContentSettingsMap>(this),
+ Details<const ContentSettingsDetails>(&details));
+}
+
+void GeolocationContentSettingsMap::Observe(
+ NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (NotificationType::PREF_CHANGED == type) {
jochen (gone - plz use gerrit) 2010/12/09 14:36:28 type == NotificationType::PREF_CHANGED (see coding
markusheintz_ 2010/12/15 12:15:58 Done.
+ const std::string& name = *Details<std::string>(details).ptr();
+ if (name == prefs::kGeolocationDefaultContentSetting) {
+ NotifyObservers(ContentSettingsDetails(
+ ContentSettingsPattern(),
+ CONTENT_SETTINGS_TYPE_DEFAULT,
+ ""));
+ }
+ } else if (NotificationType::PROFILE_DESTROYED == type) {
+ UnregisterObservers();
+ } else {
+ NOTREACHED();
+ }
+}
+
+void GeolocationContentSettingsMap::UnregisterObservers() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (!profile_)
+ return;
+ prefs_registrar_.RemoveAll();
+ notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED,
+ Source<Profile>(profile_));
+ profile_ = NULL;
+}
+
GeolocationContentSettingsMap::~GeolocationContentSettingsMap() {
+ UnregisterObservers();
}
// static

Powered by Google App Engine
This is Rietveld 408576698