Commit c71b9857 authored by Lucas Furukawa Gadani's avatar Lucas Furukawa Gadani Committed by Commit Bot

Portals: Prevent closing of the portal window.

Bug: 1110926
Change-Id: Ib22e96d4898f08f326094bfdc030eb7a73b65e00
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2353016
Commit-Queue: Lucas Gadani <lfg@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Reviewed-by: default avatarNasko Oskov <nasko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798125}
parent 75bae800
......@@ -258,6 +258,7 @@ enum BadMessageReason {
RFH_SUBFRAME_CAPTURE_ON_MAIN_FRAME = 230,
RFH_CSP_ATTRIBUTE = 231,
RFH_RECEIVED_ASSOCIATED_MESSAGE_WHILE_BFCACHED = 232,
RWH_CLOSE_PORTAL = 233,
// Please add new elements here. The naming convention is abbreviated class
// name (e.g. RenderFrameHost becomes RFH) plus a unique description of the
......
......@@ -9,6 +9,7 @@
#include "base/feature_list.h"
#include "base/memory/ptr_util.h"
#include "content/browser/bad_message.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/devtools/devtools_instrumentation.h"
#include "content/browser/frame_host/navigation_request.h"
......@@ -530,7 +531,15 @@ void Portal::PortalWebContentsCreated(WebContents* portal_web_contents) {
void Portal::CloseContents(WebContents* web_contents) {
DCHECK_EQ(web_contents, portal_contents_.get());
DestroySelf(); // Deletes |this|.
if (portal_contents_->GetOuterWebContents()) {
// This portal was still attached, we shouldn't have received a request to
// close it.
bad_message::ReceivedBadMessage(web_contents->GetMainFrame()->GetProcess(),
bad_message::RWH_CLOSE_PORTAL);
} else {
// Orphaned portal was closed.
DestroySelf(); // Deletes |this|.
}
}
WebContents* Portal::GetResponsibleWebContents(WebContents* web_contents) {
......
......@@ -328,6 +328,9 @@ void DOMWindow::Close(LocalDOMWindow* incumbent_window) {
if (!page)
return;
if (page->InsidePortal())
return;
Document* active_document = incumbent_window->document();
if (!(active_document && active_document->GetFrame() &&
active_document->GetFrame()->CanNavigate(*GetFrame()))) {
......
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
promise_test(async t => {
assert_implements("HTMLPortalElement" in self);
let portal = document.createElement('portal');
portal.src = "resources/portal-close-window.html";
let waitForMessage = new Promise((resolve, reject) => {
portal.onmessage = e => resolve(e.data);
document.body.appendChild(portal);
});
document.body.appendChild(portal);
var message = await waitForMessage;
assert_equals(message, false);
t.add_cleanup(() => { document.body.removeChild(portal); });
}, "A portal's window cannot be closed");
</script>
</body>
<!DOCTYPE html>
<script>
onload = () => {
window.close();
window.portalHost.postMessage(window.closed, '*');
};
</script>
......@@ -6249,6 +6249,7 @@ Called by update_bad_message_reasons.py.-->
<int value="230" label="RFH_SUBFRAME_CAPTURE_ON_MAIN_FRAME"/>
<int value="231" label="RFH_CSP_ATTRIBUTE"/>
<int value="232" label="RFH_RECEIVED_ASSOCIATED_MESSAGE_WHILE_BFCACHED"/>
<int value="233" label="RWH_CLOSE_PORTAL"/>
</enum>
<enum name="BadMessageReasonExtensions">
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