netwerk/protocol/http/PHttpChannelParams.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set sw=2 ts=8 et tw=80 : */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #ifndef mozilla_net_PHttpChannelParams_h
     8 #define mozilla_net_PHttpChannelParams_h
    10 #define ALLOW_LATE_NSHTTP_H_INCLUDE 1
    11 #include "base/basictypes.h"
    13 #include "ipc/IPCMessageUtils.h"
    14 #include "nsHttp.h"
    15 #include "nsHttpHeaderArray.h"
    16 #include "nsHttpResponseHead.h"
    18 #include "nsIClassInfo.h"
    19 #include "nsNetUtil.h"
    21 namespace mozilla {
    22 namespace net {
    24 struct RequestHeaderTuple {
    25   nsCString mHeader;
    26   nsCString mValue;
    27   bool      mMerge;
    29   bool operator ==(const RequestHeaderTuple &other) const {
    30     return mHeader.Equals(other.mHeader) &&
    31            mValue.Equals(other.mValue) &&
    32            mMerge == other.mMerge;
    33   }
    34 };
    36 typedef nsTArray<RequestHeaderTuple> RequestHeaderTuples;
    38 } // namespace net
    39 } // namespace mozilla
    41 namespace IPC {
    43 template<>
    44 struct ParamTraits<mozilla::net::RequestHeaderTuple>
    45 {
    46   typedef mozilla::net::RequestHeaderTuple paramType;
    48   static void Write(Message* aMsg, const paramType& aParam)
    49   {
    50     WriteParam(aMsg, aParam.mHeader);
    51     WriteParam(aMsg, aParam.mValue);
    52     WriteParam(aMsg, aParam.mMerge);
    53   }
    55   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
    56   {
    57     if (!ReadParam(aMsg, aIter, &aResult->mHeader) ||
    58         !ReadParam(aMsg, aIter, &aResult->mValue)  ||
    59         !ReadParam(aMsg, aIter, &aResult->mMerge))
    60       return false;
    62     return true;
    63   }
    64 };
    66 template<>
    67 struct ParamTraits<mozilla::net::nsHttpAtom>
    68 {
    69   typedef mozilla::net::nsHttpAtom paramType;
    71   static void Write(Message* aMsg, const paramType& aParam)
    72   {
    73     // aParam.get() cannot be null.
    74     MOZ_ASSERT(aParam.get(), "null nsHTTPAtom value");
    75     nsAutoCString value(aParam.get());
    76     WriteParam(aMsg, value);
    77   }
    79   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
    80   {
    81     nsAutoCString value;
    82     if (!ReadParam(aMsg, aIter, &value))
    83       return false;
    85     *aResult = mozilla::net::nsHttp::ResolveAtom(value.get());
    86     MOZ_ASSERT(aResult->get(), "atom table not initialized");
    87     return true;
    88   }
    89 };
    91 template<>
    92 struct ParamTraits<mozilla::net::nsHttpHeaderArray::nsEntry>
    93 {
    94   typedef mozilla::net::nsHttpHeaderArray::nsEntry paramType;
    96   static void Write(Message* aMsg, const paramType& aParam)
    97   {
    98     WriteParam(aMsg, aParam.header);
    99     WriteParam(aMsg, aParam.value);
   100   }
   102   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   103   {
   104     if (!ReadParam(aMsg, aIter, &aResult->header) ||
   105         !ReadParam(aMsg, aIter, &aResult->value))
   106       return false;
   108     return true;
   109   }
   110 };
   113 template<>
   114 struct ParamTraits<mozilla::net::nsHttpHeaderArray>
   115 {
   116   typedef mozilla::net::nsHttpHeaderArray paramType;
   118   static void Write(Message* aMsg, const paramType& aParam)
   119   {
   120     paramType& p = const_cast<paramType&>(aParam);
   122     WriteParam(aMsg, p.mHeaders);
   123   }
   125   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   126   {
   127     if (!ReadParam(aMsg, aIter, &aResult->mHeaders))
   128       return false;
   130     return true;
   131   }
   132 };
   134 template<>
   135 struct ParamTraits<mozilla::net::nsHttpResponseHead>
   136 {
   137   typedef mozilla::net::nsHttpResponseHead paramType;
   139   static void Write(Message* aMsg, const paramType& aParam)
   140   {
   141     WriteParam(aMsg, aParam.mHeaders);
   142     WriteParam(aMsg, aParam.mVersion);
   143     WriteParam(aMsg, aParam.mStatus);
   144     WriteParam(aMsg, aParam.mStatusText);
   145     WriteParam(aMsg, aParam.mContentLength);
   146     WriteParam(aMsg, aParam.mContentType);
   147     WriteParam(aMsg, aParam.mContentCharset);
   148     WriteParam(aMsg, aParam.mCacheControlNoStore);
   149     WriteParam(aMsg, aParam.mCacheControlNoCache);
   150     WriteParam(aMsg, aParam.mPragmaNoCache);
   151   }
   153   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   154   {
   155     if (!ReadParam(aMsg, aIter, &aResult->mHeaders)             ||
   156         !ReadParam(aMsg, aIter, &aResult->mVersion)             ||
   157         !ReadParam(aMsg, aIter, &aResult->mStatus)              ||
   158         !ReadParam(aMsg, aIter, &aResult->mStatusText)          ||
   159         !ReadParam(aMsg, aIter, &aResult->mContentLength)       ||
   160         !ReadParam(aMsg, aIter, &aResult->mContentType)         ||
   161         !ReadParam(aMsg, aIter, &aResult->mContentCharset)      ||
   162         !ReadParam(aMsg, aIter, &aResult->mCacheControlNoStore) ||
   163         !ReadParam(aMsg, aIter, &aResult->mCacheControlNoCache) ||
   164         !ReadParam(aMsg, aIter, &aResult->mPragmaNoCache))
   165       return false;
   167     return true;
   168   }
   169 };
   171 } // namespace IPC
   173 #endif // mozilla_net_PHttpChannelParams_h

mercurial