Line data Source code
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/. */
5 :
6 : #include "txXMLParser.h"
7 : #include "txURIUtils.h"
8 : #include "txXPathTreeWalker.h"
9 :
10 : #include "nsIDocument.h"
11 : #include "nsIDOMDocument.h"
12 : #include "nsSyncLoadService.h"
13 : #include "nsNetUtil.h"
14 : #include "nsIURI.h"
15 : #include "nsIPrincipal.h"
16 :
17 : nsresult
18 0 : txParseDocumentFromURI(const nsAString& aHref,
19 : const txXPathNode& aLoader,
20 : nsAString& aErrMsg,
21 : txXPathNode** aResult)
22 : {
23 0 : NS_ENSURE_ARG_POINTER(aResult);
24 0 : *aResult = nullptr;
25 0 : nsCOMPtr<nsIURI> documentURI;
26 0 : nsresult rv = NS_NewURI(getter_AddRefs(documentURI), aHref);
27 0 : NS_ENSURE_SUCCESS(rv, rv);
28 :
29 0 : nsIDocument* loaderDocument = txXPathNativeNode::getDocument(aLoader);
30 :
31 0 : nsCOMPtr<nsILoadGroup> loadGroup = loaderDocument->GetDocumentLoadGroup();
32 :
33 : // For the system principal loaderUri will be null here, which is good
34 : // since that means that chrome documents can load any uri.
35 :
36 : // Raw pointer, we want the resulting txXPathNode to hold a reference to
37 : // the document.
38 0 : nsIDOMDocument* theDocument = nullptr;
39 0 : nsAutoSyncOperation sync(loaderDocument);
40 0 : rv = nsSyncLoadService::LoadDocument(documentURI,
41 : nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST,
42 : loaderDocument->NodePrincipal(),
43 : nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS,
44 : loadGroup, true,
45 : loaderDocument->GetReferrerPolicy(),
46 : &theDocument);
47 :
48 0 : if (NS_FAILED(rv)) {
49 0 : aErrMsg.AppendLiteral("Document load of ");
50 0 : aErrMsg.Append(aHref);
51 0 : aErrMsg.AppendLiteral(" failed.");
52 0 : return NS_FAILED(rv) ? rv : NS_ERROR_FAILURE;
53 : }
54 :
55 0 : *aResult = txXPathNativeNode::createXPathNode(theDocument);
56 0 : if (!*aResult) {
57 0 : NS_RELEASE(theDocument);
58 0 : return NS_ERROR_FAILURE;
59 : }
60 :
61 0 : return NS_OK;
62 : }
|