aboutsummaryrefslogtreecommitdiff
path: root/www/waterfox/files/patch-bug1435036
blob: 4cb2b39fd1dee7d13a5fed6875ee9454c875e2c7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
commit a857f1b964fc
Author: Andreas Pehrson <pehrsons@mozilla.com>
Date:   Mon Mar 19 09:40:38 2018 +0100

    Bug 1435036 - Improve window checks. r=jib, a=RyanVM
    
    --HG--
    extra : source : 37039eaf524823ed3157fafbdfcfbc450b67b4ab
---
 dom/media/MediaManager.cpp | 30 +++++++++++++++++++-----------
 dom/media/MediaManager.h   |  1 +
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git dom/media/MediaManager.cpp dom/media/MediaManager.cpp
index e96509db4ce0..f2862dc0b23c 100644
--- dom/media/MediaManager.cpp
+++ dom/media/MediaManager.cpp
@@ -1013,14 +1013,17 @@ public:
   public:
     TracksAvailableCallback(MediaManager* aManager,
                             already_AddRefed<nsIDOMGetUserMediaSuccessCallback> aSuccess,
-                            uint64_t aWindowID,
+                            const RefPtr<GetUserMediaWindowListener>& aWindowListener,
                             DOMMediaStream* aStream)
-      : mWindowID(aWindowID), mOnSuccess(aSuccess), mManager(aManager),
-        mStream(aStream) {}
+      : mWindowListener(aWindowListener),
+        mOnSuccess(aSuccess),
+        mManager(aManager),
+        mStream(aStream)
+    {}
     void NotifyTracksAvailable(DOMMediaStream* aStream) override
     {
-      // We're in the main thread, so no worries here.
-      if (!(mManager->IsWindowStillActive(mWindowID))) {
+      // We're on the main thread, so no worries here.
+      if (!mManager->IsWindowListenerStillActive(mWindowListener)) {
         return;
       }
 
@@ -1033,7 +1036,7 @@ public:
       LOG(("Returning success for getUserMedia()"));
       mOnSuccess->OnSuccess(aStream);
     }
-    uint64_t mWindowID;
+    RefPtr<GetUserMediaWindowListener> mWindowListener;
     nsCOMPtr<nsIDOMGetUserMediaSuccessCallback> mOnSuccess;
     RefPtr<MediaManager> mManager;
     // Keep the DOMMediaStream alive until the NotifyTracksAvailable callback
@@ -1056,10 +1059,8 @@ public:
 
     // We're on main-thread, and the windowlist can only
     // be invalidated from the main-thread (see OnNavigation)
-    GetUserMediaWindowListener* listener =
-      mManager->GetWindowListener(mWindowID);
-    if (!listener || !window || !window->GetExtantDoc()) {
-      // This window is no longer live.  mListener has already been removed
+    if (!mManager->IsWindowListenerStillActive(mWindowListener)) {
+      // This window is no longer live. mListener has already been removed.
       return NS_OK;
     }
 
@@ -1219,7 +1220,7 @@ public:
 
     // Note: includes JS callbacks; must be released on MainThread
     auto callback = MakeRefPtr<Refcountable<UniquePtr<OnTracksAvailableCallback>>>(
-        new TracksAvailableCallback(mManager, mOnSuccess.forget(), mWindowID, domStream));
+        new TracksAvailableCallback(mManager, mOnSuccess.forget(), mWindowListener, domStream));
 
     // Dispatch to the media thread to ask it to start the sources,
     // because that can take a while.
@@ -3015,6 +3016,13 @@ MediaManager::RemoveWindowID(uint64_t aWindowId)
        aWindowId, outerID));
 }
 
+bool
+MediaManager::IsWindowListenerStillActive(GetUserMediaWindowListener* aListener)
+{
+  MOZ_DIAGNOSTIC_ASSERT(aListener);
+  return aListener && aListener == GetWindowListener(aListener->WindowID());
+}
+
 void
 MediaManager::GetPref(nsIPrefBranch *aBranch, const char *aPref,
                       const char *aData, int32_t *aVal)
diff --git dom/media/MediaManager.h dom/media/MediaManager.h
index 3d9d9e55f8ec..f9c5b0647f64 100644
--- dom/media/MediaManager.h
+++ dom/media/MediaManager.h
@@ -237,6 +237,7 @@ public:
   bool IsWindowStillActive(uint64_t aWindowId) {
     return !!GetWindowListener(aWindowId);
   }
+  bool IsWindowListenerStillActive(GetUserMediaWindowListener* aListener);
   // Note: also calls aListener->Remove(), even if inactive
   void RemoveFromWindowList(uint64_t aWindowID,
     GetUserMediaWindowListener *aListener);