Skip to content

Commit

Permalink
Portals: Support adoption of the predecessor.
Browse files Browse the repository at this point in the history
This CL adds support for an activated portal to adopt its predecessor
as a portal. Adopting the predecessor enables developers to quickly
transition back and forth between different pages.

Bug: 914122

Change-Id: I80381017ddb774da20ae07efcba2f4fee733fc3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1456869
Commit-Queue: Lucas Gadani <lfg@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Jeremy Roman <jbroman@chromium.org>
Reviewed-by: Charlie Reis <creis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#643463}
  • Loading branch information
lucasgadani authored and Marcos Cáceres committed Jul 23, 2019
1 parent 1cf5241 commit f13bccf
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
14 changes: 14 additions & 0 deletions portals/portals-adopt-predecessor.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<title>Tests that a portal can adopt its predecessor</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
async_test(function(t) {
var bc = new BroadcastChannel("portal-test");
bc.onmessage = t.step_func_done(function(e) {
assert_equals(e.data, "passed");
bc.close();
});
window.open("resources/portals-adopt-predecessor.html");
}, "Tests that a portal can adopt its predecessor.");
</script>
17 changes: 17 additions & 0 deletions portals/resources/portals-adopt-predecessor-portal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<script>
window.onportalactivate = function(e) {
var portal = e.adoptPredecessor();
document.body.appendChild(portal);

if (portal instanceof HTMLPortalElement) {
var bc_adopted = new BroadcastChannel("portal-adopted");
bc_adopted.postMessage("adopted");
bc_adopted.close();
}
}

var bc_loaded = new BroadcastChannel("portal-loaded");
bc_loaded.postMessage("loaded");
bc_loaded.close();
</script>
20 changes: 20 additions & 0 deletions portals/resources/portals-adopt-predecessor.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<body>
<portal src="portals-adopt-predecessor-portal.html"></portal>
</body>
<script>
var bc_loaded = new BroadcastChannel("portal-loaded");
bc_loaded.onmessage = function(e) {
document.querySelector("portal").activate();
bc_loaded.close();

var bc_adopted = new BroadcastChannel("portal-adopted");
bc_adopted.onmessage = function(e) {
bc_adopted.close();

var bc_test = new BroadcastChannel("portal-test");
bc_test.postMessage("passed");
bc_test.close();
}
}
</script>

0 comments on commit f13bccf

Please sign in to comment.