2005-11-02 07:42:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
2005-11-02 07:40:03 +00:00
|
|
|
|
|
|
|
#include "txXMLParser.h"
|
|
|
|
#include "txURIUtils.h"
|
2005-11-02 07:41:43 +00:00
|
|
|
#include "txXPathTreeWalker.h"
|
|
|
|
|
2005-11-02 07:40:03 +00:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
2006-06-15 20:30:44 +00:00
|
|
|
#include "nsSyncLoadService.h"
|
2005-11-02 07:40:03 +00:00
|
|
|
#include "nsNetUtil.h"
|
2015-07-07 02:17:00 +00:00
|
|
|
#include "nsIURI.h"
|
2007-09-27 22:05:07 +00:00
|
|
|
#include "nsIPrincipal.h"
|
2005-11-02 07:40:03 +00:00
|
|
|
|
|
|
|
nsresult
|
2006-03-24 00:09:50 +00:00
|
|
|
txParseDocumentFromURI(const nsAString& aHref, const txXPathNode& aLoader,
|
|
|
|
nsAString& aErrMsg, txXPathNode** aResult)
|
2005-11-02 07:40:03 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
2012-07-30 14:20:58 +00:00
|
|
|
*aResult = nullptr;
|
2005-11-02 07:40:03 +00:00
|
|
|
nsCOMPtr<nsIURI> documentURI;
|
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(documentURI), aHref);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-11-02 07:41:43 +00:00
|
|
|
nsIDocument* loaderDocument = txXPathNativeNode::getDocument(aLoader);
|
|
|
|
|
2005-11-02 07:41:29 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup = loaderDocument->GetDocumentLoadGroup();
|
2007-09-27 22:05:07 +00:00
|
|
|
|
|
|
|
// For the system principal loaderUri will be null here, which is good
|
|
|
|
// since that means that chrome documents can load any uri.
|
2005-11-02 07:40:03 +00:00
|
|
|
|
2005-11-02 07:41:43 +00:00
|
|
|
// Raw pointer, we want the resulting txXPathNode to hold a reference to
|
|
|
|
// the document.
|
2012-07-30 14:20:58 +00:00
|
|
|
nsIDOMDocument* theDocument = nullptr;
|
2012-03-31 16:30:13 +00:00
|
|
|
nsAutoSyncOperation sync(loaderDocument);
|
2008-02-27 03:45:29 +00:00
|
|
|
rv = nsSyncLoadService::LoadDocument(documentURI,
|
|
|
|
loaderDocument->NodePrincipal(),
|
2014-11-18 13:47:20 +00:00
|
|
|
loadGroup, true,
|
|
|
|
loaderDocument->GetReferrerPolicy(),
|
|
|
|
&theDocument);
|
2006-06-15 20:30:44 +00:00
|
|
|
|
2006-05-05 11:48:07 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-05-22 03:48:50 +00:00
|
|
|
aErrMsg.AppendLiteral("Document load of ");
|
|
|
|
aErrMsg.Append(aHref);
|
|
|
|
aErrMsg.AppendLiteral(" failed.");
|
2005-11-02 07:42:43 +00:00
|
|
|
return NS_FAILED(rv) ? rv : NS_ERROR_FAILURE;
|
2005-11-02 07:40:03 +00:00
|
|
|
}
|
|
|
|
|
2005-11-02 07:41:43 +00:00
|
|
|
*aResult = txXPathNativeNode::createXPathNode(theDocument);
|
2005-11-02 07:40:03 +00:00
|
|
|
if (!*aResult) {
|
2005-11-02 07:41:43 +00:00
|
|
|
NS_RELEASE(theDocument);
|
2005-11-02 07:40:03 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2005-11-02 07:41:38 +00:00
|
|
|
|
2005-11-02 07:40:03 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|