Chromium Code Reviews| Index: chrome/browser/content_settings/cookie_settings.h |
| diff --git a/chrome/browser/content_settings/cookie_settings.h b/chrome/browser/content_settings/cookie_settings.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..59d13f0bd9726a686ed043d2aa2c3cd45c5746d2 |
| --- /dev/null |
| +++ b/chrome/browser/content_settings/cookie_settings.h |
| @@ -0,0 +1,117 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ |
| +#define CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ |
| +#pragma once |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "base/synchronization/lock.h" |
| +#include "chrome/browser/prefs/pref_change_registrar.h" |
| +#include "chrome/common/content_settings.h" |
| +#include "content/common/notification_observer.h" |
| + |
| +class ContentSettingsPattern; |
| +class GURL; |
| +class HostContentSettingsMap; |
| + |
| +// A frontend to the cookie-specific settings of HostContentSettingsMap. Handles |
| +// cookie-specific logic such as blocking third-party cookies. |
|
Bernhard Bauer
2011/08/28 19:18:49
You should add some comments about thread safety o
marja
2011/09/01 11:03:19
Done.
|
| +class CookieSettings |
| + : public NotificationObserver, |
| + public base::RefCountedThreadSafe<CookieSettings> { |
| + public: |
| + CookieSettings( |
| + HostContentSettingsMap* host_content_settings_map, |
| + PrefService* prefs, |
| + bool incognito); |
|
Bernhard Bauer
2011/08/28 19:18:49
These are all attributes of the Profile, so we cou
markusheintz_
2011/08/29 08:47:09
If we do not pass in the profile but the stuff tha
marja
2011/08/30 13:14:08
I bumped into a problem when trying to make it a P
Bernhard Bauer
2011/08/30 13:20:25
Right (also, I guess you're on the IO thread there
marja
2011/09/01 11:03:19
Ok, I made it a ProfileKeyedService, and made Prof
Bernhard Bauer
2011/09/01 11:41:54
OK… but what happens after the profile is shutdown
marja
2011/09/01 13:34:48
Thanks for the hint. I did that, and changed raw p
|
| + |
| + // Returns the default content setting (CONTENT_SETTING_ALLOW, |
| + // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies. |
| + ContentSetting GetDefaultSetting() const; |
| + |
| + // Returns true if the page identified by (url, first_party_url) is allowed to |
| + // set a cookie (permanent or session only). |
| + bool IsCookieAllowed(const GURL& url, |
|
Bernhard Bauer
2011/08/28 19:18:49
I think splitting this method up into two methods
marja
2011/09/01 11:03:19
Done.
|
| + const GURL& first_party_url, |
| + bool setting_cookie) const; |
| + |
| + // Returns true if the cookie set by a page identified by url should be |
| + // session only. Querying this only makes sense if IsCookieAllowed has |
| + // returned true. |
| + bool IsCookieSessionOnly(const GURL& url) const; |
| + |
| + // Sets the default content setting (CONTENT_SETTING_ALLOW, |
| + // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies. |
| + void SetDefaultSetting(ContentSetting setting); |
| + |
| + // Sets cookies allowed for (url, first_party_url) patterns matching |
| + // (primary_pattern, secondary_pattern). The cookies can be permanent or |
| + // session-only. |
| + void SetCookieAllowed(const ContentSettingsPattern& primary_pattern, |
| + const ContentSettingsPattern& secondary_pattern, |
| + bool allowed); |
| + |
| + // Sets whether an origin matching primary pattern can set session-only |
| + // cookies or permanent cookies. |
| + void SetCookieSessionOnly(const ContentSettingsPattern& primary_pattern, |
| + bool session_only); |
| + |
| + void ResetCookieAllowed(const ContentSettingsPattern& primary_pattern, |
| + const ContentSettingsPattern& secondary_pattern); |
| + void ResetCookieSessionOnly(const ContentSettingsPattern& primary_pattern); |
| + |
| + // This setting trumps any host-specific settings. |
| + bool BlockThirdPartyCookies() const { return block_third_party_cookies_; } |
| + bool IsBlockThirdPartyCookiesManaged() const { |
|
Bernhard Bauer
2011/08/28 19:18:49
Is this method called anywhere?
marja
2011/09/01 11:03:19
No; I removed it.
|
| + return is_block_third_party_cookies_managed_; |
| + } |
| + |
| + // Sets whether we block all third-party cookies. This method must not be |
| + // invoked on an incognito map. |
| + // |
| + // This should only be called on the UI thread. |
| + void SetBlockThirdPartyCookies(bool block); |
|
Bernhard Bauer
2011/08/28 19:18:49
In the interest of simplicity, we could remove thi
marja
2011/09/01 11:03:19
This CL is getting bigger than expected; can I lea
Bernhard Bauer
2011/09/01 11:41:54
Ok, can you add a TODO for me (or yourself ;-) ) t
marja
2011/09/01 13:34:48
Done.
|
| + |
| + // NotificationObserver implementation. |
| + virtual void Observe(int type, |
| + const NotificationSource& source, |
| + const NotificationDetails& details); |
| + |
| + // Detaches the CookieSettings from all Profile-related objects like |
| + // PrefService. This methods needs to be called before destroying the Profile. |
| + // Afterwards, none of the methods above that should only be called on the UI |
| + // thread should be called anymore. |
| + void ShutdownOnUIThread(); |
| + |
| + private: |
| + // Various migration methods (old cookie, popup and per-host data gets |
| + // migrated to the new format). |
| + void MigrateObsoleteCookiePref(); |
| + |
| + // A helper for retrieving data for CONTENT_TYPE_COOKIES and |
| + // CONTENT_TYPE_COOKIES_SESSION_ONLY. |
| + ContentSetting GetCookieContentSetting(const GURL& url, |
| + const GURL& first_party_url, |
| + ContentSettingsType content_type, |
| + bool setting_cookie) const; |
| + |
| + // Weak pointer to the data backend (which also owns this object). |
| + HostContentSettingsMap* host_content_settings_map_; |
| + |
| + // Weak; owned by the profile. |
| + PrefService* prefs_; |
| + PrefChangeRegistrar pref_change_registrar_; |
| + |
| + bool is_off_the_record_; |
| + |
| + // Used around accesses to the following objects to guarantee thread safety. |
| + mutable base::Lock lock_; |
| + |
| + // Misc global settings. |
|
Bernhard Bauer
2011/08/28 19:18:49
Nit: This comment could be updated.
marja
2011/09/01 11:03:19
Done.
|
| + bool block_third_party_cookies_; |
| + bool is_block_third_party_cookies_managed_; |
| +}; |
| + |
| +#endif // CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ |