2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "txXMLParser.h"
|
|
|
|
#include "txURIUtils.h"
|
|
|
|
#include "txXPathTreeWalker.h"
|
|
|
|
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsSyncLoadService.h"
|
|
|
|
#include "nsNetUtil.h"
|
2007-09-27 15:05:07 -07:00
|
|
|
#include "nsIPrincipal.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
txParseDocumentFromURI(const nsAString& aHref, const txXPathNode& aLoader,
|
|
|
|
nsAString& aErrMsg, txXPathNode** aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
2012-07-30 07:20:58 -07:00
|
|
|
*aResult = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIURI> documentURI;
|
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(documentURI), aHref);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsIDocument* loaderDocument = txXPathNativeNode::getDocument(aLoader);
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup = loaderDocument->GetDocumentLoadGroup();
|
2007-09-27 15:05:07 -07:00
|
|
|
|
|
|
|
// For the system principal loaderUri will be null here, which is good
|
|
|
|
// since that means that chrome documents can load any uri.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Raw pointer, we want the resulting txXPathNode to hold a reference to
|
|
|
|
// the document.
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIDOMDocument* theDocument = nullptr;
|
2012-03-31 09:30:13 -07:00
|
|
|
nsAutoSyncOperation sync(loaderDocument);
|
2008-02-26 19:45:29 -08:00
|
|
|
rv = nsSyncLoadService::LoadDocument(documentURI,
|
|
|
|
loaderDocument->NodePrincipal(),
|
2011-10-17 07:59:28 -07:00
|
|
|
loadGroup, true, &theDocument);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aErrMsg.Append(NS_LITERAL_STRING("Document load of ") +
|
|
|
|
aHref + NS_LITERAL_STRING(" failed."));
|
|
|
|
return NS_FAILED(rv) ? rv : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = txXPathNativeNode::createXPathNode(theDocument);
|
|
|
|
if (!*aResult) {
|
|
|
|
NS_RELEASE(theDocument);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|