Source code

Revision control

Other Tools

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 "nsIPrivateBrowsingChannel.h"
11
#include "nsIWebSocketChannel.h"
12
13
namespace IPC {
14
15
SerializedLoadContext::SerializedLoadContext(nsILoadContext* aLoadContext)
16
: mIsContent(false),
17
mUseRemoteTabs(false),
18
mUseRemoteSubframes(false),
19
mUseTrackingProtection(false) {
20
Init(aLoadContext);
21
}
22
23
SerializedLoadContext::SerializedLoadContext(nsIChannel* aChannel)
24
: mIsContent(false),
25
mUseRemoteTabs(false),
26
mUseRemoteSubframes(false),
27
mUseTrackingProtection(false) {
28
if (!aChannel) {
29
Init(nullptr);
30
return;
31
}
32
33
nsCOMPtr<nsILoadContext> loadContext;
34
NS_QueryNotificationCallbacks(aChannel, loadContext);
35
Init(loadContext);
36
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(
45
pbChannel->IsPrivateModeOverriden(&isPrivate, &isOverriden)) &&
46
isOverriden) {
47
mIsPrivateBitValid = true;
48
}
49
mOriginAttributes.SyncAttributesWithPrivateBrowsing(isPrivate);
50
}
51
}
52
53
SerializedLoadContext::SerializedLoadContext(nsIWebSocketChannel* aChannel)
54
: mIsContent(false),
55
mUseRemoteTabs(false),
56
mUseRemoteSubframes(false),
57
mUseTrackingProtection(false) {
58
nsCOMPtr<nsILoadContext> loadContext;
59
if (aChannel) {
60
NS_QueryNotificationCallbacks(aChannel, loadContext);
61
}
62
Init(loadContext);
63
}
64
65
void SerializedLoadContext::Init(nsILoadContext* aLoadContext) {
66
if (aLoadContext) {
67
mIsNotNull = true;
68
mIsPrivateBitValid = true;
69
aLoadContext->GetIsContent(&mIsContent);
70
aLoadContext->GetUseRemoteTabs(&mUseRemoteTabs);
71
aLoadContext->GetUseRemoteSubframes(&mUseRemoteSubframes);
72
aLoadContext->GetUseTrackingProtection(&mUseTrackingProtection);
73
aLoadContext->GetOriginAttributes(mOriginAttributes);
74
} else {
75
mIsNotNull = false;
76
mIsPrivateBitValid = false;
77
// none of below values really matter when mIsNotNull == false:
78
// we won't be GetInterfaced to nsILoadContext
79
mIsContent = true;
80
mUseRemoteTabs = false;
81
mUseRemoteSubframes = false;
82
mUseTrackingProtection = false;
83
}
84
}
85
86
} // namespace IPC