DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Header

Mercurial (4a108e94d3e2)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
/* 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/. */

#include "LoadContextInfo.h"

#include "nsNetUtil.h"
#include "nsIChannel.h"
#include "nsILoadContext.h"

namespace mozilla {
namespace net {

NS_IMPL_ISUPPORTS(LoadContextInfo, nsILoadContextInfo)

LoadContextInfo::LoadContextInfo(bool aIsPrivate, uint32_t aAppId, bool aIsInBrowser, bool aIsAnonymous)
  : mAppId(aAppId)
  , mIsPrivate(aIsPrivate)
  , mIsInBrowser(aIsInBrowser)
  , mIsAnonymous(aIsAnonymous)
{
}

LoadContextInfo::~LoadContextInfo()
{
}

NS_IMETHODIMP LoadContextInfo::GetIsPrivate(bool *aIsPrivate)
{
  *aIsPrivate = mIsPrivate;
  return NS_OK;
}

NS_IMETHODIMP LoadContextInfo::GetAppId(uint32_t *aAppId)
{
  *aAppId = mAppId;
  return NS_OK;
}

NS_IMETHODIMP LoadContextInfo::GetIsInBrowserElement(bool *aIsInBrowser)
{
  *aIsInBrowser = mIsInBrowser;
  return NS_OK;
}

NS_IMETHODIMP LoadContextInfo::GetIsAnonymous(bool *aIsAnonymous)
{
  *aIsAnonymous = mIsAnonymous;
  return NS_OK;
}

LoadContextInfo *
GetLoadContextInfo(nsIChannel * aChannel)
{
  bool pb = NS_UsePrivateBrowsing(aChannel);
  uint32_t appId;
  bool ib;
  if (!NS_GetAppInfo(aChannel, &appId, &ib)) {
    appId = nsILoadContextInfo::NO_APP_ID;
    ib = false;
  }

  bool anon = false;
  nsLoadFlags loadFlags;
  nsresult rv = aChannel->GetLoadFlags(&loadFlags);
  if (NS_SUCCEEDED(rv))
    anon = !!(loadFlags & nsIChannel::LOAD_ANONYMOUS);

  return new LoadContextInfo(pb, appId, ib, anon);
}

LoadContextInfo *
GetLoadContextInfo(nsILoadContext * aLoadContext, bool aIsAnonymous)
{
  if (!aLoadContext)
    return new LoadContextInfo(false, nsILoadContextInfo::NO_APP_ID, false, aIsAnonymous); // nullptr?

  bool pb = aLoadContext->UsePrivateBrowsing();

  bool ib;
  nsresult rv = aLoadContext->GetIsInBrowserElement(&ib);
  if (NS_FAILED(rv))
    ib = false; // todo NS_WARNING...

  uint32_t appId;
  rv = aLoadContext->GetAppId(&appId);
  if (NS_FAILED(rv))
    appId = nsILoadContextInfo::NO_APP_ID;

  return new LoadContextInfo(pb, appId, ib, aIsAnonymous);
}

LoadContextInfo *
GetLoadContextInfo(nsILoadContextInfo* aInfo)
{
  return new LoadContextInfo(aInfo->IsPrivate(),
                             aInfo->AppId(),
                             aInfo->IsInBrowserElement(),
                             aInfo->IsAnonymous());
}

LoadContextInfo *
GetLoadContextInfo(bool const aIsPrivate,
                   uint32_t const aAppId,
                   bool const aIsInBrowserElement,
                   bool const aIsAnonymous)
{
  return new LoadContextInfo(aIsPrivate,
                             aAppId,
                             aIsInBrowserElement,
                             aIsAnonymous);
}

} // net
} // mozilla