diff options
-rw-r--r-- | Redirector.csproj | 4 | ||||
-rw-r--r-- | Redirector.sln | 2 | ||||
-rw-r--r-- | chrome.manifest | 1 | ||||
-rw-r--r-- | chrome/content/help.html | 9 | ||||
-rw-r--r-- | chrome/content/overlay.js | 8 | ||||
-rw-r--r-- | chrome/content/overlay.xul | 1 | ||||
-rw-r--r-- | chrome/content/redirect.xul | 1 | ||||
-rw-r--r-- | chrome/content/redirectList.js | 18 | ||||
-rw-r--r-- | chrome/content/redirectList.xul | 5 | ||||
-rw-r--r-- | chrome/locale/en-US/redirector.properties | 1 | ||||
-rw-r--r-- | chrome/skin/overlay.css | 1 | ||||
-rw-r--r-- | components/redirector.js | 602 |
12 files changed, 331 insertions, 322 deletions
diff --git a/Redirector.csproj b/Redirector.csproj index 493850f..ef3b3fd 100644 --- a/Redirector.csproj +++ b/Redirector.csproj @@ -1,4 +1,5 @@ -<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
+<!-- $Id$ -->
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -52,7 +53,6 @@ <Content Include="chrome\content\redirector.png" />
<Content Include="chrome\content\statusactive.PNG" />
<Content Include="chrome\content\statusinactive.PNG" />
- <Content Include="chrome\skin\overlay.css" />
<Content Include="components\redirector.js" />
<Content Include="defaults\preferences\redirector.js" />
</ItemGroup>
diff --git a/Redirector.sln b/Redirector.sln index a61c861..11e33d9 100644 --- a/Redirector.sln +++ b/Redirector.sln @@ -1,4 +1,4 @@ -
+# $Id$
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Redirector", "Redirector.csproj", "{1C962CCA-74DC-4F72-8C83-7617F2275D1A}"
diff --git a/chrome.manifest b/chrome.manifest index a64fc76..f3fbf82 100644 --- a/chrome.manifest +++ b/chrome.manifest @@ -1,5 +1,4 @@ # $Id$ content redirector file:chrome/content/ locale redirector en-US file:chrome/locale/en-US/ -skin redirector classic/1.0 file:chrome/skin/ overlay chrome://browser/content/browser.xul chrome://redirector/content/overlay.xul
\ No newline at end of file diff --git a/chrome/content/help.html b/chrome/content/help.html index e74048e..0ce6769 100644 --- a/chrome/content/help.html +++ b/chrome/content/help.html @@ -1,3 +1,4 @@ +<!-- $Id$ -->
<html>
<head>
<title>Redirector Help</title>
@@ -18,7 +19,6 @@ <li><a href="#excludepattern">Exclude pattern</a></li>
<li><a href="#redirectto">Redirect to</a></li>
<li><a href="#patterntype">Pattern type</a></li>
- <li><a href="#onlyiflinkexists">Only if link exists</a></li>
</ul>
</li>
<li><a href="#wildcards">Wildcards</a></li>
@@ -49,7 +49,7 @@ <h4>Basic usage</h4>
<p>To add a new redirect you can go to the <em>Tools</em> menuitem and select <em>Redirector</em>. That will
open the <em>Redirector settings</em> window which shows all your redirects. The window can also be opened
- by right clicking on the <strong>R</strong> icon in your statusbar and selecting <em>Manage redirects</em>.
+ by right clicking on the <strong>R</strong> icon in your statusbar.
There you can press the <em>Add...</em> button and then you can enter the details for the new redirect. A redirect
consists of a few things:
<ul>
@@ -75,11 +75,6 @@ <li><a name="patterntype"></a><strong>Pattern type:</strong> This specifies how Redirector should interpret the patterns, either as
<a href="#wildcards">wildcards</a> or <a href="#regularexpressions#">regular expressions</a>.</li>
- <li><a name="onlyiflinkexists"></a><strong>Only if link exists:</strong> If this is checked then the redirect will only happen if there is a link
- to the target page on the page that matches the include pattern. For instance, if you have a redirect from http://foo.com to
- http://bar.com and check <em>Only if link exists</em> then http://foo.com has to have a hyperlink to http://bar.com, otherwise
- nothing will happen.
- </li>
</ul>
</p>
diff --git a/chrome/content/overlay.js b/chrome/content/overlay.js index 46f69cc..760f828 100644 --- a/chrome/content/overlay.js +++ b/chrome/content/overlay.js @@ -117,8 +117,6 @@ var RedirectorOverlay = { } }, - - prefObserver : { getService : function() { @@ -138,11 +136,7 @@ var RedirectorOverlay = { RedirectorOverlay.setStatusBarImg(); } } - } - - }; window.addEventListener("load", function(event) { RedirectorOverlay.onLoad(event); }, false); -window.addEventListener("DOMContentLoaded", function(event) { RedirectorOverlay.onDOMContentLoaded(event); }, true); -window.addEventListener("unload", function(event) { RedirectorOverlay.onUnload(event); }, false);
\ No newline at end of file +window.addEventListener("unload", function(event) { RedirectorOverlay.onUnload(event); }, false); diff --git a/chrome/content/overlay.xul b/chrome/content/overlay.xul index f46bfcf..9c4619e 100644 --- a/chrome/content/overlay.xul +++ b/chrome/content/overlay.xul @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- $Id$ --> -<?xml-stylesheet href="chrome://redirector/skin/overlay.css" type="text/css"?> <!DOCTYPE overlay SYSTEM "chrome://redirector/locale/redirector.dtd"> <overlay id="redirector-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> diff --git a/chrome/content/redirect.xul b/chrome/content/redirect.xul index e808fc4..aea930b 100644 --- a/chrome/content/redirect.xul +++ b/chrome/content/redirect.xul @@ -1,4 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?>
+<!-- $Id$ -->
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<!DOCTYPE dialog SYSTEM "chrome://redirector/locale/redirect.dtd">
<dialog title="&redirectWindow.title;"
diff --git a/chrome/content/redirectList.js b/chrome/content/redirectList.js index c50583b..cd8c550 100644 --- a/chrome/content/redirectList.js +++ b/chrome/content/redirectList.js @@ -1,5 +1,8 @@ +//// $Id$ var Redirector = Components.classes["@einaregilsson.com/redirector;1"].getService(Components.interfaces.nsISupports).wrappedJSObject; +const Cc = Components.classes; +const Ci = Components.interfaces; function $(id) { return document.getElementById(id); @@ -45,6 +48,21 @@ var RedirectList = { } }, + openHelp : function() {
+ var windowName = "redirectorHelp";
+ var windowsMediator = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
+ var win;
+ var iter = windowsMediator.getEnumerator(null);
+ while (iter.hasMoreElements()) {
+ win = iter.getNext();
+ if (win.name == windowName) {
+ win.focus();
+ return;
+ }
+ }
+ window.openDialog("chrome://redirector/content/help.html", windowName, "chrome,dialog,resizable=yes,location=0,toolbar=0,status=0,width=800px,height=600px,centerscreen", this);
+ },
+ close : function() { window.close(); }, diff --git a/chrome/content/redirectList.xul b/chrome/content/redirectList.xul index 630c364..f43a0b1 100644 --- a/chrome/content/redirectList.xul +++ b/chrome/content/redirectList.xul @@ -1,4 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?>
+<!-- $Id -->
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<!DOCTYPE dialog SYSTEM "chrome://redirector/locale/redirectList.dtd">
<window title="&window.title;"
@@ -41,9 +42,11 @@ <button id="btnEdit" onclick="RedirectList.editRedirect();" label="&btnEdit.label;" disabled="true" />
<button id="btnDelete" onclick="RedirectList.deleteRedirect();" label="&btnDelete.label;" disabled="true" />
<button id="btnClose" onclick="RedirectList.close();" label="&btnClose.label;"/>
- <button id="btnHelp" onclick="Redirector.openHelp();" label="&btnHelp.label;"/>
+ <button id="btnHelp" onclick="RedirectList.openHelp();" label="&btnHelp.label;"/>
+ <!-- TODO: include in v2.0
<button id="btnUp" onclick="RedirectList.moveUp();" label="UP" disabled="false" />
<button id="btnDown" onclick="RedirectList.moveDown();" label="Down" />
+ -->
</hbox>
</vbox>
</window>
diff --git a/chrome/locale/en-US/redirector.properties b/chrome/locale/en-US/redirector.properties index bac0d6c..f884575 100644 --- a/chrome/locale/en-US/redirector.properties +++ b/chrome/locale/en-US/redirector.properties @@ -1,3 +1,4 @@ +# $Id$ initError=Failed to initialize %S. extensions.redirector@einaregilsson.com.description=Automatically redirects to user-defined urls on certain pages extensionName=Redirector diff --git a/chrome/skin/overlay.css b/chrome/skin/overlay.css deleted file mode 100644 index b670fa5..0000000 --- a/chrome/skin/overlay.css +++ /dev/null @@ -1 +0,0 @@ -/* Include your overlay stylings here */
\ No newline at end of file diff --git a/components/redirector.js b/components/redirector.js index 4c962ee..6949cdb 100644 --- a/components/redirector.js +++ b/components/redirector.js @@ -1,119 +1,119 @@ - -const CSSB_CONTRACTID = "@einaregilsson.com/redirector;1"; -const CSSB_CID = Components.ID("{b7a7a54f-0581-47ff-b086-d6920cb7a3f7}"); - -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cr = Components.results; -const kRedirectorWildcard = 'W'; -const kRedirectorRegex= 'R'; - -const nsIContentPolicy = Ci.nsIContentPolicy; - -function RedirectorPolicy() { - this.prefBranch = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService).getBranch("extensions.redirector."); - - //Check if we need to update existing redirects - - var data = this.prefBranch.getCharPref('redirects'); - var version = this.prefBranch.getCharPref('version'); - this.debugEnabled = this.prefBranch.getBoolPref('debug'); - this.enabled = this.prefBranch.getBoolPref('enabled'); - this.loadStrings(); - //Here update checks are handled - if (version == 'undefined') { //Either a fresh install of Redirector, or first time install of v2.0 - if (data) { //There is some data in redirects, we are upgrading from a previous version, need to upgrade data - var tempList = eval(data); - var arr; - var newArr = [] - for each (arr in tempList) { - if (arr.length == 5) { - arr.push(''); //For those that don't have an exclude pattern. Backwards compatibility is a bitch! - } - arr.splice(3,1); //Remove the "only if link exists" data - newArr.push(arr.join(',,,')); - } - this.prefBranch.setCharPref('redirects', newArr.join(':::')); - } - this.prefBranch.setCharPref('version', '2.0'); - } - //Update finished - - //Now get from the new format - data = this.prefBranch.getCharPref('redirects'); - var arr; - this.list = []; - for each (redirectString in data.split(':::')) { - arr = redirectString.split(',,,'); - this.list.push({ - exampleUrl : arr[0], - pattern : arr[1], - redirectUrl : arr[2], - patternType : arr[3], - excludePattern : arr[4] - }); - } -} - -RedirectorPolicy.prototype = { +//// $Id$
+const CSSB_CONTRACTID = "@einaregilsson.com/redirector;1";
+const CSSB_CID = Components.ID("{b7a7a54f-0581-47ff-b086-d6920cb7a3f7}");
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cr = Components.results;
+const kRedirectorWildcard = 'W';
+const kRedirectorRegex= 'R';
+
+const nsIContentPolicy = Ci.nsIContentPolicy;
+
+function RedirectorPolicy() {
+ this.prefBranch = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService).getBranch("extensions.redirector.");
+
+ //Check if we need to update existing redirects
+
+ var data = this.prefBranch.getCharPref('redirects');
+ var version = this.prefBranch.getCharPref('version');
+ this.debugEnabled = this.prefBranch.getBoolPref('debug');
+ this.enabled = this.prefBranch.getBoolPref('enabled');
+ this.loadStrings();
+ //Here update checks are handled
+ if (version == 'undefined') { //Either a fresh install of Redirector, or first time install of v2.0
+ if (data) { //There is some data in redirects, we are upgrading from a previous version, need to upgrade data
+ var tempList = eval(data);
+ var arr;
+ var newArr = []
+ for each (arr in tempList) {
+ if (arr.length == 5) {
+ arr.push(''); //For those that don't have an exclude pattern. Backwards compatibility is a bitch!
+ }
+ arr.splice(3,1); //Remove the "only if link exists" data
+ newArr.push(arr.join(',,,'));
+ }
+ this.prefBranch.setCharPref('redirects', newArr.join(':::'));
+ }
+ this.prefBranch.setCharPref('version', '2.0');
+ }
+ //Update finished
+
+ //Now get from the new format
+ data = this.prefBranch.getCharPref('redirects');
+ var arr;
+ this.list = [];
+ for each (redirectString in data.split(':::')) {
+ arr = redirectString.split(',,,');
+ this.list.push({
+ exampleUrl : arr[0],
+ pattern : arr[1],
+ redirectUrl : arr[2],
+ patternType : arr[3],
+ excludePattern : arr[4]
+ });
+ }
+}
+
+RedirectorPolicy.prototype = {
prefBranch : null,
list : null,
- strings : null, - - loadStrings : function() { + strings : null,
+
+ loadStrings : function() {
var src = 'chrome://redirector/locale/redirector.properties';
var localeService = Cc["@mozilla.org/intl/nslocaleservice;1"].getService(Ci.nsILocaleService);
var appLocale = localeService.getApplicationLocale();
var stringBundleService = Cc["@mozilla.org/intl/stringbundle;1"].getService(Ci.nsIStringBundleService);
- this.strings = stringBundleService.createBundle(src, appLocale); - }, - - debug : function(msg) { - if (this.debugEnabled) { - dump("REDIRECTOR: " + msg + "\n"); - } - }, - - // nsIContentPolicy interface implementation - shouldLoad: function(contentType, contentLocation, requestOrigin, aContext, mimeTypeGuess, extra) { - if (!this.enabled) { - return nsIContentPolicy.ACCEPT; - } - if (contentLocation.scheme != "http" && contentLocation.scheme != "https") { - return nsIContentPolicy.ACCEPT; - } - - if (contentType != nsIContentPolicy.TYPE_DOCUMENT && contentType != nsIContentPolicy.TYPE_SUBDOCUMENT) { - return nsIContentPolicy.ACCEPT; - } - - if (!aContext || !aContext.loadURI) { - return nsIContentPolicy.ACCEPT; - } - this.debug("CHECK: " + contentLocation.spec + "\n"); - - var url = contentLocation.spec; - - for each (var redirect in this.list) { - var redirectUrl = this.getRedirectUrl(url, redirect); - if (redirectUrl) { - redirectUrl = this.makeAbsoluteUrl(url, redirectUrl); - aContext.loadURI(redirectUrl, requestOrigin, null); - return nsIContentPolicy.REJECT_REQUEST; - } - } - return nsIContentPolicy.ACCEPT; - }, - - shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode, mimeType, extra) { - return nsIContentPolicy.ACCEPT; - }, - - setEnabled : function(val) { - this.enabled = val; - this.prefBranch.setBoolPref('enabled', val); - }, - + this.strings = stringBundleService.createBundle(src, appLocale);
+ },
+
+ debug : function(msg) {
+ if (this.debugEnabled) {
+ dump("REDIRECTOR: " + msg + "\n");
+ }
+ },
+
+ // nsIContentPolicy interface implementation
+ shouldLoad: function(contentType, contentLocation, requestOrigin, aContext, mimeTypeGuess, extra) {
+ if (!this.enabled) {
+ return nsIContentPolicy.ACCEPT;
+ }
+ if (contentLocation.scheme != "http" && contentLocation.scheme != "https") {
+ return nsIContentPolicy.ACCEPT;
+ }
+
+ if (contentType != nsIContentPolicy.TYPE_DOCUMENT && contentType != nsIContentPolicy.TYPE_SUBDOCUMENT) {
+ return nsIContentPolicy.ACCEPT;
+ }
+
+ if (!aContext || !aContext.loadURI) {
+ return nsIContentPolicy.ACCEPT;
+ }
+ this.debug("CHECK: " + contentLocation.spec + "\n");
+
+ var url = contentLocation.spec;
+
+ for each (var redirect in this.list) {
+ var redirectUrl = this.getRedirectUrl(url, redirect);
+ if (redirectUrl) {
+ redirectUrl = this.makeAbsoluteUrl(url, redirectUrl);
+ aContext.loadURI(redirectUrl, requestOrigin, null);
+ return nsIContentPolicy.REJECT_REQUEST;
+ }
+ }
+ return nsIContentPolicy.ACCEPT;
+ },
+
+ shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode, mimeType, extra) {
+ return nsIContentPolicy.ACCEPT;
+ },
+
+ setEnabled : function(val) {
+ this.enabled = val;
+ this.prefBranch.setBoolPref('enabled', val);
+ },
+
addRedirect : function(redirect) {
this.list.push(redirect);
this.save();
@@ -138,201 +138,201 @@ RedirectorPolicy.prototype = { return this.prefBranch.getBoolPref(name);
},
- regexMatch : function(pattern, text, redirectUrl) { - - if (!pattern) { - return null; - } - var strings, rx, match; - try { - rx = new RegExp(pattern, 'gi'); - match = rx.exec(text); - } catch(e) { - this.msgBox(this.strings.GetStringFromName('extensionName'), this.strings.formatStringFromName('regexPatternError', [pattern, e.toString()],2)); - return null; - } - - var rxrepl; - - if (match) { - for (var i = 1; i < match.length; i++) { - rxrepl = new RegExp('\\$' + i, 'gi'); - redirectUrl = redirectUrl.replace(rxrepl, match[i]); - } - return redirectUrl; - } - - return null; - - }, + regexMatch : function(pattern, text, redirectUrl) {
+
+ if (!pattern) {
+ return null;
+ }
+ var strings, rx, match;
+ try {
+ rx = new RegExp(pattern, 'gi');
+ match = rx.exec(text);
+ } catch(e) {
+ this.msgBox(this.strings.GetStringFromName('extensionName'), this.strings.formatStringFromName('regexPatternError', [pattern, e.toString()],2));
+ return null;
+ }
+
+ var rxrepl;
+
+ if (match) {
+ for (var i = 1; i < match.length; i++) {
+ rxrepl = new RegExp('\\$' + i, 'gi');
+ redirectUrl = redirectUrl.replace(rxrepl, match[i]);
+ }
+ return redirectUrl;
+ }
+
+ return null;
+
+ },
msgBox : function(title, text) {
Cc["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Ci.nsIPromptService)
.alert(null, title, text);
},
- - getRedirectUrl: function(url, redirect) { - - if (redirect.patternType == kRedirectorWildcard) { - if (this.wildcardMatch(redirect.excludePattern, url, 'whatever')) { - this.debug(url + ' matches exclude pattern ' + redirect.excludePattern); - return null; - } - return this.wildcardMatch(redirect.pattern, url, redirect.redirectUrl); - } else if (redirect.patternType == kRedirectorRegex) { - if (this.regexMatch(redirect.excludePattern, url, 'whatever')) { - this.debug(url + ' matches exclude pattern ' + redirect.excludePattern); - return null; - } - return this.regexMatch(redirect.pattern, url, redirect.redirectUrl); - } - return null; - }, - - makeAbsoluteUrl : function(currentUrl, relativeUrl) { - - if (relativeUrl.match(/https?:/)) { - return relativeUrl; - } - - var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); - //this.debug(currentUrl); - var uri = ioService.newURI(currentUrl, null, null); - - return uri.resolve(relativeUrl); - }, - - wildcardMatch : function(pattern, text, redirectUrl) { - var parts - , part - , i - , pos - , originalText - , stars; - - if (!pattern) { - return null; - } - parts = pattern.split('*'); - - stars = []; - originalText = text; - var starStart = -1; - - for (i in parts) { - - part = parts[i]; - - pos = text.lastIndexOf(part); - - if (pos == -1) { - return null; - } - - if (i == 0 && pos != 0) { - return null; - } - - if (i == parts.length -1 && i != "" && text.substr(text.length - part.length) != part) { - return null; - - } - - if (i == 0) { - //Do nothing, part will be added on next run - } else if (i == parts.length-1 && parts[i] == '') { - stars.push(text); - } else { - stars.push(text.substr(0, pos)); - } - - text = text.substr(pos + part.length); - } - - for (var i = 1; i <= stars.length; i++) { - redirectUrl = redirectUrl.replace(new RegExp('\\$' + i, 'gi'), stars[i-1]); - } - - return redirectUrl; - } -}; - -/* - * Factory object - */ - -var redirectorInstance = null; - -const factory = { - // nsIFactory interface implementation - createInstance: function(outer, iid) { - if (outer != null) { - Components.returnCode = Cr.NS_ERROR_NO_AGGREGATION; - return null; - } - - if (!iid.equals(Ci.nsIContentPolicy) && - !iid.equals(Ci.nsISupports)) { - Components.returnCode = Cr.NS_ERROR_NO_INTERFACE; - return null; - } - - if(!redirectorInstance) { - redirectorInstance = new RedirectorPolicy(); - redirectorInstance.wrappedJSObject = redirectorInstance; - } - - return redirectorInstance; - }, - - // nsISupports interface implementation - QueryInterface: function(iid) { - if (iid.equals(Ci.nsISupports) || - iid.equals(Ci.nsIModule) || - iid.equals(Ci.nsIFactory)) { - return this; - } - Components.returnCode = Cr.NS_ERROR_NO_INTERFACE; - return null; - } -} - - -/* - * Module object - */ -const module = { - registerSelf: function(compMgr, fileSpec, location, type) { - compMgr = compMgr.QueryInterface(Ci.nsIComponentRegistrar); - compMgr.registerFactoryLocation(CSSB_CID, - "Redirector content policy", - CSSB_CONTRACTID, - fileSpec, location, type); - - var catman = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager); - catman.addCategoryEntry("content-policy", CSSB_CONTRACTID, CSSB_CONTRACTID, true, true); - }, - - unregisterSelf: function(compMgr, fileSpec, location) { - compMgr.QueryInterface(Ci.nsIComponentRegistrar).unregisterFactoryLocation(CSSB_CID, fileSpec); - Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager).deleteCategoryEntry("content-policy", CSSB_CONTRACTID, true); - }, - - getClassObject: function(compMgr, cid, iid) { - if (cid.equals(CSSB_CID)) { - return factory; - } - - Components.returnCode = Cr.NS_ERROR_NOT_REGISTERED; - return null; - }, - - canUnload: function(compMgr) { - return true; - } -}; - -function NSGetModule(comMgr, fileSpec) { - return module; +
+ getRedirectUrl: function(url, redirect) {
+
+ if (redirect.patternType == kRedirectorWildcard) {
+ if (this.wildcardMatch(redirect.excludePattern, url, 'whatever')) {
+ this.debug(url + ' matches exclude pattern ' + redirect.excludePattern);
+ return null;
+ }
+ return this.wildcardMatch(redirect.pattern, url, redirect.redirectUrl);
+ } else if (redirect.patternType == kRedirectorRegex) {
+ if (this.regexMatch(redirect.excludePattern, url, 'whatever')) {
+ this.debug(url + ' matches exclude pattern ' + redirect.excludePattern);
+ return null;
+ }
+ return this.regexMatch(redirect.pattern, url, redirect.redirectUrl);
+ }
+ return null;
+ },
+
+ makeAbsoluteUrl : function(currentUrl, relativeUrl) {
+
+ if (relativeUrl.match(/https?:/)) {
+ return relativeUrl;
+ }
+
+ var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
+ //this.debug(currentUrl);
+ var uri = ioService.newURI(currentUrl, null, null);
+
+ return uri.resolve(relativeUrl);
+ },
+
+ wildcardMatch : function(pattern, text, redirectUrl) {
+ var parts
+ , part
+ , i
+ , pos
+ , originalText
+ , stars;
+
+ if (!pattern) {
+ return null;
+ }
+ parts = pattern.split('*');
+
+ stars = [];
+ originalText = text;
+ var starStart = -1;
+
+ for (i in parts) {
+
+ part = parts[i];
+
+ pos = text.lastIndexOf(part);
+
+ if (pos == -1) {
+ return null;
+ }
+
+ if (i == 0 && pos != 0) {
+ return null;
+ }
+
+ if (i == parts.length -1 && i != "" && text.substr(text.length - part.length) != part) {
+ return null;
+
+ }
+
+ if (i == 0) {
+ //Do nothing, part will be added on next run
+ } else if (i == parts.length-1 && parts[i] == '') {
+ stars.push(text);
+ } else {
+ stars.push(text.substr(0, pos));
+ }
+
+ text = text.substr(pos + part.length);
+ }
+
+ for (var i = 1; i <= stars.length; i++) {
+ redirectUrl = redirectUrl.replace(new RegExp('\\$' + i, 'gi'), stars[i-1]);
+ }
+
+ return redirectUrl;
+ }
+};
+
+/*
+ * Factory object
+ */
+
+var redirectorInstance = null;
+
+const factory = {
+ // nsIFactory interface implementation
+ createInstance: function(outer, iid) {
+ if (outer != null) {
+ Components.returnCode = Cr.NS_ERROR_NO_AGGREGATION;
+ return null;
+ }
+
+ if (!iid.equals(Ci.nsIContentPolicy) &&
+ !iid.equals(Ci.nsISupports)) {
+ Components.returnCode = Cr.NS_ERROR_NO_INTERFACE;
+ return null;
+ }
+
+ if(!redirectorInstance) {
+ redirectorInstance = new RedirectorPolicy();
+ redirectorInstance.wrappedJSObject = redirectorInstance;
+ }
+
+ return redirectorInstance;
+ },
+
+ // nsISupports interface implementation
+ QueryInterface: function(iid) {
+ if (iid.equals(Ci.nsISupports) ||
+ iid.equals(Ci.nsIModule) ||
+ iid.equals(Ci.nsIFactory)) {
+ return this;
+ }
+ Components.returnCode = Cr.NS_ERROR_NO_INTERFACE;
+ return null;
+ }
+}
+
+
+/*
+ * Module object
+ */
+const module = {
+ registerSelf: function(compMgr, fileSpec, location, type) {
+ compMgr = compMgr.QueryInterface(Ci.nsIComponentRegistrar);
+ compMgr.registerFactoryLocation(CSSB_CID,
+ "Redirector content policy",
+ CSSB_CONTRACTID,
+ fileSpec, location, type);
+
+ var catman = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
+ catman.addCategoryEntry("content-policy", CSSB_CONTRACTID, CSSB_CONTRACTID, true, true);
+ },
+
+ unregisterSelf: function(compMgr, fileSpec, location) {
+ compMgr.QueryInterface(Ci.nsIComponentRegistrar).unregisterFactoryLocation(CSSB_CID, fileSpec);
+ Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager).deleteCategoryEntry("content-policy", CSSB_CONTRACTID, true);
+ },
+
+ getClassObject: function(compMgr, cid, iid) {
+ if (cid.equals(CSSB_CID)) {
+ return factory;
+ }
+
+ Components.returnCode = Cr.NS_ERROR_NOT_REGISTERED;
+ return null;
+ },
+
+ canUnload: function(compMgr) {
+ return true;
+ }
+};
+
+function NSGetModule(comMgr, fileSpec) {
+ return module;
}
\ No newline at end of file |