Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: chrome/browser/content_settings/host_content_settings_map.h

Issue 542253003: Add a global on/off switch for content settings and expose a toggle on the Website Settings options… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@global-settings
Patch Set: Rebase. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_override_provider.h"
21 #include "components/content_settings/core/browser/content_settings_observer.h" 22 #include "components/content_settings/core/browser/content_settings_observer.h"
22 #include "components/content_settings/core/common/content_settings.h" 23 #include "components/content_settings/core/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 ObservableProvider; 38 class ObservableProvider;
37 class ProviderInterface; 39 class ProviderInterface;
38 class PrefProvider; 40 class PrefProvider;
39 } 41 }
40 42
41 namespace user_prefs { 43 namespace user_prefs {
42 class PrefRegistrySyncable; 44 class PrefRegistrySyncable;
43 } 45 }
44 46
45 class HostContentSettingsMap 47 class HostContentSettingsMap
46 : public content_settings::Observer, 48 : public content_settings::Observer,
47 public base::RefCountedThreadSafe<HostContentSettingsMap> { 49 public base::RefCountedThreadSafe<HostContentSettingsMap> {
48 public: 50 public:
49 enum ProviderType { 51 enum ProviderType {
50 // EXTENSION names is a layering violation when this class will move to 52 // EXTENSION names is a layering violation when this class will move to
51 // components. 53 // components.
52 // TODO(mukai): find the solution. 54 // TODO(mukai): find the solution.
53 INTERNAL_EXTENSION_PROVIDER = 0, 55 INTERNAL_EXTENSION_PROVIDER = 0,
54 POLICY_PROVIDER, 56 POLICY_PROVIDER,
55 CUSTOM_EXTENSION_PROVIDER, 57 CUSTOM_EXTENSION_PROVIDER,
58 OVERRIDE_PROVIDER,
56 PREF_PROVIDER, 59 PREF_PROVIDER,
57 DEFAULT_PROVIDER, 60 DEFAULT_PROVIDER,
58 NUM_PROVIDER_TYPES, 61 NUM_PROVIDER_TYPES,
59 }; 62 };
60 63
61 HostContentSettingsMap(PrefService* prefs, bool incognito); 64 HostContentSettingsMap(PrefService* prefs, bool incognito);
62 65
63 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 66 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
64 67
65 // Adds a new provider for |type|. 68 // Adds a new provider for |type|.
(...skipping 26 matching lines...) Expand all
92 // If |info| is not NULL, then the |source| field of |info| is set to the 95 // If |info| is not NULL, then the |source| field of |info| is set to the
93 // source of the returned |Value| (POLICY, EXTENSION, USER, ...) and the 96 // source of the returned |Value| (POLICY, EXTENSION, USER, ...) and the
94 // |primary_pattern| and the |secondary_pattern| fields of |info| are set to 97 // |primary_pattern| and the |secondary_pattern| fields of |info| are set to
95 // the patterns of the applying rule. Note that certain internal schemes are 98 // the patterns of the applying rule. Note that certain internal schemes are
96 // whitelisted. For whitelisted schemes the |source| field of |info| is set 99 // whitelisted. For whitelisted schemes the |source| field of |info| is set
97 // the |SETTING_SOURCE_WHITELIST| and the |primary_pattern| and 100 // the |SETTING_SOURCE_WHITELIST| and the |primary_pattern| and
98 // |secondary_pattern| are set to a wildcard pattern. If there is no content 101 // |secondary_pattern| are set to a wildcard pattern. If there is no content
99 // setting, NULL is returned and the |source| field of |info| is set to 102 // setting, NULL is returned and the |source| field of |info| is set to
100 // |SETTING_SOURCE_NONE|. The pattern fiels of |info| are set to empty 103 // |SETTING_SOURCE_NONE|. The pattern fiels of |info| are set to empty
101 // patterns. 104 // patterns.
102 // The ownership of the resulting |Value| is transfered to the caller.
103 // May be called on any thread. 105 // May be called on any thread.
104 base::Value* GetWebsiteSetting( 106 scoped_ptr<base::Value> GetWebsiteSetting(
105 const GURL& primary_url, 107 const GURL& primary_url,
106 const GURL& secondary_url, 108 const GURL& secondary_url,
107 ContentSettingsType content_type, 109 ContentSettingsType content_type,
108 const std::string& resource_identifier, 110 const std::string& resource_identifier,
109 content_settings::SettingInfo* info) const; 111 content_settings::SettingInfo* info) const;
110 112
111 // For a given content type, returns all patterns with a non-default setting, 113 // For a given content type, returns all patterns with a non-default setting,
112 // mapped to their actual settings, in the precedence order of the rules. 114 // mapped to their actual settings, in the precedence order of the rules.
113 // |settings| must be a non-NULL outparam. 115 // |settings| must be a non-NULL outparam.
114 // 116 //
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 const GURL& secondary_url, 245 const GURL& secondary_url,
244 ContentSettingsType content_type); 246 ContentSettingsType content_type);
245 247
246 // Returns the last time the pattern has requested permission for the 248 // Returns the last time the pattern has requested permission for the
247 // |content_type| setting. 249 // |content_type| setting.
248 base::Time GetLastUsageByPattern( 250 base::Time GetLastUsageByPattern(
249 const ContentSettingsPattern& primary_pattern, 251 const ContentSettingsPattern& primary_pattern,
250 const ContentSettingsPattern& secondary_pattern, 252 const ContentSettingsPattern& secondary_pattern,
251 ContentSettingsType content_type); 253 ContentSettingsType content_type);
252 254
255 // Returns the content setting without considering the global on/off toggle
256 // for the content setting that matches the URLs.
257 ContentSetting GetContentSettingWithoutOverride(
258 const GURL& primary_url,
259 const GURL& secondary_url,
260 ContentSettingsType content_type,
261 const std::string& resource_identifier);
262
263 // Returns the single content setting |value| without considering the
264 // global on/off toggle for the content setting that matches the given
265 // patterns.
266 scoped_ptr<base::Value> GetWebsiteSettingWithoutOverride(
267 const GURL& primary_url,
268 const GURL& secondary_url,
269 ContentSettingsType content_type,
270 const std::string& resource_identifier,
271 content_settings::SettingInfo* info) const;
272
273 // Sets globally if a given |content_type| |is_enabled|.
274 void SetContentSettingOverride(ContentSettingsType content_type,
275 bool is_enabled);
276
277 // Returns if a given |content_type| is enabled.
278 bool GetContentSettingOverride(ContentSettingsType content_type);
279
253 // Adds/removes an observer for content settings changes. 280 // Adds/removes an observer for content settings changes.
254 void AddObserver(content_settings::Observer* observer); 281 void AddObserver(content_settings::Observer* observer);
255 void RemoveObserver(content_settings::Observer* observer); 282 void RemoveObserver(content_settings::Observer* observer);
256 283
257 // Passes ownership of |clock|. 284 // Passes ownership of |clock|.
258 void SetPrefClockForTesting(scoped_ptr<base::Clock> clock); 285 void SetPrefClockForTesting(scoped_ptr<base::Clock> clock);
259 286
260 private: 287 private:
261 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; 288 friend class base::RefCountedThreadSafe<HostContentSettingsMap>;
262 friend class HostContentSettingsMapTest_NonDefaultSettings_Test; 289 friend class HostContentSettingsMapTest_NonDefaultSettings_Test;
(...skipping 24 matching lines...) Expand all
287 const std::string& resource_identifier, 314 const std::string& resource_identifier,
288 ContentSettingsForOneType* settings, 315 ContentSettingsForOneType* settings,
289 bool incognito) const; 316 bool incognito) const;
290 317
291 // Call UsedContentSettingsProviders() whenever you access 318 // Call UsedContentSettingsProviders() whenever you access
292 // content_settings_providers_ (apart from initialization and 319 // content_settings_providers_ (apart from initialization and
293 // teardown), so that we can DCHECK in RegisterExtensionService that 320 // teardown), so that we can DCHECK in RegisterExtensionService that
294 // it is not being called too late. 321 // it is not being called too late.
295 void UsedContentSettingsProviders() const; 322 void UsedContentSettingsProviders() const;
296 323
324 // Returns the single content setting |value| with a toggle for if it
325 // takes the global on/off switch into account.
326 scoped_ptr<base::Value> GetWebsiteSettingInternal(
327 const GURL& primary_url,
328 const GURL& secondary_url,
329 ContentSettingsType content_type,
330 const std::string& resource_identifier,
331 content_settings::SettingInfo* info,
332 bool get_override) const;
333
297 content_settings::PrefProvider* GetPrefProvider(); 334 content_settings::PrefProvider* GetPrefProvider();
298 335
299 #ifndef NDEBUG 336 #ifndef NDEBUG
300 // This starts as the thread ID of the thread that constructs this 337 // This starts as the thread ID of the thread that constructs this
301 // object, and remains until used by a different thread, at which 338 // object, and remains until used by a different thread, at which
302 // point it is set to base::kInvalidThreadId. This allows us to 339 // point it is set to base::kInvalidThreadId. This allows us to
303 // DCHECK on unsafe usage of content_settings_providers_ (they 340 // DCHECK on unsafe usage of content_settings_providers_ (they
304 // should be set up on a single thread, after which they are 341 // should be set up on a single thread, after which they are
305 // immutable). 342 // immutable).
306 mutable base::PlatformThreadId used_from_thread_id_; 343 mutable base::PlatformThreadId used_from_thread_id_;
307 #endif 344 #endif
308 345
309 // Weak; owned by the Profile. 346 // Weak; owned by the Profile.
310 PrefService* prefs_; 347 PrefService* prefs_;
311 348
312 // Whether this settings map is for an OTR session. 349 // Whether this settings map is for an OTR session.
313 bool is_off_the_record_; 350 bool is_off_the_record_;
314 351
315 // Content setting providers. This is only modified at construction 352 // Content setting providers. This is only modified at construction
316 // time and by RegisterExtensionService, both of which should happen 353 // time and by RegisterExtensionService, both of which should happen
317 // before any other uses of it. 354 // before any other uses of it.
318 ProviderMap content_settings_providers_; 355 ProviderMap content_settings_providers_;
319 356
320 ObserverList<content_settings::Observer> observers_; 357 ObserverList<content_settings::Observer> observers_;
321 358
322 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); 359 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap);
323 }; 360 };
324 361
325 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ 362 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_
OLDNEW
« no previous file with comments | « chrome/browser/content_settings/cookie_settings.cc ('k') | chrome/browser/content_settings/host_content_settings_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698