Bug 1974407 - nsSyncLoadService::LoadDocument should use loadingDocument. r=smaug a=pascalc

Differential Revision: https://phabricator.services.mozilla.com/D255478
This commit is contained in:
Tom Schuster
2025-07-07 08:04:00 +00:00
committed by pchevrel@mozilla.com
parent 8e03515d6c
commit 7611dc2923
5 changed files with 36 additions and 29 deletions

View File

@@ -280,16 +280,27 @@ nsSyncLoader::GetInterface(const nsIID& aIID, void** aResult) {
/* static */
nsresult nsSyncLoadService::LoadDocument(
nsIURI* aURI, nsContentPolicyType aContentPolicyType,
nsIURI* aURI, nsContentPolicyType aContentPolicyType, Document* aLoaderDoc,
nsIPrincipal* aLoaderPrincipal, nsSecurityFlags aSecurityFlags,
nsILoadGroup* aLoadGroup, nsICookieJarSettings* aCookieJarSettings,
bool aForceToXML, ReferrerPolicy aReferrerPolicy, Document** aResult) {
MOZ_ASSERT(!!aLoaderPrincipal != !!aLoaderDoc);
nsCOMPtr<nsIChannel> channel;
nsresult rv =
NS_NewChannel(getter_AddRefs(channel), aURI, aLoaderPrincipal,
aSecurityFlags, aContentPolicyType, aCookieJarSettings,
nullptr, // PerformanceStorage
aLoadGroup);
nsresult rv;
if (aLoaderDoc) {
MOZ_ASSERT(!aCookieJarSettings);
rv = NS_NewChannel(getter_AddRefs(channel), aURI, aLoaderDoc,
aSecurityFlags, aContentPolicyType,
nullptr, // PerformanceStorage
aLoadGroup);
} else {
rv = NS_NewChannel(getter_AddRefs(channel), aURI, aLoaderPrincipal,
aSecurityFlags, aContentPolicyType, aCookieJarSettings,
nullptr, // PerformanceStorage
aLoadGroup);
}
NS_ENSURE_SUCCESS(rv, rv);
if (!aForceToXML) {

View File

@@ -48,9 +48,10 @@ class nsSyncLoadService {
*/
static nsresult LoadDocument(
nsIURI* aURI, nsContentPolicyType aContentPolicyType,
nsIPrincipal* aLoaderPrincipal, nsSecurityFlags aSecurityFlags,
nsILoadGroup* aLoadGroup, nsICookieJarSettings* aCookieJarSettings,
bool aForceToXML, mozilla::dom::ReferrerPolicy aReferrerPolicy,
mozilla::dom::Document* aLoaderDoc, nsIPrincipal* aLoaderPrincipal,
nsSecurityFlags aSecurityFlags, nsILoadGroup* aLoadGroup,
nsICookieJarSettings* aCookieJarSettings, bool aForceToXML,
mozilla::dom::ReferrerPolicy aReferrerPolicy,
mozilla::dom::Document** aResult);
/**

View File

@@ -65,7 +65,8 @@ nsresult nsXMLPrettyPrinter::PrettyPrint(Document* aDocument,
nsCOMPtr<Document> xslDocument;
rv = nsSyncLoadService::LoadDocument(
xslUri, nsIContentPolicy::TYPE_XSLT, nsContentUtils::GetSystemPrincipal(),
xslUri, nsIContentPolicy::TYPE_XSLT, nullptr,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL, nullptr,
aDocument->CookieJarSettings(), true, ReferrerPolicy::_empty,
getter_AddRefs(xslDocument));

View File

@@ -36,10 +36,9 @@ Result<txXPathNode, nsresult> txParseDocumentFromURI(const nsAString& aHref,
SyncOperationBehavior::eSuspendInput);
rv = nsSyncLoadService::LoadDocument(
documentURI, nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST_SYNC,
loaderDocument->NodePrincipal(),
nsILoadInfo::SEC_REQUIRE_CORS_INHERITS_SEC_CONTEXT, loadGroup,
loaderDocument->CookieJarSettings(), true,
loaderDocument->GetReferrerPolicy(), getter_AddRefs(theDocument));
loaderDocument, nullptr,
nsILoadInfo::SEC_REQUIRE_CORS_INHERITS_SEC_CONTEXT, loadGroup, nullptr,
true, loaderDocument->GetReferrerPolicy(), getter_AddRefs(theDocument));
if (NS_FAILED(rv)) {
aErrMsg.AppendLiteral("Document load of ");

View File

@@ -539,29 +539,24 @@ nsresult txSyncCompileObserver::loadURI(const nsAString& aUri,
nsresult rv = NS_NewURI(getter_AddRefs(uri), aUri);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIURI> referrerUri;
rv = NS_NewURI(getter_AddRefs(referrerUri), aReferrerUri);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIPrincipal> referrerPrincipal =
BasePrincipal::CreateContentPrincipal(referrerUri, OriginAttributes());
NS_ENSURE_TRUE(referrerPrincipal, NS_ERROR_FAILURE);
nsCOMPtr<nsPIDOMWindowInner> window =
do_QueryInterface(mProcessor->GetParentObject());
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
nsCOMPtr<Document> loaderDoc = window->GetExtantDoc();
NS_ENSURE_TRUE(loaderDoc, NS_ERROR_FAILURE);
// This is probably called by js, a loadGroup for the channel doesn't
// make sense.
nsCOMPtr<nsINode> source;
if (mProcessor) {
source = mProcessor->GetSourceContentModel();
}
nsCOMPtr<nsINode> source = mProcessor->GetSourceContentModel();
dom::nsAutoSyncOperation sync(source ? source->OwnerDoc() : nullptr,
dom::SyncOperationBehavior::eSuspendInput);
nsCOMPtr<Document> document;
rv = nsSyncLoadService::LoadDocument(
uri, nsIContentPolicy::TYPE_XSLT, referrerPrincipal,
nsILoadInfo::SEC_REQUIRE_CORS_INHERITS_SEC_CONTEXT, nullptr,
source ? source->OwnerDoc()->CookieJarSettings() : nullptr, false,
aReferrerPolicy, getter_AddRefs(document));
uri, nsIContentPolicy::TYPE_XSLT, loaderDoc,
/* aLoaderPrincipal */ nullptr,
nsILoadInfo::SEC_REQUIRE_CORS_INHERITS_SEC_CONTEXT, nullptr, nullptr,
false, aReferrerPolicy, getter_AddRefs(document));
NS_ENSURE_SUCCESS(rv, rv);
rv = handleNode(document, aCompiler);