REGRESSION: Crash when typing into text field that clears itself on iOS
authorjhoneycutt@apple.com <jhoneycutt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Jul 2014 17:21:20 +0000 (17:21 +0000)
committerjhoneycutt@apple.com <jhoneycutt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Jul 2014 17:21:20 +0000 (17:21 +0000)
<https://bugs.webkit.org/show_bug.cgi?id=135044>
<rdar://problem/17640443>

Reviewed by Darin Adler.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::requestAutocorrectionData):
wordRangeFromPosition() returns null in some cases; null check range
before dereferencing it. Moved some variable declarations around to
better match our style.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@171225 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

index 0325e4e..4d129b9 100644 (file)
@@ -1,3 +1,18 @@
+2014-07-18  Jon Honeycutt  <jhoneycutt@apple.com>
+
+        REGRESSION: Crash when typing into text field that clears itself on iOS
+
+        <https://bugs.webkit.org/show_bug.cgi?id=135044>
+        <rdar://problem/17640443>
+
+        Reviewed by Darin Adler.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::requestAutocorrectionData):
+        wordRangeFromPosition() returns null in some cases; null check range
+        before dereferencing it. Moved some variable declarations around to
+        better match our style.
+
 2014-07-18  Tim Horton  <timothy_horton@apple.com>
 
         [WK2] Provide a mechanism to grab the back-forward list for gesture navigation purposes from another WKWebView
index ad72508..013fce4 100644 (file)
@@ -1620,7 +1620,6 @@ void WebPage::replaceDictatedText(const String& oldText, const String& newText)
 
 void WebPage::requestAutocorrectionData(const String& textForAutocorrection, uint64_t callbackID)
 {
-    RefPtr<Range> range;
     Frame& frame = m_page->focusController().focusedOrMainFrame();
     if (!frame.selection().isCaret()) {
         send(Messages::WebPageProxy::AutocorrectionDataCallback(Vector<FloatRect>(), String(), 0, 0, callbackID));
@@ -1628,9 +1627,12 @@ void WebPage::requestAutocorrectionData(const String& textForAutocorrection, uin
     }
 
     VisiblePosition position = frame.selection().selection().start();
-    Vector<SelectionRect> selectionRects;
+    RefPtr<Range> range = wordRangeFromPosition(position);
+    if (!range) {
+        send(Messages::WebPageProxy::AutocorrectionDataCallback(Vector<FloatRect>(), String(), 0, 0, callbackID));
+        return;
+    }
 
-    range = wordRangeFromPosition(position);
     String textForRange = plainTextReplacingNoBreakSpace(range.get());
     const unsigned maxSearchAttempts = 5;
     for (size_t i = 0;  i < maxSearchAttempts && textForRange != textForAutocorrection; ++i)
@@ -1641,6 +1643,8 @@ void WebPage::requestAutocorrectionData(const String& textForAutocorrection, uin
         range = Range::create(*frame.document(), wordRangeFromPosition(position)->startPosition(), range->endPosition());
         textForRange = plainTextReplacingNoBreakSpace(range.get());
     }
+
+    Vector<SelectionRect> selectionRects;
     if (textForRange == textForAutocorrection)
         range->collectSelectionRects(selectionRects);