mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-12 22:28:59 +02:00
This also removes any redundant Ci.nsISupports elements in the interface
lists.
This was done using the following script:
acecb401b7/processors/chromeutils-generateQI.jsm
MozReview-Commit-ID: AIx10P8GpZY
--HG--
extra : rebase_source : a29c07530586dc18ba040f19215475ac20fcfb3b
63 lines
1.9 KiB
JavaScript
63 lines
1.9 KiB
JavaScript
const THUMBNAIL_DIRECTORY = "thumbnails";
|
|
|
|
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", this);
|
|
ChromeUtils.import("resource://gre/modules/osfile.jsm", this);
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "gCryptoHash", function() {
|
|
return Cc["@mozilla.org/security/hash;1"].createInstance(Ci.nsICryptoHash);
|
|
});
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "gUnicodeConverter", function() {
|
|
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
|
|
.createInstance(Ci.nsIScriptableUnicodeConverter);
|
|
converter.charset = "utf8";
|
|
return converter;
|
|
});
|
|
function PageThumbsStorageService() {}
|
|
|
|
PageThumbsStorageService.prototype = {
|
|
classID: Components.ID("{97943eec-0e48-49ef-b7b7-cf4aa0109bb6}"),
|
|
QueryInterface: ChromeUtils.generateQI([Ci.nsIPageThumbsStorageService]),
|
|
_xpcom_categories: [{
|
|
service: true
|
|
}],
|
|
// The path for the storage
|
|
_path: null,
|
|
get path() {
|
|
if (!this._path) {
|
|
this._path = OS.Path.join(OS.Constants.Path.localProfileDir, THUMBNAIL_DIRECTORY);
|
|
}
|
|
return this._path;
|
|
},
|
|
|
|
getLeafNameForURL(aURL) {
|
|
if (typeof aURL != "string") {
|
|
throw new TypeError("Expecting a string");
|
|
}
|
|
let hash = this._calculateMD5Hash(aURL);
|
|
return hash + ".png";
|
|
},
|
|
|
|
getFilePathForURL(aURL) {
|
|
return OS.Path.join(this.path, this.getLeafNameForURL(aURL));
|
|
},
|
|
|
|
_calculateMD5Hash(aValue) {
|
|
let hash = gCryptoHash;
|
|
let value = gUnicodeConverter.convertToByteArray(aValue);
|
|
|
|
hash.init(hash.MD5);
|
|
hash.update(value, value.length);
|
|
return this._convertToHexString(hash.finish(false));
|
|
},
|
|
|
|
_convertToHexString(aData) {
|
|
let hex = "";
|
|
for (let i = 0; i < aData.length; i++)
|
|
hex += ("0" + aData.charCodeAt(i).toString(16)).slice(-2);
|
|
return hex;
|
|
},
|
|
|
|
};
|
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([PageThumbsStorageService]);
|