aboutsummaryrefslogtreecommitdiff
path: root/chrome/content/code/redirect.js
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/content/code/redirect.js')
-rw-r--r--chrome/content/code/redirect.js241
1 files changed, 131 insertions, 110 deletions
diff --git a/chrome/content/code/redirect.js b/chrome/content/code/redirect.js
index e65ca50..2be8fc9 100644
--- a/chrome/content/code/redirect.js
+++ b/chrome/content/code/redirect.js
@@ -1,5 +1,7 @@
//// $Id$
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
function Redirect(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, disabled) {
this._init(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, disabled);
}
@@ -9,33 +11,145 @@ Redirect.WILDCARD = 'W';
Redirect.REGEX = 'R';
Redirect.prototype = {
-
- //These are the only ones that are necessary to have as properties for now
- //The others can be changed to properties later as neccessary
- _includePattern : null,
- _excludePattern : null,
- _patternType : null,
- _rxInclude : null,
- _rxExclude : null,
-
- get patternType() { return this._patternType; },
- set patternType(value) {
- this._patternType = value;
- this.compile();
- },
+ // rdIRedirect implementation
+
+ //attributes
+ exampleUrl : null,
+
get includePattern() { return this._includePattern; },
set includePattern(value) {
this._includePattern = value;
this._rxInclude = this._compile(value);
},
-
+
get excludePattern() { return this._excludePattern; },
set excludePattern(value) {
this._excludePattern = value;
this._rxExclude = this._compile(value);
},
+ redirectTo : null,
+
+ get patternType() { return this._patternType; },
+ set patternType(value) {
+ this._patternType = value;
+ this.compile();
+ },
+
+ unescapeMatches : false,
+
+ disabled : false,
+
+ //Functions
+ clone : function() {
+ return new Redirect(this.exampleUrl, this.includePattern,
+ this.redirectUrl, this.patternType,
+ this.excludePattern, this.unescapeMatches,
+ this.disabled);
+ },
+
+ compile : function() {
+ this._rxInclude = this._compile(this._includePattern);
+ this._rxExclude = this._compile(this._excludePattern);
+ },
+
+ copyValues : function(other) {
+ this.exampleUrl = other.exampleUrl;
+ this.includePattern = other.includePattern;
+ this.excludePattern = other.excludePattern;
+ this.redirectUrl = other.redirectUrl;
+ this.patternType = other.patternType;
+ this.unescapeMatches = other.unescapeMatches;
+ this.disabled = other.disabled;
+ },
+
+ deserialize : function(str) {
+ if (!str || !str.split) {
+ throw Error("Invalid serialized redirect: " + str);
+ }
+ var parts = str.split(',,,');
+ if (parts.length < 5) {
+ throw Error("Invalid serialized redirect, too few fields: " + str);
+ }
+ this._init.apply(this, parts);
+ },
+
+ equals : function(redirect) {
+ return this.exampleUrl == redirect.exampleUrl
+ && this.includePattern == redirect.includePattern
+ && this.excludePattern == redirect.excludePattern
+ && this.redirectUrl == redirect.redirectUrl
+ && this.patternType == redirect.patternType
+ && this.unescapeMatches == redirect.unescapeMatches
+ ;
+ },
+
+ getMatch: function(url) {
+ var result = {
+ isMatch : false,
+ isExcludeMatch : false,
+ isDisabledMatch : false,
+ redirectTo : '',
+ toString : function() { return "{ isMatch : " + this.isMatch +
+ ", isExcludeMatch : " + this.isExcludeMatch +
+ ", isDisabledMatch : " + this.isDisabledMatch +
+ ", redirectTo : \"" + this.redirectTo + "\"" +
+ "}"; }
+ };
+ var redirectTo = null;
+
+ redirectTo = this._includeMatch(url);
+ if (redirectTo !== null) {
+ if (this.disabled) {
+ result.isDisabledMatch = true;
+ } else if (this._excludeMatch(url)) {
+ result.isExcludeMatch = true;
+ } else {
+ result.isMatch = true;
+ result.redirectTo = redirectTo;
+ }
+ }
+ return result;
+ },
+
+ isRegex: function() {
+ return this.patternType == Redirect.REGEX;
+ },
+
+ isWildcard : function() {
+ return this.patternType == Redirect.WILDCARD;
+ },
+
+ serialize : function() {
+ return [ this.exampleUrl
+ , this.includePattern
+ , this.redirectUrl
+ , this.patternType
+ , this.excludePattern
+ , this.unescapeMatches
+ , this.disabled ].join(',,,');
+ },
+
+ test : function() {
+ return this.getMatch(this.exampleUrl);
+ },
+
+ //end rdIRedirect
+
+ //nsISupports
+ QueryInterface : XPCOMUtils.generateQI([Components.interfaces.rdIRedirect]),
+
+ //end nsISupports
+
+ //Private functions below
+
+ _includePattern : null,
+ _excludePattern : null,
+ _patternType : null,
+ _rxInclude : null,
+ _rxExclude : null,
+
_preparePattern : function(pattern) {
if (this.patternType == Redirect.REGEX) {
return pattern;
@@ -55,12 +169,7 @@ Redirect.prototype = {
return converted;
}
},
-
- compile : function() {
- this._rxInclude = this._compile(this._includePattern);
- this._rxExclude = this._compile(this._excludePattern);
- },
-
+
_compile : function(pattern) {
if (!pattern) {
return null;
@@ -90,67 +199,6 @@ Redirect.prototype = {
+ '\n}\n';
},
- isWildcard : function() {
- return this.patternType == Redirect.WILDCARD;
- },
-
- isRegex: function() {
- return this.patternType == Redirect.REGEX;
- },
-
- test : function() {
- return this.getMatch(this.exampleUrl);
- },
-
- serialize : function() {
- return [ this.exampleUrl
- , this.includePattern
- , this.redirectUrl
- , this.patternType
- , this.excludePattern
- , this.unescapeMatches
- , this.disabled ].join(',,,');
- },
-
- deserialize : function(str) {
- if (!str || !str.split) {
- throw Error("Invalid serialized redirect: " + str);
- }
- var parts = str.split(',,,');
- if (parts.length < 5) {
- throw Error("Invalid serialized redirect, too few fields: " + str);
- }
- this._init.apply(this, parts);
- },
-
- getMatch: function(url) {
- var result = {
- isMatch : false,
- isExcludeMatch : false,
- isDisabledMatch : false,
- redirectTo : '',
- toString : function() { return "{ isMatch : " + this.isMatch +
- ", isExcludeMatch : " + this.isExcludeMatch +
- ", isDisabledMatch : " + this.isDisabledMatch +
- ", redirectTo : \"" + this.redirectTo + "\"" +
- "}"; }
- };
- var redirectTo = null;
-
- redirectTo = this._includeMatch(url);
- if (redirectTo !== null) {
- if (this.disabled) {
- result.isDisabledMatch = true;
- } else if (this._excludeMatch(url)) {
- result.isExcludeMatch = true;
- } else {
- result.isMatch = true;
- result.redirectTo = redirectTo;
- }
- }
- return result;
- },
-
_includeMatch : function(url) {
if (!this._rxInclude) {
return null;
@@ -174,32 +222,5 @@ Redirect.prototype = {
var shouldExclude = !!this._rxExclude.exec(url);
this._rxExclude.lastIndex = 0;
return shouldExclude;
- },
-
- clone : function() {
- return new Redirect(this.exampleUrl, this.includePattern,
- this.redirectUrl, this.patternType,
- this.excludePattern, this.unescapeMatches,
- this.disabled);
- },
-
- copyValues : function(other) {
- this.exampleUrl = other.exampleUrl;
- this.includePattern = other.includePattern;
- this.excludePattern = other.excludePattern;
- this.redirectUrl = other.redirectUrl;
- this.patternType = other.patternType;
- this.unescapeMatches = other.unescapeMatches;
- this.disabled = other.disabled;
- },
-
- equals : function(redirect) {
- return this.exampleUrl == redirect.exampleUrl
- && this.includePattern == redirect.includePattern
- && this.excludePattern == redirect.excludePattern
- && this.redirectUrl == redirect.redirectUrl
- && this.patternType == redirect.patternType
- && this.unescapeMatches == redirect.unescapeMatches
- ;
- }
+ }
}; \ No newline at end of file