Bug 1466720 - Don't reload l10n.js in the PaymentRequest scope on a refresh. r=sfoster
There was an error trying to redefine variables from l10n.js via loadSubScript. We really only need
it loaded once like a frame script but I had to fix the l10n.js code to handle this properly.
MozReview-Commit-ID: EbNrEaRQJbs
--- a/browser/components/payments/content/paymentDialogFrameScript.js
+++ b/browser/components/payments/content/paymentDialogFrameScript.js
@@ -57,22 +57,16 @@ let PaymentFrameScript = {
let contentLogObject = Cu.waiveXrays(content).log;
for (let name of ["error", "warn", "info", "debug"]) {
Cu.exportFunction(privilegedLogger[name].bind(privilegedLogger), contentLogObject, {
defineAs: name,
});
}
},
- setupL10n() {
- // Until we have bug 1446164 and bug 1407418 we use form autofill's temporary
- // shim for data-localization* attributes.
- Services.scriptloader.loadSubScript("chrome://formautofill/content/l10n.js");
- },
-
/**
* Expose privileged utility functions to the unprivileged page.
*/
exposeUtilityFunctions() {
let waivedContent = Cu.waiveXrays(content);
let PaymentDialogUtils = {
DEFAULT_REGION: FormAutofillUtils.DEFAULT_REGION,
supportedCountries: FormAutofillUtils.supportedCountries,
@@ -94,17 +88,16 @@ let PaymentFrameScript = {
cloneFunctions: true,
});
},
sendToChrome({detail}) {
let {messageType} = detail;
if (messageType == "initializeRequest") {
this.setupContentConsole();
- this.setupL10n();
this.exposeUtilityFunctions();
}
this.log.debug("sendToChrome:", messageType, detail);
this.sendMessageToChrome(messageType, detail);
},
sendToContent(messageType, detail = {}) {
this.log.debug("sendToContent", messageType, detail);
--- a/browser/components/payments/content/paymentDialogWrapper.js
+++ b/browser/components/payments/content/paymentDialogWrapper.js
@@ -188,16 +188,19 @@ var paymentDialogWrapper = {
if (!this.request) {
throw new Error(`PaymentRequest not found: ${requestId}`);
}
this.frame = frame;
this.mm = frame.frameLoader.messageManager;
this.mm.addMessageListener("paymentContentToChrome", this);
this.mm.loadFrameScript("chrome://payments/content/paymentDialogFrameScript.js", true);
+ // Until we have bug 1446164 and bug 1407418 we use form autofill's temporary
+ // shim for data-localization* attributes.
+ this.mm.loadFrameScript("chrome://formautofill/content/l10n.js", true);
if (AppConstants.platform == "win") {
this.frame.setAttribute("selectmenulist", "ContentSelectDropdown-windows");
}
this.frame.loadURI("resource://payments/paymentRequest.xhtml");
this.temporaryStore = {
addresses: new TempCollection(),
creditCards: new TempCollection(),
--- a/browser/extensions/formautofill/content/l10n.js
+++ b/browser/extensions/formautofill/content/l10n.js
@@ -9,32 +9,33 @@
* the edit dialog code with the unprivileged PaymentRequest dialog before the
* Fluent conversion
*/
/* global content */
ChromeUtils.import("resource://formautofill/FormAutofillUtils.jsm");
-const CONTENT_WIN = typeof(window) != "undefined" ? window : content.window;
+const CONTENT_WIN = typeof(window) != "undefined" ? window : this;
const L10N_ATTRIBUTES = ["data-localization", "data-localization-region"];
-let mutationObserver = new CONTENT_WIN.MutationObserver(function onMutation(mutations) {
- for (let mutation of mutations) {
- if (!mutation.target.hasAttribute(mutation.attributeName)) {
- // The attribute was removed in the meantime.
- continue;
+// eslint-disable-next-line mozilla/balanced-listeners
+CONTENT_WIN.addEventListener("DOMContentLoaded", function onDCL(evt) {
+ let doc = evt.target;
+ FormAutofillUtils.localizeMarkup(doc);
+
+ let mutationObserver = new doc.ownerGlobal.MutationObserver(function onMutation(mutations) {
+ for (let mutation of mutations) {
+ if (!mutation.target.hasAttribute(mutation.attributeName)) {
+ // The attribute was removed in the meantime.
+ continue;
+ }
+ FormAutofillUtils.localizeAttributeForElement(mutation.target, mutation.attributeName);
}
- FormAutofillUtils.localizeAttributeForElement(mutation.target, mutation.attributeName);
- }
-});
+ });
-CONTENT_WIN.document.addEventListener("DOMContentLoaded", function onDCL() {
- FormAutofillUtils.localizeMarkup(CONTENT_WIN.document);
- mutationObserver.observe(CONTENT_WIN.document, {
+ mutationObserver.observe(doc, {
attributes: true,
attributeFilter: L10N_ATTRIBUTES,
subtree: true,
});
-}, {
- once: true,
});