aboutsummaryrefslogtreecommitdiff
path: root/chrome
diff options
context:
space:
mode:
authorEinar Egilsson2009-10-16 07:23:54 +0000
committerEinar Egilsson2009-10-16 07:23:54 +0000
commit6177295e1d9a9ebba5acc68df4800d8557b22cab (patch)
tree66a670cd5f54f6ee06d2ecb06c7751cee4463e85 /chrome
parent9266c7831e5e4d0f4e123bd62e6cc0a2d114038f (diff)
Before using XPCOMUtils
git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@269 119bf307-c92d-0410-89bd-8f53e6181181
Diffstat (limited to 'chrome')
-rw-r--r--chrome/content/code/redirector.prototype.js62
-rw-r--r--chrome/content/log.html7
2 files changed, 61 insertions, 8 deletions
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) + '<br>';
+ if (document) {
+ document.body.innerHTML += msg.message.substr(prefix.length) + '<br>';
+ } else {
+ //Been destroyed and we're still getting message, lets try to unsubscribe...
+ try { unload(); } catch(e) {}
+ }
}
}
};