Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // Maps [requesting_origin, embedder] to content settings. Written on the UI | 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 | 6 // thread and read on any thread. One instance per profile. This is based on |
| 7 // HostContentSettingsMap but differs significantly in two aspects: | 7 // HostContentSettingsMap but differs significantly in two aspects: |
| 8 // - It maps [requesting_origin.GetOrigin(), embedder.GetOrigin()] => setting | 8 // - It maps [requesting_origin.GetOrigin(), embedder.GetOrigin()] => setting |
| 9 // rather than host => setting. | 9 // rather than host => setting. |
| 10 // - It manages only Geolocation. | 10 // - It manages only Geolocation. |
| 11 | 11 |
| 12 #ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONTENT_SETTINGS_MAP_H_ | 12 #ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONTENT_SETTINGS_MAP_H_ |
| 13 #define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONTENT_SETTINGS_MAP_H_ | 13 #define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONTENT_SETTINGS_MAP_H_ |
| 14 #pragma once | 14 #pragma once |
| 15 | 15 |
| 16 #include <map> | 16 #include <map> |
| 17 | 17 |
| 18 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
| 19 #include "base/ref_counted.h" | 19 #include "base/ref_counted.h" |
| 20 #include "chrome/browser/prefs/pref_change_registrar.h" | |
| 20 #include "chrome/common/content_settings.h" | 21 #include "chrome/common/content_settings.h" |
| 22 #include "chrome/common/notification_observer.h" | |
| 23 #include "chrome/common/notification_registrar.h" | |
| 21 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
| 22 | 25 |
| 26 class ContentSettingsDetails; | |
| 23 class DictionaryValue; | 27 class DictionaryValue; |
| 24 class PrefService; | 28 class PrefService; |
| 25 class Profile; | 29 class Profile; |
| 26 | 30 |
| 27 class GeolocationContentSettingsMap | 31 class GeolocationContentSettingsMap |
| 28 : public base::RefCountedThreadSafe<GeolocationContentSettingsMap> { | 32 : public base::RefCountedThreadSafe<GeolocationContentSettingsMap>, |
| 33 public NotificationObserver { | |
| 29 public: | 34 public: |
| 30 typedef std::map<GURL, ContentSetting> OneOriginSettings; | 35 typedef std::map<GURL, ContentSetting> OneOriginSettings; |
| 31 typedef std::map<GURL, OneOriginSettings> AllOriginsSettings; | 36 typedef std::map<GURL, OneOriginSettings> AllOriginsSettings; |
| 32 | 37 |
| 33 explicit GeolocationContentSettingsMap(Profile* profile); | 38 explicit GeolocationContentSettingsMap(Profile* profile); |
| 34 | 39 |
| 35 static void RegisterUserPrefs(PrefService* prefs); | 40 static void RegisterUserPrefs(PrefService* prefs); |
| 36 | 41 |
| 37 // Returns the default setting. | 42 // Returns the default setting. |
| 38 // | 43 // |
| 39 // This should only be called on the UI thread. | 44 // This should only be called on the UI thread. |
| 40 ContentSetting GetDefaultContentSetting() const; | 45 ContentSetting GetDefaultContentSetting() const; |
| 41 | 46 |
| 47 // Returns true if the content setting is managed (set by a policy). | |
| 48 bool IsDefaultContentSettingManaged() const; | |
| 49 | |
| 42 // Returns a single ContentSetting which applies to the given |requesting_url| | 50 // Returns a single ContentSetting which applies to the given |requesting_url| |
| 43 // when embedded in a top-level page from |embedding_url|. To determine the | 51 // when embedded in a top-level page from |embedding_url|. To determine the |
| 44 // setting for a top-level page, as opposed to a frame embedded in a page, | 52 // setting for a top-level page, as opposed to a frame embedded in a page, |
| 45 // pass the page's URL for both arguments. | 53 // pass the page's URL for both arguments. |
| 46 // | 54 // |
| 47 // This should only be called on the UI thread. | 55 // This should only be called on the UI thread. |
| 48 // Both arguments should be valid GURLs. | 56 // Both arguments should be valid GURLs. |
| 49 ContentSetting GetContentSetting(const GURL& requesting_url, | 57 ContentSetting GetContentSetting(const GURL& requesting_url, |
| 50 const GURL& embedding_url) const; | 58 const GURL& embedding_url) const; |
| 51 | 59 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 73 // a valid GURL, and |embedding_url| should be valid or empty. | 81 // a valid GURL, and |embedding_url| should be valid or empty. |
| 74 void SetContentSetting(const GURL& requesting_url, | 82 void SetContentSetting(const GURL& requesting_url, |
| 75 const GURL& embedding_url, | 83 const GURL& embedding_url, |
| 76 ContentSetting setting); | 84 ContentSetting setting); |
| 77 | 85 |
| 78 // Resets all settings. | 86 // Resets all settings. |
| 79 // | 87 // |
| 80 // This should only be called on the UI thread. | 88 // This should only be called on the UI thread. |
| 81 void ResetToDefault(); | 89 void ResetToDefault(); |
| 82 | 90 |
| 91 // NotificationObserver implementation. | |
| 92 virtual void Observe(NotificationType type, | |
| 93 const NotificationSource& source, | |
| 94 const NotificationDetails& details); | |
| 95 | |
| 83 private: | 96 private: |
| 84 friend class base::RefCountedThreadSafe<GeolocationContentSettingsMap>; | 97 friend class base::RefCountedThreadSafe<GeolocationContentSettingsMap>; |
| 85 | 98 |
| 86 // The default setting. | 99 // The default setting. |
| 87 static const ContentSetting kDefaultSetting; | 100 static const ContentSetting kDefaultSetting; |
| 88 | 101 |
| 102 // Sends a CONTENT_SETTINGS_CHANGED notification. | |
| 103 void NotifyObservers(const ContentSettingsDetails& details); | |
| 104 | |
| 105 void UnregisterObservers(); | |
| 106 | |
| 89 ~GeolocationContentSettingsMap(); | 107 ~GeolocationContentSettingsMap(); |
|
jochen (gone - plz use gerrit)
2010/12/15 14:02:11
destructor should come before other methods. also,
markusheintz_
2010/12/15 14:08:35
Done.
| |
| 90 | 108 |
| 91 // Sets the fields of |one_origin_settings| based on the values in | 109 // Sets the fields of |one_origin_settings| based on the values in |
| 92 // |dictionary|. | 110 // |dictionary|. |
| 93 static void GetOneOriginSettingsFromDictionary( | 111 static void GetOneOriginSettingsFromDictionary( |
| 94 const DictionaryValue* dictionary, | 112 const DictionaryValue* dictionary, |
| 95 OneOriginSettings* one_origin_settings); | 113 OneOriginSettings* one_origin_settings); |
| 96 | 114 |
| 97 // The profile we're associated with. | 115 // The profile we're associated with. |
| 98 Profile* profile_; | 116 Profile* profile_; |
| 99 | 117 |
| 118 // Registrar to register for PREF_CHANGED notifications. | |
| 119 PrefChangeRegistrar prefs_registrar_; | |
| 120 NotificationRegistrar notification_registrar_; | |
| 121 | |
| 100 DISALLOW_COPY_AND_ASSIGN(GeolocationContentSettingsMap); | 122 DISALLOW_COPY_AND_ASSIGN(GeolocationContentSettingsMap); |
| 101 }; | 123 }; |
| 102 | 124 |
| 103 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONTENT_SETTINGS_MAP_H_ | 125 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONTENT_SETTINGS_MAP_H_ |
| OLD | NEW |