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"
|
2019-03-08 12:04:34 +03:00
|
|
|
#include "nsICookiePermission.h"
|
2003-10-11 03:09:18 +04:00
|
|
|
#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;
|
2019-03-08 12:04:34 +03:00
|
|
|
class nsICookieSettings;
|
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
|
2019-10-28 15:07:39 +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
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsCookieEntry(const nsCookieEntry& toCopy) {
|
2003-10-22 10:53:19 +04:00
|
|
|
// 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
|
|
|
|
2019-05-01 11:47:10 +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
|
|
|
};
|
|
|
|
|
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;
|
2019-05-31 12:31:12 +03:00
|
|
|
OriginAttributes originAttributes;
|
|
|
|
mozilla::UniquePtr<mozilla::net::CookieStruct> 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.
|
2019-05-01 11:47:10 +03:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2019-01-22 22:46:10 +03:00
|
|
|
// these constants represent an operation being performed on cookies
|
|
|
|
enum CookieOperation { OPERATION_READ, OPERATION_WRITE };
|
|
|
|
|
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
|
|
|
|
******************************************************************************/
|
|
|
|
|
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();
|
2019-05-01 11:47:10 +03:00
|
|
|
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(nsCookie* aCookie, const nsACString& aHost);
|
|
|
|
static bool PathMatches(nsCookie* aCookie, const nsACString& aPath);
|
|
|
|
static bool CanSetCookie(nsIURI* aHostURI, const nsCookieKey& aKey,
|
2019-05-31 12:31:30 +03:00
|
|
|
mozilla::net::CookieStruct& aCookieData,
|
2017-02-17 05:58:48 +03:00
|
|
|
bool aRequireHostMatch, CookieStatus aStatus,
|
2019-05-31 12:36:44 +03:00
|
|
|
nsCString& aCookieHeader, int64_t aServerTime,
|
|
|
|
bool aFromHttp, nsIChannel* aChannel,
|
|
|
|
bool& aSetCookie,
|
2019-05-01 11:47:10 +03:00
|
|
|
mozIThirdPartyUtil* aThirdPartyUtil);
|
2018-08-31 12:02:33 +03:00
|
|
|
static CookieStatus CheckPrefs(
|
2019-05-31 12:32:33 +03:00
|
|
|
nsICookieSettings* aCookieSettings, nsIURI* aHostURI, bool aIsForeign,
|
2019-11-02 02:24:25 +03:00
|
|
|
bool aIsTrackingResource, bool aIsSocialTrackingResource,
|
|
|
|
bool aIsFirstPartyStorageAccessGranted, const nsACString& aCookieHeader,
|
|
|
|
const int aNumOfCookies, const OriginAttributes& aOriginAttrs,
|
|
|
|
uint32_t* aRejectedReason);
|
2019-05-31 12:36:44 +03:00
|
|
|
static int64_t ParseServerTime(const nsACString& aServerTime);
|
2019-03-08 12:04:34 +03:00
|
|
|
|
|
|
|
static already_AddRefed<nsICookieSettings> GetCookieSettings(
|
2019-05-01 11:47:10 +03:00
|
|
|
nsIChannel* aChannel);
|
2019-03-08 12:04:34 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void GetCookiesForURI(nsIURI* aHostURI, nsIChannel* aChannel, bool aIsForeign,
|
2018-07-10 11:09:59 +03:00
|
|
|
bool aIsTrackingResource,
|
2019-11-02 02:24:25 +03:00
|
|
|
bool aIsSocialTrackingResource,
|
2018-07-10 11:09:59 +03:00
|
|
|
bool aFirstPartyStorageAccessGranted,
|
2019-05-25 04:25:41 +03:00
|
|
|
uint32_t aRejectedReason, bool aIsSafeTopLevelNav,
|
|
|
|
bool aIsSameSiteForeign, bool aHttpBound,
|
|
|
|
const OriginAttributes& aOriginAttrs,
|
2019-05-01 11:47:10 +03:00
|
|
|
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
|
|
|
|
2019-05-01 11:47:10 +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();
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult CreateTableWorker(const char* aName);
|
2016-12-03 04:10:11 +03:00
|
|
|
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();
|
2019-05-01 11:47:10 +03:00
|
|
|
void HandleDBClosed(DBState* aDBState);
|
|
|
|
void HandleCorruptDB(DBState* aDBState);
|
|
|
|
void RebuildCorruptDB(DBState* aDBState);
|
2010-11-12 20:32:35 +03:00
|
|
|
OpenDBResult Read();
|
2019-05-31 12:31:12 +03:00
|
|
|
mozilla::UniquePtr<mozilla::net::CookieStruct> GetCookieFromRow(
|
|
|
|
mozIStorageStatement* aRow);
|
2017-08-29 13:16:27 +03:00
|
|
|
void EnsureReadComplete(bool aInitDBConn);
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult NormalizeHost(nsCString& aHost);
|
|
|
|
nsresult GetCookieStringCommon(nsIURI* aHostURI, nsIChannel* aChannel,
|
2019-05-31 12:36:44 +03:00
|
|
|
bool aHttpBound, nsACString& aCookie);
|
2019-11-02 02:24:25 +03:00
|
|
|
void GetCookieStringInternal(
|
|
|
|
nsIURI* aHostURI, nsIChannel* aChannel, bool aIsForeign,
|
|
|
|
bool aIsTrackingResource, bool aIsSocialTrackingResource,
|
|
|
|
bool aFirstPartyStorageAccessGranted, uint32_t aRejectedReason,
|
|
|
|
bool aIsSafeTopLevelNav, bool aIsSameSiteForeign, bool aHttpBound,
|
|
|
|
const OriginAttributes& aOriginAttrs, nsACString& aCookie);
|
2019-05-31 12:36:44 +03:00
|
|
|
nsresult SetCookieStringCommon(nsIURI* aHostURI,
|
|
|
|
const nsACString& aCookieHeader,
|
|
|
|
const nsACString& aServerTime,
|
|
|
|
nsIChannel* aChannel, bool aFromHttp);
|
|
|
|
void SetCookieStringInternal(
|
|
|
|
nsIURI* aHostURI, bool aIsForeign, bool aIsTrackingResource,
|
2019-11-02 02:24:25 +03:00
|
|
|
bool aIsSocialTrackingResource, bool aFirstPartyStorageAccessGranted,
|
|
|
|
uint32_t aRejectedReason, nsCString& aCookieHeader,
|
|
|
|
const nsACString& aServerTime, bool aFromHttp,
|
2019-05-31 12:36:44 +03:00
|
|
|
const OriginAttributes& aOriginAttrs, nsIChannel* aChannel);
|
2019-05-01 11:47:10 +03:00
|
|
|
bool SetCookieInternal(nsIURI* aHostURI, const nsCookieKey& aKey,
|
2018-04-19 14:18:50 +03:00
|
|
|
bool aRequireHostMatch, CookieStatus aStatus,
|
2019-05-31 12:36:44 +03:00
|
|
|
nsCString& aCookieHeader, int64_t aServerTime,
|
2019-05-01 11:47:10 +03:00
|
|
|
bool aFromHttp, nsIChannel* aChannel);
|
|
|
|
void AddInternal(const nsCookieKey& aKey, nsCookie* aCookie,
|
|
|
|
int64_t aCurrentTimeInUsec, nsIURI* aHostURI,
|
2019-05-31 12:36:44 +03:00
|
|
|
const nsACString& aCookieHeader, bool aFromHttp);
|
2013-09-19 23:28:26 +04:00
|
|
|
void RemoveCookieFromList(
|
2019-05-01 11:47:10 +03:00
|
|
|
const nsListIter& aIter,
|
|
|
|
mozIStorageBindingParamsArray* aParamsArray = nullptr);
|
|
|
|
void AddCookieToList(const nsCookieKey& aKey, nsCookie* aCookie,
|
|
|
|
DBState* aDBState,
|
|
|
|
mozIStorageBindingParamsArray* aParamsArray,
|
2017-06-20 12:18:17 +03:00
|
|
|
bool aWriteToDB = true);
|
2019-05-01 11:47:10 +03:00
|
|
|
void UpdateCookieInList(nsCookie* aCookie, int64_t aLastAccessed,
|
|
|
|
mozIStorageBindingParamsArray* aParamsArray);
|
|
|
|
static bool GetTokenValue(nsACString::const_char_iterator& aIter,
|
|
|
|
nsACString::const_char_iterator& aEndIter,
|
|
|
|
nsDependentCSubstring& aTokenString,
|
|
|
|
nsDependentCSubstring& aTokenValue,
|
|
|
|
bool& aEqualsFound);
|
2019-05-31 12:36:44 +03:00
|
|
|
static bool ParseAttributes(nsCString& aCookieHeader,
|
2019-05-31 12:31:30 +03:00
|
|
|
mozilla::net::CookieStruct& aCookieData,
|
2019-06-05 15:18:52 +03:00
|
|
|
nsACString& aExpires, nsACString& aMaxage,
|
|
|
|
bool& aAcceptedByParser);
|
2012-09-18 20:04:04 +04:00
|
|
|
bool RequireThirdPartyCheck();
|
2019-05-31 12:31:30 +03:00
|
|
|
static bool CheckDomain(mozilla::net::CookieStruct& aCookieData,
|
|
|
|
nsIURI* aHostURI, const nsCString& aBaseDomain,
|
|
|
|
bool aRequireHostMatch);
|
|
|
|
static bool CheckPath(mozilla::net::CookieStruct& aCookieData,
|
|
|
|
nsIURI* aHostURI);
|
|
|
|
static bool CheckPrefixes(mozilla::net::CookieStruct& aCookieData,
|
|
|
|
bool aSecureRequest);
|
|
|
|
static bool GetExpiry(mozilla::net::CookieStruct& aCookieData,
|
|
|
|
const nsACString& aExpires, const nsACString& aMaxage,
|
|
|
|
int64_t aServerTime, int64_t aCurrentTime,
|
|
|
|
bool aFromHttp);
|
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);
|
2019-05-01 11:47:10 +03:00
|
|
|
bool FindCookie(const nsCookieKey& aKey, const nsCString& aHost,
|
|
|
|
const nsCString& aName, const nsCString& aPath,
|
|
|
|
nsListIter& aIter);
|
|
|
|
bool FindSecureCookie(const nsCookieKey& aKey, nsCookie* aCookie);
|
|
|
|
void FindStaleCookies(nsCookieEntry* aEntry, int64_t aCurrentTime,
|
|
|
|
bool aIsSecure, nsTArray<nsListIter>& aOutput,
|
2019-02-20 12:42:22 +03:00
|
|
|
uint32_t aLimit);
|
2019-05-01 11:47:10 +03:00
|
|
|
void NotifyAccepted(nsIChannel* aChannel);
|
|
|
|
void NotifyRejected(nsIURI* aHostURI, nsIChannel* aChannel,
|
2019-01-22 22:46:10 +03:00
|
|
|
uint32_t aRejectedReason, CookieOperation aOperation);
|
2019-05-01 11:47:10 +03:00
|
|
|
void NotifyChanged(nsISupports* aSubject, const char16_t* aData,
|
2018-04-19 14:18:50 +03:00
|
|
|
bool aOldCookieIsSession = false, bool aFromHttp = false);
|
2019-05-31 12:36:44 +03:00
|
|
|
void NotifyPurged(nsICookie* aCookie);
|
|
|
|
already_AddRefed<nsIArray> CreatePurgeList(nsICookie* aCookie);
|
|
|
|
void CreateOrUpdatePurgeList(nsIArray** aPurgeList, nsICookie* aCookie);
|
2019-05-01 11:47:10 +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(
|
2019-05-01 11:47:10 +03:00
|
|
|
const mozilla::OriginAttributesPattern& aPattern,
|
2019-10-28 15:07:39 +03:00
|
|
|
const nsCString& aBaseDomain, nsTArray<RefPtr<nsICookie>>& aResult);
|
2017-01-12 19:38:48 +03:00
|
|
|
nsresult RemoveCookiesWithOriginAttributes(
|
2019-05-01 11:47:10 +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
|
|
|
*/
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult Remove(const nsACString& aHost, const OriginAttributes& aAttrs,
|
2019-09-24 20:13:43 +03:00
|
|
|
const nsACString& aName, const nsACString& aPath);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-12-05 03:03:22 +03:00
|
|
|
protected:
|
2019-09-09 16:58:06 +03:00
|
|
|
nsresult RemoveCookiesFromExactHost(
|
2019-05-01 11:47:10 +03:00
|
|
|
const nsACString& aHost,
|
|
|
|
const mozilla::OriginAttributesPattern& aPattern);
|
2019-04-12 23:27:21 +03:00
|
|
|
|
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.
|
2019-05-01 11:47:10 +03:00
|
|
|
DBState* mDBState;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DBState> mDefaultDBState;
|
|
|
|
RefPtr<DBState> mPrivateDBState;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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__
|