Bug 1861709 replace AudioCallbackDriver::ThreadRunning() assertions that mean to...
[gecko.git] / docshell / base / SerializedLoadContext.cpp
blobcb598b43fef3b6c4f6f5de28c3e6c510fed64a81
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/. */
7 #include "SerializedLoadContext.h"
8 #include "nsNetUtil.h"
9 #include "nsIChannel.h"
10 #include "nsILoadContext.h"
11 #include "nsIPrivateBrowsingChannel.h"
12 #include "nsIWebSocketChannel.h"
14 namespace IPC {
16 SerializedLoadContext::SerializedLoadContext(nsILoadContext* aLoadContext)
17 : mIsContent(false),
18 mUseRemoteTabs(false),
19 mUseRemoteSubframes(false),
20 mUseTrackingProtection(false) {
21 Init(aLoadContext);
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;
34 nsCOMPtr<nsILoadContext> loadContext;
35 NS_QueryNotificationCallbacks(aChannel, loadContext);
36 Init(loadContext);
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;
50 mOriginAttributes.SyncAttributesWithPrivateBrowsing(isPrivate);
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);
63 Init(loadContext);
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;
87 } // namespace IPC