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:
21
dom/quota/QuotaUtilsService.sys.mjs
Normal file
21
dom/quota/QuotaUtilsService.sys.mjs
Normal 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"),
|
||||||
|
};
|
||||||
@@ -5,6 +5,12 @@
|
|||||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
Classes = [
|
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}',
|
'cid': '{b6f2f870-b0bc-4a1a-9c40-02cc171adb5b}',
|
||||||
'contract_ids': ['@mozilla.org/network/protocol;1?name=indexeddb'],
|
'contract_ids': ['@mozilla.org/network/protocol;1?name=indexeddb'],
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ XPIDL_SOURCES += [
|
|||||||
"nsIQuotaManagerService.idl",
|
"nsIQuotaManagerService.idl",
|
||||||
"nsIQuotaRequests.idl",
|
"nsIQuotaRequests.idl",
|
||||||
"nsIQuotaResults.idl",
|
"nsIQuotaResults.idl",
|
||||||
|
"nsIQuotaUtilsService.idl",
|
||||||
]
|
]
|
||||||
|
|
||||||
XPIDL_MODULE = "dom_quota"
|
XPIDL_MODULE = "dom_quota"
|
||||||
@@ -170,6 +171,10 @@ IPDL_SOURCES += [
|
|||||||
"PRemoteQuotaObject.ipdl",
|
"PRemoteQuotaObject.ipdl",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
EXTRA_JS_MODULES += [
|
||||||
|
"QuotaUtilsService.sys.mjs",
|
||||||
|
]
|
||||||
|
|
||||||
include("/ipc/chromium/chromium-config.mozbuild")
|
include("/ipc/chromium/chromium-config.mozbuild")
|
||||||
|
|
||||||
FINAL_LIBRARY = "xul"
|
FINAL_LIBRARY = "xul"
|
||||||
|
|||||||
24
dom/quota/nsIQuotaUtilsService.idl
Normal file
24
dom/quota/nsIQuotaUtilsService.idl
Normal 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);
|
||||||
|
};
|
||||||
23
dom/quota/test/xpcshell/test_quotaUtilsService.js
Normal file
23
dom/quota/test/xpcshell/test_quotaUtilsService.js
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -113,6 +113,8 @@ skip-if = ["condprof"] # frequent perma fail, then goes away.
|
|||||||
|
|
||||||
["test_quotaClientInteractions.js"]
|
["test_quotaClientInteractions.js"]
|
||||||
|
|
||||||
|
["test_quotaUtilsService.js"]
|
||||||
|
|
||||||
["test_removeLocalStorage.js"]
|
["test_removeLocalStorage.js"]
|
||||||
|
|
||||||
["test_simpledb.js"]
|
["test_simpledb.js"]
|
||||||
|
|||||||
Reference in New Issue
Block a user