Bug 1540965 - Make nsIControllerContext builtinclass and removes its init() method r=bzbarsky
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 03 Apr 2019 12:52:56 +0000
changeset 467857 42b4d2faa54345b470bba2ceeadbc97191056b20
parent 467856 3fb9140b5e81a7caef45e118be9208c273b7f654
child 467858 395ff10d7debcb20d87e09c60600240c6cc1aef9
push id35810
push useraciure@mozilla.com
push dateThu, 04 Apr 2019 04:33:36 +0000
treeherdermozilla-central@b72c02e34261 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1540965
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 1540965 - Make nsIControllerContext builtinclass and removes its init() method r=bzbarsky `nsIControllerContext` isn't implemented with JS even in comm-central nor BlueGriffon. Therefore, it can be a builtinclass. Additionally, it's `init()` returns always `NS_OK`, and always called with `null` from JS, and always called with an instance from C++. So that its the only implementation, `nsBaseCommandController` can have 2 constructors which does what `Init()` currently does. Differential Revision: https://phabricator.services.mozilla.com/D25728
dom/base/nsGlobalWindowInner.cpp
dom/commandhandler/nsBaseCommandController.cpp
dom/commandhandler/nsBaseCommandController.h
dom/commandhandler/nsIControllerContext.idl
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -139,17 +139,16 @@
 #include "nsIWindowMediator.h"  // For window.find()
 #include "nsDOMCID.h"
 #include "nsDOMWindowUtils.h"
 #include "nsIWindowWatcher.h"
 #include "nsPIWindowWatcher.h"
 #include "nsIContentViewer.h"
 #include "nsIScriptError.h"
 #include "nsIControllers.h"
-#include "nsIControllerContext.h"
 #include "nsGlobalWindowCommands.h"
 #include "nsQueryObject.h"
 #include "nsContentUtils.h"
 #include "nsCSSProps.h"
 #include "nsIURIFixup.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventStateManager.h"
 #include "nsIObserverService.h"
--- a/dom/commandhandler/nsBaseCommandController.cpp
+++ b/dom/commandhandler/nsBaseCommandController.cpp
@@ -16,33 +16,23 @@ NS_IMPL_RELEASE(nsBaseCommandController)
 NS_INTERFACE_MAP_BEGIN(nsBaseCommandController)
   NS_INTERFACE_MAP_ENTRY(nsIController)
   NS_INTERFACE_MAP_ENTRY(nsICommandController)
   NS_INTERFACE_MAP_ENTRY(nsIControllerContext)
   NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIControllerContext)
 NS_INTERFACE_MAP_END
 
-nsBaseCommandController::nsBaseCommandController()
-    : mCommandContextRawPtr(nullptr) {}
+nsBaseCommandController::nsBaseCommandController(
+    nsControllerCommandTable* aControllerCommandTable)
+    : mCommandContextRawPtr(nullptr), mCommandTable(aControllerCommandTable) {}
 
 nsBaseCommandController::~nsBaseCommandController() {}
 
 NS_IMETHODIMP
-nsBaseCommandController::Init(nsIControllerCommandTable* aCommandTable) {
-  if (aCommandTable) {
-    mCommandTable = aCommandTable->AsControllerCommandTable();
-  } else {
-    mCommandTable = new nsControllerCommandTable();
-  }
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
 nsBaseCommandController::SetCommandContext(nsISupports* aCommandContext) {
   mCommandContextWeakPtr = nullptr;
   mCommandContextRawPtr = nullptr;
 
   if (aCommandContext) {
     nsCOMPtr<nsISupportsWeakReference> weak =
         do_QueryInterface(aCommandContext);
     if (weak) {
@@ -166,32 +156,26 @@ nsBaseCommandController::GetSupportedCom
   NS_ENSURE_STATE(mCommandTable);
   return mCommandTable->GetSupportedCommands(aCount, aCommands);
 }
 
 typedef already_AddRefed<nsControllerCommandTable> (*CommandTableCreatorFn)();
 
 static already_AddRefed<nsBaseCommandController>
 CreateControllerWithSingletonCommandTable(CommandTableCreatorFn aCreatorFn) {
-  RefPtr<nsBaseCommandController> commandController =
-      new nsBaseCommandController();
-
   RefPtr<nsControllerCommandTable> commandTable = aCreatorFn();
   if (!commandTable) {
     return nullptr;
   }
 
   // this is a singleton; make it immutable
   commandTable->MakeImmutable();
 
-  nsresult rv = commandController->Init(commandTable);
-  if (NS_FAILED(rv)) {
-    return nullptr;
-  }
-
+  RefPtr<nsBaseCommandController> commandController =
+      new nsBaseCommandController(commandTable);
   return commandController.forget();
 }
 
 already_AddRefed<nsBaseCommandController>
 nsBaseCommandController::CreateWindowController() {
   return CreateControllerWithSingletonCommandTable(
       nsControllerCommandTable::CreateWindowCommandTable);
 }
--- a/dom/commandhandler/nsBaseCommandController.h
+++ b/dom/commandhandler/nsBaseCommandController.h
@@ -6,27 +6,34 @@
 
 #ifndef nsBaseCommandController_h__
 #define nsBaseCommandController_h__
 
 #include "nsIController.h"
 #include "nsIControllerContext.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIWeakReferenceUtils.h"
-
-class nsControllerCommandTable;
+#include "nsControllerCommandTable.h"
 
 // The base editor controller is used for both text widgets, and all other text
 // and html editing
-class nsBaseCommandController : public nsIController,
-                                public nsIControllerContext,
-                                public nsIInterfaceRequestor,
-                                public nsICommandController {
+class nsBaseCommandController final : public nsIController,
+                                      public nsIControllerContext,
+                                      public nsIInterfaceRequestor,
+                                      public nsICommandController {
  public:
-  nsBaseCommandController();
+  /**
+   * The default constructor initializes the instance with new
+   * nsControllerCommandTable.  The other constructor does it with
+   * the given aControllerCommandTable.
+   */
+  nsBaseCommandController() = delete;
+  explicit nsBaseCommandController(
+      nsControllerCommandTable* aControllerCommandTable =
+          new nsControllerCommandTable());
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSICONTROLLER
   NS_DECL_NSICOMMANDCONTROLLER
   NS_DECL_NSICONTROLLERCONTEXT
   NS_DECL_NSIINTERFACEREQUESTOR
 
   static already_AddRefed<nsBaseCommandController> CreateWindowController();
--- a/dom/commandhandler/nsIControllerContext.idl
+++ b/dom/commandhandler/nsIControllerContext.idl
@@ -1,35 +1,22 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  
 #include "nsISupports.idl"
 #include "nsIControllerCommandTable.idl"
 
-[scriptable, uuid(47B82B60-A36F-4167-8072-6F421151ED50)]
+[scriptable, builtinclass, uuid(47B82B60-A36F-4167-8072-6F421151ED50)]
 interface nsIControllerContext : nsISupports
 {
-
   /**
-   *  Init the controller, optionally passing a controller
-   *  command table.
-   *
-   * @param aCommandTable  a command table, used internally
-   *                       by this controller. May be null, in
-   *                       which case the controller will create
-   *                       a new, empty table.
-   */
-  void init(in nsIControllerCommandTable aCommandTable);
-
-  /** 
    *  Set a context on this controller, which is passed
    *  to commands to give them some context when they execute.
    *
    * @param aCommandContext  the context passed to commands.
    *                        Note that this is *not* addreffed by the
    *                        controller, and so needs to outlive it,
    *                        or be nulled out.
    */
   void setCommandContext(in nsISupports aCommandContext);
-  
 };