Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Maps [requesting_origin, embedder] to content settings. Written on the UI | |
| 6 // thread and read on any thread. One instance per profile. This is based on | |
| 7 // HostContentSettingsMap but differs significantly in two aspects: | |
| 8 // - It maps [requesting_origin.GetOrigin(), embedder.GetOrigin()] => setting | |
| 9 // rather than host => setting. | |
| 10 // - It manages only Geolocation. | |
| 11 | |
| 12 #ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONTENT_SETTINGS_MAP_H_ | |
| 13 #define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONTENT_SETTINGS_MAP_H_ | |
| 14 | |
| 15 #include <map> | |
| 16 #include <string> | |
| 17 #include <utility> | |
| 18 #include <vector> | |
| 19 | |
| 20 #include "base/basictypes.h" | |
| 21 #include "base/lock.h" | |
| 22 #include "base/ref_counted.h" | |
| 23 #include "chrome/common/content_settings.h" | |
| 24 #include "googleurl/src/gurl.h" | |
| 25 | |
| 26 class DictionaryValue; | |
| 27 class PrefService; | |
| 28 class Profile; | |
| 29 | |
| 30 class GeolocationContentSettingsMap | |
| 31 : public base::RefCountedThreadSafe<GeolocationContentSettingsMap> { | |
| 32 public: | |
| 33 | |
| 34 typedef std::map<GURL, ContentSetting> EmbedderSettings; | |
| 35 typedef std::map<GURL, EmbedderSettings> RequestingOriginSettings; | |
| 36 | |
| 37 explicit GeolocationContentSettingsMap(Profile* profile); | |
| 38 | |
| 39 static void RegisterUserPrefs(PrefService* prefs); | |
| 40 | |
| 41 // Returns the default setting. | |
| 42 // | |
| 43 // This may be called on any thread. | |
| 44 ContentSetting GetDefaultContentSetting() const; | |
| 45 | |
| 46 // Returns a single ContentSetting which applies to the given | |
| 47 // |requesting_origin| when embedded in a page of |embedder|. | |
| 48 // Note: if |requesting_origin| is a top-level page, it's the same as | |
|
Peter Kasting
2010/03/18 20:59:20
Nit: Better wording might be:
"Note: To determine
| |
| 49 // |embedder|. | |
| 50 // | |
| 51 // This may be called on any thread. | |
| 52 ContentSetting GetContentSetting(const GURL& embedder, | |
|
Peter Kasting
2010/03/18 20:59:20
Nit: I think it would make sense to swap these arg
| |
| 53 const GURL& requesting_origin) const; | |
| 54 | |
| 55 // Returns all origins with a non-default setting, mapped to their embedder | |
| 56 // settings. | |
| 57 // | |
| 58 // This may be called on any thread. | |
| 59 const RequestingOriginSettings& requesting_origin_settings() const; | |
|
Peter Kasting
2010/03/18 20:59:20
I'm a bit uncomfortable with returning a const ref
Peter Kasting
2010/03/18 21:53:30
Actually, since we have to perform a deep copy any
| |
| 60 | |
| 61 // Sets the default setting. | |
| 62 // | |
| 63 // This should only be called on the UI thread. | |
| 64 void SetDefaultContentSetting(ContentSetting setting); | |
| 65 | |
| 66 // Sets the content setting for a particular |embedder| and | |
| 67 // |requesting_origin|. | |
| 68 // Setting the value to CONTENT_SETTING_DEFAULT causes the default setting | |
| 69 // to be used when loading pages from this |embedder| and |requesting_origin|. | |
| 70 // An empty |embedder| is considered a wildcard for any embedder, that is, | |
|
Peter Kasting
2010/03/18 20:59:20
Nit: "any embedder except the origin itself"
| |
| 71 // it will be used by GetContentSetting() when there's no specific setting for | |
| 72 // |requesting_origin| and |embedder|. | |
|
Peter Kasting
2010/03/18 20:59:20
Nit: "when |embedder| != |requesting_origin| and t
| |
| 73 // |requesting_origin| must be is_valid(). | |
|
Peter Kasting
2010/03/18 20:59:20
Nit: "must be a valid GURL."
| |
| 74 // | |
| 75 // | |
| 76 // This should only be called on the UI thread. | |
| 77 void SetContentSetting(const GURL& embedder, | |
|
Peter Kasting
2010/03/18 20:59:20
Nit: As above, I'd reverse these first two args.
| |
| 78 const GURL& requesting_origin, | |
| 79 ContentSetting setting); | |
| 80 | |
| 81 // Resets all settings levels. | |
| 82 // | |
| 83 // This should only be called on the UI thread. | |
| 84 void ResetToDefault(); | |
| 85 | |
| 86 private: | |
| 87 friend class base::RefCountedThreadSafe<GeolocationContentSettingsMap>; | |
| 88 | |
| 89 // The name to use with dictionary prefs. | |
| 90 static const wchar_t* kTypeName; | |
| 91 | |
| 92 // The default setting. | |
| 93 static const ContentSetting kDefaultSetting; | |
| 94 | |
| 95 ~GeolocationContentSettingsMap(); | |
| 96 | |
| 97 // Sets the fields of |embedder_settings| based on the values in |dictionary|. | |
| 98 static void GetEmbedderSettingsFromDictionary( | |
| 99 const DictionaryValue* dictionary, EmbedderSettings* embedder_settings); | |
| 100 | |
| 101 static ContentSetting ConvertToContentSetting(int content_setting); | |
|
Peter Kasting
2010/03/18 20:59:20
If we want this, it should live in content_setting
| |
| 102 | |
| 103 // The profile we're associated with. | |
| 104 Profile* profile_; | |
| 105 | |
| 106 // Copies of the pref data, so that we can read it on the IO thread. | |
| 107 ContentSetting default_content_setting_; | |
| 108 RequestingOriginSettings requesting_origin_settings_; | |
| 109 | |
| 110 // Used around accesses to the settings objects to guarantee thread safety. | |
| 111 mutable Lock lock_; | |
| 112 | |
| 113 DISALLOW_COPY_AND_ASSIGN(GeolocationContentSettingsMap); | |
| 114 }; | |
| 115 | |
| 116 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONTENT_SETTINGS_MAP_H_ | |
| OLD | NEW |