From 832f0ee2aea01da213ad948e94fdff72df6c9710 Mon Sep 17 00:00:00 2001 From: Stephen A Pohl Date: Tue, 21 Apr 2020 12:31:51 +0000 Subject: [PATCH] Bug 1597508: Use WidgetUtils::DOMWindowToWidget to determine native window during reopen of Firefox on macOS. r=farre Differential Revision: https://phabricator.services.mozilla.com/D71408 --- toolkit/xre/nsNativeAppSupportCocoa.mm | 28 +++++++++----------------- 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/toolkit/xre/nsNativeAppSupportCocoa.mm b/toolkit/xre/nsNativeAppSupportCocoa.mm index c43388b74281..f981dea8ac85 100644 --- a/toolkit/xre/nsNativeAppSupportCocoa.mm +++ b/toolkit/xre/nsNativeAppSupportCocoa.mm @@ -15,38 +15,30 @@ #include "nsIBaseWindow.h" #include "nsCommandLine.h" #include "mozIDOMWindow.h" -#include "nsIDocShellTreeItem.h" -#include "nsIDocShellTreeOwner.h" -#include "nsIInterfaceRequestorUtils.h" #include "nsIWebNavigation.h" #include "nsIWidget.h" #include "nsIWindowMediator.h" +#include "nsPIDOMWindow.h" +#include "WidgetUtils.h" // This must be included last: #include "nsObjCExceptions.h" +using mozilla::widget::WidgetUtils; + nsresult GetNativeWindowPointerFromDOMWindow(mozIDOMWindowProxy* a_window, NSWindow** a_nativeWindow) { *a_nativeWindow = nil; if (!a_window) return NS_ERROR_INVALID_ARG; - nsCOMPtr mruWebNav(do_GetInterface(a_window)); - if (mruWebNav) { - nsCOMPtr mruTreeItem(do_QueryInterface(mruWebNav)); - nsCOMPtr mruTreeOwner = nullptr; - mruTreeItem->GetTreeOwner(getter_AddRefs(mruTreeOwner)); - if (mruTreeOwner) { - nsCOMPtr mruBaseWindow(do_QueryInterface(mruTreeOwner)); - if (mruBaseWindow) { - nsCOMPtr mruWidget = nullptr; - mruBaseWindow->GetMainWidget(getter_AddRefs(mruWidget)); - if (mruWidget) { - *a_nativeWindow = (NSWindow*)mruWidget->GetNativeData(NS_NATIVE_WINDOW); - } - } - } + nsPIDOMWindowOuter* win = nsPIDOMWindowOuter::From(a_window); + nsCOMPtr widget = WidgetUtils::DOMWindowToWidget(win); + if (!widget) { + return NS_ERROR_FAILURE; } + *a_nativeWindow = (NSWindow*)widget->GetNativeData(NS_NATIVE_WINDOW); + return NS_OK; }