summaryrefslogtreecommitdiffstats
path: root/comm/mail/components/enterprisepolicies/content
diff options
context:
space:
mode:
Diffstat (limited to 'comm/mail/components/enterprisepolicies/content')
-rw-r--r--comm/mail/components/enterprisepolicies/content/aboutPolicies.js410
-rw-r--r--comm/mail/components/enterprisepolicies/content/aboutPolicies.xhtml107
-rw-r--r--comm/mail/components/enterprisepolicies/content/policies-active.svg6
-rw-r--r--comm/mail/components/enterprisepolicies/content/policies-documentation.svg6
-rw-r--r--comm/mail/components/enterprisepolicies/content/policies-error.svg6
5 files changed, 535 insertions, 0 deletions
diff --git a/comm/mail/components/enterprisepolicies/content/aboutPolicies.js b/comm/mail/components/enterprisepolicies/content/aboutPolicies.js
new file mode 100644
index 0000000000..850286e001
--- /dev/null
+++ b/comm/mail/components/enterprisepolicies/content/aboutPolicies.js
@@ -0,0 +1,410 @@
+/* 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/. */
+
+"use strict";
+
+const { XPCOMUtils } = ChromeUtils.importESModule(
+ "resource://gre/modules/XPCOMUtils.sys.mjs"
+);
+
+const lazy = {};
+ChromeUtils.defineESModuleGetters(lazy, {
+ schema: "resource:///modules/policies/schema.sys.mjs",
+});
+
+function col(text, className) {
+ let column = document.createElement("td");
+ if (className) {
+ column.classList.add(className);
+ }
+ let content = document.createTextNode(text);
+ column.appendChild(content);
+ return column;
+}
+
+function addMissingColumns() {
+ const table = document.getElementById("activeContent");
+ let maxColumns = 0;
+
+ // count the number of columns per row and set the max number of columns
+ for (let i = 0, length = table.rows.length; i < length; i++) {
+ if (maxColumns < table.rows[i].cells.length) {
+ maxColumns = table.rows[i].cells.length;
+ }
+ }
+
+ // add the missing columns
+ for (let i = 0, length = table.rows.length; i < length; i++) {
+ const rowLength = table.rows[i].cells.length;
+
+ if (rowLength < maxColumns) {
+ let missingColumns = maxColumns - rowLength;
+
+ while (missingColumns > 0) {
+ table.rows[i].insertCell();
+ missingColumns--;
+ }
+ }
+ }
+}
+
+/*
+ * This function generates the Active Policies content to be displayed by calling
+ * a recursive function called generatePolicy() according to the policy schema.
+ */
+
+function generateActivePolicies(data) {
+ let new_cont = document.getElementById("activeContent");
+ new_cont.classList.add("active-policies");
+
+ let policy_count = 0;
+
+ for (let policyName in data) {
+ const color_class = ++policy_count % 2 === 0 ? "even" : "odd";
+
+ if (lazy.schema.properties[policyName].type == "array") {
+ for (let count in data[policyName]) {
+ let isFirstRow = count == 0;
+ let isLastRow = count == data[policyName].length - 1;
+ let row = document.createElement("tr");
+ row.classList.add(color_class);
+ row.appendChild(col(isFirstRow ? policyName : ""));
+ generatePolicy(
+ data[policyName][count],
+ row,
+ 1,
+ new_cont,
+ isLastRow,
+ data[policyName].length > 1
+ );
+ }
+ } else if (lazy.schema.properties[policyName].type == "object") {
+ let count = 0;
+ for (let obj in data[policyName]) {
+ let isFirstRow = count == 0;
+ let isLastRow = count == Object.keys(data[policyName]).length - 1;
+ let row = document.createElement("tr");
+ row.classList.add(color_class);
+ row.appendChild(col(isFirstRow ? policyName : ""));
+ row.appendChild(col(obj));
+ generatePolicy(
+ data[policyName][obj],
+ row,
+ 2,
+ new_cont,
+ isLastRow,
+ true
+ );
+ count++;
+ }
+ } else {
+ let row = document.createElement("tr");
+ row.appendChild(col(policyName));
+ row.appendChild(col(JSON.stringify(data[policyName])));
+ row.classList.add(color_class, "last_row");
+ new_cont.appendChild(row);
+ }
+ }
+
+ if (policy_count < 1) {
+ let current_tab = document.querySelector(".active");
+ if (Services.policies.status == Services.policies.ACTIVE) {
+ current_tab.classList.add("no-specified-policies");
+ } else {
+ current_tab.classList.add("inactive-service");
+ }
+ }
+
+ addMissingColumns();
+}
+
+/*
+ * This is a helper recursive function that iterates levels of each
+ * policy and formats the content to be displayed accordingly.
+ */
+
+function generatePolicy(data, row, depth, new_cont, islast, arr_sep = false) {
+ const color_class = row.classList.contains("odd") ? "odd" : "even";
+
+ if (Array.isArray(data)) {
+ for (let count in data) {
+ if (count == 0) {
+ if (count == data.length - 1) {
+ generatePolicy(
+ data[count],
+ row,
+ depth + 1,
+ new_cont,
+ islast ? islast : false,
+ true
+ );
+ } else {
+ generatePolicy(data[count], row, depth + 1, new_cont, false, false);
+ }
+ } else if (count == data.length - 1) {
+ let last_row = document.createElement("tr");
+ last_row.classList.add(color_class, "arr_sep");
+
+ for (let i = 0; i < depth; i++) {
+ last_row.appendChild(col(""));
+ }
+
+ generatePolicy(
+ data[count],
+ last_row,
+ depth + 1,
+ new_cont,
+ islast ? islast : false,
+ arr_sep
+ );
+ } else {
+ let new_row = document.createElement("tr");
+ new_row.classList.add(color_class);
+
+ for (let i = 0; i < depth; i++) {
+ new_row.appendChild(col(""));
+ }
+
+ generatePolicy(data[count], new_row, depth + 1, new_cont, false, false);
+ }
+ }
+ } else if (typeof data == "object" && Object.keys(data).length > 0) {
+ let count = 0;
+ for (let obj in data) {
+ if (count == 0) {
+ row.appendChild(col(obj));
+ if (count == Object.keys(data).length - 1) {
+ generatePolicy(
+ data[obj],
+ row,
+ depth + 1,
+ new_cont,
+ islast ? islast : false,
+ arr_sep
+ );
+ } else {
+ generatePolicy(data[obj], row, depth + 1, new_cont, false, false);
+ }
+ } else if (count == Object.keys(data).length - 1) {
+ let last_row = document.createElement("tr");
+ for (let i = 0; i < depth; i++) {
+ last_row.appendChild(col(""));
+ }
+
+ last_row.appendChild(col(obj));
+ last_row.classList.add(color_class);
+
+ if (arr_sep) {
+ last_row.classList.add("arr_sep");
+ }
+
+ generatePolicy(
+ data[obj],
+ last_row,
+ depth + 1,
+ new_cont,
+ islast ? islast : false,
+ false
+ );
+ } else {
+ let new_row = document.createElement("tr");
+ new_row.classList.add(color_class);
+
+ for (let i = 0; i < depth; i++) {
+ new_row.appendChild(col(""));
+ }
+
+ new_row.appendChild(col(obj));
+ generatePolicy(data[obj], new_row, depth + 1, new_cont, false, false);
+ }
+ count++;
+ }
+ } else {
+ row.appendChild(col(JSON.stringify(data)));
+
+ if (arr_sep) {
+ row.classList.add("arr_sep");
+ }
+ if (islast) {
+ row.classList.add("last_row");
+ }
+ new_cont.appendChild(row);
+ }
+}
+
+function generateErrors() {
+ const consoleStorage = Cc["@mozilla.org/consoleAPI-storage;1"];
+ const storage = consoleStorage.getService(Ci.nsIConsoleAPIStorage);
+ const consoleEvents = storage.getEvents();
+ const prefixes = [
+ "Enterprise Policies",
+ "JsonSchemaValidator.jsm",
+ "Policies.jsm",
+ "GPOParser.jsm",
+ "Enterprise Policies Child",
+ "BookmarksPolicies.jsm",
+ "ProxyPolicies.jsm",
+ "WebsiteFilter Policy",
+ "macOSPoliciesParser.jsm",
+ ];
+
+ let new_cont = document.getElementById("errorsContent");
+ new_cont.classList.add("errors");
+
+ let flag = false;
+ for (let err of consoleEvents) {
+ if (prefixes.includes(err.prefix)) {
+ flag = true;
+ let row = document.createElement("tr");
+ row.appendChild(col(err.arguments[0]));
+ new_cont.appendChild(row);
+ }
+ }
+ if (!flag) {
+ let errors_tab = document.getElementById("category-errors");
+ errors_tab.style.display = "none";
+ }
+}
+
+function generateDocumentation() {
+ let new_cont = document.getElementById("documentationContent");
+ new_cont.setAttribute("id", "documentationContent");
+
+ // map specific policies to a different string ID, to allow updates to
+ // existing descriptions
+ let string_mapping = {
+ BackgroundAppUpdate: "BackgroundAppUpdate2",
+ Certificates: "CertificatesDescription",
+ };
+
+ for (let policyName in lazy.schema.properties) {
+ let main_tbody = document.createElement("tbody");
+ main_tbody.classList.add("collapsible");
+ main_tbody.addEventListener("click", function () {
+ let content = this.nextElementSibling;
+ content.classList.toggle("content");
+ });
+ let row = document.createElement("tr");
+ row.appendChild(col(policyName));
+ let descriptionColumn = col("");
+ let stringID = string_mapping[policyName] || policyName;
+ descriptionColumn.setAttribute("data-l10n-id", `policy-${stringID}`);
+ row.appendChild(descriptionColumn);
+ main_tbody.appendChild(row);
+ let sec_tbody = document.createElement("tbody");
+ sec_tbody.classList.add("content");
+ sec_tbody.classList.add("content-style");
+ let schema_row = document.createElement("tr");
+ if (lazy.schema.properties[policyName].properties) {
+ let column = col(
+ JSON.stringify(lazy.schema.properties[policyName].properties, null, 1),
+ "schema"
+ );
+ column.colSpan = "2";
+ schema_row.appendChild(column);
+ sec_tbody.appendChild(schema_row);
+ } else if (lazy.schema.properties[policyName].items) {
+ let column = col(
+ JSON.stringify(lazy.schema.properties[policyName], null, 1),
+ "schema"
+ );
+ column.colSpan = "2";
+ schema_row.appendChild(column);
+ sec_tbody.appendChild(schema_row);
+ } else {
+ let column = col(
+ "type: " + lazy.schema.properties[policyName].type,
+ "schema"
+ );
+ column.colSpan = "2";
+ schema_row.appendChild(column);
+ sec_tbody.appendChild(schema_row);
+ if (lazy.schema.properties[policyName].enum) {
+ let enum_row = document.createElement("tr");
+ column = col(
+ "enum: " +
+ JSON.stringify(lazy.schema.properties[policyName].enum, null, 1),
+ "schema"
+ );
+ column.colSpan = "2";
+ enum_row.appendChild(column);
+ sec_tbody.appendChild(enum_row);
+ }
+ }
+ new_cont.appendChild(main_tbody);
+ new_cont.appendChild(sec_tbody);
+ }
+}
+
+let gInited = false;
+function init() {
+ if (gInited) {
+ return;
+ }
+ gInited = true;
+
+ let data = Services.policies.getActivePolicies();
+ generateActivePolicies(data);
+ generateErrors();
+ generateDocumentation();
+
+ // Event delegation on #categories element
+ let menu = document.getElementById("categories");
+ for (let category of menu.children) {
+ category.addEventListener("click", () => show(category));
+ }
+
+ if (location.hash) {
+ let sectionButton = document.getElementById(
+ "category-" + location.hash.substring(1)
+ );
+ if (sectionButton) {
+ sectionButton.click();
+ }
+ }
+
+ window.addEventListener("hashchange", function () {
+ if (location.hash) {
+ let sectionButton = document.getElementById(
+ "category-" + location.hash.substring(1)
+ );
+ sectionButton.click();
+ }
+ });
+}
+
+function show(button) {
+ let current_tab = document.querySelector(".active");
+ let category = button.getAttribute("id").substring("category-".length);
+ let content = document.getElementById(category);
+ if (current_tab == content) {
+ return;
+ }
+ saveScrollPosition(current_tab.id);
+ current_tab.classList.remove("active");
+ current_tab.hidden = true;
+ content.classList.add("active");
+ content.hidden = false;
+
+ let current_button = document.querySelector("[selected=true]");
+ current_button.removeAttribute("selected");
+ button.setAttribute("selected", "true");
+
+ let title = document.getElementById("sectionTitle");
+ title.textContent = button.children[1].textContent;
+ location.hash = category;
+ restoreScrollPosition(category);
+}
+
+const scrollPositions = {};
+function saveScrollPosition(category) {
+ const mainContent = document.querySelector(".main-content");
+ scrollPositions[category] = mainContent.scrollTop;
+}
+
+function restoreScrollPosition(category) {
+ const scrollY = scrollPositions[category] || 0;
+ const mainContent = document.querySelector(".main-content");
+ mainContent.scrollTo(0, scrollY);
+}
diff --git a/comm/mail/components/enterprisepolicies/content/aboutPolicies.xhtml b/comm/mail/components/enterprisepolicies/content/aboutPolicies.xhtml
new file mode 100644
index 0000000000..6ded7130a4
--- /dev/null
+++ b/comm/mail/components/enterprisepolicies/content/aboutPolicies.xhtml
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+# 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/.
+-->
+<!DOCTYPE html>
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title data-l10n-id="about-policies-title" />
+ <link
+ rel="stylesheet"
+ href="chrome://messenger/skin/aboutPolicies.css"
+ type="text/css"
+ />
+ <link rel="localization" href="branding/brand.ftl" />
+ <link rel="localization" href="messenger/policies/aboutPolicies.ftl" />
+ <link
+ rel="localization"
+ href="messenger/policies/policies-descriptions.ftl"
+ />
+ <script
+ type="application/javascript"
+ src="chrome://messenger/content/policies/aboutPolicies.js"
+ />
+ </head>
+ <body id="body" onload="init()">
+ <div id="categories">
+ <div class="category" selected="true" id="category-active">
+ <img
+ class="category-icon"
+ src="chrome://messenger/content/policies/policies-active.svg"
+ alt=""
+ />
+ <label class="category-name" data-l10n-id="active-policies-tab"></label>
+ </div>
+ <div class="category" id="category-documentation">
+ <img
+ class="category-icon"
+ src="chrome://messenger/content/policies/policies-documentation.svg"
+ alt=""
+ />
+ <label class="category-name" data-l10n-id="documentation-tab"></label>
+ </div>
+ <div class="category" id="category-errors">
+ <img
+ class="category-icon"
+ src="chrome://messenger/content/policies/policies-error.svg"
+ alt=""
+ />
+ <label class="category-name" data-l10n-id="errors-tab"></label>
+ </div>
+ </div>
+ <div class="main-content">
+ <div class="header">
+ <div
+ id="sectionTitle"
+ class="header-name"
+ data-l10n-id="active-policies-tab"
+ />
+ </div>
+
+ <div id="active" class="tab active">
+ <h3
+ class="inactive-service-message"
+ data-l10n-id="inactive-message"
+ ></h3>
+ <h3
+ class="no-specified-policies-message"
+ data-l10n-id="no-specified-policies-message"
+ ></h3>
+ <table>
+ <thead>
+ <tr>
+ <th data-l10n-id="policy-name" />
+ <th data-l10n-id="policy-value" />
+ </tr>
+ </thead>
+ <tbody id="activeContent" />
+ </table>
+ </div>
+
+ <div id="documentation" class="tab" hidden="true">
+ <table>
+ <thead>
+ <tr>
+ <th data-l10n-id="policy-name" />
+ </tr>
+ </thead>
+ <tbody id="documentationContent" />
+ </table>
+ </div>
+
+ <div id="errors" class="tab" hidden="true">
+ <table>
+ <thead>
+ <tr>
+ <th data-l10n-id="policy-errors" />
+ </tr>
+ </thead>
+ <tbody id="errorsContent" />
+ </table>
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/comm/mail/components/enterprisepolicies/content/policies-active.svg b/comm/mail/components/enterprisepolicies/content/policies-active.svg
new file mode 100644
index 0000000000..9ec258d4e0
--- /dev/null
+++ b/comm/mail/components/enterprisepolicies/content/policies-active.svg
@@ -0,0 +1,6 @@
+<!-- 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 height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg">
+ <path fill="context-fill" fill-opacity="context-fill-opacity" d="M11 10a1 1 0 01-1-1V5H3v8a1 1 0 001 1h2a1 1 0 010 2H3a2 2 0 01-2-2V4c0-1.1.9-2 2-2h1.05a2.5 2.5 0 014.9 0H10a2 2 0 012 2v5a1 1 0 01-1 1zm-1-6V3H8.95a1 1 0 01-.98-.8 1.5 1.5 0 00-2.94 0 1 1 0 01-.98.8H3v1zM6.5 2a.5.5 0 110 1 .5.5 0 010-1zm-2 5a.5.5 0 010-1h4a.5.5 0 010 1zm0 2a.5.5 0 010-1h2a.5.5 0 010 1zm0 2a.5.5 0 110-1h3a.5.5 0 110 1zm5.16 5a.67.67 0 01-.47-.2l-2-2a.67.67 0 01.94-.95l1.44 1.44 4.22-6.02a.67.67 0 011.1.77L10.2 15.7a.67.67 0 01-.55.29z"/>
+</svg>
diff --git a/comm/mail/components/enterprisepolicies/content/policies-documentation.svg b/comm/mail/components/enterprisepolicies/content/policies-documentation.svg
new file mode 100644
index 0000000000..a2817d3514
--- /dev/null
+++ b/comm/mail/components/enterprisepolicies/content/policies-documentation.svg
@@ -0,0 +1,6 @@
+<!-- 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 height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg">
+ <path fill="context-fill" fill-opacity="context-fill-opacity" d="M11 7a1 1 0 01-1-1V5H3v8a1 1 0 001 1h2a1 1 0 110 2H3a2 2 0 01-2-2V4c0-1.1.9-2 2-2h1.05a2.5 2.5 0 014.9 0H10a2 2 0 012 2v2a1 1 0 01-1 1zm-1-3V3H8.95a1 1 0 01-.98-.8 1.5 1.5 0 00-2.94 0 1 1 0 01-.98.8H3v1zM6.5 2a.5.5 0 110 1 .5.5 0 010-1zm-2 5a.5.5 0 110-1h4a.5.5 0 010 1zm0 2a.5.5 0 110-1h2a.5.5 0 010 1zm0 2a.5.5 0 110-1h1a.5.5 0 110 1zm6.5 5a4 4 0 110-8 4 4 0 010 8zm.46-2a.46.46 0 10-.92 0 .46.46 0 00.92 0zm-1.06-3c0-.3.25-.6.6-.6s.6.3.6.6c0 .12-.06.25-.16.39-.08.1-.16.17-.23.24l-.1.09-.01.02a1.3 1.3 0 00-.5 1.06.4.4 0 10.8 0c0-.17.04-.26.08-.3a.61.61 0 01.08-.1l.05-.05.07-.07.04-.03c.12-.11.24-.24.35-.37.16-.2.33-.5.33-.88a1.4 1.4 0 00-2.8 0 .4.4 0 10.8 0z"/>
+</svg>
diff --git a/comm/mail/components/enterprisepolicies/content/policies-error.svg b/comm/mail/components/enterprisepolicies/content/policies-error.svg
new file mode 100644
index 0000000000..fad8ddd632
--- /dev/null
+++ b/comm/mail/components/enterprisepolicies/content/policies-error.svg
@@ -0,0 +1,6 @@
+<!-- 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 height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg">
+ <path fill="context-fill" fill-opacity="context-fill-opacity" d="M11 7a1 1 0 01-1-1V5H3v8a1 1 0 001 1h1a1 1 0 110 2H3a2 2 0 01-2-2V4c0-1.1.9-2 2-2h1.05a2.5 2.5 0 014.9 0H10a2 2 0 012 2v2a1 1 0 01-1 1zm-1-3V3H8.95a1 1 0 01-.98-.8 1.5 1.5 0 00-2.94 0 1 1 0 01-.98.8H3v1zM6.5 2a.5.5 0 110 1 .5.5 0 010-1zm-2 5a.5.5 0 110-1h4a.5.5 0 010 1zm0 2a.5.5 0 110-1h3a.5.5 0 010 1zm0 2a.5.5 0 110-1h2a.5.5 0 110 1zm10.4 3.34A1.15 1.15 0 0113.83 16h-5.7a1.15 1.15 0 01-1-1.66l2.85-5.7a1.15 1.15 0 012.06 0zm-4.44-3.78v1.73a.58.58 0 001.15 0v-1.73a.58.58 0 10-1.15 0zm.57 4.13a.68.68 0 100-1.36.68.68 0 000 1.36z"/>
+</svg>