2010-11-12 20:32:35 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2003-10-11 03:09:18 +04:00
|
|
|
|
|
|
|
#ifndef nsCookieService_h__
|
|
|
|
#define nsCookieService_h__
|
|
|
|
|
2007-06-26 14:41:58 +04:00
|
|
|
#include "nsICookieService.h"
|
2003-10-11 03:09:18 +04:00
|
|
|
#include "nsICookieManager.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsWeakReference.h"
|
|
|
|
|
|
|
|
#include "nsCookie.h"
|
2017-08-03 14:00:41 +03:00
|
|
|
#include "nsCookieKey.h"
|
2003-10-11 03:09:18 +04:00
|
|
|
#include "nsString.h"
|
2009-12-20 02:55:56 +03:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsHashKeys.h"
|
2013-12-04 01:58:41 +04:00
|
|
|
#include "nsIMemoryReporter.h"
|
2003-10-22 10:53:19 +04:00
|
|
|
#include "nsTHashtable.h"
|
2009-10-17 01:26:00 +04:00
|
|
|
#include "mozIStorageStatement.h"
|
2010-11-12 20:32:35 +03:00
|
|
|
#include "mozIStorageAsyncStatement.h"
|
2010-07-29 23:17:42 +04:00
|
|
|
#include "mozIStoragePendingStatement.h"
|
2009-10-17 01:26:00 +04:00
|
|
|
#include "mozIStorageConnection.h"
|
2010-07-29 23:17:42 +04:00
|
|
|
#include "mozIStorageRow.h"
|
2010-11-12 20:32:35 +03:00
|
|
|
#include "mozIStorageCompletionCallback.h"
|
|
|
|
#include "mozIStorageStatementCallback.h"
|
2015-09-03 13:22:51 +03:00
|
|
|
#include "mozIStorageFunction.h"
|
|
|
|
#include "nsIVariant.h"
|
2015-07-07 05:17:00 +03:00
|
|
|
#include "nsIFile.h"
|
2017-08-29 13:16:27 +03:00
|
|
|
#include "mozilla/Atomics.h"
|
2015-09-03 13:22:51 +03:00
|
|
|
#include "mozilla/BasePrincipal.h"
|
2013-12-04 01:58:41 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2016-11-09 12:14:21 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2017-08-29 13:16:27 +03:00
|
|
|
#include "mozilla/Monitor.h"
|
|
|
|
#include "mozilla/UniquePtr.h"
|
|
|
|
|
2016-01-14 11:03:50 +03:00
|
|
|
using mozilla::OriginAttributes;
|
2015-09-03 13:22:51 +03:00
|
|
|
|
2003-10-11 03:09:18 +04:00
|
|
|
class nsICookiePermission;
|
2007-12-05 03:03:22 +03:00
|
|
|
class nsIEffectiveTLDService;
|
2010-01-12 21:29:20 +03:00
|
|
|
class nsIIDNService;
|
2003-10-11 03:09:18 +04:00
|
|
|
class nsIPrefBranch;
|
|
|
|
class nsIObserverService;
|
|
|
|
class nsIURI;
|
|
|
|
class nsIChannel;
|
2010-11-12 20:32:35 +03:00
|
|
|
class nsIArray;
|
2017-08-29 13:16:27 +03:00
|
|
|
class nsIThread;
|
2010-07-30 00:43:34 +04:00
|
|
|
class mozIStorageService;
|
2010-10-19 20:37:03 +04:00
|
|
|
class mozIThirdPartyUtil;
|
2010-07-29 23:17:42 +04:00
|
|
|
class ReadCookieDBListener;
|
2003-10-11 03:09:18 +04:00
|
|
|
|
2010-03-26 02:02:28 +03:00
|
|
|
struct nsListIter;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
2017-08-03 14:00:41 +03:00
|
|
|
class nsCookieKey;
|
2010-03-26 02:02:28 +03:00
|
|
|
class CookieServiceParent;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|
2010-03-26 02:02:28 +03:00
|
|
|
|
2017-08-03 14:00:41 +03:00
|
|
|
using mozilla::net::nsCookieKey;
|
2012-09-18 20:04:04 +04:00
|
|
|
// Inherit from nsCookieKey so this can be stored in nsTHashTable
|
|
|
|
// TODO: why aren't we using nsClassHashTable<nsCookieKey, ArrayType>?
|
|
|
|
class nsCookieEntry : public nsCookieKey {
|
2003-10-22 10:53:19 +04:00
|
|
|
public:
|
|
|
|
// Hash methods
|
2015-10-18 08:24:48 +03:00
|
|
|
typedef nsTArray<RefPtr<nsCookie> > ArrayType;
|
2009-12-20 02:55:56 +03:00
|
|
|
typedef ArrayType::index_type IndexType;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-08-05 17:20:24 +04:00
|
|
|
explicit nsCookieEntry(KeyTypePointer aKey) : nsCookieKey(aKey) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-10-22 10:53:19 +04:00
|
|
|
nsCookieEntry(const nsCookieEntry &toCopy) {
|
|
|
|
// if we end up here, things will break. nsTHashtable shouldn't
|
|
|
|
// allow this, since we set ALLOW_MEMMOVE to true.
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("nsCookieEntry copy constructor is forbidden!");
|
2003-10-22 10:53:19 +04:00
|
|
|
}
|
|
|
|
|
2018-04-30 19:46:04 +03:00
|
|
|
~nsCookieEntry() = default;
|
2003-10-22 10:53:19 +04:00
|
|
|
|
2009-12-20 02:55:56 +03:00
|
|
|
inline ArrayType &GetCookies() { return mCookies; }
|
2003-10-22 10:53:19 +04:00
|
|
|
|
2013-12-04 01:58:41 +04:00
|
|
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
|
|
|
|
2003-10-22 10:53:19 +04:00
|
|
|
private:
|
2009-12-20 02:55:56 +03:00
|
|
|
ArrayType mCookies;
|
2003-10-22 10:53:19 +04:00
|
|
|
};
|
|
|
|
|
2017-08-29 13:16:27 +03:00
|
|
|
// struct for a constant cookie for threadsafe
|
|
|
|
struct ConstCookie {
|
|
|
|
ConstCookie(const nsCString &aName, const nsCString &aValue,
|
|
|
|
const nsCString &aHost, const nsCString &aPath, int64_t aExpiry,
|
|
|
|
int64_t aLastAccessed, int64_t aCreationTime, bool aIsSecure,
|
|
|
|
bool aIsHttpOnly, const OriginAttributes &aOriginAttributes,
|
|
|
|
int32_t aSameSite)
|
|
|
|
: name(aName),
|
|
|
|
value(aValue),
|
|
|
|
host(aHost),
|
|
|
|
path(aPath),
|
|
|
|
expiry(aExpiry),
|
|
|
|
lastAccessed(aLastAccessed),
|
|
|
|
creationTime(aCreationTime),
|
|
|
|
isSecure(aIsSecure),
|
|
|
|
isHttpOnly(aIsHttpOnly),
|
|
|
|
originAttributes(aOriginAttributes),
|
|
|
|
sameSite(aSameSite) {}
|
|
|
|
|
|
|
|
const nsCString name;
|
|
|
|
const nsCString value;
|
|
|
|
const nsCString host;
|
|
|
|
const nsCString path;
|
|
|
|
const int64_t expiry;
|
|
|
|
const int64_t lastAccessed;
|
|
|
|
const int64_t creationTime;
|
|
|
|
const bool isSecure;
|
|
|
|
const bool isHttpOnly;
|
|
|
|
const OriginAttributes originAttributes;
|
|
|
|
const int32_t sameSite;
|
|
|
|
};
|
|
|
|
|
2012-09-18 20:04:04 +04:00
|
|
|
// encapsulates a (key, nsCookie) tuple for temporary storage purposes.
|
2010-07-29 23:17:42 +04:00
|
|
|
struct CookieDomainTuple {
|
2012-09-18 20:04:04 +04:00
|
|
|
nsCookieKey key;
|
2017-08-29 13:16:27 +03:00
|
|
|
mozilla::UniquePtr<ConstCookie> cookie;
|
2010-07-29 23:17:42 +04:00
|
|
|
};
|
|
|
|
|
2009-10-17 01:01:47 +04:00
|
|
|
// encapsulates in-memory and on-disk DB states, so we can
|
|
|
|
// conveniently switch state when entering or exiting private browsing.
|
2015-03-21 19:28:04 +03:00
|
|
|
struct DBState final {
|
2018-06-13 23:52:59 +03:00
|
|
|
DBState()
|
|
|
|
: cookieCount(0),
|
|
|
|
cookieOldestTime(INT64_MAX),
|
|
|
|
corruptFlag(OK),
|
|
|
|
readListener(nullptr) {}
|
2010-11-12 20:32:35 +03:00
|
|
|
|
2014-04-02 22:20:46 +04:00
|
|
|
private:
|
|
|
|
// Private destructor, to discourage deletion outside of Release():
|
2018-04-30 19:46:04 +03:00
|
|
|
~DBState() = default;
|
2014-04-02 22:20:46 +04:00
|
|
|
|
|
|
|
public:
|
2010-11-12 20:32:35 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(DBState)
|
2009-10-17 01:01:47 +04:00
|
|
|
|
2013-12-04 01:58:41 +04:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
|
|
|
|
2010-11-12 20:32:35 +03:00
|
|
|
// State of the database connection.
|
|
|
|
enum CorruptFlag {
|
|
|
|
OK, // normal
|
|
|
|
CLOSING_FOR_REBUILD, // corruption detected, connection closing
|
|
|
|
REBUILDING // close complete, rebuilding database from memory
|
|
|
|
};
|
|
|
|
|
2009-10-17 01:01:47 +04:00
|
|
|
nsTHashtable<nsCookieEntry> hostTable;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t cookieCount;
|
|
|
|
int64_t cookieOldestTime;
|
2010-11-12 20:32:35 +03:00
|
|
|
nsCOMPtr<nsIFile> cookieFile;
|
2009-10-17 01:01:47 +04:00
|
|
|
nsCOMPtr<mozIStorageConnection> dbConn;
|
2010-11-12 20:32:35 +03:00
|
|
|
nsCOMPtr<mozIStorageAsyncStatement> stmtInsert;
|
|
|
|
nsCOMPtr<mozIStorageAsyncStatement> stmtDelete;
|
|
|
|
nsCOMPtr<mozIStorageAsyncStatement> stmtUpdate;
|
2010-11-12 20:32:35 +03:00
|
|
|
CorruptFlag corruptFlag;
|
2010-07-29 23:17:42 +04:00
|
|
|
|
2010-07-29 23:17:42 +04:00
|
|
|
// Various parts representing asynchronous read state. These are useful
|
|
|
|
// while the background read is taking place.
|
2010-07-30 00:43:34 +04:00
|
|
|
nsCOMPtr<mozIStorageConnection> syncConn;
|
2010-07-29 23:17:42 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> stmtReadDomain;
|
|
|
|
// The asynchronous read listener. This is a weak ref (storage has ownership)
|
|
|
|
// since it may need to outlive the DBState's database connection.
|
|
|
|
ReadCookieDBListener *readListener;
|
2010-11-12 20:32:35 +03:00
|
|
|
|
|
|
|
// DB completion handlers.
|
|
|
|
nsCOMPtr<mozIStorageStatementCallback> insertListener;
|
|
|
|
nsCOMPtr<mozIStorageStatementCallback> updateListener;
|
|
|
|
nsCOMPtr<mozIStorageStatementCallback> removeListener;
|
|
|
|
nsCOMPtr<mozIStorageCompletionCallback> closeListener;
|
2009-10-17 01:01:47 +04:00
|
|
|
};
|
|
|
|
|
2010-06-07 23:32:12 +04:00
|
|
|
// these constants represent a decision about a cookie based on user prefs.
|
|
|
|
enum CookieStatus {
|
|
|
|
STATUS_ACCEPTED,
|
|
|
|
STATUS_ACCEPT_SESSION,
|
|
|
|
STATUS_REJECTED,
|
|
|
|
// STATUS_REJECTED_WITH_ERROR indicates the cookie should be rejected because
|
|
|
|
// of an error (rather than something the user can control). this is used for
|
|
|
|
// notification purposes, since we only want to notify of rejections where
|
|
|
|
// the user can do something about it (e.g. whitelist the site).
|
|
|
|
STATUS_REJECTED_WITH_ERROR
|
|
|
|
};
|
|
|
|
|
2010-11-12 20:32:35 +03:00
|
|
|
// Result codes for TryInitDB() and Read().
|
|
|
|
enum OpenDBResult { RESULT_OK, RESULT_RETRY, RESULT_FAILURE };
|
|
|
|
|
2003-10-11 03:09:18 +04:00
|
|
|
/******************************************************************************
|
|
|
|
* nsCookieService:
|
|
|
|
* class declaration
|
|
|
|
******************************************************************************/
|
|
|
|
|
2017-08-03 12:59:31 +03:00
|
|
|
// struct for temporarily storing cookie attributes during header parsing
|
|
|
|
struct nsCookieAttributes {
|
|
|
|
nsAutoCString name;
|
|
|
|
nsAutoCString value;
|
|
|
|
nsAutoCString host;
|
|
|
|
nsAutoCString path;
|
|
|
|
nsAutoCString expires;
|
|
|
|
nsAutoCString maxage;
|
|
|
|
int64_t expiryTime;
|
|
|
|
bool isSession;
|
|
|
|
bool isSecure;
|
|
|
|
bool isHttpOnly;
|
2017-09-24 20:27:04 +03:00
|
|
|
int8_t sameSite;
|
2017-08-03 12:59:31 +03:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsCookieService final : public nsICookieService,
|
2017-10-31 15:02:28 +03:00
|
|
|
public nsICookieManager,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIObserver,
|
|
|
|
public nsSupportsWeakReference,
|
|
|
|
public nsIMemoryReporter {
|
2013-12-04 01:58:41 +04:00
|
|
|
private:
|
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
|
|
|
|
2018-04-14 04:52:28 +03:00
|
|
|
static bool sSameSiteEnabled; // cached pref
|
|
|
|
|
2003-10-11 03:09:18 +04:00
|
|
|
public:
|
2013-12-08 10:09:10 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
2003-10-11 03:09:18 +04:00
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
NS_DECL_NSICOOKIESERVICE
|
|
|
|
NS_DECL_NSICOOKIEMANAGER
|
2013-12-08 10:09:10 +04:00
|
|
|
NS_DECL_NSIMEMORYREPORTER
|
2003-10-11 03:09:18 +04:00
|
|
|
|
|
|
|
nsCookieService();
|
2017-09-05 01:05:10 +03:00
|
|
|
static already_AddRefed<nsICookieService> GetXPCOMSingleton();
|
|
|
|
nsresult Init();
|
2003-10-11 03:09:18 +04:00
|
|
|
|
2012-09-28 01:37:28 +04:00
|
|
|
/**
|
|
|
|
* Start watching the observer service for messages indicating that an app has
|
|
|
|
* been uninstalled. When an app is uninstalled, we get the cookie service
|
|
|
|
* (thus instantiating it, if necessary) and clear all the cookies for that
|
|
|
|
* app.
|
|
|
|
*/
|
2012-09-29 04:03:00 +04:00
|
|
|
static void AppClearDataObserverInit();
|
Bug 1489944 - Fixed some std::move warnings - r=froydnj
> dom/media/gmp/CDMStorageIdProvider.cpp(63,10): warning:
> local variable 'storageId' will be copied despite being returned by name [-Wreturn-std-move]
nsAutoCString -> nsCString, will add std::move().
> layout/painting/DisplayItemClip.cpp(581,10): warning:
> local variable 'str' will be copied despite being returned by name [-Wreturn-std-move]
nsAutoCString -> nsCString, will add std::move().
> layout/painting/DisplayItemClipChain.cpp(88,10): warning:
> local variable 'str' will be copied despite being returned by name [-Wreturn-std-move]
nsAutoCString -> nsCString, will add std::move().
> layout/painting/nsDisplayList.cpp(179,10): warning:
> local variable 'str' will be copied despite being returned by name [-Wreturn-std-move]
nsAutoCString -> nsCString, will add std::move().
> gfx/thebes/gfxWindowsPlatform.cpp(454,10): warning:
> moving a local object in a return statement prevents copy elision [-Wpessimizing-move]
Will remove std::move().
> gfx/thebes/gfxFontEntry.cpp(245,20): warning:
> local variable 'name' will be copied despite being returned by name [-Wreturn-std-move]
nsAutoCString -> nsCString, will add std::move().
> netwerk/cookie/nsCookieService.cpp(4460,10): warning:
> local variable 'path' will be copied despite being returned by name [-Wreturn-std-move]
GetPathFromURI() result is stored in an nsAutoCString, so it might as well return that type.
> toolkit/components/extensions/WebExtensionPolicy.cpp(462,12): warning:
> local variable 'result' will be copied despite being returned by name [-Wreturn-std-move]
> toolkit/components/extensions/WebExtensionPolicy.cpp(475,10): warning:
> local variable 'result' will be copied despite being returned by name [-Wreturn-std-move]
`result` may be empty or may be arbitrarily long, so I'll use nsCString inside the function.
> toolkit/xre/CmdLineAndEnvUtils.h(349,10): warning:
> moving a local object in a return statement prevents copy elision [-Wpessimizing-move]
Returning an UniquePtr, will remove std::move().
Also will `return s` instead of `return nullptr` when `(!s)`, to avoid extra construction which could also prevent elision (not entirely sure, but it's at least not worse!); and it's clearer that the two `return`s return the same already-constructed on-stack object.
> tools/profiler/core/shared-libraries-win32.cc(111,10): warning:
> local variable 'version' will be copied despite being returned by name [-Wreturn-std-move]
nsPrintfCString -> nsCString, will add std::move().
> xpcom/glue/FileUtils.cpp(179,10): warning:
> local variable 'fullName' will be copied despite being returned by name [-Wreturn-std-move]
> xpcom/glue/FileUtils.cpp(209,10): warning:
> local variable 'path' will be copied despite being returned by name [-Wreturn-std-move]
nsAuto{,C}String -> ns{,C}String, will add std::move().
This allowed removals of 'AllowCompilerWarnings' from layout/painting,
netwerk/cookie, and toolkit/components/extensions.
Differential Revision: https://phabricator.services.mozilla.com/D5425
--HG--
extra : moz-landing-system : lando
2018-09-10 18:51:48 +03:00
|
|
|
static nsAutoCString GetPathFromURI(nsIURI *aHostURI);
|
2017-08-03 14:00:41 +03:00
|
|
|
static nsresult GetBaseDomain(nsIEffectiveTLDService *aTLDService,
|
|
|
|
nsIURI *aHostURI, nsCString &aBaseDomain,
|
|
|
|
bool &aRequireHostMatch);
|
|
|
|
static nsresult GetBaseDomainFromHost(nsIEffectiveTLDService *aTLDService,
|
|
|
|
const nsACString &aHost,
|
|
|
|
nsCString &aBaseDomain);
|
|
|
|
static bool DomainMatches(nsCookie *aCookie, const nsACString &aHost);
|
2018-04-14 04:52:28 +03:00
|
|
|
static bool IsSameSiteEnabled();
|
2017-08-03 14:00:41 +03:00
|
|
|
static bool PathMatches(nsCookie *aCookie, const nsACString &aPath);
|
2017-02-17 05:58:48 +03:00
|
|
|
static bool CanSetCookie(nsIURI *aHostURI, const nsCookieKey &aKey,
|
|
|
|
nsCookieAttributes &aCookieAttributes,
|
|
|
|
bool aRequireHostMatch, CookieStatus aStatus,
|
|
|
|
nsDependentCString &aCookieHeader,
|
|
|
|
int64_t aServerTime, bool aFromHttp,
|
|
|
|
nsIChannel *aChannel, bool aLeaveSercureAlone,
|
|
|
|
bool &aSetCookie,
|
|
|
|
mozIThirdPartyUtil *aThirdPartyUtil);
|
2018-08-31 12:02:33 +03:00
|
|
|
static CookieStatus CheckPrefs(
|
|
|
|
nsICookiePermission *aPermissionServices, uint8_t aCookieBehavior,
|
|
|
|
bool aThirdPartySession, bool aThirdPartyNonsecureSession,
|
|
|
|
nsIURI *aHostURI, bool aIsForeign, bool aIsTrackingResource,
|
|
|
|
bool aIsFirstPartyStorageAccessGranted, const char *aCookieHeader,
|
|
|
|
const int aNumOfCookies, const OriginAttributes &aOriginAttrs,
|
|
|
|
uint32_t *aRejectedReason);
|
2017-08-03 12:59:31 +03:00
|
|
|
static int64_t ParseServerTime(const nsCString &aServerTime);
|
2018-07-10 11:09:59 +03:00
|
|
|
void GetCookiesForURI(nsIURI *aHostURI, bool aIsForeign,
|
|
|
|
bool aIsTrackingResource,
|
|
|
|
bool aFirstPartyStorageAccessGranted,
|
|
|
|
bool aIsSafeTopLevelNav, bool aIsTopLevelForeign,
|
|
|
|
bool aHttpBound, const OriginAttributes &aOriginAttrs,
|
|
|
|
nsTArray<nsCookie *> &aCookieList);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-10-11 03:09:18 +04:00
|
|
|
protected:
|
2014-06-24 20:36:44 +04:00
|
|
|
virtual ~nsCookieService();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-11-14 09:43:08 +03:00
|
|
|
void PrefChanged(nsIPrefBranch *aPrefBranch);
|
2010-11-12 20:32:35 +03:00
|
|
|
void InitDBStates();
|
2010-11-12 20:32:35 +03:00
|
|
|
OpenDBResult TryInitDB(bool aDeleteExistingDB);
|
2017-08-29 13:16:27 +03:00
|
|
|
void InitDBConn();
|
|
|
|
nsresult InitDBConnInternal();
|
2016-12-03 04:10:11 +03:00
|
|
|
nsresult CreateTableWorker(const char *aName);
|
|
|
|
nsresult CreateIndex();
|
2007-06-18 01:52:22 +04:00
|
|
|
nsresult CreateTable();
|
2015-11-03 13:40:58 +03:00
|
|
|
nsresult CreateTableForSchemaVersion6();
|
2015-09-03 13:22:51 +03:00
|
|
|
nsresult CreateTableForSchemaVersion5();
|
2010-11-12 20:32:35 +03:00
|
|
|
void CloseDBStates();
|
2013-07-24 00:41:23 +04:00
|
|
|
void CleanupCachedStatements();
|
|
|
|
void CleanupDefaultDBConnection();
|
2010-11-12 20:32:35 +03:00
|
|
|
void HandleDBClosed(DBState *aDBState);
|
|
|
|
void HandleCorruptDB(DBState *aDBState);
|
|
|
|
void RebuildCorruptDB(DBState *aDBState);
|
2010-11-12 20:32:35 +03:00
|
|
|
OpenDBResult Read();
|
2017-08-29 13:16:27 +03:00
|
|
|
mozilla::UniquePtr<ConstCookie> GetCookieFromRow(
|
|
|
|
mozIStorageStatement *aRow, const OriginAttributes &aOriginAttributes);
|
|
|
|
void EnsureReadComplete(bool aInitDBConn);
|
2010-01-12 21:29:20 +03:00
|
|
|
nsresult NormalizeHost(nsCString &aHost);
|
2010-09-17 00:21:12 +04:00
|
|
|
nsresult GetCookieStringCommon(nsIURI *aHostURI, nsIChannel *aChannel,
|
|
|
|
bool aHttpBound, char **aCookie);
|
2018-07-10 11:09:59 +03:00
|
|
|
void GetCookieStringInternal(nsIURI *aHostURI, bool aIsForeign,
|
|
|
|
bool aIsTrackingResource,
|
|
|
|
bool aFirstPartyStorageAccessGranted,
|
|
|
|
bool aIsSafeTopLevelNav, bool aIsTopLevelForeign,
|
|
|
|
bool aHttpBound,
|
|
|
|
const OriginAttributes &aOriginAttrs,
|
|
|
|
nsCString &aCookie);
|
2010-09-17 00:21:12 +04:00
|
|
|
nsresult SetCookieStringCommon(nsIURI *aHostURI, const char *aCookieHeader,
|
|
|
|
const char *aServerTime, nsIChannel *aChannel,
|
|
|
|
bool aFromHttp);
|
2018-07-10 11:09:59 +03:00
|
|
|
void SetCookieStringInternal(nsIURI *aHostURI, bool aIsForeign,
|
|
|
|
bool aIsTrackingResource,
|
|
|
|
bool aFirstPartyStorageAccessGranted,
|
|
|
|
nsDependentCString &aCookieHeader,
|
|
|
|
const nsCString &aServerTime, bool aFromHttp,
|
|
|
|
const OriginAttributes &aOriginAttrs,
|
2018-04-19 14:18:50 +03:00
|
|
|
nsIChannel *aChannel);
|
|
|
|
bool SetCookieInternal(nsIURI *aHostURI, const nsCookieKey &aKey,
|
|
|
|
bool aRequireHostMatch, CookieStatus aStatus,
|
|
|
|
nsDependentCString &aCookieHeader, int64_t aServerTime,
|
|
|
|
bool aFromHttp, nsIChannel *aChannel);
|
|
|
|
void AddInternal(const nsCookieKey &aKey, nsCookie *aCookie,
|
|
|
|
int64_t aCurrentTimeInUsec, nsIURI *aHostURI,
|
|
|
|
const char *aCookieHeader, bool aFromHttp);
|
2013-09-19 23:28:26 +04:00
|
|
|
void RemoveCookieFromList(
|
|
|
|
const nsListIter &aIter,
|
|
|
|
mozIStorageBindingParamsArray *aParamsArray = nullptr);
|
2012-09-18 20:04:04 +04:00
|
|
|
void AddCookieToList(const nsCookieKey &aKey, nsCookie *aCookie,
|
|
|
|
DBState *aDBState,
|
2012-08-22 19:56:38 +04:00
|
|
|
mozIStorageBindingParamsArray *aParamsArray,
|
2017-06-20 12:18:17 +03:00
|
|
|
bool aWriteToDB = true);
|
2018-09-03 17:49:58 +03:00
|
|
|
void UpdateCookieInList(nsCookie *aCookie, int64_t aLastAccessed,
|
|
|
|
mozIStorageBindingParamsArray *aParamsArray);
|
|
|
|
static bool GetTokenValue(nsACString::const_char_iterator &aIter,
|
2017-06-20 12:18:17 +03:00
|
|
|
nsACString::const_char_iterator &aEndIter,
|
2018-09-03 17:49:58 +03:00
|
|
|
nsDependentCSubstring &aTokenString,
|
|
|
|
nsDependentCSubstring &aTokenValue,
|
|
|
|
bool &aEqualsFound);
|
|
|
|
static bool ParseAttributes(nsDependentCString &aCookieHeader,
|
2011-09-29 10:19:26 +04:00
|
|
|
nsCookieAttributes &aCookie);
|
2012-09-18 20:04:04 +04:00
|
|
|
bool RequireThirdPartyCheck();
|
2018-09-03 17:49:58 +03:00
|
|
|
static bool CheckDomain(nsCookieAttributes &aCookie, nsIURI *aHostURI,
|
|
|
|
const nsCString &aBaseDomain, bool aRequireHostMatch);
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool CheckPath(nsCookieAttributes &aCookie, nsIURI *aHostURI);
|
2018-09-03 17:49:58 +03:00
|
|
|
static bool CheckPrefixes(nsCookieAttributes &aCookie, bool aSecureRequest);
|
2016-11-09 12:14:21 +03:00
|
|
|
static bool GetExpiry(nsCookieAttributes &aCookie, int64_t aServerTime,
|
2018-08-31 12:02:33 +03:00
|
|
|
int64_t aCurrentTime);
|
2018-04-19 14:18:50 +03:00
|
|
|
void RemoveAllFromMemory();
|
2010-11-12 20:32:35 +03:00
|
|
|
already_AddRefed<nsIArray> PurgeCookies(int64_t aCurrentTimeInUsec);
|
2015-07-09 04:25:50 +03:00
|
|
|
bool FindCookie(const nsCookieKey &aKey, const nsCString &aHost,
|
2016-07-28 06:46:04 +03:00
|
|
|
const nsCString &aName, const nsCString &aPath,
|
|
|
|
nsListIter &aIter);
|
|
|
|
bool FindSecureCookie(const nsCookieKey &aKey, nsCookie *aCookie);
|
|
|
|
void FindStaleCookies(nsCookieEntry *aEntry, int64_t aCurrentTime,
|
|
|
|
const mozilla::Maybe<bool> &aIsSecure,
|
2012-09-28 01:37:02 +04:00
|
|
|
nsTArray<nsListIter> &aOutput, uint32_t aLimit);
|
|
|
|
void TelemetryForEvictingStaleCookie(nsCookie *aEvicted,
|
|
|
|
int64_t oldestCookieTime);
|
2013-06-22 09:11:12 +04:00
|
|
|
void NotifyAccepted(nsIChannel *aChannel);
|
2018-08-31 12:02:33 +03:00
|
|
|
void NotifyRejected(nsIURI *aHostURI, nsIChannel *aChannel,
|
|
|
|
uint32_t aRejectedReason);
|
2012-09-28 01:37:02 +04:00
|
|
|
void NotifyThirdParty(nsIURI *aHostURI, bool aAccepted, nsIChannel *aChannel);
|
|
|
|
void NotifyChanged(nsISupports *aSubject, const char16_t *aData,
|
2018-04-19 14:18:50 +03:00
|
|
|
bool aOldCookieIsSession = false, bool aFromHttp = false);
|
2010-11-02 20:46:19 +03:00
|
|
|
void NotifyPurged(nsICookie2 *aCookie);
|
2017-01-12 19:38:48 +03:00
|
|
|
already_AddRefed<nsIArray> CreatePurgeList(nsICookie2 *aCookie);
|
2018-09-03 17:49:58 +03:00
|
|
|
void CreateOrUpdatePurgeList(nsIArray **aPurgeList, nsICookie2 *aCookie);
|
2017-01-12 19:38:48 +03:00
|
|
|
void UpdateCookieOldestTime(DBState *aDBState, nsCookie *aCookie);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-01-12 19:38:48 +03:00
|
|
|
nsresult GetCookiesWithOriginAttributes(
|
2012-09-28 01:37:02 +04:00
|
|
|
const mozilla::OriginAttributesPattern &aPattern,
|
2017-01-12 19:38:48 +03:00
|
|
|
const nsCString &aBaseDomain, nsISimpleEnumerator **aEnumerator);
|
|
|
|
nsresult RemoveCookiesWithOriginAttributes(
|
2015-09-03 13:22:51 +03:00
|
|
|
const mozilla::OriginAttributesPattern &aPattern,
|
|
|
|
const nsCString &aBaseDomain);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-10-17 01:01:47 +04:00
|
|
|
/**
|
2007-12-05 03:03:22 +03:00
|
|
|
* This method is a helper that allows calling nsICookieManager::Remove()
|
2010-10-19 20:37:03 +04:00
|
|
|
* with OriginAttributes parameter.
|
|
|
|
* NOTE: this could be added to a public interface if we happen to need it.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2010-10-19 20:37:03 +04:00
|
|
|
nsresult Remove(const nsACString &aHost, const OriginAttributes &aAttrs,
|
|
|
|
const nsACString &aName, const nsACString &aPath,
|
|
|
|
bool aBlocked);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-12-05 03:03:22 +03:00
|
|
|
protected:
|
2009-10-17 01:01:47 +04:00
|
|
|
// cached members.
|
2007-12-05 03:03:22 +03:00
|
|
|
nsCOMPtr<nsICookiePermission> mPermissionService;
|
2010-01-12 21:29:20 +03:00
|
|
|
nsCOMPtr<mozIThirdPartyUtil> mThirdPartyUtil;
|
|
|
|
nsCOMPtr<nsIEffectiveTLDService> mTLDService;
|
2010-07-30 00:43:34 +04:00
|
|
|
nsCOMPtr<nsIIDNService> mIDNService;
|
2010-11-12 20:32:35 +03:00
|
|
|
nsCOMPtr<mozIStorageService> mStorageService;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-10-17 01:01:47 +04:00
|
|
|
// we have two separate DB states: one for normal browsing and one for
|
2012-02-08 22:37:07 +04:00
|
|
|
// private browsing, switching between them on a per-cookie-request basis.
|
|
|
|
// this state encapsulates both the in-memory table and the on-disk DB.
|
2009-10-17 01:01:47 +04:00
|
|
|
// note that the private states' dbConn should always be null - we never
|
|
|
|
// want to be dealing with the on-disk DB when in private browsing.
|
|
|
|
DBState *mDBState;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DBState> mDefaultDBState;
|
|
|
|
RefPtr<DBState> mPrivateDBState;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-10-11 03:09:18 +04:00
|
|
|
// cached prefs
|
2013-02-22 20:16:01 +04:00
|
|
|
uint8_t mCookieBehavior; // BEHAVIOR_{ACCEPT, REJECTFOREIGN, REJECT,
|
|
|
|
// LIMITFOREIGN}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mThirdPartySession;
|
2017-02-17 06:27:49 +03:00
|
|
|
bool mThirdPartyNonsecureSession;
|
2016-11-09 12:14:21 +03:00
|
|
|
bool mLeaveSecureAlone;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t mMaxNumberOfCookies;
|
|
|
|
uint16_t mMaxCookiesPerHost;
|
2018-09-03 17:49:58 +03:00
|
|
|
uint16_t mCookieQuotaPerHost;
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t mCookiePurgeAge;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-08-29 13:16:27 +03:00
|
|
|
// thread
|
|
|
|
nsCOMPtr<nsIThread> mThread;
|
|
|
|
mozilla::Monitor mMonitor;
|
|
|
|
mozilla::Atomic<bool> mInitializedDBStates;
|
|
|
|
mozilla::Atomic<bool> mInitializedDBConn;
|
2017-11-21 18:51:11 +03:00
|
|
|
mozilla::TimeStamp mEndInitDBConn;
|
2017-08-29 13:16:27 +03:00
|
|
|
nsTArray<CookieDomainTuple> mReadArray;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-07-29 23:17:42 +04:00
|
|
|
// friends!
|
2010-11-12 20:32:35 +03:00
|
|
|
friend class DBListenerErrorHandler;
|
2010-07-29 23:17:42 +04:00
|
|
|
friend class ReadCookieDBListener;
|
2010-11-12 20:32:35 +03:00
|
|
|
friend class CloseCookieDBListener;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-09-05 01:05:10 +03:00
|
|
|
static already_AddRefed<nsCookieService> GetSingleton();
|
2010-03-26 02:02:28 +03:00
|
|
|
friend class mozilla::net::CookieServiceParent;
|
2003-10-11 03:09:18 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsCookieService_h__
|