From b5ad01ad2749fcaa4b2fac94d22bd4f2c7f98ad4 Mon Sep 17 00:00:00 2001 From: Einar Egilsson Date: Fri, 16 Oct 2009 09:15:44 +0000 Subject: Redirecting after 30x redirects now works ! git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@272 119bf307-c92d-0410-89bd-8f53e6181181 --- chrome/content/code/redirector.prototype.js | 30 ++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'chrome/content/code') diff --git a/chrome/content/code/redirector.prototype.js b/chrome/content/code/redirector.prototype.js index f954c5f..74f7e61 100644 --- a/chrome/content/code/redirector.prototype.js +++ b/chrome/content/code/redirector.prototype.js @@ -121,20 +121,44 @@ Redirector.prototype = { }, //nsIChannelEventSink interface implementation + //Mostly borrowed from the excellent Adblock Plus extension onChannelRedirect: function(oldChannel, newChannel, flags) { try { let newLocation = newChannel.URI.spec; + if (!(newChannel.loadFlags & Ci.nsIChannel.LOAD_DOCUMENT_URI)) { + //We only redirect documents... + return; + } if (!newLocation) { return; } - + let callbacks = []; + if (newChannel.notificationCallbacks) { + callbacks.push(newChannel.notificationCallbacks); + } + if (newChannel.loadGroup && newChannel.loadGroup.notificationCallbacks) { + callbacks.push(newChannel.loadGroup.notificationCallbacks); + } + var win; + var webNav; + for each (let callback in callbacks) + { + try { + win = callback.getInterface(Ci.nsILoadContext).associatedWindow; + webNav = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation); + break; + } catch(e) {} + } + if (!webNav) { + return; + } var redirectUrl = this.getRedirectUrl(newLocation); if (redirectUrl) { - throw Cr.NS_BASE_STREAM_WOULD_BLOCK; - //TODO: Get window + webNav.loadURI(redirectUrl,null,null,null,null); + throw Cr.NS_BASE_STREAM_WOULD_BLOCK; //Throw this because the real error we should throw shows up in console... } } catch (e if (e != Cr.NS_BASE_STREAM_WOULD_BLOCK)) { -- cgit v1.2.3-70-g09d2