mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-11 21:58:41 +02:00
Ideally, formAttributeName would be a field on the prototype of each front, but unfortunately, Firefox doesn't support ES Class's fields yet. So it is put as an instance attribute instead. This patch streamline the manually set actorID and the retrieval of actor ID from root or target front's form into `getFront` helper method. So that all the specific related to the lazy actor is now inside of this helper. It also moves the special "this.manage(this)" to this helper. We might be able to followup on this one and finally have only the root front being self managed. But the initialize method makes it hard. Note the special tweak made to devtools/client/responsive.html/manager.js Hopefully this can be removed once the target classes are merged. Depends on D15832 Differential Revision: https://phabricator.services.mozilla.com/D17615 --HG-- extra : moz-landing-system : lando
63 lines
1.9 KiB
JavaScript
63 lines
1.9 KiB
JavaScript
/* 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";
|
|
|
|
const { components } = require("chrome");
|
|
const Services = require("Services");
|
|
const { actorActorSpec, actorRegistrySpec } = require("devtools/shared/specs/actor-registry");
|
|
const { FrontClassWithSpec, registerFront } = require("devtools/shared/protocol");
|
|
|
|
loader.lazyImporter(this, "NetUtil", "resource://gre/modules/NetUtil.jsm");
|
|
|
|
class ActorActorFront extends FrontClassWithSpec(actorActorSpec) {
|
|
}
|
|
|
|
exports.ActorActorFront = ActorActorFront;
|
|
registerFront(ActorActorFront);
|
|
|
|
function request(uri) {
|
|
return new Promise((resolve, reject) => {
|
|
try {
|
|
uri = Services.io.newURI(uri);
|
|
} catch (e) {
|
|
reject(e);
|
|
}
|
|
|
|
NetUtil.asyncFetch({
|
|
uri,
|
|
loadUsingSystemPrincipal: true,
|
|
}, (stream, status, req) => {
|
|
if (!components.isSuccessCode(status)) {
|
|
reject(new Error("Request failed with status code = "
|
|
+ status
|
|
+ " after NetUtil.asyncFetch for url = "
|
|
+ uri));
|
|
return;
|
|
}
|
|
|
|
const source = NetUtil.readInputStreamToString(stream, stream.available());
|
|
stream.close();
|
|
resolve(source);
|
|
});
|
|
});
|
|
}
|
|
|
|
class ActorRegistryFront extends FrontClassWithSpec(actorRegistrySpec) {
|
|
constructor(client) {
|
|
super(client);
|
|
|
|
// Attribute name from which to retrieve the actorID out of the target actor's form
|
|
this.formAttributeName = "actorRegistryActor";
|
|
}
|
|
|
|
registerActor(uri, options) {
|
|
return request(uri, options)
|
|
.then(sourceText => {
|
|
return super.registerActor(sourceText, uri, options);
|
|
});
|
|
}
|
|
}
|
|
|
|
exports.ActorRegistryFront = ActorRegistryFront;
|
|
registerFront(ActorRegistryFront);
|