netwerk/base/src/LoadContextInfo.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #include "LoadContextInfo.h"
     7 #include "nsNetUtil.h"
     8 #include "nsIChannel.h"
     9 #include "nsILoadContext.h"
    11 namespace mozilla {
    12 namespace net {
    14 NS_IMPL_ISUPPORTS(LoadContextInfo, nsILoadContextInfo)
    16 LoadContextInfo::LoadContextInfo(bool aIsPrivate, uint32_t aAppId, bool aIsInBrowser, bool aIsAnonymous)
    17   : mAppId(aAppId)
    18   , mIsPrivate(aIsPrivate)
    19   , mIsInBrowser(aIsInBrowser)
    20   , mIsAnonymous(aIsAnonymous)
    21 {
    22 }
    24 LoadContextInfo::~LoadContextInfo()
    25 {
    26 }
    28 NS_IMETHODIMP LoadContextInfo::GetIsPrivate(bool *aIsPrivate)
    29 {
    30   *aIsPrivate = mIsPrivate;
    31   return NS_OK;
    32 }
    34 NS_IMETHODIMP LoadContextInfo::GetAppId(uint32_t *aAppId)
    35 {
    36   *aAppId = mAppId;
    37   return NS_OK;
    38 }
    40 NS_IMETHODIMP LoadContextInfo::GetIsInBrowserElement(bool *aIsInBrowser)
    41 {
    42   *aIsInBrowser = mIsInBrowser;
    43   return NS_OK;
    44 }
    46 NS_IMETHODIMP LoadContextInfo::GetIsAnonymous(bool *aIsAnonymous)
    47 {
    48   *aIsAnonymous = mIsAnonymous;
    49   return NS_OK;
    50 }
    52 LoadContextInfo *
    53 GetLoadContextInfo(nsIChannel * aChannel)
    54 {
    55   bool pb = NS_UsePrivateBrowsing(aChannel);
    56   uint32_t appId;
    57   bool ib;
    58   if (!NS_GetAppInfo(aChannel, &appId, &ib)) {
    59     appId = nsILoadContextInfo::NO_APP_ID;
    60     ib = false;
    61   }
    63   bool anon = false;
    64   nsLoadFlags loadFlags;
    65   nsresult rv = aChannel->GetLoadFlags(&loadFlags);
    66   if (NS_SUCCEEDED(rv))
    67     anon = !!(loadFlags & nsIChannel::LOAD_ANONYMOUS);
    69   return new LoadContextInfo(pb, appId, ib, anon);
    70 }
    72 LoadContextInfo *
    73 GetLoadContextInfo(nsILoadContext * aLoadContext, bool aIsAnonymous)
    74 {
    75   if (!aLoadContext)
    76     return new LoadContextInfo(false, nsILoadContextInfo::NO_APP_ID, false, aIsAnonymous); // nullptr?
    78   bool pb = aLoadContext->UsePrivateBrowsing();
    80   bool ib;
    81   nsresult rv = aLoadContext->GetIsInBrowserElement(&ib);
    82   if (NS_FAILED(rv))
    83     ib = false; // todo NS_WARNING...
    85   uint32_t appId;
    86   rv = aLoadContext->GetAppId(&appId);
    87   if (NS_FAILED(rv))
    88     appId = nsILoadContextInfo::NO_APP_ID;
    90   return new LoadContextInfo(pb, appId, ib, aIsAnonymous);
    91 }
    93 LoadContextInfo *
    94 GetLoadContextInfo(nsILoadContextInfo* aInfo)
    95 {
    96   return new LoadContextInfo(aInfo->IsPrivate(),
    97                              aInfo->AppId(),
    98                              aInfo->IsInBrowserElement(),
    99                              aInfo->IsAnonymous());
   100 }
   102 LoadContextInfo *
   103 GetLoadContextInfo(bool const aIsPrivate,
   104                    uint32_t const aAppId,
   105                    bool const aIsInBrowserElement,
   106                    bool const aIsAnonymous)
   107 {
   108   return new LoadContextInfo(aIsPrivate,
   109                              aAppId,
   110                              aIsInBrowserElement,
   111                              aIsAnonymous);
   112 }
   114 } // net
   115 } // mozilla

mercurial