Bug 1543315 - part 16: Mark PresShell::HandleEventWithTarget() as MOZ_CAN_RUN_SCRIPT r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 06 May 2019 13:15:05 +0000
changeset 531505 801ff1a58ffc0cbfa6641b31b7a030b53d5bc6d5
parent 531504 b4cbda10ffaf3584fcbc8df61a7c643979072891
child 531506 dae98f84b3f415d10c31cbe7d88778de8ebfe74c
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1543315
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1543315 - part 16: Mark PresShell::HandleEventWithTarget() as MOZ_CAN_RUN_SCRIPT r=smaug Differential Revision: https://phabricator.services.mozilla.com/D30011
dom/base/Element.cpp
dom/base/Element.h
dom/base/nsISelectionListener.idl
dom/events/EventStateManager.cpp
dom/events/EventStateManager.h
dom/events/PointerEventHandler.cpp
dom/events/PointerEventHandler.h
dom/html/HTMLLabelElement.cpp
dom/html/HTMLLabelElement.h
dom/html/TextInputListener.h
dom/html/nsTextEditorState.cpp
layout/base/PresShell.h
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -3151,17 +3151,17 @@ nsresult Element::PostHandleEventForLink
         aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
       }
     } break;
 
     case eKeyPress: {
       WidgetKeyboardEvent* keyEvent = aVisitor.mEvent->AsKeyboardEvent();
       if (keyEvent && keyEvent->mKeyCode == NS_VK_RETURN) {
         nsEventStatus status = nsEventStatus_eIgnore;
-        rv = DispatchClickEvent(aVisitor.mPresContext, keyEvent, this, false,
+        rv = DispatchClickEvent(MOZ_KnownLive(aVisitor.mPresContext), keyEvent, this, false,
                                 nullptr, &status);
         if (NS_SUCCEEDED(rv)) {
           aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
         }
       }
     } break;
 
     default:
--- a/dom/base/Element.h
+++ b/dom/base/Element.h
@@ -1363,30 +1363,32 @@ class Element : public FragmentOrElement
    * aSourceEvent. If aFullDispatch is true, the event will be dispatched
    * through the full dispatching of the presshell of the aPresContext; if it's
    * false the event will be dispatched only as a DOM event.
    * If aPresContext is nullptr, this does nothing.
    *
    * @param aFlags      Extra flags for the dispatching event.  The true flags
    *                    will be respected.
    */
+  MOZ_CAN_RUN_SCRIPT
   static nsresult DispatchClickEvent(nsPresContext* aPresContext,
                                      WidgetInputEvent* aSourceEvent,
                                      nsIContent* aTarget, bool aFullDispatch,
                                      const EventFlags* aFlags,
                                      nsEventStatus* aStatus);
 
   /**
    * Method to dispatch aEvent to aTarget. If aFullDispatch is true, the event
    * will be dispatched through the full dispatching of the presshell of the
    * aPresContext; if it's false the event will be dispatched only as a DOM
    * event.
    * If aPresContext is nullptr, this does nothing.
    */
   using nsIContent::DispatchEvent;
+  MOZ_CAN_RUN_SCRIPT
   static nsresult DispatchEvent(nsPresContext* aPresContext,
                                 WidgetEvent* aEvent, nsIContent* aTarget,
                                 bool aFullDispatch, nsEventStatus* aStatus);
 
   bool IsDisplayContents() const {
     return HasServoData() && Servo_Element_IsDisplayContents(this);
   }
 
--- a/dom/base/nsISelectionListener.idl
+++ b/dom/base/nsISelectionListener.idl
@@ -16,13 +16,14 @@ interface nsISelectionListener : nsISupp
   const short MOUSEDOWN_REASON=2;/*bitflags*/
   const short MOUSEUP_REASON=4;/*bitflags*/
   const short KEYPRESS_REASON=8;/*bitflags*/
   const short SELECTALL_REASON=16;
   const short COLLAPSETOSTART_REASON=32;
   const short COLLAPSETOEND_REASON=64;
   const short IME_REASON=128;
 
+  [can_run_script]
   void notifySelectionChanged(in Document doc, in Selection sel,
                               in short reason);
 };
 
 
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -4886,18 +4886,18 @@ nsresult EventStateManager::InitAndDispa
   if (!target->IsInComposedDoc()) {
     return NS_OK;
   }
 
   // Use local event status for each click event dispatching since it'll be
   // cleared by EventStateManager::PreHandleEvent().  Therefore, dispatching
   // an event means that previous event status will be ignored.
   nsEventStatus status = nsEventStatus_eIgnore;
-  nsresult rv =
-      aPresShell->HandleEventWithTarget(&event, targetFrame, target, &status);
+  nsresult rv = aPresShell->HandleEventWithTarget(
+      &event, targetFrame, MOZ_KnownLive(target), &status);
   // Copy mMultipleActionsPrevented flag from a click event to the mouseup
   // event only when it's set to true.  It may be set to true if an editor has
   // already handled it.  This is important to avoid two or more default
   // actions handled here.
   aMouseUpEvent->mFlags.mMultipleActionsPrevented |=
       event.mFlags.mMultipleActionsPrevented;
   // If current status is nsEventStatus_eConsumeNoDefault, we don't need to
   // overwrite it.
--- a/dom/events/EventStateManager.h
+++ b/dom/events/EventStateManager.h
@@ -1041,23 +1041,25 @@ class EventStateManager : public nsSuppo
 
   void SetGestureDownPoint(WidgetGUIEvent* aEvent);
 
   LayoutDeviceIntPoint GetEventRefPoint(WidgetEvent* aEvent) const;
 
   friend class mozilla::dom::BrowserParent;
   void BeginTrackingRemoteDragGesture(nsIContent* aContent);
   void StopTrackingDragGesture();
+  MOZ_CAN_RUN_SCRIPT
   void GenerateDragGesture(nsPresContext* aPresContext,
                            WidgetInputEvent* aEvent);
 
   /**
    * When starting a dnd session, UA must fire a pointercancel event and stop
    * firing the subsequent pointer events.
    */
+  MOZ_CAN_RUN_SCRIPT
   void MaybeFirePointerCancel(WidgetInputEvent* aEvent);
 
   /**
    * Determine which node the drag should be targeted at.
    * This is either the node clicked when there is a selection, or, for HTML,
    * the element with a draggable property set to true.
    *
    * aSelectionTarget - target to check for selection
--- a/dom/events/PointerEventHandler.cpp
+++ b/dom/events/PointerEventHandler.cpp
@@ -283,27 +283,28 @@ void PointerEventHandler::CheckPointerCa
   }
 
   if (!captureInfo ||
       captureInfo->mPendingContent == captureInfo->mOverrideContent) {
     return;
   }
   // cache captureInfo->mPendingContent since it may be changed in the pointer
   // event listener
-  nsIContent* pendingContent = captureInfo->mPendingContent.get();
+  nsCOMPtr<nsIContent> pendingContent = captureInfo->mPendingContent.get();
   if (captureInfo->mOverrideContent) {
+    nsCOMPtr<nsIContent> overrideContent = captureInfo->mOverrideContent;
     DispatchGotOrLostPointerCaptureEvent(/* aIsGotCapture */ false, aEvent,
-                                         captureInfo->mOverrideContent);
+                                         overrideContent);
   }
   if (pendingContent) {
     DispatchGotOrLostPointerCaptureEvent(/* aIsGotCapture */ true, aEvent,
                                          pendingContent);
   }
 
-  captureInfo->mOverrideContent = pendingContent;
+  captureInfo->mOverrideContent = std::move(pendingContent);
   if (captureInfo->Empty()) {
     sPointerCaptureList->Remove(aEvent->pointerId);
   }
 }
 
 /* static */
 void PointerEventHandler::ImplicitlyCapturePointer(nsIFrame* aFrame,
                                                    WidgetEvent* aEvent) {
--- a/dom/events/PointerEventHandler.h
+++ b/dom/events/PointerEventHandler.h
@@ -65,23 +65,28 @@ class PointerEventHandler final {
   // GetPointerInfo returns true if pointer with aPointerId is situated in
   // device, false otherwise.
   // aActiveState is additional information, which shows state of pointer like
   // button state for mouse.
   static bool GetPointerInfo(uint32_t aPointerId, bool& aActiveState);
 
   // CheckPointerCaptureState checks cases, when got/lostpointercapture events
   // should be fired.
+  MOZ_CAN_RUN_SCRIPT
   static void MaybeProcessPointerCapture(WidgetGUIEvent* aEvent);
+  MOZ_CAN_RUN_SCRIPT
   static void ProcessPointerCaptureForMouse(WidgetMouseEvent* aEvent);
+  MOZ_CAN_RUN_SCRIPT
   static void ProcessPointerCaptureForTouch(WidgetTouchEvent* aEvent);
+  MOZ_CAN_RUN_SCRIPT
   static void CheckPointerCaptureState(WidgetPointerEvent* aEvent);
 
   // Implicitly get and release capture of current pointer for touch.
   static void ImplicitlyCapturePointer(nsIFrame* aFrame, WidgetEvent* aEvent);
+  MOZ_CAN_RUN_SCRIPT
   static void ImplicitlyReleasePointerCapture(WidgetEvent* aEvent);
 
   /**
    * GetPointerCapturingContent returns a target content which captures the
    * pointer. It's applied to mouse or pointer event (except mousedown and
    * pointerdown). When capturing, return the content. Otherwise, nullptr.
    *
    * @param aEvent               A mouse event or pointer event which may be
@@ -162,16 +167,17 @@ class PointerEventHandler final {
   // event with pointerId. The return value must be one of
   // MouseEvent_Binding::MOZ_SOURCE_*
   static uint16_t GetPointerType(uint32_t aPointerId);
 
   // GetPointerPrimaryState returns state of attribute isPrimary for pointer
   // event with pointerId
   static bool GetPointerPrimaryState(uint32_t aPointerId);
 
+  MOZ_CAN_RUN_SCRIPT
   static void DispatchGotOrLostPointerCaptureEvent(
       bool aIsGotCapture, const WidgetPointerEvent* aPointerEvent,
       nsIContent* aCaptureTarget);
 
   // The cached spoofed pointer ID for fingerprinting resistance. We will use a
   // mouse pointer id for desktop. For mobile, we should use the touch pointer
   // id as the spoofed one, and this work will be addressed in Bug 1492775.
   static Maybe<int32_t> sSpoofedPointerId;
--- a/dom/html/HTMLLabelElement.cpp
+++ b/dom/html/HTMLLabelElement.cpp
@@ -155,18 +155,18 @@ nsresult HTMLLabelElement::PostHandleEve
           //    would do nothing.  If we wanted to do something
           //    sensible, we might send more events through like
           //    this.)  See bug 7554, bug 49897, and bug 96813.
           nsEventStatus status = aVisitor.mEventStatus;
           // Ok to use aVisitor.mEvent as parameter because DispatchClickEvent
           // will actually create a new event.
           EventFlags eventFlags;
           eventFlags.mMultipleActionsPrevented = true;
-          DispatchClickEvent(aVisitor.mPresContext, mouseEvent, content, false,
-                             &eventFlags, &status);
+          DispatchClickEvent(MOZ_KnownLive(aVisitor.mPresContext), mouseEvent,
+                             content, false, &eventFlags, &status);
           // Do we care about the status this returned?  I don't think we do...
           // Don't run another <label> off of this click
           mouseEvent->mFlags.mMultipleActionsPrevented = true;
         }
         break;
 
       default:
         break;
--- a/dom/html/HTMLLabelElement.h
+++ b/dom/html/HTMLLabelElement.h
@@ -42,16 +42,17 @@ class HTMLLabelElement final : public ns
   }
   nsGenericHTMLElement* GetControl() const { return GetLabeledElement(); }
 
   using nsGenericHTMLElement::Focus;
   virtual void Focus(const FocusOptions& aOptions,
                      ErrorResult& aError) override;
 
   // nsIContent
+  MOZ_CAN_RUN_SCRIPT_BOUNDARY
   virtual nsresult PostHandleEvent(EventChainPostVisitor& aVisitor) override;
   virtual bool PerformAccesskey(bool aKeyCausesActivation,
                                 bool aIsTrustedEvent) override;
   virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
 
   nsGenericHTMLElement* GetLabeledElement() const;
 
  protected:
--- a/dom/html/TextInputListener.h
+++ b/dom/html/TextInputListener.h
@@ -42,16 +42,17 @@ class TextInputListener final : public n
   /**
    * OnEditActionHandled() is called when the editor handles each edit action.
    */
   void OnEditActionHandled();
 
   /**
    * OnSelectionChange() is called when selection is changed in the editor.
    */
+  MOZ_CAN_RUN_SCRIPT
   void OnSelectionChange(dom::Selection& aSelection, int16_t aReason);
 
   /**
    * Start to listen or end listening to selection change in the editor.
    */
   void StartToListenToSelectionChange() { mListeningToSelectionChange = true; }
   void EndListeningToSelectionChange() { mListeningToSelectionChange = false; }
 
--- a/dom/html/nsTextEditorState.cpp
+++ b/dom/html/nsTextEditorState.cpp
@@ -799,22 +799,19 @@ void TextInputListener::OnSelectionChang
   //          create the event each time select all is called, even if
   //          everything was previously selected, becase technically select all
   //          will first collapse and then extend. Mozilla will never create an
   //          event if the selection collapses to nothing.
   bool collapsed = aSelection.IsCollapsed();
   if (!collapsed && (aReason & (nsISelectionListener::MOUSEUP_REASON |
                                 nsISelectionListener::KEYPRESS_REASON |
                                 nsISelectionListener::SELECTALL_REASON))) {
-    nsIContent* content = mFrame->GetContent();
-    if (content) {
-      nsCOMPtr<Document> doc = content->GetComposedDoc();
-      if (doc) {
-        RefPtr<PresShell> presShell = doc->GetPresShell();
-        if (presShell) {
+    if (nsCOMPtr<nsIContent> content = mFrame->GetContent()) {
+      if (nsCOMPtr<Document> doc = content->GetComposedDoc()) {
+        if (RefPtr<PresShell> presShell = doc->GetPresShell()) {
           nsEventStatus status = nsEventStatus_eIgnore;
           WidgetEvent event(true, eFormSelect);
 
           presShell->HandleEventWithTarget(&event, mFrame, content, &status);
         }
       }
     }
   }
--- a/layout/base/PresShell.h
+++ b/layout/base/PresShell.h
@@ -633,17 +633,17 @@ class PresShell final : public nsStubDoc
   already_AddRefed<nsISelectionController>
   GetSelectionControllerForFocusedContent(
       nsIContent** aFocusedContent = nullptr);
 
   /**
    * Interface to dispatch events via the presshell
    * @note The caller must have a strong reference to the PresShell.
    */
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY
+  MOZ_CAN_RUN_SCRIPT
   nsresult HandleEventWithTarget(WidgetEvent* aEvent, nsIFrame* aFrame,
                                  nsIContent* aContent,
                                  nsEventStatus* aEventStatus,
                                  bool aIsHandlingNativeEvent = false,
                                  nsIContent** aTargetContent = nullptr,
                                  nsIContent* aOverrideClickTarget = nullptr) {
     MOZ_ASSERT(aEvent);
     EventHandler eventHandler(*this);