summaryrefslogtreecommitdiffstats
path: root/browser/components/migration/MigrationUtils.sys.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'browser/components/migration/MigrationUtils.sys.mjs')
-rw-r--r--browser/components/migration/MigrationUtils.sys.mjs49
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)
);
}
}