Bug 1549270 - part 2: Mark EditorBase::RemoveAttributeWithTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 08 May 2019 05:09:56 +0000
changeset 531823 7755efc24f6d991b81598fca36a126f0fb1f565d
parent 531822 e9e1b9c2cab6cfa713c6119c5b32b1a928faa4f9
child 531824 8b9baadda0a72a67b359b2cbfad5de61565a4517
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)
reviewersm_kato
bugs1549270
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 1549270 - part 2: Mark EditorBase::RemoveAttributeWithTransaction() as MOZ_CAN_RUN_SCRIPT r=m_kato Differential Revision: https://phabricator.services.mozilla.com/D30044
editor/libeditor/EditorBase.cpp
editor/libeditor/EditorBase.h
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditor.h
editor/libeditor/HTMLStyleEditor.cpp
editor/nsIEditor.idl
editor/nsIHTMLEditor.idl
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -2373,18 +2373,18 @@ void EditorBase::CloneAttributesWithTran
   OwningNonNull<Element> destElement(aDestElement);
   OwningNonNull<Element> sourceElement(aSourceElement);
   bool isDestElementInBody = rootElement->Contains(destElement);
 
   // Clear existing attributes
   RefPtr<nsDOMAttributeMap> destAttributes = destElement->Attributes();
   while (RefPtr<Attr> attr = destAttributes->Item(0)) {
     if (isDestElementInBody) {
-      RemoveAttributeWithTransaction(destElement,
-                                     *attr->NodeInfo()->NameAtom());
+      RemoveAttributeWithTransaction(
+          destElement, MOZ_KnownLive(*attr->NodeInfo()->NameAtom()));
     } else {
       destElement->UnsetAttr(kNameSpaceID_None, attr->NodeInfo()->NameAtom(),
                              true);
     }
   }
 
   // Set just the attributes that the source element has
   RefPtr<nsDOMAttributeMap> sourceAttributes = sourceElement->Attributes();
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -1184,16 +1184,17 @@ class EditorBase : public nsIEditor,
                                          Element& aSourceElement);
 
   /**
    * RemoveAttributeWithTransaction() removes aAttribute from aElement.
    *
    * @param aElement        Element node which will lose aAttribute.
    * @param aAttribute      Attribute name to be removed from aElement.
    */
+  MOZ_CAN_RUN_SCRIPT
   nsresult RemoveAttributeWithTransaction(Element& aElement,
                                           nsAtom& aAttribute);
 
   MOZ_CAN_RUN_SCRIPT
   virtual nsresult RemoveAttributeOrEquivalent(Element* aElement,
                                                nsAtom* aAttribute,
                                                bool aSuppressTransaction) = 0;
 
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -4172,18 +4172,18 @@ nsresult HTMLEditRules::MakeList(nsAtom&
             *curElement, *nsGkAtoms::type, *aBulletType);
         if (NS_WARN_IF(!CanHandleEditAction())) {
           return NS_ERROR_EDITOR_DESTROYED;
         }
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
       } else {
-        rv = HTMLEditorRef().RemoveAttributeWithTransaction(*curElement,
-                                                            *nsGkAtoms::type);
+        rv = MOZ_KnownLive(HTMLEditorRef())
+                 .RemoveAttributeWithTransaction(*curElement, *nsGkAtoms::type);
         if (NS_WARN_IF(!CanHandleEditAction())) {
           return NS_ERROR_EDITOR_DESTROYED;
         }
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
       }
       continue;
@@ -8084,18 +8084,18 @@ nsresult HTMLEditRules::SplitParagraph(
       return NS_ERROR_EDITOR_DESTROYED;
     }
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
   // Remove ID attribute on the paragraph from the existing right node.
-  rv = HTMLEditorRef().RemoveAttributeWithTransaction(aParentDivOrP,
-                                                      *nsGkAtoms::id);
+  rv = MOZ_KnownLive(HTMLEditorRef())
+           .RemoveAttributeWithTransaction(aParentDivOrP, *nsGkAtoms::id);
   if (NS_WARN_IF(!CanHandleEditAction())) {
     return NS_ERROR_EDITOR_DESTROYED;
   }
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // We need to ensure to both paragraphs visible even if they are empty.
@@ -10266,18 +10266,20 @@ nsresult HTMLEditRules::RemoveAlignment(
       }
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     } else if (IsBlockNode(*child) || child->IsHTMLElement(nsGkAtoms::hr)) {
       // the current node is a block element
       if (HTMLEditUtils::SupportsAlignAttr(*child)) {
         // remove the ALIGN attribute if this element can have it
-        nsresult rv = HTMLEditorRef().RemoveAttributeWithTransaction(
-            *child->AsElement(), *nsGkAtoms::align);
+        nsresult rv =
+            MOZ_KnownLive(HTMLEditorRef())
+                .RemoveAttributeWithTransaction(
+                    MOZ_KnownLive(*child->AsElement()), *nsGkAtoms::align);
         if (NS_WARN_IF(!CanHandleEditAction())) {
           return NS_ERROR_EDITOR_DESTROYED;
         }
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
       }
       if (useCSS) {
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -1541,16 +1541,17 @@ class HTMLEditor final : public TextEdit
 
   static nsresult GetCellFromRange(nsRange* aRange, Element** aCell);
 
   /**
    * This sets background on the appropriate container element (table, cell,)
    * or calls into nsTextEditor to set the page background.
    */
   nsresult SetCSSBackgroundColorWithTransaction(const nsAString& aColor);
+  MOZ_CAN_RUN_SCRIPT
   nsresult SetHTMLBackgroundColorWithTransaction(const nsAString& aColor);
 
   virtual void InitializeSelectionAncestorLimit(
       nsIContent& aAncestorLimit) override;
 
   /**
    * Make the given selection span the entire document.
    */
--- a/editor/libeditor/HTMLStyleEditor.cpp
+++ b/editor/libeditor/HTMLStyleEditor.cpp
@@ -824,18 +824,18 @@ nsresult HTMLEditor::RemoveStyleInside(n
         // then remove the whole node.  Otherwise just nix the attribute.
         if (IsOnlyAttribute(aNode.AsElement(), aAttribute)) {
           nsresult rv =
               RemoveContainerWithTransaction(MOZ_KnownLive(*aNode.AsElement()));
           if (NS_WARN_IF(NS_FAILED(rv))) {
             return rv;
           }
         } else {
-          nsresult rv =
-              RemoveAttributeWithTransaction(*aNode.AsElement(), *aAttribute);
+          nsresult rv = RemoveAttributeWithTransaction(
+              MOZ_KnownLive(*aNode.AsElement()), *aAttribute);
           if (NS_WARN_IF(NS_FAILED(rv))) {
             return rv;
           }
         }
       }
     }
   }
 
--- a/editor/nsIEditor.idl
+++ b/editor/nsIEditor.idl
@@ -359,16 +359,17 @@ interface nsIEditor  : nsISupports
 
   /**
    * removeAttribute() deletes aAttribute from the attribute list of aElement.
    * If aAttribute is not an attribute of aElement, nothing is done.
    *
    * @param aElement      the content element to operate on
    * @param aAttribute    the string representation of the attribute to get
    */
+  [can_run_script]
   void removeAttribute(in Element aElement,
                        in AString aAttribute);
 
   /**
    * cloneAttribute() copies the attribute from the source node to
    * the destination node and delete those not in the source.
    *
    * The supplied nodes MUST BE ELEMENTS (most callers are working with nodes)
--- a/editor/nsIHTMLEditor.idl
+++ b/editor/nsIHTMLEditor.idl
@@ -381,16 +381,17 @@ interface nsIHTMLEditor : nsISupports
   [can_run_script]
   void insertLinkAroundSelection(in Element aAnchorElement);
 
   /**
    * Set the value of the "bgcolor" attribute on the document's <body> element
    *
    * @param aColor  The HTML color string, such as "#ffccff" or "yellow"
    */
+  [can_run_script]
   void setBackgroundColor(in AString aColor);
 
   /**
    * Find all the nodes in the document which contain references
    * to outside URIs (e.g. a href, img src, script src, etc.)
    * The objects in the array will be type nsIURIRefObject.
    *
    * @return aNodeList    the linked nodes found