From 364a0584172356dd1bcf3050eb0a727bb8b37681 Mon Sep 17 00:00:00 2001 From: Mike Conley Date: Fri, 8 May 2020 22:31:19 +0000 Subject: [PATCH] Bug 1634703 - Add a parent-process-only method to nsIDOMWindowUtils to get the native window ID from a window. r=mstange Differential Revision: https://phabricator.services.mozilla.com/D73481 --- dom/base/nsDOMWindowUtils.cpp | 23 +++++++++++++++++++++++ dom/interfaces/base/nsIDOMWindowUtils.idl | 9 +++++++++ widget/nsIWidget.h | 1 + 3 files changed, 33 insertions(+) diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 3719e6df1073..00ab45f1f8ee 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -4342,3 +4342,26 @@ nsDOMWindowUtils::GetPaintCount(uint64_t* aPaintCount) { *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; +} diff --git a/dom/interfaces/base/nsIDOMWindowUtils.idl b/dom/interfaces/base/nsIDOMWindowUtils.idl index 88085bcbef53..35d6f61260be 100644 --- a/dom/interfaces/base/nsIDOMWindowUtils.idl +++ b/dom/interfaces/base/nsIDOMWindowUtils.idl @@ -2054,6 +2054,15 @@ interface nsIDOMWindowUtils : nsISupports { // 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)] diff --git a/widget/nsIWidget.h b/widget/nsIWidget.h index 5fd000964968..2c15d57795d1 100644 --- a/widget/nsIWidget.h +++ b/widget/nsIWidget.h @@ -131,6 +131,7 @@ typedef void* nsNativeWidget; // 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