--- a/toolkit/modules/addons/WebRequest.jsm
+++ b/toolkit/modules/addons/WebRequest.jsm
@@ -558,122 +558,115 @@ HttpObserverManager = {
errorCheck(channel, loadContext, channelData = null) {
let errorData = this.maybeError(channel, null, channelData);
if (errorData) {
this.runChannelListener(channel, loadContext, "onError", errorData);
}
return errorData;
},
- runChannelListener(channel, loadContext, kind, extraData = null) {
+ runChannelListener(channel, loadContext = null, kind, extraData = null) {
if (this.activityInitialized) {
let channelData = getData(channel);
if (kind === "onError") {
if (channelData.errorNotified) {
return;
}
channelData.errorNotified = true;
} else if (this.errorCheck(channel, loadContext, channelData)) {
return;
}
}
let listeners = this.listeners[kind];
- let browser = loadContext ? loadContext.topFrameElement : null;
+ let browser = loadContext && loadContext.topFrameElement;
let loadInfo = channel.loadInfo;
- let policyType = loadInfo ?
- loadInfo.externalContentPolicyType :
- Ci.nsIContentPolicy.TYPE_OTHER;
+ let policyType = (loadInfo ? loadInfo.externalContentPolicyType
+ : Ci.nsIContentPolicy.TYPE_OTHER);
- let requestBody;
-
- let includeStatus = (
- kind === "headersReceived" ||
- kind === "onRedirect" ||
- kind === "onStart" ||
- kind === "onStop"
- ) && channel instanceof Ci.nsIHttpChannel;
+ let includeStatus = (["headersReceived", "onRedirect", "onStart", "onStop"].includes(kind) &&
+ channel instanceof Ci.nsIHttpChannel);
let requestHeaders = new RequestHeaderChanger(channel);
let responseHeaders;
try {
responseHeaders = new ResponseHeaderChanger(channel);
} catch (e) {
// Meh.
}
let commonData = null;
let uri = channel.URI;
let handlerResults = [];
+ let requestBody;
for (let [callback, opts] of listeners.entries()) {
if (!this.shouldRunListener(policyType, uri, opts.filter)) {
continue;
}
if (!commonData) {
commonData = {
requestId: RequestId.get(channel),
url: uri.spec,
method: channel.requestMethod,
browser: browser,
type: WebRequestCommon.typeForPolicyType(policyType),
fromCache: getData(channel).fromCache,
+ windowId: 0,
+ parentWindowId: 0,
};
if (loadInfo) {
- let originPrincipal = loadInfo.triggeringPrincipal || loadInfo.loadingPrincipal;
+ let originPrincipal = loadInfo.triggeringPrincipal;
if (originPrincipal.URI) {
commonData.originUrl = originPrincipal.URI.spec;
}
- Object.assign(commonData, {
- windowId: loadInfo.frameOuterWindowID ?
- loadInfo.frameOuterWindowID : loadInfo.outerWindowID,
- parentWindowId: loadInfo.frameOuterWindowID ?
- loadInfo.outerWindowID : loadInfo.parentOuterWindowID,
- isSystemPrincipal: Services.scriptSecurityManager
- .isSystemPrincipal(loadInfo.triggeringPrincipal) ||
- Services.scriptSecurityManager
- .isSystemPrincipal(loadInfo.loadingPrincipal),
- });
- } else {
- Object.assign(commonData, {
- windowId: 0,
- parentWindowId: 0,
- });
+
+ let {isSystemPrincipal} = Services.scriptSecurityManager;
+
+ commonData.isSystemPrincipal = (isSystemPrincipal(loadInfo.triggeringPrincipal) ||
+ isSystemPrincipal(loadInfo.loadingPrincipal));
+
+ if (loadInfo.frameOuterWindowID) {
+ Object.assign(commonData, {
+ windowId: loadInfo.frameOuterWindowID,
+ parentWindowId: loadInfo.outerWindowID,
+ });
+ } else {
+ Object.assign(commonData, {
+ windowId: loadInfo.outerWindowID,
+ parentWindowId: loadInfo.parentOuterWindowID,
+ });
+ }
}
if (channel instanceof Ci.nsIHttpChannelInternal) {
try {
commonData.ip = channel.remoteAddress;
} catch (e) {
// The remoteAddress getter throws if the address is unavailable,
// but ip is an optional property so just ignore the exception.
}
}
- if (extraData) {
- Object.assign(commonData, extraData);
- }
+
+ Object.assign(commonData, extraData);
}
let data = Object.assign({}, commonData);
if (opts.requestHeaders) {
data.requestHeaders = requestHeaders.toArray();
}
if (opts.responseHeaders && responseHeaders) {
data.responseHeaders = responseHeaders.toArray();
}
if (opts.requestBody) {
- if (requestBody === undefined) {
- requestBody = WebRequestUpload.createRequestBody(channel);
- }
- if (requestBody) {
- data.requestBody = requestBody;
- }
+ requestBody = requestBody || WebRequestUpload.createRequestBody(channel);
+ data.requestBody = requestBody;
}
if (includeStatus) {
mergeStatus(data, channel, kind);
}
try {
let result = callback(data);