Remove onNavigation from onTabSelect, as mentioned in #1125

pull/2/head
AlexVallat 10 years ago committed by gorhill
parent 882d1d9425
commit a0b86f7d25

@ -298,7 +298,6 @@ var windowWatcher = {
} else if ( tabBrowser.tabContainer ) { } else if ( tabBrowser.tabContainer ) {
// desktop Firefox // desktop Firefox
tabContainer = tabBrowser.tabContainer; tabContainer = tabBrowser.tabContainer;
tabBrowser.addTabsProgressListener(tabWatcher);
vAPI.contextMenu.register(this.document); vAPI.contextMenu.register(this.document);
} else { } else {
return; return;
@ -320,8 +319,6 @@ var windowWatcher = {
/******************************************************************************/ /******************************************************************************/
var tabWatcher = { var tabWatcher = {
SAME_DOCUMENT: Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT,
onTabClose: function({target}) { onTabClose: function({target}) {
// target is tab in Firefox, browser in Fennec // target is tab in Firefox, browser in Fennec
var tabId = vAPI.tabs.getTabId(target); var tabId = vAPI.tabs.getTabId(target);
@ -349,32 +346,6 @@ var tabWatcher = {
}); });
} }
}, },
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
});
},
}; };
/******************************************************************************/ /******************************************************************************/
@ -426,7 +397,6 @@ vAPI.tabs = {};
/******************************************************************************/ /******************************************************************************/
vAPI.tabs.registerListeners = function() { vAPI.tabs.registerListeners = function() {
// onNavigation and onUpdated handled with tabWatcher.onLocationChange
// onClosed - handled in tabWatcher.onTabClose // onClosed - handled in tabWatcher.onTabClose
// onPopup - handled in httpObserver.handlePopup // onPopup - handled in httpObserver.handlePopup
@ -691,24 +661,6 @@ vAPI.tabs.open = function(details) {
/******************************************************************************/ /******************************************************************************/
// Replace the URL of a tab. Noop if the tab does not exist.
vAPI.tabs.replace = function(tabId, url) {
var targetURL = url;
// extension pages
if ( /^[\w-]{2,}:/.test(targetURL) !== true ) {
targetURL = vAPI.getURL(targetURL);
}
var tab = this.getTabsForIds(tabId);
if ( tab ) {
getBrowserForTab(tab).loadURI(targetURL);
}
};
/******************************************************************************/
vAPI.tabs._remove = function(tab, tabBrowser) { vAPI.tabs._remove = function(tab, tabBrowser) {
if ( vAPI.fennec ) { if ( vAPI.fennec ) {
tabBrowser.closeTab(tab); tabBrowser.closeTab(tab);
@ -1137,13 +1089,18 @@ var httpObserver = {
return true; return true;
} }
/*if ( result.redirectUrl ) { if ( result.redirectUrl ) {
channel.redirectionLimit = 1; if ( type === 'main_frame' ) {
channel.cancel(this.ABORT);
vAPI.tabs.open({ tabId: details.tabId, url: result.redirectUrl });
return true;
}
/*channel.redirectionLimit = 1;
channel.redirectTo( channel.redirectTo(
Services.io.newURI(result.redirectUrl, null, null) Services.io.newURI(result.redirectUrl, null, null)
); );
return true; return true;*/
}*/ }
return false; return false;
}, },
@ -1245,14 +1202,6 @@ var httpObserver = {
return; 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 request is not handled we may use the data in on-modify-request
if ( channel instanceof Ci.nsIWritablePropertyBag ) { if ( channel instanceof Ci.nsIWritablePropertyBag ) {
channel.setProperty(this.REQDATAKEY, [ channel.setProperty(this.REQDATAKEY, [
@ -1367,9 +1316,6 @@ vAPI.net.registerListeners = function() {
type: details.type, type: details.type,
url: details.url url: details.url
}; };
if ( details.attrSrc !== undefined ) {
lastRequest[0].attrSrc = details.attrSrc;
}
}; };
vAPI.messaging.globalMessageManager.addMessageListener( vAPI.messaging.globalMessageManager.addMessageListener(
@ -1377,6 +1323,38 @@ vAPI.net.registerListeners = function() {
shouldLoadListener 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(); httpObserver.register();
cleanupTasks.push(function() { cleanupTasks.push(function() {
@ -1385,6 +1363,11 @@ vAPI.net.registerListeners = function() {
shouldLoadListener shouldLoadListener
); );
vAPI.messaging.globalMessageManager.removeMessageListener(
locationChangedListenerMessageName,
locationChangedListener
);
httpObserver.unregister(); httpObserver.unregister();
}); });
}; };

Loading…
Cancel
Save