2018-11-30 19:52:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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-10 23:09:18 +00:00
|
|
|
|
2020-04-06 12:22:01 +00:00
|
|
|
#ifndef mozilla_net_Cookie_h
|
|
|
|
#define mozilla_net_Cookie_h
|
2003-10-10 23:09:18 +00:00
|
|
|
|
|
|
|
#include "nsICookie.h"
|
Bug 1600545 - Remove useless inclusions of header files generated from IDL files in accessible/, browser/, caps/, chrome/, devtools/, docshell/, editor/, extensions/, gfx/, hal/, image/, intl/, ipc/, js/, layout/, and media/ r=Ehsan
The inclusions were removed with the following very crude script and the
resulting breakage was fixed up by hand. The manual fixups did either
revert the changes done by the script, replace a generic header with a more
specific one or replace a header with a forward declaration.
find . -name "*.idl" | grep -v web-platform | grep -v third_party | while read path; do
interfaces=$(grep "^\(class\|interface\).*:.*" "$path" | cut -d' ' -f2)
if [ -n "$interfaces" ]; then
if [[ "$interfaces" == *$'\n'* ]]; then
regexp="\("
for i in $interfaces; do regexp="$regexp$i\|"; done
regexp="${regexp%%\\\|}\)"
else
regexp="$interfaces"
fi
interface=$(basename "$path")
rg -l "#include.*${interface%%.idl}.h" . | while read path2; do
hits=$(grep -v "#include.*${interface%%.idl}.h" "$path2" | grep -c "$regexp" )
if [ $hits -eq 0 ]; then
echo "Removing ${interface} from ${path2}"
grep -v "#include.*${interface%%.idl}.h" "$path2" > "$path2".tmp
mv -f "$path2".tmp "$path2"
fi
done
fi
done
Differential Revision: https://phabricator.services.mozilla.com/D55443
--HG--
extra : moz-landing-system : lando
2019-12-06 09:16:44 +00:00
|
|
|
#include "nsIMemoryReporter.h"
|
2003-10-10 23:09:18 +00:00
|
|
|
#include "nsString.h"
|
|
|
|
|
2013-12-03 21:58:41 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2016-01-14 08:03:50 +00:00
|
|
|
#include "mozilla/BasePrincipal.h"
|
2019-05-31 09:31:47 +00:00
|
|
|
#include "mozilla/net/NeckoChannelParams.h"
|
Bug 1600545 - Remove useless inclusions of header files generated from IDL files in modules/, netwerk/, parser/, security/, startupcache/, storage/, toolkit/, tools/, uriloader/, widget/, xpcom/ and xpfe/ r=Ehsan
The inclusions were removed with the following very crude script and the
resulting breakage was fixed up by hand. The manual fixups did either
revert the changes done by the script, replace a generic header with a more
specific one or replace a header with a forward declaration.
find . -name "*.idl" | grep -v web-platform | grep -v third_party | while read path; do
interfaces=$(grep "^\(class\|interface\).*:.*" "$path" | cut -d' ' -f2)
if [ -n "$interfaces" ]; then
if [[ "$interfaces" == *$'\n'* ]]; then
regexp="\("
for i in $interfaces; do regexp="$regexp$i\|"; done
regexp="${regexp%%\\\|}\)"
else
regexp="$interfaces"
fi
interface=$(basename "$path")
rg -l "#include.*${interface%%.idl}.h" . | while read path2; do
hits=$(grep -v "#include.*${interface%%.idl}.h" "$path2" | grep -c "$regexp" )
if [ $hits -eq 0 ]; then
echo "Removing ${interface} from ${path2}"
grep -v "#include.*${interface%%.idl}.h" "$path2" > "$path2".tmp
mv -f "$path2".tmp "$path2"
fi
done
fi
done
Differential Revision: https://phabricator.services.mozilla.com/D55444
--HG--
extra : moz-landing-system : lando
2019-12-06 09:17:57 +00:00
|
|
|
#include "nsIMemoryReporter.h"
|
2016-01-14 08:03:50 +00:00
|
|
|
|
|
|
|
using mozilla::OriginAttributes;
|
2013-12-03 21:58:41 +00:00
|
|
|
|
2020-04-06 12:22:01 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
2003-10-10 23:09:18 +00:00
|
|
|
/**
|
2020-04-06 12:22:01 +00:00
|
|
|
* The Cookie class is the main cookie storage medium for use within cookie
|
2019-05-31 09:36:44 +00:00
|
|
|
* code.
|
2003-10-10 23:09:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/******************************************************************************
|
2020-04-06 12:22:01 +00:00
|
|
|
* Cookie:
|
2003-10-10 23:09:18 +00:00
|
|
|
* implementation
|
|
|
|
******************************************************************************/
|
|
|
|
|
2020-04-06 12:22:01 +00:00
|
|
|
class Cookie final : public nsICookie {
|
2019-05-31 09:31:47 +00:00
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf)
|
|
|
|
|
2003-10-10 23:09:18 +00:00
|
|
|
public:
|
|
|
|
// nsISupports
|
2007-10-04 19:24:00 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
2003-10-10 23:09:18 +00:00
|
|
|
NS_DECL_NSICOOKIE
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2003-11-18 12:30:23 +00:00
|
|
|
private:
|
2020-04-06 12:22:01 +00:00
|
|
|
// for internal use only. see Cookie::Create().
|
2020-04-06 12:33:45 +00:00
|
|
|
Cookie(const CookieStruct& aCookieData,
|
2020-04-06 12:22:01 +00:00
|
|
|
const OriginAttributes& aOriginAttributes)
|
2019-05-31 09:31:47 +00:00
|
|
|
: mData(aCookieData), mOriginAttributes(aOriginAttributes) {}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2003-11-18 12:30:23 +00:00
|
|
|
public:
|
2019-06-05 12:19:54 +00:00
|
|
|
// Returns false if rawSameSite has an invalid value, compared to sameSite.
|
2020-04-06 12:33:45 +00:00
|
|
|
static bool ValidateRawSame(const CookieStruct& aCookieData);
|
2019-06-05 12:19:54 +00:00
|
|
|
|
2010-10-20 00:24:52 +00:00
|
|
|
// Generate a unique and monotonically increasing creation time. See comment
|
2020-04-06 12:22:01 +00:00
|
|
|
// in Cookie.cpp.
|
2012-08-22 15:56:38 +00:00
|
|
|
static int64_t GenerateUniqueCreationTime(int64_t aCreationTime);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2020-04-06 12:22:01 +00:00
|
|
|
// public helper to create an Cookie object.
|
|
|
|
static already_AddRefed<Cookie> Create(
|
2020-04-06 12:33:45 +00:00
|
|
|
const CookieStruct& aCookieData,
|
2019-05-31 09:31:47 +00:00
|
|
|
const OriginAttributes& aOriginAttributes);
|
|
|
|
|
2013-12-03 21:58:41 +00:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2003-10-10 23:09:18 +00:00
|
|
|
// fast (inline, non-xpcom) getters
|
2019-05-31 09:31:47 +00:00
|
|
|
inline const nsCString& Name() const { return mData.name(); }
|
|
|
|
inline const nsCString& Value() const { return mData.value(); }
|
|
|
|
inline const nsCString& Host() const { return mData.host(); }
|
|
|
|
inline nsDependentCSubstring RawHost() const {
|
|
|
|
return nsDependentCSubstring(mData.host(), IsDomain() ? 1 : 0);
|
2003-10-10 23:09:18 +00:00
|
|
|
}
|
2019-05-31 09:31:47 +00:00
|
|
|
inline const nsCString& Path() const { return mData.path(); }
|
2019-09-24 14:33:59 +00:00
|
|
|
const nsCString& GetFilePath();
|
2019-05-31 09:31:47 +00:00
|
|
|
inline int64_t Expiry() const { return mData.expiry(); } // in seconds
|
2012-08-22 15:56:38 +00:00
|
|
|
inline int64_t LastAccessed() const {
|
2019-05-31 09:31:47 +00:00
|
|
|
return mData.lastAccessed();
|
2012-08-22 15:56:38 +00:00
|
|
|
} // in microseconds
|
|
|
|
inline int64_t CreationTime() const {
|
2019-05-31 09:31:47 +00:00
|
|
|
return mData.creationTime();
|
2012-08-22 15:56:38 +00:00
|
|
|
} // in microseconds
|
2019-05-31 09:31:47 +00:00
|
|
|
inline bool IsSession() const { return mData.isSession(); }
|
|
|
|
inline bool IsDomain() const { return *mData.host().get() == '.'; }
|
|
|
|
inline bool IsSecure() const { return mData.isSecure(); }
|
|
|
|
inline bool IsHttpOnly() const { return mData.isHttpOnly(); }
|
2017-04-13 08:50:52 +00:00
|
|
|
inline const OriginAttributes& OriginAttributesRef() const {
|
|
|
|
return mOriginAttributes;
|
|
|
|
}
|
2019-05-31 09:31:47 +00:00
|
|
|
inline int32_t SameSite() const { return mData.sameSite(); }
|
2019-06-05 12:19:54 +00:00
|
|
|
inline int32_t RawSameSite() const { return mData.rawSameSite(); }
|
2020-06-02 13:48:28 +00:00
|
|
|
inline uint8_t SchemeMap() const { return mData.schemeMap(); }
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2003-10-16 13:17:12 +00:00
|
|
|
// setters
|
2019-05-31 09:31:47 +00:00
|
|
|
inline void SetExpiry(int64_t aExpiry) { mData.expiry() = aExpiry; }
|
|
|
|
inline void SetLastAccessed(int64_t aTime) { mData.lastAccessed() = aTime; }
|
|
|
|
inline void SetIsSession(bool aIsSession) { mData.isSession() = aIsSession; }
|
2020-04-22 21:01:37 +00:00
|
|
|
inline bool SetIsHttpOnly(bool aIsHttpOnly) {
|
|
|
|
return mData.isHttpOnly() = aIsHttpOnly;
|
|
|
|
}
|
2010-10-20 00:24:52 +00:00
|
|
|
// Set the creation time manually, overriding the monotonicity checks in
|
|
|
|
// Create(). Use with caution!
|
2019-05-31 09:31:47 +00:00
|
|
|
inline void SetCreationTime(int64_t aTime) { mData.creationTime() = aTime; }
|
2020-06-02 13:48:54 +00:00
|
|
|
inline void SetSchemeMap(uint8_t aSchemeMap) {
|
|
|
|
mData.schemeMap() = aSchemeMap;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-07-09 01:25:50 +00:00
|
|
|
bool IsStale() const;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2020-04-06 12:33:45 +00:00
|
|
|
const CookieStruct& ToIPC() const { return mData; }
|
2019-05-31 09:31:47 +00:00
|
|
|
|
2020-04-22 21:01:37 +00:00
|
|
|
already_AddRefed<Cookie> Clone() const;
|
|
|
|
|
2003-10-10 23:09:18 +00:00
|
|
|
protected:
|
2020-04-06 12:22:01 +00:00
|
|
|
virtual ~Cookie() = default;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-02-21 06:22:35 +00:00
|
|
|
private:
|
2003-10-10 23:09:18 +00:00
|
|
|
// member variables
|
2013-12-03 21:58:41 +00:00
|
|
|
//
|
|
|
|
// Please update SizeOfIncludingThis if this strategy changes.
|
2020-04-06 12:33:45 +00:00
|
|
|
CookieStruct mData;
|
|
|
|
OriginAttributes mOriginAttributes;
|
2019-09-24 14:33:59 +00:00
|
|
|
nsCString mFilePathCache;
|
2003-10-10 23:09:18 +00:00
|
|
|
};
|
|
|
|
|
2017-08-03 11:00:41 +00:00
|
|
|
// Comparator class for sorting cookies before sending to a server.
|
|
|
|
class CompareCookiesForSending {
|
|
|
|
public:
|
2020-04-06 12:22:01 +00:00
|
|
|
bool Equals(const Cookie* aCookie1, const Cookie* aCookie2) const {
|
2017-08-03 11:00:41 +00:00
|
|
|
return aCookie1->CreationTime() == aCookie2->CreationTime() &&
|
|
|
|
aCookie2->Path().Length() == aCookie1->Path().Length();
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:22:01 +00:00
|
|
|
bool LessThan(const Cookie* aCookie1, const Cookie* aCookie2) const {
|
2017-08-03 11:00:41 +00:00
|
|
|
// compare by cookie path length in accordance with RFC2109
|
|
|
|
int32_t result = aCookie2->Path().Length() - aCookie1->Path().Length();
|
|
|
|
if (result != 0) return result < 0;
|
|
|
|
|
|
|
|
// when path lengths match, older cookies should be listed first. this is
|
|
|
|
// required for backwards compatibility since some websites erroneously
|
|
|
|
// depend on receiving cookies in the order in which they were sent to the
|
|
|
|
// browser! see bug 236772.
|
|
|
|
return aCookie1->CreationTime() < aCookie2->CreationTime();
|
|
|
|
}
|
|
|
|
};
|
2020-04-06 12:22:01 +00:00
|
|
|
|
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_net_Cookie_h
|