Bug 1610070 - Part 3: Convert the rest of netwerk/ to use UniquePtr. r=mayhemer
authorEric Rahm <erahm@mozilla.com>
Tue, 11 Feb 2020 16:20:08 +0000
changeset 513365 6107ec699b838b776aa6c5385c5d4f9e5a27b25c
parent 513364 4bf8e9950c4310e79d49d39f6a37a313cdfd2296
child 513366 c5dd189b917280ca7b5f1a4ac5ba288f4c8ebd38
push id37112
push userbtara@mozilla.com
push dateTue, 11 Feb 2020 21:47:36 +0000
treeherdermozilla-central@79d5ac0c4227 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1610070
milestone75.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 1610070 - Part 3: Convert the rest of netwerk/ to use UniquePtr. r=mayhemer Differential Revision: https://phabricator.services.mozilla.com/D60341
netwerk/base/AutoClose.h
netwerk/base/RequestContextService.cpp
netwerk/base/TLSServerSocket.cpp
netwerk/base/TLSServerSocket.h
netwerk/base/Tickler.h
netwerk/base/nsAsyncRedirectVerifyHelper.h
netwerk/base/nsBaseChannel.cpp
netwerk/base/nsBaseChannel.h
netwerk/base/nsFileStreams.cpp
netwerk/base/nsFileStreams.h
netwerk/base/nsPACMan.h
netwerk/base/nsProtocolProxyService.cpp
netwerk/base/nsProtocolProxyService.h
netwerk/base/nsRequestObserverProxy.cpp
netwerk/base/nsSerializationHelper.cpp
netwerk/base/nsServerSocket.cpp
netwerk/base/nsSocketTransport2.cpp
netwerk/base/nsSocketTransport2.h
netwerk/base/nsStandardURL.cpp
netwerk/base/nsTransportUtils.cpp
netwerk/base/nsUDPSocket.cpp
netwerk/base/nsUDPSocket.h
netwerk/cache/nsCacheEntry.h
netwerk/cache/nsDeleteDir.cpp
netwerk/cache/nsDiskCacheDeviceSQL.cpp
netwerk/cache/nsDiskCacheDeviceSQL.h
netwerk/cache2/CacheFileChunk.cpp
netwerk/cache2/CacheFileChunk.h
netwerk/cache2/CacheFileContextEvictor.cpp
netwerk/cache2/CacheFileContextEvictor.h
netwerk/cache2/CacheFileInputStream.h
netwerk/cache2/CacheFileMetadata.h
netwerk/cache2/CacheFileOutputStream.h
netwerk/cache2/CacheFileUtils.cpp
netwerk/cache2/CacheIOThread.h
netwerk/cache2/CacheIndex.cpp
netwerk/cache2/CacheIndex.h
netwerk/cache2/CacheIndexIterator.h
netwerk/cookie/nsCookie.cpp
netwerk/cookie/nsCookieService.cpp
netwerk/cookie/nsCookieService.h
netwerk/dns/GetAddrInfo.cpp
netwerk/dns/TRR.cpp
netwerk/dns/nsDNSService2.cpp
netwerk/dns/nsDNSService2.h
netwerk/dns/nsHostResolver.cpp
netwerk/ipc/ChannelEventQueue.h
netwerk/protocol/about/nsAboutProtocolHandler.cpp
netwerk/protocol/file/nsFileChannel.cpp
netwerk/protocol/ftp/nsFtpConnectionThread.h
netwerk/protocol/ftp/nsFtpControlConnection.h
netwerk/protocol/http/Http2Session.cpp
netwerk/protocol/http/Http2Stream.h
netwerk/protocol/http/HttpBaseChannel.cpp
netwerk/protocol/http/HttpBaseChannel.h
netwerk/protocol/http/HttpChannelChild.cpp
netwerk/protocol/http/HttpChannelChild.h
netwerk/protocol/http/HttpChannelParent.cpp
netwerk/protocol/http/HttpChannelParent.h
netwerk/protocol/http/HttpTransactionChild.cpp
netwerk/protocol/http/HttpTransactionParent.cpp
netwerk/protocol/http/HttpTransactionParent.h
netwerk/protocol/http/HttpTransactionShell.h
netwerk/protocol/http/InterceptedChannel.cpp
netwerk/protocol/http/InterceptedChannel.h
netwerk/protocol/http/InterceptedHttpChannel.cpp
netwerk/protocol/http/PSpdyPush.h
netwerk/protocol/http/ParentChannelListener.cpp
netwerk/protocol/http/ParentChannelListener.h
netwerk/protocol/http/nsCORSListenerProxy.cpp
netwerk/protocol/http/nsHttp.h
netwerk/protocol/http/nsHttpActivityDistributor.cpp
netwerk/protocol/http/nsHttpChannel.cpp
netwerk/protocol/http/nsHttpChannel.h
netwerk/protocol/http/nsHttpChunkedDecoder.cpp
netwerk/protocol/http/nsHttpChunkedDecoder.h
netwerk/protocol/http/nsHttpConnection.h
netwerk/protocol/http/nsHttpConnectionMgr.h
netwerk/protocol/http/nsHttpResponseHead.cpp
netwerk/protocol/http/nsHttpResponseHead.h
netwerk/protocol/http/nsHttpTransaction.cpp
netwerk/protocol/http/nsHttpTransaction.h
netwerk/protocol/websocket/BaseWebSocketChannel.cpp
netwerk/protocol/websocket/WebSocketChannel.cpp
netwerk/protocol/websocket/WebSocketChannel.h
netwerk/protocol/websocket/WebSocketChannelChild.cpp
netwerk/protocol/websocket/WebSocketEventService.h
netwerk/protocol/websocket/WebSocketFrame.h
netwerk/sctp/datachannel/DataChannel.cpp
netwerk/sctp/datachannel/DataChannel.h
netwerk/streamconv/converters/nsHTTPCompressConv.cpp
netwerk/streamconv/converters/nsHTTPCompressConv.h
netwerk/streamconv/converters/nsMultiMixedConv.h
netwerk/streamconv/nsStreamConverterService.cpp
netwerk/system/netlink/NetlinkService.cpp
netwerk/system/netlink/NetlinkService.h
netwerk/system/win32/nsNotifyAddrListener.cpp
netwerk/wifi/nsWifiMonitor.cpp
netwerk/wifi/nsWifiMonitor.h
netwerk/wifi/nsWifiScannerMac.cpp
netwerk/wifi/nsWifiScannerWin.cpp
netwerk/wifi/osx_corewlan.mm
netwerk/wifi/win_wifiScanner.cpp
netwerk/wifi/win_wifiScanner.h
netwerk/wifi/win_wlanLibrary.h
--- a/netwerk/base/AutoClose.h
+++ b/netwerk/base/AutoClose.h
@@ -8,17 +8,17 @@
 #define mozilla_net_AutoClose_h
 
 #include "nsCOMPtr.h"
 #include "mozilla/Mutex.h"
 
 namespace mozilla {
 namespace net {
 
-// Like an nsAutoPtr for XPCOM streams (e.g. nsIAsyncInputStream) and other
+// A container for XPCOM streams (e.g. nsIAsyncInputStream) and other
 // refcounted classes that need to have the Close() method called explicitly
 // before they are destroyed.
 template <typename T>
 class AutoClose {
  public:
   AutoClose() : mMutex("net::AutoClose.mMutex") {}
   ~AutoClose() { CloseAndRelease(); }
 
--- a/netwerk/base/RequestContextService.cpp
+++ b/netwerk/base/RequestContextService.cpp
@@ -1,15 +1,14 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 ;*; */
 /* vim: set sw=2 ts=8 et tw=80 : */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "nsAutoPtr.h"
 #include "nsIDocShell.h"
 #include "mozilla/dom/Document.h"
 #include "nsIDocumentLoader.h"
 #include "nsIObserverService.h"
 #include "nsIXULRuntime.h"
 #include "nsServiceManagerUtils.h"
 #include "nsThreadUtils.h"
 #include "RequestContextService.h"
@@ -54,17 +53,17 @@ class RequestContext final : public nsIR
   void ProcessTailQueue(nsresult aResult);
   // Reschedules the timer if needed
   void ScheduleUnblock();
   // Hard-reschedules the timer
   void RescheduleUntailTimer(TimeStamp const& now);
 
   uint64_t mID;
   Atomic<uint32_t> mBlockingTransactionCount;
-  nsAutoPtr<SpdyPushCache> mSpdyCache;
+  UniquePtr<SpdyPushCache> mSpdyCache;
 
   typedef nsCOMPtr<nsIRequestTailUnblockCallback> PendingTailRequest;
   // Number of known opened non-tailed requets
   uint32_t mNonTailRequests;
   // Queue of requests that have been tailed, when conditions are met
   // we call each of them to unblock and drop the reference
   nsTArray<PendingTailRequest> mTailQueue;
   // Loosly scheduled timer, never scheduled further to the future than
@@ -173,20 +172,20 @@ RequestContext::RemoveBlockingTransactio
   NS_ENSURE_ARG_POINTER(outval);
   mBlockingTransactionCount--;
   LOG(("RequestContext::RemoveBlockingTransaction this=%p blockers=%u", this,
        static_cast<uint32_t>(mBlockingTransactionCount)));
   *outval = mBlockingTransactionCount;
   return NS_OK;
 }
 
-SpdyPushCache* RequestContext::GetSpdyPushCache() { return mSpdyCache; }
+SpdyPushCache* RequestContext::GetSpdyPushCache() { return mSpdyCache.get(); }
 
 void RequestContext::SetSpdyPushCache(SpdyPushCache* aSpdyPushCache) {
-  mSpdyCache = aSpdyPushCache;
+  mSpdyCache = WrapUnique(aSpdyPushCache);
 }
 
 uint64_t RequestContext::GetID() { return mID; }
 
 NS_IMETHODIMP
 RequestContext::AddNonTailRequest() {
   MOZ_ASSERT(NS_IsMainThread());
 
--- a/netwerk/base/TLSServerSocket.cpp
+++ b/netwerk/base/TLSServerSocket.cpp
@@ -1,17 +1,16 @@
 /* vim:set ts=2 sw=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "TLSServerSocket.h"
 
 #include "mozilla/net/DNS.h"
-#include "nsAutoPtr.h"
 #include "nsComponentManagerUtils.h"
 #include "nsDependentSubstring.h"
 #include "nsIServerSocket.h"
 #include "nsIX509Cert.h"
 #include "nsIX509CertDB.h"
 #include "nsNetCID.h"
 #include "nsProxyRelease.h"
 #include "nsServiceManagerUtils.h"
--- a/netwerk/base/TLSServerSocket.h
+++ b/netwerk/base/TLSServerSocket.h
@@ -1,17 +1,16 @@
 /* vim:set ts=2 sw=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_net_TLSServerSocket_h
 #define mozilla_net_TLSServerSocket_h
 
-#include "nsAutoPtr.h"
 #include "nsITLSServerSocket.h"
 #include "nsServerSocket.h"
 #include "nsString.h"
 #include "mozilla/Mutex.h"
 #include "seccomon.h"
 
 namespace mozilla {
 namespace net {
--- a/netwerk/base/Tickler.h
+++ b/netwerk/base/Tickler.h
@@ -33,17 +33,16 @@
 
 #include "mozilla/Attributes.h"
 #include "nsISupports.h"
 #include <stdint.h>
 
 #ifdef MOZ_USE_WIFI_TICKLER
 #  include "mozilla/Mutex.h"
 #  include "mozilla/TimeStamp.h"
-#  include "nsAutoPtr.h"
 #  include "nsISupports.h"
 #  include "nsIThread.h"
 #  include "nsITimer.h"
 #  include "nsWeakReference.h"
 #  include "prio.h"
 
 class nsIPrefBranch;
 #endif
--- a/netwerk/base/nsAsyncRedirectVerifyHelper.h
+++ b/netwerk/base/nsAsyncRedirectVerifyHelper.h
@@ -5,17 +5,16 @@
 
 #ifndef nsAsyncRedirectVerifyHelper_h
 #define nsAsyncRedirectVerifyHelper_h
 
 #include "nsIRunnable.h"
 #include "nsIChannelEventSink.h"
 #include "nsIAsyncVerifyRedirectCallback.h"
 #include "nsCOMPtr.h"
-#include "nsAutoPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "mozilla/Attributes.h"
 
 class nsIChannel;
 
 namespace mozilla {
 namespace net {
 
--- a/netwerk/base/nsBaseChannel.cpp
+++ b/netwerk/base/nsBaseChannel.cpp
@@ -598,17 +598,18 @@ nsBaseChannel::GetContentDispositionFile
 
   aContentDispositionFilename = *mContentDispositionFilename;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsBaseChannel::SetContentDispositionFilename(
     const nsAString& aContentDispositionFilename) {
-  mContentDispositionFilename = new nsString(aContentDispositionFilename);
+  mContentDispositionFilename =
+      MakeUnique<nsString>(aContentDispositionFilename);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsBaseChannel::GetContentDispositionHeader(
     nsACString& aContentDispositionHeader) {
   return NS_ERROR_NOT_AVAILABLE;
 }
--- a/netwerk/base/nsBaseChannel.h
+++ b/netwerk/base/nsBaseChannel.h
@@ -4,18 +4,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsBaseChannel_h__
 #define nsBaseChannel_h__
 
 #include "mozilla/net/NeckoTargetHolder.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/MozPromise.h"
+#include "mozilla/UniquePtr.h"
 #include "nsString.h"
-#include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsHashPropertyBag.h"
 #include "nsInputStreamPump.h"
 
 #include "nsIChannel.h"
 #include "nsIURI.h"
 #include "nsILoadGroup.h"
 #include "nsILoadInfo.h"
@@ -290,17 +290,17 @@ class nsBaseChannel
  protected:
   nsCOMPtr<nsIURI> mURI;
   nsCOMPtr<nsILoadGroup> mLoadGroup;
   nsCOMPtr<nsILoadInfo> mLoadInfo;
   nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
   nsCOMPtr<nsIStreamListener> mListener;
   nsresult mStatus;
   uint32_t mContentDispositionHint;
-  nsAutoPtr<nsString> mContentDispositionFilename;
+  mozilla::UniquePtr<nsString> mContentDispositionFilename;
   int64_t mContentLength;
   bool mWasOpened;
   bool mCanceled;
 
   friend class mozilla::net::PrivateBrowsingChannel<nsBaseChannel>;
 };
 
 #endif  // !nsBaseChannel_h__
--- a/netwerk/base/nsFileStreams.cpp
+++ b/netwerk/base/nsFileStreams.cpp
@@ -484,17 +484,17 @@ nsFileInputStream::Read(char* aBuf, uint
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFileInputStream::ReadLine(nsACString& aLine, bool* aResult) {
   if (!mLineBuffer) {
-    mLineBuffer = new nsLineBuffer<char>;
+    mLineBuffer = MakeUnique<nsLineBuffer<char>>();
   }
   return NS_ReadLine(this, mLineBuffer.get(), aLine, aResult);
 }
 
 NS_IMETHODIMP
 nsFileInputStream::Seek(int32_t aWhence, int64_t aOffset) {
   return SeekInternal(aWhence, aOffset);
 }
--- a/netwerk/base/nsFileStreams.h
+++ b/netwerk/base/nsFileStreams.h
@@ -1,17 +1,17 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsFileStreams_h__
 #define nsFileStreams_h__
 
-#include "nsAutoPtr.h"
+#include "mozilla/UniquePtr.h"
 #include "nsIFileStreams.h"
 #include "nsIFile.h"
 #include "nsICloneableInputStream.h"
 #include "nsIInputStream.h"
 #include "nsIOutputStream.h"
 #include "nsISafeOutputStream.h"
 #include "nsISeekableStream.h"
 #include "nsILineInputStream.h"
@@ -154,17 +154,17 @@ class nsFileInputStream : public nsFileS
   virtual ~nsFileInputStream() = default;
 
   void SerializeInternal(mozilla::ipc::InputStreamParams& aParams,
                          FileDescriptorArray& aFileDescriptors);
 
   nsresult SeekInternal(int32_t aWhence, int64_t aOffset,
                         bool aClearBuf = true);
 
-  nsAutoPtr<nsLineBuffer<char> > mLineBuffer;
+  mozilla::UniquePtr<nsLineBuffer<char>> mLineBuffer;
 
   /**
    * The file being opened.
    */
   nsCOMPtr<nsIFile> mFile;
   /**
    * The IO flags passed to Init() for the file open.
    */
--- a/netwerk/base/nsPACMan.h
+++ b/netwerk/base/nsPACMan.h
@@ -8,17 +8,16 @@
 #define nsPACMan_h__
 
 #include "mozilla/Atomics.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/LinkedList.h"
 #include "mozilla/Logging.h"
 #include "mozilla/net/NeckoTargetHolder.h"
 #include "mozilla/TimeStamp.h"
-#include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsIChannelEventSink.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIStreamLoader.h"
 #include "nsThreadUtils.h"
 #include "nsIURI.h"
 #include "nsString.h"
 #include "ProxyAutoConfig.h"
--- a/netwerk/base/nsProtocolProxyService.cpp
+++ b/netwerk/base/nsProtocolProxyService.cpp
@@ -1100,17 +1100,17 @@ bool nsProtocolProxyService::CanUseProxy
        (host.EqualsLiteral("127.0.0.1") || host.EqualsLiteral("::1") ||
         host.EqualsLiteral("localhost")))) {
     LOG(("Not using proxy for this local host [%s]!\n", host.get()));
     return false;  // don't allow proxying
   }
 
   int32_t index = -1;
   while (++index < int32_t(mHostFiltersArray.Length())) {
-    HostInfo* hinfo = mHostFiltersArray[index];
+    const auto& hinfo = mHostFiltersArray[index];
 
     if (is_ipaddr != hinfo->is_ipaddr) continue;
     if (hinfo->port && hinfo->port != port) continue;
 
     if (is_ipaddr) {
       // generate masked version of target IPv6 address
       PRIPv6Addr masked;
       memcpy(&masked, &ipv6, sizeof(PRIPv6Addr));
--- a/netwerk/base/nsProtocolProxyService.h
+++ b/netwerk/base/nsProtocolProxyService.h
@@ -3,17 +3,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsProtocolProxyService_h__
 #define nsProtocolProxyService_h__
 
 #include "nsString.h"
 #include "nsCOMPtr.h"
-#include "nsAutoPtr.h"
 #include "nsTArray.h"
 #include "nsIProtocolProxyService2.h"
 #include "nsIProtocolProxyFilter.h"
 #include "nsIProxyInfo.h"
 #include "nsIObserver.h"
 #include "nsDataHashtable.h"
 #include "nsHashKeys.h"
 #include "prio.h"
@@ -359,17 +358,17 @@ class nsProtocolProxyService final : pub
   nsresult InsertFilterLink(RefPtr<FilterLink>&& link);
   nsresult RemoveFilterLink(nsISupports* givenObject);
 
  protected:
   // Indicates if local hosts (plain hostnames, no dots) should use the proxy
   bool mFilterLocalHosts;
 
   // Holds an array of HostInfo objects
-  nsTArray<nsAutoPtr<HostInfo>> mHostFiltersArray;
+  nsTArray<UniquePtr<HostInfo>> mHostFiltersArray;
 
   // Filters, always sorted by the position.
   nsTArray<RefPtr<FilterLink>> mFilters;
 
   uint32_t mProxyConfig;
 
   nsCString mHTTPProxyHost;
   int32_t mHTTPProxyPort;
--- a/netwerk/base/nsRequestObserverProxy.cpp
+++ b/netwerk/base/nsRequestObserverProxy.cpp
@@ -3,17 +3,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/DebugOnly.h"
 
 #include "nscore.h"
 #include "nsRequestObserverProxy.h"
 #include "nsIRequest.h"
-#include "nsAutoPtr.h"
 #include "mozilla/Logging.h"
 #include "mozilla/IntegerPrintfMacros.h"
 
 namespace mozilla {
 namespace net {
 
 static LazyLogModule gRequestObserverProxyLog("nsRequestObserverProxy");
 
--- a/netwerk/base/nsSerializationHelper.cpp
+++ b/netwerk/base/nsSerializationHelper.cpp
@@ -5,17 +5,16 @@
 #include "nsSerializationHelper.h"
 
 #include "mozilla/Base64.h"
 #include "nsISerializable.h"
 #include "nsIObjectOutputStream.h"
 #include "nsIObjectInputStream.h"
 #include "nsString.h"
 #include "nsBase64Encoder.h"
-#include "nsAutoPtr.h"
 #include "nsComponentManagerUtils.h"
 #include "nsStringStream.h"
 
 using namespace mozilla;
 
 nsresult NS_SerializeToString(nsISerializable* obj, nsACString& str) {
   RefPtr<nsBase64Encoder> stream(new nsBase64Encoder());
   if (!stream) return NS_ERROR_OUT_OF_MEMORY;
--- a/netwerk/base/nsServerSocket.cpp
+++ b/netwerk/base/nsServerSocket.cpp
@@ -1,17 +1,16 @@
 /* vim:set ts=2 sw=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsSocketTransport2.h"
 #include "nsServerSocket.h"
 #include "nsProxyRelease.h"
-#include "nsAutoPtr.h"
 #include "nsError.h"
 #include "nsNetCID.h"
 #include "prnetdb.h"
 #include "prio.h"
 #include "nsThreadUtils.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/EndianUtils.h"
 #include "mozilla/net/DNS.h"
--- a/netwerk/base/nsSocketTransport2.cpp
+++ b/netwerk/base/nsSocketTransport2.cpp
@@ -11,17 +11,16 @@
 #include "nsIOService.h"
 #include "nsStreamUtils.h"
 #include "nsNetSegmentUtils.h"
 #include "nsNetAddr.h"
 #include "nsTransportUtils.h"
 #include "nsProxyInfo.h"
 #include "nsNetCID.h"
 #include "nsNetUtil.h"
-#include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "plstr.h"
 #include "prerr.h"
 #include "IOActivityMonitor.h"
 #include "NSSErrorsService.h"
 #include "mozilla/dom/ToJSValue.h"
 #include "mozilla/net/NeckoChild.h"
 #include "nsThreadUtils.h"
@@ -2847,17 +2846,17 @@ NS_IMETHODIMP
 nsSocketTransport::Bind(NetAddr* aLocalAddr) {
   NS_ENSURE_ARG(aLocalAddr);
 
   MutexAutoLock lock(mLock);
   if (mAttached) {
     return NS_ERROR_FAILURE;
   }
 
-  mBindAddr = new NetAddr();
+  mBindAddr = MakeUnique<NetAddr>();
   memcpy(mBindAddr.get(), aLocalAddr, sizeof(NetAddr));
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSocketTransport::GetScriptablePeerAddr(nsINetAddr** addr) {
   NetAddr rawAddr;
--- a/netwerk/base/nsSocketTransport2.h
+++ b/netwerk/base/nsSocketTransport2.h
@@ -21,17 +21,16 @@
 #include "nsIDNSListener.h"
 #include "nsIClassInfo.h"
 #include "TCPFastOpen.h"
 #include "mozilla/net/DNS.h"
 #include "nsASocketHandler.h"
 #include "mozilla/Telemetry.h"
 
 #include "prerror.h"
-#include "nsAutoPtr.h"
 #include "ssl.h"
 
 class nsICancelable;
 class nsIDNSRecord;
 class nsIInterfaceRequestor;
 
 //-----------------------------------------------------------------------------
 
@@ -342,17 +341,17 @@ class nsSocketTransport final : public n
   // mNetAddr/mSelfAddr is valid from GetPeerAddr()/GetSelfAddr() once we have
   // reached STATE_TRANSFERRING. It must not change after that.
   void SetSocketName(PRFileDesc* fd);
   NetAddr mNetAddr;
   NetAddr mSelfAddr;  // getsockname()
   Atomic<bool, Relaxed> mNetAddrIsSet;
   Atomic<bool, Relaxed> mSelfAddrIsSet;
 
-  nsAutoPtr<NetAddr> mBindAddr;
+  UniquePtr<NetAddr> mBindAddr;
 
   // socket methods (these can only be called on the socket thread):
 
   void SendStatus(nsresult status);
   nsresult ResolveHost();
   nsresult BuildSocket(PRFileDesc*&, bool&, bool&);
   nsresult InitiateSocket();
   bool RecoverFromError();
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -10,17 +10,16 @@
 #include "nsStandardURL.h"
 #include "nsCRT.h"
 #include "nsEscape.h"
 #include "nsIFile.h"
 #include "nsIObjectInputStream.h"
 #include "nsIObjectOutputStream.h"
 #include "nsIIDNService.h"
 #include "mozilla/Logging.h"
-#include "nsAutoPtr.h"
 #include "nsIURLParser.h"
 #include "nsNetCID.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/ipc/URIUtils.h"
 #include "mozilla/TextUtils.h"
 #include <algorithm>
 #include "nsContentUtils.h"
 #include "prprf.h"
--- a/netwerk/base/nsTransportUtils.cpp
+++ b/netwerk/base/nsTransportUtils.cpp
@@ -2,17 +2,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Mutex.h"
 #include "nsTransportUtils.h"
 #include "nsITransport.h"
 #include "nsProxyRelease.h"
 #include "nsThreadUtils.h"
-#include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 
 using namespace mozilla;
 
 //-----------------------------------------------------------------------------
 
 class nsTransportStatusEvent;
 
--- a/netwerk/base/nsUDPSocket.cpp
+++ b/netwerk/base/nsUDPSocket.cpp
@@ -7,17 +7,16 @@
 #include "mozilla/EndianUtils.h"
 #include "mozilla/dom/TypedArray.h"
 #include "mozilla/HoldDropJSObjects.h"
 #include "mozilla/Telemetry.h"
 
 #include "nsSocketTransport2.h"
 #include "nsUDPSocket.h"
 #include "nsProxyRelease.h"
-#include "nsAutoPtr.h"
 #include "nsError.h"
 #include "nsNetCID.h"
 #include "nsNetUtil.h"
 #include "nsIOService.h"
 #include "prnetdb.h"
 #include "prio.h"
 #include "nsNetAddr.h"
 #include "nsNetSegmentUtils.h"
--- a/netwerk/base/nsUDPSocket.h
+++ b/netwerk/base/nsUDPSocket.h
@@ -5,17 +5,16 @@
 
 #ifndef nsUDPSocket_h__
 #define nsUDPSocket_h__
 
 #include "nsIUDPSocket.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/net/DNS.h"
 #include "nsIOutputStream.h"
-#include "nsAutoPtr.h"
 #include "nsCycleCollectionParticipant.h"
 
 //-----------------------------------------------------------------------------
 
 namespace mozilla {
 namespace net {
 
 class nsUDPSocket final : public nsASocketHandler, public nsIUDPSocket {
--- a/netwerk/cache/nsCacheEntry.h
+++ b/netwerk/cache/nsCacheEntry.h
@@ -8,17 +8,16 @@
 #define _nsCacheEntry_h_
 
 #include "nsICache.h"
 #include "nsICacheEntryDescriptor.h"
 #include "nsCacheMetaData.h"
 
 #include "nspr.h"
 #include "PLDHashTable.h"
-#include "nsAutoPtr.h"
 #include "nscore.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsAString.h"
 
 class nsCacheDevice;
 class nsCacheMetaData;
 class nsCacheRequest;
--- a/netwerk/cache/nsDeleteDir.cpp
+++ b/netwerk/cache/nsDeleteDir.cpp
@@ -4,17 +4,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsDeleteDir.h"
 #include "nsIFile.h"
 #include "nsString.h"
 #include "mozilla/Telemetry.h"
 #include "nsITimer.h"
-#include "nsAutoPtr.h"
 #include "nsThreadUtils.h"
 #include "nsISupportsPriority.h"
 #include "nsCacheUtils.h"
 #include "prtime.h"
 #include <time.h>
 
 using namespace mozilla;
 
@@ -141,18 +140,18 @@ void nsDeleteDir::TimerCallback(nsITimer
     if (idx == -1) {
       // Timer was canceled and removed during shutdown.
       return;
     }
 
     gInstance->mTimers.RemoveObjectAt(idx);
   }
 
-  nsAutoPtr<nsCOMArray<nsIFile> > dirList;
-  dirList = static_cast<nsCOMArray<nsIFile>*>(arg);
+  UniquePtr<nsCOMArray<nsIFile>> dirList;
+  dirList.reset(static_cast<nsCOMArray<nsIFile>*>(arg));
 
   bool shuttingDown = false;
 
   // Intentional extra braces to control variable sope.
   {
     // Low IO priority can only be set when running in the context of the
     // current thread.  So this shouldn't be moved to where we set the priority
     // of the Cache deleter thread using the nsThread's NSPR priority constants.
@@ -221,23 +220,23 @@ nsresult nsDeleteDir::DeleteDir(nsIFile*
     rv = dir->MoveToNative(nullptr, leaf);
 #endif
     if (NS_FAILED(rv)) return rv;
   } else {
     // we want to pass a clone of the original off to the worker thread.
     trash.swap(dir);
   }
 
-  nsAutoPtr<nsCOMArray<nsIFile> > arg(new nsCOMArray<nsIFile>);
+  UniquePtr<nsCOMArray<nsIFile>> arg(new nsCOMArray<nsIFile>);
   arg->AppendObject(trash);
 
-  rv = gInstance->PostTimer(arg, delay);
+  rv = gInstance->PostTimer(arg.get(), delay);
   if (NS_FAILED(rv)) return rv;
 
-  arg.forget();
+  Unused << arg.release();
   return NS_OK;
 }
 
 nsresult nsDeleteDir::GetTrashDir(nsIFile* target, nsCOMPtr<nsIFile>* result) {
   nsresult rv;
 #if defined(MOZ_WIDGET_ANDROID)
   // Try to use the app cache folder for cache trash on Android
   char* cachePath = getenv("CACHE_DIRECTORY");
@@ -285,36 +284,36 @@ nsresult nsDeleteDir::RemoveOldTrashes(n
   rv = cacheDir->GetParent(getter_AddRefs(parent));
 #endif
   if (NS_FAILED(rv)) return rv;
 
   nsCOMPtr<nsIDirectoryEnumerator> iter;
   rv = parent->GetDirectoryEntries(getter_AddRefs(iter));
   if (NS_FAILED(rv)) return rv;
 
-  nsAutoPtr<nsCOMArray<nsIFile> > dirList;
+  UniquePtr<nsCOMArray<nsIFile>> dirList;
 
   nsCOMPtr<nsIFile> file;
   while (NS_SUCCEEDED(iter->GetNextFile(getter_AddRefs(file))) && file) {
     nsAutoString leafName;
     rv = file->GetLeafName(leafName);
     if (NS_FAILED(rv)) continue;
 
     // match all names that begin with the trash name (i.e. "Cache.Trash")
     if (Substring(leafName, 0, trashName.Length()).Equals(trashName)) {
-      if (!dirList) dirList = new nsCOMArray<nsIFile>;
+      if (!dirList) dirList = MakeUnique<nsCOMArray<nsIFile>>();
       dirList->AppendObject(file);
     }
   }
 
   if (dirList) {
-    rv = gInstance->PostTimer(dirList, 90000);
+    rv = gInstance->PostTimer(dirList.get(), 90000);
     if (NS_FAILED(rv)) return rv;
 
-    dirList.forget();
+    Unused << dirList.release();
   }
 
   return NS_OK;
 }
 
 nsresult nsDeleteDir::PostTimer(void* arg, uint32_t delay) {
   nsresult rv;
 
--- a/netwerk/cache/nsDiskCacheDeviceSQL.cpp
+++ b/netwerk/cache/nsDiskCacheDeviceSQL.cpp
@@ -16,17 +16,16 @@
 #include "nsDiskCacheDeviceSQL.h"
 #include "nsCacheService.h"
 #include "nsApplicationCache.h"
 #include "../cache2/CacheHashUtils.h"
 
 #include "nsNetCID.h"
 #include "nsNetUtil.h"
 #include "nsIURI.h"
-#include "nsAutoPtr.h"
 #include "nsEscape.h"
 #include "nsIPrefBranch.h"
 #include "nsString.h"
 #include "nsPrintfCString.h"
 #include "nsCRT.h"
 #include "nsArrayUtils.h"
 #include "nsIArray.h"
 #include "nsIVariant.h"
--- a/netwerk/cache/nsDiskCacheDeviceSQL.h
+++ b/netwerk/cache/nsDiskCacheDeviceSQL.h
@@ -6,17 +6,16 @@
 #ifndef nsOfflineCacheDevice_h__
 #define nsOfflineCacheDevice_h__
 
 #include "nsCacheDevice.h"
 #include "nsIApplicationCache.h"
 #include "mozIStorageConnection.h"
 #include "mozIStorageFunction.h"
 #include "nsIFile.h"
-#include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsCOMArray.h"
 #include "nsInterfaceHashtable.h"
 #include "nsClassHashtable.h"
 #include "nsIWeakReference.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Mutex.h"
 
--- a/netwerk/cache2/CacheFileChunk.cpp
+++ b/netwerk/cache2/CacheFileChunk.cpp
@@ -390,17 +390,17 @@ nsresult CacheFileChunk::Write(CacheFile
   MOZ_ASSERT(!mWritingStateHandle);
   MOZ_ASSERT(mBuf->DataSize());  // Don't write chunk when it is empty
   MOZ_ASSERT(mBuf->ReadHandlesCount() == 0);
   MOZ_ASSERT(!mBuf->WriteHandleExists());
 
   nsresult rv;
 
   mState = WRITING;
-  mWritingStateHandle = new CacheFileChunkReadHandle(mBuf);
+  mWritingStateHandle = MakeUnique<CacheFileChunkReadHandle>(mBuf);
 
   rv = CacheFileIOManager::Write(
       aHandle, mIndex * kChunkSize, mWritingStateHandle->Buf(),
       mWritingStateHandle->DataSize(), false, false, this);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     mWritingStateHandle = nullptr;
     SetError(rv);
   } else {
--- a/netwerk/cache2/CacheFileChunk.h
+++ b/netwerk/cache2/CacheFileChunk.h
@@ -4,18 +4,18 @@
 
 #ifndef CacheFileChunk__h__
 #define CacheFileChunk__h__
 
 #include "CacheFileIOManager.h"
 #include "CacheStorageService.h"
 #include "CacheHashUtils.h"
 #include "CacheFileUtils.h"
-#include "nsAutoPtr.h"
 #include "mozilla/Mutex.h"
+#include "mozilla/UniquePtr.h"
 
 namespace mozilla {
 namespace net {
 
 #define kChunkSize (256 * 1024)
 #define kEmptyChunkHash 0x1826
 
 class CacheFileChunk;
@@ -212,17 +212,17 @@ class CacheFileChunk final : public Cach
   // of the buffer is created. This prevents invalidating the buffer when
   // CacheFileInputStream::ReadSegments calls the handler outside the lock.
   RefPtr<CacheFileChunkBuffer> mBuf;
 
   // We need to keep pointers of the old buffers for memory reporting.
   nsTArray<RefPtr<CacheFileChunkBuffer>> mOldBufs;
 
   // Read handle that is used during writing the chunk to the disk.
-  nsAutoPtr<CacheFileChunkReadHandle> mWritingStateHandle;
+  UniquePtr<CacheFileChunkReadHandle> mWritingStateHandle;
 
   // Buffer that is used to read the chunk from the disk. It is allowed to write
   // a new data to chunk while we wait for the data from the disk. In this case
   // this buffer is merged with mBuf in OnDataRead().
   RefPtr<CacheFileChunkBuffer> mReadingStateBuf;
   CacheHash::Hash16_t mExpectedHash;
 
   RefPtr<CacheFile> mFile;  // is null if chunk is cached to
--- a/netwerk/cache2/CacheFileContextEvictor.cpp
+++ b/netwerk/cache2/CacheFileContextEvictor.cpp
@@ -94,17 +94,17 @@ nsresult CacheFileContextEvictor::AddCon
   MOZ_ASSERT(CacheFileIOManager::IsOnIOThread());
 
   CacheFileContextEvictorEntry* entry = nullptr;
   if (aLoadContextInfo) {
     for (uint32_t i = 0; i < mEntries.Length(); ++i) {
       if (mEntries[i]->mInfo && mEntries[i]->mInfo->Equals(aLoadContextInfo) &&
           mEntries[i]->mPinned == aPinned &&
           mEntries[i]->mOrigin.Equals(aOrigin)) {
-        entry = mEntries[i];
+        entry = mEntries[i].get();
         break;
       }
     }
   } else {
     // Not providing load context info means we want to delete everything,
     // so let's not bother with any currently running context cleanups
     // for the same pinning state.
     for (uint32_t i = mEntries.Length(); i > 0;) {
@@ -117,17 +117,17 @@ nsresult CacheFileContextEvictor::AddCon
     }
   }
 
   if (!entry) {
     entry = new CacheFileContextEvictorEntry();
     entry->mInfo = aLoadContextInfo;
     entry->mPinned = aPinned;
     entry->mOrigin = aOrigin;
-    mEntries.AppendElement(entry);
+    mEntries.AppendElement(WrapUnique(entry));
   }
 
   entry->mTimeStamp = PR_Now() / PR_USEC_PER_MSEC;
 
   PersistEvictionInfoToDisk(aLoadContextInfo, aPinned, aOrigin);
 
   if (mIndexIsUpToDate) {
     // Already existing context could be added again, in this case the iterator
@@ -212,17 +212,17 @@ void CacheFileContextEvictor::WasEvicted
   nsCOMPtr<nsILoadContextInfo> info = CacheFileUtils::ParseKey(aKey);
   MOZ_ASSERT(info);
   if (!info) {
     LOG(("CacheFileContextEvictor::WasEvicted() - Cannot parse key!"));
     return;
   }
 
   for (uint32_t i = 0; i < mEntries.Length(); ++i) {
-    CacheFileContextEvictorEntry* entry = mEntries[i];
+    const auto& entry = mEntries[i];
 
     if (entry->mInfo && !info->Equals(entry->mInfo)) {
       continue;
     }
 
     PRTime lastModifiedTime;
     if (NS_FAILED(aFile->GetLastModifiedTime(&lastModifiedTime))) {
       LOG(
--- a/netwerk/cache2/CacheFileContextEvictor.h
+++ b/netwerk/cache2/CacheFileContextEvictor.h
@@ -1,18 +1,18 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef CacheFileContextEvictor__h__
 #define CacheFileContextEvictor__h__
 
+#include "mozilla/UniquePtr.h"
 #include "nsTArray.h"
 #include "nsCOMPtr.h"
-#include "nsAutoPtr.h"
 
 class nsIFile;
 class nsILoadContextInfo;
 
 namespace mozilla {
 namespace net {
 
 class CacheIndexIterator;
@@ -83,17 +83,17 @@ class CacheFileContextEvictor {
   // update process when it is outdated. NOTE: We also stop eviction in progress
   // when the index is found outdated, the eviction is restarted again once the
   // update process finishes.
   bool mIndexIsUpToDate;
   // Whether we already tried to restore unfinished jobs from previous run after
   // startup.
   static bool sDiskAlreadySearched;
   // Array of contexts being evicted.
-  nsTArray<nsAutoPtr<CacheFileContextEvictorEntry> > mEntries;
+  nsTArray<UniquePtr<CacheFileContextEvictorEntry>> mEntries;
   nsCOMPtr<nsIFile> mCacheDirectory;
   nsCOMPtr<nsIFile> mEntriesDir;
 };
 
 }  // namespace net
 }  // namespace mozilla
 
 #endif
--- a/netwerk/cache2/CacheFileInputStream.h
+++ b/netwerk/cache2/CacheFileInputStream.h
@@ -3,17 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef CacheFileInputStream__h__
 #define CacheFileInputStream__h__
 
 #include "nsIAsyncInputStream.h"
 #include "nsISeekableStream.h"
 #include "nsCOMPtr.h"
-#include "nsAutoPtr.h"
 #include "CacheFileChunk.h"
 
 namespace mozilla {
 namespace net {
 
 class CacheFile;
 
 class CacheFileInputStream : public nsIAsyncInputStream,
--- a/netwerk/cache2/CacheFileMetadata.h
+++ b/netwerk/cache2/CacheFileMetadata.h
@@ -6,17 +6,16 @@
 #define CacheFileMetadata__h__
 
 #include "CacheFileIOManager.h"
 #include "CacheStorageService.h"
 #include "CacheHashUtils.h"
 #include "CacheObserver.h"
 #include "mozilla/EndianUtils.h"
 #include "mozilla/BasePrincipal.h"
-#include "nsAutoPtr.h"
 #include "nsString.h"
 
 class nsICacheEntryMetaDataVisitor;
 
 namespace mozilla {
 namespace net {
 
 // Flags stored in CacheFileMetadataHeader.mFlags
--- a/netwerk/cache2/CacheFileOutputStream.h
+++ b/netwerk/cache2/CacheFileOutputStream.h
@@ -3,17 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef CacheFileOutputStream__h__
 #define CacheFileOutputStream__h__
 
 #include "nsIAsyncOutputStream.h"
 #include "nsISeekableStream.h"
 #include "nsCOMPtr.h"
-#include "nsAutoPtr.h"
 #include "CacheFileChunk.h"
 
 namespace mozilla {
 namespace net {
 
 class CacheFile;
 class CacheOutputCloseListener;
 
--- a/netwerk/cache2/CacheFileUtils.cpp
+++ b/netwerk/cache2/CacheFileUtils.cpp
@@ -4,17 +4,16 @@
 
 #include "CacheIndex.h"
 #include "CacheLog.h"
 #include "CacheFileUtils.h"
 #include "LoadContextInfo.h"
 #include "mozilla/Tokenizer.h"
 #include "mozilla/Telemetry.h"
 #include "nsCOMPtr.h"
-#include "nsAutoPtr.h"
 #include "nsString.h"
 #include <algorithm>
 #include "mozilla/Unused.h"
 
 namespace mozilla {
 namespace net {
 namespace CacheFileUtils {
 
--- a/netwerk/cache2/CacheIOThread.h
+++ b/netwerk/cache2/CacheIOThread.h
@@ -4,17 +4,16 @@
 
 #ifndef CacheIOThread__h__
 #define CacheIOThread__h__
 
 #include "nsIThreadInternal.h"
 #include "nsISupportsImpl.h"
 #include "prthread.h"
 #include "nsTArray.h"
-#include "nsAutoPtr.h"
 #include "mozilla/Monitor.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/UniquePtr.h"
 
 class nsIRunnable;
 
 namespace mozilla {
--- a/netwerk/cache2/CacheIndex.cpp
+++ b/netwerk/cache2/CacheIndex.cpp
@@ -82,53 +82,54 @@ class CacheIndexEntryAutoManage {
         mDoNotSearchInIndex(false),
         mDoNotSearchInUpdates(false) {
     CacheIndex::sLock.AssertCurrentThreadOwns();
 
     mHash = aHash;
     const CacheIndexEntry* entry = FindEntry();
     mIndex->mIndexStats.BeforeChange(entry);
     if (entry && entry->IsInitialized() && !entry->IsRemoved()) {
-      mOldRecord = entry->mRec;
+      mOldRecord = entry->mRec.get();
       mOldFrecency = entry->mRec->mFrecency;
     }
   }
 
   ~CacheIndexEntryAutoManage() {
     CacheIndex::sLock.AssertCurrentThreadOwns();
 
     const CacheIndexEntry* entry = FindEntry();
     mIndex->mIndexStats.AfterChange(entry);
     if (!entry || !entry->IsInitialized() || entry->IsRemoved()) {
       entry = nullptr;
     }
 
     if (entry && !mOldRecord) {
-      mIndex->mFrecencyArray.AppendRecord(entry->mRec);
-      mIndex->AddRecordToIterators(entry->mRec);
+      mIndex->mFrecencyArray.AppendRecord(entry->mRec.get());
+      mIndex->AddRecordToIterators(entry->mRec.get());
     } else if (!entry && mOldRecord) {
       mIndex->mFrecencyArray.RemoveRecord(mOldRecord);
       mIndex->RemoveRecordFromIterators(mOldRecord);
     } else if (entry && mOldRecord) {
-      if (entry->mRec != mOldRecord) {
+      auto rec = entry->mRec.get();
+      if (rec != mOldRecord) {
         // record has a different address, we have to replace it
-        mIndex->ReplaceRecordInIterators(mOldRecord, entry->mRec);
+        mIndex->ReplaceRecordInIterators(mOldRecord, rec);
 
         if (entry->mRec->mFrecency == mOldFrecency) {
           // If frecency hasn't changed simply replace the pointer
-          mIndex->mFrecencyArray.ReplaceRecord(mOldRecord, entry->mRec);
+          mIndex->mFrecencyArray.ReplaceRecord(mOldRecord, rec);
         } else {
           // Remove old pointer and insert the new one at the end of the array
           mIndex->mFrecencyArray.RemoveRecord(mOldRecord);
-          mIndex->mFrecencyArray.AppendRecord(entry->mRec);
+          mIndex->mFrecencyArray.AppendRecord(rec);
         }
       } else if (entry->mRec->mFrecency != mOldFrecency) {
         // Move the element at the end of the array
-        mIndex->mFrecencyArray.RemoveRecord(entry->mRec);
-        mIndex->mFrecencyArray.AppendRecord(entry->mRec);
+        mIndex->mFrecencyArray.RemoveRecord(rec);
+        mIndex->mFrecencyArray.AppendRecord(rec);
       }
     } else {
       // both entries were removed or not initialized, do nothing
     }
   }
 
   // We cannot rely on nsTHashtable::GetEntry() in case we are removing entries
   // while iterating. Destructor is called before the entry is removed. Caller
@@ -1270,17 +1271,17 @@ nsresult CacheIndex::GetEntryForEviction
     if (IsForcedValidEntry(&hash)) {
       continue;
     }
 
     if (CacheIndexEntry::IsPinned(rec)) {
       continue;
     }
 
-    if (aIgnoreEmptyEntries && !CacheIndexEntry::GetFileSize(rec)) {
+    if (aIgnoreEmptyEntries && !CacheIndexEntry::GetFileSize(*rec)) {
       continue;
     }
 
     --skipped;
     foundRecord = rec;
     break;
   }
 
@@ -1371,17 +1372,17 @@ nsresult CacheIndex::GetCacheStats(nsILo
   *aSize = 0;
   *aCount = 0;
 
   for (auto iter = index->mFrecencyArray.Iter(); !iter.Done(); iter.Next()) {
     CacheIndexRecord* record = iter.Get();
     if (aInfo && !CacheIndexEntry::RecordMatchesLoadContextInfo(record, aInfo))
       continue;
 
-    *aSize += CacheIndexEntry::GetFileSize(record);
+    *aSize += CacheIndexEntry::GetFileSize(*record);
     ++*aCount;
   }
 
   return NS_OK;
 }
 
 // static
 nsresult CacheIndex::AsyncGetDiskConsumption(
--- a/netwerk/cache2/CacheIndex.h
+++ b/netwerk/cache2/CacheIndex.h
@@ -16,16 +16,17 @@
 #include "nsTHashtable.h"
 #include "nsThreadUtils.h"
 #include "mozilla/IntegerPrintfMacros.h"
 #include "mozilla/SHA1.h"
 #include "mozilla/StaticMutex.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/EndianUtils.h"
 #include "mozilla/TimeStamp.h"
+#include "mozilla/UniquePtr.h"
 
 class nsIFile;
 class nsIDirectoryEnumerator;
 class nsITimer;
 
 #ifdef DEBUG
 #  define DEBUG_STATS 1
 #endif
@@ -109,17 +110,17 @@ static_assert(sizeof(CacheIndexRecord::m
 
 class CacheIndexEntry : public PLDHashEntryHdr {
  public:
   typedef const SHA1Sum::Hash& KeyType;
   typedef const SHA1Sum::Hash* KeyTypePointer;
 
   explicit CacheIndexEntry(KeyTypePointer aKey) {
     MOZ_COUNT_CTOR(CacheIndexEntry);
-    mRec = new CacheIndexRecord();
+    mRec = MakeUnique<CacheIndexRecord>();
     LOG(("CacheIndexEntry::CacheIndexEntry() - Created record [rec=%p]",
          mRec.get()));
     memcpy(&mRec->mHash, aKey, sizeof(SHA1Sum::Hash));
   }
   CacheIndexEntry(const CacheIndexEntry& aOther) {
     MOZ_ASSERT_UNREACHABLE("CacheIndexEntry copy constructor is forbidden!");
   }
   ~CacheIndexEntry() {
@@ -237,19 +238,19 @@ class CacheIndexEntry : public PLDHashEn
            "truncating to %u",
            kFileSizeMask));
       aFileSize = kFileSizeMask;
     }
     mRec->mFlags &= ~kFileSizeMask;
     mRec->mFlags |= aFileSize;
   }
   // Returns filesize in kilobytes.
-  uint32_t GetFileSize() const { return GetFileSize(mRec); }
-  static uint32_t GetFileSize(CacheIndexRecord* aRec) {
-    return aRec->mFlags & kFileSizeMask;
+  uint32_t GetFileSize() const { return GetFileSize(*mRec); }
+  static uint32_t GetFileSize(const CacheIndexRecord& aRec) {
+    return aRec.mFlags & kFileSizeMask;
   }
   static uint32_t IsPinned(CacheIndexRecord* aRec) {
     return aRec->mFlags & kPinnedMask;
   }
   bool IsFileEmpty() const { return GetFileSize() == 0; }
 
   void WriteToBuf(void* aBuf) {
     uint8_t* ptr = static_cast<uint8_t*>(aBuf);
@@ -348,17 +349,17 @@ class CacheIndexEntry : public PLDHashEn
 
   // Indicates there is cached alternative data in the entry.
   static const uint32_t kHasAltDataMask = 0x02000000;
   static const uint32_t kReservedMask = 0x01000000;
 
   // FileSize in kilobytes
   static const uint32_t kFileSizeMask = 0x00FFFFFF;
 
-  nsAutoPtr<CacheIndexRecord> mRec;
+  UniquePtr<CacheIndexRecord> mRec;
 };
 
 class CacheIndexEntryUpdate : public CacheIndexEntry {
  public:
   explicit CacheIndexEntryUpdate(CacheIndexEntry::KeyTypePointer aKey)
       : CacheIndexEntry(aKey), mUpdateFlags(0) {
     MOZ_COUNT_CTOR(CacheIndexEntryUpdate);
     LOG(("CacheIndexEntryUpdate::CacheIndexEntryUpdate()"));
--- a/netwerk/cache2/CacheIndexIterator.h
+++ b/netwerk/cache2/CacheIndexIterator.h
@@ -2,17 +2,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef CacheIndexIterator__h__
 #define CacheIndexIterator__h__
 
 #include "nsTArray.h"
 #include "nsCOMPtr.h"
-#include "nsAutoPtr.h"
 #include "mozilla/SHA1.h"
 
 namespace mozilla {
 namespace net {
 
 class CacheIndex;
 struct CacheIndexRecord;
 
--- a/netwerk/cookie/nsCookie.cpp
+++ b/netwerk/cookie/nsCookie.cpp
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Encoding.h"
 #include "mozilla/dom/ToJSValue.h"
 #include "mozilla/StaticPrefs_network.h"
-#include "nsAutoPtr.h"
 #include "nsCookie.h"
 #include "nsIURLParser.h"
 #include "nsURLHelper.h"
 #include <stdlib.h>
 
 /******************************************************************************
  * nsCookie:
  * creation helper
--- a/netwerk/cookie/nsCookieService.cpp
+++ b/netwerk/cookie/nsCookieService.cpp
@@ -36,17 +36,16 @@
 #include "mozIStorageError.h"
 #include "mozIStorageFunction.h"
 #include "mozIStorageService.h"
 #include "mozIThirdPartyUtil.h"
 
 #include "nsTArray.h"
 #include "nsCOMArray.h"
 #include "nsIMutableArray.h"
-#include "nsAutoPtr.h"
 #include "nsReadableUtils.h"
 #include "nsCRT.h"
 #include "prprf.h"
 #include "nsNetUtil.h"
 #include "nsNetCID.h"
 #include "nsIInputStream.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsNetCID.h"
--- a/netwerk/cookie/nsCookieService.h
+++ b/netwerk/cookie/nsCookieService.h
@@ -10,17 +10,16 @@
 #include "nsICookieManager.h"
 #include "nsICookiePermission.h"
 #include "nsIObserver.h"
 #include "nsWeakReference.h"
 
 #include "nsCookie.h"
 #include "nsCookieKey.h"
 #include "nsString.h"
-#include "nsAutoPtr.h"
 #include "nsHashKeys.h"
 #include "nsIMemoryReporter.h"
 #include "nsTHashtable.h"
 #include "mozIStorageStatement.h"
 #include "mozIStorageAsyncStatement.h"
 #include "mozIStorageConnection.h"
 #include "mozIStorageCompletionCallback.h"
 #include "mozIStorageStatementCallback.h"
--- a/netwerk/dns/GetAddrInfo.cpp
+++ b/netwerk/dns/GetAddrInfo.cpp
@@ -5,17 +5,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "GetAddrInfo.h"
 #include "mozilla/net/DNS.h"
 #include "prnetdb.h"
 #include "nsHostResolver.h"
 #include "nsError.h"
 #include "mozilla/Mutex.h"
-#include "nsAutoPtr.h"
 #include "mozilla/StaticPtr.h"
 #include "MainThreadUtils.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/net/DNS.h"
 #include <algorithm>
 #include "prerror.h"
 
 #include "mozilla/Logging.h"
--- a/netwerk/dns/TRR.cpp
+++ b/netwerk/dns/TRR.cpp
@@ -26,16 +26,17 @@
 #include "mozilla/Base64.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/Logging.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/StaticPrefs_network.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Tokenizer.h"
+#include "mozilla/UniquePtr.h"
 
 namespace mozilla {
 namespace net {
 
 #undef LOG
 extern mozilla::LazyLogModule gHostResolverLog;
 #define LOG(args) MOZ_LOG(gHostResolverLog, mozilla::LogLevel::Debug, args)
 #define LOG_ENABLED() \
@@ -175,17 +176,18 @@ nsresult TRR::SendHTTPRequest() {
   }
 
   if (((mType == TRRTYPE_A) || (mType == TRRTYPE_AAAA)) &&
       mRec->mEffectiveTRRMode != nsIRequest::TRR_ONLY_MODE) {
     // let NS resolves skip the blacklist check
     // we also don't check the blacklist for TRR only requests
     MOZ_ASSERT(mRec);
 
-    if (UseDefaultServer() &&  gTRRService->IsTRRBlacklisted(mHost, mOriginSuffix, mPB, true)) {
+    if (UseDefaultServer() &&
+        gTRRService->IsTRRBlacklisted(mHost, mOriginSuffix, mPB, true)) {
       if (mType == TRRTYPE_A) {
         // count only blacklist for A records to avoid double counts
         Telemetry::Accumulate(Telemetry::DNS_TRR_BLACKLISTED, true);
       }
       // not really an error but no TRR is issued
       return NS_ERROR_UNKNOWN_HOST;
     } else {
       if (UseDefaultServer() && (mType == TRRTYPE_A)) {
@@ -1132,17 +1134,17 @@ TRR::OnDataAvailable(nsIRequest* aReques
   }
   MOZ_ASSERT(count == aCount);
   mBodySize += aCount;
   return NS_OK;
 }
 
 nsresult DOHresp::Add(uint32_t TTL, unsigned char* dns, int index, uint16_t len,
                       bool aLocalAllowed) {
-  nsAutoPtr<DOHaddr> doh(new DOHaddr);
+  auto doh = MakeUnique<DOHaddr>();
   NetAddr* addr = &doh->mNet;
   if (4 == len) {
     // IPv4
     addr->inet.family = AF_INET;
     addr->inet.port = 0;  // unknown
     addr->inet.ip = ntohl(get32bit(dns, index));
   } else if (16 == len) {
     // IPv6
@@ -1162,17 +1164,17 @@ nsresult DOHresp::Add(uint32_t TTL, unsi
   }
   doh->mTtl = TTL;
 
   if (LOG_ENABLED()) {
     char buf[128];
     NetAddrToString(addr, buf, sizeof(buf));
     LOG(("DOHresp:Add %s\n", buf));
   }
-  mAddresses.insertBack(doh.forget());
+  mAddresses.insertBack(doh.release());
   return NS_OK;
 }
 
 class ProxyCancel : public Runnable {
  public:
   explicit ProxyCancel(TRR* aTRR) : Runnable("proxyTrrCancel"), mTRR(aTRR) {}
 
   NS_IMETHOD Run() override {
@@ -1195,17 +1197,15 @@ void TRR::Cancel() {
          mHost.get(), mType));
     mChannel->Cancel(NS_ERROR_ABORT);
     if (UseDefaultServer()) {
       gTRRService->TRRIsOkay(TRRService::OKAY_TIMEOUT);
     }
   }
 }
 
-bool TRR::UseDefaultServer() {
-  return !mRec || mRec->mTrrServer.IsEmpty();
-}
+bool TRR::UseDefaultServer() { return !mRec || mRec->mTrrServer.IsEmpty(); }
 
 #undef LOG
 
 // namespace
 }  // namespace net
 }  // namespace mozilla
--- a/netwerk/dns/nsDNSService2.cpp
+++ b/netwerk/dns/nsDNSService2.cpp
@@ -9,17 +9,16 @@
 #include "nsIDNSListener.h"
 #include "nsIDNSByTypeRecord.h"
 #include "nsICancelable.h"
 #include "nsIPrefBranch.h"
 #include "nsIXPConnect.h"
 #include "nsProxyRelease.h"
 #include "nsReadableUtils.h"
 #include "nsString.h"
-#include "nsAutoPtr.h"
 #include "nsNetCID.h"
 #include "nsError.h"
 #include "nsDNSPrefetch.h"
 #include "nsThreadUtils.h"
 #include "nsIProtocolProxyService.h"
 #include "prsystem.h"
 #include "prnetdb.h"
 #include "prmon.h"
--- a/netwerk/dns/nsDNSService2.h
+++ b/netwerk/dns/nsDNSService2.h
@@ -7,17 +7,16 @@
 #ifndef nsDNSService2_h__
 #define nsDNSService2_h__
 
 #include "nsPIDNSService.h"
 #include "nsIIDNService.h"
 #include "nsIMemoryReporter.h"
 #include "nsIObserver.h"
 #include "nsHostResolver.h"
-#include "nsAutoPtr.h"
 #include "nsString.h"
 #include "nsTHashtable.h"
 #include "nsHashKeys.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/Attributes.h"
 #include "TRRService.h"
 
 class nsAuthSSPI;
--- a/netwerk/dns/nsHostResolver.cpp
+++ b/netwerk/dns/nsHostResolver.cpp
@@ -14,17 +14,16 @@
 
 #include <stdlib.h>
 #include <ctime>
 #include "nsHostResolver.h"
 #include "nsError.h"
 #include "nsISupportsBase.h"
 #include "nsISupportsUtils.h"
 #include "nsIThreadManager.h"
-#include "nsAutoPtr.h"
 #include "nsComponentManagerUtils.h"
 #include "nsPrintfCString.h"
 #include "nsXPCOMCIDInternal.h"
 #include "prthread.h"
 #include "prerror.h"
 #include "prtime.h"
 #include "mozilla/Logging.h"
 #include "PLDHashTable.h"
--- a/netwerk/ipc/ChannelEventQueue.h
+++ b/netwerk/ipc/ChannelEventQueue.h
@@ -4,17 +4,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_net_ChannelEventQueue_h
 #define mozilla_net_ChannelEventQueue_h
 
 #include "nsTArray.h"
-#include "nsAutoPtr.h"
 #include "nsIEventTarget.h"
 #include "nsThreadUtils.h"
 #include "nsXULAppAPI.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/RecursiveMutex.h"
 #include "mozilla/UniquePtr.h"
 #include "mozilla/Unused.h"
--- a/netwerk/protocol/about/nsAboutProtocolHandler.cpp
+++ b/netwerk/protocol/about/nsAboutProtocolHandler.cpp
@@ -11,17 +11,16 @@
 #include "nsIAboutModule.h"
 #include "nsString.h"
 #include "nsNetCID.h"
 #include "nsAboutProtocolUtils.h"
 #include "nsError.h"
 #include "nsNetUtil.h"
 #include "nsIObjectInputStream.h"
 #include "nsIObjectOutputStream.h"
-#include "nsAutoPtr.h"
 #include "nsIWritablePropertyBag2.h"
 #include "nsIChannel.h"
 #include "nsIScriptError.h"
 #include "nsIEnterprisePolicies.h"
 
 namespace mozilla {
 namespace net {
 
--- a/netwerk/protocol/file/nsFileChannel.cpp
+++ b/netwerk/protocol/file/nsFileChannel.cpp
@@ -13,17 +13,16 @@
 #include "nsStreamUtils.h"
 #include "nsMimeTypes.h"
 #include "nsNetUtil.h"
 #include "nsNetCID.h"
 #include "nsIOutputStream.h"
 #include "nsIFileStreams.h"
 #include "nsFileProtocolHandler.h"
 #include "nsProxyRelease.h"
-#include "nsAutoPtr.h"
 #include "nsIContentPolicy.h"
 #include "nsContentUtils.h"
 
 #include "nsIFileURL.h"
 #include "nsIURIMutator.h"
 #include "nsIFile.h"
 #include "nsIMIMEService.h"
 #include "prio.h"
--- a/netwerk/protocol/ftp/nsFtpConnectionThread.h
+++ b/netwerk/protocol/ftp/nsFtpConnectionThread.h
@@ -6,17 +6,16 @@
 #ifndef __nsFtpConnectionThread__h_
 #define __nsFtpConnectionThread__h_
 
 #include "nsBaseContentStream.h"
 
 #include "nsString.h"
 #include "nsCOMPtr.h"
 #include "nsIAsyncInputStream.h"
-#include "nsAutoPtr.h"
 #include "nsITransport.h"
 #include "mozilla/net/DNS.h"
 #include "nsFtpControlConnection.h"
 #include "nsIProtocolProxyCallback.h"
 
 // ftp server types
 #define FTP_GENERIC_TYPE 0
 #define FTP_UNIX_TYPE 1
--- a/netwerk/protocol/ftp/nsFtpControlConnection.h
+++ b/netwerk/protocol/ftp/nsFtpControlConnection.h
@@ -6,17 +6,16 @@
 
 #ifndef nsFtpControlConnection_h___
 #define nsFtpControlConnection_h___
 
 #include "nsCOMPtr.h"
 
 #include "nsISocketTransport.h"
 #include "nsIAsyncInputStream.h"
-#include "nsAutoPtr.h"
 #include "nsString.h"
 #include "mozilla/Attributes.h"
 
 class nsIOutputStream;
 class nsIProxyInfo;
 class nsITransportEventSink;
 
 class nsFtpControlConnectionListener : public nsISupports {
--- a/netwerk/protocol/http/Http2Session.cpp
+++ b/netwerk/protocol/http/Http2Session.cpp
@@ -1911,17 +1911,17 @@ nsresult Http2Session::RecvPushPromise(H
     Telemetry::Accumulate(Telemetry::SPDY_CONTINUED_HEADERS,
                           self->mAggregatedHeaderSize);
   }
 
   // Create the buffering transaction and push stream
   RefPtr<Http2PushTransactionBuffer> transactionBuffer =
       new Http2PushTransactionBuffer();
   transactionBuffer->SetConnection(self);
-  nsAutoPtr<Http2PushedStream> pushedStream(new Http2PushedStream(
+  UniquePtr<Http2PushedStream> pushedStream(new Http2PushedStream(
       transactionBuffer, self, associatedStream, promisedID,
       self->mCurrentForegroundTabOuterContentWindowId));
 
   rv = pushedStream->ConvertPushHeaders(&self->mDecompressor,
                                         self->mDecompressBuffer,
                                         pushedStream->GetRequestString());
 
   if (rv == NS_ERROR_NOT_IMPLEMENTED) {
@@ -1938,17 +1938,17 @@ nsresult Http2Session::RecvPushPromise(H
     self->ResetDownstreamState();
     return NS_OK;
   } else if (NS_FAILED(rv)) {
     // This is fatal to the session.
     self->mGoAwayReason = COMPRESSION_ERROR;
     return rv;
   }
 
-  WeakPtr<Http2Stream> pushedWeak = pushedStream.forget();
+  WeakPtr<Http2Stream> pushedWeak = pushedStream.release();
 
   // Ownership of the pushed stream is by the transaction hash, just as it
   // is for a client initiated stream. Errors that aren't fatal to the
   // whole session must call cleanupStream() after this point in order
   // to remove the stream from that hash.
   self->mStreamTransactionHash.Put(transactionBuffer, pushedWeak);
   self->mPushedStreams.AppendElement(
       static_cast<Http2PushedStream*>(pushedWeak.get()));
--- a/netwerk/protocol/http/Http2Stream.h
+++ b/netwerk/protocol/http/Http2Stream.h
@@ -243,17 +243,17 @@ class Http2Stream : public nsAHttpSegmen
   nsISocketTransport* mSocketTransport;
 
   uint8_t mPriorityWeight;       // h2 weight
   uint32_t mPriorityDependency;  // h2 stream id this one depends on
   uint64_t mCurrentForegroundTabOuterContentWindowId;
   uint64_t mTransactionTabId;
 
  private:
-  friend class nsAutoPtr<Http2Stream>;
+  friend class mozilla::DefaultDelete<Http2Stream>;
 
   MOZ_MUST_USE nsresult ParseHttpRequestHeaders(const char*, uint32_t,
                                                 uint32_t*);
   MOZ_MUST_USE nsresult GenerateOpen();
 
   void AdjustPushedPriority();
   void GenerateDataFrameHeader(uint32_t, bool);
 
--- a/netwerk/protocol/http/HttpBaseChannel.cpp
+++ b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -709,17 +709,18 @@ HttpBaseChannel::GetContentDispositionFi
 
   return NS_GetFilenameFromDisposition(aContentDispositionFilename, header,
                                        mURI);
 }
 
 NS_IMETHODIMP
 HttpBaseChannel::SetContentDispositionFilename(
     const nsAString& aContentDispositionFilename) {
-  mContentDispositionFilename = new nsString(aContentDispositionFilename);
+  mContentDispositionFilename =
+      MakeUnique<nsString>(aContentDispositionFilename);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HttpBaseChannel::GetContentDispositionHeader(
     nsACString& aContentDispositionHeader) {
   if (!mResponseHead) return NS_ERROR_NOT_AVAILABLE;
 
@@ -2235,17 +2236,17 @@ HttpBaseChannel::GetChannelIsForDownload
 NS_IMETHODIMP
 HttpBaseChannel::SetChannelIsForDownload(bool aChannelIsForDownload) {
   mChannelIsForDownload = aChannelIsForDownload;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HttpBaseChannel::SetCacheKeysRedirectChain(nsTArray<nsCString>* cacheKeys) {
-  mRedirectedCachekeys = cacheKeys;
+  mRedirectedCachekeys = WrapUnique(cacheKeys);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HttpBaseChannel::GetLocalAddress(nsACString& addr) {
   if (mSelfAddr.raw.family == PR_AF_UNSPEC) return NS_ERROR_NOT_AVAILABLE;
 
   addr.SetLength(kIPv6CStrBufSize);
@@ -3611,17 +3612,17 @@ nsresult HttpBaseChannel::SetupReplaceme
     // if there is a chain of keys for redirect-responses we transfer it to
     // the new channel (see bug #561276)
     if (mRedirectedCachekeys) {
       LOG(
           ("HttpBaseChannel::SetupReplacementChannel "
            "[this=%p] transferring chain of redirect cache-keys",
            this));
       rv = httpInternal->SetCacheKeysRedirectChain(
-          mRedirectedCachekeys.forget());
+          mRedirectedCachekeys.release());
       MOZ_ASSERT(NS_SUCCEEDED(rv));
     }
 
     // Preserve CORS mode flag.
     rv = httpInternal->SetCorsMode(mCorsMode);
     MOZ_ASSERT(NS_SUCCEEDED(rv));
 
     // Preserve Redirect mode flag.
@@ -4384,17 +4385,17 @@ void HttpBaseChannel::CallTypeSniffers(v
   NS_SniffContent(NS_CONTENT_SNIFFER_CATEGORY, chan, aData, aCount, newType);
   if (!newType.IsEmpty()) {
     chan->SetContentType(newType);
   }
 }
 
 template <class T>
 static void ParseServerTimingHeader(
-    const nsAutoPtr<T>& aHeader, nsTArray<nsCOMPtr<nsIServerTiming>>& aOutput) {
+    const UniquePtr<T>& aHeader, nsTArray<nsCOMPtr<nsIServerTiming>>& aOutput) {
   if (!aHeader) {
     return;
   }
 
   nsAutoCString serverTimingHeader;
   Unused << aHeader->GetHeader(nsHttp::Server_Timing, serverTimingHeader);
   if (serverTimingHeader.IsEmpty()) {
     return;
--- a/netwerk/protocol/http/HttpBaseChannel.h
+++ b/netwerk/protocol/http/HttpBaseChannel.h
@@ -14,17 +14,16 @@
 #include "mozilla/IntegerPrintfMacros.h"
 #include "mozilla/Tuple.h"
 #include "mozilla/dom/DOMTypes.h"
 #include "mozilla/dom/ReferrerInfo.h"
 #include "mozilla/net/ChannelEventQueue.h"
 #include "mozilla/net/DNS.h"
 #include "mozilla/net/NeckoCommon.h"
 #include "mozilla/net/PrivateBrowsingChannel.h"
-#include "nsAutoPtr.h"
 #include "nsCOMArray.h"
 #include "nsCOMPtr.h"
 #include "nsHashPropertyBag.h"
 #include "nsHttp.h"
 #include "nsHttpConnectionInfo.h"
 #include "nsHttpHandler.h"
 #include "nsHttpRequestHead.h"
 #include "nsHttpResponseHead.h"
@@ -394,19 +393,21 @@ class HttpBaseChannel : public nsHashPro
 
     // Hold a ref to our channel so that it can't go away and take the
     // header with it.
     nsCOMPtr<nsIHttpChannel> mChannel;
 
     bool mReady;
   };
 
-  nsHttpResponseHead* GetResponseHead() const { return mResponseHead; }
+  nsHttpResponseHead* GetResponseHead() const { return mResponseHead.get(); }
   nsHttpRequestHead* GetRequestHead() { return &mRequestHead; }
-  nsHttpHeaderArray* GetResponseTrailers() const { return mResponseTrailers; }
+  nsHttpHeaderArray* GetResponseTrailers() const {
+    return mResponseTrailers.get();
+  }
 
   const NetAddr& GetSelfAddr() { return mSelfAddr; }
   const NetAddr& GetPeerAddr() { return mPeerAddr; }
 
   MOZ_MUST_USE nsresult OverrideSecurityInfo(nsISupports* aSecurityInfo);
 
  public: /* Necko internal use only... */
   int64_t GetAltDataLength() { return mAltDataLength; }
@@ -658,27 +659,27 @@ class HttpBaseChannel : public nsHashPro
 
   nsCOMPtr<nsISupports> mOwner;
 
   nsHttpRequestHead mRequestHead;
   // Upload throttling.
   nsCOMPtr<nsIInputChannelThrottleQueue> mThrottleQueue;
   nsCOMPtr<nsIInputStream> mUploadStream;
   nsCOMPtr<nsIRunnable> mUploadCloneableCallback;
-  nsAutoPtr<nsHttpResponseHead> mResponseHead;
-  nsAutoPtr<nsHttpHeaderArray> mResponseTrailers;
+  UniquePtr<nsHttpResponseHead> mResponseHead;
+  UniquePtr<nsHttpHeaderArray> mResponseTrailers;
   RefPtr<nsHttpConnectionInfo> mConnectionInfo;
   nsCOMPtr<nsIProxyInfo> mProxyInfo;
   nsCOMPtr<nsISupports> mSecurityInfo;
   nsCOMPtr<nsIHttpUpgradeListener> mUpgradeProtocolCallback;
-  nsAutoPtr<nsString> mContentDispositionFilename;
+  UniquePtr<nsString> mContentDispositionFilename;
   nsCOMPtr<nsIConsoleReportCollector> mReportCollector;
 
   RefPtr<nsHttpHandler> mHttpHandler;  // keep gHttpHandler alive
-  nsAutoPtr<nsTArray<nsCString>> mRedirectedCachekeys;
+  UniquePtr<nsTArray<nsCString>> mRedirectedCachekeys;
   nsCOMPtr<nsIRequestContext> mRequestContext;
 
   NetAddr mSelfAddr;
   NetAddr mPeerAddr;
 
   nsTArray<Pair<nsString, nsString>> mSecurityConsoleMessages;
   nsTArray<nsCString> mUnsafeHeaders;
 
--- a/netwerk/protocol/http/HttpChannelChild.cpp
+++ b/netwerk/protocol/http/HttpChannelChild.cpp
@@ -497,17 +497,17 @@ void HttpChannelChild::OnStartRequest(
     mStatus = aChannelStatus;
   }
 
   // Cookies headers should not be visible to the child process
   MOZ_ASSERT(!aRequestHeaders.HasHeader(nsHttp::Cookie));
   MOZ_ASSERT(!nsHttpResponseHead(aResponseHead).HasHeader(nsHttp::Set_Cookie));
 
   if (aUseResponseHead && !mCanceled)
-    mResponseHead = new nsHttpResponseHead(aResponseHead);
+    mResponseHead = MakeUnique<nsHttpResponseHead>(aResponseHead);
 
   if (!aSecurityInfoSerialization.IsEmpty()) {
     nsresult rv = NS_DeserializeObject(aSecurityInfoSerialization,
                                        getter_AddRefs(mSecurityInfo));
     MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
                           "Deserializing security info should not fail");
     Unused << rv;  // So we don't get an unused error in release builds.
   }
@@ -1068,17 +1068,17 @@ void HttpChannelChild::OnStopRequest(
     profiler_add_network_marker(
         mURI, priority, mChannelId, NetworkLoadType::LOAD_STOP,
         mLastStatusReported, TimeStamp::Now(), mTransferSize, kCacheUnknown,
         mLoadInfo->GetInnerWindowID(), &mTransactionTimings, nullptr,
         std::move(mSource));
   }
 #endif
 
-  mResponseTrailers = new nsHttpHeaderArray(aResponseTrailers);
+  mResponseTrailers = MakeUnique<nsHttpHeaderArray>(aResponseTrailers);
 
   DoPreOnStopRequest(aChannelStatus);
 
   {  // We must flush the queue before we Send__delete__
     // (although we really shouldn't receive any msgs after OnStop),
     // so make sure this goes out of scope before then.
     AutoEventEnqueuer ensureSerialDispatch(mEventQ);
 
@@ -1367,25 +1367,25 @@ mozilla::ipc::IPCResult HttpChannelChild
       this,
       [self = UnsafePtr<HttpChannelChild>(this)]() { self->DeleteSelf(); }));
   return IPC_OK();
 }
 
 HttpChannelChild::OverrideRunnable::OverrideRunnable(
     HttpChannelChild* aChannel, HttpChannelChild* aNewChannel,
     InterceptStreamListener* aListener, nsIInputStream* aInput,
-    nsIInterceptedBodyCallback* aCallback, nsAutoPtr<nsHttpResponseHead>& aHead,
-    nsICacheInfoChannel* aCacheInfo)
+    nsIInterceptedBodyCallback* aCallback,
+    UniquePtr<nsHttpResponseHead>&& aHead, nsICacheInfoChannel* aCacheInfo)
     : Runnable("net::HttpChannelChild::OverrideRunnable") {
   mChannel = aChannel;
   mNewChannel = aNewChannel;
   mListener = aListener;
   mInput = aInput;
   mCallback = aCallback;
-  mHead = aHead;
+  mHead = std::move(aHead);
   mSynthesizedCacheInfo = aCacheInfo;
 }
 
 void HttpChannelChild::OverrideRunnable::OverrideWithSynthesizedResponse() {
   if (mNewChannel) {
     mNewChannel->OverrideWithSynthesizedResponse(
         mHead, mInput, mCallback, mListener, mSynthesizedCacheInfo);
   }
@@ -1588,17 +1588,17 @@ nsresult HttpChannelChild::SetupRedirect
   rv = NS_NewChannelInternal(getter_AddRefs(newChannel), uri, redirectLoadInfo,
                              nullptr,  // PerformanceStorage
                              nullptr,  // aLoadGroup
                              nullptr,  // aCallbacks
                              nsIRequest::LOAD_NORMAL, ioService);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // We won't get OnStartRequest, set cookies here.
-  mResponseHead = new nsHttpResponseHead(*responseHead);
+  mResponseHead = MakeUnique<nsHttpResponseHead>(*responseHead);
 
   bool rewriteToGET = HttpBaseChannel::ShouldRewriteRedirectToGET(
       mResponseHead->Status(), mRequestHead.ParsedMethod());
 
   rv = SetupReplacementChannel(uri, newChannel, !rewriteToGET, redirectFlags);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIHttpChannelChild> httpChannelChild =
@@ -2161,18 +2161,18 @@ HttpChannelChild::OnRedirectVerifyCallba
     nsCOMPtr<nsIEventTarget> neckoTarget = GetNeckoTarget();
     MOZ_ASSERT(neckoTarget);
 
     nsCOMPtr<nsIInterceptedBodyCallback> callback =
         mSynthesizedCallback.forget();
 
     Unused << neckoTarget->Dispatch(
         new OverrideRunnable(this, redirectedChannel, streamListener,
-                             mSynthesizedInput, callback, mResponseHead,
-                             mSynthesizedCacheInfo),
+                             mSynthesizedInput, callback,
+                             std::move(mResponseHead), mSynthesizedCacheInfo),
         NS_DISPATCH_NORMAL);
 
     return NS_OK;
   }
 
   RequestHeaderTuples emptyHeaders;
   RequestHeaderTuples* headerTuples = &emptyHeaders;
   nsLoadFlags loadFlags = 0;
@@ -3707,17 +3707,17 @@ void HttpChannelChild::CancelOnMainThrea
   mEventQ->PrependEvent(MakeUnique<NeckoTargetChannelFunctionEvent>(
       this, [self = UnsafePtr<HttpChannelChild>(this), aRv]() {
         self->Cancel(aRv);
       }));
   mEventQ->Resume();
 }
 
 void HttpChannelChild::OverrideWithSynthesizedResponse(
-    nsAutoPtr<nsHttpResponseHead>& aResponseHead,
+    UniquePtr<nsHttpResponseHead>& aResponseHead,
     nsIInputStream* aSynthesizedInput,
     nsIInterceptedBodyCallback* aSynthesizedCallback,
     InterceptStreamListener* aStreamListener,
     nsICacheInfoChannel* aCacheInfoChannel) {
   MOZ_ASSERT(NS_IsMainThread());
   nsresult rv = NS_OK;
   auto autoCleanup = MakeScopeExit([&] {
     // Auto-cancel on failure.  Do this first to get mStatus set, if necessary.
@@ -3736,32 +3736,32 @@ void HttpChannelChild::OverrideWithSynth
   if (NS_FAILED(mStatus)) {
     return;
   }
 
   mInterceptListener = aStreamListener;
 
   // Intercepted responses should already be decoded.  If its a redirect,
   // however, we want to respect the encoding of the final result instead.
-  if (!nsHttpChannel::WillRedirect(aResponseHead)) {
+  if (!nsHttpChannel::WillRedirect(*aResponseHead)) {
     SetApplyConversion(false);
   }
 
-  mResponseHead = aResponseHead;
+  mResponseHead = std::move(aResponseHead);
   mSynthesizedResponse = true;
 
   mSynthesizedInput = aSynthesizedInput;
 
   if (!mSynthesizedInput) {
     rv = NS_NewCStringInputStream(getter_AddRefs(mSynthesizedInput),
                                   EmptyCString());
     NS_ENSURE_SUCCESS_VOID(rv);
   }
 
-  if (nsHttpChannel::WillRedirect(mResponseHead)) {
+  if (nsHttpChannel::WillRedirect(*mResponseHead)) {
     // Normally we handle redirect limits in the parent process.  The way
     // e10s synthesized redirects work, however, the parent process does not
     // get an accurate redirect count.  Therefore we need to enforce it here.
     rv = CheckRedirectLimit(nsIChannelEventSink::REDIRECT_TEMPORARY);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       Cancel(rv);
       return;
     }
--- a/netwerk/protocol/http/HttpChannelChild.h
+++ b/netwerk/protocol/http/HttpChannelChild.h
@@ -253,29 +253,29 @@ class HttpChannelChild final : public PH
   nsresult AsyncCallImpl(void (HttpChannelChild::*funcPtr)(),
                          nsRunnableMethod<HttpChannelChild>** retval);
 
   class OverrideRunnable : public Runnable {
    public:
     OverrideRunnable(HttpChannelChild* aChannel, HttpChannelChild* aNewChannel,
                      InterceptStreamListener* aListener, nsIInputStream* aInput,
                      nsIInterceptedBodyCallback* aCallback,
-                     nsAutoPtr<nsHttpResponseHead>& aHead,
+                     UniquePtr<nsHttpResponseHead>&& aHead,
                      nsICacheInfoChannel* aCacheInfo);
 
     NS_IMETHOD Run() override;
     void OverrideWithSynthesizedResponse();
 
    private:
     RefPtr<HttpChannelChild> mChannel;
     RefPtr<HttpChannelChild> mNewChannel;
     RefPtr<InterceptStreamListener> mListener;
     nsCOMPtr<nsIInputStream> mInput;
     nsCOMPtr<nsIInterceptedBodyCallback> mCallback;
-    nsAutoPtr<nsHttpResponseHead> mHead;
+    UniquePtr<nsHttpResponseHead> mHead;
     nsCOMPtr<nsICacheInfoChannel> mSynthesizedCacheInfo;
   };
 
   // Sets the event target for future IPC messages. Messages will either be
   // directed to the TabGroup or DocGroup, depending on the LoadInfo associated
   // with the channel. Should be called when a new channel is being set up,
   // before the constructor message is sent to the parent.
   void SetEventTarget();
@@ -318,17 +318,17 @@ class HttpChannelChild final : public PH
 
   // Discard the prior interception and continue with the original network
   // request.
   void ResetInterception();
 
   // Override this channel's pending response with a synthesized one. The
   // content will be asynchronously read from the pump.
   void OverrideWithSynthesizedResponse(
-      nsAutoPtr<nsHttpResponseHead>& aResponseHead,
+      UniquePtr<nsHttpResponseHead>& aResponseHead,
       nsIInputStream* aSynthesizedInput,
       nsIInterceptedBodyCallback* aSynthesizedCallback,
       InterceptStreamListener* aStreamListener,
       nsICacheInfoChannel* aCacheInfoChannel);
 
   void ForceIntercepted(nsIInputStream* aSynthesizedInput,
                         nsIInterceptedBodyCallback* aSynthesizedCallback,
                         nsICacheInfoChannel* aCacheInfo);
--- a/netwerk/protocol/http/HttpChannelParent.cpp
+++ b/netwerk/protocol/http/HttpChannelParent.cpp
@@ -1432,18 +1432,18 @@ HttpChannelParent::OnStartRequest(nsIReq
     httpChannelImpl->GetCacheTokenCachedCharset(cachedCharset);
   }
 
   bool loadedFromApplicationCache = false;
 
   if (httpChannelImpl) {
     httpChannelImpl->GetLoadedFromApplicationCache(&loadedFromApplicationCache);
     if (loadedFromApplicationCache) {
-      mOfflineForeignMarker =
-          httpChannelImpl->GetOfflineCacheEntryAsForeignMarker();
+      mOfflineForeignMarker.reset(
+          httpChannelImpl->GetOfflineCacheEntryAsForeignMarker());
       nsCOMPtr<nsIApplicationCache> appCache;
       httpChannelImpl->GetApplicationCache(getter_AddRefs(appCache));
       nsCString appCacheGroupId;
       nsCString appCacheClientId;
       appCache->GetGroupID(appCacheGroupId);
       appCache->GetClientID(appCacheClientId);
       if (mIPCClosed ||
           !SendAssociateApplicationCache(appCacheGroupId, appCacheClientId)) {
--- a/netwerk/protocol/http/HttpChannelParent.h
+++ b/netwerk/protocol/http/HttpChannelParent.h
@@ -281,17 +281,17 @@ class HttpChannelParent final : public n
   friend class DivertCompleteEvent;
 
   RefPtr<HttpBaseChannel> mChannel;
   nsCOMPtr<nsICacheEntry> mCacheEntry;
 
   nsCOMPtr<nsIChannel> mRedirectChannel;
   nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;
 
-  nsAutoPtr<class nsHttpChannel::OfflineCacheEntryAsForeignMarker>
+  UniquePtr<class nsHttpChannel::OfflineCacheEntryAsForeignMarker>
       mOfflineForeignMarker;
   nsCOMPtr<nsILoadContext> mLoadContext;
   RefPtr<nsHttpHandler> mHttpHandler;
 
   RefPtr<ParentChannelListener> mParentListener;
   // The listener we are diverting to or will divert to if mPendingDiversion
   // is set.
   nsCOMPtr<nsIStreamListener> mDivertListener;
--- a/netwerk/protocol/http/HttpTransactionChild.cpp
+++ b/netwerk/protocol/http/HttpTransactionChild.cpp
@@ -315,17 +315,17 @@ HttpTransactionChild::OnStartRequest(nsI
   nsCOMPtr<nsISupports> secInfoSupp = mTransaction->SecurityInfo();
   if (secInfoSupp) {
     nsCOMPtr<nsISerializable> secInfoSer = do_QueryInterface(secInfoSupp);
     if (secInfoSer) {
       NS_SerializeToString(secInfoSer, serializedSecurityInfoOut);
     }
   }
 
-  nsAutoPtr<nsHttpResponseHead> head(mTransaction->TakeResponseHead());
+  UniquePtr<nsHttpResponseHead> head(mTransaction->TakeResponseHead());
   Maybe<nsHttpResponseHead> optionalHead;
   nsTArray<uint8_t> dataForSniffer;
   if (head) {
     optionalHead = Some(*head);
     if (mTransaction->Caps() & NS_HTTP_CALL_CONTENT_SNIFFER) {
       nsAutoCString contentTypeOptionsHeader;
       if (head->GetContentTypeOptionsHeader(contentTypeOptionsHeader) &&
           contentTypeOptionsHeader.EqualsIgnoreCase("nosniff")) {
@@ -356,17 +356,17 @@ HttpTransactionChild::OnStopRequest(nsIR
   }
 
   if (!CanSend()) {
     return NS_ERROR_FAILURE;
   }
 
   MOZ_ASSERT(mTransaction);
 
-  nsAutoPtr<nsHttpHeaderArray> headerArray(
+  UniquePtr<nsHttpHeaderArray> headerArray(
       mTransaction->TakeResponseTrailers());
   Maybe<nsHttpHeaderArray> responseTrailers;
   if (headerArray) {
     responseTrailers.emplace(*headerArray);
   }
 
   Unused << SendOnStopRequest(
       aStatus, mTransaction->ResponseIsComplete(),
--- a/netwerk/protocol/http/HttpTransactionParent.cpp
+++ b/netwerk/protocol/http/HttpTransactionParent.cpp
@@ -181,30 +181,30 @@ nsresult HttpTransactionParent::AsyncRea
   mChannel = listener;
   return NS_OK;
 }
 
 void HttpTransactionParent::SetClassOfService(uint32_t classOfService) {
   Unused << SendUpdateClassOfService(classOfService);
 }
 
-nsHttpResponseHead* HttpTransactionParent::TakeResponseHead() {
+UniquePtr<nsHttpResponseHead> HttpTransactionParent::TakeResponseHead() {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(!mResponseHeadTaken, "TakeResponseHead called 2x");
 
   mResponseHeadTaken = true;
-  return mResponseHead.forget();
+  return std::move(mResponseHead);
 }
 
-nsHttpHeaderArray* HttpTransactionParent::TakeResponseTrailers() {
+UniquePtr<nsHttpHeaderArray> HttpTransactionParent::TakeResponseTrailers() {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(!mResponseTrailersTaken, "TakeResponseTrailers called 2x");
 
   mResponseTrailersTaken = true;
-  return mResponseTrailers.forget();
+  return std::move(mResponseTrailers);
 }
 
 void HttpTransactionParent::SetSniffedTypeToChannel(
     nsInputStreamPump::PeekSegmentFun aCallTypeSniffers, nsIChannel* aChannel) {
   if (!mDataForSniffer.IsEmpty()) {
     aCallTypeSniffers(aChannel, mDataForSniffer.Elements(),
                       mDataForSniffer.Length());
   }
@@ -394,17 +394,17 @@ void HttpTransactionParent::DoOnStartReq
   mStatus = aStatus;
 
   if (!aSecurityInfoSerialization.IsEmpty()) {
     NS_DeserializeObject(aSecurityInfoSerialization,
                          getter_AddRefs(mSecurityInfo));
   }
 
   if (aResponseHead.isSome()) {
-    mResponseHead = new nsHttpResponseHead(aResponseHead.ref());
+    mResponseHead = MakeUnique<nsHttpResponseHead>(aResponseHead.ref());
   }
   mProxyConnectFailed = aProxyConnectFailed;
   TimingStructArgsToTimingsStruct(aTimings, mTimings);
 
   mProxyConnectResponseCode = aProxyConnectResponseCode;
   mDataForSniffer = std::move(aDataForSniffer);
 
   AutoEventEnqueuer ensureSerialDispatch(mEventQ);
@@ -512,17 +512,17 @@ void HttpTransactionParent::DoOnStopRequ
 
   nsCOMPtr<nsIRequest> deathGrip = this;
 
   mResponseIsComplete = aResponseIsComplete;
   mTransferSize = aTransferSize;
   TimingStructArgsToTimingsStruct(aTimings, mTimings);
 
   if (aResponseTrailers.isSome()) {
-    mResponseTrailers = new nsHttpHeaderArray(aResponseTrailers.ref());
+    mResponseTrailers = MakeUnique<nsHttpHeaderArray>(aResponseTrailers.ref());
   }
   mHasStickyConnection = aHasStickyConn;
   if (aTransactionObserverResult.isSome()) {
     mTransactionObserverResult = aTransactionObserverResult.value();
     mTransactionObserver();
   }
 
   AutoEventEnqueuer ensureSerialDispatch(mEventQ);
--- a/netwerk/protocol/http/HttpTransactionParent.h
+++ b/netwerk/protocol/http/HttpTransactionParent.h
@@ -101,18 +101,18 @@ class HttpTransactionParent final : publ
       const bool& aHasStickyConn,
       const Maybe<TransactionObserverResult>& aTransactionObserverResult);
   void DoNotifyListener();
 
   nsCOMPtr<nsITransportEventSink> mEventsink;
   nsCOMPtr<nsIStreamListener> mChannel;
   nsCOMPtr<nsIEventTarget> mTargetThread;
   nsCOMPtr<nsISupports> mSecurityInfo;
-  nsAutoPtr<nsHttpResponseHead> mResponseHead;
-  nsAutoPtr<nsHttpHeaderArray> mResponseTrailers;
+  UniquePtr<nsHttpResponseHead> mResponseHead;
+  UniquePtr<nsHttpHeaderArray> mResponseTrailers;
   RefPtr<ChannelEventQueue> mEventQ;
 
   bool mResponseIsComplete;
   int64_t mTransferSize;
   int64_t mRequestSize;
   bool mProxyConnectFailed;
   bool mCanceled;
   nsresult mStatus;
--- a/netwerk/protocol/http/HttpTransactionShell.h
+++ b/netwerk/protocol/http/HttpTransactionShell.h
@@ -5,16 +5,18 @@
 #ifndef HttpTransactionShell_h__
 #define HttpTransactionShell_h__
 
 #include <functional>
 #include "nsISupports.h"
 #include "TimingStruct.h"
 #include "nsInputStreamPump.h"
 
+#include "mozilla/UniquePtr.h"
+
 class nsIEventTraget;
 class nsIInputStream;
 class nsIInterfaceRequestor;
 class nsIRequest;
 class nsIRequestContext;
 class nsITransportEventSink;
 enum HttpTrafficCategory : uint8_t;
 
@@ -92,21 +94,21 @@ class HttpTransactionShell : public nsIS
   //        available (check transaction status).
   virtual nsresult AsyncRead(nsIStreamListener* listener,
                              nsIRequest** pump) = 0;
 
   virtual void SetClassOfService(uint32_t classOfService) = 0;
 
   // Called to take ownership of the response headers; the transaction
   // will drop any reference to the response headers after this call.
-  virtual nsHttpResponseHead* TakeResponseHead() = 0;
+  virtual UniquePtr<nsHttpResponseHead> TakeResponseHead() = 0;
 
   // Called to take ownership of the trailer headers.
   // Returning null if there is no trailer.
-  virtual nsHttpHeaderArray* TakeResponseTrailers() = 0;
+  virtual UniquePtr<nsHttpHeaderArray> TakeResponseTrailers() = 0;
 
   virtual nsISupports* SecurityInfo() = 0;
   virtual void SetSecurityCallbacks(nsIInterfaceRequestor* aCallbacks) = 0;
 
   virtual void GetNetworkAddresses(NetAddr& self, NetAddr& peer,
                                    bool& aResolvedByTRR) = 0;
 
   // Functions for Timing interface
@@ -165,18 +167,18 @@ NS_DEFINE_STATIC_IID_ACCESSOR(HttpTransa
       bool responseTimeoutEnabled, uint64_t channelId,                         \
       TransactionObserverFunc&& transactionObserver,                           \
       OnPushCallback&& aOnPushCallback,                                        \
       HttpTransactionShell* aTransWithPushedStream, uint32_t aPushedStreamId)  \
       override;                                                                \
   virtual nsresult AsyncRead(nsIStreamListener* listener, nsIRequest** pump)   \
       override;                                                                \
   virtual void SetClassOfService(uint32_t classOfService) override;            \
-  virtual nsHttpResponseHead* TakeResponseHead() override;                     \
-  virtual nsHttpHeaderArray* TakeResponseTrailers() override;                  \
+  virtual UniquePtr<nsHttpResponseHead> TakeResponseHead() override;           \
+  virtual UniquePtr<nsHttpHeaderArray> TakeResponseTrailers() override;        \
   virtual nsISupports* SecurityInfo() override;                                \
   virtual void SetSecurityCallbacks(nsIInterfaceRequestor* aCallbacks)         \
       override;                                                                \
   virtual void GetNetworkAddresses(NetAddr& self, NetAddr& peer,               \
                                    bool& aResolvedByTRR) override;             \
   virtual mozilla::TimeStamp GetDomainLookupStart() override;                  \
   virtual mozilla::TimeStamp GetDomainLookupEnd() override;                    \
   virtual mozilla::TimeStamp GetConnectStart() override;                       \
--- a/netwerk/protocol/http/InterceptedChannel.cpp
+++ b/netwerk/protocol/http/InterceptedChannel.cpp
@@ -306,17 +306,17 @@ InterceptedChannelContent::StartSynthesi
   } else {
     responseURI = originalURI;
   }
 
   bool equal = false;
   originalURI->Equals(responseURI, &equal);
   if (!equal) {
     mChannel->ForceIntercepted(aBody, aBodyCallback, aCacheInfoChannel);
-    mChannel->BeginNonIPCRedirect(responseURI, *mSynthesizedResponseHead.ptr(),
+    mChannel->BeginNonIPCRedirect(responseURI, mSynthesizedResponseHead->get(),
                                   aResponseRedirected);
   } else {
     mChannel->OverrideWithSynthesizedResponse(
         mSynthesizedResponseHead.ref(), aBody, aBodyCallback, mStreamListener,
         aCacheInfoChannel);
   }
 
   return NS_OK;
--- a/netwerk/protocol/http/InterceptedChannel.h
+++ b/netwerk/protocol/http/InterceptedChannel.h
@@ -28,17 +28,17 @@ class InterceptStreamListener;
 // synthesizing responses.
 class InterceptedChannelBase : public nsIInterceptedChannel {
  protected:
   // The interception controller to notify about the successful channel
   // interception
   nsCOMPtr<nsINetworkInterceptController> mController;
 
   // Response head for use when synthesizing
-  Maybe<nsAutoPtr<nsHttpResponseHead>> mSynthesizedResponseHead;
+  Maybe<UniquePtr<nsHttpResponseHead>> mSynthesizedResponseHead;
 
   nsCOMPtr<nsIConsoleReportCollector> mReportCollector;
   nsCOMPtr<nsISupports> mReleaseHandle;
 
   bool mClosed;
 
   void EnsureSynthesizedResponse();
   void DoNotifyController();
--- a/netwerk/protocol/http/InterceptedHttpChannel.cpp
+++ b/netwerk/protocol/http/InterceptedHttpChannel.cpp
@@ -147,17 +147,17 @@ void InterceptedHttpChannel::AsyncOpenIn
   }
 
   rv = controller->ChannelIntercepted(this);
   NS_ENSURE_SUCCESS_VOID(rv);
 }
 
 bool InterceptedHttpChannel::ShouldRedirect() const {
   // Determine if the synthetic response requires us to perform a real redirect.
-  return nsHttpChannel::WillRedirect(mResponseHead) &&
+  return nsHttpChannel::WillRedirect(*mResponseHead) &&
          !mLoadInfo->GetDontFollowRedirects();
 }
 
 nsresult InterceptedHttpChannel::FollowSyntheticRedirect() {
   // Perform a real redirect based on the synthetic response.
 
   nsCOMPtr<nsIIOService> ioService;
   nsresult rv = gHttpHandler->GetIOService(getter_AddRefs(ioService));
@@ -228,17 +228,17 @@ nsresult InterceptedHttpChannel::Redirec
   nsresult rv = NS_OK;
 
   // We want to pass ownership of the body callback to the new synthesized
   // channel.  We need to hold a reference to the callbacks on the stack
   // as well, though, so we can call them if a failure occurs.
   nsCOMPtr<nsIInterceptedBodyCallback> bodyCallback = mBodyCallback.forget();
 
   RefPtr<InterceptedHttpChannel> newChannel = CreateForSynthesis(
-      mResponseHead, mBodyReader, bodyCallback, mChannelCreationTime,
+      mResponseHead.get(), mBodyReader, bodyCallback, mChannelCreationTime,
       mChannelCreationTimestamp, mAsyncOpenTime);
 
   // If the response has been redirected, propagate all the URLs to content.
   // Thus, the exact value of the redirect flag does not matter as long as it's
   // not REDIRECT_INTERNAL.
   uint32_t flags = aResponseRedirected ? nsIChannelEventSink::REDIRECT_TEMPORARY
                                        : nsIChannelEventSink::REDIRECT_INTERNAL;
 
@@ -447,17 +447,17 @@ InterceptedHttpChannel::CreateForSynthes
   MOZ_DIAGNOSTIC_ASSERT(aBody);
 
   // Create an InterceptedHttpChannel that already has a synthesized response.
   // The synthetic response will be processed when opened.  A FetchEvent
   // will not be triggered.
   RefPtr<InterceptedHttpChannel> ref = new InterceptedHttpChannel(
       aCreationTime, aCreationTimestamp, aAsyncOpenTimestamp);
 
-  ref->mResponseHead = new nsHttpResponseHead(*aHead);
+  ref->mResponseHead = MakeUnique<nsHttpResponseHead>(*aHead);
   ref->mBodyReader = aBody;
   ref->mBodyCallback = aBodyCallback;
 
   return ref.forget();
 }
 
 NS_IMETHODIMP
 InterceptedHttpChannel::Cancel(nsresult aStatus) {
@@ -736,17 +736,17 @@ InterceptedHttpChannel::StartSynthesized
   aBodyCallback = nullptr;
 
   mSynthesizedCacheInfo = aSynthesizedCacheInfo;
 
   if (!mSynthesizedResponseHead) {
     mSynthesizedResponseHead.reset(new nsHttpResponseHead());
   }
 
-  mResponseHead = mSynthesizedResponseHead.release();
+  mResponseHead = std::move(mSynthesizedResponseHead);
 
   if (ShouldRedirect()) {
     rv = FollowSyntheticRedirect();
     NS_ENSURE_SUCCESS(rv, rv);
 
     return NS_OK;
   }
 
--- a/netwerk/protocol/http/PSpdyPush.h
+++ b/netwerk/protocol/http/PSpdyPush.h
@@ -20,17 +20,16 @@
   Pushed streams are subject to aggressive flow control before they are matched
   with a GET at which point flow control is effectively disabled to match the
   client pull behavior.
 */
 
 #ifndef mozilla_net_SpdyPush_Public_h
 #define mozilla_net_SpdyPush_Public_h
 
-#include "nsAutoPtr.h"
 #include "nsDataHashtable.h"
 #include "nsISupports.h"
 #include "nsStringFwd.h"
 
 namespace mozilla {
 namespace net {
 
 class Http2PushedStream;
--- a/netwerk/protocol/http/ParentChannelListener.cpp
+++ b/netwerk/protocol/http/ParentChannelListener.cpp
@@ -349,17 +349,17 @@ void ParentChannelListener::DivertTo(nsI
   mInterceptCanceled = false;
 
   mNextListener = aListener;
   ResumeForDiversion();
 }
 
 void ParentChannelListener::SetupInterception(
     const nsHttpResponseHead& aResponseHead) {
-  mSynthesizedResponseHead = new nsHttpResponseHead(aResponseHead);
+  mSynthesizedResponseHead = MakeUnique<nsHttpResponseHead>(aResponseHead);
   mShouldIntercept = true;
 }
 
 void ParentChannelListener::SetupInterceptionAfterRedirect(
     bool aShouldIntercept) {
   mShouldIntercept = aShouldIntercept;
   if (mShouldIntercept) {
     // When an interception occurs, this channel should suspend all further
--- a/netwerk/protocol/http/ParentChannelListener.h
+++ b/netwerk/protocol/http/ParentChannelListener.h
@@ -75,17 +75,17 @@ class ParentChannelListener final : publ
   bool mShouldIntercept;
   // Set if this channel should suspend on interception.
   bool mShouldSuspendIntercept;
   // Set if the channel interception has been canceled.  Can be set before
   // interception first occurs.  In this case cancelation is deferred until
   // the interception takes place.
   bool mInterceptCanceled;
 
-  nsAutoPtr<nsHttpResponseHead> mSynthesizedResponseHead;
+  UniquePtr<nsHttpResponseHead> mSynthesizedResponseHead;
 
   // Handle to the channel wrapper if this channel has been intercepted.
   nsCOMPtr<nsIInterceptedChannel> mInterceptedChannel;
 
   // This will be populated with a real network controller if parent-side
   // interception is enabled.
   nsCOMPtr<nsINetworkInterceptController> mInterceptController;
 
--- a/netwerk/protocol/http/nsCORSListenerProxy.cpp
+++ b/netwerk/protocol/http/nsCORSListenerProxy.cpp
@@ -180,20 +180,20 @@ class nsPreflightCache {
 };
 
 // Will be initialized in EnsurePreflightCache.
 static nsPreflightCache* sPreflightCache = nullptr;
 
 static bool EnsurePreflightCache() {
   if (sPreflightCache) return true;
 
-  nsAutoPtr<nsPreflightCache> newCache(new nsPreflightCache());
+  UniquePtr<nsPreflightCache> newCache(new nsPreflightCache());
 
   if (newCache->Initialize()) {
-    sPreflightCache = newCache.forget();
+    sPreflightCache = newCache.release();
     return true;
   }
 
   return false;
 }
 
 void nsPreflightCache::CacheEntry::PurgeExpired(TimeStamp now) {
   for (uint32_t i = 0, len = mMethods.Length(); i < len; ++i) {
--- a/netwerk/protocol/http/nsHttp.h
+++ b/netwerk/protocol/http/nsHttp.h
@@ -4,17 +4,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsHttp_h__
 #define nsHttp_h__
 
 #include <stdint.h>
 #include "prtime.h"
-#include "nsAutoPtr.h"
 #include "nsString.h"
 #include "nsError.h"
 #include "nsTArray.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/UniquePtr.h"
 
 class nsICacheEntry;
 
--- a/netwerk/protocol/http/nsHttpActivityDistributor.cpp
+++ b/netwerk/protocol/http/nsHttpActivityDistributor.cpp
@@ -4,17 +4,16 @@
 
 // HttpLog.h should generally be included first
 #include "HttpLog.h"
 
 #include "mozilla/net/SocketProcessChild.h"
 #include "mozilla/net/SocketProcessParent.h"
 #include "nsHttpActivityDistributor.h"
 #include "nsCOMPtr.h"
-#include "nsAutoPtr.h"
 #include "nsIOService.h"
 #include "nsThreadUtils.h"
 #include "NullHttpChannel.h"
 
 namespace mozilla {
 namespace net {
 
 typedef nsMainThreadPtrHolder<nsIHttpActivityObserver> ObserverHolder;
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -291,19 +291,19 @@ bool IsInSubpathOfAppCacheManifest(nsIAp
 
   return StringBeginsWith(directory, manifestDirectory);
 }
 
 }  // unnamed namespace
 
 // We only treat 3xx responses as redirects if they have a Location header and
 // the status code is in a whitelist.
-bool nsHttpChannel::WillRedirect(nsHttpResponseHead* response) {
-  return IsRedirectStatus(response->Status()) &&
-         response->HasHeader(nsHttp::Location);
+bool nsHttpChannel::WillRedirect(const nsHttpResponseHead& response) {
+  return IsRedirectStatus(response.Status()) &&
+         response.HasHeader(nsHttp::Location);
 }
 
 nsresult StoreAuthorizationMetaData(nsICacheEntry* entry,
                                     nsHttpRequestHead* requestHead);
 
 class AutoRedirectVetoNotifier {
  public:
   explicit AutoRedirectVetoNotifier(nsHttpChannel* channel)
@@ -1868,23 +1868,23 @@ nsresult nsHttpChannel::CallOnStartReque
     if (mListener) {
       nsCOMPtr<nsIStreamListener> deleteProtector(mListener);
       mOnStartRequestCalled = true;
       deleteProtector->OnStartRequest(this);
     }
     mOnStartRequestCalled = true;
   });
 
-  nsresult rv = EnsureMIMEOfScript(this, mURI, mResponseHead, mLoadInfo);
+  nsresult rv = EnsureMIMEOfScript(this, mURI, mResponseHead.get(), mLoadInfo);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = ProcessXCTO(this, mURI, mResponseHead, mLoadInfo);
+  rv = ProcessXCTO(this, mURI, mResponseHead.get(), mLoadInfo);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  WarnWrongMIMEOfScript(this, mURI, mResponseHead, mLoadInfo);
+  WarnWrongMIMEOfScript(this, mURI, mResponseHead.get(), mLoadInfo);
 
   // Allow consumers to override our content type
   if (mLoadFlags & LOAD_CALL_CONTENT_SNIFFERS) {
     // NOTE: We can have both a txn pump and a cache pump when the cache
     // content is partial. In that case, we need to read from the cache,
     // because that's the one that has the initial contents. If that fails
     // then give the transaction pump a shot.
 
@@ -2522,17 +2522,17 @@ nsresult nsHttpChannel::ProcessResponse(
   nsCOMPtr<nsIURI> referrer = GetReferringPage();
   if (!referrer && mReferrerInfo) {
     referrer = mReferrerInfo->GetOriginalReferrer();
   }
 
   if (referrer) {
     nsCOMPtr<nsILoadContextInfo> lci = GetLoadContextInfo(this);
     mozilla::net::Predictor::UpdateCacheability(
-        referrer, mURI, httpStatus, mRequestHead, mResponseHead, lci,
+        referrer, mURI, httpStatus, mRequestHead, mResponseHead.get(), lci,
         IsThirdPartyTrackingResource());
   }
 
   // Only allow 407 (authentication required) to continue
   if (mTransaction && mTransaction->ProxyConnectFailed() && httpStatus != 407) {
     return ProcessFailedProxyConnect(httpStatus);
   }
 
@@ -3668,17 +3668,17 @@ nsresult nsHttpChannel::ProcessPartialCo
     }
   } else {
     // suspend the current transaction
     rv = mTransactionPump->Suspend();
     if (NS_FAILED(rv)) return rv;
   }
 
   // merge any new headers with the cached response headers
-  mCachedResponseHead->UpdateHeaders(mResponseHead);
+  mCachedResponseHead->UpdateHeaders(mResponseHead.get());
 
   // update the cached response head
   nsAutoCString head;
   mCachedResponseHead->Flatten(head, true);
   rv = mCacheEntry->SetMetaDataElement("response-head", head.get());
   if (NS_FAILED(rv)) return rv;
 
   // make the cached response be the current response
@@ -3811,17 +3811,17 @@ nsresult nsHttpChannel::ProcessNotModifi
          "[%s] and [%s]\n",
          lastModifiedCached.get(), lastModified304.get()));
 
     mCacheEntry->AsyncDoom(nullptr);
     Telemetry::Accumulate(Telemetry::CACHE_LM_INCONSISTENT, true);
   }
 
   // merge any new headers with the cached response headers
-  mCachedResponseHead->UpdateHeaders(mResponseHead);
+  mCachedResponseHead->UpdateHeaders(mResponseHead.get());
 
   // update the cached response head
   nsAutoCString head;
   mCachedResponseHead->Flatten(head, true);
   rv = mCacheEntry->SetMetaDataElement("response-head", head.get());
   if (NS_FAILED(rv)) return rv;
 
   // make the cached response be the current response
@@ -4266,17 +4266,17 @@ bypassCacheEntryOpen:
 
   return NS_OK;
 }
 
 nsresult nsHttpChannel::CheckPartial(nsICacheEntry* aEntry, int64_t* aSize,
                                      int64_t* aContentLength) {
   return nsHttp::CheckPartial(
       aEntry, aSize, aContentLength,
-      mCachedResponseHead ? mCachedResponseHead : mResponseHead);
+      mCachedResponseHead ? mCachedResponseHead.get() : mResponseHead.get());
 }
 
 void nsHttpChannel::UntieValidationRequest() {
   DebugOnly<nsresult> rv;
   // Make the request unconditional again.
   rv = mRequestHead.ClearHeader(nsHttp::If_Modified_Since);
   MOZ_ASSERT(NS_SUCCEEDED(rv));
   rv = mRequestHead.ClearHeader(nsHttp::If_None_Match);
@@ -4355,22 +4355,23 @@ nsHttpChannel::OnCacheEntryCheck(nsICach
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Determine if this is the first time that this cache entry
   // has been accessed during this session.
   bool fromPreviousSession =
       (gHttpHandler->SessionStartTime() > lastModifiedTime);
 
   // Get the cached HTTP response headers
-  mCachedResponseHead = new nsHttpResponseHead();
-
-  rv = nsHttp::GetHttpResponseHeadFromCacheEntry(entry, mCachedResponseHead);
+  mCachedResponseHead = MakeUnique<nsHttpResponseHead>();
+
+  rv = nsHttp::GetHttpResponseHeadFromCacheEntry(entry,
+                                                 mCachedResponseHead.get());
   NS_ENSURE_SUCCESS(rv, rv);
 
-  bool isCachedRedirect = WillRedirect(mCachedResponseHead);
+  bool isCachedRedirect = WillRedirect(*mCachedResponseHead);
 
   // Do not return 304 responses from the cache, and also do not return
   // any other non-redirect 3xx responses from the cache (see bug 759043).
   NS_ENSURE_TRUE((mCachedResponseHead->Status() / 100 != 3) || isCachedRedirect,
                  NS_ERROR_ABORT);
 
   if (mCachedResponseHead->NoStore() && mCacheEntryIsReadOnly) {
     // This prevents loading no-store responses when navigating back
@@ -4485,29 +4486,30 @@ nsHttpChannel::OnCacheEntryCheck(nsICach
   bool doValidation = false;
   bool doBackgroundValidation = false;
   bool canAddImsHeader = true;
 
   bool isForcedValid = false;
   entry->GetIsForcedValid(&isForcedValid);
 
   bool weaklyFramed, isImmutable;
-  nsHttp::DetermineFramingAndImmutability(entry, mCachedResponseHead, isHttps,
-                                          &weaklyFramed, &isImmutable);
+  nsHttp::DetermineFramingAndImmutability(entry, mCachedResponseHead.get(),
+                                          isHttps, &weaklyFramed, &isImmutable);
 
   // Cached entry is not the entity we request (see bug #633743)
   if (ResponseWouldVary(entry)) {
     LOG(("Validating based on Vary headers returning TRUE\n"));
     canAddImsHeader = false;
     doValidation = true;
   } else {
     doValidation = nsHttp::ValidationRequired(
-        isForcedValid, mCachedResponseHead, mLoadFlags, mAllowStaleCacheContent,
-        isImmutable, mCustomConditionalRequest, mRequestHead, entry,
-        cacheControlRequest, fromPreviousSession, &doBackgroundValidation);
+        isForcedValid, mCachedResponseHead.get(), mLoadFlags,
+        mAllowStaleCacheContent, isImmutable, mCustomConditionalRequest,
+        mRequestHead, entry, cacheControlRequest, fromPreviousSession,
+        &doBackgroundValidation);
   }
 
   nsAutoCString requestedETag;
   if (!doValidation &&
       NS_SUCCEEDED(mRequestHead.GetHeader(nsHttp::If_Match, requestedETag)) &&
       (methodWasGet || methodWasHead)) {
     nsAutoCString cachedETag;
     Unused << mCachedResponseHead->GetHeader(nsHttp::ETag, cachedETag);
@@ -4549,17 +4551,17 @@ nsHttpChannel::OnCacheEntryCheck(nsICach
   // a limited number of redirects (cached or not) is allowed and is
   // enforced independently of this mechanism
   if (!doValidation && isCachedRedirect) {
     nsAutoCString cacheKey;
     rv = GenerateCacheKey(mPostID, cacheKey);
     MOZ_ASSERT(NS_SUCCEEDED(rv));
 
     if (!mRedirectedCachekeys)
-      mRedirectedCachekeys = new nsTArray<nsCString>();
+      mRedirectedCachekeys = MakeUnique<nsTArray<nsCString>>();
     else if (mRedirectedCachekeys->Contains(cacheKey))
       doValidation = true;
 
     LOG(("Redirection-chain %s key %s\n",
          doValidation ? "contains" : "does not contain", cacheKey.get()));
 
     // Append cacheKey if not in the chain already
     if (!doValidation) mRedirectedCachekeys->AppendElement(cacheKey);
@@ -5029,18 +5031,18 @@ nsresult DoUpdateExpirationTime(nsHttpCh
 //
 // From section 13.2.4 of RFC2616, we compute expiration time as follows:
 //
 //    timeRemaining = freshnessLifetime - currentAge
 //    expirationTime = now + timeRemaining
 //
 nsresult nsHttpChannel::UpdateExpirationTime() {
   uint32_t expirationTime = 0;
-  nsresult rv =
-      DoUpdateExpirationTime(this, mCacheEntry, mResponseHead, expirationTime);
+  nsresult rv = DoUpdateExpirationTime(this, mCacheEntry, mResponseHead.get(),
+                                       expirationTime);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (mOfflineCacheEntry) {
     rv = mOfflineCacheEntry->SetExpirationTime(expirationTime);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
@@ -5108,17 +5110,17 @@ nsresult nsHttpChannel::OpenCacheInputSt
       return NS_ERROR_UNEXPECTED;  // XXX error code
     }
   }
 
   // Keep the conditions below in sync with the conditions in ReadFromCache.
 
   rv = NS_OK;
 
-  if (WillRedirect(mCachedResponseHead)) {
+  if (WillRedirect(*mCachedResponseHead)) {
     // Do not even try to read the entity for a redirect because we do not
     // return an entity to the application when we process redirects.
     LOG(("Will skip read of cached redirect entity\n"));
     return NS_OK;
   }
 
   if ((mLoadFlags & nsICachingChannel::LOAD_ONLY_IF_MODIFIED) &&
       !mCachedContentIsPartial) {
@@ -5352,17 +5354,17 @@ nsresult nsHttpChannel::ReadFromCache(bo
     mCacheEntry->MaybeMarkValid();
   }
 
   nsresult rv;
 
   // Keep the conditions below in sync with the conditions in
   // StartBufferingCachedEntity.
 
-  if (WillRedirect(mResponseHead)) {
+  if (WillRedirect(*mResponseHead)) {
     // TODO: Bug 759040 - We should call HandleAsyncRedirect directly here,
     // to avoid event dispatching latency.
     MOZ_ASSERT(!mCacheInputStream);
     LOG(("Skipping skip read of cached redirect entity\n"));
     return AsyncCall(&nsHttpChannel::HandleAsyncRedirect);
   }
 
   if ((mLoadFlags & LOAD_ONLY_IF_MODIFIED) && !mCachedContentIsPartial) {
@@ -5695,17 +5697,17 @@ nsresult DoAddCacheEntryHeaders(nsHttpCh
 
   // Indicate we have successfully finished setting metadata on the cache entry.
   rv = entry->MetaDataReady();
 
   return rv;
 }
 
 nsresult nsHttpChannel::AddCacheEntryHeaders(nsICacheEntry* entry) {
-  return DoAddCacheEntryHeaders(this, entry, &mRequestHead, mResponseHead,
+  return DoAddCacheEntryHeaders(this, entry, &mRequestHead, mResponseHead.get(),
                                 mSecurityInfo);
 }
 
 inline void GetAuthType(const char* challenge, nsCString& authType) {
   const char* p;
 
   // get the challenge type
   if ((p = strchr(challenge, ' ')) != nullptr)
@@ -7523,19 +7525,17 @@ nsresult nsHttpChannel::ComputeCrossOrig
 
   // Only consider Cross-Origin-Opener-Policy for toplevel document loads.
   if (mLoadInfo->GetExternalContentPolicyType() !=
       nsIContentPolicy::TYPE_DOCUMENT) {
     return NS_OK;
   }
 
   // Maybe the channel failed and we have no response head?
-  nsHttpResponseHead* head =
-      mResponseHead ? mResponseHead : mCachedResponseHead;
-  if (!head) {
+  if (!mResponseHead && !mCachedResponseHead) {
     // Not having a response head is not a hard failure at the point where
     // this method is called.
     return NS_OK;
   }
 
   RefPtr<mozilla::dom::BrowsingContext> ctx;
   mLoadInfo->GetBrowsingContext(getter_AddRefs(ctx));
 
@@ -9240,17 +9240,17 @@ nsresult nsHttpChannel::OfflineCacheEntr
 
   return mApplicationCache->MarkEntry(spec, nsIApplicationCache::ITEM_FOREIGN);
 }
 
 NS_IMETHODIMP
 nsHttpChannel::MarkOfflineCacheEntryAsForeign() {
   nsresult rv;
 
-  nsAutoPtr<OfflineCacheEntryAsForeignMarker> marker(
+  UniquePtr<OfflineCacheEntryAsForeignMarker> marker(
       GetOfflineCacheEntryAsForeignMarker());
 
   if (!marker) return NS_ERROR_NOT_AVAILABLE;
 
   rv = marker->MarkAsForeign();
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
--- a/netwerk/protocol/http/nsHttpChannel.h
+++ b/netwerk/protocol/http/nsHttpChannel.h
@@ -135,17 +135,17 @@ class nsHttpChannel final : public HttpB
   Init(nsIURI* aURI, uint32_t aCaps, nsProxyInfo* aProxyInfo,
        uint32_t aProxyResolveFlags, nsIURI* aProxyURI, uint64_t aChannelId,
        nsContentPolicyType aContentPolicyType) override;
 
   MOZ_MUST_USE nsresult OnPush(uint32_t aPushedStreamId, const nsACString& aUrl,
                                const nsACString& aRequestString);
 
   static bool IsRedirectStatus(uint32_t status);
-  static bool WillRedirect(nsHttpResponseHead* response);
+  static bool WillRedirect(const nsHttpResponseHead& response);
 
   // Methods HttpBaseChannel didn't implement for us or that we override.
   //
   // nsIRequest
   NS_IMETHOD Cancel(nsresult status) override;
   NS_IMETHOD Suspend() override;
   NS_IMETHOD Resume() override;
   // nsIChannel
@@ -627,17 +627,17 @@ class nsHttpChannel final : public HttpB
   // but only if the listener wants to use alt-data (signaled by
   // HttpBaseChannel::mPreferredCachedAltDataType being not empty)
   // Needed because calling openAlternativeOutputStream needs a reference
   // to the cache entry.
   nsCOMPtr<nsICacheEntry> mAltDataCacheEntry;
   // We must close mCacheInputStream explicitly to avoid leaks.
   AutoClose<nsIInputStream> mCacheInputStream;
   RefPtr<nsInputStreamPump> mCachePump;
-  nsAutoPtr<nsHttpResponseHead> mCachedResponseHead;
+  UniquePtr<nsHttpResponseHead> mCachedResponseHead;
   nsCOMPtr<nsISupports> mCachedSecurityInfo;
   uint32_t mPostID;
   uint32_t mRequestTime;
 
   nsCOMPtr<nsICacheEntry> mOfflineCacheEntry;
   uint32_t mOfflineCacheLastModifiedTime;
 
   mozilla::TimeStamp mOnStartRequestTimestamp;
--- a/netwerk/protocol/http/nsHttpChunkedDecoder.cpp
+++ b/netwerk/protocol/http/nsHttpChunkedDecoder.cpp
@@ -106,17 +106,17 @@ nsresult nsHttpChunkedDecoder::ParseChun
       count = mLineBuf.Length();
     }
 
     if (mWaitEOF) {
       if (*buf) {
         LOG(("got trailer: %s\n", buf));
         // allocate a header array for the trailers on demand
         if (!mTrailers) {
-          mTrailers = new nsHttpHeaderArray();
+          mTrailers = MakeUnique<nsHttpHeaderArray>();
         }
 
         nsHttpAtom hdr;
         nsAutoCString headerNameOriginal;
         nsAutoCString val;
         if (NS_SUCCEEDED(
                 mTrailers->ParseHeaderLine(nsDependentCSubstring(buf, count),
                                            &hdr, &headerNameOriginal, &val))) {
--- a/netwerk/protocol/http/nsHttpChunkedDecoder.h
+++ b/netwerk/protocol/http/nsHttpChunkedDecoder.h
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsHttpChunkedDecoder_h__
 #define nsHttpChunkedDecoder_h__
 
-#include "nsAutoPtr.h"
 #include "nsError.h"
 #include "nsString.h"
 #include "nsHttpHeaderArray.h"
 
 namespace mozilla {
 namespace net {
 
 class nsHttpChunkedDecoder {
@@ -27,27 +26,27 @@ class nsHttpChunkedDecoder {
 
   // called by the transaction to handle chunked content.
   MOZ_MUST_USE nsresult HandleChunkedContent(char* buf, uint32_t count,
                                              uint32_t* contentRead,
                                              uint32_t* contentRemaining);
 
   nsHttpHeaderArray* Trailers() { return mTrailers.get(); }
 
-  nsHttpHeaderArray* TakeTrailers() { return mTrailers.forget(); }
+  UniquePtr<nsHttpHeaderArray> TakeTrailers() { return std::move(mTrailers); }
 
   // How mush data is still missing(needs to arrive) from the current chunk.
   uint32_t GetChunkRemaining() { return mChunkRemaining; }
 
  private:
   MOZ_MUST_USE nsresult ParseChunkRemaining(char* buf, uint32_t count,
                                             uint32_t* countRead);
 
  private:
-  nsAutoPtr<nsHttpHeaderArray> mTrailers;
+  UniquePtr<nsHttpHeaderArray> mTrailers;
   uint32_t mChunkRemaining;
   nsCString mLineBuf;  // may hold a partial line
   bool mReachedEOF;
   bool mWaitEOF;
 };
 
 }  // namespace net
 }  // namespace mozilla
--- a/netwerk/protocol/http/nsHttpConnection.h
+++ b/netwerk/protocol/http/nsHttpConnection.h
@@ -5,17 +5,16 @@
 
 #ifndef nsHttpConnection_h__
 #define nsHttpConnection_h__
 
 #include "nsHttpConnectionInfo.h"
 #include "nsHttpResponseHead.h"
 #include "nsAHttpTransaction.h"
 #include "nsCOMPtr.h"
-#include "nsAutoPtr.h"
 #include "nsProxyRelease.h"
 #include "prinrval.h"
 #include "TunnelUtils.h"
 #include "mozilla/Mutex.h"
 #include "ARefBase.h"
 #include "TimingStruct.h"
 #include "HttpTrafficAnalyzer.h"
 
--- a/netwerk/protocol/http/nsHttpConnectionMgr.h
+++ b/netwerk/protocol/http/nsHttpConnectionMgr.h
@@ -8,17 +8,16 @@
 
 #include "HttpConnectionMgrShell.h"
 #include "nsHttpConnection.h"
 #include "nsHttpTransaction.h"
 #include "nsTArray.h"
 #include "nsThreadUtils.h"
 #include "nsClassHashtable.h"
 #include "nsDataHashtable.h"
-#include "nsAutoPtr.h"
 #include "mozilla/ReentrantMonitor.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Attributes.h"
 #include "ARefBase.h"
 #include "nsWeakReference.h"
 #include "TCPFastOpen.h"
 
 #include "nsINamed.h"
--- a/netwerk/protocol/http/nsHttpResponseHead.cpp
+++ b/netwerk/protocol/http/nsHttpResponseHead.cpp
@@ -67,17 +67,17 @@ nsHttpResponseHead& nsHttpResponseHead::
   return *this;
 }
 
 HttpVersion nsHttpResponseHead::Version() {
   RecursiveMutexAutoLock monitor(mRecursiveMutex);
   return mVersion;
 }
 
-uint16_t nsHttpResponseHead::Status() {
+uint16_t nsHttpResponseHead::Status() const {
   RecursiveMutexAutoLock monitor(mRecursiveMutex);
   return mStatus;
 }
 
 void nsHttpResponseHead::StatusText(nsACString& aStatusText) {
   RecursiveMutexAutoLock monitor(mRecursiveMutex);
   aStatusText = mStatusText;
 }
@@ -184,17 +184,17 @@ void nsHttpResponseHead::ClearHeaders() 
   mHeaders.Clear();
 }
 
 bool nsHttpResponseHead::HasHeaderValue(nsHttpAtom h, const char* v) {
   RecursiveMutexAutoLock monitor(mRecursiveMutex);
   return mHeaders.HasHeaderValue(h, v);
 }
 
-bool nsHttpResponseHead::HasHeader(nsHttpAtom h) {
+bool nsHttpResponseHead::HasHeader(nsHttpAtom h) const {
   RecursiveMutexAutoLock monitor(mRecursiveMutex);
   return mHeaders.HasHeader(h);
 }
 
 void nsHttpResponseHead::SetContentType(const nsACString& s) {
   RecursiveMutexAutoLock monitor(mRecursiveMutex);
   mContentType = s;
 }
--- a/netwerk/protocol/http/nsHttpResponseHead.h
+++ b/netwerk/protocol/http/nsHttpResponseHead.h
@@ -53,17 +53,17 @@ class nsHttpResponseHead {
 
   nsHttpResponseHead(const nsHttpResponseHead& aOther);
   nsHttpResponseHead& operator=(const nsHttpResponseHead& aOther);
 
   void Enter() { mRecursiveMutex.Lock(); }
   void Exit() { mRecursiveMutex.Unlock(); }
 
   HttpVersion Version();
-  uint16_t Status();
+  uint16_t Status() const;
   void StatusText(nsACString& aStatusText);
   int64_t ContentLength();
   void ContentType(nsACString& aContentType);
   void ContentCharset(nsACString& aContentCharset);
   bool Public();
   bool Private();
   bool NoStore();
   bool NoCache();
@@ -78,17 +78,17 @@ class nsHttpResponseHead {
   MOZ_MUST_USE nsresult SetHeader(const nsACString& h, const nsACString& v,
                                   bool m = false);
   MOZ_MUST_USE nsresult SetHeader(nsHttpAtom h, const nsACString& v,
                                   bool m = false);
   MOZ_MUST_USE nsresult GetHeader(nsHttpAtom h, nsACString& v);
   void ClearHeader(nsHttpAtom h);
   void ClearHeaders();
   bool HasHeaderValue(nsHttpAtom h, const char* v);
-  bool HasHeader(nsHttpAtom h);
+  bool HasHeader(nsHttpAtom h) const;
 
   void SetContentType(const nsACString& s);
   void SetContentCharset(const nsACString& s);
   void SetContentLength(int64_t);
 
   // write out the response status line and headers as a single text block,
   // optionally pruning out transient headers (ie. headers that only make
   // sense the first time the response is handled).
@@ -201,17 +201,17 @@ class nsHttpResponseHead {
   bool mCacheControlPrivate;
   bool mCacheControlNoStore;
   bool mCacheControlNoCache;
   bool mCacheControlImmutable;
   bool mPragmaNoCache;
 
   // We are using RecursiveMutex instead of a Mutex because VisitHeader
   // function calls nsIHttpHeaderVisitor::VisitHeader while under lock.
-  RecursiveMutex mRecursiveMutex;
+  mutable RecursiveMutex mRecursiveMutex;
   // During VisitHeader we sould not allow cal to SetHeader.
   bool mInVisitHeaders;
 
   friend struct IPC::ParamTraits<nsHttpResponseHead>;
 };
 
 }  // namespace net
 }  // namespace mozilla
--- a/netwerk/protocol/http/nsHttpTransaction.cpp
+++ b/netwerk/protocol/http/nsHttpTransaction.cpp
@@ -480,44 +480,42 @@ void nsHttpTransaction::SetH2WSConnRefTa
     // Need to let the websocket transaction/connection know we've reached
     // this point so it can stop forwarding information through us and
     // instead communicate directly with the websocket channel.
     mH2WSTransaction->SetConnRefTaken();
     mH2WSTransaction = nullptr;
   }
 }
 
-nsHttpResponseHead* nsHttpTransaction::TakeResponseHead() {
+UniquePtr<nsHttpResponseHead> nsHttpTransaction::TakeResponseHead() {
   MOZ_ASSERT(!mResponseHeadTaken, "TakeResponseHead called 2x");
 
   // Lock TakeResponseHead() against main thread
   MutexAutoLock lock(*nsHttp::GetLock());
 
   mResponseHeadTaken = true;
 
   // Even in OnStartRequest() the headers won't be available if we were
   // canceled
   if (!mHaveAllHeaders) {
     NS_WARNING("response headers not available or incomplete");
     return nullptr;
   }
 
-  nsHttpResponseHead* head = mResponseHead;
-  mResponseHead = nullptr;
-  return head;
+  return WrapUnique(std::exchange(mResponseHead, nullptr));
 }
 
-nsHttpHeaderArray* nsHttpTransaction::TakeResponseTrailers() {
+UniquePtr<nsHttpHeaderArray> nsHttpTransaction::TakeResponseTrailers() {
   MOZ_ASSERT(!mResponseTrailersTaken, "TakeResponseTrailers called 2x");
 
   // Lock TakeResponseTrailers() against main thread
   MutexAutoLock lock(*nsHttp::GetLock());
 
   mResponseTrailersTaken = true;
-  return mForTakeResponseTrailers.forget();
+  return std::move(mForTakeResponseTrailers);
 }
 
 void nsHttpTransaction::SetProxyConnectFailed() { mProxyConnectFailed = true; }
 
 nsHttpRequestHead* nsHttpTransaction::RequestHead() { return mRequestHead; }
 
 uint32_t nsHttpTransaction::Http1xTransactionCount() { return 1; }
 
@@ -2459,17 +2457,17 @@ void nsHttpTransaction::Refused0RTT() {
   }
 }
 
 void nsHttpTransaction::SetHttpTrailers(nsCString& aTrailers) {
   LOG(("nsHttpTransaction::SetHttpTrailers %p", this));
   LOG(("[\n    %s\n]", aTrailers.BeginReading()));
 
   // Introduce a local variable to minimize the critical section.
-  nsAutoPtr<nsHttpHeaderArray> httpTrailers(new nsHttpHeaderArray());
+  UniquePtr<nsHttpHeaderArray> httpTrailers(new nsHttpHeaderArray());
   // Given it's usually null, use double-check locking for performance.
   if (mForTakeResponseTrailers) {
     MutexAutoLock lock(*nsHttp::GetLock());
     if (mForTakeResponseTrailers) {
       // Copy the trailer. |TakeResponseTrailers| gets the original trailer
       // until the final swap.
       *httpTrailers = *mForTakeResponseTrailers;
     }
--- a/netwerk/protocol/http/nsHttpTransaction.h
+++ b/netwerk/protocol/http/nsHttpTransaction.h
@@ -331,17 +331,17 @@ class nsHttpTransaction final : public n
   // mResponseComplete := transaction ran to completion
 
   // For Restart-In-Progress Functionality
   bool mReportedStart;
   bool mReportedResponseHeader;
 
   // protected by nsHttp::GetLock()
   bool mResponseHeadTaken;
-  nsAutoPtr<nsHttpHeaderArray> mForTakeResponseTrailers;
+  UniquePtr<nsHttpHeaderArray> mForTakeResponseTrailers;
   bool mResponseTrailersTaken;
 
   // The time when the transaction was submitted to the Connection Manager
   TimeStamp mPendingTime;
 
   uint64_t mTopLevelOuterContentWindowId;
 
   // For Rate Pacing via an EventTokenBucket
--- a/netwerk/protocol/websocket/BaseWebSocketChannel.cpp
+++ b/netwerk/protocol/websocket/BaseWebSocketChannel.cpp
@@ -5,17 +5,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebSocketLog.h"
 #include "BaseWebSocketChannel.h"
 #include "MainThreadUtils.h"
 #include "nsILoadGroup.h"
 #include "nsINode.h"
 #include "nsIInterfaceRequestor.h"
-#include "nsAutoPtr.h"
 #include "nsProxyRelease.h"
 #include "nsStandardURL.h"
 #include "LoadInfo.h"
 #include "mozilla/dom/ContentChild.h"
 #include "nsITransportProvider.h"
 
 using mozilla::dom::ContentChild;
 
--- a/netwerk/protocol/websocket/WebSocketChannel.cpp
+++ b/netwerk/protocol/websocket/WebSocketChannel.cpp
@@ -35,17 +35,16 @@
 #include "nsIProtocolHandler.h"
 #include "nsIRandomGenerator.h"
 #include "nsISocketTransport.h"
 #include "nsThreadUtils.h"
 #include "nsINetworkLinkService.h"
 #include "nsIObserverService.h"
 #include "nsCharSeparatedTokenizer.h"
 
-#include "nsAutoPtr.h"
 #include "nsNetCID.h"
 #include "nsServiceManagerUtils.h"
 #include "nsCRT.h"
 #include "nsThreadUtils.h"
 #include "nsError.h"
 #include "nsStringStream.h"
 #include "nsAlgorithm.h"
 #include "nsProxyRelease.h"
@@ -987,27 +986,27 @@ class OutboundMessage {
     return (uint8_t*)(mMsg.pString.mOrigValue
                           ? mMsg.pString.mOrigValue->BeginReading()
                           : nullptr);
   }
 
   nsresult ConvertStreamToString() {
     MOZ_ASSERT(mMsgType == kMsgTypeStream, "Not a stream!");
 
-    nsAutoPtr<nsCString> temp(new nsCString());
+    UniquePtr<nsCString> temp(new nsCString());
     nsresult rv = NS_ReadInputStreamToString(mMsg.pStream, *temp, mLength);
 
     NS_ENSURE_SUCCESS(rv, rv);
     if (temp->Length() != mLength) {
       return NS_ERROR_UNEXPECTED;
     }
 
     mMsg.pStream->Close();
     mMsg.pStream->Release();
-    mMsg.pString.mValue = temp.forget();
+    mMsg.pString.mValue = temp.release();
     mMsg.pString.mOrigValue = nullptr;
     mMsgType = kMsgTypeBinaryString;
 
     return NS_OK;
   }
 
   bool DeflatePayload(PMCECompression* aCompressor) {
     MOZ_ASSERT(mMsgType != kMsgTypeStream,
@@ -1016,17 +1015,17 @@ class OutboundMessage {
 
     nsresult rv;
 
     if (mLength == 0) {
       // Empty message
       return false;
     }
 
-    nsAutoPtr<nsCString> temp(new nsCString());
+    UniquePtr<nsCString> temp(new nsCString());
     rv = aCompressor->Deflate(BeginReading(), mLength, *temp);
     if (NS_FAILED(rv)) {
       LOG(
           ("WebSocketChannel::OutboundMessage: Deflating payload failed "
            "[rv=0x%08" PRIx32 "]\n",
            static_cast<uint32_t>(rv)));
       return false;
     }
@@ -1045,17 +1044,17 @@ class OutboundMessage {
            temp->Length(), mLength));
       return false;
     }
 
     mOrigLength = mLength;
     mDeflated = true;
     mLength = temp->Length();
     mMsg.pString.mOrigValue = mMsg.pString.mValue;
-    mMsg.pString.mValue = temp.forget();
+    mMsg.pString.mValue = temp.release();
     return true;
   }
 
  private:
   union {
     struct {
       nsCString* mValue;
       nsCString* mOrigValue;
@@ -2052,17 +2051,17 @@ void WebSocketChannel::PrimeNewOutgoingM
       case kMsgTypeFin:
         MOZ_ASSERT(false, "unreachable");  // avoid compiler warning
         break;
     }
 
     // deflate the payload if PMCE is negotiated
     if (mPMCECompressor &&
         (msgType == kMsgTypeString || msgType == kMsgTypeBinaryString)) {
-      if (mCurrentOut->DeflatePayload(mPMCECompressor)) {
+      if (mCurrentOut->DeflatePayload(mPMCECompressor.get())) {
         // The payload was deflated successfully, set RSV1 bit
         mOutHeader[0] |= kRsv1Bit;
 
         LOG(
             ("WebSocketChannel::PrimeNewOutgoingMessage %p current msg %p was "
              "deflated [origLength=%d, newLength=%d].\n",
              this, mCurrentOut, mCurrentOut->OrigLength(),
              mCurrentOut->Length()));
@@ -2600,17 +2599,17 @@ nsresult WebSocketChannel::HandleExtensi
 
   if (clientMaxWindowBits == -1) {
     clientMaxWindowBits = 15;
   }
   if (serverMaxWindowBits == -1) {
     serverMaxWindowBits = 15;
   }
 
-  mPMCECompressor = new PMCECompression(
+  mPMCECompressor = MakeUnique<PMCECompression>(
       clientNoContextTakeover, clientMaxWindowBits, serverMaxWindowBits);
   if (mPMCECompressor->Active()) {
     LOG(
         ("WebSocketChannel::HandleExtensions: PMCE negotiated, %susing "
          "context takeover, clientMaxWindowBits=%d, "
          "serverMaxWindowBits=%d\n",
          clientNoContextTakeover ? "NOT " : "", clientMaxWindowBits,
          serverMaxWindowBits));
@@ -3614,17 +3613,17 @@ WebSocketChannel::OnTransportAvailable(n
 
       if (clientMaxWindowBits == -1) {
         clientMaxWindowBits = 15;
       }
       if (serverMaxWindowBits == -1) {
         serverMaxWindowBits = 15;
       }
 
-      mPMCECompressor = new PMCECompression(
+      mPMCECompressor = MakeUnique<PMCECompression>(
           serverNoContextTakeover, serverMaxWindowBits, clientMaxWindowBits);
       if (mPMCECompressor->Active()) {
         LOG(
             ("WebSocketChannel::OnTransportAvailable: PMCE negotiated, %susing "
              "context takeover, serverMaxWindowBits=%d, "
              "clientMaxWindowBits=%d\n",
              serverNoContextTakeover ? "NOT " : "", serverMaxWindowBits,
              clientMaxWindowBits));
--- a/netwerk/protocol/websocket/WebSocketChannel.h
+++ b/netwerk/protocol/websocket/WebSocketChannel.h
@@ -285,17 +285,17 @@ class WebSocketChannel : public BaseWebS
   OutboundMessage* mCurrentOut;
   uint32_t mCurrentOutSent;
   nsDeque mOutgoingMessages;
   nsDeque mOutgoingPingMessages;
   nsDeque mOutgoingPongMessages;
   uint32_t mHdrOutToSend;
   uint8_t* mHdrOut;
   uint8_t mOutHeader[kCopyBreak + 16];
-  nsAutoPtr<PMCECompression> mPMCECompressor;
+  UniquePtr<PMCECompression> mPMCECompressor;
   uint32_t mDynamicOutputSize;
   uint8_t* mDynamicOutput;
   bool mPrivateBrowsing;
 
   nsCOMPtr<nsIDashboardEventNotifier> mConnectionLogService;
 
   mozilla::Mutex mMutex;
 };
--- a/netwerk/protocol/websocket/WebSocketChannelChild.cpp
+++ b/netwerk/protocol/websocket/WebSocketChannelChild.cpp
@@ -124,45 +124,45 @@ class WebSocketEvent {
   WebSocketEvent() { MOZ_COUNT_CTOR(WebSocketEvent); }
   virtual ~WebSocketEvent() { MOZ_COUNT_DTOR(WebSocketEvent); }
   virtual void Run(WebSocketChannelChild* aChild) = 0;
 };
 
 class WrappedWebSocketEvent : public Runnable {
  public:
   WrappedWebSocketEvent(WebSocketChannelChild* aChild,
-                        WebSocketEvent* aWebSocketEvent)
+                        UniquePtr<WebSocketEvent>&& aWebSocketEvent)
       : Runnable("net::WrappedWebSocketEvent"),
         mChild(aChild),
-        mWebSocketEvent(aWebSocketEvent) {
-    MOZ_RELEASE_ASSERT(aWebSocketEvent);
+        mWebSocketEvent(std::move(aWebSocketEvent)) {
+    MOZ_RELEASE_ASSERT(!!mWebSocketEvent);
   }
   NS_IMETHOD Run() override {
     mWebSocketEvent->Run(mChild);
     return NS_OK;
   }
 
  private:
   RefPtr<WebSocketChannelChild> mChild;
-  nsAutoPtr<WebSocketEvent> mWebSocketEvent;
+  UniquePtr<WebSocketEvent> mWebSocketEvent;
 };
 
 class EventTargetDispatcher : public ChannelEvent {
  public:
   EventTargetDispatcher(WebSocketChannelChild* aChild,
                         WebSocketEvent* aWebSocketEvent,
                         nsIEventTarget* aEventTarget)
       : mChild(aChild),
         mWebSocketEvent(aWebSocketEvent),
         mEventTarget(aEventTarget) {}
 
   void Run() override {
     if (mEventTarget) {
       mEventTarget->Dispatch(
-          new WrappedWebSocketEvent(mChild, mWebSocketEvent.forget()),
+          new WrappedWebSocketEvent(mChild, std::move(mWebSocketEvent)),
           NS_DISPATCH_NORMAL);
       return;
     }
 
     mWebSocketEvent->Run(mChild);
   }
 
   already_AddRefed<nsIEventTarget> GetEventTarget() override {
@@ -171,17 +171,17 @@ class EventTargetDispatcher : public Cha
       target = GetMainThreadEventTarget();
     }
     return target.forget();
   }
 
  private:
   // The lifetime of the child is ensured by ChannelEventQueue.
   WebSocketChannelChild* mChild;
-  nsAutoPtr<WebSocketEvent> mWebSocketEvent;
+  UniquePtr<WebSocketEvent> mWebSocketEvent;
   nsCOMPtr<nsIEventTarget> mEventTarget;
 };
 
 class StartEvent : public WebSocketEvent {
  public:
   StartEvent(const nsCString& aProtocol, const nsCString& aExtensions,
              const nsString& aEffectiveURL, bool aEncrypted,
              uint64_t aHttpChannelId)
--- a/netwerk/protocol/websocket/WebSocketEventService.h
+++ b/netwerk/protocol/websocket/WebSocketEventService.h
@@ -5,17 +5,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_net_WebSocketEventService_h
 #define mozilla_net_WebSocketEventService_h
 
 #include "mozilla/AlreadyAddRefed.h"
 #include "mozilla/Atomics.h"
 #include "nsIWebSocketEventService.h"
-#include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsClassHashtable.h"
 #include "nsHashKeys.h"
 #include "nsIObserver.h"
 #include "nsISupportsImpl.h"
 #include "nsTArray.h"
 
 namespace mozilla {
--- a/netwerk/protocol/websocket/WebSocketFrame.h
+++ b/netwerk/protocol/websocket/WebSocketFrame.h
@@ -4,17 +4,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_net_WebSocketFrame_h
 #define mozilla_net_WebSocketFrame_h
 
 #include "nsIWebSocketEventService.h"
 
-#include "nsAutoPtr.h"
 #include "nsIWebSocketEventService.h"
 #include "nsString.h"
 
 namespace IPC {
 class Message;
 }
 
 namespace mozilla {
--- a/netwerk/sctp/datachannel/DataChannel.cpp
+++ b/netwerk/sctp/datachannel/DataChannel.cpp
@@ -35,17 +35,16 @@
 #include "nsIObserver.h"
 #include "nsIPrefBranch.h"
 #include "nsIPrefService.h"
 #include "mozilla/Services.h"
 #include "mozilla/Sprintf.h"
 #include "nsProxyRelease.h"
 #include "nsThread.h"
 #include "nsThreadUtils.h"
-#include "nsAutoPtr.h"
 #include "nsNetUtil.h"
 #include "nsNetCID.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/StaticMutex.h"
 #include "mozilla/Unused.h"
 #ifdef MOZ_PEERCONNECTION
 #  include "mtransport/runnable_utils.h"
 #  include "signaling/src/peerconnection/MediaTransportHandler.h"
@@ -1327,17 +1326,17 @@ bool DataChannelConnection::SendDeferred
   }
   return blocked;
 }
 
 // Called with mLock locked!
 // buffer MUST have at least one item!
 // returns if we're still blocked (true)
 bool DataChannelConnection::SendBufferedMessages(
-    nsTArray<nsAutoPtr<BufferedOutgoingMsg>>& buffer, size_t* aWritten) {
+    nsTArray<UniquePtr<BufferedOutgoingMsg>>& buffer, size_t* aWritten) {
   do {
     // Re-send message
     int error = SendMsgInternal(*buffer[0], aWritten);
     switch (error) {
       case 0:
         buffer.RemoveElementAt(0);
         break;
       case EAGAIN:
@@ -2564,17 +2563,17 @@ out:
 
   return error;
 }
 
 // Requires mLock to be locked!
 // Returns a POSIX error code directly instead of setting errno.
 // IMPORTANT: Ensure that the buffer passed is guarded by mLock!
 int DataChannelConnection::SendMsgInternalOrBuffer(
-    nsTArray<nsAutoPtr<BufferedOutgoingMsg>>& buffer, OutgoingMsg& msg,
+    nsTArray<UniquePtr<BufferedOutgoingMsg>>& buffer, OutgoingMsg& msg,
     bool& buffered, size_t* aWritten) {
   NS_WARNING_ASSERTION(msg.GetLength() > 0, "Length is 0?!");
 
   int error = 0;
   bool need_buffering = false;
 
   // Note: Main-thread IO, but doesn't block!
   // XXX FIX!  to deal with heavy overruns of JS trying to pass data in
--- a/netwerk/sctp/datachannel/DataChannel.h
+++ b/netwerk/sctp/datachannel/DataChannel.h
@@ -12,16 +12,17 @@
 #endif
 
 #include <memory>
 #include <string>
 #include <vector>
 #include <errno.h>
 #include "nsISupports.h"
 #include "nsCOMPtr.h"
+#include "mozilla/UniquePtr.h"
 #include "mozilla/WeakPtr.h"
 #include "nsString.h"
 #include "nsThreadUtils.h"
 #include "nsTArray.h"
 #include "nsDeque.h"
 #include "mozilla/dom/Blob.h"
 #include "mozilla/Mutex.h"
 #include "DataChannelProtocol.h"
@@ -252,20 +253,20 @@ class DataChannelConnection final : publ
   uint32_t UpdateCurrentStreamIndex();
   uint32_t GetCurrentStreamIndex();
   int SendControlMessage(const uint8_t* data, uint32_t len, uint16_t stream);
   int SendOpenAckMessage(uint16_t stream);
   int SendOpenRequestMessage(const nsACString& label,
                              const nsACString& protocol, uint16_t stream,
                              bool unordered, uint16_t prPolicy,
                              uint32_t prValue);
-  bool SendBufferedMessages(nsTArray<nsAutoPtr<BufferedOutgoingMsg>>& buffer,
+  bool SendBufferedMessages(nsTArray<UniquePtr<BufferedOutgoingMsg>>& buffer,
                             size_t* aWritten);
   int SendMsgInternal(OutgoingMsg& msg, size_t* aWritten);
-  int SendMsgInternalOrBuffer(nsTArray<nsAutoPtr<BufferedOutgoingMsg>>& buffer,
+  int SendMsgInternalOrBuffer(nsTArray<UniquePtr<BufferedOutgoingMsg>>& buffer,
                               OutgoingMsg& msg, bool& buffered,
                               size_t* aWritten);
   int SendDataMsgInternalOrBuffer(DataChannel& channel, const uint8_t* data,
                                   size_t len, uint32_t ppid);
   int SendDataMsg(DataChannel& channel, const uint8_t* data, size_t len,
                   uint32_t ppidPartial, uint32_t ppidFinal);
   int SendDataMsgCommon(uint16_t stream, const nsACString& aMsg, bool isBinary);
 
@@ -351,19 +352,19 @@ class DataChannelConnection final : publ
   Channels mChannels;
   // STS only
   uint32_t mCurrentStream = 0;
   nsDeque mPending;  // Holds addref'ed DataChannel's -- careful!
   // STS and main
   size_t mNegotiatedIdLimit = 0;  // GUARDED_BY(mConnection->mLock)
   uint8_t mPendingType = PENDING_NONE;
   // holds data that's come in before a channel is open
-  nsTArray<nsAutoPtr<QueuedDataMessage>> mQueuedData;
+  nsTArray<UniquePtr<QueuedDataMessage>> mQueuedData;
   // holds outgoing control messages
-  nsTArray<nsAutoPtr<BufferedOutgoingMsg>>
+  nsTArray<UniquePtr<BufferedOutgoingMsg>>
       mBufferedControl;  // GUARDED_BY(mConnection->mLock)
 
   // Streams pending reset. Accessed from main and STS.
   AutoTArray<uint16_t, 4> mStreamsResetting;  // GUARDED_BY(mConnection->mLock)
   // accessed from STS thread
   struct socket* mMasterSocket = nullptr;
   // cloned from mMasterSocket on successful Connect on STS thread
   struct socket* mSocket = nullptr;
@@ -528,17 +529,17 @@ class DataChannel {
   const bool mOrdered;
   uint32_t mFlags;
   bool mIsRecvBinary;
   size_t mBufferedThreshold;
   // Read/written on main only. Decremented via message-passing, because the
   // spec requires us to queue a task for this.
   size_t mBufferedAmount;
   nsCString mRecvBuffer;
-  nsTArray<nsAutoPtr<BufferedOutgoingMsg>>
+  nsTArray<UniquePtr<BufferedOutgoingMsg>>
       mBufferedData;  // GUARDED_BY(mConnection->mLock)
   nsCOMPtr<nsIEventTarget> mMainThreadEventTarget;
 };
 
 // used to dispatch notifications of incoming data to the main thread
 // Patterned on CallOnMessageAvailable in WebSockets
 // Also used to proxy other items to MainThread
 class DataChannelOnMessageAvailable : public Runnable {
--- a/netwerk/streamconv/converters/nsHTTPCompressConv.cpp
+++ b/netwerk/streamconv/converters/nsHTTPCompressConv.cpp
@@ -468,17 +468,17 @@ nsHTTPCompressConv::OnDataAvailable(nsIR
             return NS_ERROR_INVALID_CONTENT_ENCODING;
           }
         } /* for */
       }   /* gzip */
       break;
 
     case HTTP_COMPRESS_BROTLI: {
       if (!mBrotli) {
-        mBrotli = new BrotliWrapper();
+        mBrotli = MakeUnique<BrotliWrapper>();
       }
 
       mBrotli->mRequest = request;
       mBrotli->mContext = nullptr;
       mBrotli->mSourceOffset = aSourceOffset;
 
       uint32_t countRead;
       rv = iStr->ReadSegments(BrotliHandler, this, streamLen, &countRead);
--- a/netwerk/streamconv/converters/nsHTTPCompressConv.h
+++ b/netwerk/streamconv/converters/nsHTTPCompressConv.h
@@ -6,17 +6,16 @@
 
 #if !defined(__nsHTTPCompressConv__h__)
 #  define __nsHTTPCompressConv__h__ 1
 
 #  include "nsIStreamConverter.h"
 #  include "nsICompressConvStats.h"
 #  include "nsIThreadRetargetableStreamListener.h"
 #  include "nsCOMPtr.h"
-#  include "nsAutoPtr.h"
 #  include "mozilla/Atomics.h"
 #  include "mozilla/Mutex.h"
 
 #  include "zlib.h"
 
 // brotli includes
 #  undef assert
 #  include "assert.h"
@@ -99,17 +98,17 @@ class nsHTTPCompressConv : public nsIStr
   Atomic<CompressMode, Relaxed> mMode;
 
   unsigned char* mOutBuffer;
   unsigned char* mInpBuffer;
 
   uint32_t mOutBufferLen;
   uint32_t mInpBufferLen;
 
-  nsAutoPtr<BrotliWrapper> mBrotli;
+  UniquePtr<BrotliWrapper> mBrotli;
 
   nsCOMPtr<nsIStringInputStream> mStream;
 
   static nsresult BrotliHandler(nsIInputStream* stream, void* closure,
                                 const char* dataIn, uint32_t, uint32_t avail,
                                 uint32_t* countRead);
 
   nsresult do_OnDataAvailable(nsIRequest* request, nsISupports* aContext,
--- a/netwerk/streamconv/converters/nsMultiMixedConv.h
+++ b/netwerk/streamconv/converters/nsMultiMixedConv.h
@@ -6,17 +6,16 @@
 #define __nsmultimixedconv__h__
 
 #include "nsIStreamConverter.h"
 #include "nsIChannel.h"
 #include "nsString.h"
 #include "nsCOMPtr.h"
 #include "nsIByteRangeRequest.h"
 #include "nsIMultiPartChannel.h"
-#include "nsAutoPtr.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/IncrementalTokenizer.h"
 #include "nsHttpResponseHead.h"
 
 #define NS_MULTIMIXEDCONVERTER_CID                 \
   { /* 7584CE90-5B25-11d3-A175-0050041CAF44 */     \
     0x7584ce90, 0x5b25, 0x11d3, {                  \
       0xa1, 0x75, 0x0, 0x50, 0x4, 0x1c, 0xaf, 0x44 \
@@ -41,33 +40,34 @@ class nsPartChannel final : public nsICh
   void SetIsLastPart() { mIsLastPart = true; }
   nsresult SendOnStartRequest(nsISupports* aContext);
   nsresult SendOnDataAvailable(nsISupports* aContext, nsIInputStream* aStream,
                                uint64_t aOffset, uint32_t aLen);
   nsresult SendOnStopRequest(nsISupports* aContext, nsresult aStatus);
   /* SetContentDisposition expects the full value of the Content-Disposition
    * header */
   void SetContentDisposition(const nsACString& aContentDispositionHeader);
+  // TODO(ER): This appears to be dead code
   void SetResponseHead(mozilla::net::nsHttpResponseHead* head) {
-    mResponseHead = head;
+    mResponseHead.reset(head);
   }
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIREQUEST
   NS_DECL_NSICHANNEL
   NS_DECL_NSIBYTERANGEREQUEST
   NS_DECL_NSIMULTIPARTCHANNEL
 
  protected:
   ~nsPartChannel() = default;
 
  protected:
   nsCOMPtr<nsIChannel> mMultipartChannel;
   nsCOMPtr<nsIStreamListener> mListener;
-  nsAutoPtr<mozilla::net::nsHttpResponseHead> mResponseHead;
+  UniquePtr<mozilla::net::nsHttpResponseHead> mResponseHead;
 
   nsresult mStatus;
   nsLoadFlags mLoadFlags;
 
   nsCOMPtr<nsILoadGroup> mLoadGroup;
 
   nsCString mContentType;
   nsCString mContentCharset;
--- a/netwerk/streamconv/nsStreamConverterService.cpp
+++ b/netwerk/streamconv/nsStreamConverterService.cpp
@@ -2,42 +2,42 @@
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsComponentManagerUtils.h"
 #include "nsStreamConverterService.h"
 #include "nsIComponentRegistrar.h"
-#include "nsAutoPtr.h"
 #include "nsString.h"
 #include "nsAtom.h"
 #include "nsDeque.h"
 #include "nsIInputStream.h"
 #include "nsIStreamConverter.h"
 #include "nsICategoryManager.h"
 #include "nsXPCOM.h"
 #include "nsISupportsPrimitives.h"
 #include "nsCOMArray.h"
 #include "nsTArray.h"
 #include "nsServiceManagerUtils.h"
 #include "nsISimpleEnumerator.h"
+#include "mozilla/UniquePtr.h"
 
 ///////////////////////////////////////////////////////////////////
 // Breadth-First-Search (BFS) algorithm state classes and types.
 
 // Used to establish discovered verticies.
 enum BFScolors { white, gray, black };
 
 // BFS hashtable data class.
 struct BFSTableData {
   nsCString key;
   BFScolors color;
   int32_t distance;
-  nsAutoPtr<nsCString> predecessor;
+  mozilla::UniquePtr<nsCString> predecessor;
 
   explicit BFSTableData(const nsACString& aKey)
       : key(aKey), color(white), distance(-1) {}
 };
 
 ////////////////////////////////////////////////////////////
 // nsISupports methods
 NS_IMPL_ISUPPORTS(nsStreamConverterService, nsIStreamConverterService)
@@ -244,17 +244,18 @@ nsresult nsStreamConverterService::FindC
       if (!curVertexState) {
         delete curVertex;
         return NS_ERROR_FAILURE;
       }
 
       if (white == curVertexState->color) {
         curVertexState->color = gray;
         curVertexState->distance = headVertexState->distance + 1;
-        curVertexState->predecessor = new nsCString(*currentHead);
+        curVertexState->predecessor =
+            mozilla::MakeUnique<nsCString>(*currentHead);
         grayQ.Push(curVertex);
       } else {
         delete curVertex;  // if this vertex has already been discovered, we
                            // don't want to leak it. (non-discovered vertex's
                            // get cleaned up when they're popped).
       }
     }
     headVertexState->color = black;
--- a/netwerk/system/netlink/NetlinkService.cpp
+++ b/netwerk/system/netlink/NetlinkService.cpp
@@ -70,36 +70,36 @@ class NetlinkAddress {
   NetlinkAddress() {}
 
   uint8_t Family() const { return mIfam.ifa_family; }
   uint32_t GetIndex() const { return mIfam.ifa_index; }
   uint8_t GetPrefixLen() const { return mIfam.ifa_prefixlen; }
   bool ScopeIsUniverse() const { return mIfam.ifa_scope == RT_SCOPE_UNIVERSE; }
   const in_common_addr* GetAddrPtr() const { return &mAddr; }
 
-  bool MsgEquals(const NetlinkAddress* aOther) const {
-    return !memcmp(&mIfam, &(aOther->mIfam), sizeof(mIfam));
+  bool MsgEquals(const NetlinkAddress& aOther) const {
+    return !memcmp(&mIfam, &(aOther.mIfam), sizeof(mIfam));
   }
 
-  bool Equals(const NetlinkAddress* aOther) const {
-    if (mIfam.ifa_family != aOther->mIfam.ifa_family) {
+  bool Equals(const NetlinkAddress& aOther) const {
+    if (mIfam.ifa_family != aOther.mIfam.ifa_family) {
       return false;
     }
-    if (mIfam.ifa_index != aOther->mIfam.ifa_index) {
+    if (mIfam.ifa_index != aOther.mIfam.ifa_index) {
       // addresses are different when they are on a different interface
       return false;
     }
-    if (mIfam.ifa_prefixlen != aOther->mIfam.ifa_prefixlen) {
+    if (mIfam.ifa_prefixlen != aOther.mIfam.ifa_prefixlen) {
       // It's possible to have two equal addresses with a different netmask on
       // the same interface, so we need to check prefixlen too.
       return false;
     }
     size_t addrSize = (mIfam.ifa_family == AF_INET) ? sizeof(mAddr.addr4)
                                                     : sizeof(mAddr.addr6);
-    return memcmp(&mAddr, aOther->GetAddrPtr(), addrSize) == 0;
+    return memcmp(&mAddr, aOther.GetAddrPtr(), addrSize) == 0;
   }
 
   bool ContainsAddr(const in_common_addr* aAddr) {
     int32_t addrSize = (mIfam.ifa_family == AF_INET)
                            ? (int32_t)sizeof(mAddr.addr4)
                            : (int32_t)sizeof(mAddr.addr6);
     uint8_t maskit[] = {0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe};
     int32_t bits = mIfam.ifa_prefixlen;
@@ -298,78 +298,78 @@ class NetlinkRoute {
   bool HasPrefSrcAddr() const { return mHasPrefSrcAddr; }
   const in_common_addr* GetGWAddrPtr() const {
     return mHasGWAddr ? &mGWAddr : nullptr;
   }
   const in_common_addr* GetPrefSrcAddrPtr() const {
     return mHasPrefSrcAddr ? &mPrefSrcAddr : nullptr;
   }
 
-  bool Equals(const NetlinkRoute* aOther) const {
+  bool Equals(const NetlinkRoute& aOther) const {
     size_t addrSize = (mRtm.rtm_family == AF_INET) ? sizeof(mDstAddr.addr4)
                                                    : sizeof(mDstAddr.addr6);
-    if (memcmp(&mRtm, &(aOther->mRtm), sizeof(mRtm))) {
+    if (memcmp(&mRtm, &(aOther.mRtm), sizeof(mRtm))) {
       return false;
     }
-    if (mHasOif != aOther->mHasOif || mOif != aOther->mOif) {
+    if (mHasOif != aOther.mHasOif || mOif != aOther.mOif) {
       return false;
     }
-    if (mHasPrio != aOther->mHasPrio || mPrio != aOther->mPrio) {
+    if (mHasPrio != aOther.mHasPrio || mPrio != aOther.mPrio) {
       return false;
     }
-    if ((mHasGWAddr != aOther->mHasGWAddr) ||
-        (mHasGWAddr && memcmp(&mGWAddr, &(aOther->mGWAddr), addrSize))) {
+    if ((mHasGWAddr != aOther.mHasGWAddr) ||
+        (mHasGWAddr && memcmp(&mGWAddr, &(aOther.mGWAddr), addrSize))) {
       return false;
     }
-    if ((mHasDstAddr != aOther->mHasDstAddr) ||
-        (mHasDstAddr && memcmp(&mDstAddr, &(aOther->mDstAddr), addrSize))) {
+    if ((mHasDstAddr != aOther.mHasDstAddr) ||
+        (mHasDstAddr && memcmp(&mDstAddr, &(aOther.mDstAddr), addrSize))) {
       return false;
     }
-    if ((mHasPrefSrcAddr != aOther->mHasPrefSrcAddr) ||
+    if ((mHasPrefSrcAddr != aOther.mHasPrefSrcAddr) ||
         (mHasPrefSrcAddr &&
-         memcmp(&mPrefSrcAddr, &(aOther->mPrefSrcAddr), addrSize))) {
+         memcmp(&mPrefSrcAddr, &(aOther.mPrefSrcAddr), addrSize))) {
       return false;
     }
     return true;
   }
 
-  bool GatewayEquals(const NetlinkNeighbor* aNeigh) const {
+  bool GatewayEquals(const NetlinkNeighbor& aNeigh) const {
     if (!mHasGWAddr) {
       return false;
     }
-    if (aNeigh->Family() != mRtm.rtm_family) {
+    if (aNeigh.Family() != mRtm.rtm_family) {
       return false;
     }
     size_t addrSize = (mRtm.rtm_family == AF_INET) ? sizeof(mGWAddr.addr4)
                                                    : sizeof(mGWAddr.addr6);
-    return memcmp(&mGWAddr, aNeigh->GetAddrPtr(), addrSize) == 0;
+    return memcmp(&mGWAddr, aNeigh.GetAddrPtr(), addrSize) == 0;
   }
 
   bool GatewayEquals(const NetlinkRoute* aRoute) const {
     if (!mHasGWAddr || !aRoute->mHasGWAddr) {
       return false;
     }
     if (mRtm.rtm_family != aRoute->mRtm.rtm_family) {
       return false;
     }
     size_t addrSize = (mRtm.rtm_family == AF_INET) ? sizeof(mGWAddr.addr4)
                                                    : sizeof(mGWAddr.addr6);
     return memcmp(&mGWAddr, &(aRoute->mGWAddr), addrSize) == 0;
   }
 
-  bool PrefSrcAddrEquals(const NetlinkAddress* aAddress) const {
+  bool PrefSrcAddrEquals(const NetlinkAddress& aAddress) const {
     if (!mHasPrefSrcAddr) {
       return false;
     }
-    if (mRtm.rtm_family != aAddress->Family()) {
+    if (mRtm.rtm_family != aAddress.Family()) {
       return false;
     }
     size_t addrSize = (mRtm.rtm_family == AF_INET) ? sizeof(mPrefSrcAddr.addr4)
                                                    : sizeof(mPrefSrcAddr.addr6);
-    return memcmp(&mPrefSrcAddr, aAddress->GetAddrPtr(), addrSize) == 0;
+    return memcmp(&mPrefSrcAddr, aAddress.GetAddrPtr(), addrSize) == 0;
   }
 
   void GetAsString(nsACString& _retval) const {
     nsAutoCString addrStr;
     _retval.Assign("table=");
     _retval.AppendInt(mRtm.rtm_table);
     _retval.Append(" type=");
     _retval.AppendInt(mRtm.rtm_type);
@@ -578,18 +578,18 @@ class NetlinkRtMsg : public NetlinkMsg {
  private:
   struct {
     struct nlmsghdr hdr;
     struct rtmsg rtm;
     unsigned char data[1024];
   } mReq;
 };
 
-NetlinkService::LinkInfo::LinkInfo(NetlinkLink* aLink)
-    : mLink(aLink), mIsUp(false) {}
+NetlinkService::LinkInfo::LinkInfo(UniquePtr<NetlinkLink>&& aLink)
+    : mLink(std::move(aLink)), mIsUp(false) {}
 
 NetlinkService::LinkInfo::~LinkInfo() {}
 
 bool NetlinkService::LinkInfo::UpdateStatus() {
   LOG(("NetlinkService::LinkInfo::UpdateStatus"));
 
   bool oldIsUp = mIsUp;
   mIsUp = false;
@@ -746,49 +746,49 @@ void NetlinkService::OnNetlinkMessage(in
     }
   }
 }
 
 void NetlinkService::OnLinkMessage(struct nlmsghdr* aNlh) {
   LOG(("NetlinkService::OnLinkMessage [type=%s]",
        aNlh->nlmsg_type == RTM_NEWLINK ? "new" : "del"));
 
-  nsAutoPtr<NetlinkLink> link(new NetlinkLink());
+  UniquePtr<NetlinkLink> link(new NetlinkLink());
   if (!link->Init(aNlh)) {
     return;
   }
 
   uint32_t linkIndex = link->GetIndex();
   nsAutoCString linkName;
   link->GetName(linkName);
 
   LinkInfo* linkInfo = nullptr;
   mLinks.Get(linkIndex, &linkInfo);
 
   if (aNlh->nlmsg_type == RTM_NEWLINK) {
     if (!linkInfo) {
       LOG(("Creating new link [index=%u, name=%s, flags=%u, type=%u]",
            linkIndex, linkName.get(), link->GetFlags(), link->GetType()));
-      linkInfo = new LinkInfo(link.forget());
+      linkInfo = new LinkInfo(std::move(link));
       mLinks.Put(linkIndex, linkInfo);
     } else {
       LOG(("Updating link [index=%u, name=%s, flags=%u, type=%u]", linkIndex,
            linkName.get(), link->GetFlags(), link->GetType()));
 
       // Check whether administrative state has changed.
       if (linkInfo->mLink->GetFlags() & IFF_UP &&
           !(link->GetFlags() & IFF_UP)) {
         LOG(("  link went down"));
         // If the link went down, remove all routes and neighbors, but keep
         // addresses.
         linkInfo->mDefaultRoutes.Clear();
         linkInfo->mNeighbors.Clear();
       }
 
-      linkInfo->mLink = link.forget();
+      linkInfo->mLink = std::move(link);
       linkInfo->UpdateStatus();
     }
   } else {
     if (!linkInfo) {
       // This can happen during startup
       LOG(("Link info doesn't exist [index=%u, name=%s]", linkIndex,
            linkName.get()));
     } else {
@@ -797,17 +797,17 @@ void NetlinkService::OnLinkMessage(struc
     }
   }
 }
 
 void NetlinkService::OnAddrMessage(struct nlmsghdr* aNlh) {
   LOG(("NetlinkService::OnAddrMessage [type=%s]",
        aNlh->nlmsg_type == RTM_NEWADDR ? "new" : "del"));
 
-  nsAutoPtr<NetlinkAddress> address(new NetlinkAddress());
+  UniquePtr<NetlinkAddress> address(new NetlinkAddress());
   if (!address->Init(aNlh)) {
     return;
   }
 
   uint32_t ifIdx = address->GetIndex();
 
   nsAutoCString addrStr;
   GetAddrStr(address->GetAddrPtr(), address->Family(), addrStr);
@@ -823,35 +823,35 @@ void NetlinkService::OnAddrMessage(struc
 
   // There might be already an equal address in the array even in case of
   // RTM_NEWADDR message, e.g. when lifetime of IPv6 address is renewed. Equal
   // in this case means that IP and prefix is the same but some attributes might
   // be different. Remove existing equal address in case of RTM_DELADDR as well
   // as RTM_NEWADDR message and add a new one in the latter case.
   for (uint32_t i = 0; i < linkInfo->mAddresses.Length(); ++i) {
     if (aNlh->nlmsg_type == RTM_NEWADDR &&
-        linkInfo->mAddresses[i]->MsgEquals(address)) {
+        linkInfo->mAddresses[i]->MsgEquals(*address)) {
       // If the new address is exactly the same, there is nothing to do.
       LOG(("Exactly the same address already exists [ifIdx=%u, addr=%s/%u",
            ifIdx, addrStr.get(), address->GetPrefixLen()));
       return;
     }
 
-    if (linkInfo->mAddresses[i]->Equals(address)) {
+    if (linkInfo->mAddresses[i]->Equals(*address)) {
       LOG(("Removing address [ifIdx=%u, addr=%s/%u]", ifIdx, addrStr.get(),
            address->GetPrefixLen()));
       linkInfo->mAddresses.RemoveElementAt(i);
       break;
     }
   }
 
   if (aNlh->nlmsg_type == RTM_NEWADDR) {
     LOG(("Adding address [ifIdx=%u, addr=%s/%u]", ifIdx, addrStr.get(),
          address->GetPrefixLen()));
-    linkInfo->mAddresses.AppendElement(address.forget());
+    linkInfo->mAddresses.AppendElement(std::move(address));
   } else {
     // Remove all routes associated with this address
     for (uint32_t i = linkInfo->mDefaultRoutes.Length(); i-- > 0;) {
       MOZ_ASSERT(linkInfo->mDefaultRoutes[i]->GetGWAddrPtr(),
                  "Stored routes must have gateway!");
       if (linkInfo->mDefaultRoutes[i]->Family() == address->Family() &&
           address->ContainsAddr(linkInfo->mDefaultRoutes[i]->GetGWAddrPtr())) {
         if (LOG_ENABLED()) {
@@ -885,17 +885,17 @@ void NetlinkService::OnAddrMessage(struc
     TriggerNetworkIDCalculation();
   }
 }
 
 void NetlinkService::OnRouteMessage(struct nlmsghdr* aNlh) {
   LOG(("NetlinkService::OnRouteMessage [type=%s]",
        aNlh->nlmsg_type == RTM_NEWROUTE ? "new" : "del"));
 
-  nsAutoPtr<NetlinkRoute> route(new NetlinkRoute());
+  UniquePtr<NetlinkRoute> route(new NetlinkRoute());
   if (!route->Init(aNlh)) {
     return;
   }
 
   if (!route->IsUnicast() || !route->ScopeIsUniverse()) {
     // Use only unicast routes
     if (LOG_ENABLED()) {
       nsAutoCString routeDbgStr;
@@ -956,17 +956,17 @@ void NetlinkService::OnRouteMessage(stru
       nsAutoCString routeDbgStr;
       route->GetAsString(routeDbgStr);
       LOG(("Cannot find link info for route: %s", routeDbgStr.get()));
     }
     return;
   }
 
   for (uint32_t i = 0; i < linkInfo->mDefaultRoutes.Length(); ++i) {
-    if (linkInfo->mDefaultRoutes[i]->Equals(route)) {
+    if (linkInfo->mDefaultRoutes[i]->Equals(*route)) {
       // We shouldn't find equal route when adding a new one, but just in case
       // it can happen remove the old one to avoid duplicities.
       if (LOG_ENABLED()) {
         nsAutoCString routeDbgStr;
         route->GetAsString(routeDbgStr);
         LOG(("Removing default route: %s", routeDbgStr.get()));
       }
       linkInfo->mDefaultRoutes.RemoveElementAt(i);
@@ -975,25 +975,25 @@ void NetlinkService::OnRouteMessage(stru
   }
 
   if (aNlh->nlmsg_type == RTM_NEWROUTE) {
     if (LOG_ENABLED()) {
       nsAutoCString routeDbgStr;
       route->GetAsString(routeDbgStr);
       LOG(("Adding default route: %s", routeDbgStr.get()));
     }
-    linkInfo->mDefaultRoutes.AppendElement(route.forget());
+    linkInfo->mDefaultRoutes.AppendElement(std::move(route));
   }
 }
 
 void NetlinkService::OnNeighborMessage(struct nlmsghdr* aNlh) {
   LOG(("NetlinkService::OnNeighborMessage [type=%s]",
        aNlh->nlmsg_type == RTM_NEWNEIGH ? "new" : "del"));
 
-  nsAutoPtr<NetlinkNeighbor> neigh(new NetlinkNeighbor());
+  UniquePtr<NetlinkNeighbor> neigh(new NetlinkNeighbor());
   if (!neigh->Init(aNlh)) {
     return;
   }
 
   LinkInfo* linkInfo = nullptr;
   mLinks.Get(neigh->GetIndex(), &linkInfo);
   if (!linkInfo) {
     // This can happen during startup
@@ -1021,52 +1021,52 @@ void NetlinkService::OnNeighborMessage(s
     if (!mRecalculateNetworkId && neigh->HasMAC()) {
       NetlinkNeighbor* oldNeigh = nullptr;
       linkInfo->mNeighbors.Get(key, &oldNeigh);
 
       if (!oldNeigh || !oldNeigh->HasMAC()) {
         // The MAC address was added, if it's a host from some of the saved
         // routing tables we should recalculate network ID
         for (uint32_t i = 0; i < linkInfo->mDefaultRoutes.Length(); ++i) {
-          if (linkInfo->mDefaultRoutes[i]->GatewayEquals(neigh)) {
+          if (linkInfo->mDefaultRoutes[i]->GatewayEquals(*neigh)) {
             TriggerNetworkIDCalculation();
             break;
           }
         }
         if ((mIPv4RouteCheckResult &&
-             mIPv4RouteCheckResult->GatewayEquals(neigh)) ||
+             mIPv4RouteCheckResult->GatewayEquals(*neigh)) ||
             (mIPv6RouteCheckResult &&
-             mIPv6RouteCheckResult->GatewayEquals(neigh))) {
+             mIPv6RouteCheckResult->GatewayEquals(*neigh))) {
           TriggerNetworkIDCalculation();
         }
       }
     }
 
     if (LOG_ENABLED()) {
       nsAutoCString neighDbgStr;
       neigh->GetAsString(neighDbgStr);
       LOG(("Adding neighbor: %s", neighDbgStr.get()));
     }
-    linkInfo->mNeighbors.Put(key, neigh.forget());
+    linkInfo->mNeighbors.Put(key, neigh.release());
   } else {
     if (LOG_ENABLED()) {
       nsAutoCString neighDbgStr;
       neigh->GetAsString(neighDbgStr);
       LOG(("Removing neighbor %s", neighDbgStr.get()));
     }
     linkInfo->mNeighbors.Remove(key);
   }
 }
 
 void NetlinkService::OnRouteCheckResult(struct nlmsghdr* aNlh) {
   LOG(("NetlinkService::OnRouteCheckResult"));
-  nsAutoPtr<NetlinkRoute> route;
+  UniquePtr<NetlinkRoute> route;
 
   if (aNlh) {
-    route = new NetlinkRoute();
+    route = MakeUnique<NetlinkRoute>();
     if (!route->Init(aNlh)) {
       route = nullptr;
     } else {
       if (!route->IsUnicast() || !route->ScopeIsUniverse()) {
         if (LOG_ENABLED()) {
           nsAutoCString routeDbgStr;
           route->GetAsString(routeDbgStr);
           LOG(("Not an unicast global route: %s", routeDbgStr.get()));
@@ -1089,19 +1089,19 @@ void NetlinkService::OnRouteCheckResult(
       route->GetAsString(routeDbgStr);
       LOG(("Storing route: %s", routeDbgStr.get()));
     } else {
       LOG(("Clearing result for the check"));
     }
   }
 
   if (mOutgoingMessages[0]->Family() == AF_INET) {
-    mIPv4RouteCheckResult = route.forget();
+    mIPv4RouteCheckResult = std::move(route);
   } else {
-    mIPv6RouteCheckResult = route.forget();
+    mIPv6RouteCheckResult = std::move(route);
   }
 }
 
 void NetlinkService::EnqueueGenMsg(uint16_t aMsgType, uint8_t aFamily) {
   NetlinkGenMsg* msg = new NetlinkGenMsg(aMsgType, aFamily, ++mMsgId);
   mOutgoingMessages.AppendElement(msg);
 }
 
@@ -1340,17 +1340,17 @@ bool NetlinkService::CalculateIDForFamil
   bool retval = false;
 
   if (!mLinkUp) {
     // Skip ID calculation if the link is down, we have no ID...
     LOG(("Link is down, skipping ID calculation."));
     return retval;
   }
 
-  nsAutoPtr<NetlinkRoute>* routeCheckResultPtr;
+  UniquePtr<NetlinkRoute>* routeCheckResultPtr;
   if (aFamily == AF_INET) {
     routeCheckResultPtr = &mIPv4RouteCheckResult;
   } else {
     routeCheckResultPtr = &mIPv6RouteCheckResult;
   }
 
   // All GW neighbors for which we know MAC address. We'll probably have at
   // most only one, but in case we have more default routes, we hash them all
@@ -1572,26 +1572,26 @@ bool NetlinkService::CalculateIDForFamil
       for (uint32_t i = 0; i < routeCheckLinkInfo->mAddresses.Length(); ++i) {
         if (!hasSrcAddr) {
           // there is no preferred src, match just the family
           if (routeCheckLinkInfo->mAddresses[i]->Family() != aFamily) {
             continue;
           }
         } else if (!(*routeCheckResultPtr)
                         ->PrefSrcAddrEquals(
-                            routeCheckLinkInfo->mAddresses[i])) {
+                            *routeCheckLinkInfo->mAddresses[i])) {
           continue;
         }
 
         if (!linkAddress ||
             linkAddress->GetPrefixLen() >
                 routeCheckLinkInfo->mAddresses[i]->GetPrefixLen()) {
           // We have no address yet or this one has smaller prefix length,
           // use it.
-          linkAddress = routeCheckLinkInfo->mAddresses[i];
+          linkAddress = routeCheckLinkInfo->mAddresses[i].get();
         }
       }
 
       if (!linkAddress) {
         // There is no address in our array?
         if (LOG_ENABLED()) {
           nsAutoCString dbgStr;
           (*routeCheckResultPtr)->GetAsString(dbgStr);
--- a/netwerk/system/netlink/NetlinkService.h
+++ b/netwerk/system/netlink/NetlinkService.h
@@ -4,24 +4,24 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #ifndef NETLINKSERVICE_H_
 #define NETLINKSERVICE_H_
 
 #include <netinet/in.h>
 #include <linux/netlink.h>
 
-#include "nsAutoPtr.h"
 #include "nsIRunnable.h"
 #include "nsThreadUtils.h"
 #include "nsCOMPtr.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/TimeStamp.h"
 #include "nsClassHashtable.h"
 #include "mozilla/SHA1.h"
+#include "mozilla/UniquePtr.h"
 
 namespace mozilla {
 namespace net {
 
 class NetlinkAddress;
 class NetlinkNeighbor;
 class NetlinkLink;
 class NetlinkRoute;
@@ -104,48 +104,48 @@ class NetlinkService : public nsIRunnabl
   // Time stamp of setting mRecalculateNetworkId to true
   mozilla::TimeStamp mTriggerTime;
 
   nsCString mNetworkId;
   nsTArray<nsCString> mDNSSuffixList;
 
   class LinkInfo {
    public:
-    explicit LinkInfo(NetlinkLink* aLink);
+    explicit LinkInfo(UniquePtr<NetlinkLink>&& aLink);
     virtual ~LinkInfo();
 
     // Updates mIsUp according to current mLink and mAddresses. Returns true if
     // the value has changed.
     bool UpdateStatus();
 
     // NetlinkLink structure for this link
-    nsAutoPtr<NetlinkLink> mLink;
+    UniquePtr<NetlinkLink> mLink;
 
     // All IPv4/IPv6 addresses on this link
-    nsTArray<nsAutoPtr<NetlinkAddress> > mAddresses;
+    nsTArray<UniquePtr<NetlinkAddress>> mAddresses;
 
     // All neighbors on this link, key is an address
     nsClassHashtable<nsCStringHashKey, NetlinkNeighbor> mNeighbors;
 
     // Default IPv4/IPv6 routes
-    nsTArray<nsAutoPtr<NetlinkRoute> > mDefaultRoutes;
+    nsTArray<UniquePtr<NetlinkRoute>> mDefaultRoutes;
 
     // Link is up when it's running, it's not a loopback and there is
     // a non-local address associated with it.
     bool mIsUp;
   };
 
   nsClassHashtable<nsUint32HashKey, LinkInfo> mLinks;
 
   // Route for mRouteCheckIPv4 address
-  nsAutoPtr<NetlinkRoute> mIPv4RouteCheckResult;
+  UniquePtr<NetlinkRoute> mIPv4RouteCheckResult;
   // Route for mRouteCheckIPv6 address
-  nsAutoPtr<NetlinkRoute> mIPv6RouteCheckResult;
+  UniquePtr<NetlinkRoute> mIPv6RouteCheckResult;
 
-  nsTArray<nsAutoPtr<NetlinkMsg> > mOutgoingMessages;
+  nsTArray<UniquePtr<NetlinkMsg>> mOutgoingMessages;
 
   RefPtr<NetlinkServiceListener> mListener;
 };
 
 }  // namespace net
 }  // namespace mozilla
 
 #endif /* NETLINKSERVICE_H_ */
--- a/netwerk/system/win32/nsNotifyAddrListener.cpp
+++ b/netwerk/system/win32/nsNotifyAddrListener.cpp
@@ -31,17 +31,16 @@
 #include "nsComponentManagerUtils.h"
 #include "nsThreadUtils.h"
 #include "nsIObserverService.h"
 #include "nsIWindowsRegKey.h"
 #include "nsServiceManagerUtils.h"
 #include "nsNotifyAddrListener.h"
 #include "nsString.h"
 #include "nsPrintfCString.h"
-#include "nsAutoPtr.h"
 #include "mozilla/Services.h"
 #include "nsCRT.h"
 #include "mozilla/StaticPrefs_network.h"
 #include "mozilla/SHA1.h"
 #include "mozilla/Base64.h"
 #include "mozilla/ScopeExit.h"
 #include "mozilla/Telemetry.h"
 #include <iptypes.h>
--- a/netwerk/wifi/nsWifiMonitor.cpp
+++ b/netwerk/wifi/nsWifiMonitor.cpp
@@ -106,23 +106,23 @@ NS_IMETHODIMP nsWifiMonitor::StopWatchin
 
 typedef nsTArray<nsMainThreadPtrHandle<nsIWifiListener>> WifiListenerArray;
 
 class nsPassErrorToWifiListeners final : public nsIRunnable {
  public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
 
-  nsPassErrorToWifiListeners(nsAutoPtr<WifiListenerArray> aListeners,
+  nsPassErrorToWifiListeners(UniquePtr<WifiListenerArray>&& aListeners,
                              nsresult aResult)
-      : mListeners(aListeners), mResult(aResult) {}
+      : mListeners(std::move(aListeners)), mResult(aResult) {}
 
  private:
   ~nsPassErrorToWifiListeners() = default;
-  nsAutoPtr<WifiListenerArray> mListeners;
+  UniquePtr<WifiListenerArray> mListeners;
   nsresult mResult;
 };
 
 NS_IMPL_ISUPPORTS(nsPassErrorToWifiListeners, nsIRunnable)
 
 NS_IMETHODIMP nsPassErrorToWifiListeners::Run() {
   LOG(("About to send error to the wifi listeners\n"));
   for (size_t i = 0; i < mListeners->Length(); i++) {
@@ -133,36 +133,36 @@ NS_IMETHODIMP nsPassErrorToWifiListeners
 
 NS_IMETHODIMP nsWifiMonitor::Run() {
   LOG(("@@@@@ wifi monitor run called\n"));
 
   nsresult rv = DoScan();
   LOG(("@@@@@ wifi monitor run::doscan complete %" PRIx32 "\n",
        static_cast<uint32_t>(rv)));
 
-  nsAutoPtr<WifiListenerArray> currentListeners;
+  UniquePtr<WifiListenerArray> currentListeners;
   bool doError = false;
 
   {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
     if (mKeepGoing && NS_FAILED(rv)) {
       doError = true;
-      currentListeners = new WifiListenerArray(mListeners.Length());
+      currentListeners = MakeUnique<WifiListenerArray>(mListeners.Length());
       for (uint32_t i = 0; i < mListeners.Length(); i++)
         currentListeners->AppendElement(mListeners[i].mListener);
     }
     mThreadComplete = true;
   }
 
   if (doError) {
     nsCOMPtr<nsIEventTarget> target = GetMainThreadEventTarget();
     if (!target) return NS_ERROR_UNEXPECTED;
 
     nsCOMPtr<nsIRunnable> runnable(
-        new nsPassErrorToWifiListeners(currentListeners, rv));
+        new nsPassErrorToWifiListeners(std::move(currentListeners), rv));
     if (!runnable) return NS_ERROR_OUT_OF_MEMORY;
 
     target->Dispatch(runnable, NS_DISPATCH_SYNC);
   }
 
   LOG(("@@@@@ wifi monitor run complete\n"));
   return NS_OK;
 }
--- a/netwerk/wifi/nsWifiMonitor.h
+++ b/netwerk/wifi/nsWifiMonitor.h
@@ -2,17 +2,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef __nsWifiMonitor__
 #define __nsWifiMonitor__
 
 #include "nsIWifiMonitor.h"
 #include "nsCOMPtr.h"
-#include "nsAutoPtr.h"
 #include "nsProxyRelease.h"
 #include "nsIThread.h"
 #include "nsIRunnable.h"
 #include "nsCOMArray.h"
 #include "nsIWifiListener.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/ReentrantMonitor.h"
 #include "mozilla/Logging.h"
@@ -64,13 +63,13 @@ class nsWifiMonitor final : nsIRunnable,
   mozilla::Atomic<bool> mThreadComplete;
   nsCOMPtr<nsIThread> mThread;
 
   nsTArray<nsWifiListener> mListeners;
 
   mozilla::ReentrantMonitor mReentrantMonitor;
 
 #ifdef XP_WIN
-  nsAutoPtr<WinWifiScanner> mWinWifiScanner;
+  mozilla::UniquePtr<WinWifiScanner> mWinWifiScanner;
 #endif
 };
 
 #endif
--- a/netwerk/wifi/nsWifiScannerMac.cpp
+++ b/netwerk/wifi/nsWifiScannerMac.cpp
@@ -3,17 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <mach-o/dyld.h>
 #include <dlfcn.h>
 #include <unistd.h>
 
 #include "osx_wifi.h"
 
-#include "nsAutoPtr.h"
 #include "nsCOMArray.h"
 #include "nsWifiMonitor.h"
 #include "nsWifiAccessPoint.h"
 
 #include "nsServiceManagerUtils.h"
 #include "nsComponentManagerUtils.h"
 
 using namespace mozilla;
--- a/netwerk/wifi/nsWifiScannerWin.cpp
+++ b/netwerk/wifi/nsWifiScannerWin.cpp
@@ -1,16 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsWifiMonitor.h"
 
 // moz headers (alphabetical)
-#include "nsAutoPtr.h"
 #include "nsCOMArray.h"
 #include "nsComponentManagerUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsWifiAccessPoint.h"
 #include "win_wifiScanner.h"
 
 using namespace mozilla;
 
@@ -21,17 +20,17 @@ using namespace mozilla;
  * is almost identical in each file. We relegate the Windows-specific
  * work to the `WinWifiScanner` class and deal with non-Windows-specific
  * issues like calling listeners here. Hopefully this file can be merged
  * with the other implementations of `nsWifiMonitor::DoScan` since a lot
  * of the code is identical
  */
 nsresult nsWifiMonitor::DoScan() {
   if (!mWinWifiScanner) {
-    mWinWifiScanner = new WinWifiScanner();
+    mWinWifiScanner = MakeUnique<WinWifiScanner>();
     if (!mWinWifiScanner) {
       // TODO: Probably return OOM error
       return NS_ERROR_FAILURE;
     }
   }
 
   // Regularly get the access point data.
 
--- a/netwerk/wifi/osx_corewlan.mm
+++ b/netwerk/wifi/osx_corewlan.mm
@@ -7,17 +7,16 @@
 
 #include <dlfcn.h>
 #include <unistd.h>
 
 #include <objc/objc.h>
 #include <objc/objc-runtime.h>
 
 #include "nsObjCExceptions.h"
-#include "nsAutoPtr.h"
 #include "nsCOMArray.h"
 #include "nsWifiMonitor.h"
 #include "nsWifiAccessPoint.h"
 
 nsresult GetAccessPointsFromWLAN(nsCOMArray<nsWifiAccessPoint>& accessPoints) {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
 
   accessPoints.Clear();
--- a/netwerk/wifi/win_wifiScanner.cpp
+++ b/netwerk/wifi/win_wifiScanner.cpp
@@ -59,17 +59,17 @@ static void WINAPI OnScanComplete(PWLAN_
 
 WinWifiScanner::WinWifiScanner() {
   // NOTE: We assume that, if we were unable to load the WLAN library when
   // we initially tried, we will not be able to load it in the future.
   // Technically, on Windows XP SP2, a user could install the redistributable
   // and make our assumption incorrect. We opt to avoid making a bunch of
   // spurious LoadLibrary calls in the common case rather than load the
   // WLAN API in the edge case.
-  mWlanLibrary = WinWLANLibrary::Load();
+  mWlanLibrary.reset(WinWLANLibrary::Load());
   if (!mWlanLibrary) {
     NS_WARNING("Could not initialize Windows Wi-Fi scanner");
   }
 }
 
 WinWifiScanner::~WinWifiScanner() {}
 
 nsresult WinWifiScanner::GetAccessPointsFromWLAN(
@@ -86,17 +86,17 @@ nsresult WinWifiScanner::GetAccessPoints
   WLAN_INTERFACE_INFO_LIST* interface_list = nullptr;
   if (ERROR_SUCCESS !=
       (*mWlanLibrary->GetWlanEnumInterfacesPtr())(mWlanLibrary->GetWLANHandle(),
                                                   nullptr, &interface_list)) {
     return NS_ERROR_FAILURE;
   }
 
   // This ensures we call WlanFreeMemory on interface_list
-  ScopedWLANObject scopedInterfaceList(mWlanLibrary, interface_list);
+  ScopedWLANObject scopedInterfaceList(*mWlanLibrary, interface_list);
 
   if (!interface_list->dwNumberOfItems) {
     return NS_OK;
   }
 
   InterfaceScanCallbackData cbData(interface_list->dwNumberOfItems);
 
   DWORD wlanNotifySource;
@@ -140,17 +140,17 @@ nsresult WinWifiScanner::GetAccessPoints
                              DOT11_BSS_TYPE_UNUSED,
                              false,    // bSecurityEnabled - unused
                              nullptr,  // reserved
                              &bss_list)) {
       continue;
     }
 
     // This ensures we call WlanFreeMemory on bss_list
-    ScopedWLANObject scopedBssList(mWlanLibrary, bss_list);
+    ScopedWLANObject scopedBssList(*mWlanLibrary, bss_list);
 
     // Store each discovered access point in our outparam
     for (int j = 0; j < static_cast<int>(bss_list->dwNumberOfItems); ++j) {
       nsWifiAccessPoint* ap = new nsWifiAccessPoint();
       if (!ap) {
         continue;
       }
 
--- a/netwerk/wifi/win_wifiScanner.h
+++ b/netwerk/wifi/win_wifiScanner.h
@@ -1,16 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #pragma once
 
 // Moz headers (alphabetical)
-#include "nsAutoPtr.h"
+#include "mozilla/UniquePtr.h"
 #include "nsCOMArray.h"
 #include "win_wlanLibrary.h"
 
 class nsWifiAccessPoint;
 
 class WinWifiScanner final {
  public:
   WinWifiScanner();
@@ -23,10 +23,10 @@ class WinWifiScanner final {
    * populates the supplied collection with them
    *
    * @param accessPoints The collection to populate with available APs
    * @return NS_OK on success, failure codes on failure
    */
   nsresult GetAccessPointsFromWLAN(nsCOMArray<nsWifiAccessPoint>& accessPoints);
 
  private:
-  nsAutoPtr<WinWLANLibrary> mWlanLibrary;
+  mozilla::UniquePtr<WinWLANLibrary> mWlanLibrary;
 };
--- a/netwerk/wifi/win_wlanLibrary.h
+++ b/netwerk/wifi/win_wlanLibrary.h
@@ -38,17 +38,17 @@ class WinWLANLibrary {
   decltype(::WlanCloseHandle)* mWlanCloseHandlePtr;
   decltype(::WlanOpenHandle)* mWlanOpenHandlePtr;
   decltype(::WlanRegisterNotification)* mWlanRegisterNotificationPtr;
   decltype(::WlanScan)* mWlanScanPtr;
 };
 
 class ScopedWLANObject {
  public:
-  ScopedWLANObject(WinWLANLibrary* library, void* object)
+  ScopedWLANObject(const WinWLANLibrary& library, void* object)
       : mLibrary(library), mObject(object) {}
 
-  ~ScopedWLANObject() { (*(mLibrary->GetWlanFreeMemoryPtr()))(mObject); }
+  ~ScopedWLANObject() { (*(mLibrary.GetWlanFreeMemoryPtr()))(mObject); }
 
  private:
-  WinWLANLibrary* mLibrary;
+  const WinWLANLibrary& mLibrary;
   void* mObject;
 };