bug 1523104: remote: drop protocol schema validation; r=ochameau
authorAndreas Tolfsen <ato@sny.no>
Thu, 21 Feb 2019 13:01:23 +0000
changeset 521100 59da827edf022ed0d69517e69c42e768b2623337
parent 521099 e3d8a66cdad1fcbea0a25ed9948bb51cf26fe086
child 521101 2f7767b51e69f23c955628d058ff1897af5085c1
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1523104
milestone67.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 1523104: remote: drop protocol schema validation; r=ochameau
remote/Domain.jsm
remote/Protocol.jsm
remote/Session.jsm
remote/domain/Log.jsm
remote/domain/Network.jsm
remote/domain/Page.jsm
remote/domain/Runtime.jsm
remote/jar.mn
--- a/remote/Domain.jsm
+++ b/remote/Domain.jsm
@@ -30,12 +30,10 @@ class Domain {
 
   get chromeEventHandler() {
     return this.docShell.chromeEventHandler;
   }
 }
 
 XPCOMUtils.defineLazyModuleGetters(Domain, {
   Log: "chrome://remote/content/domain/Log.jsm",
-  Network: "chrome://remote/content/domain/Network.jsm",
   Page: "chrome://remote/content/domain/Page.jsm",
-  Runtime: "chrome://remote/content/domain/Runtime.jsm",
 });
--- a/remote/Protocol.jsm
+++ b/remote/Protocol.jsm
@@ -1,62 +1,11 @@
 "use strict";
 
-var EXPORTED_SYMBOLS = [
-  "Protocol",
-  "t",
-];
-
-var t = {
-  String: x => typeof x == "string" || x instanceof String,
-  Number: x => typeof x == "number",
-  Boolean: x => typeof x == "boolean",
-  Null: x => Object.is(x, null),
-  Enum: values => x => values.includes(x),
-  Undefined: x => Object.is(x, undefined),
-  Or: (...schemas) => x => schemas.some(schema => checkSchema(schema, x)),
-  Either: (...schemas) => x => schemas.map(schema => checkSchema(schema, x)).reduce((acc, x) => acc + (x ? 1 : 0)) === 1,
-  Array: schema => x => Array.isArray(x) && x.every(element => checkSchema(schema, element)),
-  Nullable: schema => x => Object.is(x, null) || checkSchema(schema, x),
-  Optional: schema => x => Object.is(x, undefined) || checkSchema(schema, x),
-  Any: x => true,
-};
-
-// TODO(ato): Add support for .schema()
-function checkSchema(schema, x, details = {}, path = []) {
-  if (typeof schema == "object") {
-    for (const [propertyName, check] of Object.entries(schema)) {
-      path.push(propertyName);
-      const result = checkSchema(check, x[propertyName], details, path);
-      path.pop();
-      if (!result) {
-        return false;
-      }
-    }
-
-    for (const propertyName of Object.keys(x)) {
-      if (!schema[propertyName]) {
-        path.push(propertyName);
-        details.propertyName = path.join(".");
-        details.propertyValue = x[propertyName];
-        details.errorType = "extra";
-        return false;
-      }
-    }
-    return true;
-  }
-
-  const rv = schema(x);
-  if (!rv) {
-    details.propertyName = path.join(".");
-    details.propertyValue = x;
-    details.errorType = "unsupported";
-  }
-  return rv;
-}
+var EXPORTED_SYMBOLS = ["Protocol"];
 
 // TODO(ato): We send back a description of the protocol
 // when the user makes the initial HTTP request,
 // but the following is pure fiction.
 const Description = {
     "domains": [
         {
             "domain": "Accessibility",
@@ -17399,12 +17348,9 @@ const Description = {
         }
     ],
     "version": {
         "major": "1",
         "minor": "3"
     }
 };
 
-var Protocol = {
-  checkSchema,
-  Description,
-};
+const Protocol = {Description};
--- a/remote/Session.jsm
+++ b/remote/Session.jsm
@@ -3,17 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 var EXPORTED_SYMBOLS = ["Session"];
 
 const {Domain} = ChromeUtils.import("chrome://remote/content/Domain.jsm");
 const {formatError} = ChromeUtils.import("chrome://remote/content/Error.jsm");
-const {Protocol} = ChromeUtils.import("chrome://remote/content/Protocol.jsm");
 
 class Session {
   constructor(connection, target) {
     this.connection = connection;
     this.target = target;
 
     this.browsingContext = target.browser.browsingContext;
     this.messageManager = target.browser.messageManager;
@@ -41,21 +40,24 @@ class Session {
       if (typeof id == "undefined") {
         throw new TypeError("Message missing 'id' field");
       }
       if (typeof method == "undefined") {
         throw new TypeError("Message missing 'method' field");
       }
 
       const [domainName, methodName] = split(method, ".", 1);
-      assertSchema(domainName, methodName, params);
+      const domain = Domain[domainName];
+      if (!domain) {
+        throw new TypeError("No such domain: " + domainName);
+      }
 
       this.messageManager.sendAsyncMessage("remote-protocol:request", {
         browsingContextId: this.browsingContext.id,
-        request: { id, domainName, methodName, params },
+        request: {id, domainName, methodName, params},
       });
     } catch (e) {
       const error = formatError(e, {stack: true});
       this.connection.send({id, error});
     }
   }
 
   receiveMessage({ name, data }) {
@@ -72,34 +74,16 @@ class Session {
       case "remote-protocol:error":
         const error = formatError(data.error, {stack: true});
         this.connection.send({id: data.id, error});
         break;
     }
   }
 }
 
-function assertSchema(domainName, methodName, params) {
-  const domain = Domain[domainName];
-  if (!domain) {
-    throw new TypeError("No such domain: " + domainName);
-  }
-  if (!domain.schema) {
-    throw new Error(`Domain ${domainName} missing schema description`);
-  }
-
-  let details = {};
-  const descriptor = (domain.schema.methods || {})[methodName];
-  if (!Protocol.checkSchema(descriptor.params || {}, params, details)) {
-    const {errorType, propertyName, propertyValue} = details;
-    throw new TypeError(`${domainName}.${methodName} called ` +
-        `with ${errorType} ${propertyName}: ${propertyValue}`);
-  }
-}
-
 /**
  * Split s by sep, returning list of substrings.
  * If max is given, at most max splits are done.
  * If max is 0, there is no limit on the number of splits.
  */
 function split(s, sep, max = 0) {
   if (typeof s != "string" ||
       typeof sep != "string" ||
--- a/remote/domain/Log.jsm
+++ b/remote/domain/Log.jsm
@@ -3,42 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 var EXPORTED_SYMBOLS = ["Log"];
 
 const {Domain} = ChromeUtils.import("chrome://remote/content/Domain.jsm");
 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
-const {t} = ChromeUtils.import("chrome://remote/content/Protocol.jsm");
-
-const {Network, Runtime} = Domain;
-
-const ALLOWED_SOURCES = [
-  "xml",
-  "javascript",
-  "network",
-  "storage",
-  "appcache",
-  "rendering",
-  "security",
-  "deprecation",
-  "worker",
-  "violation",
-  "intervention",
-  "recommendation",
-  "other",
-];
-
-const ALLOWED_LEVELS = [
-  "verbose",
-  "info",
-  "warning",
-  "error",
-];
 
 class Log extends Domain {
   constructor(session, target) {
     super(session, target);
     this.enabled = false;
   }
 
   destructor() {
@@ -79,48 +53,23 @@ class Log extends Domain {
       entry = fromConsoleMessage(message);
     } else if (topic == "console-api-log-event") {
       entry = fromConsoleAPI(message.wrappedJSObject);
     }
 
     this.emit("Log.entryAdded", {entry});
   }
 
+  // XPCOM
+
   get QueryInterface() {
     return ChromeUtils.generateQI([Ci.nsIConsoleListener]);
   }
-
-  static get schema() {
-    return {
-      methods: {
-        enable: {},
-        disable: {},
-      },
-      events: {
-        entryAdded: Log.LogEntry.schema,
-      },
-    };
-  }
 }
 
-Log.LogEntry = {
-  schema: {
-    source: t.Enum(ALLOWED_SOURCES),
-    level: t.Enum(ALLOWED_LEVELS),
-    text: t.String,
-    timestamp: Runtime.Timestamp,
-    url: t.Optional(t.String),
-    lineNumber: t.Optional(t.Number),
-    stackTrace: t.Optional(Runtime.StackTrace.schema),
-    networkRequestId: t.Optional(Network.RequestId.schema),
-    workerId: t.Optional(t.String),
-    args: t.Optional(t.Array(Runtime.RemoteObject.schema)),
-  },
-};
-
 function fromConsoleMessage(message) {
   const levels = {
     [Ci.nsIConsoleMessage.debug]: "verbose",
     [Ci.nsIConsoleMessage.info]: "info",
     [Ci.nsIConsoleMessage.warn]: "warning",
     [Ci.nsIConsoleMessage.error]: "error",
   };
   const level = levels[message.logLevel];
deleted file mode 100644
--- a/remote/domain/Network.jsm
+++ /dev/null
@@ -1,15 +0,0 @@
-/* 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";
-
-var EXPORTED_SYMBOLS = ["Network"];
-
-const {t} = ChromeUtils.import("chrome://remote/content/Protocol.jsm");
-
-var Network = {
-  MonotonicTime: {schema: t.Number},
-  LoaderId: {schema: t.String},
-  RequestId: {schema: t.Number},
-};
--- a/remote/domain/Page.jsm
+++ b/remote/domain/Page.jsm
@@ -2,17 +2,16 @@
  * 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";
 
 var EXPORTED_SYMBOLS = ["Page"];
 
 const {Domain} = ChromeUtils.import("chrome://remote/content/Domain.jsm");
-const {t} = ChromeUtils.import("chrome://remote/content/Protocol.jsm");
 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 const {UnsupportedError} = ChromeUtils.import("chrome://remote/content/Error.jsm");
 
 class Page extends Domain {
   constructor(session, target) {
     super(session, target);
     this.enabled = false;
   }
@@ -80,61 +79,18 @@ class Page extends Domain {
       this.emit("Page.domContentEventFired", {timestamp});
       break;
 
     case "pageshow":
       this.emit("Page.loadEventFired", {timestamp});
       break;
     }
   }
-
-  static get schema() {
-    return {
-      methods: {
-        enable: {},
-        disable: {},
-        navigate: {
-          params: {
-            url: t.String,
-            referrer: t.Optional(t.String),
-            transitionType: t.Optional(Page.TransitionType.schema),
-            frameId: t.Optional(Page.FrameId.schema),
-          },
-          returns: {
-            frameId: Page.FrameId,
-            loaderId: t.Optional(Domain.Network.LoaderId.schema),
-            errorText: t.String,
-          },
-        },
-      },
-
-      events: {
-        domContentEventFired: {
-          timestamp: Domain.Network.MonotonicTime.schema,
-        },
-        loadEventFired: {
-          timestamp: Domain.Network.MonotonicTime.schema,
-        },
-      },
-    };
-  }
 }
 
-Page.FrameId = {schema: t.String};
-Page.TransitionType = {
-  schema: t.Enum([
-    "auto_bookmark",
-    "auto_subframe",
-    "link",
-    "manual_subframe",
-    "reload",
-    "typed",
-  ]),
-};
-
 function transitionToLoadFlag(transitionType) {
   switch (transitionType) {
   case "reload":
     return Ci.nsIWebNavigation.LOAD_FLAG_IS_REFRESH;
   case "link":
   default:
     return Ci.nsIWebNavigation.LOAD_FLAG_IS_LINK;
   }
deleted file mode 100644
--- a/remote/domain/Runtime.jsm
+++ /dev/null
@@ -1,51 +0,0 @@
-/* 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";
-
-var EXPORTED_SYMBOLS = ["Runtime"];
-
-const {t} = ChromeUtils.import("chrome://remote/content/Protocol.jsm");
-
-var Runtime = {
-  StackTrace: {schema: t.String},
-
-  RemoteObject: {
-    schema: t.Either(
-        {
-          type: t.Enum([
-            "object",
-            "function",
-            "undefined",
-            "string",
-            "number",
-            "boolean",
-            "symbol",
-            "bigint",
-          ]),
-          subtype: t.Optional(t.Enum([
-            "array",
-            "date",
-            "error",
-            "map",
-            "node",
-            "null",
-            "promise",
-            "proxy",
-            "regexp",
-            "set",
-            "typedarray",
-            "weakmap",
-            "weakset",
-          ])),
-          objectId: t.String,
-      },
-      {
-        unserializableValue: t.Enum(["Infinity", "-Infinity", "-0", "NaN"]),
-      },
-      {
-        value: t.Any,
-      }),
-  },
-};
--- a/remote/jar.mn
+++ b/remote/jar.mn
@@ -22,19 +22,17 @@ remote.jar:
   content/Targets.jsm (Targets.jsm)
   content/WindowManager.jsm (WindowManager.jsm)
 
   # Frame scripts
   content/frame-script.js (frame-script.js)
 
   # domains
   content/domain/Log.jsm (domain/Log.jsm)
-  content/domain/Network.jsm (domain/Network.jsm)
   content/domain/Page.jsm (domain/Page.jsm)
-  content/domain/Runtime.jsm (domain/Runtime.jsm)
 
   # transport layer
   content/server/HTTPD.jsm (../netwerk/test/httpserver/httpd.js)
   content/server/Packet.jsm (server/Packet.jsm)
   content/server/Socket.jsm (server/Socket.jsm)
   content/server/Stream.jsm (server/Stream.jsm)
   content/server/Transport.jsm (server/Transport.jsm)
   content/server/WebSocket.jsm (server/WebSocket.jsm)