Bug 1909613 - Enable <details name=''> everywhere, r=emilio
[gecko.git] / netwerk / base / nsINetworkInterceptController.idl
blob7f91d2df6f8bb4020c75c132dc8f6bf26625fa1e
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, builtinclass, 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 boolean 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);
147 [noscript]
148 void SetRemoteWorkerLaunchStart(in TimeStamp aTimeStamp);
150 [noscript]
151 void SetRemoteWorkerLaunchEnd(in TimeStamp aTimeStamp);
154 * This method indicates if the ServiceWorker Interception is reset to
155 * network or not.
157 [noscript]
158 boolean GetIsReset();
160 %{C++
161 already_AddRefed<nsIConsoleReportCollector>
162 GetConsoleReportCollector()
164 nsCOMPtr<nsIConsoleReportCollector> reporter;
165 GetConsoleReportCollector(getter_AddRefs(reporter));
166 return reporter.forget();
169 void
170 GetSubresourceTimeStampKey(nsIChannel* aChannel, nsACString& aKey)
172 if (!nsContentUtils::IsNonSubresourceRequest(aChannel)) {
173 nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
174 switch(loadInfo->InternalContentPolicyType()) {
175 case nsIContentPolicy::TYPE_SCRIPT:
176 case nsIContentPolicy::TYPE_INTERNAL_SCRIPT:
177 case nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD:
178 case nsIContentPolicy::TYPE_INTERNAL_MODULE:
179 case nsIContentPolicy::TYPE_INTERNAL_MODULE_PRELOAD:
180 case nsIContentPolicy::TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS:
181 case nsIContentPolicy::TYPE_INTERNAL_WORKER_STATIC_MODULE: {
182 aKey = "subresource-script"_ns;
183 break;
185 case nsIContentPolicy::TYPE_IMAGE:
186 case nsIContentPolicy::TYPE_INTERNAL_IMAGE:
187 case nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD:
188 case nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON: {
189 aKey = "subresource-image"_ns;
190 break;
192 case nsIContentPolicy::TYPE_STYLESHEET:
193 case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET:
194 case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET_PRELOAD: {
195 aKey = "subresource-stylesheet"_ns;
196 break;
198 default: {
199 aKey = "subresource-other"_ns;
200 break;
206 bool
207 IsReset()
209 bool result;
210 GetIsReset(&result);
211 return result;
216 * Allow the ServiceWorkerManager to set an RAII-style object on the
217 * intercepted channel that should be released once the channel is
218 * torn down.
220 [noscript]
221 void setReleaseHandle(in nsISupports aHandle);
225 * Interface to allow consumers to attach themselves to a channel's
226 * notification callbacks/loadgroup and determine if a given channel
227 * request should be intercepted before any network request is initiated.
230 [scriptable, uuid(70d2b4fe-a552-48cd-8d93-1d8437a56b53)]
231 interface nsINetworkInterceptController : nsISupports
234 * Returns true if a channel should avoid initiating any network
235 * requests until specifically instructed to do so.
237 * @param aURI The URI to be loaded. Note, this may differ from
238 * the channel's current URL in some cases.
239 * @param aChannel The channel that may be intercepted. It will
240 * be in the state prior to calling OnStartRequest().
242 boolean shouldPrepareForIntercept(in nsIURI aURI, in nsIChannel aChannel);
245 * Notification when a given intercepted channel is prepared to accept a synthesized
246 * response via the provided stream.
248 * @param aChannel the controlling interface for a channel that has been intercepted
250 void channelIntercepted(in nsIInterceptedChannel aChannel);