Skip to content

Commit 797f26e

Browse files
committed
[Site Isolation] Web Inspector: Add the debugger pause session coordinator with typed IPC and release on teardown
https://bugs.webkit.org/show_bug.cgi?id=326737 rdar://189451502 Reviewed by Qianlang Chen. With site isolation, a paused frame holds every page in its own WebContent process (webkit.org/b/326582), but frames of the same page in other processes keep running timers, rAF, postMessage handlers, and fetch callbacks. This is the first step of holding them too: a pause session coordinator in the UI process, behind a new off-by-default preference, SiteIsolationGlobalDebuggerPauseEnabled. - WebContent to UI: when a FrameDebugger pauses or continues and the preference is on, DebuggerSuspensionController tells the page's InspectorBackendClient, which in WebKit sends WebPageProxy::FrameDidPauseForDebugger or FrameDidContinueForDebugger. Iframe processes send these to their WebPageProxy directly, and ProvisionalPageProxy forwards them like SendMessageToInspectorFrontend. The paused frame's page and identifier are kept for the end-of-pause notification, since a paused iframe can be removed before it resumes. - UI: DebuggerPauseCoordinator, owned by WebPageProxy, opens a session on the first stopping frame and sends WebInspectorBackend::SuspendForDebugger with a new DebuggerPauseSessionIdentifier to the page in every other process of forEachWebContentProcess(); the pausing process already holds its pages. When the last stopping frame continues, it sends ResumeFromDebugger to the same pages. The identifier is a WebCore type, so the session holds stay typed in WebCore too. - UI to WebContent: PageInspectorController::suspendForDebuggerSession() and resumeFromDebuggerSession() add and remove a session hold in the page's DebuggerSuspensionController, which holds the page's documents while any hold is active. - Validation: a pause report counts only while an inspector frontend is connected, as counted by WebPageInspectorController (a new hasFrontends()) rather than by the count the web process reports, and only for a frame that the sending process hosts or is loading. A frame of another page fails a MESSAGE_CHECK. Other mismatches are ignored rather than treated as bad messages, because a report can race with the frame's removal and with a commit in another process. A continue report only ends a pause that the same process reported, so stopping frames are kept as (process, frame) pairs: a frame that moved can be stopping in its old and its new process at once. - Teardown: the session closes, resuming the other processes, when the last inspector frontend disconnects and when the page closes. Releasing it when the paused frame's process exits, or when the paused frame is removed or moves to another process, is webkit.org/b/327427. Later steps add the stepping signal, late joiners, continuation deferral, concurrent stoppers (the process that paused first is not held if it resumes while another stays paused), the scope rule, and the protocol and frontend; until then every step closes and reopens the session. pause-holds-cross-process-frames.html pauses the main frame and checks that a cross-site iframe in another process stops until resume, and does the same the other way around; both checks fail without the coordinator. pause-holds-cross-process-frames-disabled.html checks that nothing is held with the preference off. * LayoutTests/http/tests/site-isolation/inspector/debugger/pause-holds-cross-process-frames-disabled-expected.txt: Added. * LayoutTests/http/tests/site-isolation/inspector/debugger/pause-holds-cross-process-frames-disabled.html: Added. * LayoutTests/http/tests/site-isolation/inspector/debugger/pause-holds-cross-process-frames-expected.txt: Added. * LayoutTests/http/tests/site-isolation/inspector/debugger/pause-holds-cross-process-frames.html: Added. * Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml: * Source/WebCore/Headers.cmake: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/inspector/DebuggerPauseSessionIdentifier.h: Added. * Source/WebCore/inspector/DebuggerSuspensionController.cpp: (WebCore::pausedPage): (WebCore::DebuggerSuspensionController::frameDebuggerDidPause): (WebCore::DebuggerSuspensionController::frameDebuggerDidContinue): (WebCore::DebuggerSuspensionController::addSessionHold): (WebCore::DebuggerSuspensionController::removeSessionHold): (WebCore::DebuggerSuspensionController::shouldHoldDocuments const): * Source/WebCore/inspector/DebuggerSuspensionController.h: * Source/WebCore/inspector/FrameDebugger.cpp: (WebCore::FrameDebugger::didPause): * Source/WebCore/inspector/InspectorBackendClient.h: (WebCore::InspectorBackendClient::frameDebuggerDidPause): (WebCore::InspectorBackendClient::frameDebuggerDidContinue): * Source/WebCore/inspector/PageInspectorController.cpp: (WebCore::PageInspectorController::suspendForDebuggerSession): (WebCore::PageInspectorController::resumeFromDebuggerSession): * Source/WebCore/inspector/PageInspectorController.h: * Source/WebKit/Scripts/webkit/messages.py: (serialized_identifiers): * Source/WebKit/Scripts/webkit/tests/MessageArgumentDescriptions.cpp: (IPC::serializedIdentifiers): * Source/WebKit/Shared/WTFArgumentCoders.serialization.in: * Source/WebKit/Sources.txt: * Source/WebKit/UIProcess/Inspector/DebuggerPauseCoordinator.cpp: Added. (WebKit::DebuggerPauseCoordinator::DebuggerPauseCoordinator): (WebKit::DebuggerPauseCoordinator::~DebuggerPauseCoordinator): (WebKit::DebuggerPauseCoordinator::frameDidPause): (WebKit::DebuggerPauseCoordinator::frameDidContinue): (WebKit::DebuggerPauseCoordinator::openSession): (WebKit::DebuggerPauseCoordinator::closeSession): * Source/WebKit/UIProcess/Inspector/DebuggerPauseCoordinator.h: Added. * Source/WebKit/UIProcess/Inspector/WebPageInspectorController.cpp: (WebKit::WebPageInspectorController::hasFrontends const): (WebKit::WebPageInspectorController::disconnectFrontend): (WebKit::WebPageInspectorController::disconnectAllFrontends): * Source/WebKit/UIProcess/Inspector/WebPageInspectorController.h: * Source/WebKit/UIProcess/ProvisionalPageProxy.cpp: (WebKit::ProvisionalPageProxy::didReceiveMessage): * Source/WebKit/UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::close): (WebKit::WebPageProxy::frameDidPauseForDebugger): (WebKit::WebPageProxy::frameDidContinueForDebugger): (WebKit::WebPageProxy::lastInspectorFrontendDidDisconnect): * Source/WebKit/UIProcess/WebPageProxy.h: * Source/WebKit/UIProcess/WebPageProxy.messages.in: * Source/WebKit/WebKit.xcodeproj/project.pbxproj: * Source/WebKit/WebProcess/Inspector/WebInspectorBackend.cpp: (WebKit::WebInspectorBackend::suspendForDebugger): (WebKit::WebInspectorBackend::resumeFromDebugger): * Source/WebKit/WebProcess/Inspector/WebInspectorBackend.h: * Source/WebKit/WebProcess/Inspector/WebInspectorBackend.messages.in: * Source/WebKit/WebProcess/Inspector/WebInspectorBackendClient.cpp: (WebKit::WebInspectorBackendClient::frameDebuggerDidPause): (WebKit::WebInspectorBackendClient::frameDebuggerDidContinue): * Source/WebKit/WebProcess/Inspector/WebInspectorBackendClient.h: Canonical link: https://commits.webkit.org/323835@main
1 parent f3e9b7e commit 797f26e

32 files changed

Lines changed: 545 additions & 4 deletions
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Test that pausing a frame does not hold frames in other processes when the global debugger pause preference is off.
2+
3+
4+
5+
== Running test suite: SiteIsolation.Debugger.PauseHoldsCrossProcessFramesDisabled
6+
-- Running test case: SiteIsolation.Debugger.PauseHoldsCrossProcessFramesDisabled.PauseMainFrame
7+
PASS: The cross-site frame's interval should be running.
8+
PASS: The cross-site frame's interval should keep advancing while the main frame is paused.
9+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!-- webkit-test-runner [ SiteIsolationEnabled=true SiteIsolationGlobalDebuggerPauseEnabled=false ] -->
2+
<script src="../../../inspector/resources/inspector-test.js"></script>
3+
<script src="resources/site-isolation-debugger-test-utilities.js"></script>
4+
<script>
5+
function pauseHere()
6+
{
7+
debugger;
8+
return "resumed";
9+
}
10+
11+
function test() {
12+
let suite = InspectorTest.createAsyncSuite("SiteIsolation.Debugger.PauseHoldsCrossProcessFramesDisabled");
13+
14+
let crossProcessTarget;
15+
16+
function sleep(ms) {
17+
return new Promise((resolve) => setTimeout(resolve, ms));
18+
}
19+
20+
async function evaluate(target, expression) {
21+
let {result} = await target.RuntimeAgent.evaluate.invoke({expression, objectGroup: "test", returnByValue: true});
22+
return result.value;
23+
}
24+
25+
suite.addTestCase({
26+
name: "SiteIsolation.Debugger.PauseHoldsCrossProcessFramesDisabled.PauseMainFrame",
27+
description: "Without the preference, pausing the main frame should not hold a cross-site frame in another process.",
28+
async test() {
29+
let mainTarget = InspectorTest.mainFrameTarget;
30+
crossProcessTarget = await frameTargetForURLContaining("same-process-frame.html?X");
31+
InspectorTest.expectThat(await waitForExpressionInTarget(crossProcessTarget, "window.ticks > 2"), "The cross-site frame's interval should be running.");
32+
33+
let paused = WI.debuggerManager.awaitEvent(WI.DebuggerManager.Event.Paused);
34+
mainTarget.RuntimeAgent.evaluate.invoke({expression: "pauseHere()", objectGroup: "test"}).catch(() => { });
35+
await paused;
36+
37+
let before = await evaluate(crossProcessTarget, "window.ticks");
38+
InspectorTest.expectThat(await waitForExpressionInTarget(crossProcessTarget, `window.ticks > ${before}`), "The cross-site frame's interval should keep advancing while the main frame is paused.");
39+
40+
let resumed = WI.debuggerManager.awaitEvent(WI.DebuggerManager.Event.Resumed);
41+
await WI.debuggerManager.resume();
42+
await resumed;
43+
}
44+
});
45+
46+
suite.runTestCasesAndFinish();
47+
}
48+
</script>
49+
50+
<body onload="runTest()">
51+
<p>Test that pausing a frame does not hold frames in other processes when the global debugger pause preference is off.</p>
52+
<iframe src="http://localhost:8000/site-isolation/inspector/debugger/resources/same-process-frame.html?X"></iframe>
53+
</body>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Test that pausing a frame holds the frames of the same page in other processes until resuming.
2+
3+
4+
5+
== Running test suite: SiteIsolation.Debugger.PauseHoldsCrossProcessFrames
6+
-- Running test case: SiteIsolation.Debugger.PauseHoldsCrossProcessFrames.Setup
7+
PASS: Should find the cross-site frame target.
8+
PASS: The cross-site frame's interval should be running.
9+
10+
-- Running test case: SiteIsolation.Debugger.PauseHoldsCrossProcessFrames.PauseMainFrame
11+
PASS: The cross-site frame's interval should not advance while a frame in another process is paused.
12+
PASS: The cross-site frame's interval should advance after resuming.
13+
14+
-- Running test case: SiteIsolation.Debugger.PauseHoldsCrossProcessFrames.PauseCrossSiteFrame
15+
PASS: The main frame's interval should not advance while a frame in another process is paused.
16+
PASS: The main frame's interval should advance after resuming.
17+
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<!-- webkit-test-runner [ SiteIsolationEnabled=true SiteIsolationGlobalDebuggerPauseEnabled=true ] -->
2+
<script src="../../../inspector/resources/inspector-test.js"></script>
3+
<script src="resources/site-isolation-debugger-test-utilities.js"></script>
4+
<script>
5+
window.mainTicks = 0;
6+
setInterval(() => { window.mainTicks++; }, 50);
7+
8+
function pauseHere()
9+
{
10+
debugger;
11+
return "resumed";
12+
}
13+
14+
function test() {
15+
let suite = InspectorTest.createAsyncSuite("SiteIsolation.Debugger.PauseHoldsCrossProcessFrames");
16+
17+
let mainTarget;
18+
let crossProcessTarget;
19+
20+
function sleep(ms) {
21+
return new Promise((resolve) => setTimeout(resolve, ms));
22+
}
23+
24+
async function evaluate(target, expression) {
25+
let {result} = await target.RuntimeAgent.evaluate.invoke({expression, objectGroup: "test", returnByValue: true});
26+
return result.value;
27+
}
28+
29+
async function pause(target) {
30+
let paused = new Promise((resolve) => {
31+
let listener = WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.CallFramesDidChange, (event) => {
32+
if (event.data.target !== target || !WI.debuggerManager.dataForTarget(target).paused)
33+
return;
34+
WI.debuggerManager.removeEventListener(WI.DebuggerManager.Event.CallFramesDidChange, listener);
35+
resolve();
36+
});
37+
});
38+
target.RuntimeAgent.evaluate.invoke({expression: "pauseHere()", objectGroup: "test"}).catch(() => { });
39+
await paused;
40+
}
41+
42+
async function expectHeld(target, counter, description) {
43+
let before = await evaluate(target, counter);
44+
await sleep(300);
45+
InspectorTest.expectEqual(await evaluate(target, counter), before, `${description} should not advance while a frame in another process is paused.`);
46+
return before;
47+
}
48+
49+
async function resumeAndExpectRunning(target, counter, before, description) {
50+
let resumed = WI.debuggerManager.awaitEvent(WI.DebuggerManager.Event.Resumed);
51+
await WI.debuggerManager.resume();
52+
await resumed;
53+
InspectorTest.expectThat(await waitForExpressionInTarget(target, `${counter} > ${before}`), `${description} should advance after resuming.`);
54+
}
55+
56+
suite.addTestCase({
57+
name: "SiteIsolation.Debugger.PauseHoldsCrossProcessFrames.Setup",
58+
description: "Find the frame target of a cross-site iframe, which runs in another process.",
59+
async test() {
60+
mainTarget = InspectorTest.mainFrameTarget;
61+
crossProcessTarget = await frameTargetForURLContaining("same-process-frame.html?X");
62+
InspectorTest.expectNotNull(crossProcessTarget, "Should find the cross-site frame target.");
63+
InspectorTest.expectThat(await waitForExpressionInTarget(crossProcessTarget, "window.ticks > 2"), "The cross-site frame's interval should be running.");
64+
}
65+
});
66+
67+
suite.addTestCase({
68+
name: "SiteIsolation.Debugger.PauseHoldsCrossProcessFrames.PauseMainFrame",
69+
description: "Pausing the main frame should hold the cross-site frame until resuming.",
70+
async test() {
71+
await pause(mainTarget);
72+
let before = await expectHeld(crossProcessTarget, "window.ticks", "The cross-site frame's interval");
73+
await resumeAndExpectRunning(crossProcessTarget, "window.ticks", before, "The cross-site frame's interval");
74+
}
75+
});
76+
77+
suite.addTestCase({
78+
name: "SiteIsolation.Debugger.PauseHoldsCrossProcessFrames.PauseCrossSiteFrame",
79+
description: "Pausing the cross-site frame should hold the main frame until resuming.",
80+
async test() {
81+
await pause(crossProcessTarget);
82+
let before = await expectHeld(mainTarget, "window.mainTicks", "The main frame's interval");
83+
await resumeAndExpectRunning(mainTarget, "window.mainTicks", before, "The main frame's interval");
84+
}
85+
});
86+
87+
suite.runTestCasesAndFinish();
88+
}
89+
</script>
90+
91+
<body onload="runTest()">
92+
<p>Test that pausing a frame holds the frames of the same page in other processes until resuming.</p>
93+
<iframe src="http://localhost:8000/site-isolation/inspector/debugger/resources/same-process-frame.html?X"></iframe>
94+
</body>

‎Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5860,6 +5860,14 @@ SiteIsolationEnabled:
58605860
defaultValue: false
58615861
sharedPreferenceForWebProcess: true
58625862

5863+
SiteIsolationGlobalDebuggerPauseEnabled:
5864+
type: bool
5865+
status: unstable
5866+
category: security
5867+
humanReadableName: "Site Isolation: hold all frames while debugging"
5868+
humanReadableDescription: "While Web Inspector is paused in a frame, hold the frames of the same page in other processes"
5869+
defaultValue: false
5870+
58635871
SiteIsolationHighValueFraudTargetDomainsEnabled:
58645872
type: bool
58655873
status: unstable

‎Source/WebCore/Headers.cmake‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
17641764
html/track/WebVTTParser.h
17651765

17661766
inspector/CommandLineAPIHost.h
1767+
inspector/DebuggerPauseSessionIdentifier.h
17671768
inspector/FrameInspectorController.h
17681769
inspector/InspectorBackendClient.h
17691770
inspector/InspectorDebuggableType.h

‎Source/WebCore/WebCore.xcodeproj/project.pbxproj‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7604,6 +7604,7 @@
76047604
4A3A479BAB413F796EF38438 /* ProofOfPossessionCredential.h in Headers */ = {isa = PBXBuildFile; fileRef = F6EF1185B9BFEAED5D815C1E /* ProofOfPossessionCredential.h */; };
76057605
A4C507AADDFB428EA96A5E75 /* FrameIndexedDBAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = D4D9D4D70C1F40D88DBFCA80 /* FrameIndexedDBAgent.h */; };
76067606
B1EA5351EAA94AFA936F8771 /* PageIndexedDBAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = E3F630DF69544CEA9A7BE1E2 /* PageIndexedDBAgent.h */; };
7607+
63CF7B735BFB48D09CC3FA61 /* DebuggerPauseSessionIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 8673CA88C6A741C6B689B59A /* DebuggerPauseSessionIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
76077608
/* End PBXBuildFile section */
76087609

76097610
/* Begin PBXBuildRule section */
@@ -24330,6 +24331,7 @@
2433024331
0970201322E546E9A5B1334A /* FrameIndexedDBAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FrameIndexedDBAgent.cpp; sourceTree = "<group>"; };
2433124332
E3F630DF69544CEA9A7BE1E2 /* PageIndexedDBAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PageIndexedDBAgent.h; sourceTree = "<group>"; };
2433224333
9E05DE2045A04C30A1A879F9 /* PageIndexedDBAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PageIndexedDBAgent.cpp; sourceTree = "<group>"; };
24334+
8673CA88C6A741C6B689B59A /* DebuggerPauseSessionIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebuggerPauseSessionIdentifier.h; sourceTree = "<group>"; };
2433324335
/* End PBXFileReference section */
2433424336

2433524337
/* Begin PBXFrameworksBuildPhase section */
@@ -26575,6 +26577,7 @@
2657526577
A584FE291863870F00843B10 /* CommandLineAPIModule.cpp */,
2657626578
A584FE2A1863870F00843B10 /* CommandLineAPIModule.h */,
2657726579
A584FE2718637DCA00843B10 /* CommandLineAPIModuleSource.js */,
26580+
8673CA88C6A741C6B689B59A /* DebuggerPauseSessionIdentifier.h */,
2657826581
2EA33ABA0CA84C378492C732 /* DebuggerSuspensionController.cpp */,
2657926582
E1DEC3457E95468589B6727B /* DebuggerSuspensionController.h */,
2658026583
7AABA25714BC613300AA9A11 /* DOMEditor.cpp */,
@@ -45673,6 +45676,7 @@
4567345676
F55B3DBA1251F12D003EF269 /* DateTimeLocalInputType.h in Headers */,
4567445677
E5F06AEB24D49BF700BBC4F8 /* DateTimeNumericFieldElement.h in Headers */,
4567545678
E5F06AEF24D4A63700BBC4F8 /* DateTimeSymbolicFieldElement.h in Headers */,
45679+
63CF7B735BFB48D09CC3FA61 /* DebuggerPauseSessionIdentifier.h in Headers */,
4567645680
86721D4F7D1D46A6B80B9F9A /* DebuggerSuspensionController.h in Headers */,
4567745681
BC4A532D256056D50028C592 /* DebugOverlayRegions.h in Headers */,
4567845682
0F6A12BE1A00923700C6DE72 /* DebugPageOverlays.h in Headers */,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) 2026 Apple Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#pragma once
27+
28+
#include <wtf/ObjectIdentifier.h>
29+
30+
namespace WebCore {
31+
32+
struct DebuggerPauseSessionIdentifierType;
33+
using DebuggerPauseSessionIdentifier = ObjectIdentifier<DebuggerPauseSessionIdentifierType>;
34+
35+
} // namespace WebCore

‎Source/WebCore/inspector/DebuggerSuspensionController.cpp‎

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@
2828

2929
#include "ActiveDOMObject.h"
3030
#include "Document.h"
31+
#include "DocumentPage.h"
3132
#include "FrameDestructionObserverInlines.h"
33+
#include "InspectorBackendClient.h"
3234
#include "LocalFrame.h"
3335
#include "LocalFrameInlines.h"
3436
#include "Page.h"
3537
#include "PageInspectorController.h"
3638
#include "ScriptController.h"
39+
#include "Settings.h"
40+
#include <wtf/NeverDestroyed.h>
3741
#include <wtf/TZoneMallocInlines.h>
3842

3943
namespace WebCore {
@@ -42,25 +46,64 @@ WTF_MAKE_TZONE_ALLOCATED_IMPL(DebuggerSuspensionController);
4246

4347
static bool s_isFrameDebuggerPaused;
4448

49+
// The paused frame may be detached by the time the pause ends, so remember its page and identifier for the end-of-pause notification.
50+
static WeakPtr<Page>& pausedPage()
51+
{
52+
static NeverDestroyed<WeakPtr<Page>> page;
53+
return page;
54+
}
55+
56+
static std::optional<FrameIdentifier> s_pausedFrameID;
57+
4558
DebuggerSuspensionController::DebuggerSuspensionController(Page& page)
4659
: m_page(page)
4760
{
4861
}
4962

5063
DebuggerSuspensionController::~DebuggerSuspensionController() = default;
5164

52-
void DebuggerSuspensionController::frameDebuggerDidPause()
65+
void DebuggerSuspensionController::frameDebuggerDidPause(LocalFrame& frame)
5366
{
5467
ASSERT(!s_isFrameDebuggerPaused);
5568
s_isFrameDebuggerPaused = true;
5669
updateHeldDocumentsInAllPages();
70+
71+
RefPtr page = frame.page();
72+
if (!page || !page->settings().siteIsolationGlobalDebuggerPauseEnabled())
73+
return;
74+
75+
pausedPage() = page.get();
76+
s_pausedFrameID = frame.frameID();
77+
if (auto* client = page->inspectorController().inspectorBackendClient())
78+
client->frameDebuggerDidPause(frame.frameID());
5779
}
5880

5981
void DebuggerSuspensionController::frameDebuggerDidContinue()
6082
{
6183
ASSERT(s_isFrameDebuggerPaused);
6284
s_isFrameDebuggerPaused = false;
6385
updateHeldDocumentsInAllPages();
86+
87+
RefPtr page = std::exchange(pausedPage(), nullptr).get();
88+
auto frameID = std::exchange(s_pausedFrameID, std::nullopt);
89+
if (page && frameID) {
90+
if (auto* client = page->inspectorController().inspectorBackendClient())
91+
client->frameDebuggerDidContinue(*frameID);
92+
}
93+
}
94+
95+
void DebuggerSuspensionController::addSessionHold(DebuggerPauseSessionIdentifier sessionID)
96+
{
97+
if (!m_sessionHolds.add(sessionID).isNewEntry)
98+
return;
99+
updateHeldDocuments();
100+
}
101+
102+
void DebuggerSuspensionController::removeSessionHold(DebuggerPauseSessionIdentifier sessionID)
103+
{
104+
if (!m_sessionHolds.remove(sessionID))
105+
return;
106+
updateHeldDocuments();
64107
}
65108

66109
void DebuggerSuspensionController::updateHeldDocumentsInAllPages()
@@ -78,7 +121,7 @@ void DebuggerSuspensionController::documentDidBecomeCurrent(Document& document)
78121

79122
bool DebuggerSuspensionController::shouldHoldDocuments() const
80123
{
81-
return s_isFrameDebuggerPaused;
124+
return s_isFrameDebuggerPaused || !m_sessionHolds.isEmpty();
82125
}
83126

84127
void DebuggerSuspensionController::updateHeldDocuments()

‎Source/WebCore/inspector/DebuggerSuspensionController.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525

2626
#pragma once
2727

28+
#include "DebuggerPauseSessionIdentifier.h"
2829
#include <wtf/CheckedPtr.h>
30+
#include <wtf/HashSet.h>
2931
#include <wtf/Noncopyable.h>
3032
#include <wtf/TZoneMalloc.h>
3133
#include <wtf/WeakHashSet.h>
@@ -48,9 +50,12 @@ class DebuggerSuspensionController final : public CanMakeCheckedPtr<DebuggerSusp
4850

4951
// A paused FrameDebugger holds every page in the process, not only its own: pages in one process share the
5052
// main thread, and related pages (an opener and its popup) can call into each other synchronously.
51-
static void frameDebuggerDidPause();
53+
static void frameDebuggerDidPause(LocalFrame&);
5254
static void frameDebuggerDidContinue();
5355

56+
void addSessionHold(DebuggerPauseSessionIdentifier);
57+
void removeSessionHold(DebuggerPauseSessionIdentifier);
58+
5459
void documentDidBecomeCurrent(Document&);
5560

5661
private:
@@ -64,6 +69,7 @@ class DebuggerSuspensionController final : public CanMakeCheckedPtr<DebuggerSusp
6469
WeakRef<Page> m_page;
6570
WeakHashSet<Document, WeakPtrImplWithEventTargetData> m_heldDocuments;
6671
WeakHashSet<LocalFrame> m_pausedFrames;
72+
HashSet<DebuggerPauseSessionIdentifier> m_sessionHolds;
6773
};
6874

6975
} // namespace WebCore

0 commit comments

Comments
 (0)