diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/xslt/xml/txXMLParser.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/xslt/xml/txXMLParser.cpp')
-rw-r--r-- | dom/xslt/xml/txXMLParser.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/dom/xslt/xml/txXMLParser.cpp b/dom/xslt/xml/txXMLParser.cpp new file mode 100644 index 000000000..0cf281f2c --- /dev/null +++ b/dom/xslt/xml/txXMLParser.cpp @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* 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 "nsIDocument.h" +#include "nsIDOMDocument.h" +#include "nsSyncLoadService.h" +#include "nsNetUtil.h" +#include "nsIURI.h" +#include "nsIPrincipal.h" + +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); + + nsIDocument* 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. + nsIDOMDocument* theDocument = nullptr; + nsAutoSyncOperation sync(loaderDocument); + rv = nsSyncLoadService::LoadDocument(documentURI, + nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST, + loaderDocument->NodePrincipal(), + nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS, + loadGroup, 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; +} |