Bug 1266022 - skip checking of LoadInfo for chrome resources. r=sicking
authorYoshi Huang <allstars.chh@mozilla.com>
Fri, 29 Apr 2016 10:52:47 +0800
changeset 337355 5fbcba6455cb98a95705249606afbe6fb53cdc3d
parent 337354 b2cc990b42461e111ca854d4111965cc5fe5ff80
child 337356 7c71d376dfac6280c520b09acf3acba01da33bbc
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs1266022
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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.
browser/components/contextualidentity/test/browser/browser.ini
browser/components/contextualidentity/test/browser/browser_aboutURLs.js
netwerk/base/nsBaseChannel.cpp
--- a/browser/components/contextualidentity/test/browser/browser.ini
+++ b/browser/components/contextualidentity/test/browser/browser.ini
@@ -1,14 +1,15 @@
 [DEFAULT]
 skip-if = buildapp == "mulet"
 support-files =
   empty_file.html
   file_reflect_cookie_into_title.html
   serviceworker.html
   worker.js
 
+[browser_aboutURLs.js]
 [browser_usercontext.js]
 [browser_usercontextid_tabdrop.js]
 [browser_windowName.js]
 [browser_windowOpen.js]
 [browser_serviceworkers.js]
 [browser_broadcastchannel.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/contextualidentity/test/browser/browser_aboutURLs.js
@@ -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);
+  }
+});
--- a/netwerk/base/nsBaseChannel.cpp
+++ b/netwerk/base/nsBaseChannel.cpp
@@ -642,17 +642,22 @@ nsBaseChannel::AsyncOpen(nsIStreamListen
               nsContentUtils::IsSystemPrincipal(mLoadInfo->LoadingPrincipal())),
              "security flags in loadInfo but asyncOpen2() not called");
 
   NS_ENSURE_TRUE(mURI, NS_ERROR_NOT_INITIALIZED);
   NS_ENSURE_TRUE(!mPump, NS_ERROR_IN_PROGRESS);
   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);
   if (NS_FAILED(rv)) {
     mCallbacks = nullptr;
     return rv;
   }