| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 public: | 37 public: |
| 38 typedef std::map<GURL, ContentSetting> OneOriginSettings; | 38 typedef std::map<GURL, ContentSetting> OneOriginSettings; |
| 39 typedef std::map<GURL, OneOriginSettings> AllOriginsSettings; | 39 typedef std::map<GURL, OneOriginSettings> AllOriginsSettings; |
| 40 | 40 |
| 41 explicit GeolocationContentSettingsMap(Profile* profile); | 41 explicit GeolocationContentSettingsMap(Profile* profile); |
| 42 | 42 |
| 43 virtual ~GeolocationContentSettingsMap(); | 43 virtual ~GeolocationContentSettingsMap(); |
| 44 | 44 |
| 45 static void RegisterUserPrefs(PrefService* prefs); | 45 static void RegisterUserPrefs(PrefService* prefs); |
| 46 | 46 |
| 47 // Returns the default setting. | |
| 48 // | |
| 49 // This should only be called on the UI thread. | |
| 50 ContentSetting GetDefaultContentSetting() const; | |
| 51 | |
| 52 // Returns true if the content setting is managed (set by a policy). | |
| 53 bool IsDefaultContentSettingManaged() const; | |
| 54 | |
| 55 // Returns a single ContentSetting which applies to the given |requesting_url| | 47 // Returns a single ContentSetting which applies to the given |requesting_url| |
| 56 // when embedded in a top-level page from |embedding_url|. To determine the | 48 // when embedded in a top-level page from |embedding_url|. To determine the |
| 57 // setting for a top-level page, as opposed to a frame embedded in a page, | 49 // setting for a top-level page, as opposed to a frame embedded in a page, |
| 58 // pass the page's URL for both arguments. | 50 // pass the page's URL for both arguments. |
| 59 // | 51 // |
| 60 // This should only be called on the UI thread. | 52 // This should only be called on the UI thread. |
| 61 // Both arguments should be valid GURLs. | 53 // Both arguments should be valid GURLs. |
| 62 ContentSetting GetContentSetting(const GURL& requesting_url, | 54 ContentSetting GetContentSetting(const GURL& requesting_url, |
| 63 const GURL& embedding_url) const; | 55 const GURL& embedding_url) const; |
| 64 | 56 |
| 65 // Returns the settings for all origins with any non-default settings. | 57 // Returns the settings for all origins with any non-default settings. |
| 66 // | 58 // |
| 67 // This should only be called on the UI thread. | 59 // This should only be called on the UI thread. |
| 68 AllOriginsSettings GetAllOriginsSettings() const; | 60 AllOriginsSettings GetAllOriginsSettings() const; |
| 69 | 61 |
| 70 // Sets the default setting. | |
| 71 // | |
| 72 // This should only be called on the UI thread. | |
| 73 void SetDefaultContentSetting(ContentSetting setting); | |
| 74 | |
| 75 // Sets the content setting for a particular (requesting origin, embedding | 62 // Sets the content setting for a particular (requesting origin, embedding |
| 76 // origin) pair. If the embedding origin is the same as the requesting | 63 // origin) pair. If the embedding origin is the same as the requesting |
| 77 // origin, this represents the setting used when the requesting origin is | 64 // origin, this represents the setting used when the requesting origin is |
| 78 // itself the top-level page. If |embedder| is the empty GURL, |setting| | 65 // itself the top-level page. If |embedder| is the empty GURL, |setting| |
| 79 // becomes the default setting for the requesting origin when embedded on any | 66 // becomes the default setting for the requesting origin when embedded on any |
| 80 // page that does not have an explicit setting. Passing | 67 // page that does not have an explicit setting. Passing |
| 81 // CONTENT_SETTING_DEFAULT for |setting| effectively removes that setting and | 68 // CONTENT_SETTING_DEFAULT for |setting| effectively removes that setting and |
| 82 // allows future requests to return the all-embedders or global defaults (as | 69 // allows future requests to return the all-embedders or global defaults (as |
| 83 // applicable). | 70 // applicable). |
| 84 // | 71 // |
| 85 // This should only be called on the UI thread. |requesting_url| should be | 72 // This should only be called on the UI thread. |requesting_url| should be |
| 86 // a valid GURL, and |embedding_url| should be valid or empty. | 73 // a valid GURL, and |embedding_url| should be valid or empty. |
| 87 void SetContentSetting(const GURL& requesting_url, | 74 void SetContentSetting(const GURL& requesting_url, |
| 88 const GURL& embedding_url, | 75 const GURL& embedding_url, |
| 89 ContentSetting setting); | 76 ContentSetting setting); |
| 90 | 77 |
| 91 // Resets all settings. | 78 // Resets all settings. |
| 92 // | 79 // |
| 93 // This should only be called on the UI thread. | 80 // This should only be called on the UI thread. |
| 94 void ResetToDefault(); | 81 void ResetToDefault(); |
| 95 | 82 |
| 96 // NotificationObserver implementation. | 83 // NotificationObserver implementation. |
| 97 virtual void Observe(int type, | 84 virtual void Observe(int type, |
| 98 const NotificationSource& source, | 85 const NotificationSource& source, |
| 99 const NotificationDetails& details); | 86 const NotificationDetails& details); |
| 100 | 87 |
| 101 private: | 88 private: |
| 102 friend class base::RefCountedThreadSafe<GeolocationContentSettingsMap>; | 89 friend class base::RefCountedThreadSafe<GeolocationContentSettingsMap>; |
| 103 | 90 |
| 104 // The default setting. | |
| 105 static const ContentSetting kDefaultSetting; | |
| 106 | |
| 107 // Sends a CONTENT_SETTINGS_CHANGED notification. | 91 // Sends a CONTENT_SETTINGS_CHANGED notification. |
| 108 void NotifyObservers(const ContentSettingsDetails& details); | 92 void NotifyObservers(const ContentSettingsDetails& details); |
| 109 | 93 |
| 110 void UnregisterObservers(); | 94 void UnregisterObservers(); |
| 111 | 95 |
| 112 // Sets the fields of |one_origin_settings| based on the values in | 96 // Sets the fields of |one_origin_settings| based on the values in |
| 113 // |dictionary|. | 97 // |dictionary|. |
| 114 static void GetOneOriginSettingsFromDictionary( | 98 static void GetOneOriginSettingsFromDictionary( |
| 115 const base::DictionaryValue* dictionary, | 99 const base::DictionaryValue* dictionary, |
| 116 OneOriginSettings* one_origin_settings); | 100 OneOriginSettings* one_origin_settings); |
| 117 | 101 |
| 118 // The profile we're associated with. | 102 // The profile we're associated with. |
| 119 Profile* profile_; | 103 Profile* profile_; |
| 120 | 104 |
| 121 // Registrar to register for PREF_CHANGED notifications. | 105 // Registrar to register for PREF_CHANGED notifications. |
| 122 PrefChangeRegistrar prefs_registrar_; | 106 PrefChangeRegistrar prefs_registrar_; |
| 123 NotificationRegistrar notification_registrar_; | 107 NotificationRegistrar notification_registrar_; |
| 124 | 108 |
| 125 DISALLOW_COPY_AND_ASSIGN(GeolocationContentSettingsMap); | 109 DISALLOW_COPY_AND_ASSIGN(GeolocationContentSettingsMap); |
| 126 }; | 110 }; |
| 127 | 111 |
| 128 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONTENT_SETTINGS_MAP_H_ | 112 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_CONTENT_SETTINGS_MAP_H_ |
| OLD | NEW |