/* 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/. */
function onRemoteDevToolsClientClosed() {
window.AboutDebugging.onNetworkLocationsUpdated();
window.AboutDebugging.onUSBRuntimesUpdated();
}
function connectRuntime(id) { // Create a random connection id to track the connection attempt in telemetry. const connectionId = (Math.random() * 100000) | 0;
// The preferences test-connection-timing-out-delay and test-connection-cancel-delay // don't have a default value but will be overridden during our tests. const connectionTimingOutDelay = Services.prefs.getIntPref( "devtools.aboutdebugging.test-connection-timing-out-delay",
CONNECTION_TIMING_OUT_DELAY
); const connectionCancelDelay = Services.prefs.getIntPref( "devtools.aboutdebugging.test-connection-cancel-delay",
CONNECTION_CANCEL_DELAY
);
const connectionNotRespondingTimer = setTimeout(() => { // If connecting to the runtime takes time over CONNECTION_TIMING_OUT_DELAY, // we assume the connection prompt is showing on the runtime, show a dialog // to let user know that.
dispatch({ type: CONNECT_RUNTIME_NOT_RESPONDING, connectionId, id });
}, connectionTimingOutDelay); const connectionCancelTimer = setTimeout(() => { // Connect button of the runtime will be disabled during connection, but the status // continues till the connection was either succeed or failed. This may have a // possibility that the disabling continues unless page reloading, user will not be // able to click again. To avoid this, revert the connect button status after // CONNECTION_CANCEL_DELAY ms.
dispatch({ type: CONNECT_RUNTIME_CANCEL, connectionId, id });
}, connectionCancelDelay);
// Fenix specific workarounds are needed until we can get proper server side APIs // to detect Fenix and get the proper application names and versions. // See https://github.com/mozilla-mobile/fenix/issues/2016.
// For Fenix runtimes, the ADB runtime name is more accurate than the one returned // by the Device actor. const runtimeName = runtime.isFenix
? runtime.name
: deviceDescription.name;
// For Fenix runtimes, the version we should display is the application version // retrieved from ADB, and not the Gecko version returned by the Device actor. const version = runtime.isFenix
? runtime.extra.adbPackageVersion
: deviceDescription.version;
if (runtime.type !== RUNTIMES.THIS_FIREFOX) { // `closed` event will be emitted when disabling remote debugging // on the connected remote runtime.
clientWrapper.once("closed", onRemoteDevToolsClientClosed);
}
try { if (id === RUNTIMES.THIS_FIREFOX) { // THIS_FIREFOX connects and disconnects on the fly when opening the page.
await dispatch(connectRuntime(RUNTIMES.THIS_FIREFOX));
}
// The selected runtime should already have a connected client assigned. const runtime = findRuntimeById(id, getState().runtimes);
await dispatch({ type: WATCH_RUNTIME_SUCCESS, runtime });
dispatch(Actions.requestExtensions()); // we have to wait for tabs, otherwise the requests to getTarget may interfer // with listProcesses
await dispatch(Actions.requestTabs());
dispatch(Actions.requestWorkers());
try { if (id === RUNTIMES.THIS_FIREFOX) { // THIS_FIREFOX connects and disconnects on the fly when opening the page.
await dispatch(disconnectRuntime(RUNTIMES.THIS_FIREFOX));
}
/** * Check that a given runtime can still be found in the provided array of runtimes, and * that the connection of the associated DevToolsClient is still valid. * Note that this check is only valid for runtimes which match the type of the runtimes * in the array.
*/ function _isRuntimeValid(runtime, runtimes) { const isRuntimeAvailable = runtimes.some(r => r.id === runtime.id); const isConnectionValid =
runtime.runtimeDetails && !runtime.runtimeDetails.clientWrapper.isClosed(); return isRuntimeAvailable && isConnectionValid;
}
// Check if the updated remote runtimes should trigger a navigation out of the current // runtime page. if (
currentRuntime &&
currentRuntime.type === type &&
!_isRuntimeValid(currentRuntime, runtimes)
) { // Since current remote runtime is invalid, move to this firefox page. // This case is considered as followings and so on: // * Remove ADB addon // * (Physically) Disconnect USB runtime // // The reason we call selectPage before REMOTE_RUNTIMES_UPDATED is fired is below. // Current runtime can not be retrieved after REMOTE_RUNTIMES_UPDATED action, since // that updates runtime state. So, before that we fire selectPage action to execute // `unwatchRuntime` correctly.
await dispatch(
Actions.selectPage(PAGE_TYPES.RUNTIME, RUNTIMES.THIS_FIREFOX)
);
}
// For existing runtimes, transfer all properties that are not available in the // runtime objects passed to this method: // - runtimeDetails (set by about:debugging after a successful connection) // - isConnecting (set by about:debugging during the connection) // - isConnectionFailed (set by about:debugging if connection was failed) // - isConnectionNotResponding // (set by about:debugging if connection is taking too much time) // - isConnectionTimeout (set by about:debugging if connection was timeout)
runtimes.forEach(runtime => { const existingRuntime = findRuntimeById(runtime.id, getState().runtimes); const isConnectionValid =
existingRuntime?.runtimeDetails &&
!existingRuntime.runtimeDetails.clientWrapper.isClosed();
runtime.runtimeDetails = isConnectionValid
? existingRuntime.runtimeDetails
: null;
runtime.isConnecting = existingRuntime
? existingRuntime.isConnecting
: false;
runtime.isConnectionFailed = existingRuntime
? existingRuntime.isConnectionFailed
: false;
runtime.isConnectionNotResponding = existingRuntime
? existingRuntime.isConnectionNotResponding
: false;
runtime.isConnectionTimeout = existingRuntime
? existingRuntime.isConnectionTimeout
: false;
});
const existingRuntimes = getAllRuntimes(getState().runtimes); for (const runtime of existingRuntimes) { // Runtime was connected before. const isConnected = runtime.runtimeDetails; // Runtime is of the same type as the updated runtimes array, so we should check it. const isSameType = runtime.type === type; if (isConnected && isSameType && !_isRuntimeValid(runtime, runtimes)) { // Disconnect runtimes that were no longer valid.
await dispatch(disconnectRuntime(runtime.id));
}
}
dispatch({ type: REMOTE_RUNTIMES_UPDATED, runtimes, runtimeType: type });
for (const runtime of getAllRuntimes(getState().runtimes)) { if (runtime.type !== type) { continue;
}
// Reconnect clients already available in the RemoteClientManager. const isConnected = !!runtime.runtimeDetails; const hasConnectedClient = remoteClientManager.hasClient(
runtime.id,
runtime.type
); if (!isConnected && hasConnectedClient) {
await dispatch(connectRuntime(runtime.id));
}
}
};
}
/** * Remove all the listeners added on client objects. Since those objects are persisted * regardless of the about:debugging lifecycle, all the added events should be removed * before leaving about:debugging.
*/ function removeRuntimeListeners() { return ({ getState }) => { const allRuntimes = getAllRuntimes(getState().runtimes); const remoteRuntimes = allRuntimes.filter(
r => r.type !== RUNTIMES.THIS_FIREFOX
); for (const runtime of remoteRuntimes) { if (runtime.runtimeDetails) { const { clientWrapper } = runtime.runtimeDetails;
clientWrapper.off("closed", onRemoteDevToolsClientClosed);
}
}
};
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.