Files
tubestation/dom/workers/nsIWorkerDebugger.idl
Eden Chuang a829345ca5 Bug 1899503 - P3 PRemoteWorkerDebugger binding implementation. r=asuth
This patch implements the PRemoteWorkerDebugger binding.

We are trying to keep the same logic debugger registration/unregistration to minimize the difference between the local debugger(the debugger on the content process main thread)

The registration logic is
After constructing a Worker, we start the debugger registration and block the parent thread until the registration is complete. Blocking the parent thread because we don't want to dispatch the ComplieScriptRunnable() and any other DebuggeeRunnables before the debugger is ready. Blocking the parent thread also forbids the IPC that we might not be able to handle during the debugger registration, such as SharedWorkerTerminateOpArgs which can terminate a "Pending" worker.

After RemoteWorkerDebuggerManagerChild::SendRegister() is called, we use mRemoteDebuggerBindingCondVar to block the parent thread. After registration is done in the parent process, RemoteWorkerDebugger receives the RegistrationDone() on the WorkerThread, then calling mRemoteWorkerDebuggerBindingCondVar.Notify to unblock the parent thread.

However, To ensure the message can be sent immediately after RemoteWorkerDebuggerParent binding, RemoteWorkerDebuggerChild binding needs to be completed in the Worker thread before calling RemoteWorkerDebuggerManagerChild::SendRegister(), so we wait for the child binding to complete in EnableRemoteDebugger().

RemoteWorkerDebuggerChild binding happens on the Worker thread when needed. The time points are the start of WorkerThreadPrimaryRunnable::Run() and WorkerPrivate::ThawInternal(). So when the Worker starts to run the event loops, we create the RemoteWorkerDebuggerChild and bind it to the child Endpoint. We then notify the parent thread that the child binding is done to start remote debugger registration on the parent process.

Through this implementation, the remote debugger mechanism has similar logic to the local debugger and can be used by all types of Workers.

Depends on D231682

Differential Revision: https://phabricator.services.mozilla.com/D230260
2025-04-15 09:47:39 +00:00

78 lines
2.4 KiB
Plaintext

/* 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 https://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
interface mozIDOMWindow;
interface nsIPrincipal;
[scriptable, uuid(9cf3b48e-361d-486a-8917-55cf8d00bb41)]
interface nsIWorkerDebuggerListener : nsISupports
{
void onClose();
void onError(in ACString filename, in unsigned long lineno,
in AString message);
void onMessage(in AString message);
};
[scriptable, builtinclass, uuid(22f93aa3-8a05-46be-87e0-fa93bf8a8eff)]
interface nsIWorkerDebugger : nsISupports
{
const unsigned long TYPE_DEDICATED = 0;
const unsigned long TYPE_SHARED = 1;
const unsigned long TYPE_SERVICE = 2;
readonly attribute boolean isClosed;
readonly attribute boolean isChrome;
readonly attribute boolean isRemote;
readonly attribute boolean isInitialized;
readonly attribute nsIWorkerDebugger parent;
readonly attribute unsigned long type;
readonly attribute AString url;
// If this is a dedicated worker, the window this worker or (in the case of
// nested workers) its top-level ancestral worker is associated with.
readonly attribute mozIDOMWindow window;
readonly attribute Array<uint64_t> windowIDs;
readonly attribute nsIPrincipal principal;
readonly attribute unsigned long serviceWorkerID;
readonly attribute AString id;
readonly attribute AString name;
void initialize(in AString url);
[binaryname(PostMessageMoz)]
void postMessage(in AString message);
void addListener(in nsIWorkerDebuggerListener listener);
void removeListener(in nsIWorkerDebuggerListener listener);
// Indicate whether the debugger has finished initializing. By default the
// debugger will be considered initialized when the onRegister hooks in all
// nsIWorkerDebuggerManagerListener have been called.
//
// setDebuggerReady(false) can be called during an onRegister hook to mark
// the debugger as not being ready yet. This will prevent all content from
// running in the worker, including the worker's main script and any messages
// posted to it. Other runnables will still execute in the worker as normal.
//
// When the debugger is ready, setDebuggerReady(true) should then be called
// to allow the worker to begin executing content.
void setDebuggerReady(in boolean ready);
};