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

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

Issue 8383004: Adding CookieSettings for storing cookie content settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing the rebase. Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_
6 #define CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_
7 #pragma once
8
9 #include <string>
10
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/singleton.h"
14 #include "base/synchronization/lock.h"
15 #include "chrome/browser/content_settings/host_content_settings_map.h"
16 #include "chrome/browser/prefs/pref_change_registrar.h"
17 #include "chrome/browser/profiles/profile_keyed_service_factory.h"
18 #include "chrome/common/content_settings.h"
19 #include "content/public/browser/notification_observer.h"
20
21 class ContentSettingsPattern;
22 class CookieSettingsWrapper;
23 class GURL;
24 class PrefService;
25 class Profile;
26
27 // A frontend to the cookie settings of |HostContentSettingsMap|. Handles
28 // cookie-specific logic such as blocking third-party cookies. Written on the UI
29 // thread and read on any thread. One instance per profile.
30
31 class CookieSettings
32 : public content::NotificationObserver,
33 public base::RefCountedThreadSafe<CookieSettings> {
34 public:
35 CookieSettings(
36 HostContentSettingsMap* host_content_settings_map,
37 PrefService* prefs);
38
39 virtual ~CookieSettings();
40
41 // Returns the |CookieSettings| associated with the |profile|.
42 //
43 // This should only be called on the UI thread.
44 static CookieSettings* GetForProfile(Profile* profile);
45
46 // Returns the default content setting (CONTENT_SETTING_ALLOW,
47 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies. If
48 // |provider_id| is not NULL, the id of the provider which provided the
49 // default setting is assigned to it.
50 //
51 // This may be called on any thread.
52 ContentSetting GetDefaultCookieSetting(std::string* provider_id) const;
53
54 // Returns true if the page identified by (|url|, |first_party_url|) is
55 // allowed to read cookies.
56 //
57 // This may be called on any thread.
58 bool IsReadingCookieAllowed(const GURL& url,
59 const GURL& first_party_url) const;
60
61 // Returns true if the page identified by (|url|, |first_party_url|) is
62 // allowed to set cookies (permanent or session only).
63 //
64 // This may be called on any thread.
65 bool IsSettingCookieAllowed(const GURL& url,
66 const GURL& first_party_url) const;
67
68 // Returns true if the cookie set by a page identified by |url| should be
69 // session only. Querying this only makes sense if |IsSettingCookieAllowed|
70 // has returned true.
71 //
72 // This may be called on any thread.
73 bool IsCookieSessionOnly(const GURL& url) const;
74
75 // Returns all patterns with a non-default cookie setting, mapped to their
76 // actual settings, in the precedence order of the setting rules. |settings|
77 // must be a non-NULL outparam.
78 //
79 // This may be called on any thread.
80 void GetCookieSettings(ContentSettingsForOneType* settings) const;
81
82 // Sets the default content setting (CONTENT_SETTING_ALLOW,
83 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies.
84 //
85 // This should only be called on the UI thread.
86 void SetDefaultCookieSetting(ContentSetting setting);
87
88 // Sets the cookie setting for the given patterns.
89 //
90 // This should only be called on the UI thread.
91 void SetCookieSetting(const ContentSettingsPattern& primary_pattern,
92 const ContentSettingsPattern& secondary_pattern,
93 ContentSetting setting);
94
95 // Resets the cookie setting for the given patterns.
96 //
97 // This should only be called on the UI thread.
98 void ResetCookieSetting(const ContentSettingsPattern& primary_pattern,
99 const ContentSettingsPattern& secondary_pattern);
100
101 // |NotificationObserver| implementation.
102 virtual void Observe(int type,
103 const content::NotificationSource& source,
104 const content::NotificationDetails& details) OVERRIDE;
105
106 // Detaches the |CookieSettings| from all |Profile|-related objects like
107 // |PrefService|. This methods needs to be called before destroying the
108 // |Profile|. Afterwards, only const methods can be called.
109 void ShutdownOnUIThread();
110
111 // A helper for applying third party cookie blocking rules.
112 ContentSetting GetCookieSetting(const GURL& url,
113 const GURL& first_party_url,
114 bool setting_cookie) const;
115
116 static void RegisterUserPrefs(PrefService* prefs);
117
118 class Factory : public ProfileKeyedServiceFactory {
119 public:
120 static Factory* GetInstance();
121 CookieSettingsWrapper* GetWrapperForProfile(Profile* profile);
122
123 private:
124 friend struct DefaultSingletonTraits<Factory>;
125
126 Factory();
127 virtual ~Factory() {}
128
129 // |ProfileKeyedServiceFactory| methods:
130 virtual ProfileKeyedService* BuildServiceInstanceFor(
131 Profile* profile) const OVERRIDE;
132 virtual bool ServiceRedirectedInIncognito() OVERRIDE { return true; }
133 };
134
135 private:
136 // Returns true if the "block third party cookies" preference is set.
137 //
138 // This method may be called on any thread.
139 bool ShouldBlockThirdPartyCookies() const;
140
141 scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
142 PrefChangeRegistrar pref_change_registrar_;
143
144 // Used around accesses to |block_third_party_cookies_| to guarantee thread
145 // safety.
146 mutable base::Lock lock_;
147
148 bool block_third_party_cookies_;
149 };
150
151 #endif // CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_
OLDNEW
« no previous file with comments | « chrome/browser/content_settings/content_settings_browsertest.cc ('k') | chrome/browser/content_settings/cookie_settings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698