Open Bug 737861 Opened 10 years ago Updated 10 years ago

New Safari Migrator: Thumbnails for Top Sites

Categories

(Firefox :: Migration, defect)

x86
macOS
defect
Not set
normal

Tracking

()

People

(Reporter: asaf, Unassigned)

References

Details

In the new Safari migrator Top Sites are imported without their thumbnails.
This should be easy to fix.  Safari saves the thumbnails, as files, in
~/Library/Caches/com.apple.Safari/WebPage Previews (I've not looked for the path on Windows yet). For each top site, there are two thumbnails (png & jpg). The file names are the urls in a MD5-hash form.
Depends on: 710259
Required MD5-hash-generation code (from test_authentication.js):

function bytesFromString(str) {
    var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
    converter.charset = "UTF-8";
    var data = converter.convertToByteArray(str);
    return data;
}

function toHexString(charCode) {
    return ("0" + charCode.toString(16)).slice( - 2);
}

function H(str) {
    var data = bytesFromString(str);
    var ch = Components.classes["@mozilla.org/security/hash;1"].createInstance(Components.interfaces.nsICryptoHash);
    ch.init(Components.interfaces.nsICryptoHash.MD5);
    ch.update(data, data.length);
    var hash = ch.finish(false);
    return [toHexString(hash.charCodeAt(i)) for (i in hash)].join("");
}
Remaining issues:
1. Minor: Safari stores both png and jpeg variants of the thumbnail, which one should we use?
2. The thumbnails stored by safari are bigger, and have different proportions. Should they be rescaled (and cut) before storing them?

Another approach would be to retrieve thumbnails on our own.
Summary: New Safari Migrator: Import thumbnails for Top Sites → New Safari Migrator: Thumbnails for Top Sites
Correction: the thumbnails are not scaled at all, because they also have a use for the full-sized screenshot.
You could just import the PNG thumbnail and store it in the cache [PageThumbs.jsm / PageThumbsCache.getWriteEntry()]. I think it shouldn't look too bad in the newtab page and the thumbnails get updated anyway when visiting those pages.
You need to log in before you can comment on or make changes to this bug.