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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const UNKNOWN = nsIPermissionManager.UNKNOWN_ACTION; // 0
const ALLOW = nsIPermissionManager.ALLOW_ACTION; // 1
const BLOCK = nsIPermissionManager.DENY_ACTION; // 2
const SESSION = nsICookiePermission.ACCESS_SESSION; // 8
const nsIQuotaManager = Components.interfaces.nsIQuotaManager;
var gPermURI;
var gPrefs;
var gUsageRequest;
var gPermObj = {
image: function getImageDefaultPermission()
{
if (gPrefs.getIntPref("permissions.default.image") == 2)
return BLOCK;
return ALLOW;
},
cookie: function getCookieDefaultPermission()
{
if (gPrefs.getIntPref("network.cookie.cookieBehavior") == 2)
return BLOCK;
if (gPrefs.getIntPref("network.cookie.lifetimePolicy") == 2)
return SESSION;
return ALLOW;
},
"desktop-notification": function getNotificationDefaultPermission()
{
return BLOCK;
},
popup: function getPopupDefaultPermission()
{
if (gPrefs.getBoolPref("dom.disable_open_during_load"))
return BLOCK;
return ALLOW;
},
install: function getInstallDefaultPermission()
{
try {
if (!gPrefs.getBoolPref("xpinstall.whitelist.required"))
return ALLOW;
}
catch (e) {
}
return BLOCK;
},
geo: function getGeoDefaultPermissions()
{
return BLOCK;
},
indexedDB: function getIndexedDBDefaultPermissions()
{
return UNKNOWN;
},
plugins: function getPluginsDefaultPermissions()
{
return UNKNOWN;
},
fullscreen: function getFullscreenDefaultPermissions()
{
return UNKNOWN;
},
pointerLock: function getPointerLockPermissions()
{
return BLOCK;
},
};
var permissionObserver = {
observe: function (aSubject, aTopic, aData)
{
if (aTopic == "perm-changed") {
var permission = aSubject.QueryInterface(Components.interfaces.nsIPermission);
if (permission.host == gPermURI.host) {
if (permission.type in gPermObj)
initRow(permission.type);
else if (permission.type.startsWith("plugin"))
setPluginsRadioState();
}
}
}
};
function onLoadPermission()
{
gPrefs = Components.classes[PREFERENCES_CONTRACTID]
.getService(Components.interfaces.nsIPrefBranch);
var uri = gDocument.documentURIObject;
var permTab = document.getElementById("permTab");
if (/^https?$/.test(uri.scheme)) {
gPermURI = uri;
var hostText = document.getElementById("hostText");
hostText.value = gPermURI.host;
for (var i in gPermObj)
initRow(i);
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
os.addObserver(permissionObserver, "perm-changed", false);
onUnloadRegistry.push(onUnloadPermission);
permTab.hidden = false;
}
else
permTab.hidden = true;
}
function onUnloadPermission()
{
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
os.removeObserver(permissionObserver, "perm-changed");
if (gUsageRequest) {
gUsageRequest.cancel();
gUsageRequest = null;
}
}
function initRow(aPartId)
{
if (aPartId == "plugins") {
initPluginsRow();
return;
}
var permissionManager = Components.classes[PERMISSION_CONTRACTID]
.getService(nsIPermissionManager);
var checkbox = document.getElementById(aPartId + "Def");
var command = document.getElementById("cmd_" + aPartId + "Toggle");
// Geolocation and PointerLock permission consumers use testExactPermission, not testPermission.
var perm;
if (aPartId == "geo" || aPartId == "pointerLock")
perm = permissionManager.testExactPermission(gPermURI, aPartId);
else
perm = permissionManager.testPermission(gPermURI, aPartId);
if (perm) {
checkbox.checked = false;
command.removeAttribute("disabled");
}
else {
checkbox.checked = true;
command.setAttribute("disabled", "true");
perm = gPermObj[aPartId]();
}
setRadioState(aPartId, perm);
if (aPartId == "indexedDB") {
initIndexedDBRow();
}
}
function onCheckboxClick(aPartId)
{
var permissionManager = Components.classes[PERMISSION_CONTRACTID]
.getService(nsIPermissionManager);
var command = document.getElementById("cmd_" + aPartId + "Toggle");
var checkbox = document.getElementById(aPartId + "Def");
if (checkbox.checked) {
permissionManager.remove(gPermURI.host, aPartId);
command.setAttribute("disabled", "true");
var perm = gPermObj[aPartId]();
setRadioState(aPartId, perm);
}
else {
onRadioClick(aPartId);
command.removeAttribute("disabled");
}
}
function onPluginRadioClick(aEvent) {
onRadioClick(aEvent.originalTarget.getAttribute("id").split('#')[0]);
}
function onRadioClick(aPartId)
{
var permissionManager = Components.classes[PERMISSION_CONTRACTID]
.getService(nsIPermissionManager);
var radioGroup = document.getElementById(aPartId + "RadioGroup");
var id = radioGroup.selectedItem.id;
var permission = id.split('#')[1];
if (permission == UNKNOWN) {
permissionManager.remove(gPermURI.host, aPartId);
} else {
permissionManager.add(gPermURI, aPartId, permission);
}
if (aPartId == "indexedDB" &&
(permission == ALLOW || permission == BLOCK)) {
permissionManager.remove(gPermURI.host, "indexedDB-unlimited");
}
}
function setRadioState(aPartId, aValue)
{
var radio = document.getElementById(aPartId + "#" + aValue);
radio.radioGroup.selectedItem = radio;
}
function initIndexedDBRow()
{
var quotaManager = Components.classes["@mozilla.org/dom/quota/manager;1"]
.getService(nsIQuotaManager);
gUsageRequest =
quotaManager.getUsageForURI(gPermURI, onIndexedDBUsageCallback);
var status = document.getElementById("indexedDBStatus");
var button = document.getElementById("indexedDBClear");
status.value = "";
status.setAttribute("hidden", "true");
button.setAttribute("hidden", "true");
}
function onIndexedDBClear()
{
Components.classes["@mozilla.org/dom/quota/manager;1"]
.getService(nsIQuotaManager)
.clearStoragesForURI(gPermURI);
var permissionManager = Components.classes[PERMISSION_CONTRACTID]
.getService(nsIPermissionManager);
permissionManager.remove(gPermURI.host, "indexedDB-unlimited");
initIndexedDBRow();
}
function onIndexedDBUsageCallback(uri, usage, fileUsage)
{
if (!uri.equals(gPermURI)) {
throw new Error("Callback received for bad URI: " + uri);
}
if (usage) {
if (!("DownloadUtils" in window)) {
Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
}
var status = document.getElementById("indexedDBStatus");
var button = document.getElementById("indexedDBClear");
status.value =
gBundle.getFormattedString("indexedDBUsage",
DownloadUtils.convertByteUnits(usage));
status.removeAttribute("hidden");
button.removeAttribute("hidden");
}
}
// XXX copied this from browser-plugins.js - is there a way to share?
function makeNicePluginName(aName) {
if (aName == "Shockwave Flash")
return "Adobe Flash";
// Clean up the plugin name by stripping off any trailing version numbers
// or "plugin". EG, "Foo Bar Plugin 1.23_02" --> "Foo Bar"
// Do this by first stripping the numbers, etc. off the end, and then
// removing "Plugin" (and then trimming to get rid of any whitespace).
// (Otherwise, something like "Java(TM) Plug-in 1.7.0_07" gets mangled)
let newName = aName.replace(/[\s\d\.\-\_\(\)]+$/, "").replace(/\bplug-?in\b/i, "").trim();
return newName;
}
function fillInPluginPermissionTemplate(aPluginName, aPermissionString) {
let permPluginTemplate = document.getElementById("permPluginTemplate").cloneNode(true);
permPluginTemplate.setAttribute("permString", aPermissionString);
let attrs = [
[ ".permPluginTemplateLabel", "value", aPluginName ],
[ ".permPluginTemplateRadioGroup", "id", aPermissionString + "RadioGroup" ],
[ ".permPluginTemplateRadioDefault", "id", aPermissionString + "#0" ],
[ ".permPluginTemplateRadioAsk", "id", aPermissionString + "#3" ],
[ ".permPluginTemplateRadioAllow", "id", aPermissionString + "#1" ],
[ ".permPluginTemplateRadioBlock", "id", aPermissionString + "#2" ]
];
for (let attr of attrs) {
permPluginTemplate.querySelector(attr[0]).setAttribute(attr[1], attr[2]);
}
return permPluginTemplate;
}
function clearPluginPermissionTemplate() {
let permPluginTemplate = document.getElementById("permPluginTemplate");
permPluginTemplate.hidden = true;
permPluginTemplate.removeAttribute("permString");
document.querySelector(".permPluginTemplateLabel").removeAttribute("value");
document.querySelector(".permPluginTemplateRadioGroup").removeAttribute("id");
document.querySelector(".permPluginTemplateRadioAsk").removeAttribute("id");
document.querySelector(".permPluginTemplateRadioAllow").removeAttribute("id");
document.querySelector(".permPluginTemplateRadioBlock").removeAttribute("id");
}
function initPluginsRow() {
let vulnerableLabel = document.getElementById("browserBundle").getString("pluginActivateVulnerable.label");
let pluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
let permissionMap = Map();
for (let plugin of pluginHost.getPluginTags()) {
if (plugin.disabled) {
continue;
}
for (let mimeType of plugin.getMimeTypes()) {
let permString = pluginHost.getPermissionStringForType(mimeType);
if (!permissionMap.has(permString)) {
var name = makeNicePluginName(plugin.name);
if (permString.startsWith("plugin-vulnerable:")) {
name += " \u2014 " + vulnerableLabel;
}
permissionMap.set(permString, name);
}
}
}
let entries = [{name: item[1], permission: item[0]} for (item of permissionMap)];
entries.sort(function(a, b) {
return a.name < b.name ? -1 : (a.name == b.name ? 0 : 1);
});
let permissionEntries = [
fillInPluginPermissionTemplate(p.name, p.permission) for (p of entries)
];
let permPluginsRow = document.getElementById("permPluginsRow");
clearPluginPermissionTemplate();
if (permissionEntries.length < 1) {
permPluginsRow.hidden = true;
return;
}
for (let permissionEntry of permissionEntries) {
permPluginsRow.appendChild(permissionEntry);
}
setPluginsRadioState();
}
function setPluginsRadioState() {
var permissionManager = Components.classes[PERMISSION_CONTRACTID]
.getService(nsIPermissionManager);
let box = document.getElementById("permPluginsRow");
for (let permissionEntry of box.childNodes) {
if (permissionEntry.hasAttribute("permString")) {
let permString = permissionEntry.getAttribute("permString");
let permission = permissionManager.testPermission(gPermURI, permString);
setRadioState(permString, permission);
}
}
}
|