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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 // Implementation of the geolocation content settings map. Styled on 5 // Implementation of the geolocation content settings map. Styled on
6 // HostContentSettingsMap however unlike that class, this one does not hold 6 // HostContentSettingsMap however unlike that class, this one does not hold
7 // an additional in-memory copy of the settings as it does not need to support 7 // an additional in-memory copy of the settings as it does not need to support
8 // thread safe synchronous access to the settings; all geolocation permissions 8 // thread safe synchronous access to the settings; all geolocation permissions
9 // are read and written in the UI thread. (If in future this is no longer the 9 // are read and written in the UI thread. (If in future this is no longer the
10 // case, refer to http://codereview.chromium.org/1525018 for a previous version 10 // case, refer to http://codereview.chromium.org/1525018 for a previous version
11 // with caching. Note that as we must observe the prefs store for settings 11 // with caching. Note that as we must observe the prefs store for settings
12 // changes, e.g. coming from the sync engine, the simplest design would be to 12 // changes, e.g. coming from the sync engine, the simplest design would be to
13 // always write-through changes straight to the prefs store, and rely on the 13 // always write-through changes straight to the prefs store, and rely on the
14 // notification observer to subsequently update any cached copy). 14 // notification observer to subsequently update any cached copy).
15 15
16 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" 16 #include "chrome/browser/geolocation/geolocation_content_settings_map.h"
17 17
18 #include "base/string_piece.h" 18 #include "base/string_piece.h"
19 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
20 #include "chrome/browser/browser_thread.h" 20 #include "chrome/browser/browser_thread.h"
21 #include "chrome/browser/prefs/pref_service.h" 21 #include "chrome/browser/prefs/pref_service.h"
22 #include "chrome/browser/prefs/scoped_pref_update.h" 22 #include "chrome/browser/prefs/scoped_pref_update.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/common/content_settings_types.h"
jochen (gone - plz use gerrit) 2010/12/07 09:43:52 why did you need this?
markusheintz_ 2010/12/07 11:46:15 removed
24 #include "chrome/common/notification_service.h" 25 #include "chrome/common/notification_service.h"
26 #include "chrome/common/notification_source.h"
25 #include "chrome/common/notification_type.h" 27 #include "chrome/common/notification_type.h"
26 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
27 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
28 #include "net/base/dns_util.h" 30 #include "net/base/dns_util.h"
29 #include "net/base/static_cookie_policy.h" 31 #include "net/base/static_cookie_policy.h"
30 32
31 // static 33 // static
32 const ContentSetting 34 const ContentSetting
33 GeolocationContentSettingsMap::kDefaultSetting = CONTENT_SETTING_ASK; 35 GeolocationContentSettingsMap::kDefaultSetting = CONTENT_SETTING_ASK;
34 36
35 GeolocationContentSettingsMap::GeolocationContentSettingsMap(Profile* profile) 37 GeolocationContentSettingsMap::GeolocationContentSettingsMap(Profile* profile)
36 : profile_(profile) { 38 : profile_(profile) {
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
40 prefs_registrar_.Init(profile_->GetPrefs());
41 prefs_registrar_.Add(prefs::kGeolocationDefaultContentSetting, this);
42 prefs_registrar_.Add(prefs::kGeolocationContentSettings, this);
38 } 43 }
39 44
40 // static 45 // static
41 void GeolocationContentSettingsMap::RegisterUserPrefs(PrefService* prefs) { 46 void GeolocationContentSettingsMap::RegisterUserPrefs(PrefService* prefs) {
42 prefs->RegisterIntegerPref(prefs::kGeolocationDefaultContentSetting, 47 prefs->RegisterIntegerPref(prefs::kGeolocationDefaultContentSetting,
43 CONTENT_SETTING_ASK); 48 CONTENT_SETTING_ASK);
44 prefs->RegisterDictionaryPref(prefs::kGeolocationContentSettings); 49 prefs->RegisterDictionaryPref(prefs::kGeolocationContentSettings);
45 } 50 }
46 51
47 ContentSetting GeolocationContentSettingsMap::GetDefaultContentSetting() const { 52 ContentSetting GeolocationContentSettingsMap::GetDefaultContentSetting() const {
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
49 const PrefService* prefs = profile_->GetPrefs(); 54 const PrefService* prefs = profile_->GetPrefs();
50 const ContentSetting default_content_setting = IntToContentSetting( 55 const ContentSetting default_content_setting = IntToContentSetting(
51 prefs->GetInteger(prefs::kGeolocationDefaultContentSetting)); 56 prefs->GetInteger(prefs::kGeolocationDefaultContentSetting));
52 return default_content_setting == CONTENT_SETTING_DEFAULT ? 57 return default_content_setting == CONTENT_SETTING_DEFAULT ?
53 kDefaultSetting : default_content_setting; 58 kDefaultSetting : default_content_setting;
54 } 59 }
55 60
61 bool GeolocationContentSettingsMap::IsDefaultContentSettingManaged() const {
62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
63 return profile_->GetPrefs()->IsManagedPreference(
jochen (gone - plz use gerrit) 2010/12/07 09:43:52 you should also watch for PROFILE_DESTROYED
markusheintz_ 2010/12/07 11:46:15 Done.
64 prefs::kGeolocationDefaultContentSetting);
65 }
66
56 ContentSetting GeolocationContentSettingsMap::GetContentSetting( 67 ContentSetting GeolocationContentSettingsMap::GetContentSetting(
57 const GURL& requesting_url, 68 const GURL& requesting_url,
58 const GURL& embedding_url) const { 69 const GURL& embedding_url) const {
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
60 DCHECK(requesting_url.is_valid() && embedding_url.is_valid()); 71 DCHECK(requesting_url.is_valid() && embedding_url.is_valid());
61 GURL requesting_origin(requesting_url.GetOrigin()); 72 GURL requesting_origin(requesting_url.GetOrigin());
62 GURL embedding_origin(embedding_url.GetOrigin()); 73 GURL embedding_origin(embedding_url.GetOrigin());
63 DCHECK(requesting_origin.is_valid() && embedding_origin.is_valid()); 74 DCHECK(requesting_origin.is_valid() && embedding_origin.is_valid());
64 75
65 const DictionaryValue* all_settings_dictionary = 76 const DictionaryValue* all_settings_dictionary =
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 } 171 }
161 172
162 void GeolocationContentSettingsMap::ResetToDefault() { 173 void GeolocationContentSettingsMap::ResetToDefault() {
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
164 175
165 PrefService* prefs = profile_->GetPrefs(); 176 PrefService* prefs = profile_->GetPrefs();
166 prefs->ClearPref(prefs::kGeolocationDefaultContentSetting); 177 prefs->ClearPref(prefs::kGeolocationDefaultContentSetting);
167 prefs->ClearPref(prefs::kGeolocationContentSettings); 178 prefs->ClearPref(prefs::kGeolocationContentSettings);
168 } 179 }
169 180
181 void GeolocationContentSettingsMap::NotifyObservers(
182 const ContentSettingsDetails& details) {
183 NotificationService::current()->Notify(
184 NotificationType::CONTENT_SETTINGS_CHANGED,
185 Source<GeolocationContentSettingsMap>(this),
186 Details<const ContentSettingsDetails>(&details));
187 }
188
189 void GeolocationContentSettingsMap::Observe(
190 NotificationType type,
191 const NotificationSource& source,
192 const NotificationDetails& details) {
193 if (NotificationType::PREF_CHANGED == type) {
jochen (gone - plz use gerrit) 2010/12/07 09:43:52 hum, why are you doing this here instead of sendin
markusheintz_ 2010/12/07 11:46:15 Because I must listen for PREF_CHANGED events that
194 const std::string& name = *Details<std::string>(details).ptr();
195 if (name == prefs::kGeolocationDefaultContentSetting) {
196 NotifyObservers(ContentSettingsDetails(
197 ContentSettingsPattern(),
198 CONTENT_SETTINGS_TYPE_DEFAULT,
199 ""));
200 }
201 } else {
202 NOTREACHED();
203 }
204 }
205
170 GeolocationContentSettingsMap::~GeolocationContentSettingsMap() { 206 GeolocationContentSettingsMap::~GeolocationContentSettingsMap() {
171 } 207 }
172 208
173 // static 209 // static
174 void GeolocationContentSettingsMap::GetOneOriginSettingsFromDictionary( 210 void GeolocationContentSettingsMap::GetOneOriginSettingsFromDictionary(
175 const DictionaryValue* dictionary, 211 const DictionaryValue* dictionary,
176 OneOriginSettings* one_origin_settings) { 212 OneOriginSettings* one_origin_settings) {
177 for (DictionaryValue::key_iterator i(dictionary->begin_keys()); 213 for (DictionaryValue::key_iterator i(dictionary->begin_keys());
178 i != dictionary->end_keys(); ++i) { 214 i != dictionary->end_keys(); ++i) {
179 const std::string& target(*i); 215 const std::string& target(*i);
180 int setting = kDefaultSetting; 216 int setting = kDefaultSetting;
181 bool found = dictionary->GetIntegerWithoutPathExpansion(target, &setting); 217 bool found = dictionary->GetIntegerWithoutPathExpansion(target, &setting);
182 DCHECK(found); 218 DCHECK(found);
183 GURL target_url(target); 219 GURL target_url(target);
184 // An empty URL has a special meaning (wildcard), so only accept invalid 220 // An empty URL has a special meaning (wildcard), so only accept invalid
185 // URLs if the original version was empty (avoids treating corrupted prefs 221 // URLs if the original version was empty (avoids treating corrupted prefs
186 // as the wildcard entry; see http://crbug.com/39685) 222 // as the wildcard entry; see http://crbug.com/39685)
187 if (target_url.is_valid() || target.empty()) 223 if (target_url.is_valid() || target.empty())
188 (*one_origin_settings)[target_url] = IntToContentSetting(setting); 224 (*one_origin_settings)[target_url] = IntToContentSetting(setting);
189 } 225 }
190 } 226 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698