Skip to content

Commit bc8c520

Browse files
Bug 1748138 - Modified cache checks to account for partition key taken from content process. r=anti-tracking-reviewers,timhuang,mconley
Differential Revision: https://phabricator.services.mozilla.com/D183190
1 parent ab39b57 commit bc8c520

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

browser/actors/PageInfoChild.sys.mjs

+10
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,21 @@ export class PageInfoChild extends JSWindowActorChild {
3030
mediaItems: await this.getDocumentMedia(document),
3131
});
3232
}
33+
case "PageInfo:getPartitionKey": {
34+
return Promise.resolve({
35+
partitionKey: await this.getPartitionKey(document),
36+
});
37+
}
3338
}
3439

3540
return undefined;
3641
}
3742

43+
getPartitionKey(document) {
44+
let partitionKey = document.cookieJarSettings.partitionKey;
45+
return partitionKey;
46+
}
47+
3848
getMetaInfo(document) {
3949
let metaViewRows = [];
4050

browser/base/content/pageinfo/pageInfo.js

+28-5
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,7 @@ const cacheService = Cc[
271271
"@mozilla.org/netwerk/cache-storage-service;1"
272272
].getService(nsICacheStorageService);
273273

274-
var loadContextInfo = Services.loadContextInfo.fromLoadContext(
275-
window.docShell.QueryInterface(Ci.nsILoadContext),
276-
false
277-
);
278-
var diskStorage = cacheService.diskCacheStorage(loadContextInfo);
274+
var diskStorage = null;
279275

280276
const nsICookiePermission = Ci.nsICookiePermission;
281277

@@ -464,6 +460,20 @@ async function loadTab(args) {
464460
let browsingContext = args?.browsingContext;
465461
let browser = args?.browser;
466462

463+
// Check if diskStorage has not be created yet if it has not been, get
464+
// partitionKey from content process and create diskStorage with said partitionKey
465+
if (!diskStorage) {
466+
let oaWithPartitionKey = await getOaWithPartitionKey(
467+
browsingContext,
468+
browser
469+
);
470+
let loadContextInfo = Services.loadContextInfo.custom(
471+
false,
472+
oaWithPartitionKey
473+
);
474+
diskStorage = cacheService.diskCacheStorage(loadContextInfo);
475+
}
476+
467477
/* Load the page info */
468478
await loadPageInfo(browsingContext, imageElement, browser);
469479

@@ -1170,3 +1180,16 @@ function checkProtocol(img) {
11701180
/^(https?|file|about|chrome|resource):/.test(url)
11711181
);
11721182
}
1183+
1184+
async function getOaWithPartitionKey(browsingContext, browser) {
1185+
browser = browser || window.opener.gBrowser.selectedBrowser;
1186+
browsingContext = browsingContext || browser.browsingContext;
1187+
1188+
let actor = browsingContext.currentWindowGlobal.getActor("PageInfo");
1189+
let partitionKeyFromChild = await actor.sendQuery("PageInfo:getPartitionKey");
1190+
1191+
let oa = browser.contentPrincipal.originAttributes;
1192+
oa.partitionKey = partitionKeyFromChild.partitionKey;
1193+
1194+
return oa;
1195+
}

browser/base/content/test/pageinfo/browser_pageinfo_images.js

+19
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,22 @@ add_task(async function test_view_image_info() {
9191
}
9292
);
9393
});
94+
95+
add_task(async function test_image_size() {
96+
await BrowserTestUtils.withNewTab(
97+
TEST_PATH + "all_images.html",
98+
async function () {
99+
let pageInfo = BrowserPageInfo(
100+
gBrowser.selectedBrowser.currentURI.spec,
101+
"mediaTab"
102+
);
103+
await BrowserTestUtils.waitForEvent(pageInfo, "page-info-init");
104+
105+
let imageSize = pageInfo.document.getElementById("imagesizetext");
106+
107+
Assert.notEqual("media-unknown-not-cached", imageSize.value);
108+
109+
pageInfo.close();
110+
}
111+
);
112+
});

0 commit comments

Comments
 (0)