Bug 1187165 - Use channel->ascynOpen2 in dom/base/ImportManager (r=sicking)
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Mon, 10 Aug 2015 10:25:20 -0700
changeset 257369 12742043d2a70d926a290828e04688c4c3473d4c
parent 257368 f73f15ea2b8ea5e1654078b2bae16172af2c1f0f
child 257370 a647ab8f8d8d5808980a1d28f28f26e2f0d910c8
push id29215
push userryanvm@gmail.com
push dateWed, 12 Aug 2015 14:47:21 +0000
treeherdermozilla-central@295bbb5db86b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs1187165
milestone43.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 1187165 - Use channel->ascynOpen2 in dom/base/ImportManager (r=sicking)
dom/base/ImportManager.cpp
dom/security/nsContentSecurityManager.cpp
--- a/dom/base/ImportManager.cpp
+++ b/dom/base/ImportManager.cpp
@@ -458,61 +458,32 @@ ImportLoader::Principal()
   MOZ_ASSERT(sop);
   return sop->GetPrincipal();
 }
 
 void
 ImportLoader::Open()
 {
   AutoError ae(this, false);
-  // Imports should obey to the master documents CSP.
-  nsCOMPtr<nsIDocument> master = mImportParent->MasterDocument();
-  nsIPrincipal* principal = Principal();
+
+  nsCOMPtr<nsILoadGroup> loadGroup =
+    mImportParent->MasterDocument()->GetDocumentLoadGroup();
 
-  int16_t shouldLoad = nsIContentPolicy::ACCEPT;
-  nsresult rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_SUBDOCUMENT,
-                                          mURI,
-                                          principal,
-                                          mImportParent,
-                                          NS_LITERAL_CSTRING("text/html"),
-                                          /* extra = */ nullptr,
-                                          &shouldLoad,
-                                          nsContentUtils::GetContentPolicy(),
-                                          nsContentUtils::GetSecurityManager());
-  if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) {
-    NS_WARN_IF_FALSE(NS_CP_ACCEPTED(shouldLoad), "ImportLoader rejected by CSP");
-    return;
-  }
-
-  nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
-  rv = secMan->CheckLoadURIWithPrincipal(principal, mURI,
-                                         nsIScriptSecurityManager::STANDARD);
-  NS_ENSURE_SUCCESS_VOID(rv);
-
-  nsCOMPtr<nsILoadGroup> loadGroup = master->GetDocumentLoadGroup();
   nsCOMPtr<nsIChannel> channel;
-  rv = NS_NewChannel(getter_AddRefs(channel),
-                     mURI,
-                     mImportParent,
-                     nsILoadInfo::SEC_NORMAL,
-                     nsIContentPolicy::TYPE_SUBDOCUMENT,
-                     loadGroup,
-                     nullptr,  // aCallbacks
-                     nsIRequest::LOAD_BACKGROUND);
+  nsresult rv = NS_NewChannel(getter_AddRefs(channel),
+                              mURI,
+                              mImportParent,
+                              nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS,
+                              nsIContentPolicy::TYPE_SUBDOCUMENT,
+                              loadGroup,
+                              nullptr,  // aCallbacks
+                              nsIRequest::LOAD_BACKGROUND);
 
   NS_ENSURE_SUCCESS_VOID(rv);
-
-  // Init CORSListenerProxy and omit credentials.
-  nsRefPtr<nsCORSListenerProxy> corsListener =
-    new nsCORSListenerProxy(this, principal,
-                            /* aWithCredentials */ false);
-  rv = corsListener->Init(channel, DataURIHandling::Allow);
-  NS_ENSURE_SUCCESS_VOID(rv);
-
-  rv = channel->AsyncOpen(corsListener, nullptr);
+  rv = channel->AsyncOpen2(this);
   NS_ENSURE_SUCCESS_VOID(rv);
 
   BlockScripts();
   ae.Pass();
 }
 
 NS_IMETHODIMP
 ImportLoader::OnDataAvailable(nsIRequest* aRequest,
--- a/dom/security/nsContentSecurityManager.cpp
+++ b/dom/security/nsContentSecurityManager.cpp
@@ -125,18 +125,30 @@ DoContentSecurityChecks(nsIURI* aURI, ns
       requestingContext = aLoadInfo->LoadingNode();
       break;
     }
 
     case nsIContentPolicy::TYPE_SCRIPT:
     case nsIContentPolicy::TYPE_IMAGE:
     case nsIContentPolicy::TYPE_STYLESHEET:
     case nsIContentPolicy::TYPE_OBJECT:
-    case nsIContentPolicy::TYPE_DOCUMENT:
-    case nsIContentPolicy::TYPE_SUBDOCUMENT:
+    case nsIContentPolicy::TYPE_DOCUMENT: {
+      MOZ_ASSERT(false, "contentPolicyType not supported yet");
+      break;
+    }
+
+    case nsIContentPolicy::TYPE_SUBDOCUMENT: {
+      mimeTypeGuess = NS_LITERAL_CSTRING("text/html");
+      requestingContext = aLoadInfo->LoadingNode();
+      MOZ_ASSERT(!requestingContext ||
+                 requestingContext->NodeType() == nsIDOMNode::DOCUMENT_NODE,
+                 "type_subdocument requires requestingContext of type Document");
+      break;
+    }
+
     case nsIContentPolicy::TYPE_REFRESH:
     case nsIContentPolicy::TYPE_XBL:
     case nsIContentPolicy::TYPE_PING: {
       MOZ_ASSERT(false, "contentPolicyType not supported yet");
       break;
     }
 
     case nsIContentPolicy::TYPE_XMLHTTPREQUEST: {