Bug 1718236 - [devtools] Move BrowsingContextTargetActor reload to descriptor actors r=ochameau,nchevobbe,devtools-backward-compat-reviewers

Depends on D118471

Differential Revision: https://phabricator.services.mozilla.com/D118473
This commit is contained in:
Julian Descottes 2021-06-25 11:15:00 +00:00
Родитель fc7629cc33
Коммит c07fae4f8a
10 изменённых файлов: 118 добавлений и 10 удалений

Просмотреть файл

@ -163,10 +163,26 @@ const ProcessDescriptorActor = ActorClassWithSpec(processDescriptorSpec, {
traits: {
// Supports the Watcher actor. Can be removed as part of Bug 1680280.
watcher: true,
// ParentProcessTargetActor can be reloaded.
supportsReloadBrowsingContext: this.isParent,
},
};
},
async reloadBrowsingContext({ bypassCache }) {
if (!this.isParent) {
throw new Error(
"reloadBrowsingContext is not available for content process descriptors"
);
}
this._browsingContextTargetActor.browsingContext.reload(
bypassCache
? Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE
: Ci.nsIWebNavigation.LOAD_FLAGS_NONE
);
},
destroy() {
this.emit("descriptor-destroyed");

Просмотреть файл

@ -12,6 +12,7 @@
* See devtools/docs/backend/actor-hierarchy.md for more details.
*/
const { Ci } = require("chrome");
const Services = require("Services");
const {
connectToFrame,
@ -62,6 +63,7 @@ const TabDescriptorActor = ActorClassWithSpec(tabDescriptorSpec, {
traits: {
// Supports the Watcher actor. Can be removed as part of Bug 1680280.
watcher: true,
supportsReloadBrowsingContext: true,
},
url: this._getUrl(),
};
@ -214,6 +216,18 @@ const TabDescriptorActor = ActorClassWithSpec(tabDescriptorSpec, {
return tab?.hasAttribute && tab.hasAttribute("pending");
},
reloadBrowsingContext({ bypassCache }) {
if (!this._browser || !this._browser.browsingContext) {
return;
}
this._browser.browsingContext.reload(
bypassCache
? Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE
: Ci.nsIWebNavigation.LOAD_FLAGS_NONE
);
},
destroy() {
this.emit("descriptor-destroyed");
this._browser = null;

Просмотреть файл

@ -12,6 +12,7 @@
* See devtools/docs/backend/actor-hierarchy.md for more details.
*/
const { Ci } = require("chrome");
const protocol = require("devtools/shared/protocol");
const {
webExtensionDescriptorSpec,
@ -82,7 +83,9 @@ const WebExtensionDescriptorActor = protocol.ActorClassWithSpec(
manifestURL: policy && policy.getURL("manifest.json"),
name: this.addon.name,
temporarilyInstalled: this.addon.temporarilyInstalled,
traits: {},
traits: {
supportsReloadBrowsingContext: true,
},
url: this.addon.sourceURI ? this.addon.sourceURI.spec : undefined,
warnings: ExtensionParent.DebugUtils.getExtensionManifestWarnings(
this.addonId
@ -141,6 +144,18 @@ const WebExtensionDescriptorActor = protocol.ActorClassWithSpec(
return this._form;
},
async reloadBrowsingContext({ bypassCache }) {
if (!this._browser || !this._browser.browsingContext) {
return;
}
this._browser.browsingContext.reload(
bypassCache
? Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE
: Ci.nsIWebNavigation.LOAD_FLAGS_NONE
);
},
/** WebExtension Actor Methods **/
async reload() {
await this.addon.reload();

Просмотреть файл

@ -1155,6 +1155,10 @@ const browsingContextTargetPrototype = {
/**
* Reload the page in this browsing context.
*
* @backward-compat { legacy }
* reload is preserved for third party tools. See Bug 1717837.
* DevTools should use Descriptor::reloadBrowsingContext instead.
*/
reload(request) {
const force = request?.options?.force;
@ -1291,7 +1295,7 @@ const browsingContextTargetPrototype = {
}
if (reload) {
this.reload();
this.webNavigation.reload(Ci.nsIWebNavigation.LOAD_FLAGS_NONE);
}
},

Просмотреть файл

@ -758,9 +758,14 @@ class TargetCommand extends EventEmitter {
* If true, the reload will be forced to bypass any cache.
*/
async reloadTopLevelTarget(bypassCache = false) {
// @backward-compat { version 91 }
// BrowsingContextTargetActor.reload was moved to descriptors.
// After release 91 is on the release channel, we can check
// this.descriptorFront.traits.supportsReloadBrowsingContext
// instead.
if (!this.targetFront.isBrowsingContext) {
throw new Error(
"The top level target isn't a BrowsingContext and don't support being reloaded"
"The top level target isn't a BrowsingContext and doesn't support being reloaded"
);
}
@ -780,12 +785,24 @@ class TargetCommand extends EventEmitter {
}
);
// @backward-compat { version 91 }
// BrowsingContextTargetActor.reload was moved to descriptors.
if (this.descriptorFront.traits.supportsReloadBrowsingContext) {
await this.descriptorFront.reloadBrowsingContext({ bypassCache });
} else {
await this._legacyTargetActorReload(bypassCache);
}
await onReloaded;
}
async _legacyTargetActorReload(force) {
const { targetFront } = this;
try {
// Arguments of reload are a bit convoluted.
// We expect an dictionary object, which only support one attribute
// called "force" which force bypassing the caches.
await targetFront.reload({ options: { force: bypassCache } });
await targetFront.reload({ options: { force } });
} catch (e) {
// If the target follows the window global lifecycle, the reload request
// will fail, and we should swallow the error. Re-throw it otherwise.
@ -793,8 +810,6 @@ class TargetCommand extends EventEmitter {
throw e;
}
}
await onReloaded;
}
/**

Просмотреть файл

@ -81,7 +81,7 @@ add_task(async function() {
} catch (e) {
is(
e.message,
"The top level target isn't a BrowsingContext and don't support being reloaded"
"The top level target isn't a BrowsingContext and doesn't support being reloaded"
);
}
await commands.destroy();

Просмотреть файл

@ -3,7 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { generateActorSpec, RetVal } = require("devtools/shared/protocol");
const {
generateActorSpec,
RetVal,
Option,
} = require("devtools/shared/protocol");
const processDescriptorSpec = generateActorSpec({
typeName: "processDescriptor",
@ -19,6 +23,12 @@ const processDescriptorSpec = generateActorSpec({
request: {},
response: RetVal("watcher"),
},
reloadBrowsingContext: {
request: {
bypassCache: Option(0, "boolean"),
},
response: {},
},
},
events: {

Просмотреть файл

@ -3,7 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { generateActorSpec, RetVal } = require("devtools/shared/protocol");
const {
generateActorSpec,
Option,
RetVal,
} = require("devtools/shared/protocol");
const tabDescriptorSpec = generateActorSpec({
typeName: "tabDescriptor",
@ -25,6 +29,12 @@ const tabDescriptorSpec = generateActorSpec({
request: {},
response: RetVal("watcher"),
},
reloadBrowsingContext: {
request: {
bypassCache: Option(0, "boolean"),
},
response: {},
},
},
events: {

Просмотреть файл

@ -3,7 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { RetVal, generateActorSpec } = require("devtools/shared/protocol");
const {
RetVal,
generateActorSpec,
Option,
} = require("devtools/shared/protocol");
const webExtensionDescriptorSpec = generateActorSpec({
typeName: "webExtensionDescriptor",
@ -24,6 +28,13 @@ const webExtensionDescriptorSpec = generateActorSpec({
request: {},
response: { form: RetVal("json") },
},
reloadBrowsingContext: {
request: {
bypassCache: Option(0, "boolean"),
},
response: {},
},
},
events: {

Просмотреть файл

@ -37,6 +37,12 @@ types.addDictType("browsingContextTarget.workers", {
workers: "array:workerDescriptor",
});
// @backward-compat { version 91 }
// BrowsingContextTarget reload should no longer be used within
// DevTools. Remove this comment when version 91 hits release.
// @backward-compat { legacy }
// reload is preserved for third party tools. See Bug 1717837.
// DevTools should use Descriptor::reloadBrowsingContext instead.
types.addDictType("browsingContextTarget.reload", {
force: "boolean",
});
@ -79,6 +85,13 @@ const browsingContextTargetSpecPrototype = {
request: {},
response: {},
},
// @backward-compat { version 91 }
// BrowsingContextTarget reload should no longer be used within
// DevTools. Remove this comment when version 91 hits release.
// @backward-compat { legacy }
// reload is preserved for third party tools. See Bug 1717837.
// DevTools should use Descriptor::reloadBrowsingContext instead.
reload: {
request: {
options: Option(0, "browsingContextTarget.reload"),