Bug 1634703 - Add a parent-process-only method to nsIDOMWindowUtils to get the native window ID from a window. r=mstange a=pascalc
authorMike Conley <mconley@mozilla.com>
Tue, 12 May 2020 14:50:21 +0000
changeset 595036 d393dc7dd956b57bfc4cb0937a03c99e79984035
parent 595035 fcfb2d79521f920bfcab63bd05ee6c80ac3d8df1
child 595037 f5f3a5d324386b1575cfc67de3684ea541436cb2
push id2335
push userffxbld-merge
push dateMon, 25 May 2020 13:47:24 +0000
treeherdermozilla-release@69ca1d06f46a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange, pascalc
bugs1634703
milestone77.0
Bug 1634703 - Add a parent-process-only method to nsIDOMWindowUtils to get the native window ID from a window. r=mstange a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D73481
dom/base/nsDOMWindowUtils.cpp
dom/interfaces/base/nsIDOMWindowUtils.idl
widget/nsIWidget.h
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -4336,8 +4336,31 @@ nsDOMWindowUtils::GetUsesOverlayScrollba
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetPaintCount(uint64_t* aPaintCount) {
   auto* presShell = GetPresShell();
   *aPaintCount = presShell ? presShell->GetPaintCount() : 0;
   return NS_OK;
 }
+
+NS_IMETHODIMP
+nsDOMWindowUtils::GetWebrtcRawDeviceId(nsAString& aRawDeviceId) {
+  if (!XRE_IsParentProcess()) {
+    MOZ_CRASH(
+        "GetWebrtcRawDeviceId is only available in the parent "
+        "process");
+  }
+
+  nsIWidget* widget = GetWidget();
+  if (!widget) {
+    return NS_ERROR_FAILURE;
+  }
+
+  int64_t rawDeviceId =
+      (int64_t)(widget->GetNativeData(NS_NATIVE_WINDOW_WEBRTC_DEVICE_ID));
+  if (!rawDeviceId) {
+    return NS_ERROR_FAILURE;
+  }
+
+  aRawDeviceId.AppendInt(rawDeviceId);
+  return NS_OK;
+}
--- a/dom/interfaces/base/nsIDOMWindowUtils.idl
+++ b/dom/interfaces/base/nsIDOMWindowUtils.idl
@@ -2049,16 +2049,25 @@ interface nsIDOMWindowUtils : nsISupport
   const long DIRECTION_NOT_SET = 2;
 
   void syncFlushCompositor();
 
   unsigned long long getLayersId();
 
   // Returns true if we are using overlay scrollbars.
   readonly attribute bool usesOverlayScrollbars;
+
+  // Returns the ID for the underlying window widget, which can
+  // be compared against the rawId from a nsIMediaDevice to determine
+  // if the window is being shared.
+  //
+  // Using this only makes sense in the parent process, and the function
+  // will intentionally crash any non-parent process that tries to access
+  // it.
+  readonly attribute AString webrtcRawDeviceId;
 };
 
 [scriptable, uuid(c694e359-7227-4392-a138-33c0cc1f15a6)]
 interface nsITranslationNodeList : nsISupports {
   readonly attribute unsigned long length;
   Node item(in unsigned long index);
 
   // A translation root is a block element, or an inline element
--- a/widget/nsIWidget.h
+++ b/widget/nsIWidget.h
@@ -126,16 +126,17 @@ typedef void* nsNativeWidget;
 #define NS_NATIVE_PLUGIN_ID 13
 // This is available only with GetNativeData() in parent process.  Anybody
 // shouldn't access this pointer as a valid pointer since the result may be
 // special value like NS_ONLY_ONE_NATIVE_IME_CONTEXT.  So, the result is just
 // an identifier of distinguishing a text composition is caused by which native
 // IME context.  Note that the result is only valid in the process.  So,
 // XP code should use nsIWidget::GetNativeIMEContext() instead of using this.
 #define NS_RAW_NATIVE_IME_CONTEXT 14
+#define NS_NATIVE_WINDOW_WEBRTC_DEVICE_ID 15
 #ifdef XP_MACOSX
 #  define NS_NATIVE_PLUGIN_PORT_QD 100
 #  define NS_NATIVE_PLUGIN_PORT_CG 101
 #endif
 #ifdef XP_WIN
 #  define NS_NATIVE_TSF_THREAD_MGR 100
 #  define NS_NATIVE_TSF_CATEGORY_MGR 101
 #  define NS_NATIVE_TSF_DISPLAY_ATTR_MGR 102