[Pale-Moon] Issue #1737 - Part 3: Clean up base/content p.3

This commit is contained in:
Pale Moon 2020-03-10 17:19:36 +01:00 • committed by Roy Tam
commit 6c51c7704a
9 changed files with 833 additions and 836 deletions

View file

@ -5,88 +5,92 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
var padlock_PadLock =
{
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
Ci.nsISupportsWeakReference]),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
Ci.nsISupportsWeakReference]),
onButtonClick: function(event) {
event.stopPropagation();
gIdentityHandler.handleMoreInfoClick(event);
},
onStateChange: function() {},
onProgressChange: function() {},
onLocationChange: function() {},
onStatusChange: function() {},
onSecurityChange: function(aCallerWebProgress, aRequestWithState, aState) {
// aState is defined as a bitmask that may be extended in the future.
// We filter out any unknown bits before testing for known values.
const wpl = Ci.nsIWebProgressListener;
const wpl_security_bits = wpl.STATE_IS_SECURE |
wpl.STATE_IS_BROKEN |
wpl.STATE_IS_INSECURE |
wpl.STATE_IDENTITY_EV_TOPLEVEL |
wpl.STATE_SECURE_HIGH |
wpl.STATE_SECURE_MED |
wpl.STATE_SECURE_LOW;
var level;
var is_insecure;
var highlight_urlbar = false;
onStateChange: function() { },
onProgressChange: function() { },
onLocationChange: function() { },
onStatusChange: function() { },
onSecurityChange: function(aCallerWebProgress, aRequestWithState, aState) {
// aState is defined as a bitmask that may be extended in the future.
// We filter out any unknown bits before testing for known values.
const wpl = Ci.nsIWebProgressListener;
const wpl_security_bits = wpl.STATE_IS_SECURE |
wpl.STATE_IS_BROKEN |
wpl.STATE_IS_INSECURE |
wpl.STATE_IDENTITY_EV_TOPLEVEL |
wpl.STATE_SECURE_HIGH |
wpl.STATE_SECURE_MED |
wpl.STATE_SECURE_LOW;
var level;
var is_insecure;
var highlight_urlbar = false;
switch (aState & wpl_security_bits) {
case wpl.STATE_IS_SECURE | wpl.STATE_SECURE_HIGH | wpl.STATE_IDENTITY_EV_TOPLEVEL:
level = "ev";
is_insecure = "";
highlight_urlbar = true;
break;
case wpl.STATE_IS_SECURE | wpl.STATE_SECURE_HIGH:
level = "high";
is_insecure = "";
highlight_urlbar = true;
break;
case wpl.STATE_IS_SECURE | wpl.STATE_SECURE_MED:
case wpl.STATE_IS_SECURE | wpl.STATE_SECURE_LOW:
level = "low";
is_insecure = "insecure";
break;
case wpl.STATE_IS_BROKEN | wpl.STATE_SECURE_LOW:
level = "mixed";
is_insecure = "insecure";
highlight_urlbar = true;
break;
case wpl.STATE_IS_BROKEN:
level = "broken";
is_insecure = "insecure";
highlight_urlbar = true;
break;
default: // should not be reached
level = null;
is_insecure = "insecure";
}
switch (aState & wpl_security_bits) {
case wpl.STATE_IS_SECURE | wpl.STATE_SECURE_HIGH | wpl.STATE_IDENTITY_EV_TOPLEVEL:
level = "ev";
is_insecure = "";
highlight_urlbar = true;
break;
case wpl.STATE_IS_SECURE | wpl.STATE_SECURE_HIGH:
level = "high";
is_insecure = "";
highlight_urlbar = true;
break;
case wpl.STATE_IS_SECURE | wpl.STATE_SECURE_MED:
case wpl.STATE_IS_SECURE | wpl.STATE_SECURE_LOW:
level = "low";
is_insecure = "insecure";
break;
case wpl.STATE_IS_BROKEN | wpl.STATE_SECURE_LOW:
level = "mixed";
is_insecure = "insecure";
highlight_urlbar = true;
break;
case wpl.STATE_IS_BROKEN:
level = "broken";
is_insecure = "insecure";
highlight_urlbar = true;
break;
default: // should not be reached
level = null;
is_insecure = "insecure";
}
try {
var proto = gBrowser.contentWindow.location.protocol;
if (proto == "about:" || proto == "chrome:" || proto == "file:" ) {
// do not warn when using local protocols
is_insecure = false;
}
}
catch (ex) {}
try {
var proto = gBrowser.contentWindow.location.protocol;
if (proto == "about:" || proto == "chrome:" || proto == "file:" ) {
// do not warn when using local protocols
is_insecure = false;
}
} catch(ex) {
}
let ub = document.getElementById("urlbar");
if (ub) { // Only call if URL bar is present.
if (highlight_urlbar) {
ub.setAttribute("security_level", level);
} else {
ub.removeAttribute("security_level");
}
}
let ub = document.getElementById("urlbar");
if (ub) {
// Only call if URL bar is present.
if (highlight_urlbar) {
ub.setAttribute("security_level", level);
} else {
ub.removeAttribute("security_level");
}
}
try { // URL bar may be hidden
padlock_PadLock.setPadlockLevel("padlock-ib", level);
padlock_PadLock.setPadlockLevel("padlock-ib-left", level);
padlock_PadLock.setPadlockLevel("padlock-ub-right", level);
} catch(e) {}
padlock_PadLock.setPadlockLevel("padlock-sb", level);
padlock_PadLock.setPadlockLevel("padlock-tab", level);
},
try { // URL bar may be hidden
padlock_PadLock.setPadlockLevel("padlock-ib", level);
padlock_PadLock.setPadlockLevel("padlock-ib-left", level);
padlock_PadLock.setPadlockLevel("padlock-ub-right", level);
} catch(e) {
}
padlock_PadLock.setPadlockLevel("padlock-sb", level);
padlock_PadLock.setPadlockLevel("padlock-tab", level);
},
setPadlockLevel: function(item, level) {
let secbut = document.getElementById(item);
var sectooltip = "";
@ -120,7 +124,9 @@ var padlock_PadLock =
}
secbut.setAttribute("tooltiptext", sectooltip);
},
prefbranch : null,
onLoad: function() {
gBrowser.addProgressListener(padlock_PadLock);
@ -148,40 +154,32 @@ var padlock_PadLock =
if (prefval == 2) {
position = "ib-left";
padstyle = "modern";
}
else if (prefval == 3) {
} else if (prefval == 3) {
position = "ub-right";
padstyle = "modern";
}
else if (prefval == 4) {
} else if (prefval == 4) {
position = "statbar";
padstyle = "modern";
}
else if (prefval == 5) {
} else if (prefval == 5) {
position = "tabs-bar";
padstyle = "modern";
}
else if (prefval == 6) {
} else if (prefval == 6) {
position = "ib-trans-bg";
padstyle = "classic";
}
else if (prefval == 7) {
} else if (prefval == 7) {
position = "ib-left";
padstyle = "classic";
}
else if (prefval == 8) {
} else if (prefval == 8) {
position = "ub-right";
padstyle = "classic";
}
else if (prefval == 9) {
} else if (prefval == 9) {
position = "statbar";
padstyle = "classic";
}
else if (prefval == 10) {
} else if (prefval == 10) {
position = "tabs-bar";
padstyle = "classic";
}
else { // 1 or anything else_ default
} else {
// 1 or anything else_ default
position = "ib-trans-bg";
padstyle = "modern";
}
@ -198,12 +196,15 @@ var padlock_PadLock =
case 1:
colshow = "secure-only";
break;
default:
colshow = ""; // 0 or anything else: no shading
default:
// 0 or anything else: no shading
colshow = "";
}
try { // URL bar may be hidden
try {
// XXX should probably be done automatically
document.getElementById("urlbar").setAttribute("https_color", colshow);
} catch(e) {}
} catch(e) {
}
var lockenabled = padlock_PadLock.prefbranch.getBoolPref("shown");
var padshow = "";
@ -215,7 +216,9 @@ var padlock_PadLock =
document.getElementById("padlock-ib").setAttribute("padshow", padshow);
document.getElementById("padlock-ib-left").setAttribute("padshow", padshow);
document.getElementById("padlock-ub-right").setAttribute("padshow", padshow);
} catch(e) {}
} catch(e) {
}
document.getElementById("padlock-sb").setAttribute("padshow", padshow);
document.getElementById("padlock-tab").setAttribute("padshow", padshow);
@ -223,7 +226,9 @@ var padlock_PadLock =
document.getElementById("padlock-ib").setAttribute("padstyle", padstyle);
document.getElementById("padlock-ib-left").setAttribute("padstyle", padstyle);
document.getElementById("padlock-ub-right").setAttribute("padstyle", padstyle);
} catch(e) {}
} catch(e) {
}
document.getElementById("padlock-sb").setAttribute("padstyle", padstyle);
document.getElementById("padlock-tab").setAttribute("padstyle", padstyle);