1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
var padlock_PadLock =
{
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;
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) {}
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);
},
setPadlockLevel: function(item, level) {
let secbut = document.getElementById(item);
var sectooltip = "";
if (level) {
secbut.setAttribute("level", level);
secbut.hidden = false;
} else {
secbut.hidden = true;
secbut.removeAttribute("level");
}
switch (level) {
case "ev":
sectooltip = "Extended Validated";
break;
case "high":
sectooltip = "Secure";
break;
case "low":
sectooltip = "Weak security";
break;
case "mixed":
sectooltip = "Mixed mode (partially encrypted)";
break;
case "broken":
sectooltip = "Not secure";
break;
default:
sectooltip = "";
}
secbut.setAttribute("tooltiptext", sectooltip);
},
prefbranch : null,
onLoad: function() {
gBrowser.addProgressListener(padlock_PadLock);
var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
padlock_PadLock.prefbranch = prefService.getBranch("browser.padlock.");
padlock_PadLock.prefbranch.QueryInterface(Components.interfaces.nsIPrefBranch2);
padlock_PadLock.usePrefs();
padlock_PadLock.prefbranch.addObserver("", padlock_PadLock, false);
},
onUnLoad: function() {
padlock_PadLock.prefbranch.removeObserver("", padlock_PadLock);
},
observe: function(subject, topic, data)
{
if (topic != "nsPref:changed")
return;
if (data != "style" && data != "urlbar_background" && data != "shown")
return;
padlock_PadLock.usePrefs();
},
usePrefs: function() {
var prefval = padlock_PadLock.prefbranch.getIntPref("style");
var position;
var padstyle;
if (prefval == 2) {
position = "ib-left";
padstyle = "modern";
}
else if (prefval == 3) {
position = "ub-right";
padstyle = "modern";
}
else if (prefval == 4) {
position = "statbar";
padstyle = "modern";
}
else if (prefval == 5) {
position = "tabs-bar";
padstyle = "modern";
}
else if (prefval == 6) {
position = "ib-trans-bg";
padstyle = "classic";
}
else if (prefval == 7) {
position = "ib-left";
padstyle = "classic";
}
else if (prefval == 8) {
position = "ub-right";
padstyle = "classic";
}
else if (prefval == 9) {
position = "statbar";
padstyle = "classic";
}
else if (prefval == 10) {
position = "tabs-bar";
padstyle = "classic";
}
else { // 1 or anything else_ default
position = "ib-trans-bg";
padstyle = "modern";
}
var colshow;
var colprefval = padlock_PadLock.prefbranch.getIntPref("urlbar_background");
switch (colprefval) {
case 3:
colshow = "all";
break;
case 2:
colshow = "secure-mixed";
break;
case 1:
colshow = "secure-only";
break;
default:
colshow = ""; // 0 or anything else: no shading
}
try { // URL bar may be hidden
document.getElementById("urlbar").setAttribute("https_color", colshow);
} catch(e) {}
var lockenabled = padlock_PadLock.prefbranch.getBoolPref("shown");
var padshow = "";
if (lockenabled) {
padshow = position;
}
try { // URL bar may be hidden
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) {}
document.getElementById("padlock-sb").setAttribute("padshow", padshow);
document.getElementById("padlock-tab").setAttribute("padshow", padshow);
try { // URL bar may be hidden
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) {}
document.getElementById("padlock-sb").setAttribute("padstyle", padstyle);
document.getElementById("padlock-tab").setAttribute("padstyle", padstyle);
}
};
window.addEventListener("load", padlock_PadLock.onLoad, false );
window.addEventListener("unload", padlock_PadLock.onUnLoad, false );
|