nsINetworkInterceptController.idl (8612B)
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/. */ 5 6 #include "nsISupports.idl" 7 #include "nsIContentPolicy.idl" 8 9 interface nsICacheInfoChannel; 10 interface nsIChannel; 11 interface nsIConsoleReportCollector; 12 interface nsIInputStream; 13 interface nsIOutputStream; 14 interface nsIURI; 15 16 %{C++ 17 #include "nsContentUtils.h" 18 #include "nsIChannel.h" 19 #include "nsIConsoleReportCollector.h" 20 #include "nsILoadInfo.h" 21 namespace mozilla { 22 class TimeStamp; 23 24 namespace dom { 25 class ChannelInfo; 26 } 27 } 28 %} 29 30 native TimeStamp(mozilla::TimeStamp); 31 32 [ptr] native ChannelInfo(mozilla::dom::ChannelInfo); 33 34 /** 35 * Interface allowing the nsIInterceptedChannel to callback when it is 36 * done reading from the body stream. 37 */ 38 [scriptable, uuid(51039eb6-bea0-40c7-b523-ccab56cc4fde)] 39 interface nsIInterceptedBodyCallback : nsISupports 40 { 41 void bodyComplete(in nsresult aRv); 42 }; 43 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. 49 */ 50 51 [scriptable, builtinclass, uuid(f4b82975-6a86-4cc4-87fe-9a1fd430c86d)] 52 interface nsIInterceptedChannel : nsISupports 53 { 54 /** 55 * Instruct a channel that has been intercepted to continue with the original 56 * network request. 57 * 58 * For our mitigations, we support this reset triggering "bypass" mode which 59 * results in the resulting client not being controlled. 60 */ 61 void resetInterception(in boolean bypass); 62 63 /** 64 * Set the status and reason for the forthcoming synthesized response. 65 * Multiple calls overwrite existing values. 66 */ 67 void synthesizeStatus(in uint16_t status, in ACString reason); 68 69 /** 70 * Attach a header name/value pair to the forthcoming synthesized response. 71 * Overwrites any existing header value. 72 */ 73 void synthesizeHeader(in ACString name, in ACString value); 74 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. 95 */ 96 void startSynthesizedResponse(in nsIInputStream body, 97 in nsIInterceptedBodyCallback callback, 98 in nsICacheInfoChannel channel, 99 in ACString finalURLSpec, 100 in boolean responseRedirected); 101 102 /** 103 * Instruct a channel that has been intercepted that response synthesis 104 * has completed and all outstanding resources can be closed. 105 */ 106 void finishSynthesizedResponse(); 107 108 /** 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. 112 */ 113 void cancelInterception(in nsresult status); 114 115 /** 116 * The underlying channel object that was intercepted. 117 */ 118 readonly attribute nsIChannel channel; 119 120 /** 121 * The URL of the underlying channel object, corrected for a potential 122 * secure upgrade. 123 */ 124 readonly attribute nsIURI secureUpgradedChannelURI; 125 126 /** 127 * This method allows to override the channel info for the channel. 128 */ 129 [noscript] 130 void setChannelInfo(in ChannelInfo channelInfo); 131 132 /** 133 * Get the internal load type from the underlying channel. 134 */ 135 [noscript] 136 readonly attribute nsContentPolicyType internalContentPolicyType; 137 138 [noscript] 139 readonly attribute nsIConsoleReportCollector consoleReportCollector; 140 141 [noscript] 142 void SetFetchHandlerStart(in TimeStamp aTimeStamp); 143 144 [noscript] 145 void SetFetchHandlerFinish(in TimeStamp aTimeStamp); 146 147 [noscript] 148 void SetRemoteWorkerLaunchStart(in TimeStamp aTimeStamp); 149 150 [noscript] 151 void SetRemoteWorkerLaunchEnd(in TimeStamp aTimeStamp); 152 153 /** 154 * This method indicates if the ServiceWorker Interception is reset to 155 * network or not. 156 */ 157 [noscript] 158 boolean GetIsReset(); 159 160 %{C++ 161 already_AddRefed<nsIConsoleReportCollector> 162 GetConsoleReportCollector() 163 { 164 nsCOMPtr<nsIConsoleReportCollector> reporter; 165 GetConsoleReportCollector(getter_AddRefs(reporter)); 166 return reporter.forget(); 167 } 168 169 void 170 GetSubresourceTimeStampKey(nsIChannel* aChannel, nsACString& aKey) 171 { 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; 184 } 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; 191 } 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; 197 } 198 default: { 199 aKey = "subresource-other"_ns; 200 break; 201 } 202 } 203 } 204 } 205 206 bool 207 IsReset() 208 { 209 bool result; 210 GetIsReset(&result); 211 return result; 212 } 213 %} 214 215 /** 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. 219 */ 220 [noscript] 221 void setReleaseHandle(in nsISupports aHandle); 222 }; 223 224 /** 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. 228 */ 229 230 [scriptable, uuid(70d2b4fe-a552-48cd-8d93-1d8437a56b53)] 231 interface nsINetworkInterceptController : nsISupports 232 { 233 /** 234 * Returns true if a channel should avoid initiating any network 235 * requests until specifically instructed to do so. 236 * 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(). 241 */ 242 boolean shouldPrepareForIntercept(in nsIURI aURI, in nsIChannel aChannel); 243 244 /** 245 * Notification when a given intercepted channel is prepared to accept a synthesized 246 * response via the provided stream. 247 * 248 * @param aChannel the controlling interface for a channel that has been intercepted 249 */ 250 void channelIntercepted(in nsIInterceptedChannel aChannel); 251 };