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