Bug 1370467 - avoid CPOW in screenshot gcli command;r=pbro
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 07 Jun 2017 01:13:42 +0200
changeset 410913 1766ee2089e809650c6f44f91c38fa953b335347
parent 410912 0498a3f9d548b986ed103bc8bd0d32dbfa975f8c
child 410914 2f14337def2d952661fd523c175c27775f7c000a
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbro
bugs1370467
milestone55.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 1370467 - avoid CPOW in screenshot gcli command;r=pbro MozReview-Commit-ID: 9nFkfmjG8CD
devtools/shared/gcli/commands/screenshot.js
--- a/devtools/shared/gcli/commands/screenshot.js
+++ b/devtools/shared/gcli/commands/screenshot.js
@@ -42,69 +42,77 @@ const filenameParam = {
     existing: "maybe",
   },
   defaultValue: FILENAME_DEFAULT_VALUE,
   description: l10n.lookup("screenshotFilenameDesc"),
   manual: l10n.lookup("screenshotFilenameManual")
 };
 
 /**
- * Both commands have the same set of standard optional parameters
+ * Both commands have almost the same set of standard optional parameters, except for the
+ * type of the --selector option, which can be a node only on the server.
  */
-const standardParams = {
-  group: l10n.lookup("screenshotGroupOptions"),
-  params: [
-    {
-      name: "clipboard",
-      type: "boolean",
-      description: l10n.lookup("screenshotClipboardDesc"),
-      manual: l10n.lookup("screenshotClipboardManual")
-    },
-    {
-      name: "imgur",
-      type: "boolean",
-      description: l10n.lookup("screenshotImgurDesc"),
-      manual: l10n.lookup("screenshotImgurManual")
-    },
-    {
-      name: "delay",
-      type: { name: "number", min: 0 },
-      defaultValue: 0,
-      description: l10n.lookup("screenshotDelayDesc"),
-      manual: l10n.lookup("screenshotDelayManual")
-    },
-    {
-      name: "dpr",
-      type: { name: "number", min: 0, allowFloat: true },
-      defaultValue: 0,
-      description: l10n.lookup("screenshotDPRDesc"),
-      manual: l10n.lookup("screenshotDPRManual")
-    },
-    {
-      name: "fullpage",
-      type: "boolean",
-      description: l10n.lookup("screenshotFullPageDesc"),
-      manual: l10n.lookup("screenshotFullPageManual")
-    },
-    {
-      name: "selector",
-      type: "node",
-      defaultValue: null,
-      description: l10n.lookup("inspectNodeDesc"),
-      manual: l10n.lookup("inspectNodeManual")
-    },
-    {
-      name: "file",
-      type: "boolean",
-      description: l10n.lookup("screenshotFileDesc"),
-      manual: l10n.lookup("screenshotFileManual"),
-    },
-  ]
+const getScreenshotCommandParams = function (isClient) {
+  return {
+    group: l10n.lookup("screenshotGroupOptions"),
+    params: [
+      {
+        name: "clipboard",
+        type: "boolean",
+        description: l10n.lookup("screenshotClipboardDesc"),
+        manual: l10n.lookup("screenshotClipboardManual")
+      },
+      {
+        name: "imgur",
+        type: "boolean",
+        description: l10n.lookup("screenshotImgurDesc"),
+        manual: l10n.lookup("screenshotImgurManual")
+      },
+      {
+        name: "delay",
+        type: { name: "number", min: 0 },
+        defaultValue: 0,
+        description: l10n.lookup("screenshotDelayDesc"),
+        manual: l10n.lookup("screenshotDelayManual")
+      },
+      {
+        name: "dpr",
+        type: { name: "number", min: 0, allowFloat: true },
+        defaultValue: 0,
+        description: l10n.lookup("screenshotDPRDesc"),
+        manual: l10n.lookup("screenshotDPRManual")
+      },
+      {
+        name: "fullpage",
+        type: "boolean",
+        description: l10n.lookup("screenshotFullPageDesc"),
+        manual: l10n.lookup("screenshotFullPageManual")
+      },
+      {
+        name: "selector",
+        // On the client side, don't try to parse the selector as a node as it will
+        // trigger an unsafe CPOW.
+        type: isClient ? "string" : "node",
+        defaultValue: null,
+        description: l10n.lookup("inspectNodeDesc"),
+        manual: l10n.lookup("inspectNodeManual")
+      },
+      {
+        name: "file",
+        type: "boolean",
+        description: l10n.lookup("screenshotFileDesc"),
+        manual: l10n.lookup("screenshotFileManual"),
+      },
+    ]
+  };
 };
 
+const clientScreenshotParams = getScreenshotCommandParams(true);
+const serverScreenshotParams = getScreenshotCommandParams(false);
+
 exports.items = [
   {
     /**
      * Format an 'imageSummary' (as output by the screenshot command).
      * An 'imageSummary' is a simple JSON object that looks like this:
      *
      * {
      *   destinations: [ "..." ], // Required array of descriptions of the
@@ -175,17 +183,17 @@ exports.items = [
     description: l10n.lookup("screenshotDesc"),
     manual: l10n.lookup("screenshotManual"),
     returnType: "imageSummary",
     buttonId: "command-button-screenshot",
     buttonClass: "command-button command-button-invertable",
     tooltipText: l10n.lookup("screenshotTooltipPage"),
     params: [
       filenameParam,
-      standardParams,
+      clientScreenshotParams,
     ],
     exec: function (args, context) {
       // Re-execute the command on the server
       const command = context.typed.replace(/^screenshot/, "screenshot_server");
       let capture = context.updateExec(command).then(output => {
         return output.error ? Promise.reject(output.data) : output.data;
       });
 
@@ -194,17 +202,20 @@ exports.items = [
     },
   },
   {
     item: "command",
     runAt: "server",
     name: "screenshot_server",
     hidden: true,
     returnType: "imageSummary",
-    params: [ filenameParam, standardParams ],
+    params: [
+      filenameParam,
+      serverScreenshotParams,
+    ],
     exec: function (args, context) {
       return captureScreenshot(args, context.environment.document);
     },
   }
 ];
 
 /**
  * This function is called to simulate camera effects