Bug 1405264 Part 2: Use startupData for new langpacks r=gandalf,kmag

Webextension-formatted langpacks now store their list of chrome
registry resources in startupData so that those resources can be
registered early in startup.

MozReview-Commit-ID: 80eOiPKLlWu

--HG--
extra : rebase_source : b00abc0484e6b41bfb1d17c543a450dc737a6b30
This commit is contained in:
Andrew Swan 2017-10-04 13:29:20 -07:00
Родитель 73d8eb4bdc
Коммит 1b859fa83a
2 изменённых файлов: 29 добавлений и 28 удалений

Просмотреть файл

@ -313,6 +313,8 @@ this.ExtensionData = class {
this.dependencies = new Set();
this.permissions = new Set();
this.startupData = null;
this.errors = [];
this.warnings = [];
}
@ -620,6 +622,24 @@ this.ExtensionData = class {
webAccessibleResources = manifest.web_accessible_resources
.map(path => path.replace(/^\/*/, "/"));
}
} else if (this.type == "langpack") {
// Compute the chrome resources to be registered for this langpack
// and stash them in startupData
const platform = AppConstants.platform;
const chromeEntries = [];
for (const [language, entry] of Object.entries(manifest.languages)) {
for (const [alias, path] of Object.entries(entry.chrome_resources || {})) {
if (typeof path === "string") {
chromeEntries.push(["locale", alias, language, path]);
} else if (platform in path) {
// If the path is not a string, it's an object with path per
// platform where the keys are taken from AppConstants.platform
chromeEntries.push(["locale", alias, language, path[platform]]);
}
}
}
this.startupData = {chromeEntries};
}
return {apiNames, dependencies, originPermissions, id, manifest, permissions,
@ -1608,6 +1628,7 @@ this.Extension = class extends ExtensionData {
this.Langpack = class extends ExtensionData {
constructor(addonData, startupReason) {
super(addonData.resourceURI);
this.startupData = addonData.startupData;
}
static getBootstrapScope(id, file) {
@ -1661,7 +1682,6 @@ this.Langpack = class extends ExtensionData {
}
data.l10nRegistrySources = l10nRegistrySources;
data.chromeResources = this.getChromeResources(data.manifest);
return data;
}
@ -1672,19 +1692,18 @@ this.Langpack = class extends ExtensionData {
}
async startup(reason) {
this.chromeRegistryHandle = null;
if (this.startupData.chromeEntries.length > 0) {
const manifestURI = Services.io.newURI("manifest.json", null, this.rootURI);
this.chromeRegistryHandle =
aomStartup.registerChrome(manifestURI, this.startupData.chromeEntries);
}
const data = await this.parseManifest();
this.langpackId = data.langpackId;
this.l10nRegistrySources = data.l10nRegistrySources;
const languages = Object.keys(data.manifest.languages);
const manifestURI = Services.io.newURI("manifest.json", null, this.rootURI);
this.chromeRegistryHandle = null;
if (data.chromeResources.length > 0) {
this.chromeRegistryHandle =
aomStartup.registerChrome(manifestURI, data.chromeResources);
}
resourceProtocol.setSubstitution(this.langpackId, this.rootURI);
for (const [sourceName, basePath] of Object.entries(this.l10nRegistrySources)) {
@ -1707,23 +1726,4 @@ this.Langpack = class extends ExtensionData {
resourceProtocol.setSubstitution(this.langpackId, null);
}
getChromeResources(manifest) {
const chromeEntries = [];
for (const [language, entry] of Object.entries(manifest.languages)) {
for (const [alias, path] of Object.entries(entry.chrome_resources || {})) {
if (typeof path === "string") {
chromeEntries.push(["locale", alias, language, path]);
} else {
// If the path is not a string, it's an object with path per platform
// where the keys are taken from AppConstants.platform
const platform = AppConstants.platform;
if (platform in path) {
chromeEntries.push(["locale", alias, language, path[platform]]);
}
}
}
}
return chromeEntries;
}
};

Просмотреть файл

@ -363,6 +363,7 @@ async function loadManifestFromWebManifest(aUri) {
addon.optionsType = null;
addon.aboutURL = null;
addon.dependencies = Object.freeze(Array.from(extension.dependencies));
addon.startupData = extension.startupData;
if (manifest.options_ui) {
// Store just the relative path here, the AddonWrapper getURL