1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-08 04:49:12 +02:00
This commit is contained in:
gorhill 2016-08-15 22:50:24 -04:00
parent a76703b6ad
commit 2725479709
3 changed files with 30 additions and 22 deletions

View File

@ -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;

View File

@ -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) ) {

View File

@ -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;