Bug 536324 part 3 - Change consumers of nsIChannel. r=sworkman
authorNick Hurley <hurley@todesschaf.org>
Mon, 22 Oct 2012 10:51:07 -0700
changeset 119704 af7e6c8e6d768e7dcf2e9f7f30fc7f4c8b37d4f5
parent 119703 90d8a63e061cc05f84d5f4c87dd9b2ebded439b9
child 119705 4bb51e245a4ed53ffaace1923cfa100d627b3261
push id273
push userlsblakk@mozilla.com
push dateThu, 14 Feb 2013 23:19:38 +0000
treeherdermozilla-release@c5e807a3f8b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssworkman
bugs536324
milestone19.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 536324 part 3 - Change consumers of nsIChannel. r=sworkman
content/base/src/nsSyncLoadService.cpp
content/base/src/nsXMLHttpRequest.cpp
content/media/MediaResource.cpp
dom/plugins/base/nsPluginStreamListenerPeer.cpp
embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp
extensions/gnomevfs/nsGnomeVFSProtocolHandler.cpp
js/xpconnect/loader/mozJSSubScriptLoader.cpp
layout/style/nsFontFaceLoader.cpp
netwerk/base/src/nsBaseChannel.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/FTPChannelChild.cpp
netwerk/protocol/ftp/FTPChannelChild.h
netwerk/protocol/ftp/FTPChannelParent.cpp
netwerk/protocol/ftp/PFTPChannel.ipdl
netwerk/protocol/ftp/nsFtpConnectionThread.cpp
netwerk/protocol/wyciwyg/PWyciwygChannel.ipdl
netwerk/test/TestProtocols.cpp
security/manager/ssl/src/nsNSSComponent.cpp
uriloader/exthandler/nsExternalHelperAppService.cpp
uriloader/prefetch/nsOfflineCacheUpdate.cpp
uriloader/prefetch/nsOfflineCacheUpdate.h
uriloader/prefetch/nsPrefetchService.cpp
uriloader/prefetch/nsPrefetchService.h
--- a/content/base/src/nsSyncLoadService.cpp
+++ b/content/base/src/nsSyncLoadService.cpp
@@ -332,22 +332,22 @@ nsresult
 nsSyncLoadService::PushSyncStreamToListener(nsIInputStream* aIn,
                                             nsIStreamListener* aListener,
                                             nsIChannel* aChannel)
 {
     // Set up buffering stream
     nsresult rv;
     nsCOMPtr<nsIInputStream> bufferedStream;
     if (!NS_InputStreamIsBuffered(aIn)) {
-        int32_t chunkSize;
+        int64_t chunkSize;
         rv = aChannel->GetContentLength(&chunkSize);
         if (NS_FAILED(rv)) {
             chunkSize = 4096;
         }
-        chunkSize = NS_MIN(int32_t(UINT16_MAX), chunkSize);
+        chunkSize = NS_MIN(int64_t(UINT16_MAX), chunkSize);
 
         rv = NS_NewBufferedInputStream(getter_AddRefs(bufferedStream), aIn,
                                        chunkSize);
         NS_ENSURE_SUCCESS(rv, rv);
 
         aIn = bufferedStream;
     }
 
--- a/content/base/src/nsXMLHttpRequest.cpp
+++ b/content/base/src/nsXMLHttpRequest.cpp
@@ -1390,17 +1390,17 @@ nsXMLHttpRequest::GetAllResponseHeaders(
     AppendASCIItoUTF16(value, aResponseHeaders);
     if (NS_SUCCEEDED(mChannel->GetContentCharset(value)) && !value.IsEmpty()) {
       aResponseHeaders.AppendLiteral(";charset=");
       AppendASCIItoUTF16(value, aResponseHeaders);
     }
     aResponseHeaders.AppendLiteral("\r\n");
   }
 
-  int32_t length;
+  int64_t length;
   if (NS_SUCCEEDED(mChannel->GetContentLength(&length))) {
     aResponseHeaders.AppendLiteral("Content-Length: ");
     aResponseHeaders.AppendInt(length);
     aResponseHeaders.AppendLiteral("\r\n");
   }
 }
 
 NS_IMETHODIMP
@@ -1451,17 +1451,17 @@ nsXMLHttpRequest::GetResponseHeader(cons
           !value.IsEmpty()) {
         _retval.Append(";charset=");
         _retval.Append(value);
       }
     }
 
     // Content Length:
     else if (header.LowerCaseEqualsASCII("content-length")) {
-      int32_t length;
+      int64_t length;
       if (NS_SUCCEEDED(mChannel->GetContentLength(&length))) {
         _retval.AppendInt(length);
       }
     }
 
     return;
   }
 
--- a/content/media/MediaResource.cpp
+++ b/content/media/MediaResource.cpp
@@ -279,27 +279,17 @@ ChannelMediaResource::OnStartRequest(nsI
       // The server claimed it supported range requests.  It lied.
       acceptsRanges = false;
     } 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.
       int64_t cl = -1;
-      nsCOMPtr<nsIPropertyBag2> bag = do_QueryInterface(hc);
-
-      if (bag) {
-        bag->GetPropertyAsInt64(NS_CHANNEL_PROP_CONTENT_LENGTH, &cl);
-      }
-
-      if (cl < 0) {
-        int32_t cl32;
-        hc->GetContentLength(&cl32);
-        cl = cl32;
-      }
+      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/dom/plugins/base/nsPluginStreamListenerPeer.cpp
+++ b/dom/plugins/base/nsPluginStreamListenerPeer.cpp
@@ -551,17 +551,17 @@ nsPluginStreamListenerPeer::OnStartReque
   if (callbacks)
     mWeakPtrChannelCallbacks = do_GetWeakReference(callbacks);
   
   nsCOMPtr<nsILoadGroup> loadGroup;
   channel->GetLoadGroup(getter_AddRefs(loadGroup));
   if (loadGroup)
     mWeakPtrChannelLoadGroup = do_GetWeakReference(loadGroup);
   
-  int32_t length;
+  int64_t 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/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp
+++ b/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp
@@ -871,17 +871,17 @@ nsWebBrowserPersist::OnDataAvailable(
             }
             else
             {
                 // Disaster - can't read the bytes - broken link / file error?
                 cancel = true;
             }
         }
 
-        int32_t channelContentLength = -1;
+        int64_t 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
@@ -428,19 +428,20 @@ nsGnomeVFSInputStream::DoOpen()
 
       if (info.mime_type && (strcmp(info.mime_type, APPLICATION_OCTET_STREAM) != 0))
         SetContentTypeOfChannel(info.mime_type);
 
       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 != UINT64_MAX) {
-        // XXX 64-bit
-        mChannel->SetContentLength(NS_MAX((int32_t)mBytesRemaining, INT32_MAX));
+      if (mBytesRemaining > INT64_MAX) {
+        mChannel->SetContentLength(-1);
+      } else {
+        mChannel->SetContentLength(mBytesRemaining);
       }
     }
     else
     {
       mDirOpen = true;
 
       // Sort mDirList
       mDirList = g_list_sort(mDirList, FileInfoComparator);
--- a/js/xpconnect/loader/mozJSSubScriptLoader.cpp
+++ b/js/xpconnect/loader/mozJSSubScriptLoader.cpp
@@ -40,16 +40,17 @@ using namespace mozilla::scache;
 #define LOAD_ERROR_URI_NOT_LOCAL "Trying to load a non-local URI."
 #define LOAD_ERROR_NOSTREAM  "Error opening input stream (invalid filename?)"
 #define LOAD_ERROR_NOCONTENT "ContentLength not available (not a local URL?)"
 #define LOAD_ERROR_BADCHARSET "Error converting to specified charset"
 #define LOAD_ERROR_BADREAD   "File Read Error."
 #define LOAD_ERROR_READUNDERFLOW "File Read Error (underflow.)"
 #define LOAD_ERROR_NOPRINCIPALS "Failed to get principals."
 #define LOAD_ERROR_NOSPEC "Failed to get URI spec.  This is bad."
+#define LOAD_ERROR_CONTENTTOOBIG "ContentLength is too large"
 
 // We just use the same reporter as the component loader
 extern void
 mozJSLoaderErrorReporter(JSContext *cx, const char *message, JSErrorReport *rep);
 
 mozJSSubScriptLoader::mozJSSubScriptLoader() : mSystemPrincipal(nullptr)
 {
 }
@@ -87,23 +88,27 @@ mozJSSubScriptLoader::ReadScript(nsIURI 
         chan->SetContentType(NS_LITERAL_CSTRING("application/javascript"));
         rv = chan->Open(getter_AddRefs(instream));
     }
 
     if (NS_FAILED(rv)) {
         return ReportError(cx, LOAD_ERROR_NOSTREAM);
     }
 
-    int32_t len = -1;
+    int64_t len = -1;
 
     rv = chan->GetContentLength(&len);
     if (NS_FAILED(rv) || len == -1) {
         return ReportError(cx, LOAD_ERROR_NOCONTENT);
     }
 
+    if (len > INT32_MAX) {
+        return ReportError(cx, LOAD_ERROR_CONTENTTOOBIG);
+    }
+
     nsCString buf;
     rv = NS_ReadInputStreamToString(instream, buf, len);
     if (NS_FAILED(rv))
         return rv;
 
     /* set our own error reporter so we can report any bad things as catchable
      * exceptions, including the source/line number */
     er = JS_SetErrorReporter(cx, mozJSLoaderErrorReporter);
--- a/layout/style/nsFontFaceLoader.cpp
+++ b/layout/style/nsFontFaceLoader.cpp
@@ -98,20 +98,21 @@ nsFontFaceLoader::LoadTimerCallback(nsIT
   nsFontFaceLoader *loader = static_cast<nsFontFaceLoader*>(aClosure);
 
   gfxProxyFontEntry *pe = loader->mFontEntry.get();
   bool updateUserFontSet = true;
 
   // If the entry is loading, check whether it's >75% done; if so,
   // we allow another timeout period before showing a fallback font.
   if (pe->mLoadingState == gfxProxyFontEntry::LOADING_STARTED) {
-    int32_t contentLength;
+    int64_t contentLength;
     uint32_t numBytesRead;
     if (NS_SUCCEEDED(loader->mChannel->GetContentLength(&contentLength)) &&
         contentLength > 0 &&
+        contentLength < UINT32_MAX &&
         NS_SUCCEEDED(loader->mStreamLoader->GetNumBytesRead(&numBytesRead)) &&
         numBytesRead > 3 * (uint32_t(contentLength) >> 2))
     {
       // More than 3/4 the data has been downloaded, so allow 50% extra
       // time and hope the remainder will arrive before the additional
       // time expires.
       pe->mLoadingState = gfxProxyFontEntry::LOADING_ALMOST_DONE;
       uint32_t delay;
--- a/netwerk/base/src/nsBaseChannel.h
+++ b/netwerk/base/src/nsBaseChannel.h
@@ -252,24 +252,24 @@ private:
   nsCString                           mContentCharset;
   uint32_t                            mLoadFlags;
   bool                                mQueriedProgressSink;
   bool                                mSynthProgressEvents;
   bool                                mWasOpened;
   bool                                mWaitingOnAsyncRedirect;
   bool                                mOpenRedirectChannel;
   uint32_t                            mRedirectFlags;
-  int64_t                             mContentLength;
 
 protected:
   nsCOMPtr<nsIURI>                    mURI;
   nsCOMPtr<nsILoadGroup>              mLoadGroup;
   nsCOMPtr<nsIInterfaceRequestor>     mCallbacks;
   nsCOMPtr<nsIStreamListener>         mListener;
   nsCOMPtr<nsISupports>               mListenerContext;
   nsresult                            mStatus;
   uint32_t                            mContentDispositionHint;
   nsAutoPtr<nsString>                 mContentDispositionFilename;
+  int64_t                             mContentLength;
 
   friend class mozilla::net::PrivateBrowsingChannel<nsBaseChannel>;
 };
 
 #endif // !nsBaseChannel_h__
--- a/netwerk/base/src/nsIncrementalDownload.cpp
+++ b/netwerk/base/src/nsIncrementalDownload.cpp
@@ -563,23 +563,19 @@ nsIncrementalDownload::OnStartRequest(ns
       int32_t 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", (int64_t *) &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);
+      rv = http->GetContentLength(&mTotalSize);
       if (NS_FAILED(rv))
         return rv;
-      rv = props->GetPropertyAsInt64(NS_CHANNEL_PROP_CONTENT_LENGTH,
-                                     &mTotalSize);
       // We need to know the total size of the thing we're trying to download.
       if (mTotalSize == int64_t(-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, nullptr, 0, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE);
--- a/netwerk/base/src/nsInputStreamChannel.cpp
+++ b/netwerk/base/src/nsInputStreamChannel.cpp
@@ -12,27 +12,26 @@ nsresult
 nsInputStreamChannel::OpenContentStream(bool 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.
 
-  int64_t len = ContentLength64();
-  if (len < 0) {
+  if (mContentLength < 0) {
     uint64_t 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);
+    mContentLength = avail;
   }
 
   EnableSynthesizedProgressEvents(true);
   
   NS_ADDREF(*result = mContentStream);
   return NS_OK;
 }
 
--- a/netwerk/base/src/nsStreamLoader.cpp
+++ b/netwerk/base/src/nsStreamLoader.cpp
@@ -63,25 +63,31 @@ nsStreamLoader::GetRequest(nsIRequest **
   return NS_OK;
 }
 
 NS_IMETHODIMP 
 nsStreamLoader::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
 {
   nsCOMPtr<nsIChannel> chan( do_QueryInterface(request) );
   if (chan) {
-    int32_t contentLength = -1;
+    int64_t contentLength = -1;
     chan->GetContentLength(&contentLength);
     if (contentLength >= 0) {
+      if (contentLength > UINT32_MAX) {
+        // Too big to fit into uint32, so let's bail.
+        // XXX we should really make mAllocated and mLength 64-bit instead.
+        return NS_ERROR_OUT_OF_MEMORY;
+      }
+      uint32_t contentLength32 = uint32_t(contentLength);
       // preallocate buffer
-      mData = static_cast<uint8_t*>(NS_Alloc(contentLength));
+      mData = static_cast<uint8_t*>(NS_Alloc(contentLength32));
       if (!mData) {
         return NS_ERROR_OUT_OF_MEMORY;
       }
-      mAllocated = contentLength;
+      mAllocated = contentLength32;
     }
   }
   mContext = ctxt;
   return NS_OK;
 }
 
 NS_IMETHODIMP 
 nsStreamLoader::OnStopRequest(nsIRequest* request, nsISupports *ctxt,
--- a/netwerk/protocol/data/nsDataChannel.cpp
+++ b/netwerk/protocol/data/nsDataChannel.cpp
@@ -84,14 +84,14 @@ nsDataChannel::OpenContentStream(bool as
     } else {
         rv = bufOutStream->Write(dataBuffer.get(), dataBuffer.Length(), &contentLen);
     }
     if (NS_FAILED(rv))
         return rv;
 
     SetContentType(contentType);
     SetContentCharset(contentCharset);
-    SetContentLength64(contentLen);
+    mContentLength = contentLen;
 
     NS_ADDREF(*result = bufInStream);
 
     return NS_OK;
 }
--- a/netwerk/protocol/file/nsFileChannel.cpp
+++ b/netwerk/protocol/file/nsFileChannel.cpp
@@ -349,39 +349,39 @@ nsFileChannel::OpenContentStream(bool as
         new nsFileUploadContentStream(async, fileStream, mUploadStream,
                                       mUploadLength, this);
     if (!uploadStream || !uploadStream->IsInitialized()) {
       delete uploadStream;
       return NS_ERROR_OUT_OF_MEMORY;
     }
     stream = uploadStream;
 
-    SetContentLength64(0);
+    mContentLength = 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 {
     nsAutoCString contentType;
     rv = MakeFileInputStream(file, stream, contentType);
     if (NS_FAILED(rv))
       return rv;
 
     EnableSynthesizedProgressEvents(true);
 
     // fixup content length and type
-    if (ContentLength64() < 0) {
+    if (mContentLength < 0) {
       int64_t size;
       rv = file->GetFileSize(&size);
       if (NS_FAILED(rv))
         return rv;
-      SetContentLength64(size);
+      mContentLength = size;
     }
     if (!contentType.IsEmpty())
       SetContentType(contentType);
   }
 
   *result = nullptr;
   stream.swap(*result);
   return NS_OK;
--- a/netwerk/protocol/ftp/FTPChannelChild.cpp
+++ b/netwerk/protocol/ftp/FTPChannelChild.cpp
@@ -201,59 +201,59 @@ FTPChannelChild::OpenContentStream(bool 
   
 //-----------------------------------------------------------------------------
 // FTPChannelChild::PFTPChannelChild
 //-----------------------------------------------------------------------------
 
 class FTPStartRequestEvent : public ChannelEvent
 {
  public:
-  FTPStartRequestEvent(FTPChannelChild* aChild, const int32_t& aContentLength,
+  FTPStartRequestEvent(FTPChannelChild* aChild, const int64_t& aContentLength,
                        const nsCString& aContentType, const PRTime& aLastModified,
                        const nsCString& aEntityID, const URIParams& aURI)
   : mChild(aChild), mContentLength(aContentLength), mContentType(aContentType),
     mLastModified(aLastModified), mEntityID(aEntityID), mURI(aURI) {}
   void Run() { mChild->DoOnStartRequest(mContentLength, mContentType,
                                        mLastModified, mEntityID, mURI); }
  private:
   FTPChannelChild* mChild;
-  int32_t mContentLength;
+  int64_t mContentLength;
   nsCString mContentType;
   PRTime mLastModified;
   nsCString mEntityID;
   URIParams mURI;
 };
 
 bool
-FTPChannelChild::RecvOnStartRequest(const int32_t& aContentLength,
+FTPChannelChild::RecvOnStartRequest(const int64_t& aContentLength,
                                     const nsCString& aContentType,
                                     const PRTime& aLastModified,
                                     const nsCString& aEntityID,
                                     const URIParams& aURI)
 {
   if (mEventQ.ShouldEnqueue()) {
     mEventQ.Enqueue(new FTPStartRequestEvent(this, aContentLength, aContentType,
                                              aLastModified, aEntityID, aURI));
   } else {
     DoOnStartRequest(aContentLength, aContentType, aLastModified,
                      aEntityID, aURI);
   }
   return true;
 }
 
 void
-FTPChannelChild::DoOnStartRequest(const int32_t& aContentLength,
+FTPChannelChild::DoOnStartRequest(const int64_t& aContentLength,
                                   const nsCString& aContentType,
                                   const PRTime& aLastModified,
                                   const nsCString& aEntityID,
                                   const URIParams& aURI)
 {
   LOG(("FTPChannelChild::RecvOnStartRequest [this=%x]\n", this));
 
-  SetContentLength(aContentLength);
+  mContentLength = aContentLength;
   SetContentType(aContentType);
   mLastModifiedTime = aLastModified;
   mEntityID = aEntityID;
 
   nsCString spec;
   nsCOMPtr<nsIURI> uri = DeserializeURI(aURI);
   uri->GetSpec(spec);
   nsBaseChannel::URI()->SetSpec(spec);
--- a/netwerk/protocol/ftp/FTPChannelChild.h
+++ b/netwerk/protocol/ftp/FTPChannelChild.h
@@ -64,29 +64,29 @@ public:
 
   nsresult OpenContentStream(bool async,
                              nsIInputStream** stream,
                              nsIChannel** channel) MOZ_OVERRIDE;
 
   bool IsSuspended();
 
 protected:
-  bool RecvOnStartRequest(const int32_t& aContentLength,
+  bool RecvOnStartRequest(const int64_t& aContentLength,
                           const nsCString& aContentType,
                           const PRTime& aLastModified,
                           const nsCString& aEntityID,
                           const URIParams& aURI) MOZ_OVERRIDE;
   bool RecvOnDataAvailable(const nsCString& data,
                            const uint64_t& offset,
                            const uint32_t& count) MOZ_OVERRIDE;
   bool RecvOnStopRequest(const nsresult& statusCode) MOZ_OVERRIDE;
   bool RecvFailedAsyncOpen(const nsresult& statusCode) MOZ_OVERRIDE;
   bool RecvDeleteSelf() MOZ_OVERRIDE;
 
-  void DoOnStartRequest(const int32_t& aContentLength,
+  void DoOnStartRequest(const int64_t& aContentLength,
                         const nsCString& aContentType,
                         const PRTime& aLastModified,
                         const nsCString& aEntityID,
                         const URIParams& aURI);
   void DoOnDataAvailable(const nsCString& data,
                          const uint64_t& offset,
                          const uint32_t& count);
   void DoOnStopRequest(const nsresult& statusCode);
--- a/netwerk/protocol/ftp/FTPChannelParent.cpp
+++ b/netwerk/protocol/ftp/FTPChannelParent.cpp
@@ -161,29 +161,29 @@ FTPChannelParent::RecvResume()
 //-----------------------------------------------------------------------------
 
 NS_IMETHODIMP
 FTPChannelParent::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
 {
   LOG(("FTPChannelParent::OnStartRequest [this=%x]\n", this));
 
   nsFtpChannel* chan = static_cast<nsFtpChannel*>(aRequest);
-  int32_t aContentLength;
-  chan->GetContentLength(&aContentLength);
+  int64_t contentLength;
+  chan->GetContentLength(&contentLength);
   nsCString contentType;
   chan->GetContentType(contentType);
   nsCString entityID;
   chan->GetEntityID(entityID);
   PRTime lastModified;
   chan->GetLastModifiedTime(&lastModified);
 
   URIParams uri;
   SerializeURI(chan->URI(), uri);
 
-  if (mIPCClosed || !SendOnStartRequest(aContentLength, contentType,
+  if (mIPCClosed || !SendOnStartRequest(contentLength, contentType,
                                        lastModified, entityID, uri)) {
     return NS_ERROR_UNEXPECTED;
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/netwerk/protocol/ftp/PFTPChannel.ipdl
+++ b/netwerk/protocol/ftp/PFTPChannel.ipdl
@@ -33,17 +33,17 @@ parent:
             SerializedLoadContext loadContext);
 
   ConnectChannel(uint32_t channelId);
   Cancel(nsresult status);
   Suspend();
   Resume();
 
 child:
-  OnStartRequest(int32_t aContentLength, nsCString aContentType,
+  OnStartRequest(int64_t aContentLength, nsCString aContentType,
                  PRTime aLastModified, nsCString aEntityID, URIParams aURI);
   OnDataAvailable(nsCString data, uint64_t offset, uint32_t count);
   OnStopRequest(nsresult statusCode);
   FailedAsyncOpen(nsresult statusCode);
   DeleteSelf();
 };
 
 } // namespace net
--- a/netwerk/protocol/ftp/nsFtpConnectionThread.cpp
+++ b/netwerk/protocol/ftp/nsFtpConnectionThread.cpp
@@ -993,17 +993,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->SetContentLength(mFileSize);
     }
 
     // We may want to be able to resume this
     return FTP_S_MDTM;
 }
 
 nsresult
 nsFtpState::S_mdtm() {
--- a/netwerk/protocol/wyciwyg/PWyciwygChannel.ipdl
+++ b/netwerk/protocol/wyciwyg/PWyciwygChannel.ipdl
@@ -29,17 +29,17 @@ parent:
   WriteToCacheEntry(nsString data);
   CloseCacheEntry(nsresult reason);
   SetCharsetAndSource(int32_t source, nsCString charset);
   SetSecurityInfo(nsCString securityInfo);
   Cancel(nsresult status);
 
 child:
   OnStartRequest(nsresult  statusCode,
-                 int32_t   contentLength,
+                 int64_t   contentLength,
                  int32_t   source,
                  nsCString charset,
                  nsCString securityInfo);
 
   OnDataAvailable(nsCString data,
                   uint64_t  offset);
 
   OnStopRequest(nsresult statusCode);
--- a/netwerk/test/TestProtocols.cpp
+++ b/netwerk/test/TestProtocols.cpp
@@ -399,19 +399,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()));
 
-      int32_t length = -1;
+      int64_t 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()));
@@ -425,26 +425,16 @@ InputTestConsumer::OnStartRequest(nsIReq
                                     getter_AddRefs(foo));
       if (foo) {
           nsAutoCString spec;
           foo->GetSpec(spec);
           LOG(("\ttest.foo: %s\n", spec.get()));
       }
   }
 
-  nsCOMPtr<nsIPropertyBag2> propbag = do_QueryInterface(request);
-  if (propbag) {
-      int64_t 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) {
       uint32_t majorVer, minorVer;
       nsresult rv = httpChannelInt->GetResponseVersion(&majorVer, &minorVer);
       if (NS_SUCCEEDED(rv)) {
           LOG(("HTTP Response version: %u.%u\n", majorVer, minorVer));
       }
   }
--- a/security/manager/ssl/src/nsNSSComponent.cpp
+++ b/security/manager/ssl/src/nsNSSComponent.cpp
@@ -3134,28 +3134,30 @@ PSMContentDownloader::OnStartRequest(nsI
   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));
 
-  int32_t contentLength;
+  int64_t contentLength;
   rv = channel->GetContentLength(&contentLength);
   if (NS_FAILED(rv) || contentLength <= 0)
     contentLength = kDefaultCertAllocLength;
+  if (contentLength > 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;
+  mBufferSize = int32_t(contentLength);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PSMContentDownloader::OnDataAvailable(nsIRequest* request,
                                 nsISupports* context,
                                 nsIInputStream *aIStream,
                                 uint64_t aSourceOffset,
--- a/uriloader/exthandler/nsExternalHelperAppService.cpp
+++ b/uriloader/exthandler/nsExternalHelperAppService.cpp
@@ -536,54 +536,35 @@ nsresult nsExternalHelperAppService::Ini
   NS_ENSURE_SUCCESS(rv, rv);
   return obs->AddObserver(this, "last-pb-context-exited", true);
 }
 
 nsExternalHelperAppService::~nsExternalHelperAppService()
 {
 }
 
-static int64_t GetContentLengthAsInt64(nsIRequest *request)
-{
-  int64_t 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) {
-      int32_t smallLen;
-      channel->GetContentLength(&smallLen);
-      contentLength = smallLen;
-    }
-  }
-
-  return contentLength;
-}
-
 NS_IMETHODIMP nsExternalHelperAppService::DoContent(const nsACString& aMimeContentType,
                                                     nsIRequest *aRequest,
                                                     nsIInterfaceRequestor *aWindowContext,
                                                     bool aForceSave,
                                                     nsIStreamListener ** aStreamListener)
 {
   nsAutoString fileName;
   nsAutoCString fileExtension;
   uint32_t reason = nsIHelperAppLauncherDialog::REASON_CANTHANDLE;
   nsresult rv;
 
   // Get the file extension and name that we will need later
   nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
   nsCOMPtr<nsIURI> uri;
-  if (channel)
+  int64_t contentLength = -1;
+  if (channel) {
     channel->GetURI(getter_AddRefs(uri));
-
-  int64_t contentLength = GetContentLengthAsInt64(aRequest);
+    channel->GetContentLength(&contentLength);
+  }
   if (XRE_GetProcessType() == GeckoProcessType_Content) {
     // We need to get a hold of a ContentChild 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.
     using mozilla::dom::ContentChild;
     using mozilla::dom::ExternalHelperAppChild;
@@ -1422,17 +1403,19 @@ NS_IMETHODIMP nsExternalAppHandler::OnSt
   nsCOMPtr<nsIChannel> aChannel = do_QueryInterface(request);
   
   nsresult rv;
   
   nsCOMPtr<nsIFileChannel> fileChan(do_QueryInterface(request));
   mIsFileChannel = fileChan != nullptr;
 
   // Get content length
-  mContentLength = GetContentLengthAsInt64(request);
+  if (aChannel) {
+    aChannel->GetContentLength(&mContentLength);
+  }
 
   nsCOMPtr<nsIPropertyBag2> props(do_QueryInterface(request, &rv));
   // Determine whether a new window was opened specifically for this request
   if (props) {
     bool tmp = false;
     props->GetPropertyAsBool(NS_LITERAL_STRING("docshell.newWindowTarget"),
                              &tmp);
     mShouldCloseWindow = tmp;
--- a/uriloader/prefetch/nsOfflineCacheUpdate.cpp
+++ b/uriloader/prefetch/nsOfflineCacheUpdate.cpp
@@ -539,27 +539,31 @@ nsOfflineCacheUpdateItem::GetUri(nsAStri
     CopyUTF8toUTF16(spec, aURI);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsOfflineCacheUpdateItem::GetTotalSize(int32_t *aTotalSize)
 {
     if (mChannel) {
-        return mChannel->GetContentLength(aTotalSize);
+      int64_t size64;
+      nsresult rv = mChannel->GetContentLength(&size64);
+      NS_ENSURE_SUCCESS(rv, rv);
+      *aTotalSize = int32_t(size64); // XXX - loses precision
+      return NS_OK;
     }
 
     *aTotalSize = -1;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsOfflineCacheUpdateItem::GetLoadedSize(int32_t *aLoadedSize)
 {
-    *aLoadedSize = mBytesRead;
+    *aLoadedSize = int32_t(mBytesRead); // XXX - loses precision
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsOfflineCacheUpdateItem::GetReadyState(uint16_t *aReadyState)
 {
     *aReadyState = mState;
     return NS_OK;
--- a/uriloader/prefetch/nsOfflineCacheUpdate.h
+++ b/uriloader/prefetch/nsOfflineCacheUpdate.h
@@ -76,17 +76,17 @@ public:
     bool IsCompleted();
 
 private:
     nsRefPtr<nsOfflineCacheUpdate> mUpdate;
     nsCOMPtr<nsIChannel>           mChannel;
     uint16_t                       mState;
 
 protected:
-    int32_t                        mBytesRead;
+    int64_t                        mBytesRead;
 };
 
 
 class nsOfflineManifestItem : public nsOfflineCacheUpdateItem
 {
 public:
     NS_DECL_NSISTREAMLISTENER
     NS_DECL_NSIREQUESTOBSERVER
--- a/uriloader/prefetch/nsPrefetchService.cpp
+++ b/uriloader/prefetch/nsPrefetchService.cpp
@@ -799,27 +799,31 @@ nsPrefetchNode::GetUri(nsAString &aURI)
     CopyUTF8toUTF16(spec, aURI);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPrefetchNode::GetTotalSize(int32_t *aTotalSize)
 {
     if (mChannel) {
-        return mChannel->GetContentLength(aTotalSize);
+        int64_t size64;
+        nsresult rv = mChannel->GetContentLength(&size64);
+        NS_ENSURE_SUCCESS(rv, rv);
+        *aTotalSize = int32_t(size64); // XXX - loses precision
+        return NS_OK;
     }
 
     *aTotalSize = -1;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPrefetchNode::GetLoadedSize(int32_t *aLoadedSize)
 {
-    *aLoadedSize = mBytesRead;
+    *aLoadedSize = int32_t(mBytesRead); // XXX - loses precision
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPrefetchNode::GetReadyState(uint16_t *aReadyState)
 {
     *aReadyState = mState;
     return NS_OK;
--- a/uriloader/prefetch/nsPrefetchService.h
+++ b/uriloader/prefetch/nsPrefetchService.h
@@ -112,12 +112,12 @@ public:
     nsCOMPtr<nsIURI>            mReferrerURI;
     nsCOMPtr<nsIWeakReference>  mSource;
 
 private:
     nsRefPtr<nsPrefetchService> mService;
     nsCOMPtr<nsIChannel>        mChannel;
     nsCOMPtr<nsIChannel>        mRedirectChannel;
     uint16_t                    mState;
-    int32_t                     mBytesRead;
+    int64_t                     mBytesRead;
 };
 
 #endif // !nsPrefetchService_h__