Bug 1455649 - DocumentL10n, part 4 - Add mozIDOMLocalization API. draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Fri, 22 Jun 2018 13:14:23 -0700
changeset 815118 268829f20dde3f865af4589fd86c20325c83cdab
parent 815117 5246ee946c259a116dfb097b6a3dda110a0432f3
child 815119 3505693c7bf116c0331cb23462708f9e40df5578
push id115447
push userbmo:gandalf@aviary.pl
push dateFri, 06 Jul 2018 20:45:09 +0000
bugs1455649
milestone63.0a1
Bug 1455649 - DocumentL10n, part 4 - Add mozIDOMLocalization API. In order to use DOMLocalization from C++ we need an XPIDL interface. mozIDOMLocalization exposes the class and functionality allowing DocumentL10n to hook into it. MozReview-Commit-ID: GPMhw61LPEg
browser/installer/package-manifest.in
intl/l10n/moz.build
intl/l10n/mozDOMLocalization.js
intl/l10n/mozDOMLocalization.manifest
intl/l10n/mozIDOMLocalization.idl
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -357,16 +357,19 @@
 @RESPATH@/components/TestInterfaceJSMaplike.js
 #endif
 
 #if defined(MOZ_DEBUG) || defined(MOZ_DEV_EDITION) || defined(NIGHTLY_BUILD)
 @RESPATH@/browser/components/testComponents.manifest
 @RESPATH@/browser/components/startupRecorder.js
 #endif
 
+@RESPATH@/components/mozDOMLocalization.js
+@RESPATH@/components/mozDOMLocalization.manifest
+
 ; [Extensions]
 @RESPATH@/components/extensions-toolkit.manifest
 @RESPATH@/components/extension-process-script.js
 @RESPATH@/browser/components/extensions-browser.manifest
 
 ; Modules
 @RESPATH@/browser/modules/*
 @RESPATH@/modules/*
--- a/intl/l10n/moz.build
+++ b/intl/l10n/moz.build
@@ -6,16 +6,27 @@
 
 EXTRA_JS_MODULES += [
     'DOMLocalization.jsm',
     'L10nRegistry.jsm',
     'Localization.jsm',
     'MessageContext.jsm',
 ]
 
+XPIDL_SOURCES += [
+    'mozIDOMLocalization.idl',
+]
+
+XPIDL_MODULE = 'locale'
+
+EXTRA_COMPONENTS += [
+    'mozDOMLocalization.js',
+    'mozDOMLocalization.manifest',
+]
+
 XPCSHELL_TESTS_MANIFESTS += ['test/xpcshell.ini']
 
 MOCHITEST_CHROME_MANIFESTS += ['test/chrome.ini']
 
 JAR_MANIFESTS += ['jar.mn']
 
 SPHINX_TREES['l10n'] = 'docs'
 
new file mode 100644
--- /dev/null
+++ b/intl/l10n/mozDOMLocalization.js
@@ -0,0 +1,12 @@
+const { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", {});
+const { DOMLocalization } = ChromeUtils.import("resource://gre/modules/DOMLocalization.jsm", {});
+
+class mozDOMLocalization extends DOMLocalization {}
+
+
+mozDOMLocalization.prototype.classID =
+  Components.ID("{29cc3895-8835-4c5b-b53a-0c0d1a458dee}");
+mozDOMLocalization.prototype.QueryInterface =
+  ChromeUtils.generateQI([Ci.mozIDOMLocalization]);
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([mozDOMLocalization]);
new file mode 100644
--- /dev/null
+++ b/intl/l10n/mozDOMLocalization.manifest
@@ -0,0 +1,2 @@
+component {29cc3895-8835-4c5b-b53a-0c0d1a458dee} mozDOMLocalization.js
+contract @mozilla.org/intl/domlocalization;1 {29cc3895-8835-4c5b-b53a-0c0d1a458dee}
new file mode 100644
--- /dev/null
+++ b/intl/l10n/mozIDOMLocalization.idl
@@ -0,0 +1,30 @@
+/* -*- Mode: IDL; 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"
+
+webidl Document;
+webidl Element;
+
+[scriptable, uuid(7c468500-541f-4fe0-98c9-92a53b63ec8d)]
+interface mozIDOMLocalization : nsISupports
+{
+  void onDocumentParsed(in Document document);
+  void unregisterObservers();
+
+  unsigned long addResourceIds([array, size_is(aLength)] in string resourceIds, in unsigned long aLength);
+  unsigned long removeResourceIds([array, size_is(aLength)] in string resourceIds, in unsigned long aLength);
+
+  Promise formatMessages([array, size_is(aLength)] in jsval aKeys, in unsigned long aLength);
+  Promise formatValues([array, size_is(aLength)] in jsval aKeys, in unsigned long aLength);
+  Promise formatValue(in DOMString aId, [optional] in jsval aArgs);
+
+  Promise translateFragment(in Element aElement);
+  Promise translateElements([array, size_is(aLength)] in Element aElements, in unsigned long aLength);
+
+  void connectRoot(in Element aElement);
+  Promise translateRoots();
+  readonly attribute Promise ready;
+};