From 12faf49780b2e2247d49049d604f506c201afd5a Mon Sep 17 00:00:00 2001 From: Dianna Smith Date: Tue, 10 Sep 2024 22:18:04 -0400 Subject: [PATCH] Backed out changeset e29230160e7b (bug 1753352) for causing wpt failures, a=backout --- caps/ContentPrincipal.cpp | 2 +- docshell/base/CanonicalBrowsingContext.cpp | 2 +- docshell/base/nsDocShell.cpp | 2 +- dom/base/nsContentUtils.cpp | 3 +-- dom/base/nsGlobalWindowInner.cpp | 7 ++++-- dom/clients/api/Clients.cpp | 5 +--- dom/clients/manager/ClientNavigateOpChild.cpp | 2 +- dom/html/nsHTMLDocument.cpp | 8 +++++-- netwerk/base/nsNetUtil.cpp | 15 ------------ netwerk/base/nsNetUtil.h | 6 ----- parser/htmlparser/nsParser.h | 2 -- ...eshow-events-iframe-contentWindow.html.ini | 24 +++++++++---------- .../load-pageshow-events-window-open.html.ini | 12 ++++++---- 13 files changed, 37 insertions(+), 53 deletions(-) diff --git a/caps/ContentPrincipal.cpp b/caps/ContentPrincipal.cpp index d6208c0b6c7d..5aeecaf2bd42 100644 --- a/caps/ContentPrincipal.cpp +++ b/caps/ContentPrincipal.cpp @@ -97,7 +97,7 @@ nsresult ContentPrincipal::GenerateOriginNoSuffixFromURI( return NS_ERROR_FAILURE; } - MOZ_ASSERT(!NS_IsAboutBlankAllowQueryAndFragment(origin), + MOZ_ASSERT(!NS_IsAboutBlank(origin), "The inner URI for about:blank must be moz-safe-about:blank"); // Handle non-strict file:// uris. diff --git a/docshell/base/CanonicalBrowsingContext.cpp b/docshell/base/CanonicalBrowsingContext.cpp index ec9ec72f3209..d4aa89be8526 100644 --- a/docshell/base/CanonicalBrowsingContext.cpp +++ b/docshell/base/CanonicalBrowsingContext.cpp @@ -2804,7 +2804,7 @@ bool CanonicalBrowsingContext::AllowedInBFCache( nsCOMPtr currentURI = wgp->GetDocumentURI(); // Exempt about:* pages from bfcache, with the exception of about:blank if (currentURI->SchemeIs("about") && - !NS_IsAboutBlankAllowQueryAndFragment(currentURI)) { + !currentURI->GetSpecOrDefault().EqualsLiteral("about:blank")) { bfcacheCombo |= BFCacheStatus::ABOUT_PAGE; MOZ_LOG(gSHIPBFCacheLog, LogLevel::Debug, (" * about:* page")); } diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 0bfd0c5951f5..d8226fa159b0 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -10164,7 +10164,7 @@ nsIPrincipal* nsDocShell::GetInheritedPrincipal( bool nsDocShell::IsAboutBlankLoadOntoInitialAboutBlank( nsIURI* aURI, bool aInheritPrincipal, nsIPrincipal* aPrincipalToInherit) { - return NS_IsAboutBlankAllowQueryAndFragment(aURI) && aInheritPrincipal && + return NS_IsAboutBlank(aURI) && aInheritPrincipal && (aPrincipalToInherit == GetInheritedPrincipal(false)) && (!mContentViewer || !mContentViewer->GetDocument() || mContentViewer->GetDocument()->IsInitialDocument()); diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index daa6c0f8c1de..21519d91e6f0 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -7282,8 +7282,7 @@ bool nsContentUtils::ChannelShouldInheritPrincipal( // we're checking for things that will use the owner. inherit = (NS_SUCCEEDED(URIInheritsSecurityContext(aURI, &uriInherits)) && - (uriInherits || (aInheritForAboutBlank && - NS_IsAboutBlankAllowQueryAndFragment(aURI)))) || + (uriInherits || (aInheritForAboutBlank && NS_IsAboutBlank(aURI)))) || // // file: uri special-casing // diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index 408487416a33..cfab7954e1aa 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -1848,9 +1848,12 @@ nsresult nsGlobalWindowInner::EnsureClientSource() { bool ignoreLoadInfo = false; + // Note, this is mostly copied from NS_IsAboutBlank(). Its duplicated + // here so we can efficiently check about:srcdoc as well. if (uri->SchemeIs("about")) { - ignoreLoadInfo = - NS_IsAboutBlankAllowQueryAndFragment(uri) || NS_IsAboutSrcdoc(uri); + nsCString spec = uri->GetSpecOrDefault(); + ignoreLoadInfo = spec.EqualsLiteral("about:blank") || + spec.EqualsLiteral("about:srcdoc"); } else { // Its not an about: URL, so now check for our other URL types. ignoreLoadInfo = uri->SchemeIs("data") || uri->SchemeIs("blob"); diff --git a/dom/clients/api/Clients.cpp b/dom/clients/api/Clients.cpp index 7250efc4809b..6dd88953b3ab 100644 --- a/dom/clients/api/Clients.cpp +++ b/dom/clients/api/Clients.cpp @@ -21,7 +21,6 @@ #include "mozilla/StorageAccess.h" #include "nsIGlobalObject.h" #include "nsString.h" -#include "nsReadableUtils.h" namespace mozilla::dom { @@ -215,9 +214,7 @@ already_AddRefed Clients::OpenWindow(const nsAString& aURL, return outerPromise.forget(); } - if (aURL.EqualsLiteral(u"about:blank") || - StringBeginsWith(aURL, u"about:blank?"_ns) || - StringBeginsWith(aURL, u"about:blank#"_ns)) { + if (aURL.EqualsLiteral("about:blank")) { CopyableErrorResult rv; rv.ThrowTypeError( "Passing \"about:blank\" to Clients.openWindow is not allowed"); diff --git a/dom/clients/manager/ClientNavigateOpChild.cpp b/dom/clients/manager/ClientNavigateOpChild.cpp index bd0b37c3c7bd..b1fd5fb36f20 100644 --- a/dom/clients/manager/ClientNavigateOpChild.cpp +++ b/dom/clients/manager/ClientNavigateOpChild.cpp @@ -224,7 +224,7 @@ RefPtr ClientNavigateOpChild::DoNavigate( return ClientOpPromise::CreateAndReject(result, __func__); } - if (NS_IsAboutBlankAllowQueryAndFragment(url)) { + if (url->GetSpecOrDefault().EqualsLiteral("about:blank")) { CopyableErrorResult result; result.ThrowTypeError("Navigation to \"about:blank\" is not allowed"); return ClientOpPromise::CreateAndReject(result, __func__); diff --git a/dom/html/nsHTMLDocument.cpp b/dom/html/nsHTMLDocument.cpp index 9ab2408bc4c9..747ab0b82197 100644 --- a/dom/html/nsHTMLDocument.cpp +++ b/dom/html/nsHTMLDocument.cpp @@ -338,8 +338,12 @@ nsresult nsHTMLDocument::StartDocumentLoad( // mDocumentURI hasn't been set, yet, so get the URI from the channel nsCOMPtr uri; aChannel->GetOriginalURI(getter_AddRefs(uri)); - if (NS_IsAboutBlankAllowQueryAndFragment(uri)) { - loadAsHtml5 = false; + // Adapted from nsDocShell: + // GetSpec can be expensive for some URIs, so check the scheme first. + if (uri && uri->SchemeIs("about")) { + if (uri->GetSpecOrDefault().EqualsLiteral("about:blank")) { + loadAsHtml5 = false; + } } } diff --git a/netwerk/base/nsNetUtil.cpp b/netwerk/base/nsNetUtil.cpp index 55ba54d5797e..897656acbb52 100644 --- a/netwerk/base/nsNetUtil.cpp +++ b/netwerk/base/nsNetUtil.cpp @@ -23,7 +23,6 @@ #include "mozilla/StoragePrincipalHelper.h" #include "mozilla/TaskQueue.h" #include "mozilla/Telemetry.h" -#include "nsAboutProtocolUtils.h" #include "nsBufferedStreams.h" #include "nsCategoryCache.h" #include "nsComponentManagerUtils.h" @@ -2762,20 +2761,6 @@ bool NS_IsAboutBlank(nsIURI* uri) { return spec.EqualsLiteral("about:blank"); } -bool NS_IsAboutBlankAllowQueryAndFragment(nsIURI* uri) { - // GetSpec can be expensive for some URIs, so check the scheme first. - if (!uri->SchemeIs("about")) { - return false; - } - - nsAutoCString name; - if (NS_FAILED(NS_GetAboutModuleName(uri, name))) { - return false; - } - - return name.EqualsLiteral("blank"); -} - bool NS_IsAboutSrcdoc(nsIURI* uri) { // GetSpec can be expensive for some URIs, so check the scheme first. if (!uri->SchemeIs("about")) { diff --git a/netwerk/base/nsNetUtil.h b/netwerk/base/nsNetUtil.h index 681fcc46f936..cc036fd69768 100644 --- a/netwerk/base/nsNetUtil.h +++ b/netwerk/base/nsNetUtil.h @@ -857,12 +857,6 @@ void net_EnsurePSMInit(); */ bool NS_IsAboutBlank(nsIURI* uri); -/** - * Test whether a URI is "about:blank", possibly with fragment or query. |uri| - * must not be null - */ -bool NS_IsAboutBlankAllowQueryAndFragment(nsIURI* uri); - /** * Test whether a URI is "about:srcdoc". |uri| must not be null */ diff --git a/parser/htmlparser/nsParser.h b/parser/htmlparser/nsParser.h index 40edb3dc802f..95782e954be9 100644 --- a/parser/htmlparser/nsParser.h +++ b/parser/htmlparser/nsParser.h @@ -239,8 +239,6 @@ class nsParser final : public nsIParser, void HandleParserContinueEvent(class nsParserContinueEvent*); void Reset() { - MOZ_ASSERT(!mIsAboutBlank, - "Only the XML fragment parsing case is supposed to call this."); Cleanup(); mUnusedInput.Truncate(); Initialize(); diff --git a/testing/web-platform/meta/html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/load-pageshow-events-iframe-contentWindow.html.ini b/testing/web-platform/meta/html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/load-pageshow-events-iframe-contentWindow.html.ini index 525f3b49b87f..c514ffc0ea07 100644 --- a/testing/web-platform/meta/html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/load-pageshow-events-iframe-contentWindow.html.ini +++ b/testing/web-platform/meta/html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/load-pageshow-events-iframe-contentWindow.html.ini @@ -2,19 +2,19 @@ expected: if (os == "android") and fission: [OK, TIMEOUT] [load & pageshow event do not fire on contentWindow of