зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1280590 - nsICookieManager2.cookieExists must use the originAttributes, r=smaug
This commit is contained in:
Родитель
7a2b5bfab6
Коммит
cd5d3f1870
|
@ -115,6 +115,7 @@ var SessionCookiesInternal = {
|
||||||
* Restores a given list of session cookies.
|
* Restores a given list of session cookies.
|
||||||
*/
|
*/
|
||||||
restore(cookies) {
|
restore(cookies) {
|
||||||
|
|
||||||
for (let cookie of cookies) {
|
for (let cookie of cookies) {
|
||||||
let expiry = "expiry" in cookie ? cookie.expiry : MAX_EXPIRY;
|
let expiry = "expiry" in cookie ? cookie.expiry : MAX_EXPIRY;
|
||||||
let cookieObj = {
|
let cookieObj = {
|
||||||
|
@ -122,7 +123,7 @@ var SessionCookiesInternal = {
|
||||||
path: cookie.path || "",
|
path: cookie.path || "",
|
||||||
name: cookie.name || ""
|
name: cookie.name || ""
|
||||||
};
|
};
|
||||||
if (!Services.cookies.cookieExists(cookieObj)) {
|
if (!Services.cookies.cookieExists(cookieObj, cookie.originAttributes || {})) {
|
||||||
Services.cookies.add(cookie.host, cookie.path || "", cookie.name || "",
|
Services.cookies.add(cookie.host, cookie.path || "", cookie.name || "",
|
||||||
cookie.value, !!cookie.secure, !!cookie.httponly,
|
cookie.value, !!cookie.secure, !!cookie.httponly,
|
||||||
/* isSession = */ true, expiry, cookie.originAttributes || {});
|
/* isSession = */ true, expiry, cookie.originAttributes || {});
|
||||||
|
|
|
@ -4356,10 +4356,51 @@ nsCookieService::PurgeCookies(int64_t aCurrentTimeInUsec)
|
||||||
// find whether a given cookie has been previously set. this is provided by the
|
// find whether a given cookie has been previously set. this is provided by the
|
||||||
// nsICookieManager2 interface.
|
// nsICookieManager2 interface.
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsCookieService::CookieExists(nsICookie2 *aCookie,
|
nsCookieService::CookieExists(nsICookie2* aCookie,
|
||||||
bool *aFoundCookie)
|
JS::HandleValue aOriginAttributes,
|
||||||
|
JSContext* aCx,
|
||||||
|
uint8_t aArgc,
|
||||||
|
bool* aFoundCookie)
|
||||||
{
|
{
|
||||||
NS_ENSURE_ARG_POINTER(aCookie);
|
NS_ENSURE_ARG_POINTER(aCookie);
|
||||||
|
NS_ENSURE_ARG_POINTER(aCx);
|
||||||
|
NS_ENSURE_ARG_POINTER(aFoundCookie);
|
||||||
|
|
||||||
|
MOZ_ASSERT(aArgc == 0 || aArgc == 1);
|
||||||
|
|
||||||
|
nsresult rv;
|
||||||
|
NeckoOriginAttributes attrs;
|
||||||
|
|
||||||
|
if (aArgc == 0) {
|
||||||
|
JS::Rooted<JS::Value> value(aCx);
|
||||||
|
rv = aCookie->GetOriginAttributes(aCx, &value);
|
||||||
|
// We ignore this failure because nsICookie2 could be implemented in JS and
|
||||||
|
// this getter will failed because marked [implicit_jscontext].
|
||||||
|
if (NS_SUCCEEDED(rv) &&
|
||||||
|
(!value.isObject() || !attrs.Init(aCx, value))) {
|
||||||
|
return NS_ERROR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rv = InitializeOriginAttributes(&attrs,
|
||||||
|
aOriginAttributes,
|
||||||
|
aCx,
|
||||||
|
aArgc,
|
||||||
|
u"nsICookieManager2.cookieExists()",
|
||||||
|
u"2");
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
}
|
||||||
|
|
||||||
|
return CookieExistsNative(aCookie, &attrs, aFoundCookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP_(nsresult)
|
||||||
|
nsCookieService::CookieExistsNative(nsICookie2* aCookie,
|
||||||
|
NeckoOriginAttributes* aOriginAttributes,
|
||||||
|
bool* aFoundCookie)
|
||||||
|
{
|
||||||
|
NS_ENSURE_ARG_POINTER(aCookie);
|
||||||
|
NS_ENSURE_ARG_POINTER(aOriginAttributes);
|
||||||
|
NS_ENSURE_ARG_POINTER(aFoundCookie);
|
||||||
|
|
||||||
if (!mDBState) {
|
if (!mDBState) {
|
||||||
NS_WARNING("No DBState! Profile already closed?");
|
NS_WARNING("No DBState! Profile already closed?");
|
||||||
|
@ -4379,7 +4420,8 @@ nsCookieService::CookieExists(nsICookie2 *aCookie,
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
nsListIter iter;
|
nsListIter iter;
|
||||||
*aFoundCookie = FindCookie(DEFAULT_APP_KEY(baseDomain), host, name, path, iter);
|
*aFoundCookie = FindCookie(nsCookieKey(baseDomain, *aOriginAttributes),
|
||||||
|
host, name, path, iter);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,11 +76,23 @@ interface nsICookieManager2 : nsICookieManager
|
||||||
*
|
*
|
||||||
* @param aCookie
|
* @param aCookie
|
||||||
* the cookie to look for
|
* the cookie to look for
|
||||||
|
* @param aOriginAttributes
|
||||||
|
* nsICookie2 contains an originAttributes but if nsICookie2 is
|
||||||
|
* implemented in JS, we can't retrieve its originAttributes because
|
||||||
|
* the getter is marked [implicit_jscontext]. This optional parameter
|
||||||
|
* is a workaround.
|
||||||
*
|
*
|
||||||
* @return true if a cookie was found which matches the host, path, and name
|
* @return true if a cookie was found which matches the host, path, and name
|
||||||
* fields of aCookie
|
* fields of aCookie
|
||||||
*/
|
*/
|
||||||
boolean cookieExists(in nsICookie2 aCookie);
|
[implicit_jscontext, optional_argc]
|
||||||
|
boolean cookieExists(in nsICookie2 aCookie,
|
||||||
|
[optional] in jsval aOriginAttributes);
|
||||||
|
|
||||||
|
[notxpcom]
|
||||||
|
nsresult cookieExistsNative(in nsICookie2 aCookie,
|
||||||
|
in NeckoOriginAttributesPtr aOriginAttributes,
|
||||||
|
out boolean aExists);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Count how many cookies exist within the base domain of 'aHost'.
|
* Count how many cookies exist within the base domain of 'aHost'.
|
||||||
|
|
|
@ -757,9 +757,9 @@ main(int32_t argc, char *argv[])
|
||||||
uint32_t hostCookies = 0;
|
uint32_t hostCookies = 0;
|
||||||
rv[8] = NS_SUCCEEDED(cookieMgr2->CountCookiesFromHost(NS_LITERAL_CSTRING("cookiemgr.test"), &hostCookies)) &&
|
rv[8] = NS_SUCCEEDED(cookieMgr2->CountCookiesFromHost(NS_LITERAL_CSTRING("cookiemgr.test"), &hostCookies)) &&
|
||||||
hostCookies == 2;
|
hostCookies == 2;
|
||||||
// check CookieExists() using the third cookie
|
// check CookieExistsNative() using the third cookie
|
||||||
bool found;
|
bool found;
|
||||||
rv[9] = NS_SUCCEEDED(cookieMgr2->CookieExists(newDomainCookie, &found)) && found;
|
rv[9] = NS_SUCCEEDED(cookieMgr2->CookieExistsNative(newDomainCookie, &attrs, &found)) && found;
|
||||||
|
|
||||||
|
|
||||||
// remove the cookie, block it, and ensure it can't be added again
|
// remove the cookie, block it, and ensure it can't be added again
|
||||||
|
@ -768,7 +768,7 @@ main(int32_t argc, char *argv[])
|
||||||
NS_LITERAL_CSTRING("/rabbit"), // path
|
NS_LITERAL_CSTRING("/rabbit"), // path
|
||||||
true, // is blocked
|
true, // is blocked
|
||||||
&attrs)); // originAttributes
|
&attrs)); // originAttributes
|
||||||
rv[11] = NS_SUCCEEDED(cookieMgr2->CookieExists(newDomainCookie, &found)) && !found;
|
rv[11] = NS_SUCCEEDED(cookieMgr2->CookieExistsNative(newDomainCookie, &attrs, &found)) && !found;
|
||||||
rv[12] = NS_SUCCEEDED(cookieMgr2->AddNative(NS_LITERAL_CSTRING("new.domain"), // domain
|
rv[12] = NS_SUCCEEDED(cookieMgr2->AddNative(NS_LITERAL_CSTRING("new.domain"), // domain
|
||||||
NS_LITERAL_CSTRING("/rabbit"), // path
|
NS_LITERAL_CSTRING("/rabbit"), // path
|
||||||
NS_LITERAL_CSTRING("test3"), // name
|
NS_LITERAL_CSTRING("test3"), // name
|
||||||
|
@ -778,14 +778,14 @@ main(int32_t argc, char *argv[])
|
||||||
true, // is session
|
true, // is session
|
||||||
INT64_MIN, // expiry time
|
INT64_MIN, // expiry time
|
||||||
&attrs)); // originAttributes
|
&attrs)); // originAttributes
|
||||||
rv[13] = NS_SUCCEEDED(cookieMgr2->CookieExists(newDomainCookie, &found)) && !found;
|
rv[13] = NS_SUCCEEDED(cookieMgr2->CookieExistsNative(newDomainCookie, &attrs, &found)) && !found;
|
||||||
// sleep four seconds, to make sure the second cookie has expired
|
// sleep four seconds, to make sure the second cookie has expired
|
||||||
PR_Sleep(4 * PR_TicksPerSecond());
|
PR_Sleep(4 * PR_TicksPerSecond());
|
||||||
// check that both CountCookiesFromHost() and CookieExists() count the
|
// check that both CountCookiesFromHost() and CookieExistsNative() count the
|
||||||
// expired cookie
|
// expired cookie
|
||||||
rv[14] = NS_SUCCEEDED(cookieMgr2->CountCookiesFromHost(NS_LITERAL_CSTRING("cookiemgr.test"), &hostCookies)) &&
|
rv[14] = NS_SUCCEEDED(cookieMgr2->CountCookiesFromHost(NS_LITERAL_CSTRING("cookiemgr.test"), &hostCookies)) &&
|
||||||
hostCookies == 2;
|
hostCookies == 2;
|
||||||
rv[15] = NS_SUCCEEDED(cookieMgr2->CookieExists(expiredCookie, &found)) && found;
|
rv[15] = NS_SUCCEEDED(cookieMgr2->CookieExistsNative(expiredCookie, &attrs, &found)) && found;
|
||||||
// double-check RemoveAll() using the enumerator
|
// double-check RemoveAll() using the enumerator
|
||||||
rv[16] = NS_SUCCEEDED(cookieMgr->RemoveAll());
|
rv[16] = NS_SUCCEEDED(cookieMgr->RemoveAll());
|
||||||
rv[17] = NS_SUCCEEDED(cookieMgr->GetEnumerator(getter_AddRefs(enumerator))) &&
|
rv[17] = NS_SUCCEEDED(cookieMgr->GetEnumerator(getter_AddRefs(enumerator))) &&
|
||||||
|
|
Загрузка…
Ссылка в новой задаче