Bug 1203292 - Replace permissions dropdown with a remove button. r=paolo

MozReview-Commit-ID: LmdRlgzeW1c

--HG--
extra : rebase_source : 06dc8afaa69c42fe753937000c05a3b08bb9d650
This commit is contained in:
Ricky Chien 2016-07-22 12:13:00 +01:00
Родитель 01dbcb42ca
Коммит 6c0688e34b
5 изменённых файлов: 125 добавлений и 59 удалений

Просмотреть файл

@ -7288,50 +7288,39 @@ var gIdentityHandler = {
}
},
setPermission: function (aPermission, aState) {
if (aState == SitePermissions.getDefault(aPermission))
SitePermissions.remove(gBrowser.currentURI, aPermission);
else
SitePermissions.set(gBrowser.currentURI, aPermission, aState);
},
_createPermissionItem: function (aPermission) {
let menulist = document.createElement("menulist");
let menupopup = document.createElement("menupopup");
for (let state of aPermission.availableStates) {
let menuitem = document.createElement("menuitem");
menuitem.setAttribute("value", state.id);
menuitem.setAttribute("label", state.label);
menupopup.appendChild(menuitem);
}
menulist.appendChild(menupopup);
menulist.setAttribute("value", aPermission.state);
menulist.setAttribute("oncommand", "gIdentityHandler.setPermission('" +
aPermission.id + "', this.value)");
menulist.setAttribute("id", "identity-popup-permission:" + aPermission.id);
let label = document.createElement("label");
label.setAttribute("flex", "1");
label.setAttribute("class", "identity-popup-permission-label");
label.setAttribute("control", menulist.getAttribute("id"));
label.textContent = aPermission.label;
let container = document.createElement("hbox");
container.setAttribute("class", "identity-popup-permission-item");
container.setAttribute("align", "center");
let img = document.createElement("image");
let isBlocked = (aPermission.state == SitePermissions.BLOCK) ? " blocked" : "";
img.setAttribute("class",
"identity-popup-permission-icon " + aPermission.id + "-icon" + isBlocked);
let container = document.createElement("hbox");
container.setAttribute("align", "center");
container.appendChild(img);
container.appendChild(label);
container.appendChild(menulist);
let nameLabel = document.createElement("label");
nameLabel.setAttribute("flex", "1");
nameLabel.setAttribute("class", "identity-popup-permission-label");
nameLabel.textContent = SitePermissions.getPermissionLabel(aPermission.id);
// The menuitem text can be long and we don't want the dropdown
// to expand to the width of unselected labels.
// Need to set this attribute after it's appended, otherwise it gets
// overridden with sizetopopup="pref".
menulist.setAttribute("sizetopopup", "none");
let stateLabel = document.createElement("label");
stateLabel.setAttribute("flex", "1");
stateLabel.setAttribute("class", "identity-popup-permission-state-label");
stateLabel.textContent = SitePermissions.getStateLabel(
aPermission.id, aPermission.state);
let button = document.createElement("button");
button.setAttribute("class", "identity-popup-permission-remove-button");
button.addEventListener("command", () => {
this._permissionList.removeChild(container);
this._identityPopupMultiView.setHeightToFit();
SitePermissions.remove(gBrowser.currentURI, aPermission.id);
});
container.appendChild(img);
container.appendChild(nameLabel);
container.appendChild(stateLabel);
container.appendChild(button);
return container;
}

Просмотреть файл

@ -7,7 +7,6 @@ const PERMISSIONS_PAGE = "http://example.com/browser/browser/base/content/test/g
var {SitePermissions} = Cu.import("resource:///modules/SitePermissions.jsm", {});
registerCleanupFunction(function() {
SitePermissions.remove(gBrowser.currentURI, "install");
SitePermissions.remove(gBrowser.currentURI, "cookie");
SitePermissions.remove(gBrowser.currentURI, "geo");
SitePermissions.remove(gBrowser.currentURI, "camera");
@ -30,27 +29,21 @@ add_task(function* testMainViewVisible() {
ok(!is_hidden(emptyLabel), "List of permissions is empty");
gIdentityHandler._identityPopup.hidden = true;
gIdentityHandler.setPermission("install", SitePermissions.ALLOW);
SitePermissions.set(gBrowser.currentURI, "camera", SitePermissions.ALLOW);
gIdentityHandler._identityBox.click();
ok(is_hidden(emptyLabel), "List of permissions is not empty");
let labelText = SitePermissions.getPermissionLabel("install");
let labelText = SitePermissions.getPermissionLabel("camera");
let labels = permissionsList.querySelectorAll(".identity-popup-permission-label");
is(labels.length, 1, "One permission visible in main view");
is(labels[0].textContent, labelText, "Correct value");
let menulists = permissionsList.querySelectorAll("menulist");
is(menulists.length, 1, "One permission visible in main view");
is(menulists[0].id, "identity-popup-permission:install", "Install permission visible");
is(menulists[0].value, "1", "Correct value on install menulist");
gIdentityHandler._identityPopup.hidden = true;
let img = menulists[0].parentNode.querySelector("image");
let img = permissionsList.querySelector("image.identity-popup-permission-icon");
ok(img, "There is an image for the permissions");
ok(img.classList.contains("install-icon"), "proper class is in image class");
ok(img.classList.contains("camera-icon"), "proper class is in image class");
gIdentityHandler.setPermission("install", SitePermissions.getDefault("install"));
SitePermissions.remove(gBrowser.currentURI, "camera");
gIdentityHandler._identityBox.click();
ok(!is_hidden(emptyLabel), "List of permissions is empty");
@ -62,25 +55,57 @@ add_task(function* testIdentityIcon() {
let tab = gBrowser.selectedTab = gBrowser.addTab();
yield promiseTabLoadEvent(tab, PERMISSIONS_PAGE);
gIdentityHandler.setPermission("geo", SitePermissions.ALLOW);
SitePermissions.set(gBrowser.currentURI, "geo", SitePermissions.ALLOW);
ok(gIdentityHandler._identityBox.classList.contains("grantedPermissions"),
"identity-box signals granted permissions");
gIdentityHandler.setPermission("geo", SitePermissions.getDefault("geo"));
SitePermissions.remove(gBrowser.currentURI, "geo");
ok(!gIdentityHandler._identityBox.classList.contains("grantedPermissions"),
"identity-box doesn't signal granted permissions");
gIdentityHandler.setPermission("camera", SitePermissions.BLOCK);
SitePermissions.set(gBrowser.currentURI, "camera", SitePermissions.BLOCK);
ok(!gIdentityHandler._identityBox.classList.contains("grantedPermissions"),
"identity-box doesn't signal granted permissions");
gIdentityHandler.setPermission("cookie", SitePermissions.SESSION);
SitePermissions.set(gBrowser.currentURI, "cookie", SitePermissions.SESSION);
ok(gIdentityHandler._identityBox.classList.contains("grantedPermissions"),
"identity-box signals granted permissions");
SitePermissions.remove(gBrowser.currentURI, "geo");
SitePermissions.remove(gBrowser.currentURI, "camera");
SitePermissions.remove(gBrowser.currentURI, "cookie");
});
add_task(function* testCancelPermission() {
let {gIdentityHandler} = gBrowser.ownerGlobal;
let tab = gBrowser.selectedTab = gBrowser.addTab();
yield promiseTabLoadEvent(tab, PERMISSIONS_PAGE);
let permissionsList = document.getElementById("identity-popup-permission-list");
let emptyLabel = permissionsList.nextSibling;
SitePermissions.set(gBrowser.currentURI, "geo", SitePermissions.ALLOW);
SitePermissions.set(gBrowser.currentURI, "camera", SitePermissions.BLOCK);
gIdentityHandler._identityBox.click();
ok(is_hidden(emptyLabel), "List of permissions is not empty");
let cancelButtons = permissionsList
.querySelectorAll(".identity-popup-permission-remove-button");
cancelButtons[0].click();
let labels = permissionsList.querySelectorAll(".identity-popup-permission-label");
is(labels.length, 1, "One permission should be removed");
cancelButtons[1].click();
labels = permissionsList.querySelectorAll(".identity-popup-permission-label");
is(labels.length, 0, "One permission should be removed");
gIdentityHandler._identityPopup.hidden = true;
});
add_task(function* testPermissionIcons() {
@ -88,9 +113,9 @@ add_task(function* testPermissionIcons() {
let tab = gBrowser.selectedTab = gBrowser.addTab();
yield promiseTabLoadEvent(tab, PERMISSIONS_PAGE);
gIdentityHandler.setPermission("camera", SitePermissions.ALLOW);
gIdentityHandler.setPermission("geo", SitePermissions.BLOCK);
gIdentityHandler.setPermission("microphone", SitePermissions.SESSION);
SitePermissions.set(gBrowser.currentURI, "camera", SitePermissions.ALLOW);
SitePermissions.set(gBrowser.currentURI, "geo", SitePermissions.BLOCK);
SitePermissions.set(gBrowser.currentURI, "microphone", SitePermissions.SESSION);
let geoIcon = gIdentityHandler._identityBox.querySelector("[data-permission-id='geo']");
ok(geoIcon.hasAttribute("showing"), "blocked permission icon is shown");
@ -105,7 +130,7 @@ add_task(function* testPermissionIcons() {
ok(!microphoneIcon.hasAttribute("showing"),
"allowed permission icon is not shown");
gIdentityHandler.setPermission("geo", SitePermissions.getDefault("geo"));
SitePermissions.remove(gBrowser.currentURI, "geo");
ok(!geoIcon.hasAttribute("showing"),
"blocked permission icon is not shown after reset");

Просмотреть файл

@ -362,8 +362,8 @@ description#identity-popup-content-verifier,
margin-inline-start: calc(-1em - 16px);
}
#identity-popup-permission-list menulist {
min-width: 60px;
.identity-popup-permission-item {
min-height: 24px;
}
#identity-popup-permission-list:not(:empty) {
@ -381,5 +381,48 @@ description#identity-popup-content-verifier,
.identity-popup-permission-label {
margin-inline-start: 1em;
word-wrap: break-word;
}
.identity-popup-permission-state-label {
text-align: end;
opacity: 0.6;
}
.identity-popup-permission-remove-button {
-moz-appearance: none;
margin: 0;
border-width: 0;
border-radius: 50%;
min-width: 0;
padding: 2px;
}
.identity-popup-permission-remove-button > .button-box {
border-width: 0;
padding: 0;
}
.identity-popup-permission-remove-button > .button-box > .button-icon {
margin: 0;
width: 16px;
height: 16px;
list-style-image: url(chrome://browser/skin/panel-icons.svg#cancel);
filter: url(chrome://browser/skin/filters.svg#fill);
fill: #999;
}
.identity-popup-permission-remove-button > .button-box > .button-text {
display: none;
}
.identity-popup-permission-remove-button:hover {
background-color: #999;
}
.identity-popup-permission-remove-button:hover > .button-box > .button-icon {
fill: #fff;
}
.identity-popup-permission-remove-button:hover:active {
background-color: #808080;
}

Просмотреть файл

@ -72,6 +72,7 @@
skin/classic/browser/newtab/close.png (../shared/newtab/close.png)
skin/classic/browser/newtab/controls.svg (../shared/newtab/controls.svg)
skin/classic/browser/newtab/whimsycorn.png (../shared/newtab/whimsycorn.png)
skin/classic/browser/panel-icons.svg (../shared/panel-icons.svg)
skin/classic/browser/preferences/in-content/favicon.ico (../shared/incontentprefs/favicon.ico)
skin/classic/browser/preferences/in-content/icons.svg (../shared/incontentprefs/icons.svg)
skin/classic/browser/preferences/in-content/search.css (../shared/incontentprefs/search.css)

Просмотреть файл

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!-- 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/. -->
<svg xmlns="http://www.w3.org/2000/svg"
width="32" height="32" viewBox="0 0 32 32">
<path id="cancel" d="m 6,9.5 6.5,6.5 -6.5,6.5 3.5,3.5 6.5,-6.5 6.5,6.5 3.5,-3.5 -6.5,-6.5 6.5,-6.5 -3.5,-3.5 -6.5,6.5 -6.5,-6.5 z" />
</svg>

После

Ширина:  |  Высота:  |  Размер: 466 B