Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Crash under VisibleSelection::firstRange()
https://bugs.webkit.org/show_bug.cgi?id=158241 Reviewed by Enrica Casucci. Source/WebCore: The crash was commonly caused by parentAnchoredEquivalent returning null when the anchored node was a shadow root. Fixed it by returning a shadow root in parentAnchoredEquivalent. Also guard against other kinds of crashes by adding a null check in VisibleSelection::firstRange() since we've seen a crash in the same code path outside of a shadow tree. This patch also fixes other Position methods to stop using nonShadowBoundaryParentNode in place of parentNode as that would cause a similar crash and/or a bug elsewhere. Test: fast/shadow-dom/selection-at-shadow-root-crash.html * accessibility/AXObjectCache.cpp: (AXObjectCache::startCharacterOffsetOfParagraph): Fixed a bug uncovered by the assertion fix in Position::Position. This code was sometimes creating a position inside a BR, which is wrong. (AXObjectCache::endCharacterOffsetOfParagraph): Ditto. * dom/Position.cpp: (WebCore::Position::Position): Fixed an assertion which was checking that this constructor wasn't being called with m_anchorNode set to an element editing ignores content of. ||ing it with isShadowRoot() made this assertion useless because it's true whenever m_anchorNode is not a shadow root. (WebCore::Position::containerNode): Use parentNode() instead of findParent() which calls nonShadowBoundaryParentNode since Position should (WebCore::Position::parentAnchoredEquivalent): Fixed the bug by letting this function return a shadow root. (WebCore::Position::previous): Use parentNode() instead of findParent(). (WebCore::Position::next): Ditto. (WebCore::Position::atStartOfTree): Ditto. (WebCore::Position::atEndOfTree): Ditto. (WebCore::Position::findParent): Deleted. * dom/Position.h: * editing/VisibleSelection.cpp: (VisibleSelection::firstRange): Added a null check. LayoutTests: Added a regression test. * fast/shadow-dom/selection-at-shadow-root-crash-expected.txt: Added. * fast/shadow-dom/selection-at-shadow-root-crash.html: Added. Canonical link: https://commits.webkit.org/176453@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@201667 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
9 changed files
with
97 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,4 @@ | ||
This tests copying an image which is a direct child of a shadow root. To manually test, copy the image by pressing command / control + c. WebKit should not crash or hit an assertion. | ||
|
||
PASS - WebKit did not crash | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,30 @@ | ||
<!DOCTYPE html> | ||
<body> | ||
<p>This tests copying an image which is a direct child of a shadow root. | ||
To manually test, copy the image by pressing command / control + c. WebKit should not crash or hit an assertion. | ||
</p> | ||
<pre id="result"></pre> | ||
<script> | ||
if (window.testRunner) { | ||
testRunner.dumpAsText(); | ||
testRunner.waitUntilDone(); | ||
} | ||
|
||
var host = document.createElement('div'); | ||
var root = host.attachShadow({mode: 'closed'}); | ||
root.innerHTML = '<img src="../../editing/resources/abe.png" onload="runTest()">'; | ||
|
||
document.body.appendChild(host); | ||
|
||
function runTest() { | ||
window.getSelection().selectAllChildren(root); | ||
document.execCommand('copy', null, false); | ||
document.getElementById('result').textContent = 'PASS - WebKit did not crash'; | ||
|
||
if (testRunner) | ||
testRunner.notifyDone(); | ||
} | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters