Bug 1206964 - Use channel->AsyncOpen2() in netwerk/base/nsNetUtil.cpp (r=sicking)
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Mon, 02 Nov 2015 17:31:08 -0800
changeset 270904 c6eb37d7c93eb11917560f24dda69f8733309319
parent 270903 e2bfee574e4e5842be48a81f7e485a2f0ec08848
child 270905 ad08ab3d158e4ffd408f5716cb5c07cbeb875921
push id18459
push usercbook@mozilla.com
push dateTue, 03 Nov 2015 11:14:32 +0000
treeherderb2g-inbound@09173d8e6694 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs1206964
milestone45.0a1
Bug 1206964 - Use channel->AsyncOpen2() in netwerk/base/nsNetUtil.cpp (r=sicking)
dom/xul/XULDocument.cpp
netwerk/base/nsNetUtil.cpp
netwerk/base/nsNetUtil.h
widget/cocoa/nsSound.mm
widget/gtk/nsSound.cpp
widget/windows/nsSound.cpp
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -3239,57 +3239,43 @@ XULDocument::LoadScript(nsXULPrototypeSc
             rv = ExecuteScript(aScriptProto);
 
             // Ignore return value from execution, and don't block
             *aBlock = false;
             return NS_OK;
         }
     }
 
-    // Allow security manager and content policies to veto the load. Note that
-    // at this point we already lost context information of the script.
-    rv = nsScriptLoader::ShouldLoadScript(
-                            this,
-                            static_cast<nsIDocument*>(this),
-                            aScriptProto->mSrcURI,
-                            NS_LITERAL_STRING("application/x-javascript"),
-                            false);
-    if (NS_FAILED(rv)) {
-      *aBlock = false;
-      return rv;
-    }
-
     // Release script objects from FastLoad since we decided against using them
     aScriptProto->UnlinkJSObjects();
 
     // Set the current script prototype so that OnStreamComplete can report
     // the right file if there are errors in the script.
     NS_ASSERTION(!mCurrentScriptProto,
                  "still loading a script when starting another load?");
     mCurrentScriptProto = aScriptProto;
 
-    if (aScriptProto->mSrcLoading) {
+    if (isChromeDoc && aScriptProto->mSrcLoading) {
         // Another XULDocument load has started, which is still in progress.
         // Remember to ResumeWalk this document when the load completes.
         mNextSrcLoadWaiter = aScriptProto->mSrcLoadWaiters;
         aScriptProto->mSrcLoadWaiters = this;
         NS_ADDREF_THIS();
     }
     else {
         nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup);
 
         // Note: the loader will keep itself alive while it's loading.
         nsCOMPtr<nsIStreamLoader> loader;
         rv = NS_NewStreamLoader(getter_AddRefs(loader),
                                 aScriptProto->mSrcURI,
                                 this, // aObserver
                                 this, // aRequestingContext
-                                nsILoadInfo::SEC_NORMAL,
-                                nsIContentPolicy::TYPE_OTHER,
-                                nullptr, // aContext
+                                nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS,
+                                nsIContentPolicy::TYPE_INTERNAL_SCRIPT,
                                 group);
 
         if (NS_FAILED(rv)) {
             mCurrentScriptProto = nullptr;
             return rv;
         }
 
         aScriptProto->mSrcLoading = true;
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -582,17 +582,16 @@ NS_NewDownloader(nsIStreamListener   **r
 nsresult
 NS_NewStreamLoaderInternal(nsIStreamLoader        **outStream,
                            nsIURI                  *aUri,
                            nsIStreamLoaderObserver *aObserver,
                            nsINode                 *aLoadingNode,
                            nsIPrincipal            *aLoadingPrincipal,
                            nsSecurityFlags          aSecurityFlags,
                            nsContentPolicyType      aContentPolicyType,
-                           nsISupports             *aContext /* = nullptr */,
                            nsILoadGroup            *aLoadGroup /* = nullptr */,
                            nsIInterfaceRequestor   *aCallbacks /* = nullptr */,
                            nsLoadFlags              aLoadFlags /* = nsIRequest::LOAD_NORMAL */,
                            nsIURI                  *aReferrer /* = nullptr */)
 {
    nsCOMPtr<nsIChannel> channel;
    nsresult rv = NS_NewChannelInternal(getter_AddRefs(channel),
                                        aUri,
@@ -607,69 +606,65 @@ NS_NewStreamLoaderInternal(nsIStreamLoad
 
   NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
   if (httpChannel) {
     httpChannel->SetReferrer(aReferrer);
   }
   rv = NS_NewStreamLoader(outStream, aObserver);
   NS_ENSURE_SUCCESS(rv, rv);
-  return channel->AsyncOpen(*outStream, aContext);
+  return channel->AsyncOpen2(*outStream);
 }
 
 
 nsresult /* NS_NewStreamLoaderNode */
 NS_NewStreamLoader(nsIStreamLoader        **outStream,
                    nsIURI                  *aUri,
                    nsIStreamLoaderObserver *aObserver,
                    nsINode                 *aLoadingNode,
                    nsSecurityFlags          aSecurityFlags,
                    nsContentPolicyType      aContentPolicyType,
-                   nsISupports             *aContext /* = nullptr */,
                    nsILoadGroup            *aLoadGroup /* = nullptr */,
                    nsIInterfaceRequestor   *aCallbacks /* = nullptr */,
                    nsLoadFlags              aLoadFlags /* = nsIRequest::LOAD_NORMAL */,
                    nsIURI                  *aReferrer /* = nullptr */)
 {
   NS_ASSERTION(aLoadingNode, "Can not create stream loader without a loading Node!");
   return NS_NewStreamLoaderInternal(outStream,
                                     aUri,
                                     aObserver,
                                     aLoadingNode,
                                     aLoadingNode->NodePrincipal(),
                                     aSecurityFlags,
                                     aContentPolicyType,
-                                    aContext,
                                     aLoadGroup,
                                     aCallbacks,
                                     aLoadFlags,
                                     aReferrer);
 }
 
 nsresult /* NS_NewStreamLoaderPrincipal */
 NS_NewStreamLoader(nsIStreamLoader        **outStream,
                    nsIURI                  *aUri,
                    nsIStreamLoaderObserver *aObserver,
                    nsIPrincipal            *aLoadingPrincipal,
                    nsSecurityFlags          aSecurityFlags,
                    nsContentPolicyType      aContentPolicyType,
-                   nsISupports             *aContext /* = nullptr */,
                    nsILoadGroup            *aLoadGroup /* = nullptr */,
                    nsIInterfaceRequestor   *aCallbacks /* = nullptr */,
                    nsLoadFlags              aLoadFlags /* = nsIRequest::LOAD_NORMAL */,
                    nsIURI                  *aReferrer /* = nullptr */)
 {
   return NS_NewStreamLoaderInternal(outStream,
                                     aUri,
                                     aObserver,
                                     nullptr, // aLoadingNode
                                     aLoadingPrincipal,
                                     aSecurityFlags,
                                     aContentPolicyType,
-                                    aContext,
                                     aLoadGroup,
                                     aCallbacks,
                                     aLoadFlags,
                                     aReferrer);
 }
 
 nsresult
 NS_NewUnicharStreamLoader(nsIUnicharStreamLoader        **result,
--- a/netwerk/base/nsNetUtil.h
+++ b/netwerk/base/nsNetUtil.h
@@ -371,43 +371,40 @@ nsresult NS_NewStreamLoader(nsIStreamLoa
 
 nsresult NS_NewStreamLoaderInternal(nsIStreamLoader        **outStream,
                                     nsIURI                  *aUri,
                                     nsIStreamLoaderObserver *aObserver,
                                     nsINode                 *aLoadingNode,
                                     nsIPrincipal            *aLoadingPrincipal,
                                     nsSecurityFlags          aSecurityFlags,
                                     nsContentPolicyType      aContentPolicyType,
-                                    nsISupports             *aContext = nullptr,
                                     nsILoadGroup            *aLoadGroup = nullptr,
                                     nsIInterfaceRequestor   *aCallbacks = nullptr,
                                     nsLoadFlags              aLoadFlags = nsIRequest::LOAD_NORMAL,
                                     nsIURI                  *aReferrer = nullptr);
 
 nsresult /* NS_NewStreamLoaderNode */
 NS_NewStreamLoader(nsIStreamLoader        **outStream,
                    nsIURI                  *aUri,
                    nsIStreamLoaderObserver *aObserver,
                    nsINode                 *aLoadingNode,
                    nsSecurityFlags          aSecurityFlags,
                    nsContentPolicyType      aContentPolicyType,
-                   nsISupports             *aContext = nullptr,
                    nsILoadGroup            *aLoadGroup = nullptr,
                    nsIInterfaceRequestor   *aCallbacks = nullptr,
                    nsLoadFlags              aLoadFlags = nsIRequest::LOAD_NORMAL,
                    nsIURI                  *aReferrer = nullptr);
 
 nsresult /* NS_NewStreamLoaderPrincipal */
 NS_NewStreamLoader(nsIStreamLoader        **outStream,
                    nsIURI                  *aUri,
                    nsIStreamLoaderObserver *aObserver,
                    nsIPrincipal            *aLoadingPrincipal,
                    nsSecurityFlags          aSecurityFlags,
                    nsContentPolicyType      aContentPolicyType,
-                   nsISupports             *aContext = nullptr,
                    nsILoadGroup            *aLoadGroup = nullptr,
                    nsIInterfaceRequestor   *aCallbacks = nullptr,
                    nsLoadFlags              aLoadFlags = nsIRequest::LOAD_NORMAL,
                    nsIURI                  *aReferrer = nullptr);
 
 nsresult NS_NewUnicharStreamLoader(nsIUnicharStreamLoader        **result,
                                    nsIUnicharStreamLoaderObserver *observer);
 
--- a/widget/cocoa/nsSound.mm
+++ b/widget/cocoa/nsSound.mm
@@ -61,17 +61,17 @@ NS_IMETHODIMP
 nsSound::Play(nsIURL *aURL)
 {
   nsCOMPtr<nsIURI> uri(do_QueryInterface(aURL));
   nsCOMPtr<nsIStreamLoader> loader;
   return NS_NewStreamLoader(getter_AddRefs(loader),
                             uri,
                             this, // aObserver
                             nsContentUtils::GetSystemPrincipal(),
-                            nsILoadInfo::SEC_NORMAL,
+                            nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
                             nsIContentPolicy::TYPE_OTHER);
 }
 
 NS_IMETHODIMP
 nsSound::Init()
 {
   return NS_OK;
 }
--- a/widget/gtk/nsSound.cpp
+++ b/widget/gtk/nsSound.cpp
@@ -347,17 +347,17 @@ NS_METHOD nsSound::Play(nsIURL *aURL)
         ca_context_play(ctx, 0, "media.filename", path, nullptr);
         g_free(path);
     } else {
         nsCOMPtr<nsIStreamLoader> loader;
         rv = NS_NewStreamLoader(getter_AddRefs(loader),
                                 aURL,
                                 this, // aObserver
                                 nsContentUtils::GetSystemPrincipal(),
-                                nsILoadInfo::SEC_NORMAL,
+                                nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
                                 nsIContentPolicy::TYPE_OTHER);
     }
 
     return rv;
 }
 
 NS_IMETHODIMP nsSound::PlayEventSound(uint32_t aEventId)
 {
--- a/widget/windows/nsSound.cpp
+++ b/widget/windows/nsSound.cpp
@@ -207,17 +207,17 @@ NS_IMETHODIMP nsSound::Play(nsIURL *aURL
          ("%s\n", url));
 #endif
 
   nsCOMPtr<nsIStreamLoader> loader;
   rv = NS_NewStreamLoader(getter_AddRefs(loader),
                           aURL,
                           this, // aObserver
                           nsContentUtils::GetSystemPrincipal(),
-                          nsILoadInfo::SEC_NORMAL,
+                          nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
                           nsIContentPolicy::TYPE_OTHER);
   return rv;
 }
 
 
 NS_IMETHODIMP nsSound::Init()
 {
   // This call halts a sound if it was still playing.