diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
commit | a90a5cba08fdf6c0ceb95101c275108a152a3aed (patch) | |
tree | 532507288f3defd7f4dcf1af49698bcb76034855 /browser/components/migration/MigrationUtils.sys.mjs | |
parent | Adding debian version 126.0.1-1. (diff) | |
download | firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.tar.xz firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/migration/MigrationUtils.sys.mjs')
-rw-r--r-- | browser/components/migration/MigrationUtils.sys.mjs | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/browser/components/migration/MigrationUtils.sys.mjs b/browser/components/migration/MigrationUtils.sys.mjs index cda3028cc4..90ba6a535e 100644 --- a/browser/components/migration/MigrationUtils.sys.mjs +++ b/browser/components/migration/MigrationUtils.sys.mjs @@ -870,36 +870,53 @@ class MigrationUtils { * Iterates through the favicons, sniffs for a mime type, * and uses the mime type to properly import the favicon. * + * Note: You may not want to await on the returned promise, especially if by + * doing so there's risk of interrupting the migration of more critical + * data (e.g. bookmarks). + * * @param {object[]} favicons * An array of Objects with these properties: * {Uint8Array} faviconData: The binary data of a favicon * {nsIURI} uri: The URI of the associated page */ - insertManyFavicons(favicons) { + async insertManyFavicons(favicons) { let sniffer = Cc["@mozilla.org/image/loader;1"].createInstance( Ci.nsIContentSniffer ); + for (let faviconDataItem of favicons) { - let mimeType = sniffer.getMIMETypeFromContent( - null, - faviconDataItem.faviconData, - faviconDataItem.faviconData.length - ); + let dataURL; + + try { + // getMIMETypeFromContent throws error if could not get the mime type + // from the data. + let mimeType = sniffer.getMIMETypeFromContent( + null, + faviconDataItem.faviconData, + faviconDataItem.faviconData.length + ); + + dataURL = await new Promise((resolve, reject) => { + let buffer = new Uint8ClampedArray(faviconDataItem.faviconData); + let blob = new Blob([buffer], { type: mimeType }); + let reader = new FileReader(); + reader.addEventListener("load", () => resolve(reader.result)); + reader.addEventListener("error", reject); + reader.readAsDataURL(blob); + }); + } catch (e) { + // Even if error happens for favicon, continue the process. + console.warn(e); + continue; + } + let fakeFaviconURI = Services.io.newURI( "fake-favicon-uri:" + faviconDataItem.uri.spec ); - lazy.PlacesUtils.favicons.replaceFaviconData( - fakeFaviconURI, - faviconDataItem.faviconData, - mimeType - ); - lazy.PlacesUtils.favicons.setAndFetchFaviconForPage( + lazy.PlacesUtils.favicons.setFaviconForPage( faviconDataItem.uri, fakeFaviconURI, - true, - lazy.PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, - null, - Services.scriptSecurityManager.getSystemPrincipal() + Services.io.newURI(dataURL) ); } } |