Bug 1266022 - skip checking of LoadInfo for chrome resources. r=sicking

When tab with a userContextId!=0 contains a chrome page (such as
about:newtab) the userContextId in the LoadInfo won't match the
userContextId in the LoadContext. The LoadInfo will contain the
systemPrincipal and so use userContextId=0, the LoadContext has the
userContextId of the tab (!=0).

This is fine as long as we page only loads chrome-URLs and other
non-http URLs since those don't use cookies anyway.

So avoid asserting in this situation.

Long term we want the chrome page to use the default userContextId for
cookies, since that's what it chrome code normally use. This will work
properly once we get the cookie jar information from the LoadInfo rather
than from the LoadContext.
This commit is contained in:
Yoshi Huang 2016-04-29 10:52:47 +08:00
parent 287cf0140e
commit de5b190579
3 changed files with 49 additions and 1 deletions

View File

@ -6,6 +6,7 @@ support-files =
serviceworker.html
worker.js
[browser_aboutURLs.js]
[browser_usercontext.js]
[browser_usercontextid_tabdrop.js]
[browser_windowName.js]

View File

@ -0,0 +1,42 @@
add_task(function* () {
let aboutURLs = [];
// List of about: URLs that will initiate network requests.
let networkURLs = [
"credits",
"telemetry" // about:telemetry will fetch Telemetry asynchrounously and takes
// longer, we skip this for now.
];
let ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
for (let cid in Cc) {
let result = cid.match(/@mozilla.org\/network\/protocol\/about;1\?what\=(.*)$/);
if (!result) {
continue;
}
let aboutType = result[1];
let contract = "@mozilla.org/network/protocol/about;1?what=" + aboutType;
try {
let am = Cc[contract].getService(Ci.nsIAboutModule);
let uri = ios.newURI("about:"+aboutType, null, null);
let flags = am.getURIFlags(uri);
if (!(flags & Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT) &&
networkURLs.indexOf(aboutType) == -1) {
aboutURLs.push(aboutType);
}
} catch (e) {
// getService might have thrown if the component doesn't actually
// implement nsIAboutModule
}
}
for (let url of aboutURLs) {
let tab = gBrowser.addTab("about:"+url, {userContextId: 1});
yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
ok(true);
yield BrowserTestUtils.removeTab(tab);
}
});

View File

@ -647,7 +647,12 @@ nsBaseChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt)
NS_ENSURE_TRUE(!mWasOpened, NS_ERROR_ALREADY_OPENED);
NS_ENSURE_ARG(listener);
NS_CompareLoadInfoAndLoadContext(this);
// Skip checking for chrome:// sub-resources.
nsAutoCString scheme;
mURI->GetScheme(scheme);
if (!scheme.EqualsLiteral("file")) {
NS_CompareLoadInfoAndLoadContext(this);
}
// Ensure that this is an allowed port before proceeding.
nsresult rv = NS_CheckPortSafety(mURI);