Bug 1933053 - QM: Introduce nsIQuotaUtilsService for accessing information available only in JS; r=dom-storage-reviewers,asuth

This patch introduces a new scriptable interface, nsIQuotaUtilsService,
designed to enable C++ code to access information that is exclusively available
through JavaScript system modules.

Differential Revision: https://phabricator.services.mozilla.com/D231264
This commit is contained in:
Jan Varga
2024-12-11 14:08:22 +00:00
parent 12e7fa313c
commit 01952e6cea
6 changed files with 81 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
import { ContextualIdentityService } from "resource://gre/modules/ContextualIdentityService.sys.mjs";
export function QuotaUtilsService() {}
QuotaUtilsService.prototype = {
getPrivateIdentityId(aName) {
const privateIdentity = ContextualIdentityService.getPrivateIdentity(aName);
if (!privateIdentity) {
return 0;
}
return privateIdentity.userContextId;
},
QueryInterface: ChromeUtils.generateQI(["nsIQuotaUtilsService"]),
classDescription: "Quota Utils Service",
contractID: "@mozilla.org/dom/quota-utils-service;1",
classID: Components.ID("3e65d9b5-5b41-4c18-ac7b-681b9df9df97"),
};

View File

@@ -5,6 +5,12 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
Classes = [
{
'cid': '{3e65d9b5-5b41-4c18-ac7B-681b9df9df97}',
'contract_ids': ['@mozilla.org/dom/quota-utils-service;1'],
'esModule': 'resource://gre/modules/QuotaUtilsService.sys.mjs',
'constructor': 'QuotaUtilsService',
},
{
'cid': '{b6f2f870-b0bc-4a1a-9c40-02cc171adb5b}',
'contract_ids': ['@mozilla.org/network/protocol;1?name=indexeddb'],

View File

@@ -15,6 +15,7 @@ XPIDL_SOURCES += [
"nsIQuotaManagerService.idl",
"nsIQuotaRequests.idl",
"nsIQuotaResults.idl",
"nsIQuotaUtilsService.idl",
]
XPIDL_MODULE = "dom_quota"
@@ -170,6 +171,10 @@ IPDL_SOURCES += [
"PRemoteQuotaObject.ipdl",
]
EXTRA_JS_MODULES += [
"QuotaUtilsService.sys.mjs",
]
include("/ipc/chromium/chromium-config.mozbuild")
FINAL_LIBRARY = "xul"

View File

@@ -0,0 +1,24 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
/**
* This interface provides utility methods for storage and quota management
* that require information only available in JavaScript system modules. It
* serves as a bridge for accessing such information from C++ code where direct
* access is not feasible.
*/
[scriptable, uuid(cdeca40d-74f4-44a2-beb3-84cd0bbc7785)]
interface nsIQuotaUtilsService : nsISupports
{
/**
* Retrieves the private identity id corresponding to the specified name.
*
* @param aName The name for which the private identity id is requested.
* @return The private identity id as an unsigned long.
*/
unsigned long getPrivateIdentityId(in AString aName);
};

View File

@@ -0,0 +1,23 @@
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
/* exported testSteps */
async function testSteps() {
const quotaUtilsService = Cc[
"@mozilla.org/dom/quota-utils-service;1"
].getService(Ci.nsIQuotaUtilsService);
{
const id = quotaUtilsService.getPrivateIdentityId("");
Assert.equal(id, 0, "Correct id");
}
{
const id = quotaUtilsService.getPrivateIdentityId(
"userContextIdInternal.thumbnail"
);
Assert.greater(id, 4, "Correct id");
}
}

View File

@@ -113,6 +113,8 @@ skip-if = ["condprof"] # frequent perma fail, then goes away.
["test_quotaClientInteractions.js"]
["test_quotaUtilsService.js"]
["test_removeLocalStorage.js"]
["test_simpledb.js"]