/src/mozilla-central/docshell/base/SerializedLoadContext.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | , mUseTrackingProtection(false) |
19 | 0 | { |
20 | 0 | Init(aLoadContext); |
21 | 0 | } |
22 | | |
23 | | SerializedLoadContext::SerializedLoadContext(nsIChannel* aChannel) |
24 | | : mIsContent(false) |
25 | | , mUseRemoteTabs(false) |
26 | | , mUseTrackingProtection(false) |
27 | 0 | { |
28 | 0 | if (!aChannel) { |
29 | 0 | Init(nullptr); |
30 | 0 | return; |
31 | 0 | } |
32 | 0 | |
33 | 0 | nsCOMPtr<nsILoadContext> loadContext; |
34 | 0 | NS_QueryNotificationCallbacks(aChannel, loadContext); |
35 | 0 | Init(loadContext); |
36 | 0 |
|
37 | 0 | if (!loadContext) { |
38 | 0 | // Attempt to retrieve the private bit from the channel if it has been |
39 | 0 | // overriden. |
40 | 0 | bool isPrivate = false; |
41 | 0 | bool isOverriden = false; |
42 | 0 | nsCOMPtr<nsIPrivateBrowsingChannel> pbChannel = do_QueryInterface(aChannel); |
43 | 0 | if (pbChannel && |
44 | 0 | NS_SUCCEEDED(pbChannel->IsPrivateModeOverriden(&isPrivate, |
45 | 0 | &isOverriden)) && |
46 | 0 | isOverriden) { |
47 | 0 | mIsPrivateBitValid = true; |
48 | 0 | } |
49 | 0 | mOriginAttributes.SyncAttributesWithPrivateBrowsing(isPrivate); |
50 | 0 | } |
51 | 0 | } |
52 | | |
53 | | SerializedLoadContext::SerializedLoadContext(nsIWebSocketChannel* aChannel) |
54 | | : mIsContent(false) |
55 | | , mUseRemoteTabs(false) |
56 | | , mUseTrackingProtection(false) |
57 | 0 | { |
58 | 0 | nsCOMPtr<nsILoadContext> loadContext; |
59 | 0 | if (aChannel) { |
60 | 0 | NS_QueryNotificationCallbacks(aChannel, loadContext); |
61 | 0 | } |
62 | 0 | Init(loadContext); |
63 | 0 | } |
64 | | |
65 | | void |
66 | | SerializedLoadContext::Init(nsILoadContext* aLoadContext) |
67 | 0 | { |
68 | 0 | if (aLoadContext) { |
69 | 0 | mIsNotNull = true; |
70 | 0 | mIsPrivateBitValid = true; |
71 | 0 | aLoadContext->GetIsContent(&mIsContent); |
72 | 0 | aLoadContext->GetUseRemoteTabs(&mUseRemoteTabs); |
73 | 0 | aLoadContext->GetUseTrackingProtection(&mUseTrackingProtection); |
74 | 0 | aLoadContext->GetOriginAttributes(mOriginAttributes); |
75 | 0 | } else { |
76 | 0 | mIsNotNull = false; |
77 | 0 | mIsPrivateBitValid = false; |
78 | 0 | // none of below values really matter when mIsNotNull == false: |
79 | 0 | // we won't be GetInterfaced to nsILoadContext |
80 | 0 | mIsContent = true; |
81 | 0 | mUseRemoteTabs = false; |
82 | 0 | mUseTrackingProtection = false; |
83 | 0 | } |
84 | 0 | } |
85 | | |
86 | | } // namespace IPC |