Skip to content

Loading…

Use webProgressListener instead of tabsProgressListener #1135

Merged
merged 9 commits into from

2 participants

@AlexVallat
Collaborator

This fixes #1122 and #1072, and more generally any case when navigation occurs but no http request is made. Further discussion on this change can be found from gorhill/uBlock#1084 (comment)

@AlexVallat AlexVallat referenced this pull request
Closed

Fix for #1122 #1125

@Deathamns
  • tabBrowser.removeTabsProgressListener(tabWatcher); should be removed too
  • Unnecessary return statement in onTabSelect method
  • Missing semicolons after function definitions. LocationChangeListener in frameModule.js, locationChangedListener in vapi-backgorund.js
@AlexVallat
Collaborator

Thanks for the review, I've fixed those issues now

@Deathamns Deathamns merged commit b053f1e into chrisaljoudi:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 26, 2015
  1. @AlexVallat
  2. @AlexVallat

    More restrictive monitoring.

    AlexVallat committed
    Probably doesn't make a difference, but at least theoretically more efficient.
Commits on Mar 30, 2015
  1. @AlexVallat

    Fix for #1122

    AlexVallat committed
  2. @AlexVallat
Commits on Mar 31, 2015
  1. @AlexVallat

    Fix for #1122

    AlexVallat committed
  2. @AlexVallat
  3. @AlexVallat

    Merge branch 'master' of https://github.com/AlexVallat/uBlock

    AlexVallat committed
    Conflicts:
    	platform/firefox/vapi-background.js
  4. @AlexVallat

    Merge branch 'webProgressListener'

    AlexVallat committed
    Conflicts:
    	platform/firefox/vapi-background.js
  5. @AlexVallat

    Changes following review

    AlexVallat committed
This page is out of date. Refresh to see the latest.
Showing with 78 additions and 84 deletions.
  1. +35 −7 platform/firefox/frameModule.js
  2. +5 −1 platform/firefox/frameScript.js
  3. +38 −76 platform/firefox/vapi-background.js
View
42 platform/firefox/frameModule.js
@@ -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();
/******************************************************************************/
View
6 platform/firefox/frameScript.js
@@ -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);
+
/******************************************************************************/
})();
View
114 platform/firefox/vapi-background.js
@@ -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
- });
- }
- },
-
- 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
- });
+ vAPI.setIcon(vAPI.tabs.getTabId(target), getOwnerWindow(target));
},
-
- 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();
});
};
Something went wrong with that request. Please try again.