diff --git a/platform/firefox/frameModule.js b/platform/firefox/frameModule.js index ef5f04c2b..6f2c284c2 100644 --- a/platform/firefox/frameModule.js +++ b/platform/firefox/frameModule.js @@ -207,11 +207,7 @@ var contentObserver = { // - Enable uBlock // - Services and all other global variables are undefined // Hopefully will eventually understand why this happens. - if ( Services === undefined ) { - return this.ACCEPT; - } - - if ( !context ) { + if ( Services === undefined || !context ) { return this.ACCEPT; } @@ -219,6 +215,13 @@ var contentObserver = { this.handlePopup(location, origin, context); } + // https://bugzilla.mozilla.org/show_bug.cgi?id=1232354 + // For modern versions of Firefox, the frameId/parentFrameId + // information can be found in channel.loadInfo of the HTTP observer. + if ( this.canE10S ) { + return this.ACCEPT; + } + if ( !location.schemeIs('http') && !location.schemeIs('https') ) { return this.ACCEPT; } @@ -245,19 +248,12 @@ var contentObserver = { return this.ACCEPT; } - // https://bugzilla.mozilla.org/show_bug.cgi?id=1232354 - // For top-level resources, no need to send information to the - // main process. - let isTopContext = context === context.top; - if ( isTopContext && this.canE10S ) { - return this.ACCEPT; - } - let messageManager = getMessageManager(context); if ( messageManager === null ) { return this.ACCEPT; } + let isTopContext = context === context.top; var parentFrameId; if ( isTopContext ) { parentFrameId = -1; diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 52485c6fd..b5df649b1 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -2026,11 +2026,11 @@ var httpObserver = { if ( bucket === undefined ) { return null; } - var i = bucket.charCodeAt(0); + var i = bucket.charCodeAt(bucket.length - 1); if ( bucket.length === 1 ) { this.pendingURLToIndex.delete(url); } else { - this.pendingURLToIndex.set(url, bucket.slice(1)); + this.pendingURLToIndex.set(url, bucket.slice(0, -1)); } var preq = this.pendingRingBuffer[i]; preq._key = ''; // mark as "serviced" @@ -2225,8 +2225,15 @@ var httpObserver = { var pendingRequest = this.lookupPendingRequest(URI.spec); // https://github.com/gorhill/uMatrix/issues/390#issuecomment-155759004 - var rawtype = 1; - var loadInfo = channel.loadInfo; + var loadInfo = channel.loadInfo, + rawtype = 1, + frameId = 0, + parentFrameId = -1; + + // https://bugzilla.mozilla.org/show_bug.cgi?id=1232354 + // https://dxr.mozilla.org/mozilla-central/source/toolkit/modules/addons/WebRequest.jsm#537-553 + // For modern Firefox, loadInfo contains the information about the + // context of the network request. if ( loadInfo ) { rawtype = loadInfo.externalContentPolicyType !== undefined ? loadInfo.externalContentPolicyType : @@ -2234,6 +2241,11 @@ var httpObserver = { if ( !rawtype ) { rawtype = 1; } + frameId = loadInfo.frameOuterWindowID ? loadInfo.frameOuterWindowID : loadInfo.outerWindowID; + parentFrameId = loadInfo.frameOuterWindowID ? loadInfo.outerWindowID : loadInfo.parentOuterWindowID; + if ( frameId === parentFrameId ) { + parentFrameId = -1; + } } if ( pendingRequest !== null ) { @@ -2259,6 +2271,8 @@ var httpObserver = { pendingRequest = this.syntheticPendingRequest; pendingRequest.tabId = this.tabIdFromChannel(channel); pendingRequest.rawtype = rawtype; + pendingRequest.frameId = frameId; + pendingRequest.parentFrameId = parentFrameId; } if ( this.handleRequest(channel, URI, pendingRequest) ) { diff --git a/src/js/traffic.js b/src/js/traffic.js index b57e3aa75..4d6fb1f0a 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -77,10 +77,9 @@ var onBeforeRequest = function(details) { // > the outer frame. // > (ref: https://developer.chrome.com/extensions/webRequest) var isFrame = requestType === 'sub_frame'; - var frameId = isFrame ? details.parentFrameId : details.frameId; // https://github.com/chrisaljoudi/uBlock/issues/114 - var requestContext = pageStore.createContextFromFrameId(frameId); + var requestContext = pageStore.createContextFromFrameId(isFrame ? details.parentFrameId : details.frameId); // Setup context and evaluate var requestURL = details.url; @@ -109,9 +108,8 @@ var onBeforeRequest = function(details) { // Not blocked if ( µb.isAllowResult(result) ) { // https://github.com/chrisaljoudi/uBlock/issues/114 - frameId = details.frameId; - if ( frameId > 0 && isFrame ) { - pageStore.setFrame(frameId, requestURL); + if ( details.parentFrameId !== -1 && isFrame ) { + pageStore.setFrame(details.frameId, requestURL); } requestContext.dispose(); return;