Bug 1038756: Callsites creating a channel in /netwerk/ (r=mcmanus)
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Sun, 21 Sep 2014 09:40:12 -0700
changeset 206450 0dabb0a747fcbf2cdfe6c7452e021046553fa61c
parent 206449 cc656384d43ee7e7d7eb7651ae9ee15419c93d90
child 206451 2d6e88e962a7f6acbb083002d5c8cdb9f19f25f5
push id49423
push usermozilla@christophkerschbaumer.com
push dateMon, 22 Sep 2014 12:15:44 +0000
treeherdermozilla-inbound@4120e1cbb5b4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus
bugs1038756
milestone35.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 1038756: Callsites creating a channel in /netwerk/ (r=mcmanus) * * * [mq]: child_parent_communication.patch
netwerk/base/src/nsBufferedStreams.cpp
netwerk/base/src/nsIncrementalDownload.cpp
netwerk/protocol/file/nsFileChannel.cpp
netwerk/test/TestHttp.cpp
netwerk/test/TestOpen.cpp
netwerk/test/TestPageLoad.cpp
netwerk/test/TestPerf.cpp
netwerk/test/TestProtocols.cpp
netwerk/test/TestStreamLoader.cpp
netwerk/test/TestSyncHTTP.cpp
netwerk/test/TestThreadedIO.cpp
--- a/netwerk/base/src/nsBufferedStreams.cpp
+++ b/netwerk/base/src/nsBufferedStreams.cpp
@@ -810,9 +810,11 @@ nsBufferedOutputStream::GetUnbufferedStr
             return rv;
     }
 
     *aStream = mStream;
     NS_IF_ADDREF(*aStream);
     return NS_OK;
 }
 
+#undef METER
+
 ////////////////////////////////////////////////////////////////////////////////
--- a/netwerk/base/src/nsIncrementalDownload.cpp
+++ b/netwerk/base/src/nsIncrementalDownload.cpp
@@ -17,16 +17,18 @@
 #include "nsIFile.h"
 #include "nsITimer.h"
 #include "nsNetUtil.h"
 #include "nsAutoPtr.h"
 #include "nsWeakReference.h"
 #include "prio.h"
 #include "prprf.h"
 #include <algorithm>
+#include "nsIContentPolicy.h"
+#include "nsContentUtils.h"
 
 // Default values used to initialize a nsIncrementalDownload object.
 #define DEFAULT_CHUNK_SIZE (4096 * 16)  // bytes
 #define DEFAULT_INTERVAL    60          // seconds
 
 #define UPDATE_PROGRESS_INTERVAL PRTime(500 * PR_USEC_PER_MSEC) // 500ms
 
 // Number of times to retry a failed byte-range request.
@@ -255,18 +257,26 @@ nsIncrementalDownload::ProcessTimeout()
   if (NS_FAILED(mStatus)) {
     CallOnStopRequest();
     return NS_OK;
   }
 
   // Fetch next chunk
   
   nsCOMPtr<nsIChannel> channel;
-  nsresult rv = NS_NewChannel(getter_AddRefs(channel), mFinalURI, nullptr,
-                              nullptr, this, mLoadFlags);
+  nsresult rv = NS_NewChannel(getter_AddRefs(channel),
+                              mFinalURI,
+                              nsContentUtils::GetSystemPrincipal(),
+                              nsILoadInfo::SEC_NORMAL,
+                              nsIContentPolicy::TYPE_OTHER,
+                              nullptr,   // aChannelPolicy
+                              nullptr,   // loadGroup
+                              this,      // aCallbacks
+                              mLoadFlags);
+
   if (NS_FAILED(rv))
     return rv;
 
   nsCOMPtr<nsIHttpChannel> http = do_QueryInterface(channel, &rv);
   if (NS_FAILED(rv))
     return rv;
 
   NS_ASSERTION(mCurrentSize != int64_t(-1),
--- a/netwerk/protocol/file/nsFileChannel.cpp
+++ b/netwerk/protocol/file/nsFileChannel.cpp
@@ -10,16 +10,18 @@
 #include "nsDirectoryIndexStream.h"
 #include "nsThreadUtils.h"
 #include "nsTransportUtils.h"
 #include "nsStreamUtils.h"
 #include "nsMimeTypes.h"
 #include "nsNetUtil.h"
 #include "nsProxyRelease.h"
 #include "nsAutoPtr.h"
+#include "nsIContentPolicy.h"
+#include "nsContentUtils.h"
 
 #include "nsIFileURL.h"
 #include "nsIMIMEService.h"
 #include <algorithm>
 
 //-----------------------------------------------------------------------------
 
 class nsFileCopyEvent : public nsRunnable {
@@ -331,17 +333,22 @@ nsFileChannel::OpenContentStream(bool as
   rv = NS_GetFileProtocolHandler(getter_AddRefs(fileHandler));
   if (NS_FAILED(rv))
     return rv;
     
   nsCOMPtr<nsIURI> newURI;
   rv = fileHandler->ReadURLFile(file, getter_AddRefs(newURI));
   if (NS_SUCCEEDED(rv)) {
     nsCOMPtr<nsIChannel> newChannel;
-    rv = NS_NewChannel(getter_AddRefs(newChannel), newURI);
+    rv = NS_NewChannel(getter_AddRefs(newChannel),
+                       newURI,
+                       nsContentUtils::GetSystemPrincipal(),
+                       nsILoadInfo::SEC_NORMAL,
+                       nsIContentPolicy::TYPE_OTHER);
+
     if (NS_FAILED(rv))
       return rv;
 
     *result = nullptr;
     newChannel.forget(channel);
     return NS_OK;
   }
 
--- a/netwerk/test/TestHttp.cpp
+++ b/netwerk/test/TestHttp.cpp
@@ -1,16 +1,19 @@
 #include "nsNetUtil.h"
 #include "nsIEventQueueService.h"
 #include "nsIServiceManager.h"
 #include "nsIComponentRegistrar.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIProgressEventSink.h"
 #include <algorithm>
+#include "nsIContentPolicy.h"
+#include "mozilla/LoadInfo.h"
+#include "nsContentUtils.h"
 
 #define RETURN_IF_FAILED(rv, step) \
     PR_BEGIN_MACRO \
     if (NS_FAILED(rv)) { \
         printf(">>> %s failed: rv=%x\n", step, rv); \
         return rv;\
     } \
     PR_END_MACRO
@@ -157,17 +160,22 @@ int main(int argc, char **argv)
         nsCOMPtr<nsIURI> uri;
         nsCOMPtr<nsIChannel> chan;
         nsCOMPtr<nsIStreamListener> listener = new MyListener();
         nsCOMPtr<nsIInterfaceRequestor> callbacks = new MyNotifications();
 
         rv = NS_NewURI(getter_AddRefs(uri), argv[1]);
         RETURN_IF_FAILED(rv, "NS_NewURI");
 
-        rv = NS_NewChannel(getter_AddRefs(chan), uri, nullptr, nullptr, callbacks);
+        rv = NS_NewChannel(getter_AddRefs(chan),
+                           uri,
+                           nsContentUtils::GetSystemPrincipal(),
+                           nsILoadInfo::SEC_NORMAL,
+                           nsIContentPolicy::TYPE_OTHER);
+
         RETURN_IF_FAILED(rv, "NS_OpenURI");
 
         rv = chan->AsyncOpen(listener, nullptr);
         RETURN_IF_FAILED(rv, "AsyncOpen");
 
         while (gKeepRunning)
             gEventQ->ProcessPendingEvents();
 
--- a/netwerk/test/TestOpen.cpp
+++ b/netwerk/test/TestOpen.cpp
@@ -7,16 +7,17 @@
 #include "nsCOMPtr.h"
 #include "nsStringAPI.h"
 #include "nsIURI.h"
 #include "nsIChannel.h"
 #include "nsIHttpChannel.h"
 #include "nsIInputStream.h"
 #include "nsNetUtil.h"
 #include "mozilla/unused.h"
+#include "nsIScriptSecurityManager.h"
 
 #include <stdio.h>
 
 using namespace mozilla;
 
 /*
  * Test synchronous Open.
  */
@@ -46,17 +47,29 @@ main(int argc, char **argv)
     }
 
     nsCOMPtr<nsIURI> uri;
     nsCOMPtr<nsIInputStream> stream;
 
     rv = NS_NewURI(getter_AddRefs(uri), argv[1]);
     RETURN_IF_FAILED(rv, "NS_NewURI");
 
-    rv = NS_OpenURI(getter_AddRefs(stream), uri);
+    nsCOMPtr<nsIScriptSecurityManager> secman =
+      do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
+    RETURN_IF_FAILED(rv, "Couldn't get script security manager!");
+       nsCOMPtr<nsIPrincipal> systemPrincipal;
+    rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
+    RETURN_IF_FAILED(rv, "Couldn't get system principal!");
+
+    rv = NS_OpenURI(getter_AddRefs(stream),
+                    uri,
+                    systemPrincipal,
+                    nsILoadInfo::SEC_NORMAL,
+                    nsIContentPolicy::TYPE_OTHER);
+
     RETURN_IF_FAILED(rv, "NS_OpenURI");
 
     FILE* outfile = fopen(argv[2], "wb");
     if (!outfile) {
       printf("error opening %s\n", argv[2]);
       return 1;
     }
 
--- a/netwerk/test/TestPageLoad.cpp
+++ b/netwerk/test/TestPageLoad.cpp
@@ -12,16 +12,17 @@
 #include "nsIComponentManager.h"
 #include "prprf.h"
 #include "nsXPCOM.h"
 #include "nsISupportsPrimitives.h"
 #include "plstr.h"
 #include "nsCOMArray.h"
 #include "nsIComponentRegistrar.h"
 #include <algorithm>
+#include "nsIScriptSecurityManager.h"
 
 namespace TestPageLoad {
 
 int getStrLine(const char *src, char *str, int ind, int max);
 nsresult auxLoad(char *uriBuf);
 //----------------------------------------------------------------------
 
 
@@ -293,17 +294,33 @@ nsresult auxLoad(char *uriBuf)
       uri->Equals(uriList[i], &equal);
       if(equal) {
         printf("(duplicate, canceling) %s\n",uriBuf); 
         return NS_OK;
       }
     }
     printf("\n");
     uriList.AppendObject(uri);
-    rv = NS_NewChannel(getter_AddRefs(chan), uri, nullptr, nullptr, callbacks);
+
+    nsCOMPtr<nsIScriptSecurityManager> secman =
+      do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
+    RETURN_IF_FAILED(rv, rv, "Couldn't get script security manager!");
+       nsCOMPtr<nsIPrincipal> systemPrincipal;
+    rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
+    RETURN_IF_FAILED(rv, rv, "Couldn't get system principal!");
+
+    rv = NS_NewChannel(getter_AddRefs(chan),
+                       uri,
+                       systemPrincipal,
+                       nsILoadInfo::SEC_NORMAL,
+                       nsIContentPolicy::TYPE_OTHER,
+                       nullptr,   // aChannelPolicy
+                       nullptr,   // loadGroup
+                       callbacks);
+
     RETURN_IF_FAILED(rv, rv, "NS_NewChannel");
 
     gKeepRunning++;
     rv = chan->AsyncOpen(listener, myBool);
     RETURN_IF_FAILED(rv, rv, "AsyncOpen");
 
     return NS_OK;
 
@@ -337,17 +354,32 @@ int main(int argc, char **argv)
         printf("Loading necko ... \n");
         nsCOMPtr<nsIChannel> chan;
         nsCOMPtr<nsIStreamListener> listener = new MyListener();
         nsCOMPtr<nsIInterfaceRequestor> callbacks = new MyNotifications();
 
         rv = NS_NewURI(getter_AddRefs(baseURI), argv[1]);
         RETURN_IF_FAILED(rv, -1, "NS_NewURI");
 
-        rv = NS_NewChannel(getter_AddRefs(chan), baseURI, nullptr, nullptr, callbacks);
+        nsCOMPtr<nsIScriptSecurityManager> secman =
+          do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
+        RETURN_IF_FAILED(rv, -1, "Couldn't get script security manager!");
+           nsCOMPtr<nsIPrincipal> systemPrincipal;
+        rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
+        RETURN_IF_FAILED(rv, -1, "Couldn't get system principal!");
+
+        rv = NS_NewChannel(getter_AddRefs(chan),
+                           baseURI,
+                           systemPrincipal,
+                           nsILoadInfo::SEC_NORMAL,
+                           nsIContentPolicy::TYPE_OTHER,
+                           nullptr,   // aChannelPolicy
+                           nullptr,   // loadGroup
+                           callbacks);
+
         RETURN_IF_FAILED(rv, -1, "NS_OpenURI");
         gKeepRunning++;
 
         //TIMER STARTED-----------------------
         printf("Starting clock ... \n");
         start = PR_Now();
         rv = chan->AsyncOpen(listener, nullptr);
         RETURN_IF_FAILED(rv, -1, "AsyncOpen");
--- a/netwerk/test/TestPerf.cpp
+++ b/netwerk/test/TestPerf.cpp
@@ -1,32 +1,42 @@
 #include "TestCommon.h"
 #include <stdio.h>
 #include "nsCRT.h" /* should be "plstr.h"? */
 #include "nsNetUtil.h"
 #include "nsIServiceManager.h"
 #include "nsIComponentRegistrar.h"
 #include "nsISupportsArray.h"
+#include "nsContentUtils.h"
 #include <algorithm>
 
 namespace TestPerf {
 
 static nsIIOService *gIOService = nullptr;
 
 //-----------------------------------------------------------------------------
 
 static bool
 load_sync_1(nsISupports *element, void *data)
 {
     nsCOMPtr<nsIInputStream> stream;
     nsCOMPtr<nsIURI> uri( do_QueryInterface(element) );
     nsAutoCString spec;
     nsresult rv;
 
-    rv = NS_OpenURI(getter_AddRefs(stream), uri, gIOService);
+    rv = NS_OpenURI(getter_AddRefs(stream),
+                    uri,
+                    nsContentUtils::GetSystemPrincipal(),
+                    nsILoadInfo::SEC_NORMAL,
+                    nsIContentPolicy::TYPE_OTHER,
+                    nullptr, // aLoadGroup
+                    nullptr, // aCallbacks
+                    LOAD_NORMAL,
+                    gIOService);
+
     if (NS_FAILED(rv)) {
         uri->GetAsciiSpec(spec);
         fprintf(stderr, "*** failed opening %s [rv=%x]\n", spec.get(), rv);
         return true;
     }
 
     char buf[4096];
     uint32_t bytesRead;
@@ -116,17 +126,27 @@ load_async_1(nsISupports *element, void 
     nsCOMPtr<nsIURI> uri( do_QueryInterface(element) );
     if (!uri)
         return true;
 
     MyListener *listener = new MyListener();
     if (!listener)
         return true;
     NS_ADDREF(listener);
-    nsresult rv = NS_OpenURI(listener, nullptr, uri, gIOService);
+
+    nsresult rv = NS_OpenURI(listener,
+                             nullptr,   // aContext
+                             uri,
+                             nsContentUtils::GetSystemPrincipal(),
+                             nsILoadInfo::SEC_NORMAL,
+                             nsIContentPolicy::TYPE_OTHER,
+                             nullptr,   // aLoadGroup
+                             nullptr,   // aCallbacks
+                             gIOService);
+
     NS_RELEASE(listener);
     if (NS_SUCCEEDED(rv))
         gRequestCount++;
     else 
         printf(">> NS_OpenURI failed [rv=%x]\n", rv);
     return true;
 }
 
--- a/netwerk/test/TestProtocols.cpp
+++ b/netwerk/test/TestProtocols.cpp
@@ -47,16 +47,17 @@
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "nsIPropertyBag2.h"
 #include "nsIWritablePropertyBag2.h"
 #include "nsITimedChannel.h"
 #include "nsChannelProperties.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/unused.h"
+#include "nsIScriptSecurityManager.h"
 
 #include "nsISimpleEnumerator.h"
 #include "nsStringAPI.h"
 #include "nsNetUtil.h"
 #include "prlog.h"
 
 using namespace mozilla;
 
@@ -625,20 +626,35 @@ nsresult StartLoadingURL(const char* aUr
 
         NotificationCallbacks* callbacks = new NotificationCallbacks();
         if (!callbacks) {
             LOG(("Failed to create a new consumer!"));
             return NS_ERROR_OUT_OF_MEMORY;;
         }
         NS_ADDREF(callbacks);
 
+        nsCOMPtr<nsIScriptSecurityManager> secman =
+          do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
+        NS_ENSURE_SUCCESS(rv, rv);
+           nsCOMPtr<nsIPrincipal> systemPrincipal;
+        rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
+        NS_ENSURE_SUCCESS(rv, rv);
+
         // Async reading thru the calls of the event sink interface
-        rv = NS_NewChannel(getter_AddRefs(pChannel), pURL, pService,
-                           nullptr,     // loadGroup
-                           callbacks); // notificationCallbacks
+        rv = NS_NewChannel(getter_AddRefs(pChannel),
+                           pURL,
+                           systemPrincipal,
+                           nsILoadInfo::SEC_NORMAL,
+                           nsIContentPolicy::TYPE_OTHER,
+                           nullptr,  // aChannelPolicy
+                           nullptr,  // loadGroup
+                           callbacks,
+                           nsIRequest::LOAD_NORMAL,
+                           pService);
+
         NS_RELEASE(callbacks);
         if (NS_FAILED(rv)) {
             LOG(("ERROR: NS_OpenURI failed for %s [rv=%x]\n", aUrlString, rv));
             return rv;
         }
 
         nsCOMPtr<nsITimedChannel> timed(do_QueryInterface(pChannel));
         if (timed)
--- a/netwerk/test/TestStreamLoader.cpp
+++ b/netwerk/test/TestStreamLoader.cpp
@@ -1,14 +1,15 @@
 #include <stdio.h>
 #include "TestCommon.h"
 #include "nsNetUtil.h"
 #include "nsThreadUtils.h"
 #include "prlog.h"
 #include "mozilla/Attributes.h"
+#include "nsIScriptSecurityManager.h"
 
 #if defined(PR_LOGGING)
 //
 // set NSPR_LOG_MODULES=Test:5
 //
 static PRLogModuleInfo *gTestLog = nullptr;
 #endif
 #define LOG(args) PR_LOG(gTestLog, PR_LOG_DEBUG, args)
@@ -60,18 +61,30 @@ int main(int argc, char **argv)
     return -1;
 
   {
     nsCOMPtr<nsIURI> uri;
     rv = NS_NewURI(getter_AddRefs(uri), nsDependentCString(argv[1]));
     if (NS_FAILED(rv))
       return -1;
 
+    nsCOMPtr<nsIScriptSecurityManager> secman =
+      do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
+    NS_ENSURE_SUCCESS(rv, -1);
+       nsCOMPtr<nsIPrincipal> systemPrincipal;
+    rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
+    NS_ENSURE_SUCCESS(rv, -1);
+
     nsCOMPtr<nsIChannel> chan;
-    rv = NS_NewChannel(getter_AddRefs(chan), uri);
+    rv = NS_NewChannel(getter_AddRefs(chan),
+                       uri,
+                       systemPrincipal,
+                       nsILoadInfo::SEC_NORMAL,
+                       nsIContentPolicy::TYPE_OTHER);
+
     if (NS_FAILED(rv))
       return -1;
 
     nsCOMPtr<nsIStreamLoaderObserver> observer = new MyStreamLoaderObserver();
     if (!observer)
       return -1;
 
     nsCOMPtr<nsIStreamLoader> loader;
--- a/netwerk/test/TestSyncHTTP.cpp
+++ b/netwerk/test/TestSyncHTTP.cpp
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <nsCOMPtr.h>
 #include <nsString.h>
 #include <nsIURI.h>
 #include <nsIChannel.h>
 #include <nsIHTTPChannel.h>
 #include <nsIInputStream.h>
+#include "nsContentUtils.h"
 #include <nsNetUtil.h>
 
 /*
  * Test synchronous HTTP.
  */
 
 #define RETURN_IF_FAILED(rv, what) \
     PR_BEGIN_MACRO \
@@ -51,17 +52,22 @@ main(int argc, char **argv)
     }
 
     c = new TestContext[argc-1];
 
     for (i=0; i<(argc-1); ++i, ++nc) {
         rv = NS_NewURI(getter_AddRefs(c[i].uri), argv[i+1]);
         RETURN_IF_FAILED(rv, "NS_NewURI");
 
-        rv = NS_OpenURI(getter_AddRefs(c[i].channel), c[i].uri, nullptr, nullptr);
+        rv = NS_OpenURI(getter_AddRefs(c[i].channel,
+                        c[i].uri,
+                        nsContentUtils::GetSystemPrincipal(),
+                        nsILoadInfo::SEC_NORMAL,
+                        nsIContentPolicy::TYPE_OTHER);
+
         RETURN_IF_FAILED(rv, "NS_OpenURI");
 
         nsCOMPtr<nsIHTTPChannel> httpChannel = do_QueryInterface(c[i].channel);
         if (httpChannel)
             httpChannel->SetOpenHasEventQueue(false);
 
         // initialize these fields for reading
         c[i].bytesRead = 1;
--- a/netwerk/test/TestThreadedIO.cpp
+++ b/netwerk/test/TestThreadedIO.cpp
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #include <stdio.h>
 #include "nsCOMPtr.h"
 #include "nsIEventQueueService.h"
 #include "nsIServiceManager.h"
 #include "nsIStreamListener.h"
 #include "nsIURI.h"
 #include "nsNetUtil.h"
+#include "nsContentUtils.h"
 #include <algorithm>
 //#include "prthread.h"
 
 // This test attempts to load a URL on a separate thread.  It is currently
 // designed simply to expose the problems inherent in such an ambitous task
 // (i.e., it don't work).
 
 // Utility functions...
@@ -44,17 +45,22 @@ createChannel( const char *url ) {
     printf( "Calling NS_NewURI for %s...\n", url );
     nsresult rv = NS_NewURI( getter_AddRefs( uri ), url );
 
     if ( NS_SUCCEEDED( rv ) ) {
         printf( "...NS_NewURI completed OK\n" );
 
         // Allocate a new input channel on this thread.
         printf( "Calling NS_OpenURI...\n" );
-        nsresult rv = NS_OpenURI( getter_AddRefs( result ), uri, 0 );
+
+        nsresult rv = NS_OpenURI(getter_AddRefs(result),
+                                 uri,
+                                 nsContentUtils::GetSystemPrincipal(),
+                                 nsILoadInfo::SEC_NORMAL,
+                                 nsIContentPolicy::TYPE_OTHER);
 
         if ( NS_SUCCEEDED( rv ) ) {
             printf( "...NS_OpenURI completed OK\n" );
         } else {
             printf( "%s %d: NS_OpenURI failed, rv=0x%08X\n",
                     (char*)__FILE__, (int)__LINE__, (int)rv );
         }
     } else {