Bug 1489790 - Part 6: Add an overload of nsEditingSession::SetupEditorCommandController which takes a creator function argument instead of a contract ID; r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 07 Sep 2018 09:24:34 -0400
changeset 435703 c578fb3304f1ad33519465e8c645ad7eda47bb02
parent 435702 effc266bc7e14b6b0d14949fd2bfe18b87ad786e
child 435704 8b0247a1496add1fc732cee8a7e9828e370c9874
push id34618
push userbtara@mozilla.com
push dateTue, 11 Sep 2018 22:13:11 +0000
treeherdermozilla-central@1169e8a4ca2b [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 6: Add an overload of nsEditingSession::SetupEditorCommandController which takes a creator function argument instead of a contract ID; r=baku Differential Revision: https://phabricator.services.mozilla.com/D5361
editor/composer/nsEditingSession.cpp
editor/composer/nsEditingSession.h
--- a/editor/composer/nsEditingSession.cpp
+++ b/editor/composer/nsEditingSession.cpp
@@ -1089,16 +1089,63 @@ nsEditingSession::PrepareForEditing(nsPI
 
   SetupEditorCommandController
 
   Create a command controller, append to controllers,
   get and return the controller ID, and set the context
 ----------------------------------------------------------------------------*/
 nsresult
 nsEditingSession::SetupEditorCommandController(
+                                  nsEditingSession::ControllerCreatorFn aControllerCreatorFn,
+                                  mozIDOMWindowProxy* aWindow,
+                                  nsISupports* aContext,
+                                  uint32_t* aControllerId)
+{
+  NS_ENSURE_ARG_POINTER(aControllerCreatorFn);
+  NS_ENSURE_ARG_POINTER(aWindow);
+  NS_ENSURE_ARG_POINTER(aContext);
+  NS_ENSURE_ARG_POINTER(aControllerId);
+
+  auto* piWindow = nsPIDOMWindowOuter::From(aWindow);
+  MOZ_ASSERT(piWindow);
+
+  nsCOMPtr<nsIControllers> controllers;
+  nsresult rv = piWindow->GetControllers(getter_AddRefs(controllers));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  // We only have to create each singleton controller once
+  // We know this has happened once we have a controllerId value
+  if (!*aControllerId) {
+    nsCOMPtr<nsIController> controller = aControllerCreatorFn();
+    NS_ENSURE_TRUE(controller, NS_ERROR_FAILURE);
+
+    // We must insert at head of the list to be sure our
+    //   controller is found before other implementations
+    //   (e.g., not-implemented versions by browser)
+    rv = controllers->InsertControllerAt(0, controller);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    // Remember the ID for the controller
+    rv = controllers->GetControllerId(controller, aControllerId);
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
+
+  // Set the context
+  return SetContextOnControllerById(controllers, aContext, *aControllerId);
+}
+
+/*---------------------------------------------------------------------------
+
+  SetupEditorCommandController
+
+  Create a command controller, append to controllers,
+  get and return the controller ID, and set the context
+----------------------------------------------------------------------------*/
+nsresult
+nsEditingSession::SetupEditorCommandController(
                                   const char *aControllerClassName,
                                   mozIDOMWindowProxy *aWindow,
                                   nsISupports *aContext,
                                   uint32_t *aControllerId)
 {
   NS_ENSURE_ARG_POINTER(aControllerClassName);
   NS_ENSURE_ARG_POINTER(aWindow);
   NS_ENSURE_ARG_POINTER(aContext);
--- a/editor/composer/nsEditingSession.h
+++ b/editor/composer/nsEditingSession.h
@@ -57,16 +57,23 @@ public:
   NS_DECL_NSIWEBPROGRESSLISTENER
 
   // nsIEditingSession
   NS_DECL_NSIEDITINGSESSION
 
 protected:
   virtual         ~nsEditingSession();
 
+  typedef already_AddRefed<nsIController> (*ControllerCreatorFn)();
+
+  nsresult        SetupEditorCommandController(ControllerCreatorFn aControllerCreatorFn,
+                                               mozIDOMWindowProxy* aWindow,
+                                               nsISupports* aContext,
+                                               uint32_t* aControllerId);
+
   nsresult        SetupEditorCommandController(const char *aControllerClassName,
                                                mozIDOMWindowProxy* aWindow,
                                                nsISupports *aContext,
                                                uint32_t *aControllerId);
 
   nsresult        SetContextOnControllerById(nsIControllers* aControllers,
                                             nsISupports* aContext,
                                             uint32_t aID);