Changeset 206985 in webkit


Ignore:
Timestamp:
Oct 10, 2016 12:12:35 AM (8 years ago)
Author:
commit-queue@webkit.org
Message:

[GTK] UIProcess crashes when using Japanese IM
https://bugs.webkit.org/show_bug.cgi?id=163011

We have to reference the current GdkEventKey before we try process it
as later when the lambda body is reached the event could be already
freed.

Patch by Tomas Popela <tpopela@redhat.com> on 2016-10-10
Reviewed by Carlos Garcia Campos.

  • UIProcess/API/gtk/WebKitWebViewBase.cpp:

(webkitWebViewBaseKeyPressEvent):
(webkitWebViewBaseKeyReleaseEvent):

  • UIProcess/gtk/InputMethodFilter.h:

Use non-copyable Function so we can use WTFMove to pass the event to
lambda.

Location:
trunk/Source/WebKit2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r206979 r206985  
     12016-10-10  Tomas Popela  <tpopela@redhat.com>
     2
     3        [GTK] UIProcess crashes when using Japanese IM
     4        https://bugs.webkit.org/show_bug.cgi?id=163011
     5
     6        We have to reference the current GdkEventKey before we try process it
     7        as later when the lambda body is reached the event could be already
     8        freed.
     9
     10        Reviewed by Carlos Garcia Campos.
     11
     12        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
     13        (webkitWebViewBaseKeyPressEvent):
     14        (webkitWebViewBaseKeyReleaseEvent):
     15        * UIProcess/gtk/InputMethodFilter.h:
     16        Use non-copyable Function so we can use WTFMove to pass the event to
     17        lambda.
     18
    1192016-10-09  Wenson Hsieh  <wenson_hsieh@apple.com>
    220
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp

    r206915 r206985  
    675675}
    676676
    677 static gboolean webkitWebViewBaseKeyPressEvent(GtkWidget* widget, GdkEventKey* event)
     677static gboolean webkitWebViewBaseKeyPressEvent(GtkWidget* widget, GdkEventKey* keyEvent)
    678678{
    679679    WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
     
    681681
    682682    if (priv->authenticationDialog)
    683         return GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->key_press_event(widget, event);
     683        return GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->key_press_event(widget, keyEvent);
    684684
    685685#if ENABLE(FULLSCREEN_API)
    686686    if (priv->fullScreenModeActive) {
    687         switch (event->keyval) {
     687        switch (keyEvent->keyval) {
    688688        case GDK_KEY_Escape:
    689689        case GDK_KEY_f:
     
    703703    if (priv->shouldForwardNextKeyEvent) {
    704704        priv->shouldForwardNextKeyEvent = FALSE;
    705         return GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->key_press_event(widget, event);
    706     }
    707 
    708     priv->inputMethodFilter.filterKeyEvent(event, [priv, event](const WebCore::CompositionResults& compositionResults, InputMethodFilter::EventFakedForComposition faked) {
    709         priv->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(event), compositionResults, faked,
    710             !compositionResults.compositionUpdated() ? priv->keyBindingTranslator.commandsForKeyEvent(event) : Vector<String>()));
     705        return GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->key_press_event(widget, keyEvent);
     706    }
     707
     708    // We need to copy the event as otherwise it could be destroyed before we reach the lambda body.
     709    GUniquePtr<GdkEvent> event(gdk_event_copy(reinterpret_cast<GdkEvent*>(keyEvent)));
     710    priv->inputMethodFilter.filterKeyEvent(keyEvent, [priv, event = WTFMove(event)](const WebCore::CompositionResults& compositionResults, InputMethodFilter::EventFakedForComposition faked) {
     711        priv->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(event.get(), compositionResults, faked,
     712            !compositionResults.compositionUpdated() ? priv->keyBindingTranslator.commandsForKeyEvent(&event->key) : Vector<String>()));
    711713    });
    712714
     
    714716}
    715717
    716 static gboolean webkitWebViewBaseKeyReleaseEvent(GtkWidget* widget, GdkEventKey* event)
     718static gboolean webkitWebViewBaseKeyReleaseEvent(GtkWidget* widget, GdkEventKey* keyEvent)
    717719{
    718720    WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
     
    721723    if (priv->shouldForwardNextKeyEvent) {
    722724        priv->shouldForwardNextKeyEvent = FALSE;
    723         return GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->key_release_event(widget, event);
    724     }
    725 
    726     priv->inputMethodFilter.filterKeyEvent(event, [priv, event](const WebCore::CompositionResults& compositionResults, InputMethodFilter::EventFakedForComposition faked) {
    727         priv->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(event), compositionResults, faked, { }));
     725        return GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->key_release_event(widget, keyEvent);
     726    }
     727
     728    // We need to copy the event as otherwise it could be destroyed before we reach the lambda body.
     729    GUniquePtr<GdkEvent> event(gdk_event_copy(reinterpret_cast<GdkEvent*>(keyEvent)));
     730    priv->inputMethodFilter.filterKeyEvent(keyEvent, [priv, event = WTFMove(event)](const WebCore::CompositionResults& compositionResults, InputMethodFilter::EventFakedForComposition faked) {
     731        priv->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(event.get(), compositionResults, faked, { }));
    728732    });
    729733
  • trunk/Source/WebKit2/UIProcess/gtk/InputMethodFilter.h

    r206915 r206985  
    2222
    2323#include <WebCore/IntPoint.h>
    24 #include <functional>
     24#include <wtf/Function.h>
    2525#include <wtf/Noncopyable.h>
    2626#include <wtf/glib/GRefPtr.h>
     
    5757    void setCursorRect(const WebCore::IntRect&);
    5858
    59     using FilterKeyEventCompletionHandler = std::function<void (const WebCore::CompositionResults&, InputMethodFilter::EventFakedForComposition)>;
     59    using FilterKeyEventCompletionHandler = Function<void(const WebCore::CompositionResults&, InputMethodFilter::EventFakedForComposition)>;
    6060    void filterKeyEvent(GdkEventKey*, FilterKeyEventCompletionHandler&& = nullptr);
    6161    void notifyFocusedIn();
Note: See TracChangeset for help on using the changeset viewer.