-
-
Save kmaglione/12a9e443609cd44b809df42804b0d27b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HG changeset patch | |
# User Zibi Braniecki <zbraniecki@mozilla.com> | |
# Date 1548628144 0 | |
# Sun Jan 27 22:29:04 2019 +0000 | |
# Node ID 582f8a42b7a91e12c9c315857a59dc95095c05e3 | |
# Parent 3db3e47eebe3c9ef94cc3f5bc82f329aec22f741 | |
Bug 1523194 - Remove XPIDL for DOMLocalization and use do_ImportModule instead. r?jfkthame | |
Differential Revision: https://phabricator.services.mozilla.com/D17780 | |
diff --git browser/installer/package-manifest.in browser/installer/package-manifest.in | |
--- browser/installer/package-manifest.in | |
+++ browser/installer/package-manifest.in | |
@@ -196,19 +196,16 @@ | |
@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@/browser/components/extensions-browser.manifest | |
; Modules | |
@RESPATH@/browser/modules/* | |
@RESPATH@/modules/* | |
@RESPATH@/browser/actors/* | |
diff --git intl/l10n/DOMLocalization.jsm intl/l10n/DOMLocalization.jsm | |
--- intl/l10n/DOMLocalization.jsm | |
+++ intl/l10n/DOMLocalization.jsm | |
@@ -814,10 +814,10 @@ class DOMLocalization extends Localizati | |
getKeysForElement(element) { | |
return { | |
id: element.getAttribute(L10NID_ATTR_NAME), | |
args: JSON.parse(element.getAttribute(L10NARGS_ATTR_NAME) || null), | |
}; | |
} | |
} | |
-this.DOMLocalization = DOMLocalization; | |
-var EXPORTED_SYMBOLS = ["DOMLocalization"]; | |
+var getDOMLocalization = () => new DOMLocalization(); | |
+var EXPORTED_SYMBOLS = ["DOMLocalization", "getDOMLocalization"]; | |
diff --git intl/l10n/DocumentL10n.cpp intl/l10n/DocumentL10n.cpp | |
--- intl/l10n/DocumentL10n.cpp | |
+++ intl/l10n/DocumentL10n.cpp | |
@@ -7,16 +7,17 @@ | |
#include "js/JSON.h" | |
#include "mozilla/dom/DocumentL10n.h" | |
#include "mozilla/dom/DocumentL10nBinding.h" | |
#include "mozilla/dom/Element.h" | |
#include "mozilla/dom/Promise.h" | |
#include "mozilla/dom/PromiseNativeHandler.h" | |
#include "nsQueryObject.h" | |
#include "nsISupports.h" | |
+#include "nsImportModule.h" | |
#include "nsContentUtils.h" | |
#include "xpcprivate.h" | |
namespace mozilla { | |
namespace dom { | |
NS_INTERFACE_MAP_BEGIN(PromiseResolver) | |
NS_INTERFACE_MAP_ENTRY(nsISupports) | |
@@ -68,43 +69,43 @@ NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(D | |
DocumentL10n::DocumentL10n(Document* aDocument) | |
: mDocument(aDocument), mState(DocumentL10nState::Initialized) { | |
mContentSink = do_QueryInterface(aDocument->GetCurrentContentSink()); | |
} | |
DocumentL10n::~DocumentL10n() {} | |
bool DocumentL10n::Init(nsTArray<nsString>& aResourceIds) { | |
- nsCOMPtr<mozIDOMLocalization> domL10n = | |
- do_CreateInstance("@mozilla.org/intl/domlocalization;1"); | |
- if (NS_WARN_IF(!domL10n)) { | |
- return false; | |
- } | |
+ nsCOMPtr<mozIDOMLocalizationJSM> jsm = | |
+ do_ImportModule("resource://gre/modules/DOMLocalization.jsm"); | |
+ MOZ_RELEASE_ASSERT(jsm); | |
+ | |
+ Unused << jsm->GetDOMLocalization(getter_AddRefs(mDOMLocalization)); | |
+ MOZ_RELEASE_ASSERT(mDOMLocalization); | |
nsIGlobalObject* global = mDocument->GetScopeObject(); | |
if (!global) { | |
return false; | |
} | |
ErrorResult rv; | |
mReady = Promise::Create(global, rv); | |
if (rv.Failed()) { | |
return false; | |
} | |
- mDOMLocalization = domL10n; | |
// The `aEager = true` here allows us to eagerly trigger | |
// resource fetching to increase the chance that the l10n | |
// resources will be ready by the time the document | |
// is ready for localization. | |
uint32_t ret; | |
mDOMLocalization->AddResourceIds(aResourceIds, true, &ret); | |
// Register observers for this instance of | |
- // mozDOMLocalization to allow it to retranslate | |
+ // DOMLocalization to allow it to retranslate | |
// the document when locale changes or pseudolocalization | |
// gets turned on. | |
mDOMLocalization->RegisterObservers(); | |
return true; | |
} | |
JSObject* DocumentL10n::WrapObject(JSContext* aCx, | |
JS::Handle<JSObject*> aGivenProto) { | |
@@ -332,16 +333,17 @@ void DocumentL10n::TriggerInitialDocumen | |
Element* elem = mDocument->GetDocumentElement(); | |
if (elem) { | |
mDOMLocalization->ConnectRoot(elem); | |
} | |
RefPtr<Promise> promise; | |
mDOMLocalization->TranslateRoots(getter_AddRefs(promise)); | |
+ | |
RefPtr<PromiseNativeHandler> l10nReadyHandler = | |
new L10nReadyHandler(mReady, this); | |
promise->AppendNativeHandler(l10nReadyHandler); | |
} | |
void DocumentL10n::InitialDocumentTranslationCompleted() { | |
if (mState >= DocumentL10nState::InitialTranslationCompleted) { | |
return; | |
diff --git intl/l10n/docs/fluent_tutorial.rst intl/l10n/docs/fluent_tutorial.rst | |
--- intl/l10n/docs/fluent_tutorial.rst | |
+++ intl/l10n/docs/fluent_tutorial.rst | |
@@ -692,22 +692,16 @@ methods. | |
DOMLocalization | |
--------------- | |
DOMLocalization extends :js:`Localization` with functionality to operate on HTML, XUL | |
and the DOM directly including DOM Overlays and Mutation Observers. | |
-mozDOMLocalization | |
------------------- | |
- | |
-mozDOMLocalization is a wrapper on DOMLocalization which exposes it via XPIDL | |
-to allow DocumentL10n and Document to communicate with it. | |
- | |
DocumentL10n | |
------------ | |
DocumentL10n implements the DocumentL10n WebIDL API and allows Document to | |
communicate with mozDOMLocalization. | |
L10nRegistry | |
------------ | |
diff --git intl/l10n/moz.build intl/l10n/moz.build | |
--- intl/l10n/moz.build | |
+++ intl/l10n/moz.build | |
@@ -12,21 +12,16 @@ EXTRA_JS_MODULES += [ | |
] | |
XPIDL_SOURCES += [ | |
'mozIDOMLocalization.idl', | |
] | |
XPIDL_MODULE = 'locale' | |
-EXTRA_COMPONENTS += [ | |
- 'mozDOMLocalization.js', | |
- 'mozDOMLocalization.manifest', | |
-] | |
- | |
EXPORTS.mozilla.dom += [ | |
'DocumentL10n.h', | |
] | |
UNIFIED_SOURCES += [ | |
'DocumentL10n.cpp', | |
] | |
diff --git intl/l10n/mozDOMLocalization.js intl/l10n/mozDOMLocalization.js | |
deleted file mode 100644 | |
--- intl/l10n/mozDOMLocalization.js | |
+++ /dev/null | |
@@ -1,9 +0,0 @@ | |
-const { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); | |
-const { DOMLocalization } = ChromeUtils.import("resource://gre/modules/DOMLocalization.jsm"); | |
- | |
-DOMLocalization.prototype.classID = | |
- Components.ID("{29cc3895-8835-4c5b-b53a-0c0d1a458dee}"); | |
-DOMLocalization.prototype.QueryInterface = | |
- ChromeUtils.generateQI([Ci.mozIDOMLocalization, Ci.nsISupportsWeakReference]); | |
- | |
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DOMLocalization]); | |
diff --git intl/l10n/mozDOMLocalization.manifest intl/l10n/mozDOMLocalization.manifest | |
deleted file mode 100644 | |
--- intl/l10n/mozDOMLocalization.manifest | |
+++ /dev/null | |
@@ -1,2 +0,0 @@ | |
-component {29cc3895-8835-4c5b-b53a-0c0d1a458dee} mozDOMLocalization.js | |
-contract @mozilla.org/intl/domlocalization;1 {29cc3895-8835-4c5b-b53a-0c0d1a458dee} | |
diff --git intl/l10n/mozIDOMLocalization.idl intl/l10n/mozIDOMLocalization.idl | |
--- intl/l10n/mozIDOMLocalization.idl | |
+++ intl/l10n/mozIDOMLocalization.idl | |
@@ -22,8 +22,14 @@ interface mozIDOMLocalization : nsISuppo | |
Promise translateFragment(in Node aNode); | |
Promise translateElements(in Array<Element> aElements); | |
void connectRoot(in Element aElement); | |
Promise translateRoots(); | |
readonly attribute Promise ready; | |
}; | |
+ | |
+[scriptable,uuid(96532d26-2422-11e9-a1ce-9bb586acd241)] | |
+interface mozIDOMLocalizationJSM : nsISupports | |
+{ | |
+ mozIDOMLocalization getDOMLocalization(); | |
+}; | |
diff --git intl/l10n/test/test_mozdomlocalization.js intl/l10n/test/test_mozdomlocalization.js | |
deleted file mode 100644 | |
--- intl/l10n/test/test_mozdomlocalization.js | |
+++ /dev/null | |
@@ -1,96 +0,0 @@ | |
-const domLocalization = | |
- Cc["@mozilla.org/intl/domlocalization;1"].createInstance( | |
- Ci.mozIDOMLocalization); | |
- | |
-const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); | |
-const { L10nRegistry, FileSource } = | |
- ChromeUtils.import("resource://gre/modules/L10nRegistry.jsm"); | |
- | |
-const fs = { | |
- "/localization/en-US/browser/menu.ftl": "key = [en] Value", | |
-}; | |
-const originalLoad = L10nRegistry.load; | |
-const originalRequested = Services.locale.requestedLocales; | |
- | |
-// Variable used to test for `L10nRegistry.load` | |
-// execution count. | |
-let loadCounter = 0; | |
- | |
-L10nRegistry.load = async function(url) { | |
- loadCounter++; | |
- return fs.hasOwnProperty(url) ? fs[url] : false; | |
-}; | |
- | |
-const source = new FileSource("test", ["en-US"], "/localization/{locale}"); | |
-L10nRegistry.registerSource(source); | |
- | |
-add_task(function test_methods_presence() { | |
- equal(typeof domLocalization.addResourceIds, "function"); | |
- equal(typeof domLocalization.removeResourceIds, "function"); | |
- equal(typeof domLocalization.registerObservers, "function"); | |
- | |
- equal(typeof domLocalization.formatMessages, "function"); | |
- equal(typeof domLocalization.formatValues, "function"); | |
- equal(typeof domLocalization.formatValue, "function"); | |
- | |
- equal(typeof domLocalization.translateFragment, "function"); | |
- equal(typeof domLocalization.translateElements, "function"); | |
- | |
- equal(typeof domLocalization.connectRoot, "function"); | |
- equal(typeof domLocalization.translateRoots, "function"); | |
- | |
- equal(typeof domLocalization.ready, "object"); | |
-}); | |
- | |
-add_task(function test_add_remove_resources() { | |
- equal(domLocalization.addResourceIds(["./path1.ftl", "./path2.ftl"], false), 2); | |
- equal(domLocalization.removeResourceIds(["./path1.ftl", "./path2.ftl"]), 0); | |
-}); | |
- | |
-add_task(async function test_add_messages_eager() { | |
- loadCounter = 0; | |
- | |
- domLocalization.addResourceIds(["/browser/menu.ftl"], true); | |
- | |
- equal(loadCounter, 1, "Load should be eagerly performed"); | |
- | |
- // Cleanup | |
- domLocalization.removeResourceIds(["/browser/menu.ftl"]); | |
-}); | |
- | |
-add_task(async function test_format_messages() { | |
- // Make sure that the cache is empty to test for I/O. | |
- L10nRegistry.sources.get("test").cache = {}; | |
- loadCounter = 0; | |
- | |
- domLocalization.addResourceIds(["/browser/menu.ftl"], false); | |
- | |
- equal(loadCounter, 0, "No loading should be performed eagerly"); | |
- | |
- let msgs = await domLocalization.formatMessages([{"id": "key"}], 1); | |
- equal(loadCounter, 1); | |
- equal(msgs.length, 1); | |
- equal(msgs[0].value, "[en] Value"); | |
-}); | |
- | |
-add_task(async function test_format_values() { | |
- let msgs = await domLocalization.formatValues([{"id": "key"}]); | |
- equal(msgs.length, 1); | |
- equal(msgs[0], "[en] Value"); | |
-}); | |
- | |
-add_task(async function test_format_value() { | |
- let msg = await domLocalization.formatValue("key"); | |
- equal(msg, "[en] Value"); | |
-}); | |
- | |
-add_task(async function test_ready() { | |
- await domLocalization.ready; | |
- equal(1, 1); | |
-}); | |
- | |
-add_task(function cleanup() { | |
- L10nRegistry.sources.clear(); | |
- L10nRegistry.load = originalLoad; | |
- Services.locale.requestedLocales = originalRequested; | |
-}); | |
diff --git intl/l10n/test/xpcshell.ini intl/l10n/test/xpcshell.ini | |
--- intl/l10n/test/xpcshell.ini | |
+++ intl/l10n/test/xpcshell.ini | |
@@ -1,10 +1,9 @@ | |
[DEFAULT] | |
head = | |
[test_domlocalization.js] | |
[test_l10nregistry.js] | |
[test_l10nregistry_sync.js] | |
[test_localization.js] | |
[test_messagecontext.js] | |
-[test_mozdomlocalization.js] | |
[test_pseudo.js] | |
diff --git mobile/android/installer/package-manifest.in mobile/android/installer/package-manifest.in | |
--- mobile/android/installer/package-manifest.in | |
+++ mobile/android/installer/package-manifest.in | |
@@ -127,19 +127,16 @@ | |
@BINPATH@/components/servicesSettings.manifest | |
#if defined(ENABLE_TESTS) && defined(MOZ_DEBUG) | |
@BINPATH@/components/TestInterfaceJS.js | |
@BINPATH@/components/TestInterfaceJS.manifest | |
@BINPATH@/components/TestInterfaceJSMaplike.js | |
#endif | |
-@BINPATH@/components/mozDOMLocalization.js | |
-@BINPATH@/components/mozDOMLocalization.manifest | |
- | |
; Modules | |
@BINPATH@/modules/* | |
@BINPATH@/actors/* | |
; [Browser Chrome Files] | |
@BINPATH@/chrome/toolkit@JAREXT@ | |
@BINPATH@/chrome/toolkit.manifest | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment