Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(514)

Unified Diff: third_party/WebKit/Source/core/editing/DOMSelection.cpp

Issue 2783103002: Dispose temporary and not-cached Range in DOMSelection
Patch Set: update Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/editing/DOMSelection.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/DOMSelection.cpp
diff --git a/third_party/WebKit/Source/core/editing/DOMSelection.cpp b/third_party/WebKit/Source/core/editing/DOMSelection.cpp
index d473161afba0f1e496fda0842d1b9f6079b6c2fb..aa15eb366788d22e532b65d8de49279b9a4a7dda 100644
--- a/third_party/WebKit/Source/core/editing/DOMSelection.cpp
+++ b/third_party/WebKit/Source/core/editing/DOMSelection.cpp
@@ -125,8 +125,25 @@ static Position extentPosition(const VisibleSelection& selection) {
return selection.extent().parentAnchoredEquivalent();
}
+class ScopedRange {
yosin_UTC9 2017/03/30 08:58:17 Please introduce a function acts like primaryRange
+ STACK_ALLOCATED();
+
+ public:
+ ScopedRange(Range* range, bool dispose)
+ : m_range(range), m_dispose(dispose) {}
+ ~ScopedRange() {
+ if (m_dispose)
+ m_range->dispose();
+ }
+
+ private:
+ Member<Range> m_range;
+ bool m_dispose;
+};
+
Node* DOMSelection::anchorNode() const {
if (Range* range = primaryRangeOrNull()) {
+ ScopedRange scope(range, !isSelectionOfDocument());
if (!frame() || isBaseFirstInSelection())
return range->startContainer();
return range->endContainer();
@@ -136,6 +153,7 @@ Node* DOMSelection::anchorNode() const {
unsigned DOMSelection::anchorOffset() const {
if (Range* range = primaryRangeOrNull()) {
+ ScopedRange scope(range, !isSelectionOfDocument());
if (!frame() || isBaseFirstInSelection())
return range->startOffset();
return range->endOffset();
@@ -145,6 +163,7 @@ unsigned DOMSelection::anchorOffset() const {
Node* DOMSelection::focusNode() const {
if (Range* range = primaryRangeOrNull()) {
+ ScopedRange scope(range, !isSelectionOfDocument());
if (!frame() || isBaseFirstInSelection())
return range->endContainer();
return range->startContainer();
@@ -154,6 +173,7 @@ Node* DOMSelection::focusNode() const {
unsigned DOMSelection::focusOffset() const {
if (Range* range = primaryRangeOrNull()) {
+ ScopedRange scope(range, !isSelectionOfDocument());
if (!frame() || isBaseFirstInSelection())
return range->endOffset();
return range->startOffset();
@@ -589,7 +609,9 @@ void DOMSelection::removeRange(Range* range) {
DCHECK(range);
if (!isAvailable())
return;
- if (range == primaryRangeOrNull())
+ Range* originalRange = primaryRangeOrNull();
+ ScopedRange scope(originalRange, !isSelectionOfDocument());
+ if (range == originalRange)
frame()->selection().clear();
}
@@ -631,6 +653,7 @@ void DOMSelection::addRange(Range* newRange) {
Range* originalRange = primaryRangeOrNull();
DCHECK(originalRange);
+ ScopedRange scope(originalRange, !isSelectionOfDocument());
if (originalRange->startContainer()->treeScope() !=
newRange->startContainer()->treeScope()) {
« no previous file with comments | « third_party/WebKit/Source/core/editing/DOMSelection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698