mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Firefox: each frame should have a unique ID
This commit is contained in:
parent
f9109d7460
commit
9bd31f1362
@ -30,7 +30,7 @@ const {Services} = Cu.import('resource://gre/modules/Services.jsm', null);
|
|||||||
const hostName = Services.io.newURI(Components.stack.filename, null, null).host;
|
const hostName = Services.io.newURI(Components.stack.filename, null, null).host;
|
||||||
let uniqueSandboxId = 1;
|
let uniqueSandboxId = 1;
|
||||||
|
|
||||||
// let {console} = Cu.import('resource://gre/modules/devtools/Console.jsm', null);
|
// Cu.import('resource://gre/modules/devtools/Console.jsm');
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
@ -112,6 +112,13 @@ const contentObserver = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getFrameId: function(win) {
|
||||||
|
return win
|
||||||
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIDOMWindowUtils)
|
||||||
|
.outerWindowID;
|
||||||
|
},
|
||||||
|
|
||||||
// https://bugzil.la/612921
|
// https://bugzil.la/612921
|
||||||
shouldLoad: function(type, location, origin, context) {
|
shouldLoad: function(type, location, origin, context) {
|
||||||
if ( !context ) {
|
if ( !context ) {
|
||||||
@ -122,10 +129,17 @@ const contentObserver = {
|
|||||||
return this.ACCEPT;
|
return this.ACCEPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
let openerURL, frameId;
|
let openerURL = null;
|
||||||
|
|
||||||
if ( type === this.MAIN_FRAME ) {
|
if ( type === this.MAIN_FRAME ) {
|
||||||
frameId = -1;
|
// When an iframe is loaded, it will be reported first as type = 6,
|
||||||
|
// then immediately after that type = 7, so ignore the first report.
|
||||||
|
// Origin should be "chrome://browser/content/browser.xul" here.
|
||||||
|
// The lack of side-effects are not guaranteed though.
|
||||||
|
if ( origin === null || origin.schemeIs('chrome') === false ) {
|
||||||
|
return this.ACCEPT;
|
||||||
|
}
|
||||||
|
|
||||||
context = context.contentWindow || context;
|
context = context.contentWindow || context;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -134,9 +148,6 @@ const contentObserver = {
|
|||||||
}
|
}
|
||||||
} catch (ex) {}
|
} catch (ex) {}
|
||||||
} else {
|
} else {
|
||||||
// TODO: frameId from outerWindowID?
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIDOMWindowUtils
|
|
||||||
frameId = context === context.top ? 0 : 1;
|
|
||||||
context = (context.ownerDocument || context).defaultView;
|
context = (context.ownerDocument || context).defaultView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,11 +157,23 @@ const contentObserver = {
|
|||||||
return this.ACCEPT;
|
return this.ACCEPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let isTopLevel = context === context.top;
|
||||||
|
let frameId = isTopLevel ? 0 : this.getFrameId(context);
|
||||||
|
let parentFrameId;
|
||||||
|
|
||||||
|
if ( isTopLevel ) {
|
||||||
|
parentFrameId = -1;
|
||||||
|
} else if ( context.parent === context.top ) {
|
||||||
|
parentFrameId = 0;
|
||||||
|
} else {
|
||||||
|
parentFrameId = this.getFrameId(context.parent);
|
||||||
|
}
|
||||||
|
|
||||||
let messageManager = getMessageManager(context);
|
let messageManager = getMessageManager(context);
|
||||||
let details = {
|
let details = {
|
||||||
frameId: frameId,
|
frameId: frameId,
|
||||||
openerURL: openerURL || null,
|
openerURL: openerURL,
|
||||||
parentFrameId: context === context.top ? -1 : 0,
|
parentFrameId: parentFrameId,
|
||||||
type: type,
|
type: type,
|
||||||
url: location.spec
|
url: location.spec
|
||||||
};
|
};
|
||||||
|
@ -958,7 +958,13 @@ var httpObserver = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// [type, tabId, sourceTabId - given if it was a popup]
|
/*[
|
||||||
|
type,
|
||||||
|
tabId,
|
||||||
|
sourceTabId - given if it was a popup,
|
||||||
|
frameId,
|
||||||
|
parentFrameId
|
||||||
|
]*/
|
||||||
channelData = channel.getProperty(location.host + 'reqdata');
|
channelData = channel.getProperty(location.host + 'reqdata');
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
return;
|
return;
|
||||||
@ -1047,7 +1053,13 @@ var httpObserver = {
|
|||||||
if ( channel instanceof Ci.nsIWritablePropertyBag ) {
|
if ( channel instanceof Ci.nsIWritablePropertyBag ) {
|
||||||
channel.setProperty(
|
channel.setProperty(
|
||||||
location.host + 'reqdata',
|
location.host + 'reqdata',
|
||||||
[lastRequest.type, lastRequest.tabId, sourceTabId]
|
[
|
||||||
|
lastRequest.type,
|
||||||
|
lastRequest.tabId,
|
||||||
|
sourceTabId,
|
||||||
|
lastRequest.frameId,
|
||||||
|
lastRequest.parentFrameId
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -1074,20 +1086,21 @@ var httpObserver = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: what if a behind-the-scene request is being redirected?
|
||||||
|
// This data is present only for tabbed requests, so if this throws,
|
||||||
|
// the redirection won't be evaluated and canceled (if necessary)
|
||||||
var channelData = oldChannel.getProperty(location.host + 'reqdata');
|
var channelData = oldChannel.getProperty(location.host + 'reqdata');
|
||||||
var [type, tabId, sourceTabId] = channelData;
|
|
||||||
|
|
||||||
if ( this.handlePopup(URI, tabId, sourceTabId) ) {
|
if ( this.handlePopup(URI, channelData[1], channelData[2]) ) {
|
||||||
result = this.ABORT;
|
result = this.ABORT;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var details = {
|
var details = {
|
||||||
type: type,
|
type: channelData[0],
|
||||||
tabId: tabId,
|
tabId: channelData[1],
|
||||||
// well...
|
frameId: channelData[3],
|
||||||
frameId: type === this.MAIN_FRAME ? -1 : 0,
|
parentFrameId: channelData[4]
|
||||||
parentFrameId: -1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if ( this.handleRequest(newChannel, URI, details) ) {
|
if ( this.handleRequest(newChannel, URI, details) ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user