# HG changeset patch # User Frank-Rainer Grahl # Date 1623162001 14400 # Parent 05f3656bec57cee4d170d4338cd789886bca3061 Bug 1209626 - Stand alone (popup-) Permissions Manager does not show web pages' domain names diff --git a/suite/components/permissions/content/permissionsManager.js b/suite/components/permissions/content/permissionsManager.js --- a/suite/components/permissions/content/permissionsManager.js +++ b/suite/components/permissions/content/permissionsManager.js @@ -1,31 +1,31 @@ /* 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/. */ Cu.import("resource://gre/modules/Services.jsm"); -var additions = []; +var permissions = []; var removals = []; var sortColumn; var sortAscending; var permissionsTreeView = { rowCount: 0, setTree: function(tree) {}, getImageSrc: function(row, column) {}, getProgressMode: function(row, column) {}, getCellValue: function(row, column) {}, getCellText: function(row, column) { if (column.id == "siteCol") - return additions[row].rawHost; + return permissions[row].rawHost; else if (column.id == "statusCol") - return additions[row].capability; + return permissions[row].capability; return ""; }, isSeparator: function(index) { return false; }, isSorted: function() { return false; }, isContainer: function(index) { return false; }, cycleHeader: function(column) {}, getRowProperties: function(row, column) { return ""; }, getColumnProperties: function(column) { return ""; }, @@ -43,28 +43,35 @@ function Startup() { permissionsTree = document.getElementById("permissionsTree"); permissionsBundle = document.getElementById("permissionsBundle"); sortAscending = (permissionsTree.getAttribute("sortAscending") == "true"); sortColumn = permissionsTree.getAttribute("sortColumn"); + var params = { blockVisible : true, + sessionVisible : true, + allowVisible : true, + manageCapability : true + }; + if (window.arguments && window.arguments[0]) { - var params = window.arguments[0]; - document.getElementById("btnBlock").hidden = !params.blockVisible; - document.getElementById("btnSession").hidden = !params.sessionVisible; - document.getElementById("btnAllow").hidden = !params.allowVisible; + params = window.arguments[0]; setHost(params.prefilledHost); permissionType = params.permissionType; gManageCapability = params.manageCapability; introText = params.introText; windowTitle = params.windowTitle; } + document.getElementById("btnBlock").hidden = !params.blockVisible; + document.getElementById("btnSession").hidden = !params.sessionVisible; + document.getElementById("btnAllow").hidden = !params.allowVisible; + document.getElementById("permissionsText").textContent = introText || permissionsBundle.getString(permissionType + "permissionstext"); document.title = windowTitle || permissionsBundle.getString(permissionType + "permissionstitle"); var dialogElement = document.getElementById("permissionsManager"); dialogElement.setAttribute("windowtype", "permissions-" + permissionType); @@ -77,31 +84,47 @@ function Startup() { document.getElementById("urlLabel").hidden = !urlFieldVisible; handleHostInput(document.getElementById("url")); loadPermissions(); } function onAccept() { finalizeChanges(); + reInitialize(); - permissionsTree.setAttribute("sortAscending", !sortAscending); - permissionsTree.setAttribute("sortColumn", sortColumn); + // Don't close the window. + return false; +} + +function onCancel() { + reInitialize(); - return true; + // Don't close the window. + return false; } +function reInitialize() { + permissions = []; + removals = []; + + // Reload permissions tree. + loadPermissions(); +} + + function setHost(aHost) { document.getElementById("url").value = aHost; } -function Permission(id, host, rawHost, type, capability, perm) { +function Permission(id, principal, host, type, capability, perm) { this.id = id; + this.principal = principal; this.host = host; - this.rawHost = rawHost; + this.rawHost = host.replace(/^\./, ""); this.type = type; this.capability = capability; this.perm = perm; } function handleHostInput(aSiteField) { // trim any leading and trailing spaces and scheme // and set buttons appropiately @@ -124,31 +147,37 @@ function loadPermissions() { var enumerator = Services.perms.enumerator; var count = 0; var permission; try { while (enumerator.hasMoreElements()) { permission = enumerator.getNext().QueryInterface(Ci.nsIPermission); if (permission.type == permissionType && - (!gManageCapability || permission.capability == gManageCapability)) - permissionPush(count++, permission.host, permission.type, - capabilityString(permission.capability), permission.capability); + (!gManageCapability || permission.capability == gManageCapability)) { + permissions.push(new Permission(count++, + permission.principal, + permission.principal.URI.host, + permission.type, + capabilityString(permission.capability), + permission.capability)); + } } } catch(ex) { } - permissionsTreeView.rowCount = additions.length; + permissionsTreeView.rowCount = permissions.length; // sort and display the table permissionsTree.view = permissionsTreeView; permissionColumnSort(sortColumn, false); // disable "remove all" button if there are none - document.getElementById("removeAllPermissions").disabled = additions.length == 0; + document.getElementById("removeAllPermissions").disabled = + permissions.length == 0; } function capabilityString(aCapability) { var capability = null; switch (aCapability) { case Ci.nsIPermissionManager.ALLOW_ACTION: capability = "can"; break; @@ -160,118 +189,123 @@ function capabilityString(aCapability) { capability = "canSession"; break; default: break; } return permissionsBundle.getString(capability); } -function permissionPush(aId, aHost, aType, aString, aCapability) { - var rawHost = (aHost.charAt(0) == ".") ? aHost.substring(1, aHost.length) : aHost; - var p = new Permission(aId, aHost, rawHost, aType, aString, aCapability); - additions.push(p); -} - function permissionColumnSort(aColumn, aUpdateSelection) { sortAscending = - SortTree(permissionsTree, permissionsTreeView, additions, + SortTree(permissionsTree, permissionsTreeView, permissions, aColumn, sortColumn, sortAscending, aUpdateSelection); sortColumn = aColumn; } function permissionSelected() { if (Services.perms) { var selections = GetTreeSelections(permissionsTree); document.getElementById("removePermission").disabled = (selections.length < 1); } } function deletePermissions() { - DeleteSelectedItemFromTree(permissionsTree, permissionsTreeView, additions, removals, + DeleteSelectedItemFromTree(permissionsTree, permissionsTreeView, + permissions, removals, "removePermission", "removeAllPermissions"); } function deleteAllPermissions() { - DeleteAllFromTree(permissionsTree, permissionsTreeView, additions, removals, - "removePermission", "removeAllPermissions"); + DeleteAllFromTree(permissionsTree, permissionsTreeView, permissions, + removals, "removePermission", "removeAllPermissions"); } function finalizeChanges() { - var i, p; + let p; - for (i in removals) { - p = removals[i]; + for (let i in permissions) { + p = permissions[i]; try { - Services.perms.remove(p.host, p.type); + // Principal is null so a permission we just added in this session. + if (p.principal == null) { + let uri = Services.io.newURI("https://" + p.host); + Services.perms.add(uri, p.type, p.perm); + } } catch(ex) { } } - for (i in additions) { - p = additions[i]; + for (let i in removals) { + p = removals[i]; try { - var uri = Services.io.newURI("http://" + p.host); - Services.perms.add(uri, p.type, p.perm); + // Principal is not null so not a permission we just added in this + // session. + if (p.principal) { + Services.perms.removeFromPrincipal(p.principal, + p.type); + } } catch(ex) { } } } function handlePermissionKeyPress(e) { if (e.keyCode == 46) { deletePermissions(); } } function addPermission(aPermission) { var textbox = document.getElementById("url"); // trim any leading and trailing spaces and scheme var host = trimSpacesAndScheme(textbox.value); try { - var uri = Services.io.newURI("http://" + host); + let uri = Services.io.newURI("https://" + host); host = uri.host; } catch(ex) { var message = permissionsBundle.getFormattedString("alertInvalid", [host]); var title = permissionsBundle.getString("alertInvalidTitle"); Services.prompt.alert(window, title, message); textbox.value = ""; textbox.focus(); handleHostInput(textbox); return; } // we need this whether the perm exists or not var stringCapability = capabilityString(aPermission); // check whether the permission already exists, if not, add it var exists = false; - for (var i in additions) { - if (additions[i].rawHost == host) { + for (var i in permissions) { + if (permissions[i].rawHost == host) { // Avoid calling the permission manager if the capability settings are // the same. Otherwise allow the call to the permissions manager to // update the listbox for us. - exists = additions[i].perm == aPermission; + exists = permissions[i].perm == aPermission; break; } } if (!exists) { - permissionPush(additions.length, host, permissionType, stringCapability, aPermission); + permissions.push(new Permission(permissions.length, null, host, + permissionType, stringCapability, + aPermission)); - permissionsTreeView.rowCount = additions.length; - permissionsTree.treeBoxObject.rowCountChanged(additions.length - 1, 1); - permissionsTree.treeBoxObject.ensureRowIsVisible(additions.length - 1); + permissionsTreeView.rowCount = permissions.length; + permissionsTree.treeBoxObject.rowCountChanged(permissions.length - 1, 1); + permissionsTree.treeBoxObject.ensureRowIsVisible(permissions.length - 1); } textbox.value = ""; textbox.focus(); // covers a case where the site exists already, so the buttons don't disable handleHostInput(textbox); // enable "remove all" button as needed - document.getElementById("removeAllPermissions").disabled = additions.length == 0; + document.getElementById("removeAllPermissions").disabled = permissions.length == 0; } function doHelpButton() { openHelp(permissionsBundle.getString(permissionType + "permissionshelp"), "chrome://communicator/locale/help/suitehelp.rdf"); return true; } diff --git a/suite/components/permissions/content/permissionsManager.xul b/suite/components/permissions/content/permissionsManager.xul --- a/suite/components/permissions/content/permissionsManager.xul +++ b/suite/components/permissions/content/permissionsManager.xul @@ -12,16 +12,17 @@ buttons="accept,cancel,help" windowtype="exceptions" title="&windowtitle.label;" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" style="width:32em; height:42em;" persist="width height screenX screenY" onload="Startup();" ondialogaccept="return onAccept();" + ondialogcancel="return onCancel();" ondialoghelp="return doHelpButton();">