Commit c778bc4a authored by Adithya Srinivasan's avatar Adithya Srinivasan Committed by Commit Bot

Portals: Detach pending activation promise after disconnection

This should fix an existing issue where a DCHECK is hit when the
test runner/browser is being torn down. Also cleans up
portals-create-orphaned.html.

Bug: 1018940
Change-Id: I35d1a842923e7302b308b57856e4c165bd07bd6b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2007473Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Commit-Queue: Adithya Srinivasan <adithyas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733038}
parent 10c8b121
......@@ -1279,6 +1279,7 @@ void RenderFrameHostImpl::OnPortalActivated(
break;
case blink::mojom::PortalActivateResult::
kRejectedDueToPredecessorNavigation:
case blink::mojom::PortalActivateResult::kDisconnected:
case blink::mojom::PortalActivateResult::kAbortedDueToBug:
// The renderer is misbehaving.
mojo::ReportBadMessage(
......
......@@ -23,6 +23,11 @@ enum PortalActivateResult {
// navigating and the navigation could not be cancelled.
kRejectedDueToPredecessorNavigation,
// The connection with the remote was closed (usually happens during a
// browser shutdown). This error code is never sent as an IPC response, but
// is synthesized by the renderer.
kDisconnected,
// The activation was attempted but was aborted due to a logic error, such as
// a nonsensical reply from the other renderer. This should never happen; it
// is always an indication of a bug if it does.
......
......@@ -33,7 +33,7 @@ PortalContents::PortalContents(
remote_portal_(std::move(remote_portal)),
portal_client_receiver_(this, std::move(portal_client_receiver)) {
remote_portal_.set_disconnect_handler(
WTF::Bind(&PortalContents::Destroy, WrapWeakPersistent(this)));
WTF::Bind(&PortalContents::DisconnectHandler, WrapWeakPersistent(this)));
DocumentPortals::From(GetDocument()).RegisterPortalContents(this);
}
......@@ -100,6 +100,11 @@ void PortalContents::OnActivateResponse(
}
break;
}
case mojom::blink::PortalActivateResult::kDisconnected:
// Only called when |remote_portal_| is disconnected. This usually happens
// when the browser/test runner is being shut down.
activate_resolver_->Detach();
break;
case mojom::blink::PortalActivateResult::kAbortedDueToBug:
// This should never happen. Ignore this and wait for the frame to be
// discarded by the browser, if it hasn't already.
......@@ -172,6 +177,12 @@ void PortalContents::Destroy() {
DocumentPortals::From(GetDocument()).DeregisterPortalContents(this);
}
void PortalContents::DisconnectHandler() {
if (IsActivating())
OnActivateResponse(mojom::blink::PortalActivateResult::kDisconnected);
Destroy();
}
void PortalContents::ForwardMessageFromGuest(
BlinkTransferableMessage message,
const scoped_refptr<const SecurityOrigin>& source_origin,
......
......@@ -79,6 +79,10 @@ class PortalContents : public GarbageCollected<PortalContents>,
// down.
void Destroy();
// Called when the connection to the browser-side Portal object is lost.
// Cleans up any remaining state.
void DisconnectHandler();
// blink::mojom::PortalClient implementation
void ForwardMessageFromGuest(
BlinkTransferableMessage message,
......
......@@ -4,17 +4,12 @@
<script src="/portals/resources/open-blank-host.js"></script>
<body>
<script>
function createPortal(doc, src, channel) {
async function createPortal(doc, src) {
var portal = doc.createElement("portal");
portal.src = new URL(src, location.href);
return new Promise((resolve, reject) => {
var bc = new BroadcastChannel(channel);
bc.onmessage = () => {
bc.close();
resolve(portal);
}
doc.body.appendChild(portal);
});
doc.body.appendChild(portal);
await new Promise(r => portal.onload = r);
return portal;
}
promise_test(async () => {
......@@ -24,7 +19,7 @@
"resources/portals-create-orphaned-portal.html",
"create-orphaned-portal");
portal.activate();
return createPortal(doc, "resources/simple-portal.html", "simple-portal");
await createPortal(doc, "resources/simple-portal.html");
}, "creating a portal from an orphaned portal should succeed");
</script>
</body>
......@@ -5,7 +5,4 @@
// works if we create portals in a separate process.
while (true) {}
}
var bc = new BroadcastChannel("create-orphaned-portal");
bc.postMessage("loaded");
bc.close();
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment