Title: [164963] trunk/Source/WebKit2
Revision
164963
Author
[email protected]
Date
2014-03-02 18:07:25 -0800 (Sun, 02 Mar 2014)

Log Message

[iOS WebKit2] Keyboard deadlock when accepting/dismissing autocorrection.
https://bugs.webkit.org/show_bug.cgi?id=129594
<rdar://problem/16168978>

Reviewed by Sam Weinig.

As a temporary fix, we are using a synchronous
message to accept autocorrection until we implement
a solution that processes these requests on a thread that
is not the main thread.

* UIProcess/WebPageProxy.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView applyAutocorrection:toString:withCompletionHandler:]):
(-[WKContentView requestAutocorrectionContextWithCompletionHandler:]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::applyAutocorrection):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::applyAutocorrection):
(WebKit::WebPage::syncApplyAutocorrection):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (164962 => 164963)


--- trunk/Source/WebKit2/ChangeLog	2014-03-03 02:00:46 UTC (rev 164962)
+++ trunk/Source/WebKit2/ChangeLog	2014-03-03 02:07:25 UTC (rev 164963)
@@ -1,3 +1,28 @@
+2014-03-02  Enrica Casucci  <[email protected]>
+
+        [iOS WebKit2] Keyboard deadlock when accepting/dismissing autocorrection.
+        https://bugs.webkit.org/show_bug.cgi?id=129594
+        <rdar://problem/16168978>
+
+        Reviewed by Sam Weinig.
+
+        As a temporary fix, we are using a synchronous
+        message to accept autocorrection until we implement
+        a solution that processes these requests on a thread that
+        is not the main thread.
+
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView applyAutocorrection:toString:withCompletionHandler:]):
+        (-[WKContentView requestAutocorrectionContextWithCompletionHandler:]):
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::applyAutocorrection):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::applyAutocorrection):
+        (WebKit::WebPage::syncApplyAutocorrection):
+
 2014-03-02  Dan Bernstein  <[email protected]>
 
         Try to fix the 32-bit build.

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (164962 => 164963)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2014-03-03 02:00:46 UTC (rev 164962)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2014-03-03 02:07:25 UTC (rev 164963)
@@ -469,6 +469,7 @@
     void extendSelection(WebCore::TextGranularity);
     void requestAutocorrectionData(const String& textForAutocorrection, PassRefPtr<AutocorrectionDataCallback>);
     void applyAutocorrection(const String& correction, const String& originalText, PassRefPtr<StringCallback>);
+    bool applyAutocorrection(const String& correction, const String& originalText);
     void requestAutocorrectionContext(PassRefPtr<AutocorrectionContextCallback>);
     void getAutocorrectionContext(String& contextBefore, String& markedText, String& selectedText, String& contextAfter, uint64_t& location, uint64_t& length);
     void didReceivePositionInformation(const InteractionInformationAtPosition&);

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (164962 => 164963)


--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2014-03-03 02:00:46 UTC (rev 164962)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2014-03-03 02:07:25 UTC (rev 164963)
@@ -1234,6 +1234,13 @@
 // The completion handler should pass the rect of the correction text after replacing the input text, or nil if the replacement could not be performed.
 - (void)applyAutocorrection:(NSString *)correction toString:(NSString *)input withCompletionHandler:(void (^)(UIWKAutocorrectionRects *rectsForCorrection))completionHandler
 {
+    // FIXME: Remove the synchronous call when <rdar://problem/16207002> is fixed.
+    const bool useSyncRequest = true;
+
+    if (useSyncRequest) {
+        completionHandler(_page->applyAutocorrection(correction, input) ? [WKAutocorrectionRects autocorrectionRectsWithRects:_autocorrectionData.textFirstRect lastRect:_autocorrectionData.textLastRect] : nil);
+        return;
+    }
     _autocorrectionData.autocorrectionHandler = [completionHandler copy];
     _page->applyAutocorrection(correction, input, StringCallback::create([self](bool /*error*/, StringImpl* string) {
         _autocorrectionData.autocorrectionHandler(string ? [WKAutocorrectionRects autocorrectionRectsWithRects:_autocorrectionData.textFirstRect lastRect:_autocorrectionData.textLastRect] : nil);
@@ -1244,7 +1251,7 @@
 
 - (void)requestAutocorrectionContextWithCompletionHandler:(void (^)(UIWKAutocorrectionContext *autocorrectionContext))completionHandler
 {
-    // FIXME: Remove the synchronous call as soon as Keyboard removes locking of the main thread.
+    // FIXME: Remove the synchronous call when <rdar://problem/16207002> is fixed.
     const bool useSyncRequest = true;
 
     if (useSyncRequest) {

Modified: trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm (164962 => 164963)


--- trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm	2014-03-03 02:00:46 UTC (rev 164962)
+++ trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm	2014-03-03 02:07:25 UTC (rev 164963)
@@ -301,6 +301,13 @@
     m_process->send(Messages::WebPage::ApplyAutocorrection(correction, originalText, callbackID), m_pageID);
 }
 
+bool WebPageProxy::applyAutocorrection(const String& correction, const String& originalText)
+{
+    bool autocorrectionApplied = false;
+    m_process->sendSync(Messages::WebPage::SyncApplyAutocorrection(correction, originalText), Messages::WebPage::SyncApplyAutocorrection::Reply(autocorrectionApplied), m_pageID);
+    return autocorrectionApplied;
+}
+
 void WebPageProxy::requestAutocorrectionContext(PassRefPtr<AutocorrectionContextCallback> callback)
 {
     if (!isValid()) {

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (164962 => 164963)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2014-03-03 02:00:46 UTC (rev 164962)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2014-03-03 02:07:25 UTC (rev 164963)
@@ -455,6 +455,7 @@
     void elementDidBlur(WebCore::Node*);
     void requestAutocorrectionData(const String& textForAutocorrection, uint64_t callbackID);
     void applyAutocorrection(const String& correction, const String& originalText, uint64_t callbackID);
+    void syncApplyAutocorrection(const String& correction, const String& originalText, bool& correctionApplied);
     void requestAutocorrectionContext(uint64_t callbackID);
     void getAutocorrectionContext(String& beforeText, String& markedText, String& selectedText, String& afterText, uint64_t& location, uint64_t& length);
     void insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd);

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (164962 => 164963)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2014-03-03 02:00:46 UTC (rev 164962)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2014-03-03 02:07:25 UTC (rev 164963)
@@ -53,6 +53,7 @@
     ExtendSelection(uint32_t granularity)
     RequestAutocorrectionData(String textForAutocorrection, uint64_t callbackID)
     ApplyAutocorrection(String correction, String originalText, uint64_t callbackID)
+    SyncApplyAutocorrection(String correction, String originalText) -> (bool autocorrectionApplied)
     RequestAutocorrectionContext(uint64_t callbackID)
     GetAutocorrectionContext() -> (String beforeContext, String markedText, String selectedText, String afterContext, uint64_t location, uint64_t length) 
     InsertText(String text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (164962 => 164963)


--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2014-03-03 02:00:46 UTC (rev 164962)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2014-03-03 02:07:25 UTC (rev 164963)
@@ -1287,11 +1287,20 @@
 
 void WebPage::applyAutocorrection(const String& correction, const String& originalText, uint64_t callbackID)
 {
+    bool correctionApplied;
+    syncApplyAutocorrection(correction, originalText, correctionApplied);
+    send(Messages::WebPageProxy::StringCallback(correctionApplied ? correction : String(), callbackID));
+}
+
+void WebPage::syncApplyAutocorrection(const String& correction, const String& originalText, bool& correctionApplied)
+{
     RefPtr<Range> range;
+    correctionApplied = false;
     Frame& frame = m_page->focusController().focusedOrMainFrame();
-    ASSERT(frame.selection().isCaret());
+    if (!frame.selection().isCaret())
+        return;
     VisiblePosition position = frame.selection().selection().start();
-
+    
     range = wordRangeFromPosition(position);
     String textForRange = plainText(range.get());
     if (textForRange != originalText) {
@@ -1315,17 +1324,16 @@
         }
     }
     if (textForRange != originalText) {
-        send(Messages::WebPageProxy::StringCallback(String(), callbackID));
+        correctionApplied = false;
         return;
     }
-
+    
     frame.selection().setSelectedRange(range.get(), UPSTREAM, true);
     if (correction.length())
         frame.editor().insertText(correction, 0);
     else
         frame.editor().deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
-
-    send(Messages::WebPageProxy::StringCallback(correction, callbackID));
+    correctionApplied = true;
 }
 
 static void computeAutocorrectionContext(Frame& frame, String& contextBefore, String& markedText, String& selectedText, String& contextAfter, uint64_t& location, uint64_t& length)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to