1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
12 * Load types that correspond to the external types in nsIContentPolicy.idl.
13 * Please also update that IDL when updating this list.
15 enum MozContentPolicyType {
40 * String versions of CLASSIFIED_* tracking flags from nsIClassifiedChannel.idl
42 enum MozUrlClassificationFlags {
44 "fingerprinting_content",
46 "cryptomining_content",
48 "emailtracking_content",
55 "socialtracking_facebook",
56 "socialtracking_linkedin",
57 "socialtracking_twitter",
59 "any_strict_tracking",
64 * A thin wrapper around nsIChannel and nsIHttpChannel that allows JS
65 * callers to access them without XPConnect overhead.
67 [ChromeOnly, Exposed=Window]
68 interface ChannelWrapper : EventTarget {
70 * Returns the wrapper instance for the given channel. The same wrapper is
71 * always returned for a given channel.
73 static ChannelWrapper get(MozChannel channel);
76 * Returns the wrapper instance for the given channel. The same wrapper is
77 * always returned for a given channel.
79 static ChannelWrapper? getRegisteredChannel(unsigned long long aChannelId,
80 WebExtensionPolicy extension,
81 RemoteTab? remoteTab);
84 * A unique ID for for the requests which remains constant throughout the
87 [Constant, StoreInSlot]
88 readonly attribute unsigned long long id;
90 // Not technically pure, since it's backed by a weak reference, but if JS
91 // has a reference to the previous value, we can depend on it not being
94 attribute MozChannel? channel;
98 * Cancels the request with the given nsresult status code.
100 * The optional reason parameter should be one of the BLOCKING_REASON
101 * constants from nsILoadInfo.idl
104 undefined cancel(unsigned long result, optional unsigned long reason = 0);
107 * Redirects the wrapped HTTP channel to the given URI. For other channel
108 * types, this method will throw. The redirect is an internal redirect, and
109 * the behavior is the same as nsIHttpChannel.redirectTo.
112 undefined redirectTo(URI url);
115 * Requests an upgrade of the HTTP channel to a secure request. For other channel
116 * types, this method will throw. The redirect is an internal redirect, and
117 * the behavior is the same as nsIHttpChannel.upgradeToSecure. Setting this
118 * flag is only effective during the WebRequest.onBeforeRequest in
119 * Web Extensions, calling this at any other point during the request will
120 * have no effect. Setting this flag in addition to calling redirectTo
121 * results in the redirect happening rather than the upgrade request.
124 undefined upgradeToSecure();
127 * Suspends the underlying channel. The profilerText parameter is only used
128 * to annotate profiles.
131 undefined suspend(ByteString profileMarkerText);
134 * Resumes (un-suspends) the underlying channel.
140 * The content type of the request, usually as read from the Content-Type
141 * header. This should be used in preference to the header to determine the
142 * content type of the channel.
145 attribute ByteString contentType;
149 * For HTTP requests, the request method (e.g., GET, POST, HEAD). For other
150 * request types, returns an empty string.
153 readonly attribute ByteString method;
156 * For requests with LoadInfo, the content policy type that corresponds to
157 * the request. For requests without LoadInfo, returns "other".
160 readonly attribute MozContentPolicyType type;
164 * When true, the request is currently suspended by the wrapper. When false,
165 * the request is not suspended by the wrapper, but may still be suspended
169 readonly attribute boolean suspended;
173 * The final URI of the channel (as returned by NS_GetFinalChannelURI) after
174 * any redirects have been processed.
177 readonly attribute URI finalURI;
180 * The string version of finalURI (but cheaper to access than
184 readonly attribute DOMString finalURL;
188 * Returns true if the request matches the given request filter, and the
189 * given extension has permission to access it.
191 boolean matches(optional MozRequestFilter filter = {},
192 optional WebExtensionPolicy? extension = null,
193 optional MozRequestMatchOptions options = {});
197 * Register's this channel as traceable by the given add-on when accessed
198 * via the process of the given RemoteTab.
200 undefined registerTraceableChannel(WebExtensionPolicy extension, RemoteTab? remoteTab);
203 * The current HTTP status code of the request. This will be 0 if a response
204 * has not yet been received, or if the request is not an HTTP request.
207 readonly attribute unsigned long statusCode;
210 * The HTTP status line for the request (e.g., "HTTP/1.0 200 Success"). This
211 * will be an empty string if a response has not yet been received, or if
212 * the request is not an HTTP request.
215 readonly attribute ByteString statusLine;
219 * If the request has failed or been canceled, an opaque string representing
220 * the error. For requests that failed at the NSS layer, this is an NSS
221 * error message. For requests that failed for any other reason, it is the
222 * name of an nsresult error code. For requests which haven't failed, this
225 * This string is used in the error message when notifying extension
226 * webRequest listeners of failure. The documentation specifically states
227 * that this value MUST NOT be parsed, and is only meant to be displayed to
228 * humans, but we all know how that works in real life.
231 readonly attribute DOMString? errorString;
234 * Dispatched when the channel is closed with an error status. Check
235 * errorString for the error details.
237 attribute EventHandler onerror;
240 * Checks the request's current status and dispatches an error event if the
241 * request has failed and one has not already been dispatched.
243 undefined errorCheck();
247 * Dispatched when the channel begins receiving data.
249 attribute EventHandler onstart;
252 * Dispatched when the channel has finished receiving data.
254 attribute EventHandler onstop;
258 * Information about the proxy server which is handling this request, or
259 * null if the request is not proxied.
261 [Cached, Frozen, GetterThrows, Pure]
262 readonly attribute MozProxyInfo? proxyInfo;
265 * For HTTP requests, the IP address of the remote server handling the
266 * request. For other request types, returns null.
269 readonly attribute ByteString? remoteAddress;
273 * The LoadInfo object for this channel, if available. Null for channels
274 * without load info, until support for those is removed.
277 readonly attribute LoadInfo? loadInfo;
280 * True if this load for a service worker script (either a main script or import scripts).
283 readonly attribute boolean isServiceWorkerScript;
286 * True if this load was triggered by a system caller. This currently always
287 * false if the request has no LoadInfo or is a top-level document load.
290 readonly attribute boolean isSystemLoad;
293 * The URL of the principal that triggered this load. This is equivalent to
294 * the LoadInfo's triggeringPrincipal, and will only ever be null for
295 * requests without LoadInfo.
298 readonly attribute ByteString? originURL;
301 * The URL of the document loading the content for this request. This is
302 * equivalent to the LoadInfo's loadingPrincipal. This may only ever be null
303 * for top-level requests and requests without LoadInfo.
306 readonly attribute ByteString? documentURL;
309 * The URI version of originURL. Will be null only when originURL is null.
312 readonly attribute URI? originURI;
315 * The URI version of documentURL. Will be null only when documentURL is
319 readonly attribute URI? documentURI;
323 * True if extensions may modify this request. This is currently false only
324 * if the request belongs to a document which has access to the
325 * mozAddonManager API.
327 [Cached, GetterThrows, Pure]
328 readonly attribute boolean canModify;
332 * The BrowsingContext ID of the frame that the request belongs to, or 0 if it
333 * is a top-level load or does not belong to a document.
336 readonly attribute long long frameId;
339 * The BrowsingContext ID of the parent frame of the window that the request
340 * belongs to, 0 if that parent frame is the top-level frame, and -1 if the
341 * request belongs to a top-level frame.
344 readonly attribute long long parentFrameId;
347 * For cross-process requests, the <browser> or <iframe> element to which the
348 * content loading this request belongs. For requests that don't originate
349 * from a remote browser, this is null.
351 * This is not an Element because those are by default only exposed in
352 * Window, but we're exposed in System.
355 readonly attribute nsISupports? browserElement;
358 * Returns an array of objects that combine the url and frameId from the
359 * ancestorPrincipals and ancestorOuterWindowIDs on loadInfo.
360 * The immediate parent is the first entry, the last entry is always the top
361 * level frame. It will be an empty list for toplevel window loads and
362 * non-subdocument resource loads within a toplevel window. For the latter,
363 * originURL will provide information on what window is doing the load. It
364 * will be null if the request is not associated with a window (e.g. XHR with
365 * mozBackgroundRequest = true).
367 [Cached, Frozen, GetterThrows, Pure]
368 readonly attribute sequence<MozFrameAncestorInfo>? frameAncestors;
371 * For HTTP requests, returns an array of request headers which will be, or
372 * have been, sent with this request.
374 * For non-HTTP requests, throws NS_ERROR_UNEXPECTED.
377 sequence<MozHTTPHeader> getRequestHeaders();
380 * For HTTP requests: returns the value of the request header, null if not set.
382 * For non-HTTP requests, throws NS_ERROR_UNEXPECTED.
385 ByteString? getRequestHeader(ByteString header);
388 * For HTTP requests, returns an array of response headers which were
389 * received for this request, in the same format as returned by
392 * Throws NS_ERROR_NOT_AVAILABLE if a response has not yet been received, or
393 * NS_ERROR_UNEXPECTED if the channel is not an HTTP channel.
395 * Note: The Content-Type header is handled specially. That header is
396 * usually not mutable after the request has been received, and the content
397 * type must instead be changed via the contentType attribute. If a caller
398 * attempts to set the Content-Type header via setRequestHeader, however,
399 * that value is assigned to the contentType attribute and its original
400 * string value is cached. That original value is returned in place of the
401 * actual Content-Type header.
404 sequence<MozHTTPHeader> getResponseHeaders();
407 * Sets the given request header to the given value, overwriting any
408 * previous value. Setting a header to a null string has the effect of
409 * removing it. If merge is true, then the passed value will be merged
410 * to any existing value that exists for the header. Otherwise, any prior
411 * value for the header will be overwritten. Merge is ignored for headers
412 * that cannot be merged.
414 * For non-HTTP requests, throws NS_ERROR_UNEXPECTED.
417 undefined setRequestHeader(ByteString header,
419 optional boolean merge = false);
422 * Sets the given response header to the given value, overwriting any
423 * previous value. Setting a header to a null string has the effect of
424 * removing it. If merge is true, then the passed value will be merged
425 * to any existing value that exists for the header (e.g. handling multiple
426 * Set-Cookie headers). Otherwise, any prior value for the header will be
427 * overwritten. Merge is ignored for headers that cannot be merged.
429 * For non-HTTP requests, throws NS_ERROR_UNEXPECTED.
431 * Note: The content type header is handled specially by this function. See
432 * getResponseHeaders() for details.
435 undefined setResponseHeader(ByteString header,
437 optional boolean merge = false);
440 * Provides the tracking classification data when it is available.
442 [Cached, Frozen, GetterThrows, Pure]
443 readonly attribute MozUrlClassification? urlClassification;
446 * Indicates if this response and its content window hierarchy is third
450 readonly attribute boolean thirdParty;
453 * The current bytes sent of the request. This will be 0 if a request has not
454 * sent yet, or if the request is not an HTTP request.
457 readonly attribute unsigned long long requestSize;
460 * The current bytes received of the response. This will be 0 if a response
461 * has not recieved yet, or if the request is not an HTTP response.
464 readonly attribute unsigned long long responseSize;
468 * Wrapper for first and third party tracking classification data.
470 dictionary MozUrlClassification {
471 required sequence<MozUrlClassificationFlags> firstParty;
472 required sequence<MozUrlClassificationFlags> thirdParty;
476 * Information about the proxy server handing a request. This is approximately
477 * equivalent to nsIProxyInfo.
479 dictionary MozProxyInfo {
481 * The hostname of the server.
483 required ByteString host;
485 * The TCP port of the server.
489 * The type of proxy (e.g., HTTP, SOCKS).
491 required ByteString type;
494 * True if the proxy is responsible for DNS lookups.
496 required boolean proxyDNS;
499 * The authentication username for the proxy, if any.
501 ByteString? username = null;
504 * The timeout, in seconds, before the network stack will failover to the
505 * next candidate proxy server if it has not received a response.
507 unsigned long failoverTimeout;
510 * Any non-empty value will be passed directly as Proxy-Authorization header
511 * value for the CONNECT request attempt. However, this header set on the
512 * resource request itself takes precedence.
514 ByteString? proxyAuthorizationHeader = null;
517 * An optional key used for additional isolation of this proxy connection.
519 ByteString? connectionIsolationKey = null;
523 * MozFrameAncestorInfo combines loadInfo::AncestorPrincipals with
524 * loadInfo::AncestorOuterWindowIDs for easier access in the WebRequest API.
526 * url represents the parent of the loading window.
527 * frameId is the outerWindowID for the parent of the loading window.
529 * For further details see nsILoadInfo.idl and Document::AncestorPrincipals.
531 dictionary MozFrameAncestorInfo {
532 required ByteString url;
533 required unsigned long long frameId;
537 * Represents an HTTP request or response header.
539 dictionary MozHTTPHeader {
541 * The case-insensitive, non-case-normalized header name.
543 required ByteString name;
547 required ByteString value;
551 * An object used for filtering requests.
553 dictionary MozRequestFilter {
555 * If present, the request only matches if its `type` attribute matches one
556 * of the given types.
558 sequence<MozContentPolicyType>? types = null;
561 * If present, the request only matches if its finalURI matches the given
564 MatchPatternSet? urls = null;
567 * If present, the request only matches if the loadInfo privateBrowsingId matches
568 * against the given incognito value.
570 boolean? incognito = null;
573 dictionary MozRequestMatchOptions {
575 * True if we're matching for the proxy portion of a proxied request.
577 boolean isProxy = false;