Bug 536324 - e10s HTTP: refactor nsHashPropertyBag. Part 3: contentLength consumers. r=jduell, a=beta5+
authorDan Witte <dwitte@mozilla.com>
Sat, 21 Aug 2010 00:31:35 -0700
changeset 51339 3c7ac02b55d3bd0b88346892f60c20153a7a9d15
parent 51338 b69195520ef4558c2f780104b88e9e0ba8eb3efc
child 51340 a87d3efaaedae983024ddd99ff662dda84ff0793
push id15277
push userdwitte@mozilla.com
push dateTue, 24 Aug 2010 04:18:33 +0000
treeherdermozilla-central@49dc8d6901a7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjduell, beta5
bugs536324
milestone2.0b5pre
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 536324 - e10s HTTP: refactor nsHashPropertyBag. Part 3: contentLength consumers. r=jduell, a=beta5+
content/base/src/nsSyncLoadService.cpp
content/media/nsMediaStream.cpp
embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp
extensions/gnomevfs/nsGnomeVFSProtocolHandler.cpp
js/src/xpconnect/loader/mozJSSubScriptLoader.cpp
modules/libpr0n/src/imgRequest.cpp
modules/plugin/base/src/nsPluginStreamListenerPeer.cpp
modules/plugin/base/src/nsPluginStreamListenerPeer.h
netwerk/base/src/nsIncrementalDownload.cpp
netwerk/base/src/nsInputStreamChannel.cpp
netwerk/base/src/nsStreamLoader.cpp
netwerk/protocol/data/nsDataChannel.cpp
netwerk/protocol/file/nsFileChannel.cpp
netwerk/protocol/ftp/nsFtpConnectionThread.cpp
netwerk/streamconv/converters/nsMultiMixedConv.cpp
netwerk/streamconv/converters/nsMultiMixedConv.h
netwerk/test/TestProtocols.cpp
security/manager/ssl/src/nsNSSComponent.cpp
uriloader/exthandler/ExternalHelperAppParent.cpp
uriloader/exthandler/nsExternalHelperAppService.cpp
uriloader/exthandler/nsExternalHelperAppService.h
uriloader/prefetch/nsOfflineCacheUpdate.cpp
uriloader/prefetch/nsOfflineCacheUpdate.h
uriloader/prefetch/nsPrefetchService.cpp
uriloader/prefetch/nsPrefetchService.h
widget/src/windows/nsDataObj.cpp
xpinstall/src/nsXPInstallManager.cpp
xpinstall/src/nsXPInstallManager.h
--- a/content/base/src/nsSyncLoadService.cpp
+++ b/content/base/src/nsSyncLoadService.cpp
@@ -455,22 +455,22 @@ nsresult
 nsSyncLoadService::PushSyncStreamToListener(nsIInputStream* aIn,
                                             nsIStreamListener* aListener,
                                             nsIChannel* aChannel)
 {
     // Set up buffering stream
     nsresult rv;
     nsCOMPtr<nsIInputStream> bufferedStream;
     if (!NS_InputStreamIsBuffered(aIn)) {
-        PRInt32 chunkSize;
+        PRInt64 chunkSize;
         rv = aChannel->GetContentLength(&chunkSize);
         if (NS_FAILED(rv)) {
             chunkSize = 4096;
         }
-        chunkSize = NS_MIN(PRInt32(PR_UINT16_MAX), chunkSize);
+        chunkSize = NS_MIN(PRInt64(PR_UINT16_MAX), chunkSize);
 
         rv = NS_NewBufferedInputStream(getter_AddRefs(bufferedStream), aIn,
                                        chunkSize);
         NS_ENSURE_SUCCESS(rv, rv);
 
         aIn = bufferedStream;
     }
 
--- a/content/media/nsMediaStream.cpp
+++ b/content/media/nsMediaStream.cpp
@@ -235,17 +235,17 @@ nsMediaChannelStream::OnStartRequest(nsI
       // it's getting data for the start of the stream.
       mCacheStream.NotifyDataStarted(0);
       mOffset = 0;
     } else if (mOffset == 0 &&
                (responseStatus == HTTP_OK_CODE ||
                 responseStatus == HTTP_PARTIAL_RESPONSE_CODE)) {
       // We weren't seeking and got a valid response status,
       // set the length of the content.
-      PRInt32 cl = -1;
+      PRInt64 cl = -1;
       hc->GetContentLength(&cl);
       if (cl >= 0) {
         mCacheStream.NotifyDataLength(cl);
       }
     }
     // XXX we probably should examine the Content-Range header in case
     // the server gave us a range which is not quite what we asked for
 
--- a/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp
+++ b/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp
@@ -900,17 +900,17 @@ NS_IMETHODIMP nsWebBrowserPersist::OnDat
             }
             else
             {
                 // Disaster - can't read the bytes - broken link / file error?
                 cancel = PR_TRUE;
             }
         }
 
-        PRInt32 channelContentLength = -1;
+        PRInt64 channelContentLength = -1;
         if (!cancel &&
             NS_SUCCEEDED(channel->GetContentLength(&channelContentLength)))
         {
             // if we get -1 at this point, we didn't get content-length header
             // assume that we got all of the data and push what we have; 
             // that's the best we can do now
             if ((-1 == channelContentLength) ||
                 ((channelContentLength - (aOffset + aLength)) == 0))
--- a/extensions/gnomevfs/nsGnomeVFSProtocolHandler.cpp
+++ b/extensions/gnomevfs/nsGnomeVFSProtocolHandler.cpp
@@ -345,17 +345,17 @@ class nsGnomeVFSInputStream : public nsI
   public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIINPUTSTREAM
 
     nsGnomeVFSInputStream(const nsCString &uriSpec)
       : mSpec(uriSpec)
       , mChannel(nsnull)
       , mHandle(nsnull)
-      , mBytesRemaining(PR_UINT32_MAX)
+      , mBytesRemaining(LL_MAXUINT)
       , mStatus(NS_OK)
       , mDirList(nsnull)
       , mDirListPtr(nsnull)
       , mDirBufCursor(0)
       , mDirOpen(PR_FALSE) {}
 
    ~nsGnomeVFSInputStream() { Close(); }
 
@@ -381,17 +381,17 @@ class nsGnomeVFSInputStream : public nsI
     GnomeVFSResult DoOpen();
     GnomeVFSResult DoRead(char *aBuf, PRUint32 aCount, PRUint32 *aCountRead);
     nsresult       SetContentTypeOfChannel(const char *contentType);
 
   private:
     nsCString                mSpec;
     nsIChannel              *mChannel; // manually refcounted
     GnomeVFSHandle          *mHandle;
-    PRUint32                 mBytesRemaining;
+    PRUint64                 mBytesRemaining;
     nsresult                 mStatus;
     GList                   *mDirList;
     GList                   *mDirListPtr;
     nsCString                mDirBuf;
     PRUint32                 mDirBufCursor;
     PRPackedBool             mDirOpen;
 };
 
@@ -455,22 +455,21 @@ nsGnomeVFSInputStream::DoOpen()
       // type determined by GnomeVFS.  However, if GnomeVFS is telling us that
       // the document is binary, we'll ignore that and keep the channel's
       // content type unspecified.  That will enable our content type sniffing
       // algorithms.  This should provide more consistent mime type handling.
 
       if (info.mime_type && (strcmp(info.mime_type, APPLICATION_OCTET_STREAM) != 0))
         SetContentTypeOfChannel(info.mime_type);
 
-      // XXX truncates size from 64-bit to 32-bit
-      mBytesRemaining = (PRUint32) info.size;
+      mBytesRemaining = info.size;
 
       // Update the content length attribute on the channel.  We do this
       // synchronously without proxying.  This hack is not as bad as it looks!
-      if (mBytesRemaining != PR_UINT32_MAX)
+      if (mBytesRemaining != PRUint64(-1))
         mChannel->SetContentLength(mBytesRemaining);
     }
     else
     {
       mDirOpen = PR_TRUE;
 
       // Sort mDirList
       mDirList = g_list_sort(mDirList, FileInfoComparator);
@@ -504,16 +503,17 @@ nsGnomeVFSInputStream::DoRead(char *aBuf
   GnomeVFSResult rv;
 
   if (mHandle)
   {
     GnomeVFSFileSize bytesRead;
     rv = gnome_vfs_read(mHandle, aBuf, aCount, &bytesRead);
     if (rv == GNOME_VFS_OK)
     {
+      // XXX 64-bit here
       *aCountRead = (PRUint32) bytesRead;
       mBytesRemaining -= *aCountRead;
     }
   }
   else if (mDirOpen)
   {
     rv = GNOME_VFS_OK;
 
@@ -699,16 +699,17 @@ nsGnomeVFSInputStream::Close()
 }
 
 NS_IMETHODIMP
 nsGnomeVFSInputStream::Available(PRUint32 *aResult)
 {
   if (NS_FAILED(mStatus))
     return mStatus;
 
+  // XXX 64-bit here
   *aResult = mBytesRemaining;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsGnomeVFSInputStream::Read(char *aBuf,
                             PRUint32 aCount,
                             PRUint32 *aCountRead)
--- a/js/src/xpconnect/loader/mozJSSubScriptLoader.cpp
+++ b/js/src/xpconnect/loader/mozJSSubScriptLoader.cpp
@@ -211,17 +211,17 @@ mozJSSubScriptLoader::LoadSubScript (con
         if (!target_obj) return NS_ERROR_FAILURE;
 #ifdef DEBUG_rginda
         fprintf (stderr, "Final global: %p\n", target_obj);
 #endif
     }
 
     /* load up the url.  From here on, failures are reflected as ``custom''
      * js exceptions */
-    PRInt32   len = -1;
+    PRInt64   len = -1;
     PRUint32  readcount = 0;  // Total amount of data read
     PRUint32  lastReadCount = 0;  // Amount of data read in last Read() call
     nsAutoArrayPtr<char> buf;
     
     JSString        *errmsg;
     JSErrorReporter  er;
     JSPrincipals    *jsPrincipals;
     
@@ -308,16 +308,19 @@ mozJSSubScriptLoader::LoadSubScript (con
     
     rv = chan->GetContentLength (&len);
     if (NS_FAILED(rv) || len == -1)
     {
         errmsg = JS_NewStringCopyZ (cx, LOAD_ERROR_NOCONTENT);
         goto return_exception;
     }
 
+    if (len > PR_INT32_MAX)
+      return NS_ERROR_OUT_OF_MEMORY;
+
     buf = new char[len + 1];
     if (!buf)
         return NS_ERROR_OUT_OF_MEMORY;
     buf[len] = '\0';
     
     do {
         rv = instream->Read (buf + readcount, len - readcount, &lastReadCount);
         if (NS_FAILED(rv))
--- a/modules/libpr0n/src/imgRequest.cpp
+++ b/modules/libpr0n/src/imgRequest.cpp
@@ -1036,26 +1036,23 @@ NS_IMETHODIMP imgRequest::OnDataAvailabl
 
       this->Cancel(rv);
       return NS_BINDING_ABORTED;
     }
 
     if (imageType == imgIContainer::TYPE_RASTER) {
       /* Use content-length as a size hint for http channels. */
       if (httpChannel) {
-        nsCAutoString contentLength;
-        rv = httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("content-length"),
-                                            contentLength);
+        PRInt64 contentLength;
+        rv = httpChannel->GetContentLength(&contentLength);
         if (NS_SUCCEEDED(rv)) {
-          PRInt32 len = contentLength.ToInteger(&rv);
-
           // Pass anything usable on so that the RasterImage can preallocate
           // its source buffer
-          if (len > 0) {
-            PRUint32 sizeHint = (PRUint32) len;
+          if (contentLength > 0) {
+            PRUint32 sizeHint = (PRUint32) contentLength;
             sizeHint = PR_MIN(sizeHint, 20000000); /* Bound by something reasonable */
             RasterImage* rasterImage = static_cast<RasterImage*>(mImage.get());
             rasterImage->SetSourceSizeHint(sizeHint);
           }
         }
       }
     }
 
--- a/modules/plugin/base/src/nsPluginStreamListenerPeer.cpp
+++ b/modules/plugin/base/src/nsPluginStreamListenerPeer.cpp
@@ -514,17 +514,17 @@ nsPluginStreamListenerPeer::OnStartReque
   if (callbacks)
     mWeakPtrChannelCallbacks = do_GetWeakReference(callbacks);
   
   nsCOMPtr<nsILoadGroup> loadGroup;
   channel->GetLoadGroup(getter_AddRefs(loadGroup));
   if (loadGroup)
     mWeakPtrChannelLoadGroup = do_GetWeakReference(loadGroup);
   
-  PRInt32 length;
+  PRInt64 length;
   rv = channel->GetContentLength(&length);
   
   // it's possible for the server to not send a Content-Length.
   // we should still work in this case.
   if (NS_FAILED(rv) || length == -1) {
     // check out if this is file channel
     nsCOMPtr<nsIFileChannel> fileChannel = do_QueryInterface(channel);
     if (fileChannel) {
--- a/modules/plugin/base/src/nsPluginStreamListenerPeer.h
+++ b/modules/plugin/base/src/nsPluginStreamListenerPeer.h
@@ -131,17 +131,17 @@ private:
    * Set to PR_TRUE after nsIPluginStreamListener::OnStartBinding() has
    * been called.  Checked in ::OnStopRequest so we can call the
    * plugin's OnStartBinding if, for some reason, it has not already
    * been called.
    */
   PRPackedBool      mStartBinding;
   PRPackedBool      mHaveFiredOnStartRequest;
   // these get passed to the plugin stream listener
-  PRUint32                mLength;
+  PRUint64                mLength;
   PRInt32                 mStreamType;
   
   // local cached file, we save the content into local cache if browser cache is not available,
   // or plugin asks stream as file and it expects file extension until bug 90558 got fixed
   nsRefPtr<CachedFileHolder> mLocalCachedFileHolder;
   nsCOMPtr<nsIOutputStream> mFileCacheOutputStream;
   nsHashtable             *mDataForwardToRequest;
   
--- a/netwerk/base/src/nsIncrementalDownload.cpp
+++ b/netwerk/base/src/nsIncrementalDownload.cpp
@@ -43,17 +43,16 @@
 #include "nsIAsyncVerifyRedirectCallback.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIObserverService.h"
 #include "nsIObserver.h"
 #include "nsIPropertyBag2.h"
 #include "nsIServiceManager.h"
 #include "nsILocalFile.h"
 #include "nsITimer.h"
-#include "nsInt64.h"
 #include "nsNetUtil.h"
 #include "nsAutoPtr.h"
 #include "nsWeakReference.h"
 #include "nsChannelProperties.h"
 #include "prio.h"
 #include "prprf.h"
 
 // Error code used internally by the incremental downloader to cancel the
@@ -96,32 +95,32 @@ static nsresult
 AppendToFile(nsILocalFile *lf, const char *data, PRUint32 len)
 {
   PRInt32 flags = PR_WRONLY | PR_CREATE_FILE | PR_APPEND;
   return WriteToFile(lf, data, len, flags);
 }
 
 // maxSize may be -1 if unknown
 static void
-MakeRangeSpec(const nsInt64 &size, const nsInt64 &maxSize, PRInt32 chunkSize,
+MakeRangeSpec(PRInt64 size, PRInt64 maxSize, PRInt32 chunkSize,
               PRBool fetchRemaining, nsCString &rangeSpec)
 {
   rangeSpec.AssignLiteral("bytes=");
-  rangeSpec.AppendInt(PRInt64(size));
+  rangeSpec.AppendInt(size);
   rangeSpec.Append('-');
 
   if (fetchRemaining)
     return;
 
-  nsInt64 end = size + nsInt64(chunkSize);
-  if (maxSize != nsInt64(-1) && end > maxSize)
+  PRInt64 end = size + chunkSize;
+  if (maxSize != -1 && end > maxSize)
     end = maxSize;
   end -= 1;
 
-  rangeSpec.AppendInt(PRInt64(end));
+  rangeSpec.AppendInt(end);
 }
 
 //-----------------------------------------------------------------------------
 
 class nsIncrementalDownload : public nsIIncrementalDownload
                             , public nsIStreamListener
                             , public nsIObserver
                             , public nsIInterfaceRequestor
@@ -160,18 +159,18 @@ private:
   nsCOMPtr<nsIURI>                         mFinalURI;
   nsCOMPtr<nsILocalFile>                   mDest;
   nsCOMPtr<nsIChannel>                     mChannel;
   nsCOMPtr<nsITimer>                       mTimer;
   nsAutoArrayPtr<char>                     mChunk;
   PRInt32                                  mChunkLen;
   PRInt32                                  mChunkSize;
   PRInt32                                  mInterval;
-  nsInt64                                  mTotalSize;
-  nsInt64                                  mCurrentSize;
+  PRInt64                                  mTotalSize;
+  PRInt64                                  mCurrentSize;
   PRUint32                                 mLoadFlags;
   PRInt32                                  mNonPartialCount;
   nsresult                                 mStatus;
   PRPackedBool                             mIsPending;
   PRPackedBool                             mDidOnStartRequest;
   PRTime                                   mLastProgressUpdate;
   nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;
   nsCOMPtr<nsIChannel>                     mNewRedirectChannel;
@@ -192,40 +191,40 @@ nsIncrementalDownload::nsIncrementalDown
   , mRedirectCallback(nsnull)
   , mNewRedirectChannel(nsnull)
 {
 }
 
 nsresult
 nsIncrementalDownload::FlushChunk()
 {
-  NS_ASSERTION(mTotalSize != nsInt64(-1), "total size should be known");
+  NS_ASSERTION(mTotalSize != -1, "total size should be known");
 
   if (mChunkLen == 0)
     return NS_OK;
 
   nsresult rv = AppendToFile(mDest, mChunk, mChunkLen);
   if (NS_FAILED(rv))
     return rv;
 
-  mCurrentSize += nsInt64(mChunkLen);
+  mCurrentSize += mChunkLen;
   mChunkLen = 0;
 
   return NS_OK;
 }
 
 void
 nsIncrementalDownload::UpdateProgress()
 {
   mLastProgressUpdate = PR_Now();
 
   if (mProgressSink)
     mProgressSink->OnProgress(this, mObserverContext,
-                              PRUint64(PRInt64(mCurrentSize) + mChunkLen),
-                              PRUint64(PRInt64(mTotalSize)));
+                              mCurrentSize + mChunkLen,
+                              mTotalSize);
 }
 
 nsresult
 nsIncrementalDownload::CallOnStartRequest()
 {
   if (!mObserver || mDidOnStartRequest)
     return NS_OK;
 
@@ -280,26 +279,26 @@ nsIncrementalDownload::ProcessTimeout()
                               nsnull, this, mLoadFlags);
   if (NS_FAILED(rv))
     return rv;
 
   nsCOMPtr<nsIHttpChannel> http = do_QueryInterface(channel, &rv);
   if (NS_FAILED(rv))
     return rv;
 
-  NS_ASSERTION(mCurrentSize != nsInt64(-1),
+  NS_ASSERTION(mCurrentSize != -1,
       "we should know the current file size by now");
 
   rv = ClearRequestHeader(http);
   if (NS_FAILED(rv))
     return rv;
 
   // Don't bother making a range request if we are just going to fetch the
   // entire document.
-  if (mInterval || mCurrentSize != nsInt64(0)) {
+  if (mInterval || mCurrentSize != 0) {
     nsCAutoString range;
     MakeRangeSpec(mCurrentSize, mTotalSize, mChunkSize, mInterval == 0, range);
 
     rv = http->SetRequestHeader(NS_LITERAL_CSTRING("Range"), range, PR_FALSE);
     if (NS_FAILED(rv))
       return rv;
   }
 
@@ -314,18 +313,18 @@ nsIncrementalDownload::ProcessTimeout()
   mChannel = channel;
   return NS_OK;
 }
 
 // Reads the current file size and validates it.
 nsresult
 nsIncrementalDownload::ReadCurrentSize()
 {
-  nsInt64 size;
-  nsresult rv = mDest->GetFileSize((PRInt64 *) &size);
+  PRInt64 size;
+  nsresult rv = mDest->GetFileSize(&size);
   if (rv == NS_ERROR_FILE_NOT_FOUND ||
       rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) {
     mCurrentSize = 0;
     return NS_OK;
   }
   if (NS_FAILED(rv))
     return rv;
 
@@ -548,17 +547,17 @@ nsIncrementalDownload::OnStartRequest(ns
   PRUint32 code;
   rv = http->GetResponseStatus(&code);
   if (NS_FAILED(rv))
     return rv;
   if (code != 206) {
     // We may already have the entire file downloaded, in which case
     // our request for a range beyond the end of the file would have
     // been met with an error response code.
-    if (code == 416 && mTotalSize == nsInt64(-1)) {
+    if (code == 416 && mTotalSize == -1) {
       mTotalSize = mCurrentSize;
       // Return an error code here to suppress OnDataAvailable.
       return NS_ERROR_DOWNLOAD_COMPLETE;
     }
     // The server may have decided to give us all of the data in one chunk.  If
     // we requested a partial range, then we don't want to download all of the
     // data at once.  So, we'll just try again, but if this keeps happening then
     // we'll eventually give up.
@@ -582,17 +581,17 @@ nsIncrementalDownload::OnStartRequest(ns
     }
   } else {
     // We got a partial response, so clear this counter in case the next chunk
     // results in a 200 response.
     mNonPartialCount = 0;
   }
 
   // Do special processing after the first response.
-  if (mTotalSize == nsInt64(-1)) {
+  if (mTotalSize == -1) {
     // Update knowledge of mFinalURI
     rv = http->GetURI(getter_AddRefs(mFinalURI));
     if (NS_FAILED(rv))
       return rv;
 
     if (code == 206) {
       // OK, read the Content-Range header to determine the total size of this
       // download file.
@@ -600,51 +599,45 @@ nsIncrementalDownload::OnStartRequest(ns
       rv = http->GetResponseHeader(NS_LITERAL_CSTRING("Content-Range"), buf);
       if (NS_FAILED(rv))
         return rv;
       PRInt32 slash = buf.FindChar('/');
       if (slash == kNotFound) {
         NS_WARNING("server returned invalid Content-Range header!");
         return NS_ERROR_UNEXPECTED;
       }
-      if (PR_sscanf(buf.get() + slash + 1, "%lld", (PRInt64 *) &mTotalSize) != 1)
+      if (PR_sscanf(buf.get() + slash + 1, "%lld", &mTotalSize) != 1)
         return NS_ERROR_UNEXPECTED;
     } else {
-      // Use nsIPropertyBag2 to fetch the content length as it exposes the
-      // value as a 64-bit number.
-      nsCOMPtr<nsIPropertyBag2> props = do_QueryInterface(request, &rv);
-      if (NS_FAILED(rv))
-        return rv;
-      rv = props->GetPropertyAsInt64(NS_CHANNEL_PROP_CONTENT_LENGTH,
-                                     &mTotalSize.mValue);
+      http->GetContentLength(&mTotalSize);
       // We need to know the total size of the thing we're trying to download.
-      if (mTotalSize == nsInt64(-1)) {
+      if (mTotalSize == -1) {
         NS_WARNING("server returned no content-length header!");
         return NS_ERROR_UNEXPECTED;
       }
       // Need to truncate (or create, if it doesn't exist) the file since we
       // are downloading the whole thing.
       WriteToFile(mDest, nsnull, 0, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE);
       mCurrentSize = 0;
     }
 
     // Notify observer that we are starting...
     rv = CallOnStartRequest();
     if (NS_FAILED(rv))
       return rv;
   }
 
   // Adjust mChunkSize accordingly if mCurrentSize is close to mTotalSize.
-  nsInt64 diff = mTotalSize - mCurrentSize;
-  if (diff <= nsInt64(0)) {
+  PRInt64 diff = mTotalSize - mCurrentSize;
+  if (diff <= 0) {
     NS_WARNING("about to set a bogus chunk size; giving up");
     return NS_ERROR_UNEXPECTED;
   }
 
-  if (diff < nsInt64(mChunkSize))
+  if (diff < mChunkSize)
     mChunkSize = PRUint32(diff);
 
   mChunk = new char[mChunkSize];
   if (!mChunk)
     rv = NS_ERROR_OUT_OF_MEMORY;
 
   return rv;
 }
--- a/netwerk/base/src/nsInputStreamChannel.cpp
+++ b/netwerk/base/src/nsInputStreamChannel.cpp
@@ -44,27 +44,26 @@ nsresult
 nsInputStreamChannel::OpenContentStream(PRBool async, nsIInputStream **result,
                                         nsIChannel** channel)
 {
   NS_ENSURE_TRUE(mContentStream, NS_ERROR_NOT_INITIALIZED);
 
   // If content length is unknown, then we must guess.  In this case, we assume
   // the stream can tell us.  If the stream is a pipe, then this will not work.
 
-  PRInt64 len = ContentLength64();
-  if (len < 0) {
+  if (ContentLength() < 0) {
     PRUint32 avail;
     nsresult rv = mContentStream->Available(&avail);
     if (rv == NS_BASE_STREAM_CLOSED) {
       // This just means there's nothing in the stream
       avail = 0;
     } else if (NS_FAILED(rv)) {
       return rv;
     }
-    SetContentLength64(avail);
+    ContentLength() = avail;
   }
 
   EnableSynthesizedProgressEvents(PR_TRUE);
   
   NS_ADDREF(*result = mContentStream);
   return NS_OK;
 }
 
--- a/netwerk/base/src/nsStreamLoader.cpp
+++ b/netwerk/base/src/nsStreamLoader.cpp
@@ -94,19 +94,25 @@ nsStreamLoader::GetRequest(nsIRequest **
   return NS_OK;
 }
 
 NS_IMETHODIMP 
 nsStreamLoader::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
 {
   nsCOMPtr<nsIChannel> chan( do_QueryInterface(request) );
   if (chan) {
-    PRInt32 contentLength = -1;
+    PRInt64 contentLength = -1;
     chan->GetContentLength(&contentLength);
     if (contentLength >= 0) {
+      if (contentLength > PR_UINT32_MAX) {
+        // too big to fit in a PRUint32, bail now.
+        // XXX make mAllocated and mLength 64-bit
+        return NS_ERROR_OUT_OF_MEMORY;
+      }
+
       // preallocate buffer
       mData = static_cast<PRUint8*>(NS_Alloc(contentLength));
       if (!mData) {
         return NS_ERROR_OUT_OF_MEMORY;
       }
       mAllocated = contentLength;
     }
   }
--- a/netwerk/protocol/data/nsDataChannel.cpp
+++ b/netwerk/protocol/data/nsDataChannel.cpp
@@ -116,14 +116,14 @@ nsDataChannel::OpenContentStream(PRBool 
     } else {
         rv = bufOutStream->Write(dataBuffer.get(), dataBuffer.Length(), &contentLen);
     }
     if (NS_FAILED(rv))
         return rv;
 
     SetContentType(contentType);
     SetContentCharset(contentCharset);
-    SetContentLength64(contentLen);
+    ContentLength() = contentLen;
 
     NS_ADDREF(*result = bufInStream);
 
     return NS_OK;
 }
--- a/netwerk/protocol/file/nsFileChannel.cpp
+++ b/netwerk/protocol/file/nsFileChannel.cpp
@@ -352,39 +352,39 @@ nsFileChannel::OpenContentStream(PRBool 
         new nsFileUploadContentStream(async, fileStream, mUploadStream,
                                       mUploadLength, this);
     if (!uploadStream || !uploadStream->IsInitialized()) {
       delete uploadStream;
       return NS_ERROR_OUT_OF_MEMORY;
     }
     stream = uploadStream;
 
-    SetContentLength64(0);
+    ContentLength() = 0;
 
     // Since there isn't any content to speak of we just set the content-type
     // to something other than "unknown" to avoid triggering the content-type
     // sniffer code in nsBaseChannel.
     // However, don't override explicitly set types.
     if (!HasContentTypeHint())
       SetContentType(NS_LITERAL_CSTRING(APPLICATION_OCTET_STREAM));
   } else {
     nsCAutoString contentType;
     nsresult rv = MakeFileInputStream(file, stream, contentType);
     if (NS_FAILED(rv))
       return rv;
 
     EnableSynthesizedProgressEvents(PR_TRUE);
 
     // fixup content length and type
-    if (ContentLength64() < 0) {
+    if (ContentLength() < 0) {
       PRInt64 size;
       rv = file->GetFileSize(&size);
       if (NS_FAILED(rv))
         return rv;
-      SetContentLength64(size);
+      ContentLength() = size;
     }
     if (!contentType.IsEmpty())
       SetContentType(contentType);
   }
 
   *result = nsnull;
   stream.swap(*result);
   return NS_OK;
--- a/netwerk/protocol/ftp/nsFtpConnectionThread.cpp
+++ b/netwerk/protocol/ftp/nsFtpConnectionThread.cpp
@@ -1002,17 +1002,17 @@ nsFtpState::S_size() {
 
     return SendFTPCommand(sizeBuf);
 }
 
 FTP_STATE
 nsFtpState::R_size() {
     if (mResponseCode/100 == 2) {
         PR_sscanf(mResponseMsg.get() + 4, "%llu", &mFileSize);
-        mChannel->SetContentLength64(mFileSize);
+        mChannel->ContentLength() = mFileSize;
     }
 
     // We may want to be able to resume this
     return FTP_S_MDTM;
 }
 
 nsresult
 nsFtpState::S_mdtm() {
--- a/netwerk/streamconv/converters/nsMultiMixedConv.cpp
+++ b/netwerk/streamconv/converters/nsMultiMixedConv.cpp
@@ -43,16 +43,17 @@
 #include "nsNetUtil.h"
 #include "nsMimeTypes.h"
 #include "nsIStringStream.h"
 #include "nsReadableUtils.h"
 #include "nsCRT.h"
 #include "nsIHttpChannelInternal.h"
 #include "nsURLHelper.h"
 #include "nsIStreamConverterService.h"
+#include "prprf.h"
 
 //
 // Helper function for determining the length of data bytes up to
 // the next multipart token.  A token is usually preceded by a LF
 // or CRLF delimiter.
 // 
 static PRUint32
 LengthToToken(const char *cursor, const char *token)
--- a/netwerk/streamconv/converters/nsMultiMixedConv.h
+++ b/netwerk/streamconv/converters/nsMultiMixedConv.h
@@ -38,17 +38,16 @@
 #define __nsmultimixedconv__h__
 
 #include "nsIStreamConverter.h"
 #include "nsIChannel.h"
 #include "nsIURI.h"
 #include "nsString.h"
 #include "nsXPIDLString.h"
 #include "nsCOMPtr.h"
-#include "nsInt64.h"
 #include "nsIByteRangeRequest.h"
 #include "nsIMultiPartChannel.h"
 #include "nsAutoPtr.h"
 
 #define NS_MULTIMIXEDCONVERTER_CID                         \
 { /* 7584CE90-5B25-11d3-A175-0050041CAF44 */         \
     0x7584ce90,                                      \
     0x5b25,                                          \
@@ -97,18 +96,18 @@ protected:
   nsCOMPtr<nsILoadGroup>  mLoadGroup;
 
   nsCString               mContentType;
   nsCString               mContentCharset;
   nsCString               mContentDisposition;
   PRUint64                mContentLength;
 
   PRBool                  mIsByteRangeRequest;
-  nsInt64                 mByteRangeStart;
-  nsInt64                 mByteRangeEnd;
+  PRInt64                 mByteRangeStart;
+  PRInt64                 mByteRangeEnd;
 
   PRUint32                mPartID; // unique ID that can be used to identify
                                    // this part of the multipart document
   PRBool                  mIsLastPart;
 };
 
 // The nsMultiMixedConv stream converter converts a stream of type "multipart/x-mixed-replace"
 // to it's subparts. There was some debate as to whether or not the functionality desired
@@ -185,16 +184,16 @@ protected:
     char                *mBuffer;
     PRUint32            mBufLen;
     PRUint64            mTotalSent;
     PRBool              mFirstOnData;   // used to determine if we're in our first OnData callback.
 
     // The following members are for tracking the byte ranges in
     // multipart/mixed content which specified the 'Content-Range:'
     // header...
-    nsInt64             mByteRangeStart;
-    nsInt64             mByteRangeEnd;
+    PRInt64             mByteRangeStart;
+    PRInt64             mByteRangeEnd;
     PRBool              mIsByteRangeRequest;
 
     PRUint32            mCurrentPartID;
 };
 
 #endif /* __nsmultimixedconv__h__ */
--- a/netwerk/test/TestProtocols.cpp
+++ b/netwerk/test/TestProtocols.cpp
@@ -394,19 +394,19 @@ InputTestConsumer::OnStartRequest(nsIReq
       LOG(("\tName: %s\n", value.get()));
 
       channel->GetContentType(value);
       LOG(("\tContent-Type: %s\n", value.get()));
 
       channel->GetContentCharset(value);
       LOG(("\tContent-Charset: %s\n", value.get()));
 
-      PRInt32 length = -1;
+      PRInt64 length = -1;
       if (NS_SUCCEEDED(channel->GetContentLength(&length)))
-        LOG(("\tContent-Length: %d\n", length));
+        LOG(("\tContent-Length: %lld\n", length));
       else
         LOG(("\tContent-Length: Unknown\n"));
     }
 
     nsCOMPtr<nsISupports> owner;
     channel->GetOwner(getter_AddRefs(owner));
     LOG(("\tChannel Owner: %x\n", owner.get()));
   }
@@ -419,25 +419,16 @@ InputTestConsumer::OnStartRequest(nsIReq
                                     getter_AddRefs(foo));
       if (foo) {
           nsCAutoString spec;
           foo->GetSpec(spec);
           LOG(("\ttest.foo: %s\n", spec.get()));
       }
   }
 
-  nsCOMPtr<nsIPropertyBag2> propbag = do_QueryInterface(request);
-  if (propbag) {
-      PRInt64 len;
-      nsresult rv = propbag->GetPropertyAsInt64(NS_CHANNEL_PROP_CONTENT_LENGTH,
-                                                &len);
-      if (NS_SUCCEEDED(rv))
-          LOG(("\t64-bit length: %lli\n", len));
-  }
-
   nsCOMPtr<nsIHttpChannelInternal> httpChannelInt(do_QueryInterface(request));
   if (httpChannelInt) {
       PRUint32 majorVer, minorVer;
       nsresult rv = httpChannelInt->GetResponseVersion(&majorVer, &minorVer);
       if (NS_SUCCEEDED(rv))
           LOG(("HTTP Response version: %u.%u\n", majorVer, minorVer));
   }
   nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(request));
--- a/security/manager/ssl/src/nsNSSComponent.cpp
+++ b/security/manager/ssl/src/nsNSSComponent.cpp
@@ -3146,34 +3146,37 @@ PSMContentDownloader::PSMContentDownload
 PSMContentDownloader::~PSMContentDownloader()
 {
   if (mByteData)
     nsMemory::Free(mByteData);
 }
 
 NS_IMPL_ISUPPORTS2(PSMContentDownloader, nsIStreamListener, nsIRequestObserver)
 
-const PRInt32 kDefaultCertAllocLength = 2048;
+const PRInt64 kDefaultCertAllocLength = 2048;
 
 NS_IMETHODIMP
 PSMContentDownloader::OnStartRequest(nsIRequest* request, nsISupports* context)
 {
   nsresult rv;
   PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("CertDownloader::OnStartRequest\n"));
   nsCOMPtr<nsIChannel> channel(do_QueryInterface(request));
   if (!channel) return NS_ERROR_FAILURE;
 
   // Get the URI //
   channel->GetURI(getter_AddRefs(mURI));
 
-  PRInt32 contentLength;
+  PRInt64 contentLength;
   rv = channel->GetContentLength(&contentLength);
   if (NS_FAILED(rv) || contentLength <= 0)
     contentLength = kDefaultCertAllocLength;
   
+  if (contentLength > PR_INT32_MAX)
+    return NS_ERROR_OUT_OF_MEMORY;
+
   mBufferOffset = 0;
   mBufferSize = 0;
   mByteData = (char*) nsMemory::Alloc(contentLength);
   if (!mByteData)
     return NS_ERROR_OUT_OF_MEMORY;
   
   mBufferSize = contentLength;
   return NS_OK;
--- a/uriloader/exthandler/ExternalHelperAppParent.cpp
+++ b/uriloader/exthandler/ExternalHelperAppParent.cpp
@@ -77,17 +77,16 @@ ExternalHelperAppParent::Init(TabParent 
   nsCOMPtr<nsIContent> frame = do_QueryInterface(parent->GetOwnerElement());
   nsCOMPtr<nsISupports> container = frame->GetOwnerDoc()->GetContainer();
   nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryInterface(container);
 
   nsCOMPtr<nsIExternalHelperAppService> helperAppService =
     do_GetService(NS_EXTERNALHELPERAPPSERVICE_CONTRACTID);
   NS_ASSERTION(helperAppService, "No Helper App Service!");
 
-  SetPropertyAsInt64(NS_CHANNEL_PROP_CONTENT_LENGTH, mContentLength);
   helperAppService->DoContent(aMimeContentType, this, ir,
                               aForceSave, getter_AddRefs(mListener));
 }
 
 bool
 ExternalHelperAppParent::RecvOnStartRequest()
 {
   mPending = PR_TRUE;
@@ -291,26 +290,23 @@ ExternalHelperAppParent::GetContentChars
 
 NS_IMETHODIMP
 ExternalHelperAppParent::SetContentCharset(const nsACString& aContentCharset)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
-ExternalHelperAppParent::GetContentLength(PRInt32 *aContentLength)
+ExternalHelperAppParent::GetContentLength(PRInt64 *aContentLength)
 {
-  if (mContentLength > PR_INT32_MAX || mContentLength < 0)
-    *aContentLength = -1;
-  else
-    *aContentLength = (PRInt32)mContentLength;
+  *aContentLength = mContentLength;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-ExternalHelperAppParent::SetContentLength(PRInt32 aContentLength)
+ExternalHelperAppParent::SetContentLength(PRInt64 aContentLength)
 {
   mContentLength = aContentLength;
   return NS_OK;
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/uriloader/exthandler/nsExternalHelperAppService.cpp
+++ b/uriloader/exthandler/nsExternalHelperAppService.cpp
@@ -622,36 +622,16 @@ nsresult nsExternalHelperAppService::Ini
   return obs->AddObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC, PR_TRUE);
 }
 
 nsExternalHelperAppService::~nsExternalHelperAppService()
 {
   gExtProtSvc = nsnull;
 }
 
-static PRInt64 GetContentLengthAsInt64(nsIRequest *request)
-{
-  PRInt64 contentLength = -1;
-  nsresult rv;
-  nsCOMPtr<nsIPropertyBag2> props(do_QueryInterface(request, &rv));
-  if (props)
-    rv = props->GetPropertyAsInt64(NS_CHANNEL_PROP_CONTENT_LENGTH, &contentLength);
-
-  if (NS_FAILED(rv)) {
-    nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
-    if (channel) {
-      PRInt32 smallLen;
-      channel->GetContentLength(&smallLen);
-      contentLength = smallLen;
-    }
-  }
-
-  return contentLength;
-}
-
 NS_IMETHODIMP nsExternalHelperAppService::DoContent(const nsACString& aMimeContentType,
                                                     nsIRequest *aRequest,
                                                     nsIInterfaceRequestor *aWindowContext,
                                                     PRBool aForceSave,
                                                     nsIStreamListener ** aStreamListener)
 {
   nsAutoString fileName;
   nsCAutoString fileExtension;
@@ -660,33 +640,36 @@ NS_IMETHODIMP nsExternalHelperAppService
 
   // Get the file extension and name that we will need later
   nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
   nsCOMPtr<nsIURI> uri;
   if (channel)
     channel->GetURI(getter_AddRefs(uri));
 
 #ifdef MOZ_IPC
-  PRInt64 contentLength = GetContentLengthAsInt64(aRequest);
   if (XRE_GetProcessType() == GeckoProcessType_Content) {
     // We need to get a hold of a TabChild so that we can begin forwarding
     // this data to the parent.  In the HTTP case, this is unfortunate, since
     // we're actually passing data from parent->child->parent wastefully, but
     // the Right Fix will eventually be to short-circuit those channels on the
     // parent side based on some sort of subscription concept.
     nsCOMPtr<nsIDocShell> docshell(do_GetInterface(aWindowContext));
     nsCOMPtr<nsIDocShellTreeItem> item = do_QueryInterface(docshell);
     nsCOMPtr<nsIDocShellTreeOwner> owner;
     item->GetTreeOwner(getter_AddRefs(owner));
     NS_ENSURE_TRUE(owner, NS_ERROR_FAILURE);
 
     nsCOMPtr<nsITabChild> tabchild = do_GetInterface(owner);
     if (!tabchild)
       return NS_ERROR_FAILURE;
 
+    PRInt64 contentLength = -1;
+    if (channel)
+      channel->GetContentLength(&contentLength);
+
     // Now we build a protocol for forwarding our data to the parent.  The
     // protocol will act as a listener on the child-side and create a "real"
     // helperAppService listener on the parent-side, via another call to
     // DoContent.
     using mozilla::dom::TabChild;
     using mozilla::dom::ExternalHelperAppChild;
     TabChild *child = static_cast<TabChild*>(tabchild.get());
     mozilla::dom::PExternalHelperAppChild *pc;
@@ -1396,17 +1379,17 @@ void nsExternalAppHandler::EnsureSuggest
     if (fileExt.Equals(mTempFileExtension, nsCaseInsensitiveStringComparator()))
     {
       // Matches -> mTempFileExtension can be empty
       mTempFileExtension.Truncate();
     }
   }
 }
 
-nsresult nsExternalAppHandler::SetUpTempFile(nsIChannel * aChannel)
+nsresult nsExternalAppHandler::SetUpTempFile()
 {
   // First we need to try to get the destination directory for the temporary
   // file.
   nsresult rv = GetDownloadDirectory(getter_AddRefs(mTempFile));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // At this point, we do not have a filename for the temp file.  For security
   // purposes, this cannot be predictable, so we must use a cryptographic
@@ -1533,35 +1516,34 @@ NS_IMETHODIMP nsExternalAppHandler::OnSt
 
   nsCOMPtr<nsIChannel> aChannel = do_QueryInterface(request);
   
   nsresult rv;
   
   nsCOMPtr<nsIFileChannel> fileChan(do_QueryInterface(request));
   mIsFileChannel = fileChan != nsnull;
 
-  // Get content length
-  mContentLength.mValue = GetContentLengthAsInt64(request);
-
   nsCOMPtr<nsIPropertyBag2> props(do_QueryInterface(request, &rv));
   // Determine whether a new window was opened specifically for this request
   if (props) {
     PRBool tmp = PR_FALSE;
     props->GetPropertyAsBool(NS_LITERAL_STRING("docshell.newWindowTarget"),
                              &tmp);
     mShouldCloseWindow = tmp;
   }
 
-  // Now get the URI
+  // Get content length and URI
+  mContentLength = -1;
   if (aChannel)
   {
     aChannel->GetURI(getter_AddRefs(mSourceUrl));
+    aChannel->GetContentLength(&mContentLength);
   }
 
-  rv = SetUpTempFile(aChannel);
+  rv = SetUpTempFile();
   if (NS_FAILED(rv)) {
     mCanceled = PR_TRUE;
     request->Cancel(rv);
     nsAutoString path;
     if (mTempFile)
       mTempFile->GetPath(path);
     SendStatusChange(kWriteError, rv, request, path);
     return NS_OK;
--- a/uriloader/exthandler/nsExternalHelperAppService.h
+++ b/uriloader/exthandler/nsExternalHelperAppService.h
@@ -44,18 +44,16 @@
 #define nsExternalHelperAppService_h__
 
 #ifdef MOZ_LOGGING
 #define FORCE_PR_LOG
 #endif
 #include "prlog.h"
 #include "prtime.h"
 
-#include "nsInt64.h"
-
 #include "nsIExternalHelperAppService.h"
 #include "nsIExternalProtocolService.h"
 #include "nsIWebProgressListener2.h"
 #include "nsIHelperAppLauncherDialog.h"
 
 #include "nsIMIMEInfo.h"
 #include "nsMIMEInfoImpl.h"
 #include "nsIMIMEService.h"
@@ -337,34 +335,34 @@ protected:
   PRUint32 mReason;
 
   /**
    * Track the executable-ness of the temporary file.
    */
   PRBool mTempFileIsExecutable;
 
   PRTime mTimeDownloadStarted;
-  nsInt64 mContentLength;
-  nsInt64 mProgress; /**< Number of bytes received (for sending progress notifications). */
+  PRInt64 mContentLength;
+  PRInt64 mProgress; /**< Number of bytes received (for sending progress notifications). */
 
   /**
    * When we are told to save the temp file to disk (in a more permament
    * location) before we are done writing the content to a temp file, then
    * we need to remember the final destination until we are ready to use it.
    */
   nsCOMPtr<nsIFile> mFinalFileDestination;
 
   PRUint32 mBufferSize;
   char    *mDataBuffer;
 
   /**
    * Creates the temporary file for the download and an output stream for it.
    * Upon successful return, both mTempFile and mOutStream will be valid.
    */
-  nsresult SetUpTempFile(nsIChannel * aChannel);
+  nsresult SetUpTempFile();
   /**
    * When we download a helper app, we are going to retarget all load
    * notifications into our own docloader and load group instead of
    * using the window which initiated the load....RetargetLoadNotifications
    * contains that information...
    */
   void RetargetLoadNotifications(nsIRequest *request); 
   /**
--- a/uriloader/prefetch/nsOfflineCacheUpdate.cpp
+++ b/uriloader/prefetch/nsOfflineCacheUpdate.cpp
@@ -569,27 +569,31 @@ nsOfflineCacheUpdateItem::GetUri(nsAStri
     CopyUTF8toUTF16(spec, aURI);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsOfflineCacheUpdateItem::GetTotalSize(PRInt32 *aTotalSize)
 {
     if (mChannel) {
-        return mChannel->GetContentLength(aTotalSize);
+        PRInt64 length;
+        mChannel->GetContentLength(&length);
+
+        *aTotalSize = PRInt32(length);
+        return NS_OK;
     }
 
     *aTotalSize = -1;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsOfflineCacheUpdateItem::GetLoadedSize(PRInt32 *aLoadedSize)
 {
-    *aLoadedSize = mBytesRead;
+    *aLoadedSize = PRInt32(mBytesRead);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsOfflineCacheUpdateItem::GetReadyState(PRUint16 *aReadyState)
 {
     *aReadyState = mState;
     return NS_OK;
--- a/uriloader/prefetch/nsOfflineCacheUpdate.h
+++ b/uriloader/prefetch/nsOfflineCacheUpdate.h
@@ -105,17 +105,17 @@ public:
     nsresult GetRequestSucceeded(PRBool * succeeded);
 
 private:
     nsOfflineCacheUpdate*          mUpdate;
     nsCOMPtr<nsIChannel>           mChannel;
     PRUint16                       mState;
 
 protected:
-    PRInt32                        mBytesRead;
+    PRInt64                        mBytesRead;
 };
 
 
 class nsOfflineManifestItem : public nsOfflineCacheUpdateItem
 {
 public:
     NS_DECL_NSISTREAMLISTENER
     NS_DECL_NSIREQUESTOBSERVER
--- a/uriloader/prefetch/nsPrefetchService.cpp
+++ b/uriloader/prefetch/nsPrefetchService.cpp
@@ -811,27 +811,31 @@ nsPrefetchNode::GetUri(nsAString &aURI)
     CopyUTF8toUTF16(spec, aURI);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPrefetchNode::GetTotalSize(PRInt32 *aTotalSize)
 {
     if (mChannel) {
-        return mChannel->GetContentLength(aTotalSize);
+        PRInt64 length;
+        mChannel->GetContentLength(&length);
+
+        *aTotalSize = PRInt32(length);
+        return NS_OK;
     }
 
     *aTotalSize = -1;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPrefetchNode::GetLoadedSize(PRInt32 *aLoadedSize)
 {
-    *aLoadedSize = mBytesRead;
+    *aLoadedSize = PRInt32(mBytesRead);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPrefetchNode::GetReadyState(PRUint16 *aReadyState)
 {
     *aReadyState = mState;
     return NS_OK;
--- a/uriloader/prefetch/nsPrefetchService.h
+++ b/uriloader/prefetch/nsPrefetchService.h
@@ -141,12 +141,12 @@ public:
     nsCOMPtr<nsIURI>            mURI;
     nsCOMPtr<nsIURI>            mReferrerURI;
     nsCOMPtr<nsIWeakReference>  mSource;
 
 private:
     nsRefPtr<nsPrefetchService> mService;
     nsCOMPtr<nsIChannel>        mChannel;
     PRUint16                    mState;
-    PRInt32                     mBytesRead;
+    PRInt64                     mBytesRead;
 };
 
 #endif // !nsPrefetchService_h__
--- a/widget/src/windows/nsDataObj.cpp
+++ b/widget/src/windows/nsDataObj.cpp
@@ -285,24 +285,24 @@ STDMETHODIMP nsDataObj::CStream::Stat(ST
   SYSTEMTIME st;
 
   statstg->type = STGTY_STREAM;
 
   GetSystemTime(&st);
   SystemTimeToFileTime((const SYSTEMTIME*)&st, (LPFILETIME)&statstg->mtime);
   statstg->ctime = statstg->atime = statstg->mtime;
 
-  PRInt32 nLength = 0;
+  PRInt64 nLength = 0;
   if (mChannel)
     mChannel->GetContentLength(&nLength);
 
   if (nLength < 0) 
     nLength = 0;
 
-  statstg->cbSize.LowPart = (DWORD)nLength;
+  statstg->cbSize.QuadPart = nLength;
   statstg->grfMode = STGM_READ;
   statstg->grfLocksSupported = LOCK_ONLYONCE;
   statstg->clsid = CLSID_NULL;
 
   return S_OK;
 }
 
 //-----------------------------------------------------------------------------
--- a/xpinstall/src/nsXPInstallManager.cpp
+++ b/xpinstall/src/nsXPInstallManager.cpp
@@ -1274,18 +1274,17 @@ nsXPInstallManager::OnProgress(nsIReques
     {
         if (mContentLength < 1) {
             nsCOMPtr<nsIChannel> channel = do_QueryInterface(request,&rv);
             NS_ASSERTION(channel, "should have a channel");
             if (NS_FAILED(rv)) return rv;
             rv = channel->GetContentLength(&mContentLength);
             if (NS_FAILED(rv)) return rv;
         }
-        // XXX once channels support that, use 64-bit contentlength
-        rv = mDlg->OnProgress( mNextItem-1, aProgress, PRUint64(mContentLength) );
+        rv = mDlg->OnProgress( mNextItem-1, aProgress, mContentLength );
     }
 
     return rv;
 }
 
 NS_IMETHODIMP
 nsXPInstallManager::OnStatus(nsIRequest* request, nsISupports *ctxt,
                              nsresult aStatus, const PRUnichar *aStatusArg)
--- a/xpinstall/src/nsXPInstallManager.h
+++ b/xpinstall/src/nsXPInstallManager.h
@@ -123,17 +123,17 @@ class nsXPInstallManager : public nsIXPI
         PRBool      VerifyHash(nsXPITriggerItem* aItem);
         PRInt32     GetIndexFromURL(const PRUnichar* aUrl);
         nsresult    CheckCert(nsIChannel* aChannel);
 
         nsXPITriggerInfo*   mTriggers;
         nsXPITriggerItem*   mItem;
         PRUint32            mNextItem;
         PRUint32            mChromeType;
-        PRInt32             mContentLength;
+        PRInt64             mContentLength;
         PRInt32             mOutstandingCertLoads;
         PRBool              mDialogOpen;
         PRBool              mCancelled;
         PRBool              mNeedsShutdown;
         PRBool              mFromChrome;
 
         nsCOMPtr<nsIXPIProgressDialog>  mDlg;