mirror of https://github.com/gorhill/uBlock.git
Merge branch 'master' of github.com:gorhill/uBlock
This commit is contained in:
commit
91e143008f
|
@ -23,10 +23,12 @@
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
this.EXPORTED_SYMBOLS = ['contentObserver'];
|
||||
this.EXPORTED_SYMBOLS = ['contentObserver', 'LocationChangeListener'];
|
||||
|
||||
const {interfaces: Ci, utils: Cu} = Components;
|
||||
const {Services} = Cu.import('resource://gre/modules/Services.jsm', null);
|
||||
const {XPCOMUtils} = Cu.import('resource://gre/modules/XPCOMUtils.jsm', null);
|
||||
|
||||
const hostName = Services.io.newURI(Components.stack.filename, null, null).host;
|
||||
|
||||
// Cu.import('resource://gre/modules/devtools/Console.jsm');
|
||||
|
@ -65,16 +67,12 @@ const contentObserver = {
|
|||
.getService(Ci.nsICategoryManager);
|
||||
},
|
||||
|
||||
QueryInterface: (function() {
|
||||
let {XPCOMUtils} = Cu.import('resource://gre/modules/XPCOMUtils.jsm', null);
|
||||
|
||||
return XPCOMUtils.generateQI([
|
||||
QueryInterface: XPCOMUtils.generateQI([
|
||||
Ci.nsIFactory,
|
||||
Ci.nsIObserver,
|
||||
Ci.nsIContentPolicy,
|
||||
Ci.nsISupportsWeakReference
|
||||
]);
|
||||
})(),
|
||||
]),
|
||||
|
||||
createInstance: function(outer, iid) {
|
||||
if ( outer ) {
|
||||
|
@ -312,6 +310,36 @@ 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,13 +21,15 @@
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
var locationChangeListener; // Keep alive while frameScript is alive
|
||||
|
||||
(function() {
|
||||
|
||||
'use strict';
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
let {contentObserver} = Components.utils.import(
|
||||
let {contentObserver, LocationChangeListener} = Components.utils.import(
|
||||
Components.stack.filename.replace('Script', 'Module'),
|
||||
null
|
||||
);
|
||||
|
@ -54,6 +56,8 @@ let onLoadCompleted = function() {
|
|||
|
||||
addMessageListener('ublock-load-completed', onLoadCompleted);
|
||||
|
||||
locationChangeListener = new LocationChangeListener(docShell);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
})();
|
||||
|
|
|
@ -295,11 +295,9 @@ var windowWatcher = {
|
|||
if ( tabBrowser.deck ) {
|
||||
// Fennec
|
||||
tabContainer = tabBrowser.deck;
|
||||
tabContainer.addEventListener('DOMTitleChanged', tabWatcher.onFennecLocationChange);
|
||||
} else if ( tabBrowser.tabContainer ) {
|
||||
// desktop Firefox
|
||||
tabContainer = tabBrowser.tabContainer;
|
||||
tabBrowser.addTabsProgressListener(tabWatcher);
|
||||
vAPI.contextMenu.register(this.document);
|
||||
} else {
|
||||
return;
|
||||
|
@ -321,8 +319,6 @@ 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);
|
||||
|
@ -331,68 +327,8 @@ var tabWatcher = {
|
|||
},
|
||||
|
||||
onTabSelect: function({target}) {
|
||||
// target is tab in Firefox, browser in Fennec
|
||||
var browser = (target.linkedBrowser || target);
|
||||
var URI = browser.currentURI;
|
||||
var aboutPath = URI.schemeIs('about') && URI.path;
|
||||
var tabId = vAPI.tabs.getTabId(target);
|
||||
|
||||
if ( !aboutPath || (aboutPath !== 'blank' && aboutPath !== 'newtab') ) {
|
||||
vAPI.setIcon(tabId, getOwnerWindow(target));
|
||||
return;
|
||||
}
|
||||
|
||||
if ( browser.webNavigation.busyFlags === 0 /*BUSY_FLAGS_NONE*/ ) {
|
||||
vAPI.tabs.onNavigation({
|
||||
frameId: 0,
|
||||
tabId: tabId,
|
||||
url: URI.asciiSpec
|
||||
});
|
||||
}
|
||||
vAPI.setIcon(vAPI.tabs.getTabId(target), 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}, {
|
||||
frameId: 0,
|
||||
tabId: tabId,
|
||||
url: browser.currentURI.asciiSpec
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// https://github.com/gorhill/uBlock/issues/105
|
||||
// Allow any kind of pages
|
||||
vAPI.tabs.onNavigation({
|
||||
frameId: 0,
|
||||
tabId: tabId,
|
||||
url: location.asciiSpec
|
||||
});
|
||||
},
|
||||
|
||||
onFennecLocationChange: function({target: doc}) {
|
||||
// Fennec "equivalent" to onLocationChange
|
||||
// note that DOMTitleChanged is selected as it fires very early
|
||||
// (before DOMContentLoaded), and it does fire even if there is no title
|
||||
var win = doc.defaultView;
|
||||
if ( win !== win.top ) {
|
||||
return;
|
||||
}
|
||||
|
||||
vAPI.tabs.onNavigation({
|
||||
frameId: 0,
|
||||
tabId: vAPI.tabs.getTabId(getOwnerWindow(win).BrowserApp.getTabForWindow(win)),
|
||||
url: Services.io.newURI(win.location.href, null, null).asciiSpec
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -444,7 +380,6 @@ vAPI.tabs = {};
|
|||
/******************************************************************************/
|
||||
|
||||
vAPI.tabs.registerListeners = function() {
|
||||
// onNavigation and onUpdated handled with tabWatcher.onLocationChange
|
||||
// onClosed - handled in tabWatcher.onTabClose
|
||||
// onPopup - handled in httpObserver.handlePopup
|
||||
|
||||
|
@ -470,10 +405,8 @@ vAPI.tabs.registerListeners = function() {
|
|||
if ( tabBrowser.deck ) {
|
||||
// Fennec
|
||||
tabContainer = tabBrowser.deck;
|
||||
tabContainer.removeEventListener('DOMTitleChanged', tabWatcher.onFennecLocationChange);
|
||||
} else if ( tabBrowser.tabContainer ) {
|
||||
tabContainer = tabBrowser.tabContainer;
|
||||
tabBrowser.removeTabsProgressListener(tabWatcher);
|
||||
}
|
||||
|
||||
tabContainer.removeEventListener('TabClose', tabWatcher.onTabClose);
|
||||
|
@ -1264,14 +1197,6 @@ var httpObserver = {
|
|||
return;
|
||||
}
|
||||
|
||||
if ( vAPI.fennec && lastRequest.type === this.MAIN_FRAME ) {
|
||||
vAPI.tabs.onNavigation({
|
||||
frameId: 0,
|
||||
tabId: lastRequest.tabId,
|
||||
url: URI.asciiSpec
|
||||
});
|
||||
}
|
||||
|
||||
// If request is not handled we may use the data in on-modify-request
|
||||
if ( channel instanceof Ci.nsIWritablePropertyBag ) {
|
||||
channel.setProperty(this.REQDATAKEY, [
|
||||
|
@ -1396,6 +1321,38 @@ vAPI.net.registerListeners = function() {
|
|||
shouldLoadListener
|
||||
);
|
||||
|
||||
var locationChangedListenerMessageName = location.host + ':locationChanged';
|
||||
var locationChangedListener = function(e) {
|
||||
var details = e.data;
|
||||
var browser = e.target;
|
||||
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}, {
|
||||
frameId: 0,
|
||||
tabId: tabId,
|
||||
url: browser.currentURI.asciiSpec
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// https://github.com/gorhill/uBlock/issues/105
|
||||
// Allow any kind of pages
|
||||
vAPI.tabs.onNavigation({
|
||||
frameId: 0,
|
||||
tabId: tabId,
|
||||
url: details.url,
|
||||
});
|
||||
};
|
||||
|
||||
vAPI.messaging.globalMessageManager.addMessageListener(
|
||||
locationChangedListenerMessageName,
|
||||
locationChangedListener
|
||||
);
|
||||
|
||||
httpObserver.register();
|
||||
|
||||
cleanupTasks.push(function() {
|
||||
|
@ -1404,6 +1361,11 @@ vAPI.net.registerListeners = function() {
|
|||
shouldLoadListener
|
||||
);
|
||||
|
||||
vAPI.messaging.globalMessageManager.removeMessageListener(
|
||||
locationChangedListenerMessageName,
|
||||
locationChangedListener
|
||||
);
|
||||
|
||||
httpObserver.unregister();
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue