Bug 1565380 - Add a deprecation warning message to Scratchpad. r=jdescottes.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Fri, 23 Aug 2019 12:30:10 +0000
changeset 553330 12326ee4016914006e2914b91700eb86753bf3f5
parent 553329 2c8f5d2048d395ff8637a3f30e2c0a41326b274f
child 553331 d02248cec4c046f8380b78cbef84eee084982445
push id2165
push userffxbld-merge
push dateMon, 14 Oct 2019 16:30:58 +0000
treeherdermozilla-release@0eae18af659f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1565380, 1527294
milestone70.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 1565380 - Add a deprecation warning message to Scratchpad. r=jdescottes. This patch contains 2 parts: - First one is adding a label + icon in the settings panel next to the Scratchpad tool entry. This is mainly re-adding what was done for Bug 1527294. - Second is adding a deprecation warning message *in* the Scratchpad panel. This is using the NotificationBox that is already used in the panel. Both have a link to the deprecated tools MDN page, in which we'll add a Scratchpad section soon. Differential Revision: https://phabricator.services.mozilla.com/D43206
devtools/client/definitions.js
devtools/client/framework/toolbox-options.js
devtools/client/locales/en-US/scratchpad.properties
devtools/client/locales/en-US/toolbox.properties
devtools/client/scratchpad/scratchpad.js
devtools/client/scratchpad/test/browser_scratchpad_contexts.js
devtools/client/scratchpad/test/browser_scratchpad_tab_switch.js
devtools/client/themes/scratchpad.css
--- a/devtools/client/definitions.js
+++ b/devtools/client/definitions.js
@@ -109,16 +109,20 @@ loader.lazyImporter(
 );
 
 const { MultiLocalizationHelper } = require("devtools/shared/l10n");
 const L10N = new MultiLocalizationHelper(
   "devtools/client/locales/startup.properties",
   "devtools/startup/locales/key-shortcuts.properties"
 );
 
+// URL to direct people to the deprecated tools panel
+const DEPRECATION_URL =
+  "https://developer.mozilla.org/docs/Tools/Deprecated_tools";
+
 var Tools = {};
 exports.Tools = Tools;
 
 // Definitions
 Tools.options = {
   id: "options",
   ordinal: 0,
   url: "chrome://devtools/content/framework/toolbox-options.xhtml",
@@ -384,16 +388,18 @@ Tools.storage = {
 
   build: function(iframeWindow, toolbox) {
     return new StoragePanel(iframeWindow, toolbox);
   },
 };
 
 Tools.scratchpad = {
   id: "scratchpad",
+  deprecated: true,
+  deprecationURL: `${DEPRECATION_URL}#Scratchpad`,
   ordinal: 12,
   visibilityswitch: "devtools.scratchpad.enabled",
   icon: "chrome://devtools/skin/images/tool-scratchpad.svg",
   url: "chrome://devtools/content/scratchpad/index.xul",
   label: l10n("scratchpad.label"),
   panelLabel: l10n("scratchpad.panelLabel"),
   tooltip: l10n("scratchpad.tooltip"),
   inMenu: false,
--- a/devtools/client/framework/toolbox-options.js
+++ b/devtools/client/framework/toolbox-options.js
@@ -275,16 +275,29 @@ OptionsPanel.prototype = {
       checkboxInput.addEventListener(
         "change",
         onCheckboxClick.bind(checkboxInput, this.telemetry, tool)
       );
 
       checkboxLabel.appendChild(checkboxInput);
       checkboxLabel.appendChild(checkboxSpanLabel);
 
+      // TODO: remove in Firefox 71, with bug #1519103
+      if (tool.deprecated) {
+        const deprecationURL = this.panelDoc.createElement("a");
+        deprecationURL.title = deprecationURL.href = tool.deprecationURL;
+        deprecationURL.textContent = L10N.getStr("options.deprecationNotice");
+        deprecationURL.target = "_blank";
+
+        const checkboxSpanDeprecated = this.panelDoc.createElement("span");
+        checkboxSpanDeprecated.className = "deprecation-notice";
+        checkboxLabel.appendChild(checkboxSpanDeprecated);
+        checkboxSpanDeprecated.appendChild(deprecationURL);
+      }
+
       return checkboxLabel;
     };
 
     // Clean up any existent default tools content.
     for (const label of defaultToolsBox.querySelectorAll("label")) {
       label.remove();
     }
 
--- a/devtools/client/locales/en-US/scratchpad.properties
+++ b/devtools/client/locales/en-US/scratchpad.properties
@@ -98,8 +98,13 @@ connectionTimeout=Connection timeout. Ch
 # a new user of the developer tools pastes code into the console
 # %1 is the text of selfxss.okstring
 selfxss.msg=Scam Warning: Take care when pasting things you don’t understand. This could allow attackers to steal your identity or take control of your computer. Please type ‘%S’ in the scratchpad below to allow pasting.
 
 # LOCALIZATION NOTE (selfxss.okstring): the string to be typed
 # in by a new user of the developer tools when they receive the sefxss.msg prompt.
 # Please avoid using non-keyboard characters here
 selfxss.okstring=allow pasting
+
+# LOCALIZATION NOTE (scratchpad.deprecated.label): Text for the deprecation message
+# displayed when starting Scratchpad. 
+# This entire text is treated as a link to an MDN page.
+scratchpad.deprecated.label=Scratchpad will be disabled in a future release. Learn more…
--- a/devtools/client/locales/en-US/toolbox.properties
+++ b/devtools/client/locales/en-US/toolbox.properties
@@ -289,8 +289,13 @@ toolbox.replay.jumpMessage=Jump to messa
 # for the Error view shown by the toolbox when a connection to a debug target
 # could not be made
 toolbox.debugTargetErrorPage.title = Error
 
 # LOCALIZATION NOTE (toolbox.debugTargetErrorPage.description): This is the
 # text that appears in the Error view and explains to the user that an error
 # has happened while trying to connect to a debug target
 toolbox.debugTargetErrorPage.description = Cannot connect to the debug target. See error details below:
+
+# LOCALIZATION NOTE (options.deprecationNotice): This is the text that appears in the 
+# settings panel for panel that will be removed in future releases.
+# This entire text is treated as a link to an MDN page.
+options.deprecationNotice=Deprecated. Learn More…
--- a/devtools/client/scratchpad/scratchpad.js
+++ b/devtools/client/scratchpad/scratchpad.js
@@ -1740,16 +1740,37 @@ var Scratchpad = {
     const editorElement = document.querySelector("#scratchpad-editor");
     this.editor
       .appendTo(editorElement)
       .then(() => {
         var lines = initialText.split("\n");
 
         this.editor.setFontSize(Services.prefs.getIntPref(EDITOR_FONT_SIZE));
 
+        // Display the deprecation warning for Scratchpad.
+        const deprecationWarning = document.createElement("a");
+        deprecationWarning.setAttribute(
+          "href",
+          "https://developer.mozilla.org/docs/Tools/Deprecated_tools#Scratchpad"
+        );
+        deprecationWarning.setAttribute("target", "_blank");
+        deprecationWarning.append(
+          this.strings.GetStringFromName("scratchpad.deprecated.label")
+        );
+
+        const deprecationFragment = document.createDocumentFragment();
+        deprecationFragment.append(deprecationWarning);
+
+        this.notificationBox.appendNotification(
+          deprecationFragment,
+          "scratchpad.deprecated",
+          null,
+          this.notificationBox.PRIORITY_WARNING_HIGH
+        );
+
         this.editor.on("change", this._onChanged);
         // Keep a reference to the bound version for use in onUnload.
         this.updateStatusBar = Scratchpad.updateStatusBar.bind(this);
         this.editor.on("cursorActivity", this.updateStatusBar);
         const okstring = this.strings.GetStringFromName("selfxss.okstring");
         const msg = this.strings.formatStringFromName("selfxss.msg", [
           okstring,
         ]);
--- a/devtools/client/scratchpad/test/browser_scratchpad_contexts.js
+++ b/devtools/client/scratchpad/test/browser_scratchpad_contexts.js
@@ -49,19 +49,20 @@ function runTests() {
         );
 
         isnot(
           chromeMenu.getAttribute("checked"),
           "true",
           "chrome menuitem is not checked"
         );
 
-        ok(
-          !notificationBox.currentNotification,
-          "there is no notification in content context"
+        is(
+          notificationBox.currentNotification.messageText.textContent,
+          "Scratchpad will be disabled in a future release. Learn more…",
+          "The deprecation warning is displayed in content context"
         );
 
         sp.editor.setText("window.foobarBug636725 = 'aloha';");
 
         const pageResult = await inContent(function() {
           return content.wrappedJSObject.foobarBug636725;
         });
         ok(!pageResult, "no content.foobarBug636725");
@@ -93,19 +94,33 @@ function runTests() {
         );
 
         isnot(
           contentMenu.getAttribute("checked"),
           "true",
           "content menuitem is not checked"
         );
 
-        ok(
-          notificationBox.currentNotification,
-          "there is a notification in browser context"
+        const { allNotifications } = notificationBox;
+        is(
+          allNotifications.length,
+          2,
+          "There are 2 notifications in browser context"
+        );
+
+        is(
+          allNotifications[0].messageText.textContent,
+          "This scratchpad executes in the Browser context.",
+          "There is a notification in browser context"
+        );
+
+        is(
+          allNotifications[1].messageText.textContent,
+          "Scratchpad will be disabled in a future release. Learn more…",
+          "The deprecation warning is displayed"
         );
 
         const [from, to] = sp.editor.getPosition(31, 32);
         sp.editor.replaceText("2'", from, to);
 
         is(
           sp.getText(),
           "window.foobarBug636725 = 'aloha2';",
--- a/devtools/client/scratchpad/test/browser_scratchpad_tab_switch.js
+++ b/devtools/client/scratchpad/test/browser_scratchpad_tab_switch.js
@@ -59,19 +59,19 @@ async function runTests() {
 
   isnot(
     browserMenu.getAttribute("checked"),
     "true",
     "chrome menuitem is not checked"
   );
 
   is(
-    notificationBox.currentNotification,
-    null,
-    "there is no notification currently shown for content context"
+    notificationBox.currentNotification.messageText.textContent,
+    "Scratchpad will be disabled in a future release. Learn more…",
+    "The deprecation warning is displayed in content context"
   );
 
   sp.setText("window.foosbug653108 = 'aloha';");
 
   await ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
     ok(!content.wrappedJSObject.foosbug653108, "no content.foosbug653108");
   });
 
--- a/devtools/client/themes/scratchpad.css
+++ b/devtools/client/themes/scratchpad.css
@@ -5,8 +5,13 @@
 #scratchpad-sidebar > tabs {
   height: 0;
   border: none;
 }
 
 #sp-toolbar {
   border: none;
 }
+
+notification a {
+  color: currentColor;
+  text-decoration: underline;
+}