forked from mirrors/gecko-dev
Backed out 2 changesets (bug 1532712) for mochitest failures at browser_policy_set_homepage.js on a CLOSED TREE.
Backed out changeset 1af088f5fc34 (bug 1532712) Backed out changeset 5fb5272aec8e (bug 1532712)
This commit is contained in:
parent
cdabe87d66
commit
cd795da219
5 changed files with 44 additions and 58 deletions
|
|
@ -24,7 +24,7 @@ ChromeUtils.defineModuleGetter(this, "AMTelemetry",
|
|||
ChromeUtils.defineModuleGetter(this, "formAutofillParent",
|
||||
"resource://formautofill/FormAutofillParent.jsm");
|
||||
|
||||
var gLastCategory = {category: undefined, subcategory: undefined};
|
||||
var gLastHash = "";
|
||||
const gXULDOMParser = new DOMParser();
|
||||
|
||||
var gCategoryInits = new Map();
|
||||
|
|
@ -34,27 +34,48 @@ function init_category_if_required(category) {
|
|||
throw "Unknown in-content prefs category! Can't init " + category;
|
||||
}
|
||||
if (categoryInfo.inited) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
return categoryInfo.init();
|
||||
categoryInfo.init();
|
||||
}
|
||||
|
||||
function register_module(categoryName, categoryObject) {
|
||||
gCategoryInits.set(categoryName, {
|
||||
inited: false,
|
||||
async init() {
|
||||
init() {
|
||||
let template = document.getElementById("template-" + categoryName);
|
||||
if (template) {
|
||||
// Replace the template element with the nodes from the parsed comment
|
||||
// string.
|
||||
let frag = MozXULElement.parseXULToFragment(template.firstChild.data);
|
||||
|
||||
await document.l10n.translateFragment(frag);
|
||||
// Gather the to-be-translated elements so that we could pass them to
|
||||
// l10n.translateElements() and get a translated promise.
|
||||
// Here we loop through the first level elements (<hbox>/<groupbox>/<deck>/etc)
|
||||
// because we know that they are not implemented by XBL bindings,
|
||||
// so it's ok to get a reference of them before inserting the node
|
||||
// to the DOM.
|
||||
//
|
||||
// If we don't have to worry about XBL, this can simply be
|
||||
// let l10nUpdatedElements = Array.from(frag.querySelectorAll("[data-l10n-id]"))
|
||||
//
|
||||
// If we can get a translated promise after insertion, this can all be
|
||||
// removed (see bug 1520659.)
|
||||
let firstLevelElements = Array.from(frag.children);
|
||||
|
||||
// Actually insert them into the DOM.
|
||||
document.l10n.pauseObserving();
|
||||
template.replaceWith(frag);
|
||||
document.l10n.resumeObserving();
|
||||
|
||||
let l10nUpdatedElements = [];
|
||||
// Collect the elements from the newly inserted first level elements.
|
||||
for (let el of firstLevelElements) {
|
||||
l10nUpdatedElements = l10nUpdatedElements.concat(
|
||||
Array.from(el.querySelectorAll("[data-l10n-id]")));
|
||||
}
|
||||
|
||||
// Set a promise on the categoryInfo object that the highlight code can await on.
|
||||
this.translated = document.l10n.translateElements(l10nUpdatedElements)
|
||||
.then(() => this.translated = undefined);
|
||||
|
||||
// Asks Preferences to update the attribute value of the entire
|
||||
// document again (this can be simplified if we could seperate the
|
||||
|
|
@ -69,7 +90,7 @@ function register_module(categoryName, categoryObject) {
|
|||
|
||||
document.addEventListener("DOMContentLoaded", init_all, {once: true});
|
||||
|
||||
async function init_all() {
|
||||
function init_all() {
|
||||
Preferences.forceEnableInstantApply();
|
||||
|
||||
gSubDialog.init();
|
||||
|
|
@ -101,7 +122,7 @@ async function init_all() {
|
|||
maybeDisplayPoliciesNotice();
|
||||
|
||||
window.addEventListener("hashchange", onHashChange);
|
||||
await gotoPref();
|
||||
gotoPref();
|
||||
|
||||
let helpButton = document.getElementById("helpButton");
|
||||
let helpUrl = Services.urlFormatter.formatURLPref("app.support.baseURL") + "preferences";
|
||||
|
|
@ -143,7 +164,7 @@ function onHashChange() {
|
|||
gotoPref();
|
||||
}
|
||||
|
||||
async function gotoPref(aCategory) {
|
||||
function gotoPref(aCategory) {
|
||||
let categories = document.getElementById("categories");
|
||||
const kDefaultCategoryInternalName = "paneGeneral";
|
||||
const kDefaultCategory = "general";
|
||||
|
|
@ -174,7 +195,7 @@ async function gotoPref(aCategory) {
|
|||
|
||||
// Updating the hash (below) or changing the selected category
|
||||
// will re-enter gotoPref.
|
||||
if (gLastCategory.category == category && !subcategory)
|
||||
if (gLastHash == category && !subcategory)
|
||||
return;
|
||||
|
||||
let item;
|
||||
|
|
@ -186,35 +207,26 @@ async function gotoPref(aCategory) {
|
|||
}
|
||||
}
|
||||
|
||||
if (gLastCategory.category || category != kDefaultCategoryInternalName || subcategory) {
|
||||
let friendlyName = internalPrefCategoryNameToFriendlyName(category);
|
||||
try {
|
||||
init_category_if_required(category);
|
||||
} catch (ex) {
|
||||
Cu.reportError("Error initializing preference category " + category + ": " + ex);
|
||||
throw ex;
|
||||
}
|
||||
|
||||
let friendlyName = internalPrefCategoryNameToFriendlyName(category);
|
||||
if (gLastHash || category != kDefaultCategoryInternalName || subcategory) {
|
||||
document.location.hash = friendlyName;
|
||||
}
|
||||
// Need to set the gLastCategory before setting categories.selectedItem since
|
||||
// Need to set the gLastHash before setting categories.selectedItem since
|
||||
// the categories 'select' event will re-enter the gotoPref codepath.
|
||||
gLastCategory.category = category;
|
||||
gLastCategory.subcategory = subcategory;
|
||||
gLastHash = category;
|
||||
if (item) {
|
||||
categories.selectedItem = item;
|
||||
} else {
|
||||
categories.clearSelection();
|
||||
}
|
||||
window.history.replaceState(category, document.title);
|
||||
|
||||
try {
|
||||
await init_category_if_required(category);
|
||||
} catch (ex) {
|
||||
Cu.reportError(new Error("Error initializing preference category " + category + ": " + ex));
|
||||
throw ex;
|
||||
}
|
||||
|
||||
// Bail out of this goToPref if the category
|
||||
// or subcategory changed during async operation.
|
||||
if (gLastCategory.category !== category ||
|
||||
gLastCategory.subcategory !== subcategory) {
|
||||
return;
|
||||
}
|
||||
|
||||
search(category, "data-category");
|
||||
|
||||
let mainContent = document.querySelector(".main-content");
|
||||
|
|
@ -272,6 +284,7 @@ async function scrollAndHighlight(subcategory, category) {
|
|||
return;
|
||||
}
|
||||
let header = getClosestDisplayedHeader(element);
|
||||
await gCategoryInits.get(category).translated;
|
||||
|
||||
scrollContentTo(header);
|
||||
element.classList.add("spotlight");
|
||||
|
|
|
|||
|
|
@ -141,18 +141,6 @@ interface DocumentL10n {
|
|||
*/
|
||||
[NewObject] Promise<void> translateElements(sequence<Element> aElements);
|
||||
|
||||
/**
|
||||
* Pauses the MutationObserver set to observe
|
||||
* localization related DOM mutations.
|
||||
*/
|
||||
[Throws] void pauseObserving();
|
||||
|
||||
/**
|
||||
* Resumes the MutationObserver set to observe
|
||||
* localization related DOM mutations.
|
||||
*/
|
||||
[Throws] void resumeObserving();
|
||||
|
||||
/**
|
||||
* A promise which gets resolved when the initial DOM localization resources
|
||||
* fetching is complete and the initial translation of the DOM is finished.
|
||||
|
|
|
|||
|
|
@ -351,14 +351,6 @@ already_AddRefed<Promise> DocumentL10n::TranslateElements(
|
|||
return MaybeWrapPromise(promise);
|
||||
}
|
||||
|
||||
void DocumentL10n::PauseObserving(ErrorResult& aRv) {
|
||||
aRv = mDOMLocalization->PauseObserving();
|
||||
}
|
||||
|
||||
void DocumentL10n::ResumeObserving(ErrorResult& aRv) {
|
||||
aRv = mDOMLocalization->ResumeObserving();
|
||||
}
|
||||
|
||||
class L10nReadyHandler final : public PromiseNativeHandler {
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
|
|
|
|||
|
|
@ -125,9 +125,6 @@ class DocumentL10n final : public nsIObserver,
|
|||
already_AddRefed<Promise> TranslateElements(
|
||||
const Sequence<OwningNonNull<Element>>& aElements, ErrorResult& aRv);
|
||||
|
||||
void PauseObserving(ErrorResult& aRv);
|
||||
void ResumeObserving(ErrorResult& aRv);
|
||||
|
||||
Promise* Ready();
|
||||
|
||||
void TriggerInitialDocumentTranslation();
|
||||
|
|
|
|||
|
|
@ -25,10 +25,6 @@ interface mozIDOMLocalization : nsISupports
|
|||
|
||||
void connectRoot(in Element aElement);
|
||||
void disconnectRoot(in Element aElement);
|
||||
|
||||
void pauseObserving();
|
||||
void resumeObserving();
|
||||
|
||||
Promise translateRoots();
|
||||
readonly attribute Promise ready;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue