|
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 |
|
4 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
7 |
|
8 #ifndef mozilla_net_HttpChannelParent_h |
|
9 #define mozilla_net_HttpChannelParent_h |
|
10 |
|
11 #include "ADivertableParentChannel.h" |
|
12 #include "nsHttp.h" |
|
13 #include "mozilla/dom/PBrowserParent.h" |
|
14 #include "mozilla/net/PHttpChannelParent.h" |
|
15 #include "mozilla/net/NeckoCommon.h" |
|
16 #include "mozilla/net/NeckoParent.h" |
|
17 #include "nsIParentRedirectingChannel.h" |
|
18 #include "nsIProgressEventSink.h" |
|
19 #include "nsHttpChannel.h" |
|
20 |
|
21 class nsICacheEntry; |
|
22 class nsIAssociatedContentSecurity; |
|
23 |
|
24 namespace mozilla { |
|
25 |
|
26 namespace dom{ |
|
27 class TabParent; |
|
28 } |
|
29 |
|
30 namespace net { |
|
31 |
|
32 class HttpChannelParentListener; |
|
33 |
|
34 class HttpChannelParent : public PHttpChannelParent |
|
35 , public nsIParentRedirectingChannel |
|
36 , public nsIProgressEventSink |
|
37 , public nsIInterfaceRequestor |
|
38 , public ADivertableParentChannel |
|
39 { |
|
40 public: |
|
41 NS_DECL_ISUPPORTS |
|
42 NS_DECL_NSIREQUESTOBSERVER |
|
43 NS_DECL_NSISTREAMLISTENER |
|
44 NS_DECL_NSIPARENTCHANNEL |
|
45 NS_DECL_NSIPARENTREDIRECTINGCHANNEL |
|
46 NS_DECL_NSIPROGRESSEVENTSINK |
|
47 NS_DECL_NSIINTERFACEREQUESTOR |
|
48 |
|
49 HttpChannelParent(mozilla::dom::PBrowserParent* iframeEmbedding, |
|
50 nsILoadContext* aLoadContext, |
|
51 PBOverrideStatus aStatus); |
|
52 virtual ~HttpChannelParent(); |
|
53 |
|
54 bool Init(const HttpChannelCreationArgs& aOpenArgs); |
|
55 |
|
56 // ADivertableParentChannel functions. |
|
57 void DivertTo(nsIStreamListener *aListener) MOZ_OVERRIDE; |
|
58 nsresult SuspendForDiversion() MOZ_OVERRIDE; |
|
59 |
|
60 // Calls OnStartRequest for "DivertTo" listener, then notifies child channel |
|
61 // that it should divert OnDataAvailable and OnStopRequest calls to this |
|
62 // parent channel. |
|
63 void StartDiversion(); |
|
64 |
|
65 // Handles calling OnStart/Stop if there are errors during diversion. |
|
66 // Called asynchronously from FailDiversion. |
|
67 void NotifyDiversionFailed(nsresult aErrorCode, bool aSkipResume = true); |
|
68 |
|
69 protected: |
|
70 // used to connect redirected-to channel in parent with just created |
|
71 // ChildChannel. Used during redirects. |
|
72 bool ConnectChannel(const uint32_t& channelId); |
|
73 |
|
74 bool DoAsyncOpen(const URIParams& uri, |
|
75 const OptionalURIParams& originalUri, |
|
76 const OptionalURIParams& docUri, |
|
77 const OptionalURIParams& referrerUri, |
|
78 const OptionalURIParams& internalRedirectUri, |
|
79 const uint32_t& loadFlags, |
|
80 const RequestHeaderTuples& requestHeaders, |
|
81 const nsCString& requestMethod, |
|
82 const OptionalInputStreamParams& uploadStream, |
|
83 const bool& uploadStreamHasHeaders, |
|
84 const uint16_t& priority, |
|
85 const uint8_t& redirectionLimit, |
|
86 const bool& allowPipelining, |
|
87 const bool& forceAllowThirdPartyCookie, |
|
88 const bool& doResumeAt, |
|
89 const uint64_t& startPos, |
|
90 const nsCString& entityID, |
|
91 const bool& chooseApplicationCache, |
|
92 const nsCString& appCacheClientID, |
|
93 const bool& allowSpdy, |
|
94 const OptionalFileDescriptorSet& aFds); |
|
95 |
|
96 virtual bool RecvSetPriority(const uint16_t& priority) MOZ_OVERRIDE; |
|
97 virtual bool RecvSetCacheTokenCachedCharset(const nsCString& charset) MOZ_OVERRIDE; |
|
98 virtual bool RecvSuspend() MOZ_OVERRIDE; |
|
99 virtual bool RecvResume() MOZ_OVERRIDE; |
|
100 virtual bool RecvCancel(const nsresult& status) MOZ_OVERRIDE; |
|
101 virtual bool RecvRedirect2Verify(const nsresult& result, |
|
102 const RequestHeaderTuples& changedHeaders, |
|
103 const OptionalURIParams& apiRedirectUri) MOZ_OVERRIDE; |
|
104 virtual bool RecvUpdateAssociatedContentSecurity(const int32_t& broken, |
|
105 const int32_t& no) MOZ_OVERRIDE; |
|
106 virtual bool RecvDocumentChannelCleanup() MOZ_OVERRIDE; |
|
107 virtual bool RecvMarkOfflineCacheEntryAsForeign() MOZ_OVERRIDE; |
|
108 virtual bool RecvDivertOnDataAvailable(const nsCString& data, |
|
109 const uint64_t& offset, |
|
110 const uint32_t& count) MOZ_OVERRIDE; |
|
111 virtual bool RecvDivertOnStopRequest(const nsresult& statusCode) MOZ_OVERRIDE; |
|
112 virtual bool RecvDivertComplete() MOZ_OVERRIDE; |
|
113 virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE; |
|
114 |
|
115 // Supporting function for ADivertableParentChannel. |
|
116 nsresult ResumeForDiversion(); |
|
117 |
|
118 // Asynchronously calls NotifyDiversionFailed. |
|
119 void FailDiversion(nsresult aErrorCode, bool aSkipResume = true); |
|
120 |
|
121 friend class HttpChannelParentListener; |
|
122 nsRefPtr<mozilla::dom::TabParent> mTabParent; |
|
123 |
|
124 private: |
|
125 nsRefPtr<nsHttpChannel> mChannel; |
|
126 nsCOMPtr<nsICacheEntry> mCacheEntry; |
|
127 nsCOMPtr<nsIAssociatedContentSecurity> mAssociatedContentSecurity; |
|
128 bool mIPCClosed; // PHttpChannel actor has been Closed() |
|
129 |
|
130 nsCOMPtr<nsIChannel> mRedirectChannel; |
|
131 nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback; |
|
132 |
|
133 nsAutoPtr<class nsHttpChannel::OfflineCacheEntryAsForeignMarker> mOfflineForeignMarker; |
|
134 |
|
135 // state for combining OnStatus/OnProgress with OnDataAvailable |
|
136 // into one IPDL call to child. |
|
137 nsresult mStoredStatus; |
|
138 uint64_t mStoredProgress; |
|
139 uint64_t mStoredProgressMax; |
|
140 |
|
141 bool mSentRedirect1Begin : 1; |
|
142 bool mSentRedirect1BeginFailed : 1; |
|
143 bool mReceivedRedirect2Verify : 1; |
|
144 |
|
145 PBOverrideStatus mPBOverride; |
|
146 |
|
147 nsCOMPtr<nsILoadContext> mLoadContext; |
|
148 nsRefPtr<nsHttpHandler> mHttpHandler; |
|
149 |
|
150 nsRefPtr<HttpChannelParentListener> mParentListener; |
|
151 // Set to the canceled status value if the main channel was canceled. |
|
152 nsresult mStatus; |
|
153 // Once set, no OnStart/OnData/OnStop calls should be accepted; conversely, it |
|
154 // must be set when RecvDivertOnData/~DivertOnStop/~DivertComplete are |
|
155 // received from the child channel. |
|
156 bool mDivertingFromChild; |
|
157 |
|
158 // Set if OnStart|StopRequest was called during a diversion from the child. |
|
159 bool mDivertedOnStartRequest; |
|
160 |
|
161 bool mSuspendedForDiversion; |
|
162 }; |
|
163 |
|
164 } // namespace net |
|
165 } // namespace mozilla |
|
166 |
|
167 #endif // mozilla_net_HttpChannelParent_h |