mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
bug 1523104: remote: drop protocol schema validation; r=ochameau
This commit is contained in:
parent
d43ba5f39c
commit
0431233f04
@ -35,7 +35,5 @@ class Domain {
|
||||
|
||||
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",
|
||||
});
|
||||
|
@ -1,57 +1,6 @@
|
||||
"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,
|
||||
@ -17404,7 +17353,4 @@ const Description = {
|
||||
}
|
||||
};
|
||||
|
||||
var Protocol = {
|
||||
checkSchema,
|
||||
Description,
|
||||
};
|
||||
const Protocol = {Description};
|
||||
|
@ -8,7 +8,6 @@ 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) {
|
||||
@ -46,11 +45,14 @@ class Session {
|
||||
}
|
||||
|
||||
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});
|
||||
@ -77,24 +79,6 @@ class Session {
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
|
@ -8,32 +8,6 @@ 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) {
|
||||
@ -84,38 +58,13 @@ class Log extends Domain {
|
||||
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",
|
||||
|
@ -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},
|
||||
};
|
@ -7,7 +7,6 @@
|
||||
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");
|
||||
|
||||
@ -85,51 +84,8 @@ class Page extends Domain {
|
||||
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":
|
||||
|
@ -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,
|
||||
}),
|
||||
},
|
||||
};
|
@ -27,9 +27,7 @@ remote.jar:
|
||||
|
||||
# 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)
|
||||
|
Loading…
Reference in New Issue
Block a user