diff --git a/platform/firefox/frameModule.js b/platform/firefox/frameModule.js index d01309a7d..ebb6378f0 100644 --- a/platform/firefox/frameModule.js +++ b/platform/firefox/frameModule.js @@ -248,26 +248,27 @@ var contentObserver = { return this.ACCEPT; } - let details = { - frameId: this.getFrameId(context), - parentFrameId: context.parent === context.top ? 0 : this.getFrameId(context.parent), - rawtype: type, - tabId: '', - url: location.spec - }; + let rpcData = this.rpcData; + rpcData.frameId = this.getFrameId(context); + rpcData.pFrameId = context.parent === context.top ? 0 : this.getFrameId(context.parent); + rpcData.type = type; + rpcData.url = location.spec; //console.log('shouldLoad: type=' + type + ' url=' + location.spec); if ( typeof messageManager.sendRpcMessage === 'function' ) { // https://bugzil.la/1092216 - messageManager.sendRpcMessage(this.cpMessageName, details); + messageManager.sendRpcMessage(this.cpMessageName, rpcData); } else { // Compatibility for older versions - messageManager.sendSyncMessage(this.cpMessageName, details); + messageManager.sendSyncMessage(this.cpMessageName, rpcData); } return this.ACCEPT; }, + // Reuse object to avoid repeated memory allocation. + rpcData: { frameId: 0, pFrameId: -1, type: 0, url: '' }, + initContentScripts: function(win, create) { let messager = getMessageManager(win); let sandboxId = hostName + ':sb:' + this.uniqueSandboxId++; diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 108ad61e3..324651d97 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -2089,19 +2089,7 @@ var httpObserver = { }, // https://github.com/gorhill/uBlock/issues/959 - // Try to synthesize a pending request from a behind-the-scene request. - synthesizePendingRequest: function(channel, rawtype) { - var tabId = this.tabIdFromChannel(channel); - if ( tabId === vAPI.noTabId ) { - return null; - } - return { - frameId: 0, - parentFrameId: -1, - tabId: tabId, - rawtype: rawtype - }; - }, + syntheticPendingRequest: { frameId: 0, parentFrameId: -1, tabId: '', rawtype: 1 }, handleRequest: function(channel, URI, details) { var type = this.typeMap[details.rawtype] || 'other'; @@ -2244,37 +2232,28 @@ var httpObserver = { } } - // IMPORTANT: - // If this is a main frame, ensure that the proper tab id is being - // used: it can happen that the wrong tab id was looked up at - // `shouldLoadListener` time. Without this, the popup blocker may - // not work properly, and also a tab opened from a link may end up - // being wrongly reported as an embedded element. - if ( pendingRequest !== null && pendingRequest.rawtype === 6 ) { - var tabId = this.tabIdFromChannel(channel); - if ( tabId !== vAPI.noTabId ) { - pendingRequest.tabId = tabId; + if ( pendingRequest !== null ) { + // https://github.com/gorhill/uBlock/issues/654 + // Use the request type from the HTTP observer point of view. + if ( rawtype !== 1 ) { + pendingRequest.rawtype = rawtype; } - } - - // Behind-the-scene request... Really? - if ( pendingRequest === null ) { - pendingRequest = this.synthesizePendingRequest(channel, rawtype); - } - - // Behind-the-scene request... Yes, really. - if ( pendingRequest === null ) { - pendingRequest = { - frameId: 0, - parentFrameId: -1, - tabId: vAPI.noTabId, - rawtype: rawtype - }; - } - - // https://github.com/gorhill/uBlock/issues/654 - // Use the request type from the HTTP observer point of view. - if ( rawtype !== 1 ) { + // IMPORTANT: + // If this is a main frame, ensure that the proper tab id is being + // used: it can happen that the wrong tab id was looked up at + // `shouldLoadListener` time. Without this, the popup blocker may + // not work properly, and also a tab opened from a link may end up + // being wrongly reported as an embedded element. + if ( pendingRequest.rawtype === 6 ) { + var tabId = this.tabIdFromChannel(channel); + if ( tabId !== vAPI.noTabId ) { + pendingRequest.tabId = tabId; + } + } + } else { // pendingRequest === null + // No matching pending request found, synthetize one. + pendingRequest = this.syntheticPendingRequest; + pendingRequest.tabId = this.tabIdFromChannel(channel); pendingRequest.rawtype = rawtype; } @@ -2401,8 +2380,8 @@ vAPI.net.registerListeners = function() { // request into a ring buffer for later retrieval by the HTTP observer. var pendingReq = httpObserver.createPendingRequest(details.url); pendingReq.frameId = details.frameId; - pendingReq.parentFrameId = details.parentFrameId; - pendingReq.rawtype = details.rawtype; + pendingReq.parentFrameId = details.pFrameId; + pendingReq.rawtype = details.type; pendingReq.tabId = tabWatcher.tabIdFromTarget(e.target); }; diff --git a/src/js/contentscript.js b/src/js/contentscript.js index ef65718e1..799f23091 100644 --- a/src/js/contentscript.js +++ b/src/js/contentscript.js @@ -1516,7 +1516,7 @@ vAPI.executionCost.stop('domIsLoaded'); /******************************************************************************/ if ( document.readyState !== 'loading' ) { - domIsLoaded(); + window.requestAnimationFrame(domIsLoaded); } else { document.addEventListener('DOMContentLoaded', domIsLoaded); }