Bug 1430982 - part 5: Make nsEditorSpellCheck store mozSpellChecker directly rather than nsISpellChecker r?m_kato
nsEditorSpellCheck::mSpellChecker is always mozSpellChecker because it's
created only by nsEditorSpellCheck. Additionally, mozSpellChecker.h is
already exposed. So, nsEditorSpellCheck can store it as mozSpellChecker
directly.
MozReview-Commit-ID: 2vyDe4plncM
--- a/editor/composer/nsEditorSpellCheck.cpp
+++ b/editor/composer/nsEditorSpellCheck.cpp
@@ -6,16 +6,17 @@
#include <stdlib.h> // for getenv
#include "mozilla/Attributes.h" // for final
#include "mozilla/dom/Element.h" // for Element
#include "mozilla/dom/Selection.h"
#include "mozilla/intl/LocaleService.h" // for retrieving app locale
#include "mozilla/mozalloc.h" // for operator delete, etc
+#include "mozilla/mozSpellChecker.h" // for mozSpellChecker
#include "mozilla/Preferences.h" // for Preferences
#include "mozilla/TextServicesDocument.h" // for TextServicesDocument
#include "nsAString.h" // for nsAString::IsEmpty, etc
#include "nsComponentManagerUtils.h" // for do_CreateInstance
#include "nsDebug.h" // for NS_ENSURE_TRUE, etc
#include "nsDependentSubstring.h" // for Substring
#include "nsEditorSpellCheck.h"
#include "nsError.h" // for NS_ERROR_NOT_INITIALIZED, etc
@@ -23,17 +24,16 @@
#include "nsIContentPrefService2.h" // for nsIContentPrefService2, etc
#include "nsIDOMDocument.h" // for nsIDOMDocument
#include "nsIDOMElement.h" // for nsIDOMElement
#include "nsIDocument.h" // for nsIDocument
#include "nsIEditor.h" // for nsIEditor
#include "nsIHTMLEditor.h" // for nsIHTMLEditor
#include "nsILoadContext.h"
#include "nsISelection.h" // for nsISelection
-#include "nsISpellChecker.h" // for nsISpellChecker, etc
#include "nsISupportsBase.h" // for nsISupports
#include "nsISupportsUtils.h" // for NS_ADDREF
#include "nsITextServicesFilter.h" // for nsITextServicesFilter
#include "nsIURI.h" // for nsIURI
#include "nsThreadUtils.h" // for GetMainThreadSerialEventTarget
#include "nsVariant.h" // for nsIWritableVariant, etc
#include "nsLiteralString.h" // for NS_LITERAL_STRING, etc
#include "nsMemory.h" // for nsMemory
@@ -314,27 +314,27 @@ nsEditorSpellCheck::~nsEditorSpellCheck(
// The problem is that if the spell checker does not exist, we can not tell
// which dictionaries are installed. This function works around the problem,
// 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
nsEditorSpellCheck::CanSpellCheck(bool* _retval)
{
- nsresult rv;
- nsCOMPtr<nsISpellChecker> spellChecker;
- if (! mSpellChecker) {
- spellChecker = do_CreateInstance(NS_SPELLCHECKER_CONTRACTID, &rv);
- NS_ENSURE_SUCCESS(rv, rv);
- } else {
- spellChecker = mSpellChecker;
+ RefPtr<mozSpellChecker> spellChecker = mSpellChecker;
+ if (!spellChecker) {
+ spellChecker = new mozSpellChecker();
+ DebugOnly<nsresult> rv = spellChecker->Init();
+ MOZ_ASSERT(NS_SUCCEEDED(rv));
}
nsTArray<nsString> dictList;
- rv = spellChecker->GetDictionaryList(&dictList);
- NS_ENSURE_SUCCESS(rv, rv);
+ nsresult rv = spellChecker->GetDictionaryList(&dictList);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
*_retval = (dictList.Length() > 0);
return NS_OK;
}
// Instances of this class can be used as either runnables or RAII helpers.
class CallbackCaller final : public Runnable
{
@@ -415,21 +415,19 @@ nsEditorSpellCheck::InitSpellChecker(nsI
// to iterate over the text in this range.
rv = textServicesDocument->SetExtent(rangeBounds);
NS_ENSURE_SUCCESS(rv, rv);
}
}
}
- mSpellChecker = do_CreateInstance(NS_SPELLCHECKER_CONTRACTID, &rv);
- NS_ENSURE_SUCCESS(rv, rv);
-
- NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NULL_POINTER);
-
+ mSpellChecker = new mozSpellChecker();
+ rv = mSpellChecker->Init();
+ MOZ_ASSERT(NS_SUCCEEDED(rv));
rv = mSpellChecker->SetDocument(textServicesDocument, true);
NS_ENSURE_SUCCESS(rv, 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
--- a/editor/composer/nsEditorSpellCheck.h
+++ b/editor/composer/nsEditorSpellCheck.h
@@ -10,16 +10,17 @@
#include "nsCOMPtr.h" // for nsCOMPtr
#include "nsCycleCollectionParticipant.h"
#include "nsIEditorSpellCheck.h" // for NS_DECL_NSIEDITORSPELLCHECK, etc
#include "nsISupportsImpl.h"
#include "nsString.h" // for nsString
#include "nsTArray.h" // for nsTArray
#include "nscore.h" // for nsresult
+class mozSpellChecker;
class nsIEditor;
class nsISpellChecker;
class nsITextServicesFilter;
#define NS_EDITORSPELLCHECK_CID \
{ /* {75656ad9-bd13-4c5d-939a-ec6351eea0cc} */ \
0x75656ad9, 0xbd13, 0x4c5d, \
{ 0x93, 0x9a, 0xec, 0x63, 0x51, 0xee, 0xa0, 0xcc }\
@@ -44,17 +45,17 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS(nsEditorSpellCheck)
/* Declare all methods in the nsIEditorSpellCheck interface */
NS_DECL_NSIEDITORSPELLCHECK
protected:
virtual ~nsEditorSpellCheck();
- nsCOMPtr<nsISpellChecker> mSpellChecker;
+ RefPtr<mozSpellChecker> mSpellChecker;
nsTArray<nsString> mSuggestedWordList;
int32_t mSuggestedWordIndex;
// these are the words in the current personal dictionary,
// GetPersonalDictionary must be called to load them.
nsTArray<nsString> mDictionaryList;
int32_t mDictionaryIndex;
--- a/extensions/spellcheck/src/mozSpellChecker.cpp
+++ b/extensions/spellcheck/src/mozSpellChecker.cpp
@@ -9,16 +9,17 @@
#include "nsIStringEnumerator.h"
#include "nsICategoryManager.h"
#include "nsISupportsPrimitives.h"
#include "nsISimpleEnumerator.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/PRemoteSpellcheckEngineChild.h"
#include "mozilla/TextServicesDocument.h"
#include "nsXULAppAPI.h"
+#include "RemoteSpellCheckEngineChild.h"
using mozilla::dom::ContentChild;
using mozilla::GenericPromise;
using mozilla::PRemoteSpellcheckEngineChild;
using mozilla::RemoteSpellcheckEngineChild;
using mozilla::TextServicesDocument;
#define DEFAULT_SPELL_CHECKER "@mozilla.org/spellchecker/engine;1"
--- a/extensions/spellcheck/src/mozSpellChecker.h
+++ b/extensions/spellcheck/src/mozSpellChecker.h
@@ -11,17 +11,16 @@
#include "nsISpellChecker.h"
#include "nsString.h"
#include "mozIPersonalDictionary.h"
#include "mozISpellCheckingEngine.h"
#include "nsClassHashtable.h"
#include "nsTArray.h"
#include "mozISpellI18NUtil.h"
#include "nsCycleCollectionParticipant.h"
-#include "RemoteSpellCheckEngineChild.h"
namespace mozilla {
class RemoteSpellcheckEngineChild;
} // namespace mozilla
class mozSpellChecker : public nsISpellChecker
{
public: