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
|
|
|
|
2013-07-09 05:44:41 -07:00
|
|
|
Components.utils.import("resource:///modules/SitePermissions.jsm");
|
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;
|
2013-03-26 04:13:17 -07:00
|
|
|
var gUsageRequest;
|
2007-04-12 18:26:39 -07:00
|
|
|
|
2013-07-09 05:44:41 -07:00
|
|
|
var gPermissions = SitePermissions.listPermissions();
|
|
|
|
gPermissions.push("plugins");
|
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) {
|
2013-07-09 05:44:41 -07:00
|
|
|
if (gPermissions.indexOf(permission.type) > -1)
|
2013-02-10 18:27:02 -08:00
|
|
|
initRow(permission.type);
|
|
|
|
else if (permission.type.startsWith("plugin"))
|
|
|
|
setPluginsRadioState();
|
|
|
|
}
|
2007-04-12 18:26:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function onLoadPermission()
|
|
|
|
{
|
|
|
|
var uri = gDocument.documentURIObject;
|
2007-08-06 09:13:05 -07:00
|
|
|
var permTab = document.getElementById("permTab");
|
2013-07-09 05:44:41 -07:00
|
|
|
if (SitePermissions.isSupportedURI(uri)) {
|
2007-04-12 18:26:39 -07:00
|
|
|
gPermURI = uri;
|
|
|
|
var hostText = document.getElementById("hostText");
|
|
|
|
hostText.value = gPermURI.host;
|
|
|
|
|
2013-07-09 05:44:41 -07:00
|
|
|
for (var i of gPermissions)
|
2007-04-12 18:26:39 -07:00
|
|
|
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
|
|
|
|
2013-07-09 05:44:41 -07:00
|
|
|
createRow(aPartId);
|
2007-04-12 18:26:39 -07:00
|
|
|
|
|
|
|
var checkbox = document.getElementById(aPartId + "Def");
|
|
|
|
var command = document.getElementById("cmd_" + aPartId + "Toggle");
|
2013-07-09 05:44:41 -07:00
|
|
|
var perm = SitePermissions.get(gPermURI, aPartId);
|
2013-03-24 03:32:44 -07:00
|
|
|
|
2007-04-12 18:26:39 -07:00
|
|
|
if (perm) {
|
|
|
|
checkbox.checked = false;
|
|
|
|
command.removeAttribute("disabled");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
checkbox.checked = true;
|
|
|
|
command.setAttribute("disabled", "true");
|
2013-07-09 05:44:41 -07:00
|
|
|
perm = SitePermissions.getDefault(aPartId);
|
2007-04-12 18:26:39 -07:00
|
|
|
}
|
|
|
|
setRadioState(aPartId, perm);
|
2010-09-10 12:12:11 -07:00
|
|
|
|
|
|
|
if (aPartId == "indexedDB") {
|
|
|
|
initIndexedDBRow();
|
|
|
|
}
|
2007-04-12 18:26:39 -07:00
|
|
|
}
|
|
|
|
|
2013-07-09 05:44:41 -07:00
|
|
|
function createRow(aPartId) {
|
|
|
|
let rowId = "perm-" + aPartId + "-row";
|
|
|
|
if (document.getElementById(rowId))
|
|
|
|
return;
|
|
|
|
|
|
|
|
let commandId = "cmd_" + aPartId + "Toggle";
|
|
|
|
let labelId = "perm-" + aPartId + "-label";
|
|
|
|
let radiogroupId = aPartId + "RadioGroup";
|
|
|
|
|
|
|
|
let command = document.createElement("command");
|
|
|
|
command.setAttribute("id", commandId);
|
|
|
|
command.setAttribute("oncommand", "onRadioClick('" + aPartId + "');");
|
|
|
|
document.getElementById("pageInfoCommandSet").appendChild(command);
|
|
|
|
|
|
|
|
let row = document.createElement("vbox");
|
|
|
|
row.setAttribute("id", rowId);
|
|
|
|
row.setAttribute("class", "permission");
|
|
|
|
|
|
|
|
let label = document.createElement("label");
|
|
|
|
label.setAttribute("id", labelId);
|
|
|
|
label.setAttribute("control", radiogroupId);
|
|
|
|
label.setAttribute("value", SitePermissions.getPermissionLabel(aPartId));
|
|
|
|
label.setAttribute("class", "permissionLabel");
|
|
|
|
row.appendChild(label);
|
|
|
|
|
|
|
|
let controls = document.createElement("hbox");
|
|
|
|
controls.setAttribute("role", "group");
|
|
|
|
controls.setAttribute("aria-labelledby", labelId);
|
|
|
|
|
|
|
|
let checkbox = document.createElement("checkbox");
|
|
|
|
checkbox.setAttribute("id", aPartId + "Def");
|
|
|
|
checkbox.setAttribute("oncommand", "onCheckboxClick('" + aPartId + "');");
|
|
|
|
checkbox.setAttribute("label", gBundle.getString("permissions.useDefault"));
|
|
|
|
controls.appendChild(checkbox);
|
|
|
|
|
|
|
|
let spacer = document.createElement("spacer");
|
|
|
|
spacer.setAttribute("flex", "1");
|
|
|
|
controls.appendChild(spacer);
|
|
|
|
|
|
|
|
let radiogroup = document.createElement("radiogroup");
|
|
|
|
radiogroup.setAttribute("id", radiogroupId);
|
|
|
|
radiogroup.setAttribute("orient", "horizontal");
|
|
|
|
for (let state of SitePermissions.getAvailableStates(aPartId)) {
|
|
|
|
let radio = document.createElement("radio");
|
|
|
|
radio.setAttribute("id", aPartId + "#" + state);
|
2013-07-16 00:59:34 -07:00
|
|
|
radio.setAttribute("label", SitePermissions.getStateLabel(aPartId, state));
|
2013-07-09 05:44:41 -07:00
|
|
|
radio.setAttribute("command", commandId);
|
|
|
|
radiogroup.appendChild(radio);
|
|
|
|
}
|
|
|
|
controls.appendChild(radiogroup);
|
|
|
|
|
|
|
|
row.appendChild(controls);
|
|
|
|
|
|
|
|
document.getElementById("permList").appendChild(row);
|
|
|
|
}
|
|
|
|
|
2007-04-12 18:26:39 -07:00
|
|
|
function onCheckboxClick(aPartId)
|
|
|
|
{
|
|
|
|
var command = document.getElementById("cmd_" + aPartId + "Toggle");
|
|
|
|
var checkbox = document.getElementById(aPartId + "Def");
|
|
|
|
if (checkbox.checked) {
|
2013-07-19 14:15:35 -07:00
|
|
|
SitePermissions.remove(gPermURI, aPartId);
|
2007-04-12 18:26:39 -07:00
|
|
|
command.setAttribute("disabled", "true");
|
2013-07-09 05:44:41 -07:00
|
|
|
var perm = SitePermissions.getDefault(aPartId);
|
2007-04-12 18:26:39 -07:00
|
|
|
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 radioGroup = document.getElementById(aPartId + "RadioGroup");
|
|
|
|
var id = radioGroup.selectedItem.id;
|
|
|
|
var permission = id.split('#')[1];
|
2013-07-09 05:44:41 -07:00
|
|
|
SitePermissions.set(gPermURI, aPartId, permission);
|
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-07-09 05:44:41 -07:00
|
|
|
let row = document.getElementById("perm-indexedDB-row");
|
|
|
|
let extras = document.getElementById("perm-indexedDB-extras");
|
|
|
|
|
|
|
|
row.appendChild(extras);
|
|
|
|
|
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
|
|
|
|
2013-07-09 05:44:41 -07:00
|
|
|
SitePermissions.remove(gPermURI, "indexedDB-unlimited");
|
2010-09-10 12:12:11 -07:00
|
|
|
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) {
|
2013-06-11 07:58:43 -07:00
|
|
|
let permPluginTemplate = document.getElementById("permPluginTemplate").cloneNode(true);
|
2013-02-10 18:27:02 -08:00
|
|
|
permPluginTemplate.setAttribute("permString", aPermissionString);
|
|
|
|
let attrs = [
|
|
|
|
[ ".permPluginTemplateLabel", "value", aPluginName ],
|
|
|
|
[ ".permPluginTemplateRadioGroup", "id", aPermissionString + "RadioGroup" ],
|
2013-06-11 07:58:43 -07:00
|
|
|
[ ".permPluginTemplateRadioDefault", "id", aPermissionString + "#0" ],
|
|
|
|
[ ".permPluginTemplateRadioAsk", "id", aPermissionString + "#3" ],
|
2013-02-10 18:27:02 -08:00
|
|
|
[ ".permPluginTemplateRadioAllow", "id", aPermissionString + "#1" ],
|
|
|
|
[ ".permPluginTemplateRadioBlock", "id", aPermissionString + "#2" ]
|
|
|
|
];
|
|
|
|
|
|
|
|
for (let attr of attrs) {
|
2013-06-11 07:58:43 -07:00
|
|
|
permPluginTemplate.querySelector(attr[0]).setAttribute(attr[1], attr[2]);
|
2013-02-10 18:27:02 -08:00
|
|
|
}
|
|
|
|
|
2013-06-11 07:58:43 -07:00
|
|
|
return permPluginTemplate;
|
2013-02-10 18:27:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2013-06-24 05:51:07 -07:00
|
|
|
let vulnerableLabel = document.getElementById("browserBundle").getString("pluginActivateVulnerable.label");
|
2013-02-10 18:27:02 -08:00
|
|
|
let pluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
|
|
|
|
|
2013-06-11 07:58:43 -07:00
|
|
|
let permissionMap = Map();
|
2013-02-10 18:27:02 -08:00
|
|
|
|
2013-06-11 07:58:43 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2013-02-10 18:27:02 -08:00
|
|
|
}
|
|
|
|
|
2013-06-11 07:58:43 -07:00
|
|
|
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)
|
|
|
|
];
|
|
|
|
|
2013-07-09 05:44:41 -07:00
|
|
|
let permPluginsRow = document.getElementById("perm-plugins-row");
|
2013-02-10 18:27:02 -08:00
|
|
|
clearPluginPermissionTemplate();
|
|
|
|
if (permissionEntries.length < 1) {
|
|
|
|
permPluginsRow.hidden = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let permissionEntry of permissionEntries) {
|
|
|
|
permPluginsRow.appendChild(permissionEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
setPluginsRadioState();
|
|
|
|
}
|
|
|
|
|
|
|
|
function setPluginsRadioState() {
|
2013-07-09 05:44:41 -07:00
|
|
|
let box = document.getElementById("perm-plugins-row");
|
2013-02-10 18:27:02 -08:00
|
|
|
for (let permissionEntry of box.childNodes) {
|
|
|
|
if (permissionEntry.hasAttribute("permString")) {
|
|
|
|
let permString = permissionEntry.getAttribute("permString");
|
2013-07-09 05:44:41 -07:00
|
|
|
let permission = SitePermissions.get(gPermURI, permString);
|
2013-02-10 18:27:02 -08:00
|
|
|
setRadioState(permString, permission);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|