Bug 514280 Stop using nsCOMPtr for concrete types r=bsmedberg
☠☠ backed out by cfe51017482e ☠ ☠
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Mon, 17 Mar 2014 19:07:09 +0000
changeset 185997 a01f97c1ed02e49e8d4289d8e9b5544f67c856bb
parent 185996 c3431749b0acaf5f9c5154651cf8c185017a698e
child 185998 2a015b45d8085e960f6bdd88e891989d96a2ee9e
push id5832
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:43:22 +0000
treeherdermozilla-aurora@4974d9da2f7d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs514280
milestone31.0a1
Bug 514280 Stop using nsCOMPtr for concrete types r=bsmedberg
content/canvas/src/DocumentRendererChild.cpp
content/media/MediaDecoder.h
content/media/MediaDecoderStateMachine.cpp
content/media/plugins/MediaPluginHost.h
content/media/plugins/MediaResourceServer.cpp
content/media/webaudio/AudioContext.cpp
content/xml/document/src/nsXMLContentSink.cpp
content/xul/templates/src/nsXULTemplateQueryProcessorRDF.h
dom/base/Navigator.h
dom/base/nsContentPermissionHelper.cpp
dom/base/nsGlobalWindow.cpp
dom/camera/DOMCameraControl.cpp
dom/camera/DOMCameraControl.h
dom/camera/DOMCameraManager.cpp
dom/devicestorage/DeviceStorageRequestChild.cpp
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
dom/plugins/base/nsNPAPIPluginInstance.h
dom/smil/nsSMILTimeValueSpec.h
editor/composer/src/nsEditorSpellCheck.cpp
embedding/components/find/src/nsFind.h
extensions/auth/nsAuthFactory.cpp
extensions/spellcheck/src/mozInlineSpellChecker.h
gfx/layers/LayerScope.cpp
ipc/glue/BackgroundImpl.cpp
layout/generic/nsSubDocumentFrame.cpp
layout/inspector/nsFontFaceList.cpp
layout/mathml/nsMathMLmactionFrame.h
layout/style/MediaQueryList.h
media/mtransport/nriceresolver.cpp
media/mtransport/transportlayerprsock.h
netwerk/base/src/BackgroundFileSaver.cpp
netwerk/base/src/nsUDPSocket.cpp
netwerk/cache/nsCacheEntryDescriptor.cpp
netwerk/cache2/CacheIndex.cpp
netwerk/test/TestUDPSocket.cpp
parser/xml/src/nsSAXXMLReader.cpp
security/manager/ssl/src/nsNSSCallbacks.cpp
security/manager/ssl/src/nsNSSCallbacks.h
storage/src/VacuumManager.cpp
toolkit/components/url-classifier/nsUrlClassifierDBService.h
toolkit/profile/nsToolkitProfileService.cpp
widget/android/nsAppShell.cpp
widget/xpwidgets/nsBaseWidget.h
xpcom/ds/nsINIParserImpl.cpp
--- a/content/canvas/src/DocumentRendererChild.cpp
+++ b/content/canvas/src/DocumentRendererChild.cpp
@@ -42,17 +42,17 @@ DocumentRendererChild::RenderDocument(ns
                                       uint32_t renderFlags,
                                       bool flushLayout,
                                       const nsIntSize& renderSize,
                                       nsCString& data)
 {
     if (flushLayout)
         nsContentUtils::FlushLayoutForTree(window);
 
-    nsCOMPtr<nsPresContext> presContext;
+    nsRefPtr<nsPresContext> presContext;
     nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(window);
     if (win) {
         nsIDocShell* docshell = win->GetDocShell();
         if (docshell) {
             docshell->GetPresContext(getter_AddRefs(presContext));
         }
     }
     if (!presContext)
--- a/content/media/MediaDecoder.h
+++ b/content/media/MediaDecoder.h
@@ -1020,17 +1020,17 @@ protected:
    * The following member variables can be accessed from any thread.
    ******/
 
   // The state machine object for handling the decoding. It is safe to
   // call methods of this object from other threads. Its internal data
   // is synchronised on a monitor. The lifetime of this object is
   // after mPlayState is LOADING and before mPlayState is SHUTDOWN. It
   // is safe to access it during this period.
-  nsCOMPtr<MediaDecoderStateMachine> mDecoderStateMachine;
+  nsRefPtr<MediaDecoderStateMachine> mDecoderStateMachine;
 
   // Media data resource.
   nsRefPtr<MediaResource> mResource;
 
   // |ReentrantMonitor| for detecting when the video play state changes. A call
   // to |Wait| on this monitor will block the thread until the next state
   // change.
   // Using a wrapper class to restrict direct access to the |ReentrantMonitor|
--- a/content/media/MediaDecoderStateMachine.cpp
+++ b/content/media/MediaDecoderStateMachine.cpp
@@ -2055,17 +2055,17 @@ public:
     mStateMachine->ReleaseDecoder();
     mDecoder->ReleaseStateMachine();
     mStateMachine = nullptr;
     mDecoder = nullptr;
     return NS_OK;
   }
 private:
   nsRefPtr<MediaDecoder> mDecoder;
-  nsCOMPtr<MediaDecoderStateMachine> mStateMachine;
+  nsRefPtr<MediaDecoderStateMachine> mStateMachine;
 };
 
 // Runnable which dispatches an event to the main thread to dispose of the
 // decoder and state machine. This runs on the state machine thread after
 // the state machine has shutdown, and all events for that state machine have
 // finished running.
 class nsDispatchDisposeEvent : public nsRunnable {
 public:
@@ -2074,17 +2074,17 @@ public:
     : mDecoder(aDecoder), mStateMachine(aStateMachine) {}
   NS_IMETHOD Run() {
     NS_DispatchToMainThread(new nsDecoderDisposeEvent(mDecoder.forget(),
                                                       mStateMachine.forget()));
     return NS_OK;
   }
 private:
   nsRefPtr<MediaDecoder> mDecoder;
-  nsCOMPtr<MediaDecoderStateMachine> mStateMachine;
+  nsRefPtr<MediaDecoderStateMachine> mStateMachine;
 };
 
 nsresult MediaDecoderStateMachine::RunStateMachine()
 {
   AssertCurrentThreadInMonitor();
 
   MediaResource* resource = mDecoder->GetResource();
   NS_ENSURE_TRUE(resource, NS_ERROR_NULL_POINTER);
--- a/content/media/plugins/MediaPluginHost.h
+++ b/content/media/plugins/MediaPluginHost.h
@@ -11,17 +11,17 @@
 #include "MPAPI.h"
 #include "MediaResourceServer.h"
 
 namespace mozilla {
 
 class MediaPluginReader;
 
 class MediaPluginHost {
-  nsCOMPtr<MediaResourceServer> mResourceServer;
+  nsRefPtr<MediaResourceServer> mResourceServer;
   nsTArray<MPAPI::Manifest *> mPlugins;
 
   MPAPI::Manifest *FindPlugin(const nsACString& aMimeType);
 public:
   MediaPluginHost();
   ~MediaPluginHost();
 
   static void Shutdown();
--- a/content/media/plugins/MediaResourceServer.cpp
+++ b/content/media/plugins/MediaResourceServer.cpp
@@ -107,17 +107,17 @@ private:
   // Reading from this reads the data sent from the client.
   nsCOMPtr<nsIInputStream> mInput;
 
   // Writing to this sends data to the client.
   nsCOMPtr<nsIOutputStream> mOutput;
 
   // The MediaResourceServer that owns the MediaResource instances
   // served. This is used to lookup the MediaResource from the URL.
-  nsCOMPtr<MediaResourceServer> mServer;
+  nsRefPtr<MediaResourceServer> mServer;
 
   // Write 'aBufferLength' bytes from 'aBuffer' to 'mOutput'. This
   // method ensures all the data is written by checking the number
   // of bytes returned from the output streams 'Write' method and
   // looping until done.
   nsresult WriteAll(char const* aBuffer, int32_t aBufferLength);
 
 public:
@@ -337,17 +337,17 @@ ServeResourceEvent::Shutdown()
   from the MediaResourceServer that created this listener, using the
   URL the client requested.
 */
 class ResourceSocketListener : public nsIServerSocketListener
 {
 public:
   // The MediaResourceServer used to look up the MediaResource
   // on requests.
-  nsCOMPtr<MediaResourceServer> mServer;
+  nsRefPtr<MediaResourceServer> mServer;
 
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSISERVERSOCKETLISTENER
 
   ResourceSocketListener(MediaResourceServer* aServer) :
     mServer(aServer)
   {
@@ -411,17 +411,17 @@ MediaResourceServer::Run()
 
   return NS_OK;
 }
 
 /* static */
 already_AddRefed<MediaResourceServer>
 MediaResourceServer::Start()
 {
-  nsCOMPtr<MediaResourceServer> server = new MediaResourceServer();
+  nsRefPtr<MediaResourceServer> server = new MediaResourceServer();
   NS_DispatchToMainThread(server, NS_DISPATCH_SYNC);
   return server.forget();
 }
 
 void
 MediaResourceServer::Stop()
 {
   MutexAutoLock lock(mMutex);
--- a/content/media/webaudio/AudioContext.cpp
+++ b/content/media/webaudio/AudioContext.cpp
@@ -455,17 +455,17 @@ AudioContext::DecodeAudioData(const Arra
 {
   // Sniff the content of the media.
   // Failed type sniffing will be handled by AsyncDecodeMedia.
   nsAutoCString contentType;
   NS_SniffContent(NS_DATA_SNIFFER_CATEGORY, nullptr,
                   aBuffer.Data(), aBuffer.Length(),
                   contentType);
 
-  nsCOMPtr<DecodeErrorCallback> failureCallback;
+  nsRefPtr<DecodeErrorCallback> failureCallback;
   if (aFailureCallback.WasPassed()) {
     failureCallback = &aFailureCallback.Value();
   }
   nsRefPtr<WebAudioDecodeJob> job(
     new WebAudioDecodeJob(contentType, this, aBuffer,
                           &aSuccessCallback, failureCallback));
   mDecoder.AsyncDecodeMedia(contentType.get(),
                             aBuffer.Data(), aBuffer.Length(), *job);
--- a/content/xml/document/src/nsXMLContentSink.cpp
+++ b/content/xml/document/src/nsXMLContentSink.cpp
@@ -197,17 +197,17 @@ nsXMLContentSink::MaybePrettyPrint()
   mDocument->RemoveObserver(this);
   mIsDocumentObserver = false;
 
   // Reenable the CSSLoader so that the prettyprinting stylesheets can load
   if (mCSSLoader) {
     mCSSLoader->SetEnabled(true);
   }
   
-  nsCOMPtr<nsXMLPrettyPrinter> printer;
+  nsRefPtr<nsXMLPrettyPrinter> printer;
   nsresult rv = NS_NewXMLPrettyPrinter(getter_AddRefs(printer));
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool isPrettyPrinting;
   rv = printer->PrettyPrint(mDocument, &isPrettyPrinting);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mPrettyPrinting = isPrettyPrinting;
--- a/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.h
+++ b/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.h
@@ -39,17 +39,17 @@ class nsXULTemplateResultRDF;
 
 /**
  * An object that generates results from a query on an RDF graph
  */
 class nsXULTemplateQueryProcessorRDF MOZ_FINAL : public nsIXULTemplateQueryProcessor,
                                                  public nsIRDFObserver
 {
 public:
-    typedef nsTArray<nsCOMPtr<nsXULTemplateResultRDF> > ResultArray;
+    typedef nsTArray<nsRefPtr<nsXULTemplateResultRDF> > ResultArray;
 
     nsXULTemplateQueryProcessorRDF();
 
     ~nsXULTemplateQueryProcessorRDF();
 
     nsresult InitGlobals();
 
     // nsISupports interface
--- a/dom/base/Navigator.h
+++ b/dom/base/Navigator.h
@@ -333,17 +333,17 @@ private:
   nsRefPtr<network::Connection> mConnection;
 #ifdef MOZ_B2G_RIL
   nsRefPtr<MobileConnectionArray> mMobileConnections;
   nsRefPtr<CellBroadcast> mCellBroadcast;
   nsRefPtr<IccManager> mIccManager;
   nsRefPtr<Voicemail> mVoicemail;
 #endif
 #ifdef MOZ_B2G_BT
-  nsCOMPtr<bluetooth::BluetoothManager> mBluetooth;
+  nsRefPtr<bluetooth::BluetoothManager> mBluetooth;
 #endif
 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
   nsRefPtr<system::AudioChannelManager> mAudioChannelManager;
 #endif
   nsRefPtr<nsDOMCameraManager> mCameraManager;
   nsCOMPtr<nsIDOMNavigatorSystemMessages> mMessagesManager;
   nsTArray<nsRefPtr<nsDOMDeviceStorage> > mDeviceStorageStores;
   nsRefPtr<time::TimeManager> mTimeManager;
--- a/dom/base/nsContentPermissionHelper.cpp
+++ b/dom/base/nsContentPermissionHelper.cpp
@@ -37,17 +37,17 @@ class ContentPermissionRequestParent : p
                                  Element* element,
                                  const IPC::Principal& principal);
   virtual ~ContentPermissionRequestParent();
 
   bool IsBeingDestroyed();
 
   nsCOMPtr<nsIPrincipal> mPrincipal;
   nsCOMPtr<Element> mElement;
-  nsCOMPtr<nsContentPermissionRequestProxy> mProxy;
+  nsRefPtr<nsContentPermissionRequestProxy> mProxy;
   nsTArray<PermissionRequest> mRequests;
 
  private:
   virtual bool Recvprompt();
   virtual void ActorDestroy(ActorDestroyReason why);
 };
 
 ContentPermissionRequestParent::ContentPermissionRequestParent(const nsTArray<PermissionRequest>& aRequests,
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -5028,17 +5028,17 @@ float
 nsGlobalWindow::GetDevicePixelRatio(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(GetDevicePixelRatio, (aError), aError, 0.0);
 
   if (!mDocShell) {
     return 1.0;
   }
 
-  nsCOMPtr<nsPresContext> presContext;
+  nsRefPtr<nsPresContext> presContext;
   mDocShell->GetPresContext(getter_AddRefs(presContext));
   if (!presContext) {
     return 1.0;
   }
 
   return float(nsPresContext::AppUnitsPerCSSPixel())/
       presContext->AppUnitsPerDevPixel();
 }
--- a/dom/camera/DOMCameraControl.cpp
+++ b/dom/camera/DOMCameraControl.cpp
@@ -608,58 +608,58 @@ nsDOMCameraControl::SensorAngle()
   int32_t angle = 0;
   mCameraControl->Get(CAMERA_PARAM_SENSORANGLE, angle);
   return angle;
 }
 
 already_AddRefed<CameraShutterCallback>
 nsDOMCameraControl::GetOnShutter()
 {
-  nsCOMPtr<CameraShutterCallback> cb = mOnShutterCb;
+  nsRefPtr<CameraShutterCallback> cb = mOnShutterCb;
   return cb.forget();
 }
 
 void
 nsDOMCameraControl::SetOnShutter(CameraShutterCallback* aCb)
 {
   mOnShutterCb = aCb;
 }
 
 /* attribute CameraClosedCallback onClosed; */
 already_AddRefed<CameraClosedCallback>
 nsDOMCameraControl::GetOnClosed()
 {
-  nsCOMPtr<CameraClosedCallback> onClosed = mOnClosedCb;
+  nsRefPtr<CameraClosedCallback> onClosed = mOnClosedCb;
   return onClosed.forget();
 }
 
 void
 nsDOMCameraControl::SetOnClosed(CameraClosedCallback* aCb)
 {
   mOnClosedCb = aCb;
 }
 
 already_AddRefed<CameraRecorderStateChange>
 nsDOMCameraControl::GetOnRecorderStateChange()
 {
-  nsCOMPtr<CameraRecorderStateChange> cb = mOnRecorderStateChangeCb;
+  nsRefPtr<CameraRecorderStateChange> cb = mOnRecorderStateChangeCb;
   return cb.forget();
 }
 
 void
 nsDOMCameraControl::SetOnRecorderStateChange(CameraRecorderStateChange* aCb)
 {
   mOnRecorderStateChangeCb = aCb;
 }
 
 /* attribute CameraPreviewStateChange onPreviewStateChange; */
 already_AddRefed<CameraPreviewStateChange>
 nsDOMCameraControl::GetOnPreviewStateChange()
 {
-  nsCOMPtr<CameraPreviewStateChange> cb = mOnPreviewStateChangeCb;
+  nsRefPtr<CameraPreviewStateChange> cb = mOnPreviewStateChangeCb;
   return cb.forget();
 }
 void
 nsDOMCameraControl::SetOnPreviewStateChange(CameraPreviewStateChange* aCb)
 {
   mOnPreviewStateChangeCb = aCb;
 }
 
@@ -778,17 +778,17 @@ nsDOMCameraControl::ResumePreview(ErrorR
 void
 nsDOMCameraControl::SetConfiguration(const CameraConfiguration& aConfiguration,
                                      const Optional<OwningNonNull<CameraSetConfigurationCallback> >& aOnSuccess,
                                      const Optional<OwningNonNull<CameraErrorCallback> >& aOnError,
                                      ErrorResult& aRv)
 {
   MOZ_ASSERT(mCameraControl);
 
-  nsCOMPtr<CameraTakePictureCallback> cb = mTakePictureOnSuccessCb;
+  nsRefPtr<CameraTakePictureCallback> cb = mTakePictureOnSuccessCb;
   if (cb) {
     // We're busy taking a picture, can't change modes right now.
     if (aOnError.WasPassed()) {
       ErrorResult ignored;
       aOnError.Value().Call(NS_LITERAL_STRING("Busy"), ignored);
     }
     aRv = NS_ERROR_FAILURE;
     return;
@@ -817,22 +817,22 @@ nsDOMCameraControl::SetConfiguration(con
 
 void
 nsDOMCameraControl::AutoFocus(CameraAutoFocusCallback& aOnSuccess,
                               const Optional<OwningNonNull<CameraErrorCallback> >& aOnError,
                               ErrorResult& aRv)
 {
   MOZ_ASSERT(mCameraControl);
 
-  nsCOMPtr<CameraAutoFocusCallback> cb = mAutoFocusOnSuccessCb.forget();
+  nsRefPtr<CameraAutoFocusCallback> cb = mAutoFocusOnSuccessCb.forget();
   bool cancel = false;
   if (cb) {
     // we have a callback, which means we're already in the process of
     // auto-focusing--cancel the old callback
-    nsCOMPtr<CameraErrorCallback> ecb = mAutoFocusOnErrorCb.forget();
+    nsRefPtr<CameraErrorCallback> ecb = mAutoFocusOnErrorCb.forget();
     if (ecb) {
       ErrorResult ignored;
       ecb->Call(NS_LITERAL_STRING("Interrupted"), ignored);
     }
     cancel = true;
   }
 
   mAutoFocusOnSuccessCb = &aOnSuccess;
@@ -847,17 +847,17 @@ nsDOMCameraControl::AutoFocus(CameraAuto
 void
 nsDOMCameraControl::TakePicture(const CameraPictureOptions& aOptions,
                                 CameraTakePictureCallback& aOnSuccess,
                                 const Optional<OwningNonNull<CameraErrorCallback> >& aOnError,
                                 ErrorResult& aRv)
 {
   MOZ_ASSERT(mCameraControl);
 
-  nsCOMPtr<CameraTakePictureCallback> cb = mTakePictureOnSuccessCb;
+  nsRefPtr<CameraTakePictureCallback> cb = mTakePictureOnSuccessCb;
   if (cb) {
     // There is already a call to TakePicture() in progress, abort this one and
     //  invoke the error callback (if one was passed in).
     if (aOnError.WasPassed()) {
       ErrorResult ignored;
       aOnError.Value().Call(NS_LITERAL_STRING("TakePictureAlreadyInProgress"), ignored);
     }
     aRv = NS_ERROR_FAILURE;
@@ -966,49 +966,49 @@ nsDOMCameraControl::OnHardwareStateChang
 
   DOM_CAMERA_LOGI("DOM OnHardwareStateChange(%d)\n", aState);
 
   switch (aState) {
     case CameraControlListener::kHardwareOpen:
       // The hardware is open, so we can return a camera to JS, even if
       // the preview hasn't started yet.
       if (mGetCameraOnSuccessCb) {
-        nsCOMPtr<GetCameraCallback> cb = mGetCameraOnSuccessCb.forget();
+        nsRefPtr<GetCameraCallback> cb = mGetCameraOnSuccessCb.forget();
         ErrorResult ignored;
         mGetCameraOnErrorCb = nullptr;
         cb->Call(*this, *mCurrentConfiguration, ignored);
       }
       break;
 
     case CameraControlListener::kHardwareClosed:
       if (mReleaseOnSuccessCb) {
         // If we have this event handler, this was a solicited hardware close.
-        nsCOMPtr<CameraReleaseCallback> cb = mReleaseOnSuccessCb.forget();
+        nsRefPtr<CameraReleaseCallback> cb = mReleaseOnSuccessCb.forget();
         mReleaseOnErrorCb = nullptr;
         cb->Call(ignored);
       } else if(mOnClosedCb) {
         // If not, something else closed the hardware.
-        nsCOMPtr<CameraClosedCallback> cb = mOnClosedCb;
+        nsRefPtr<CameraClosedCallback> cb = mOnClosedCb;
         cb->Call(ignored);
       }
       break;
 
     default:
       MOZ_ASSUME_UNREACHABLE("Unanticipated camera hardware state");
   }
 }
 
 void
 nsDOMCameraControl::OnShutter()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   DOM_CAMERA_LOGI("DOM ** SNAP **\n");
 
-  nsCOMPtr<CameraShutterCallback> cb = mOnShutterCb;
+  nsRefPtr<CameraShutterCallback> cb = mOnShutterCb;
   if (cb) {
     ErrorResult ignored;
     cb->Call(ignored);
   }
 }
 
 void
 nsDOMCameraControl::OnPreviewStateChange(CameraControlListener::PreviewState aState)
@@ -1025,17 +1025,17 @@ nsDOMCameraControl::OnPreviewStateChange
       state = NS_LITERAL_STRING("started");
       break;
 
     default:
       state = NS_LITERAL_STRING("stopped");
       break;
   }
 
-  nsCOMPtr<CameraPreviewStateChange> cb = mOnPreviewStateChangeCb;
+  nsRefPtr<CameraPreviewStateChange> cb = mOnPreviewStateChangeCb;
   ErrorResult ignored;
   cb->Call(state, ignored);
 }
 
 void
 nsDOMCameraControl::OnRecorderStateChange(CameraControlListener::RecorderState aState,
                                           int32_t aArg, int32_t aTrackNum)
 {
@@ -1043,17 +1043,17 @@ nsDOMCameraControl::OnRecorderStateChang
   MOZ_ASSERT(NS_IsMainThread());
 
   ErrorResult ignored;
   nsString state;
 
   switch (aState) {
     case CameraControlListener::kRecorderStarted:
       if (mStartRecordingOnSuccessCb) {
-        nsCOMPtr<CameraStartRecordingCallback> cb = mStartRecordingOnSuccessCb.forget();
+        nsRefPtr<CameraStartRecordingCallback> cb = mStartRecordingOnSuccessCb.forget();
         mStartRecordingOnErrorCb = nullptr;
         cb->Call(ignored);
       }
       state = NS_LITERAL_STRING("Started");
       break;
 
     case CameraControlListener::kRecorderStopped:
       NotifyRecordingStatusChange(NS_LITERAL_STRING("shutdown"));
@@ -1086,17 +1086,17 @@ nsDOMCameraControl::OnRecorderStateChang
       break;
 #endif
 
     default:
       MOZ_ASSUME_UNREACHABLE("Unanticipated video recorder error");
       return;
   }
 
-  nsCOMPtr<CameraRecorderStateChange> cb = mOnRecorderStateChangeCb;
+  nsRefPtr<CameraRecorderStateChange> cb = mOnRecorderStateChangeCb;
   if (cb) {
     cb->Call(state, ignored);
   }
 }
 
 void
 nsDOMCameraControl::OnConfigurationChange(DOMCameraConfiguration* aConfiguration)
 {
@@ -1112,43 +1112,43 @@ nsDOMCameraControl::OnConfigurationChang
     mCurrentConfiguration->mMaxFocusAreas);
   DOM_CAMERA_LOGI("    maximum metering areas : %d\n",
     mCurrentConfiguration->mMaxMeteringAreas);
   DOM_CAMERA_LOGI("    preview size (w x h)   : %d x %d\n",
     mCurrentConfiguration->mPreviewSize.mWidth, mCurrentConfiguration->mPreviewSize.mHeight);
   DOM_CAMERA_LOGI("    recorder profile       : %s\n",
     NS_ConvertUTF16toUTF8(mCurrentConfiguration->mRecorderProfile).get());
 
-  nsCOMPtr<CameraSetConfigurationCallback> cb = mSetConfigurationOnSuccessCb.forget();
+  nsRefPtr<CameraSetConfigurationCallback> cb = mSetConfigurationOnSuccessCb.forget();
   mSetConfigurationOnErrorCb = nullptr;
   if (cb) {
     ErrorResult ignored;
     cb->Call(*mCurrentConfiguration, ignored);
   }
 }
 
 void
 nsDOMCameraControl::OnAutoFocusComplete(bool aAutoFocusSucceeded)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  nsCOMPtr<CameraAutoFocusCallback> cb = mAutoFocusOnSuccessCb.forget();
+  nsRefPtr<CameraAutoFocusCallback> cb = mAutoFocusOnSuccessCb.forget();
   mAutoFocusOnErrorCb = nullptr;
   if (cb) {
     ErrorResult ignored;
     cb->Call(aAutoFocusSucceeded, ignored);
   }
 }
 
 void
 nsDOMCameraControl::OnTakePictureComplete(nsIDOMBlob* aPicture)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  nsCOMPtr<CameraTakePictureCallback> cb = mTakePictureOnSuccessCb.forget();
+  nsRefPtr<CameraTakePictureCallback> cb = mTakePictureOnSuccessCb.forget();
   mTakePictureOnErrorCb = nullptr;
   if (!cb) {
     // Warn because it shouldn't be possible to get here without
     // having passed a success callback into takePicture(), even
     // though we guard against a nullptr dereference.
     NS_WARNING("DOM Null success callback in OnTakePictureComplete()");
     return;
   }
@@ -1159,17 +1159,17 @@ nsDOMCameraControl::OnTakePictureComplet
 
 void
 nsDOMCameraControl::OnError(CameraControlListener::CameraErrorContext aContext, const nsAString& aError)
 {
   DOM_CAMERA_LOGI("DOM OnError context=%d, error='%s'\n", aContext,
     NS_LossyConvertUTF16toASCII(aError).get());
   MOZ_ASSERT(NS_IsMainThread());
 
-  nsCOMPtr<CameraErrorCallback>* errorCb;
+  nsRefPtr<CameraErrorCallback>* errorCb;
   switch (aContext) {
     case CameraControlListener::kInStartCamera:
       mGetCameraOnSuccessCb = nullptr;
       errorCb = &mGetCameraOnErrorCb;
       break;
 
     case CameraControlListener::kInStopCamera:
       mReleaseOnSuccessCb = nullptr;
@@ -1235,13 +1235,13 @@ nsDOMCameraControl::OnError(CameraContro
 
   if (!*errorCb) {
     DOM_CAMERA_LOGW("DOM No error handler for error '%s' in context=%d\n",
       NS_LossyConvertUTF16toASCII(aError).get(), aContext);
     return;
   }
 
   // kung-fu death grip
-  nsCOMPtr<CameraErrorCallback> cb = (*errorCb).forget();
+  nsRefPtr<CameraErrorCallback> cb = (*errorCb).forget();
   ErrorResult ignored;
   cb->Call(aError, ignored);
 }
 
--- a/dom/camera/DOMCameraControl.h
+++ b/dom/camera/DOMCameraControl.h
@@ -163,34 +163,34 @@ protected:
 
   nsresult Set(JSContext* aCx, uint32_t aKey, const JS::Value& aValue, uint32_t aLimit);
   nsresult Get(JSContext* aCx, uint32_t aKey, JS::Value* aValue);
 
   nsRefPtr<DOMCameraConfiguration>              mCurrentConfiguration;
   nsRefPtr<dom::CameraCapabilities>             mCapabilities;
 
   // solicited camera control event handlers
-  nsCOMPtr<dom::GetCameraCallback>              mGetCameraOnSuccessCb;
-  nsCOMPtr<dom::CameraErrorCallback>            mGetCameraOnErrorCb;
-  nsCOMPtr<dom::CameraAutoFocusCallback>        mAutoFocusOnSuccessCb;
-  nsCOMPtr<dom::CameraErrorCallback>            mAutoFocusOnErrorCb;
-  nsCOMPtr<dom::CameraTakePictureCallback>      mTakePictureOnSuccessCb;
-  nsCOMPtr<dom::CameraErrorCallback>            mTakePictureOnErrorCb;
-  nsCOMPtr<dom::CameraStartRecordingCallback>   mStartRecordingOnSuccessCb;
-  nsCOMPtr<dom::CameraErrorCallback>            mStartRecordingOnErrorCb;
-  nsCOMPtr<dom::CameraReleaseCallback>          mReleaseOnSuccessCb;
-  nsCOMPtr<dom::CameraErrorCallback>            mReleaseOnErrorCb;
-  nsCOMPtr<dom::CameraSetConfigurationCallback> mSetConfigurationOnSuccessCb;
-  nsCOMPtr<dom::CameraErrorCallback>            mSetConfigurationOnErrorCb;
+  nsRefPtr<dom::GetCameraCallback>              mGetCameraOnSuccessCb;
+  nsRefPtr<dom::CameraErrorCallback>            mGetCameraOnErrorCb;
+  nsRefPtr<dom::CameraAutoFocusCallback>        mAutoFocusOnSuccessCb;
+  nsRefPtr<dom::CameraErrorCallback>            mAutoFocusOnErrorCb;
+  nsRefPtr<dom::CameraTakePictureCallback>      mTakePictureOnSuccessCb;
+  nsRefPtr<dom::CameraErrorCallback>            mTakePictureOnErrorCb;
+  nsRefPtr<dom::CameraStartRecordingCallback>   mStartRecordingOnSuccessCb;
+  nsRefPtr<dom::CameraErrorCallback>            mStartRecordingOnErrorCb;
+  nsRefPtr<dom::CameraReleaseCallback>          mReleaseOnSuccessCb;
+  nsRefPtr<dom::CameraErrorCallback>            mReleaseOnErrorCb;
+  nsRefPtr<dom::CameraSetConfigurationCallback> mSetConfigurationOnSuccessCb;
+  nsRefPtr<dom::CameraErrorCallback>            mSetConfigurationOnErrorCb;
 
   // unsolicited event handlers
-  nsCOMPtr<dom::CameraShutterCallback>          mOnShutterCb;
-  nsCOMPtr<dom::CameraClosedCallback>           mOnClosedCb;
-  nsCOMPtr<dom::CameraRecorderStateChange>      mOnRecorderStateChangeCb;
-  nsCOMPtr<dom::CameraPreviewStateChange>       mOnPreviewStateChangeCb;
+  nsRefPtr<dom::CameraShutterCallback>          mOnShutterCb;
+  nsRefPtr<dom::CameraClosedCallback>           mOnClosedCb;
+  nsRefPtr<dom::CameraRecorderStateChange>      mOnRecorderStateChangeCb;
+  nsRefPtr<dom::CameraPreviewStateChange>       mOnPreviewStateChangeCb;
 
   // Camera event listener; we only need this weak reference so that
   //  we can remove the listener from the camera when we're done
   //  with it.
   DOMCameraControlListener* mListener;
 
   // our viewfinder stream
   CameraPreviewMediaStream* mInput;
--- a/dom/camera/DOMCameraManager.cpp
+++ b/dom/camera/DOMCameraManager.cpp
@@ -114,17 +114,17 @@ nsDOMCameraManager::GetCamera(const nsAS
 {
   DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
 
   uint32_t cameraId = 0;  // back (or forward-facing) camera by default
   if (aCamera.EqualsLiteral("front")) {
     cameraId = 1;
   }
 
-  nsCOMPtr<CameraErrorCallback> errorCallback = nullptr;
+  nsRefPtr<CameraErrorCallback> errorCallback = nullptr;
   if (aOnError.WasPassed()) {
     errorCallback = &aOnError.Value();
   }
 
   // Creating this object will trigger the aOnSuccess callback
   //  (or the aOnError one, if it fails).
   nsRefPtr<nsDOMCameraControl> cameraControl =
     new nsDOMCameraControl(cameraId, aInitialConfig, &aOnSuccess, errorCallback, mWindow);
--- a/dom/devicestorage/DeviceStorageRequestChild.cpp
+++ b/dom/devicestorage/DeviceStorageRequestChild.cpp
@@ -185,17 +185,17 @@ DeviceStorageRequestChild::
       uint32_t count = r.paths().Length();
       for (uint32_t i = 0; i < count; i++) {
         nsRefPtr<DeviceStorageFile> dsf
           = new DeviceStorageFile(r.type(), r.paths()[i].storageName(),
                                   r.rootdir(), r.paths()[i].name());
         cursor->mFiles.AppendElement(dsf);
       }
 
-      nsCOMPtr<ContinueCursorEvent> event = new ContinueCursorEvent(cursor);
+      nsRefPtr<ContinueCursorEvent> event = new ContinueCursorEvent(cursor);
       event->Continue();
       break;
     }
 
     default:
     {
       NS_RUNTIMEABORT("not reached");
       break;
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -3324,31 +3324,31 @@ ContentParent::RecvGetGraphicsFeatureSta
 bool
 ContentParent::RecvAddIdleObserver(const uint64_t& aObserver, const uint32_t& aIdleTimeInS)
 {
   nsresult rv;
   nsCOMPtr<nsIIdleService> idleService =
     do_GetService("@mozilla.org/widget/idleservice;1", &rv);
   NS_ENSURE_SUCCESS(rv, false);
 
-  nsCOMPtr<ParentIdleListener> listener = new ParentIdleListener(this, aObserver);
+  nsRefPtr<ParentIdleListener> listener = new ParentIdleListener(this, aObserver);
   mIdleListeners.Put(aObserver, listener);
   idleService->AddIdleObserver(listener, aIdleTimeInS);
   return true;
 }
 
 bool
 ContentParent::RecvRemoveIdleObserver(const uint64_t& aObserver, const uint32_t& aIdleTimeInS)
 {
   nsresult rv;
   nsCOMPtr<nsIIdleService> idleService =
     do_GetService("@mozilla.org/widget/idleservice;1", &rv);
   NS_ENSURE_SUCCESS(rv, false);
 
-  nsCOMPtr<ParentIdleListener> listener;
+  nsRefPtr<ParentIdleListener> listener;
   bool found = mIdleListeners.Get(aObserver, &listener);
   if (found) {
     mIdleListeners.Remove(aObserver);
     idleService->RemoveIdleObserver(listener, aIdleTimeInS);
   }
 
   return true;
 }
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -580,17 +580,17 @@ private:
     bool mCalledCloseWithError;
     bool mCalledKillHard;
 
     friend class CrashReporterParent;
 
     nsRefPtr<nsConsoleService>  mConsoleService;
     nsConsoleService* GetConsoleService();
 
-    nsDataHashtable<nsUint64HashKey, nsCOMPtr<ParentIdleListener> > mIdleListeners;
+    nsDataHashtable<nsUint64HashKey, nsRefPtr<ParentIdleListener> > mIdleListeners;
 
 #ifdef MOZ_X11
     // Dup of child's X socket, used to scope its resources to this
     // object instead of the child process's lifetime.
     ScopedClose mChildXSocketFdDup;
 #endif
 };
 
--- a/dom/plugins/base/nsNPAPIPluginInstance.h
+++ b/dom/plugins/base/nsNPAPIPluginInstance.h
@@ -321,17 +321,17 @@ protected:
 
   NPDrawingModel mDrawingModel;
 
 #ifdef MOZ_WIDGET_ANDROID
   uint32_t mANPDrawingModel;
 
   friend class PluginEventRunnable;
 
-  nsTArray<nsCOMPtr<PluginEventRunnable>> mPostedEvents;
+  nsTArray<nsRefPtr<PluginEventRunnable>> mPostedEvents;
   void PopPostedEvent(PluginEventRunnable* r);
   void OnSurfaceTextureFrameAvailable();
 
   uint32_t mFullScreenOrientation;
   bool mWakeLocked;
   bool mFullScreen;
   bool mInverted;
 
--- a/dom/smil/nsSMILTimeValueSpec.h
+++ b/dom/smil/nsSMILTimeValueSpec.h
@@ -119,12 +119,12 @@ protected:
     }
 
     NS_DECL_ISUPPORTS
     NS_DECL_NSIDOMEVENTLISTENER
 
   private:
     nsSMILTimeValueSpec* mSpec;
   };
-  nsCOMPtr<EventListener> mEventListener;
+  nsRefPtr<EventListener> mEventListener;
 };
 
 #endif // NS_SMILTIMEVALUESPEC_H_
--- a/editor/composer/src/nsEditorSpellCheck.cpp
+++ b/editor/composer/src/nsEditorSpellCheck.cpp
@@ -139,17 +139,17 @@ public:
 
   nsCOMPtr<nsIEditorSpellCheckCallback> mCallback;
   uint32_t mGroup;
   nsString mRootContentLang;
   nsString mRootDocContentLang;
   nsString mDictionary;
 
 private:
-  nsCOMPtr<nsEditorSpellCheck> mSpellCheck;
+  nsRefPtr<nsEditorSpellCheck> mSpellCheck;
 };
 NS_IMPL_ISUPPORTS1(DictionaryFetcher, nsIContentPrefCallback2)
 
 NS_IMETHODIMP
 DictionaryFetcher::Fetch(nsIEditor* aEditor)
 {
   NS_ENSURE_ARG_POINTER(aEditor);
 
--- a/embedding/components/find/src/nsFind.h
+++ b/embedding/components/find/src/nsFind.h
@@ -3,16 +3,17 @@
  * 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 nsFind_h__
 #define nsFind_h__
 
 #include "nsIFind.h"
 
+#include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsIDOMNode.h"
 #include "nsIDOMRange.h"
 #include "nsIContentIterator.h"
 #include "nsIWordBreaker.h"
 
 class nsIAtom;
@@ -64,12 +65,12 @@ protected:
                     bool aContinueOk);
 
   // Reset variables before returning -- don't hold any references.
   void ResetAll();
 
   // The iterator we use to move through the document:
   nsresult InitIterator(nsIDOMNode* aStartNode, int32_t aStartOffset,
                         nsIDOMNode* aEndNode, int32_t aEndOffset);
-  nsCOMPtr<nsFindContentIterator> mIterator;
+  nsRefPtr<nsFindContentIterator> mIterator;
 };
 
 #endif // nsFind_h__
--- a/extensions/auth/nsAuthFactory.cpp
+++ b/extensions/auth/nsAuthFactory.cpp
@@ -1,14 +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 "mozilla/ModuleUtils.h"
 #include "nsAuth.h"
+#include "nsAutoPtr.h"
 
 //-----------------------------------------------------------------------------
 
 #define NS_HTTPNEGOTIATEAUTH_CID                   \
 { /* 75c80fd0-accb-432c-af59-ec60668c3990 */       \
   0x75c80fd0,                                      \
   0xaccb,                                          \
   0x432c,                                          \
@@ -107,17 +108,17 @@ nsKerbSSPIAuthConstructor(nsISupports *o
 
 #include "nsAuthSambaNTLM.h"
 static nsresult
 nsSambaNTLMAuthConstructor(nsISupports *outer, REFNSIID iid, void **result)
 {
   if (outer)
     return NS_ERROR_NO_AGGREGATION;
 
-  nsCOMPtr<nsAuthSambaNTLM> auth = new nsAuthSambaNTLM();
+  nsRefPtr<nsAuthSambaNTLM> auth = new nsAuthSambaNTLM();
   if (!auth)
     return NS_ERROR_OUT_OF_MEMORY;
 
   nsresult rv = auth->SpawnNTLMAuthHelper();
   if (NS_FAILED(rv)) {
     // Failure here probably means that cached credentials were not available
     return rv;
   }
--- a/extensions/spellcheck/src/mozInlineSpellChecker.h
+++ b/extensions/spellcheck/src/mozInlineSpellChecker.h
@@ -166,17 +166,17 @@ private:
 
   // This number is incremented each time the spell checker is disabled so that
   // pending scheduled spell checks and UpdateCurrentDictionary calls can be
   // ignored when they finish.
   uint32_t mDisabledAsyncToken;
 
   // When mPendingSpellCheck is non-null, this is the callback passed when
   // it was initialized.
-  nsCOMPtr<InitEditorSpellCheckCallback> mPendingInitEditorSpellCheckCallback;
+  nsRefPtr<InitEditorSpellCheckCallback> mPendingInitEditorSpellCheckCallback;
 
   // Set when we have spellchecked after the last edit operation. See the
   // commment at the top of the .cpp file for more info.
   bool mNeedsCheckAfterNavigation;
 
   // Set when we have a pending mozInlineSpellResume which will check
   // the whole document.
   bool mFullSpellCheckScheduled;
--- a/gfx/layers/LayerScope.cpp
+++ b/gfx/layers/LayerScope.cpp
@@ -309,17 +309,17 @@ public:
         return (mHandlers.Length() != 0) ? true : false;
     }
 
     void AppendDebugData(DebugGLData *aDebugData);
     void DispatchDebugData();
 private:
     nsTArray<nsRefPtr<LayerScopeWebSocketHandler> > mHandlers;
     nsCOMPtr<nsIThread> mDebugSenderThread;
-    nsCOMPtr<DebugDataSender> mCurrentSender;
+    nsRefPtr<DebugDataSender> mCurrentSender;
     nsCOMPtr<nsIServerSocket> mServerSocket;
 };
 
 static StaticAutoPtr<LayerScopeWebSocketManager> gLayerScopeWebSocketManager;
 
 class DebugGLData : public LinkedListElement<DebugGLData> {
 public:
     typedef enum {
--- a/ipc/glue/BackgroundImpl.cpp
+++ b/ipc/glue/BackgroundImpl.cpp
@@ -1516,17 +1516,17 @@ ChildImpl::GetOrCreateForCurrentThread(
   if (NS_IsMainThread()) {
     if (NS_WARN_IF(!OpenProtocolOnMainThread(NS_GetCurrentThread()))) {
       return false;
     }
 
     return true;
   }
 
-  nsCOMPtr<CreateActorRunnable> runnable = new CreateActorRunnable();
+  nsRefPtr<CreateActorRunnable> runnable = new CreateActorRunnable();
   if (NS_FAILED(NS_DispatchToMainThread(runnable, NS_DISPATCH_NORMAL))) {
     CRASH_IN_CHILD_PROCESS("Failed to dispatch to main thread!");
     return false;
   }
 
   return true;
 }
 
--- a/layout/generic/nsSubDocumentFrame.cpp
+++ b/layout/generic/nsSubDocumentFrame.cpp
@@ -1037,17 +1037,17 @@ EndSwapDocShellsForDocument(nsIDocument*
   // Our docshell and view trees have been updated for the new hierarchy.
   // Now also update all nsDeviceContext::mWidget to that of the
   // container view in the new hierarchy.
   nsCOMPtr<nsIDocShell> ds = aDocument->GetDocShell();
   if (ds) {
     nsCOMPtr<nsIContentViewer> cv;
     ds->GetContentViewer(getter_AddRefs(cv));
     while (cv) {
-      nsCOMPtr<nsPresContext> pc;
+      nsRefPtr<nsPresContext> pc;
       cv->GetPresContext(getter_AddRefs(pc));
       if (pc && pc->GetPresShell()) {
         pc->GetPresShell()->SetNeverPainting(ds->IsInvisible());
       }
       nsDeviceContext* dc = pc ? pc->DeviceContext() : nullptr;
       if (dc) {
         nsView* v = cv->FindContainerView();
         dc->Init(v ? v->GetNearestWidget(nullptr) : nullptr);
--- a/layout/inspector/nsFontFaceList.cpp
+++ b/layout/inspector/nsFontFaceList.cpp
@@ -79,17 +79,17 @@ nsFontFaceList::AddFontsFromTextRun(gfxT
     // if we have already listed this face, just make sure the match type is
     // recorded
     nsFontFace* existingFace =
       static_cast<nsFontFace*>(mFontFaces.GetWeak(fe));
     if (existingFace) {
       existingFace->AddMatchType(iter.GetGlyphRun()->mMatchType);
     } else {
       // A new font entry we haven't seen before
-      nsCOMPtr<nsFontFace> ff =
+      nsRefPtr<nsFontFace> ff =
         new nsFontFace(fe, aTextRun->GetFontGroup(),
                        iter.GetGlyphRun()->mMatchType);
       mFontFaces.Put(fe, ff);
     }
   }
 
   return NS_OK;
 }
--- a/layout/mathml/nsMathMLmactionFrame.h
+++ b/layout/mathml/nsMathMLmactionFrame.h
@@ -57,16 +57,16 @@ protected:
   nsMathMLmactionFrame(nsStyleContext* aContext) :
     nsMathMLSelectedFrame(aContext) {}
   virtual ~nsMathMLmactionFrame();
   
 private:
   int32_t         mActionType;
   int32_t         mChildCount;
   int32_t         mSelection;
-  nsCOMPtr<MouseListener> mListener;
+  nsRefPtr<MouseListener> mListener;
 
   // helper to return the frame for the attribute selection="number"
   nsIFrame* 
   GetSelectedFrame() MOZ_OVERRIDE;
 };
 
 #endif /* nsMathMLmactionFrame_h___ */
--- a/layout/style/MediaQueryList.h
+++ b/layout/style/MediaQueryList.h
@@ -6,17 +6,16 @@
 /* implements DOM interface for querying and observing media queries */
 
 #ifndef mozilla_dom_MediaQueryList_h
 #define mozilla_dom_MediaQueryList_h
 
 #include "nsISupports.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsAutoPtr.h"
-#include "nsCOMPtr.h"
 #include "nsTArray.h"
 #include "prclist.h"
 #include "mozilla/Attributes.h"
 #include "nsWrapperCache.h"
 #include "mozilla/dom/MediaQueryListBinding.h"
 
 class nsPresContext;
 class nsMediaList;
@@ -39,17 +38,17 @@ private:
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaQueryList)
 
   nsISupports* GetParentObject() const;
 
   struct HandleChangeData {
     nsRefPtr<MediaQueryList> mql;
-    nsCOMPtr<mozilla::dom::MediaQueryListListener> callback;
+    nsRefPtr<mozilla::dom::MediaQueryListListener> callback;
   };
 
   typedef FallibleTArray< nsRefPtr<mozilla::dom::MediaQueryListListener> > CallbackList;
   typedef FallibleTArray<HandleChangeData> NotifyList;
 
   // Appends listeners that need notification to aListenersToNotify
   void MediumFeaturesChanged(NotifyList &aListenersToNotify);
 
--- a/media/mtransport/nriceresolver.cpp
+++ b/media/mtransport/nriceresolver.cpp
@@ -144,17 +144,17 @@ int NrIceResolver::resolve(void *obj,
 
 int NrIceResolver::resolve(nr_resolver_resource *resource,
                            int (*cb)(void *cb_arg, nr_transport_addr *addr),
                            void *cb_arg,
                            void **handle) {
   int _status;
   MOZ_ASSERT(allocated_resolvers_ > 0);
   ASSERT_ON_THREAD(sts_thread_);
-  nsCOMPtr<PendingResolution> pr;
+  nsRefPtr<PendingResolution> pr;
 
   if (resource->transport_protocol != IPPROTO_UDP &&
       resource->transport_protocol != IPPROTO_TCP) {
     MOZ_MTLOG(ML_ERROR, "Only UDP and TCP are is supported.");
     ABORT(R_NOT_FOUND);
   }
   pr = new PendingResolution(sts_thread_,
                              resource->port? resource->port : 3478,
--- a/media/mtransport/transportlayerprsock.h
+++ b/media/mtransport/transportlayerprsock.h
@@ -104,17 +104,17 @@ class TransportLayerPrsock : public Tran
     TL_SET_STATE(TS_CLOSED);
   }
   void IsLocal(bool *aIsLocal) {
     // TODO(jesup): better check? Does it matter? (likely no)
     *aIsLocal = false;
   }
 
   PRFileDesc *fd_;
-  nsCOMPtr<SocketHandler> handler_;
+  nsRefPtr<SocketHandler> handler_;
   nsCOMPtr<nsISocketTransportService> stservice_;
 
 };
 
 
 
 }  // close namespace
 #endif
--- a/netwerk/base/src/BackgroundFileSaver.cpp
+++ b/netwerk/base/src/BackgroundFileSaver.cpp
@@ -77,17 +77,17 @@ public:
   }
 
   NS_IMETHODIMP Run()
   {
     return mSaver->NotifyTargetChange(mTarget);
   }
 
 private:
-  nsCOMPtr<BackgroundFileSaver> mSaver;
+  nsRefPtr<BackgroundFileSaver> mSaver;
   nsCOMPtr<nsIFile> mTarget;
 };
 
 ////////////////////////////////////////////////////////////////////////////////
 //// BackgroundFileSaver
 
 uint32_t BackgroundFileSaver::sThreadCount = 0;
 uint32_t BackgroundFileSaver::sTelemetryMaxThreadCount = 0;
--- a/netwerk/base/src/nsUDPSocket.cpp
+++ b/netwerk/base/src/nsUDPSocket.cpp
@@ -347,17 +347,17 @@ nsUDPSocket::OnSocketReady(PRFileDesc *f
   net_ResolveSegmentParams(segsize, segcount);
   nsresult rv = NS_NewPipe2(getter_AddRefs(pipeIn), getter_AddRefs(pipeOut),
                 true, true, segsize, segcount);
 
   if (NS_FAILED(rv)) {
     return;
   }
 
-  nsCOMPtr<nsUDPOutputStream> os = new nsUDPOutputStream(this, mFD, prClientAddr);
+  nsRefPtr<nsUDPOutputStream> os = new nsUDPOutputStream(this, mFD, prClientAddr);
   rv = NS_AsyncCopy(pipeIn, os, mSts,
                     NS_ASYNCCOPY_VIA_READSEGMENTS, 1400);
 
   if (NS_FAILED(rv)) {
     return;
   }
 
   nsCOMPtr<nsIUDPMessage> message = new nsUDPMessage(&prClientAddr, pipeOut, data);
--- a/netwerk/cache/nsCacheEntryDescriptor.cpp
+++ b/netwerk/cache/nsCacheEntryDescriptor.cpp
@@ -59,17 +59,17 @@ public:
             // posted event will release the reference on the correct thread
             mListener = nullptr;
         }
 
         return NS_OK;
     }
 
 private:
-    nsCOMPtr<nsCacheEntryDescriptor> mDescriptor;
+    nsRefPtr<nsCacheEntryDescriptor> mDescriptor;
     nsICacheListener                *mListener;
     nsCOMPtr<nsIThread>              mThread;
 };
 
 
 NS_IMPL_ISUPPORTS2(nsCacheEntryDescriptor,
                    nsICacheEntryDescriptor,
                    nsICacheEntryInfo)
--- a/netwerk/cache2/CacheIndex.cpp
+++ b/netwerk/cache2/CacheIndex.cpp
@@ -1693,17 +1693,17 @@ private:
 
   nsresult FlushBuffer();
 
   nsresult            mStatus;
   PRFileDesc         *mFD;
   char               *mBuf;
   uint32_t            mBufSize;
   int32_t             mBufPos;
-  nsCOMPtr<CacheHash> mHash;
+  nsRefPtr<CacheHash> mHash;
 };
 
 nsresult
 WriteLogHelper::AddEntry(CacheIndexEntry *aEntry)
 {
   nsresult rv;
 
   if (NS_FAILED(mStatus)) {
--- a/netwerk/test/TestUDPSocket.cpp
+++ b/netwerk/test/TestUDPSocket.cpp
@@ -208,27 +208,27 @@ main(int32_t argc, char *argv[])
   // Create UDPSocket
   nsCOMPtr<nsIUDPSocket> server, client;
   server = do_CreateInstance("@mozilla.org/network/udp-socket;1", &rv);
   NS_ENSURE_SUCCESS(rv, -1);
   client = do_CreateInstance("@mozilla.org/network/udp-socket;1", &rv);
   NS_ENSURE_SUCCESS(rv, -1);
 
   // Create UDPServerListener to process UDP packets
-  nsCOMPtr<UDPServerListener> serverListener = new UDPServerListener();
+  nsRefPtr<UDPServerListener> serverListener = new UDPServerListener();
 
   // Bind server socket to 127.0.0.1
   rv = server->Init(0, true);
   NS_ENSURE_SUCCESS(rv, -1);
   int32_t serverPort;
   server->GetPort(&serverPort);
   server->AsyncListen(serverListener);
 
   // Bind clinet on arbitrary port
-  nsCOMPtr<UDPClientListener> clientListener = new UDPClientListener();
+  nsRefPtr<UDPClientListener> clientListener = new UDPClientListener();
   client->Init(0, true);
   client->AsyncListen(clientListener);
 
   // Write data to server
   uint32_t count;
   const uint32_t data = REQUEST;
 
   phase = TEST_OUTPUT_STREAM;
--- a/parser/xml/src/nsSAXXMLReader.cpp
+++ b/parser/xml/src/nsSAXXMLReader.cpp
@@ -82,17 +82,17 @@ nsSAXXMLReader::HandleStartElement(const
                                    const char16_t **aAtts,
                                    uint32_t aAttsCount,
                                    int32_t aIndex,
                                    uint32_t aLineNumber)
 {
   if (!mContentHandler)
     return NS_OK;
 
-  nsCOMPtr<nsSAXAttributes> atts = new nsSAXAttributes();
+  nsRefPtr<nsSAXAttributes> atts = new nsSAXAttributes();
   if (!atts)
     return NS_ERROR_OUT_OF_MEMORY;
   nsAutoString uri, localName, qName;
   for (; *aAtts; aAtts += 2) {
     SplitExpatName(aAtts[0], uri, localName, qName);
     // XXX don't have attr type information
     NS_NAMED_LITERAL_STRING(cdataType, "CDATA");
     // could support xmlns reporting, it's a standard SAX feature
--- a/security/manager/ssl/src/nsNSSCallbacks.cpp
+++ b/security/manager/ssl/src/nsNSSCallbacks.cpp
@@ -54,17 +54,17 @@ class nsHTTPDownloadEvent : public nsRun
 public:
   nsHTTPDownloadEvent();
   ~nsHTTPDownloadEvent();
 
   NS_IMETHOD Run();
 
   nsNSSHttpRequestSession *mRequestSession;
   
-  nsCOMPtr<nsHTTPListener> mListener;
+  nsRefPtr<nsHTTPListener> mListener;
   bool mResponsibleForDoneSignal;
   TimeStamp mStartTime;
 };
 
 nsHTTPDownloadEvent::nsHTTPDownloadEvent()
 :mResponsibleForDoneSignal(true)
 {
 }
@@ -162,17 +162,17 @@ nsHTTPDownloadEvent::Run()
     mListener->mLoadGroup = nullptr;
     mListener->mLoadGroupOwnerThread = nullptr;
   }
 
   return NS_OK;
 }
 
 struct nsCancelHTTPDownloadEvent : nsRunnable {
-  nsCOMPtr<nsHTTPListener> mListener;
+  nsRefPtr<nsHTTPListener> mListener;
 
   NS_IMETHOD Run() {
     mListener->FreeLoadGroup(true);
     mListener = nullptr;
     return NS_OK;
   }
 };
 
--- a/security/manager/ssl/src/nsNSSCallbacks.h
+++ b/security/manager/ssl/src/nsNSSCallbacks.h
@@ -2,16 +2,17 @@
  *
  * 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 _NSNSSCALLBACKS_H_
 #define _NSNSSCALLBACKS_H_
 
+#include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "pk11func.h"
 #include "nspr.h"
 #include "ocspt.h"
 #include "nsIStreamLoader.h"
 #include "mozilla/CondVar.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/Attributes.h"
@@ -115,17 +116,17 @@ public:
   nsCString mRequestMethod;
   
   bool mHasPostData;
   nsCString mPostData;
   nsCString mPostContentType;
   
   PRIntervalTime mTimeoutInterval;
   
-  nsCOMPtr<nsHTTPListener> mListener;
+  nsRefPtr<nsHTTPListener> mListener;
   
 protected:
   nsNSSHttpRequestSession();
   ~nsNSSHttpRequestSession();
 
   SECStatus internal_send_receive_attempt(bool &retryable_error,
                                           PRPollDesc **pPollDesc,
                                           uint16_t *http_response_code,
--- a/storage/src/VacuumManager.cpp
+++ b/storage/src/VacuumManager.cpp
@@ -201,17 +201,17 @@ Vacuumer::execute()
   // vacuum, if they are executed in the same transaction.
   nsCOMPtr<mozIStorageAsyncStatement> pageSizeStmt;
   nsAutoCString pageSizeQuery(MOZ_STORAGE_UNIQUIFY_QUERY_STR
                               "PRAGMA page_size = ");
   pageSizeQuery.AppendInt(expectedPageSize);
   rv = mDBConn->CreateAsyncStatement(pageSizeQuery,
                                      getter_AddRefs(pageSizeStmt));
   NS_ENSURE_SUCCESS(rv, false);
-  nsCOMPtr<BaseCallback> callback = new BaseCallback();
+  nsRefPtr<BaseCallback> callback = new BaseCallback();
   nsCOMPtr<mozIStoragePendingStatement> ps;
   rv = pageSizeStmt->ExecuteAsync(callback, getter_AddRefs(ps));
   NS_ENSURE_SUCCESS(rv, false);
 
   nsCOMPtr<mozIStorageAsyncStatement> stmt;
   rv = mDBConn->CreateAsyncStatement(NS_LITERAL_CSTRING(
     "VACUUM"
   ), getter_AddRefs(stmt));
@@ -370,17 +370,17 @@ VacuumManager::Observe(nsISupports *aSub
     // skipping some, since we run daily.  So we use a starting index.
     static const char* kPrefName = PREF_VACUUM_BRANCH "index";
     int32_t startIndex = Preferences::GetInt(kPrefName, 0);
     if (startIndex >= entries.Count()) {
       startIndex = 0;
     }
     int32_t index;
     for (index = startIndex; index < entries.Count(); ++index) {
-      nsCOMPtr<Vacuumer> vacuum = new Vacuumer(entries[index]);
+      nsRefPtr<Vacuumer> vacuum = new Vacuumer(entries[index]);
       // Only vacuum one database per day.
       if (vacuum->execute()) {
         break;
       }
     }
     DebugOnly<nsresult> rv = Preferences::SetInt(kPrefName, index);
     MOZ_ASSERT(NS_SUCCEEDED(rv), "Should be able to set a preference");
   }
--- a/toolkit/components/url-classifier/nsUrlClassifierDBService.h
+++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.h
@@ -76,17 +76,17 @@ private:
 
   // Close db connection and join the background thread if it exists.
   nsresult Shutdown();
 
   // Check if the key is on a known-clean host.
   nsresult CheckClean(const nsACString &lookupKey,
                       bool *clean);
 
-  nsCOMPtr<nsUrlClassifierDBServiceWorker> mWorker;
+  nsRefPtr<nsUrlClassifierDBServiceWorker> mWorker;
   nsCOMPtr<nsIUrlClassifierDBServiceWorker> mWorkerProxy;
 
   nsInterfaceHashtable<nsCStringHashKey, nsIUrlClassifierHashCompleter> mCompleters;
 
   // TRUE if the nsURIClassifier implementation should check for malware
   // uris on document loads.
   bool mCheckMalware;
 
--- a/toolkit/profile/nsToolkitProfileService.cpp
+++ b/toolkit/profile/nsToolkitProfileService.cpp
@@ -45,17 +45,17 @@ using namespace mozilla;
 
 class nsToolkitProfile MOZ_FINAL : public nsIToolkitProfile
 {
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSITOOLKITPROFILE
 
     friend class nsToolkitProfileService;
-    nsCOMPtr<nsToolkitProfile> mNext;
+    nsRefPtr<nsToolkitProfile> mNext;
     nsToolkitProfile          *mPrev;
 
     ~nsToolkitProfile() { }
 
 private:
     nsToolkitProfile(const nsACString& aName,
                      nsIFile* aRootDir,
                      nsIFile* aLocalDir,
@@ -80,17 +80,17 @@ public:
     nsresult Init(nsToolkitProfile* aProfile, nsIProfileUnlocker* *aUnlocker);
     nsresult Init(nsIFile* aDirectory, nsIFile* aLocalDirectory,
                   nsIProfileUnlocker* *aUnlocker);
 
     nsToolkitProfileLock() { }
     ~nsToolkitProfileLock();
 
 private:
-    nsCOMPtr<nsToolkitProfile> mProfile;
+    nsRefPtr<nsToolkitProfile> mProfile;
     nsCOMPtr<nsIFile> mDirectory;
     nsCOMPtr<nsIFile> mLocalDirectory;
 
     nsProfileLock mLock;
 };
 
 class nsToolkitProfileFactory MOZ_FINAL : public nsIFactory
 {
@@ -151,17 +151,17 @@ private:
     public:
         NS_DECL_ISUPPORTS
         NS_DECL_NSISIMPLEENUMERATOR
 
         ProfileEnumerator(nsToolkitProfile *first)
           { mCurrent = first; }
     private:
         ~ProfileEnumerator() { }
-        nsCOMPtr<nsToolkitProfile> mCurrent;
+        nsRefPtr<nsToolkitProfile> mCurrent;
     };
 };
 
 nsToolkitProfile::nsToolkitProfile(const nsACString& aName,
                                    nsIFile* aRootDir,
                                    nsIFile* aLocalDir,
                                    nsToolkitProfile* aPrev,
                                    bool aForExternalApp) :
@@ -269,17 +269,17 @@ nsToolkitProfile::Remove(bool removeFile
 NS_IMETHODIMP
 nsToolkitProfile::Lock(nsIProfileUnlocker* *aUnlocker, nsIProfileLock* *aResult)
 {
     if (mLock) {
         NS_ADDREF(*aResult = mLock);
         return NS_OK;
     }
 
-    nsCOMPtr<nsToolkitProfileLock> lock = new nsToolkitProfileLock();
+    nsRefPtr<nsToolkitProfileLock> lock = new nsToolkitProfileLock();
     if (!lock) return NS_ERROR_OUT_OF_MEMORY;
 
     nsresult rv = lock->Init(this, aUnlocker);
     if (NS_FAILED(rv)) return rv;
 
     NS_ADDREF(*aResult = lock);
     return NS_OK;
 }
@@ -590,17 +590,17 @@ nsToolkitProfileService::LockProfilePath
 {
     return NS_LockProfilePath(aDirectory, aLocalDirectory, nullptr, aResult);
 }
 
 nsresult
 NS_LockProfilePath(nsIFile* aPath, nsIFile* aTempPath,
                    nsIProfileUnlocker* *aUnlocker, nsIProfileLock* *aResult)
 {
-    nsCOMPtr<nsToolkitProfileLock> lock = new nsToolkitProfileLock();
+    nsRefPtr<nsToolkitProfileLock> lock = new nsToolkitProfileLock();
     if (!lock) return NS_ERROR_OUT_OF_MEMORY;
 
     nsresult rv = lock->Init(aPath, aTempPath, aUnlocker);
     if (NS_FAILED(rv)) return rv;
 
     NS_ADDREF(*aResult = lock);
     return NS_OK;
 }
--- a/widget/android/nsAppShell.cpp
+++ b/widget/android/nsAppShell.cpp
@@ -357,17 +357,17 @@ nsAppShell::ProcessNextNativeEvent(bool 
 
     case AndroidGeckoEvent::THUMBNAIL: {
         if (!mBrowserApp)
             break;
 
         int32_t tabId = curEvent->MetaState();
         const nsTArray<nsIntPoint>& points = curEvent->Points();
         RefCountedJavaObject* buffer = curEvent->ByteBuffer();
-        nsCOMPtr<ThumbnailRunnable> sr = new ThumbnailRunnable(mBrowserApp, tabId, points, buffer);
+        nsRefPtr<ThumbnailRunnable> sr = new ThumbnailRunnable(mBrowserApp, tabId, points, buffer);
         MessageLoop::current()->PostIdleTask(FROM_HERE, NewRunnableMethod(sr.get(), &ThumbnailRunnable::Run));
         break;
     }
 
     case AndroidGeckoEvent::VIEWPORT:
     case AndroidGeckoEvent::BROADCAST: {
         if (curEvent->Characters().Length() == 0)
             break;
--- a/widget/xpwidgets/nsBaseWidget.h
+++ b/widget/xpwidgets/nsBaseWidget.h
@@ -401,17 +401,17 @@ protected:
 
   nsIWidgetListener* mWidgetListener;
   nsIWidgetListener* mAttachedWidgetListener;
   nsDeviceContext* mContext;
   nsRefPtr<LayerManager> mLayerManager;
   nsRefPtr<LayerManager> mBasicLayerManager;
   nsRefPtr<CompositorChild> mCompositorChild;
   nsRefPtr<CompositorParent> mCompositorParent;
-  nsCOMPtr<WidgetShutdownObserver> mShutdownObserver;
+  nsRefPtr<WidgetShutdownObserver> mShutdownObserver;
   nscolor           mBackground;
   nscolor           mForeground;
   nsCursor          mCursor;
   nsWindowType      mWindowType;
   nsBorderStyle     mBorderStyle;
   bool              mUseLayersAcceleration;
   bool              mForceLayersAcceleration;
   bool              mTemporarilyUseBasicLayerManager;
--- a/xpcom/ds/nsINIParserImpl.cpp
+++ b/xpcom/ds/nsINIParserImpl.cpp
@@ -29,17 +29,17 @@ NS_IMPL_ISUPPORTS2(nsINIParserFactory,
                    nsIFactory)
 
 NS_IMETHODIMP
 nsINIParserFactory::CreateINIParser(nsIFile* aINIFile,
                                     nsIINIParser* *aResult)
 {
   *aResult = nullptr;
 
-  nsCOMPtr<nsINIParserImpl> p(new nsINIParserImpl());
+  nsRefPtr<nsINIParserImpl> p(new nsINIParserImpl());
   if (!p)
     return NS_ERROR_OUT_OF_MEMORY;
 
   nsresult rv = p->Init(aINIFile);
 
   if (NS_SUCCEEDED(rv))
     NS_ADDREF(*aResult = p);