netwerk/cookie/nsCookie.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
child 4
fc2d59ddac77
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsCookie_h__
michael@0 7 #define nsCookie_h__
michael@0 8
michael@0 9 #include "nsICookie.h"
michael@0 10 #include "nsICookie2.h"
michael@0 11 #include "nsString.h"
michael@0 12
michael@0 13 #include "mozilla/MemoryReporting.h"
michael@0 14
michael@0 15 /**
michael@0 16 * The nsCookie class is the main cookie storage medium for use within cookie
michael@0 17 * code. It implements nsICookie2, which extends nsICookie, a frozen interface
michael@0 18 * for xpcom access of cookie objects.
michael@0 19 */
michael@0 20
michael@0 21 /******************************************************************************
michael@0 22 * nsCookie:
michael@0 23 * implementation
michael@0 24 ******************************************************************************/
michael@0 25
michael@0 26 class nsCookie : public nsICookie2
michael@0 27 {
michael@0 28 public:
michael@0 29 // nsISupports
michael@0 30 NS_DECL_ISUPPORTS
michael@0 31 NS_DECL_NSICOOKIE
michael@0 32 NS_DECL_NSICOOKIE2
michael@0 33
michael@0 34 private:
michael@0 35 // for internal use only. see nsCookie::Create().
michael@0 36 nsCookie(const char *aName,
michael@0 37 const char *aValue,
michael@0 38 const char *aHost,
michael@0 39 const char *aPath,
michael@0 40 const char *aEnd,
michael@0 41 int64_t aExpiry,
michael@0 42 int64_t aLastAccessed,
michael@0 43 int64_t aCreationTime,
michael@0 44 bool aIsSession,
michael@0 45 bool aIsSecure,
michael@0 46 bool aIsHttpOnly)
michael@0 47 : mName(aName)
michael@0 48 , mValue(aValue)
michael@0 49 , mHost(aHost)
michael@0 50 , mPath(aPath)
michael@0 51 , mEnd(aEnd)
michael@0 52 , mExpiry(aExpiry)
michael@0 53 , mLastAccessed(aLastAccessed)
michael@0 54 , mCreationTime(aCreationTime)
michael@0 55 , mIsSession(aIsSession != false)
michael@0 56 , mIsSecure(aIsSecure != false)
michael@0 57 , mIsHttpOnly(aIsHttpOnly != false)
michael@0 58 {
michael@0 59 }
michael@0 60
michael@0 61 public:
michael@0 62 // Generate a unique and monotonically increasing creation time. See comment
michael@0 63 // in nsCookie.cpp.
michael@0 64 static int64_t GenerateUniqueCreationTime(int64_t aCreationTime);
michael@0 65
michael@0 66 // public helper to create an nsCookie object. use |operator delete|
michael@0 67 // to destroy an object created by this method.
michael@0 68 static nsCookie * Create(const nsACString &aName,
michael@0 69 const nsACString &aValue,
michael@0 70 const nsACString &aHost,
michael@0 71 const nsACString &aPath,
michael@0 72 int64_t aExpiry,
michael@0 73 int64_t aLastAccessed,
michael@0 74 int64_t aCreationTime,
michael@0 75 bool aIsSession,
michael@0 76 bool aIsSecure,
michael@0 77 bool aIsHttpOnly);
michael@0 78
michael@0 79 virtual ~nsCookie() {}
michael@0 80
michael@0 81 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
michael@0 82
michael@0 83 // fast (inline, non-xpcom) getters
michael@0 84 inline const nsDependentCString Name() const { return nsDependentCString(mName, mValue - 1); }
michael@0 85 inline const nsDependentCString Value() const { return nsDependentCString(mValue, mHost - 1); }
michael@0 86 inline const nsDependentCString Host() const { return nsDependentCString(mHost, mPath - 1); }
michael@0 87 inline const nsDependentCString RawHost() const { return nsDependentCString(IsDomain() ? mHost + 1 : mHost, mPath - 1); }
michael@0 88 inline const nsDependentCString Path() const { return nsDependentCString(mPath, mEnd); }
michael@0 89 inline int64_t Expiry() const { return mExpiry; } // in seconds
michael@0 90 inline int64_t LastAccessed() const { return mLastAccessed; } // in microseconds
michael@0 91 inline int64_t CreationTime() const { return mCreationTime; } // in microseconds
michael@0 92 inline bool IsSession() const { return mIsSession; }
michael@0 93 inline bool IsDomain() const { return *mHost == '.'; }
michael@0 94 inline bool IsSecure() const { return mIsSecure; }
michael@0 95 inline bool IsHttpOnly() const { return mIsHttpOnly; }
michael@0 96
michael@0 97 // setters
michael@0 98 inline void SetExpiry(int64_t aExpiry) { mExpiry = aExpiry; }
michael@0 99 inline void SetLastAccessed(int64_t aTime) { mLastAccessed = aTime; }
michael@0 100 inline void SetIsSession(bool aIsSession) { mIsSession = (bool) aIsSession; }
michael@0 101 // Set the creation time manually, overriding the monotonicity checks in
michael@0 102 // Create(). Use with caution!
michael@0 103 inline void SetCreationTime(int64_t aTime) { mCreationTime = aTime; }
michael@0 104
michael@0 105 protected:
michael@0 106 // member variables
michael@0 107 // we use char* ptrs to store the strings in a contiguous block,
michael@0 108 // so we save on the overhead of using nsCStrings. However, we
michael@0 109 // store a terminating null for each string, so we can hand them
michael@0 110 // out as nsAFlatCStrings.
michael@0 111 //
michael@0 112 // Please update SizeOfIncludingThis if this strategy changes.
michael@0 113 const char *mName;
michael@0 114 const char *mValue;
michael@0 115 const char *mHost;
michael@0 116 const char *mPath;
michael@0 117 const char *mEnd;
michael@0 118 int64_t mExpiry;
michael@0 119 int64_t mLastAccessed;
michael@0 120 int64_t mCreationTime;
michael@0 121 bool mIsSession;
michael@0 122 bool mIsSecure;
michael@0 123 bool mIsHttpOnly;
michael@0 124 };
michael@0 125
michael@0 126 #endif // nsCookie_h__

mercurial