Bug 71895 - Create the hidden window on macOS only r=firefox-desktop-core-reviewers ,mossop

Differential Revision: https://phabricator.services.mozilla.com/D219834
This commit is contained in:
Gregory Pappas
2024-09-24 23:45:09 +00:00
parent 7968ad8964
commit 49494b7cae
22 changed files with 59 additions and 165 deletions

View File

@@ -90,6 +90,7 @@
// Do tests // Do tests
function doTests() { function doTests() {
if (Services.appShell.hasHiddenWindow) {
// Front end stuff sometimes likes to stuff things in the hidden window(s) // Front end stuff sometimes likes to stuff things in the hidden window(s)
// in which case we should repress all accessibles for those. // in which case we should repress all accessibles for those.
@@ -97,6 +98,7 @@
let doc = Services.appShell.hiddenDOMWindow.document; let doc = Services.appShell.hiddenDOMWindow.document;
let hiddenDocAcc = gAccService.getAccessibleFor(doc); let hiddenDocAcc = gAccService.getAccessibleFor(doc);
ok(!hiddenDocAcc, "hiddenDOMWindow should not have an accessible."); ok(!hiddenDocAcc, "hiddenDOMWindow should not have an accessible.");
}
const gQueue = new eventQueue(); const gQueue = new eventQueue();
gQueue.push(new openDialogWnd("about:about")); gQueue.push(new openDialogWnd("about:about"));

View File

@@ -107,6 +107,7 @@
// Do tests // Do tests
function doTests() { function doTests() {
if (Services.appShell.hasHiddenWindow) {
// Front end stuff sometimes likes to stuff things in the hidden window(s) // Front end stuff sometimes likes to stuff things in the hidden window(s)
// in which case we should repress all accessibles for those. // in which case we should repress all accessibles for those.
@@ -114,6 +115,7 @@
let doc = Services.appShell.hiddenDOMWindow.document; let doc = Services.appShell.hiddenDOMWindow.document;
let hiddenDocAcc = gAccService.getAccessibleFor(doc); let hiddenDocAcc = gAccService.getAccessibleFor(doc);
ok(!hiddenDocAcc, "hiddenDOMWindow should not have an accessible."); ok(!hiddenDocAcc, "hiddenDOMWindow should not have an accessible.");
}
const gQueue = new eventQueue(); const gQueue = new eventQueue();
gQueue.push(new openWndShutdownDoc("../../events/docload/docload_wnd.html")); gQueue.push(new openWndShutdownDoc("../../events/docload/docload_wnd.html"));

View File

@@ -335,10 +335,6 @@ var gBrowserInit = {
this._cancelDelayedStartup(); this._cancelDelayedStartup();
// Bug 1531854 - The hidden window is force-created here
// until all of its dependencies are handled.
Services.appShell.hiddenDOMWindow;
gBrowser.addEventListener( gBrowser.addEventListener(
"PermissionStateChange", "PermissionStateChange",
function () { function () {

View File

@@ -35,6 +35,8 @@ skip-if = [
["browser_hidden_browser_vsync.js"] ["browser_hidden_browser_vsync.js"]
["browser_hiddenwindow_existence.js"]
["browser_panel_vsync.js"] ["browser_panel_vsync.js"]
support-files = ["!/browser/components/downloads/test/browser/head.js"] support-files = ["!/browser/components/downloads/test/browser/head.js"]
@@ -64,12 +66,6 @@ run-if = [
"nightly_build", # Requires StartupRecorder.sys.mjs, which isn't shipped everywhere by default "nightly_build", # Requires StartupRecorder.sys.mjs, which isn't shipped everywhere by default
] ]
["browser_startup_hiddenwindow.js"]
run-if = [
"os == 'linux'",
"os == 'win'",
]
["browser_tabclose.js"] ["browser_tabclose.js"]
skip-if = [ skip-if = [
"os == 'linux' && devedition", # Bug 1737131 "os == 'linux' && devedition", # Bug 1737131

View File

@@ -0,0 +1,18 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function test_hiddenwindow_existence() {
switch (AppConstants.platform) {
case "macosx":
is(Services.appShell.hasHiddenWindow, true, "Hidden window exists");
break;
default:
is(
Services.appShell.hasHiddenWindow,
false,
"Hidden window does not exist"
);
}
});

View File

@@ -1,47 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function () {
if (
!AppConstants.NIGHTLY_BUILD &&
!AppConstants.MOZ_DEV_EDITION &&
!AppConstants.DEBUG
) {
ok(
!("@mozilla.org/test/startuprecorder;1" in Cc),
"the startup recorder component shouldn't exist in this non-nightly/non-devedition/" +
"non-debug build."
);
return;
}
let startupRecorder =
Cc["@mozilla.org/test/startuprecorder;1"].getService().wrappedJSObject;
await startupRecorder.done;
let extras = Cu.cloneInto(startupRecorder.data.extras, {});
let phasesExpectations = {
"before profile selection": false,
"before opening first browser window": false,
"before first paint": AppConstants.platform === "macosx",
// Bug 1531854
"before handling user events": true,
"before becoming idle": true,
};
for (let phase in extras) {
if (!(phase in phasesExpectations)) {
ok(false, `Startup phase '${phase}' should be specified.`);
continue;
}
is(
extras[phase].hiddenWindowLoaded,
phasesExpectations[phase],
`Hidden window loaded at '${phase}': ${phasesExpectations[phase]}`
);
}
});

View File

@@ -87,7 +87,6 @@ browser.jar:
content/browser/nsContextMenu.sys.mjs (content/nsContextMenu.sys.mjs) content/browser/nsContextMenu.sys.mjs (content/nsContextMenu.sys.mjs)
content/browser/contentTheme.js (content/contentTheme.js) content/browser/contentTheme.js (content/contentTheme.js)
#ifdef XP_MACOSX #ifdef XP_MACOSX
# XXX: We should exclude this one as well (bug 71895)
* content/browser/hiddenWindowMac.xhtml (content/hiddenWindowMac.xhtml) * content/browser/hiddenWindowMac.xhtml (content/hiddenWindowMac.xhtml)
content/browser/nonbrowser-mac.js (content/nonbrowser-mac.js) content/browser/nonbrowser-mac.js (content/nonbrowser-mac.js)
#endif #endif

View File

@@ -4868,7 +4868,7 @@ BrowserGlue.prototype = {
return; return;
} }
if (Services.appShell.hiddenDOMWindow.openPreferences) { if (AppConstants.platform == "macosx") {
Services.appShell.hiddenDOMWindow.openPreferences(...args); Services.appShell.hiddenDOMWindow.openPreferences(...args);
} }
}, },

View File

@@ -80,7 +80,6 @@ export function StartupRecorder() {
"image-loading": new Set(), "image-loading": new Set(),
}, },
code: {}, code: {},
extras: {},
prefStats: {}, prefStats: {},
}; };
this.done = new Promise(resolve => { this.done = new Promise(resolve => {
@@ -103,9 +102,6 @@ StartupRecorder.prototype = {
} }
}), }),
}; };
this.data.extras[name] = {
hiddenWindowLoaded: Services.appShell.hasHiddenWindow,
};
}, },
observe(subject, topic, data) { observe(subject, topic, data) {

View File

@@ -80,8 +80,8 @@ class nsGlobalWindowInner;
* its own sub-tree, even if multiple tabs are showing the same URI. * its own sub-tree, even if multiple tabs are showing the same URI.
* *
* - <top-uri> is the URI of the top window. Excepting special windows (such * - <top-uri> is the URI of the top window. Excepting special windows (such
* as browser.xhtml or hiddenWindow.html) it's what the address bar shows for * as browser.xhtml or hiddenWindowMac.xhtml) it's what the address bar shows
* the tab. * for the tab.
* *
*/ */
class nsWindowMemoryReporter final : public nsIMemoryReporter, class nsWindowMemoryReporter final : public nsIMemoryReporter,

View File

@@ -1,6 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
toolkit.jar:
res/hiddenWindow.html (res/hiddenWindow.html)

View File

@@ -8,8 +8,6 @@
with Files("**"): with Files("**"):
BUG_COMPONENT = ("Core", "DOM: Core & HTML") BUG_COMPONENT = ("Core", "DOM: Core & HTML")
JAR_MANIFESTS += ["jar.mn"]
interfaces = [ interfaces = [
"base", "base",
"events", "events",

View File

@@ -1,11 +0,0 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body></body>
</html>

View File

@@ -277,10 +277,7 @@ class ShutdownLeaks(object):
return sorted(counts, key=itemgetter(1), reverse=True) return sorted(counts, key=itemgetter(1), reverse=True)
def _isHiddenWindowURL(self, url): def _isHiddenWindowURL(self, url):
return ( return url == "resource://gre-resources/hiddenWindowMac.xhtml"
url == "resource://gre-resources/hiddenWindow.html"
or url == "chrome://browser/content/hiddenWindowMac.xhtml" # Win / Linux
) # Mac
class LSANLeaks(object): class LSANLeaks(object):

View File

@@ -361,7 +361,7 @@ add_task(async function test_non_addable_uri_errors() {
"cached-favicon:http://mozilla.org/made-up-favicon", "cached-favicon:http://mozilla.org/made-up-favicon",
"view-source:http://mozilla.org", "view-source:http://mozilla.org",
"chrome://browser/content/browser.xhtml", "chrome://browser/content/browser.xhtml",
"resource://gre-resources/hiddenWindow.html", "resource://gre-resources/hiddenWindowMac.html",
"data:,Hello%2C%20World!", "data:,Hello%2C%20World!",
"javascript:alert('hello wolrd!');", "javascript:alert('hello wolrd!');",
"blob:foo", "blob:foo",

View File

@@ -40,7 +40,7 @@ add_task(async function test_execute() {
"cached-favicon:http://mozilla.org/made-up-favicon", "cached-favicon:http://mozilla.org/made-up-favicon",
"view-source:http://mozilla.org", "view-source:http://mozilla.org",
"chrome://browser/content/browser.xhtml", "chrome://browser/content/browser.xhtml",
"resource://gre-resources/hiddenWindow.html", "resource://gre-resources/hiddenWindowMac.xhtml",
"data:,Hello%2C%20World!", "data:,Hello%2C%20World!",
"javascript:alert('hello wolrd!');", "javascript:alert('hello wolrd!');",
"http://localhost/" + "a".repeat(1984), "http://localhost/" + "a".repeat(1984),

View File

@@ -346,17 +346,12 @@ nsAppStartup::Quit(uint32_t aMode, int aExitCode, bool* aUserAllowedQuit) {
} }
#ifdef XP_MACOSX #ifdef XP_MACOSX
else if (mConsiderQuitStopper == suspiciousCount) { else if (mConsiderQuitStopper == suspiciousCount) {
// ... or there is only a hiddenWindow left, and it's useless:
// Failure shouldn't be fatal, but will abort quit attempt: // Failure shouldn't be fatal, but will abort quit attempt:
if (!appShell) return NS_OK; if (!appShell) return NS_OK;
bool hasHiddenWindow = false;
bool usefulHiddenWindow; appShell->GetHasHiddenWindow(&hasHiddenWindow);
appShell->GetApplicationProvidedHiddenWindow(&usefulHiddenWindow); // If there's a hidden window, we won't quit:
nsCOMPtr<nsIAppWindow> hiddenWindow; if (hasHiddenWindow) {
appShell->GetHiddenWindow(getter_AddRefs(hiddenWindow));
// If the remaining windows are useful, we won't quit:
if (!hiddenWindow || usefulHiddenWindow) {
return NS_OK; return NS_OK;
} }

View File

@@ -13,12 +13,14 @@ interface nsIAppStartup : nsISupports
/** /**
* Create the hidden window. * Create the hidden window.
*/ */
[noscript]
void createHiddenWindow(); void createHiddenWindow();
/** /**
* Destroys the hidden window. This will have no effect if the hidden window * Destroys the hidden window. This will have no effect if the hidden window
* has not yet been created. * has not yet been created.
*/ */
[noscript]
void destroyHiddenWindow(); void destroyHiddenWindow();
/** /**

View File

@@ -5639,25 +5639,12 @@ nsresult XREMain::XRE_mainRun() {
SaveToEnv("XRE_RESTARTED_BY_PROFILE_MANAGER="); SaveToEnv("XRE_RESTARTED_BY_PROFILE_MANAGER=");
if (!AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) { if (!AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) {
// Don't create the hidden window during startup on
// platforms that don't always need it.
#ifdef XP_MACOSX #ifdef XP_MACOSX
bool lazyHiddenWindow = false; if (!BackgroundTasks::IsBackgroundTaskMode()) {
#else
bool lazyHiddenWindow = true;
#endif
#ifdef MOZ_BACKGROUNDTASKS
if (BackgroundTasks::IsBackgroundTaskMode()) {
// Background tasks aren't going to load a chrome XUL document.
lazyHiddenWindow = true;
}
#endif
if (!lazyHiddenWindow) {
rv = appStartup->CreateHiddenWindow(); rv = appStartup->CreateHiddenWindow();
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
} }
#endif
#ifdef XP_WIN #ifdef XP_WIN
Preferences::RegisterCallbackAndCall( Preferences::RegisterCallbackAndCall(

View File

@@ -50,16 +50,12 @@ using namespace mozilla;
using mozilla::dom::BrowsingContext; using mozilla::dom::BrowsingContext;
using mozilla::intl::LocaleService; using mozilla::intl::LocaleService;
// Default URL for the hidden window, can be overridden by a pref on Mac
#define DEFAULT_HIDDENWINDOW_URL "resource://gre-resources/hiddenWindow.html"
class nsIAppShell; class nsIAppShell;
nsAppShellService::nsAppShellService() nsAppShellService::nsAppShellService()
: mXPCOMWillShutDown(false), : mXPCOMWillShutDown(false),
mXPCOMShuttingDown(false), mXPCOMShuttingDown(false),
mModalWindowCount(0), mModalWindowCount(0),
mApplicationProvidedHiddenWindow(false),
mScreenId(0) { mScreenId(0) {
nsCOMPtr<nsIObserverService> obs = services::GetObserverService(); nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
@@ -82,14 +78,9 @@ nsAppShellService::SetScreenId(uint32_t aScreenId) {
return NS_OK; return NS_OK;
} }
void nsAppShellService::EnsureHiddenWindow() {
if (!mHiddenWindow) {
(void)CreateHiddenWindow();
}
}
NS_IMETHODIMP NS_IMETHODIMP
nsAppShellService::CreateHiddenWindow() { nsAppShellService::CreateHiddenWindow() {
#if defined(XP_MACOSX)
if (!XRE_IsParentProcess()) { if (!XRE_IsParentProcess()) {
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }
@@ -113,17 +104,13 @@ nsAppShellService::CreateHiddenWindow() {
nsresult rv; nsresult rv;
int32_t initialHeight = 100, initialWidth = 100; int32_t initialHeight = 100, initialWidth = 100;
#ifdef XP_MACOSX
uint32_t chromeMask = 0; uint32_t chromeMask = 0;
nsAutoCString prefVal; nsAutoCString prefVal;
rv = Preferences::GetCString("browser.hiddenWindowChromeURL", prefVal); rv = Preferences::GetCString("browser.hiddenWindowChromeURL", prefVal);
const char* hiddenWindowURL = if (NS_FAILED(rv)) {
NS_SUCCEEDED(rv) ? prefVal.get() : DEFAULT_HIDDENWINDOW_URL; return NS_OK;
mApplicationProvidedHiddenWindow = prefVal.get() ? true : false; }
#else const char* hiddenWindowURL = prefVal.get();
static const char hiddenWindowURL[] = DEFAULT_HIDDENWINDOW_URL;
uint32_t chromeMask = nsIWebBrowserChrome::CHROME_ALL;
#endif
nsCOMPtr<nsIURI> url; nsCOMPtr<nsIURI> url;
rv = NS_NewURI(getter_AddRefs(url), hiddenWindowURL); rv = NS_NewURI(getter_AddRefs(url), hiddenWindowURL);
@@ -142,6 +129,7 @@ nsAppShellService::CreateHiddenWindow() {
} }
mHiddenWindow.swap(newWindow); mHiddenWindow.swap(newWindow);
#endif
return NS_OK; return NS_OK;
} }
@@ -677,8 +665,6 @@ NS_IMETHODIMP
nsAppShellService::GetHiddenWindow(nsIAppWindow** aWindow) { nsAppShellService::GetHiddenWindow(nsIAppWindow** aWindow) {
NS_ENSURE_ARG_POINTER(aWindow); NS_ENSURE_ARG_POINTER(aWindow);
EnsureHiddenWindow();
*aWindow = mHiddenWindow; *aWindow = mHiddenWindow;
NS_IF_ADDREF(*aWindow); NS_IF_ADDREF(*aWindow);
return *aWindow ? NS_OK : NS_ERROR_FAILURE; return *aWindow ? NS_OK : NS_ERROR_FAILURE;
@@ -688,8 +674,6 @@ NS_IMETHODIMP
nsAppShellService::GetHiddenDOMWindow(mozIDOMWindowProxy** aWindow) { nsAppShellService::GetHiddenDOMWindow(mozIDOMWindowProxy** aWindow) {
NS_ENSURE_ARG_POINTER(aWindow); NS_ENSURE_ARG_POINTER(aWindow);
EnsureHiddenWindow();
nsresult rv; nsresult rv;
nsCOMPtr<nsIDocShell> docShell; nsCOMPtr<nsIDocShell> docShell;
NS_ENSURE_TRUE(mHiddenWindow, NS_ERROR_FAILURE); NS_ENSURE_TRUE(mHiddenWindow, NS_ERROR_FAILURE);
@@ -711,12 +695,6 @@ nsAppShellService::GetHasHiddenWindow(bool* aHasHiddenWindow) {
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsAppShellService::GetApplicationProvidedHiddenWindow(bool* aAPHW) {
*aAPHW = mApplicationProvidedHiddenWindow;
return NS_OK;
}
/* /*
* Register a new top level window (created elsewhere) * Register a new top level window (created elsewhere)
*/ */

View File

@@ -34,8 +34,6 @@ class nsAppShellService final : public nsIAppShellService, public nsIObserver {
protected: protected:
~nsAppShellService(); ~nsAppShellService();
void EnsureHiddenWindow();
nsresult JustCreateTopWindow(nsIAppWindow* aParent, nsIURI* aUrl, nsresult JustCreateTopWindow(nsIAppWindow* aParent, nsIURI* aUrl,
uint32_t aChromeMask, int32_t aInitialWidth, uint32_t aChromeMask, int32_t aInitialWidth,
int32_t aInitialHeight, bool aIsHiddenWindow, int32_t aInitialHeight, bool aIsHiddenWindow,
@@ -46,7 +44,6 @@ class nsAppShellService final : public nsIAppShellService, public nsIObserver {
bool mXPCOMWillShutDown; bool mXPCOMWillShutDown;
bool mXPCOMShuttingDown; bool mXPCOMShuttingDown;
uint16_t mModalWindowCount; uint16_t mModalWindowCount;
bool mApplicationProvidedHiddenWindow;
uint32_t mScreenId; uint32_t mScreenId;
}; };

View File

@@ -58,6 +58,7 @@ interface nsIAppShellService : nsISupports
[noscript] [noscript]
void createHiddenWindow(); void createHiddenWindow();
[noscript]
void destroyHiddenWindow(); void destroyHiddenWindow();
/** /**
@@ -86,13 +87,6 @@ interface nsIAppShellService : nsISupports
*/ */
readonly attribute mozIDOMWindowProxy hiddenDOMWindow; readonly attribute mozIDOMWindowProxy hiddenDOMWindow;
/**
* Return true if the application hidden window was provided by the
* application. If it wasn't, the default hidden window was used. This will
* usually be false on all non-mac platforms.
*/
readonly attribute boolean applicationProvidedHiddenWindow;
/** /**
* Add a window to the application's registry of windows. These windows * Add a window to the application's registry of windows. These windows
* are generally shown in the Windows taskbar, and the application * are generally shown in the Windows taskbar, and the application
@@ -112,7 +106,8 @@ interface nsIAppShellService : nsISupports
void unregisterTopLevelWindow(in nsIAppWindow aWindow); void unregisterTopLevelWindow(in nsIAppWindow aWindow);
/** /**
* Whether the hidden window has been lazily created. * Whether the hidden window exists.
* This will be false on all non-mac platforms.
*/ */
readonly attribute boolean hasHiddenWindow; readonly attribute boolean hasHiddenWindow;
}; };