Bug 1546578 - part 10: Mark methods of editor command classes as far as possible r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 27 Apr 2019 07:37:19 +0000
changeset 530503 a0c695448d6e69bfd315a233cef61147d9b75bdb
parent 530502 7c45189445aab81ca8032e963fd66ecf394157c2
child 530504 e3f73de9200d562c134c39e5dceaa96f67c1d012
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
bugs1546578
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 1546578 - part 10: Mark methods of editor command classes as far as possible r=m_kato Differential Revision: https://phabricator.services.mozilla.com/D28698
editor/libeditor/EditorCommands.cpp
editor/libeditor/EditorCommands.h
editor/libeditor/HTMLEditorCommands.cpp
--- a/editor/libeditor/EditorCommands.cpp
+++ b/editor/libeditor/EditorCommands.cpp
@@ -36,17 +36,17 @@ NS_IMETHODIMP
 EditorCommand::IsCommandEnabled(const char* aCommandName,
                                 nsISupports* aCommandRefCon, bool* aIsEnabled) {
   if (NS_WARN_IF(!aCommandName) || NS_WARN_IF(!aIsEnabled)) {
     return NS_ERROR_INVALID_ARG;
   }
 
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
   TextEditor* textEditor = editor ? editor->AsTextEditor() : nullptr;
-  *aIsEnabled = IsCommandEnabled(aCommandName, textEditor);
+  *aIsEnabled = IsCommandEnabled(aCommandName, MOZ_KnownLive(textEditor));
   return NS_OK;
 }
 
 NS_IMETHODIMP
 EditorCommand::DoCommand(const char* aCommandName,
                          nsISupports* aCommandRefCon) {
   if (NS_WARN_IF(!aCommandName) || NS_WARN_IF(!aCommandRefCon)) {
     return NS_ERROR_INVALID_ARG;
@@ -86,26 +86,29 @@ NS_IMETHODIMP
 EditorCommand::GetCommandStateParams(const char* aCommandName,
                                      nsICommandParams* aParams,
                                      nsISupports* aCommandRefCon) {
   if (NS_WARN_IF(!aCommandName) || NS_WARN_IF(!aParams)) {
     return NS_ERROR_INVALID_ARG;
   }
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
   if (editor) {
-    return GetCommandStateParams(aCommandName, *aParams->AsCommandParams(),
-                                 editor->AsTextEditor(), nullptr);
+    return GetCommandStateParams(
+        aCommandName, MOZ_KnownLive(*aParams->AsCommandParams()),
+        MOZ_KnownLive(editor->AsTextEditor()), nullptr);
   }
   nsCOMPtr<nsIEditingSession> editingSession =
       do_QueryInterface(aCommandRefCon);
   if (editingSession) {
-    return GetCommandStateParams(aCommandName, *aParams->AsCommandParams(),
+    return GetCommandStateParams(aCommandName,
+                                 MOZ_KnownLive(*aParams->AsCommandParams()),
                                  nullptr, editingSession);
   }
-  return GetCommandStateParams(aCommandName, *aParams->AsCommandParams(),
+  return GetCommandStateParams(aCommandName,
+                               MOZ_KnownLive(*aParams->AsCommandParams()),
                                nullptr, nullptr);
 }
 
 /******************************************************************************
  * mozilla::UndoCommand
  ******************************************************************************/
 
 StaticRefPtr<UndoCommand> UndoCommand::sInstance;
--- a/editor/libeditor/EditorCommands.h
+++ b/editor/libeditor/EditorCommands.h
@@ -29,30 +29,33 @@ class TextEditor;
  */
 
 class EditorCommand : public nsIControllerCommand {
  public:
   NS_DECL_ISUPPORTS
 
   // nsIControllerCommand methods.  Use EditorCommand specific methods instead
   // for internal use.
+  MOZ_CAN_RUN_SCRIPT_BOUNDARY
   NS_IMETHOD IsCommandEnabled(const char* aCommandName,
                               nsISupports* aCommandRefCon,
                               bool* aIsEnabled) final;
   MOZ_CAN_RUN_SCRIPT
   NS_IMETHOD DoCommand(const char* aCommandName,
                        nsISupports* aCommandRefCon) final;
   MOZ_CAN_RUN_SCRIPT
   NS_IMETHOD DoCommandParams(const char* aCommandName,
                              nsICommandParams* aParams,
                              nsISupports* aCommandRefCon) final;
+  MOZ_CAN_RUN_SCRIPT_BOUNDARY
   NS_IMETHOD GetCommandStateParams(const char* aCommandName,
                                    nsICommandParams* aParams,
                                    nsISupports* aCommandRefCon) final;
 
+  MOZ_CAN_RUN_SCRIPT
   virtual bool IsCommandEnabled(const char* aCommandName,
                                 TextEditor* aTextEditor) const = 0;
   MOZ_CAN_RUN_SCRIPT
   virtual nsresult DoCommand(const char* aCommandName,
                              TextEditor& aTextEditor) const = 0;
   MOZ_CAN_RUN_SCRIPT
   virtual nsresult DoCommandParams(const char* aCommandName,
                                    nsCommandParams* aParams,
@@ -60,39 +63,42 @@ class EditorCommand : public nsIControll
   /**
    * @param aTextEditor         If the context is an editor, should be set to
    *                            it.  Otherwise, nullptr.
    * @param aEditingSession     If the context is an editing session, should be
    *                            set to it.  This usually occurs if editor has
    *                            not been created yet during initialization.
    *                            Otherwise, nullptr.
    */
+  MOZ_CAN_RUN_SCRIPT
   virtual nsresult GetCommandStateParams(
       const char* aCommandName, nsCommandParams& aParams,
       TextEditor* aTextEditor, nsIEditingSession* aEditingSession) const = 0;
 
  protected:
   EditorCommand() = default;
   virtual ~EditorCommand() = default;
 };
 
 #define NS_DECL_EDITOR_COMMAND_METHODS(_cmd)                             \
  public:                                                                 \
+  MOZ_CAN_RUN_SCRIPT                                                     \
   virtual bool IsCommandEnabled(const char* aCommandName,                \
                                 TextEditor* aTextEditor) const final;    \
   using EditorCommand::IsCommandEnabled;                                 \
   MOZ_CAN_RUN_SCRIPT                                                     \
   virtual nsresult DoCommand(const char* aCommandName,                   \
                              TextEditor& aTextEditor) const final;       \
   using EditorCommand::DoCommand;                                        \
   MOZ_CAN_RUN_SCRIPT                                                     \
   virtual nsresult DoCommandParams(const char* aCommandName,             \
                                    nsCommandParams* aParams,             \
                                    TextEditor& aTextEditor) const final; \
   using EditorCommand::DoCommandParams;                                  \
+  MOZ_CAN_RUN_SCRIPT                                                     \
   virtual nsresult GetCommandStateParams(                                \
       const char* aCommandName, nsCommandParams& aParams,                \
       TextEditor* aTextEditor, nsIEditingSession* aEditingSession)       \
       const final;                                                       \
   using EditorCommand::GetCommandStateParams;
 
 #define NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(_cmd) \
  public:                                                   \
@@ -152,20 +158,19 @@ class StateUpdatingCommandBase : public 
 
   NS_DECL_EDITOR_COMMAND_METHODS(StateUpdatingCommandBase)
 
  protected:
   StateUpdatingCommandBase() = default;
   virtual ~StateUpdatingCommandBase() { sTagNameTable.Clear(); }
 
   // get the current state (on or off) for this style or block format
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY  // XXX Needs to change nsIControllerCommand.idl
-      virtual nsresult
-      GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
-                      nsCommandParams& aParams) const = 0;
+  MOZ_CAN_RUN_SCRIPT
+  virtual nsresult GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
+                                   nsCommandParams& aParams) const = 0;
 
   // add/remove the style
   MOZ_CAN_RUN_SCRIPT
   virtual nsresult ToggleState(nsAtom* aTagName,
                                HTMLEditor* aHTMLEditor) const = 0;
 
   static already_AddRefed<nsAtom> TagName(const char* aCommandName) {
     MOZ_DIAGNOSTIC_ASSERT(aCommandName);
@@ -210,20 +215,19 @@ class StyleUpdatingCommand final : publi
  public:
   NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(StyleUpdatingCommand)
 
  protected:
   StyleUpdatingCommand() = default;
   virtual ~StyleUpdatingCommand() = default;
 
   // get the current state (on or off) for this style or block format
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY  // XXX Needs to change nsIControllerCommand.idl
-      nsresult
-      GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
-                      nsCommandParams& aParams) const final;
+  MOZ_CAN_RUN_SCRIPT
+  nsresult GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
+                           nsCommandParams& aParams) const final;
 
   // add/remove the style
   MOZ_CAN_RUN_SCRIPT
   nsresult ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor) const final;
 };
 
 class InsertTagCommand final : public EditorCommand {
  public:
@@ -258,195 +262,184 @@ class ListCommand final : public StateUp
  public:
   NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(ListCommand)
 
  protected:
   ListCommand() = default;
   virtual ~ListCommand() = default;
 
   // get the current state (on or off) for this style or block format
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY  // XXX Needs to change nsIControllerCommand.idl
-      nsresult
-      GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
-                      nsCommandParams& aParams) const final;
+  MOZ_CAN_RUN_SCRIPT
+  nsresult GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
+                           nsCommandParams& aParams) const final;
 
   // add/remove the style
   MOZ_CAN_RUN_SCRIPT
   nsresult ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor) const final;
 };
 
 class ListItemCommand final : public StateUpdatingCommandBase {
  public:
   NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(ListItemCommand)
 
  protected:
   ListItemCommand() = default;
   virtual ~ListItemCommand() = default;
 
   // get the current state (on or off) for this style or block format
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY  // XXX Needs to change nsIControllerCommand.idl
-      nsresult
-      GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
-                      nsCommandParams& aParams) const final;
+  MOZ_CAN_RUN_SCRIPT
+  nsresult GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
+                           nsCommandParams& aParams) const final;
 
   // add/remove the style
   MOZ_CAN_RUN_SCRIPT
   nsresult ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor) const final;
 };
 
 // Base class for commands whose state consists of a string (e.g. para format)
 class MultiStateCommandBase : public EditorCommand {
  public:
   NS_INLINE_DECL_REFCOUNTING_INHERITED(MultiStateCommandBase, EditorCommand)
   NS_DECL_EDITOR_COMMAND_METHODS(MultiStateCommandBase)
 
  protected:
   MultiStateCommandBase() = default;
   virtual ~MultiStateCommandBase() = default;
 
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY  // XXX Needs to change nsIControllerCommand.idl
-      virtual nsresult
-      GetCurrentState(HTMLEditor* aHTMLEditor,
-                      nsCommandParams& aParams) const = 0;
+  MOZ_CAN_RUN_SCRIPT
+  virtual nsresult GetCurrentState(HTMLEditor* aHTMLEditor,
+                                   nsCommandParams& aParams) const = 0;
   MOZ_CAN_RUN_SCRIPT
   virtual nsresult SetState(HTMLEditor* aHTMLEditor,
                             const nsString& newState) const = 0;
 };
 
 class ParagraphStateCommand final : public MultiStateCommandBase {
  public:
   NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(ParagraphStateCommand)
 
  protected:
   ParagraphStateCommand() = default;
   virtual ~ParagraphStateCommand() = default;
 
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY  // XXX Needs to change nsIControllerCommand.idl
-      nsresult
-      GetCurrentState(HTMLEditor* aHTMLEditor,
-                      nsCommandParams& aParams) const final;
+  MOZ_CAN_RUN_SCRIPT
+  nsresult GetCurrentState(HTMLEditor* aHTMLEditor,
+                           nsCommandParams& aParams) const final;
   MOZ_CAN_RUN_SCRIPT
   nsresult SetState(HTMLEditor* aHTMLEditor,
                     const nsString& newState) const final;
 };
 
 class FontFaceStateCommand final : public MultiStateCommandBase {
  public:
   NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(FontFaceStateCommand)
 
  protected:
   FontFaceStateCommand() = default;
   virtual ~FontFaceStateCommand() = default;
 
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY  // XXX Needs to change nsIControllerCommand.idl
-      nsresult
-      GetCurrentState(HTMLEditor* aHTMLEditor,
-                      nsCommandParams& aParams) const final;
+  MOZ_CAN_RUN_SCRIPT
+  nsresult GetCurrentState(HTMLEditor* aHTMLEditor,
+                           nsCommandParams& aParams) const final;
   MOZ_CAN_RUN_SCRIPT
   nsresult SetState(HTMLEditor* aHTMLEditor,
                     const nsString& newState) const final;
 };
 
 class FontSizeStateCommand final : public MultiStateCommandBase {
  public:
   NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(FontSizeStateCommand)
 
  protected:
   FontSizeStateCommand() = default;
   virtual ~FontSizeStateCommand() = default;
 
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY  // XXX Needs to change nsIControllerCommand.idl
-      nsresult
-      GetCurrentState(HTMLEditor* aHTMLEditor,
-                      nsCommandParams& aParams) const final;
+  MOZ_CAN_RUN_SCRIPT
+  nsresult GetCurrentState(HTMLEditor* aHTMLEditor,
+                           nsCommandParams& aParams) const final;
   MOZ_CAN_RUN_SCRIPT
   nsresult SetState(HTMLEditor* aHTMLEditor,
                     const nsString& newState) const final;
 };
 
 class HighlightColorStateCommand final : public MultiStateCommandBase {
  public:
   NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(HighlightColorStateCommand)
 
  protected:
   HighlightColorStateCommand() = default;
   virtual ~HighlightColorStateCommand() = default;
 
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY  // XXX Needs to change nsIControllerCommand.idl
-      nsresult
-      GetCurrentState(HTMLEditor* aHTMLEditor,
-                      nsCommandParams& aParams) const final;
+  MOZ_CAN_RUN_SCRIPT
+  nsresult GetCurrentState(HTMLEditor* aHTMLEditor,
+                           nsCommandParams& aParams) const final;
   MOZ_CAN_RUN_SCRIPT
   nsresult SetState(HTMLEditor* aHTMLEditor,
                     const nsString& newState) const final;
 };
 
 class FontColorStateCommand final : public MultiStateCommandBase {
  public:
   NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(FontColorStateCommand)
 
  protected:
   FontColorStateCommand() = default;
   virtual ~FontColorStateCommand() = default;
 
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY  // XXX Needs to change nsIControllerCommand.idl
-      nsresult
-      GetCurrentState(HTMLEditor* aHTMLEditor,
-                      nsCommandParams& aParams) const final;
+  MOZ_CAN_RUN_SCRIPT
+  nsresult GetCurrentState(HTMLEditor* aHTMLEditor,
+                           nsCommandParams& aParams) const final;
   MOZ_CAN_RUN_SCRIPT
   nsresult SetState(HTMLEditor* aHTMLEditor,
                     const nsString& newState) const final;
 };
 
 class AlignCommand final : public MultiStateCommandBase {
  public:
   NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(AlignCommand)
 
  protected:
   AlignCommand() = default;
   virtual ~AlignCommand() = default;
 
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY  // XXX Needs to change nsIControllerCommand.idl
-      nsresult
-      GetCurrentState(HTMLEditor* aHTMLEditor,
-                      nsCommandParams& aParams) const final;
+  MOZ_CAN_RUN_SCRIPT
+  nsresult GetCurrentState(HTMLEditor* aHTMLEditor,
+                           nsCommandParams& aParams) const final;
   MOZ_CAN_RUN_SCRIPT
   nsresult SetState(HTMLEditor* aHTMLEditor,
                     const nsString& newState) const final;
 };
 
 class BackgroundColorStateCommand final : public MultiStateCommandBase {
  public:
   NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(BackgroundColorStateCommand)
 
  protected:
   BackgroundColorStateCommand() = default;
   virtual ~BackgroundColorStateCommand() = default;
 
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY  // XXX Needs to change nsIControllerCommand.idl
-      nsresult
-      GetCurrentState(HTMLEditor* aHTMLEditor,
-                      nsCommandParams& aParams) const final;
+  MOZ_CAN_RUN_SCRIPT
+  nsresult GetCurrentState(HTMLEditor* aHTMLEditor,
+                           nsCommandParams& aParams) const final;
   MOZ_CAN_RUN_SCRIPT
   nsresult SetState(HTMLEditor* aHTMLEditor,
                     const nsString& newState) const final;
 };
 
 class AbsolutePositioningCommand final : public StateUpdatingCommandBase {
  public:
   NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(AbsolutePositioningCommand)
 
  protected:
   AbsolutePositioningCommand() = default;
   virtual ~AbsolutePositioningCommand() = default;
 
-  MOZ_CAN_RUN_SCRIPT_BOUNDARY  // XXX Needs to change nsIControllerCommand.idl
-      nsresult
-      GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
-                      nsCommandParams& aParams) const final;
+  MOZ_CAN_RUN_SCRIPT
+  nsresult GetCurrentState(nsAtom* aTagName, HTMLEditor* aHTMLEditor,
+                           nsCommandParams& aParams) const final;
   MOZ_CAN_RUN_SCRIPT
   nsresult ToggleState(nsAtom* aTagName, HTMLEditor* aHTMLEditor) const final;
 };
 
 // composer commands
 
 NS_DECL_EDITOR_COMMAND(DocumentStateCommand)
 NS_DECL_EDITOR_COMMAND(SetDocumentStateCommand)
--- a/editor/libeditor/HTMLEditorCommands.cpp
+++ b/editor/libeditor/HTMLEditorCommands.cpp
@@ -23,19 +23,19 @@
 #include "nsStringFwd.h"      // for nsString
 
 class nsISupports;
 
 namespace mozilla {
 using dom::Element;
 
 // prototype
-MOZ_CAN_RUN_SCRIPT_BOUNDARY  // XXX Needs to change nsIControllerCommand.idl
-    static nsresult
-    GetListState(HTMLEditor* aHTMLEditor, bool* aMixed, nsAString& aLocalName);
+MOZ_CAN_RUN_SCRIPT
+static nsresult GetListState(HTMLEditor* aHTMLEditor, bool* aMixed,
+                             nsAString& aLocalName);
 
 // defines
 #define STATE_ENABLED "state_enabled"
 #define STATE_ALL "state_all"
 #define STATE_ANY "state_any"
 #define STATE_MIXED "state_mixed"
 #define STATE_BEGIN "state_begin"
 #define STATE_END "state_end"
@@ -92,17 +92,17 @@ nsresult StateUpdatingCommandBase::GetCo
   HTMLEditor* htmlEditor = aTextEditor->AsHTMLEditor();
   if (NS_WARN_IF(!htmlEditor)) {
     return NS_ERROR_FAILURE;
   }
   RefPtr<nsAtom> tagName = TagName(aCommandName);
   if (NS_WARN_IF(!tagName)) {
     return NS_ERROR_UNEXPECTED;
   }
-  return GetCurrentState(tagName, htmlEditor, aParams);
+  return GetCurrentState(tagName, MOZ_KnownLive(htmlEditor), aParams);
 }
 
 /*****************************************************************************
  * mozilla::PasteNoFormattingCommand
  *****************************************************************************/
 
 StaticRefPtr<PasteNoFormattingCommand> PasteNoFormattingCommand::sInstance;