2012-08-10 13:20:25 -07:00
|
|
|
/* 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/. */
|
2012-05-08 14:47:18 -07:00
|
|
|
|
|
|
|
const UNKNOWN = nsIPermissionManager.UNKNOWN_ACTION; // 0
|
|
|
|
const ALLOW = nsIPermissionManager.ALLOW_ACTION; // 1
|
|
|
|
const BLOCK = nsIPermissionManager.DENY_ACTION; // 2
|
|
|
|
const SESSION = nsICookiePermission.ACCESS_SESSION; // 8
|
2010-09-10 12:12:11 -07:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
const nsIQuotaManager = Components.interfaces.nsIQuotaManager;
|
2010-09-10 12:12:11 -07:00
|
|
|
|
2007-04-12 18:26:39 -07:00
|
|
|
var gPermURI;
|
|
|
|
var gPrefs;
|
2013-03-26 04:13:17 -07:00
|
|
|
var gUsageRequest;
|
2007-04-12 18:26:39 -07:00
|
|
|
|
|
|
|
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;
|
|
|
|
},
|
2012-07-12 08:45:38 -07:00
|
|
|
"desktop-notification": function getNotificationDefaultPermission()
|
|
|
|
{
|
|
|
|
return BLOCK;
|
|
|
|
},
|
2007-04-12 18:26:39 -07:00
|
|
|
popup: function getPopupDefaultPermission()
|
|
|
|
{
|
|
|
|
if (gPrefs.getBoolPref("dom.disable_open_during_load"))
|
|
|
|
return BLOCK;
|
|
|
|
return ALLOW;
|
|
|
|
},
|
|
|
|
install: function getInstallDefaultPermission()
|
|
|
|
{
|
2010-04-28 15:02:43 -07:00
|
|
|
try {
|
|
|
|
if (!gPrefs.getBoolPref("xpinstall.whitelist.required"))
|
|
|
|
return ALLOW;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
}
|
|
|
|
return BLOCK;
|
2009-05-06 15:38:50 -07:00
|
|
|
},
|
|
|
|
geo: function getGeoDefaultPermissions()
|
|
|
|
{
|
2010-09-10 12:12:11 -07:00
|
|
|
return BLOCK;
|
|
|
|
},
|
|
|
|
indexedDB: function getIndexedDBDefaultPermissions()
|
|
|
|
{
|
2012-07-05 14:11:48 -07:00
|
|
|
return UNKNOWN;
|
2012-04-18 11:40:30 -07:00
|
|
|
},
|
|
|
|
plugins: function getPluginsDefaultPermissions()
|
|
|
|
{
|
2013-02-10 18:27:02 -08:00
|
|
|
return UNKNOWN;
|
2012-05-08 14:47:18 -07:00
|
|
|
},
|
|
|
|
fullscreen: function getFullscreenDefaultPermissions()
|
|
|
|
{
|
|
|
|
return UNKNOWN;
|
2013-03-24 03:32:44 -07:00
|
|
|
},
|
|
|
|
pointerLock: function getPointerLockPermissions()
|
|
|
|
{
|
|
|
|
return BLOCK;
|
|
|
|
},
|
2007-04-12 18:26:39 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
var permissionObserver = {
|
|
|
|
observe: function (aSubject, aTopic, aData)
|
|
|
|
{
|
|
|
|
if (aTopic == "perm-changed") {
|
|
|
|
var permission = aSubject.QueryInterface(Components.interfaces.nsIPermission);
|
2013-02-10 18:27:02 -08:00
|
|
|
if (permission.host == gPermURI.host) {
|
|
|
|
if (permission.type in gPermObj)
|
|
|
|
initRow(permission.type);
|
|
|
|
else if (permission.type.startsWith("plugin"))
|
|
|
|
setPluginsRadioState();
|
|
|
|
}
|
2007-04-12 18:26:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function onLoadPermission()
|
|
|
|
{
|
|
|
|
gPrefs = Components.classes[PREFERENCES_CONTRACTID]
|
2012-01-16 17:34:51 -08:00
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
2007-04-12 18:26:39 -07:00
|
|
|
|
|
|
|
var uri = gDocument.documentURIObject;
|
2007-08-06 09:13:05 -07:00
|
|
|
var permTab = document.getElementById("permTab");
|
2012-09-23 12:09:29 -07:00
|
|
|
if (/^https?$/.test(uri.scheme)) {
|
2007-04-12 18:26:39 -07:00
|
|
|
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);
|
2007-08-06 09:13:05 -07:00
|
|
|
permTab.hidden = false;
|
2007-04-12 18:26:39 -07:00
|
|
|
}
|
|
|
|
else
|
2007-08-06 09:13:05 -07:00
|
|
|
permTab.hidden = true;
|
2007-04-12 18:26:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function onUnloadPermission()
|
|
|
|
{
|
|
|
|
var os = Components.classes["@mozilla.org/observer-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIObserverService);
|
|
|
|
os.removeObserver(permissionObserver, "perm-changed");
|
2010-10-19 10:58:33 -07:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
if (gUsageRequest) {
|
|
|
|
gUsageRequest.cancel();
|
|
|
|
gUsageRequest = null;
|
|
|
|
}
|
2007-04-12 18:26:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function initRow(aPartId)
|
|
|
|
{
|
2013-02-10 18:27:02 -08:00
|
|
|
if (aPartId == "plugins") {
|
|
|
|
initPluginsRow();
|
|
|
|
return;
|
|
|
|
}
|
2012-04-18 11:40:30 -07:00
|
|
|
|
2007-04-12 18:26:39 -07:00
|
|
|
var permissionManager = Components.classes[PERMISSION_CONTRACTID]
|
|
|
|
.getService(nsIPermissionManager);
|
|
|
|
|
|
|
|
var checkbox = document.getElementById(aPartId + "Def");
|
|
|
|
var command = document.getElementById("cmd_" + aPartId + "Toggle");
|
2013-03-24 03:32:44 -07:00
|
|
|
// 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);
|
|
|
|
|
2007-04-12 18:26:39 -07:00
|
|
|
if (perm) {
|
|
|
|
checkbox.checked = false;
|
|
|
|
command.removeAttribute("disabled");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
checkbox.checked = true;
|
|
|
|
command.setAttribute("disabled", "true");
|
|
|
|
perm = gPermObj[aPartId]();
|
|
|
|
}
|
|
|
|
setRadioState(aPartId, perm);
|
2010-09-10 12:12:11 -07:00
|
|
|
|
|
|
|
if (aPartId == "indexedDB") {
|
|
|
|
initIndexedDBRow();
|
|
|
|
}
|
2007-04-12 18:26:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-10 18:27:02 -08:00
|
|
|
function onPluginRadioClick(aEvent) {
|
|
|
|
onRadioClick(aEvent.originalTarget.getAttribute("id").split('#')[0]);
|
|
|
|
}
|
|
|
|
|
2007-04-12 18:26:39 -07:00
|
|
|
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];
|
|
|
|
permissionManager.add(gPermURI, aPartId, permission);
|
2012-07-05 14:11:48 -07:00
|
|
|
if (aPartId == "indexedDB" &&
|
|
|
|
(permission == ALLOW || permission == BLOCK)) {
|
2010-09-10 12:12:11 -07:00
|
|
|
permissionManager.remove(gPermURI.host, "indexedDB-unlimited");
|
|
|
|
}
|
2012-05-08 14:47:18 -07:00
|
|
|
if (aPartId == "fullscreen" && permission == UNKNOWN) {
|
|
|
|
permissionManager.remove(gPermURI.host, "fullscreen");
|
|
|
|
}
|
2007-04-12 18:26:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function setRadioState(aPartId, aValue)
|
|
|
|
{
|
|
|
|
var radio = document.getElementById(aPartId + "#" + aValue);
|
|
|
|
radio.radioGroup.selectedItem = radio;
|
|
|
|
}
|
2010-09-10 12:12:11 -07:00
|
|
|
|
|
|
|
function initIndexedDBRow()
|
|
|
|
{
|
2013-03-26 04:13:17 -07:00
|
|
|
var quotaManager = Components.classes["@mozilla.org/dom/quota/manager;1"]
|
|
|
|
.getService(nsIQuotaManager);
|
|
|
|
gUsageRequest =
|
|
|
|
quotaManager.getUsageForURI(gPermURI, onIndexedDBUsageCallback);
|
2010-10-19 10:58:33 -07:00
|
|
|
|
2010-09-10 12:12:11 -07:00
|
|
|
var status = document.getElementById("indexedDBStatus");
|
|
|
|
var button = document.getElementById("indexedDBClear");
|
|
|
|
|
2010-10-19 10:58:33 -07:00
|
|
|
status.value = "";
|
|
|
|
status.setAttribute("hidden", "true");
|
|
|
|
button.setAttribute("hidden", "true");
|
2010-09-10 12:12:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function onIndexedDBClear()
|
|
|
|
{
|
2013-03-26 04:13:17 -07:00
|
|
|
Components.classes["@mozilla.org/dom/quota/manager;1"]
|
|
|
|
.getService(nsIQuotaManager)
|
|
|
|
.clearStoragesForURI(gPermURI);
|
2010-09-10 12:12:11 -07:00
|
|
|
|
|
|
|
var permissionManager = Components.classes[PERMISSION_CONTRACTID]
|
|
|
|
.getService(nsIPermissionManager);
|
|
|
|
permissionManager.remove(gPermURI.host, "indexedDB-unlimited");
|
|
|
|
initIndexedDBRow();
|
|
|
|
}
|
2010-10-19 10:58:33 -07:00
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
function onIndexedDBUsageCallback(uri, usage, fileUsage)
|
2010-10-19 10:58:33 -07:00
|
|
|
{
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
2013-02-10 18:27:02 -08:00
|
|
|
|
|
|
|
// 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");
|
|
|
|
permPluginTemplate.setAttribute("permString", aPermissionString);
|
|
|
|
let attrs = [
|
|
|
|
[ ".permPluginTemplateLabel", "value", aPluginName ],
|
|
|
|
[ ".permPluginTemplateRadioGroup", "id", aPermissionString + "RadioGroup" ],
|
|
|
|
[ ".permPluginTemplateRadioAsk", "id", aPermissionString + "#0" ],
|
|
|
|
[ ".permPluginTemplateRadioAllow", "id", aPermissionString + "#1" ],
|
|
|
|
[ ".permPluginTemplateRadioBlock", "id", aPermissionString + "#2" ]
|
|
|
|
];
|
|
|
|
|
|
|
|
for (let attr of attrs) {
|
|
|
|
document.querySelector(attr[0]).setAttribute(attr[1], attr[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return permPluginTemplate.cloneNode(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 pluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
|
|
|
|
let tags = pluginHost.getPluginTags().filter(function(aTag) {
|
|
|
|
let mimeTypes = aTag.getMimeTypes();
|
|
|
|
if (mimeTypes.length < 1)
|
|
|
|
return false;
|
2013-03-27 22:19:41 -07:00
|
|
|
let mimeType = mimeTypes[0];
|
2013-02-10 18:27:02 -08:00
|
|
|
return (!aTag.disabled && pluginHost.isPluginClickToPlayForType(mimeType));
|
|
|
|
});
|
|
|
|
|
|
|
|
tags.sort(function(tagA, tagB) {
|
|
|
|
let nameA = makeNicePluginName(tagA.name);
|
|
|
|
let nameB = makeNicePluginName(tagB.name);
|
|
|
|
return nameA < nameB ? -1 : (nameA == nameB ? 0 : 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
let permissionEntries = [];
|
|
|
|
for (let plugin of tags) {
|
2013-03-27 22:19:41 -07:00
|
|
|
let mimeType = plugin.getMimeTypes()[0];
|
2013-02-10 18:27:02 -08:00
|
|
|
let permString = pluginHost.getPermissionStringForType(mimeType);
|
|
|
|
let pluginName = makeNicePluginName(plugin.name)
|
|
|
|
let permEntry = fillInPluginPermissionTemplate(pluginName, permString);
|
|
|
|
permissionEntries.push(permEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|