From 6177295e1d9a9ebba5acc68df4800d8557b22cab Mon Sep 17 00:00:00 2001
From: Einar Egilsson
Date: Fri, 16 Oct 2009 07:23:54 +0000
Subject: Before using XPCOMUtils
git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@269 119bf307-c92d-0410-89bd-8f53e6181181
---
chrome/content/code/redirector.prototype.js | 62 +++++++++++++++++++++++++----
chrome/content/log.html | 7 +++-
2 files changed, 61 insertions(+), 8 deletions(-)
(limited to 'chrome')
diff --git a/chrome/content/code/redirector.prototype.js b/chrome/content/code/redirector.prototype.js
index b69a52f..979e9f7 100644
--- a/chrome/content/code/redirector.prototype.js
+++ b/chrome/content/code/redirector.prototype.js
@@ -70,6 +70,7 @@ Redirector.prototype = {
// nsIContentPolicy interface implementation
shouldLoad: function(contentType, contentLocation, requestOrigin, aContext, mimeTypeGuess, extra) {
try {
+
if (!this.prefs.enabled) {
return nsIContentPolicy.ACCEPT;
}
@@ -90,7 +91,6 @@ Redirector.prototype = {
var url = contentLocation.spec;
for each (var redirect in this.list) {
- //this.debug(redirect);
var result = redirect.getMatch(url);
if (result.isExcludeMatch) {
this.debug(url + ' matched exclude pattern ' + redirect.excludePattern + ' so the redirect ' + redirect.includePattern + ' will not be used');
@@ -114,6 +114,60 @@ Redirector.prototype = {
return nsIContentPolicy.ACCEPT;
},
+ //nsIChannelEventSink interface implementation
+ onChannelRedirect: function(oldChannel, newChannel, flags)
+ {
+ dump("****************** HI THERE ****************************");
+ //throw Cr.NS_BASE_STREAM_WOULD_BLOCK;
+/*
+ try {
+ let oldLocation = null;
+ let newLocation = null;
+ try {
+ oldLocation = oldChannel.originalURI.spec;
+ newLocation = newChannel.URI.spec;
+ }
+ catch(e2) {}
+
+ if (!oldLocation || !newLocation || oldLocation == newLocation)
+ return;
+
+ // Look for the request both in the origin window and in its parent (for frames)
+ let contexts = [getRequestWindow(newChannel)];
+ if (!contexts[0])
+ contexts.pop();
+ else if (contexts[0] && contexts[0].parent != contexts[0])
+ contexts.push(contexts[0].parent);
+
+ let info = null;
+ for each (let context in contexts)
+ {
+ // Did we record the original request in its own window?
+ let data = RequestList.getDataForWindow(context, true);
+ if (data)
+ info = data.getURLInfo(oldLocation);
+
+ if (info)
+ {
+ let nodes = info.nodes;
+ let node = (nodes.length > 0 ? nodes[nodes.length - 1] : context.document);
+
+ // HACK: NS_BINDING_ABORTED would be proper error code to throw but this will show up in error console (bug 287107)
+ if (!this.processNode(context, node, info.type, newChannel.URI))
+ throw Cr.NS_BASE_STREAM_WOULD_BLOCK;
+ else
+ return;
+ }
+ }
+ }
+ catch (e if (e != Cr.NS_BASE_STREAM_WOULD_BLOCK))
+ {
+ // We shouldn't throw exceptions here - this will prevent the redirect.
+ dump("Adblock Plus: Unexpected error in policy.onChannelRedirect: " + e + "\n");
+ }
+ */
+ },
+
reload : function() {
loader.loadSubScript('chrome://redirector/content/code/redirector.prototype.js');
loader.loadSubScript('chrome://redirector/content/code/redirect.js');
@@ -185,12 +239,6 @@ Redirector.prototype = {
containsRedirect : function(redirect) {
for each (var existing in this.list) {
- this.debug("EXAMPLEURL: " + (redirect.exampleUrl == existing.exampleUrl));
- this.debug("INCLUDEPATTERN: " + (redirect.includePattern == existing.includePattern));
- this.debug("EXCLUDEPATTERN: " + (redirect.excludePattern == existing.excludePattern));
- this.debug("unescape: " + (redirect.unescapeMatches == existing.unescapeMatches));
- this.debug("REDIRECTTO: " + (redirect.redirectUrl == existing.redirectUrl));
- this.debug("PATTERNTYPE: " + (redirect.patternType == existing.patternType));
if (existing.equals(redirect)) {
return true;
}
diff --git a/chrome/content/log.html b/chrome/content/log.html
index a70d9f4..a4f04d1 100644
--- a/chrome/content/log.html
+++ b/chrome/content/log.html
@@ -13,7 +13,12 @@
var prefix = 'REDIRECTOR:';
if (msg.message.substr(0, prefix.length) == prefix)
{
- document.body.innerHTML += msg.message.substr(prefix.length) + '
';
+ if (document) {
+ document.body.innerHTML += msg.message.substr(prefix.length) + '
';
+ } else {
+ //Been destroyed and we're still getting message, lets try to unsubscribe...
+ try { unload(); } catch(e) {}
+ }
}
}
};
--
cgit v1.2.3-70-g09d2