⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243684 in webkit


Ignore:
Timestamp:
Mar 31, 2019, 1:01:44 PM (7 years ago)
Author:
Wenson Hsieh
Message:

[iOS] Crash when changing inputmode for certain types of focusable elements
https://bugs.webkit.org/show_bug.cgi?id=196431
<rdar://problem/49454962>

Reviewed by Tim Horton.

Source/WebKit:

The crash is happening because WebPage::focusedElementDidChangeInputMode assumes that the document's focused
element must be the same as m_focusedElement in WebPage. However, this is not the case, since m_focusedElement
is only set for certain types of elements that require user input (e.g. text fields, editable content, select
menus, etc.). The function then attempts to dereference m_focusedElement, which may be null if the document's
focused element doesn't fall into one of the aforementioned categories.

To fix this, bail if the element that is changing inputmode is not equal to the WebPage's current focused
element. See below for more details.

Test: fast/forms/change-inputmode-crash.html

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::isTextFormControlOrEditableContent):

Clean up some existing logic by introducing a helper method for determining whether an element should
propagate inputmode attribute changes to the UI process. Also, check the element type using type traits instead
of checking against the tag name.

(WebKit::WebPage::elementDidFocus):
(WebKit::WebPage::focusedElementDidChangeInputMode):

LayoutTests:

Add a layout test that exercises the edge case; see WebKit ChangeLogs for more details.

  • fast/forms/change-inputmode-crash-expected.txt: Added.
  • fast/forms/change-inputmode-crash.html: Added.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r243681 r243684  
     12019-03-31  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [iOS] Crash when changing inputmode for certain types of focusable elements
     4        https://bugs.webkit.org/show_bug.cgi?id=196431
     5        <rdar://problem/49454962>
     6
     7        Reviewed by Tim Horton.
     8
     9        Add a layout test that exercises the edge case; see WebKit ChangeLogs for more details.
     10
     11        * fast/forms/change-inputmode-crash-expected.txt: Added.
     12        * fast/forms/change-inputmode-crash.html: Added.
     13
    1142019-03-29  Dean Jackson  <dino@apple.com>
    215
  • trunk/Source/WebKit/ChangeLog

    r243683 r243684  
     12019-03-31  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [iOS] Crash when changing inputmode for certain types of focusable elements
     4        https://bugs.webkit.org/show_bug.cgi?id=196431
     5        <rdar://problem/49454962>
     6
     7        Reviewed by Tim Horton.
     8
     9        The crash is happening because WebPage::focusedElementDidChangeInputMode assumes that the document's focused
     10        element must be the same as m_focusedElement in WebPage. However, this is not the case, since m_focusedElement
     11        is only set for certain types of elements that require user input (e.g. text fields, editable content, select
     12        menus, etc.). The function then attempts to dereference m_focusedElement, which may be null if the document's
     13        focused element doesn't fall into one of the aforementioned categories.
     14
     15        To fix this, bail if the element that is changing inputmode is not equal to the WebPage's current focused
     16        element. See below for more details.
     17
     18        Test: fast/forms/change-inputmode-crash.html
     19
     20        * WebProcess/WebPage/WebPage.cpp:
     21        (WebKit::isTextFormControlOrEditableContent):
     22
     23        Clean up some existing logic by introducing a helper method for determining whether an element should
     24        propagate inputmode attribute changes to the UI process. Also, check the element type using type traits instead
     25        of checking against the tag name.
     26
     27        (WebKit::WebPage::elementDidFocus):
     28        (WebKit::WebPage::focusedElementDidChangeInputMode):
     29
    1302019-03-31  Sam Weinig  <weinig@apple.com>
    231
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r243630 r243684  
    174174#include <WebCore/HTMLPlugInElement.h>
    175175#include <WebCore/HTMLPlugInImageElement.h>
     176#include <WebCore/HTMLSelectElement.h>
    176177#include <WebCore/HTMLTextAreaElement.h>
     178#include <WebCore/HTMLTextFormControlElement.h>
    177179#include <WebCore/HTMLUListElement.h>
    178180#include <WebCore/HistoryController.h>
     
    53465348}
    53475349
     5350static bool isTextFormControlOrEditableContent(const WebCore::Element& element)
     5351{
     5352    return is<HTMLTextFormControlElement>(element) || element.hasEditableStyle();
     5353}
     5354
    53485355void WebPage::elementDidFocus(WebCore::Element& element)
    53495356{
     
    53545361    }
    53555362
    5356     if (element.hasTagName(WebCore::HTMLNames::selectTag) || element.hasTagName(WebCore::HTMLNames::inputTag) || element.hasTagName(WebCore::HTMLNames::textareaTag) || element.hasEditableStyle()) {
     5363    if (is<HTMLSelectElement>(element) || isTextFormControlOrEditableContent(element)) {
    53575364        m_focusedElement = &element;
    53585365
     
    54005407void WebPage::focusedElementDidChangeInputMode(WebCore::Element& element, WebCore::InputMode mode)
    54015408{
     5409    if (m_focusedElement != &element)
     5410        return;
     5411
    54025412#if PLATFORM(IOS_FAMILY)
    5403     ASSERT(m_focusedElement == &element);
    54045413    ASSERT(is<HTMLElement>(element));
    54055414    ASSERT(downcast<HTMLElement>(element).canonicalInputMode() == mode);
    54065415
    5407     if (!is<HTMLTextAreaElement>(*m_focusedElement) && !is<HTMLInputElement>(*m_focusedElement) && !m_focusedElement->hasEditableStyle())
     5416    if (!isTextFormControlOrEditableContent(element))
    54085417        return;
    54095418
    54105419    send(Messages::WebPageProxy::FocusedElementDidChangeInputMode(mode));
    54115420#else
    5412     UNUSED_PARAM(element);
    54135421    UNUSED_PARAM(mode);
    54145422#endif
Note: See TracChangeset for help on using the changeset viewer.