1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include
"nsISupports.idl"
7 #include
"nsIContentPolicy.idl"
9 interface nsICacheInfoChannel
;
11 interface nsIConsoleReportCollector
;
12 interface nsIInputStream
;
13 interface nsIOutputStream
;
17 #include
"nsContentUtils.h"
18 #include
"nsIChannel.h"
19 #include
"nsIConsoleReportCollector.h"
20 #include
"nsILoadInfo.h"
30 native TimeStamp
(mozilla
::TimeStamp
);
32 [ptr] native ChannelInfo
(mozilla
::dom
::ChannelInfo
);
35 * Interface allowing the nsIInterceptedChannel to callback when it is
36 * done reading from the body stream.
38 [scriptable
, uuid(51039eb6
-bea0
-40c7
-b523
-ccab56cc4fde
)]
39 interface nsIInterceptedBodyCallback
: nsISupports
41 void bodyComplete
(in nsresult aRv
);
45 * Interface to allow implementors of nsINetworkInterceptController to control the behaviour
46 * of intercepted channels without tying implementation details of the interception to
47 * the actual channel. nsIInterceptedChannel is expected to be implemented by objects
48 * which do not implement nsIChannel.
51 [scriptable
, uuid(f4b82975
-6a86
-4cc4
-87fe
-9a1fd430c86d
)]
52 interface nsIInterceptedChannel
: nsISupports
55 * Instruct a channel that has been intercepted to continue with the original
58 void resetInterception
();
61 * Set the status and reason for the forthcoming synthesized response.
62 * Multiple calls overwrite existing values.
64 void synthesizeStatus
(in uint16_t status
, in ACString reason
);
67 * Attach a header name/value pair to the forthcoming synthesized response.
68 * Overwrites any existing header value.
70 void synthesizeHeader
(in ACString name
, in ACString value
);
73 * Instruct a channel that has been intercepted that a response is
74 * starting to be synthesized. No further header modification is allowed
75 * after this point. There are a few parameters:
76 * - A body stream may be optionally passed. If nullptr, then an
77 * empty body is assumed.
78 * - A callback may be optionally passed. It will be invoked
79 * when the body is complete. For a nullptr body this may be
80 * synchronously on the current thread. Otherwise it will be invoked
81 * asynchronously on the current thread.
82 * - A cacheInfoChannel may be optionally passed. If the body stream is
83 * from alternative data cache, this cacheInfoChannel provides needed
85 * - The caller may optionally pass a spec for a URL that this response
86 * originates from; an empty string will cause the original
87 * intercepted request's URL to be used instead.
88 * - The responseRedirected flag is false will cause the channel do an
89 * internal redirect when the original intercepted reauest's URL is
90 * different from the response's URL. The flag is true will cause the
91 * chaanel do a non-internal redirect when the URLs are different.
93 void startSynthesizedResponse
(in nsIInputStream body
,
94 in nsIInterceptedBodyCallback
callback,
95 in nsICacheInfoChannel channel
,
96 in ACString finalURLSpec
,
97 in bool responseRedirected
);
100 * Instruct a channel that has been intercepted that response synthesis
101 * has completed and all outstanding resources can be closed.
103 void finishSynthesizedResponse
();
106 * Cancel the pending intercepted request.
107 * @return NS_ERROR_FAILURE if the response has already been synthesized or
108 * the original request has been instructed to continue.
110 void cancelInterception
(in nsresult status
);
113 * The underlying channel object that was intercepted.
115 readonly attribute nsIChannel channel
;
118 * The URL of the underlying channel object, corrected for a potential
121 readonly attribute nsIURI secureUpgradedChannelURI
;
124 * This method allows to override the channel info for the channel.
127 void setChannelInfo
(in ChannelInfo channelInfo
);
130 * Get the internal load type from the underlying channel.
133 readonly attribute nsContentPolicyType internalContentPolicyType
;
136 readonly attribute nsIConsoleReportCollector consoleReportCollector
;
139 * Save the timestamps of various service worker interception phases.
142 void SetLaunchServiceWorkerStart
(in TimeStamp aTimeStamp
);
144 // A hack to get sw launch start time for telemetry.
146 void GetLaunchServiceWorkerStart
(out TimeStamp aTimeStamp
);
149 void SetLaunchServiceWorkerEnd
(in TimeStamp aTimeStamp
);
151 // A hack to get sw launch end time for telemetry.
153 void GetLaunchServiceWorkerEnd
(out TimeStamp aTimeStamp
);
156 void SetDispatchFetchEventStart
(in TimeStamp aTimeStamp
);
159 void SetDispatchFetchEventEnd
(in TimeStamp aTimeStamp
);
162 void SetHandleFetchEventStart
(in TimeStamp aTimeStamp
);
165 void SetHandleFetchEventEnd
(in TimeStamp aTimeStamp
);
167 // Depending on the outcome we measure the time difference between
168 // |FinishResponseStart| and either |FinishSynthesizedResponseEnd| or
169 // |ChannelResetEnd|.
171 void SetFinishResponseStart
(in TimeStamp aTimeStamp
);
174 void SetFinishSynthesizedResponseEnd
(in TimeStamp aTimeStamp
);
177 void SetChannelResetEnd
(in TimeStamp aTimeStamp
);
180 void SaveTimeStamps
();
183 already_AddRefed
<nsIConsoleReportCollector
>
184 GetConsoleReportCollector
()
186 nsCOMPtr
<nsIConsoleReportCollector
> reporter
;
187 GetConsoleReportCollector
(getter_AddRefs
(reporter
));
188 return reporter.forget
();
192 GetSubresourceTimeStampKey
(nsIChannel
* aChannel
, nsACString
& aKey
)
194 if
(!nsContentUtils
::IsNonSubresourceRequest
(aChannel
)) {
195 nsCOMPtr
<nsILoadInfo
> loadInfo
= aChannel
->GetLoadInfo
();
197 switch(loadInfo
->InternalContentPolicyType
()) {
198 case nsIContentPolicy
::TYPE_SCRIPT
:
199 case nsIContentPolicy
::TYPE_INTERNAL_SCRIPT
:
200 case nsIContentPolicy
::TYPE_INTERNAL_SCRIPT_PRELOAD
:
201 case nsIContentPolicy
::TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS
: {
202 aKey
= NS_LITERAL_CSTRING
("subresource-script");
205 case nsIContentPolicy
::TYPE_IMAGE
:
206 case nsIContentPolicy
::TYPE_INTERNAL_IMAGE
:
207 case nsIContentPolicy
::TYPE_INTERNAL_IMAGE_PRELOAD
:
208 case nsIContentPolicy
::TYPE_INTERNAL_IMAGE_FAVICON
: {
209 aKey
= NS_LITERAL_CSTRING
("subresource-image");
212 case nsIContentPolicy
::TYPE_STYLESHEET
:
213 case nsIContentPolicy
::TYPE_INTERNAL_STYLESHEET
:
214 case nsIContentPolicy
::TYPE_INTERNAL_STYLESHEET_PRELOAD
: {
215 aKey
= NS_LITERAL_CSTRING
("subresource-stylesheet");
219 aKey
= NS_LITERAL_CSTRING
("subresource-other");
229 * Allow the ServiceWorkerManager to set an RAII-style object on the
230 * intercepted channel that should be released once the channel is
234 void setReleaseHandle
(in nsISupports aHandle
);
238 * Interface to allow consumers to attach themselves to a channel's
239 * notification callbacks/loadgroup and determine if a given channel
240 * request should be intercepted before any network request is initiated.
243 [scriptable
, uuid(70d2b4fe
-a552
-48cd
-8d93
-1d8437a56b53
)]
244 interface nsINetworkInterceptController
: nsISupports
247 * Returns true if a channel should avoid initiating any network
248 * requests until specifically instructed to do so.
250 * @param aURI The URI to be loaded. Note, this may differ from
251 * the channel's current URL in some cases.
252 * @param aChannel The channel that may be intercepted. It will
253 * be in the state prior to calling OnStartRequest().
255 bool shouldPrepareForIntercept
(in nsIURI aURI
, in nsIChannel aChannel
);
258 * Notification when a given intercepted channel is prepared to accept a synthesized
259 * response via the provided stream.
261 * @param aChannel the controlling interface for a channel that has been intercepted
263 void channelIntercepted
(in nsIInterceptedChannel aChannel
);