diff options
author | Einar Egilsson | 2009-11-11 07:59:43 +0000 |
---|---|---|
committer | Einar Egilsson | 2009-11-11 07:59:43 +0000 |
commit | 100883d6c539e0fa23b2baec668e4d48cf5d2506 (patch) | |
tree | 618ea301adf91b556bdae2985354578fc4c0f6ec /chrome | |
parent | d8c8ad84b03be92d40f4569b4c1b8a5822dc924d (diff) |
Fixed error when pressing Cancel on the Import file picker.
Converted spaces to tabs on all .js files.
git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@294 119bf307-c92d-0410-89bd-8f53e6181181
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/content/code/browserOverlay.xul.js | 164 | ||||
-rw-r--r-- | chrome/content/code/editRedirect.xul.js | 88 | ||||
-rw-r--r-- | chrome/content/code/prefs.js | 110 | ||||
-rw-r--r-- | chrome/content/code/redirect.js | 58 | ||||
-rw-r--r-- | chrome/content/code/redirector.prototype.js | 354 | ||||
-rw-r--r-- | chrome/content/code/settings.xul.js | 380 |
6 files changed, 577 insertions, 577 deletions
diff --git a/chrome/content/code/browserOverlay.xul.js b/chrome/content/code/browserOverlay.xul.js index 2a6fbac..e194e5f 100644 --- a/chrome/content/code/browserOverlay.xul.js +++ b/chrome/content/code/browserOverlay.xul.js @@ -4,101 +4,101 @@ var Redirector = Components.classes["@einaregilsson.com/redirector;1"].getServic var RedirectorOverlay = { - strings : null, - prefs : null, + strings : null, + prefs : null, - onLoad : function(event) { - try { + onLoad : function(event) { + try { - // initialization code - document.getElementById('contentAreaContextMenu') - .addEventListener("popupshowing", function(e) { RedirectorOverlay.showContextMenu(e); }, false); - - this.strings = document.getElementById("redirector-strings"); - this.prefs = new Prefs(); - this.changedPrefs(this.prefs); - this.prefs.addListener(this); - } catch(e) { - if (this.strings) { - alert(this.strings.getString("initError") + "\n\n" + e); - } else { - alert(e); - } - } - }, - - onUnload : function(event) { - this.prefs.dispose(); - Redirector.debug("Finished cleanup"); - }, + // initialization code + document.getElementById('contentAreaContextMenu') + .addEventListener("popupshowing", function(e) { RedirectorOverlay.showContextMenu(e); }, false); + + this.strings = document.getElementById("redirector-strings"); + this.prefs = new Prefs(); + this.changedPrefs(this.prefs); + this.prefs.addListener(this); + } catch(e) { + if (this.strings) { + alert(this.strings.getString("initError") + "\n\n" + e); + } else { + alert(e); + } + } + }, + + onUnload : function(event) { + this.prefs.dispose(); + Redirector.debug("Finished cleanup"); + }, - changedPrefs : function(prefs) { - var statusImg = document.getElementById('redirector-statusbar-img'); + changedPrefs : function(prefs) { + var statusImg = document.getElementById('redirector-statusbar-img'); - if (prefs.enabled) { - statusImg.src = 'chrome://redirector/skin/statusactive.png' - statusImg.setAttribute('tooltiptext', this.strings.getString('enabledTooltip')); - } else { - statusImg.src = 'chrome://redirector/skin/statusinactive.png' - statusImg.setAttribute('tooltiptext', this.strings.getString('disabledTooltip')); - } + if (prefs.enabled) { + statusImg.src = 'chrome://redirector/skin/statusactive.png' + statusImg.setAttribute('tooltiptext', this.strings.getString('enabledTooltip')); + } else { + statusImg.src = 'chrome://redirector/skin/statusinactive.png' + statusImg.setAttribute('tooltiptext', this.strings.getString('disabledTooltip')); + } - document.getElementById('redirector-status').hidden = !prefs.showStatusBarIcon; + document.getElementById('redirector-status').hidden = !prefs.showStatusBarIcon; document.getElementById('redirector-context').hidden = !prefs.showContextMenu; - }, - - showContextMenu : function(event) { - if (gContextMenu.onLink) { - document.getElementById("redirector-context").label = this.strings.getString('addLinkUrl'); - } else { - document.getElementById("redirector-context").label = this.strings.getString('addCurrentUrl'); - } - }, + }, + + showContextMenu : function(event) { + if (gContextMenu.onLink) { + document.getElementById("redirector-context").label = this.strings.getString('addLinkUrl'); + } else { + document.getElementById("redirector-context").label = this.strings.getString('addCurrentUrl'); + } + }, - onContextMenuCommand: function(event) { + onContextMenuCommand: function(event) { var redirect = new Redirect(window.content.location.href, window.content.location.href); - if (gContextMenu.onLink) { - redirect.redirectUrl = gContextMenu.link.toString(); - } + if (gContextMenu.onLink) { + redirect.redirectUrl = gContextMenu.link.toString(); + } var args = { saved : false, 'redirect' : redirect }; - window.openDialog("chrome://redirector/content/ui/editRedirect.xul", "redirect", "chrome,dialog,modal,centerscreen", args); - if (args.saved) { - Redirector.addRedirect(args.redirect); - } - }, - - onMenuItemCommand: function(event) { - this.openSettings(); - }, + window.openDialog("chrome://redirector/content/ui/editRedirect.xul", "redirect", "chrome,dialog,modal,centerscreen", args); + if (args.saved) { + Redirector.addRedirect(args.redirect); + } + }, + + onMenuItemCommand: function(event) { + this.openSettings(); + }, - toggleEnabled : function(event) { - this.prefs.enabled = !this.prefs.enabled; - }, + toggleEnabled : function(event) { + this.prefs.enabled = !this.prefs.enabled; + }, - openSettings : function() { - var windowName = "redirectorSettings"; - var windowsMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator); - var win = windowsMediator.getMostRecentWindow(windowName); - if (win) { - win.focus(); - } else { - window.openDialog("chrome://redirector/content/ui/settings.xul", - windowName, - "chrome,dialog,resizable=yes,centerscreen", this); - } - - }, - - statusBarClick : function(event) { - var LEFT = 0, RIGHT = 2; + openSettings : function() { + var windowName = "redirectorSettings"; + var windowsMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator); + var win = windowsMediator.getMostRecentWindow(windowName); + if (win) { + win.focus(); + } else { + window.openDialog("chrome://redirector/content/ui/settings.xul", + windowName, + "chrome,dialog,resizable=yes,centerscreen", this); + } + + }, + + statusBarClick : function(event) { + var LEFT = 0, RIGHT = 2; - if (event.button == LEFT) { - RedirectorOverlay.toggleEnabled(); - } else if (event.button == RIGHT) { - this.openSettings(); - } - } + if (event.button == LEFT) { + RedirectorOverlay.toggleEnabled(); + } else if (event.button == RIGHT) { + this.openSettings(); + } + } }; window.addEventListener("load", function(event) { RedirectorOverlay.onLoad(event); }, false); diff --git a/chrome/content/code/editRedirect.xul.js b/chrome/content/code/editRedirect.xul.js index 0902645..650a8bf 100644 --- a/chrome/content/code/editRedirect.xul.js +++ b/chrome/content/code/editRedirect.xul.js @@ -1,16 +1,16 @@ //// $Id$
var EditRedirect = {
- txtExampleUrl : null,
- txtIncludePattern : null,
- txtRedirectUrl : null,
- txtExcludePattern : null,
- chkUnescapeMatches : null,
- rdoRegex : null,
- rdoWildcard : null,
-
- onLoad : function() {
- var args = window.arguments[0];
+ txtExampleUrl : null,
+ txtIncludePattern : null,
+ txtRedirectUrl : null,
+ txtExcludePattern : null,
+ chkUnescapeMatches : null,
+ rdoRegex : null,
+ rdoWildcard : null,
+
+ onLoad : function() {
+ var args = window.arguments[0];
var redirect = args.redirect;
this.txtExampleUrl = document.getElementById('txtExampleUrl');
this.txtIncludePattern = document.getElementById('txtIncludePattern');
@@ -25,14 +25,14 @@ var EditRedirect = { this.txtExcludePattern.value = redirect.excludePattern;
this.txtRedirectUrl.value = redirect.redirectUrl;
this.chkUnescapeMatches.setAttribute('checked', redirect.unescapeMatches);
- this.rdoRegex.setAttribute('selected', redirect.isRegex());
- this.rdoWildcard.setAttribute('selected', redirect.isWildcard());
+ this.rdoRegex.setAttribute('selected', redirect.isRegex());
+ this.rdoWildcard.setAttribute('selected', redirect.isWildcard());
- this.txtIncludePattern.focus();
- this.strings = document.getElementById("redirector-strings");
- },
+ this.txtIncludePattern.focus();
+ this.strings = document.getElementById("redirector-strings");
+ },
- onAccept : function() {
+ onAccept : function() {
var args = window.arguments[0];
var msg, title;
args.saved = true;
@@ -50,12 +50,12 @@ var EditRedirect = { return rv == 0;
} else {
var resultUrl = result.redirectTo;
- if (!resultUrl.match(/https?:/)) {
- var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
- var uri = ioService.newURI(args.redirect.exampleUrl, null, null);
- resultUrl = uri.resolve(resultUrl);
- }
-
+ if (!resultUrl.match(/https?:/)) {
+ var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
+ var uri = ioService.newURI(args.redirect.exampleUrl, null, null);
+ resultUrl = uri.resolve(resultUrl);
+ }
+
var secondResult = args.redirect.getMatch(resultUrl);
if (secondResult.isMatch) {
title = this.strings.getString('errorExampleUrlMatchesRecursiveTitle');
@@ -65,16 +65,16 @@ var EditRedirect = { }
}
}
- return true;
- },
+ return true;
+ },
- msgBox : function(title, text) {
- Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService)
- .alert(window, title, text);
- },
-
- saveValues : function(redirect) {
+ msgBox : function(title, text) {
+ Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+ .getService(Components.interfaces.nsIPromptService)
+ .alert(window, title, text);
+ },
+
+ saveValues : function(redirect) {
redirect.exampleUrl = this.txtExampleUrl.value;
redirect.includePattern = this.txtIncludePattern.value;
redirect.excludePattern = this.txtExcludePattern.value;
@@ -83,21 +83,21 @@ var EditRedirect = { var val = this.chkUnescapeMatches.getAttribute('checked');
redirect.unescapeMatches = val === 'true' || val === true;
//Disabled cannot be set here
- },
-
- testPattern : function() {
- try {
+ },
+
+ testPattern : function() {
+ try {
var redirect = new Redirect();
this.saveValues(redirect);
var extName = this.strings.getString('extensionName');
var result = redirect.test();
- if (result.isMatch) {
- this.msgBox(extName, this.strings.getFormattedString('testPatternSuccess', [redirect.includePattern, redirect.exampleUrl, result.redirectTo]));
- } else if (result.isExcludeMatch) {
- this.msgBox(extName, this.strings.getFormattedString('testPatternExclude', [redirect.exampleUrl, redirect.excludePattern]));
- } else {
- this.msgBox(extName, this.strings.getFormattedString('testPatternFailure', [redirect.includePattern, redirect.exampleUrl]));
- }
- } catch(e) {alert(e);}
- }
+ if (result.isMatch) {
+ this.msgBox(extName, this.strings.getFormattedString('testPatternSuccess', [redirect.includePattern, redirect.exampleUrl, result.redirectTo]));
+ } else if (result.isExcludeMatch) {
+ this.msgBox(extName, this.strings.getFormattedString('testPatternExclude', [redirect.exampleUrl, redirect.excludePattern]));
+ } else {
+ this.msgBox(extName, this.strings.getFormattedString('testPatternFailure', [redirect.includePattern, redirect.exampleUrl]));
+ }
+ } catch(e) {alert(e);}
+ }
};
\ No newline at end of file diff --git a/chrome/content/code/prefs.js b/chrome/content/code/prefs.js index 4118bc5..055293b 100644 --- a/chrome/content/code/prefs.js +++ b/chrome/content/code/prefs.js @@ -6,77 +6,77 @@ function Prefs() { Prefs.prototype = {
- //Preferences:
- _version : null,
- _enabled : null,
- _showStatusBarIcon : null,
- _showContextMenu : null,
- _debugEnabled : null,
- _defaultDir : null,
- _redirects : null,
-
- _prefBranch : null,
-
- _listeners : null,
-
- //Preferences props
-
- get version() { return this._version; },
- set version(value) { this._prefBranch.setCharPref('version', value); },
+ //Preferences:
+ _version : null,
+ _enabled : null,
+ _showStatusBarIcon : null,
+ _showContextMenu : null,
+ _debugEnabled : null,
+ _defaultDir : null,
+ _redirects : null,
+
+ _prefBranch : null,
+
+ _listeners : null,
+
+ //Preferences props
+
+ get version() { return this._version; },
+ set version(value) { this._prefBranch.setCharPref('version', value); },
- get enabled() { return this._enabled; },
- set enabled(value) { this._prefBranch.setBoolPref('enabled', value); },
-
- get showStatusBarIcon() { return this._showStatusBarIcon; },
- set showStatusBarIcon(value) { this._prefBranch.setBoolPref('showStatusBarIcon', value); },
+ get enabled() { return this._enabled; },
+ set enabled(value) { this._prefBranch.setBoolPref('enabled', value); },
+
+ get showStatusBarIcon() { return this._showStatusBarIcon; },
+ set showStatusBarIcon(value) { this._prefBranch.setBoolPref('showStatusBarIcon', value); },
- get showContextMenu() { return this._showContextMenu; },
- set showContextMenu(value) { this._prefBranch.setBoolPref('showContextMenu', value); },
+ get showContextMenu() { return this._showContextMenu; },
+ set showContextMenu(value) { this._prefBranch.setBoolPref('showContextMenu', value); },
- get debugEnabled() { return this._debugEnabled; },
- set debugEnabled(value) { this._prefBranch.setBoolPref('debugEnabled', value); },
+ get debugEnabled() { return this._debugEnabled; },
+ set debugEnabled(value) { this._prefBranch.setBoolPref('debugEnabled', value); },
- get defaultDir() { return this._defaultDir; },
- set defaultDir(value) { this._prefBranch.setCharPref('defaultDir', value); },
+ get defaultDir() { return this._defaultDir; },
+ set defaultDir(value) { this._prefBranch.setCharPref('defaultDir', value); },
- get redirects() { return this._redirects; },
- set redirects(value) { this._prefBranch.setCharPref('redirects', value); },
+ get redirects() { return this._redirects; },
+ set redirects(value) { this._prefBranch.setCharPref('redirects', value); },
init : function() {
- this._prefBranch = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.redirector.");
+ this._prefBranch = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.redirector.");
this.reload();
this._listeners = [];
- this.service.addObserver('extensions.redirector', this, false);
- },
+ this.service.addObserver('extensions.redirector', this, false);
+ },
- dispose : function() {
- this._listeners = null;
- this.service.removeObserver('extensions.redirector', this);
+ dispose : function() {
+ this._listeners = null;
+ this.service.removeObserver('extensions.redirector', this);
},
reload : function() {
- this._version = this._prefBranch.getCharPref('version');
- this._enabled = this._prefBranch.getBoolPref('enabled');
- this._showStatusBarIcon = this._prefBranch.getBoolPref('showStatusBarIcon');
- this._showContextMenu = this._prefBranch.getBoolPref('showContextMenu');
- this._debugEnabled = this._prefBranch.getBoolPref('debugEnabled');
- this._defaultDir = this._prefBranch.getCharPref('defaultDir');
- this._redirects = this._prefBranch.getCharPref('redirects');
+ this._version = this._prefBranch.getCharPref('version');
+ this._enabled = this._prefBranch.getBoolPref('enabled');
+ this._showStatusBarIcon = this._prefBranch.getBoolPref('showStatusBarIcon');
+ this._showContextMenu = this._prefBranch.getBoolPref('showContextMenu');
+ this._debugEnabled = this._prefBranch.getBoolPref('debugEnabled');
+ this._defaultDir = this._prefBranch.getCharPref('defaultDir');
+ this._redirects = this._prefBranch.getCharPref('redirects');
},
- get service() {
- return Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranchInternal);
- },
+ get service() {
+ return Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranchInternal);
+ },
- observe : function(subject, topic, data) {
- if (topic != 'nsPref:changed') {
- return;
- }
- this.reload();
- for each (var listener in this._listeners) {
- listener && listener.changedPrefs && listener.changedPrefs(this);
- }
- },
+ observe : function(subject, topic, data) {
+ if (topic != 'nsPref:changed') {
+ return;
+ }
+ this.reload();
+ for each (var listener in this._listeners) {
+ listener && listener.changedPrefs && listener.changedPrefs(this);
+ }
+ },
addListener : function(listener) {
this._listeners.push(listener);
diff --git a/chrome/content/code/redirect.js b/chrome/content/code/redirect.js index c4fddf8..b8ca7c8 100644 --- a/chrome/content/code/redirect.js +++ b/chrome/content/code/redirect.js @@ -43,13 +43,13 @@ Redirect.prototype = { disabled : false,
//Functions
- clone : function() {
+ 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);
@@ -63,7 +63,7 @@ Redirect.prototype = { this.patternType = other.patternType;
this.unescapeMatches = other.unescapeMatches;
this.disabled = other.disabled;
- },
+ },
deserialize : function(str) {
if (!str || !str.split) {
@@ -76,7 +76,7 @@ Redirect.prototype = { this._init.apply(this, parts);
},
- equals : function(redirect) {
+ equals : function(redirect) {
return this.exampleUrl == redirect.exampleUrl
&& this.includePattern == redirect.includePattern
&& this.excludePattern == redirect.excludePattern
@@ -84,7 +84,7 @@ Redirect.prototype = { && this.patternType == redirect.patternType
&& this.unescapeMatches == redirect.unescapeMatches
;
- },
+ },
getMatch: function(url) {
var result = {
@@ -93,25 +93,25 @@ Redirect.prototype = { isDisabledMatch : false,
redirectTo : '',
toString : function() { return "{ isMatch : " + this.isMatch +
- ", isExcludeMatch : " + this.isExcludeMatch +
- ", isDisabledMatch : " + this.isDisabledMatch +
- ", redirectTo : \"" + this.redirectTo + "\"" +
- "}"; }
+ ", isExcludeMatch : " + this.isExcludeMatch +
+ ", isDisabledMatch : " + this.isDisabledMatch +
+ ", redirectTo : \"" + this.redirectTo + "\"" +
+ "}"; }
};
var redirectTo = null;
redirectTo = this._includeMatch(url);
- if (redirectTo !== null) {
- if (this.disabled) {
+ 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;
+ result.isExcludeMatch = true;
+ } else {
+ result.isMatch = true;
+ result.redirectTo = redirectTo;
+ }
+ }
+ return result;
},
isRegex: function() {
@@ -153,7 +153,7 @@ Redirect.prototype = { _preparePattern : function(pattern) {
if (this.patternType == Redirect.REGEX) {
- return pattern;
+ return pattern;
} else { //Convert wildcard to regex pattern
var converted = '^';
for (var i = 0; i < pattern.length; i++) {
@@ -190,13 +190,13 @@ Redirect.prototype = { toString : function() {
return 'REDIRECT: {'
- + '\n\tExample url : ' + this.exampleUrl
+ + '\n\tExample url : ' + this.exampleUrl
+ '\n\tInclude pattern : ' + this.includePattern
+ '\n\tExclude pattern : ' + this.excludePattern
- + '\n\tRedirect url : ' + this.redirectUrl
- + '\n\tPattern type : ' + this.patternType
+ + '\n\tRedirect url : ' + this.redirectUrl
+ + '\n\tPattern type : ' + this.patternType
+ '\n\tUnescape matches : ' + this.unescapeMatches
- + '\n\tDisabled : ' + this.disabled
+ + '\n\tDisabled : ' + this.disabled
+ '\n}\n';
},
@@ -209,11 +209,11 @@ Redirect.prototype = { return null;
}
var resultUrl = this.redirectUrl;
- for (var i = 1; i < matches.length; i++) {
- resultUrl = resultUrl.replace(new RegExp('\\$' + i, 'gi'), this.unescapeMatches ? unescape(matches[i]) : matches[i]);
- }
- this._rxInclude.lastIndex = 0;
- return resultUrl;
+ for (var i = 1; i < matches.length; i++) {
+ resultUrl = resultUrl.replace(new RegExp('\\$' + i, 'gi'), this.unescapeMatches ? unescape(matches[i]) : matches[i]);
+ }
+ this._rxInclude.lastIndex = 0;
+ return resultUrl;
},
_excludeMatch : function(url) {
diff --git a/chrome/content/code/redirector.prototype.js b/chrome/content/code/redirector.prototype.js index bcc9036..ecdcbd3 100644 --- a/chrome/content/code/redirector.prototype.js +++ b/chrome/content/code/redirector.prototype.js @@ -17,27 +17,27 @@ Redirector.prototype = { return this._list.length;
},
- addRedirect : function(redirect) {
- this._list.push(redirect);
- this.save();
- },
+ addRedirect : function(redirect) {
+ this._list.push(redirect);
+ this.save();
+ },
- debug : function(msg) {
- if (this._prefs.debugEnabled) {
- this._cout.logStringMessage('REDIRECTOR: ' + msg);
- }
- },
-
- deleteRedirectAt : function(index) {
- this._list.splice(index, 1);
- this.save();
- },
-
- exportRedirects : function(file) {
+ debug : function(msg) {
+ if (this._prefs.debugEnabled) {
+ this._cout.logStringMessage('REDIRECTOR: ' + msg);
+ }
+ },
+
+ deleteRedirectAt : function(index) {
+ this._list.splice(index, 1);
+ this.save();
+ },
+
+ exportRedirects : function(file) {
var fileStream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
- const PR_WRONLY = 0x02;
+ const PR_WRONLY = 0x02;
const PR_CREATE_FILE = 0x08;
- const PR_TRUNCATE = 0x20;
+ const PR_TRUNCATE = 0x20;
fileStream.init(file, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0644, 0);
var stream = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(Ci.nsIConverterOutputStream);
@@ -50,38 +50,38 @@ Redirector.prototype = { return this._list[index];
},
- //Get the redirect url for the given url. This will not check if we are enabled, and
- //not do any verification on the url, just assume that it is a good string url that is for http/s
- getRedirectUrl : function(url) {
- this.debug("Checking " + url);
-
- for each (var redirect in this._list) {
- 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');
- } else if (result.isDisabledMatch) {
- this.debug(url + ' matched pattern ' + redirect.includePattern + ' but the redirect is disabled');
- } else if (result.isMatch) {
- redirectUrl = this._makeAbsoluteUrl(url, result.redirectTo);
+ //Get the redirect url for the given url. This will not check if we are enabled, and
+ //not do any verification on the url, just assume that it is a good string url that is for http/s
+ getRedirectUrl : function(url) {
+ this.debug("Checking " + url);
+
+ for each (var redirect in this._list) {
+ 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');
+ } else if (result.isDisabledMatch) {
+ this.debug(url + ' matched pattern ' + redirect.includePattern + ' but the redirect is disabled');
+ } else if (result.isMatch) {
+ redirectUrl = this._makeAbsoluteUrl(url, result.redirectTo);
- //check for loops...
- result = redirect.getMatch(redirectUrl);
- if (result.isMatch) {
- var title = this._getString('invalidRedirectTitle');
- var msg = this._getFormattedString('invalidRedirectText', [redirect.includePattern, url, redirectUrl]);
- this.debug(msg);
+ //check for loops...
+ result = redirect.getMatch(redirectUrl);
+ if (result.isMatch) {
+ var title = this._getString('invalidRedirectTitle');
+ var msg = this._getFormattedString('invalidRedirectText', [redirect.includePattern, url, redirectUrl]);
+ this.debug(msg);
redirect.disabled = true;
- this.save();
+ this.save();
this._msgBox(title, msg);
- } else {
- this.debug('Redirecting ' + url + ' to ' + redirectUrl);
- return redirectUrl;
- }
- }
- }
- return null;
- },
-
+ } else {
+ this.debug('Redirecting ' + url + ' to ' + redirectUrl);
+ return redirectUrl;
+ }
+ }
+ }
+ return null;
+ },
+
importRedirects : function(file) {
var fileStream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
fileStream.init(file, 0x01, 0444, 0); //TODO: Find the actual constants for these magic numbers
@@ -109,8 +109,8 @@ Redirector.prototype = { this.save();
return importCount | (existsCount << 16);
},
-
- reload : function() {
+
+ reload : function() {
loader.loadSubScript('chrome://redirector/content/code/redirector.prototype.js');
loader.loadSubScript('chrome://redirector/content/code/redirect.js');
var oldEnabled = this.enabled;
@@ -121,11 +121,11 @@ Redirector.prototype = { }
this._init();
this.enabled = oldEnabled;
- },
-
- save : function() {
- this._prefs.redirects = this._redirectsAsString(':::');
- },
+ },
+
+ save : function() {
+ this._prefs.redirects = this._redirectsAsString(':::');
+ },
switchItems : function(index1, index2) {
var item = this._list[index1];
@@ -133,61 +133,61 @@ Redirector.prototype = { this._list[index2] = item;
this.save();
},
-
- //End rdIRedirector
-
- // nsIContentPolicy implementation
- shouldLoad: function(contentType, contentLocation, requestOrigin, aContext, mimeTypeGuess, extra) {
- try {
- //This is also done in getRedirectUrl, but we want to exit as quickly as possible for performance
- if (!this._prefs.enabled) {
- return Ci.nsIContentPolicy.ACCEPT;
- }
-
- if (contentType != Ci.nsIContentPolicy.TYPE_DOCUMENT) {
- return Ci.nsIContentPolicy.ACCEPT;
- }
+
+ //End rdIRedirector
+
+ // nsIContentPolicy implementation
+ shouldLoad: function(contentType, contentLocation, requestOrigin, aContext, mimeTypeGuess, extra) {
+ try {
+ //This is also done in getRedirectUrl, but we want to exit as quickly as possible for performance
+ if (!this._prefs.enabled) {
+ return Ci.nsIContentPolicy.ACCEPT;
+ }
+
+ if (contentType != Ci.nsIContentPolicy.TYPE_DOCUMENT) {
+ return Ci.nsIContentPolicy.ACCEPT;
+ }
- if (contentLocation.scheme != "http" && contentLocation.scheme != "https") {
- return Ci.nsIContentPolicy.ACCEPT;
- }
-
- if (!aContext || !aContext.loadURI) {
- return Ci.nsIContentPolicy.ACCEPT;
- }
-
- var redirectUrl = this.getRedirectUrl(contentLocation.spec);
+ if (contentLocation.scheme != "http" && contentLocation.scheme != "https") {
+ return Ci.nsIContentPolicy.ACCEPT;
+ }
+
+ if (!aContext || !aContext.loadURI) {
+ return Ci.nsIContentPolicy.ACCEPT;
+ }
+
+ var redirectUrl = this.getRedirectUrl(contentLocation.spec);
- if (!redirectUrl) {
- return Ci.nsIContentPolicy.ACCEPT;
- }
+ if (!redirectUrl) {
+ return Ci.nsIContentPolicy.ACCEPT;
+ }
- aContext.loadURI(redirectUrl, requestOrigin, null);
- return Ci.nsIContentPolicy.REJECT_REQUEST;
- } catch(e) {
- this.debug(e);
- }
-
- },
-
- shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode, mimeType, extra) {
- return Ci.nsIContentPolicy.ACCEPT;
- },
- //end nsIContentPolicy
+ aContext.loadURI(redirectUrl, requestOrigin, null);
+ return Ci.nsIContentPolicy.REJECT_REQUEST;
+ } catch(e) {
+ this.debug(e);
+ }
+
+ },
+
+ shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode, mimeType, extra) {
+ return Ci.nsIContentPolicy.ACCEPT;
+ },
+ //end nsIContentPolicy
- //nsIChannelEventSink implementation
+ //nsIChannelEventSink implementation
onChannelRedirect: function(oldChannel, newChannel, flags)
{
try {
let newLocation = newChannel.URI.spec;
if (!(newChannel.loadFlags & Ci.nsIChannel.LOAD_DOCUMENT_URI)) {
//We only redirect documents...
- return;
+ return;
}
if (!this._prefs.enabled) {
- return;
- }
+ return;
+ }
if (!newLocation) {
return;
@@ -210,14 +210,14 @@ Redirector.prototype = { } catch(e) {}
}
if (!webNav) {
- return;
+ return;
}
var redirectUrl = this.getRedirectUrl(newLocation);
- if (redirectUrl) {
- 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...
- }
+ if (redirectUrl) {
+ 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)) {
// We shouldn't throw exceptions here - this will prevent the redirect.
@@ -230,63 +230,63 @@ Redirector.prototype = { _prefs : null,
_list : null,
- _strings : null,
- _cout : Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService),
+ _strings : null,
+ _cout : Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService),
- _init : function() {
- if (this._prefs) {
- this._prefs.dispose();
- }
- this._prefs = new Prefs();
- //Check if we need to update existing redirects
+ _init : function() {
+ if (this._prefs) {
+ this._prefs.dispose();
+ }
+ this._prefs = new Prefs();
+ //Check if we need to update existing redirects
var data = this._prefs.redirects;
- var version = this._prefs.version;
- 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 = JSON.parse(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._prefs.redirects = newArr.join(':::');
- }
- this._prefs.version = '2.0';
- }
- //Update finished
-
- //Now get from the new format
- data = this._prefs.redirects;
- var arr;
- this._list = [];
- if (data != '') {
- for each (redirectString in data.split(':::')) {
- var redirect = new Redirect();
- redirect.deserialize(redirectString);
- this._list.push(redirect);
- }
- }
- },
-
- _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);
- },
+ var version = this._prefs.version;
+ 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 = JSON.parse(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._prefs.redirects = newArr.join(':::');
+ }
+ this._prefs.version = '2.0';
+ }
+ //Update finished
+
+ //Now get from the new format
+ data = this._prefs.redirects;
+ var arr;
+ this._list = [];
+ if (data != '') {
+ for each (redirectString in data.split(':::')) {
+ var redirect = new Redirect();
+ redirect.deserialize(redirectString);
+ this._list.push(redirect);
+ }
+ }
+ },
+
+ _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);
+ },
- _redirectsAsString : function(seperator) {
+ _redirectsAsString : function(seperator) {
return [r.serialize() for each (r in this._list)].join(seperator);
- },
-
+ },
+
_containsRedirect : function(redirect) {
for each (var existing in this._list) {
@@ -297,29 +297,29 @@ Redirector.prototype = { return false;
},
- _getString : function(name) {
- return this._strings.GetStringFromName(name);
- },
-
- _getFormattedString : function(name, params) {
+ _getString : function(name) {
+ return this._strings.GetStringFromName(name);
+ },
+
+ _getFormattedString : function(name, params) {
return this._strings.formatStringFromName(name, params, params.length);
- },
-
- _msgBox : function(title, text) {
- Cc["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Ci.nsIPromptService)
- .alert(null, title, text);
- },
+ },
+
+ _msgBox : function(title, text) {
+ Cc["@mozilla.org/embedcomp/prompt-service;1"]
+ .getService(Ci.nsIPromptService)
+ .alert(null, title, text);
+ },
- _makeAbsoluteUrl : function(currentUrl, relativeUrl) {
-
- if (relativeUrl.match(/https?:/)) {
- return relativeUrl;
- }
-
- var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
- var uri = ioService.newURI(currentUrl, null, null);
-
- return uri.resolve(relativeUrl);
- }
+ _makeAbsoluteUrl : function(currentUrl, relativeUrl) {
+
+ if (relativeUrl.match(/https?:/)) {
+ return relativeUrl;
+ }
+
+ var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
+ var uri = ioService.newURI(currentUrl, null, null);
+
+ return uri.resolve(relativeUrl);
+ }
};
diff --git a/chrome/content/code/settings.xul.js b/chrome/content/code/settings.xul.js index 3102e31..21f514f 100644 --- a/chrome/content/code/settings.xul.js +++ b/chrome/content/code/settings.xul.js @@ -7,244 +7,244 @@ const nsLocalFile = Components.Constructor("@mozilla.org/file/local;1", "nsILoca var Settings = {
- lstRedirects: null,
- btnDelete : null,
- btnEdit : null,
- btnUp : null,
- btnDown : null,
- btnExport : null,
- btnImport : null,
+ lstRedirects: null,
+ btnDelete : null,
+ btnEdit : null,
+ btnUp : null,
+ btnDown : null,
+ btnExport : null,
+ btnImport : null,
chkEnableRedirector : null,
chkShowStatusBarIcon : null,
chkShowContextMenu : null,
chkEnableDebugOutput : null,
prefs : null,
- onLoad : function() {
- try {
- //Get references to controls
- this.lstRedirects = document.getElementById('lstRedirects');
- this.btnDelete = document.getElementById('btnDelete');
- this.btnEdit = document.getElementById('btnEdit');
- this.btnUp = document.getElementById('btnUp');
- this.btnDown = document.getElementById('btnDown');
- this.btnExport = document.getElementById('btnExport');
- this.btnImport = document.getElementById('btnImport');
- this.chkEnableRedirector = document.getElementById('chkEnableRedirector');
- this.chkShowStatusBarIcon = document.getElementById('chkShowStatusBarIcon');
- this.chkShowContextMenu = document.getElementById('chkShowContextMenu');
- this.chkEnableDebugOutput = document.getElementById('chkEnableDebugOutput');
-
- this.prefs = new Prefs();
- //Preferences
- this.changedPrefs(this.prefs);
- this.prefs.addListener(this);
+ onLoad : function() {
+ try {
+ //Get references to controls
+ this.lstRedirects = document.getElementById('lstRedirects');
+ this.btnDelete = document.getElementById('btnDelete');
+ this.btnEdit = document.getElementById('btnEdit');
+ this.btnUp = document.getElementById('btnUp');
+ this.btnDown = document.getElementById('btnDown');
+ this.btnExport = document.getElementById('btnExport');
+ this.btnImport = document.getElementById('btnImport');
+ this.chkEnableRedirector = document.getElementById('chkEnableRedirector');
+ this.chkShowStatusBarIcon = document.getElementById('chkShowStatusBarIcon');
+ this.chkShowContextMenu = document.getElementById('chkShowContextMenu');
+ this.chkEnableDebugOutput = document.getElementById('chkEnableDebugOutput');
+
+ this.prefs = new Prefs();
+ //Preferences
+ this.changedPrefs(this.prefs);
+ this.prefs.addListener(this);
- //Redirect list
- this.lstRedirects.selType = 'single';
- this.template = document.getElementsByTagName('richlistitem')[0];
- this.lstRedirects.removeChild(this.template);
- var list = [];
- for (var i = 0; i < Redirector.redirectCount; i++) {
- list.push(Redirector.getRedirectAt(i));
- }
- this.addItemsToListBox(list);
+ //Redirect list
+ this.lstRedirects.selType = 'single';
+ this.template = document.getElementsByTagName('richlistitem')[0];
+ this.lstRedirects.removeChild(this.template);
+ var list = [];
+ for (var i = 0; i < Redirector.redirectCount; i++) {
+ list.push(Redirector.getRedirectAt(i));
+ }
+ this.addItemsToListBox(list);
this.selectionChange();
- this.strings = document.getElementById('redirector-strings');
- this.strings.getPluralized = function(id, number) {
+ this.strings = document.getElementById('redirector-strings');
+ this.strings.getPluralized = function(id, number) {
id += number == 1 ? 'Singular' : '';
return this.getFormattedString(id, [number]);
- };
- } catch(e) {
- alert(e);
- }
- },
-
- onUnload : function() {
+ };
+ } catch(e) {
+ alert(e);
+ }
+ },
+
+ onUnload : function() {
this.prefs.dispose();
- },
+ },
changedPrefs : function(prefs) {
- this.chkEnableRedirector.setAttribute('checked', prefs.enabled);
- this.chkShowStatusBarIcon.setAttribute('checked', prefs.showStatusBarIcon);
- this.chkShowContextMenu.setAttribute('checked', prefs.showContextMenu);
- this.chkEnableDebugOutput.setAttribute('checked', prefs.debugEnabled);
+ this.chkEnableRedirector.setAttribute('checked', prefs.enabled);
+ this.chkShowStatusBarIcon.setAttribute('checked', prefs.showStatusBarIcon);
+ this.chkShowContextMenu.setAttribute('checked', prefs.showContextMenu);
+ this.chkEnableDebugOutput.setAttribute('checked', prefs.debugEnabled);
},
- addItemsToListBox : function(items) {
+ addItemsToListBox : function(items) {
- var item, row, value, newItem;
-
- for each (item in items) {
- newItem = this.template.cloneNode(true);
+ var item, row, value, newItem;
+
+ for each (item in items) {
+ newItem = this.template.cloneNode(true);
- newItem.getElementsByAttribute('name', 'dscrIncludePattern')[0].setAttribute('value', item.includePattern);
- newItem.getElementsByAttribute('name', 'dscrExcludePattern')[0].setAttribute('value', item.excludePattern);
- newItem.getElementsByAttribute('name', 'dscrRedirectTo')[0].setAttribute('value', item.redirectUrl);
- var checkEnabled = newItem.getElementsByAttribute('name', 'chkEnabled')[0];
- checkEnabled.setAttribute('checked', !item.disabled);
- newItem.setAttribute('class', item.disabled ? 'disabledRedirect' : '');
- newItem.item = item;
- this.lstRedirects.appendChild(newItem);
- newItem.setAttribute('selected', false)
- }
-
- //Enable, disable functionality
- this.lstRedirects.addEventListener('click', function(ev) {
- if (ev.originalTarget && ev.originalTarget.tagName == 'checkbox') {
- var parent = ev.originalTarget.parentNode;
- while (!parent.item) {
- parent = parent.parentNode;
- }
- parent.item.disabled = !ev.originalTarget.hasAttribute('checked');
- parent.setAttribute('class', parent.item.disabled ? 'disabledRedirect' : '');
- Redirector.save();
- }
- },false);
- },
-
- moveUp : function(){
- if (this.lstRedirects.selectedIndex <= 0) {
- return;
- }
- this.switchItems(this.lstRedirects.selectedIndex-1);
- },
+ newItem.getElementsByAttribute('name', 'dscrIncludePattern')[0].setAttribute('value', item.includePattern);
+ newItem.getElementsByAttribute('name', 'dscrExcludePattern')[0].setAttribute('value', item.excludePattern);
+ newItem.getElementsByAttribute('name', 'dscrRedirectTo')[0].setAttribute('value', item.redirectUrl);
+ var checkEnabled = newItem.getElementsByAttribute('name', 'chkEnabled')[0];
+ checkEnabled.setAttribute('checked', !item.disabled);
+ newItem.setAttribute('class', item.disabled ? 'disabledRedirect' : '');
+ newItem.item = item;
+ this.lstRedirects.appendChild(newItem);
+ newItem.setAttribute('selected', false)
+ }
+
+ //Enable, disable functionality
+ this.lstRedirects.addEventListener('click', function(ev) {
+ if (ev.originalTarget && ev.originalTarget.tagName == 'checkbox') {
+ var parent = ev.originalTarget.parentNode;
+ while (!parent.item) {
+ parent = parent.parentNode;
+ }
+ parent.item.disabled = !ev.originalTarget.hasAttribute('checked');
+ parent.setAttribute('class', parent.item.disabled ? 'disabledRedirect' : '');
+ Redirector.save();
+ }
+ },false);
+ },
+
+ moveUp : function(){
+ if (this.lstRedirects.selectedIndex <= 0) {
+ return;
+ }
+ this.switchItems(this.lstRedirects.selectedIndex-1);
+ },
- moveDown : function() {
- if (this.lstRedirects.selectedIndex == Redirector.redirectCount-1) {
- return;
- }
- this.switchItems(this.lstRedirects.selectedIndex);
- },
+ moveDown : function() {
+ if (this.lstRedirects.selectedIndex == Redirector.redirectCount-1) {
+ return;
+ }
+ this.switchItems(this.lstRedirects.selectedIndex);
+ },
- switchItems : function(firstIndex) {
- Redirector.switchItems(firstIndex, firstIndex+1);
- var firstItem = this.lstRedirects.children[firstIndex];
- var secondItem = this.lstRedirects.children[firstIndex+1];
- this.lstRedirects.removeChild(secondItem);
- this.lstRedirects.insertBefore(secondItem, firstItem);
- this.selectionChange();
- },
-
- setListItemValues : function(listItem, item){
- listItem.getElementsByAttribute('name', 'dscrIncludePattern')[0].setAttribute('value', item.includePattern);
- listItem.getElementsByAttribute('name', 'dscrExcludePattern')[0].setAttribute('value', item.excludePattern);
- listItem.getElementsByAttribute('name', 'dscrRedirectTo')[0].setAttribute('value', item.redirectUrl);
- },
-
- preferenceChange : function(event) {
- this.prefs[event.originalTarget.getAttribute('preference')] = event.originalTarget.hasAttribute('checked');
- },
-
- addRedirect : function() {
+ switchItems : function(firstIndex) {
+ Redirector.switchItems(firstIndex, firstIndex+1);
+ var firstItem = this.lstRedirects.children[firstIndex];
+ var secondItem = this.lstRedirects.children[firstIndex+1];
+ this.lstRedirects.removeChild(secondItem);
+ this.lstRedirects.insertBefore(secondItem, firstItem);
+ this.selectionChange();
+ },
+
+ setListItemValues : function(listItem, item){
+ listItem.getElementsByAttribute('name', 'dscrIncludePattern')[0].setAttribute('value', item.includePattern);
+ listItem.getElementsByAttribute('name', 'dscrExcludePattern')[0].setAttribute('value', item.excludePattern);
+ listItem.getElementsByAttribute('name', 'dscrRedirectTo')[0].setAttribute('value', item.redirectUrl);
+ },
+
+ preferenceChange : function(event) {
+ this.prefs[event.originalTarget.getAttribute('preference')] = event.originalTarget.hasAttribute('checked');
+ },
+
+ addRedirect : function() {
var args = { saved : false, redirect : new Redirect() };
- window.openDialog("chrome://redirector/content/ui/editRedirect.xul", "redirect", "chrome,dialog,modal,centerscreen", args);
- if (args.saved) {
- this.addItemsToListBox([args.redirect]);
- Redirector.addRedirect(args.redirect);
- this.selectionChange();
- }
- },
+ window.openDialog("chrome://redirector/content/ui/editRedirect.xul", "redirect", "chrome,dialog,modal,centerscreen", args);
+ if (args.saved) {
+ this.addItemsToListBox([args.redirect]);
+ Redirector.addRedirect(args.redirect);
+ this.selectionChange();
+ }
+ },
- editRedirect : function() {
+ editRedirect : function() {
if (this.lstRedirects.selectedIndex == -1) {
return;
}
//.selectedItem is still there after it has been removed, that's why we have the .selectedIndex check above as well
- var listItem = this.lstRedirects.selectedItem;
- if (!listItem) {
- return;
- }
- var redirect = listItem.item;
+ var listItem = this.lstRedirects.selectedItem;
+ if (!listItem) {
+ return;
+ }
+ var redirect = listItem.item;
var args = { saved: false, "redirect":redirect.clone()};
- window.openDialog("chrome://redirector/content/ui/editRedirect.xul", "redirect", "chrome,dialog,modal,centerscreen", args);
+ window.openDialog("chrome://redirector/content/ui/editRedirect.xul", "redirect", "chrome,dialog,modal,centerscreen", args);
- if (args.saved) {
- redirect.copyValues(args.redirect);
- this.setListItemValues(listItem, redirect);
- Redirector.save();
- this.selectionChange();
- }
- },
-
- deleteRedirect : function() {
- var index = this.lstRedirects.selectedIndex;
+ if (args.saved) {
+ redirect.copyValues(args.redirect);
+ this.setListItemValues(listItem, redirect);
+ Redirector.save();
+ this.selectionChange();
+ }
+ },
+
+ deleteRedirect : function() {
+ var index = this.lstRedirects.selectedIndex;
- if (index == -1) {
- return;
- }
-
- var text = this.strings.getString("deleteConfirmationText");
- var title = this.strings.getString("deleteConfirmationTitle");
- var reallyDelete = Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService).confirm(null, title, text);
+ if (index == -1) {
+ return;
+ }
+
+ var text = this.strings.getString("deleteConfirmationText");
+ var title = this.strings.getString("deleteConfirmationTitle");
+ var reallyDelete = Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService).confirm(null, title, text);
if (!reallyDelete) {
return;
}
- try {
- this.lstRedirects.removeChild(this.lstRedirects.children[index]);
- Redirector.deleteRedirectAt(index);
- this.selectionChange();
- } catch(e) {
- alert(e);
- }
- },
-
- listKeypress : function(event) {
- if (event.keyCode == 13) { //Enter button
+ try {
+ this.lstRedirects.removeChild(this.lstRedirects.children[index]);
+ Redirector.deleteRedirectAt(index);
+ this.selectionChange();
+ } catch(e) {
+ alert(e);
+ }
+ },
+
+ listKeypress : function(event) {
+ if (event.keyCode == 13) { //Enter button
this.editRedirect();
- } else if (event.keyCode == 46) { //Del button
- this.deleteRedirect();
- }
- },
+ } else if (event.keyCode == 46) { //Del button
+ this.deleteRedirect();
+ }
+ },
- selectionChange : function() {
- if (!this.lstRedirects) {
- return;
+ selectionChange : function() {
+ if (!this.lstRedirects) {
+ return;
}
- var index = this.lstRedirects.selectedIndex;
+ var index = this.lstRedirects.selectedIndex;
- this.btnEdit.disabled = (index == -1);
- this.btnDelete.disabled = (index == -1);
- this.btnUp.disabled = (index <= 0);
- this.btnDown.disabled = (index == -1 || index >= Redirector.redirectCount-1);
- this.btnExport.disabled = (Redirector.redirectCount== 0);
- },
+ this.btnEdit.disabled = (index == -1);
+ this.btnDelete.disabled = (index == -1);
+ this.btnUp.disabled = (index <= 0);
+ this.btnDown.disabled = (index == -1 || index >= Redirector.redirectCount-1);
+ this.btnExport.disabled = (Redirector.redirectCount== 0);
+ },
- getFile : function(captionKey, mode) {
+ getFile : function(captionKey, mode) {
//Mostly borrowed from Adblock Plus
var picker = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
picker.init(window, this.strings.getString(captionKey), mode);
picker.defaultExtension = ".rdx";
var dir = this.prefs.defaultDir;
if (dir) {
- picker.displayDirectory = new nsLocalFile(dir);
+ picker.displayDirectory = new nsLocalFile(dir);
}
picker.appendFilter(this.strings.getString('redirectorFiles'), '*.rdx');
if (picker.show() == picker.returnCancel) {
- return null;
+ return null;
}
this.prefs.defaultDir = picker.displayDirectory.path;
return picker.file;
- },
-
- export : function() {
- var file = this.getFile('exportCaption', Ci.nsIFilePicker.modeSave);
- if (file) {
+ },
+
+ export : function() {
+ var file = this.getFile('exportCaption', Ci.nsIFilePicker.modeSave);
+ if (file) {
Redirector.exportRedirects(file);
- }
- },
-
- import : function() {
- var file = this.getFile('importCaption', Ci.nsIFilePicker.modeOpen);
- var result;
- if (file) {
- result = Redirector.importRedirects(file);
- }
-
+ }
+ },
+
+ import : function() {
+ var file = this.getFile('importCaption', Ci.nsIFilePicker.modeOpen);
+ var result;
+ if (!file) {
+ return;
+ }
+ result = Redirector.importRedirects(file);
var msg, imported, existed;
imported = result & 0xFFFF;
existed = result >> 16;
@@ -252,9 +252,9 @@ var Settings = { if (imported > 0) {
msg = this.strings.getPluralized('importedMessage', imported);
if (existed > 0) {
- msg += ', ' + this.strings.getPluralized('existedMessage',existed);
+ msg += ', ' + this.strings.getPluralized('existedMessage',existed);
} else {
- msg += '.';
+ msg += '.';
}
} else if (imported == 0 && existed > 0) {
msg = this.strings.getPluralized('allExistedMessage', existed);
@@ -263,14 +263,14 @@ var Settings = { }
var title = this.strings.getString("importResult");
- Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService).alert(null, title, msg);
+ Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService).alert(null, title, msg);
if (imported > 0) {
var newlist = [];
for (var i = Redirector.redirectCount-imported; i < Redirector.redirectCount; i++) {
newlist.push(Redirector.getRedirectAt(i));
}
- this.addItemsToListBox(newlist);
+ this.addItemsToListBox(newlist);
}
- }
+ }
};
|