/src/mozilla-central/netwerk/base/PrivateBrowsingChannel.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* vim:set ts=4 sts=4 sw=4 et cin: */ |
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 | | #ifndef mozilla_net_PrivateBrowsingChannel_h__ |
8 | | #define mozilla_net_PrivateBrowsingChannel_h__ |
9 | | |
10 | | #include "nsIPrivateBrowsingChannel.h" |
11 | | #include "nsCOMPtr.h" |
12 | | #include "nsILoadGroup.h" |
13 | | #include "nsILoadContext.h" |
14 | | #include "nsIInterfaceRequestorUtils.h" |
15 | | #include "nsIInterfaceRequestor.h" |
16 | | #include "nsNetUtil.h" |
17 | | #include "mozilla/Unused.h" |
18 | | |
19 | | namespace mozilla { |
20 | | namespace net { |
21 | | |
22 | | template <class Channel> |
23 | | class PrivateBrowsingChannel : public nsIPrivateBrowsingChannel |
24 | | { |
25 | | public: |
26 | | PrivateBrowsingChannel() : |
27 | | mPrivateBrowsingOverriden(false), |
28 | | mPrivateBrowsing(false) |
29 | 0 | { |
30 | 0 | } Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<nsBaseChannel>::PrivateBrowsingChannel() Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<mozilla::net::HttpBaseChannel>::PrivateBrowsingChannel() Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<mozilla::net::WyciwygChannelChild>::PrivateBrowsingChannel() Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<nsWyciwygChannel>::PrivateBrowsingChannel() Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<mozilla::dom::ExternalHelperAppParent>::PrivateBrowsingChannel() |
31 | | |
32 | | NS_IMETHOD SetPrivate(bool aPrivate) override |
33 | 0 | { |
34 | 0 | // Make sure that we don't have a load context |
35 | 0 | // This is a fatal error in debug builds, and a runtime error in release |
36 | 0 | // builds. |
37 | 0 | nsCOMPtr<nsILoadContext> loadContext; |
38 | 0 | NS_QueryNotificationCallbacks(static_cast<Channel*>(this), loadContext); |
39 | 0 | MOZ_ASSERT(!loadContext); |
40 | 0 | if (loadContext) { |
41 | 0 | return NS_ERROR_FAILURE; |
42 | 0 | } |
43 | 0 | |
44 | 0 | mPrivateBrowsingOverriden = true; |
45 | 0 | mPrivateBrowsing = aPrivate; |
46 | 0 | return NS_OK; |
47 | 0 | } Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<nsBaseChannel>::SetPrivate(bool) Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<mozilla::net::HttpBaseChannel>::SetPrivate(bool) Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<mozilla::net::WyciwygChannelChild>::SetPrivate(bool) Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<nsWyciwygChannel>::SetPrivate(bool) Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<mozilla::dom::ExternalHelperAppParent>::SetPrivate(bool) |
48 | | |
49 | | NS_IMETHOD GetIsChannelPrivate(bool *aResult) override |
50 | 0 | { |
51 | 0 | NS_ENSURE_ARG_POINTER(aResult); |
52 | 0 | *aResult = mPrivateBrowsing; |
53 | 0 | return NS_OK; |
54 | 0 | } Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<nsBaseChannel>::GetIsChannelPrivate(bool*) Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<mozilla::net::HttpBaseChannel>::GetIsChannelPrivate(bool*) Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<mozilla::net::WyciwygChannelChild>::GetIsChannelPrivate(bool*) Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<nsWyciwygChannel>::GetIsChannelPrivate(bool*) Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<mozilla::dom::ExternalHelperAppParent>::GetIsChannelPrivate(bool*) |
55 | | |
56 | | NS_IMETHOD IsPrivateModeOverriden(bool* aValue, bool *aResult) override |
57 | 0 | { |
58 | 0 | NS_ENSURE_ARG_POINTER(aValue); |
59 | 0 | NS_ENSURE_ARG_POINTER(aResult); |
60 | 0 | *aResult = mPrivateBrowsingOverriden; |
61 | 0 | if (mPrivateBrowsingOverriden) { |
62 | 0 | *aValue = mPrivateBrowsing; |
63 | 0 | } |
64 | 0 | return NS_OK; |
65 | 0 | } Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<nsBaseChannel>::IsPrivateModeOverriden(bool*, bool*) Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<mozilla::net::HttpBaseChannel>::IsPrivateModeOverriden(bool*, bool*) Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<mozilla::net::WyciwygChannelChild>::IsPrivateModeOverriden(bool*, bool*) Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<nsWyciwygChannel>::IsPrivateModeOverriden(bool*, bool*) Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<mozilla::dom::ExternalHelperAppParent>::IsPrivateModeOverriden(bool*, bool*) |
66 | | |
67 | | // Must be called every time the channel's callbacks or loadGroup is updated |
68 | | void UpdatePrivateBrowsing() |
69 | 0 | { |
70 | 0 | // once marked as private we never go un-private |
71 | 0 | if (mPrivateBrowsing) { |
72 | 0 | return; |
73 | 0 | } |
74 | 0 | |
75 | 0 | auto channel = static_cast<Channel*>(this); |
76 | 0 |
|
77 | 0 | nsCOMPtr<nsILoadContext> loadContext; |
78 | 0 | NS_QueryNotificationCallbacks(channel, loadContext); |
79 | 0 | if (loadContext) { |
80 | 0 | mPrivateBrowsing = loadContext->UsePrivateBrowsing(); |
81 | 0 | return; |
82 | 0 | } |
83 | 0 | |
84 | 0 | nsCOMPtr<nsILoadInfo> loadInfo; |
85 | 0 | Unused << channel->GetLoadInfo(getter_AddRefs(loadInfo)); |
86 | 0 | if (loadInfo) { |
87 | 0 | OriginAttributes attrs = loadInfo->GetOriginAttributes(); |
88 | 0 | mPrivateBrowsing = attrs.mPrivateBrowsingId > 0; |
89 | 0 | } |
90 | 0 | } Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<nsBaseChannel>::UpdatePrivateBrowsing() Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<mozilla::net::HttpBaseChannel>::UpdatePrivateBrowsing() Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<mozilla::net::WyciwygChannelChild>::UpdatePrivateBrowsing() Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<nsWyciwygChannel>::UpdatePrivateBrowsing() |
91 | | |
92 | | bool CanSetCallbacks(nsIInterfaceRequestor* aCallbacks) const |
93 | 0 | { |
94 | 0 | // Make sure that the private bit override flag is not set. |
95 | 0 | // This is a fatal error in debug builds, and a runtime error in release |
96 | 0 | // builds. |
97 | 0 | if (!aCallbacks) { |
98 | 0 | return true; |
99 | 0 | } |
100 | 0 | nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(aCallbacks); |
101 | 0 | if (!loadContext) { |
102 | 0 | return true; |
103 | 0 | } |
104 | 0 | MOZ_ASSERT(!mPrivateBrowsingOverriden); |
105 | 0 | return !mPrivateBrowsingOverriden; |
106 | 0 | } Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<nsBaseChannel>::CanSetCallbacks(nsIInterfaceRequestor*) const Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<mozilla::net::HttpBaseChannel>::CanSetCallbacks(nsIInterfaceRequestor*) const Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<mozilla::net::WyciwygChannelChild>::CanSetCallbacks(nsIInterfaceRequestor*) const Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<nsWyciwygChannel>::CanSetCallbacks(nsIInterfaceRequestor*) const |
107 | | |
108 | | bool CanSetLoadGroup(nsILoadGroup* aLoadGroup) const |
109 | 0 | { |
110 | 0 | // Make sure that the private bit override flag is not set. |
111 | 0 | // This is a fatal error in debug builds, and a runtime error in release |
112 | 0 | // builds. |
113 | 0 | if (!aLoadGroup) { |
114 | 0 | return true; |
115 | 0 | } |
116 | 0 | nsCOMPtr<nsIInterfaceRequestor> callbacks; |
117 | 0 | aLoadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks)); |
118 | 0 | // From this point on, we just hand off the work to CanSetCallbacks, |
119 | 0 | // because the logic is exactly the same. |
120 | 0 | return CanSetCallbacks(callbacks); |
121 | 0 | } Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<nsBaseChannel>::CanSetLoadGroup(nsILoadGroup*) const Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<mozilla::net::HttpBaseChannel>::CanSetLoadGroup(nsILoadGroup*) const Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<mozilla::net::WyciwygChannelChild>::CanSetLoadGroup(nsILoadGroup*) const Unexecuted instantiation: mozilla::net::PrivateBrowsingChannel<nsWyciwygChannel>::CanSetLoadGroup(nsILoadGroup*) const |
122 | | |
123 | | protected: |
124 | | bool mPrivateBrowsingOverriden; |
125 | | bool mPrivateBrowsing; |
126 | | }; |
127 | | |
128 | | } // namespace net |
129 | | } // namespace mozilla |
130 | | |
131 | | #endif |
132 | | |