txXMLParser.cpp (1917B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #include "txXMLParser.h" 7 8 #include "mozilla/dom/Document.h" 9 #include "nsIURI.h" 10 #include "nsNetUtil.h" 11 #include "nsSyncLoadService.h" 12 #include "txURIUtils.h" 13 #include "txXPathTreeWalker.h" 14 15 using namespace mozilla; 16 using namespace mozilla::dom; 17 18 Result<txXPathNode, nsresult> txParseDocumentFromURI(const nsAString& aHref, 19 const txXPathNode& aLoader, 20 nsAString& aErrMsg) { 21 nsCOMPtr<nsIURI> documentURI; 22 nsresult rv = NS_NewURI(getter_AddRefs(documentURI), aHref); 23 NS_ENSURE_SUCCESS(rv, Err(rv)); 24 25 Document* loaderDocument = txXPathNativeNode::getDocument(aLoader); 26 27 nsCOMPtr<nsILoadGroup> loadGroup = loaderDocument->GetDocumentLoadGroup(); 28 29 // For the system principal loaderUri will be null here, which is good 30 // since that means that chrome documents can load any uri. 31 32 // Raw pointer, we want the resulting txXPathNode to hold a reference to 33 // the document. 34 nsCOMPtr<Document> theDocument; 35 nsAutoSyncOperation sync(loaderDocument, 36 SyncOperationBehavior::eSuspendInput); 37 rv = nsSyncLoadService::LoadDocument( 38 documentURI, nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST_SYNC, 39 loaderDocument, nullptr, 40 nsILoadInfo::SEC_REQUIRE_CORS_INHERITS_SEC_CONTEXT, loadGroup, nullptr, 41 true, loaderDocument->GetReferrerPolicy(), getter_AddRefs(theDocument)); 42 43 if (NS_FAILED(rv)) { 44 aErrMsg.AppendLiteral("Document load of "); 45 aErrMsg.Append(aHref); 46 aErrMsg.AppendLiteral(" failed."); 47 return Err(rv); 48 } 49 50 return txXPathNode(theDocument); 51 }