SerializedLoadContext.cpp (2737B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "SerializedLoadContext.h" 8 #include "nsNetUtil.h" 9 #include "nsIChannel.h" 10 #include "nsILoadContext.h" 11 #include "nsIPrivateBrowsingChannel.h" 12 #include "nsIWebSocketChannel.h" 13 14 namespace IPC { 15 16 SerializedLoadContext::SerializedLoadContext(nsILoadContext* aLoadContext) 17 : mIsContent(false), 18 mUseRemoteTabs(false), 19 mUseRemoteSubframes(false), 20 mUseTrackingProtection(false) { 21 Init(aLoadContext); 22 } 23 24 SerializedLoadContext::SerializedLoadContext(nsIChannel* aChannel) 25 : mIsContent(false), 26 mUseRemoteTabs(false), 27 mUseRemoteSubframes(false), 28 mUseTrackingProtection(false) { 29 if (!aChannel) { 30 Init(nullptr); 31 return; 32 } 33 34 nsCOMPtr<nsILoadContext> loadContext; 35 NS_QueryNotificationCallbacks(aChannel, loadContext); 36 Init(loadContext); 37 38 if (!loadContext) { 39 // Attempt to retrieve the private bit from the channel if it has been 40 // overriden. 41 bool isPrivate = false; 42 bool isOverriden = false; 43 nsCOMPtr<nsIPrivateBrowsingChannel> pbChannel = do_QueryInterface(aChannel); 44 if (pbChannel && 45 NS_SUCCEEDED( 46 pbChannel->IsPrivateModeOverriden(&isPrivate, &isOverriden)) && 47 isOverriden) { 48 mIsPrivateBitValid = true; 49 } 50 mOriginAttributes.SyncAttributesWithPrivateBrowsing(isPrivate); 51 } 52 } 53 54 SerializedLoadContext::SerializedLoadContext(nsIWebSocketChannel* aChannel) 55 : mIsContent(false), 56 mUseRemoteTabs(false), 57 mUseRemoteSubframes(false), 58 mUseTrackingProtection(false) { 59 nsCOMPtr<nsILoadContext> loadContext; 60 if (aChannel) { 61 NS_QueryNotificationCallbacks(aChannel, loadContext); 62 } 63 Init(loadContext); 64 } 65 66 void SerializedLoadContext::Init(nsILoadContext* aLoadContext) { 67 if (aLoadContext) { 68 mIsNotNull = true; 69 mIsPrivateBitValid = true; 70 aLoadContext->GetIsContent(&mIsContent); 71 aLoadContext->GetUseRemoteTabs(&mUseRemoteTabs); 72 aLoadContext->GetUseRemoteSubframes(&mUseRemoteSubframes); 73 aLoadContext->GetUseTrackingProtection(&mUseTrackingProtection); 74 aLoadContext->GetOriginAttributes(mOriginAttributes); 75 } else { 76 mIsNotNull = false; 77 mIsPrivateBitValid = false; 78 // none of below values really matter when mIsNotNull == false: 79 // we won't be GetInterfaced to nsILoadContext 80 mIsContent = true; 81 mUseRemoteTabs = false; 82 mUseRemoteSubframes = false; 83 mUseTrackingProtection = false; 84 } 85 } 86 87 } // namespace IPC