Bug 1489790 - Part 9: Remove the XPCOM component registration for @mozilla.org/editor/htmleditorcontroller;1; r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Sat, 08 Sep 2018 01:35:56 -0400
changeset 491442 a84e71d43f2f61ce0f92646a4d7b36bd2def816d
parent 491441 8b97390b3b8c04479a866cff0a17c27826d889bf
child 491443 1bf6928fd462262c56f9abf37d8e51332fabfba9
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1489790
milestone64.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 1489790 - Part 9: Remove the XPCOM component registration for @mozilla.org/editor/htmleditorcontroller;1; r=baku Differential Revision: https://phabricator.services.mozilla.com/D5364
dom/commandhandler/nsBaseCommandController.cpp
dom/commandhandler/nsBaseCommandController.h
editor/composer/nsComposerRegistration.cpp
editor/composer/nsEditingSession.cpp
editor/libeditor/HTMLEditorController.h
--- a/dom/commandhandler/nsBaseCommandController.cpp
+++ b/dom/commandhandler/nsBaseCommandController.cpp
@@ -238,8 +238,30 @@ nsBaseCommandController::CreateEditingCo
   nsCOMPtr<nsIControllerContext> controllerContext = do_QueryInterface(controller, &rv);
   if (NS_FAILED(rv)) return nullptr;
 
   rv = controllerContext->Init(editingCommandTable);
   if (NS_FAILED(rv)) return nullptr;
 
   return controller.forget();
 }
+
+already_AddRefed<nsIController>
+nsBaseCommandController::CreateHTMLEditorController()
+{
+  nsCOMPtr<nsIController> controller = new nsBaseCommandController();
+
+  nsCOMPtr<nsIControllerCommandTable> composerCommandTable =
+    nsControllerCommandTable::CreateHTMLEditorCommandTable();
+
+  // this guy is a singleton, so make it immutable
+  composerCommandTable->MakeImmutable();
+
+  nsresult rv;
+  nsCOMPtr<nsIControllerContext> controllerContext = do_QueryInterface(controller, &rv);
+  NS_ENSURE_SUCCESS(rv, nullptr);
+
+  rv = controllerContext->Init(composerCommandTable);
+  NS_ENSURE_SUCCESS(rv, nullptr);
+
+  return controller.forget();
+}
+
--- a/dom/commandhandler/nsBaseCommandController.h
+++ b/dom/commandhandler/nsBaseCommandController.h
@@ -28,16 +28,17 @@ public:
   NS_DECL_NSICONTROLLER
   NS_DECL_NSICOMMANDCONTROLLER
   NS_DECL_NSICONTROLLERCONTEXT
   NS_DECL_NSIINTERFACEREQUESTOR
 
   static already_AddRefed<nsIController> CreateWindowController();
   static already_AddRefed<nsIController> CreateEditorController();
   static already_AddRefed<nsIController> CreateEditingController();
+  static already_AddRefed<nsIController> CreateHTMLEditorController();
 
 protected:
   virtual ~nsBaseCommandController();
 
 private:
   nsWeakPtr mCommandContextWeakPtr;
   nsISupports* mCommandContextRawPtr;
 
--- a/editor/composer/nsComposerRegistration.cpp
+++ b/editor/composer/nsComposerRegistration.cpp
@@ -76,43 +76,26 @@ nsHTMLEditorDocStateControllerConstructo
   nsresult rv = CreateControllerWithSingletonCommandTable(
                   nsControllerCommandTable::CreateHTMLEditorDocStateCommandTable(),
                   getter_AddRefs(controller));
   NS_ENSURE_SUCCESS(rv, rv);
 
   return controller->QueryInterface(aIID, aResult);
 }
 
-// Tere we make an instance of the controller that holds composer commands.
-// We set it up with a singleton command table.
-static nsresult
-nsHTMLEditorControllerConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
-{
-  nsCOMPtr<nsIController> controller;
-  nsresult rv = CreateControllerWithSingletonCommandTable(
-                  nsControllerCommandTable::CreateHTMLEditorCommandTable(),
-                  getter_AddRefs(controller));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return controller->QueryInterface(aIID, aResult);
-}
-
-NS_DEFINE_NAMED_CID(NS_HTMLEDITORCONTROLLER_CID);
 NS_DEFINE_NAMED_CID(NS_EDITORDOCSTATECONTROLLER_CID);
 NS_DEFINE_NAMED_CID(NS_EDITORSPELLCHECK_CID);
 
 static const mozilla::Module::CIDEntry kComposerCIDs[] = {
-  { &kNS_HTMLEDITORCONTROLLER_CID, false, nullptr, nsHTMLEditorControllerConstructor },
   { &kNS_EDITORDOCSTATECONTROLLER_CID, false, nullptr, nsHTMLEditorDocStateControllerConstructor },
   { &kNS_EDITORSPELLCHECK_CID, false, nullptr, EditorSpellCheckConstructor },
   { nullptr }
 };
 
 static const mozilla::Module::ContractIDEntry kComposerContracts[] = {
-  { "@mozilla.org/editor/htmleditorcontroller;1", &kNS_HTMLEDITORCONTROLLER_CID },
   { "@mozilla.org/editor/editordocstatecontroller;1", &kNS_EDITORDOCSTATECONTROLLER_CID },
   { "@mozilla.org/editor/editorspellchecker;1", &kNS_EDITORSPELLCHECK_CID },
   { nullptr }
 };
 
 static const mozilla::Module kComposerModule = {
   mozilla::Module::kVersion,
   kComposerCIDs,
--- a/editor/composer/nsEditingSession.cpp
+++ b/editor/composer/nsEditingSession.cpp
@@ -422,17 +422,17 @@ nsEditingSession::SetupEditorOnWindow(mo
   }
   // set the editor on the docShell. The docShell now owns it.
   rv = docShell->SetHTMLEditor(htmlEditor);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // setup the HTML editor command controller
   if (needHTMLController) {
     // The third controller takes an nsIEditor as the context
-    rv = SetupEditorCommandController("@mozilla.org/editor/htmleditorcontroller;1",
+    rv = SetupEditorCommandController(nsBaseCommandController::CreateHTMLEditorController,
                                       aWindow,
                                       static_cast<nsIEditor*>(htmlEditor),
                                       &mHTMLCommandControllerId);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // Set mimetype on editor
   rv = htmlEditor->SetContentsMIMEType(mimeCType.get());
@@ -1402,17 +1402,17 @@ nsEditingSession::ReattachToWindow(mozID
     nsPresContext* presContext = presShell->GetPresContext();
     NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
 
     mImageAnimationMode = presContext->ImageAnimationMode();
     presContext->SetImageAnimationMode(imgIContainer::kDontAnimMode);
   }
 
   // The third controller takes an nsIEditor as the context
-  rv = SetupEditorCommandController("@mozilla.org/editor/htmleditorcontroller;1",
+  rv = SetupEditorCommandController(nsBaseCommandController::CreateHTMLEditorController,
                                     aWindow,
                                     static_cast<nsIEditor*>(htmlEditor.get()),
                                     &mHTMLCommandControllerId);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Set context on all controllers to be the editor
   rv = SetEditorOnControllers(aWindow, htmlEditor);
   NS_ENSURE_SUCCESS(rv, rv);
--- a/editor/libeditor/HTMLEditorController.h
+++ b/editor/libeditor/HTMLEditorController.h
@@ -14,20 +14,16 @@ class nsIControllerCommandTable;
 
 // The plaintext editor controller is used for basic text editing and html editing
 // commands in composer
 // The refCon that gets passed to its commands is initially nsIEditingSession,
 //   and after successfule editor creation it is changed to nsIEditor.
 #define NS_EDITORDOCSTATECONTROLLER_CID \
  { 0x50e95301, 0x17a8, 0x11d4, { 0x9f, 0x7e, 0xdd, 0x53, 0x0d, 0x5f, 0x05, 0x7c } }
 
-// The HTMLEditor controller is used only for HTML editors and takes nsIEditor as refCon
-#define NS_HTMLEDITORCONTROLLER_CID \
- { 0x62db0002, 0xdbb6, 0x43f4, { 0x8f, 0xb7, 0x9d, 0x25, 0x38, 0xbc, 0x57, 0x47 } }
-
 namespace mozilla {
 
 class HTMLEditorController final
 {
 public:
   static nsresult RegisterEditorDocStateCommands(nsIControllerCommandTable* inCommandTable);
   static nsresult RegisterHTMLEditorCommands(nsIControllerCommandTable* inCommandTable);
 };