Bug 1599971 - part 5: Mark `TextControlState::BindToFrame()` and `TextControlState::UnbindFromFrame()` as `MOZ_CAN_RUN_SCRIPT` r=m_kato! draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 04 Dec 2019 13:05:13 +0900
changeset 2514402 4c767cd9cb8237dd174afef8d2122ec59dae1235
parent 2514401 23a86617e5ae2a227ae654597bcce8b6c097c541
child 2514403 01e8278a60a85fc11cac65c668b4dfd7a420fe97
push id459907
push usermasayuki@d-toybox.com
push dateWed, 04 Dec 2019 12:49:29 +0000
treeherdertry@ee01a7f649cb [default view] [failures only]
reviewersm_kato
bugs1599971
milestone73.0a1
Bug 1599971 - part 5: Mark `TextControlState::BindToFrame()` and `TextControlState::UnbindFromFrame()` as `MOZ_CAN_RUN_SCRIPT` r=m_kato! Differential Revision: https://phabricator.services.mozilla.com/D55776
dom/html/HTMLInputElement.h
dom/html/HTMLTextAreaElement.h
dom/html/TextControlElement.h
dom/html/TextControlState.cpp
dom/html/TextControlState.h
layout/forms/nsTextControlFrame.h
--- a/dom/html/HTMLInputElement.h
+++ b/dom/html/HTMLInputElement.h
@@ -227,18 +227,19 @@ class HTMLInputElement final : public Te
                                   bool aIgnoreWrap) const override;
   MOZ_CAN_RUN_SCRIPT TextEditor* GetTextEditor() override;
   virtual TextEditor* GetTextEditorWithoutCreation() override;
   virtual nsISelectionController* GetSelectionController() override;
   virtual nsFrameSelection* GetConstFrameSelection() override;
   virtual TextControlState* GetTextControlState() const override {
     return GetEditorState();
   }
-  virtual nsresult BindToFrame(nsTextControlFrame* aFrame) override;
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual void UnbindFromFrame(
+  MOZ_CAN_RUN_SCRIPT virtual nsresult BindToFrame(
+      nsTextControlFrame* aFrame) override;
+  MOZ_CAN_RUN_SCRIPT virtual void UnbindFromFrame(
       nsTextControlFrame* aFrame) override;
   MOZ_CAN_RUN_SCRIPT virtual nsresult CreateEditor() override;
   virtual void UpdateOverlayTextVisibility(bool aNotify) override;
   virtual void SetPreviewValue(const nsAString& aValue) override;
   virtual void GetPreviewValue(nsAString& aValue) override;
   virtual void EnablePreview() override;
   virtual bool IsPreviewEnabled() override;
   virtual bool GetPlaceholderVisibility() override;
--- a/dom/html/HTMLTextAreaElement.h
+++ b/dom/html/HTMLTextAreaElement.h
@@ -82,18 +82,19 @@ class HTMLTextAreaElement final : public
                                   bool aIgnoreWrap) const override;
   MOZ_CAN_RUN_SCRIPT virtual TextEditor* GetTextEditor() override;
   virtual TextEditor* GetTextEditorWithoutCreation() override;
   virtual nsISelectionController* GetSelectionController() override;
   virtual nsFrameSelection* GetConstFrameSelection() override;
   virtual TextControlState* GetTextControlState() const override {
     return mState;
   }
-  virtual nsresult BindToFrame(nsTextControlFrame* aFrame) override;
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual void UnbindFromFrame(
+  MOZ_CAN_RUN_SCRIPT virtual nsresult BindToFrame(
+      nsTextControlFrame* aFrame) override;
+  MOZ_CAN_RUN_SCRIPT virtual void UnbindFromFrame(
       nsTextControlFrame* aFrame) override;
   MOZ_CAN_RUN_SCRIPT virtual nsresult CreateEditor() override;
   virtual void UpdateOverlayTextVisibility(bool aNotify) override;
   virtual bool GetPlaceholderVisibility() override;
   virtual bool GetPreviewVisibility() override;
   virtual void SetPreviewValue(const nsAString& aValue) override;
   virtual void GetPreviewValue(nsAString& aValue) override;
   virtual void EnablePreview() override;
--- a/dom/html/TextControlElement.h
+++ b/dom/html/TextControlElement.h
@@ -122,23 +122,24 @@ class TextControlElement : public nsGene
   virtual nsFrameSelection* GetConstFrameSelection() = 0;
 
   virtual TextControlState* GetTextControlState() const = 0;
 
   /**
    * Binds a frame to the text control.  This is performed when a frame
    * is created for the content node.
    */
-  virtual nsresult BindToFrame(nsTextControlFrame* aFrame) = 0;
+  MOZ_CAN_RUN_SCRIPT virtual nsresult BindToFrame(
+      nsTextControlFrame* aFrame) = 0;
 
   /**
    * Unbinds a frame from the text control.  This is performed when a frame
    * belonging to a content node is destroyed.
    */
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual void UnbindFromFrame(
+  MOZ_CAN_RUN_SCRIPT virtual void UnbindFromFrame(
       nsTextControlFrame* aFrame) = 0;
 
   /**
    * Creates an editor for the text control.  This should happen when
    * a frame has been created for the text control element, but the created
    * editor may outlive the frame itself.
    */
   MOZ_CAN_RUN_SCRIPT virtual nsresult CreateEditor() = 0;
--- a/dom/html/TextControlState.cpp
+++ b/dom/html/TextControlState.cpp
@@ -1070,23 +1070,25 @@ nsresult TextInputListener::UpdateTextIn
  *
  * This class is temporarily created in the stack and can manage nested
  * handling state of TextControlState.  While this instance exists, lifetime of
  * TextControlState which created the instance is guaranteed.  In other words,
  * you can use this class as "kungFuDeathGrip" for TextControlState.
  *****************************************************************************/
 
 enum class TextControlAction {
+  BindToFrame,
   CacheForReuse,
   CommitComposition,
   Destructor,
   PrepareEditor,
   SetRangeText,
   SetSelectionRange,
   SetValue,
+  UnbindFromFrame,
   Unlink,
 };
 
 class MOZ_STACK_CLASS AutoTextControlHandlingState {
  public:
   AutoTextControlHandlingState() = delete;
   explicit AutoTextControlHandlingState(const AutoTextControlHandlingState&) =
       delete;
@@ -1542,17 +1544,17 @@ class PrepareEditorEvent : public Runnab
                      const nsAString& aCurrentValue)
       : Runnable("PrepareEditorEvent"),
         mState(&aState),
         mOwnerContent(aOwnerContent),
         mCurrentValue(aCurrentValue) {
     aState.mValueTransferInProgress = true;
   }
 
-  NS_IMETHOD Run() override {
+  MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHOD Run() override {
     if (NS_WARN_IF(!mState)) {
       return NS_ERROR_NULL_POINTER;
     }
 
     // Transfer the saved value to the editor if we have one
     const nsAString* value = nullptr;
     if (!mCurrentValue.IsEmpty()) {
       value = &mCurrentValue;
@@ -1586,16 +1588,19 @@ nsresult TextControlState::BindToFrame(n
 
   // If we'll need to transfer our current value to the editor, save it before
   // binding to the frame.
   nsAutoString currentValue;
   if (mTextEditor) {
     GetValue(currentValue, true);
   }
 
+  AutoTextControlHandlingState handlingBindToFrame(
+      *this, TextControlAction::BindToFrame);
+
   mBoundFrame = aFrame;
 
   Element* rootNode = aFrame->GetRootNode();
   MOZ_ASSERT(rootNode);
 
   PresShell* presShell = aFrame->PresContext()->GetPresShell();
   MOZ_ASSERT(presShell);
 
@@ -2396,16 +2401,19 @@ void TextControlState::UnbindFromFrame(n
   }
 
   // If it was, however, it should be unbounded from the same frame.
   MOZ_ASSERT(aFrame == mBoundFrame, "Unbinding from the wrong frame");
   if (aFrame && aFrame != mBoundFrame) {
     return;
   }
 
+  AutoTextControlHandlingState handlingUnbindFromFrame(
+      *this, TextControlAction::UnbindFromFrame);
+
   // We need to start storing the value outside of the editor if we're not
   // going to use it anymore, so retrieve it for now.
   nsAutoString value;
   GetValue(value, true);
 
   if (mRestoringSelection) {
     mRestoringSelection->Revoke();
     mRestoringSelection = nullptr;
--- a/dom/html/TextControlState.h
+++ b/dom/html/TextControlState.h
@@ -161,20 +161,19 @@ class TextControlState final : public Su
   MOZ_CAN_RUN_SCRIPT_BOUNDARY void Unlink();
 
   bool IsBusy() const { return !!mHandlingState || mValueTransferInProgress; }
 
   MOZ_CAN_RUN_SCRIPT TextEditor* GetTextEditor();
   TextEditor* GetTextEditorWithoutCreation();
   nsISelectionController* GetSelectionController() const;
   nsFrameSelection* GetConstFrameSelection();
-  nsresult BindToFrame(nsTextControlFrame* aFrame);
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY void UnbindFromFrame(nsTextControlFrame* aFrame);
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult
-  PrepareEditor(const nsAString* aValue = nullptr);
+  MOZ_CAN_RUN_SCRIPT nsresult BindToFrame(nsTextControlFrame* aFrame);
+  MOZ_CAN_RUN_SCRIPT void UnbindFromFrame(nsTextControlFrame* aFrame);
+  MOZ_CAN_RUN_SCRIPT nsresult PrepareEditor(const nsAString* aValue = nullptr);
   void InitializeKeyboardEventListeners();
 
   /**
    * OnEditActionHandled() is called when mTextEditor handles something
    * and immediately before dispatching "input" event.
    */
   MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult OnEditActionHandled();
 
--- a/layout/forms/nsTextControlFrame.h
+++ b/layout/forms/nsTextControlFrame.h
@@ -36,18 +36,18 @@ class nsTextControlFrame final : public 
   NS_DECL_FRAMEARENA_HELPERS(nsTextControlFrame)
 
   NS_DECLARE_FRAME_PROPERTY_DELETABLE(ContentScrollPos, nsPoint)
 
   explicit nsTextControlFrame(ComputedStyle* aStyle,
                               nsPresContext* aPresContext);
   virtual ~nsTextControlFrame();
 
-  virtual void DestroyFrom(nsIFrame* aDestructRoot,
-                           PostDestroyData& aPostDestroyData) override;
+  MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual void DestroyFrom(
+      nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData) override;
 
   virtual nsIScrollableFrame* GetScrollTargetFrame() override {
     return do_QueryFrame(PrincipalChildList().FirstChild());
   }
 
   virtual nscoord GetMinISize(gfxContext* aRenderingContext) override;
   virtual nscoord GetPrefISize(gfxContext* aRenderingContext) override;
 
@@ -105,17 +105,17 @@ class nsTextControlFrame final : public 
 #ifdef DEBUG
   void MarkIntrinsicISizesDirty() override {
     // Need another Reflow to have a correct baseline value again.
     mFirstBaseline = NS_INTRINSIC_ISIZE_UNKNOWN;
   }
 #endif
 
   // nsIAnonymousContentCreator
-  virtual nsresult CreateAnonymousContent(
+  MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual nsresult CreateAnonymousContent(
       nsTArray<ContentInfo>& aElements) override;
   virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
                                         uint32_t aFilter) override;
 
   virtual void SetInitialChildList(ChildListID aListID,
                                    nsFrameList& aChildList) override;
 
   virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,