mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 08:12:05 +00:00
Bug 1644186 - Add ResourceTransformers. r=ochameau.
Differential Revision: https://phabricator.services.mozilla.com/D81831
This commit is contained in:
parent
52507b5218
commit
d225d7ad21
@ -5,6 +5,7 @@
|
|||||||
DIRS += [
|
DIRS += [
|
||||||
'legacy-listeners',
|
'legacy-listeners',
|
||||||
'legacy-target-watchers',
|
'legacy-target-watchers',
|
||||||
|
'transformers',
|
||||||
]
|
]
|
||||||
|
|
||||||
DevToolsModules(
|
DevToolsModules(
|
||||||
|
@ -9,14 +9,6 @@ const EventEmitter = require("devtools/shared/event-emitter");
|
|||||||
// eslint-disable-next-line mozilla/reject-some-requires
|
// eslint-disable-next-line mozilla/reject-some-requires
|
||||||
const { gDevTools } = require("devtools/client/framework/devtools");
|
const { gDevTools } = require("devtools/client/framework/devtools");
|
||||||
|
|
||||||
// eslint-disable-next-line mozilla/reject-some-requires
|
|
||||||
loader.lazyRequireGetter(
|
|
||||||
this,
|
|
||||||
"getAdHocFrontOrPrimitiveGrip",
|
|
||||||
"devtools/client/fronts/object",
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
class ResourceWatcher {
|
class ResourceWatcher {
|
||||||
/**
|
/**
|
||||||
* This class helps retrieving existing and listening to resources.
|
* This class helps retrieving existing and listening to resources.
|
||||||
@ -233,19 +225,20 @@ class ResourceWatcher {
|
|||||||
* which describes the resource.
|
* which describes the resource.
|
||||||
*/
|
*/
|
||||||
_onResourceAvailable(targetFront, resources) {
|
_onResourceAvailable(targetFront, resources) {
|
||||||
for (const resource of resources) {
|
for (let resource of resources) {
|
||||||
// Put the targetFront on the resource for easy retrieval.
|
// Put the targetFront on the resource for easy retrieval.
|
||||||
if (!resource.targetFront) {
|
if (!resource.targetFront) {
|
||||||
resource.targetFront = targetFront;
|
resource.targetFront = targetFront;
|
||||||
}
|
}
|
||||||
const { resourceType } = resource;
|
const { resourceType } = resource;
|
||||||
if (resourceType == ResourceWatcher.TYPES.CONSOLE_MESSAGE) {
|
|
||||||
if (Array.isArray(resource.message.arguments)) {
|
if (ResourceTransformers[resourceType]) {
|
||||||
// We might need to create fronts for each of the message arguments.
|
resource = ResourceTransformers[resourceType]({
|
||||||
resource.message.arguments = resource.message.arguments.map(arg =>
|
resource,
|
||||||
getAdHocFrontOrPrimitiveGrip(arg, targetFront)
|
targetList: this.targetList,
|
||||||
);
|
targetFront,
|
||||||
}
|
isFissionEnabledOnContentToolbox: gDevTools.isFissionContentToolboxEnabled(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this._availableListeners.emit(resourceType, {
|
this._availableListeners.emit(resourceType, {
|
||||||
@ -456,3 +449,12 @@ const LegacyListeners = {
|
|||||||
[ResourceWatcher.TYPES
|
[ResourceWatcher.TYPES
|
||||||
.ROOT_NODE]: require("devtools/shared/resources/legacy-listeners/root-node"),
|
.ROOT_NODE]: require("devtools/shared/resources/legacy-listeners/root-node"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Optional transformers for each type of resource.
|
||||||
|
// Each module added here should be a function that will receive the resource, the target, …
|
||||||
|
// and perform some transformation on the resource before it will be emitted.
|
||||||
|
// This is a good place to handle backward compatibility and manual resource marshalling.
|
||||||
|
const ResourceTransformers = {
|
||||||
|
[ResourceWatcher.TYPES
|
||||||
|
.CONSOLE_MESSAGE]: require("devtools/shared/resources/transformers/console-messages"),
|
||||||
|
};
|
||||||
|
23
devtools/shared/resources/transformers/console-messages.js
Normal file
23
devtools/shared/resources/transformers/console-messages.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/* 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";
|
||||||
|
|
||||||
|
// eslint-disable-next-line mozilla/reject-some-requires
|
||||||
|
loader.lazyRequireGetter(
|
||||||
|
this,
|
||||||
|
"getAdHocFrontOrPrimitiveGrip",
|
||||||
|
"devtools/client/fronts/object",
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
module.exports = function({ resource, targetFront }) {
|
||||||
|
if (Array.isArray(resource.message.arguments)) {
|
||||||
|
// We might need to create fronts for each of the message arguments.
|
||||||
|
resource.message.arguments = resource.message.arguments.map(arg =>
|
||||||
|
getAdHocFrontOrPrimitiveGrip(arg, targetFront)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return resource;
|
||||||
|
};
|
7
devtools/shared/resources/transformers/moz.build
Normal file
7
devtools/shared/resources/transformers/moz.build
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# 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/.
|
||||||
|
|
||||||
|
DevToolsModules(
|
||||||
|
'console-messages.js'
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user