netwerk/cookie/nsCookie.h

changeset 0
6474c204b198
child 4
fc2d59ddac77
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/cookie/nsCookie.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,126 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsCookie_h__
    1.10 +#define nsCookie_h__
    1.11 +
    1.12 +#include "nsICookie.h"
    1.13 +#include "nsICookie2.h"
    1.14 +#include "nsString.h"
    1.15 +
    1.16 +#include "mozilla/MemoryReporting.h"
    1.17 +
    1.18 +/** 
    1.19 + * The nsCookie class is the main cookie storage medium for use within cookie
    1.20 + * code. It implements nsICookie2, which extends nsICookie, a frozen interface
    1.21 + * for xpcom access of cookie objects.
    1.22 + */
    1.23 +
    1.24 +/******************************************************************************
    1.25 + * nsCookie:
    1.26 + * implementation
    1.27 + ******************************************************************************/
    1.28 +
    1.29 +class nsCookie : public nsICookie2
    1.30 +{
    1.31 +  public:
    1.32 +    // nsISupports
    1.33 +    NS_DECL_ISUPPORTS
    1.34 +    NS_DECL_NSICOOKIE
    1.35 +    NS_DECL_NSICOOKIE2
    1.36 +
    1.37 +  private:
    1.38 +    // for internal use only. see nsCookie::Create().
    1.39 +    nsCookie(const char     *aName,
    1.40 +             const char     *aValue,
    1.41 +             const char     *aHost,
    1.42 +             const char     *aPath,
    1.43 +             const char     *aEnd,
    1.44 +             int64_t         aExpiry,
    1.45 +             int64_t         aLastAccessed,
    1.46 +             int64_t         aCreationTime,
    1.47 +             bool            aIsSession,
    1.48 +             bool            aIsSecure,
    1.49 +             bool            aIsHttpOnly)
    1.50 +     : mName(aName)
    1.51 +     , mValue(aValue)
    1.52 +     , mHost(aHost)
    1.53 +     , mPath(aPath)
    1.54 +     , mEnd(aEnd)
    1.55 +     , mExpiry(aExpiry)
    1.56 +     , mLastAccessed(aLastAccessed)
    1.57 +     , mCreationTime(aCreationTime)
    1.58 +     , mIsSession(aIsSession != false)
    1.59 +     , mIsSecure(aIsSecure != false)
    1.60 +     , mIsHttpOnly(aIsHttpOnly != false)
    1.61 +    {
    1.62 +    }
    1.63 +
    1.64 +  public:
    1.65 +    // Generate a unique and monotonically increasing creation time. See comment
    1.66 +    // in nsCookie.cpp.
    1.67 +    static int64_t GenerateUniqueCreationTime(int64_t aCreationTime);
    1.68 +
    1.69 +    // public helper to create an nsCookie object. use |operator delete|
    1.70 +    // to destroy an object created by this method.
    1.71 +    static nsCookie * Create(const nsACString &aName,
    1.72 +                             const nsACString &aValue,
    1.73 +                             const nsACString &aHost,
    1.74 +                             const nsACString &aPath,
    1.75 +                             int64_t           aExpiry,
    1.76 +                             int64_t           aLastAccessed,
    1.77 +                             int64_t           aCreationTime,
    1.78 +                             bool              aIsSession,
    1.79 +                             bool              aIsSecure,
    1.80 +                             bool              aIsHttpOnly);
    1.81 +
    1.82 +    virtual ~nsCookie() {}
    1.83 +
    1.84 +    size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
    1.85 +
    1.86 +    // fast (inline, non-xpcom) getters
    1.87 +    inline const nsDependentCString Name()  const { return nsDependentCString(mName, mValue - 1); }
    1.88 +    inline const nsDependentCString Value() const { return nsDependentCString(mValue, mHost - 1); }
    1.89 +    inline const nsDependentCString Host()  const { return nsDependentCString(mHost, mPath - 1); }
    1.90 +    inline const nsDependentCString RawHost() const { return nsDependentCString(IsDomain() ? mHost + 1 : mHost, mPath - 1); }
    1.91 +    inline const nsDependentCString Path()  const { return nsDependentCString(mPath, mEnd); }
    1.92 +    inline int64_t Expiry()                 const { return mExpiry; }        // in seconds
    1.93 +    inline int64_t LastAccessed()           const { return mLastAccessed; }  // in microseconds
    1.94 +    inline int64_t CreationTime()           const { return mCreationTime; }  // in microseconds
    1.95 +    inline bool IsSession()               const { return mIsSession; }
    1.96 +    inline bool IsDomain()                const { return *mHost == '.'; }
    1.97 +    inline bool IsSecure()                const { return mIsSecure; }
    1.98 +    inline bool IsHttpOnly()              const { return mIsHttpOnly; }
    1.99 +
   1.100 +    // setters
   1.101 +    inline void SetExpiry(int64_t aExpiry)        { mExpiry = aExpiry; }
   1.102 +    inline void SetLastAccessed(int64_t aTime)    { mLastAccessed = aTime; }
   1.103 +    inline void SetIsSession(bool aIsSession)   { mIsSession = (bool) aIsSession; }
   1.104 +    // Set the creation time manually, overriding the monotonicity checks in
   1.105 +    // Create(). Use with caution!
   1.106 +    inline void SetCreationTime(int64_t aTime)    { mCreationTime = aTime; }
   1.107 +
   1.108 +  protected:
   1.109 +    // member variables
   1.110 +    // we use char* ptrs to store the strings in a contiguous block,
   1.111 +    // so we save on the overhead of using nsCStrings. However, we
   1.112 +    // store a terminating null for each string, so we can hand them
   1.113 +    // out as nsAFlatCStrings.
   1.114 +    //
   1.115 +    // Please update SizeOfIncludingThis if this strategy changes.
   1.116 +    const char  *mName;
   1.117 +    const char  *mValue;
   1.118 +    const char  *mHost;
   1.119 +    const char  *mPath;
   1.120 +    const char  *mEnd;
   1.121 +    int64_t      mExpiry;
   1.122 +    int64_t      mLastAccessed;
   1.123 +    int64_t      mCreationTime;
   1.124 +    bool mIsSession;
   1.125 +    bool mIsSecure;
   1.126 +    bool mIsHttpOnly;
   1.127 +};
   1.128 +
   1.129 +#endif // nsCookie_h__

mercurial