From 2ed39ba9920face606a1335795c5dfd1685a3c82 Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Thu, 10 Nov 2022 08:07:58 +0000 Subject: [PATCH] Bug 1788773 - [devtools] network observer: set default values for properties in class definition r=ochameau Depends on D161691 Differential Revision: https://phabricator.services.mozilla.com/D161692 --- .../network-observer/NetworkObserver.sys.mjs | 116 ++++++++------ .../NetworkResponseListener.sys.mjs | 148 ++++++++++++------ 2 files changed, 168 insertions(+), 96 deletions(-) diff --git a/devtools/shared/network-observer/NetworkObserver.sys.mjs b/devtools/shared/network-observer/NetworkObserver.sys.mjs index 01a05772e729..1fb444d177d5 100644 --- a/devtools/shared/network-observer/NetworkObserver.sys.mjs +++ b/devtools/shared/network-observer/NetworkObserver.sys.mjs @@ -91,58 +91,84 @@ const HTTP_DOWNLOAD_ACTIVITIES = [ * methods which are used to add further network request/response information. */ export class NetworkObserver { - #blockedURLs; - #decodedCertificateCache; + /** + * Array of URL-like patterns used for request blocking. + * + * @type {Array} + */ + #blockedURLs = []; + /** + * Used by NetworkHelper.parseSecurityInfo to skip decoding known certificates. + * + * @type {Map} + */ + #decodedCertificateCache = new Map(); + /** + * See constructor argument of the same name. + * + * @type {Function} + */ #ignoreChannelFunction; - #interceptedChannels; - #isDestroyed; + /** + * Used to store channels intercepted for service-worker requests. + * + * @type {WeakSet} + */ + #interceptedChannels = new WeakSet(); + /** + * Explicit flag to check if this observer was already destroyed. + * + * @type {boolean} + */ + #isDestroyed = false; + /** + * See constructor argument of the same name. + * + * @type {Function} + */ #onNetworkEvent; - #openRequests; - #openResponses; - #responsePipeSegmentSize; - #saveRequestAndResponseBodies; - #throttleData; - #throttler; + /** + * Object that holds the HTTP activity objects for ongoing requests. + * + * @type {ChannelMap} + */ + #openRequests = new lazy.ChannelMap(); + /** + * Object that holds response data coming from this.#httpResponseExaminer. + * @type {ChannelMap} + */ + #openResponses = new lazy.ChannelMap(); + /** + * Network response bodies are piped through a buffer of the given size + * (in bytes). + * + * @type {Number} + */ + #responsePipeSegmentSize = Services.prefs.getIntPref( + "network.buffer.cache.size" + ); + /** + * Whether to save the bodies of network requests and responses. + * + * @type {boolean} + */ + #saveRequestAndResponseBodies = true; + /** + * Throttling configuration, see constructor of NetworkThrottleManager + * + * @type {Object} + */ + #throttleData = null; + /** + * NetworkThrottleManager instance, created when a valid throttleData is set. + * @type {NetworkThrottleManager} + */ + #throttler = null; constructor(ignoreChannelFunction, onNetworkEvent) { - // Explicit flag to check if this observer was already destroyed. - this.#isDestroyed = false; - this.#ignoreChannelFunction = ignoreChannelFunction; this.#onNetworkEvent = onNetworkEvent; - /** - * Object that holds the HTTP activity objects for ongoing requests. - */ - this.#openRequests = new lazy.ChannelMap(); - - /** - * Object that holds response data coming from this.#httpResponseExaminer. - */ - this.#openResponses = new lazy.ChannelMap(); - - this.#blockedURLs = []; - - this.#throttleData = null; - this.#throttler = null; - - // This is ultimately used by NetworkHelper.parseSecurityInfo to avoid - // repeatedly decoding already-seen certificates. - this.#decodedCertificateCache = new Map(); - - /** - * Whether to save the bodies of network requests and responses. - * @type boolean - */ - this.#saveRequestAndResponseBodies = true; - - // Network response bodies are piped through a buffer of the given size (in - // bytes). - this.#responsePipeSegmentSize = Services.prefs.getIntPref( - "network.buffer.cache.size" - ); - this.#interceptedChannels = new WeakSet(); - // Start all platform observers. if (Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT) { gActivityDistributor.addObserver(this); diff --git a/devtools/shared/network-observer/NetworkResponseListener.sys.mjs b/devtools/shared/network-observer/NetworkResponseListener.sys.mjs index 8bd67bf6db1c..73942f116e2a 100644 --- a/devtools/shared/network-observer/NetworkResponseListener.sys.mjs +++ b/devtools/shared/network-observer/NetworkResponseListener.sys.mjs @@ -40,47 +40,111 @@ XPCOMUtils.defineLazyModuleGetters(lazy, { * repeatedly decoding previously-seen certificates. */ export class NetworkResponseListener { - #bodySize; - #converter; + /** + * The uncompressed, decoded response body size. + * + * @type {Number} + */ + #bodySize = 0; + /** + * nsIStreamListener created by nsIStreamConverterService.asyncConvertData + * + * @type {nsIStreamListener} + */ + #converter = null; + /** + * See constructor argument of the same name. + * + * @type {Map} + */ #decodedCertificateCache; - #foundOpenResponse; + /** + * This NetworkResponseListener tracks the NetworkObserver.openResponses + * object to find the associated uncached headers. + * + * @type {boolean} + */ + #foundOpenResponse = false; + /** + * See constructor argument of the same name. + * + * @type {Object} + */ #httpActivity; - #inputStream; - #isDestroyed; - #onSecurityInfo; - #offset; + /** + * Set from sink.inputStream, mainly to prevent GC. + * + * @type {nsIInputStream} + */ + #inputStream = null; + /** + * Explicit flag to check if this listener was already destroyed. + * + * @type {boolean} + */ + #isDestroyed = false; + /** + * Internal promise used to hold the completion of #getSecurityInfo. + * + * @type {Promise} + */ + #onSecurityInfo = null; + /** + * Offset for the onDataAvailable calls where we pass the data from our pipe + * to the converter. + * + * @type {Number} + */ + #offset = 0; + /** + * The NetworkObserver instance which created this listener. + * + * @type {NetworkObserver} + */ #networkObserver; - #receivedData; - #request; - #sink; - #transferredSize; - #truncated; + /** + * Stores the received data as a string. + * + * @type {string} + */ + #receivedData = ""; + /** + * The nsIRequest we are started for. + * + * @type {nsIRequest} + */ + #request = null; + /** + * The response will be written into the outputStream of this nsIPipe. + * Both ends of the pipe must be blocking. + * + * @type {nsIPipe} + */ + #sink = null; + /** + * Response size on the wire, potentially compressed / encoded. + * + * @type {Number} + */ + #transferredSize = null; + /** + * Indicates if the response had a size greater than response body limit. + * + * @type {boolean} + */ + #truncated = false; + /** + * Backup for existing notificationCallbacks set on the monitored channel. + * Initialized in the constructor. + * + * @type {Object} + */ #wrappedNotificationCallbacks; constructor(networkObserver, httpActivity, decodedCertificateCache) { - // Explicit flag to check if this listener was already destroyed. - this.#isDestroyed = false; - - // The networkObserver instance which created this listener. this.#networkObserver = networkObserver; - - // Stores the received data as a string. - this.#receivedData = ""; - - // The HttpActivity object associated with this response. this.#httpActivity = httpActivity; - - // The uncompressed, decoded response body size. - this.#bodySize = 0; - - // Indicates if the response had a size greater than response body limit. - this.#truncated = false; - - // The nsIRequest we are started for. - this.#request = null; - - // Response size on the wire, potentially compressed / encoded. - this.#transferredSize = null; + this.#decodedCertificateCache = decodedCertificateCache; // Note that this is really only needed for the non-e10s case. // See bug 1309523. @@ -89,24 +153,6 @@ export class NetworkResponseListener { // internally so that we can forward getInterface requests to that object. this.#wrappedNotificationCallbacks = channel.notificationCallbacks; channel.notificationCallbacks = this; - - // A Map of certificate fingerprints to decoded certificates, to avoid - // repeatedly decoding previously-seen certificates. - this.#decodedCertificateCache = decodedCertificateCache; - - // This NetworkResponseListener tracks the NetworkObserver.openResponses - // object to find the associated uncached headers. - this.#foundOpenResponse = false; - - // The response will be written into the outputStream of this nsIPipe. - // Both ends of the pipe must be blocking. - this.#sink = null; - - // Set from sink.inputStream, mainly to prevent GC. - this.#inputStream = null; - - // nsIStreamListener created by nsIStreamConverterService.asyncConvertData - this.#converter = null; } set inputStream(inputStream) {