|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set sw=2 ts=8 et 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 "nsIWebSocketChannel.h" |
|
11 |
|
12 namespace IPC { |
|
13 |
|
14 SerializedLoadContext::SerializedLoadContext(nsILoadContext* aLoadContext) |
|
15 { |
|
16 Init(aLoadContext); |
|
17 } |
|
18 |
|
19 SerializedLoadContext::SerializedLoadContext(nsIChannel* aChannel) |
|
20 { |
|
21 if (!aChannel) { |
|
22 Init(nullptr); |
|
23 return; |
|
24 } |
|
25 |
|
26 nsCOMPtr<nsILoadContext> loadContext; |
|
27 NS_QueryNotificationCallbacks(aChannel, loadContext); |
|
28 Init(loadContext); |
|
29 |
|
30 if (!loadContext) { |
|
31 // Attempt to retrieve the private bit from the channel if it has been |
|
32 // overriden. |
|
33 bool isPrivate = false; |
|
34 bool isOverriden = false; |
|
35 nsCOMPtr<nsIPrivateBrowsingChannel> pbChannel = do_QueryInterface(aChannel); |
|
36 if (pbChannel && |
|
37 NS_SUCCEEDED(pbChannel->IsPrivateModeOverriden(&isPrivate, &isOverriden)) && |
|
38 isOverriden) { |
|
39 mUsePrivateBrowsing = isPrivate; |
|
40 mIsPrivateBitValid = true; |
|
41 } |
|
42 } |
|
43 } |
|
44 |
|
45 SerializedLoadContext::SerializedLoadContext(nsIWebSocketChannel* aChannel) |
|
46 { |
|
47 nsCOMPtr<nsILoadContext> loadContext; |
|
48 if (aChannel) { |
|
49 NS_QueryNotificationCallbacks(aChannel, loadContext); |
|
50 } |
|
51 Init(loadContext); |
|
52 } |
|
53 |
|
54 void |
|
55 SerializedLoadContext::Init(nsILoadContext* aLoadContext) |
|
56 { |
|
57 if (aLoadContext) { |
|
58 mIsNotNull = true; |
|
59 mIsPrivateBitValid = true; |
|
60 aLoadContext->GetIsContent(&mIsContent); |
|
61 aLoadContext->GetUsePrivateBrowsing(&mUsePrivateBrowsing); |
|
62 aLoadContext->GetUseRemoteTabs(&mUseRemoteTabs); |
|
63 aLoadContext->GetAppId(&mAppId); |
|
64 aLoadContext->GetIsInBrowserElement(&mIsInBrowserElement); |
|
65 } else { |
|
66 mIsNotNull = false; |
|
67 mIsPrivateBitValid = false; |
|
68 // none of below values really matter when mIsNotNull == false: |
|
69 // we won't be GetInterfaced to nsILoadContext |
|
70 mIsContent = true; |
|
71 mUsePrivateBrowsing = false; |
|
72 mUseRemoteTabs = false; |
|
73 mAppId = 0; |
|
74 mIsInBrowserElement = false; |
|
75 } |
|
76 } |
|
77 |
|
78 } // namespace IPC |
|
79 |