Bug 1488659 - Part 1: Remove the XPCOM registrations for character detector classes; r=hsivonen
authorEhsan Akhgari <ehsan@mozilla.com>
Sun, 09 Sep 2018 20:27:17 -0400
changeset 435449 d94ad30a3001
parent 435448 86bba958748d
child 435450 68ad5bdca1ce
push id107637
push usereakhgari@mozilla.com
push dateMon, 10 Sep 2018 11:59:50 +0000
treeherdermozilla-inbound@68ad5bdca1ce [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsivonen
bugs1488659
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 1488659 - Part 1: Remove the XPCOM registrations for character detector classes; r=hsivonen Differential Revision: https://phabricator.services.mozilla.com/D5392
extensions/universalchardet/src/xpcom/moz.build
extensions/universalchardet/src/xpcom/nsUdetXPCOMWrapper.h
extensions/universalchardet/src/xpcom/nsUniversalCharDetModule.cpp
intl/chardet/moz.build
intl/chardet/nsCharDetConstructors.h
intl/chardet/nsChardetModule.cpp
intl/chardet/nsCyrillicDetector.h
intl/chardet/nsICharsetDetector.h
intl/chardet/nsIStringCharsetDetector.h
parser/html/moz.build
parser/html/nsHtml5StreamParser.cpp
--- a/extensions/universalchardet/src/xpcom/moz.build
+++ b/extensions/universalchardet/src/xpcom/moz.build
@@ -1,16 +1,15 @@
 # -*- 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/.
 
 UNIFIED_SOURCES += [
     'nsUdetXPCOMWrapper.cpp',
-    'nsUniversalCharDetModule.cpp',
 ]
 
 FINAL_LIBRARY = 'xul'
 
 LOCAL_INCLUDES += [
     '../base',
 ]
--- a/extensions/universalchardet/src/xpcom/nsUdetXPCOMWrapper.h
+++ b/extensions/universalchardet/src/xpcom/nsUdetXPCOMWrapper.h
@@ -5,18 +5,18 @@
 
 #ifndef _nsUdetXPCOMWrapper_h__
 #define _nsUdetXPCOMWrapper_h__
 #include "nsISupports.h"
 #include "nsICharsetDetector.h"
 #include "nsIStringCharsetDetector.h"
 #include "nsICharsetDetectionObserver.h"
 #include "nsCOMPtr.h"
-
 #include "nsIFactory.h"
+#include "nsUniversalDetector.h"
 
 // {12BB8F1B-2389-11d3-B3BF-00805F8A6670}
 #define NS_JA_PSMDETECTOR_CID \
 { 0x12bb8f1b, 0x2389, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
 
 // {12BB8F1C-2389-11d3-B3BF-00805F8A6670}
 #define NS_JA_STRING_PSMDETECTOR_CID \
 { 0x12bb8f1c, 0x2389, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
deleted file mode 100644
--- a/extensions/universalchardet/src/xpcom/nsUniversalCharDetModule.cpp
+++ /dev/null
@@ -1,52 +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/. */
-
-#include "mozilla/ModuleUtils.h"
-
-#include "nsCOMPtr.h"
-
-#include "nspr.h"
-#include "nsString.h"
-#include "nsUniversalCharDetDll.h"
-#include "nsISupports.h"
-#include "nsICategoryManager.h"
-#include "nsIComponentManager.h"
-#include "nsIServiceManager.h"
-#include "nsICharsetDetector.h"
-#include "nsIStringCharsetDetector.h"
-
-#include "nsUniversalDetector.h"
-#include "nsUdetXPCOMWrapper.h"
-
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsJAPSMDetector)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsJAStringPSMDetector)
-NS_DEFINE_NAMED_CID(NS_JA_PSMDETECTOR_CID);
-NS_DEFINE_NAMED_CID(NS_JA_STRING_PSMDETECTOR_CID);
-
-static const mozilla::Module::CIDEntry kChardetCIDs[] = {
-  { &kNS_JA_PSMDETECTOR_CID, false, nullptr, nsJAPSMDetectorConstructor },
-  { &kNS_JA_STRING_PSMDETECTOR_CID, false, nullptr, nsJAStringPSMDetectorConstructor },
-  { nullptr }
-};
-
-static const mozilla::Module::ContractIDEntry kChardetContracts[] = {
-  { NS_CHARSET_DETECTOR_CONTRACTID_BASE "ja_parallel_state_machine", &kNS_JA_PSMDETECTOR_CID },
-  { NS_STRCDETECTOR_CONTRACTID_BASE "ja_parallel_state_machine", &kNS_JA_STRING_PSMDETECTOR_CID },
-  { nullptr }
-};
-
-static const mozilla::Module::CategoryEntry kChardetCategories[] = {
-  { NS_CHARSET_DETECTOR_CATEGORY, "ja_parallel_state_machine", NS_CHARSET_DETECTOR_CONTRACTID_BASE "ja_parallel_state_machine" },
-  { nullptr }
-};
-
-static const mozilla::Module kChardetModule = {
-  mozilla::Module::kVersion,
-  kChardetCIDs,
-  kChardetContracts,
-  kChardetCategories
-};
-
-NSMODULE_DEFN(nsUniversalCharDetModule) = &kChardetModule;
--- a/intl/chardet/moz.build
+++ b/intl/chardet/moz.build
@@ -7,13 +7,12 @@
 EXPORTS += [
     'nsDetectionConfident.h',
     'nsICharsetDetectionObserver.h',
     'nsICharsetDetector.h',
     'nsIStringCharsetDetector.h',
 ]
 
 UNIFIED_SOURCES += [
-    'nsChardetModule.cpp',
     'nsCyrillicDetector.cpp',
 ]
 
 FINAL_LIBRARY = 'xul'
deleted file mode 100644
--- a/intl/chardet/nsCharDetConstructors.h
+++ /dev/null
@@ -1,26 +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/. */
-
-/*
- * Header file to be included by module -
- * warning: defines a whole bunch of static functions
- */
-
-#ifndef nsCharDetConstructors_h__
-#define nsCharDetConstructors_h__
-
-// chardet
-#include "nsISupports.h"
-#include "nsICharsetDetector.h"
-#include "nsICharsetDetectionObserver.h"
-#include "nsIStringCharsetDetector.h"
-#include "nsCyrillicDetector.h"
-
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsRUProbDetector)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsUKProbDetector)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsRUStringProbDetector)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsUKStringProbDetector)
-
-#endif
deleted file mode 100644
--- a/intl/chardet/nsChardetModule.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; 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/ModuleUtils.h"
-
-#include "nsCharDetConstructors.h"
-
-NS_DEFINE_NAMED_CID(NS_RU_PROBDETECTOR_CID);
-NS_DEFINE_NAMED_CID(NS_UK_PROBDETECTOR_CID);
-NS_DEFINE_NAMED_CID(NS_RU_STRING_PROBDETECTOR_CID);
-NS_DEFINE_NAMED_CID(NS_UK_STRING_PROBDETECTOR_CID);
-
-static const mozilla::Module::CIDEntry kChardetCIDs[] = {
-  { &kNS_RU_PROBDETECTOR_CID, false, nullptr, nsRUProbDetectorConstructor },
-  { &kNS_UK_PROBDETECTOR_CID, false, nullptr, nsUKProbDetectorConstructor },
-  { &kNS_RU_STRING_PROBDETECTOR_CID, false, nullptr, nsRUStringProbDetectorConstructor },
-  { &kNS_UK_STRING_PROBDETECTOR_CID, false, nullptr, nsUKStringProbDetectorConstructor },
-  { nullptr }
-};
-
-static const mozilla::Module::ContractIDEntry kChardetContracts[] = {
-  { NS_CHARSET_DETECTOR_CONTRACTID_BASE "ruprob", &kNS_RU_PROBDETECTOR_CID },
-  { NS_CHARSET_DETECTOR_CONTRACTID_BASE "ukprob", &kNS_UK_PROBDETECTOR_CID },
-  { NS_STRCDETECTOR_CONTRACTID_BASE "ruprob", &kNS_RU_STRING_PROBDETECTOR_CID },
-  { NS_STRCDETECTOR_CONTRACTID_BASE "ukprob", &kNS_UK_STRING_PROBDETECTOR_CID },
-  { nullptr }
-};
-
-static const mozilla::Module::CategoryEntry kChardetCategories[] = {
-  { NS_CHARSET_DETECTOR_CATEGORY, "off", "off" },
-  { NS_CHARSET_DETECTOR_CATEGORY, "ruprob", NS_CHARSET_DETECTOR_CONTRACTID_BASE "ruprob" },
-  { NS_CHARSET_DETECTOR_CATEGORY, "ukprob", NS_CHARSET_DETECTOR_CONTRACTID_BASE "ukprob" },
-  { nullptr }
-};
-
-static const mozilla::Module kChardetModule = {
-  mozilla::Module::kVersion,
-  kChardetCIDs,
-  kChardetContracts,
-  kChardetCategories
-};
-
-NSMODULE_DEFN(nsChardetModule) = &kChardetModule;
--- a/intl/chardet/nsCyrillicDetector.h
+++ b/intl/chardet/nsCyrillicDetector.h
@@ -1,16 +1,17 @@
 /* -*- Mode: C; tab-width: 4; 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 nsCyrillicDetector_h__
 #define nsCyrillicDetector_h__
 
 #include "nsCyrillicClass.h"
+#include "nsIStringCharsetDetector.h"
 
 
 
 
 // {2002F781-3960-11d3-B3C3-00805F8A6670}
 #define NS_RU_PROBDETECTOR_CID \
 { 0x2002f781, 0x3960, 0x11d3, { 0xb3, 0xc3, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
 
--- a/intl/chardet/nsICharsetDetector.h
+++ b/intl/chardet/nsICharsetDetector.h
@@ -9,19 +9,16 @@
 #include "nsISupports.h"
 
 class nsICharsetDetectionObserver;
 
 // {12BB8F14-2389-11d3-B3BF-00805F8A6670}
 #define NS_ICHARSETDETECTOR_IID \
 { 0x12bb8f14, 0x2389, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
 
-#define NS_CHARSET_DETECTOR_CONTRACTID_BASE "@mozilla.org/intl/charsetdetect;1?type="
-#define NS_CHARSET_DETECTOR_CATEGORY "charset-detectors"
-
 class nsICharsetDetector : public nsISupports {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICHARSETDETECTOR_IID)
 
   /*
      Setup the observer so it know how to notify the answer
    */
   NS_IMETHOD Init(nsICharsetDetectionObserver* observer) = 0;
--- a/intl/chardet/nsIStringCharsetDetector.h
+++ b/intl/chardet/nsIStringCharsetDetector.h
@@ -7,19 +7,16 @@
 
 #include "nsISupports.h"
 #include "nsDetectionConfident.h"
 
 // {12BB8F15-2389-11d3-B3BF-00805F8A6670}
 #define NS_ISTRINGCHARSETDETECTOR_IID \
 { 0x12bb8f15, 0x2389, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
 
-
-#define NS_STRCDETECTOR_CONTRACTID_BASE "@mozilla.org/intl/stringcharsetdetect;1?type="
-
 /*
   This interface is similar to nsICharsetDetector
   The difference is it is for line base detection instead of block based
   detectection.
  */
 
 
 class nsIStringCharsetDetector : public nsISupports {
--- a/parser/html/moz.build
+++ b/parser/html/moz.build
@@ -91,12 +91,15 @@ UNIFIED_SOURCES += [
 ]
 
 FINAL_LIBRARY = 'xul'
 
 # DEFINES['ENABLE_VOID_MENUITEM'] = True
 
 LOCAL_INCLUDES += [
     '/dom/base',
+    '/extensions/universalchardet/src/base',
+    '/extensions/universalchardet/src/xpcom',
+    '/intl/chardet',
 ]
 
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
     CXXFLAGS += ['-Wno-error=shadow']
--- a/parser/html/nsHtml5StreamParser.cpp
+++ b/parser/html/nsHtml5StreamParser.cpp
@@ -4,16 +4,17 @@
  * 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 "nsHtml5StreamParser.h"
 
 #include "mozilla/DebugOnly.h"
 #include "mozilla/Encoding.h"
 #include "nsContentUtils.h"
+#include "nsCyrillicDetector.h"
 #include "nsHtml5Tokenizer.h"
 #include "nsIHttpChannel.h"
 #include "nsHtml5Parser.h"
 #include "nsHtml5TreeBuilder.h"
 #include "nsHtml5AtomTable.h"
 #include "nsHtml5Module.h"
 #include "nsHtml5StreamParserPtr.h"
 #include "nsIDocShell.h"
@@ -26,16 +27,17 @@
 #include "expat_config.h"
 #include "expat.h"
 #include "nsINestedURI.h"
 #include "nsCharsetSource.h"
 #include "nsIWyciwygChannel.h"
 #include "nsIThreadRetargetableRequest.h"
 #include "nsPrintfCString.h"
 #include "nsNetUtil.h"
+#include "nsUdetXPCOMWrapper.h"
 #include "nsXULAppAPI.h"
 #include "mozilla/SchedulerGroup.h"
 #include "nsJSEnvironment.h"
 
 using namespace mozilla;
 
 /*
  * Note that nsHtml5StreamParser implements cycle collecting AddRef and
@@ -198,20 +200,27 @@ nsHtml5StreamParser::nsHtml5StreamParser
 
   // Chardet instantiation adapted from File.
   // Chardet is initialized here even if it turns out to be useless
   // to make the chardet refcount its observer (nsHtml5StreamParser)
   // on the main thread.
   nsAutoCString detectorName;
   Preferences::GetLocalizedCString("intl.charset.detector", detectorName);
   if (!detectorName.IsEmpty()) {
-    nsAutoCString detectorContractID;
-    detectorContractID.AssignLiteral(NS_CHARSET_DETECTOR_CONTRACTID_BASE);
-    detectorContractID += detectorName;
-    if ((mChardet = do_CreateInstance(detectorContractID.get()))) {
+    // We recognize one of the three magic strings for the following languages.
+    if (detectorName.EqualsLiteral("ruprob")) {
+      mChardet = new nsRUProbDetector();
+    } else if (detectorName.EqualsLiteral("ukprob")) {
+      mChardet = new nsUKProbDetector();
+    } else if (detectorName.EqualsLiteral("ja_parallel_state_machine")) {
+      mChardet = new nsJAPSMDetector();
+    } else {
+      mChardet = nullptr;
+    }
+    if (mChardet) {
       (void)mChardet->Init(this);
       mFeedChardet = true;
     }
   }
 
   // There's a zeroing operator new for everything else
 }