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( ...@@ -1279,6 +1279,7 @@ void RenderFrameHostImpl::OnPortalActivated(
break; break;
case blink::mojom::PortalActivateResult:: case blink::mojom::PortalActivateResult::
kRejectedDueToPredecessorNavigation: kRejectedDueToPredecessorNavigation:
case blink::mojom::PortalActivateResult::kDisconnected:
case blink::mojom::PortalActivateResult::kAbortedDueToBug: case blink::mojom::PortalActivateResult::kAbortedDueToBug:
// The renderer is misbehaving. // The renderer is misbehaving.
mojo::ReportBadMessage( mojo::ReportBadMessage(
......
...@@ -23,6 +23,11 @@ enum PortalActivateResult { ...@@ -23,6 +23,11 @@ enum PortalActivateResult {
// navigating and the navigation could not be cancelled. // navigating and the navigation could not be cancelled.
kRejectedDueToPredecessorNavigation, 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 // 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 // a nonsensical reply from the other renderer. This should never happen; it
// is always an indication of a bug if it does. // is always an indication of a bug if it does.
......
...@@ -33,7 +33,7 @@ PortalContents::PortalContents( ...@@ -33,7 +33,7 @@ PortalContents::PortalContents(
remote_portal_(std::move(remote_portal)), remote_portal_(std::move(remote_portal)),
portal_client_receiver_(this, std::move(portal_client_receiver)) { portal_client_receiver_(this, std::move(portal_client_receiver)) {
remote_portal_.set_disconnect_handler( remote_portal_.set_disconnect_handler(
WTF::Bind(&PortalContents::Destroy, WrapWeakPersistent(this))); WTF::Bind(&PortalContents::DisconnectHandler, WrapWeakPersistent(this)));
DocumentPortals::From(GetDocument()).RegisterPortalContents(this); DocumentPortals::From(GetDocument()).RegisterPortalContents(this);
} }
...@@ -100,6 +100,11 @@ void PortalContents::OnActivateResponse( ...@@ -100,6 +100,11 @@ void PortalContents::OnActivateResponse(
} }
break; 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: case mojom::blink::PortalActivateResult::kAbortedDueToBug:
// This should never happen. Ignore this and wait for the frame to be // This should never happen. Ignore this and wait for the frame to be
// discarded by the browser, if it hasn't already. // discarded by the browser, if it hasn't already.
...@@ -172,6 +177,12 @@ void PortalContents::Destroy() { ...@@ -172,6 +177,12 @@ void PortalContents::Destroy() {
DocumentPortals::From(GetDocument()).DeregisterPortalContents(this); DocumentPortals::From(GetDocument()).DeregisterPortalContents(this);
} }
void PortalContents::DisconnectHandler() {
if (IsActivating())
OnActivateResponse(mojom::blink::PortalActivateResult::kDisconnected);
Destroy();
}
void PortalContents::ForwardMessageFromGuest( void PortalContents::ForwardMessageFromGuest(
BlinkTransferableMessage message, BlinkTransferableMessage message,
const scoped_refptr<const SecurityOrigin>& source_origin, const scoped_refptr<const SecurityOrigin>& source_origin,
......
...@@ -79,6 +79,10 @@ class PortalContents : public GarbageCollected<PortalContents>, ...@@ -79,6 +79,10 @@ class PortalContents : public GarbageCollected<PortalContents>,
// down. // down.
void Destroy(); 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 // blink::mojom::PortalClient implementation
void ForwardMessageFromGuest( void ForwardMessageFromGuest(
BlinkTransferableMessage message, BlinkTransferableMessage message,
......
...@@ -4,17 +4,12 @@ ...@@ -4,17 +4,12 @@
<script src="/portals/resources/open-blank-host.js"></script> <script src="/portals/resources/open-blank-host.js"></script>
<body> <body>
<script> <script>
function createPortal(doc, src, channel) { async function createPortal(doc, src) {
var portal = doc.createElement("portal"); var portal = doc.createElement("portal");
portal.src = new URL(src, location.href); portal.src = new URL(src, location.href);
return new Promise((resolve, reject) => { doc.body.appendChild(portal);
var bc = new BroadcastChannel(channel); await new Promise(r => portal.onload = r);
bc.onmessage = () => { return portal;
bc.close();
resolve(portal);
}
doc.body.appendChild(portal);
});
} }
promise_test(async () => { promise_test(async () => {
...@@ -24,7 +19,7 @@ ...@@ -24,7 +19,7 @@
"resources/portals-create-orphaned-portal.html", "resources/portals-create-orphaned-portal.html",
"create-orphaned-portal"); "create-orphaned-portal");
portal.activate(); 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"); }, "creating a portal from an orphaned portal should succeed");
</script> </script>
</body> </body>
...@@ -5,7 +5,4 @@ ...@@ -5,7 +5,4 @@
// works if we create portals in a separate process. // works if we create portals in a separate process.
while (true) {} while (true) {}
} }
var bc = new BroadcastChannel("create-orphaned-portal");
bc.postMessage("loaded");
bc.close();
</script> </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