Bug 1424898 - patch 2 - De-virtualize nsIWordBreaker and rename to mozilla::intl::WordBreaker. r=m_kato
authorJonathan Kew <jkew@mozilla.com>
Wed, 13 Dec 2017 22:17:38 -0600
changeset 448117 4c6d8b6d91b1af04198a2ad6f22f69afad1be62a
parent 448116 80ed22b2c35c71738d8bb17e5ab9923753a4afcb
child 448118 8062887ff0d9382ea84177f2c21f62dc0e613d9e
child 448123 a91a06d7c3f33efb71d6c9ff1bbc08289f83fcaa
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1424898
milestone59.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 1424898 - patch 2 - De-virtualize nsIWordBreaker and rename to mozilla::intl::WordBreaker. r=m_kato
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
dom/base/nsGlobalWindowCommands.cpp
dom/base/nsHTMLContentSerializer.cpp
dom/base/nsPlainTextSerializer.cpp
dom/base/nsXHTMLContentSerializer.cpp
editor/libeditor/InternetCiter.cpp
editor/txtsvc/nsTextServicesDocument.cpp
intl/build/nsI18nModule.cpp
intl/lwbrk/WordBreaker.cpp
intl/lwbrk/WordBreaker.h
intl/lwbrk/gtest/TestLineBreak.cpp
intl/lwbrk/moz.build
intl/lwbrk/nsIWordBreaker.h
intl/lwbrk/nsSampleWordBreaker.cpp
intl/lwbrk/nsSampleWordBreaker.h
layout/generic/nsTextFrame.cpp
toolkit/components/find/nsFind.cpp
toolkit/components/find/nsFind.h
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -175,20 +175,18 @@
 #include "nsIScrollable.h"
 #include "nsIStreamConverterService.h"
 #include "nsIStringBundle.h"
 #include "nsIURI.h"
 #include "nsIURIWithPrincipal.h"
 #include "nsIURL.h"
 #include "nsIWebNavigation.h"
 #include "nsIWindowMediator.h"
-#include "nsIWordBreaker.h"
 #include "nsIXPConnect.h"
 #include "nsJSUtils.h"
-#include "nsLWBrkCIID.h"
 #include "nsMappedAttributes.h"
 #include "nsNetCID.h"
 #include "nsNetUtil.h"
 #include "nsNodeInfoManager.h"
 #include "NullPrincipal.h"
 #include "nsParserCIID.h"
 #include "nsParserConstants.h"
 #include "nsPIDOMWindow.h"
@@ -262,17 +260,17 @@ nsIConsoleService *nsContentUtils::sCons
 nsDataHashtable<nsRefPtrHashKey<nsAtom>, EventNameMapping>* nsContentUtils::sAtomEventTable = nullptr;
 nsDataHashtable<nsStringHashKey, EventNameMapping>* nsContentUtils::sStringEventTable = nullptr;
 nsTArray<RefPtr<nsAtom>>* nsContentUtils::sUserDefinedEvents = nullptr;
 nsIStringBundleService *nsContentUtils::sStringBundleService;
 nsIStringBundle *nsContentUtils::sStringBundles[PropertiesFile_COUNT];
 nsIContentPolicy *nsContentUtils::sContentPolicyService;
 bool nsContentUtils::sTriedToGetContentPolicy = false;
 RefPtr<mozilla::intl::LineBreaker> nsContentUtils::sLineBreaker;
-nsIWordBreaker *nsContentUtils::sWordBreaker;
+RefPtr<mozilla::intl::WordBreaker> nsContentUtils::sWordBreaker;
 nsIBidiKeyboard *nsContentUtils::sBidiKeyboard = nullptr;
 uint32_t nsContentUtils::sScriptBlockerCount = 0;
 uint32_t nsContentUtils::sDOMNodeRemovedSuppressCount = 0;
 AutoTArray<nsCOMPtr<nsIRunnable>, 8>* nsContentUtils::sBlockedScriptRunners = nullptr;
 uint32_t nsContentUtils::sRunnersCountAtFirstBlocker = 0;
 nsIInterfaceRequestor* nsContentUtils::sSameOriginChecker = nullptr;
 
 bool nsContentUtils::sIsHandlingKeyBoardEvent = false;
@@ -603,18 +601,17 @@ nsContentUtils::Init()
   if (NS_FAILED(rv)) {
     // This makes life easier, but we can live without it.
 
     sIOService = nullptr;
   }
 
   sLineBreaker = mozilla::intl::LineBreaker::Create();
 
-  rv = CallGetService(NS_WBRK_CONTRACTID, &sWordBreaker);
-  NS_ENSURE_SUCCESS(rv, rv);
+  sWordBreaker = mozilla::intl::WordBreaker::Create();
 
   if (!InitializeEventTable())
     return NS_ERROR_FAILURE;
 
   if (!sEventListenerManagersHash) {
     static const PLDHashTableOps hash_table_ops =
     {
       PLDHashTable::HashVoidPtrKeyStub,
@@ -2114,17 +2111,17 @@ nsContentUtils::Shutdown()
   NS_IF_RELEASE(sConsoleService);
   sXPConnect = nullptr;
   NS_IF_RELEASE(sSecurityManager);
   NS_IF_RELEASE(sSystemPrincipal);
   NS_IF_RELEASE(sNullSubjectPrincipal);
   NS_IF_RELEASE(sIOService);
   NS_IF_RELEASE(sUUIDGenerator);
   sLineBreaker = nullptr;
-  NS_IF_RELEASE(sWordBreaker);
+  sWordBreaker = nullptr;
   NS_IF_RELEASE(sBidiKeyboard);
 
   delete sAtomEventTable;
   sAtomEventTable = nullptr;
   delete sStringEventTable;
   sStringEventTable = nullptr;
   delete sUserDefinedEvents;
   sUserDefinedEvents = nullptr;
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -30,16 +30,17 @@
 #include "nsMathUtils.h"
 #include "nsTArrayForwardDeclare.h"
 #include "Units.h"
 #include "mozilla/dom/AutocompleteInfoBinding.h"
 #include "mozilla/dom/BindingDeclarations.h" // For CallerType
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/FloatingPoint.h"
 #include "mozilla/intl/LineBreaker.h"
+#include "mozilla/intl/WordBreaker.h"
 #include "mozilla/net/ReferrerPolicy.h"
 #include "mozilla/Logging.h"
 #include "mozilla/NotNull.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/RangeBoundary.h"
 #include "nsIContentPolicy.h"
 #include "nsIDocument.h"
 #include "nsIDOMMouseEvent.h"
@@ -95,17 +96,16 @@ class nsIRunnable;
 class nsIScriptContext;
 class nsIScriptSecurityManager;
 class nsIStringBundle;
 class nsIStringBundleService;
 class nsISupportsHashKey;
 class nsIURI;
 class nsIUUIDGenerator;
 class nsIWidget;
-class nsIWordBreaker;
 class nsIXPConnect;
 class nsNodeInfoManager;
 class nsPIDOMWindowInner;
 class nsPIDOMWindowOuter;
 class nsPresContext;
 class nsStringBuffer;
 class nsStringHashKey;
 class nsTextFragment;
@@ -752,19 +752,19 @@ public:
   // Returns true if aDoc1 and aDoc2 have equal NodePrincipal()s.
   static bool HaveEqualPrincipals(nsIDocument* aDoc1, nsIDocument* aDoc2);
 
   static mozilla::intl::LineBreaker* LineBreaker()
   {
     return sLineBreaker.get();
   }
 
-  static nsIWordBreaker* WordBreaker()
+  static mozilla::intl::WordBreaker* WordBreaker()
   {
-    return sWordBreaker;
+    return sWordBreaker.get();
   }
 
   /**
    * Regster aObserver as a shutdown observer. A strong reference is held
    * to aObserver until UnregisterShutdownObserver is called.
    */
   static void RegisterShutdownObserver(nsIObserver* aObserver);
   static void UnregisterShutdownObserver(nsIObserver* aObserver);
@@ -3390,17 +3390,17 @@ private:
 
   static nsIStringBundleService* sStringBundleService;
   static nsIStringBundle* sStringBundles[PropertiesFile_COUNT];
 
   static nsIContentPolicy* sContentPolicyService;
   static bool sTriedToGetContentPolicy;
 
   static RefPtr<mozilla::intl::LineBreaker> sLineBreaker;
-  static nsIWordBreaker* sWordBreaker;
+  static RefPtr<mozilla::intl::WordBreaker> sWordBreaker;
 
   static nsIBidiKeyboard* sBidiKeyboard;
 
   static bool sInitialized;
   static uint32_t sScriptBlockerCount;
   static uint32_t sDOMNodeRemovedSuppressCount;
 
   // Not an nsCOMArray because removing elements from those is slower
--- a/dom/base/nsGlobalWindowCommands.cpp
+++ b/dom/base/nsGlobalWindowCommands.cpp
@@ -26,17 +26,16 @@
 #include "nsIWebNavigation.h"
 #include "nsIContentViewerEdit.h"
 #include "nsIContentViewer.h"
 #include "nsFocusManager.h"
 #include "nsCopySupport.h"
 #include "nsIClipboard.h"
 #include "ContentEventHandler.h"
 #include "nsContentUtils.h"
-#include "nsIWordBreaker.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/BasicEvents.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/dom/Selection.h"
 #include "mozilla/layers/KeyboardMap.h"
 
 #include "nsIClipboardDragDropHooks.h"
 #include "nsIClipboardDragDropHookList.h"
@@ -1124,22 +1123,22 @@ nsLookUpDictionaryCommand::DoCommandPara
   handler.OnQueryTextContent(&textContent);
   if (NS_WARN_IF(!textContent.mSucceeded ||
                  textContent.mReply.mString.IsEmpty())) {
     return NS_ERROR_FAILURE;
   }
 
   // XXX nsIWordBreaker doesn't use contextual breaker.
   // If OS provides it, widget should use it if contextual breaker is needed.
-  nsCOMPtr<nsIWordBreaker> wordBreaker = nsContentUtils::WordBreaker();
+  RefPtr<mozilla::intl::WordBreaker> wordBreaker = nsContentUtils::WordBreaker();
   if (NS_WARN_IF(!wordBreaker)) {
     return NS_ERROR_FAILURE;
   }
 
-  nsWordRange range =
+  mozilla::intl::WordRange range =
     wordBreaker->FindWord(textContent.mReply.mString.get(),
                           textContent.mReply.mString.Length(),
                           charAt.mReply.mOffset - offset);
   if (range.mEnd == range.mBegin) {
     return NS_ERROR_FAILURE;
   }
   range.mBegin += offset;
   range.mEnd += offset;
--- a/dom/base/nsHTMLContentSerializer.cpp
+++ b/dom/base/nsHTMLContentSerializer.cpp
@@ -22,17 +22,16 @@
 #include "nsIServiceManager.h"
 #include "nsIDocumentEncoder.h"
 #include "nsGkAtoms.h"
 #include "nsIURI.h"
 #include "nsNetUtil.h"
 #include "nsEscape.h"
 #include "nsCRT.h"
 #include "nsContentUtils.h"
-#include "nsLWBrkCIID.h"
 #include "nsIScriptElement.h"
 #include "nsAttrName.h"
 #include "nsIDocShell.h"
 #include "nsIEditor.h"
 #include "nsIHTMLEditor.h"
 #include "mozilla/dom/Element.h"
 #include "nsParserConstants.h"
 
--- a/dom/base/nsPlainTextSerializer.cpp
+++ b/dom/base/nsPlainTextSerializer.cpp
@@ -6,17 +6,16 @@
 
 /*
  * nsIContentSerializer implementation that can be used with an
  * nsIDocumentEncoder to convert a DOM into plaintext in a nice way
  * (eg for copy/paste as plaintext).
  */
 
 #include "nsPlainTextSerializer.h"
-#include "nsLWBrkCIID.h"
 #include "nsIServiceManager.h"
 #include "nsGkAtoms.h"
 #include "nsNameSpaceManager.h"
 #include "nsTextFragment.h"
 #include "nsContentUtils.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsCRT.h"
--- a/dom/base/nsXHTMLContentSerializer.cpp
+++ b/dom/base/nsXHTMLContentSerializer.cpp
@@ -22,17 +22,16 @@
 #include "nsIServiceManager.h"
 #include "nsIDocumentEncoder.h"
 #include "nsGkAtoms.h"
 #include "nsIURI.h"
 #include "nsNetUtil.h"
 #include "nsEscape.h"
 #include "nsCRT.h"
 #include "nsContentUtils.h"
-#include "nsLWBrkCIID.h"
 #include "nsIScriptElement.h"
 #include "nsStubMutationObserver.h"
 #include "nsAttrName.h"
 #include "nsComputedDOMStyle.h"
 #include "mozilla/dom/Element.h"
 
 static const int32_t kLongLineLen = 128;
 
--- a/editor/libeditor/InternetCiter.cpp
+++ b/editor/libeditor/InternetCiter.cpp
@@ -7,17 +7,16 @@
 
 #include "nsAString.h"
 #include "nsCOMPtr.h"
 #include "nsCRT.h"
 #include "nsDebug.h"
 #include "nsDependentSubstring.h"
 #include "nsError.h"
 #include "mozilla/intl/LineBreaker.h"
-#include "nsLWBrkCIID.h"
 #include "nsServiceManagerUtils.h"
 #include "nsString.h"
 #include "nsStringIterator.h"
 
 namespace mozilla {
 
 const char16_t gt ('>');
 const char16_t space (' ');
--- a/editor/txtsvc/nsTextServicesDocument.cpp
+++ b/editor/txtsvc/nsTextServicesDocument.cpp
@@ -25,17 +25,17 @@
 #include "nsIEditor.h"                  // for nsIEditor, etc
 #include "nsINode.h"                    // for nsINode
 #include "nsIPlaintextEditor.h"         // for nsIPlaintextEditor
 #include "nsISelection.h"               // for nsISelection
 #include "nsISelectionController.h"     // for nsISelectionController, etc
 #include "nsISupportsBase.h"            // for nsISupports
 #include "nsISupportsUtils.h"           // for NS_IF_ADDREF, NS_ADDREF, etc
 #include "nsITextServicesFilter.h"      // for nsITextServicesFilter
-#include "nsIWordBreaker.h"             // for nsWordRange, nsIWordBreaker
+#include "mozilla/intl/WordBreaker.h"   // for WordRange, WordBreaker
 #include "nsRange.h"                    // for nsRange
 #include "nsStaticAtom.h"               // for NS_STATIC_ATOM_SETUP, etc
 #include "nsString.h"                   // for nsString, nsAutoString
 #include "nsTextServicesDocument.h"
 #include "nscore.h"                     // for nsresult, NS_IMETHODIMP, etc
 
 #define LOCK_DOC(doc)
 #define UNLOCK_DOC(doc)
@@ -3149,18 +3149,18 @@ nsTextServicesDocument::FindWordBounds(n
   uint32_t strOffset = entry->mStrOffset + aNodeOffset - entry->mNodeOffset;
 
   // Now we use the word breaker to find the beginning and end
   // of the word from our calculated string offset.
 
   const char16_t *str = aBlockStr->get();
   uint32_t strLen = aBlockStr->Length();
 
-  nsIWordBreaker* wordBreaker = nsContentUtils::WordBreaker();
-  nsWordRange res = wordBreaker->FindWord(str, strLen, strOffset);
+  mozilla::intl::WordBreaker* wordBreaker = nsContentUtils::WordBreaker();
+  mozilla::intl::WordRange res = wordBreaker->FindWord(str, strLen, strOffset);
   if (res.mBegin > strLen) {
     return str ? NS_ERROR_ILLEGAL_VALUE : NS_ERROR_NULL_POINTER;
   }
 
   // Strip out the NBSPs at the ends
   while (res.mBegin <= res.mEnd && IS_NBSP_CHAR(str[res.mBegin])) {
     res.mBegin++;
   }
--- a/intl/build/nsI18nModule.cpp
+++ b/intl/build/nsI18nModule.cpp
@@ -1,56 +1,47 @@
 /* -*- 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"
 
-// lwbrk
-#include "nsLWBrkCIID.h"
-#include "nsSampleWordBreaker.h"
-
 // string bundles (intl)
 #include "nsStringBundleService.h"
 #include "nsStringBundleTextOverride.h"
 
 // locale
 #include "nsLocaleConstructors.h"
 
 // uconv
 
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsSampleWordBreaker)
-
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsStringBundleService, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsStringBundleTextOverride, Init)
 
 NS_DEFINE_NAMED_CID(MOZ_LOCALESERVICE_CID);
 NS_DEFINE_NAMED_CID(MOZ_OSPREFERENCES_CID);
-NS_DEFINE_NAMED_CID(NS_WBRK_CID);
 NS_DEFINE_NAMED_CID(NS_STRINGBUNDLESERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_STRINGBUNDLETEXTOVERRIDE_CID);
 NS_DEFINE_NAMED_CID(NS_COLLATIONFACTORY_CID);
 NS_DEFINE_NAMED_CID(NS_COLLATION_CID);
 
 static const mozilla::Module::CIDEntry kIntlCIDs[] = {
     { &kMOZ_LOCALESERVICE_CID, false, nullptr, mozilla::intl::LocaleServiceConstructor },
     { &kMOZ_OSPREFERENCES_CID, false, nullptr, mozilla::intl::OSPreferencesConstructor },
-    { &kNS_WBRK_CID, false, nullptr, nsSampleWordBreakerConstructor },
     { &kNS_STRINGBUNDLESERVICE_CID, false, nullptr, nsStringBundleServiceConstructor },
     { &kNS_STRINGBUNDLETEXTOVERRIDE_CID, false, nullptr, nsStringBundleTextOverrideConstructor },
     { &kNS_COLLATIONFACTORY_CID, false, nullptr, nsCollationFactoryConstructor },
     { &kNS_COLLATION_CID, false, nullptr, nsCollationConstructor },
     { nullptr }
 };
 
 static const mozilla::Module::ContractIDEntry kIntlContracts[] = {
     { MOZ_LOCALESERVICE_CONTRACTID, &kMOZ_LOCALESERVICE_CID },
     { MOZ_OSPREFERENCES_CONTRACTID, &kMOZ_OSPREFERENCES_CID },
-    { NS_WBRK_CONTRACTID, &kNS_WBRK_CID },
     { NS_STRINGBUNDLE_CONTRACTID, &kNS_STRINGBUNDLESERVICE_CID },
     { NS_STRINGBUNDLETEXTOVERRIDE_CONTRACTID, &kNS_STRINGBUNDLETEXTOVERRIDE_CID },
     { NS_COLLATIONFACTORY_CONTRACTID, &kNS_COLLATIONFACTORY_CID },
     { NS_COLLATION_CONTRACTID, &kNS_COLLATION_CID },
     { nullptr }
 };
 
 static const mozilla::Module kIntlModule = {
rename from intl/lwbrk/nsSampleWordBreaker.cpp
rename to intl/lwbrk/WordBreaker.cpp
--- a/intl/lwbrk/nsSampleWordBreaker.cpp
+++ b/intl/lwbrk/WordBreaker.cpp
@@ -1,26 +1,28 @@
 /* -*- 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 "mozilla/intl/WordBreaker.h"
 
-#include "nsSampleWordBreaker.h"
+using mozilla::intl::WordBreaker;
+using mozilla::intl::WordBreakClass;
+using mozilla::intl::WordRange;
 
-nsSampleWordBreaker::nsSampleWordBreaker()
+/*static*/
+already_AddRefed<WordBreaker>
+WordBreaker::Create()
 {
-}
-nsSampleWordBreaker::~nsSampleWordBreaker()
-{
+  return RefPtr<WordBreaker>(new WordBreaker()).forget();
 }
 
-NS_IMPL_ISUPPORTS(nsSampleWordBreaker, nsIWordBreaker)
 
-bool nsSampleWordBreaker::BreakInBetween(
+bool WordBreaker::BreakInBetween(
   const char16_t* aText1 , uint32_t aTextLen1,
   const char16_t* aText2 , uint32_t aTextLen2)
 {
   NS_PRECONDITION( nullptr != aText1, "null ptr");
   NS_PRECONDITION( nullptr != aText2, "null ptr");
 
   if(!aText1 || !aText2 || (0 == aTextLen1) || (0 == aTextLen2))
     return false;
@@ -37,18 +39,18 @@ bool nsSampleWordBreaker::BreakInBetween
 
 // we change the beginning of IS_HAN from 0x4e00 to 0x3400 to relfect Unicode 3.0
 #define IS_HAN(c)              (( 0x3400 <= (c)) && ((c) <= 0x9fff))||(( 0xf900 <= (c)) && ((c) <= 0xfaff))
 #define IS_KATAKANA(c)         (( 0x30A0 <= (c)) && ((c) <= 0x30FF))
 #define IS_HIRAGANA(c)         (( 0x3040 <= (c)) && ((c) <= 0x309F))
 #define IS_HALFWIDTHKATAKANA(c)         (( 0xFF60 <= (c)) && ((c) <= 0xFF9F))
 #define IS_THAI(c)         (0x0E00 == (0xFF80 & (c) )) // Look at the higest 9 bits
 
-/* static */ nsWordBreakClass
-nsIWordBreaker::GetClass(char16_t c)
+/* static */ WordBreakClass
+WordBreaker::GetClass(char16_t c)
 {
   // begin of the hack
 
   if (IS_ALPHABETICAL_SCRIPT(c))  {
 	  if(IS_ASCII(c))  {
 		  if(ASCII_IS_SPACE(c)) {
 			  return kWbClassSpace;
 		  } else if(ASCII_IS_ALPHA(c) || ASCII_IS_DIGIT(c)) {
@@ -71,35 +73,35 @@ nsIWordBreaker::GetClass(char16_t c)
 	  } else if(IS_HIRAGANA(c))   {
 		  return kWbClassHiraganaLetter;
 	  } else if(IS_HALFWIDTHKATAKANA(c))  {
 		  return kWbClassHWKatakanaLetter;
 	  } else  {
 		  return kWbClassAlphaLetter;
 	  }
   }
-  return static_cast<nsWordBreakClass>(0);
+  return static_cast<WordBreakClass>(0);
 }
 
-nsWordRange nsSampleWordBreaker::FindWord(
+WordRange WordBreaker::FindWord(
   const char16_t* aText , uint32_t aTextLen,
   uint32_t aOffset)
 {
-  nsWordRange range;
+  WordRange range;
   NS_PRECONDITION( nullptr != aText, "null ptr");
   NS_PRECONDITION( 0 != aTextLen, "len = 0");
   NS_PRECONDITION( aOffset <= aTextLen, "aOffset > aTextLen");
 
   range.mBegin = aTextLen + 1;
   range.mEnd = aTextLen + 1;
 
   if(!aText || aOffset > aTextLen)
     return range;
 
-  nsWordBreakClass c = GetClass(aText[aOffset]);
+  WordBreakClass c = GetClass(aText[aOffset]);
   uint32_t i;
   // Scan forward
   range.mEnd--;
   for(i = aOffset +1;i <= aTextLen; i++)
   {
      if( c != GetClass(aText[i]))
      {
        range.mEnd = i;
@@ -120,20 +122,20 @@ nsWordRange nsSampleWordBreaker::FindWor
   if(kWbClassThaiLetter == c)
   {
 	// need to call Thai word breaker from here
 	// we should pass the whole Thai segment to the thai word breaker to find a shorter answer
   }
   return range;
 }
 
-int32_t nsSampleWordBreaker::NextWord(
+int32_t WordBreaker::NextWord(
   const char16_t* aText, uint32_t aLen, uint32_t aPos)
 {
-  nsWordBreakClass c1, c2;
+  WordBreakClass c1, c2;
   uint32_t cur = aPos;
   if (cur == aLen)
     return NS_WORDBREAKER_NEED_MORE_TEXT;
   c1 = GetClass(aText[cur]);
 
   for(cur++; cur <aLen; cur++)
   {
      c2 = GetClass(aText[cur]);
rename from intl/lwbrk/nsIWordBreaker.h
rename to intl/lwbrk/WordBreaker.h
--- a/intl/lwbrk/nsIWordBreaker.h
+++ b/intl/lwbrk/WordBreaker.h
@@ -1,53 +1,54 @@
 /* -*- 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/. */
-#ifndef nsIWordBreaker_h__
-#define nsIWordBreaker_h__
-
-#include "nsISupports.h"
+#ifndef mozilla_intl_WordBreaker_h__
+#define mozilla_intl_WordBreaker_h__
 
 #include "nscore.h"
+#include "nsISupports.h"
 
 #define NS_WORDBREAKER_NEED_MORE_TEXT -1
 
-// {E86B3379-BF89-11d2-B3AF-00805F8A6670}
-#define NS_IWORDBREAKER_IID \
-{ 0xe86b3379, 0xbf89, 0x11d2, \
-   { 0xb3, 0xaf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
+namespace mozilla {
+namespace intl {
 
 typedef struct {
   uint32_t mBegin;
   uint32_t mEnd;
-} nsWordRange;
+} WordRange;
 
-enum nsWordBreakClass : uint8_t {
+enum WordBreakClass : uint8_t {
   kWbClassSpace = 0,
   kWbClassAlphaLetter,
   kWbClassPunct,
   kWbClassHanLetter,
   kWbClassKatakanaLetter,
   kWbClassHiraganaLetter,
   kWbClassHWKatakanaLetter,
   kWbClassThaiLetter
 };
 
-class nsIWordBreaker : public nsISupports
+class WordBreaker
 {
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWORDBREAKER_IID)
+  NS_INLINE_DECL_REFCOUNTING(WordBreaker)
+
+  static already_AddRefed<WordBreaker> Create();
 
-  virtual bool BreakInBetween(const char16_t* aText1 , uint32_t aTextLen1,
-                                const char16_t* aText2 ,
-                                uint32_t aTextLen2) = 0;
-  virtual nsWordRange FindWord(const char16_t* aText1 , uint32_t aTextLen1,
-                               uint32_t aOffset) = 0;
-  virtual int32_t NextWord(const char16_t* aText, uint32_t aLen,
-                           uint32_t aPos) = 0;
+  bool BreakInBetween(const char16_t* aText1, uint32_t aTextLen1,
+                      const char16_t* aText2, uint32_t aTextLen2);
+  WordRange FindWord(const char16_t* aText1, uint32_t aTextLen1,
+                     uint32_t aOffset);
+  int32_t NextWord(const char16_t* aText, uint32_t aLen, uint32_t aPos);
 
-  static nsWordBreakClass GetClass(char16_t aChar);
+  static WordBreakClass GetClass(char16_t aChar);
+
+private:
+  ~WordBreaker() { }
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIWordBreaker, NS_IWORDBREAKER_IID)
+} // namespace intl
+} // namespace mozilla
 
-#endif  /* nsIWordBreaker_h__ */
+#endif  /* mozilla_intl_WordBreaker_h__ */
--- a/intl/lwbrk/gtest/TestLineBreak.cpp
+++ b/intl/lwbrk/gtest/TestLineBreak.cpp
@@ -4,24 +4,21 @@
  * 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 <stdio.h>
 #include "nsXPCOM.h"
 #include "nsIComponentManager.h"
 #include "nsISupports.h"
 #include "nsServiceManagerUtils.h"
-#include "nsIWordBreaker.h"
-#include "nsLWBrkCIID.h"
 #include "nsString.h"
 #include "gtest/gtest.h"
 
 #include "mozilla/intl/LineBreaker.h"
-
-NS_DEFINE_CID(kWBrkCID, NS_WBRK_CID);
+#include "mozilla/intl/WordBreaker.h"
 
 static char teng1[] =
 //          1         2         3         4         5         6         7
 //01234567890123456789012345678901234567890123456789012345678901234567890123456789
  "This is a test to test(reasonable) line    break. This 0.01123 = 45 x 48.";
 
 static uint32_t lexp1[] = {
   4,7,9,14,17,34,39,40,41,42,49,54,62,64,67,69,73
@@ -123,17 +120,17 @@ TestASCIILB(mozilla::intl::LineBreaker *
     curr = lb->Next(eng1.get(), eng1.Length(), curr);
     res[i] = curr != NS_LINEBREAKER_NEED_MORE_TEXT ? curr : eng1.Length();
   }
 
   return Check(in, out, outlen, i, res);
 }
 
 bool
-TestASCIIWB(nsIWordBreaker *lb,
+TestASCIIWB(mozilla::intl::WordBreaker *lb,
             const char* in,
             const uint32_t* out, uint32_t outlen)
 {
   NS_ConvertASCIItoUTF16 eng1(in);
 
   uint32_t i;
   uint32_t res[256];
   int32_t curr = 0;
@@ -155,47 +152,38 @@ TEST(LineBreak, LineBreaker)
 
   ASSERT_TRUE(TestASCIILB(t, teng1, lexp1, sizeof(lexp1) / sizeof(uint32_t)));
   ASSERT_TRUE(TestASCIILB(t, teng2, lexp2, sizeof(lexp2) / sizeof(uint32_t)));
   ASSERT_TRUE(TestASCIILB(t, teng3, lexp3, sizeof(lexp3) / sizeof(uint32_t)));
 }
 
 TEST(LineBreak, WordBreaker)
 {
-  nsIWordBreaker *t = nullptr;
-  nsresult res = CallGetService(kWBrkCID, &t);
-  ASSERT_TRUE(NS_SUCCEEDED(res) && t);
-  NS_IF_RELEASE(t);
-
-  res = CallGetService(kWBrkCID, &t);
-  ASSERT_TRUE(NS_SUCCEEDED(res) && t);
+  RefPtr<mozilla::intl::WordBreaker> t = mozilla::intl::WordBreaker::Create();
+  ASSERT_TRUE(t);
 
   ASSERT_TRUE(TestASCIIWB(t, teng1, wexp1, sizeof(wexp1) / sizeof(uint32_t)));
   ASSERT_TRUE(TestASCIIWB(t, teng2, wexp2, sizeof(wexp2) / sizeof(uint32_t)));
   ASSERT_TRUE(TestASCIIWB(t, teng3, wexp3, sizeof(wexp3) / sizeof(uint32_t)));
-
-  NS_RELEASE(t);
 }
 
 //                         012345678901234
 static const char wb0[] = "T";
 static const char wb1[] = "h";
 static const char wb2[] = "is   is a int";
 static const char wb3[] = "ernationali";
 static const char wb4[] = "zation work.";
 
 static const char* wb[] = { wb0, wb1, wb2, wb3, wb4 };
 
 void
 TestPrintWordWithBreak()
 {
   uint32_t numOfFragment = sizeof(wb) / sizeof(char*);
-  nsIWordBreaker* wbk = nullptr;
-
-  CallGetService(kWBrkCID, &wbk);
+  RefPtr<mozilla::intl::WordBreaker> wbk = mozilla::intl::WordBreaker::Create();
 
   nsAutoString result;
 
   for (uint32_t i = 0; i < numOfFragment; i++) {
     NS_ConvertASCIItoUTF16 fragText(wb[i]);
 
     int32_t cur = 0;
     cur = wbk->NextWord(fragText.get(), fragText.Length(), cur);
@@ -220,32 +208,28 @@ TestPrintWordWithBreak()
       if (canBreak) {
         result.Append('^');
       }
       fragText.Assign(nextFragText);
     }
   }
   ASSERT_STREQ("is^   ^is^ ^a^ ^  is a intzation^ ^work^ation work.",
                NS_ConvertUTF16toUTF8(result).get());
-
-  NS_IF_RELEASE(wbk);
 }
 
 void
 TestFindWordBreakFromPosition(uint32_t fragN, uint32_t offset,
                               const char* expected)
 {
   uint32_t numOfFragment = sizeof(wb) / sizeof(char*);
-  nsIWordBreaker* wbk = nullptr;
-
-  CallGetService(kWBrkCID, &wbk);
+  RefPtr<mozilla::intl::WordBreaker> wbk = mozilla::intl::WordBreaker::Create();
 
   NS_ConvertASCIItoUTF16 fragText(wb[fragN]);
 
-  nsWordRange res = wbk->FindWord(fragText.get(), fragText.Length(), offset);
+  mozilla::intl::WordRange res = wbk->FindWord(fragText.get(), fragText.Length(), offset);
 
   bool canBreak;
   nsAutoString result(Substring(fragText, res.mBegin, res.mEnd-res.mBegin));
 
   if ((uint32_t)fragText.Length() == res.mEnd) {
     // if we hit the end of the fragment
     nsAutoString curFragText = fragText;
     for(uint32_t  p = fragN +1; p < numOfFragment ;p++)
@@ -253,17 +237,17 @@ TestFindWordBreakFromPosition(uint32_t f
       NS_ConvertASCIItoUTF16 nextFragText(wb[p]);
       canBreak = wbk->BreakInBetween(curFragText.get(),
                                      curFragText.Length(),
                                      nextFragText.get(),
                                      nextFragText.Length());
       if (canBreak) {
         break;
       }
-      nsWordRange r = wbk->FindWord(nextFragText.get(), nextFragText.Length(),
+      mozilla::intl::WordRange r = wbk->FindWord(nextFragText.get(), nextFragText.Length(),
                                     0);
 
       result.Append(Substring(nextFragText, r.mBegin, r.mEnd - r.mBegin));
 
       if ((uint32_t)nextFragText.Length() != r.mEnd) {
         break;
       }
       nextFragText.Assign(curFragText);
@@ -277,32 +261,30 @@ TestFindWordBreakFromPosition(uint32_t f
       NS_ConvertASCIItoUTF16 prevFragText(wb[p-1]);
       canBreak = wbk->BreakInBetween(prevFragText.get(),
                                      prevFragText.Length(),
                                      curFragText.get(),
                                      curFragText.Length());
       if (canBreak) {
         break;
       }
-      nsWordRange r = wbk->FindWord(prevFragText.get(), prevFragText.Length(),
+      mozilla::intl::WordRange r = wbk->FindWord(prevFragText.get(), prevFragText.Length(),
                                     prevFragText.Length());
 
       result.Insert(Substring(prevFragText, r.mBegin, r.mEnd - r.mBegin), 0);
 
       if (0 != r.mBegin) {
         break;
       }
       prevFragText.Assign(curFragText);
     }
   }
 
   ASSERT_STREQ(expected, NS_ConvertUTF16toUTF8(result).get())
     << "FindWordBreakFromPosition(" << fragN << ", " << offset << ")";
-
-  NS_IF_RELEASE(wbk);
 }
 
 TEST(LineBreak, WordBreakUsage)
 {
   TestPrintWordWithBreak();
   TestFindWordBreakFromPosition(0, 0, "This");
   TestFindWordBreakFromPosition(1, 0, "his");
   TestFindWordBreakFromPosition(2, 0, "is");
--- a/intl/lwbrk/moz.build
+++ b/intl/lwbrk/moz.build
@@ -1,28 +1,24 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
 TEST_DIRS += ['gtest']
 
-EXPORTS += [
-    'nsIWordBreaker.h',
-    'nsLWBrkCIID.h',
-]
-
 EXPORTS.mozilla.intl += [
     'LineBreaker.h',
+    'WordBreaker.h',
 ]
 
 UNIFIED_SOURCES += [
     'LineBreaker.cpp',
-    'nsSampleWordBreaker.cpp',
+    'WordBreaker.cpp',
 ]
 
 if 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
     SOURCES += [
         'nsPangoBreaker.cpp',
     ]
     CXXFLAGS += CONFIG['MOZ_PANGO_CFLAGS']
 elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
deleted file mode 100644
--- a/intl/lwbrk/nsSampleWordBreaker.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/* -*- 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/. */
-#ifndef nsSampleWordBreaker_h__
-#define nsSampleWordBreaker_h__
-
-
-#include "nsIWordBreaker.h"
-
-class nsSampleWordBreaker : public nsIWordBreaker
-{
-  NS_DECL_ISUPPORTS
-public:
-
-  nsSampleWordBreaker() ;
-
-  bool BreakInBetween(const char16_t* aText1 , uint32_t aTextLen1,
-                        const char16_t* aText2 , uint32_t aTextLen2) override;
-  nsWordRange FindWord(const char16_t* aText1 , uint32_t aTextLen1,
-                       uint32_t aOffset) override;
-
-  int32_t NextWord(const char16_t* aText, uint32_t aLen, uint32_t aPos) override;
-
-protected:
-  virtual ~nsSampleWordBreaker();
-};
-
-#endif  /* nsSampleWordBreaker_h__ */
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -59,18 +59,18 @@
 
 #include "nsTextFragment.h"
 #include "nsGkAtoms.h"
 #include "nsFrameSelection.h"
 #include "nsRange.h"
 #include "nsCSSRendering.h"
 #include "nsContentUtils.h"
 #include "nsLineBreaker.h"
-#include "nsIWordBreaker.h"
 #include "nsIFrameInlines.h"
+#include "mozilla/intl/WordBreaker.h"
 #include "mozilla/StyleSetHandle.h"
 #include "mozilla/StyleSetHandleInlines.h"
 #include "mozilla/layers/LayersMessages.h"
 #include "mozilla/layers/WebRenderLayerManager.h"
 #include "mozilla/layers/WebRenderBridgeChild.h"
 #include "mozilla/webrender/WebRenderAPI.h"
 #include "mozilla/layers/StackingContextHelper.h"
 
@@ -8202,17 +8202,17 @@ ClusterIterator::ClusterIterator(nsTextF
       // No following context, so it must be the end of a line or text run
       mWordBreaks[textLen] = true;
     }
     textStart = 0;
     nsAutoString str;
     mFrag->AppendTo(str, textOffset, textLen);
     aContext.Insert(str, 0);
   }
-  nsIWordBreaker* wordBreaker = nsContentUtils::WordBreaker();
+  mozilla::intl::WordBreaker* wordBreaker = nsContentUtils::WordBreaker();
   for (int32_t i = 0; i <= textLen; ++i) {
     int32_t indexInText = i + textStart;
     mWordBreaks[i] |=
       wordBreaker->BreakInBetween(aContext.get(), indexInText,
                                   aContext.get() + indexInText,
                                   aContext.Length() - indexInText);
   }
 }
--- a/toolkit/components/find/nsFind.cpp
+++ b/toolkit/components/find/nsFind.cpp
@@ -17,17 +17,16 @@
 #include "nsITextControlFrame.h"
 #include "nsIFormControl.h"
 #include "nsTextFragment.h"
 #include "nsString.h"
 #include "nsAtom.h"
 #include "nsServiceManagerUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsIDOMElement.h"
-#include "nsIWordBreaker.h"
 #include "nsCRT.h"
 #include "nsRange.h"
 #include "nsContentUtils.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/TextEditor.h"
 
 using namespace mozilla;
 
@@ -466,16 +465,17 @@ NS_INTERFACE_MAP_END
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFind)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFind)
 
 NS_IMPL_CYCLE_COLLECTION(nsFind, mLastBlockParent, mIterNode, mIterator)
 
 nsFind::nsFind()
   : mFindBackward(false)
   , mCaseSensitive(false)
+  , mWordBreaker(nullptr)
   , mIterOffset(0)
 {
 }
 
 nsFind::~nsFind()
 {
 }
 
--- a/toolkit/components/find/nsFind.h
+++ b/toolkit/components/find/nsFind.h
@@ -9,17 +9,17 @@
 
 #include "nsIFind.h"
 
 #include "nsCOMPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsIDOMNode.h"
 #include "nsIDOMRange.h"
 #include "nsIContentIterator.h"
-#include "nsIWordBreaker.h"
+#include "mozilla/intl/WordBreaker.h"
 
 class nsIContent;
 
 #define NS_FIND_CONTRACTID "@mozilla.org/embedcomp/rangefind;1"
 
 #define NS_FIND_CID \
   {0x471f4944, 0x1dd2, 0x11b2, {0x87, 0xac, 0x90, 0xbe, 0x0a, 0x51, 0xd6, 0x09}}
 
@@ -39,17 +39,17 @@ protected:
 
   // Parameters set from the interface:
   //nsCOMPtr<nsIDOMRange> mRange;   // search only in this range
   bool mFindBackward;
   bool mCaseSensitive;
 
   // Use "find entire words" mode by setting to a word breaker or null, to
   // disable "entire words" mode.
-  nsCOMPtr<nsIWordBreaker> mWordBreaker;
+  RefPtr<mozilla::intl::WordBreaker> mWordBreaker;
 
   int32_t mIterOffset;
   nsCOMPtr<nsIDOMNode> mIterNode;
 
   // Last block parent, so that we will notice crossing block boundaries:
   nsCOMPtr<nsIDOMNode> mLastBlockParent;
   nsresult GetBlockParent(nsIDOMNode* aNode, nsIDOMNode** aParent);