Coverage Report

Created: 2018-09-25 14:53

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