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.
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 "txURIUtils.h" |
michael@0 | 7 | #include "nsNetUtil.h" |
michael@0 | 8 | #include "nsIDocument.h" |
michael@0 | 9 | #include "nsIPrincipal.h" |
michael@0 | 10 | |
michael@0 | 11 | /** |
michael@0 | 12 | * URIUtils |
michael@0 | 13 | * A set of utilities for handling URIs |
michael@0 | 14 | **/ |
michael@0 | 15 | |
michael@0 | 16 | /** |
michael@0 | 17 | * Resolves the given href argument, using the given documentBase |
michael@0 | 18 | * if necessary. |
michael@0 | 19 | * The new resolved href will be appended to the given dest String |
michael@0 | 20 | **/ |
michael@0 | 21 | void URIUtils::resolveHref(const nsAString& href, const nsAString& base, |
michael@0 | 22 | nsAString& dest) { |
michael@0 | 23 | if (base.IsEmpty()) { |
michael@0 | 24 | dest.Append(href); |
michael@0 | 25 | return; |
michael@0 | 26 | } |
michael@0 | 27 | if (href.IsEmpty()) { |
michael@0 | 28 | dest.Append(base); |
michael@0 | 29 | return; |
michael@0 | 30 | } |
michael@0 | 31 | nsCOMPtr<nsIURI> pURL; |
michael@0 | 32 | nsAutoString resultHref; |
michael@0 | 33 | nsresult result = NS_NewURI(getter_AddRefs(pURL), base); |
michael@0 | 34 | if (NS_SUCCEEDED(result)) { |
michael@0 | 35 | NS_MakeAbsoluteURI(resultHref, href, pURL); |
michael@0 | 36 | dest.Append(resultHref); |
michael@0 | 37 | } |
michael@0 | 38 | } //-- resolveHref |
michael@0 | 39 | |
michael@0 | 40 | // static |
michael@0 | 41 | void |
michael@0 | 42 | URIUtils::ResetWithSource(nsIDocument *aNewDoc, nsIDOMNode *aSourceNode) |
michael@0 | 43 | { |
michael@0 | 44 | nsCOMPtr<nsINode> node = do_QueryInterface(aSourceNode); |
michael@0 | 45 | if (!node) { |
michael@0 | 46 | // XXXbz passing nullptr as the first arg to Reset is illegal |
michael@0 | 47 | aNewDoc->Reset(nullptr, nullptr); |
michael@0 | 48 | return; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | nsCOMPtr<nsIDocument> sourceDoc = node->OwnerDoc(); |
michael@0 | 52 | nsIPrincipal* sourcePrincipal = sourceDoc->NodePrincipal(); |
michael@0 | 53 | |
michael@0 | 54 | // Copy the channel and loadgroup from the source document. |
michael@0 | 55 | nsCOMPtr<nsILoadGroup> loadGroup = sourceDoc->GetDocumentLoadGroup(); |
michael@0 | 56 | nsCOMPtr<nsIChannel> channel = sourceDoc->GetChannel(); |
michael@0 | 57 | if (!channel) { |
michael@0 | 58 | // Need to synthesize one |
michael@0 | 59 | if (NS_FAILED(NS_NewChannel(getter_AddRefs(channel), |
michael@0 | 60 | sourceDoc->GetDocumentURI(), |
michael@0 | 61 | nullptr, |
michael@0 | 62 | loadGroup))) { |
michael@0 | 63 | return; |
michael@0 | 64 | } |
michael@0 | 65 | channel->SetOwner(sourcePrincipal); |
michael@0 | 66 | } |
michael@0 | 67 | aNewDoc->Reset(channel, loadGroup); |
michael@0 | 68 | aNewDoc->SetPrincipal(sourcePrincipal); |
michael@0 | 69 | aNewDoc->SetBaseURI(sourceDoc->GetDocBaseURI()); |
michael@0 | 70 | |
michael@0 | 71 | // Copy charset |
michael@0 | 72 | aNewDoc->SetDocumentCharacterSetSource( |
michael@0 | 73 | sourceDoc->GetDocumentCharacterSetSource()); |
michael@0 | 74 | aNewDoc->SetDocumentCharacterSet(sourceDoc->GetDocumentCharacterSet()); |
michael@0 | 75 | } |