fune/toolkit/components/extensions/ext-c-webRequest.js
Kris Maglione 270a894712 Bug 1398974: Follow-up: Disconnect StreamFilters when closing extension context. r=me
If we don't do this explicitly, the channel is automatically disconnected when
it's GCed. However, if we start shutdown while a stream is being processed,
the stream may not be GCed before we shut down the parent process's message
loop. In that case, we get a shutdown crash because the StreamFilterParent's
data channel is still open when we shut down its message loop.

Explicitly disconnecting the StreamFilter when the context is closed prevents
this, since app shutdown is automatically blocked on extension shutdown, and
extension shutdown explicitly closes all extant contexts.

MozReview-Commit-ID: 5JPrSUooq1j

--HG--
extra : rebase_source : d9af8c6b1c2107a726fead2aa0bbf9cc6f7b72e2
2017-09-12 18:55:24 -07:00

35 lines
813 B
JavaScript

/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
this.webRequest = class extends ExtensionAPI {
getAPI(context) {
let filters = new WeakSet();
context.callOnClose({
close() {
for (let filter of ChromeUtils.nondeterministicGetWeakSetKeys(filters)) {
try {
filter.disconnect();
} catch (e) {
// Ignore.
}
}
},
});
return {
webRequest: {
filterResponseData(requestId) {
requestId = parseInt(requestId, 10);
let streamFilter = context.cloneScope.StreamFilter.create(
requestId, context.extension.id);
filters.add(streamFilter);
return streamFilter;
},
},
};
}
};