Commit 7ed4cd1f authored by Nektarios Paisios's avatar Nektarios Paisios Committed by Commit Bot

Creates an invalid AXRange if start and end positions are invalid instead of DCHECKing

This creates safer code overall.
If start and end AXPositions are invalid for any reason we didn't contemplate, the browser doesn't crash but returns an AXRange that is explicitly marked invalid.
It's also a nice workaround until CSS decorations are supported in AXPosition.

TBR=dmazzoni@chromium.org, aleventhal@chromium.org

Bug: 852266
Change-Id: I94db8aeda296690a842b674ea27743dc573205d7
Reviewed-on: https://chromium-review.googlesource.com/1112968Reviewed-by: default avatarNektarios Paisios <nektar@chromium.org>
Commit-Queue: Nektarios Paisios <nektar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569941}
parent 61d88c45
......@@ -121,9 +121,11 @@ void AXInlineTextBox::GetWordBoundaries(Vector<AXRange>& words) const {
inline_text_box_->GetWordBoundaries(boundaries);
words.ReserveCapacity(boundaries.size());
for (const auto& boundary : boundaries) {
words.emplace_back(
const AXRange range(
AXPosition::CreatePositionInTextObject(*this, boundary.start_index),
AXPosition::CreatePositionInTextObject(*this, boundary.end_index));
if (range.IsValid())
words.push_back(range);
}
}
......
......@@ -145,6 +145,7 @@ class MODULES_EXPORT AXPosition final {
// For access to our constructor for use when creating empty AX selections.
// There is no sense in creating empty positions in other circomstances so we
// disallow it.
friend class AXRange;
friend class AXSelection;
};
......
......@@ -10,16 +10,21 @@
namespace blink {
AXRange::AXRange(const AXPosition& start, const AXPosition& end)
: start_(start), end_(end) {
DCHECK(start.IsValid());
DCHECK(end.IsValid());
DCHECK_LE(start, end);
: start_(), end_() {
if (!start.IsValid() || !end.IsValid() || start > end)
return;
const Document* document = start.ContainerObject()->GetDocument();
DCHECK(document);
DCHECK(document->IsActive());
DCHECK(!document->NeedsLayoutTreeUpdate());
DCHECK_EQ(end.ContainerObject()->GetDocument(), document);
// We don't support ranges that span across documents.
if (end.ContainerObject()->GetDocument() != document)
return;
start_ = start;
end_ = end;
#if DCHECK_IS_ON()
dom_tree_version_ = document->DomTreeVersion();
style_version_ = document->StyleVersion();
......
......@@ -60,6 +60,10 @@ const AXSelection AXSelection::Builder::Build() {
DCHECK(document);
DCHECK(document->IsActive());
DCHECK(!document->NeedsLayoutTreeUpdate());
// We don't support selections that span across documents.
if (selection_.Extent().ContainerObject()->GetDocument() != document)
return {};
#if DCHECK_IS_ON()
selection_.dom_tree_version_ = document->DomTreeVersion();
selection_.style_version_ = document->StyleVersion();
......
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