mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-10 13:44:39 +08:00
This reverts commit 28abe7802899b037a176426f883c750fec5a6d24. Bug: 772558, 846211,846551 Change-Id: Ib782b1fb5ee737f31deaa94630fb2bb1021b579b Reviewed-on: https://chromium-review.googlesource.com/1077597 Reviewed-by: Pavel Feldman <pfeldman@chromium.org> Reviewed-by: Patrick Hulce <phulce@chromium.org> Commit-Queue: Paul Irish <paulirish@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#563121} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 8405e18c05b9e5a1c714db1e204de6aaae3be24d
92 lines
2.4 KiB
JavaScript
92 lines
2.4 KiB
JavaScript
// Copyright 2018 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
Audits2.ProtocolService = class extends Common.Object {
|
|
constructor() {
|
|
super();
|
|
/** @type {?Protocol.InspectorBackend.Connection} */
|
|
this._rawConnection = null;
|
|
/** @type {?Services.ServiceManager.Service} */
|
|
this._backend = null;
|
|
/** @type {?Promise} */
|
|
this._backendPromise = null;
|
|
/** @type {?function(string)} */
|
|
this._status = null;
|
|
}
|
|
|
|
/**
|
|
* @return {!Promise<undefined>}
|
|
*/
|
|
attach() {
|
|
return InspectorMain.interceptMainConnection(this._dispatchProtocolMessage.bind(this)).then(rawConnection => {
|
|
this._rawConnection = rawConnection;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @param {string} auditURL
|
|
* @param {!Array<string>} categoryIDs
|
|
* @param {!Object} flags
|
|
* @return {!Promise<!ReportRenderer.RunnerResult>}
|
|
*/
|
|
startLighthouse(auditURL, categoryIDs, flags) {
|
|
return this._send('start', {url: auditURL, categoryIDs, flags});
|
|
}
|
|
|
|
/**
|
|
* @return {!Promise<!Object|undefined>}
|
|
*/
|
|
detach() {
|
|
return Promise.resolve().then(() => this._send('stop')).then(() => this._backend.dispose()).then(() => {
|
|
delete this._backend;
|
|
delete this._backendPromise;
|
|
return this._rawConnection.disconnect();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @param {function (string): undefined} callback
|
|
*/
|
|
registerStatusCallback(callback) {
|
|
this._status = callback;
|
|
}
|
|
|
|
/**
|
|
* @param {string} message
|
|
*/
|
|
_dispatchProtocolMessage(message) {
|
|
this._send('dispatchProtocolMessage', {message: message});
|
|
}
|
|
|
|
_initWorker() {
|
|
this._backendPromise =
|
|
Services.serviceManager.createAppService('audits2_worker', 'Audits2Service').then(backend => {
|
|
if (this._backend)
|
|
return;
|
|
this._backend = backend;
|
|
this._backend.on('statusUpdate', result => this._status(result.message));
|
|
this._backend.on('sendProtocolMessage', result => this._sendProtocolMessage(result.message));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @param {string} message
|
|
*/
|
|
_sendProtocolMessage(message) {
|
|
this._rawConnection.sendMessage(message);
|
|
}
|
|
|
|
/**
|
|
* @param {string} method
|
|
* @param {!Object=} params
|
|
* @return {!Promise<!ReportRenderer.RunnerResult>}
|
|
*/
|
|
_send(method, params) {
|
|
if (!this._backendPromise)
|
|
this._initWorker();
|
|
|
|
return this._backendPromise.then(_ => this._backend.send(method, params));
|
|
}
|
|
};
|