Bug 1601301, add a non-recursive flag to mediaCaptureWindowState. With fission enabled, we will need to handle each subframe separately. Instead, the window will be supplied in the recording-device-events notification and mediaCaptureWindowState will be called on each window in turn, r=pehrsons draft
authorNeil Deakin <neil@mozilla.com>
Tue, 10 Dec 2019 18:16:08 +0000
changeset 2527018 92b4b531c373dfc16666ab57b77456d7ff8ae344
parent 2526795 f5d38101ac7c0bb452a09a08226f65d9e5d29f8c
child 2527019 a51f0a2ce858858837a070fa381744d491380b3d
push id463240
push userreviewbot
push dateTue, 10 Dec 2019 18:16:31 +0000
treeherdertry@a51f0a2ce858 [default view] [failures only]
reviewerspehrsons
bugs1601301
milestone73.0a1
Bug 1601301, add a non-recursive flag to mediaCaptureWindowState. With fission enabled, we will need to handle each subframe separately. Instead, the window will be supplied in the recording-device-events notification and mediaCaptureWindowState will be called on each window in turn, r=pehrsons Differential Diff: PHID-DIFF-mesd575rrw2hljktiaar
dom/media/MediaManager.cpp
dom/media/nsIMediaManager.idl
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -2132,16 +2132,17 @@ nsresult MediaManager::NotifyRecordingSt
   NS_ENSURE_TRUE(docURI, NS_ERROR_FAILURE);
 
   nsresult rv = docURI->GetSpec(pageURL);
   NS_ENSURE_SUCCESS(rv, rv);
 
   NS_ConvertUTF8toUTF16 requestURL(pageURL);
 
   props->SetPropertyAsAString(NS_LITERAL_STRING("requestURL"), requestURL);
+  props->SetPropertyAsInterface(NS_LITERAL_STRING("window"), aWindow);
 
   obs->NotifyObservers(static_cast<nsIPropertyBag2*>(props),
                        "recording-device-events", nullptr);
   LOG("Sent recording-device-events for url '%s'", pageURL.get());
 
   return NS_OK;
 }
 
@@ -3815,42 +3816,55 @@ struct CaptureWindowStateData {
   uint16_t* mAppShare;
   uint16_t* mBrowserShare;
 };
 
 NS_IMETHODIMP
 MediaManager::MediaCaptureWindowState(nsIDOMWindow* aCapturedWindow,
                                       uint16_t* aCamera, uint16_t* aMicrophone,
                                       uint16_t* aScreen, uint16_t* aWindow,
-                                      uint16_t* aBrowser) {
+                                      uint16_t* aBrowser, bool aNonRecursive) {
   MOZ_ASSERT(NS_IsMainThread());
 
   CaptureState camera = CaptureState::Off;
   CaptureState microphone = CaptureState::Off;
   CaptureState screen = CaptureState::Off;
   CaptureState window = CaptureState::Off;
   CaptureState browser = CaptureState::Off;
 
   nsCOMPtr<nsPIDOMWindowInner> piWin = do_QueryInterface(aCapturedWindow);
   if (piWin) {
-    IterateWindowListeners(
-        piWin, [&camera, &microphone, &screen, &window,
-                &browser](const RefPtr<GetUserMediaWindowListener>& aListener) {
-          camera = CombineCaptureState(
-              camera, aListener->CapturingSource(MediaSourceEnum::Camera));
-          microphone = CombineCaptureState(
-              microphone,
-              aListener->CapturingSource(MediaSourceEnum::Microphone));
-          screen = CombineCaptureState(
-              screen, aListener->CapturingSource(MediaSourceEnum::Screen));
-          window = CombineCaptureState(
-              window, aListener->CapturingSource(MediaSourceEnum::Window));
-          browser = CombineCaptureState(
-              browser, aListener->CapturingSource(MediaSourceEnum::Browser));
-        });
+    if (aNonRecursive) {
+      uint64_t windowID = piWin->WindowID();
+      RefPtr<GetUserMediaWindowListener> listener = GetWindowListener(windowID);
+      // listener might have been destroyed.
+      if (listener) {
+        camera = listener->CapturingSource(MediaSourceEnum::Camera);
+        microphone = listener->CapturingSource(MediaSourceEnum::Microphone);
+        screen = listener->CapturingSource(MediaSourceEnum::Screen);
+        window = listener->CapturingSource(MediaSourceEnum::Window);
+        browser = listener->CapturingSource(MediaSourceEnum::Browser);
+      }
+    } else {
+      IterateWindowListeners(
+          piWin, [&camera, &microphone, &screen, &window,
+                  &browser](const RefPtr<GetUserMediaWindowListener>& aListener) {
+            camera = CombineCaptureState(
+                camera, aListener->CapturingSource(MediaSourceEnum::Camera));
+            microphone = CombineCaptureState(
+                microphone,
+                aListener->CapturingSource(MediaSourceEnum::Microphone));
+            screen = CombineCaptureState(
+                screen, aListener->CapturingSource(MediaSourceEnum::Screen));
+            window = CombineCaptureState(
+                window, aListener->CapturingSource(MediaSourceEnum::Window));
+            browser = CombineCaptureState(
+                browser, aListener->CapturingSource(MediaSourceEnum::Browser));
+          });
+    }
   }
 
   *aCamera = FromCaptureState(camera);
   *aMicrophone = FromCaptureState(microphone);
   *aScreen = FromCaptureState(screen);
   *aWindow = FromCaptureState(window);
   *aBrowser = FromCaptureState(browser);
 
--- a/dom/media/nsIMediaManager.idl
+++ b/dom/media/nsIMediaManager.idl
@@ -18,20 +18,22 @@ interface nsIMediaManagerService : nsISu
   /* return a array of inner windows that have active captures */
   readonly attribute nsIArray activeMediaCaptureWindows;
 
   /* possible states for camera and microphone capture */
   const unsigned short STATE_NOCAPTURE = 0;
   const unsigned short STATE_CAPTURE_ENABLED = 1;
   const unsigned short STATE_CAPTURE_DISABLED = 2;
 
-  /* Get the capture state for the given window and all descendant windows (iframes, etc) */
+  /* Get the capture state for the given window and, optionally,
+     all descendant windows (iframes, etc). */
   void mediaCaptureWindowState(in nsIDOMWindow aWindow,
                                out unsigned short aCamera,
                                out unsigned short aMicrophone,
                                [optional] out unsigned short aScreenShare,
                                [optional] out unsigned short aWindowShare,
-                               [optional] out unsigned short aBrowserShare);
+                               [optional] out unsigned short aBrowserShare,
+                               [optional] in boolean aNonRecursive);
 
   /* Clear per-orgin list of persistent DeviceIds stored for enumerateDevices
      sinceTime is milliseconds since 1 January 1970 00:00:00 UTC. 0 = clear all */
   void sanitizeDeviceIds(in long long sinceWhen);
 };