michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "LoadContextInfo.h" michael@0: michael@0: #include "nsNetUtil.h" michael@0: #include "nsIChannel.h" michael@0: #include "nsILoadContext.h" michael@0: michael@0: namespace mozilla { michael@0: namespace net { michael@0: michael@0: NS_IMPL_ISUPPORTS(LoadContextInfo, nsILoadContextInfo) michael@0: michael@0: LoadContextInfo::LoadContextInfo(bool aIsPrivate, uint32_t aAppId, bool aIsInBrowser, bool aIsAnonymous) michael@0: : mAppId(aAppId) michael@0: , mIsPrivate(aIsPrivate) michael@0: , mIsInBrowser(aIsInBrowser) michael@0: , mIsAnonymous(aIsAnonymous) michael@0: { michael@0: } michael@0: michael@0: LoadContextInfo::~LoadContextInfo() michael@0: { michael@0: } michael@0: michael@0: NS_IMETHODIMP LoadContextInfo::GetIsPrivate(bool *aIsPrivate) michael@0: { michael@0: *aIsPrivate = mIsPrivate; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP LoadContextInfo::GetAppId(uint32_t *aAppId) michael@0: { michael@0: *aAppId = mAppId; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP LoadContextInfo::GetIsInBrowserElement(bool *aIsInBrowser) michael@0: { michael@0: *aIsInBrowser = mIsInBrowser; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP LoadContextInfo::GetIsAnonymous(bool *aIsAnonymous) michael@0: { michael@0: *aIsAnonymous = mIsAnonymous; michael@0: return NS_OK; michael@0: } michael@0: michael@0: LoadContextInfo * michael@0: GetLoadContextInfo(nsIChannel * aChannel) michael@0: { michael@0: bool pb = NS_UsePrivateBrowsing(aChannel); michael@0: uint32_t appId; michael@0: bool ib; michael@0: if (!NS_GetAppInfo(aChannel, &appId, &ib)) { michael@0: appId = nsILoadContextInfo::NO_APP_ID; michael@0: ib = false; michael@0: } michael@0: michael@0: bool anon = false; michael@0: nsLoadFlags loadFlags; michael@0: nsresult rv = aChannel->GetLoadFlags(&loadFlags); michael@0: if (NS_SUCCEEDED(rv)) michael@0: anon = !!(loadFlags & nsIChannel::LOAD_ANONYMOUS); michael@0: michael@0: return new LoadContextInfo(pb, appId, ib, anon); michael@0: } michael@0: michael@0: LoadContextInfo * michael@0: GetLoadContextInfo(nsILoadContext * aLoadContext, bool aIsAnonymous) michael@0: { michael@0: if (!aLoadContext) michael@0: return new LoadContextInfo(false, nsILoadContextInfo::NO_APP_ID, false, aIsAnonymous); // nullptr? michael@0: michael@0: bool pb = aLoadContext->UsePrivateBrowsing(); michael@0: michael@0: bool ib; michael@0: nsresult rv = aLoadContext->GetIsInBrowserElement(&ib); michael@0: if (NS_FAILED(rv)) michael@0: ib = false; // todo NS_WARNING... michael@0: michael@0: uint32_t appId; michael@0: rv = aLoadContext->GetAppId(&appId); michael@0: if (NS_FAILED(rv)) michael@0: appId = nsILoadContextInfo::NO_APP_ID; michael@0: michael@0: return new LoadContextInfo(pb, appId, ib, aIsAnonymous); michael@0: } michael@0: michael@0: LoadContextInfo * michael@0: GetLoadContextInfo(nsILoadContextInfo* aInfo) michael@0: { michael@0: return new LoadContextInfo(aInfo->IsPrivate(), michael@0: aInfo->AppId(), michael@0: aInfo->IsInBrowserElement(), michael@0: aInfo->IsAnonymous()); michael@0: } michael@0: michael@0: LoadContextInfo * michael@0: GetLoadContextInfo(bool const aIsPrivate, michael@0: uint32_t const aAppId, michael@0: bool const aIsInBrowserElement, michael@0: bool const aIsAnonymous) michael@0: { michael@0: return new LoadContextInfo(aIsPrivate, michael@0: aAppId, michael@0: aIsInBrowserElement, michael@0: aIsAnonymous); michael@0: } michael@0: michael@0: } // net michael@0: } // mozilla