Bug 1473362 [wpt PR 11778] - Update wpt metadata, a=testonly
[gecko.git] / docshell / base / SerializedLoadContext.cpp
blob93600d469165f61623fee0a4ebeb7d1e6a610698
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 "nsIPrivateBrowsingChannel.h"
11 #include "nsIWebSocketChannel.h"
13 namespace IPC {
15 SerializedLoadContext::SerializedLoadContext(nsILoadContext* aLoadContext)
16 : mIsContent(false)
17 , mUseRemoteTabs(false)
18 , mUseTrackingProtection(false)
20 Init(aLoadContext);
23 SerializedLoadContext::SerializedLoadContext(nsIChannel* aChannel)
24 : mIsContent(false)
25 , mUseRemoteTabs(false)
26 , mUseTrackingProtection(false)
28 if (!aChannel) {
29 Init(nullptr);
30 return;
33 nsCOMPtr<nsILoadContext> loadContext;
34 NS_QueryNotificationCallbacks(aChannel, loadContext);
35 Init(loadContext);
37 if (!loadContext) {
38 // Attempt to retrieve the private bit from the channel if it has been
39 // overriden.
40 bool isPrivate = false;
41 bool isOverriden = false;
42 nsCOMPtr<nsIPrivateBrowsingChannel> pbChannel = do_QueryInterface(aChannel);
43 if (pbChannel &&
44 NS_SUCCEEDED(pbChannel->IsPrivateModeOverriden(&isPrivate,
45 &isOverriden)) &&
46 isOverriden) {
47 mIsPrivateBitValid = true;
49 mOriginAttributes.SyncAttributesWithPrivateBrowsing(isPrivate);
53 SerializedLoadContext::SerializedLoadContext(nsIWebSocketChannel* aChannel)
54 : mIsContent(false)
55 , mUseRemoteTabs(false)
56 , mUseTrackingProtection(false)
58 nsCOMPtr<nsILoadContext> loadContext;
59 if (aChannel) {
60 NS_QueryNotificationCallbacks(aChannel, loadContext);
62 Init(loadContext);
65 void
66 SerializedLoadContext::Init(nsILoadContext* aLoadContext)
68 if (aLoadContext) {
69 mIsNotNull = true;
70 mIsPrivateBitValid = true;
71 aLoadContext->GetIsContent(&mIsContent);
72 aLoadContext->GetUseRemoteTabs(&mUseRemoteTabs);
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 mUseTrackingProtection = false;
86 } // namespace IPC