Bug 1861709 replace AudioCallbackDriver::ThreadRunning() assertions that mean to...
[gecko.git] / netwerk / base / nsINetworkInterceptController.idl
blobd72dc570dc82ff9d576942b9e7c23d8a74d68049
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;
10 interface nsIChannel;
11 interface nsIConsoleReportCollector;
12 interface nsIInputStream;
13 interface nsIOutputStream;
14 interface nsIURI;
16 %{C++
17 #include "nsContentUtils.h"
18 #include "nsIChannel.h"
19 #include "nsIConsoleReportCollector.h"
20 #include "nsILoadInfo.h"
21 namespace mozilla {
22 class TimeStamp;
24 namespace dom {
25 class ChannelInfo;
30 native TimeStamp(mozilla::TimeStamp);
32 [ptr] native ChannelInfo(mozilla::dom::ChannelInfo);
34 /**
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);
44 /**
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
54 /**
55 * Instruct a channel that has been intercepted to continue with the original
56 * network request.
58 * For our mitigations, we support this reset triggering "bypass" mode which
59 * results in the resulting client not being controlled.
61 void resetInterception(in boolean bypass);
63 /**
64 * Set the status and reason for the forthcoming synthesized response.
65 * Multiple calls overwrite existing values.
67 void synthesizeStatus(in uint16_t status, in ACString reason);
69 /**
70 * Attach a header name/value pair to the forthcoming synthesized response.
71 * Overwrites any existing header value.
73 void synthesizeHeader(in ACString name, in ACString value);
75 /**
76 * Instruct a channel that has been intercepted that a response is
77 * starting to be synthesized. No further header modification is allowed
78 * after this point. There are a few parameters:
79 * - A body stream may be optionally passed. If nullptr, then an
80 * empty body is assumed.
81 * - A callback may be optionally passed. It will be invoked
82 * when the body is complete. For a nullptr body this may be
83 * synchronously on the current thread. Otherwise it will be invoked
84 * asynchronously on the current thread.
85 * - A cacheInfoChannel may be optionally passed. If the body stream is
86 * from alternative data cache, this cacheInfoChannel provides needed
87 * cache information.
88 * - The caller may optionally pass a spec for a URL that this response
89 * originates from; an empty string will cause the original
90 * intercepted request's URL to be used instead.
91 * - The responseRedirected flag is false will cause the channel do an
92 * internal redirect when the original intercepted reauest's URL is
93 * different from the response's URL. The flag is true will cause the
94 * chaanel do a non-internal redirect when the URLs are different.
96 void startSynthesizedResponse(in nsIInputStream body,
97 in nsIInterceptedBodyCallback callback,
98 in nsICacheInfoChannel channel,
99 in ACString finalURLSpec,
100 in bool responseRedirected);
103 * Instruct a channel that has been intercepted that response synthesis
104 * has completed and all outstanding resources can be closed.
106 void finishSynthesizedResponse();
109 * Cancel the pending intercepted request.
110 * @return NS_ERROR_FAILURE if the response has already been synthesized or
111 * the original request has been instructed to continue.
113 void cancelInterception(in nsresult status);
116 * The underlying channel object that was intercepted.
118 readonly attribute nsIChannel channel;
121 * The URL of the underlying channel object, corrected for a potential
122 * secure upgrade.
124 readonly attribute nsIURI secureUpgradedChannelURI;
127 * This method allows to override the channel info for the channel.
129 [noscript]
130 void setChannelInfo(in ChannelInfo channelInfo);
133 * Get the internal load type from the underlying channel.
135 [noscript]
136 readonly attribute nsContentPolicyType internalContentPolicyType;
138 [noscript]
139 readonly attribute nsIConsoleReportCollector consoleReportCollector;
141 [noscript]
142 void SetFetchHandlerStart(in TimeStamp aTimeStamp);
144 [noscript]
145 void SetFetchHandlerFinish(in TimeStamp aTimeStamp);
148 * This method indicates if the ServiceWorker Interception is reset to
149 * network or not.
151 [noscript]
152 bool GetIsReset();
154 %{C++
155 already_AddRefed<nsIConsoleReportCollector>
156 GetConsoleReportCollector()
158 nsCOMPtr<nsIConsoleReportCollector> reporter;
159 GetConsoleReportCollector(getter_AddRefs(reporter));
160 return reporter.forget();
163 void
164 GetSubresourceTimeStampKey(nsIChannel* aChannel, nsACString& aKey)
166 if (!nsContentUtils::IsNonSubresourceRequest(aChannel)) {
167 nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
168 switch(loadInfo->InternalContentPolicyType()) {
169 case nsIContentPolicy::TYPE_SCRIPT:
170 case nsIContentPolicy::TYPE_INTERNAL_SCRIPT:
171 case nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD:
172 case nsIContentPolicy::TYPE_INTERNAL_MODULE:
173 case nsIContentPolicy::TYPE_INTERNAL_MODULE_PRELOAD:
174 case nsIContentPolicy::TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS:
175 case nsIContentPolicy::TYPE_INTERNAL_WORKER_STATIC_MODULE: {
176 aKey = "subresource-script"_ns;
177 break;
179 case nsIContentPolicy::TYPE_IMAGE:
180 case nsIContentPolicy::TYPE_INTERNAL_IMAGE:
181 case nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD:
182 case nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON: {
183 aKey = "subresource-image"_ns;
184 break;
186 case nsIContentPolicy::TYPE_STYLESHEET:
187 case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET:
188 case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET_PRELOAD: {
189 aKey = "subresource-stylesheet"_ns;
190 break;
192 default: {
193 aKey = "subresource-other"_ns;
194 break;
200 bool
201 IsReset()
203 bool result;
204 GetIsReset(&result);
205 return result;
210 * Allow the ServiceWorkerManager to set an RAII-style object on the
211 * intercepted channel that should be released once the channel is
212 * torn down.
214 [noscript]
215 void setReleaseHandle(in nsISupports aHandle);
219 * Interface to allow consumers to attach themselves to a channel's
220 * notification callbacks/loadgroup and determine if a given channel
221 * request should be intercepted before any network request is initiated.
224 [scriptable, uuid(70d2b4fe-a552-48cd-8d93-1d8437a56b53)]
225 interface nsINetworkInterceptController : nsISupports
228 * Returns true if a channel should avoid initiating any network
229 * requests until specifically instructed to do so.
231 * @param aURI The URI to be loaded. Note, this may differ from
232 * the channel's current URL in some cases.
233 * @param aChannel The channel that may be intercepted. It will
234 * be in the state prior to calling OnStartRequest().
236 bool shouldPrepareForIntercept(in nsIURI aURI, in nsIChannel aChannel);
239 * Notification when a given intercepted channel is prepared to accept a synthesized
240 * response via the provided stream.
242 * @param aChannel the controlling interface for a channel that has been intercepted
244 void channelIntercepted(in nsIInterceptedChannel aChannel);