From 907a5549e73a856ea12a06b1935ac623831522a5 Mon Sep 17 00:00:00 2001 From: Agi Sferro Date: Thu, 20 Feb 2020 19:29:08 +0000 Subject: [PATCH] Bug 1613237 - Call nsIWebBrowserChrome3 for main process pages. r=kmag,esawin nsContentTreeOwner uses XULBrowserWindow (which is Desktop-only) to get the current WebBrowserChrome instance. This patch adds a lookup for the WebBrowserChrome actor to make sure that the correct instance is queried on all platforms. Differential Revision: https://phabricator.services.mozilla.com/D62817 --HG-- extra : moz-landing-system : lando --- .../components/geckoview/GeckoViewStartup.js | 1 + xpfe/appshell/nsContentTreeOwner.cpp | 30 +++++++++++++++++++ xpfe/appshell/nsContentTreeOwner.h | 3 ++ 3 files changed, 34 insertions(+) diff --git a/mobile/android/components/geckoview/GeckoViewStartup.js b/mobile/android/components/geckoview/GeckoViewStartup.js index f115b5305d20..3077c3d0a0b1 100644 --- a/mobile/android/components/geckoview/GeckoViewStartup.js +++ b/mobile/android/components/geckoview/GeckoViewStartup.js @@ -31,6 +31,7 @@ const ACTORS = { child: { moduleURI: "resource:///actors/WebBrowserChromeChild.jsm", }, + includeChrome: true, }, }; diff --git a/xpfe/appshell/nsContentTreeOwner.cpp b/xpfe/appshell/nsContentTreeOwner.cpp index 2dfb5597190a..941560574930 100644 --- a/xpfe/appshell/nsContentTreeOwner.cpp +++ b/xpfe/appshell/nsContentTreeOwner.cpp @@ -33,6 +33,7 @@ #include "mozilla/NullPrincipal.h" #include "nsDocShell.h" #include "nsDocShellLoadState.h" +#include "nsQueryActor.h" #include "nsIScriptObjectPrincipal.h" #include "nsIURI.h" @@ -71,6 +72,28 @@ class nsSiteWindow : public nsIEmbeddingSiteWindow { nsContentTreeOwner* mAggregator; }; +already_AddRefed +nsContentTreeOwner::GetWebBrowserChrome() { + if (!mAppWindow) { + return nullptr; + } + + nsCOMPtr docShell; + mAppWindow->GetDocShell(getter_AddRefs(docShell)); + + if (!docShell) { + return nullptr; + } + + nsCOMPtr outer(docShell->GetWindow()); + if (nsCOMPtr chrome = + do_QueryActor(u"WebBrowserChrome", outer)) { + return chrome.forget(); + } + + return nullptr; +} + //***************************************************************************** //*** nsContentTreeOwner: Object Management //***************************************************************************** @@ -151,6 +174,13 @@ NS_IMETHODIMP nsContentTreeOwner::GetInterface(const nsIID& aIID, return mAppWindow->QueryInterface(aIID, aSink); } + if (aIID.Equals(NS_GET_IID(nsIWebBrowserChrome3))) { + if (nsCOMPtr chrome = GetWebBrowserChrome()) { + chrome.forget(aSink); + return NS_OK; + } + } + return QueryInterface(aIID, aSink); } diff --git a/xpfe/appshell/nsContentTreeOwner.h b/xpfe/appshell/nsContentTreeOwner.h index 66b318b05281..874b10c46d92 100644 --- a/xpfe/appshell/nsContentTreeOwner.h +++ b/xpfe/appshell/nsContentTreeOwner.h @@ -49,6 +49,9 @@ class nsContentTreeOwner final : public nsIDocShellTreeOwner, void AppWindow(mozilla::AppWindow* aAppWindow); mozilla::AppWindow* AppWindow(); + private: + already_AddRefed GetWebBrowserChrome(); + protected: mozilla::AppWindow* mAppWindow; nsSiteWindow* mSiteWindow;