2005-11-02 07:42:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2005-11-02 07:42:04 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
2005-11-02 07:42:05 +00:00
|
|
|
* The Original Code is TransforMiiX XSLT processor code.
|
2005-11-02 07:40:03 +00:00
|
|
|
*
|
2005-11-02 07:42:04 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* The MITRE Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2005-11-02 07:42:05 +00:00
|
|
|
* Tom Kneeland <tomk@mitre.org> (Original Author)
|
2005-11-02 07:42:04 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
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"
|
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);
|
|
|
|
*aResult = nsnull;
|
|
|
|
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.
|
|
|
|
nsIDOMDocument* theDocument = nsnull;
|
2008-02-27 03:45:29 +00:00
|
|
|
rv = nsSyncLoadService::LoadDocument(documentURI,
|
|
|
|
loaderDocument->NodePrincipal(),
|
2011-10-17 14:59:28 +00:00
|
|
|
loadGroup, true, &theDocument);
|
2006-06-15 20:30:44 +00:00
|
|
|
|
2006-05-05 11:48:07 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2005-11-02 07:40:03 +00:00
|
|
|
aErrMsg.Append(NS_LITERAL_STRING("Document load of ") +
|
|
|
|
aHref + NS_LITERAL_STRING(" 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;
|
|
|
|
}
|