Bug 1491569 - Remove the XPCOM registration for mozSpellChecker; r=smaug
authorEhsan Akhgari <ehsan@mozilla.com>
Sat, 15 Sep 2018 12:08:06 -0400
changeset 436622 1cef5144d067
parent 436621 95855da9e698
child 436623 b58b63ffcf08
push id34651
push usernerli@mozilla.com
push dateSun, 16 Sep 2018 09:50:45 +0000
treeherdermozilla-central@7ed950e60f3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1491569
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 1491569 - Remove the XPCOM registration for mozSpellChecker; r=smaug Differential Revision: https://phabricator.services.mozilla.com/D5946
dom/ipc/ContentParent.cpp
editor/spellchecker/EditorSpellCheck.cpp
editor/spellchecker/nsISpellChecker.h
extensions/spellcheck/hunspell/glue/RemoteSpellCheckEngineParent.cpp
extensions/spellcheck/src/mozSpellChecker.h
extensions/spellcheck/src/mozSpellCheckerFactory.cpp
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -147,17 +147,17 @@
 #include "nsIObserverService.h"
 #include "nsIParentChannel.h"
 #include "nsIPresShell.h"
 #include "nsIRemoteWindowContext.h"
 #include "nsIScriptError.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsISiteSecurityService.h"
 #include "nsISound.h"
-#include "nsISpellChecker.h"
+#include "mozilla/mozSpellChecker.h"
 #include "nsIStringBundle.h"
 #include "nsISupportsPrimitives.h"
 #include "nsITimer.h"
 #include "nsIURIFixup.h"
 #include "nsIURL.h"
 #include "nsIDocShellTreeOwner.h"
 #include "nsIXULWindow.h"
 #include "nsIDOMChromeWindow.h"
@@ -2400,17 +2400,17 @@ ContentParent::InitInternal(ProcessPrior
 
   xpcomInit.isLangRTL() = false;
   xpcomInit.haveBidiKeyboards() = false;
   if (bidi) {
     bidi->IsLangRTL(&xpcomInit.isLangRTL());
     bidi->GetHaveBidiKeyboards(&xpcomInit.haveBidiKeyboards());
   }
 
-  nsCOMPtr<nsISpellChecker> spellChecker(do_GetService(NS_SPELLCHECKER_CONTRACTID));
+  nsCOMPtr<nsISpellChecker> spellChecker(mozSpellChecker::Create());
   MOZ_ASSERT(spellChecker, "No spell checker?");
 
   spellChecker->GetDictionaryList(&xpcomInit.dictionaries());
 
   LocaleService::GetInstance()->GetAppLocalesAsLangTags(xpcomInit.appLocales());
   LocaleService::GetInstance()->GetRequestedLocales(xpcomInit.requestedLocales());
 
   nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1"));
@@ -4610,17 +4610,17 @@ ContentParent::IgnoreIPCPrincipal()
                                  "dom.testing.ignore_ipc_principal", false);
   }
   return sIgnoreIPCPrincipal;
 }
 
 void
 ContentParent::NotifyUpdatedDictionaries()
 {
-  nsCOMPtr<nsISpellChecker> spellChecker(do_GetService(NS_SPELLCHECKER_CONTRACTID));
+  nsCOMPtr<nsISpellChecker> spellChecker(mozSpellChecker::Create());
   MOZ_ASSERT(spellChecker, "No spell checker?");
 
   InfallibleTArray<nsString> dictionaries;
   spellChecker->GetDictionaryList(&dictionaries);
 
   for (auto* cp : AllProcesses(eLive)) {
     Unused << cp->SendUpdateDictionaryList(dictionaries);
   }
--- a/editor/spellchecker/EditorSpellCheck.cpp
+++ b/editor/spellchecker/EditorSpellCheck.cpp
@@ -318,19 +318,18 @@ EditorSpellCheck::GetSpellChecker()
 // allowing callers to ask if we can spell check without actually doing so (and
 // enabling or disabling UI as necessary). This just creates a spellcheck
 // object if needed and asks it for the dictionary list.
 NS_IMETHODIMP
 EditorSpellCheck::CanSpellCheck(bool* aCanSpellCheck)
 {
   RefPtr<mozSpellChecker> spellChecker = mSpellChecker;
   if (!spellChecker) {
-    spellChecker = new mozSpellChecker();
-    DebugOnly<nsresult> rv = spellChecker->Init();
-    MOZ_ASSERT(NS_SUCCEEDED(rv));
+    spellChecker = mozSpellChecker::Create();
+    MOZ_ASSERT(spellChecker);
   }
   nsTArray<nsString> dictList;
   nsresult rv = spellChecker->GetDictionaryList(&dictList);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   *aCanSpellCheck = !dictList.IsEmpty();
@@ -384,17 +383,18 @@ EditorSpellCheck::InitSpellChecker(nsIEd
   RefPtr<TextServicesDocument> textServicesDocument =
     new TextServicesDocument();
   textServicesDocument->SetFilterType(mTxtSrvFilterType);
 
   // EditorBase::AddEditActionListener() needs to access mSpellChecker and
   // mSpellChecker->GetTextServicesDocument().  Therefore, we need to
   // initialize them before calling TextServicesDocument::InitWithEditor()
   // since it calls EditorBase::AddEditActionListener().
-  mSpellChecker = new mozSpellChecker();
+  mSpellChecker = mozSpellChecker::Create();
+  MOZ_ASSERT(mSpellChecker);
   rv = mSpellChecker->SetDocument(textServicesDocument, true);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Pass the editor to the text services document
   rv = textServicesDocument->InitWithEditor(aEditor);
   NS_ENSURE_SUCCESS(rv, rv);
@@ -427,19 +427,16 @@ EditorSpellCheck::InitSpellChecker(nsIEd
         // Now tell the text services that you only want
         // to iterate over the text in this range.
 
         rv = textServicesDocument->SetExtent(rangeBounds);
         NS_ENSURE_SUCCESS(rv, rv);
       }
     }
   }
-
-  rv = mSpellChecker->Init();
-  MOZ_ASSERT(NS_SUCCEEDED(rv));
   // do not fail if UpdateCurrentDictionary fails because this method may
   // succeed later.
   rv = UpdateCurrentDictionary(aCallback);
   if (NS_FAILED(rv) && aCallback) {
     // However, if it does fail, we still need to call the callback since we
     // discard the failure.  Do it asynchronously so that the caller is always
     // guaranteed async behavior.
     RefPtr<CallbackCaller> caller = new CallbackCaller(aCallback);
--- a/editor/spellchecker/nsISpellChecker.h
+++ b/editor/spellchecker/nsISpellChecker.h
@@ -6,18 +6,16 @@
 #ifndef nsISpellChecker_h__
 #define nsISpellChecker_h__
 
 #include "mozilla/MozPromise.h"
 #include "nsISupports.h"
 #include "nsStringFwd.h"
 #include "nsTArray.h"
 
-#define NS_SPELLCHECKER_CONTRACTID "@mozilla.org/spellchecker;1"
-
 #define NS_ISPELLCHECKER_IID                    \
 { /* 27bff957-b486-40ae-9f5d-af0cdd211868 */    \
 0x27bff957, 0xb486, 0x40ae, \
   { 0x9f, 0x5d, 0xaf, 0x0c, 0xdd, 0x21, 0x18, 0x68 } }
 
 namespace mozilla {
 class TextServicesDocument;
 } // namespace mozilla
--- a/extensions/spellcheck/hunspell/glue/RemoteSpellCheckEngineParent.cpp
+++ b/extensions/spellcheck/hunspell/glue/RemoteSpellCheckEngineParent.cpp
@@ -1,23 +1,23 @@
 /* vim: set ts=2 sw=2 sts=2 tw=80: */
 /* 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 "RemoteSpellCheckEngineParent.h"
 #include "mozilla/Unused.h"
-#include "nsISpellChecker.h"
+#include "mozilla/mozSpellChecker.h"
 #include "nsServiceManagerUtils.h"
 
 namespace mozilla {
 
 RemoteSpellcheckEngineParent::RemoteSpellcheckEngineParent()
 {
-  mSpellChecker = do_CreateInstance(NS_SPELLCHECKER_CONTRACTID);
+  mSpellChecker = mozSpellChecker::Create();
 }
 
 RemoteSpellcheckEngineParent::~RemoteSpellcheckEngineParent()
 {
 }
 
 mozilla::ipc::IPCResult
 RemoteSpellcheckEngineParent::RecvSetDictionary(
--- a/extensions/spellcheck/src/mozSpellChecker.h
+++ b/extensions/spellcheck/src/mozSpellChecker.h
@@ -17,25 +17,30 @@
 #include "nsCycleCollectionParticipant.h"
 
 class mozEnglishWordUtils;
 
 namespace mozilla {
 class RemoteSpellcheckEngineChild;
 } // namespace mozilla
 
-class mozSpellChecker : public nsISpellChecker
+class mozSpellChecker final : public nsISpellChecker
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_CLASS(mozSpellChecker)
 
-  mozSpellChecker();
-
-  nsresult Init();
+  static already_AddRefed<mozSpellChecker>
+  Create()
+  {
+    RefPtr<mozSpellChecker> spellChecker = new mozSpellChecker();
+    nsresult rv = spellChecker->Init();
+    NS_ENSURE_SUCCESS(rv, nullptr);
+    return spellChecker.forget();
+  }
 
   // nsISpellChecker
   NS_IMETHOD SetDocument(mozilla::TextServicesDocument* aTextServicesDocument,
                          bool aFromStartofDoc) override;
   NS_IMETHOD NextMisspelledWord(nsAString &aWord, nsTArray<nsString> *aSuggestions) override;
   NS_IMETHOD CheckWord(const nsAString &aWord, bool *aIsMisspelled, nsTArray<nsString> *aSuggestions) override;
   NS_IMETHOD Replace(const nsAString &aOldWord, const nsAString &aNewWord, bool aAllOccurrences) override;
   NS_IMETHOD IgnoreAll(const nsAString &aWord) override;
@@ -52,18 +57,21 @@ public:
 
   void DeleteRemoteEngine() {
     mEngine = nullptr;
   }
 
   mozilla::TextServicesDocument* GetTextServicesDocument();
 
 protected:
+  mozSpellChecker();
   virtual ~mozSpellChecker();
 
+  nsresult Init();
+
   RefPtr<mozEnglishWordUtils> mConverter;
   RefPtr<mozilla::TextServicesDocument> mTextServicesDocument;
   nsCOMPtr<mozIPersonalDictionary> mPersonalDictionary;
 
   nsCOMPtr<mozISpellCheckingEngine>  mSpellCheckingEngine;
   bool mFromStart;
 
   nsString mCurrentDictionary;
--- a/extensions/spellcheck/src/mozSpellCheckerFactory.cpp
+++ b/extensions/spellcheck/src/mozSpellCheckerFactory.cpp
@@ -1,43 +1,33 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* 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 "mozilla/ModuleUtils.h"
 #include "mozHunspell.h"
-#include "mozSpellChecker.h"
 #include "mozPersonalDictionary.h"
 #include "nsIFile.h"
 
-#define NS_SPELLCHECKER_CID         \
-{ /* 8227f019-afc7-461e-b030-9f185d7a0e29 */    \
-0x8227F019, 0xAFC7, 0x461e,                     \
-{ 0xB0, 0x30, 0x9F, 0x18, 0x5D, 0x7A, 0x0E, 0x29} }
-
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(mozHunspell, Init)
-NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(mozSpellChecker, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(mozPersonalDictionary, Init)
 
 NS_DEFINE_NAMED_CID(MOZ_HUNSPELL_CID);
-NS_DEFINE_NAMED_CID(NS_SPELLCHECKER_CID);
 NS_DEFINE_NAMED_CID(MOZ_PERSONALDICTIONARY_CID);
 
 static const mozilla::Module::CIDEntry kSpellcheckCIDs[] = {
     { &kMOZ_HUNSPELL_CID, false, nullptr, mozHunspellConstructor },
-    { &kNS_SPELLCHECKER_CID, false, nullptr, mozSpellCheckerConstructor },
     { &kMOZ_PERSONALDICTIONARY_CID, false, nullptr, mozPersonalDictionaryConstructor },
     { nullptr }
 };
 
 static const mozilla::Module::ContractIDEntry kSpellcheckContracts[] = {
     { MOZ_HUNSPELL_CONTRACTID, &kMOZ_HUNSPELL_CID },
-    { NS_SPELLCHECKER_CONTRACTID, &kNS_SPELLCHECKER_CID },
     { MOZ_PERSONALDICTIONARY_CONTRACTID, &kMOZ_PERSONALDICTIONARY_CID },
     { nullptr }
 };
 
 const mozilla::Module kSpellcheckModule = {
     mozilla::Module::kVersion,
     kSpellcheckCIDs,
     kSpellcheckContracts,