dom/xslt/xml/txXMLParser.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "txXMLParser.h"
michael@0 7 #include "txURIUtils.h"
michael@0 8 #include "txXPathTreeWalker.h"
michael@0 9
michael@0 10 #include "nsIDocument.h"
michael@0 11 #include "nsIDOMDocument.h"
michael@0 12 #include "nsSyncLoadService.h"
michael@0 13 #include "nsNetUtil.h"
michael@0 14 #include "nsIPrincipal.h"
michael@0 15
michael@0 16 nsresult
michael@0 17 txParseDocumentFromURI(const nsAString& aHref, const txXPathNode& aLoader,
michael@0 18 nsAString& aErrMsg, txXPathNode** aResult)
michael@0 19 {
michael@0 20 NS_ENSURE_ARG_POINTER(aResult);
michael@0 21 *aResult = nullptr;
michael@0 22 nsCOMPtr<nsIURI> documentURI;
michael@0 23 nsresult rv = NS_NewURI(getter_AddRefs(documentURI), aHref);
michael@0 24 NS_ENSURE_SUCCESS(rv, rv);
michael@0 25
michael@0 26 nsIDocument* loaderDocument = txXPathNativeNode::getDocument(aLoader);
michael@0 27
michael@0 28 nsCOMPtr<nsILoadGroup> loadGroup = loaderDocument->GetDocumentLoadGroup();
michael@0 29
michael@0 30 // For the system principal loaderUri will be null here, which is good
michael@0 31 // since that means that chrome documents can load any uri.
michael@0 32
michael@0 33 // Raw pointer, we want the resulting txXPathNode to hold a reference to
michael@0 34 // the document.
michael@0 35 nsIDOMDocument* theDocument = nullptr;
michael@0 36 nsAutoSyncOperation sync(loaderDocument);
michael@0 37 rv = nsSyncLoadService::LoadDocument(documentURI,
michael@0 38 loaderDocument->NodePrincipal(),
michael@0 39 loadGroup, true, &theDocument);
michael@0 40
michael@0 41 if (NS_FAILED(rv)) {
michael@0 42 aErrMsg.Append(NS_LITERAL_STRING("Document load of ") +
michael@0 43 aHref + NS_LITERAL_STRING(" failed."));
michael@0 44 return NS_FAILED(rv) ? rv : NS_ERROR_FAILURE;
michael@0 45 }
michael@0 46
michael@0 47 *aResult = txXPathNativeNode::createXPathNode(theDocument);
michael@0 48 if (!*aResult) {
michael@0 49 NS_RELEASE(theDocument);
michael@0 50 return NS_ERROR_FAILURE;
michael@0 51 }
michael@0 52
michael@0 53 return NS_OK;
michael@0 54 }

mercurial