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

Side by Side Diff: components/content_settings/core/browser/cookie_settings.cc

Issue 2502743003: Allow getting both reading/setting cookie settings at one time (Closed)
Patch Set: swap SchemeIs with SchemeIsCryptographic Created 4 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
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 #include "components/content_settings/core/browser/cookie_settings.h" 5 #include "components/content_settings/core/browser/cookie_settings.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "components/content_settings/core/browser/content_settings_utils.h" 9 #include "components/content_settings/core/browser/content_settings_utils.h"
10 #include "components/content_settings/core/browser/host_content_settings_map.h" 10 #include "components/content_settings/core/browser/host_content_settings_map.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 51 }
52 52
53 ContentSetting CookieSettings::GetDefaultCookieSetting( 53 ContentSetting CookieSettings::GetDefaultCookieSetting(
54 std::string* provider_id) const { 54 std::string* provider_id) const {
55 return host_content_settings_map_->GetDefaultContentSetting( 55 return host_content_settings_map_->GetDefaultContentSetting(
56 CONTENT_SETTINGS_TYPE_COOKIES, provider_id); 56 CONTENT_SETTINGS_TYPE_COOKIES, provider_id);
57 } 57 }
58 58
59 bool CookieSettings::IsReadingCookieAllowed(const GURL& url, 59 bool CookieSettings::IsReadingCookieAllowed(const GURL& url,
60 const GURL& first_party_url) const { 60 const GURL& first_party_url) const {
61 ContentSetting setting = GetCookieSetting(url, first_party_url, false, NULL); 61 ContentSetting reading_setting;
62 return IsAllowed(setting); 62 GetCookieSetting(url, first_party_url, nullptr, &reading_setting,
63 nullptr /* setting_cookie */);
64 return IsAllowed(reading_setting);
63 } 65 }
64 66
65 bool CookieSettings::IsSettingCookieAllowed(const GURL& url, 67 bool CookieSettings::IsSettingCookieAllowed(const GURL& url,
66 const GURL& first_party_url) const { 68 const GURL& first_party_url) const {
67 ContentSetting setting = GetCookieSetting(url, first_party_url, true, NULL); 69 ContentSetting setting_setting;
68 return IsAllowed(setting); 70 GetCookieSetting(url, first_party_url, nullptr, nullptr /* reading_cookie */,
71 &setting_setting);
72 return IsAllowed(setting_setting);
73 }
74
75 void CookieSettings::GetReadingAndSettingCookieAllowed(
76 const GURL& url,
77 const GURL& first_party_url,
78 bool* reading_cookie_allowed,
79 bool* setting_cookie_allowed) const {
80 ContentSetting reading_setting;
81 ContentSetting setting_setting;
82 GetCookieSetting(url, first_party_url, nullptr, &reading_setting,
83 &setting_setting);
84 *reading_cookie_allowed = IsAllowed(reading_setting);
85 *setting_cookie_allowed = IsAllowed(setting_setting);
69 } 86 }
70 87
71 bool CookieSettings::IsCookieSessionOnly(const GURL& origin) const { 88 bool CookieSettings::IsCookieSessionOnly(const GURL& origin) const {
72 ContentSetting setting = GetCookieSetting(origin, origin, true, NULL); 89 ContentSetting setting;
90 GetCookieSetting(origin, origin, nullptr, nullptr, &setting);
73 DCHECK(IsValidSetting(setting)); 91 DCHECK(IsValidSetting(setting));
74 return (setting == CONTENT_SETTING_SESSION_ONLY); 92 return (setting == CONTENT_SETTING_SESSION_ONLY);
75 } 93 }
76 94
77 void CookieSettings::GetCookieSettings( 95 void CookieSettings::GetCookieSettings(
78 ContentSettingsForOneType* settings) const { 96 ContentSettingsForOneType* settings) const {
79 host_content_settings_map_->GetSettingsForOneType( 97 host_content_settings_map_->GetSettingsForOneType(
80 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), settings); 98 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), settings);
81 } 99 }
82 100
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, 133 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE,
116 std::string() /*resource_identifier*/); 134 std::string() /*resource_identifier*/);
117 return setting == CONTENT_SETTING_ALLOW; 135 return setting == CONTENT_SETTING_ALLOW;
118 } 136 }
119 137
120 void CookieSettings::ShutdownOnUIThread() { 138 void CookieSettings::ShutdownOnUIThread() {
121 DCHECK(thread_checker_.CalledOnValidThread()); 139 DCHECK(thread_checker_.CalledOnValidThread());
122 pref_change_registrar_.RemoveAll(); 140 pref_change_registrar_.RemoveAll();
123 } 141 }
124 142
125 ContentSetting CookieSettings::GetCookieSetting(const GURL& url, 143 void CookieSettings::GetCookieSetting(const GURL& url,
126 const GURL& first_party_url, 144 const GURL& first_party_url,
127 bool setting_cookie, 145 content_settings::SettingSource* source,
128 SettingSource* source) const { 146 ContentSetting* reading_cookie,
147 ContentSetting* setting_cookie) const {
129 // Auto-allow in extensions or for WebUI embedded in a secure origin. 148 // Auto-allow in extensions or for WebUI embedded in a secure origin.
130 if (url.SchemeIsCryptographic() && first_party_url.SchemeIs(kChromeUIScheme)) 149 if (first_party_url.SchemeIs(kChromeUIScheme) &&
131 return CONTENT_SETTING_ALLOW; 150 url.SchemeIsCryptographic()) {
151 if (reading_cookie)
152 *reading_cookie = CONTENT_SETTING_ALLOW;
153 if (setting_cookie)
154 *setting_cookie = CONTENT_SETTING_ALLOW;
155 return;
156 }
132 157
133 #if BUILDFLAG(ENABLE_EXTENSIONS) 158 #if BUILDFLAG(ENABLE_EXTENSIONS)
134 if (url.SchemeIs(kExtensionScheme) && 159 if (url.SchemeIs(kExtensionScheme) &&
135 first_party_url.SchemeIs(kExtensionScheme)) { 160 first_party_url.SchemeIs(kExtensionScheme)) {
Devlin 2016/11/16 20:12:00 Also not your code, but a question for the cookies
Charlie Harrison 2016/11/16 22:04:14 This strikes me as problematic. Welcome to ideas f
mmenke 2016/11/16 22:13:22 So anything set on an extensions URL is not, by de
136 return CONTENT_SETTING_ALLOW; 161 if (reading_cookie)
162 *reading_cookie = CONTENT_SETTING_ALLOW;
163 if (setting_cookie)
164 *setting_cookie = CONTENT_SETTING_ALLOW;
165 return;
137 } 166 }
138 #endif 167 #endif
139 168
140 // First get any host-specific settings. 169 // First get any host-specific settings.
141 SettingInfo info; 170 SettingInfo info;
142 std::unique_ptr<base::Value> value = 171 std::unique_ptr<base::Value> value =
143 host_content_settings_map_->GetWebsiteSetting( 172 host_content_settings_map_->GetWebsiteSetting(
144 url, first_party_url, CONTENT_SETTINGS_TYPE_COOKIES, std::string(), 173 url, first_party_url, CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
145 &info); 174 &info);
146 if (source) 175 if (source)
147 *source = info.source; 176 *source = info.source;
148 177
149 // If no explicit exception has been made and third-party cookies are blocked 178 // If no explicit exception has been made and third-party cookies are blocked
150 // by default, apply that rule. 179 // by default, apply CONTENT_SETTING_BLOCKED.
151 if (info.primary_pattern.MatchesAllHosts() && 180 bool block_third = info.primary_pattern.MatchesAllHosts() &&
152 info.secondary_pattern.MatchesAllHosts() && 181 info.secondary_pattern.MatchesAllHosts() &&
153 ShouldBlockThirdPartyCookies() && 182 ShouldBlockThirdPartyCookies() &&
154 !first_party_url.SchemeIs(extension_scheme_)) { 183 !first_party_url.SchemeIs(extension_scheme_);
Devlin 2016/11/16 20:12:00 Not your code, but.... why do we use extension_sch
Charlie Harrison 2016/11/16 22:04:14 I think we should move this to extension_scheme_ t
155 net::StaticCookiePolicy policy( 184 net::StaticCookiePolicy policy(
156 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES); 185 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES);
157 int rv;
158 if (setting_cookie)
159 rv = policy.CanSetCookie(url, first_party_url);
160 else
161 rv = policy.CanGetCookies(url, first_party_url);
162 DCHECK_NE(net::ERR_IO_PENDING, rv);
163 if (rv != net::OK)
164 return CONTENT_SETTING_BLOCK;
165 }
166 186
167 // We should always have a value, at least from the default provider. 187 // We should always have a value, at least from the default provider.
168 DCHECK(value.get()); 188 DCHECK(value.get());
169 return ValueToContentSetting(value.get()); 189 ContentSetting setting = ValueToContentSetting(value.get());
190 if (reading_cookie) {
191 bool block =
192 block_third && policy.CanGetCookies(url, first_party_url) != net::OK;
193 *reading_cookie = block ? CONTENT_SETTING_BLOCK : setting;
194 }
195 if (setting_cookie) {
196 bool block =
197 block_third && policy.CanSetCookie(url, first_party_url) != net::OK;
198 *setting_cookie = block ? CONTENT_SETTING_BLOCK : setting;
199 }
170 } 200 }
171 201
172 CookieSettings::~CookieSettings() { 202 CookieSettings::~CookieSettings() {
173 } 203 }
174 204
175 void CookieSettings::OnBlockThirdPartyCookiesChanged() { 205 void CookieSettings::OnBlockThirdPartyCookiesChanged() {
176 DCHECK(thread_checker_.CalledOnValidThread()); 206 DCHECK(thread_checker_.CalledOnValidThread());
177 207
178 base::AutoLock auto_lock(lock_); 208 base::AutoLock auto_lock(lock_);
179 block_third_party_cookies_ = pref_change_registrar_.prefs()->GetBoolean( 209 block_third_party_cookies_ = pref_change_registrar_.prefs()->GetBoolean(
180 prefs::kBlockThirdPartyCookies); 210 prefs::kBlockThirdPartyCookies);
181 } 211 }
182 212
183 bool CookieSettings::ShouldBlockThirdPartyCookies() const { 213 bool CookieSettings::ShouldBlockThirdPartyCookies() const {
184 base::AutoLock auto_lock(lock_); 214 base::AutoLock auto_lock(lock_);
185 return block_third_party_cookies_; 215 return block_third_party_cookies_;
186 } 216 }
187 217
188 } // namespace content_settings 218 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698