Browse Source

firefox: draft work for fixing #165

pull/2/head
gorhill 10 years ago
parent
commit
2cd6961ed4
  1. 32
      platform/firefox/frameModule.js
  2. 105
      platform/firefox/vapi-background.js

32
platform/firefox/frameModule.js

@ -55,7 +55,6 @@ const contentObserver = {
MAIN_FRAME: Ci.nsIContentPolicy.TYPE_DOCUMENT, MAIN_FRAME: Ci.nsIContentPolicy.TYPE_DOCUMENT,
contentBaseURI: 'chrome://' + hostName + '/content/js/', contentBaseURI: 'chrome://' + hostName + '/content/js/',
cpMessageName: hostName + ':shouldLoad', cpMessageName: hostName + ':shouldLoad',
ignoredPopups: new WeakMap(),
uniqueSandboxId: 1, uniqueSandboxId: 1,
get componentRegistrar() { get componentRegistrar() {
@ -120,6 +119,7 @@ const contentObserver = {
// https://bugzil.la/612921 // https://bugzil.la/612921
shouldLoad: function(type, location, origin, context) { shouldLoad: function(type, location, origin, context) {
/*
if ( !context ) { if ( !context ) {
return this.ACCEPT; return this.ACCEPT;
} }
@ -128,15 +128,8 @@ const contentObserver = {
return this.ACCEPT; return this.ACCEPT;
} }
let openerURL = null;
if ( type === this.MAIN_FRAME ) { if ( type === this.MAIN_FRAME ) {
context = context.contentWindow || context; context = context.contentWindow || context;
if ( context.opener && context.opener !== context
&& this.ignoredPopups.has(context) === false ) {
openerURL = context.opener.location.href;
}
} else if ( type === 7 ) { // SUB_DOCUMENT } else if ( type === 7 ) { // SUB_DOCUMENT
context = context.contentWindow; context = context.contentWindow;
} else { } else {
@ -163,7 +156,6 @@ const contentObserver = {
let messageManager = getMessageManager(context); let messageManager = getMessageManager(context);
let details = { let details = {
frameId: isTopLevel ? 0 : this.getFrameId(context), frameId: isTopLevel ? 0 : this.getFrameId(context),
openerURL: openerURL,
parentFrameId: parentFrameId, parentFrameId: parentFrameId,
type: type, type: type,
url: location.spec url: location.spec
@ -176,7 +168,7 @@ const contentObserver = {
// Compatibility for older versions // Compatibility for older versions
messageManager.sendSyncMessage(this.cpMessageName, details); messageManager.sendSyncMessage(this.cpMessageName, details);
} }
*/
return this.ACCEPT; return this.ACCEPT;
}, },
@ -247,17 +239,6 @@ const contentObserver = {
return sandbox; return sandbox;
}, },
ignorePopup: function(e) {
if ( e.isTrusted === false ) {
return;
}
let contObs = contentObserver;
contObs.ignoredPopups.set(this, true);
this.removeEventListener('keydown', contObs.ignorePopup, true);
this.removeEventListener('mousedown', contObs.ignorePopup, true);
},
observe: function(doc) { observe: function(doc) {
let win = doc.defaultView; let win = doc.defaultView;
@ -265,11 +246,6 @@ const contentObserver = {
return; return;
} }
if ( win.opener && this.ignoredPopups.has(win) === false ) {
win.addEventListener('keydown', this.ignorePopup, true);
win.addEventListener('mousedown', this.ignorePopup, true);
}
let loc = win.location; let loc = win.location;
if ( loc.protocol !== 'http:' && loc.protocol !== 'https:' && loc.protocol !== 'file:' ) { if ( loc.protocol !== 'http:' && loc.protocol !== 'https:' && loc.protocol !== 'file:' ) {
@ -291,10 +267,6 @@ const contentObserver = {
let doc = e.target; let doc = e.target;
doc.removeEventListener(e.type, docReady, true); doc.removeEventListener(e.type, docReady, true);
lss(this.contentBaseURI + 'contentscript-end.js', sandbox); lss(this.contentBaseURI + 'contentscript-end.js', sandbox);
if ( doc.querySelector('a[href^="abp:"]') ) {
lss(this.contentBaseURI + 'subscriber.js', sandbox);
}
}; };
if ( doc.readyState === 'loading') { if ( doc.readyState === 'loading') {

105
platform/firefox/vapi-background.js

@ -1027,7 +1027,6 @@ var httpObserver = {
16: 'websocket', 16: 'websocket',
21: 'image' 21: 'image'
}, },
lastRequest: [{}, {}],
get componentRegistrar() { get componentRegistrar() {
return Components.manager.QueryInterface(Ci.nsIComponentRegistrar); return Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
@ -1104,9 +1103,8 @@ var httpObserver = {
var type = this.typeMap[details.type] || 'other'; var type = this.typeMap[details.type] || 'other';
var result; var result;
var callbackDetails = { var callbackDetails = {
frameId: details.frameId,
hostname: URI.asciiHost, hostname: URI.asciiHost,
parentFrameId: details.parentFrameId,
parentFrameId: type === 'main_frame' ? -1 : 0,
tabId: details.tabId, tabId: details.tabId,
type: type, type: type,
url: URI.asciiSpec url: URI.asciiSpec
@ -1172,7 +1170,7 @@ var httpObserver = {
return; return;
} }
type = this.frameTypeMap[channelData[4]];
type = this.frameTypeMap[channelData[1]];
if ( !type ) { if ( !type ) {
return; return;
} }
@ -1187,10 +1185,10 @@ var httpObserver = {
result = vAPI.net.onHeadersReceived.callback({ result = vAPI.net.onHeadersReceived.callback({
hostname: URI.asciiHost, hostname: URI.asciiHost,
parentFrameId: channelData[1],
parentFrameId: type === 6 ? -1 : 0,
responseHeaders: result ? [{name: topic, value: result}] : [], responseHeaders: result ? [{name: topic, value: result}] : [],
tabId: channelData[3],
type: type,
tabId: channelData[0],
type: this.typeMap[type] || 'other',
url: URI.asciiSpec url: URI.asciiSpec
}); });
@ -1207,22 +1205,42 @@ var httpObserver = {
// http-on-opening-request // http-on-opening-request
var lastRequest = this.lastRequest[0];
if ( lastRequest.url !== URI.spec ) {
if ( this.lastRequest[1].url === URI.spec ) {
lastRequest = this.lastRequest[1];
} else {
lastRequest.url = null;
// https://github.com/gorhill/uMatrix/issues/165
// https://developer.mozilla.org/en-US/Firefox/Releases/3.5/Updating_extensions#Getting_a_load_context_from_a_request
// Not sure `umatrix:shouldLoad` is still needed, uMatrix does not
// care about embedded frames topography.
var tabId = vAPI.noTabId;
var loadCtx;
try {
loadCtx = channel
.QueryInterface(Components.interfaces.nsIChannel)
.notificationCallbacks
.getInterface(Components.interfaces.nsILoadContext);
} catch (ex) {
try {
loadCtx = channel
.loadGroup.notificationCallbacks
.getInterface(Components.interfaces.nsILoadContext);
} catch (ex) {
}
} }
if ( loadCtx && loadCtx.associatedWindow ) {
tabId = vAPI.tabs.getTabId(
loadCtx
.associatedWindow
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell)
.rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow)
.gBrowser
.getBrowserForContentWindow(loadCtx.associatedWindow)
);
} }
if ( lastRequest.url === null ) {
lastRequest.type = channel.loadInfo && channel.loadInfo.contentPolicyType || 1;
result = this.handleRequest(channel, URI, {
tabId: vAPI.noTabId,
type: lastRequest.type
});
type = channel.loadInfo && channel.loadInfo.contentPolicyType || 1;
result = this.handleRequest(channel, URI, { tabId: tabId, type: type });
if ( result === true ) { if ( result === true ) {
return; return;
@ -1233,31 +1251,8 @@ var httpObserver = {
} }
// Carry data for behind-the-scene redirects // Carry data for behind-the-scene redirects
channel.setProperty(
this.REQDATAKEY,
[lastRequest.type, vAPI.noTabId, null, 0, -1]
);
channel.setProperty(this.REQDATAKEY, [tabId, type]);
return; return;
}
// Important! When loading file via XHR for mirroring,
// the URL will be the same, so it could fall into an infinite loop
lastRequest.url = null;
if ( this.handleRequest(channel, URI, lastRequest) ) {
return;
}
// If request is not handled we may use the data in on-modify-request
if ( channel instanceof Ci.nsIWritablePropertyBag ) {
channel.setProperty(this.REQDATAKEY, [
lastRequest.frameId,
lastRequest.parentFrameId,
lastRequest.sourceTabId,
lastRequest.tabId,
lastRequest.type
]);
}
}, },
// contentPolicy.shouldLoad doesn't detect redirects, this needs to be used // contentPolicy.shouldLoad doesn't detect redirects, this needs to be used
@ -1279,10 +1274,8 @@ var httpObserver = {
var channelData = oldChannel.getProperty(this.REQDATAKEY); var channelData = oldChannel.getProperty(this.REQDATAKEY);
var details = { var details = {
frameId: channelData[0],
parentFrameId: channelData[1],
tabId: channelData[3],
type: channelData[4]
tabId: channelData[0],
type: channelData[1]
}; };
if ( this.handleRequest(newChannel, URI, details) ) { if ( this.handleRequest(newChannel, URI, details) ) {
@ -1317,21 +1310,7 @@ vAPI.net.registerListeners = function() {
null; null;
var shouldLoadListenerMessageName = location.host + ':shouldLoad'; var shouldLoadListenerMessageName = location.host + ':shouldLoad';
var shouldLoadListener = function(e) {
var details = e.data;
var tabId = vAPI.tabs.getTabId(e.target);
var sourceTabId = null;
var lastRequest = httpObserver.lastRequest;
lastRequest[1] = lastRequest[0];
lastRequest[0] = {
frameId: details.frameId,
parentFrameId: details.parentFrameId,
sourceTabId: sourceTabId,
tabId: tabId,
type: details.type,
url: details.url
};
};
var shouldLoadListener = function(e) { };
vAPI.messaging.globalMessageManager.addMessageListener( vAPI.messaging.globalMessageManager.addMessageListener(
shouldLoadListenerMessageName, shouldLoadListenerMessageName,

Loading…
Cancel
Save