Skip to content

Commit

Permalink
Bug 1741545 add sitepermission category to about:addons r=fluent-revi…
Browse files Browse the repository at this point in the history
…ewers,rpl

Differential Revision: https://phabricator.services.mozilla.com/D131566
  • Loading branch information
mixedpuppy committed Dec 15, 2021
1 parent ec9a017 commit 39b6e50
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type.locale.name=Languages
type.plugin.name=Plugins
type.dictionary.name=Dictionaries
type.service.name=Services
type.sitepermission.name=Site Permissions
type.legacy.name=Legacy Extensions
type.unsupported.name=Unsupported

Expand All @@ -79,6 +80,7 @@ listHeading.theme=Manage Your Themes
listHeading.plugin=Manage Your Plugins
listHeading.locale=Manage Your Languages
listHeading.dictionary=Manage Your Dictionaries
listHeading.sitepermission=Manage Your Site Permissions

searchLabel.extension=Find more extensions
searchLabel.theme=Find more themes
9 changes: 9 additions & 0 deletions toolkit/locales/en-US/toolkit/about/aboutAddons.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ addon-category-available-updates-title =
addon-category-recent-updates = Recent Updates
addon-category-recent-updates-title =
.title = Recent Updates
addon-category-sitepermission = Site Permissions
addon-category-sitepermission-title =
.title = Site Permissions
## These are global warnings

Expand Down Expand Up @@ -365,6 +368,9 @@ dictionary-disabled-heading = Disabled
locale-enabled-heading = Enabled
locale-disabled-heading = Disabled
sitepermission-enabled-heading = Enabled
sitepermission-disabled-heading = Disabled
always-activate-button = Always Activate
never-activate-button = Never Activate
Expand Down Expand Up @@ -452,6 +458,8 @@ addon-permissions-learnmore = Learn more about permissions
recommended-extensions-heading = Recommended Extensions
recommended-themes-heading = Recommended Themes
addon-sitepermissions-required = Grants the following capabilities to <span data-l10n-name="hostname">{ $hostname }</span>:
# A recommendation for the Firefox Color theme shown at the bottom of the theme
# list view. The "Firefox Color" name itself should not be translated.
recommended-theme-1 = Feeling creative? <a data-l10n-name="link">Build your own theme with Firefox Color.</a>
Expand All @@ -464,6 +472,7 @@ plugin-heading = Manage Your Plugins
dictionary-heading = Manage Your Dictionaries
locale-heading = Manage Your Languages
updates-heading = Manage Your Updates
sitepermission-heading = Manage Your Site Permissions
discover-heading = Personalize Your { -brand-short-name }
shortcuts-heading = Manage Extension Shortcuts
Expand Down
8 changes: 8 additions & 0 deletions toolkit/mozapps/extensions/content/aboutaddons.css
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ body {
.category[name="recent-updates"] {
background-image: url("chrome://mozapps/skin/extensions/category-recent.svg");
}
.category[name="sitepermission"] {
background-image: url("chrome://mozapps/skin/extensions/category-sitepermission.svg");
}

.sticky-container {
background: var(--in-content-page-background);
Expand Down Expand Up @@ -512,6 +515,7 @@ addon-details {
background-position-x: right 8px;
}

.addon-detail-sitepermissions,
.addon-detail-row {
display: flex;
justify-content: space-between;
Expand Down Expand Up @@ -802,3 +806,7 @@ section:not(:empty) ~ #empty-addons-message {
.monochromatic-addon-list .addon-name-container .spacer {
display: none;
}

.permission-header > .addon-sitepermissions-host {
font-weight: bolder;
}
11 changes: 11 additions & 0 deletions toolkit/mozapps/extensions/content/aboutaddons.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<button is="category-button" viewid="addons://list/plugin" class="category" role="tab" name="plugin"></button>
<button is="category-button" viewid="addons://list/dictionary" class="category" role="tab" name="dictionary" hidden default-hidden></button>
<button is="category-button" viewid="addons://list/locale" class="category" role="tab" name="locale" hidden default-hidden></button>
<button is="category-button" viewid="addons://list/sitepermission" class="category" role="tab" name="sitepermission" hidden default-hidden></button>
<button is="category-button" viewid="addons://updates/available" class="category" role="tab" name="available-updates" hidden default-hidden></button>
<button is="category-button" viewid="addons://updates/recent" class="category" role="tab" name="recent-updates" hidden default-hidden></button>
</categories-box>
Expand Down Expand Up @@ -135,6 +136,13 @@ <h2 class="permission-header" data-l10n-id="addon-permissions-optional"></h2>
</div>
</template>

<template name="addon-sitepermissions-list">
<div class="addon-permissions-required" hidden>
<h2 class="permission-header" data-l10n-id="addon-sitepermissions-required"><span data-l10n-name="hostname" class="addon-sitepermissions-host"></span></h2>
<ul class="addon-permissions-list"></ul>
</div>
</template>

<template name="card">
<div class="card addon">
<img class="card-heading-image">
Expand Down Expand Up @@ -232,6 +240,9 @@ <h3 class="disco-addon-name"></h3>
data-l10n-attrs="accesskey">
</button>
</div>
<div class="addon-detail-sitepermissions">
<addon-sitepermissions-list></addon-sitepermissions-list>
</div>
<div class="addon-detail-row addon-detail-row-updates">
<label data-l10n-id="addon-detail-updates-label"></label>
<div class="addon-detail-actions">
Expand Down
53 changes: 51 additions & 2 deletions toolkit/mozapps/extensions/content/aboutaddons.js
Original file line number Diff line number Diff line change
Expand Up @@ -2648,6 +2648,48 @@ class AddonPermissionsList extends HTMLElement {
}
customElements.define("addon-permissions-list", AddonPermissionsList);

class AddonSitePermissionsList extends HTMLElement {
setAddon(addon) {
this.addon = addon;
this.render();
}

async render() {
let appName = brandBundle.GetStringFromName("brandShortName");
let permissions = Extension.formatPermissionStrings(
{
sitePermissions: this.addon.sitePermissions,
siteOrigin: this.addon.siteOrigin,
appName,
},
browserBundle
);

this.textContent = "";
let frag = importTemplate("addon-sitepermissions-list");

if (permissions.msgs.length) {
let section = frag.querySelector(".addon-permissions-required");
section.hidden = false;
let list = section.querySelector(".addon-permissions-list");
let header = section.querySelector(".permission-header");
document.l10n.setAttributes(header, "addon-sitepermissions-required", {
hostname: new URL(this.addon.siteOrigin).hostname,
});

for (let msg of permissions.msgs) {
let item = document.createElement("li");
item.classList.add("permission-info", "permission-checked");
item.appendChild(document.createTextNode(msg));
list.appendChild(item);
}
}

this.appendChild(frag);
}
}
customElements.define("addon-sitepermissions-list", AddonSitePermissionsList);

class AddonDetails extends HTMLElement {
connectedCallback() {
if (!this.children.length) {
Expand Down Expand Up @@ -2787,6 +2829,10 @@ class AddonDetails extends HTMLElement {
this.permissionsList = this.querySelector("addon-permissions-list");
this.permissionsList.setAddon(addon);

// Set the add-on for the sitepermissions section.
this.sitePermissionsList = this.querySelector("addon-sitepermissions-list");
this.sitePermissionsList.setAddon(addon);

// Set the add-on for the preferences section.
this.inlineOptions = this.querySelector("inline-options-browser");
this.inlineOptions.setAddon(addon);
Expand Down Expand Up @@ -3311,7 +3357,10 @@ class AddonCard extends HTMLElement {
toggleDisabledButton,
`${toggleDisabledAction}-addon-button`
);
} else if (addon.type === "extension") {
} else if (
addon.type === "extension" ||
addon.type === "sitepermission"
) {
toggleDisabledButton.checked = !addon.userDisabled;
}
}
Expand Down Expand Up @@ -3424,7 +3473,7 @@ class AddonCard extends HTMLElement {
if (addon.type != "theme") {
this.card.querySelector(".theme-enable-button").remove();
}
if (addon.type != "extension") {
if (addon.type != "extension" && addon.type != "sitepermission") {
this.card.querySelector(".extension-enable-button").remove();
}

Expand Down
8 changes: 8 additions & 0 deletions toolkit/mozapps/extensions/internal/XPIProvider.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const ALL_EXTERNAL_TYPES = new Set([
"dictionary",
"extension",
"locale",
"sitepermission",
"theme",
]);

Expand Down Expand Up @@ -3328,6 +3329,13 @@ var addonTypes = [
AddonManager.VIEW_TYPE_LIST,
8000
),
new AddonManagerPrivate.AddonType(
"sitepermission",
URI_EXTENSION_STRINGS,
"type.sitepermission.name",
AddonManager.VIEW_TYPE_LIST,
9000
),
];

AddonManagerPrivate.registerProvider(XPIProvider, addonTypes);
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ add_task(async function enableHtmlViews() {
},
type: "extension",
},
{
id: "[email protected]",
name: "Test site permission add-on",
creator: { name: "you got it" },
description: "permission description",
fullDescription: "detailed description",
siteOrigin: "http://mochi.test",
sitePermissions: ["midi"],
type: "sitepermission",
},
{
id: "[email protected]",
name: "Test theme",
Expand Down Expand Up @@ -782,6 +792,44 @@ add_task(async function testStaticTheme() {
await closeView(win);
});

add_task(async function testSitePermission() {
let win = await loadInitialView("sitepermission");

// The list card.
let card = getAddonCard(win, "[email protected]");
ok(!card.hasAttribute("expanded"), "The list card is not expanded");

// Load the detail view.
let loaded = waitForViewLoad(win);
card.querySelector('[action="expand"]').click();
await loaded;

card = getAddonCard(win, "[email protected]");

// Check all the deck buttons are hidden.
assertDeckHeadingHidden(card.details.tabGroup);

let rows = getDetailRows(card);

// Automatic updates.
let row = rows.shift();
checkLabel(row, "updates");

// Author.
let author = rows.shift();
checkLabel(author, "author");

is(rows.length, 0, "There was only 1 row");

let permissions = Array.from(
card.querySelectorAll(".addon-permissions-list .permission-info")
);
is(permissions.length, 1, "a permission is listed");
is(permissions[0].textContent, "Access MIDI devices", "got midi permission");

await closeView(win);
});

add_task(async function testPrivateBrowsingExtension() {
Services.telemetry.clearEvents();
let id = "[email protected]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -908,9 +908,27 @@ add_task(async function testSectionHeadingKeys() {
type: "dictionary",
userDisabled: true,
},
{
id: "test-sitepermission",
name: "Test Enabled Site Permission",
type: "sitepermission",
},
{
id: "test-sitepermission-disabled",
name: "Test Disabled Site Permission",
type: "sitepermission",
userDisabled: true,
},
]);

for (let type of ["extension", "theme", "plugin", "locale", "dictionary"]) {
for (let type of [
"extension",
"theme",
"plugin",
"locale",
"dictionary",
"sitepermission",
]) {
let win = await loadInitialView(type);
let doc = win.document;

Expand Down
6 changes: 6 additions & 0 deletions toolkit/themes/shared/extensions/category-sitepermission.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions toolkit/themes/shared/mozapps.inc.mn
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
skin/classic/mozapps/extensions/category-extensions.svg (../../shared/extensions/category-extensions.svg)
skin/classic/mozapps/extensions/category-plugins.svg (../../shared/extensions/category-plugins.svg)
skin/classic/mozapps/extensions/category-recent.svg (../../shared/extensions/category-recent.svg)
skin/classic/mozapps/extensions/category-sitepermission.svg (../../shared/extensions/category-sitepermission.svg)
skin/classic/mozapps/extensions/extension.svg (../../shared/extensions/extension.svg)
skin/classic/mozapps/extensions/recommended.svg (../../shared/extensions/recommended.svg)
skin/classic/mozapps/extensions/line.svg (../../shared/extensions/line.svg)
Expand Down

0 comments on commit 39b6e50

Please sign in to comment.