Skip to content

Commit d774d64

Browse files
author
Sandor Molnar
committed
Revert "Bug 1973269 - Pass the URI directly to browser chrome page r=asuth,Gijs" for causing mochitest failures @ test_notification_serviceworker_openWindow.html
This reverts commit 8c1f5ef.
1 parent 4d337e1 commit d774d64

File tree

2 files changed

+30
-71
lines changed

2 files changed

+30
-71
lines changed

dom/clients/manager/ClientOpenWindowUtils.cpp

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,6 @@ static Result<Ok, nsresult> OpenNewWindow(
215215
nsOpenWindowInfo* aOpenWindowInfo) {
216216
nsresult rv;
217217

218-
// XXX(krosylight): In an ideal world we should be able to pass the nsIURI
219-
// directly. See bug 1485961.
220-
nsAutoCString uriToLoad;
221-
MOZ_TRY(aArgsValidated.uri->GetSpec(uriToLoad));
222-
223-
nsCOMPtr<nsISupportsCString> nsUriToLoad =
224-
do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID, &rv);
225-
MOZ_TRY(rv);
226-
MOZ_TRY(nsUriToLoad->SetData(uriToLoad));
227-
228218
nsCOMPtr<nsISupportsPRBool> nsFalse =
229219
do_CreateInstance(NS_SUPPORTS_PRBOOL_CONTRACTID, &rv);
230220
MOZ_TRY(rv);
@@ -237,7 +227,7 @@ static Result<Ok, nsresult> OpenNewWindow(
237227

238228
nsCOMPtr<nsIMutableArray> args = do_CreateInstance(NS_ARRAY_CONTRACTID);
239229
// https://searchfox.org/mozilla-central/rev/02d33f4bf984f65bd394bfd2d19d66569ae2cfe1/browser/base/content/browser-init.js#725-735
240-
args->AppendElement(nsUriToLoad); // 0: uriToLoad
230+
args->AppendElement(nullptr); // 0: uriToLoad
241231
args->AppendElement(nullptr); // 1: extraOptions
242232
args->AppendElement(nullptr); // 2: referrerInfo
243233
args->AppendElement(nullptr); // 3: postData
@@ -320,7 +310,7 @@ void OpenWindow(const ClientOpenWindowArgsParsed& aArgsValidated,
320310

321311
void WaitForLoad(const ClientOpenWindowArgsParsed& aArgsValidated,
322312
BrowsingContext* aBrowsingContext,
323-
ClientOpPromise::Private* aPromise, bool aShouldLoadURI) {
313+
ClientOpPromise::Private* aPromise) {
324314
MOZ_DIAGNOSTIC_ASSERT(aBrowsingContext);
325315

326316
RefPtr<ClientOpPromise::Private> promise = aPromise;
@@ -338,7 +328,7 @@ void WaitForLoad(const ClientOpenWindowArgsParsed& aArgsValidated,
338328
return;
339329
}
340330

341-
// Add a progress listener before we start the load of the requested URI
331+
// Add a progress listener before we start the load of the service worker URI
342332
RefPtr<WebProgressListener> listener = new WebProgressListener(
343333
aBrowsingContext, aArgsValidated.baseURI, do_AddRef(promise));
344334

@@ -352,27 +342,24 @@ void WaitForLoad(const ClientOpenWindowArgsParsed& aArgsValidated,
352342
return;
353343
}
354344

355-
if (aShouldLoadURI) {
356-
// Load the requested URI
357-
RefPtr<nsDocShellLoadState> loadState =
358-
new nsDocShellLoadState(aArgsValidated.uri);
359-
loadState->SetTriggeringPrincipal(aArgsValidated.principal);
360-
loadState->SetFirstParty(true);
361-
loadState->SetLoadFlags(
362-
nsIWebNavigation::LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL);
363-
loadState->SetTriggeringRemoteType(
364-
aArgsValidated.originContent
365-
? aArgsValidated.originContent->GetRemoteType()
366-
: NOT_REMOTE_TYPE);
367-
368-
rv = aBrowsingContext->LoadURI(loadState, true);
369-
if (NS_FAILED(rv)) {
370-
CopyableErrorResult result;
371-
result.ThrowInvalidStateError(
372-
"Unable to start the load of the actual URI");
373-
promise->Reject(result, __func__);
374-
return;
375-
}
345+
// Load the service worker URI
346+
RefPtr<nsDocShellLoadState> loadState =
347+
new nsDocShellLoadState(aArgsValidated.uri);
348+
loadState->SetTriggeringPrincipal(aArgsValidated.principal);
349+
loadState->SetFirstParty(true);
350+
loadState->SetLoadFlags(
351+
nsIWebNavigation::LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL);
352+
loadState->SetTriggeringRemoteType(
353+
aArgsValidated.originContent
354+
? aArgsValidated.originContent->GetRemoteType()
355+
: NOT_REMOTE_TYPE);
356+
357+
rv = aBrowsingContext->LoadURI(loadState, true);
358+
if (NS_FAILED(rv)) {
359+
CopyableErrorResult result;
360+
result.ThrowInvalidStateError("Unable to start the load of the actual URI");
361+
promise->Reject(result, __func__);
362+
return;
376363
}
377364

378365
// Hold the listener alive until the promise settles.
@@ -384,7 +371,8 @@ void WaitForLoad(const ClientOpenWindowArgsParsed& aArgsValidated,
384371

385372
#ifdef MOZ_GECKOVIEW
386373
void GeckoViewOpenWindow(const ClientOpenWindowArgsParsed& aArgsValidated,
387-
nsOpenWindowInfo* aOpenInfo, ErrorResult& aRv) {
374+
nsOpenWindowInfo* aOpenInfo, BrowsingContext** aBC,
375+
ErrorResult& aRv) {
388376
MOZ_ASSERT(aOpenInfo);
389377

390378
// passes the request to open a new window to GeckoView. Allowing the
@@ -499,13 +487,11 @@ RefPtr<ClientOpPromise> ClientOpenWindow(
499487

500488
RefPtr<BrowsingContext> bc;
501489
IgnoredErrorResult errResult;
502-
bool shouldLoadURI = true;
503490
#ifdef MOZ_GECKOVIEW
504491
// GeckoView has a delegation for service worker window.
505-
GeckoViewOpenWindow(argsValidated, openInfo, errResult);
492+
GeckoViewOpenWindow(argsValidated, openInfo, getter_AddRefs(bc), errResult);
506493
#else
507494
OpenWindow(argsValidated, openInfo, getter_AddRefs(bc), errResult);
508-
shouldLoadURI = !!bc;
509495
#endif
510496
if (NS_WARN_IF(errResult.Failed())) {
511497
promise->Reject(errResult, __func__);
@@ -514,9 +500,8 @@ RefPtr<ClientOpPromise> ClientOpenWindow(
514500

515501
browsingContextReadyPromise->Then(
516502
GetCurrentSerialEventTarget(), __func__,
517-
[argsValidated, promise,
518-
shouldLoadURI](const RefPtr<BrowsingContext>& aBC) {
519-
WaitForLoad(argsValidated, aBC, promise, shouldLoadURI);
503+
[argsValidated, promise](const RefPtr<BrowsingContext>& aBC) {
504+
WaitForLoad(argsValidated, aBC, promise);
520505
},
521506
[promise]() {
522507
// in case of failure, reject the original promise

dom/notification/test/browser/browser_openwindow_without_window.js

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,12 @@ add_setup(() => {
4646
BrowserTestUtils.concealWindow(window, { signal });
4747
});
4848

49-
let configs = [
50-
{
51-
permanentPbm: false,
52-
browserStartup: 1,
53-
},
54-
{
55-
permanentPbm: true,
56-
browserStartup: 1,
57-
},
58-
{
59-
permanentPbm: false,
60-
browserStartup: 3,
61-
},
62-
];
63-
64-
for (let { permanentPbm, browserStartup } of configs) {
49+
for (let permanentPbm of [false, true]) {
6550
add_task(async function () {
6651
info(`Test with PBM: ${permanentPbm}`);
67-
info(`Test with startup behavior: ${browserStartup}`);
6852

6953
await SpecialPowers.pushPrefEnv({
70-
set: [
71-
["browser.privatebrowsing.autostart", permanentPbm],
72-
["browser.startup.page", browserStartup],
73-
],
54+
set: [["browser.privatebrowsing.autostart", permanentPbm]],
7455
});
7556

7657
let win = await BrowserTestUtils.openNewBrowserWindow();
@@ -104,15 +85,8 @@ for (let { permanentPbm, browserStartup } of configs) {
10485

10586
registerCleanupFunction(() => SpecialPowers.removeAllServiceWorkerData());
10687

107-
// Now close the current window via BrowserCommands
108-
// (simple .close() will not trigger session store as it does not notify
109-
// browser-lastwindow-close-granted)
110-
let closedPromise = BrowserTestUtils.windowClosed(win);
111-
win.BrowserCommands.tryToCloseWindow();
112-
await closedPromise;
113-
114-
// Let session startup read the changed pref again
115-
SessionStartup.resetForTest();
88+
// Now close the current window
89+
await BrowserTestUtils.closeWindow(win);
11690

11791
let newWinPromise = BrowserTestUtils.waitForNewWindow({
11892
url: OPEN_URI,

0 commit comments

Comments
 (0)