mirror of
https://github.com/gorhill/uMatrix.git
synced 2024-09-30 00:56:32 +13:00
this fixes #189: reverted changes from 6123335c51
This commit is contained in:
parent
276d48a00c
commit
4ab8f52b44
3 changed files with 52 additions and 89 deletions
|
@ -23,7 +23,7 @@
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
this.EXPORTED_SYMBOLS = ['contentObserver', 'LocationChangeListener'];
|
||||
this.EXPORTED_SYMBOLS = ['contentObserver'];
|
||||
|
||||
const {interfaces: Ci, utils: Cu} = Components;
|
||||
const {Services} = Cu.import('resource://gre/modules/Services.jsm', null);
|
||||
|
@ -223,36 +223,6 @@ const contentObserver = {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
const locationChangedMessageName = hostName + ':locationChanged';
|
||||
|
||||
const LocationChangeListener = function(docShell) {
|
||||
if (docShell) {
|
||||
docShell.QueryInterface(Ci.nsIInterfaceRequestor);
|
||||
|
||||
this.docShell = docShell.getInterface(Ci.nsIWebProgress);
|
||||
this.messageManager = docShell.getInterface(Ci.nsIContentFrameMessageManager);
|
||||
|
||||
if (this.messageManager && typeof this.messageManager.sendAsyncMessage === 'function') {
|
||||
this.docShell.addProgressListener(this, Ci.nsIWebProgress.NOTIFY_LOCATION);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
LocationChangeListener.prototype.QueryInterface = XPCOMUtils.generateQI(["nsIWebProgressListener", "nsISupportsWeakReference"]);
|
||||
|
||||
LocationChangeListener.prototype.onLocationChange = function(webProgress, request, location, flags) {
|
||||
if ( !webProgress.isTopLevel ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.messageManager.sendAsyncMessage(locationChangedMessageName, {
|
||||
url: location.asciiSpec,
|
||||
flags: flags,
|
||||
});
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
contentObserver.register();
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -21,15 +21,13 @@
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
var locationChangeListener; // Keep alive while frameScript is alive
|
||||
|
||||
(function() {
|
||||
|
||||
'use strict';
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
let {contentObserver, LocationChangeListener} = Components.utils.import(
|
||||
let {contentObserver} = Components.utils.import(
|
||||
Components.stack.filename.replace('Script', 'Module'),
|
||||
null
|
||||
);
|
||||
|
@ -56,8 +54,6 @@ let onLoadCompleted = function() {
|
|||
|
||||
addMessageListener('umatrix-load-completed', onLoadCompleted);
|
||||
|
||||
locationChangeListener = new LocationChangeListener(docShell);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
})();
|
||||
|
|
|
@ -77,7 +77,7 @@ vAPI.app.restart = function() {
|
|||
|
||||
// https://stackoverflow.com/questions/6715571/how-to-get-result-of-console-trace-as-string-in-javascript-with-chrome-or-fire/28118170#28118170
|
||||
/*
|
||||
function getStackTrace () {
|
||||
function logStackTrace(msg) {
|
||||
var stack;
|
||||
try {
|
||||
throw new Error('');
|
||||
|
@ -86,7 +86,11 @@ function getStackTrace () {
|
|||
stack = error.stack || '';
|
||||
}
|
||||
stack = stack.split('\n').map(function(line) { return line.trim(); });
|
||||
return stack.splice(stack[0] == 'Error' ? 2 : 1);
|
||||
stack.shift();
|
||||
if ( msg ) {
|
||||
stack.unshift(msg);
|
||||
}
|
||||
console.log(stack.join('\n'));
|
||||
}
|
||||
*/
|
||||
/******************************************************************************/
|
||||
|
@ -323,23 +327,17 @@ var windowWatcher = {
|
|||
return;
|
||||
}
|
||||
|
||||
var tabContainer;
|
||||
var tabBrowser = getTabBrowser(this);
|
||||
|
||||
if ( !tabBrowser ) {
|
||||
if ( !tabBrowser || !tabBrowser.tabContainer ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( tabBrowser.tabContainer ) {
|
||||
// desktop Firefox
|
||||
tabContainer = tabBrowser.tabContainer;
|
||||
vAPI.contextMenu.register(this.document);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
var tabContainer = tabBrowser.tabContainer;
|
||||
|
||||
tabContainer.addEventListener('TabClose', tabWatcher.onTabClose);
|
||||
tabContainer.addEventListener('TabSelect', tabWatcher.onTabSelect);
|
||||
tabBrowser.addTabsProgressListener(tabWatcher);
|
||||
vAPI.contextMenu.register(this.document);
|
||||
|
||||
// when new window is opened TabSelect doesn't run on the selected tab?
|
||||
},
|
||||
|
@ -354,6 +352,8 @@ var windowWatcher = {
|
|||
/******************************************************************************/
|
||||
|
||||
var tabWatcher = {
|
||||
SAME_DOCUMENT: Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT,
|
||||
|
||||
onTabClose: function({target}) {
|
||||
// target is tab in Firefox, browser in Fennec
|
||||
var tabId = vAPI.tabs.getTabId(target);
|
||||
|
@ -370,6 +370,30 @@ var tabWatcher = {
|
|||
return;
|
||||
}
|
||||
vAPI.setIcon(tabId, getOwnerWindow(target));
|
||||
},
|
||||
|
||||
onLocationChange: function(browser, webProgress, request, location, flags) {
|
||||
if ( !webProgress.isTopLevel ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var tabId = vAPI.tabs.getTabId(browser);
|
||||
|
||||
// LOCATION_CHANGE_SAME_DOCUMENT = "did not load a new document"
|
||||
if ( flags & this.SAME_DOCUMENT ) {
|
||||
vAPI.tabs.onUpdated(tabId, {url: location.asciiSpec}, {
|
||||
tabId: tabId,
|
||||
url: browser.currentURI.asciiSpec
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// https://github.com/gorhill/uBlock/issues/105
|
||||
// Allow any kind of pages
|
||||
vAPI.tabs.onNavigation({
|
||||
tabId: tabId,
|
||||
url: location.asciiSpec
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -413,6 +437,7 @@ vAPI.tabs = {};
|
|||
/******************************************************************************/
|
||||
|
||||
vAPI.tabs.registerListeners = function() {
|
||||
// onNavigation and onUpdated handled with tabWatcher.onLocationChange
|
||||
// onClosed - handled in tabWatcher.onTabClose
|
||||
|
||||
for ( var win of this.getWindows() ) {
|
||||
|
@ -510,13 +535,16 @@ vAPI.tabs.getTabsForIds = function(tabIds) {
|
|||
continue;
|
||||
}
|
||||
if ( tabIds.indexOf(tabId) !== -1 ) {
|
||||
if ( singleTab ) {
|
||||
return tab;
|
||||
}
|
||||
tabs.push(tab);
|
||||
}
|
||||
if ( tabs.length >= tabIds.length ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return singleTab ? tabs[0] || null : tabs;
|
||||
return tabs.length !== 0 ? tabs : null;
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -716,7 +744,7 @@ vAPI.tabs.remove = function(tabIds) {
|
|||
tabIds = [tabIds];
|
||||
}
|
||||
var tabs = this.getTabsForIds(tabIds);
|
||||
if ( tabs.length === 0 ) {
|
||||
if ( !tabs ) {
|
||||
return;
|
||||
}
|
||||
for ( var tab of tabs ) {
|
||||
|
@ -1360,40 +1388,9 @@ vAPI.net.registerListeners = function() {
|
|||
new Set(this.onBeforeSendHeaders.types) :
|
||||
null;
|
||||
|
||||
var locationChangedListenerMessageName = location.host + ':locationChanged';
|
||||
var locationChangedListener = function(e) {
|
||||
var details = e.data;
|
||||
var browser = e.target;
|
||||
|
||||
// https://github.com/gorhill/uMatrix/issues/189
|
||||
// getTabId will calls onNavigation() if needed.
|
||||
var tabId = vAPI.tabs.getTabId(browser);
|
||||
|
||||
//console.debug("nsIWebProgressListener: onLocationChange: " + details.url + " (" + details.flags + ")");
|
||||
|
||||
// LOCATION_CHANGE_SAME_DOCUMENT = "did not load a new document"
|
||||
if ( details.flags & Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT ) {
|
||||
vAPI.tabs.onUpdated(tabId, {url: details.url}, {
|
||||
tabId: tabId,
|
||||
url: browser.currentURI.asciiSpec
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
vAPI.messaging.globalMessageManager.addMessageListener(
|
||||
locationChangedListenerMessageName,
|
||||
locationChangedListener
|
||||
);
|
||||
|
||||
httpObserver.register();
|
||||
|
||||
cleanupTasks.push(function() {
|
||||
vAPI.messaging.globalMessageManager.removeMessageListener(
|
||||
locationChangedListenerMessageName,
|
||||
locationChangedListener
|
||||
);
|
||||
|
||||
httpObserver.unregister();
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue