Change net::CookieStore::SetCookiesCallback to return CookieInclusionStatus

https://chromium-review.googlesource.com/c/chromium/src/+/1470931
This commit is contained in:
deepak1556 2019-02-27 16:05:52 +05:30 committed by Samuel Attard
parent c735116cc3
commit fb9d1bd83c
2 changed files with 44 additions and 12 deletions

View file

@ -189,16 +189,42 @@ void RemoveCookieOnIO(scoped_refptr<net::URLRequestContextGetter> getter,
}
// Callback of SetCookie.
void OnSetCookie(util::Promise promise, bool success) {
if (success) {
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI},
void OnSetCookie(util::Promise promise,
net::CanonicalCookie::CookieInclusionStatus status) {
std::string errmsg;
switch (status) {
case net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_HTTP_ONLY:
errmsg = "Failed to create httponly cookie";
break;
case net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_SECURE_ONLY:
errmsg = "Cannot create a secure cookie from an insecure URL";
break;
case net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_FAILURE_TO_STORE:
errmsg = "Failed to parse cookie";
break;
case net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_INVALID_DOMAIN:
errmsg = "Failed to get cookie domain";
break;
case net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_INVALID_PREFIX:
errmsg = "Failed because the cookie violated prefix rules.";
break;
case net::CanonicalCookie::CookieInclusionStatus::
EXCLUDE_NONCOOKIEABLE_SCHEME:
errmsg = "Cannot set cookie for current scheme";
break;
case net::CanonicalCookie::CookieInclusionStatus::INCLUDE:
errmsg = "";
break;
default:
errmsg = "Setting cookie failed";
break;
}
if (errmsg.empty()) {
RunCallbackInUI(
base::BindOnce(util::Promise::ResolveEmptyPromise, std::move(promise)));
} else {
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(util::Promise::RejectPromise, std::move(promise),
"Setting cookie failed"));
RunCallbackInUI(
base::BindOnce(util::Promise::RejectPromise, std::move(promise), errmsg));
}
}
@ -257,15 +283,21 @@ void SetCookieOnIO(scoped_refptr<net::URLRequestContextGetter> getter,
net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT));
auto completion_callback = base::BindOnce(OnSetCookie, std::move(promise));
if (!canonical_cookie || !canonical_cookie->IsCanonical()) {
std::move(completion_callback).Run(false);
std::move(completion_callback)
.Run(net::CanonicalCookie::CookieInclusionStatus::
EXCLUDE_FAILURE_TO_STORE);
return;
}
if (url.is_empty()) {
std::move(completion_callback).Run(false);
std::move(completion_callback)
.Run(net::CanonicalCookie::CookieInclusionStatus::
EXCLUDE_INVALID_DOMAIN);
return;
}
if (name.empty()) {
std::move(completion_callback).Run(false);
std::move(completion_callback)
.Run(net::CanonicalCookie::CookieInclusionStatus::
EXCLUDE_FAILURE_TO_STORE);
return;
}
GetCookieStore(getter)->SetCanonicalCookieAsync(

View file

@ -142,7 +142,7 @@ describe('session module', () => {
error = e
}
expect(error).is.an('Error')
expect(error).to.have.property('message').which.equals('Setting cookie failed')
expect(error).to.have.property('message').which.equals('Failed to get cookie domain')
})
it('should overwrite previous cookies', async () => {