File fullpage-translations.patch of Package LibreWolf
diff --git a/services/settings/Attachments.sys.mjs b/services/settings/Attachments.sys.mjs
index fd0b6a60d15e..322c42544bb3 100644
--- a/services/settings/Attachments.sys.mjs
+++ b/services/settings/Attachments.sys.mjs
@@ -160,6 +160,7 @@ export class Downloader {
* @param {Boolean} [options.fallbackToDump] Use the remote settings dump as a
* potential source of the attachment.
* (default: `false`)
+ * @param {string} options.serverUrl
* @throws {Downloader.DownloadError} if the file could not be fetched.
* @throws {Downloader.BadContentError} if the downloaded content integrity is not valid.
* @throws {Downloader.ServerInfoError} if the server response is not valid.
@@ -341,6 +342,7 @@ export class Downloader {
fallbackToDump = false,
avoidDownload = false,
cacheResult = true,
+ serverUrl,
} = options || {};
if (!attachmentId) {
// Check for pre-condition. This should not happen, but it is explicitly
@@ -401,6 +403,7 @@ export class Downloader {
const newBuffer = await this.downloadAsBytes(record, {
retries,
checkHash,
+ serverUrl,
});
if (cacheResult) {
const blob = new Blob([newBuffer]);
@@ -512,6 +515,7 @@ export class Downloader {
* @param {Object} options Some download options.
* @param {Number} options.retries Number of times download should be retried (default: `3`)
* @param {Boolean} options.checkHash Check content integrity (default: `true`)
+ * @param {String} options.serverUrl
* @throws {Downloader.DownloadError} if the file could not be fetched.
* @throws {Downloader.BadContentError} if the downloaded content integrity is not valid.
* @returns {ArrayBuffer} the file content.
@@ -520,17 +524,17 @@ export class Downloader {
const {
attachment: { location, hash, size },
} = record;
+ const { retries = 3, checkHash = true, serverUrl } = options;
let baseURL;
try {
- baseURL = await lazy.Utils.baseAttachmentsURL();
+ baseURL = await lazy.Utils.baseAttachmentsURL(serverUrl);
} catch (error) {
throw new Downloader.ServerInfoError(error);
}
const remoteFileUrl = baseURL + location;
- const { retries = 3, checkHash = true } = options;
let retried = 0;
while (true) {
try {
diff --git a/services/settings/RemoteSettingsClient.sys.mjs b/services/settings/RemoteSettingsClient.sys.mjs
index fc7f6705da46..6cd60ddf18f3 100644
--- a/services/settings/RemoteSettingsClient.sys.mjs
+++ b/services/settings/RemoteSettingsClient.sys.mjs
@@ -319,6 +319,7 @@ export class RemoteSettingsClient extends EventEmitter {
localFields = [],
keepAttachmentsIds = [],
lastCheckTimePref,
+ serverUrl,
} = {}
) {
// Remote Settings cannot be used in child processes (no access to disk,
@@ -348,6 +349,7 @@ export class RemoteSettingsClient extends EventEmitter {
this._lastCheckTimePref = lastCheckTimePref;
this._verifier = null;
this._syncRunning = false;
+ this._serverUrl = serverUrl;
// This attribute allows signature verification to be disabled, when running tests
// or when pulling data from a dev server.
@@ -389,9 +391,12 @@ export class RemoteSettingsClient extends EventEmitter {
}
httpClient() {
- const api = new lazy.KintoHttpClient(lazy.Utils.SERVER_URL, {
- fetchFunc: lazy.Utils.fetch, // Use fetch() wrapper.
- });
+ const api = new lazy.KintoHttpClient(
+ this._serverUrl || lazy.Utils.SERVER_URL,
+ {
+ fetchFunc: lazy.Utils.fetch, // Use fetch() wrapper.
+ }
+ );
return api.bucket(this.bucketName).collection(this.collectionName);
}
@@ -655,7 +660,7 @@ export class RemoteSettingsClient extends EventEmitter {
// We want to know which timestamp we are expected to obtain in order to leverage
// cache busting. We don't provide ETag because we don't want a 304.
const { changes } = await lazy.Utils.fetchLatestChanges(
- lazy.Utils.SERVER_URL,
+ this._serverUrl || lazy.Utils.SERVER_URL,
{
filters: {
collection: this.collectionName,
diff --git a/services/settings/Utils.sys.mjs b/services/settings/Utils.sys.mjs
index cbdf07bcdae1..cb4d801e5c97 100644
--- a/services/settings/Utils.sys.mjs
+++ b/services/settings/Utils.sys.mjs
@@ -295,9 +295,9 @@ export var Utils = {
* const attachmentsURL = await Downloader.baseAttachmentsURL();
* console.log(attachmentsURL);
*/
- async baseAttachmentsURL() {
- if (!_cdnURLs[Utils.SERVER_URL]) {
- const resp = await Utils.fetch(`${Utils.SERVER_URL}/`);
+ async baseAttachmentsURL(serverUrl = Utils.SERVER_URL) {
+ if (!_cdnURLs[serverUrl]) {
+ const resp = await Utils.fetch(`${serverUrl}/`);
const serverInfo = await resp.json();
// Server capabilities expose attachments configuration.
const {
@@ -306,10 +306,9 @@ export var Utils = {
},
} = serverInfo;
// Make sure the URL always has a trailing slash.
- _cdnURLs[Utils.SERVER_URL] =
- base_url + (base_url.endsWith("/") ? "" : "/");
+ _cdnURLs[serverUrl] = base_url + (base_url.endsWith("/") ? "" : "/");
}
- return _cdnURLs[Utils.SERVER_URL];
+ return _cdnURLs[serverUrl];
},
/**
diff --git a/toolkit/components/translations/actors/TranslationsParent.sys.mjs b/toolkit/components/translations/actors/TranslationsParent.sys.mjs
index 5a2be62a779f..5e49bdb1f43f 100644
--- a/toolkit/components/translations/actors/TranslationsParent.sys.mjs
+++ b/toolkit/components/translations/actors/TranslationsParent.sys.mjs
@@ -2130,7 +2130,9 @@ export class TranslationsParent extends JSWindowActorParent {
}
/** @type {RemoteSettingsClient} */
- const client = lazy.RemoteSettings("translations-models");
+ const client = lazy.RemoteSettings("translations-models", {
+ serverUrl: "https://firefox.settings.services.mozilla.com/v1",
+ });
TranslationsParent.#translationModelsRemoteClient = client;
client.on("sync", TranslationsParent.#handleTranslationsModelsSync);
@@ -2616,7 +2618,10 @@ export class TranslationsParent extends JSWindowActorParent {
/** @type {{buffer: ArrayBuffer}} */
const { buffer } = await client.attachments.download(
- await TranslationsParent.#bergamotWasmRecord
+ await TranslationsParent.#bergamotWasmRecord,
+ {
+ serverUrl: "https://firefox.settings.services.mozilla.com/v1",
+ }
);
const duration = Date.now() - start;
@@ -2691,7 +2696,9 @@ export class TranslationsParent extends JSWindowActorParent {
)) {
const download = () => {
lazy.console.log("Downloading record", record.name, record.id);
- return client.attachments.download(record);
+ return client.attachments.download(record, {
+ serverUrl: "https://firefox.settings.services.mozilla.com/v1",
+ });
};
queue.push({ download });
}
@@ -2715,7 +2722,10 @@ export class TranslationsParent extends JSWindowActorParent {
onFailure: () => {
console.error("Failed to download", record.name);
},
- download: () => client.attachments.download(record),
+ download: () =>
+ client.attachments.download(record, {
+ serverUrl: "https://firefox.settings.services.mozilla.com/v1",
+ }),
});
}
@@ -3028,7 +3038,9 @@ export class TranslationsParent extends JSWindowActorParent {
await chaosMode(1 / 3);
/** @type {{buffer: ArrayBuffer }} */
- const { buffer } = await client.attachments.download(record);
+ const { buffer } = await client.attachments.download(record, {
+ serverUrl: "https://firefox.settings.services.mozilla.com/v1",
+ });
languageModelFiles[record.fileType] = {
buffer,