Bug 1685268 - [devtools] Watch for stylesheet resources from inspector front instead of inspector panel. r=ochameau.

This was previously done in the inspector panel initialization phase, after the
inspector front was created, which could lead to races.
Since the pageStyle actor requires stylesheets to being watched (when watcher
support is enabled), we do this in the inspector front, before creating the
page style actor.
We put the resourceWatcher instance on targetFront from resourceWatcher#_onTargetAvailable
so we can use it from everywhere.

Differential Revision: https://phabricator.services.mozilla.com/D109470
This commit is contained in:
Nicolas Chevobbe 2021-03-26 09:46:32 +00:00
parent f19daf9ada
commit 28f4165fb6
4 changed files with 22 additions and 21 deletions

View File

@ -51,6 +51,21 @@ class InspectorFront extends FrontClassWithSpec(inspectorSpec) {
return this.initialized;
}
// If the server-side support for stylesheet resources is enabled, we need to start
// to watch for them before instanciating the pageStyle actor (which does use the
// watcher and assume we're already watching for stylesheets).
const { resourceWatcher } = this.targetFront;
if (
resourceWatcher?.hasResourceWatcherSupport(
resourceWatcher.TYPES.STYLESHEET
)
) {
await resourceWatcher.watchResources([resourceWatcher.TYPES.STYLESHEET], {
// we simply want to start the watcher, we don't have to do anything with those resources.
onAvailable: () => {},
});
}
this.initialized = await Promise.all([
this._getWalker(),
this._getPageStyle(),

View File

@ -110,7 +110,7 @@ class StyleRuleFront extends FrontClassWithSpec(styleRuleSpec) {
}
get parentStyleSheet() {
const resourceWatcher = this.parentFront.resourceWatcher;
const resourceWatcher = this.targetFront.resourceWatcher;
if (resourceWatcher) {
return resourceWatcher.getResourceById(
resourceWatcher.TYPES.STYLESHEET,

View File

@ -203,21 +203,6 @@ Inspector.prototype = {
r => (this._resolveMarkupViewInitialized = r)
);
// If the server-side stylesheet watcher is enabled, we should start to watch
// stylesheet resources before instanciating the inspector front since pageStyle
// actor should refer the watcher.
if (
this.toolbox.resourceWatcher.hasResourceWatcherSupport(
this.toolbox.resourceWatcher.TYPES.STYLESHEET
)
) {
this._isServerSideStyleSheetWatcherEnabled = true;
await this.toolbox.resourceWatcher.watchResources(
[this.toolbox.resourceWatcher.TYPES.STYLESHEET],
{ onAvailable: this.onResourceAvailable }
);
}
await this.toolbox.targetList.watchTargets(
[this.toolbox.targetList.TYPES.FRAME],
this._onTargetAvailable,
@ -271,11 +256,6 @@ Inspector.prototype = {
async initInspectorFront(targetFront) {
this.inspectorFront = await targetFront.getFront("inspector");
this.walker = this.inspectorFront.walker;
// PageStyle front need the resource watcher when the server-side stylesheet watcher is enabled.
if (this._isServerSideStyleSheetWatcherEnabled) {
this.inspectorFront.pageStyle.resourceWatcher = this.toolbox.resourceWatcher;
}
},
get toolbox() {

View File

@ -301,6 +301,12 @@ class ResourceWatcher {
* composed of a BrowsingContextTargetFront or ContentProcessTargetFront.
*/
async _onTargetAvailable({ targetFront, isTargetSwitching }) {
// We put the resourceWatcher on the targetFront so it can be retrieved in the
// inspector and style-rule fronts. This might be removed in the future if/when we
// turn the resourceWatcher into a Command.
// ⚠️ This shouldn't be used anywhere else ⚠️
targetFront.resourceWatcher = this;
const resources = [];
if (isTargetSwitching) {
this._onWillNavigate(targetFront);