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 9bd663d2cf
commit f7b1e37259
22 changed files with 59 additions and 165 deletions

View File

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

View File

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

View File

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

View File

@ -35,6 +35,8 @@ skip-if = [
["browser_hidden_browser_vsync.js"]
["browser_hiddenwindow_existence.js"]
["browser_panel_vsync.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
]
["browser_startup_hiddenwindow.js"]
run-if = [
"os == 'linux'",
"os == 'win'",
]
["browser_tabclose.js"]
skip-if = [
"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/contentTheme.js (content/contentTheme.js)
#ifdef XP_MACOSX
# XXX: We should exclude this one as well (bug 71895)
* content/browser/hiddenWindowMac.xhtml (content/hiddenWindowMac.xhtml)
content/browser/nonbrowser-mac.js (content/nonbrowser-mac.js)
#endif

View File

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

View File

@ -80,7 +80,6 @@ export function StartupRecorder() {
"image-loading": new Set(),
},
code: {},
extras: {},
prefStats: {},
};
this.done = new Promise(resolve => {
@ -103,9 +102,6 @@ StartupRecorder.prototype = {
}
}),
};
this.data.extras[name] = {
hiddenWindowLoaded: Services.appShell.hasHiddenWindow,
};
},
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.
*
* - <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
* the tab.
* as browser.xhtml or hiddenWindowMac.xhtml) it's what the address bar shows
* for the tab.
*
*/
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("**"):
BUG_COMPONENT = ("Core", "DOM: Core & HTML")
JAR_MANIFESTS += ["jar.mn"]
interfaces = [
"base",
"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)
def _isHiddenWindowURL(self, url):
return (
url == "resource://gre-resources/hiddenWindow.html"
or url == "chrome://browser/content/hiddenWindowMac.xhtml" # Win / Linux
) # Mac
return url == "resource://gre-resources/hiddenWindowMac.xhtml"
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",
"view-source:http://mozilla.org",
"chrome://browser/content/browser.xhtml",
"resource://gre-resources/hiddenWindow.html",
"resource://gre-resources/hiddenWindowMac.html",
"data:,Hello%2C%20World!",
"javascript:alert('hello wolrd!');",
"blob:foo",

View File

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

View File

@ -346,17 +346,12 @@ nsAppStartup::Quit(uint32_t aMode, int aExitCode, bool* aUserAllowedQuit) {
}
#ifdef XP_MACOSX
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:
if (!appShell) return NS_OK;
bool usefulHiddenWindow;
appShell->GetApplicationProvidedHiddenWindow(&usefulHiddenWindow);
nsCOMPtr<nsIAppWindow> hiddenWindow;
appShell->GetHiddenWindow(getter_AddRefs(hiddenWindow));
// If the remaining windows are useful, we won't quit:
if (!hiddenWindow || usefulHiddenWindow) {
bool hasHiddenWindow = false;
appShell->GetHasHiddenWindow(&hasHiddenWindow);
// If there's a hidden window, we won't quit:
if (hasHiddenWindow) {
return NS_OK;
}

View File

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

View File

@ -5639,25 +5639,12 @@ nsresult XREMain::XRE_mainRun() {
SaveToEnv("XRE_RESTARTED_BY_PROFILE_MANAGER=");
if (!AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) {
// Don't create the hidden window during startup on
// platforms that don't always need it.
#ifdef XP_MACOSX
bool lazyHiddenWindow = false;
#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) {
if (!BackgroundTasks::IsBackgroundTaskMode()) {
rv = appStartup->CreateHiddenWindow();
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
}
#endif
#ifdef XP_WIN
Preferences::RegisterCallbackAndCall(

View File

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

View File

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

View File

@ -58,6 +58,7 @@ interface nsIAppShellService : nsISupports
[noscript]
void createHiddenWindow();
[noscript]
void destroyHiddenWindow();
/**
@ -86,13 +87,6 @@ interface nsIAppShellService : nsISupports
*/
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
* are generally shown in the Windows taskbar, and the application
@ -112,7 +106,8 @@ interface nsIAppShellService : nsISupports
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;
};