Index: chrome/browser/geolocation/geolocation_content_settings_map.h |
diff --git a/chrome/browser/geolocation/geolocation_content_settings_map.h b/chrome/browser/geolocation/geolocation_content_settings_map.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c0646a3f039605f884387fef471a62cdccc27874 |
--- /dev/null |
+++ b/chrome/browser/geolocation/geolocation_content_settings_map.h |
@@ -0,0 +1,116 @@ |
+// Copyright (c) 2010 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. |
+ |
+// Maps [requesting_origin, embedder] to content settings. Written on the UI |
+// thread and read on any thread. One instance per profile. This is based on |
+// HostContentSettingsMap but differs significantly in two aspects: |
+// - It maps [requesting_origin.GetOrigin(), embedder.GetOrigin()] => setting |
+// rather than host => setting. |
+// - It manages only Geolocation. |
+ |
+#ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONTENT_SETTINGS_MAP_H_ |
+#define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONTENT_SETTINGS_MAP_H_ |
+ |
+#include <map> |
+#include <string> |
+#include <utility> |
+#include <vector> |
+ |
+#include "base/basictypes.h" |
+#include "base/lock.h" |
+#include "base/ref_counted.h" |
+#include "chrome/common/content_settings.h" |
+#include "googleurl/src/gurl.h" |
+ |
+class DictionaryValue; |
+class PrefService; |
+class Profile; |
+ |
+class GeolocationContentSettingsMap |
+ : public base::RefCountedThreadSafe<GeolocationContentSettingsMap> { |
+ public: |
+ |
+ typedef std::map<GURL, ContentSetting> EmbedderSettings; |
+ typedef std::map<GURL, EmbedderSettings> RequestingOriginSettings; |
+ |
+ explicit GeolocationContentSettingsMap(Profile* profile); |
+ |
+ static void RegisterUserPrefs(PrefService* prefs); |
+ |
+ // Returns the default setting. |
+ // |
+ // This may be called on any thread. |
+ ContentSetting GetDefaultContentSetting() const; |
+ |
+ // Returns a single ContentSetting which applies to the given |
+ // |requesting_origin| when embedded in a page of |embedder|. |
+ // 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
|
+ // |embedder|. |
+ // |
+ // This may be called on any thread. |
+ ContentSetting GetContentSetting(const GURL& embedder, |
Peter Kasting
2010/03/18 20:59:20
Nit: I think it would make sense to swap these arg
|
+ const GURL& requesting_origin) const; |
+ |
+ // Returns all origins with a non-default setting, mapped to their embedder |
+ // settings. |
+ // |
+ // This may be called on any thread. |
+ 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
|
+ |
+ // Sets the default setting. |
+ // |
+ // This should only be called on the UI thread. |
+ void SetDefaultContentSetting(ContentSetting setting); |
+ |
+ // Sets the content setting for a particular |embedder| and |
+ // |requesting_origin|. |
+ // Setting the value to CONTENT_SETTING_DEFAULT causes the default setting |
+ // to be used when loading pages from this |embedder| and |requesting_origin|. |
+ // 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"
|
+ // it will be used by GetContentSetting() when there's no specific setting for |
+ // |requesting_origin| and |embedder|. |
Peter Kasting
2010/03/18 20:59:20
Nit: "when |embedder| != |requesting_origin| and t
|
+ // |requesting_origin| must be is_valid(). |
Peter Kasting
2010/03/18 20:59:20
Nit: "must be a valid GURL."
|
+ // |
+ // |
+ // This should only be called on the UI thread. |
+ void SetContentSetting(const GURL& embedder, |
Peter Kasting
2010/03/18 20:59:20
Nit: As above, I'd reverse these first two args.
|
+ const GURL& requesting_origin, |
+ ContentSetting setting); |
+ |
+ // Resets all settings levels. |
+ // |
+ // This should only be called on the UI thread. |
+ void ResetToDefault(); |
+ |
+ private: |
+ friend class base::RefCountedThreadSafe<GeolocationContentSettingsMap>; |
+ |
+ // The name to use with dictionary prefs. |
+ static const wchar_t* kTypeName; |
+ |
+ // The default setting. |
+ static const ContentSetting kDefaultSetting; |
+ |
+ ~GeolocationContentSettingsMap(); |
+ |
+ // Sets the fields of |embedder_settings| based on the values in |dictionary|. |
+ static void GetEmbedderSettingsFromDictionary( |
+ const DictionaryValue* dictionary, EmbedderSettings* embedder_settings); |
+ |
+ static ContentSetting ConvertToContentSetting(int content_setting); |
Peter Kasting
2010/03/18 20:59:20
If we want this, it should live in content_setting
|
+ |
+ // The profile we're associated with. |
+ Profile* profile_; |
+ |
+ // Copies of the pref data, so that we can read it on the IO thread. |
+ ContentSetting default_content_setting_; |
+ RequestingOriginSettings requesting_origin_settings_; |
+ |
+ // Used around accesses to the settings objects to guarantee thread safety. |
+ mutable Lock lock_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(GeolocationContentSettingsMap); |
+}; |
+ |
+#endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONTENT_SETTINGS_MAP_H_ |