Bug 1486596 - Hold a WeakRef to PanZoomController from nsWindow r=jchen
authorJames Willcox <snorp@snorp.net>
Sat, 01 Sep 2018 16:50:40 -0500
changeset 495220 a82faa24a0a6c561bebfdb8e33ad21bb4dab61f2
parent 495219 c0cef26afa24e0f1c3f1ecd29fccd7f7472348c5
child 495221 355f1c2a3f8322f1d3d596423a52f3bd51a455e4
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1486596
milestone64.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 1486596 - Hold a WeakRef to PanZoomController from nsWindow r=jchen
mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/PanZoomController.java
widget/android/nsWindow.cpp
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/PanZoomController.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/PanZoomController.java
@@ -200,16 +200,21 @@ public class PanZoomController extends J
         ThreadUtils.assertOnUiThread();
 
         if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) {
             return handleMouseEvent(event);
         }
         return handleMotionEvent(event);
     }
 
+    @Override
+    protected void finalize() throws Throwable {
+        setAttached(false);
+    }
+
     /**
      * Process a non-touch motion event through the pan-zoom controller. Currently, hover
      * and scroll events are supported. Pointer coordinates should be relative to the
      * display surface.
      *
      * @param event MotionEvent to process.
      * @return True if the event was handled.
      */
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -377,17 +377,17 @@ public:
 class nsWindow::NPZCSupport final
     : public PanZoomController::Natives<NPZCSupport>
 {
     using LockedWindowPtr = WindowPtr<NPZCSupport>::Locked;
 
     static bool sNegateWheelScroll;
 
     WindowPtr<NPZCSupport> mWindow;
-    PanZoomController::GlobalRef mNPZC;
+    PanZoomController::WeakRef mNPZC;
     int mPreviousButtons;
 
     template<typename Lambda>
     class InputEvent final : public nsAppShell::Event
     {
         PanZoomController::GlobalRef mNPZC;
         Lambda mLambda;
 
@@ -485,20 +485,24 @@ public:
         // and only make a pending call if the destroyed flag is not set.
         //
         // 7) is solved by taking a lock whenever mWindow is modified on the
         // Gecko thread or accessed on the UI thread. That way, we don't
         // release mWindow until the UI thread is done using it, thus avoiding
         // the race condition.
 
         if (RefPtr<nsThread> uiThread = GetAndroidUiThread()) {
+            auto npzc = PanZoomController::GlobalRef(mNPZC);
+            if (!npzc) {
+                return;
+            }
+
             uiThread->Dispatch(NS_NewRunnableFunction(
                         "NPZCSupport::OnDetach",
-                        [npzc = PanZoomController::GlobalRef(mNPZC),
-                         disposer = RefPtr<Runnable>(aDisposer)] {
+                        [npzc, disposer = RefPtr<Runnable>(aDisposer)] {
                             npzc->SetAttached(false);
                             disposer->Run();
                         }));
         }
     }
 
     const PanZoomController::Ref& GetJavaNPZC() const
     {