diff options
author | Einar Egilsson | 2009-10-16 09:15:44 +0000 |
---|---|---|
committer | Einar Egilsson | 2009-10-16 09:15:44 +0000 |
commit | b5ad01ad2749fcaa4b2fac94d22bd4f2c7f98ad4 (patch) | |
tree | e63430d85f75b8273f8c267c99355d47be50a790 | |
parent | ccaccd42afdf9f24b615542c8760e1bf663d2373 (diff) |
Redirecting after 30x redirects now works !
git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@272 119bf307-c92d-0410-89bd-8f53e6181181
-rw-r--r-- | chrome/content/code/redirector.prototype.js | 30 |
1 files changed, 27 insertions, 3 deletions
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)) {
|