зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1749769 - [devtools] Lazy load target legacy listeners. r=nchevobbe
Differential Revision: https://phabricator.services.mozilla.com/D135832
This commit is contained in:
Родитель
3c7dc514f2
Коммит
65cecb5a83
|
@ -57,6 +57,10 @@ global.loader = {
|
|||
"devtools/client/shared/telemetry",
|
||||
"devtools/client/shared/screenshot",
|
||||
"devtools/client/shared/focus",
|
||||
"devtools/shared/commands/target/legacy-target-watchers/legacy-processes-watcher",
|
||||
"devtools/shared/commands/target/legacy-target-watchers/legacy-workers-watcher",
|
||||
"devtools/shared/commands/target/legacy-target-watchers/legacy-sharedworkers-watcher",
|
||||
"devtools/shared/commands/target/legacy-target-watchers/legacy-serviceworkers-watcher",
|
||||
];
|
||||
if (!excluded.includes(path)) {
|
||||
if (!Array.isArray(names)) {
|
||||
|
@ -64,8 +68,13 @@ global.loader = {
|
|||
}
|
||||
|
||||
for (const name of names) {
|
||||
const module = require(path);
|
||||
global[name] = destruct ? module[name] : module;
|
||||
Object.defineProperty(global, name, {
|
||||
get() {
|
||||
const module = require(path);
|
||||
return destruct ? module[name] : module;
|
||||
},
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -69,4 +69,4 @@ class LegacyProcessesWatcher {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = { LegacyProcessesWatcher };
|
||||
module.exports = LegacyProcessesWatcher;
|
||||
|
|
|
@ -7,9 +7,7 @@
|
|||
// eslint-disable-next-line mozilla/reject-some-requires
|
||||
const { WorkersListener } = require("devtools/client/shared/workers-listener");
|
||||
|
||||
const {
|
||||
LegacyWorkersWatcher,
|
||||
} = require("devtools/shared/commands/target/legacy-target-watchers/legacy-workers-watcher");
|
||||
const LegacyWorkersWatcher = require("devtools/shared/commands/target/legacy-target-watchers/legacy-workers-watcher");
|
||||
|
||||
class LegacyServiceWorkersWatcher extends LegacyWorkersWatcher {
|
||||
// Holds the current target URL object
|
||||
|
@ -317,4 +315,4 @@ class LegacyServiceWorkersWatcher extends LegacyWorkersWatcher {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = { LegacyServiceWorkersWatcher };
|
||||
module.exports = LegacyServiceWorkersWatcher;
|
||||
|
|
|
@ -4,9 +4,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const {
|
||||
LegacyWorkersWatcher,
|
||||
} = require("devtools/shared/commands/target/legacy-target-watchers/legacy-workers-watcher");
|
||||
const LegacyWorkersWatcher = require("devtools/shared/commands/target/legacy-target-watchers/legacy-workers-watcher");
|
||||
|
||||
class LegacySharedWorkersWatcher extends LegacyWorkersWatcher {
|
||||
// Flag used from the parent class to listen to process targets.
|
||||
|
@ -18,4 +16,4 @@ class LegacySharedWorkersWatcher extends LegacyWorkersWatcher {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = { LegacySharedWorkersWatcher };
|
||||
module.exports = LegacySharedWorkersWatcher;
|
||||
|
|
|
@ -4,9 +4,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const {
|
||||
LegacyProcessesWatcher,
|
||||
} = require("devtools/shared/commands/target/legacy-target-watchers/legacy-processes-watcher");
|
||||
const LegacyProcessesWatcher = require("devtools/shared/commands/target/legacy-target-watchers/legacy-processes-watcher");
|
||||
|
||||
class LegacyWorkersWatcher {
|
||||
constructor(targetCommand, onTargetAvailable, onTargetDestroyed) {
|
||||
|
@ -237,4 +235,4 @@ class LegacyWorkersWatcher {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = { LegacyWorkersWatcher };
|
||||
module.exports = LegacyWorkersWatcher;
|
||||
|
|
|
@ -9,19 +9,6 @@ const EventEmitter = require("devtools/shared/event-emitter");
|
|||
|
||||
const BROWSERTOOLBOX_FISSION_ENABLED = "devtools.browsertoolbox.fission";
|
||||
|
||||
const {
|
||||
LegacyProcessesWatcher,
|
||||
} = require("devtools/shared/commands/target/legacy-target-watchers/legacy-processes-watcher");
|
||||
const {
|
||||
LegacyServiceWorkersWatcher,
|
||||
} = require("devtools/shared/commands/target/legacy-target-watchers/legacy-serviceworkers-watcher");
|
||||
const {
|
||||
LegacySharedWorkersWatcher,
|
||||
} = require("devtools/shared/commands/target/legacy-target-watchers/legacy-sharedworkers-watcher");
|
||||
const {
|
||||
LegacyWorkersWatcher,
|
||||
} = require("devtools/shared/commands/target/legacy-target-watchers/legacy-workers-watcher");
|
||||
|
||||
class TargetCommand extends EventEmitter {
|
||||
#selectedTargetFront;
|
||||
/**
|
||||
|
@ -88,29 +75,7 @@ class TargetCommand extends EventEmitter {
|
|||
this._onTargetDestroyed = this._onTargetDestroyed.bind(this);
|
||||
this._onTargetSelected = this._onTargetSelected.bind(this);
|
||||
|
||||
this.legacyImplementation = {
|
||||
process: new LegacyProcessesWatcher(
|
||||
this,
|
||||
this._onTargetAvailable,
|
||||
this._onTargetDestroyed
|
||||
),
|
||||
worker: new LegacyWorkersWatcher(
|
||||
this,
|
||||
this._onTargetAvailable,
|
||||
this._onTargetDestroyed
|
||||
),
|
||||
shared_worker: new LegacySharedWorkersWatcher(
|
||||
this,
|
||||
this._onTargetAvailable,
|
||||
this._onTargetDestroyed
|
||||
),
|
||||
service_worker: new LegacyServiceWorkersWatcher(
|
||||
this,
|
||||
this._onTargetAvailable,
|
||||
this._onTargetDestroyed,
|
||||
this.commands
|
||||
),
|
||||
};
|
||||
this.legacyImplementation = {};
|
||||
|
||||
// Public flag to allow listening for workers even if the fission pref is off
|
||||
// This allows listening for workers in the content toolbox outside of fission contexts
|
||||
|
@ -466,7 +431,16 @@ class TargetCommand extends EventEmitter {
|
|||
if (!isTargetSwitching) {
|
||||
await this.watcherFront.watchTargets(type);
|
||||
}
|
||||
} else if (this.legacyImplementation[type]) {
|
||||
} else if (LegacyTargetWatchers[type]) {
|
||||
// Instantiate the legacy listener only once for each TargetCommand, and reuse it if we stop and restart listening
|
||||
if (!this.legacyImplementation[type]) {
|
||||
this.legacyImplementation[type] = new LegacyTargetWatchers[type](
|
||||
this,
|
||||
this._onTargetAvailable,
|
||||
this._onTargetDestroyed,
|
||||
this.commands
|
||||
);
|
||||
}
|
||||
await this.legacyImplementation[type].listen();
|
||||
} else {
|
||||
throw new Error(`Unsupported target type '${type}'`);
|
||||
|
@ -1087,4 +1061,26 @@ TargetCommand.ALL_TYPES = TargetCommand.prototype.ALL_TYPES = Object.values(
|
|||
TargetCommand.TYPES
|
||||
);
|
||||
|
||||
const LegacyTargetWatchers = {};
|
||||
loader.lazyRequireGetter(
|
||||
LegacyTargetWatchers,
|
||||
TargetCommand.TYPES.PROCESS,
|
||||
"devtools/shared/commands/target/legacy-target-watchers/legacy-processes-watcher"
|
||||
);
|
||||
loader.lazyRequireGetter(
|
||||
LegacyTargetWatchers,
|
||||
TargetCommand.TYPES.WORKER,
|
||||
"devtools/shared/commands/target/legacy-target-watchers/legacy-workers-watcher"
|
||||
);
|
||||
loader.lazyRequireGetter(
|
||||
LegacyTargetWatchers,
|
||||
TargetCommand.TYPES.SHARED_WORKER,
|
||||
"devtools/shared/commands/target/legacy-target-watchers/legacy-sharedworkers-watcher"
|
||||
);
|
||||
loader.lazyRequireGetter(
|
||||
LegacyTargetWatchers,
|
||||
TargetCommand.TYPES.SERVICE_WORKER,
|
||||
"devtools/shared/commands/target/legacy-target-watchers/legacy-serviceworkers-watcher"
|
||||
);
|
||||
|
||||
module.exports = TargetCommand;
|
||||
|
|
Загрузка…
Ссылка в новой задаче