Browse Source

code review

pull/2/head
gorhill 10 years ago
parent
commit
57de4fdf14
  1. 62
      platform/firefox/frameModule.js
  2. 115
      platform/firefox/vapi-background.js
  3. 6
      src/js/contentscript-end.js
  4. 2
      src/js/contentscript-start.js
  5. 2
      src/js/logger-ui.js

62
platform/firefox/frameModule.js

@ -54,7 +54,6 @@ const contentObserver = {
ACCEPT: Ci.nsIContentPolicy.ACCEPT,
MAIN_FRAME: Ci.nsIContentPolicy.TYPE_DOCUMENT,
contentBaseURI: 'chrome://' + hostName + '/content/js/',
cpMessageName: hostName + ':shouldLoad',
uniqueSandboxId: 1,
get componentRegistrar() {
@ -110,65 +109,8 @@ const contentObserver = {
);
},
getFrameId: function(win) {
return win
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.outerWindowID;
},
// https://bugzil.la/612921
shouldLoad: function(type, location, origin, context) {
/*
if ( !context ) {
return this.ACCEPT;
}
if ( !location.schemeIs('http') && !location.schemeIs('https') ) {
return this.ACCEPT;
}
if ( type === this.MAIN_FRAME ) {
context = context.contentWindow || context;
} else if ( type === 7 ) { // SUB_DOCUMENT
context = context.contentWindow;
} else {
context = (context.ownerDocument || context).defaultView;
}
// The context for the toolbar popup is an iframe element here,
// so check context.top instead of context
if ( !context.top || !context.location ) {
return this.ACCEPT;
}
let isTopLevel = context === context.top;
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 details = {
frameId: isTopLevel ? 0 : this.getFrameId(context),
parentFrameId: parentFrameId,
type: type,
url: location.spec
};
if ( typeof messageManager.sendRpcMessage === 'function' ) {
// https://bugzil.la/1092216
messageManager.sendRpcMessage(this.cpMessageName, details);
} else {
// Compatibility for older versions
messageManager.sendSyncMessage(this.cpMessageName, details);
}
*/
return this.ACCEPT;
},
@ -241,12 +183,14 @@ const contentObserver = {
observe: function(doc) {
let win = doc.defaultView;
if ( !win ) {
return;
}
let loc = win.location;
if ( !loc ) {
return;
}
if ( loc.protocol !== 'http:' && loc.protocol !== 'https:' && loc.protocol !== 'file:' ) {
if ( loc.protocol === 'chrome:' && loc.host === hostName ) {

115
platform/firefox/vapi-background.js

@ -1143,14 +1143,53 @@ var httpObserver = {
},
channelDataFromChannel: function(channel) {
if ( !(channel instanceof Ci.nsIWritablePropertyBag) ) {
return null;
if ( channel instanceof Ci.nsIWritablePropertyBag ) {
try {
return channel.getProperty(this.REQDATAKEY);
} catch (ex) {
}
}
return 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.
tabIdFromChannel: function(channel) {
var aWindow;
if ( channel.notificationCallbacks ) {
try {
aWindow = channel
.notificationCallbacks
.getInterface(Components.interfaces.nsILoadContext)
.associatedWindow;
} catch (ex) {
}
}
try {
return channel.getProperty(this.REQDATAKEY);
if ( !aWindow && channel.loadGroup && channel.loadGroup.notificationCallbacks ) {
aWindow = channel
.loadGroup
.notificationCallbacks
.getInterface(Components.interfaces.nsILoadContext)
.associatedWindow;
}
if ( aWindow ) {
return vAPI.tabs.getTabId(aWindow
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell)
.rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow)
.gBrowser
.getBrowserForContentWindow(aWindow)
);
}
} catch (ex) {
}
return null;
return vAPI.noTabId;
},
observe: function(channel, topic) {
@ -1159,7 +1198,7 @@ var httpObserver = {
}
var URI = channel.URI;
var channelData;
var channelData, tabId, rawtype;
if (
topic === 'http-on-examine-response' ||
@ -1216,51 +1255,8 @@ var httpObserver = {
}
// http-on-opening-request
// 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 aWindow;
if ( channel.notificationCallbacks ) {
try {
aWindow = channel
.notificationCallbacks
.getInterface(Components.interfaces.nsILoadContext)
.associatedWindow;
} catch (ex) {
}
}
if ( !aWindow && channel.loadGroup && channel.loadGroup.notificationCallbacks ) {
try {
aWindow = channel
.loadGroup.notificationCallbacks
.getInterface(Components.interfaces.nsILoadContext)
.associatedWindow;
} catch (ex) {
}
}
if ( aWindow ) {
try {
tabId = vAPI.tabs.getTabId(aWindow
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell)
.rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow)
.gBrowser
.getBrowserForContentWindow(aWindow)
);
} catch (ex) {
}
}
var rawtype = channel.loadInfo && channel.loadInfo.contentPolicyType || 1;
tabId = this.tabIdFromChannel(channel);
rawtype = channel.loadInfo && channel.loadInfo.contentPolicyType || 1;
if ( this.handleRequest(channel, URI, tabId, rawtype) === true ) {
return;
@ -1323,14 +1319,6 @@ vAPI.net.registerListeners = function() {
new Set(this.onBeforeSendHeaders.types) :
null;
var shouldLoadListenerMessageName = location.host + ':shouldLoad';
var shouldLoadListener = function(e) { };
vAPI.messaging.globalMessageManager.addMessageListener(
shouldLoadListenerMessageName,
shouldLoadListener
);
var locationChangedListenerMessageName = location.host + ':locationChanged';
var locationChangedListener = function(e) {
var details = e.data;
@ -1351,11 +1339,7 @@ vAPI.net.registerListeners = function() {
// https://github.com/chrisaljoudi/uBlock/issues/105
// Allow any kind of pages
vAPI.tabs.onNavigation({
frameId: 0,
tabId: tabId,
url: details.url,
});
vAPI.tabs.onNavigation({ frameId: 0, tabId: tabId, url: details.url });
};
vAPI.messaging.globalMessageManager.addMessageListener(
@ -1366,11 +1350,6 @@ vAPI.net.registerListeners = function() {
httpObserver.register();
cleanupTasks.push(function() {
vAPI.messaging.globalMessageManager.removeMessageListener(
shouldLoadListenerMessageName,
shouldLoadListener
);
vAPI.messaging.globalMessageManager.removeMessageListener(
locationChangedListenerMessageName,
locationChangedListener

6
src/js/contentscript-end.js

@ -45,12 +45,6 @@ if ( !vAPI ) {
return;
}
// https://github.com/chrisaljoudi/uBlock/issues/587
// Pointless to execute without the start script having done its job.
if ( !vAPI.contentscriptStartInjected ) {
return;
}
// https://github.com/chrisaljoudi/uBlock/issues/456
// Already injected?
if ( vAPI.contentscriptEndInjected ) {

2
src/js/contentscript-start.js

@ -35,7 +35,7 @@
// https://github.com/chrisaljoudi/uBlock/issues/464
if ( document instanceof HTMLDocument === false ) {
//console.debug('contentscript-start.js > not a HTLMDocument');
return false;
return;
}
// This can happen

2
src/js/logger-ui.js

@ -36,7 +36,7 @@ var trJunkyard = [];
var tdJunkyard = [];
var firstVarDataCol = 2; // currently, column 2 (0-based index)
var lastVarDataIndex = 3; // currently, d0-d3
var maxEntries = 5000;
var maxEntries = 1000;
var noTabId = '';
var allTabIds = {};

Loading…
Cancel
Save