mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1316683 - Part 2: Use the non-scriptable LoadContext object in the contentprefs module; r=hurley
This commit is contained in:
parent
f080574c7a
commit
53e5d6e240
@ -71,5 +71,9 @@ ContentPrefInstance.prototype = {
|
||||
|
||||
get DBConnection() {
|
||||
return this._contentPrefSvc.DBConnection;
|
||||
},
|
||||
|
||||
set loadContext(aLoadContext) {
|
||||
this._context = aLoadContext;
|
||||
}
|
||||
};
|
||||
|
@ -13,6 +13,17 @@ const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/ContentPrefUtils.jsm");
|
||||
|
||||
let loadContext = Cc["@mozilla.org/loadcontext;1"].
|
||||
createInstance(Ci.nsILoadContext);
|
||||
let privateLoadContext = Cc["@mozilla.org/privateloadcontext;1"].
|
||||
createInstance(Ci.nsILoadContext);
|
||||
|
||||
function contextArg(context) {
|
||||
return (context && context.usePrivateBrowsing) ?
|
||||
privateLoadContext :
|
||||
loadContext;
|
||||
}
|
||||
|
||||
var ContentPrefServiceParent = {
|
||||
_cps2: null,
|
||||
|
||||
@ -96,8 +107,15 @@ var ContentPrefServiceParent = {
|
||||
|
||||
receiveMessage(msg) {
|
||||
let data = msg.data;
|
||||
let signature;
|
||||
|
||||
if (!_methodsCallableFromChild.some(([method, args]) => method == data.call)) {
|
||||
if (!_methodsCallableFromChild.some(([method, args]) => {
|
||||
if (method == data.call) {
|
||||
signature = args;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
})) {
|
||||
throw new Error(`Can't call ${data.call} from child!`);
|
||||
}
|
||||
|
||||
@ -131,6 +149,12 @@ var ContentPrefServiceParent = {
|
||||
// Push our special listener.
|
||||
args.push(listener);
|
||||
|
||||
// Process context argument for forwarding
|
||||
let contextIndex = signature.indexOf("context");
|
||||
if (contextIndex > -1) {
|
||||
args[contextIndex] = contextArg(args[contextIndex]);
|
||||
}
|
||||
|
||||
// And call the function.
|
||||
this._cps2[data.call](...args);
|
||||
}
|
||||
|
@ -14,6 +14,11 @@
|
||||
"use strict";
|
||||
/* import-globals-from ../../../../../testing/mochitest/tests/SimpleTest/SpawnTask.js */
|
||||
|
||||
let loadContext = SpecialPowers.Cc["@mozilla.org/loadcontext;1"].
|
||||
createInstance(SpecialPowers.Ci.nsILoadContext);
|
||||
let privateLoadContext = SpecialPowers.Cc["@mozilla.org/privateloadcontext;1"].
|
||||
createInstance(SpecialPowers.Ci.nsILoadContext);
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
const childFrameURL =
|
||||
@ -189,7 +194,9 @@
|
||||
|
||||
cps.addObserverForName("test", prefObserver);
|
||||
|
||||
cps.set("http://mochi.test", "test", 42, { usePrivateBrowsing: true });
|
||||
let privateLoadContext = Cc["@mozilla.org/privateloadcontext;1"].
|
||||
createInstance(Ci.nsILoadContext);
|
||||
cps.set("http://mochi.test", "test", 42, privateLoadContext);
|
||||
let event = yield observed.promise;
|
||||
tester.is(event.name, "test", "got the right event");
|
||||
tester.is(event.isPrivate, true, "the event was for an isPrivate pref");
|
||||
@ -265,11 +272,11 @@
|
||||
.getService(SpecialPowers.Ci.nsIContentPrefService2);
|
||||
mm.addMessageListener("testRemoteContentPrefs:test2poke", function() {
|
||||
info(`received test2poke isPrivate: ${isPrivate}`);
|
||||
cps.setGlobal("testName", 42, {usePrivateBrowsing: isPrivate});
|
||||
cps.setGlobal("testName", 42, isPrivate ? privateLoadContext : loadContext);
|
||||
});
|
||||
mm.addMessageListener("testRemoteContentPrefs:test2poke2", function() {
|
||||
info(`received test2poke2 isPrivate: ${isPrivate}`);
|
||||
cps.removeGlobal("testName", {usePrivateBrowsing: isPrivate});
|
||||
cps.removeGlobal("testName", isPrivate ? privateLoadContext : loadContext);
|
||||
});
|
||||
mm.sendAsyncMessage("testRemoteContentPrefs:test2", {});
|
||||
yield curTest.promise;
|
||||
|
@ -131,12 +131,15 @@ var ContentPrefTest = {
|
||||
|
||||
};
|
||||
|
||||
var gInPrivateBrowsing = false;
|
||||
function enterPBMode() {
|
||||
gInPrivateBrowsing = true;
|
||||
let loadContext = Cc["@mozilla.org/loadcontext;1"].
|
||||
createInstance(Ci.nsILoadContext);
|
||||
let privateLoadContext = Cc["@mozilla.org/privateloadcontext;1"].
|
||||
createInstance(Ci.nsILoadContext);
|
||||
function enterPBMode(cps) {
|
||||
cps.loadContext = privateLoadContext;
|
||||
}
|
||||
function exitPBMode() {
|
||||
gInPrivateBrowsing = false;
|
||||
function exitPBMode(cps) {
|
||||
cps.loadContext = loadContext;
|
||||
Services.obs.notifyObservers(null, "last-pb-context-exited", null);
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,6 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
function run_test() {
|
||||
let loadContext = { get usePrivateBrowsing() { return gInPrivateBrowsing; } };
|
||||
|
||||
ContentPrefTest.deleteDatabase();
|
||||
var cp = new ContentPrefInstance(loadContext);
|
||||
do_check_neq(cp, null, "Retrieving the content prefs service failed");
|
||||
@ -19,7 +17,7 @@ function run_test() {
|
||||
// make sure Zoom-A is retrievable
|
||||
do_check_eq(cp.getPref(uri1, pref_name), zoomA);
|
||||
// enter private browsing mode
|
||||
enterPBMode();
|
||||
enterPBMode(cp);
|
||||
// make sure Zoom-A is retrievable
|
||||
do_check_eq(cp.getPref(uri1, pref_name), zoomA);
|
||||
// save Zoom-B
|
||||
@ -31,7 +29,7 @@ function run_test() {
|
||||
// make sure Zoom-A has changed
|
||||
do_check_eq(cp.getPref(uri1, pref_name), zoomA_new);
|
||||
// exit private browsing mode
|
||||
exitPBMode();
|
||||
exitPBMode(cp);
|
||||
// make sure Zoom-A change has not persisted
|
||||
do_check_eq(cp.getPref(uri1, pref_name), zoomA);
|
||||
// make sure Zoom-B change has not persisted
|
||||
|
@ -15,8 +15,6 @@ var prefObserver = {
|
||||
};
|
||||
|
||||
function run_test() {
|
||||
let loadContext = { get usePrivateBrowsing() { return gInPrivateBrowsing; } };
|
||||
|
||||
var cps = new ContentPrefInstance(loadContext);
|
||||
cps.removeGroupedPrefs();
|
||||
|
||||
@ -31,7 +29,7 @@ function run_test() {
|
||||
cps.addObserver("value", prefObserver);
|
||||
cps.addObserver("value-global", prefObserver);
|
||||
|
||||
enterPBMode();
|
||||
enterPBMode(cps);
|
||||
|
||||
// test setPref
|
||||
num = prefObserver.setCalledNum;
|
||||
|
@ -310,8 +310,8 @@ function run_test() {
|
||||
|
||||
// Make sure information about private context is properly
|
||||
// retrieved by the observer.
|
||||
cps.setPref(uri, "test.observer.private", "test value", {usePrivateBrowsing: true});
|
||||
cps.setPref(uri, "test.observer.normal", "test value", {usePrivateBrowsing: false});
|
||||
cps.setPref(uri, "test.observer.private", "test value", privateLoadContext);
|
||||
cps.setPref(uri, "test.observer.normal", "test value", loadContext);
|
||||
cps.removePref(uri, "test.observer.private");
|
||||
cps.removePref(uri, "test.observer.normal");
|
||||
|
||||
|
@ -10,6 +10,11 @@ var cps;
|
||||
var asyncRunner;
|
||||
var next;
|
||||
|
||||
let loadContext = Cc["@mozilla.org/loadcontext;1"].
|
||||
createInstance(Ci.nsILoadContext);
|
||||
let privateLoadContext = Cc["@mozilla.org/privateloadcontext;1"].
|
||||
createInstance(Ci.nsILoadContext);
|
||||
|
||||
(function init() {
|
||||
// There has to be a profile directory before the CPS service is gotten.
|
||||
do_get_profile();
|
||||
|
@ -54,7 +54,7 @@ var tests = [
|
||||
yield setGlobal("bar", 4);
|
||||
yield set("b.com", "foo", 5);
|
||||
|
||||
let context = { usePrivateBrowsing: true };
|
||||
let context = privateLoadContext;
|
||||
yield set("a.com", "foo", 6, context);
|
||||
yield setGlobal("foo", 7, context);
|
||||
getCachedOK(["a.com", "foo", context], true, 6);
|
||||
|
@ -160,7 +160,7 @@ var tests = [
|
||||
yield setGlobal("bar", 4);
|
||||
yield set("b.com", "foo", 5);
|
||||
|
||||
let context = { usePrivateBrowsing: true };
|
||||
let context = privateLoadContext;
|
||||
yield set("a.com", "foo", 6, context);
|
||||
yield setGlobal("foo", 7, context);
|
||||
getCachedSubdomainsOK(["a.com", "foo", context], [["a.com", 6]]);
|
||||
|
@ -45,7 +45,7 @@ var tests = [
|
||||
yield setGlobal("bar", 4);
|
||||
yield set("b.com", "foo", 5);
|
||||
|
||||
let context = { usePrivateBrowsing: true };
|
||||
let context = privateLoadContext;
|
||||
yield set("a.com", "foo", 6, context);
|
||||
yield setGlobal("foo", 7, context);
|
||||
yield getSubdomainsOK(["a.com", "foo", context], [["a.com", 6]]);
|
||||
|
@ -9,8 +9,8 @@ function run_test() {
|
||||
for (var i = 0; i < tests.length; i++) {
|
||||
// Generate two wrappers of each test function that invoke the original test with an
|
||||
// appropriate privacy context.
|
||||
var pub = eval("var f = function* " + tests[i].name + "() { yield tests[" + i + "]({ usePrivateBrowsing: false }); }; f");
|
||||
var priv = eval("var f = function* " + tests[i].name + "_private() { yield tests[" + i + "]({ usePrivateBrowsing: true }); }; f");
|
||||
var pub = eval("var f = function* " + tests[i].name + "() { yield tests[" + i + "](privateLoadContext); }; f");
|
||||
var priv = eval("var f = function* " + tests[i].name + "_private() { yield tests[" + i + "](privateLoadContext); }; f");
|
||||
allTests.push(pub);
|
||||
allTests.push(priv);
|
||||
}
|
||||
@ -155,7 +155,7 @@ var specialTests = [
|
||||
},
|
||||
|
||||
function* observerForName_removeAllDomainsSince_private() {
|
||||
let context = {usePrivateBrowsing: true};
|
||||
let context = privateLoadContext;
|
||||
yield setWithDate("a.com", "foo", 1, 100, context);
|
||||
yield setWithDate("b.com", "foo", 2, 200, context);
|
||||
yield setWithDate("c.com", "foo", 3, 300, context);
|
||||
|
@ -147,7 +147,7 @@ var tests = [
|
||||
yield set("b.com", "foo", 6);
|
||||
yield set("b.com", "bar", 7);
|
||||
|
||||
let context = { usePrivateBrowsing: true };
|
||||
let context = privateLoadContext;
|
||||
yield set("a.com", "foo", 8, context);
|
||||
yield setGlobal("foo", 9, context);
|
||||
yield cps.removeByDomainAndName("a.com", "foo", context, makeCallback());
|
||||
|
@ -45,7 +45,7 @@ var tests = [
|
||||
yield setGlobal("bar", 4);
|
||||
yield set("b.com", "foo", 5);
|
||||
|
||||
let context = { usePrivateBrowsing: true };
|
||||
let context = privateLoadContext;
|
||||
yield set("a.com", "foo", 6, context);
|
||||
yield setGlobal("foo", 7, context);
|
||||
yield cps.removeAllDomains(context, makeCallback());
|
||||
|
@ -62,7 +62,7 @@ var tests = [
|
||||
yield setGlobal("bar", 4);
|
||||
yield set("b.com", "foo", 5);
|
||||
|
||||
let context = { usePrivateBrowsing: true };
|
||||
let context = privateLoadContext;
|
||||
yield set("a.com", "foo", 6, context);
|
||||
yield setGlobal("foo", 7, context);
|
||||
yield cps.removeAllDomainsSince(0, context, makeCallback());
|
||||
|
@ -128,7 +128,7 @@ var tests = [
|
||||
yield setGlobal("bar", 4);
|
||||
yield set("b.com", "foo", 5);
|
||||
|
||||
let context = { usePrivateBrowsing: true };
|
||||
let context = privateLoadContext;
|
||||
yield set("a.com", "foo", 6, context);
|
||||
yield set("b.com", "foo", 7, context);
|
||||
yield setGlobal("foo", 8, context);
|
||||
|
@ -51,7 +51,7 @@ var tests = [
|
||||
yield set("b.com", "foo", 5);
|
||||
yield set("b.com", "bar", 6);
|
||||
|
||||
let context = { usePrivateBrowsing: true };
|
||||
let context = privateLoadContext;
|
||||
yield set("a.com", "foo", 7, context);
|
||||
yield setGlobal("foo", 8, context);
|
||||
yield set("b.com", "bar", 9, context);
|
||||
|
@ -85,7 +85,7 @@ var tests = [
|
||||
yield setGlobal("bar", 4);
|
||||
yield set("b.com", "foo", 5);
|
||||
|
||||
let context = { usePrivateBrowsing: true };
|
||||
let context = privateLoadContext;
|
||||
yield set("a.com", "foo", 6, context);
|
||||
yield setGlobal("foo", 7, context);
|
||||
yield dbOK([
|
||||
@ -181,7 +181,7 @@ var tests = [
|
||||
{"domain": null, "name": "foo", "value": 4}
|
||||
]);
|
||||
|
||||
let context = { usePrivateBrowsing: true };
|
||||
let context = privateLoadContext;
|
||||
yield set("b.com", "foo", 5, context);
|
||||
|
||||
yield getOKEx("getByName", ["foo", context], [
|
||||
|
Loading…
Reference in New Issue
Block a user