mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1523194 - Remove XPIDL for DOMLocalization and use do_ImportModule instead. r=jfkthame,kmag
Differential Revision: https://phabricator.services.mozilla.com/D17780 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
374b57edaf
commit
614ca1e082
@ -355,9 +355,6 @@
|
||||
@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
|
||||
|
@ -823,5 +823,10 @@ class DOMLocalization extends Localization {
|
||||
}
|
||||
}
|
||||
|
||||
this.DOMLocalization = DOMLocalization;
|
||||
var EXPORTED_SYMBOLS = ["DOMLocalization"];
|
||||
/**
|
||||
* Helper function which allows us to construct a new
|
||||
* DOMLocalization from DocumentL10n.
|
||||
*/
|
||||
var getDOMLocalization = () => new DOMLocalization();
|
||||
|
||||
var EXPORTED_SYMBOLS = ["DOMLocalization", "getDOMLocalization"];
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "mozilla/dom/PromiseNativeHandler.h"
|
||||
#include "nsQueryObject.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsImportModule.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "xpcprivate.h"
|
||||
|
||||
@ -73,11 +74,12 @@ DocumentL10n::DocumentL10n(Document* aDocument)
|
||||
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) {
|
||||
@ -89,20 +91,24 @@ bool DocumentL10n::Init(nsTArray<nsString>& aResourceIds) {
|
||||
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);
|
||||
if (NS_FAILED(mDOMLocalization->AddResourceIds(aResourceIds, true, &ret))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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();
|
||||
if (NS_FAILED(mDOMLocalization->RegisterObservers())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -337,6 +343,10 @@ void DocumentL10n::TriggerInitialDocumentTranslation() {
|
||||
|
||||
RefPtr<Promise> promise;
|
||||
mDOMLocalization->TranslateRoots(getter_AddRefs(promise));
|
||||
if (!promise) {
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<PromiseNativeHandler> l10nReadyHandler =
|
||||
new L10nReadyHandler(mReady, this);
|
||||
promise->AppendNativeHandler(l10nReadyHandler);
|
||||
|
@ -697,12 +697,6 @@ 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
|
||||
------------
|
||||
|
||||
|
@ -17,11 +17,6 @@ XPIDL_SOURCES += [
|
||||
|
||||
XPIDL_MODULE = 'locale'
|
||||
|
||||
EXTRA_COMPONENTS += [
|
||||
'mozDOMLocalization.js',
|
||||
'mozDOMLocalization.manifest',
|
||||
]
|
||||
|
||||
EXPORTS.mozilla.dom += [
|
||||
'DocumentL10n.h',
|
||||
]
|
||||
|
@ -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]);
|
@ -1,2 +0,0 @@
|
||||
component {29cc3895-8835-4c5b-b53a-0c0d1a458dee} mozDOMLocalization.js
|
||||
contract @mozilla.org/intl/domlocalization;1 {29cc3895-8835-4c5b-b53a-0c0d1a458dee}
|
@ -27,3 +27,9 @@ interface mozIDOMLocalization : nsISupports
|
||||
Promise translateRoots();
|
||||
readonly attribute Promise ready;
|
||||
};
|
||||
|
||||
[scriptable,uuid(96532d26-2422-11e9-a1ce-9bb586acd241)]
|
||||
interface mozIDOMLocalizationJSM : nsISupports
|
||||
{
|
||||
mozIDOMLocalization getDOMLocalization();
|
||||
};
|
||||
|
@ -7,9 +7,10 @@
|
||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
|
||||
<script type="application/javascript">
|
||||
"use strict";
|
||||
const domLocalization =
|
||||
Cc["@mozilla.org/intl/domlocalization;1"].createInstance(
|
||||
Ci.mozIDOMLocalization);
|
||||
const { getDOMLocalization } =
|
||||
ChromeUtils.import("resource://gre/modules/DOMLocalization.jsm");
|
||||
const domLocalization = getDOMLocalization();
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { L10nRegistry, FileSource } =
|
||||
ChromeUtils.import("resource://gre/modules/L10nRegistry.jsm");
|
||||
|
@ -7,9 +7,10 @@
|
||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
|
||||
<script type="application/javascript">
|
||||
"use strict";
|
||||
const domLocalization =
|
||||
Cc["@mozilla.org/intl/domlocalization;1"].createInstance(
|
||||
Ci.mozIDOMLocalization);
|
||||
const { getDOMLocalization } =
|
||||
ChromeUtils.import("resource://gre/modules/DOMLocalization.jsm");
|
||||
const domLocalization = getDOMLocalization();
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { L10nRegistry, FileSource } =
|
||||
ChromeUtils.import("resource://gre/modules/L10nRegistry.jsm");
|
||||
|
@ -7,9 +7,10 @@
|
||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
|
||||
<script type="application/javascript">
|
||||
"use strict";
|
||||
const domLocalization =
|
||||
Cc["@mozilla.org/intl/domlocalization;1"].createInstance(
|
||||
Ci.mozIDOMLocalization);
|
||||
const { getDOMLocalization } =
|
||||
ChromeUtils.import("resource://gre/modules/DOMLocalization.jsm");
|
||||
const domLocalization = getDOMLocalization();
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { L10nRegistry, FileSource } =
|
||||
ChromeUtils.import("resource://gre/modules/L10nRegistry.jsm");
|
||||
|
@ -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;
|
||||
});
|
@ -6,5 +6,4 @@ head =
|
||||
[test_l10nregistry_sync.js]
|
||||
[test_localization.js]
|
||||
[test_messagecontext.js]
|
||||
[test_mozdomlocalization.js]
|
||||
[test_pseudo.js]
|
||||
|
@ -232,9 +232,6 @@
|
||||
@BINPATH@/components/mozIntl.manifest
|
||||
@BINPATH@/components/mozIntl.js
|
||||
|
||||
@BINPATH@/components/mozDOMLocalization.js
|
||||
@BINPATH@/components/mozDOMLocalization.manifest
|
||||
|
||||
; Modules
|
||||
@BINPATH@/modules/*
|
||||
@BINPATH@/actors/*
|
||||
|
Loading…
Reference in New Issue
Block a user