Changeset 196598 in webkit


Ignore:
Timestamp:
Feb 15, 2016 1:38:25 PM (8 years ago)
Author:
jiewen_tan@apple.com
Message:

Refine SimulatedMouseEvent to support Event.isTrusted
https://bugs.webkit.org/show_bug.cgi?id=154133
<rdar://problem/24616246>

Reviewed by Darin Adler.

Source/WebCore:

This patch extracts everything related to create/dispatch SimulatedMouseEvent from MouseEvent.h/cpp
and EventDispatcher.h/cpp, and produces SimulateClick.h/cpp which will handle simulated click solely.
After that, we hide the SimulatedMouseEvent and only expose simulateClick to be called. The reason is
that we both want to tell whether the call sites are from user agent/bindings and keep the
SimulatedMouseEvent intact.

Also, this patch separate Element::dispatchSimulatedClick into two: one for the user agent, and another
for the bindings. Therefore, HTMLElement.click will be treated as untrusted.

Some of the changes in this patch referred Blink r200401:
https://codereview.chromium.org/1285793004

Modified test:
LayoutTests/imported/blink/fast/events/event-trusted.html

  • CMakeLists.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • dom/Element.cpp:

(WebCore::Element::dispatchSimulatedClick):
(WebCore::Element::dispatchSimulatedClickForBindings):

  • dom/Element.h:
  • dom/EventDispatcher.cpp:

(WebCore::EventDispatcher::dispatchSimulatedClick): Deleted.

  • dom/EventDispatcher.h:
  • dom/MouseEvent.cpp:

(WebCore::SimulatedMouseEvent::create): Deleted.
(WebCore::SimulatedMouseEvent::~SimulatedMouseEvent): Deleted.
(WebCore::SimulatedMouseEvent::SimulatedMouseEvent): Deleted.

  • dom/MouseEvent.h:
  • dom/SimulatedClick.cpp: Added.

(WebCore::simulateMouseEvent):
(WebCore::simulateClick):

  • dom/SimulatedClick.h: Added.
  • html/HTMLElement.cpp:

(WebCore::HTMLElement::click):

LayoutTests:

  • imported/blink/fast/events/event-trusted-expected.txt:
  • imported/blink/fast/events/event-trusted.html:
Location:
trunk
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r196595 r196598  
     12016-02-15  Jiewen Tan  <jiewen_tan@apple.com>
     2
     3        Refine SimulatedMouseEvent to support Event.isTrusted
     4        https://bugs.webkit.org/show_bug.cgi?id=154133
     5        <rdar://problem/24616246>
     6
     7        Reviewed by Darin Adler.
     8
     9        * imported/blink/fast/events/event-trusted-expected.txt:
     10        * imported/blink/fast/events/event-trusted.html:
     11
    1122016-02-15  Ryan Haddad  <ryanhaddad@apple.com>
    213
  • trunk/LayoutTests/imported/blink/fast/events/event-trusted-expected.txt

    r196520 r196598  
    99PASS redispatched is true
    1010PASS originalEvent.isTrusted is false
     11PASS originalEvent.isTrusted is false
    1112PASS successfullyParsed is true
    1213
  • trunk/LayoutTests/imported/blink/fast/events/event-trusted.html

    r196520 r196598  
    3737    shouldBeTrue("redispatched");
    3838    shouldBeFalse("originalEvent.isTrusted");
     39
     40    originalEvent = null;
     41    element.removeEventListener('click', redispatch);
     42    element.addEventListener('click', originalDispatch);
     43    element.click();
     44    shouldBeFalse("originalEvent.isTrusted");
    3945}
    4046
  • trunk/Source/WebCore/CMakeLists.txt

    r196594 r196598  
    15111511    dom/SelectorQuery.cpp
    15121512    dom/ShadowRoot.cpp
     1513    dom/SimulatedClick.cpp
    15131514    dom/SlotAssignment.cpp
    15141515    dom/SpaceSplitString.cpp
  • trunk/Source/WebCore/ChangeLog

    r196594 r196598  
     12016-02-15  Jiewen Tan  <jiewen_tan@apple.com>
     2
     3        Refine SimulatedMouseEvent to support Event.isTrusted
     4        https://bugs.webkit.org/show_bug.cgi?id=154133
     5        <rdar://problem/24616246>
     6
     7        Reviewed by Darin Adler.
     8
     9        This patch extracts everything related to create/dispatch SimulatedMouseEvent from MouseEvent.h/cpp
     10        and EventDispatcher.h/cpp, and produces SimulateClick.h/cpp which will handle simulated click solely.
     11        After that, we hide the SimulatedMouseEvent and only expose simulateClick to be called. The reason is
     12        that we both want to tell whether the call sites are from user agent/bindings and keep the
     13        SimulatedMouseEvent intact.
     14
     15        Also, this patch separate Element::dispatchSimulatedClick into two: one for the user agent, and another
     16        for the bindings. Therefore, HTMLElement.click will be treated as untrusted.
     17
     18        Some of the changes in this patch referred Blink r200401:
     19        https://codereview.chromium.org/1285793004
     20
     21        Modified test:
     22        LayoutTests/imported/blink/fast/events/event-trusted.html
     23
     24        * CMakeLists.txt:
     25        * WebCore.xcodeproj/project.pbxproj:
     26        * dom/Element.cpp:
     27        (WebCore::Element::dispatchSimulatedClick):
     28        (WebCore::Element::dispatchSimulatedClickForBindings):
     29        * dom/Element.h:
     30        * dom/EventDispatcher.cpp:
     31        (WebCore::EventDispatcher::dispatchSimulatedClick): Deleted.
     32        * dom/EventDispatcher.h:
     33        * dom/MouseEvent.cpp:
     34        (WebCore::SimulatedMouseEvent::create): Deleted.
     35        (WebCore::SimulatedMouseEvent::~SimulatedMouseEvent): Deleted.
     36        (WebCore::SimulatedMouseEvent::SimulatedMouseEvent): Deleted.
     37        * dom/MouseEvent.h:
     38        * dom/SimulatedClick.cpp: Added.
     39        (WebCore::simulateMouseEvent):
     40        (WebCore::simulateClick):
     41        * dom/SimulatedClick.h: Added.
     42        * html/HTMLElement.cpp:
     43        (WebCore::HTMLElement::click):
     44
    1452016-02-15  Joseph Pecoraro  <pecoraro@apple.com>
    246
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r196594 r196598  
    23122312                550A0BC9085F6039007353D6 /* QualifiedName.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 550A0BC7085F6039007353D6 /* QualifiedName.cpp */; };
    23132313                550A0BCA085F6039007353D6 /* QualifiedName.h in Headers */ = {isa = PBXBuildFile; fileRef = 550A0BC8085F6039007353D6 /* QualifiedName.h */; settings = {ATTRIBUTES = (Private, ); }; };
     2314                572A7F211C6E5719009C6149 /* SimulatedClick.h in Headers */ = {isa = PBXBuildFile; fileRef = 572A7F201C6E5719009C6149 /* SimulatedClick.h */; };
     2315                572A7F231C6E5A66009C6149 /* SimulatedClick.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 572A7F221C6E5A66009C6149 /* SimulatedClick.cpp */; };
    23142316                580371611A66F00A00BAF519 /* ClipRect.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5803715F1A66F00A00BAF519 /* ClipRect.cpp */; };
    23152317                580371621A66F00A00BAF519 /* ClipRect.h in Headers */ = {isa = PBXBuildFile; fileRef = 580371601A66F00A00BAF519 /* ClipRect.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    98509852                550A0BC8085F6039007353D6 /* QualifiedName.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = QualifiedName.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
    98519853                55D408F71A7C631800C78450 /* SVGImageClients.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGImageClients.h; sourceTree = "<group>"; };
     9854                572A7F201C6E5719009C6149 /* SimulatedClick.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimulatedClick.h; sourceTree = "<group>"; };
     9855                572A7F221C6E5A66009C6149 /* SimulatedClick.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SimulatedClick.cpp; sourceTree = "<group>"; };
    98529856                5803715F1A66F00A00BAF519 /* ClipRect.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ClipRect.cpp; sourceTree = "<group>"; };
    98539857                580371601A66F00A00BAF519 /* ClipRect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClipRect.h; sourceTree = "<group>"; };
     
    2435624360                                A6D169631346B4C1000EB770 /* ShadowRoot.h */,
    2435724361                                9B19B67E1B964E5200348745 /* ShadowRoot.idl */,
     24362                                572A7F201C6E5719009C6149 /* SimulatedClick.h */,
     24363                                572A7F221C6E5A66009C6149 /* SimulatedClick.cpp */,
    2435824364                                31741AAB16635E45008A5B7E /* SimulatedClickOptions.h */,
    2435924365                                9B532EA11BA928570038A827 /* SlotAssignment.cpp */,
     
    2806328069                                B2227AA00D00BF220071B782 /* SVGRenderingIntent.h in Headers */,
    2806428070                                BC2274790E8366E200E7F975 /* SVGRenderStyle.h in Headers */,
     28071                                572A7F211C6E5719009C6149 /* SimulatedClick.h in Headers */,
    2806528072                                BC22747B0E8366E200E7F975 /* SVGRenderStyleDefs.h in Headers */,
    2806628073                                436708F212D9CA4B00044234 /* SVGRenderSupport.h in Headers */,
     
    3143631443                                E1FF8F5F1807442100132674 /* SubtleCrypto.cpp in Sources */,
    3143731444                                93B2D8180F9920EE006AE6B2 /* SuddenTermination.mm in Sources */,
     31445                                572A7F231C6E5A66009C6149 /* SimulatedClick.cpp in Sources */,
    3143831446                                087558C513B4A57D00F49307 /* SurrogatePairAwareTextIterator.cpp in Sources */,
    3143931447                                62C1217C11AB9E77003C462C /* SuspendableTimer.cpp in Sources */,
  • trunk/Source/WebCore/dom/Element.cpp

    r196560 r196598  
    7878#include "SelectorQuery.h"
    7979#include "Settings.h"
     80#include "SimulatedClick.h"
    8081#include "StyleProperties.h"
    8182#include "StyleResolver.h"
     
    313314void Element::dispatchSimulatedClick(Event* underlyingEvent, SimulatedClickMouseEventOptions eventOptions, SimulatedClickVisualOptions visualOptions)
    314315{
    315     EventDispatcher::dispatchSimulatedClick(this, underlyingEvent, eventOptions, visualOptions);
     316    simulateClick(*this, underlyingEvent, eventOptions, visualOptions, SimulatedClickCreationOptions::FromUserAgent);
     317}
     318
     319void Element::dispatchSimulatedClickForBindings(Event* underlyingEvent)
     320{
     321    simulateClick(*this, underlyingEvent, SendNoEvents, DoNotShowPressedLook, SimulatedClickCreationOptions::FromBindings);
    316322}
    317323
  • trunk/Source/WebCore/dom/Element.h

    r196430 r196598  
    460460    bool dispatchKeyEvent(const PlatformKeyboardEvent&);
    461461    void dispatchSimulatedClick(Event* underlyingEvent, SimulatedClickMouseEventOptions = SendNoEvents, SimulatedClickVisualOptions = ShowPressedLook);
     462    void dispatchSimulatedClickForBindings(Event* underlyingEvent);
    462463    void dispatchFocusInEvent(const AtomicString& eventType, RefPtr<Element>&& oldFocusedElement);
    463464    void dispatchFocusOutEvent(const AtomicString& eventType, RefPtr<Element>&& newFocusedElement);
  • trunk/Source/WebCore/dom/EventDispatcher.cpp

    r196009 r196598  
    126126}
    127127
    128 void EventDispatcher::dispatchSimulatedClick(Element* element, Event* underlyingEvent, SimulatedClickMouseEventOptions mouseEventOptions, SimulatedClickVisualOptions visualOptions)
    129 {
    130     if (element->isDisabledFormControl())
    131         return;
    132 
    133     static NeverDestroyed<HashSet<Element*>> elementsDispatchingSimulatedClicks;
    134     if (!elementsDispatchingSimulatedClicks.get().add(element).isNewEntry)
    135         return;
    136 
    137     if (mouseEventOptions == SendMouseOverUpDownEvents)
    138         dispatchEvent(element, SimulatedMouseEvent::create(eventNames().mouseoverEvent, element->document().defaultView(), underlyingEvent, element));
    139 
    140     if (mouseEventOptions != SendNoEvents)
    141         dispatchEvent(element, SimulatedMouseEvent::create(eventNames().mousedownEvent, element->document().defaultView(), underlyingEvent, element));
    142     element->setActive(true, visualOptions == ShowPressedLook);
    143     if (mouseEventOptions != SendNoEvents)
    144         dispatchEvent(element, SimulatedMouseEvent::create(eventNames().mouseupEvent, element->document().defaultView(), underlyingEvent, element));
    145     element->setActive(false);
    146 
    147     // always send click
    148     dispatchEvent(element, SimulatedMouseEvent::create(eventNames().clickEvent, element->document().defaultView(), underlyingEvent, element));
    149 
    150     elementsDispatchingSimulatedClicks.get().remove(element);
    151 }
    152 
    153128static void callDefaultEventHandlersInTheBubblingOrder(Event& event, const EventPath& path)
    154129{
  • trunk/Source/WebCore/dom/EventDispatcher.h

    r195927 r196598  
    4040bool dispatchEvent(Node*, Event&);
    4141void dispatchScopedEvent(Node&, Event&);
    42 void dispatchSimulatedClick(Element*, Event* underlyingEvent, SimulatedClickMouseEventOptions, SimulatedClickVisualOptions);
    4342
    4443}
  • trunk/Source/WebCore/dom/MouseEvent.cpp

    r196400 r196598  
    252252}
    253253
    254 Ref<SimulatedMouseEvent> SimulatedMouseEvent::create(const AtomicString& eventType, AbstractView* view, PassRefPtr<Event> underlyingEvent, Element* target)
    255 {
    256     return adoptRef(*new SimulatedMouseEvent(eventType, view, underlyingEvent, target));
    257 }
    258 
    259 SimulatedMouseEvent::~SimulatedMouseEvent()
    260 {
    261 }
    262 
    263 SimulatedMouseEvent::SimulatedMouseEvent(const AtomicString& eventType, AbstractView* view, PassRefPtr<Event> underlyingEvent, Element* target)
    264     : MouseEvent(eventType, true, true, underlyingEvent ? underlyingEvent->timeStamp() : currentTime(), view, 0, 0, 0, 0, 0,
    265 #if ENABLE(POINTER_LOCK)
    266                  0, 0,
    267 #endif
    268                  false, false, false, false, 0, 0, 0, 0, true)
    269 {
    270     if (UIEventWithKeyState* keyStateEvent = findEventWithKeyState(underlyingEvent.get())) {
    271         m_ctrlKey = keyStateEvent->ctrlKey();
    272         m_altKey = keyStateEvent->altKey();
    273         m_shiftKey = keyStateEvent->shiftKey();
    274         m_metaKey = keyStateEvent->metaKey();
    275     }
    276     setUnderlyingEvent(underlyingEvent.get());
    277 
    278     if (is<MouseEvent>(this->underlyingEvent())) {
    279         MouseEvent& mouseEvent = downcast<MouseEvent>(*this->underlyingEvent());
    280         m_screenLocation = mouseEvent.screenLocation();
    281         initCoordinates(mouseEvent.clientLocation());
    282     } else if (target) {
    283         m_screenLocation = target->screenRect().center();
    284         initCoordinates(LayoutPoint(target->clientRect().center()));
    285     }
    286 }
    287 
    288254} // namespace WebCore
  • trunk/Source/WebCore/dom/MouseEvent.h

    r196400 r196598  
    3333
    3434struct MouseEventInit : public MouseRelatedEventInit {
    35     int clientX {0};
    36     int clientY {0};
    37     unsigned short button {0};
     35    int clientX { 0 };
     36    int clientY { 0 };
     37    unsigned short button { 0 };
    3838    RefPtr<EventTarget> relatedTarget;
    3939};
     
    130130};
    131131
    132 class SimulatedMouseEvent final : public MouseEvent {
    133 public:
    134     static Ref<SimulatedMouseEvent> create(const AtomicString& eventType, AbstractView*, PassRefPtr<Event> underlyingEvent, Element* target);
    135     virtual ~SimulatedMouseEvent();
    136 
    137 private:
    138     SimulatedMouseEvent(const AtomicString& eventType, AbstractView*, PassRefPtr<Event> underlyingEvent, Element* target);
    139 };
    140 
    141132} // namespace WebCore
    142133
  • trunk/Source/WebCore/html/HTMLElement.cpp

    r196123 r196598  
    810810void HTMLElement::click()
    811811{
    812     dispatchSimulatedClick(nullptr, SendNoEvents, DoNotShowPressedLook);
     812    dispatchSimulatedClickForBindings(nullptr);
    813813}
    814814
Note: See TracChangeset for help on using the changeset viewer.