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, |
46 public base::RefCountedThreadSafe<HostContentSettingsMap> { | 48 public base::RefCountedThreadSafe<HostContentSettingsMap> { |
47 public: | 49 public: |
48 enum ProviderType { | 50 enum ProviderType { |
49 INTERNAL_EXTENSION_PROVIDER = 0, | 51 INTERNAL_EXTENSION_PROVIDER = 0, |
50 POLICY_PROVIDER, | 52 POLICY_PROVIDER, |
51 CUSTOM_EXTENSION_PROVIDER, | 53 CUSTOM_EXTENSION_PROVIDER, |
| 54 OVERRIDE_PROVIDER, |
52 PREF_PROVIDER, | 55 PREF_PROVIDER, |
53 DEFAULT_PROVIDER, | 56 DEFAULT_PROVIDER, |
54 NUM_PROVIDER_TYPES, | 57 NUM_PROVIDER_TYPES, |
55 }; | 58 }; |
56 | 59 |
57 HostContentSettingsMap(PrefService* prefs, bool incognito); | 60 HostContentSettingsMap(PrefService* prefs, bool incognito); |
58 | 61 |
59 #if defined(ENABLE_EXTENSIONS) | 62 #if defined(ENABLE_EXTENSIONS) |
60 // In some cases, the ExtensionService is not available at the time the | 63 // In some cases, the ExtensionService is not available at the time the |
61 // HostContentSettingsMap is constructed. In these cases, we register the | 64 // HostContentSettingsMap is constructed. In these cases, we register the |
(...skipping 28 matching lines...) Expand all Loading... |
90 // If |info| is not NULL, then the |source| field of |info| is set to the | 93 // 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 | 94 // source of the returned |Value| (POLICY, EXTENSION, USER, ...) and the |
92 // |primary_pattern| and the |secondary_pattern| fields of |info| are set to | 95 // |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 | 96 // the patterns of the applying rule. Note that certain internal schemes are |
94 // whitelisted. For whitelisted schemes the |source| field of |info| is set | 97 // whitelisted. For whitelisted schemes the |source| field of |info| is set |
95 // the |SETTING_SOURCE_WHITELIST| and the |primary_pattern| and | 98 // the |SETTING_SOURCE_WHITELIST| and the |primary_pattern| and |
96 // |secondary_pattern| are set to a wildcard pattern. If there is no content | 99 // |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 | 100 // 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 | 101 // |SETTING_SOURCE_NONE|. The pattern fiels of |info| are set to empty |
99 // patterns. | 102 // patterns. |
100 // The ownership of the resulting |Value| is transfered to the caller. | |
101 // May be called on any thread. | 103 // May be called on any thread. |
102 base::Value* GetWebsiteSetting( | 104 scoped_ptr<base::Value> GetWebsiteSetting( |
103 const GURL& primary_url, | 105 const GURL& primary_url, |
104 const GURL& secondary_url, | 106 const GURL& secondary_url, |
105 ContentSettingsType content_type, | 107 ContentSettingsType content_type, |
106 const std::string& resource_identifier, | 108 const std::string& resource_identifier, |
107 content_settings::SettingInfo* info) const; | 109 content_settings::SettingInfo* info) const; |
108 | 110 |
109 // For a given content type, returns all patterns with a non-default setting, | 111 // 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. | 112 // mapped to their actual settings, in the precedence order of the rules. |
111 // |settings| must be a non-NULL outparam. | 113 // |settings| must be a non-NULL outparam. |
112 // | 114 // |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 const GURL& secondary_url, | 243 const GURL& secondary_url, |
242 ContentSettingsType content_type); | 244 ContentSettingsType content_type); |
243 | 245 |
244 // Returns the last time the pattern has requested permission for the | 246 // Returns the last time the pattern has requested permission for the |
245 // |content_type| setting. | 247 // |content_type| setting. |
246 base::Time GetLastUsageByPattern( | 248 base::Time GetLastUsageByPattern( |
247 const ContentSettingsPattern& primary_pattern, | 249 const ContentSettingsPattern& primary_pattern, |
248 const ContentSettingsPattern& secondary_pattern, | 250 const ContentSettingsPattern& secondary_pattern, |
249 ContentSettingsType content_type); | 251 ContentSettingsType content_type); |
250 | 252 |
| 253 // Returns the content setting without considering the global on/off toggle |
| 254 // for the content setting that matches the URLs. |
| 255 ContentSetting GetContentSettingWithoutOverride( |
| 256 const GURL& primary_url, |
| 257 const GURL& secondary_url, |
| 258 ContentSettingsType content_type, |
| 259 const std::string& resource_identifier); |
| 260 |
| 261 // Returns the single content setting |value| without considering the |
| 262 // global on/off toggle for the content setting that matches the given |
| 263 // patterns. |
| 264 scoped_ptr<base::Value> GetWebsiteSettingWithoutOverride( |
| 265 const GURL& primary_url, |
| 266 const GURL& secondary_url, |
| 267 ContentSettingsType content_type, |
| 268 const std::string& resource_identifier, |
| 269 content_settings::SettingInfo* info) const; |
| 270 |
| 271 // Sets globally if a given |content_type| |is_enabled|. |
| 272 void SetContentSettingOverride(ContentSettingsType content_type, |
| 273 bool is_enabled); |
| 274 |
| 275 // Returns if a given |content_type| is enabled. |
| 276 bool GetContentSettingOverride(ContentSettingsType content_type); |
| 277 |
251 // Adds/removes an observer for content settings changes. | 278 // Adds/removes an observer for content settings changes. |
252 void AddObserver(content_settings::Observer* observer); | 279 void AddObserver(content_settings::Observer* observer); |
253 void RemoveObserver(content_settings::Observer* observer); | 280 void RemoveObserver(content_settings::Observer* observer); |
254 | 281 |
255 // Passes ownership of |clock|. | 282 // Passes ownership of |clock|. |
256 void SetPrefClockForTesting(scoped_ptr<base::Clock> clock); | 283 void SetPrefClockForTesting(scoped_ptr<base::Clock> clock); |
257 | 284 |
258 private: | 285 private: |
259 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; | 286 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; |
260 friend class HostContentSettingsMapTest_NonDefaultSettings_Test; | 287 friend class HostContentSettingsMapTest_NonDefaultSettings_Test; |
(...skipping 24 matching lines...) Expand all Loading... |
285 const std::string& resource_identifier, | 312 const std::string& resource_identifier, |
286 ContentSettingsForOneType* settings, | 313 ContentSettingsForOneType* settings, |
287 bool incognito) const; | 314 bool incognito) const; |
288 | 315 |
289 // Call UsedContentSettingsProviders() whenever you access | 316 // Call UsedContentSettingsProviders() whenever you access |
290 // content_settings_providers_ (apart from initialization and | 317 // content_settings_providers_ (apart from initialization and |
291 // teardown), so that we can DCHECK in RegisterExtensionService that | 318 // teardown), so that we can DCHECK in RegisterExtensionService that |
292 // it is not being called too late. | 319 // it is not being called too late. |
293 void UsedContentSettingsProviders() const; | 320 void UsedContentSettingsProviders() const; |
294 | 321 |
| 322 // Returns the single content setting |value| with a toggle for if it |
| 323 // takes the global on/off switch into account. |
| 324 scoped_ptr<base::Value> GetWebsiteSettingInternal( |
| 325 const GURL& primary_url, |
| 326 const GURL& secondary_url, |
| 327 ContentSettingsType content_type, |
| 328 const std::string& resource_identifier, |
| 329 content_settings::SettingInfo* info, |
| 330 bool get_override) const; |
| 331 |
295 content_settings::PrefProvider* GetPrefProvider(); | 332 content_settings::PrefProvider* GetPrefProvider(); |
296 | 333 |
297 #ifndef NDEBUG | 334 #ifndef NDEBUG |
298 // This starts as the thread ID of the thread that constructs this | 335 // This starts as the thread ID of the thread that constructs this |
299 // object, and remains until used by a different thread, at which | 336 // object, and remains until used by a different thread, at which |
300 // point it is set to base::kInvalidThreadId. This allows us to | 337 // point it is set to base::kInvalidThreadId. This allows us to |
301 // DCHECK on unsafe usage of content_settings_providers_ (they | 338 // DCHECK on unsafe usage of content_settings_providers_ (they |
302 // should be set up on a single thread, after which they are | 339 // should be set up on a single thread, after which they are |
303 // immutable). | 340 // immutable). |
304 mutable base::PlatformThreadId used_from_thread_id_; | 341 mutable base::PlatformThreadId used_from_thread_id_; |
305 #endif | 342 #endif |
306 | 343 |
307 // Weak; owned by the Profile. | 344 // Weak; owned by the Profile. |
308 PrefService* prefs_; | 345 PrefService* prefs_; |
309 | 346 |
310 // Whether this settings map is for an OTR session. | 347 // Whether this settings map is for an OTR session. |
311 bool is_off_the_record_; | 348 bool is_off_the_record_; |
312 | 349 |
313 // Content setting providers. This is only modified at construction | 350 // Content setting providers. This is only modified at construction |
314 // time and by RegisterExtensionService, both of which should happen | 351 // time and by RegisterExtensionService, both of which should happen |
315 // before any other uses of it. | 352 // before any other uses of it. |
316 ProviderMap content_settings_providers_; | 353 ProviderMap content_settings_providers_; |
317 | 354 |
318 ObserverList<content_settings::Observer> observers_; | 355 ObserverList<content_settings::Observer> observers_; |
319 | 356 |
320 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); | 357 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); |
321 }; | 358 }; |
322 | 359 |
323 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ | 360 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ |
OLD | NEW |