diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /dom/xslt/xml/txXMLParser.cpp | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/xslt/xml/txXMLParser.cpp')
-rw-r--r-- | dom/xslt/xml/txXMLParser.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/dom/xslt/xml/txXMLParser.cpp b/dom/xslt/xml/txXMLParser.cpp new file mode 100644 index 0000000000..b769d6f17e --- /dev/null +++ b/dom/xslt/xml/txXMLParser.cpp @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. */ + +#include "txXMLParser.h" +#include "txURIUtils.h" +#include "txXPathTreeWalker.h" + +#include "mozilla/dom/Document.h" +#include "nsSyncLoadService.h" +#include "nsNetUtil.h" +#include "nsIURI.h" + +using namespace mozilla::dom; + +nsresult txParseDocumentFromURI(const nsAString& aHref, + const txXPathNode& aLoader, nsAString& aErrMsg, + txXPathNode** aResult) { + NS_ENSURE_ARG_POINTER(aResult); + *aResult = nullptr; + nsCOMPtr<nsIURI> documentURI; + nsresult rv = NS_NewURI(getter_AddRefs(documentURI), aHref); + NS_ENSURE_SUCCESS(rv, rv); + + Document* loaderDocument = txXPathNativeNode::getDocument(aLoader); + + nsCOMPtr<nsILoadGroup> loadGroup = loaderDocument->GetDocumentLoadGroup(); + + // For the system principal loaderUri will be null here, which is good + // since that means that chrome documents can load any uri. + + // Raw pointer, we want the resulting txXPathNode to hold a reference to + // the document. + Document* theDocument = nullptr; + nsAutoSyncOperation sync(loaderDocument, + SyncOperationBehavior::eSuspendInput); + rv = nsSyncLoadService::LoadDocument( + documentURI, nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST, + loaderDocument->NodePrincipal(), + nsILoadInfo::SEC_REQUIRE_CORS_INHERITS_SEC_CONTEXT, loadGroup, + loaderDocument->CookieJarSettings(), true, + loaderDocument->GetReferrerPolicy(), &theDocument); + + if (NS_FAILED(rv)) { + aErrMsg.AppendLiteral("Document load of "); + aErrMsg.Append(aHref); + aErrMsg.AppendLiteral(" failed."); + return NS_FAILED(rv) ? rv : NS_ERROR_FAILURE; + } + + *aResult = txXPathNativeNode::createXPathNode(theDocument); + if (!*aResult) { + NS_RELEASE(theDocument); + return NS_ERROR_FAILURE; + } + + return NS_OK; +} |