Bug 1341137 part 1 - Make Selection::addRange silently reject ranges that have a different root. r=smaug
☠☠ backed out by d309d805ebc9 ☠ ☠
authorMats Palmgren <mats@mozilla.com>
Sat, 25 Feb 2017 00:26:18 +0100
changeset 373934 6f32de880c778cbe28b80bfab9e02974ad3bdc98
parent 373933 ebb71fecdc3a42bfb94f74c0df54f42ae26d821d
child 373935 ac44e1e713e1bdfc28516b208fc02659b73899e4
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1341137
milestone54.0a1
Bug 1341137 part 1 - Make Selection::addRange silently reject ranges that have a different root. r=smaug
layout/generic/nsSelection.cpp
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -4959,16 +4959,26 @@ Selection::AddRange(nsIDOMRange* aDOMRan
   ErrorResult result;
   AddRange(*range, result);
   return result.StealNSResult();
 }
 
 void
 Selection::AddRange(nsRange& aRange, ErrorResult& aRv)
 {
+  nsINode* rangeRoot = aRange.GetRoot();
+  nsIDocument* doc = GetParentObject();
+  if (doc != rangeRoot && (!rangeRoot ||
+                           doc != rangeRoot->GetComposedDoc())) {
+    // http://w3c.github.io/selection-api/#dom-selection-addrange
+    // "...  if the root of the range's boundary points are the document
+    // associated with context object. Otherwise, this method must do nothing."
+    return;
+  }
+
   // This inserts a table cell range in proper document order
   // and returns NS_OK if range doesn't contain just one table cell
   bool didAddRange;
   int32_t rangeIndex;
   nsresult result = addTableCellRange(&aRange, &didAddRange, &rangeIndex);
   if (NS_FAILED(result)) {
     aRv.Throw(result);
     return;