This commit is contained in:
gorhill 2015-02-25 14:15:36 -05:00
parent d80446bd96
commit b323a335cd
2 changed files with 21 additions and 13 deletions

View File

@ -574,19 +574,19 @@ PageStore.prototype.disposeFrameStores = function() {
/******************************************************************************/
PageStore.prototype.addFrame = function(frameId, frameURL) {
var frameStore = this.frames[frameId];
if ( frameStore === undefined ) {
this.frames[frameId] = frameStore = FrameStore.factory(this.rootHostname, frameURL);
//console.debug('µBlock> PageStore.addFrame(%d, "%s")', frameId, frameURL);
}
return frameStore;
PageStore.prototype.getFrame = function(frameId) {
return this.frames[frameId];
};
/******************************************************************************/
PageStore.prototype.getFrame = function(frameId) {
return this.frames[frameId];
PageStore.prototype.setFrame = function(frameId, frameURL) {
var frameStore = this.frames[frameId];
if ( frameStore instanceof FrameStore ) {
frameStore.init(this.rootHostname, frameURL);
} else {
this.frames[frameId] = FrameStore.factory(this.rootHostname, frameURL);
}
};
/******************************************************************************/

View File

@ -34,7 +34,7 @@
// Intercept and filter web requests.
var onBeforeRequest = function(details) {
//console.debug('traffic.js > onBeforeRequest(): "%s": %o', details.url, details);
//console.debug('µBlock.webRequest/onBeforeRequest(): "%s": %o', details.url, details);
var tabId = details.tabId;
@ -70,7 +70,15 @@ var onBeforeRequest = function(details) {
// https://github.com/gorhill/uBlock/issues/114
var requestContext = pageStore;
var frameStore;
var frameId = details.frameId;
// https://github.com/gorhill/uBlock/issues/886
// For requests of type `sub_frame`, the parent frame id must be used
// to lookup the proper context:
// > If the document of a (sub-)frame is loaded (type is main_frame or
// > sub_frame), frameId indicates the ID of this frame, not the ID of
// > the outer frame.
// > (ref: https://developer.chrome.com/extensions/webRequest)
var isFrame = requestType === 'sub_frame' || requestType === 'main_frame';
var frameId = isFrame ? details.parentFrameId : details.frameId;
if ( frameId > 0 ) {
if ( frameStore = pageStore.getFrame(frameId) ) {
requestContext = frameStore;
@ -91,8 +99,8 @@ var onBeforeRequest = function(details) {
//console.debug('traffic.js > onBeforeRequest(): ALLOW "%s" (%o) because "%s"', details.url, details, result);
// https://github.com/gorhill/uBlock/issues/114
if ( frameId > 0 && frameStore === undefined ) {
pageStore.addFrame(frameId, requestURL);
if ( isFrame && details.frameId > 0 ) {
pageStore.setFrame(details.frameId, requestURL);
}
// https://code.google.com/p/chromium/issues/detail?id=387198