Bumping manifests a=b2g-bump
[gecko.git] / dom / xslt / xml / txXMLParser.cpp
blob72b59f8a578fac8c76d1e7c728688de10d44ce6d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/. */
6 #include "txXMLParser.h"
7 #include "txURIUtils.h"
8 #include "txXPathTreeWalker.h"
10 #include "nsIDocument.h"
11 #include "nsIDOMDocument.h"
12 #include "nsSyncLoadService.h"
13 #include "nsNetUtil.h"
14 #include "nsIPrincipal.h"
16 nsresult
17 txParseDocumentFromURI(const nsAString& aHref, const txXPathNode& aLoader,
18 nsAString& aErrMsg, txXPathNode** aResult)
20 NS_ENSURE_ARG_POINTER(aResult);
21 *aResult = nullptr;
22 nsCOMPtr<nsIURI> documentURI;
23 nsresult rv = NS_NewURI(getter_AddRefs(documentURI), aHref);
24 NS_ENSURE_SUCCESS(rv, rv);
26 nsIDocument* loaderDocument = txXPathNativeNode::getDocument(aLoader);
28 nsCOMPtr<nsILoadGroup> loadGroup = loaderDocument->GetDocumentLoadGroup();
30 // For the system principal loaderUri will be null here, which is good
31 // since that means that chrome documents can load any uri.
33 // Raw pointer, we want the resulting txXPathNode to hold a reference to
34 // the document.
35 nsIDOMDocument* theDocument = nullptr;
36 nsAutoSyncOperation sync(loaderDocument);
37 rv = nsSyncLoadService::LoadDocument(documentURI,
38 loaderDocument->NodePrincipal(),
39 loadGroup, true, &theDocument);
41 if (NS_FAILED(rv)) {
42 aErrMsg.AppendLiteral("Document load of ");
43 aErrMsg.Append(aHref);
44 aErrMsg.AppendLiteral(" failed.");
45 return NS_FAILED(rv) ? rv : NS_ERROR_FAILURE;
48 *aResult = txXPathNativeNode::createXPathNode(theDocument);
49 if (!*aResult) {
50 NS_RELEASE(theDocument);
51 return NS_ERROR_FAILURE;
54 return NS_OK;