Bug 1268313: Part 6 - Replace NewRunnableMethod with NS_NewRunnableMethod. r=froydnj
☠☠ backed out by c6884584fa07 ☠ ☠
authorKyle Huey <khuey@kylehuey.com>
Thu, 28 Apr 2016 14:08:24 -0700
changeset 295369 4bcb784492bb8d26a13a234cdf581b0badbf21e6
parent 295368 726f7361e0b84942ebcdecf78a2d5296748627f9
child 295370 85ce8cb0639aac2617f81c974d4c10ab80b49bfd
push id30223
push userkwierso@gmail.com
push dateFri, 29 Apr 2016 21:57:49 +0000
treeherderautoland@2b7c421063ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1268313
milestone49.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 1268313: Part 6 - Replace NewRunnableMethod with NS_NewRunnableMethod. r=froydnj
dom/ipc/ContentBridgeChild.cpp
dom/ipc/ContentBridgeParent.cpp
dom/ipc/ContentBridgeParent.h
dom/ipc/ContentParent.cpp
dom/ipc/PreallocatedProcessManager.cpp
dom/media/gmp/GMPDecryptorChild.cpp
dom/media/gmp/GMPPlatform.cpp
dom/media/gmp/GMPStorageChild.cpp
dom/media/gmp/GMPVideoDecoderChild.cpp
dom/media/gmp/GMPVideoEncoderChild.cpp
dom/media/systemservices/MediaSystemResourceManager.cpp
gfx/layers/apz/src/APZCTreeManager.cpp
gfx/layers/apz/src/AsyncPanZoomController.cpp
gfx/layers/apz/src/InputQueue.cpp
gfx/layers/apz/util/APZCCallbackHelper.cpp
gfx/layers/apz/util/APZCCallbackHelper.h
gfx/layers/apz/util/ChromeProcessController.cpp
gfx/layers/ipc/CompositorBridgeParent.cpp
gfx/layers/ipc/RemoteContentController.cpp
gfx/thebes/SoftwareVsyncSource.cpp
gfx/vr/ipc/VRManagerParent.cpp
ipc/chromium/src/base/task.h
widget/nsBaseWidget.cpp
xpcom/base/nsDumpUtils.cpp
xpcom/base/nsDumpUtils.h
--- a/dom/ipc/ContentBridgeChild.cpp
+++ b/dom/ipc/ContentBridgeChild.cpp
@@ -29,18 +29,18 @@ ContentBridgeChild::~ContentBridgeChild(
 {
   RefPtr<DeleteTask<Transport>> task = new DeleteTask<Transport>(mTransport);
   XRE_GetIOMessageLoop()->PostTask(task.forget());
 }
 
 void
 ContentBridgeChild::ActorDestroy(ActorDestroyReason aWhy)
 {
-  MessageLoop::current()->PostTask(
-    NewRunnableMethod(this, &ContentBridgeChild::DeferredDestroy));
+  RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &ContentBridgeChild::DeferredDestroy);
+  MessageLoop::current()->PostTask(runnable.forget());
 }
 
 /*static*/ ContentBridgeChild*
 ContentBridgeChild::Create(Transport* aTransport, ProcessId aOtherPid)
 {
   RefPtr<ContentBridgeChild> bridge =
     new ContentBridgeChild(aTransport);
   bridge->mSelfRef = bridge;
--- a/dom/ipc/ContentBridgeParent.cpp
+++ b/dom/ipc/ContentBridgeParent.cpp
@@ -32,18 +32,18 @@ ContentBridgeParent::~ContentBridgeParen
 
 void
 ContentBridgeParent::ActorDestroy(ActorDestroyReason aWhy)
 {
   nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
   if (os) {
     os->RemoveObserver(this, "content-child-shutdown");
   }
-  MessageLoop::current()->PostTask(
-    NewRunnableMethod(this, &ContentBridgeParent::DeferredDestroy));
+  RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &ContentBridgeParent::DeferredDestroy);
+  MessageLoop::current()->PostTask(runnable.forget());
 }
 
 /*static*/ ContentBridgeParent*
 ContentBridgeParent::Create(Transport* aTransport, ProcessId aOtherPid)
 {
   RefPtr<ContentBridgeParent> bridge =
     new ContentBridgeParent(aTransport);
   bridge->mSelfRef = bridge;
@@ -163,18 +163,18 @@ ContentBridgeParent::DeallocPBrowserPare
   return nsIContentParent::DeallocPBrowserParent(aParent);
 }
 
 void
 ContentBridgeParent::NotifyTabDestroyed()
 {
   int32_t numLiveTabs = ManagedPBrowserParent().Count();
   if (numLiveTabs == 1) {
-    MessageLoop::current()->PostTask(
-      NewRunnableMethod(this, &ContentBridgeParent::Close));
+    RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &ContentBridgeParent::Close);
+    MessageLoop::current()->PostTask(runnable.forget());
   }
 }
 
 // This implementation is identical to ContentParent::GetCPOWManager but we can't
 // move it to nsIContentParent because it calls ManagedPJavaScriptParent() which
 // only exists in PContentParent and PContentBridgeParent.
 jsipc::CPOWManager*
 ContentBridgeParent::GetCPOWManager()
--- a/dom/ipc/ContentBridgeParent.h
+++ b/dom/ipc/ContentBridgeParent.h
@@ -74,16 +74,22 @@ protected:
     mIsForApp = aIsForApp;
   }
 
   void SetIsForBrowser(bool aIsForBrowser)
   {
     mIsForBrowser = aIsForBrowser;
   }
 
+  void Close()
+  {
+    // Trick NS_NewRunnableMethod
+    PContentBridgeParent::Close();
+  }
+
 protected:
   virtual bool
   RecvSyncMessage(const nsString& aMsg,
                   const ClonedMessageData& aData,
                   InfallibleTArray<jsipc::CpowEntry>&& aCpows,
                   const IPC::Principal& aPrincipal,
                   nsTArray<StructuredCloneData>* aRetvals) override;
 
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -2173,19 +2173,20 @@ ContentParent::ActorDestroy(ActorDestroy
       }
     }
     }
   }
 
   // Destroy any processes created by this ContentParent
   for(uint32_t i = 0; i < childIDArray.Length(); i++) {
     ContentParent* cp = cpm->GetContentProcessById(childIDArray[i]);
-    MessageLoop::current()->PostTask(
-      NewRunnableMethod(cp, &ContentParent::ShutDownProcess,
-                        SEND_SHUTDOWN_MESSAGE));
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<ShutDownMethod>(cp, &ContentParent::ShutDownProcess,
+                                                   SEND_SHUTDOWN_MESSAGE);
+    MessageLoop::current()->PostTask(runnable.forget());
   }
   cpm->RemoveContentProcess(this->ChildID());
 
   if (mDriverCrashGuard) {
     mDriverCrashGuard->NotifyCrashed();
   }
 }
 
@@ -2256,19 +2257,20 @@ ContentParent::NotifyTabDestroyed(const 
   // There can be more than one PBrowser for a given app process
   // because of popup windows.  When the last one closes, shut
   // us down.
   ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
   nsTArray<TabId> tabIds = cpm->GetTabParentsByProcessId(this->ChildID());
   if (tabIds.Length() == 1) {
     // In the case of normal shutdown, send a shutdown message to child to
     // allow it to perform shutdown tasks.
-    MessageLoop::current()->PostTask(
-      NewRunnableMethod(this, &ContentParent::ShutDownProcess,
-                        SEND_SHUTDOWN_MESSAGE));
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<ShutDownMethod>(this, &ContentParent::ShutDownProcess,
+                                                   SEND_SHUTDOWN_MESSAGE);
+    MessageLoop::current()->PostTask(runnable.forget());
   }
 }
 
 jsipc::CPOWManager*
 ContentParent::GetCPOWManager()
 {
   if (PJavaScriptParent* p = LoneManagedOrNullAsserts(ManagedPJavaScriptParent())) {
     return CPOWManagerFor(p);
--- a/dom/ipc/PreallocatedProcessManager.cpp
+++ b/dom/ipc/PreallocatedProcessManager.cpp
@@ -199,31 +199,32 @@ PreallocatedProcessManagerImpl::Enable()
 
 void
 PreallocatedProcessManagerImpl::AllocateAfterDelay()
 {
   if (!mEnabled || mPreallocatedAppProcess) {
     return;
   }
 
+  RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &PreallocatedProcessManagerImpl::AllocateOnIdle);
   MessageLoop::current()->PostDelayedTask(
-    NewRunnableMethod(this, &PreallocatedProcessManagerImpl::AllocateOnIdle),
+    runnable.forget(),
     Preferences::GetUint("dom.ipc.processPrelaunch.delayMs",
                          DEFAULT_ALLOCATE_DELAY));
 }
 
 void
 PreallocatedProcessManagerImpl::AllocateOnIdle()
 {
   if (!mEnabled || mPreallocatedAppProcess) {
     return;
   }
 
-  MessageLoop::current()->PostIdleTask(
-    NewRunnableMethod(this, &PreallocatedProcessManagerImpl::AllocateNow));
+  RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &PreallocatedProcessManagerImpl::AllocateNow);
+  MessageLoop::current()->PostIdleTask(runnable.forget());
 }
 
 void
 PreallocatedProcessManagerImpl::AllocateNow()
 {
   if (!mEnabled || mPreallocatedAppProcess) {
     return;
   }
@@ -238,17 +239,17 @@ PreallocatedProcessManagerImpl::Schedule
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (mPreallocateAppProcessTask) {
     // Make sure there is only one request running.
     return;
   }
 
-  RefPtr<CancelableTask> task = NewRunnableMethod(
+  RefPtr<CancelableTask> task = NS_NewCancelableRunnableMethod(
     this, &PreallocatedProcessManagerImpl::DelayedNuwaFork);
   mPreallocateAppProcessTask = task;
   MessageLoop::current()->PostDelayedTask(task.forget(),
     Preferences::GetUint("dom.ipc.processPrelaunch.delayMs",
                          DEFAULT_ALLOCATE_DELAY));
 }
 
 void
--- a/dom/media/gmp/GMPDecryptorChild.cpp
+++ b/dom/media/gmp/GMPDecryptorChild.cpp
@@ -56,17 +56,18 @@ GMPDecryptorChild::CallOnGMPThread(Metho
 {
   if (ON_GMP_THREAD()) {
     // Use forwarding reference when we can.
     CallMethod(aMethod, Forward<ParamType>(aParams)...);
   } else {
     // Use const reference when we have to.
     auto m = &GMPDecryptorChild::CallMethod<
         decltype(aMethod), typename AddConstReference<ParamType>::Type...>;
-    RefPtr<mozilla::Runnable> t = NewRunnableMethod(this, m, aMethod, Forward<ParamType>(aParams)...);
+    RefPtr<mozilla::Runnable> t =
+      dont_add_new_uses_of_this::NewRunnableMethod(this, m, aMethod, Forward<ParamType>(aParams)...);
     mPlugin->GMPMessageLoop()->PostTask(t.forget());
   }
 }
 
 void
 GMPDecryptorChild::Init(GMPDecryptor* aSession)
 {
   MOZ_ASSERT(aSession);
@@ -165,17 +166,21 @@ GMPDecryptorChild::KeyStatusChanged(cons
 }
 
 void
 GMPDecryptorChild::Decrypted(GMPBuffer* aBuffer, GMPErr aResult)
 {
   if (!ON_GMP_THREAD()) {
     // We should run this whole method on the GMP thread since the buffer needs
     // to be deleted after the SendDecrypted call.
-    RefPtr<Runnable> t = NewRunnableMethod(this, &GMPDecryptorChild::Decrypted, aBuffer, aResult);
+    RefPtr<Runnable> t =
+      NS_NewRunnableMethodWithArgs<GMPBuffer*,
+                                   GMPErr>(this,
+                                           &GMPDecryptorChild::Decrypted,
+                                           aBuffer, aResult);
     mPlugin->GMPMessageLoop()->PostTask(t.forget());
     return;
   }
 
   if (!aBuffer) {
     NS_WARNING("GMPDecryptorCallback passed bull GMPBuffer");
     return;
   }
--- a/dom/media/gmp/GMPPlatform.cpp
+++ b/dom/media/gmp/GMPPlatform.cpp
@@ -68,17 +68,18 @@ public:
   void Post()
   {
     // We assert here for two reasons.
     // 1) Nobody should be blocking the main thread.
     // 2) This prevents deadlocks when doing sync calls to main which if the
     //    main thread tries to do a sync call back to the calling thread.
     MOZ_ASSERT(!IsOnChildMainThread());
 
-    mMessageLoop->PostTask(NewRunnableMethod(this, &SyncRunnable::Run));
+    RefPtr<mozilla::Runnable> runnable = NS_NewRunnableMethod(this, &SyncRunnable::Run);
+    mMessageLoop->PostTask(runnable.forget());
     MonitorAutoLock lock(mMonitor);
     while (!mDone) {
       lock.Wait();
     }
   }
 
   void Run()
   {
@@ -116,17 +117,18 @@ CreateThread(GMPThread** aThread)
 GMPErr
 RunOnMainThread(GMPTask* aTask)
 {
   if (!aTask || !sMainLoop) {
     return GMPGenericErr;
   }
 
   RefPtr<Runnable> r = new Runnable(aTask);
-  sMainLoop->PostTask(NewRunnableMethod(r.get(), &Runnable::Run));
+  RefPtr<mozilla::Runnable> runnable = NS_NewRunnableMethod(r, &Runnable::Run);
+  sMainLoop->PostTask(runnable.forget());
 
   return GMPNoErr;
 }
 
 GMPErr
 SyncRunOnMainThread(GMPTask* aTask)
 {
   if (!aTask || !sMainLoop || IsOnChildMainThread()) {
@@ -248,18 +250,18 @@ GMPThreadImpl::Post(GMPTask* aTask)
     bool started = mThread.Start();
     if (!started) {
       NS_WARNING("Unable to start GMPThread!");
       return;
     }
   }
 
   RefPtr<Runnable> r = new Runnable(aTask);
-
-  mThread.message_loop()->PostTask(NewRunnableMethod(r.get(), &Runnable::Run));
+  RefPtr<mozilla::Runnable> runnable = NS_NewRunnableMethod(r, &Runnable::Run);
+  mThread.message_loop()->PostTask(runnable.forget());
 }
 
 void
 GMPThreadImpl::Join()
 {
   {
     MutexAutoLock lock(mMutex);
     if (mThread.IsRunning()) {
--- a/dom/media/gmp/GMPStorageChild.cpp
+++ b/dom/media/gmp/GMPStorageChild.cpp
@@ -10,17 +10,17 @@
 #define ON_GMP_THREAD() (mPlugin->GMPMessageLoop() == MessageLoop::current())
 
 #define CALL_ON_GMP_THREAD(_func, ...) \
   do { \
     if (ON_GMP_THREAD()) { \
       _func(__VA_ARGS__); \
     } else { \
       mPlugin->GMPMessageLoop()->PostTask( \
-        NewRunnableMethod(this, &GMPStorageChild::_func, ##__VA_ARGS__) \
+        dont_add_new_uses_of_this::NewRunnableMethod(this, &GMPStorageChild::_func, ##__VA_ARGS__) \
       ); \
     } \
   } while(false)
 
 static nsTArray<uint8_t>
 ToArray(const uint8_t* aData, uint32_t aDataSize)
 {
   nsTArray<uint8_t> data;
--- a/dom/media/gmp/GMPVideoDecoderChild.cpp
+++ b/dom/media/gmp/GMPVideoDecoderChild.cpp
@@ -221,17 +221,18 @@ GMPVideoDecoderChild::Alloc(size_t aSize
   MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current());
 
   bool rv;
 #ifndef SHMEM_ALLOC_IN_CHILD
   ++mNeedShmemIntrCount;
   rv = CallNeedShmem(aSize, aMem);
   --mNeedShmemIntrCount;
   if (mPendingDecodeComplete) {
-    mPlugin->GMPMessageLoop()->PostTask(NewRunnableMethod(this, &GMPVideoDecoderChild::RecvDecodingComplete));
+    RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &GMPVideoDecoderChild::RecvDecodingComplete);
+    mPlugin->GMPMessageLoop()->PostTask(runnable.forget());
   }
 #else
 #ifdef GMP_SAFE_SHMEM
   rv = AllocShmem(aSize, aType, aMem);
 #else
   rv = AllocUnsafeShmem(aSize, aType, aMem);
 #endif
 #endif
--- a/dom/media/gmp/GMPVideoEncoderChild.cpp
+++ b/dom/media/gmp/GMPVideoEncoderChild.cpp
@@ -202,17 +202,18 @@ GMPVideoEncoderChild::Alloc(size_t aSize
   MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current());
 
   bool rv;
 #ifndef SHMEM_ALLOC_IN_CHILD
   ++mNeedShmemIntrCount;
   rv = CallNeedShmem(aSize, aMem);
   --mNeedShmemIntrCount;
   if (mPendingEncodeComplete) {
-    mPlugin->GMPMessageLoop()->PostTask(NewRunnableMethod(this, &GMPVideoEncoderChild::RecvEncodingComplete));
+    RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &GMPVideoEncoderChild::RecvEncodingComplete);
+    mPlugin->GMPMessageLoop()->PostTask(runnable.forget());
   }
 #else
 #ifdef GMP_SAFE_SHMEM
   rv = AllocShmem(aSize, aType, aMem);
 #else
   rv = AllocUnsafeShmem(aSize, aType, aMem);
 #endif
 #endif
--- a/dom/media/systemservices/MediaSystemResourceManager.cpp
+++ b/dom/media/systemservices/MediaSystemResourceManager.cpp
@@ -193,21 +193,22 @@ MediaSystemResourceManager::Acquire(Medi
     return;
   }
   // State Check
   if (aClient->mResourceState != MediaSystemResourceClient::RESOURCE_STATE_START) {
     HandleAcquireResult(aClient->mId, false);
     return;
   }
   aClient->mResourceState = MediaSystemResourceClient::RESOURCE_STATE_WAITING;
-  ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(
-    NewRunnableMethod(
+  RefPtr<Runnable> runnable =
+    NS_NewRunnableMethodWithArgs<uint32_t>(
       this,
       &MediaSystemResourceManager::DoAcquire,
-      aClient->mId));
+      aClient->mId);
+  ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(runnable.forget());
 }
 
 bool
 MediaSystemResourceManager::AcquireSyncNoWait(MediaSystemResourceClient* aClient)
 {
   MOZ_ASSERT(aClient);
   MOZ_ASSERT(!InImageBridgeChildThread());
 
@@ -236,21 +237,22 @@ MediaSystemResourceManager::AcquireSyncN
       return false;
     }
     // Hold barrier Monitor until acquire task end.
     aClient->mAcquireSyncWaitMonitor = &barrier;
     aClient->mAcquireSyncWaitDone = &done;
     aClient->mResourceState = MediaSystemResourceClient::RESOURCE_STATE_WAITING;
   }
 
-  ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(
-    NewRunnableMethod(
+  RefPtr<Runnable> runnable =
+    NS_NewRunnableMethodWithArgs<uint32_t>(
       this,
       &MediaSystemResourceManager::DoAcquire,
-      aClient->mId));
+      aClient->mId);
+  ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(runnable.forget());
 
   // should stop the thread until done.
   while (!done) {
     barrier.Wait();
   }
 
   {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
@@ -303,21 +305,22 @@ MediaSystemResourceManager::ReleaseResou
         aClient->mResourceState == MediaSystemResourceClient::RESOURCE_STATE_END) {
 
       aClient->mResourceState = MediaSystemResourceClient::RESOURCE_STATE_END;
       return;
     }
 
     aClient->mResourceState = MediaSystemResourceClient::RESOURCE_STATE_END;
 
-    ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(
-      NewRunnableMethod(
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<uint32_t>(
         this,
         &MediaSystemResourceManager::DoRelease,
-        aClient->mId));
+        aClient->mId);
+    ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(runnable.forget());
   }
 }
 
 void
 MediaSystemResourceManager::DoRelease(uint32_t aId)
 {
   MOZ_ASSERT(InImageBridgeChildThread());
   if (mShutDown || !mChild) {
@@ -331,22 +334,23 @@ MediaSystemResourceManager::RecvResponse
 {
   HandleAcquireResult(aId, aSuccess);
 }
 
 void
 MediaSystemResourceManager::HandleAcquireResult(uint32_t aId, bool aSuccess)
 {
   if (!InImageBridgeChildThread()) {
-    ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(
-      NewRunnableMethod(
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<uint32_t, bool>(
         this,
         &MediaSystemResourceManager::HandleAcquireResult,
         aId,
-        aSuccess));
+        aSuccess);
+    ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(runnable.forget());
     return;
   }
 
   ReentrantMonitorAutoEnter mon(mReentrantMonitor);
   MediaSystemResourceClient* client = mResourceClients.Get(aId);
   if (!client) {
     // Client was already unregistered.
     return;
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -1330,18 +1330,18 @@ APZCTreeManager::AdjustScrollForSurfaceS
 }
 
 void
 APZCTreeManager::ClearTree()
 {
   // Ensure that no references to APZCs are alive in any lingering input
   // blocks. This breaks cycles from InputBlockState::mTargetApzc back to
   // the InputQueue.
-  APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
-    mInputQueue.get(), &InputQueue::Clear));
+  RefPtr<Runnable> runnable = NS_NewRunnableMethod(mInputQueue.get(), &InputQueue::Clear);
+  APZThreadUtils::RunOnControllerThread(runnable.forget());
 
   MutexAutoLock lock(mTreeLock);
 
   // Collect the nodes into a list, and then destroy each one.
   // We can't destroy them as we collect them, because ForEachNode()
   // does a pre-order traversal of the tree, and Destroy() nulls out
   // the fields needed to reach the children of the node.
   nsTArray<RefPtr<HitTestingTreeNode>> nodesToDestroy;
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -511,19 +511,19 @@ public:
       // This APZC or an APZC further down the handoff chain may be be overscrolled.
       // Start a snap-back animation on the overscrolled APZC.
       // Note:
       //   This needs to be a deferred task even though it can safely run
       //   while holding mMonitor, because otherwise, if the overscrolled APZC
       //   is this one, then the SetState(NOTHING) in UpdateAnimation will
       //   stomp on the SetState(SNAP_BACK) it does.
       mDeferredTasks.AppendElement(
-            NewRunnableMethod(mOverscrollHandoffChain.get(),
-                              &OverscrollHandoffChain::SnapBackOverscrolledApzc,
-                              &mApzc));
+            NS_NewRunnableMethodWithArg<AsyncPanZoomController*>(mOverscrollHandoffChain.get(),
+                                                                 &OverscrollHandoffChain::SnapBackOverscrolledApzc,
+                                                                 &mApzc));
       return false;
     }
 
     // AdjustDisplacement() zeroes out the Axis velocity if we're in overscroll.
     // Since we need to hand off the velocity to the tree manager in such a case,
     // we save it here. Would be ParentLayerVector instead of ParentLayerPoint
     // if we had vector classes.
     ParentLayerPoint velocity = mApzc.GetVelocityVector();
@@ -563,21 +563,23 @@ public:
       // there isn't, we take the new fling ourselves, entering an overscrolled
       // state.
       // Note: APZC is holding mMonitor, so directly calling
       // HandleFlingOverscroll() (which acquires the tree lock) would violate
       // the lock ordering. Instead we schedule HandleFlingOverscroll() to be
       // called after mMonitor is released.
       APZC_LOG("%p fling went into overscroll, handing off with velocity %s\n", &mApzc, Stringify(velocity).c_str());
       mDeferredTasks.AppendElement(
-            NewRunnableMethod(&mApzc,
-                              &AsyncPanZoomController::HandleFlingOverscroll,
-                              velocity,
-                              mOverscrollHandoffChain,
-                              mScrolledApzc));
+          NS_NewRunnableMethodWithArgs<ParentLayerPoint,
+                                       RefPtr<const OverscrollHandoffChain>,
+                                       RefPtr<const AsyncPanZoomController>>(&mApzc,
+                                                                             &AsyncPanZoomController::HandleFlingOverscroll,
+                                                                             velocity,
+                                                                             mOverscrollHandoffChain,
+                                                                             mScrolledApzc));
 
       // If there is a remaining velocity on this APZC, continue this fling
       // as well. (This fling and the handed-off fling will run concurrently.)
       // Note that AdjustDisplacement() will have zeroed out the velocity
       // along the axes where we're overscrolled.
       return !IsZero(mApzc.GetVelocityVector());
     }
 
@@ -695,19 +697,17 @@ public:
       // animation too early. We do still want to request a fling snap, though,
       // in case the end of the axis at which we're overscrolled is not a valid
       // snap point, so we request one now. If there are no snap points, this will
       // do nothing. If there are snap points, we'll get a scrollTo that snaps us
       // back to the nearest valid snap point.
       // The scroll snapping is done in a deferred task, otherwise the state
       // change to NOTHING caused by the overscroll animation ending would
       // clobber a possible state change to SMOOTH_SCROLL in ScrollSnap().
-      mDeferredTasks.AppendElement(
-            NewRunnableMethod(&mApzc,
-            &AsyncPanZoomController::ScrollSnap));
+      mDeferredTasks.AppendElement(NS_NewRunnableMethod(&mApzc, &AsyncPanZoomController::ScrollSnap));
       return false;
     }
     return true;
   }
 
   virtual bool WantsRepaints() override
   {
     return false;
@@ -814,19 +814,19 @@ public:
       // there is an APZC further in the handoff chain which is pannable; if
       // there isn't, we take the new fling ourselves, entering an overscrolled
       // state.
       // Note: APZC is holding mMonitor, so directly calling
       // HandleSmoothScrollOverscroll() (which acquires the tree lock) would violate
       // the lock ordering. Instead we schedule HandleSmoothScrollOverscroll() to be
       // called after mMonitor is released.
       mDeferredTasks.AppendElement(
-            NewRunnableMethod(&mApzc,
-                              &AsyncPanZoomController::HandleSmoothScrollOverscroll,
-                              velocity));
+          NS_NewRunnableMethodWithArgs<ParentLayerPoint>(&mApzc,
+                                                         &AsyncPanZoomController::HandleSmoothScrollOverscroll,
+                                                         velocity));
       return false;
     }
 
     return true;
   }
 
   void SetDestination(const nsPoint& aNewDestination) {
     mXAxisModel.SetDestination(static_cast<int32_t>(aNewDestination.x));
@@ -2167,21 +2167,24 @@ nsEventStatus AsyncPanZoomController::Ge
         }
         touch->SetSingleTapOccurred();
       }
       // Because this may be being running as part of APZCTreeManager::ReceiveInputEvent,
       // calling controller->HandleSingleTap directly might mean that content receives
       // the single tap message before the corresponding touch-up. To avoid that we
       // schedule the singletap message to run on the next spin of the event loop.
       // See bug 965381 for the issue this was causing.
-      controller->PostDelayedTask(
-        NewRunnableMethod(controller.get(), &GeckoContentController::HandleSingleTap,
-                          geckoScreenPoint, aModifiers,
-                          GetGuid()),
-        0);
+      RefPtr<Runnable> runnable =
+        NS_NewRunnableMethodWithArgs<CSSPoint,
+                                     mozilla::Modifiers,
+                                     ScrollableLayerGuid>(controller, &GeckoContentController::HandleSingleTap,
+                                                          geckoScreenPoint, aModifiers,
+                                                          GetGuid());
+
+      controller->PostDelayedTask(runnable.forget(), 0);
       return nsEventStatus_eConsumeNoDefault;
     }
   }
   return nsEventStatus_eIgnore;
 }
 
 void AsyncPanZoomController::OnTouchEndOrCancel() {
   if (RefPtr<GeckoContentController> controller = GetGeckoContentController()) {
--- a/gfx/layers/apz/src/InputQueue.cpp
+++ b/gfx/layers/apz/src/InputQueue.cpp
@@ -565,18 +565,19 @@ InputQueue::IsDragOnScrollbar(bool aHitS
   return mDragTracker.IsOnScrollbar(aHitScrollbar);
 }
 
 void
 InputQueue::ScheduleMainThreadTimeout(const RefPtr<AsyncPanZoomController>& aTarget,
                                       CancelableBlockState* aBlock) {
   INPQ_LOG("scheduling main thread timeout for target %p\n", aTarget.get());
   aBlock->StartContentResponseTimer();
-  aTarget->PostDelayedTask(
-    NewRunnableMethod(this, &InputQueue::MainThreadTimeout, aBlock->GetBlockId()),
+  RefPtr<Runnable> runnable =
+    NS_NewRunnableMethodWithArgs<uint64_t>(this, &InputQueue::MainThreadTimeout, aBlock->GetBlockId());
+  aTarget->PostDelayedTask(runnable.forget(),
     gfxPrefs::APZContentResponseTimeout());
 }
 
 void
 InputQueue::MainThreadTimeout(const uint64_t& aInputBlockId) {
   APZThreadUtils::AssertOnControllerThread();
 
   INPQ_LOG("got a main thread timeout; block=%" PRIu64 "\n", aInputBlockId);
--- a/gfx/layers/apz/util/APZCCallbackHelper.cpp
+++ b/gfx/layers/apz/util/APZCCallbackHelper.cpp
@@ -683,17 +683,17 @@ public:
 
   void DidRefresh() override {
     if (!mPresShell) {
       MOZ_ASSERT_UNREACHABLE("Post-refresh observer fired again after failed attempt at unregistering it");
       return;
     }
 
     APZCCH_LOG("Got refresh, sending target APZCs for input block %" PRIu64 "\n", mInputBlockId);
-    SendLayersDependentApzcTargetConfirmation(mPresShell, mInputBlockId, mTargets);
+    SendLayersDependentApzcTargetConfirmation(mPresShell, mInputBlockId, Move(mTargets));
 
     if (!mPresShell->RemovePostRefreshObserver(this)) {
       MOZ_ASSERT_UNREACHABLE("Unable to unregister post-refresh observer! Leaking it instead of leaving garbage registered");
       // Graceful handling, just in case...
       mPresShell = nullptr;
       return;
     }
 
@@ -714,17 +714,17 @@ SendSetTargetAPZCNotificationHelper(nsIW
                                     const uint64_t& aInputBlockId,
                                     const nsTArray<ScrollableLayerGuid>& aTargets,
                                     bool aWaitForRefresh)
 {
   bool waitForRefresh = aWaitForRefresh;
   if (waitForRefresh) {
     APZCCH_LOG("At least one target got a new displayport, need to wait for refresh\n");
     waitForRefresh = aShell->AddPostRefreshObserver(
-      new DisplayportSetListener(aShell, aInputBlockId, aTargets));
+      new DisplayportSetListener(aShell, aInputBlockId, Move(aTargets)));
   }
   if (!waitForRefresh) {
     APZCCH_LOG("Sending target APZCs for input block %" PRIu64 "\n", aInputBlockId);
     aWidget->SetConfirmedTargetAPZC(aInputBlockId, aTargets);
   } else {
     APZCCH_LOG("Successfully registered post-refresh observer\n");
   }
 }
@@ -765,17 +765,17 @@ APZCCallbackHelper::SendSetTargetAPZCNot
       }
       // TODO: Do other types of events need to be handled?
 
       if (!targets.IsEmpty()) {
         SendSetTargetAPZCNotificationHelper(
           aWidget,
           shell,
           aInputBlockId,
-          targets,
+          Move(targets),
           waitForRefresh);
       }
     }
   }
 }
 
 void
 APZCCallbackHelper::SendSetAllowedTouchBehaviorNotification(
@@ -785,17 +785,17 @@ APZCCallbackHelper::SendSetAllowedTouchB
         const SetAllowedTouchBehaviorCallback& aCallback)
 {
   nsTArray<TouchBehaviorFlags> flags;
   for (uint32_t i = 0; i < aEvent.mTouches.Length(); i++) {
     flags.AppendElement(
       widget::ContentHelper::GetAllowedTouchBehavior(
                                aWidget, aEvent.mTouches[i]->mRefPoint));
   }
-  aCallback(aInputBlockId, flags);
+  aCallback(aInputBlockId, Move(flags));
 }
 
 void
 APZCCallbackHelper::NotifyMozMouseScrollEvent(const FrameMetrics::ViewID& aScrollId, const nsString& aEvent)
 {
   nsCOMPtr<nsIContent> targetContent = nsLayoutUtils::FindContentFor(aScrollId);
   if (!targetContent) {
     return;
--- a/gfx/layers/apz/util/APZCCallbackHelper.h
+++ b/gfx/layers/apz/util/APZCCallbackHelper.h
@@ -136,19 +136,19 @@ public:
                                               nsIDocument* aDocument,
                                               const WidgetGUIEvent& aEvent,
                                               const ScrollableLayerGuid& aGuid,
                                               uint64_t aInputBlockId);
 
     /* Figure out the allowed touch behaviors of each touch point in |aEvent|
      * and send that information to the provided callback. */
     static void SendSetAllowedTouchBehaviorNotification(nsIWidget* aWidget,
-                                                         const WidgetTouchEvent& aEvent,
-                                                         uint64_t aInputBlockId,
-                                                         const SetAllowedTouchBehaviorCallback& aCallback);
+                                                        const WidgetTouchEvent& aEvent,
+                                                        uint64_t aInputBlockId,
+                                                        const SetAllowedTouchBehaviorCallback& aCallback);
 
     /* Notify content of a mouse scroll testing event. */
     static void NotifyMozMouseScrollEvent(const FrameMetrics::ViewID& aScrollId, const nsString& aEvent);
 
     /* Notify content that the repaint flush is complete. */
     static void NotifyFlushComplete(nsIPresShell* aShell);
 
     /* Temporarily ignore the Displayport for better paint performance. If at
--- a/gfx/layers/apz/util/ChromeProcessController.cpp
+++ b/gfx/layers/apz/util/ChromeProcessController.cpp
@@ -31,18 +31,18 @@ ChromeProcessController::ChromeProcessCo
   , mAPZCTreeManager(aAPZCTreeManager)
   , mUILoop(MessageLoop::current())
 {
   // Otherwise we're initializing mUILoop incorrectly.
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aAPZEventState);
   MOZ_ASSERT(aAPZCTreeManager);
 
-  mUILoop->PostTask(
-      NewRunnableMethod(this, &ChromeProcessController::InitializeRoot));
+  RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &ChromeProcessController::InitializeRoot);
+  mUILoop->PostTask(runnable.forget());
 }
 
 ChromeProcessController::~ChromeProcessController() {}
 
 void
 ChromeProcessController::InitializeRoot()
 {
   APZCCallbackHelper::InitializeRootDisplayport(GetPresShell());
@@ -66,18 +66,18 @@ ChromeProcessController::PostDelayedTask
 {
   MessageLoop::current()->PostDelayedTask(Move(aTask), aDelayMs);
 }
 
 void
 ChromeProcessController::Destroy()
 {
   if (MessageLoop::current() != mUILoop) {
-    mUILoop->PostTask(
-      NewRunnableMethod(this, &ChromeProcessController::Destroy));
+    RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &ChromeProcessController::Destroy);
+    mUILoop->PostTask(runnable.forget());
     return;
   }
 
   MOZ_ASSERT(MessageLoop::current() == mUILoop);
   mWidget = nullptr;
 }
 
 nsIPresShell*
@@ -116,19 +116,22 @@ ChromeProcessController::GetRootContentD
 }
 
 void
 ChromeProcessController::HandleDoubleTap(const mozilla::CSSPoint& aPoint,
                                          Modifiers aModifiers,
                                          const ScrollableLayerGuid& aGuid)
 {
   if (MessageLoop::current() != mUILoop) {
-    mUILoop->PostTask(
-        NewRunnableMethod(this, &ChromeProcessController::HandleDoubleTap,
-                          aPoint, aModifiers, aGuid));
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<CSSPoint,
+                                   Modifiers,
+                                   ScrollableLayerGuid>(this, &ChromeProcessController::HandleDoubleTap,
+                                                        aPoint, aModifiers, aGuid);
+    mUILoop->PostTask(runnable.forget());
     return;
   }
 
   nsCOMPtr<nsIDocument> document = GetRootContentDocument(aGuid.mScrollId);
   if (!document.get()) {
     return;
   }
 
@@ -153,62 +156,75 @@ ChromeProcessController::HandleDoubleTap
 }
 
 void
 ChromeProcessController::HandleSingleTap(const CSSPoint& aPoint,
                                          Modifiers aModifiers,
                                          const ScrollableLayerGuid& aGuid)
 {
   if (MessageLoop::current() != mUILoop) {
-    mUILoop->PostTask(
-        NewRunnableMethod(this, &ChromeProcessController::HandleSingleTap,
-                          aPoint, aModifiers, aGuid));
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<CSSPoint,
+                                   Modifiers,
+                                   ScrollableLayerGuid>(this, &ChromeProcessController::HandleSingleTap,
+                                                        aPoint, aModifiers, aGuid);
+    mUILoop->PostTask(runnable.forget());
     return;
   }
 
   mAPZEventState->ProcessSingleTap(aPoint, aModifiers, aGuid);
 }
 
 void
 ChromeProcessController::HandleLongTap(const mozilla::CSSPoint& aPoint, Modifiers aModifiers,
                                        const ScrollableLayerGuid& aGuid,
                                        uint64_t aInputBlockId)
 {
   if (MessageLoop::current() != mUILoop) {
-    mUILoop->PostTask(
-        NewRunnableMethod(this, &ChromeProcessController::HandleLongTap,
-                          aPoint, aModifiers, aGuid, aInputBlockId));
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<mozilla::CSSPoint,
+                                   Modifiers,
+                                   ScrollableLayerGuid,
+                                   uint64_t>(this, &ChromeProcessController::HandleLongTap,
+                                             aPoint, aModifiers, aGuid, aInputBlockId);
+    mUILoop->PostTask(runnable.forget());
     return;
   }
 
   mAPZEventState->ProcessLongTap(GetPresShell(), aPoint, aModifiers, aGuid,
       aInputBlockId);
 }
 
 void
 ChromeProcessController::NotifyAPZStateChange(const ScrollableLayerGuid& aGuid,
                                               APZStateChange aChange,
                                               int aArg)
 {
   if (MessageLoop::current() != mUILoop) {
-    mUILoop->PostTask(
-        NewRunnableMethod(this, &ChromeProcessController::NotifyAPZStateChange,
-                          aGuid, aChange, aArg));
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<ScrollableLayerGuid,
+                                   APZStateChange,
+                                   int>(this, &ChromeProcessController::NotifyAPZStateChange,
+                                        aGuid, aChange, aArg);
+    mUILoop->PostTask(runnable.forget());
     return;
   }
 
   mAPZEventState->ProcessAPZStateChange(GetRootDocument(), aGuid.mScrollId, aChange, aArg);
 }
 
 void
 ChromeProcessController::NotifyMozMouseScrollEvent(const FrameMetrics::ViewID& aScrollId, const nsString& aEvent)
 {
   if (MessageLoop::current() != mUILoop) {
-    mUILoop->PostTask(
-      NewRunnableMethod(this, &ChromeProcessController::NotifyMozMouseScrollEvent, aScrollId, aEvent));
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<FrameMetrics::ViewID,
+                                   nsString>(this, &ChromeProcessController::NotifyMozMouseScrollEvent,
+                                             aScrollId, aEvent);
+    mUILoop->PostTask(runnable.forget());
     return;
   }
 
   APZCCallbackHelper::NotifyMozMouseScrollEvent(aScrollId, aEvent);
 }
 
 void
 ChromeProcessController::NotifyFlushComplete()
--- a/gfx/layers/ipc/CompositorBridgeParent.cpp
+++ b/gfx/layers/ipc/CompositorBridgeParent.cpp
@@ -357,17 +357,17 @@ void
 CompositorVsyncScheduler::SetDisplay(bool aDisplayEnable)
 {
   // SetDisplay() is usually called from nsScreenManager at main thread. Post
   // to compositor thread if needs.
   if (!CompositorBridgeParent::IsInCompositorThread()) {
     MOZ_ASSERT(NS_IsMainThread());
     MonitorAutoLock lock(mSetDisplayMonitor);
     RefPtr<CancelableRunnable> task =
-      NewRunnableMethod(this, &CompositorVsyncScheduler::SetDisplay, aDisplayEnable);
+      NS_NewCancelableRunnableMethodWithArgs<bool>(this, &CompositorVsyncScheduler::SetDisplay, aDisplayEnable);
     mSetDisplayTask = task;
     ScheduleTask(task.forget(), 0);
     return;
   } else {
     MonitorAutoLock lock(mSetDisplayMonitor);
     mSetDisplayTask = nullptr;
   }
 
@@ -977,32 +977,35 @@ CompositorBridgeParent::ActorDestroy(Act
   mCompositorScheduler->Destroy();
 
   // There are chances that the ref count reaches zero on the main thread shortly
   // after this function returns while some ipdl code still needs to run on
   // this thread.
   // We must keep the compositor parent alive untill the code handling message
   // reception is finished on this thread.
   mSelfRef = this;
-  MessageLoop::current()->PostTask(NewRunnableMethod(this,&CompositorBridgeParent::DeferredDestroy));
+  RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &CompositorBridgeParent::DeferredDestroy);
+  MessageLoop::current()->PostTask(runnable.forget());
 }
 
 
 void
 CompositorBridgeParent::ScheduleRenderOnCompositorThread()
 {
   MOZ_ASSERT(CompositorLoop());
-  CompositorLoop()->PostTask(NewRunnableMethod(this, &CompositorBridgeParent::ScheduleComposition));
+  RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &CompositorBridgeParent::ScheduleComposition);
+  CompositorLoop()->PostTask(runnable.forget());
 }
 
 void
 CompositorBridgeParent::InvalidateOnCompositorThread()
 {
   MOZ_ASSERT(CompositorLoop());
-  CompositorLoop()->PostTask(NewRunnableMethod(this, &CompositorBridgeParent::Invalidate));
+  RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &CompositorBridgeParent::Invalidate);
+  CompositorLoop()->PostTask(runnable.forget());
 }
 
 void
 CompositorBridgeParent::PauseComposition()
 {
   MOZ_ASSERT(IsInCompositorThread(),
              "PauseComposition() can only be called on the compositor thread");
 
@@ -1083,43 +1086,48 @@ CompositorBridgeParent::ResumeCompositio
  * really is paused.
  */
 void
 CompositorBridgeParent::SchedulePauseOnCompositorThread()
 {
   MonitorAutoLock lock(mPauseCompositionMonitor);
 
   MOZ_ASSERT(CompositorLoop());
-  CompositorLoop()->PostTask(NewRunnableMethod(this, &CompositorBridgeParent::PauseComposition));
+  RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &CompositorBridgeParent::PauseComposition);
+  CompositorLoop()->PostTask(runnable.forget());
 
   // Wait until the pause has actually been processed by the compositor thread
   lock.Wait();
 }
 
 bool
 CompositorBridgeParent::ScheduleResumeOnCompositorThread()
 {
   MonitorAutoLock lock(mResumeCompositionMonitor);
 
   MOZ_ASSERT(CompositorLoop());
-  CompositorLoop()->PostTask(NewRunnableMethod(this, &CompositorBridgeParent::ResumeComposition));
+  RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &CompositorBridgeParent::ResumeComposition);
+  CompositorLoop()->PostTask(runnable.forget());
 
   // Wait until the resume has actually been processed by the compositor thread
   lock.Wait();
 
   return !mPaused;
 }
 
 bool
 CompositorBridgeParent::ScheduleResumeOnCompositorThread(int width, int height)
 {
   MonitorAutoLock lock(mResumeCompositionMonitor);
 
   MOZ_ASSERT(CompositorLoop());
-  CompositorLoop()->PostTask(NewRunnableMethod(this, &CompositorBridgeParent::ResumeCompositionAndResize, width, height));
+  RefPtr<Runnable> runnable =
+    NS_NewRunnableMethodWithArgs<int, int>(this, &CompositorBridgeParent::ResumeCompositionAndResize,
+                                           width, height);
+  CompositorLoop()->PostTask(runnable.forget());
 
   // Wait until the resume has actually been processed by the compositor thread
   lock.Wait();
 
   return !mPaused;
 }
 
 void
@@ -2102,21 +2110,23 @@ CompositorBridgeParent::InvalidateRemote
 bool
 CompositorBridgeParent::ResetCompositor(const nsTArray<LayersBackend>& aBackendHints,
                                         TextureFactoryIdentifier* aOutIdentifier)
 {
   Maybe<TextureFactoryIdentifier> newIdentifier;
   {
     MonitorAutoLock lock(mResetCompositorMonitor);
 
-    CompositorLoop()->PostTask(
-      NewRunnableMethod(this,
-                        &CompositorBridgeParent::ResetCompositorTask,
-                        aBackendHints,
-                        &newIdentifier));
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<StoreCopyPassByConstLRef<nsTArray<LayersBackend>>,
+                                   Maybe<TextureFactoryIdentifier>*>(this,
+                                                                     &CompositorBridgeParent::ResetCompositorTask,
+                                                                     aBackendHints,
+                                                                     &newIdentifier);
+    CompositorLoop()->PostTask(runnable.forget());
 
     mResetCompositorMonitor.Wait();
   }
 
   if (!newIdentifier) {
     return false;
   }
 
@@ -2274,18 +2284,18 @@ CrossProcessCompositorBridgeParent::Acto
 
   if (mSubprocess) {
     mSubprocess->DissociateActor();
     mSubprocess = nullptr;
   }
 
   // We must keep this object alive untill the code handling message
   // reception is finished on this thread.
-  MessageLoop::current()->PostTask(
-      NewRunnableMethod(this, &CrossProcessCompositorBridgeParent::DeferredDestroy));
+  RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &CrossProcessCompositorBridgeParent::DeferredDestroy);
+  MessageLoop::current()->PostTask(runnable.forget());
 }
 
 PLayerTransactionParent*
 CrossProcessCompositorBridgeParent::AllocPLayerTransactionParent(
   const nsTArray<LayersBackend>&,
   const uint64_t& aId,
   TextureFactoryIdentifier* aTextureFactoryIdentifier,
   bool *aSuccess)
@@ -2520,32 +2530,34 @@ CompositorBridgeParent::UpdatePluginWind
   mCachedPluginData = lts.mPluginData;
   return true;
 }
 
 void
 CompositorBridgeParent::ScheduleShowAllPluginWindows()
 {
   MOZ_ASSERT(CompositorLoop());
-  CompositorLoop()->PostTask(NewRunnableMethod(this, &CompositorBridgeParent::ShowAllPluginWindows));
+  RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &CompositorBridgeParent::ShowAllPluginWindows);
+  CompositorLoop()->PostTask(runnable.forget());
 }
 
 void
 CompositorBridgeParent::ShowAllPluginWindows()
 {
   MOZ_ASSERT(!NS_IsMainThread());
   mDeferPluginWindows = false;
   ScheduleComposition();
 }
 
 void
 CompositorBridgeParent::ScheduleHideAllPluginWindows()
 {
   MOZ_ASSERT(CompositorLoop());
-  CompositorLoop()->PostTask(NewRunnableMethod(this, &CompositorBridgeParent::HideAllPluginWindows));
+  RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &CompositorBridgeParent::HideAllPluginWindows);
+  CompositorLoop()->PostTask(runnable.forget());
 }
 
 void
 CompositorBridgeParent::HideAllPluginWindows()
 {
   MOZ_ASSERT(!NS_IsMainThread());
   // No plugins in the cache implies no plugins to manage
   // in this content.
--- a/gfx/layers/ipc/RemoteContentController.cpp
+++ b/gfx/layers/ipc/RemoteContentController.cpp
@@ -53,38 +53,44 @@ RemoteContentController::RequestContentR
 void
 RemoteContentController::HandleDoubleTap(const CSSPoint& aPoint,
                                          Modifiers aModifiers,
                                          const ScrollableLayerGuid& aGuid)
 {
   if (MessageLoop::current() != mUILoop) {
     // We have to send this message from the "UI thread" (main
     // thread).
-    mUILoop->PostTask(
-      NewRunnableMethod(this, &RemoteContentController::HandleDoubleTap,
-                        aPoint, aModifiers, aGuid));
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<CSSPoint,
+                                   Modifiers,
+                                   ScrollableLayerGuid>(this, &RemoteContentController::HandleDoubleTap,
+                                                        aPoint, aModifiers, aGuid);
+    mUILoop->PostTask(runnable.forget());
     return;
   }
   if (CanSend()) {
     Unused << SendHandleDoubleTap(mBrowserParent->AdjustTapToChildWidget(aPoint),
             aModifiers, aGuid);
   }
 }
 
 void
 RemoteContentController::HandleSingleTap(const CSSPoint& aPoint,
                                          Modifiers aModifiers,
                                          const ScrollableLayerGuid& aGuid)
 {
   if (MessageLoop::current() != mUILoop) {
     // We have to send this message from the "UI thread" (main
     // thread).
-    mUILoop->PostTask(
-      NewRunnableMethod(this, &RemoteContentController::HandleSingleTap,
-                        aPoint, aModifiers, aGuid));
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<CSSPoint,
+                                   Modifiers,
+                                   ScrollableLayerGuid>(this, &RemoteContentController::HandleSingleTap,
+                                                        aPoint, aModifiers, aGuid);
+    mUILoop->PostTask(runnable.forget());
     return;
   }
 
   bool callTakeFocusForClickFromTap;
   layout::RenderFrameParent* frame;
   if (mBrowserParent && (frame = mBrowserParent->GetRenderFrame()) &&
       mLayersId == frame->GetLayersId()) {
     // Avoid going over IPC and back for calling TakeFocusForClickFromTap,
@@ -105,19 +111,23 @@ void
 RemoteContentController::HandleLongTap(const CSSPoint& aPoint,
                                        Modifiers aModifiers,
                                        const ScrollableLayerGuid& aGuid,
                                        uint64_t aInputBlockId)
 {
   if (MessageLoop::current() != mUILoop) {
     // We have to send this message from the "UI thread" (main
     // thread).
-    mUILoop->PostTask(
-      NewRunnableMethod(this, &RemoteContentController::HandleLongTap,
-                        aPoint, aModifiers, aGuid, aInputBlockId));
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<CSSPoint,
+                                   Modifiers,
+                                   ScrollableLayerGuid,
+                                   uint64_t>(this, &RemoteContentController::HandleLongTap,
+                                             aPoint, aModifiers, aGuid, aInputBlockId);
+    mUILoop->PostTask(runnable.forget());
     return;
   }
   if (CanSend()) {
     Unused << SendHandleLongTap(mBrowserParent->AdjustTapToChildWidget(aPoint),
             aModifiers, aGuid, aInputBlockId);
   }
 }
 
@@ -145,34 +155,39 @@ RemoteContentController::GetTouchSensiti
 }
 
 void
 RemoteContentController::NotifyAPZStateChange(const ScrollableLayerGuid& aGuid,
                                               APZStateChange aChange,
                                               int aArg)
 {
   if (MessageLoop::current() != mUILoop) {
-    mUILoop->PostTask(
-      NewRunnableMethod(this, &RemoteContentController::NotifyAPZStateChange,
-                        aGuid, aChange, aArg));
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<ScrollableLayerGuid,
+                                   APZStateChange,
+                                   int>(this, &RemoteContentController::NotifyAPZStateChange,
+                                        aGuid, aChange, aArg);
+    mUILoop->PostTask(runnable.forget());
     return;
   }
   if (CanSend()) {
     Unused << SendNotifyAPZStateChange(aGuid.mScrollId, aChange, aArg);
   }
 }
 
 void
 RemoteContentController::NotifyMozMouseScrollEvent(const FrameMetrics::ViewID& aScrollId,
                                                    const nsString& aEvent)
 {
   if (MessageLoop::current() != mUILoop) {
-    mUILoop->PostTask(
-      NewRunnableMethod(this, &RemoteContentController::NotifyMozMouseScrollEvent,
-                        aScrollId, aEvent));
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<FrameMetrics::ViewID,
+                                   nsString>(this, &RemoteContentController::NotifyMozMouseScrollEvent,
+                                             aScrollId, aEvent);
+    mUILoop->PostTask(runnable.forget());
     return;
   }
 
   if (mBrowserParent) {
     Unused << mBrowserParent->SendMouseScrollTestEvent(mLayersId, aScrollId, aEvent);
   }
 }
 
@@ -212,34 +227,40 @@ RemoteContentController::RecvContentRece
                                                        const bool& aPreventDefault)
 {
   if (aGuid.mLayersId != mLayersId) {
     // Guard against bad data from hijacked child processes
     NS_ERROR("Unexpected layers id in RecvContentReceivedInputBlock; dropping message...");
     return false;
   }
   if (RefPtr<APZCTreeManager> apzcTreeManager = GetApzcTreeManager()) {
-    APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
-        apzcTreeManager.get(), &APZCTreeManager::ContentReceivedInputBlock,
-        aInputBlockId, aPreventDefault));
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<uint64_t,
+                                   bool>(apzcTreeManager,
+                                         &APZCTreeManager::ContentReceivedInputBlock,
+                                         aInputBlockId, aPreventDefault);
+    APZThreadUtils::RunOnControllerThread(runnable.forget());
+
   }
   return true;
 }
 
 bool
 RemoteContentController::RecvStartScrollbarDrag(const AsyncDragMetrics& aDragMetrics)
 {
   if (RefPtr<APZCTreeManager> apzcTreeManager = GetApzcTreeManager()) {
     ScrollableLayerGuid guid(mLayersId, aDragMetrics.mPresShellId,
                              aDragMetrics.mViewId);
 
-    APZThreadUtils::RunOnControllerThread(
-      NewRunnableMethod(apzcTreeManager.get(),
-                        &APZCTreeManager::StartScrollbarDrag,
-                        guid, aDragMetrics));
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<ScrollableLayerGuid,
+                                   AsyncDragMetrics>(apzcTreeManager,
+                                                     &APZCTreeManager::StartScrollbarDrag,
+                                                     guid, aDragMetrics);
+    APZThreadUtils::RunOnControllerThread(runnable.forget());
   }
   return true;
 }
 
 bool
 RemoteContentController::RecvSetTargetAPZC(const uint64_t& aInputBlockId,
                                            nsTArray<ScrollableLayerGuid>&& aTargets)
 {
@@ -249,31 +270,37 @@ RemoteContentController::RecvSetTargetAP
       NS_ERROR("Unexpected layers id in SetTargetAPZC; dropping message...");
       return false;
     }
   }
   if (RefPtr<APZCTreeManager> apzcTreeManager = GetApzcTreeManager()) {
     // need a local var to disambiguate between the SetTargetAPZC overloads.
     void (APZCTreeManager::*setTargetApzcFunc)(uint64_t, const nsTArray<ScrollableLayerGuid>&)
         = &APZCTreeManager::SetTargetAPZC;
-    APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
-        apzcTreeManager.get(), setTargetApzcFunc,
-        aInputBlockId, aTargets));
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<uint64_t,
+                                   StoreCopyPassByRRef<nsTArray<ScrollableLayerGuid>>>(apzcTreeManager, setTargetApzcFunc,
+                                                                                       aInputBlockId, aTargets);
+    APZThreadUtils::RunOnControllerThread(runnable.forget());
+
   }
   return true;
 }
 
 bool
 RemoteContentController::RecvSetAllowedTouchBehavior(const uint64_t& aInputBlockId,
                                                      nsTArray<TouchBehaviorFlags>&& aFlags)
 {
   if (RefPtr<APZCTreeManager> apzcTreeManager = GetApzcTreeManager()) {
-    APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
-        apzcTreeManager.get(), &APZCTreeManager::SetAllowedTouchBehavior,
-        aInputBlockId, Move(aFlags)));
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<uint64_t,
+                                   StoreCopyPassByRRef<nsTArray<TouchBehaviorFlags>>>(apzcTreeManager,
+                                                                                      &APZCTreeManager::SetAllowedTouchBehavior,
+                                                                                      aInputBlockId, Move(aFlags));
+    APZThreadUtils::RunOnControllerThread(runnable.forget());
   }
   return true;
 }
 
 bool
 RemoteContentController::RecvUpdateZoomConstraints(const uint32_t& aPresShellId,
                                                    const ViewID& aViewId,
                                                    const MaybeZoomConstraints& aConstraints)
--- a/gfx/thebes/SoftwareVsyncSource.cpp
+++ b/gfx/thebes/SoftwareVsyncSource.cpp
@@ -40,18 +40,18 @@ SoftwareDisplay::EnableVsync()
 {
   MOZ_ASSERT(mVsyncThread->IsRunning());
   if (NS_IsMainThread()) {
     if (mVsyncEnabled) {
       return;
     }
     mVsyncEnabled = true;
 
-    mVsyncThread->message_loop()->PostTask(
-      NewRunnableMethod(this, &SoftwareDisplay::EnableVsync));
+    RefPtr<mozilla::Runnable> runnable = NS_NewRunnableMethod(this, &SoftwareDisplay::EnableVsync);
+    mVsyncThread->message_loop()->PostTask(runnable.forget());
     return;
   }
 
   MOZ_ASSERT(IsInSoftwareVsyncThread());
   NotifyVsync(mozilla::TimeStamp::Now());
 }
 
 void
@@ -59,18 +59,18 @@ SoftwareDisplay::DisableVsync()
 {
   MOZ_ASSERT(mVsyncThread->IsRunning());
   if (NS_IsMainThread()) {
     if (!mVsyncEnabled) {
       return;
     }
     mVsyncEnabled = false;
 
-    mVsyncThread->message_loop()->PostTask(
-      NewRunnableMethod(this, &SoftwareDisplay::DisableVsync));
+    RefPtr<mozilla::Runnable> runnable = NS_NewRunnableMethod(this, &SoftwareDisplay::DisableVsync);
+    mVsyncThread->message_loop()->PostTask(runnable.forget());
     return;
   }
 
   MOZ_ASSERT(IsInSoftwareVsyncThread());
   if (mCurrentVsyncTask) {
     mCurrentVsyncTask->Cancel();
     mCurrentVsyncTask = nullptr;
   }
--- a/gfx/vr/ipc/VRManagerParent.cpp
+++ b/gfx/vr/ipc/VRManagerParent.cpp
@@ -107,18 +107,18 @@ VRManagerParent::DeferredDestroy()
   mCompositorThreadHolder = nullptr;
   mSelfRef = nullptr;
 }
 
 void
 VRManagerParent::ActorDestroy(ActorDestroyReason why)
 {
   UnregisterFromManager();
-  MessageLoop::current()->PostTask(
-    NewRunnableMethod(this, &VRManagerParent::DeferredDestroy));
+  RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &VRManagerParent::DeferredDestroy);
+  MessageLoop::current()->PostTask(runnable.forget());
 }
 
 mozilla::ipc::IToplevelProtocol*
 VRManagerParent::CloneToplevel(const InfallibleTArray<mozilla::ipc::ProtocolFdMapping>& aFds,
                                base::ProcessHandle aPeerProcess,
                                mozilla::ipc::ProtocolCloneContext* aCtx)
 {
   for (unsigned int i = 0; i < aFds.Length(); i++) {
--- a/ipc/chromium/src/base/task.h
+++ b/ipc/chromium/src/base/task.h
@@ -298,26 +298,31 @@ class RunnableMethod : public mozilla::C
 
   // This is owning because of the RetainCallee and ReleaseCallee calls in the
   // constructor and destructor.
   T* MOZ_OWNING_REF obj_;
   Method meth_;
   Params params_;
 };
 
+namespace dont_add_new_uses_of_this {
+
+// Don't add new uses of this!!!!
 template <class T, class Method, typename... Args>
 inline already_AddRefed<mozilla::Runnable>
 NewRunnableMethod(T* object, Method method, Args&&... args) {
   typedef mozilla::Tuple<typename mozilla::Decay<Args>::Type...> ArgsTuple;
   RefPtr<mozilla::Runnable> t =
     new RunnableMethod<T, Method, ArgsTuple>(object, method,
                                              mozilla::MakeTuple(mozilla::Forward<Args>(args)...));
   return t.forget();
 }
 
+} // namespace dont_add_new_uses_of_this
+
 // RunnableFunction and NewRunnableFunction implementation ---------------------
 
 template <class Function, class Params>
 class RunnableFunction : public mozilla::CancelableRunnable {
  public:
   RunnableFunction(Function function, Params&& params)
       : function_(function), params_(mozilla::Forward<Params>(params)) {
   }
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -960,29 +960,33 @@ void nsBaseWidget::ConfigureAPZCTreeMana
   RefPtr<APZCTreeManager> treeManager = mAPZC;  // for capture by the lambdas
 
   ContentReceivedInputBlockCallback callback(
       [treeManager](const ScrollableLayerGuid& aGuid,
                     uint64_t aInputBlockId,
                     bool aPreventDefault)
       {
         MOZ_ASSERT(NS_IsMainThread());
-        APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
-            treeManager.get(), &APZCTreeManager::ContentReceivedInputBlock,
-            aInputBlockId, aPreventDefault));
+        RefPtr<Runnable> runnable =
+          NS_NewRunnableMethodWithArgs<uint64_t, bool>(treeManager, &APZCTreeManager::ContentReceivedInputBlock,
+                                                       aInputBlockId, aPreventDefault);
+        APZThreadUtils::RunOnControllerThread(runnable.forget());
       });
   mAPZEventState = new APZEventState(this, mozilla::Move(callback));
 
   mSetAllowedTouchBehaviorCallback = [treeManager](uint64_t aInputBlockId,
                                                    const nsTArray<TouchBehaviorFlags>& aFlags)
   {
     MOZ_ASSERT(NS_IsMainThread());
-    APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
-        treeManager.get(), &APZCTreeManager::SetAllowedTouchBehavior,
-        aInputBlockId, aFlags));
+    RefPtr<Runnable> runnable =
+      NS_NewRunnableMethodWithArgs<uint64_t,
+                                   StoreCopyPassByLRef<nsTArray<TouchBehaviorFlags>>>(treeManager,
+                                                                                      &APZCTreeManager::SetAllowedTouchBehavior,
+                                                                                      aInputBlockId, aFlags);
+    APZThreadUtils::RunOnControllerThread(runnable.forget());
   };
 
   mRootContentController = CreateRootContentController();
   if (mRootContentController) {
     uint64_t rootLayerTreeId = mCompositorBridgeParent->RootLayerTreeId();
     CompositorBridgeParent::SetControllerForLayerTree(rootLayerTreeId, mRootContentController);
   }
 
@@ -1003,18 +1007,22 @@ void nsBaseWidget::ConfigureAPZControlle
 
 void
 nsBaseWidget::SetConfirmedTargetAPZC(uint64_t aInputBlockId,
                                      const nsTArray<ScrollableLayerGuid>& aTargets) const
 {
   // Need to specifically bind this since it's overloaded.
   void (APZCTreeManager::*setTargetApzcFunc)(uint64_t, const nsTArray<ScrollableLayerGuid>&)
           = &APZCTreeManager::SetTargetAPZC;
-  APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
-    mAPZC.get(), setTargetApzcFunc, aInputBlockId, aTargets));
+  RefPtr<Runnable> runnable =
+    NS_NewRunnableMethodWithArgs<uint64_t,
+                                 StoreCopyPassByRRef<nsTArray<ScrollableLayerGuid>>>(mAPZC,
+                                                                                     setTargetApzcFunc,
+                                                                                     aInputBlockId, aTargets);
+  APZThreadUtils::RunOnControllerThread(runnable.forget());
 }
 
 void
 nsBaseWidget::UpdateZoomConstraints(const uint32_t& aPresShellId,
                                     const FrameMetrics::ViewID& aViewId,
                                     const Maybe<ZoomConstraints>& aConstraints)
 {
   if (!mCompositorBridgeParent || !mAPZC) {
@@ -1922,18 +1930,21 @@ nsBaseWidget::StartAsyncScrollbarDrag(co
     return;
   }
 
   MOZ_ASSERT(XRE_IsParentProcess() && mCompositorBridgeParent);
 
   int layersId = mCompositorBridgeParent->RootLayerTreeId();;
   ScrollableLayerGuid guid(layersId, aDragMetrics.mPresShellId, aDragMetrics.mViewId);
 
-  APZThreadUtils::RunOnControllerThread(
-    NewRunnableMethod(mAPZC.get(), &APZCTreeManager::StartScrollbarDrag, guid, aDragMetrics));
+  RefPtr<Runnable> runnable =
+    NS_NewRunnableMethodWithArgs<ScrollableLayerGuid,
+                                 AsyncDragMetrics>(mAPZC, &APZCTreeManager::StartScrollbarDrag,
+                                                   guid, aDragMetrics);
+  APZThreadUtils::RunOnControllerThread(runnable.forget());
 }
 
 already_AddRefed<nsIScreen>
 nsBaseWidget::GetWidgetScreen()
 {
   nsCOMPtr<nsIScreenManager> screenManager;
   screenManager = do_GetService("@mozilla.org/gfx/screenmanager;1");
   if (!screenManager) {
--- a/xpcom/base/nsDumpUtils.cpp
+++ b/xpcom/base/nsDumpUtils.cpp
@@ -69,18 +69,18 @@ NS_IMPL_ISUPPORTS(FdWatcher, nsIObserver
 void
 FdWatcher::Init()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   nsCOMPtr<nsIObserverService> os = services::GetObserverService();
   os->AddObserver(this, "xpcom-shutdown", /* ownsWeak = */ false);
 
-  XRE_GetIOMessageLoop()->PostTask(
-    NewRunnableMethod(this, &FdWatcher::StartWatching));
+  RefPtr<Runnable> runnable = NS_NewRunnableMethod(this, &FdWatcher::StartWatching);
+  XRE_GetIOMessageLoop()->PostTask(runnable.forget());
 }
 
 // Implementations may call this function multiple times if they ensure that
 // it's safe to call OpenFd() multiple times and they call StopWatching()
 // first.
 void
 FdWatcher::StartWatching()
 {
--- a/xpcom/base/nsDumpUtils.h
+++ b/xpcom/base/nsDumpUtils.h
@@ -84,18 +84,19 @@ public:
   virtual void StopWatching();
 
   NS_IMETHOD Observe(nsISupports* aSubject, const char* aTopic,
                      const char16_t* aData) override
   {
     MOZ_ASSERT(NS_IsMainThread());
     MOZ_ASSERT(!strcmp(aTopic, "xpcom-shutdown"));
 
-    XRE_GetIOMessageLoop()->PostTask(
-      NewRunnableMethod(this, &FdWatcher::StopWatching));
+    RefPtr<mozilla::Runnable> runnable =
+      NS_NewRunnableMethod(this, &FdWatcher::StopWatching);
+    XRE_GetIOMessageLoop()->PostTask(runnable.forget());
 
     return NS_OK;
   }
 };
 
 typedef void (*FifoCallback)(const nsCString& aInputStr);
 struct FifoInfo
 {