Bug 1657130 - Expose worker's window IDs to nsIWorkerDebugger r=dom-workers-and-storage-reviewers,asuth

Differential Revision: https://phabricator.services.mozilla.com/D99441
This commit is contained in:
Yaron Tausky 2021-01-19 17:04:04 +00:00
parent 3e98e56e75
commit 3f05d24fad
4 changed files with 38 additions and 5 deletions

View File

@ -269,19 +269,45 @@ WorkerDebugger::GetWindow(mozIDOMWindow** aResult) {
return NS_ERROR_UNEXPECTED;
}
nsCOMPtr<nsPIDOMWindowInner> window = DedicatedWorkerWindow();
window.forget(aResult);
return NS_OK;
}
NS_IMETHODIMP
WorkerDebugger::GetWindowIDs(nsTArray<uint64_t>& aResult) {
AssertIsOnMainThread();
if (!mWorkerPrivate) {
return NS_ERROR_UNEXPECTED;
}
if (mWorkerPrivate->IsDedicatedWorker()) {
const auto window = DedicatedWorkerWindow();
aResult.AppendElement(window->WindowID());
} else if (mWorkerPrivate->IsSharedWorker()) {
const RemoteWorkerChild* const controller =
mWorkerPrivate->GetRemoteWorkerController();
MOZ_ASSERT(controller);
aResult = controller->WindowIDs().Clone();
}
return NS_OK;
}
nsCOMPtr<nsPIDOMWindowInner> WorkerDebugger::DedicatedWorkerWindow() {
MOZ_ASSERT(mWorkerPrivate);
WorkerPrivate* worker = mWorkerPrivate;
while (worker->GetParent()) {
worker = worker->GetParent();
}
if (!worker->IsDedicatedWorker()) {
*aResult = nullptr;
return NS_OK;
return nullptr;
}
nsCOMPtr<nsPIDOMWindowInner> window = worker->GetWindow();
window.forget(aResult);
return NS_OK;
return worker->GetWindow();
}
NS_IMETHODIMP

View File

@ -13,6 +13,7 @@
class mozIDOMWindow;
class nsIPrincipal;
class nsPIDOMWindowInner;
namespace mozilla {
namespace dom {
@ -56,6 +57,8 @@ class WorkerDebugger : public nsIWorkerDebugger {
void ReportErrorToDebuggerOnMainThread(const nsAString& aFilename,
uint32_t aLineno,
const nsAString& aMessage);
nsCOMPtr<nsPIDOMWindowInner> DedicatedWorkerWindow();
};
} // namespace dom

View File

@ -37,6 +37,8 @@ interface nsIWorkerDebugger : nsISupports
// 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;

View File

@ -66,6 +66,8 @@ class RemoteWorkerChild final
RefPtr<GenericPromise> MaybeSendSetServiceWorkerSkipWaitingFlag();
const nsTArray<uint64_t>& WindowIDs() const { return mWindowIDs; }
private:
class InitializeWorkerRunnable;