dom/xslt/xml/txXMLParser.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/xslt/xml/txXMLParser.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,54 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "txXMLParser.h"
    1.10 +#include "txURIUtils.h"
    1.11 +#include "txXPathTreeWalker.h"
    1.12 +
    1.13 +#include "nsIDocument.h"
    1.14 +#include "nsIDOMDocument.h"
    1.15 +#include "nsSyncLoadService.h"
    1.16 +#include "nsNetUtil.h"
    1.17 +#include "nsIPrincipal.h"
    1.18 +
    1.19 +nsresult
    1.20 +txParseDocumentFromURI(const nsAString& aHref, const txXPathNode& aLoader,
    1.21 +                       nsAString& aErrMsg, txXPathNode** aResult)
    1.22 +{
    1.23 +    NS_ENSURE_ARG_POINTER(aResult);
    1.24 +    *aResult = nullptr;
    1.25 +    nsCOMPtr<nsIURI> documentURI;
    1.26 +    nsresult rv = NS_NewURI(getter_AddRefs(documentURI), aHref);
    1.27 +    NS_ENSURE_SUCCESS(rv, rv);
    1.28 +
    1.29 +    nsIDocument* loaderDocument = txXPathNativeNode::getDocument(aLoader);
    1.30 +
    1.31 +    nsCOMPtr<nsILoadGroup> loadGroup = loaderDocument->GetDocumentLoadGroup();
    1.32 +
    1.33 +    // For the system principal loaderUri will be null here, which is good
    1.34 +    // since that means that chrome documents can load any uri.
    1.35 +
    1.36 +    // Raw pointer, we want the resulting txXPathNode to hold a reference to
    1.37 +    // the document.
    1.38 +    nsIDOMDocument* theDocument = nullptr;
    1.39 +    nsAutoSyncOperation sync(loaderDocument);
    1.40 +    rv = nsSyncLoadService::LoadDocument(documentURI,
    1.41 +                                         loaderDocument->NodePrincipal(),
    1.42 +                                         loadGroup, true, &theDocument);
    1.43 +
    1.44 +    if (NS_FAILED(rv)) {
    1.45 +        aErrMsg.Append(NS_LITERAL_STRING("Document load of ") + 
    1.46 +                       aHref + NS_LITERAL_STRING(" failed."));
    1.47 +        return NS_FAILED(rv) ? rv : NS_ERROR_FAILURE;
    1.48 +    }
    1.49 +
    1.50 +    *aResult = txXPathNativeNode::createXPathNode(theDocument);
    1.51 +    if (!*aResult) {
    1.52 +        NS_RELEASE(theDocument);
    1.53 +        return NS_ERROR_FAILURE;
    1.54 +    }
    1.55 +
    1.56 +    return NS_OK;
    1.57 +}

mercurial