Bug 1686716 - Calling event.preventDefault in drop event handler causes a crash after target iframe has been removed, r=masayuki

Outerwindow implements nsIScriptObjectPrincipal.

Differential Revision: https://phabricator.services.mozilla.com/D101774
This commit is contained in:
Olli Pettay 2021-01-15 10:04:50 +00:00
Родитель f0af8088e4
Коммит b6bb80bd47
3 изменённых файлов: 37 добавлений и 6 удалений

Просмотреть файл

@ -412,16 +412,18 @@ void Event::PreventDefaultInternal(bool aCalledByDefaultHandler,
return;
}
nsIPrincipal* principal = nullptr;
nsCOMPtr<nsINode> node = do_QueryInterface(mEvent->mCurrentTarget);
if (!node) {
nsCOMPtr<nsPIDOMWindowOuter> win =
if (node) {
principal = node->NodePrincipal();
} else {
nsCOMPtr<nsIScriptObjectPrincipal> sop =
do_QueryInterface(mEvent->mCurrentTarget);
if (!win) {
return;
if (sop) {
principal = sop->GetPrincipal();
}
node = win->GetExtantDoc();
}
if (!nsContentUtils::IsChromeDoc(node->OwnerDoc())) {
if (principal && !principal->IsSystemPrincipal()) {
dragEvent->mDefaultPreventedOnContent = true;
}
}

Просмотреть файл

@ -30,6 +30,7 @@ support-files =
[test_all_synthetic_events.html]
[test_bug1518442.html]
[test_bug1539497.html]
[test_bug1686716.html]
[test_bug226361.xhtml]
[test_bug238987.html]
[test_bug288392.html]

Просмотреть файл

@ -0,0 +1,28 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>bug 1686716</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<script>
SimpleTest.waitForExplicitFinish();
function test() {
var ifr = document.getElementsByTagName("iframe")[0];
ifr.contentWindow.addEventListener("drop",
function(event) {
ifr.remove();
event.preventDefault();
});
sendDragEvent({type: "drop"}, ifr.contentDocument.body, ifr.contentWindow);
ok(true, "Should not crash.");
SimpleTest.finish();
}
</script>
</head>
<body onload="test()">
<iframe></iframe>
<p id="display"></p>
</body>
</html>