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