OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 hostnames to custom content settings. Written on the UI thread and read | 5 // Maps hostnames to custom content settings. Written on the UI thread and read |
6 // on any thread. One instance per profile. | 6 // on any thread. One instance per profile. |
7 | 7 |
8 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 8 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
9 #define CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 9 #define CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
18 #include "base/prefs/pref_change_registrar.h" | 18 #include "base/prefs/pref_change_registrar.h" |
19 #include "base/threading/platform_thread.h" | 19 #include "base/threading/platform_thread.h" |
20 #include "base/tuple.h" | 20 #include "base/tuple.h" |
21 #include "chrome/browser/content_settings/content_settings_observer.h" | 21 #include "chrome/browser/content_settings/content_settings_observer.h" |
| 22 #include "chrome/browser/content_settings/content_settings_override_provider.h" |
22 #include "chrome/common/content_settings.h" | 23 #include "chrome/common/content_settings.h" |
23 #include "components/content_settings/core/common/content_settings_pattern.h" | 24 #include "components/content_settings/core/common/content_settings_pattern.h" |
24 #include "components/content_settings/core/common/content_settings_types.h" | 25 #include "components/content_settings/core/common/content_settings_types.h" |
25 | 26 |
26 class ExtensionService; | 27 class ExtensionService; |
27 class GURL; | 28 class GURL; |
28 class PrefService; | 29 class PrefService; |
29 | 30 |
30 namespace base { | 31 namespace base { |
31 class Clock; | 32 class Clock; |
32 class Value; | 33 class Value; |
33 } | 34 } |
34 | 35 |
35 namespace content_settings { | 36 namespace content_settings { |
| 37 class OverrideProvider; |
36 class ProviderInterface; | 38 class ProviderInterface; |
37 class PrefProvider; | 39 class PrefProvider; |
38 } | 40 } |
39 | 41 |
40 namespace user_prefs { | 42 namespace user_prefs { |
41 class PrefRegistrySyncable; | 43 class PrefRegistrySyncable; |
42 } | 44 } |
43 | 45 |
44 class HostContentSettingsMap | 46 class HostContentSettingsMap |
45 : public content_settings::Observer, | 47 : public content_settings::Observer, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // If |info| is not NULL, then the |source| field of |info| is set to the | 92 // If |info| is not NULL, then the |source| field of |info| is set to the |
91 // source of the returned |Value| (POLICY, EXTENSION, USER, ...) and the | 93 // source of the returned |Value| (POLICY, EXTENSION, USER, ...) and the |
92 // |primary_pattern| and the |secondary_pattern| fields of |info| are set to | 94 // |primary_pattern| and the |secondary_pattern| fields of |info| are set to |
93 // the patterns of the applying rule. Note that certain internal schemes are | 95 // the patterns of the applying rule. Note that certain internal schemes are |
94 // whitelisted. For whitelisted schemes the |source| field of |info| is set | 96 // whitelisted. For whitelisted schemes the |source| field of |info| is set |
95 // the |SETTING_SOURCE_WHITELIST| and the |primary_pattern| and | 97 // the |SETTING_SOURCE_WHITELIST| and the |primary_pattern| and |
96 // |secondary_pattern| are set to a wildcard pattern. If there is no content | 98 // |secondary_pattern| are set to a wildcard pattern. If there is no content |
97 // setting, NULL is returned and the |source| field of |info| is set to | 99 // setting, NULL is returned and the |source| field of |info| is set to |
98 // |SETTING_SOURCE_NONE|. The pattern fiels of |info| are set to empty | 100 // |SETTING_SOURCE_NONE|. The pattern fiels of |info| are set to empty |
99 // patterns. | 101 // patterns. |
100 // The ownership of the resulting |Value| is transfered to the caller. | |
101 // May be called on any thread. | 102 // May be called on any thread. |
102 base::Value* GetWebsiteSetting( | 103 scoped_ptr<base::Value> GetWebsiteSetting( |
103 const GURL& primary_url, | 104 const GURL& primary_url, |
104 const GURL& secondary_url, | 105 const GURL& secondary_url, |
105 ContentSettingsType content_type, | 106 ContentSettingsType content_type, |
106 const std::string& resource_identifier, | 107 const std::string& resource_identifier, |
107 content_settings::SettingInfo* info) const; | 108 content_settings::SettingInfo* info) const; |
108 | 109 |
109 // For a given content type, returns all patterns with a non-default setting, | 110 // For a given content type, returns all patterns with a non-default setting, |
110 // mapped to their actual settings, in the precedence order of the rules. | 111 // mapped to their actual settings, in the precedence order of the rules. |
111 // |settings| must be a non-NULL outparam. | 112 // |settings| must be a non-NULL outparam. |
112 // | 113 // |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 const GURL& secondary_url, | 242 const GURL& secondary_url, |
242 ContentSettingsType content_type); | 243 ContentSettingsType content_type); |
243 | 244 |
244 // Returns the last time the pattern has requested permission for the | 245 // Returns the last time the pattern has requested permission for the |
245 // |content_type| setting. | 246 // |content_type| setting. |
246 base::Time GetLastUsageByPattern( | 247 base::Time GetLastUsageByPattern( |
247 const ContentSettingsPattern& primary_pattern, | 248 const ContentSettingsPattern& primary_pattern, |
248 const ContentSettingsPattern& secondary_pattern, | 249 const ContentSettingsPattern& secondary_pattern, |
249 ContentSettingsType content_type); | 250 ContentSettingsType content_type); |
250 | 251 |
| 252 // Returns the content setting without considering the global on/off toggle |
| 253 // for the content setting that matches the URLs. |
| 254 ContentSetting GetContentSettingWithoutOverride( |
| 255 const GURL& primary_url, |
| 256 const GURL& secondary_url, |
| 257 ContentSettingsType content_type, |
| 258 const std::string& resource_identifier); |
| 259 |
| 260 // Returns the single content setting |value| without considering the |
| 261 // global on/off toggle for the content setting that matches the given |
| 262 // patterns. |
| 263 scoped_ptr<base::Value> GetWebsiteSettingWithoutOverride( |
| 264 const GURL& primary_url, |
| 265 const GURL& secondary_url, |
| 266 ContentSettingsType content_type, |
| 267 const std::string& resource_identifier, |
| 268 content_settings::SettingInfo* info) const; |
| 269 |
| 270 // Sets globally if a given |content_type| |is_enabled|. |
| 271 void SetContentSettingOverride(ContentSettingsType content_type, |
| 272 bool is_enabled); |
| 273 |
| 274 // Returns if a given |content_type| is enabled. |
| 275 bool GetContentSettingOverride(ContentSettingsType content_type); |
| 276 |
251 // Adds/removes an observer for content settings changes. | 277 // Adds/removes an observer for content settings changes. |
252 void AddObserver(content_settings::Observer* observer); | 278 void AddObserver(content_settings::Observer* observer); |
253 void RemoveObserver(content_settings::Observer* observer); | 279 void RemoveObserver(content_settings::Observer* observer); |
254 | 280 |
255 // Passes ownership of |clock|. | 281 // Passes ownership of |clock|. |
256 void SetPrefClockForTesting(scoped_ptr<base::Clock> clock); | 282 void SetPrefClockForTesting(scoped_ptr<base::Clock> clock); |
257 | 283 |
258 private: | 284 private: |
259 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; | 285 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; |
260 friend class HostContentSettingsMapTest_NonDefaultSettings_Test; | 286 friend class HostContentSettingsMapTest_NonDefaultSettings_Test; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 // Weak; owned by the Profile. | 333 // Weak; owned by the Profile. |
308 PrefService* prefs_; | 334 PrefService* prefs_; |
309 | 335 |
310 // Whether this settings map is for an OTR session. | 336 // Whether this settings map is for an OTR session. |
311 bool is_off_the_record_; | 337 bool is_off_the_record_; |
312 | 338 |
313 // Content setting providers. This is only modified at construction | 339 // Content setting providers. This is only modified at construction |
314 // time and by RegisterExtensionService, both of which should happen | 340 // time and by RegisterExtensionService, both of which should happen |
315 // before any other uses of it. | 341 // before any other uses of it. |
316 ProviderMap content_settings_providers_; | 342 ProviderMap content_settings_providers_; |
| 343 content_settings::OverrideProvider override_; |
317 | 344 |
318 ObserverList<content_settings::Observer> observers_; | 345 ObserverList<content_settings::Observer> observers_; |
319 | 346 |
320 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); | 347 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); |
321 }; | 348 }; |
322 | 349 |
323 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 350 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
OLD | NEW |