Commit 81ed908b authored by Adithya Srinivasan's avatar Adithya Srinivasan Committed by Commit Bot

Portals: Hide portal host before dispatching activate event

window.portalHost returns null in the portal browsing context after it
has been activated.

Bug: 914117
Change-Id: I2758d2bb29ad0381cff51f0c312fa88c3bacaed4
Reviewed-on: https://chromium-review.googlesource.com/c/1412792
Commit-Queue: Adithya Srinivasan <adithyas@chromium.org>
Reviewed-by: default avatarLucas Gadani <lfg@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#628378}
parent 56e0205a
...@@ -2517,6 +2517,7 @@ void WebLocalFrameImpl::PerformMediaPlayerAction( ...@@ -2517,6 +2517,7 @@ void WebLocalFrameImpl::PerformMediaPlayerAction(
} }
void WebLocalFrameImpl::OnPortalActivated() { void WebLocalFrameImpl::OnPortalActivated() {
GetFrame()->GetPage()->SetInsidePortal(false);
PortalActivateEvent* event = PortalActivateEvent::Create(); PortalActivateEvent* event = PortalActivateEvent::Create();
GetFrame()->DomWindow()->DispatchEvent(*event); GetFrame()->DomWindow()->DispatchEvent(*event);
} }
......
...@@ -4,29 +4,35 @@ ...@@ -4,29 +4,35 @@
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script> <script>
async_test(function(t) { async_test(function(t) {
var bc = new BroadcastChannel("test-eventlistener"); let test = "eventlistener";
var bc = new BroadcastChannel(`test-${test}`);
bc.onmessage = t.step_func_done(function(e) { bc.onmessage = t.step_func_done(function(e) {
assert_equals(e.data, "passed"); assert_equals(e.data, "passed");
bc.close(); bc.close();
}); });
window.open("resources/portal-activate-event-window.html?test=eventlistener"); const portalUrl = encodeURIComponent(`portal-activate-event-portal.html?test=${test}`);
window.open(`resources/portal-embed-and-activate.html?url=${portalUrl}&channelName=portal-${test}`);
}, "Tests that the PortalActivateEvent is dispatched when a portal is activated."); }, "Tests that the PortalActivateEvent is dispatched when a portal is activated.");
async_test(function(t) { async_test(function(t) {
var bc = new BroadcastChannel("test-eventhandler"); let test = "eventhandler";
var bc = new BroadcastChannel(`test-${test}`);
bc.onmessage = t.step_func_done(function(e) { bc.onmessage = t.step_func_done(function(e) {
assert_equals(e.data, "passed"); assert_equals(e.data, "passed");
bc.close(); bc.close();
}); });
window.open("resources/portal-activate-event-window.html?test=eventhandler"); const portalUrl = encodeURIComponent(`portal-activate-event-portal.html?test=${test}`);
window.open(`resources/portal-embed-and-activate.html?url=${portalUrl}&channelName=portal-${test}`);
}, "Tests that the portalactivate event handler is dispatched when a portal is activated."); }, "Tests that the portalactivate event handler is dispatched when a portal is activated.");
async_test(function(t) { async_test(function(t) {
var bc = new BroadcastChannel("test-bodyeventhandler"); let test = "bodyeventhandler";
var bc = new BroadcastChannel(`test-${test}`);
bc.onmessage = t.step_func_done(function(e) { bc.onmessage = t.step_func_done(function(e) {
assert_equals(e.data, "passed"); assert_equals(e.data, "passed");
bc.close(); bc.close();
}); });
window.open("resources/portal-activate-event-window.html?test=bodyeventhandler"); const portalUrl = encodeURIComponent(`portal-activate-event-portal.html?test=${test}`);
window.open(`resources/portal-embed-and-activate.html?url=${portalUrl}&channelName=portal-${test}`);
}, "Tests that the HTMLBodyElement has the portalactivate event handler."); }, "Tests that the HTMLBodyElement has the portalactivate event handler.");
</script> </script>
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
// Waits for 2 messages from portal, one before activation and one after.
function waitForMessages() {
return new Promise((resolve, reject) => {
var results = [];
var bc = new BroadcastChannel("portals-host-hidden-after-activation");
bc.onmessage = e => {
results.push(e.data.hasHost);
if (results.length == 2) {
bc.close();
resolve(results);
}
};
});
}
promise_test(async () => {
const portalUrl = encodeURIComponent("portal-host-hidden-after-activation-portal.html");
window.open(`resources/portal-embed-and-activate.html?url=${portalUrl}`);
var results = await waitForMessages();
assert_true(results[0], "portalHost exposed before calling activate()");
assert_false(results[1], "portalHost hidden after receiving portalactivate event");
}, "window.portalHost should be null after portal is activated");
</script>
</body>
<!DOCTYPE html>
<script>
window.onload = function(e) {
var test = (new URL(location)).searchParams.get("test");
var portal = document.createElement("portal");
portal.src = "portal-activate-event-portal.html" + location.search;
document.body.appendChild(portal);
var bc = new BroadcastChannel("portal-" + test);
bc.onmessage = function(e) {
document.querySelector("portal").activate();
bc.close();
}
}
</script>
<body>
</body>
<!DOCTYPE html>
<!--
Embeds a portal (src specified by query parameter "url") and activates it after
receiving a message from the portal. Use query parameter "channelName" to
specify the name of the channel used by the portal src send a message
indicating that it is ready for activation (default name used is "portal").
-->
</title>
<body>
<script>
var searchParams = new URL(location).searchParams;
// TODO(adithyas): Replace this with postmessage once it's implemented for
// portals.
var channelName = searchParams.get("channelName") || "portal";
var bc = new BroadcastChannel(channelName);
bc.onmessage = function(e) {
document.querySelector("portal").activate();
bc.close();
}
let portal = document.createElement("portal");
portal.src = searchParams.get("url");
document.body.appendChild(portal);
</script>
</body>
<!DOCTYPE html>
<script>
window.addEventListener("portalactivate", function(e) {
var bc = new BroadcastChannel("portals-host-hidden-after-activation");
bc.postMessage({ hasHost: !!window.portalHost });
bc.close();
});
var bc = new BroadcastChannel("portals-host-hidden-after-activation");
bc.postMessage({hasHost: !!window.portalHost });
bc.close();
bc = new BroadcastChannel("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