Bug 1337964 - SiteDataManager should check correctly if a cookie belongs to a private identity or not, r=aryx, r=gijs

This commit is contained in:
Andrea Marchesini
2017-02-15 13:12:52 +01:00
parent 8c5a1d7423
commit 03364d5e05
10 changed files with 56 additions and 55 deletions

View File

@@ -4205,7 +4205,7 @@ function updateUserContextUIIndicator() {
return;
}
let identity = ContextualIdentityService.getIdentityFromId(userContextId);
let identity = ContextualIdentityService.getPublicIdentityFromId(userContextId);
if (!identity) {
hbox.setAttribute("data-identity-color", "");
hbox.hidden = true;

View File

@@ -475,7 +475,7 @@ function createUserContextMenu(event, {
docfrag.appendChild(menuseparator);
}
ContextualIdentityService.getIdentities().forEach(identity => {
ContextualIdentityService.getPublicIdentities().forEach(identity => {
if (identity.userContextId == excludeUserContextId) {
return;
}

View File

@@ -1140,7 +1140,7 @@ const CustomizableWidgets = [
let fragment = doc.createDocumentFragment();
let bundle = doc.getElementById("bundle_browser");
ContextualIdentityService.getIdentities().forEach(identity => {
ContextualIdentityService.getPublicIdentities().forEach(identity => {
let label = ContextualIdentityService.getUserContextLabel(identity.userContextId);
let item = doc.createElementNS(kNSXUL, "toolbarbutton");

View File

@@ -250,6 +250,7 @@ this.SiteDataManager = {
isPrivateCookie(cookie) {
let { userContextId } = cookie.originAttributes;
return userContextId && !ContextualIdentityService.getIdentityFromId(userContextId).public;
// A private cookie is when its userContextId points to a private identity.
return userContextId && !ContextualIdentityService.getPublicIdentityFromId(userContextId);
}
};

View File

@@ -23,7 +23,7 @@ let gContainersPane = {
},
_rebuildView() {
const containers = ContextualIdentityService.getIdentities();
const containers = ContextualIdentityService.getPublicIdentities();
while (this._list.firstChild) {
this._list.firstChild.remove();
}
@@ -83,7 +83,7 @@ let gContainersPane = {
};
let title;
if (userContextId) {
identity = ContextualIdentityService.getIdentityFromId(userContextId);
identity = ContextualIdentityService.getPublicIdentityFromId(userContextId);
// This is required to get the translation string from defaults
identity.name = ContextualIdentityService.getUserContextLabel(identity.userContextId);
title = containersBundle.formatStringFromName("containers.updateContainerTitle", [identity.name], 1);

View File

@@ -244,7 +244,7 @@ _ContextualIdentityService.prototype = {
}
},
getIdentities() {
getPublicIdentities() {
this.ensureDataReady();
return Cu.cloneInto(this._identities.filter(info => info.public), {});
},
@@ -254,15 +254,15 @@ _ContextualIdentityService.prototype = {
return Cu.cloneInto(this._identities.find(info => !info.public && info.name == name), {});
},
getIdentityFromId(userContextId) {
getPublicIdentityFromId(userContextId) {
this.ensureDataReady();
return Cu.cloneInto(this._identities.find(info => info.userContextId == userContextId &&
info.public), {});
},
getUserContextLabel(userContextId) {
let identity = this.getIdentityFromId(userContextId);
if (!identity || !identity.public) {
let identity = this.getPublicIdentityFromId(userContextId);
if (!identity) {
return "";
}
@@ -280,7 +280,7 @@ _ContextualIdentityService.prototype = {
}
let userContextId = tab.getAttribute("usercontextid");
let identity = this.getIdentityFromId(userContextId);
let identity = this.getPublicIdentityFromId(userContextId);
tab.setAttribute("data-identity-color", identity ? identity.color : "");
},
@@ -320,10 +320,10 @@ _ContextualIdentityService.prototype = {
},
telemetry(userContextId) {
let identity = this.getIdentityFromId(userContextId);
let identity = this.getPublicIdentityFromId(userContextId);
// Let's ignore unknown identities for now.
if (!identity || !identity.public) {
if (!identity) {
return;
}

View File

@@ -17,18 +17,18 @@ add_task(function() {
cis = ContextualIdentityService.createNewInstanceForTesting(TEST_STORE_FILE_NAME);
ok(!!cis, "We have our instance of ContextualIdentityService");
equal(cis.getIdentities().length, 4, "By default, 4 containers.");
equal(cis.getIdentityFromId(0), null, "No identity with id 0");
equal(cis.getPublicIdentities().length, 4, "By default, 4 containers.");
equal(cis.getPublicIdentityFromId(0), null, "No identity with id 0");
ok(!!cis.getIdentityFromId(1), "Identity 1 exists");
ok(!!cis.getIdentityFromId(2), "Identity 2 exists");
ok(!!cis.getIdentityFromId(3), "Identity 3 exists");
ok(!!cis.getIdentityFromId(4), "Identity 4 exists");
ok(!!cis.getPublicIdentityFromId(1), "Identity 1 exists");
ok(!!cis.getPublicIdentityFromId(2), "Identity 2 exists");
ok(!!cis.getPublicIdentityFromId(3), "Identity 3 exists");
ok(!!cis.getPublicIdentityFromId(4), "Identity 4 exists");
});
// Create a new identity
add_task(function() {
equal(cis.getIdentities().length, 4, "By default, 4 containers.");
equal(cis.getPublicIdentities().length, 4, "By default, 4 containers.");
let identity = cis.create("New Container", "Icon", "Color");
ok(!!identity, "New container created");
@@ -36,36 +36,36 @@ add_task(function() {
equal(identity.icon, "Icon", "Icon matches");
equal(identity.color, "Color", "Color matches");
equal(cis.getIdentities().length, 5, "Expected 5 containers.");
equal(cis.getPublicIdentities().length, 5, "Expected 5 containers.");
ok(!!cis.getIdentityFromId(identity.userContextId), "Identity exists");
equal(cis.getIdentityFromId(identity.userContextId).name, "New Container", "Identity name is OK");
equal(cis.getIdentityFromId(identity.userContextId).icon, "Icon", "Identity icon is OK");
equal(cis.getIdentityFromId(identity.userContextId).color, "Color", "Identity color is OK");
ok(!!cis.getPublicIdentityFromId(identity.userContextId), "Identity exists");
equal(cis.getPublicIdentityFromId(identity.userContextId).name, "New Container", "Identity name is OK");
equal(cis.getPublicIdentityFromId(identity.userContextId).icon, "Icon", "Identity icon is OK");
equal(cis.getPublicIdentityFromId(identity.userContextId).color, "Color", "Identity color is OK");
equal(cis.getUserContextLabel(identity.userContextId), "New Container", "Identity label is OK");
});
// Remove an identity
add_task(function() {
equal(cis.getIdentities().length, 5, "Expected 5 containers.");
equal(cis.getPublicIdentities().length, 5, "Expected 5 containers.");
equal(cis.remove(-1), false, "cis.remove() returns false if identity doesn't exist.");
equal(cis.remove(1), true, "cis.remove() returns true if identity exists.");
equal(cis.getIdentities().length, 4, "Expected 4 containers.");
equal(cis.getPublicIdentities().length, 4, "Expected 4 containers.");
});
// Update an identity
add_task(function() {
ok(!!cis.getIdentityFromId(2), "Identity 2 exists");
ok(!!cis.getPublicIdentityFromId(2), "Identity 2 exists");
equal(cis.update(-1, "Container", "Icon", "Color"), false, "Update returns true if everything is OK");
equal(cis.update(2, "Container", "Icon", "Color"), true, "Update returns true if everything is OK");
ok(!!cis.getIdentityFromId(2), "Identity exists");
equal(cis.getIdentityFromId(2).name, "Container", "Identity name is OK");
equal(cis.getIdentityFromId(2).icon, "Icon", "Identity icon is OK");
equal(cis.getIdentityFromId(2).color, "Color", "Identity color is OK");
ok(!!cis.getPublicIdentityFromId(2), "Identity exists");
equal(cis.getPublicIdentityFromId(2).name, "Container", "Identity name is OK");
equal(cis.getPublicIdentityFromId(2).icon, "Icon", "Identity icon is OK");
equal(cis.getPublicIdentityFromId(2).color, "Color", "Identity color is OK");
equal(cis.getUserContextLabel(2), "Container", "Identity label is OK");
});

View File

@@ -17,18 +17,18 @@ add_task(function() {
cis = ContextualIdentityService.createNewInstanceForTesting(TEST_STORE_FILE_NAME);
ok(!!cis, "We have our instance of ContextualIdentityService");
equal(cis.getIdentities().length, 4, "By default, 4 containers.");
equal(cis.getIdentityFromId(0), null, "No identity with id 0");
equal(cis.getPublicIdentities().length, 4, "By default, 4 containers.");
equal(cis.getPublicIdentityFromId(0), null, "No identity with id 0");
ok(!!cis.getIdentityFromId(1), "Identity 1 exists");
ok(!!cis.getIdentityFromId(2), "Identity 2 exists");
ok(!!cis.getIdentityFromId(3), "Identity 3 exists");
ok(!!cis.getIdentityFromId(4), "Identity 4 exists");
ok(!!cis.getPublicIdentityFromId(1), "Identity 1 exists");
ok(!!cis.getPublicIdentityFromId(2), "Identity 2 exists");
ok(!!cis.getPublicIdentityFromId(3), "Identity 3 exists");
ok(!!cis.getPublicIdentityFromId(4), "Identity 4 exists");
});
// Create a new identity
add_task(function() {
equal(cis.getIdentities().length, 4, "By default, 4 containers.");
equal(cis.getPublicIdentities().length, 4, "By default, 4 containers.");
let identity = cis.create("New Container", "Icon", "Color");
ok(!!identity, "New container created");
@@ -36,32 +36,32 @@ add_task(function() {
equal(identity.icon, "Icon", "Icon matches");
equal(identity.color, "Color", "Color matches");
equal(cis.getIdentities().length, 5, "Expected 5 containers.");
equal(cis.getPublicIdentities().length, 5, "Expected 5 containers.");
ok(!!cis.getIdentityFromId(identity.userContextId), "Identity exists");
equal(cis.getIdentityFromId(identity.userContextId).name, "New Container", "Identity name is OK");
equal(cis.getIdentityFromId(identity.userContextId).icon, "Icon", "Identity icon is OK");
equal(cis.getIdentityFromId(identity.userContextId).color, "Color", "Identity color is OK");
ok(!!cis.getPublicIdentityFromId(identity.userContextId), "Identity exists");
equal(cis.getPublicIdentityFromId(identity.userContextId).name, "New Container", "Identity name is OK");
equal(cis.getPublicIdentityFromId(identity.userContextId).icon, "Icon", "Identity icon is OK");
equal(cis.getPublicIdentityFromId(identity.userContextId).color, "Color", "Identity color is OK");
equal(cis.getUserContextLabel(identity.userContextId), "New Container", "Identity label is OK");
// Remove an identity
equal(cis.remove(-1), false, "cis.remove() returns false if identity doesn't exist.");
equal(cis.remove(1), true, "cis.remove() returns true if identity exists.");
equal(cis.getIdentities().length, 4, "Expected 4 containers.");
equal(cis.getPublicIdentities().length, 4, "Expected 4 containers.");
});
// Update an identity
add_task(function() {
ok(!!cis.getIdentityFromId(2), "Identity 2 exists");
ok(!!cis.getPublicIdentityFromId(2), "Identity 2 exists");
equal(cis.update(-1, "Container", "Icon", "Color"), false, "Update returns false if the identity doesn't exist");
equal(cis.update(2, "Container", "Icon", "Color"), true, "Update returns true if everything is OK");
ok(!!cis.getIdentityFromId(2), "Identity exists");
equal(cis.getIdentityFromId(2).name, "Container", "Identity name is OK");
equal(cis.getIdentityFromId(2).icon, "Icon", "Identity icon is OK");
equal(cis.getIdentityFromId(2).color, "Color", "Identity color is OK");
ok(!!cis.getPublicIdentityFromId(2), "Identity exists");
equal(cis.getPublicIdentityFromId(2).name, "Container", "Identity name is OK");
equal(cis.getPublicIdentityFromId(2).icon, "Icon", "Identity icon is OK");
equal(cis.getPublicIdentityFromId(2).color, "Color", "Identity color is OK");
equal(cis.getUserContextLabel(2), "Container", "Identity label is OK");
});

View File

@@ -25,13 +25,13 @@ extensions.registerSchemaAPI("contextualIdentities", "addon_parent", context =>
return Promise.resolve(null);
}
let identity = ContextualIdentityService.getIdentityFromId(containerId);
let identity = ContextualIdentityService.getPublicIdentityFromId(containerId);
return Promise.resolve(convert(identity));
},
query(details) {
let identities = [];
ContextualIdentityService.getIdentities().forEach(identity => {
ContextualIdentityService.getPublicIdentities().forEach(identity => {
if (details.name &&
ContextualIdentityService.getUserContextLabel(identity.userContextId) != details.name) {
return;
@@ -56,7 +56,7 @@ extensions.registerSchemaAPI("contextualIdentities", "addon_parent", context =>
return Promise.resolve(null);
}
let identity = ContextualIdentityService.getIdentityFromId(containerId);
let identity = ContextualIdentityService.getPublicIdentityFromId(containerId);
if (!identity) {
return Promise.resolve(null);
}
@@ -88,7 +88,7 @@ extensions.registerSchemaAPI("contextualIdentities", "addon_parent", context =>
return Promise.resolve(null);
}
let identity = ContextualIdentityService.getIdentityFromId(containerId);
let identity = ContextualIdentityService.getPublicIdentityFromId(containerId);
if (!identity) {
return Promise.resolve(null);
}

View File

@@ -50,7 +50,7 @@ global.getContainerForCookieStoreId = function(storeId) {
}
let containerId = storeId.substring(CONTAINER_STORE.length);
if (ContextualIdentityService.getIdentityFromId(containerId)) {
if (ContextualIdentityService.getPublicIdentityFromId(containerId)) {
return parseInt(containerId, 10);
}