зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1624146 - Cookie code refactoring - part 13 - More functions in CookieCommons, r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D67762 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
f6c7a629a9
Коммит
0f16f86d52
|
@ -0,0 +1,116 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "CookieCommons.h"
|
||||
#include "nsIEffectiveTLDService.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
|
||||
// static
|
||||
bool CookieCommons::DomainMatches(Cookie* aCookie, const nsACString& aHost) {
|
||||
// first, check for an exact host or domain cookie match, e.g. "google.com"
|
||||
// or ".google.com"; second a subdomain match, e.g.
|
||||
// host = "mail.google.com", cookie domain = ".google.com".
|
||||
return aCookie->RawHost() == aHost ||
|
||||
(aCookie->IsDomain() && StringEndsWith(aHost, aCookie->Host()));
|
||||
}
|
||||
|
||||
// static
|
||||
bool CookieCommons::PathMatches(Cookie* aCookie, const nsACString& aPath) {
|
||||
nsCString cookiePath(aCookie->GetFilePath());
|
||||
|
||||
// if our cookie path is empty we can't really perform our prefix check, and
|
||||
// also we can't check the last character of the cookie path, so we would
|
||||
// never return a successful match.
|
||||
if (cookiePath.IsEmpty()) return false;
|
||||
|
||||
// if the cookie path and the request path are identical, they match.
|
||||
if (cookiePath.Equals(aPath)) return true;
|
||||
|
||||
// if the cookie path is a prefix of the request path, and the last character
|
||||
// of the cookie path is %x2F ("/"), they match.
|
||||
bool isPrefix = StringBeginsWith(aPath, cookiePath);
|
||||
if (isPrefix && cookiePath.Last() == '/') return true;
|
||||
|
||||
// if the cookie path is a prefix of the request path, and the first character
|
||||
// of the request path that is not included in the cookie path is a %x2F ("/")
|
||||
// character, they match.
|
||||
uint32_t cookiePathLen = cookiePath.Length();
|
||||
if (isPrefix && aPath[cookiePathLen] == '/') return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the base domain for aHostURI; e.g. for "www.bbc.co.uk", this would be
|
||||
// "bbc.co.uk". Only properly-formed URI's are tolerated, though a trailing
|
||||
// dot may be present. If aHostURI is an IP address, an alias such as
|
||||
// 'localhost', an eTLD such as 'co.uk', or the empty string, aBaseDomain will
|
||||
// be the exact host, and aRequireHostMatch will be true to indicate that
|
||||
// substring matches should not be performed.
|
||||
nsresult CookieCommons::GetBaseDomain(nsIEffectiveTLDService* aTLDService,
|
||||
nsIURI* aHostURI, nsCString& aBaseDomain,
|
||||
bool& aRequireHostMatch) {
|
||||
// get the base domain. this will fail if the host contains a leading dot,
|
||||
// more than one trailing dot, or is otherwise malformed.
|
||||
nsresult rv = aTLDService->GetBaseDomain(aHostURI, 0, aBaseDomain);
|
||||
aRequireHostMatch = rv == NS_ERROR_HOST_IS_IP_ADDRESS ||
|
||||
rv == NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS;
|
||||
if (aRequireHostMatch) {
|
||||
// aHostURI is either an IP address, an alias such as 'localhost', an eTLD
|
||||
// such as 'co.uk', or the empty string. use the host as a key in such
|
||||
// cases.
|
||||
rv = aHostURI->GetAsciiHost(aBaseDomain);
|
||||
}
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// aHost (and thus aBaseDomain) may be the string '.'. If so, fail.
|
||||
if (aBaseDomain.Length() == 1 && aBaseDomain.Last() == '.')
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// block any URIs without a host that aren't file:// URIs.
|
||||
if (aBaseDomain.IsEmpty() && !aHostURI->SchemeIs("file")) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Get the base domain for aHost; e.g. for "www.bbc.co.uk", this would be
|
||||
// "bbc.co.uk". This is done differently than GetBaseDomain(mTLDService, ): it
|
||||
// is assumed that aHost is already normalized, and it may contain a leading dot
|
||||
// (indicating that it represents a domain). A trailing dot may be present.
|
||||
// If aHost is an IP address, an alias such as 'localhost', an eTLD such as
|
||||
// 'co.uk', or the empty string, aBaseDomain will be the exact host, and a
|
||||
// leading dot will be treated as an error.
|
||||
nsresult CookieCommons::GetBaseDomainFromHost(
|
||||
nsIEffectiveTLDService* aTLDService, const nsACString& aHost,
|
||||
nsCString& aBaseDomain) {
|
||||
// aHost must not be the string '.'.
|
||||
if (aHost.Length() == 1 && aHost.Last() == '.') return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// aHost may contain a leading dot; if so, strip it now.
|
||||
bool domain = !aHost.IsEmpty() && aHost.First() == '.';
|
||||
|
||||
// get the base domain. this will fail if the host contains a leading dot,
|
||||
// more than one trailing dot, or is otherwise malformed.
|
||||
nsresult rv = aTLDService->GetBaseDomainFromHost(Substring(aHost, domain), 0,
|
||||
aBaseDomain);
|
||||
if (rv == NS_ERROR_HOST_IS_IP_ADDRESS ||
|
||||
rv == NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS) {
|
||||
// aHost is either an IP address, an alias such as 'localhost', an eTLD
|
||||
// such as 'co.uk', or the empty string. use the host as a key in such
|
||||
// cases; however, we reject any such hosts with a leading dot, since it
|
||||
// doesn't make sense for them to be domain cookies.
|
||||
if (domain) return NS_ERROR_INVALID_ARG;
|
||||
|
||||
aBaseDomain = aHost;
|
||||
return NS_OK;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
} // namespace net
|
||||
} // namespace mozilla
|
|
@ -8,6 +8,15 @@
|
|||
|
||||
#include <cstdint>
|
||||
#include "prtime.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsIEffectiveTLDService;
|
||||
class nsIURI;
|
||||
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
|
||||
class Cookie;
|
||||
|
||||
// pref string constants
|
||||
static const char kPrefMaxNumberOfCookies[] = "network.cookie.maxNumber";
|
||||
|
@ -26,4 +35,22 @@ static const uint32_t kMaxBytesPerPath = 1024;
|
|||
static const int64_t kCookiePurgeAge =
|
||||
int64_t(30 * 24 * 60 * 60) * PR_USEC_PER_SEC; // 30 days in microseconds
|
||||
|
||||
class CookieCommons final {
|
||||
public:
|
||||
static bool DomainMatches(Cookie* aCookie, const nsACString& aHost);
|
||||
|
||||
static bool PathMatches(Cookie* aCookie, const nsACString& aPath);
|
||||
|
||||
static nsresult GetBaseDomain(nsIEffectiveTLDService* aTLDService,
|
||||
nsIURI* aHostURI, nsCString& aBaseDomain,
|
||||
bool& aRequireHostMatch);
|
||||
|
||||
static nsresult GetBaseDomainFromHost(nsIEffectiveTLDService* aTLDService,
|
||||
const nsACString& aHost,
|
||||
nsCString& aBaseDomain);
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_net_CookieCommons_h
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include "CookieCommons.h"
|
||||
#include "CookieLogging.h"
|
||||
#include "CookiePersistentStorage.h"
|
||||
#include "CookieService.h"
|
||||
|
||||
#include "mozilla/FileUtils.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
|
@ -708,7 +707,7 @@ nsresult CookiePersistentStorage::ImportCookies(nsIFile* aCookieFile) {
|
|||
}
|
||||
|
||||
// compute the baseDomain from the host
|
||||
rv = CookieService::GetBaseDomainFromHost(mTLDService, host, baseDomain);
|
||||
rv = CookieCommons::GetBaseDomainFromHost(mTLDService, host, baseDomain);
|
||||
if (NS_FAILED(rv)) continue;
|
||||
|
||||
// pre-existing cookies have inIsolatedMozBrowser=false set by default
|
||||
|
@ -1049,7 +1048,7 @@ CookiePersistentStorage::OpenDBResult CookiePersistentStorage::TryInitDB(
|
|||
int64_t id = select->AsInt64(SCHEMA2_IDX_ID);
|
||||
select->GetUTF8String(SCHEMA2_IDX_HOST, host);
|
||||
|
||||
rv = CookieService::GetBaseDomainFromHost(mTLDService, host,
|
||||
rv = CookieCommons::GetBaseDomainFromHost(mTLDService, host,
|
||||
baseDomain);
|
||||
NS_ENSURE_SUCCESS(rv, RESULT_RETRY);
|
||||
|
||||
|
@ -1798,7 +1797,7 @@ CookiePersistentStorage::OpenDBResult CookiePersistentStorage::Read() {
|
|||
|
||||
stmt->GetUTF8String(IDX_HOST, host);
|
||||
|
||||
rv = CookieService::GetBaseDomainFromHost(mTLDService, host, baseDomain);
|
||||
rv = CookieCommons::GetBaseDomainFromHost(mTLDService, host, baseDomain);
|
||||
if (NS_FAILED(rv)) {
|
||||
COOKIE_LOGSTRING(LogLevel::Debug,
|
||||
("Read(): Ignoring invalid host '%s'", host.get()));
|
||||
|
|
|
@ -175,10 +175,8 @@ void CookieService::CloseCookieStorages() {
|
|||
return;
|
||||
}
|
||||
|
||||
if (mPrivateStorage) {
|
||||
mPrivateStorage->Close();
|
||||
mPrivateStorage = nullptr;
|
||||
}
|
||||
mPrivateStorage->Close();
|
||||
mPrivateStorage = nullptr;
|
||||
|
||||
mPersistentStorage->Close();
|
||||
mPersistentStorage = nullptr;
|
||||
|
@ -370,8 +368,8 @@ void CookieService::SetCookieStringInternal(
|
|||
// is acceptable.
|
||||
bool requireHostMatch;
|
||||
nsAutoCString baseDomain;
|
||||
nsresult rv =
|
||||
GetBaseDomain(mTLDService, aHostURI, baseDomain, requireHostMatch);
|
||||
nsresult rv = CookieCommons::GetBaseDomain(mTLDService, aHostURI, baseDomain,
|
||||
requireHostMatch);
|
||||
if (NS_FAILED(rv)) {
|
||||
COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, aCookieHeader,
|
||||
"couldn't get base domain from URI");
|
||||
|
@ -387,7 +385,8 @@ void CookieService::SetCookieStringInternal(
|
|||
NS_ENSURE_SUCCESS_VOID(rv);
|
||||
|
||||
nsAutoCString baseDomainFromURI;
|
||||
rv = GetBaseDomainFromHost(mTLDService, hostFromURI, baseDomainFromURI);
|
||||
rv = CookieCommons::GetBaseDomainFromHost(mTLDService, hostFromURI,
|
||||
baseDomainFromURI);
|
||||
NS_ENSURE_SUCCESS_VOID(rv);
|
||||
|
||||
// check default prefs
|
||||
|
@ -552,7 +551,7 @@ CookieService::AddNative(const nsACString& aHost, const nsACString& aPath,
|
|||
// get the base domain for the host URI.
|
||||
// e.g. for "www.bbc.co.uk", this would be "bbc.co.uk".
|
||||
nsAutoCString baseDomain;
|
||||
rv = GetBaseDomainFromHost(mTLDService, host, baseDomain);
|
||||
rv = CookieCommons::GetBaseDomainFromHost(mTLDService, host, baseDomain);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
int64_t currentTimeInUsec = PR_Now();
|
||||
|
@ -583,7 +582,7 @@ nsresult CookieService::Remove(const nsACString& aHost,
|
|||
|
||||
nsAutoCString baseDomain;
|
||||
if (!host.IsEmpty()) {
|
||||
rv = GetBaseDomainFromHost(mTLDService, host, baseDomain);
|
||||
rv = CookieCommons::GetBaseDomainFromHost(mTLDService, host, baseDomain);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
|
@ -638,44 +637,6 @@ CookieService::ImportCookies(nsIFile* aCookieFile) {
|
|||
return mPersistentStorage->ImportCookies(aCookieFile);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* CookieService impl:
|
||||
* private GetCookie/SetCookie helpers
|
||||
******************************************************************************/
|
||||
|
||||
bool CookieService::DomainMatches(Cookie* aCookie, const nsACString& aHost) {
|
||||
// first, check for an exact host or domain cookie match, e.g. "google.com"
|
||||
// or ".google.com"; second a subdomain match, e.g.
|
||||
// host = "mail.google.com", cookie domain = ".google.com".
|
||||
return aCookie->RawHost() == aHost ||
|
||||
(aCookie->IsDomain() && StringEndsWith(aHost, aCookie->Host()));
|
||||
}
|
||||
|
||||
bool CookieService::PathMatches(Cookie* aCookie, const nsACString& aPath) {
|
||||
nsCString cookiePath(aCookie->GetFilePath());
|
||||
|
||||
// if our cookie path is empty we can't really perform our prefix check, and
|
||||
// also we can't check the last character of the cookie path, so we would
|
||||
// never return a successful match.
|
||||
if (cookiePath.IsEmpty()) return false;
|
||||
|
||||
// if the cookie path and the request path are identical, they match.
|
||||
if (cookiePath.Equals(aPath)) return true;
|
||||
|
||||
// if the cookie path is a prefix of the request path, and the last character
|
||||
// of the cookie path is %x2F ("/"), they match.
|
||||
bool isPrefix = StringBeginsWith(aPath, cookiePath);
|
||||
if (isPrefix && cookiePath.Last() == '/') return true;
|
||||
|
||||
// if the cookie path is a prefix of the request path, and the first character
|
||||
// of the request path that is not included in the cookie path is a %x2F ("/")
|
||||
// character, they match.
|
||||
uint32_t cookiePathLen = cookiePath.Length();
|
||||
if (isPrefix && aPath[cookiePathLen] == '/') return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CookieService::GetCookiesForURI(
|
||||
nsIURI* aHostURI, nsIChannel* aChannel, bool aIsForeign,
|
||||
bool aIsThirdPartyTrackingResource,
|
||||
|
@ -698,8 +659,8 @@ void CookieService::GetCookiesForURI(
|
|||
// is acceptable.
|
||||
bool requireHostMatch;
|
||||
nsAutoCString baseDomain, hostFromURI, pathFromURI;
|
||||
nsresult rv =
|
||||
GetBaseDomain(mTLDService, aHostURI, baseDomain, requireHostMatch);
|
||||
nsresult rv = CookieCommons::GetBaseDomain(mTLDService, aHostURI, baseDomain,
|
||||
requireHostMatch);
|
||||
if (NS_SUCCEEDED(rv)) rv = aHostURI->GetAsciiHost(hostFromURI);
|
||||
if (NS_SUCCEEDED(rv)) rv = aHostURI->GetFilePath(pathFromURI);
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -716,8 +677,8 @@ void CookieService::GetCookiesForURI(
|
|||
NS_ENSURE_SUCCESS_VOID(rv);
|
||||
|
||||
nsAutoCString baseDomainFromURI;
|
||||
rv = GetBaseDomainFromHost(mTLDService, normalizedHostFromURI,
|
||||
baseDomainFromURI);
|
||||
rv = CookieCommons::GetBaseDomainFromHost(mTLDService, normalizedHostFromURI,
|
||||
baseDomainFromURI);
|
||||
NS_ENSURE_SUCCESS_VOID(rv);
|
||||
|
||||
// check default prefs
|
||||
|
@ -772,7 +733,7 @@ void CookieService::GetCookiesForURI(
|
|||
// iterate the cookies!
|
||||
for (Cookie* cookie : *cookies) {
|
||||
// check the host, since the base domain lookup is conservative.
|
||||
if (!DomainMatches(cookie, hostFromURI)) continue;
|
||||
if (!CookieCommons::DomainMatches(cookie, hostFromURI)) continue;
|
||||
|
||||
// if the cookie is secure and the host scheme isn't, we can't send it
|
||||
if (cookie->IsSecure() && !potentiallyTurstworthy) continue;
|
||||
|
@ -788,7 +749,7 @@ void CookieService::GetCookiesForURI(
|
|||
if (cookie->IsHttpOnly() && !aHttpBound) continue;
|
||||
|
||||
// if the nsIURI path doesn't match the cookie path, don't send it back
|
||||
if (!PathMatches(cookie, pathFromURI)) continue;
|
||||
if (!CookieCommons::PathMatches(cookie, pathFromURI)) continue;
|
||||
|
||||
// check if the cookie has expired
|
||||
if (cookie->Expiry() <= currentTime) {
|
||||
|
@ -1429,74 +1390,6 @@ void CookieService::LogMessageToConsole(nsIChannel* aChannel, nsIURI* aURI,
|
|||
* private domain & permission compliance enforcement functions
|
||||
******************************************************************************/
|
||||
|
||||
// Get the base domain for aHostURI; e.g. for "www.bbc.co.uk", this would be
|
||||
// "bbc.co.uk". Only properly-formed URI's are tolerated, though a trailing
|
||||
// dot may be present. If aHostURI is an IP address, an alias such as
|
||||
// 'localhost', an eTLD such as 'co.uk', or the empty string, aBaseDomain will
|
||||
// be the exact host, and aRequireHostMatch will be true to indicate that
|
||||
// substring matches should not be performed.
|
||||
nsresult CookieService::GetBaseDomain(nsIEffectiveTLDService* aTLDService,
|
||||
nsIURI* aHostURI, nsCString& aBaseDomain,
|
||||
bool& aRequireHostMatch) {
|
||||
// get the base domain. this will fail if the host contains a leading dot,
|
||||
// more than one trailing dot, or is otherwise malformed.
|
||||
nsresult rv = aTLDService->GetBaseDomain(aHostURI, 0, aBaseDomain);
|
||||
aRequireHostMatch = rv == NS_ERROR_HOST_IS_IP_ADDRESS ||
|
||||
rv == NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS;
|
||||
if (aRequireHostMatch) {
|
||||
// aHostURI is either an IP address, an alias such as 'localhost', an eTLD
|
||||
// such as 'co.uk', or the empty string. use the host as a key in such
|
||||
// cases.
|
||||
rv = aHostURI->GetAsciiHost(aBaseDomain);
|
||||
}
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// aHost (and thus aBaseDomain) may be the string '.'. If so, fail.
|
||||
if (aBaseDomain.Length() == 1 && aBaseDomain.Last() == '.')
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// block any URIs without a host that aren't file:// URIs.
|
||||
if (aBaseDomain.IsEmpty() && !aHostURI->SchemeIs("file")) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Get the base domain for aHost; e.g. for "www.bbc.co.uk", this would be
|
||||
// "bbc.co.uk". This is done differently than GetBaseDomain(mTLDService, ): it
|
||||
// is assumed that aHost is already normalized, and it may contain a leading dot
|
||||
// (indicating that it represents a domain). A trailing dot may be present.
|
||||
// If aHost is an IP address, an alias such as 'localhost', an eTLD such as
|
||||
// 'co.uk', or the empty string, aBaseDomain will be the exact host, and a
|
||||
// leading dot will be treated as an error.
|
||||
nsresult CookieService::GetBaseDomainFromHost(
|
||||
nsIEffectiveTLDService* aTLDService, const nsACString& aHost,
|
||||
nsCString& aBaseDomain) {
|
||||
// aHost must not be the string '.'.
|
||||
if (aHost.Length() == 1 && aHost.Last() == '.') return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// aHost may contain a leading dot; if so, strip it now.
|
||||
bool domain = !aHost.IsEmpty() && aHost.First() == '.';
|
||||
|
||||
// get the base domain. this will fail if the host contains a leading dot,
|
||||
// more than one trailing dot, or is otherwise malformed.
|
||||
nsresult rv = aTLDService->GetBaseDomainFromHost(Substring(aHost, domain), 0,
|
||||
aBaseDomain);
|
||||
if (rv == NS_ERROR_HOST_IS_IP_ADDRESS ||
|
||||
rv == NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS) {
|
||||
// aHost is either an IP address, an alias such as 'localhost', an eTLD
|
||||
// such as 'co.uk', or the empty string. use the host as a key in such
|
||||
// cases; however, we reject any such hosts with a leading dot, since it
|
||||
// doesn't make sense for them to be domain cookies.
|
||||
if (domain) return NS_ERROR_INVALID_ARG;
|
||||
|
||||
aBaseDomain = aHost;
|
||||
return NS_OK;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Normalizes the given hostname, component by component. ASCII/ACE
|
||||
// components are lower-cased, and UTF-8 components are normalized per
|
||||
// RFC 3454 and converted to ACE.
|
||||
|
@ -1931,7 +1824,8 @@ CookieService::CookieExistsNative(const nsACString& aHost,
|
|||
}
|
||||
|
||||
nsAutoCString baseDomain;
|
||||
nsresult rv = GetBaseDomainFromHost(mTLDService, aHost, baseDomain);
|
||||
nsresult rv =
|
||||
CookieCommons::GetBaseDomainFromHost(mTLDService, aHost, baseDomain);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
CookieListIter iter;
|
||||
|
@ -1952,7 +1846,7 @@ CookieService::CountCookiesFromHost(const nsACString& aHost,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsAutoCString baseDomain;
|
||||
rv = GetBaseDomainFromHost(mTLDService, host, baseDomain);
|
||||
rv = CookieCommons::GetBaseDomainFromHost(mTLDService, host, baseDomain);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!IsInitialized()) {
|
||||
|
@ -1979,7 +1873,7 @@ CookieService::GetCookiesFromHost(const nsACString& aHost,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsAutoCString baseDomain;
|
||||
rv = GetBaseDomainFromHost(mTLDService, host, baseDomain);
|
||||
rv = CookieCommons::GetBaseDomainFromHost(mTLDService, host, baseDomain);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
OriginAttributes attrs;
|
||||
|
@ -2020,7 +1914,7 @@ CookieService::GetCookiesWithOriginAttributes(
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsAutoCString baseDomain;
|
||||
rv = GetBaseDomainFromHost(mTLDService, host, baseDomain);
|
||||
rv = CookieCommons::GetBaseDomainFromHost(mTLDService, host, baseDomain);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return GetCookiesWithOriginAttributes(pattern, baseDomain, aResult);
|
||||
|
@ -2050,7 +1944,7 @@ CookieService::RemoveCookiesWithOriginAttributes(const nsAString& aPattern,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsAutoCString baseDomain;
|
||||
rv = GetBaseDomainFromHost(mTLDService, host, baseDomain);
|
||||
rv = CookieCommons::GetBaseDomainFromHost(mTLDService, host, baseDomain);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return RemoveCookiesWithOriginAttributes(pattern, baseDomain);
|
||||
|
@ -2088,7 +1982,7 @@ nsresult CookieService::RemoveCookiesFromExactHost(
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsAutoCString baseDomain;
|
||||
rv = GetBaseDomainFromHost(mTLDService, host, baseDomain);
|
||||
rv = CookieCommons::GetBaseDomainFromHost(mTLDService, host, baseDomain);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!IsInitialized()) {
|
||||
|
|
|
@ -79,14 +79,6 @@ class CookieService final : public nsICookieService,
|
|||
* app.
|
||||
*/
|
||||
static nsAutoCString GetPathFromURI(nsIURI* aHostURI);
|
||||
static nsresult GetBaseDomain(nsIEffectiveTLDService* aTLDService,
|
||||
nsIURI* aHostURI, nsCString& aBaseDomain,
|
||||
bool& aRequireHostMatch);
|
||||
static nsresult GetBaseDomainFromHost(nsIEffectiveTLDService* aTLDService,
|
||||
const nsACString& aHost,
|
||||
nsCString& aBaseDomain);
|
||||
static bool DomainMatches(Cookie* aCookie, const nsACString& aHost);
|
||||
static bool PathMatches(Cookie* aCookie, const nsACString& aPath);
|
||||
static bool CanSetCookie(nsIURI* aHostURI, const nsACString& aBaseDomain,
|
||||
CookieStruct& aCookieData, bool aRequireHostMatch,
|
||||
CookieStatus aStatus, nsCString& aCookieHeader,
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/net/CookiePermission.h"
|
||||
#include "mozilla/net/CookieService.h"
|
||||
#include "mozilla/net/CookieServiceChild.h"
|
||||
#include "mozilla/net/NeckoChannelParams.h"
|
||||
#include "mozilla/LoadInfo.h"
|
||||
|
@ -18,6 +17,7 @@
|
|||
#include "mozilla/SystemGroup.h"
|
||||
#include "mozilla/StoragePrincipalHelper.h"
|
||||
#include "Cookie.h"
|
||||
#include "CookieCommons.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
@ -163,7 +163,7 @@ mozilla::ipc::IPCResult CookieServiceChild::RecvRemoveAll() {
|
|||
mozilla::ipc::IPCResult CookieServiceChild::RecvRemoveCookie(
|
||||
const CookieStruct& aCookie, const OriginAttributes& aAttrs) {
|
||||
nsCString baseDomain;
|
||||
CookieService::GetBaseDomainFromHost(mTLDService, aCookie.host(), baseDomain);
|
||||
CookieCommons::GetBaseDomainFromHost(mTLDService, aCookie.host(), baseDomain);
|
||||
CookieKey key(baseDomain, aAttrs);
|
||||
CookiesList* cookiesList = nullptr;
|
||||
mCookiesMap.Get(key, &cookiesList);
|
||||
|
@ -261,7 +261,7 @@ void CookieServiceChild::GetCookieStringFromCookieHashTable(
|
|||
StoragePrincipalHelper::PrepareOriginAttributes(aChannel, attrs);
|
||||
}
|
||||
|
||||
CookieService::GetBaseDomain(TLDService, aHostURI, baseDomain,
|
||||
CookieCommons::GetBaseDomain(TLDService, aHostURI, baseDomain,
|
||||
requireHostMatch);
|
||||
CookieKey key(baseDomain, attrs);
|
||||
CookiesList* cookiesList = nullptr;
|
||||
|
@ -296,7 +296,7 @@ void CookieServiceChild::GetCookieStringFromCookieHashTable(
|
|||
for (uint32_t i = 0; i < cookiesList->Length(); i++) {
|
||||
Cookie* cookie = cookiesList->ElementAt(i);
|
||||
// check the host, since the base domain lookup is conservative.
|
||||
if (!CookieService::DomainMatches(cookie, hostFromURI)) continue;
|
||||
if (!CookieCommons::DomainMatches(cookie, hostFromURI)) continue;
|
||||
|
||||
// We don't show HttpOnly cookies in content processes.
|
||||
if (cookie->IsHttpOnly()) {
|
||||
|
@ -322,7 +322,7 @@ void CookieServiceChild::GetCookieStringFromCookieHashTable(
|
|||
}
|
||||
|
||||
// if the nsIURI path doesn't match the cookie path, don't send it back
|
||||
if (!CookieService::PathMatches(cookie, pathFromURI)) continue;
|
||||
if (!CookieCommons::PathMatches(cookie, pathFromURI)) continue;
|
||||
|
||||
// check if the cookie has expired
|
||||
if (cookie->Expiry() <= currentTime) {
|
||||
|
@ -396,7 +396,7 @@ void CookieServiceChild::SetCookieInternal(
|
|||
void CookieServiceChild::RecordDocumentCookie(Cookie* aCookie,
|
||||
const OriginAttributes& aAttrs) {
|
||||
nsAutoCString baseDomain;
|
||||
CookieService::GetBaseDomainFromHost(mTLDService, aCookie->Host(),
|
||||
CookieCommons::GetBaseDomainFromHost(mTLDService, aCookie->Host(),
|
||||
baseDomain);
|
||||
|
||||
CookieKey key(baseDomain, aAttrs);
|
||||
|
@ -515,7 +515,7 @@ nsresult CookieServiceChild::SetCookieStringInternal(
|
|||
|
||||
bool requireHostMatch;
|
||||
nsCString baseDomain;
|
||||
CookieService::GetBaseDomain(mTLDService, aHostURI, baseDomain,
|
||||
CookieCommons::GetBaseDomain(mTLDService, aHostURI, baseDomain,
|
||||
requireHostMatch);
|
||||
|
||||
nsCOMPtr<nsICookieJarSettings> cookieJarSettings =
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include "Cookie.h"
|
||||
#include "CookieCommons.h"
|
||||
#include "CookieLogging.h"
|
||||
#include "CookieService.h"
|
||||
#include "CookieStorage.h"
|
||||
|
||||
#include "nsIMutableArray.h"
|
||||
|
@ -202,13 +201,13 @@ bool CookieStorage::FindSecureCookie(const nsACString& aBaseDomain,
|
|||
continue;
|
||||
|
||||
// The host must "domain-match" an existing cookie or vice-versa
|
||||
if (CookieService::DomainMatches(cookie, aCookie->Host()) ||
|
||||
CookieService::DomainMatches(aCookie, cookie->Host())) {
|
||||
if (CookieCommons::DomainMatches(cookie, aCookie->Host()) ||
|
||||
CookieCommons::DomainMatches(aCookie, cookie->Host())) {
|
||||
// If the path of new cookie and the path of existing cookie
|
||||
// aren't "/", then this situation needs to compare paths to
|
||||
// ensure only that a newly-created non-secure cookie does not
|
||||
// overlay an existing secure cookie.
|
||||
if (CookieService::PathMatches(cookie, aCookie->GetFilePath())) {
|
||||
if (CookieCommons::PathMatches(cookie, aCookie->GetFilePath())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ EXPORTS.mozilla.net = [
|
|||
]
|
||||
UNIFIED_SOURCES += [
|
||||
'Cookie.cpp',
|
||||
'CookieCommons.cpp',
|
||||
'CookieJarSettings.cpp',
|
||||
'CookieLogging.cpp',
|
||||
'CookiePermission.cpp',
|
||||
|
|
Загрузка…
Ссылка в новой задаче