[go: nahoru, domu]

Skip to content

Commit

Permalink
Allow whitelisting of custom protocol URLs (like about:addons)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustOff committed Feb 25, 2018
1 parent c1fe481 commit 7c5e63d
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ let styleSheetURI = Services.io.newURI("chrome://lull-the-tabs/skin/style.css",

let domRegex = null, gWindowListener;

function parseCustomProto(aURI) {
let match = /^(\w+:\w+)(\?.+)?$/.exec(aURI.spec);
if (match) {
return match[1];
}
}

function isWhiteListed(aURI) {
if (domRegex === null) {
try {
Expand All @@ -44,8 +51,7 @@ function isWhiteListed(aURI) {
try {
return domRegex.test(aURI.host);
} catch (e) {
// Most likely uri.host failed, so it isn't on the white list.
return false;
return domRegex.test(parseCustomProto(aURI));
}
}

Expand Down Expand Up @@ -372,10 +378,7 @@ LullTheTabs.prototype = {
try {
host = tab.linkedBrowser.currentURI.host;
} catch (ex) {
// Most likely uri.host doesn't exist which probably means
// whitelisting doesn't make sense on this tab. Set empty
// host so we don't show the menu item
host = '';
host = parseCustomProto(tab.linkedBrowser.currentURI);
}

if (!host) {
Expand All @@ -389,18 +392,6 @@ LullTheTabs.prototype = {
}

if (isWhiteListed(tab.linkedBrowser.currentURI)) {
let whitelist = [];
let wlpref = Services.prefs.getComplexValue(branch + "exceptionList", Ci.nsISupportsString).data;
if (wlpref) {
whitelist = wlpref.split(";");
}
for (let i = 0; i < whitelist.length; i++) {
let reg = new RegExp("^" + whitelist[i].replace(/\./g,"\\.").replace(/\*/g,".*") + "$");
if (reg.test(tab.linkedBrowser.currentURI.host)) {
host = whitelist[i];
break;
}
}
menuitem_neverUnload.setAttribute("checked", "true");
menuitem_unloadTab.setAttribute("disabled", "true");
} else {
Expand Down Expand Up @@ -587,8 +578,10 @@ LullTheTabs.prototype = {
try {
host = aTab.linkedBrowser.currentURI.host;
} catch(ex) {
// Most likely uri.host doesn't exist. Ignore then.
return;
host = parseCustomProto(aTab.linkedBrowser.currentURI)
if (!host) {
return;
}
}

let whitelist = [];
Expand Down

0 comments on commit 7c5e63d

Please sign in to comment.