@@ -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
321311void 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
386373void 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
0 commit comments