Bug 1548095 - Hide temporary addon category in about:debugging when xpinstall.enabled is false r=daisuke
authorJulian Descottes <jdescottes@mozilla.com>
Mon, 06 May 2019 11:40:38 +0000
changeset 531492 af96bd1090b523679af7dc0274b5842b68adfcd6
parent 531491 eae018d5c36464a8bc742160e9ee760dfa373b06
child 531493 676cf3a452c659ff68c89200770fd9fe7cd9d8f5
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaisuke
bugs1548095
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1548095 - Hide temporary addon category in about:debugging when xpinstall.enabled is false r=daisuke Differential Revision: https://phabricator.services.mozilla.com/D29424
devtools/client/aboutdebugging-new/src/constants.js
devtools/client/aboutdebugging-new/src/modules/debug-target-support.js
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_thisfirefox.js
devtools/client/aboutdebugging/components/addons/Controls.js
devtools/client/aboutdebugging/components/addons/Panel.js
--- a/devtools/client/aboutdebugging-new/src/constants.js
+++ b/devtools/client/aboutdebugging-new/src/constants.js
@@ -104,16 +104,18 @@ const PAGE_TYPES = {
 
 const PREFERENCES = {
   // Preference that drives the display of the "Tabs" category on This Firefox.
   LOCAL_TAB_DEBUGGING_ENABLED: "devtools.aboutdebugging.local-tab-debugging",
   // Preference that drives the display of the "Processes" debug target category.
   PROCESS_DEBUGGING_ENABLED: "devtools.aboutdebugging.process-debugging",
   // Preference that drives the display of hidden & system addons in about:debugging.
   SHOW_HIDDEN_ADDONS: "devtools.aboutdebugging.showHiddenAddons",
+  // Preference that disables installing extensions when set to false.
+  XPINSTALL_ENABLED: "xpinstall.enabled",
 };
 
 const RUNTIME_PREFERENCE = {
   CHROME_DEBUG_ENABLED: "devtools.chrome.enabled",
   CONNECTION_PROMPT: "devtools.debugger.prompt-connection",
   PERMANENT_PRIVATE_BROWSING: "browser.privatebrowsing.autostart",
   REMOTE_DEBUG_ENABLED: "devtools.debugger.remote-enabled",
   SERVICE_WORKERS_ENABLED: "dom.serviceWorkers.enabled",
--- a/devtools/client/aboutdebugging-new/src/modules/debug-target-support.js
+++ b/devtools/client/aboutdebugging-new/src/modules/debug-target-support.js
@@ -13,24 +13,32 @@ function isProcessDebuggingSupported() {
   return Services.prefs.getBoolPref(PREFERENCES.PROCESS_DEBUGGING_ENABLED, false);
 }
 
 // Process target debugging is disabled by default.
 function isLocalTabDebuggingSupported() {
   return Services.prefs.getBoolPref(PREFERENCES.LOCAL_TAB_DEBUGGING_ENABLED, false);
 }
 
+// Installing extensions can be disabled in enterprise policy.
+// Note: Temporary Extensions are only supported when debugging This Firefox, so checking
+// the local preference is acceptable here. If we enable Temporary extensions for remote
+// runtimes, we should retrieve the preference from the target runtime instead.
+function isTemporaryExtensionSupported() {
+  return Services.prefs.getBoolPref(PREFERENCES.XPINSTALL_ENABLED, true);
+}
+
 const ALL_DEBUG_TARGET_PANES = [
   DEBUG_TARGET_PANE.INSTALLED_EXTENSION,
   ...(isProcessDebuggingSupported() ? [DEBUG_TARGET_PANE.PROCESSES] : []),
   DEBUG_TARGET_PANE.OTHER_WORKER,
   DEBUG_TARGET_PANE.SERVICE_WORKER,
   DEBUG_TARGET_PANE.SHARED_WORKER,
   DEBUG_TARGET_PANE.TAB,
-  DEBUG_TARGET_PANE.TEMPORARY_EXTENSION,
+  ...(isTemporaryExtensionSupported() ? [DEBUG_TARGET_PANE.TEMPORARY_EXTENSION] : []),
 ];
 
 // All debug target panes except temporary extensions
 const REMOTE_DEBUG_TARGET_PANES = ALL_DEBUG_TARGET_PANES.filter(p =>
   p !== DEBUG_TARGET_PANE.TEMPORARY_EXTENSION);
 
 const THIS_FIREFOX_DEBUG_TARGET_PANES = ALL_DEBUG_TARGET_PANES
   // Main process debugging is not available for This Firefox.
--- a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_thisfirefox.js
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_thisfirefox.js
@@ -36,16 +36,33 @@ add_task(async function testThisFirefoxW
 
   // Expect all target panes but tabs to be displayed.
   const expectedTargetPanesWithoutTabs = EXPECTED_TARGET_PANES.filter(p => p !== "Tabs");
   await checkThisFirefoxTargetPanes(document, expectedTargetPanesWithoutTabs);
 
   await removeTab(tab);
 });
 
+/**
+ * Check that the Temporary Extensions is hidden if "xpinstall.enabled" is set to false.
+ */
+add_task(async function testThisFirefoxWithXpinstallDisabled() {
+  await pushPref("xpinstall.enabled", false);
+
+  const { document, tab, window } = await openAboutDebugging();
+  await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+  // Expect all target panes but temporary extensions to be displayed.
+  const expectedTargetPanesWithXpinstallDisabled =
+    EXPECTED_TARGET_PANES.filter(p => p !== "Temporary Extensions");
+  await checkThisFirefoxTargetPanes(document, expectedTargetPanesWithXpinstallDisabled);
+
+  await removeTab(tab);
+});
+
 async function checkThisFirefoxTargetPanes(doc, expectedTargetPanes) {
   const win = doc.ownerGlobal;
   // Check that the selected sidebar item is "This Firefox"/"This Nightly"/...
   const selectedSidebarItem = doc.querySelector(".qa-sidebar-item-selected");
   ok(selectedSidebarItem, "An item is selected in the sidebar");
 
   const thisFirefoxString = getThisFirefoxString(win);
   is(selectedSidebarItem.textContent, thisFirefoxString,
--- a/devtools/client/aboutdebugging/components/addons/Controls.js
+++ b/devtools/client/aboutdebugging/components/addons/Controls.js
@@ -68,16 +68,17 @@ class AddonsControls extends Component {
       .catch(e => {
         console.error(e);
         this.setState({ installError: e, lastInstallErrorFile: file });
       });
   }
 
   render() {
     const { debugDisabled } = this.props;
+    const isXpinstallEnabled = Services.prefs.getBoolPref("xpinstall.enabled", true);
 
     return dom.div({ className: "addons-top" },
       dom.div({ className: "addons-controls" },
         dom.div({ className: "addons-options toggle-container-with-text" },
           dom.input({
             id: "enable-addon-debugging",
             type: "checkbox",
             checked: !debugDisabled,
@@ -88,20 +89,20 @@ class AddonsControls extends Component {
             className: "addons-debugging-label",
             htmlFor: "enable-addon-debugging",
             title: Strings.GetStringFromName("addonDebugging.tooltip"),
           }, Strings.GetStringFromName("addonDebugging.label")),
           dom.a({ href: MORE_INFO_URL, target: "_blank" },
             Strings.GetStringFromName("addonDebugging.learnMore")
           ),
         ),
-        dom.button({
+        isXpinstallEnabled ? dom.button({
           id: "load-addon-from-file",
           onClick: this.loadAddonFromFile,
-        }, Strings.GetStringFromName("loadTemporaryAddon2"))
+        }, Strings.GetStringFromName("loadTemporaryAddon2")) : null,
       ),
       AddonsInstallError({
         error: this.state.installError,
         retryInstall: this.retryInstall,
       }));
   }
 }
 
--- a/devtools/client/aboutdebugging/components/addons/Panel.js
+++ b/devtools/client/aboutdebugging/components/addons/Panel.js
@@ -161,28 +161,31 @@ class AddonsPanel extends Component {
     const systemName = Strings.GetStringFromName("systemExtensions");
     const targetClass = AddonTarget;
 
     const installedTargets = targets.filter(
       (target) => !target.isSystem && !target.temporarilyInstalled);
     const temporaryTargets = targets.filter((target) => target.temporarilyInstalled);
     const systemTargets = showSystemAddons && targets.filter((target) => target.isSystem);
 
+    // Don't show the temporary addons category if users can't install addons.
+    const isXpinstallEnabled = Services.prefs.getBoolPref("xpinstall.enabled", true);
+
     return dom.div({
       id: id + "-panel",
       className: "panel",
       role: "tabpanel",
       "aria-labelledby": id + "-header",
     },
     PanelHeader({
       id: id + "-header",
       name: Strings.GetStringFromName("addons"),
     }),
     AddonsControls({ debugDisabled }),
-    dom.div({ id: "temporary-addons" },
+    isXpinstallEnabled ? dom.div({ id: "temporary-addons" },
       TargetList({
         id: "temporary-extensions",
         name: temporaryName,
         targets: temporaryTargets,
         client,
         connect,
         debugDisabled,
         targetClass,
@@ -192,17 +195,17 @@ class AddonsPanel extends Component {
         dom.div({ className: "addons-tip-icon"}),
         dom.span({
           className: "addons-web-ext-tip",
         }, Strings.GetStringFromName("webExtTip")),
         dom.a({ href: WEB_EXT_URL, target: "_blank" },
           Strings.GetStringFromName("webExtTip.learnMore")
         )
       )
-    ),
+    ) : null,
     dom.div({ id: "addons" },
       TargetList({
         id: "extensions",
         name: installedName,
         targets: installedTargets,
         client,
         connect,
         debugDisabled,