netwerk/base/src/LoadContextInfo.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial