summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/PlacesUtils.sys.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
commit40a355a42d4a9444dc753c04c6608dade2f06a23 (patch)
tree871fc667d2de662f171103ce5ec067014ef85e61 /toolkit/components/places/PlacesUtils.sys.mjs
parentAdding upstream version 124.0.1. (diff)
downloadfirefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz
firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/places/PlacesUtils.sys.mjs')
-rw-r--r--toolkit/components/places/PlacesUtils.sys.mjs81
1 files changed, 42 insertions, 39 deletions
diff --git a/toolkit/components/places/PlacesUtils.sys.mjs b/toolkit/components/places/PlacesUtils.sys.mjs
index aeebedd31a..8eeb4f94d8 100644
--- a/toolkit/components/places/PlacesUtils.sys.mjs
+++ b/toolkit/components/places/PlacesUtils.sys.mjs
@@ -12,7 +12,6 @@ const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
Bookmarks: "resource://gre/modules/Bookmarks.sys.mjs",
History: "resource://gre/modules/History.sys.mjs",
- Log: "resource://gre/modules/Log.sys.mjs",
PlacesSyncUtils: "resource://gre/modules/PlacesSyncUtils.sys.mjs",
Sqlite: "resource://gre/modules/Sqlite.sys.mjs",
});
@@ -817,7 +816,7 @@ export var PlacesUtils = {
},
// nsIObserver
- observe: function PU_observe(aSubject, aTopic, aData) {
+ observe: function PU_observe(aSubject, aTopic) {
switch (aTopic) {
case this.TOPIC_SHUTDOWN:
Services.obs.removeObserver(this, this.TOPIC_SHUTDOWN);
@@ -1181,7 +1180,7 @@ export var PlacesUtils = {
{
url: { requiredIf: b => !b.guid },
guid: { requiredIf: b => !b.url },
- visits: { requiredIf: b => validateVisits },
+ visits: { requiredIf: () => validateVisits },
}
);
},
@@ -1830,14 +1829,13 @@ export var PlacesUtils = {
* Run some text through md5 and return the hash.
* @param {string} data The string to hash.
* @param {string} [format] Which format of the hash to return:
- * - "ascii" for ascii format.
+ * - "base64" for ascii format.
* - "hex" for hex format.
- * @returns {string} hash of the input string in the required format.
+ * @returns {string} hash of the input data in the required format.
* @deprecated use sha256 instead.
*/
- md5(data, { format = "ascii" } = {}) {
+ md5(data, { format = "base64" } = {}) {
let hasher = new lazy.CryptoHash("md5");
-
// Convert the data to a byte array for hashing.
data = new TextEncoder().encode(data);
hasher.update(data, data.length);
@@ -1847,7 +1845,7 @@ export var PlacesUtils = {
return Array.from(hash, (c, i) =>
hash.charCodeAt(i).toString(16).padStart(2, "0")
).join("");
- case "ascii":
+ case "base64":
default:
return hasher.finish(true);
}
@@ -1855,25 +1853,35 @@ export var PlacesUtils = {
/**
* Run some text through SHA256 and return the hash.
- * @param {string} data The string to hash.
+ * @param {string|nsIStringInputStream} data The data to hash.
* @param {string} [format] Which format of the hash to return:
- * - "ascii" for ascii format.
+ * - "base64" (default) for ascii format, not safe for URIs or file names.
* - "hex" for hex format.
- * @returns {string} hash of the input string in the required format.
+ * - "base64url" for ascii format safe to be used in file names (RFC 4648).
+ * You should normally use the "hex" format for file names, but if the
+ * user may manipulate the file, it would be annoying to have very long
+ * and unreadable file names, thus this provides a shorter alternative.
+ * Note padding "=" are untouched and may have to be encoded in URIs.
+ * @returns {string} hash of the input data in the required format.
*/
- sha256(data, { format = "ascii" } = {}) {
+ sha256(data, { format = "base64" } = {}) {
let hasher = new lazy.CryptoHash("sha256");
-
- // Convert the data to a byte array for hashing.
- data = new TextEncoder().encode(data);
- hasher.update(data, data.length);
+ if (data instanceof Ci.nsIStringInputStream) {
+ hasher.updateFromStream(data, -1);
+ } else {
+ // Convert the data string to a byte array for hashing.
+ data = new TextEncoder().encode(data);
+ hasher.update(data, data.length);
+ }
switch (format) {
case "hex":
let hash = hasher.finish(false);
return Array.from(hash, (c, i) =>
hash.charCodeAt(i).toString(16).padStart(2, "0")
).join("");
- case "ascii":
+ case "base64url":
+ return hasher.finish(true).replaceAll("+", "-").replaceAll("/", "_");
+ case "base64":
default:
return hasher.finish(true);
}
@@ -1950,31 +1958,26 @@ export var PlacesUtils = {
},
/**
- * Creates a logger.
- * Logging level can be controlled through places.loglevel.
+ * Creates a console logger.
+ * Logging level can be controlled through the `places.loglevel` preference.
*
- * @param {string} [prefix] Prefix to use for the logged messages, "::" will
- * be appended automatically to the prefix.
- * @returns {object} The logger.
+ * @param {object} options
+ * @param {string} [options.prefix] Prefix to use for the logged messages.
+ * @returns {ConsoleInstance} The console logger.
*/
getLogger({ prefix = "" } = {}) {
- if (!this._logger) {
- this._logger = lazy.Log.repository.getLogger("places");
- this._logger.manageLevelFromPref("places.loglevel");
- this._logger.addAppender(
- new lazy.Log.ConsoleAppender(new lazy.Log.BasicFormatter())
- );
- }
- if (prefix) {
- // This is not an early return because it is necessary to invoke getLogger
- // at least once before getLoggerWithMessagePrefix; it replaces a
- // method of the original logger, rather than using an actual Proxy.
- return lazy.Log.repository.getLoggerWithMessagePrefix(
- "places",
- prefix + " :: "
- );
+ if (!this._loggers) {
+ this._loggers = new Map();
+ }
+ let logger = this._loggers.get(prefix);
+ if (!logger) {
+ logger = console.createInstance({
+ prefix: `Places${prefix ? " - " + prefix : ""}`,
+ maxLogLevelPref: "places.loglevel",
+ });
+ this._loggers.set(prefix, logger);
}
- return this._logger;
+ return logger;
},
};
@@ -2300,7 +2303,7 @@ PlacesUtils.metadata = {
}
return true;
})
- .map(([key, value]) => key);
+ .map(([key]) => key);
if (keysToDelete.length) {
await this.deleteWithConnection(db, ...keysToDelete);
if (keysToDelete.length == pairs.size) {