michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=8 et tw=80 : */ 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 "SerializedLoadContext.h" michael@0: #include "nsNetUtil.h" michael@0: #include "nsIChannel.h" michael@0: #include "nsIWebSocketChannel.h" michael@0: michael@0: namespace IPC { michael@0: michael@0: SerializedLoadContext::SerializedLoadContext(nsILoadContext* aLoadContext) michael@0: { michael@0: Init(aLoadContext); michael@0: } michael@0: michael@0: SerializedLoadContext::SerializedLoadContext(nsIChannel* aChannel) michael@0: { michael@0: if (!aChannel) { michael@0: Init(nullptr); michael@0: return; michael@0: } michael@0: michael@0: nsCOMPtr loadContext; michael@0: NS_QueryNotificationCallbacks(aChannel, loadContext); michael@0: Init(loadContext); michael@0: michael@0: if (!loadContext) { michael@0: // Attempt to retrieve the private bit from the channel if it has been michael@0: // overriden. michael@0: bool isPrivate = false; michael@0: bool isOverriden = false; michael@0: nsCOMPtr pbChannel = do_QueryInterface(aChannel); michael@0: if (pbChannel && michael@0: NS_SUCCEEDED(pbChannel->IsPrivateModeOverriden(&isPrivate, &isOverriden)) && michael@0: isOverriden) { michael@0: mUsePrivateBrowsing = isPrivate; michael@0: mIsPrivateBitValid = true; michael@0: } michael@0: } michael@0: } michael@0: michael@0: SerializedLoadContext::SerializedLoadContext(nsIWebSocketChannel* aChannel) michael@0: { michael@0: nsCOMPtr loadContext; michael@0: if (aChannel) { michael@0: NS_QueryNotificationCallbacks(aChannel, loadContext); michael@0: } michael@0: Init(loadContext); michael@0: } michael@0: michael@0: void michael@0: SerializedLoadContext::Init(nsILoadContext* aLoadContext) michael@0: { michael@0: if (aLoadContext) { michael@0: mIsNotNull = true; michael@0: mIsPrivateBitValid = true; michael@0: aLoadContext->GetIsContent(&mIsContent); michael@0: aLoadContext->GetUsePrivateBrowsing(&mUsePrivateBrowsing); michael@0: aLoadContext->GetUseRemoteTabs(&mUseRemoteTabs); michael@0: aLoadContext->GetAppId(&mAppId); michael@0: aLoadContext->GetIsInBrowserElement(&mIsInBrowserElement); michael@0: } else { michael@0: mIsNotNull = false; michael@0: mIsPrivateBitValid = false; michael@0: // none of below values really matter when mIsNotNull == false: michael@0: // we won't be GetInterfaced to nsILoadContext michael@0: mIsContent = true; michael@0: mUsePrivateBrowsing = false; michael@0: mUseRemoteTabs = false; michael@0: mAppId = 0; michael@0: mIsInBrowserElement = false; michael@0: } michael@0: } michael@0: michael@0: } // namespace IPC michael@0: