2003-10-11 03:09:18 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
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 nsCookie_h__
|
|
|
|
#define nsCookie_h__
|
|
|
|
|
|
|
|
#include "nsICookie.h"
|
|
|
|
#include "nsICookie2.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
2013-12-04 01:58:41 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
|
|
|
|
2003-10-11 03:09:18 +04:00
|
|
|
/**
|
|
|
|
* The nsCookie class is the main cookie storage medium for use within cookie
|
|
|
|
* code. It implements nsICookie2, which extends nsICookie, a frozen interface
|
|
|
|
* for xpcom access of cookie objects.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* nsCookie:
|
|
|
|
* implementation
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
class nsCookie : public nsICookie2
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// nsISupports
|
2007-10-04 23:24:00 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
2003-10-11 03:09:18 +04:00
|
|
|
NS_DECL_NSICOOKIE
|
|
|
|
NS_DECL_NSICOOKIE2
|
|
|
|
|
2003-11-18 15:30:23 +03:00
|
|
|
private:
|
|
|
|
// for internal use only. see nsCookie::Create().
|
|
|
|
nsCookie(const char *aName,
|
|
|
|
const char *aValue,
|
|
|
|
const char *aHost,
|
|
|
|
const char *aPath,
|
|
|
|
const char *aEnd,
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t aExpiry,
|
|
|
|
int64_t aLastAccessed,
|
|
|
|
int64_t aCreationTime,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsSession,
|
|
|
|
bool aIsSecure,
|
|
|
|
bool aIsHttpOnly)
|
2009-12-20 02:55:56 +03:00
|
|
|
: mName(aName)
|
2003-11-18 15:30:23 +03:00
|
|
|
, mValue(aValue)
|
|
|
|
, mHost(aHost)
|
|
|
|
, mPath(aPath)
|
|
|
|
, mEnd(aEnd)
|
|
|
|
, mExpiry(aExpiry)
|
2007-11-18 11:08:34 +03:00
|
|
|
, mLastAccessed(aLastAccessed)
|
2010-10-20 04:24:52 +04:00
|
|
|
, mCreationTime(aCreationTime)
|
2011-10-17 18:59:28 +04:00
|
|
|
, mIsSession(aIsSession != false)
|
|
|
|
, mIsSecure(aIsSecure != false)
|
|
|
|
, mIsHttpOnly(aIsHttpOnly != false)
|
2003-11-18 15:30:23 +03:00
|
|
|
{
|
|
|
|
}
|
2003-10-11 03:09:18 +04:00
|
|
|
|
2003-11-18 15:30:23 +03:00
|
|
|
public:
|
2010-10-20 04:24:52 +04:00
|
|
|
// Generate a unique and monotonically increasing creation time. See comment
|
|
|
|
// in nsCookie.cpp.
|
2012-08-22 19:56:38 +04:00
|
|
|
static int64_t GenerateUniqueCreationTime(int64_t aCreationTime);
|
2010-08-03 04:03:24 +04:00
|
|
|
|
2003-11-18 15:30:23 +03:00
|
|
|
// public helper to create an nsCookie object. use |operator delete|
|
|
|
|
// to destroy an object created by this method.
|
|
|
|
static nsCookie * Create(const nsACString &aName,
|
|
|
|
const nsACString &aValue,
|
|
|
|
const nsACString &aHost,
|
|
|
|
const nsACString &aPath,
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t aExpiry,
|
|
|
|
int64_t aLastAccessed,
|
|
|
|
int64_t aCreationTime,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsSession,
|
|
|
|
bool aIsSecure,
|
|
|
|
bool aIsHttpOnly);
|
2003-11-18 15:30:23 +03:00
|
|
|
|
2007-04-23 18:21:53 +04:00
|
|
|
virtual ~nsCookie() {}
|
2003-10-11 03:09:18 +04:00
|
|
|
|
2013-12-04 01:58:41 +04:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
|
|
|
|
2003-10-11 03:09:18 +04:00
|
|
|
// fast (inline, non-xpcom) getters
|
|
|
|
inline const nsDependentCString Name() const { return nsDependentCString(mName, mValue - 1); }
|
|
|
|
inline const nsDependentCString Value() const { return nsDependentCString(mValue, mHost - 1); }
|
|
|
|
inline const nsDependentCString Host() const { return nsDependentCString(mHost, mPath - 1); }
|
2003-10-22 10:53:19 +04:00
|
|
|
inline const nsDependentCString RawHost() const { return nsDependentCString(IsDomain() ? mHost + 1 : mHost, mPath - 1); }
|
2003-10-11 03:09:18 +04:00
|
|
|
inline const nsDependentCString Path() const { return nsDependentCString(mPath, mEnd); }
|
2012-08-22 19:56:38 +04:00
|
|
|
inline int64_t Expiry() const { return mExpiry; } // in seconds
|
|
|
|
inline int64_t LastAccessed() const { return mLastAccessed; } // in microseconds
|
|
|
|
inline int64_t CreationTime() const { return mCreationTime; } // in microseconds
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool IsSession() const { return mIsSession; }
|
|
|
|
inline bool IsDomain() const { return *mHost == '.'; }
|
|
|
|
inline bool IsSecure() const { return mIsSecure; }
|
|
|
|
inline bool IsHttpOnly() const { return mIsHttpOnly; }
|
2003-10-11 03:09:18 +04:00
|
|
|
|
2003-10-16 17:17:12 +04:00
|
|
|
// setters
|
2012-08-22 19:56:38 +04:00
|
|
|
inline void SetExpiry(int64_t aExpiry) { mExpiry = aExpiry; }
|
|
|
|
inline void SetLastAccessed(int64_t aTime) { mLastAccessed = aTime; }
|
2011-09-29 10:19:26 +04:00
|
|
|
inline void SetIsSession(bool aIsSession) { mIsSession = (bool) aIsSession; }
|
2010-10-20 04:24:52 +04:00
|
|
|
// Set the creation time manually, overriding the monotonicity checks in
|
|
|
|
// Create(). Use with caution!
|
2012-08-22 19:56:38 +04:00
|
|
|
inline void SetCreationTime(int64_t aTime) { mCreationTime = aTime; }
|
2003-10-11 03:09:18 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// member variables
|
|
|
|
// we use char* ptrs to store the strings in a contiguous block,
|
|
|
|
// so we save on the overhead of using nsCStrings. However, we
|
|
|
|
// store a terminating null for each string, so we can hand them
|
|
|
|
// out as nsAFlatCStrings.
|
2013-12-04 01:58:41 +04:00
|
|
|
//
|
|
|
|
// Please update SizeOfIncludingThis if this strategy changes.
|
2007-10-04 23:24:00 +04:00
|
|
|
const char *mName;
|
|
|
|
const char *mValue;
|
|
|
|
const char *mHost;
|
|
|
|
const char *mPath;
|
|
|
|
const char *mEnd;
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t mExpiry;
|
|
|
|
int64_t mLastAccessed;
|
|
|
|
int64_t mCreationTime;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsSession;
|
|
|
|
bool mIsSecure;
|
|
|
|
bool mIsHttpOnly;
|
2003-10-11 03:09:18 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsCookie_h__
|