Bug 1546578 - part 7: Make EditorCommand implement nsIControllerCommand::DoCommandParams() and call internal DoCommandParams() method which take TextEditor directly r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 26 Apr 2019 15:32:06 +0000
changeset 530500 4e5609da308736145af7e211d3048a45df5c289b
parent 530499 93f5bf3c98074111ce1a1246b89d636f4f48b491
child 530501 a90af6c1b7d1bf34cc34928da7cf5169f37837b0
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 7: Make EditorCommand implement nsIControllerCommand::DoCommandParams() and call internal DoCommandParams() method which take TextEditor directly r=m_kato This patch makes `EditorCommand` implement `nsIControllerCommand::DoCommandParams()` and then, makes it call internal `DoCommandParams()` method which takes `TextEditor` instead. This makes each implementation really simpler. Differential Revision: https://phabricator.services.mozilla.com/D28694
editor/libeditor/EditorCommands.cpp
editor/libeditor/EditorCommands.h
editor/libeditor/HTMLEditorCommands.cpp
editor/libeditor/HTMLEditorDocumentCommands.cpp
--- a/editor/libeditor/EditorCommands.cpp
+++ b/editor/libeditor/EditorCommands.cpp
@@ -62,16 +62,36 @@ EditorCommand::DoCommand(const char* aCo
   }
   nsresult rv = DoCommand(aCommandName, MOZ_KnownLive(*editor->AsTextEditor()));
   NS_WARNING_ASSERTION(
       NS_SUCCEEDED(rv),
       "Failed to do command from nsIControllerCommand::DoCommand()");
   return rv;
 }
 
+NS_IMETHODIMP
+EditorCommand::DoCommandParams(const char* aCommandName,
+                               nsICommandParams* aParams,
+                               nsISupports* aCommandRefCon) {
+  if (NS_WARN_IF(!aCommandName) || NS_WARN_IF(!aCommandRefCon)) {
+    return NS_ERROR_INVALID_ARG;
+  }
+  nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
+  if (NS_WARN_IF(!editor)) {
+    return NS_ERROR_INVALID_ARG;
+  }
+  nsresult rv =
+      DoCommandParams(aCommandName, MOZ_KnownLive(aParams->AsCommandParams()),
+                      MOZ_KnownLive(*editor->AsTextEditor()));
+  NS_WARNING_ASSERTION(
+      NS_SUCCEEDED(rv),
+      "Failed to do command from nsIControllerCommand::DoCommandParams()");
+  return rv;
+}
+
 /******************************************************************************
  * mozilla::UndoCommand
  ******************************************************************************/
 
 StaticRefPtr<UndoCommand> UndoCommand::sInstance;
 
 bool UndoCommand::IsCommandEnabled(const char* aCommandName,
                                    TextEditor* aTextEditor) const {
@@ -81,21 +101,20 @@ bool UndoCommand::IsCommandEnabled(const
   return aTextEditor->IsSelectionEditable() && aTextEditor->CanUndo();
 }
 
 nsresult UndoCommand::DoCommand(const char* aCommandName,
                                 TextEditor& aTextEditor) const {
   return aTextEditor.Undo(1);
 }
 
-NS_IMETHODIMP
-UndoCommand::DoCommandParams(const char* aCommandName,
-                             nsICommandParams* aParams,
-                             nsISupports* aCommandRefCon) {
-  return DoCommand(aCommandName, aCommandRefCon);
+nsresult UndoCommand::DoCommandParams(const char* aCommandName,
+                                      nsCommandParams* aParams,
+                                      TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 UndoCommand::GetCommandStateParams(const char* aCommandName,
                                    nsICommandParams* aParams,
                                    nsISupports* aCommandRefCon) {
   bool canUndo;
   IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
@@ -116,21 +135,20 @@ bool RedoCommand::IsCommandEnabled(const
   return aTextEditor->IsSelectionEditable() && aTextEditor->CanRedo();
 }
 
 nsresult RedoCommand::DoCommand(const char* aCommandName,
                                 TextEditor& aTextEditor) const {
   return aTextEditor.Redo(1);
 }
 
-NS_IMETHODIMP
-RedoCommand::DoCommandParams(const char* aCommandName,
-                             nsICommandParams* aParams,
-                             nsISupports* aCommandRefCon) {
-  return DoCommand(aCommandName, aCommandRefCon);
+nsresult RedoCommand::DoCommandParams(const char* aCommandName,
+                                      nsCommandParams* aParams,
+                                      TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 RedoCommand::GetCommandStateParams(const char* aCommandName,
                                    nsICommandParams* aParams,
                                    nsISupports* aCommandRefCon) {
   bool canUndo;
   IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
@@ -151,20 +169,20 @@ bool CutCommand::IsCommandEnabled(const 
   return aTextEditor->IsSelectionEditable() && aTextEditor->CanCut();
 }
 
 nsresult CutCommand::DoCommand(const char* aCommandName,
                                TextEditor& aTextEditor) const {
   return aTextEditor.Cut();
 }
 
-NS_IMETHODIMP
-CutCommand::DoCommandParams(const char* aCommandName, nsICommandParams* aParams,
-                            nsISupports* aCommandRefCon) {
-  return DoCommand(aCommandName, aCommandRefCon);
+nsresult CutCommand::DoCommandParams(const char* aCommandName,
+                                     nsCommandParams* aParams,
+                                     TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 CutCommand::GetCommandStateParams(const char* aCommandName,
                                   nsICommandParams* aParams,
                                   nsISupports* aCommandRefCon) {
   bool canUndo;
   IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
@@ -194,21 +212,20 @@ nsresult CutOrDeleteCommand::DoCommand(c
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
     return NS_OK;
   }
   return aTextEditor.Cut();
 }
 
-NS_IMETHODIMP
-CutOrDeleteCommand::DoCommandParams(const char* aCommandName,
-                                    nsICommandParams* aParams,
-                                    nsISupports* aCommandRefCon) {
-  return DoCommand(aCommandName, aCommandRefCon);
+nsresult CutOrDeleteCommand::DoCommandParams(const char* aCommandName,
+                                             nsCommandParams* aParams,
+                                             TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 CutOrDeleteCommand::GetCommandStateParams(const char* aCommandName,
                                           nsICommandParams* aParams,
                                           nsISupports* aCommandRefCon) {
   bool canUndo;
   IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
@@ -229,21 +246,20 @@ bool CopyCommand::IsCommandEnabled(const
   return aTextEditor->CanCopy();
 }
 
 nsresult CopyCommand::DoCommand(const char* aCommandName,
                                 TextEditor& aTextEditor) const {
   return aTextEditor.Copy();
 }
 
-NS_IMETHODIMP
-CopyCommand::DoCommandParams(const char* aCommandName,
-                             nsICommandParams* aParams,
-                             nsISupports* aCommandRefCon) {
-  return DoCommand(aCommandName, aCommandRefCon);
+nsresult CopyCommand::DoCommandParams(const char* aCommandName,
+                                      nsCommandParams* aParams,
+                                      TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 CopyCommand::GetCommandStateParams(const char* aCommandName,
                                    nsICommandParams* aParams,
                                    nsISupports* aCommandRefCon) {
   bool canUndo;
   IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
@@ -273,21 +289,20 @@ nsresult CopyOrDeleteCommand::DoCommand(
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
     return NS_OK;
   }
   return aTextEditor.Copy();
 }
 
-NS_IMETHODIMP
-CopyOrDeleteCommand::DoCommandParams(const char* aCommandName,
-                                     nsICommandParams* aParams,
-                                     nsISupports* aCommandRefCon) {
-  return DoCommand(aCommandName, aCommandRefCon);
+nsresult CopyOrDeleteCommand::DoCommandParams(const char* aCommandName,
+                                              nsCommandParams* aParams,
+                                              TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 CopyOrDeleteCommand::GetCommandStateParams(const char* aCommandName,
                                            nsICommandParams* aParams,
                                            nsISupports* aCommandRefCon) {
   bool canUndo;
   IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
@@ -309,21 +324,20 @@ bool PasteCommand::IsCommandEnabled(cons
          aTextEditor->CanPaste(nsIClipboard::kGlobalClipboard);
 }
 
 nsresult PasteCommand::DoCommand(const char* aCommandName,
                                  TextEditor& aTextEditor) const {
   return aTextEditor.PasteAsAction(nsIClipboard::kGlobalClipboard, true);
 }
 
-NS_IMETHODIMP
-PasteCommand::DoCommandParams(const char* aCommandName,
-                              nsICommandParams* aParams,
-                              nsISupports* aCommandRefCon) {
-  return DoCommand(aCommandName, aCommandRefCon);
+nsresult PasteCommand::DoCommandParams(const char* aCommandName,
+                                       nsCommandParams* aParams,
+                                       TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 PasteCommand::GetCommandStateParams(const char* aCommandName,
                                     nsICommandParams* aParams,
                                     nsISupports* aCommandRefCon) {
   bool canUndo;
   IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
@@ -345,41 +359,36 @@ bool PasteTransferableCommand::IsCommand
          aTextEditor->CanPasteTransferable(nullptr);
 }
 
 nsresult PasteTransferableCommand::DoCommand(const char* aCommandName,
                                              TextEditor& aTextEditor) const {
   return NS_ERROR_FAILURE;
 }
 
-NS_IMETHODIMP
-PasteTransferableCommand::DoCommandParams(const char* aCommandName,
-                                          nsICommandParams* aParams,
-                                          nsISupports* aCommandRefCon) {
-  nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
-  if (NS_WARN_IF(!editor)) {
-    return NS_ERROR_FAILURE;
+nsresult PasteTransferableCommand::DoCommandParams(
+    const char* aCommandName, nsCommandParams* aParams,
+    TextEditor& aTextEditor) const {
+  if (NS_WARN_IF(!aParams)) {
+    return NS_ERROR_INVALID_ARG;
   }
 
-  nsCOMPtr<nsISupports> supports =
-      aParams->AsCommandParams()->GetISupports("transferable");
+  nsCOMPtr<nsISupports> supports = aParams->GetISupports("transferable");
   if (NS_WARN_IF(!supports)) {
     return NS_ERROR_FAILURE;
   }
 
   nsCOMPtr<nsITransferable> trans = do_QueryInterface(supports);
   if (NS_WARN_IF(!trans)) {
     return NS_ERROR_FAILURE;
   }
 
-  TextEditor* textEditor = editor->AsTextEditor();
-  MOZ_ASSERT(textEditor);
   // We know textEditor is known-live here because we are holding a ref to it
   // via "editor".
-  nsresult rv = MOZ_KnownLive(textEditor)->PasteTransferable(trans);
+  nsresult rv = aTextEditor.PasteTransferable(trans);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PasteTransferableCommand::GetCommandStateParams(const char* aCommandName,
@@ -423,21 +432,20 @@ bool SwitchTextDirectionCommand::IsComma
   return aTextEditor->IsSelectionEditable();
 }
 
 nsresult SwitchTextDirectionCommand::DoCommand(const char* aCommandName,
                                                TextEditor& aTextEditor) const {
   return aTextEditor.ToggleTextDirection();
 }
 
-NS_IMETHODIMP
-SwitchTextDirectionCommand::DoCommandParams(const char* aCommandName,
-                                            nsICommandParams* aParams,
-                                            nsISupports* aCommandRefCon) {
-  return DoCommand(aCommandName, aCommandRefCon);
+nsresult SwitchTextDirectionCommand::DoCommandParams(
+    const char* aCommandName, nsCommandParams* aParams,
+    TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 SwitchTextDirectionCommand::GetCommandStateParams(const char* aCommandName,
                                                   nsICommandParams* aParams,
                                                   nsISupports* aCommandRefCon) {
   bool canSwitchTextDirection = true;
   IsCommandEnabled(aCommandName, aCommandRefCon, &canSwitchTextDirection);
@@ -493,21 +501,20 @@ nsresult DeleteCommand::DoCommand(const 
   nsresult rv =
       aTextEditor.DeleteSelectionAsAction(deleteDir, nsIEditor::eStrip);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
-NS_IMETHODIMP
-DeleteCommand::DoCommandParams(const char* aCommandName,
-                               nsICommandParams* aParams,
-                               nsISupports* aCommandRefCon) {
-  return DoCommand(aCommandName, aCommandRefCon);
+nsresult DeleteCommand::DoCommandParams(const char* aCommandName,
+                                        nsCommandParams* aParams,
+                                        TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 DeleteCommand::GetCommandStateParams(const char* aCommandName,
                                      nsICommandParams* aParams,
                                      nsISupports* aCommandRefCon) {
   bool canUndo;
   IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
@@ -536,21 +543,20 @@ bool SelectAllCommand::IsCommandEnabled(
   return !isEmpty;
 }
 
 nsresult SelectAllCommand::DoCommand(const char* aCommandName,
                                      TextEditor& aTextEditor) const {
   return aTextEditor.SelectAll();
 }
 
-NS_IMETHODIMP
-SelectAllCommand::DoCommandParams(const char* aCommandName,
-                                  nsICommandParams* aParams,
-                                  nsISupports* aCommandRefCon) {
-  return DoCommand(aCommandName, aCommandRefCon);
+nsresult SelectAllCommand::DoCommandParams(const char* aCommandName,
+                                           nsCommandParams* aParams,
+                                           TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 SelectAllCommand::GetCommandStateParams(const char* aCommandName,
                                         nsICommandParams* aParams,
                                         nsISupports* aCommandRefCon) {
   bool canUndo;
   IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
@@ -666,21 +672,20 @@ nsresult SelectionMoveCommands::DoComman
     } else if (!strcmp(aCommandName, cmd.select)) {
       return selectionController->PhysicalMove(cmd.direction, cmd.amount, true);
     }
   }
 
   return NS_ERROR_FAILURE;
 }
 
-NS_IMETHODIMP
-SelectionMoveCommands::DoCommandParams(const char* aCommandName,
-                                       nsICommandParams* aParams,
-                                       nsISupports* aCommandRefCon) {
-  return DoCommand(aCommandName, aCommandRefCon);
+nsresult SelectionMoveCommands::DoCommandParams(const char* aCommandName,
+                                                nsCommandParams* aParams,
+                                                TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 SelectionMoveCommands::GetCommandStateParams(const char* aCommandName,
                                              nsICommandParams* aParams,
                                              nsISupports* aCommandRefCon) {
   bool canUndo;
   IsCommandEnabled(aCommandName, aCommandRefCon, &canUndo);
@@ -709,45 +714,37 @@ nsresult InsertPlaintextCommand::DoComma
   //     better, however, this may not cause two or more placeholder
   //     transactions to the top transaction since its name may not be
   //     nsGkAtoms::TypingTxnName.
   DebugOnly<nsresult> rv = aTextEditor.InsertTextAsAction(EmptyString());
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to insert empty string");
   return NS_OK;
 }
 
-NS_IMETHODIMP
-InsertPlaintextCommand::DoCommandParams(const char* aCommandName,
-                                        nsICommandParams* aParams,
-                                        nsISupports* aCommandRefCon) {
+nsresult InsertPlaintextCommand::DoCommandParams(
+    const char* aCommandName, nsCommandParams* aParams,
+    TextEditor& aTextEditor) const {
   if (NS_WARN_IF(!aParams)) {
     return NS_ERROR_INVALID_ARG;
   }
 
-  nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
-  if (NS_WARN_IF(!editor)) {
-    return NS_ERROR_FAILURE;
-  }
-
   // Get text to insert from command params
   nsAutoString text;
-  nsresult rv = aParams->AsCommandParams()->GetString(STATE_DATA, text);
+  nsresult rv = aParams->GetString(STATE_DATA, text);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  TextEditor* textEditor = editor->AsTextEditor();
-  MOZ_ASSERT(textEditor);
   // XXX InsertTextAsAction() is not same as OnInputText().  However, other
   //     commands to insert line break or paragraph separator use OnInput*().
   //     According to the semantics of those methods, using *AsAction() is
   //     better, however, this may not cause two or more placeholder
   //     transactions to the top transaction since its name may not be
   //     nsGkAtoms::TypingTxnName.
-  rv = textEditor->InsertTextAsAction(text);
+  rv = aTextEditor.InsertTextAsAction(text);
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to insert the text");
   return NS_OK;
 }
 
 NS_IMETHODIMP
 InsertPlaintextCommand::GetCommandStateParams(const char* aCommandName,
                                               nsICommandParams* aParams,
                                               nsISupports* aCommandRefCon) {
@@ -778,21 +775,20 @@ nsresult InsertParagraphCommand::DoComma
                                            TextEditor& aTextEditor) const {
   HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
   if (!htmlEditor) {
     return NS_OK;  // Do nothing for now.
   }
   return htmlEditor->InsertParagraphSeparatorAsAction();
 }
 
-NS_IMETHODIMP
-InsertParagraphCommand::DoCommandParams(const char* aCommandName,
-                                        nsICommandParams* aParams,
-                                        nsISupports* aCommandRefCon) {
-  return DoCommand(aCommandName, aCommandRefCon);
+nsresult InsertParagraphCommand::DoCommandParams(
+    const char* aCommandName, nsCommandParams* aParams,
+    TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 InsertParagraphCommand::GetCommandStateParams(const char* aCommandName,
                                               nsICommandParams* aParams,
                                               nsISupports* aCommandRefCon) {
   if (NS_WARN_IF(!aParams)) {
     return NS_ERROR_INVALID_ARG;
@@ -821,21 +817,20 @@ nsresult InsertLineBreakCommand::DoComma
                                            TextEditor& aTextEditor) const {
   HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
   if (!htmlEditor) {
     return NS_ERROR_FAILURE;
   }
   return htmlEditor->InsertLineBreakAsAction();
 }
 
-NS_IMETHODIMP
-InsertLineBreakCommand::DoCommandParams(const char* aCommandName,
-                                        nsICommandParams* aParams,
-                                        nsISupports* aCommandRefCon) {
-  return DoCommand(aCommandName, aCommandRefCon);
+nsresult InsertLineBreakCommand::DoCommandParams(
+    const char* aCommandName, nsCommandParams* aParams,
+    TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 InsertLineBreakCommand::GetCommandStateParams(const char* aCommandName,
                                               nsICommandParams* aParams,
                                               nsISupports* aCommandRefCon) {
   if (NS_WARN_IF(!aParams)) {
     return NS_ERROR_INVALID_ARG;
@@ -866,34 +861,20 @@ nsresult PasteQuotationCommand::DoComman
   nsresult rv = aTextEditor.PasteAsQuotationAsAction(
       nsIClipboard::kGlobalClipboard, true);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
-NS_IMETHODIMP
-PasteQuotationCommand::DoCommandParams(const char* aCommandName,
-                                       nsICommandParams* aParams,
-                                       nsISupports* aCommandRefCon) {
-  nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
-  if (!editor) {
-    return NS_ERROR_FAILURE;
-  }
-  TextEditor* textEditor = editor->AsTextEditor();
-  MOZ_ASSERT(textEditor);
-  // MOZ_KnownLive because we are holding a stack ref in "editor".
-  nsresult rv =
-      MOZ_KnownLive(textEditor)
-          ->PasteAsQuotationAsAction(nsIClipboard::kGlobalClipboard, true);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-  return NS_OK;
+nsresult PasteQuotationCommand::DoCommandParams(const char* aCommandName,
+                                                nsCommandParams* aParams,
+                                                TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 PasteQuotationCommand::GetCommandStateParams(const char* aCommandName,
                                              nsICommandParams* aParams,
                                              nsISupports* aCommandRefCon) {
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
   if (!editor) {
--- a/editor/libeditor/EditorCommands.h
+++ b/editor/libeditor/EditorCommands.h
@@ -8,16 +8,17 @@
 
 #include "mozilla/StaticPtr.h"
 #include "nsIControllerCommand.h"
 #include "nsISupportsImpl.h"
 #include "nsRefPtrHashtable.h"
 #include "nsStringFwd.h"
 
 class nsAtom;
+class nsCommandParams;
 class nsICommandParams;
 
 namespace mozilla {
 
 class HTMLEditor;
 class TextEditor;
 
 /**
@@ -33,43 +34,52 @@ class EditorCommand : public nsIControll
   // nsIControllerCommand methods.  Use EditorCommand specific methods instead
   // for internal use.
   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;
 
   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,
+                                   TextEditor& aTextEditor) const = 0;
 
  protected:
   EditorCommand() = default;
   virtual ~EditorCommand() = default;
 };
 
-#define NS_DECL_EDITOR_COMMAND_METHODS(_cmd)                          \
- public:                                                              \
-  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                                                  \
-  NS_IMETHOD DoCommandParams(const char* aCommandName,                \
-                             nsICommandParams* aParams,               \
-                             nsISupports* aCommandRefCon) final;      \
-  NS_IMETHOD GetCommandStateParams(const char* aCommandName,          \
-                                   nsICommandParams* aParams,         \
+#define NS_DECL_EDITOR_COMMAND_METHODS(_cmd)                             \
+ public:                                                                 \
+  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;                                  \
+  NS_IMETHOD GetCommandStateParams(const char* aCommandName,             \
+                                   nsICommandParams* aParams,            \
                                    nsISupports* aCommandRefCon) final;
 
 #define NS_INLINE_DECL_EDITOR_COMMAND_MAKE_SINGLETON(_cmd) \
  public:                                                   \
   static _cmd* GetInstance() {                             \
     if (!sInstance) {                                      \
       sInstance = new _cmd();                              \
     }                                                      \
@@ -276,129 +286,136 @@ class MultiStateCommandBase : public Edi
   virtual ~MultiStateCommandBase() = default;
 
   MOZ_CAN_RUN_SCRIPT_BOUNDARY  // XXX Needs to change nsIControllerCommand.idl
       virtual nsresult
       GetCurrentState(HTMLEditor* aHTMLEditor,
                       nsICommandParams* aParams) const = 0;
   MOZ_CAN_RUN_SCRIPT
   virtual nsresult SetState(HTMLEditor* aHTMLEditor,
-                            const nsString& newState) = 0;
+                            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,
                       nsICommandParams* aParams) const final;
   MOZ_CAN_RUN_SCRIPT
-  nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
+  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,
                       nsICommandParams* aParams) const final;
   MOZ_CAN_RUN_SCRIPT
-  nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
+  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,
                       nsICommandParams* aParams) const final;
   MOZ_CAN_RUN_SCRIPT
-  nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
+  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,
                       nsICommandParams* aParams) const final;
   MOZ_CAN_RUN_SCRIPT
-  nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
+  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,
                       nsICommandParams* aParams) const final;
   MOZ_CAN_RUN_SCRIPT
-  nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
+  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,
                       nsICommandParams* aParams) const final;
   MOZ_CAN_RUN_SCRIPT
-  nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
+  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,
                       nsICommandParams* aParams) const final;
   MOZ_CAN_RUN_SCRIPT
-  nsresult SetState(HTMLEditor* aHTMLEditor, const nsString& newState) final;
+  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;
--- a/editor/libeditor/HTMLEditorCommands.cpp
+++ b/editor/libeditor/HTMLEditorCommands.cpp
@@ -77,21 +77,20 @@ nsresult StateUpdatingCommandBase::DoCom
   }
   RefPtr<nsAtom> tagName = TagName(aCommandName);
   if (NS_WARN_IF(!tagName)) {
     return NS_ERROR_UNEXPECTED;
   }
   return ToggleState(tagName, MOZ_KnownLive(htmlEditor));
 }
 
-NS_IMETHODIMP
-StateUpdatingCommandBase::DoCommandParams(const char* aCommandName,
-                                          nsICommandParams* aParams,
-                                          nsISupports* refCon) {
-  return DoCommand(aCommandName, refCon);
+nsresult StateUpdatingCommandBase::DoCommandParams(
+    const char* aCommandName, nsCommandParams* aParams,
+    TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 StateUpdatingCommandBase::GetCommandStateParams(const char* aCommandName,
                                                 nsICommandParams* aParams,
                                                 nsISupports* refCon) {
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
   if (!editor) {
@@ -136,21 +135,20 @@ nsresult PasteNoFormattingCommand::DoCom
   if (NS_WARN_IF(!htmlEditor)) {
     return NS_ERROR_FAILURE;
   }
   // Known live because we hold a ref above in "editor"
   return MOZ_KnownLive(htmlEditor)
       ->PasteNoFormatting(nsIClipboard::kGlobalClipboard);
 }
 
-NS_IMETHODIMP
-PasteNoFormattingCommand::DoCommandParams(const char* aCommandName,
-                                          nsICommandParams* aParams,
-                                          nsISupports* refCon) {
-  return DoCommand(aCommandName, refCon);
+nsresult PasteNoFormattingCommand::DoCommandParams(
+    const char* aCommandName, nsCommandParams* aParams,
+    TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 PasteNoFormattingCommand::GetCommandStateParams(const char* aCommandName,
                                                 nsICommandParams* aParams,
                                                 nsISupports* refCon) {
   NS_ENSURE_ARG_POINTER(aParams);
 
@@ -420,21 +418,20 @@ nsresult RemoveListCommand::DoCommand(co
   HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
   if (!htmlEditor) {
     return NS_OK;
   }
   // This removes any list type
   return htmlEditor->RemoveList(EmptyString());
 }
 
-NS_IMETHODIMP
-RemoveListCommand::DoCommandParams(const char* aCommandName,
-                                   nsICommandParams* aParams,
-                                   nsISupports* refCon) {
-  return DoCommand(aCommandName, refCon);
+nsresult RemoveListCommand::DoCommandParams(const char* aCommandName,
+                                            nsCommandParams* aParams,
+                                            TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 RemoveListCommand::GetCommandStateParams(const char* aCommandName,
                                          nsICommandParams* aParams,
                                          nsISupports* refCon) {
   bool outCmdEnabled = false;
   IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
@@ -463,20 +460,20 @@ nsresult IndentCommand::DoCommand(const 
   }
   nsresult rv = htmlEditor->IndentAsAction();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
-NS_IMETHODIMP
-IndentCommand::DoCommandParams(const char* aCommandName,
-                               nsICommandParams* aParams, nsISupports* refCon) {
-  return DoCommand(aCommandName, refCon);
+nsresult IndentCommand::DoCommandParams(const char* aCommandName,
+                                        nsCommandParams* aParams,
+                                        TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 IndentCommand::GetCommandStateParams(const char* aCommandName,
                                      nsICommandParams* aParams,
                                      nsISupports* refCon) {
   bool outCmdEnabled = false;
   IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
@@ -505,21 +502,20 @@ nsresult OutdentCommand::DoCommand(const
   }
   nsresult rv = htmlEditor->OutdentAsAction();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
-NS_IMETHODIMP
-OutdentCommand::DoCommandParams(const char* aCommandName,
-                                nsICommandParams* aParams,
-                                nsISupports* refCon) {
-  return DoCommand(aCommandName, refCon);
+nsresult OutdentCommand::DoCommandParams(const char* aCommandName,
+                                         nsCommandParams* aParams,
+                                         TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 OutdentCommand::GetCommandStateParams(const char* aCommandName,
                                       nsICommandParams* aParams,
                                       nsISupports* refCon) {
   bool outCmdEnabled = false;
   IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
@@ -541,38 +537,32 @@ bool MultiStateCommandBase::IsCommandEna
 
 nsresult MultiStateCommandBase::DoCommand(const char* aCommandName,
                                           TextEditor& aTextEditor) const {
   NS_WARNING(
       "who is calling MultiStateCommandBase::DoCommand (no implementation)?");
   return NS_OK;
 }
 
-NS_IMETHODIMP
-MultiStateCommandBase::DoCommandParams(const char* aCommandName,
-                                       nsICommandParams* aParams,
-                                       nsISupports* refCon) {
-  nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
-  if (!editor) {
-    return NS_OK;
-  }
-  mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
+nsresult MultiStateCommandBase::DoCommandParams(const char* aCommandName,
+                                                nsCommandParams* aParams,
+                                                TextEditor& aTextEditor) const {
+  HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
   if (NS_WARN_IF(!htmlEditor)) {
     return NS_ERROR_FAILURE;
   }
 
   nsAutoString attribute;
   if (aParams) {
-    nsCommandParams* params = aParams->AsCommandParams();
     nsAutoCString asciiAttribute;
-    nsresult rv = params->GetCString(STATE_ATTRIBUTE, asciiAttribute);
+    nsresult rv = aParams->GetCString(STATE_ATTRIBUTE, asciiAttribute);
     if (NS_SUCCEEDED(rv)) {
       CopyASCIItoUTF16(asciiAttribute, attribute);
     } else {
-      params->GetString(STATE_ATTRIBUTE, attribute);
+      aParams->GetString(STATE_ATTRIBUTE, attribute);
     }
   }
   return SetState(MOZ_KnownLive(htmlEditor), attribute);
 }
 
 NS_IMETHODIMP
 MultiStateCommandBase::GetCommandStateParams(const char* aCommandName,
                                              nsICommandParams* aParams,
@@ -609,17 +599,17 @@ nsresult ParagraphStateCommand::GetCurre
     nsCommandParams* params = aParams->AsCommandParams();
     params->SetBool(STATE_MIXED, outMixed);
     params->SetCString(STATE_ATTRIBUTE, tOutStateString);
   }
   return rv;
 }
 
 nsresult ParagraphStateCommand::SetState(HTMLEditor* aHTMLEditor,
-                                         const nsString& newState) {
+                                         const nsString& newState) const {
   if (NS_WARN_IF(!aHTMLEditor)) {
     return NS_ERROR_INVALID_ARG;
   }
   return aHTMLEditor->SetParagraphFormat(newState);
 }
 
 /*****************************************************************************
  * mozilla::FontFaceStateCommand
@@ -640,17 +630,17 @@ nsresult FontFaceStateCommand::GetCurren
     nsCommandParams* params = aParams->AsCommandParams();
     params->SetBool(STATE_MIXED, outMixed);
     params->SetCString(STATE_ATTRIBUTE, NS_ConvertUTF16toUTF8(outStateString));
   }
   return rv;
 }
 
 nsresult FontFaceStateCommand::SetState(HTMLEditor* aHTMLEditor,
-                                        const nsString& newState) {
+                                        const nsString& newState) const {
   if (NS_WARN_IF(!aHTMLEditor)) {
     return NS_ERROR_INVALID_ARG;
   }
 
   if (newState.EqualsLiteral("tt")) {
     // The old "teletype" attribute
     nsresult rv = aHTMLEditor->SetInlinePropertyAsAction(
         *nsGkAtoms::tt, nullptr, EmptyString());
@@ -724,17 +714,17 @@ nsresult FontSizeStateCommand::GetCurren
 //   -1
 //    0
 //   +1
 //   +2
 //   +3
 //   medium
 //   normal
 nsresult FontSizeStateCommand::SetState(HTMLEditor* aHTMLEditor,
-                                        const nsString& newState) {
+                                        const nsString& newState) const {
   if (NS_WARN_IF(!aHTMLEditor)) {
     return NS_ERROR_INVALID_ARG;
   }
 
   if (!newState.IsEmpty() && !newState.EqualsLiteral("normal") &&
       !newState.EqualsLiteral("medium")) {
     nsresult rv = aHTMLEditor->SetInlinePropertyAsAction(
         *nsGkAtoms::font, nsGkAtoms::size, newState);
@@ -786,17 +776,17 @@ nsresult FontColorStateCommand::GetCurre
   LossyCopyUTF16toASCII(outStateString, tOutStateString);
   nsCommandParams* params = aParams->AsCommandParams();
   params->SetBool(STATE_MIXED, outMixed);
   params->SetCString(STATE_ATTRIBUTE, tOutStateString);
   return NS_OK;
 }
 
 nsresult FontColorStateCommand::SetState(HTMLEditor* aHTMLEditor,
-                                         const nsString& newState) {
+                                         const nsString& newState) const {
   if (NS_WARN_IF(!aHTMLEditor)) {
     return NS_ERROR_INVALID_ARG;
   }
 
   if (newState.IsEmpty() || newState.EqualsLiteral("normal")) {
     nsresult rv = aHTMLEditor->RemoveInlinePropertyAsAction(*nsGkAtoms::font,
                                                             nsGkAtoms::color);
     if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -834,17 +824,17 @@ nsresult HighlightColorStateCommand::Get
   LossyCopyUTF16toASCII(outStateString, tOutStateString);
   nsCommandParams* params = aParams->AsCommandParams();
   params->SetBool(STATE_MIXED, outMixed);
   params->SetCString(STATE_ATTRIBUTE, tOutStateString);
   return NS_OK;
 }
 
 nsresult HighlightColorStateCommand::SetState(HTMLEditor* aHTMLEditor,
-                                              const nsString& newState) {
+                                              const nsString& newState) const {
   if (NS_WARN_IF(!aHTMLEditor)) {
     return NS_ERROR_INVALID_ARG;
   }
 
   if (newState.IsEmpty() || newState.EqualsLiteral("normal")) {
     nsresult rv = aHTMLEditor->RemoveInlinePropertyAsAction(*nsGkAtoms::font,
                                                             nsGkAtoms::bgcolor);
     if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -883,17 +873,17 @@ nsresult BackgroundColorStateCommand::Ge
   LossyCopyUTF16toASCII(outStateString, tOutStateString);
   nsCommandParams* params = aParams->AsCommandParams();
   params->SetBool(STATE_MIXED, outMixed);
   params->SetCString(STATE_ATTRIBUTE, tOutStateString);
   return NS_OK;
 }
 
 nsresult BackgroundColorStateCommand::SetState(HTMLEditor* aHTMLEditor,
-                                               const nsString& newState) {
+                                               const nsString& newState) const {
   if (NS_WARN_IF(!aHTMLEditor)) {
     return NS_ERROR_INVALID_ARG;
   }
   return aHTMLEditor->SetBackgroundColor(newState);
 }
 
 /*****************************************************************************
  * mozilla::AlignCommand
@@ -936,17 +926,17 @@ nsresult AlignCommand::GetCurrentState(H
   LossyCopyUTF16toASCII(outStateString, tOutStateString);
   nsCommandParams* params = aParams->AsCommandParams();
   params->SetBool(STATE_MIXED, outMixed);
   params->SetCString(STATE_ATTRIBUTE, tOutStateString);
   return NS_OK;
 }
 
 nsresult AlignCommand::SetState(HTMLEditor* aHTMLEditor,
-                                const nsString& newState) {
+                                const nsString& newState) const {
   if (NS_WARN_IF(!aHTMLEditor)) {
     return NS_ERROR_INVALID_ARG;
   }
   return aHTMLEditor->Align(newState);
 }
 
 /*****************************************************************************
  * mozilla::AbsolutePositioningCommand
@@ -1016,21 +1006,20 @@ nsresult DecreaseZIndexCommand::DoComman
                                           TextEditor& aTextEditor) const {
   HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
   if (NS_WARN_IF(!htmlEditor)) {
     return NS_ERROR_FAILURE;
   }
   return htmlEditor->AddZIndex(-1);
 }
 
-NS_IMETHODIMP
-DecreaseZIndexCommand::DoCommandParams(const char* aCommandName,
-                                       nsICommandParams* aParams,
-                                       nsISupports* refCon) {
-  return DoCommand(aCommandName, refCon);
+nsresult DecreaseZIndexCommand::DoCommandParams(const char* aCommandName,
+                                                nsCommandParams* aParams,
+                                                TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 DecreaseZIndexCommand::GetCommandStateParams(const char* aCommandName,
                                              nsICommandParams* aParams,
                                              nsISupports* refCon) {
   NS_ENSURE_ARG_POINTER(aParams);
 
@@ -1066,21 +1055,20 @@ nsresult IncreaseZIndexCommand::DoComman
                                           TextEditor& aTextEditor) const {
   HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
   if (NS_WARN_IF(!htmlEditor)) {
     return NS_ERROR_FAILURE;
   }
   return htmlEditor->AddZIndex(1);
 }
 
-NS_IMETHODIMP
-IncreaseZIndexCommand::DoCommandParams(const char* aCommandName,
-                                       nsICommandParams* aParams,
-                                       nsISupports* refCon) {
-  return DoCommand(aCommandName, refCon);
+nsresult IncreaseZIndexCommand::DoCommandParams(const char* aCommandName,
+                                                nsCommandParams* aParams,
+                                                TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 IncreaseZIndexCommand::GetCommandStateParams(const char* aCommandName,
                                              nsICommandParams* aParams,
                                              nsISupports* refCon) {
   NS_ENSURE_ARG_POINTER(aParams);
 
@@ -1110,21 +1098,20 @@ nsresult RemoveStylesCommand::DoCommand(
                                         TextEditor& aTextEditor) const {
   HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
   if (!htmlEditor) {
     return NS_OK;
   }
   return MOZ_KnownLive(htmlEditor)->RemoveAllInlineProperties();
 }
 
-NS_IMETHODIMP
-RemoveStylesCommand::DoCommandParams(const char* aCommandName,
-                                     nsICommandParams* aParams,
-                                     nsISupports* refCon) {
-  return DoCommand(aCommandName, refCon);
+nsresult RemoveStylesCommand::DoCommandParams(const char* aCommandName,
+                                              nsCommandParams* aParams,
+                                              TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 RemoveStylesCommand::GetCommandStateParams(const char* aCommandName,
                                            nsICommandParams* aParams,
                                            nsISupports* refCon) {
   bool outCmdEnabled = false;
   IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
@@ -1150,21 +1137,20 @@ nsresult IncreaseFontSizeCommand::DoComm
                                             TextEditor& aTextEditor) const {
   HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
   if (!htmlEditor) {
     return NS_OK;
   }
   return MOZ_KnownLive(htmlEditor)->IncreaseFontSize();
 }
 
-NS_IMETHODIMP
-IncreaseFontSizeCommand::DoCommandParams(const char* aCommandName,
-                                         nsICommandParams* aParams,
-                                         nsISupports* refCon) {
-  return DoCommand(aCommandName, refCon);
+nsresult IncreaseFontSizeCommand::DoCommandParams(
+    const char* aCommandName, nsCommandParams* aParams,
+    TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 IncreaseFontSizeCommand::GetCommandStateParams(const char* aCommandName,
                                                nsICommandParams* aParams,
                                                nsISupports* refCon) {
   bool outCmdEnabled = false;
   IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
@@ -1190,21 +1176,20 @@ nsresult DecreaseFontSizeCommand::DoComm
                                             TextEditor& aTextEditor) const {
   HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
   if (!htmlEditor) {
     return NS_OK;
   }
   return MOZ_KnownLive(htmlEditor)->DecreaseFontSize();
 }
 
-NS_IMETHODIMP
-DecreaseFontSizeCommand::DoCommandParams(const char* aCommandName,
-                                         nsICommandParams* aParams,
-                                         nsISupports* refCon) {
-  return DoCommand(aCommandName, refCon);
+nsresult DecreaseFontSizeCommand::DoCommandParams(
+    const char* aCommandName, nsCommandParams* aParams,
+    TextEditor& aTextEditor) const {
+  return DoCommand(aCommandName, aTextEditor);
 }
 
 NS_IMETHODIMP
 DecreaseFontSizeCommand::GetCommandStateParams(const char* aCommandName,
                                                nsICommandParams* aParams,
                                                nsISupports* refCon) {
   bool outCmdEnabled = false;
   IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
@@ -1233,35 +1218,31 @@ nsresult InsertHTMLCommand::DoCommand(co
   HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
   if (NS_WARN_IF(!htmlEditor)) {
     return NS_ERROR_FAILURE;
   }
   nsAutoString html;
   return MOZ_KnownLive(htmlEditor)->InsertHTML(html);
 }
 
-NS_IMETHODIMP
-InsertHTMLCommand::DoCommandParams(const char* aCommandName,
-                                   nsICommandParams* aParams,
-                                   nsISupports* refCon) {
-  NS_ENSURE_ARG_POINTER(aParams);
-  NS_ENSURE_ARG_POINTER(refCon);
+nsresult InsertHTMLCommand::DoCommandParams(const char* aCommandName,
+                                            nsCommandParams* aParams,
+                                            TextEditor& aTextEditor) const {
+  if (NS_WARN_IF(!aParams)) {
+    return NS_ERROR_INVALID_ARG;
+  }
 
-  nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
-  if (NS_WARN_IF(!editor)) {
-    return NS_ERROR_FAILURE;
-  }
-  mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
+  HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
   if (NS_WARN_IF(!htmlEditor)) {
     return NS_ERROR_FAILURE;
   }
 
   // Get HTML source string to insert from command params
   nsAutoString html;
-  nsresult rv = aParams->AsCommandParams()->GetString(STATE_DATA, html);
+  nsresult rv = aParams->GetString(STATE_DATA, html);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return MOZ_KnownLive(htmlEditor)->InsertHTML(html);
 }
 
 NS_IMETHODIMP
 InsertHTMLCommand::GetCommandStateParams(const char* aCommandName,
@@ -1311,51 +1292,42 @@ nsresult InsertTagCommand::DoCommand(con
   nsresult rv =
       MOZ_KnownLive(htmlEditor)->InsertElementAtSelection(newElement, true);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
-NS_IMETHODIMP
-InsertTagCommand::DoCommandParams(const char* aCommandName,
-                                  nsICommandParams* aParams,
-                                  nsISupports* refCon) {
-  if (NS_WARN_IF(!aCommandName) || NS_WARN_IF(!refCon)) {
-    return NS_ERROR_INVALID_ARG;
-  }
-
+nsresult InsertTagCommand::DoCommandParams(const char* aCommandName,
+                                           nsCommandParams* aParams,
+                                           TextEditor& aTextEditor) const {
   // inserting an hr shouldn't have an parameters, just call DoCommand for that
   if (!strcmp(aCommandName, "cmd_insertHR")) {
-    return DoCommand(aCommandName, refCon);
+    return DoCommand(aCommandName, aTextEditor);
   }
 
   if (NS_WARN_IF(!aParams)) {
     return NS_ERROR_INVALID_ARG;
   }
   RefPtr<nsAtom> tagName = TagName(aCommandName);
   if (NS_WARN_IF(!tagName)) {
     return NS_ERROR_UNEXPECTED;
   }
 
-  nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
-  if (NS_WARN_IF(!editor)) {
-    return NS_ERROR_FAILURE;
-  }
-  mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
+  HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
   if (NS_WARN_IF(!htmlEditor)) {
     return NS_ERROR_FAILURE;
   }
 
   // Don't use nsAutoString here because nsCommandParams stores string member
   // with nsString*.  Therefore, nsAutoString always needs to copy the storage
   // but nsString may avoid it.
   nsString value;
-  nsresult rv = aParams->AsCommandParams()->GetString(STATE_ATTRIBUTE, value);
+  nsresult rv = aParams->GetString(STATE_ATTRIBUTE, value);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   if (NS_WARN_IF(value.IsEmpty())) {
     return NS_ERROR_INVALID_ARG;
   }
 
   // filter out tags we don't know how to insert
--- a/editor/libeditor/HTMLEditorDocumentCommands.cpp
+++ b/editor/libeditor/HTMLEditorDocumentCommands.cpp
@@ -52,120 +52,110 @@ bool SetDocumentStateCommand::IsCommandE
   return true;
 }
 
 nsresult SetDocumentStateCommand::DoCommand(const char* aCommandName,
                                             TextEditor& aTextEditor) const {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-NS_IMETHODIMP
-SetDocumentStateCommand::DoCommandParams(const char* aCommandName,
-                                         nsICommandParams* aParams,
-                                         nsISupports* refCon) {
+nsresult SetDocumentStateCommand::DoCommandParams(
+    const char* aCommandName, nsCommandParams* aParams,
+    TextEditor& aTextEditor) const {
   if (NS_WARN_IF(!aParams)) {
     return NS_ERROR_INVALID_ARG;
   }
 
-  nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
-  if (NS_WARN_IF(!editor)) {
-    return NS_ERROR_INVALID_ARG;
-  }
-  TextEditor* textEditor = editor->AsTextEditor();
-  MOZ_ASSERT(textEditor);
-
-  nsCommandParams* params = aParams->AsCommandParams();
-
-  if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentModified")) {
+  if (!strcmp(aCommandName, "cmd_setDocumentModified")) {
     ErrorResult error;
-    bool modified = params->GetBool(STATE_ATTRIBUTE, error);
+    bool modified = aParams->GetBool(STATE_ATTRIBUTE, error);
     // Should we fail if this param wasn't set?
     // I'm not sure we should be that strict
     if (NS_WARN_IF(error.Failed())) {
       return error.StealNSResult();
     }
     if (modified) {
-      nsresult rv = textEditor->IncrementModificationCount(1);
+      nsresult rv = aTextEditor.IncrementModificationCount(1);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
       return NS_OK;
     }
-    nsresult rv = textEditor->ResetModificationCount();
+    nsresult rv = aTextEditor.ResetModificationCount();
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
     return NS_OK;
   }
 
-  if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentReadOnly")) {
+  if (!strcmp(aCommandName, "cmd_setDocumentReadOnly")) {
     ErrorResult error;
-    bool isReadOnly = params->GetBool(STATE_ATTRIBUTE, error);
+    bool isReadOnly = aParams->GetBool(STATE_ATTRIBUTE, error);
     if (NS_WARN_IF(error.Failed())) {
       return error.StealNSResult();
     }
     if (isReadOnly) {
       nsresult rv =
-          textEditor->AddFlags(nsIPlaintextEditor::eEditorReadonlyMask);
+          aTextEditor.AddFlags(nsIPlaintextEditor::eEditorReadonlyMask);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
       return NS_OK;
     }
     nsresult rv =
-        textEditor->RemoveFlags(nsIPlaintextEditor::eEditorReadonlyMask);
+        aTextEditor.RemoveFlags(nsIPlaintextEditor::eEditorReadonlyMask);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
     return NS_OK;
   }
 
-  if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentUseCSS")) {
-    HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
+  if (!strcmp(aCommandName, "cmd_setDocumentUseCSS")) {
+    HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
     if (NS_WARN_IF(!htmlEditor)) {
       return NS_ERROR_INVALID_ARG;
     }
     ErrorResult error;
-    bool desireCSS = params->GetBool(STATE_ATTRIBUTE, error);
+    bool desireCSS = aParams->GetBool(STATE_ATTRIBUTE, error);
     if (NS_WARN_IF(error.Failed())) {
       return error.StealNSResult();
     }
     nsresult rv = htmlEditor->SetIsCSSEnabled(desireCSS);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
     return NS_OK;
   }
 
-  if (!nsCRT::strcmp(aCommandName, "cmd_insertBrOnReturn")) {
-    HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
+  if (!strcmp(aCommandName, "cmd_insertBrOnReturn")) {
+    HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
     if (NS_WARN_IF(!htmlEditor)) {
       return NS_ERROR_INVALID_ARG;
     }
     ErrorResult error;
-    bool insertBrOnReturn = params->GetBool(STATE_ATTRIBUTE, error);
+    bool insertBrOnReturn = aParams->GetBool(STATE_ATTRIBUTE, error);
     if (NS_WARN_IF(error.Failed())) {
       return error.StealNSResult();
     }
     nsresult rv =
         htmlEditor->SetReturnInParagraphCreatesNewParagraph(!insertBrOnReturn);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
     return NS_OK;
   }
 
-  if (!nsCRT::strcmp(aCommandName, "cmd_defaultParagraphSeparator")) {
-    HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
+  if (!strcmp(aCommandName, "cmd_defaultParagraphSeparator")) {
+    HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
     if (NS_WARN_IF(!htmlEditor)) {
       return NS_ERROR_INVALID_ARG;
     }
 
     nsAutoCString newValue;
-    nsresult rv = params->GetCString(STATE_ATTRIBUTE, newValue);
+    nsresult rv = aParams->GetCString(STATE_ATTRIBUTE, newValue);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     if (newValue.LowerCaseEqualsLiteral("div")) {
       htmlEditor->SetDefaultParagraphSeparator(ParagraphSeparator::div);
       return NS_OK;
     }
@@ -179,52 +169,51 @@ SetDocumentStateCommand::DoCommandParams
       return NS_OK;
     }
 
     // This should not be reachable from nsHTMLDocument::ExecCommand
     NS_WARNING("Invalid default paragraph separator");
     return NS_ERROR_UNEXPECTED;
   }
 
-  if (!nsCRT::strcmp(aCommandName, "cmd_enableObjectResizing")) {
-    HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
+  if (!strcmp(aCommandName, "cmd_enableObjectResizing")) {
+    HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
     if (NS_WARN_IF(!htmlEditor)) {
       return NS_ERROR_INVALID_ARG;
     }
     ErrorResult error;
-    bool enabled = params->GetBool(STATE_ATTRIBUTE, error);
+    bool enabled = aParams->GetBool(STATE_ATTRIBUTE, error);
     if (NS_WARN_IF(error.Failed())) {
       return error.StealNSResult();
     }
     htmlEditor->EnableObjectResizer(enabled);
     return NS_OK;
   }
 
-  if (!nsCRT::strcmp(aCommandName, "cmd_enableInlineTableEditing")) {
-    HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
+  if (!strcmp(aCommandName, "cmd_enableInlineTableEditing")) {
+    HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
     if (NS_WARN_IF(!htmlEditor)) {
       return NS_ERROR_INVALID_ARG;
     }
     ErrorResult error;
-    bool enabled = params->GetBool(STATE_ATTRIBUTE, error);
+    bool enabled = aParams->GetBool(STATE_ATTRIBUTE, error);
     if (NS_WARN_IF(error.Failed())) {
       return error.StealNSResult();
     }
     htmlEditor->EnableInlineTableEditor(enabled);
     return NS_OK;
   }
 
-  if (!nsCRT::strcmp(aCommandName, "cmd_enableAbsolutePositionEditing")) {
-    NS_ENSURE_ARG_POINTER(aParams);
-    HTMLEditor* htmlEditor = textEditor->AsHTMLEditor();
+  if (!strcmp(aCommandName, "cmd_enableAbsolutePositionEditing")) {
+    HTMLEditor* htmlEditor = aTextEditor.AsHTMLEditor();
     if (NS_WARN_IF(!htmlEditor)) {
       return NS_ERROR_INVALID_ARG;
     }
     ErrorResult error;
-    bool enabled = params->GetBool(STATE_ATTRIBUTE, error);
+    bool enabled = aParams->GetBool(STATE_ATTRIBUTE, error);
     if (NS_WARN_IF(error.Failed())) {
       return error.StealNSResult();
     }
     htmlEditor->EnableAbsolutePositionEditor(enabled);
     return NS_OK;
   }
 
   return NS_ERROR_NOT_IMPLEMENTED;
@@ -446,20 +435,19 @@ bool DocumentStateCommand::IsCommandEnab
   return false;
 }
 
 nsresult DocumentStateCommand::DoCommand(const char* aCommandName,
                                          TextEditor& aTextEditor) const {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-NS_IMETHODIMP
-DocumentStateCommand::DoCommandParams(const char* aCommandName,
-                                      nsICommandParams* aParams,
-                                      nsISupports* refCon) {
+nsresult DocumentStateCommand::DoCommandParams(const char* aCommandName,
+                                               nsCommandParams* aParams,
+                                               TextEditor& aTextEditor) const {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
 DocumentStateCommand::GetCommandStateParams(const char* aCommandName,
                                             nsICommandParams* aParams,
                                             nsISupports* refCon) {
   if (NS_WARN_IF(!aParams) || NS_WARN_IF(!aCommandName)) {