mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 16:55:40 +00:00
Bug 1464542: Part 3c - Change Services.jsm to use the C++-implemented services cache. r=mccr8
Differential Revision: https://phabricator.services.mozilla.com/D81420
This commit is contained in:
parent
d09458dc51
commit
b787b84e52
@ -5,18 +5,7 @@
|
||||
const { UrlClassifierTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/UrlClassifierTestUtils.jsm"
|
||||
);
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
Services,
|
||||
"cookies",
|
||||
"@mozilla.org/cookieService;1",
|
||||
"nsICookieService"
|
||||
);
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
Services,
|
||||
"cookiemgr",
|
||||
"@mozilla.org/cookiemanager;1",
|
||||
"nsICookieManager"
|
||||
);
|
||||
Services.cookies.QueryInterface(Ci.nsICookieService);
|
||||
|
||||
function restore_prefs() {
|
||||
Services.prefs.clearUserPref("network.cookie.cookieBehavior");
|
||||
@ -81,12 +70,12 @@ async function test_cookie_settings({
|
||||
expectedThirdPartyCookies = 0;
|
||||
}
|
||||
is(
|
||||
Services.cookiemgr.countCookiesFromHost(firstPartyURI.host),
|
||||
Services.cookies.countCookiesFromHost(firstPartyURI.host),
|
||||
expectedFirstPartyCookies,
|
||||
"Number of first-party cookies should match expected"
|
||||
);
|
||||
is(
|
||||
Services.cookiemgr.countCookiesFromHost(thirdPartyURI.host),
|
||||
Services.cookies.countCookiesFromHost(thirdPartyURI.host),
|
||||
expectedThirdPartyCookies,
|
||||
"Number of third-party cookies should match expected"
|
||||
);
|
||||
|
@ -18,7 +18,7 @@ CookieXPCShellUtils.init(this);
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
Services,
|
||||
"cookies",
|
||||
"cookiesvc",
|
||||
"@mozilla.org/cookieService;1",
|
||||
"nsICookieService"
|
||||
);
|
||||
@ -162,7 +162,7 @@ function do_load_profile(generator) {
|
||||
// Set a single session cookie using http and test the cookie count
|
||||
// against 'expected'
|
||||
function do_set_single_http_cookie(uri, channel, expected) {
|
||||
Services.cookies.setCookieStringFromHttp(uri, "foo=bar", channel);
|
||||
Services.cookiesvc.setCookieStringFromHttp(uri, "foo=bar", channel);
|
||||
Assert.equal(Services.cookiemgr.countCookiesFromHost(uri.host), expected);
|
||||
}
|
||||
|
||||
@ -198,7 +198,7 @@ async function do_set_cookies(uri, channel, session, expected) {
|
||||
Assert.equal(Services.cookiemgr.countCookiesFromHost(uri.host), expected[0]);
|
||||
|
||||
// via http request
|
||||
Services.cookies.setCookieStringFromHttp(uri, "hot=dog" + suffix, channel);
|
||||
Services.cookiesvc.setCookieStringFromHttp(uri, "hot=dog" + suffix, channel);
|
||||
Assert.equal(Services.cookiemgr.countCookiesFromHost(uri.host), expected[1]);
|
||||
}
|
||||
|
||||
|
@ -213,7 +213,7 @@ async function run_test_2() {
|
||||
// Load the profile and populate it.
|
||||
do_load_profile();
|
||||
|
||||
Services.cookies.runInTransaction(_ => {
|
||||
Services.cookiesvc.runInTransaction(_ => {
|
||||
let uri = NetUtil.newURI("http://foo.com/");
|
||||
const channel = NetUtil.newChannel({
|
||||
uri,
|
||||
@ -223,7 +223,7 @@ async function run_test_2() {
|
||||
|
||||
for (let i = 0; i < 3000; ++i) {
|
||||
let uri = NetUtil.newURI("http://" + i + ".com/");
|
||||
Services.cookies.setCookieStringFromHttp(
|
||||
Services.cookiesvc.setCookieStringFromHttp(
|
||||
uri,
|
||||
"oh=hai; max-age=1000",
|
||||
channel
|
||||
@ -278,7 +278,7 @@ async function run_test_3() {
|
||||
|
||||
// Load the profile and populate it.
|
||||
do_load_profile();
|
||||
Services.cookies.runInTransaction(_ => {
|
||||
Services.cookiesvc.runInTransaction(_ => {
|
||||
let uri = NetUtil.newURI("http://hither.com/");
|
||||
let channel = NetUtil.newChannel({
|
||||
uri,
|
||||
@ -286,7 +286,7 @@ async function run_test_3() {
|
||||
contentPolicyType: Ci.nsIContentPolicy.TYPE_DOCUMENT,
|
||||
});
|
||||
for (let i = 0; i < 10; ++i) {
|
||||
Services.cookies.setCookieStringFromHttp(
|
||||
Services.cookiesvc.setCookieStringFromHttp(
|
||||
uri,
|
||||
"oh" + i + "=hai; max-age=1000",
|
||||
channel
|
||||
@ -299,7 +299,7 @@ async function run_test_3() {
|
||||
contentPolicyType: Ci.nsIContentPolicy.TYPE_DOCUMENT,
|
||||
});
|
||||
for (let i = 10; i < 3000; ++i) {
|
||||
Services.cookies.setCookieStringFromHttp(
|
||||
Services.cookiesvc.setCookieStringFromHttp(
|
||||
uri,
|
||||
"oh" + i + "=hai; max-age=1000",
|
||||
channel
|
||||
@ -368,7 +368,7 @@ async function run_test_3() {
|
||||
async function run_test_4() {
|
||||
// Load the profile and populate it.
|
||||
do_load_profile();
|
||||
Services.cookies.runInTransaction(_ => {
|
||||
Services.cookiesvc.runInTransaction(_ => {
|
||||
let uri = NetUtil.newURI("http://foo.com/");
|
||||
let channel = NetUtil.newChannel({
|
||||
uri,
|
||||
@ -377,7 +377,7 @@ async function run_test_4() {
|
||||
});
|
||||
for (let i = 0; i < 3000; ++i) {
|
||||
let uri = NetUtil.newURI("http://" + i + ".com/");
|
||||
Services.cookies.setCookieStringFromHttp(
|
||||
Services.cookiesvc.setCookieStringFromHttp(
|
||||
uri,
|
||||
"oh=hai; max-age=1000",
|
||||
channel
|
||||
@ -437,21 +437,21 @@ async function run_test_4() {
|
||||
async function run_test_5() {
|
||||
// Load the profile and populate it.
|
||||
do_load_profile();
|
||||
Services.cookies.runInTransaction(_ => {
|
||||
Services.cookiesvc.runInTransaction(_ => {
|
||||
let uri = NetUtil.newURI("http://bar.com/");
|
||||
const channel = NetUtil.newChannel({
|
||||
uri,
|
||||
loadUsingSystemPrincipal: true,
|
||||
contentPolicyType: Ci.nsIContentPolicy.TYPE_DOCUMENT,
|
||||
});
|
||||
Services.cookies.setCookieStringFromHttp(
|
||||
Services.cookiesvc.setCookieStringFromHttp(
|
||||
uri,
|
||||
"oh=hai; path=/; max-age=1000",
|
||||
channel
|
||||
);
|
||||
for (let i = 0; i < 3000; ++i) {
|
||||
let uri = NetUtil.newURI("http://" + i + ".com/");
|
||||
Services.cookies.setCookieStringFromHttp(
|
||||
Services.cookiesvc.setCookieStringFromHttp(
|
||||
uri,
|
||||
"oh=hai; max-age=1000",
|
||||
channel
|
||||
|
@ -45,7 +45,7 @@ add_task(async () => {
|
||||
let uri2 = NetUtil.newURI("http://bar.com/bar.html");
|
||||
|
||||
// Set a cookie for host 1.
|
||||
Services.cookies.setCookieStringFromHttp(
|
||||
Services.cookiesvc.setCookieStringFromHttp(
|
||||
uri1,
|
||||
"oh=hai; max-age=1000",
|
||||
make_channel(uri1.spec)
|
||||
@ -61,7 +61,11 @@ add_task(async () => {
|
||||
chan2.QueryInterface(Ci.nsIPrivateBrowsingChannel);
|
||||
chan2.setPrivate(true);
|
||||
|
||||
Services.cookies.setCookieStringFromHttp(uri2, "oh=hai; max-age=1000", chan2);
|
||||
Services.cookiesvc.setCookieStringFromHttp(
|
||||
uri2,
|
||||
"oh=hai; max-age=1000",
|
||||
chan2
|
||||
);
|
||||
Assert.equal(await getCookieStringFromPrivateDocument(uri1.spec), "");
|
||||
Assert.equal(await getCookieStringFromPrivateDocument(uri2.spec), "oh=hai");
|
||||
|
||||
@ -70,7 +74,11 @@ add_task(async () => {
|
||||
Assert.equal(await getCookieStringFromPrivateDocument(uri1.spec), "");
|
||||
Assert.equal(await getCookieStringFromPrivateDocument(uri2.spec), "");
|
||||
|
||||
Services.cookies.setCookieStringFromHttp(uri2, "oh=hai; max-age=1000", chan2);
|
||||
Services.cookiesvc.setCookieStringFromHttp(
|
||||
uri2,
|
||||
"oh=hai; max-age=1000",
|
||||
chan2
|
||||
);
|
||||
Assert.equal(await getCookieStringFromPrivateDocument(uri2.spec), "oh=hai");
|
||||
|
||||
// Leave private browsing mode and check counts.
|
||||
@ -89,7 +97,11 @@ add_task(async () => {
|
||||
// Enter private browsing mode, set a cookie for host 2, and check the counts.
|
||||
Assert.equal(await getCookieStringFromPrivateDocument(uri1.spec), "");
|
||||
Assert.equal(await getCookieStringFromPrivateDocument(uri2.spec), "");
|
||||
Services.cookies.setCookieStringFromHttp(uri2, "oh=hai; max-age=1000", chan2);
|
||||
Services.cookiesvc.setCookieStringFromHttp(
|
||||
uri2,
|
||||
"oh=hai; max-age=1000",
|
||||
chan2
|
||||
);
|
||||
Assert.equal(await getCookieStringFromPrivateDocument(uri2.spec), "oh=hai");
|
||||
|
||||
// Fake a profile change.
|
||||
|
@ -54,11 +54,11 @@ add_task(async () => {
|
||||
""
|
||||
);
|
||||
|
||||
Assert.equal(Services.cookies.getCookieStringFromHttp(uri, channel), "");
|
||||
Assert.equal(Services.cookiesvc.getCookieStringFromHttp(uri, channel), "");
|
||||
|
||||
await CookieXPCShellUtils.setCookieToDocument(uri.spec, "oh2=hai");
|
||||
|
||||
Services.cookies.setCookieStringFromHttp(uri, "oh3=hai", channel);
|
||||
Services.cookiesvc.setCookieStringFromHttp(uri, "oh3=hai", channel);
|
||||
Assert.equal(
|
||||
await CookieXPCShellUtils.getCookieStringFromDocument("http://foo.com/"),
|
||||
""
|
||||
|
@ -36,7 +36,7 @@ add_task(async () => {
|
||||
});
|
||||
for (let i = 0; i < CMAX; ++i) {
|
||||
let uri = NetUtil.newURI("http://" + i + ".com/");
|
||||
Services.cookies.setCookieStringFromHttp(
|
||||
Services.cookiesvc.setCookieStringFromHttp(
|
||||
uri,
|
||||
"oh=hai; max-age=1000",
|
||||
channel
|
||||
|
@ -182,7 +182,7 @@ function* run_test_1(generator) {
|
||||
});
|
||||
|
||||
// Load the profile and populate it.
|
||||
Services.cookies.setCookieStringFromHttp(
|
||||
Services.cookiesvc.setCookieStringFromHttp(
|
||||
uri,
|
||||
"oh=hai; max-age=1000",
|
||||
channel
|
||||
@ -217,7 +217,7 @@ function* run_test_2(generator) {
|
||||
loadUsingSystemPrincipal: true,
|
||||
contentPolicyType: Ci.nsIContentPolicy.TYPE_DOCUMENT,
|
||||
});
|
||||
Services.cookies.setCookieStringFromHttp(
|
||||
Services.cookiesvc.setCookieStringFromHttp(
|
||||
uri,
|
||||
"oh=hai; max-age=1000",
|
||||
channel
|
||||
|
@ -174,7 +174,7 @@ var SysInfo = {
|
||||
return this.overrides[name];
|
||||
}
|
||||
|
||||
return this._genuine.getProperty(name);
|
||||
return this._genuine.QueryInterface(Ci.nsIPropertyBag).getProperty(name);
|
||||
},
|
||||
|
||||
getPropertyAsUint32(name) {
|
||||
@ -182,7 +182,7 @@ var SysInfo = {
|
||||
},
|
||||
|
||||
get(name) {
|
||||
return this._genuine.get(name);
|
||||
return this._genuine.QueryInterface(Ci.nsIPropertyBag2).get(name);
|
||||
},
|
||||
|
||||
get diskInfo() {
|
||||
|
@ -23,13 +23,6 @@ ChromeUtils.defineModuleGetter(
|
||||
"resource://gre/modules/HealthPing.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
Services,
|
||||
"cookies",
|
||||
"@mozilla.org/cookieService;1",
|
||||
"nsICookieService"
|
||||
);
|
||||
|
||||
const MS_IN_A_MINUTE = 60 * 1000;
|
||||
|
||||
function countPingTypes(pings) {
|
||||
@ -973,6 +966,7 @@ add_task(async function testCookies() {
|
||||
loadUsingSystemPrincipal: true,
|
||||
contentPolicyType: Ci.nsIContentPolicy.TYPE_DOCUMENT,
|
||||
});
|
||||
Services.cookies.QueryInterface(Ci.nsICookieService);
|
||||
Services.cookies.setCookieStringFromHttp(uri, "cookie-time=yes", channel);
|
||||
|
||||
const id = await TelemetryController.submitExternalPing(TEST_TYPE, {});
|
||||
|
@ -2,171 +2,6 @@
|
||||
* 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/. */
|
||||
|
||||
/* eslint mozilla/use-services:off */
|
||||
|
||||
var EXPORTED_SYMBOLS = ["Services"];
|
||||
|
||||
const { AppConstants } = ChromeUtils.import(
|
||||
"resource://gre/modules/AppConstants.jsm"
|
||||
);
|
||||
const { XPCOMUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
||||
var Services = {};
|
||||
|
||||
/**
|
||||
* WARNING: If you add a getter that isn't in the initTable, please update the
|
||||
* eslint rule in /tools/lint/eslint/eslint-plugin-mozilla/lib/rules/use-services.js
|
||||
*/
|
||||
|
||||
XPCOMUtils.defineLazyGetter(Services, "prefs", function() {
|
||||
return Cc["@mozilla.org/preferences-service;1"]
|
||||
.getService(Ci.nsIPrefService)
|
||||
.QueryInterface(Ci.nsIPrefBranch);
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(Services, "appinfo", function() {
|
||||
let appinfo = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime);
|
||||
try {
|
||||
appinfo.QueryInterface(Ci.nsIXULAppInfo);
|
||||
} catch (ex) {
|
||||
// Not all applications implement nsIXULAppInfo (e.g. xpcshell doesn't).
|
||||
if (
|
||||
!(ex instanceof Components.Exception) ||
|
||||
ex.result != Cr.NS_NOINTERFACE
|
||||
) {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
return appinfo;
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(Services, "dirsvc", function() {
|
||||
return Cc["@mozilla.org/file/directory_service;1"]
|
||||
.getService(Ci.nsIDirectoryService)
|
||||
.QueryInterface(Ci.nsIProperties);
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(Services, "sysinfo", function() {
|
||||
return Cc["@mozilla.org/system-info;1"]
|
||||
.getService(Ci.nsIPropertyBag2)
|
||||
.QueryInterface(Ci.nsISystemInfo);
|
||||
});
|
||||
|
||||
if (AppConstants.MOZ_CRASHREPORTER) {
|
||||
XPCOMUtils.defineLazyGetter(Services, "crashmanager", () => {
|
||||
let ns = {};
|
||||
ChromeUtils.import("resource://gre/modules/CrashManager.jsm", ns);
|
||||
|
||||
return ns.CrashManager.Singleton;
|
||||
});
|
||||
}
|
||||
|
||||
XPCOMUtils.defineLazyGetter(Services, "io", () => {
|
||||
return Cc["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService)
|
||||
.QueryInterface(Ci.nsISpeculativeConnect);
|
||||
});
|
||||
|
||||
var initTable = {
|
||||
appShell: ["@mozilla.org/appshell/appShellService;1", "nsIAppShellService"],
|
||||
cache2: [
|
||||
"@mozilla.org/netwerk/cache-storage-service;1",
|
||||
"nsICacheStorageService",
|
||||
],
|
||||
catMan: ["@mozilla.org/categorymanager;1", "nsICategoryManager"],
|
||||
clearData: ["@mozilla.org/clear-data-service;1", "nsIClearDataService"],
|
||||
cpmm: ["@mozilla.org/childprocessmessagemanager;1", "nsIMessageSender"],
|
||||
console: ["@mozilla.org/consoleservice;1", "nsIConsoleService"],
|
||||
cookies: ["@mozilla.org/cookiemanager;1", "nsICookieManager"],
|
||||
droppedLinkHandler: [
|
||||
"@mozilla.org/content/dropped-link-handler;1",
|
||||
"nsIDroppedLinkHandler",
|
||||
],
|
||||
els: ["@mozilla.org/eventlistenerservice;1", "nsIEventListenerService"],
|
||||
eTLD: [
|
||||
"@mozilla.org/network/effective-tld-service;1",
|
||||
"nsIEffectiveTLDService",
|
||||
],
|
||||
intl: ["@mozilla.org/mozintl;1", "mozIMozIntl"],
|
||||
locale: ["@mozilla.org/intl/localeservice;1", "mozILocaleService"],
|
||||
logins: ["@mozilla.org/login-manager;1", "nsILoginManager"],
|
||||
mm: ["@mozilla.org/globalmessagemanager;1", "nsISupports"],
|
||||
obs: ["@mozilla.org/observer-service;1", "nsIObserverService"],
|
||||
perms: ["@mozilla.org/permissionmanager;1", "nsIPermissionManager"],
|
||||
ppmm: ["@mozilla.org/parentprocessmessagemanager;1", "nsISupports"],
|
||||
prompt: ["@mozilla.org/embedcomp/prompt-service;1", "nsIPromptService"],
|
||||
scriptloader: [
|
||||
"@mozilla.org/moz/jssubscript-loader;1",
|
||||
"mozIJSSubScriptLoader",
|
||||
],
|
||||
scriptSecurityManager: [
|
||||
"@mozilla.org/scriptsecuritymanager;1",
|
||||
"nsIScriptSecurityManager",
|
||||
],
|
||||
storage: ["@mozilla.org/storage/service;1", "mozIStorageService"],
|
||||
domStorageManager: [
|
||||
"@mozilla.org/dom/localStorage-manager;1",
|
||||
"nsIDOMStorageManager",
|
||||
],
|
||||
lsm: ["@mozilla.org/dom/localStorage-manager;1", "nsILocalStorageManager"],
|
||||
search: ["@mozilla.org/browser/search-service;1", "nsISearchService"],
|
||||
strings: ["@mozilla.org/intl/stringbundle;1", "nsIStringBundleService"],
|
||||
telemetry: ["@mozilla.org/base/telemetry;1", "nsITelemetry"],
|
||||
textToSubURI: ["@mozilla.org/intl/texttosuburi;1", "nsITextToSubURI"],
|
||||
tm: ["@mozilla.org/thread-manager;1", "nsIThreadManager"],
|
||||
urlFormatter: [
|
||||
"@mozilla.org/toolkit/URLFormatterService;1",
|
||||
"nsIURLFormatter",
|
||||
],
|
||||
vc: ["@mozilla.org/xpcom/version-comparator;1", "nsIVersionComparator"],
|
||||
wm: ["@mozilla.org/appshell/window-mediator;1", "nsIWindowMediator"],
|
||||
ww: ["@mozilla.org/embedcomp/window-watcher;1", "nsIWindowWatcher"],
|
||||
startup: ["@mozilla.org/toolkit/app-startup;1", "nsIAppStartup"],
|
||||
clipboard: ["@mozilla.org/widget/clipboard;1", "nsIClipboard"],
|
||||
DOMRequest: [
|
||||
"@mozilla.org/dom/dom-request-service;1",
|
||||
"nsIDOMRequestService",
|
||||
],
|
||||
focus: ["@mozilla.org/focus-manager;1", "nsIFocusManager"],
|
||||
uriFixup: ["@mozilla.org/docshell/uri-fixup;1", "nsIURIFixup"],
|
||||
blocklist: ["@mozilla.org/extensions/blocklist;1"],
|
||||
netUtils: ["@mozilla.org/network/util;1", "nsINetUtil"],
|
||||
loadContextInfo: [
|
||||
"@mozilla.org/load-context-info-factory;1",
|
||||
"nsILoadContextInfoFactory",
|
||||
],
|
||||
qms: ["@mozilla.org/dom/quota-manager-service;1", "nsIQuotaManagerService"],
|
||||
};
|
||||
|
||||
if (AppConstants.platform == "android") {
|
||||
initTable.androidBridge = [
|
||||
"@mozilla.org/android/bridge;1",
|
||||
"nsIAndroidBridge",
|
||||
];
|
||||
}
|
||||
if (AppConstants.MOZ_GECKO_PROFILER) {
|
||||
initTable.profiler = ["@mozilla.org/tools/profiler;1", "nsIProfiler"];
|
||||
}
|
||||
if ("@mozilla.org/enterprisepolicies;1" in Cc) {
|
||||
initTable.policies = [
|
||||
"@mozilla.org/enterprisepolicies;1",
|
||||
"nsIEnterprisePolicies",
|
||||
];
|
||||
}
|
||||
|
||||
if (AppConstants.MOZ_NEW_XULSTORE) {
|
||||
XPCOMUtils.defineLazyGetter(Services, "xulStore", () => {
|
||||
const { XULStore } = ChromeUtils.import(
|
||||
"resource://gre/modules/XULStore.jsm"
|
||||
);
|
||||
return XULStore;
|
||||
});
|
||||
} else {
|
||||
initTable.xulStore = ["@mozilla.org/xul/xulstore;1", "nsIXULStore"];
|
||||
}
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetters(Services, initTable);
|
||||
|
||||
initTable = undefined;
|
||||
var Services = Cu.createServicesCache();
|
||||
|
Loading…
Reference in New Issue
Block a user