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: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
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 "mozilla/AppData.h" |
michael@0 | 7 | #include "nsXULAppAPI.h" |
michael@0 | 8 | #include "nsINIParser.h" |
michael@0 | 9 | #include "nsIFile.h" |
michael@0 | 10 | #include "nsCRTGlue.h" |
michael@0 | 11 | #include "nsAutoPtr.h" |
michael@0 | 12 | |
michael@0 | 13 | namespace mozilla { |
michael@0 | 14 | |
michael@0 | 15 | void |
michael@0 | 16 | SetAllocatedString(const char *&str, const char *newvalue) |
michael@0 | 17 | { |
michael@0 | 18 | NS_Free(const_cast<char*>(str)); |
michael@0 | 19 | if (newvalue) { |
michael@0 | 20 | str = NS_strdup(newvalue); |
michael@0 | 21 | } |
michael@0 | 22 | else { |
michael@0 | 23 | str = nullptr; |
michael@0 | 24 | } |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | void |
michael@0 | 28 | SetAllocatedString(const char *&str, const nsACString &newvalue) |
michael@0 | 29 | { |
michael@0 | 30 | NS_Free(const_cast<char*>(str)); |
michael@0 | 31 | if (newvalue.IsEmpty()) { |
michael@0 | 32 | str = nullptr; |
michael@0 | 33 | } |
michael@0 | 34 | else { |
michael@0 | 35 | str = ToNewCString(newvalue); |
michael@0 | 36 | } |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | ScopedAppData::ScopedAppData(const nsXREAppData* aAppData) |
michael@0 | 40 | { |
michael@0 | 41 | Zero(); |
michael@0 | 42 | |
michael@0 | 43 | this->size = aAppData->size; |
michael@0 | 44 | |
michael@0 | 45 | SetAllocatedString(this->vendor, aAppData->vendor); |
michael@0 | 46 | SetAllocatedString(this->name, aAppData->name); |
michael@0 | 47 | SetAllocatedString(this->version, aAppData->version); |
michael@0 | 48 | SetAllocatedString(this->buildID, aAppData->buildID); |
michael@0 | 49 | SetAllocatedString(this->ID, aAppData->ID); |
michael@0 | 50 | SetAllocatedString(this->copyright, aAppData->copyright); |
michael@0 | 51 | SetAllocatedString(this->profile, aAppData->profile); |
michael@0 | 52 | SetStrongPtr(this->directory, aAppData->directory); |
michael@0 | 53 | this->flags = aAppData->flags; |
michael@0 | 54 | |
michael@0 | 55 | if (aAppData->size > offsetof(nsXREAppData, xreDirectory)) { |
michael@0 | 56 | SetStrongPtr(this->xreDirectory, aAppData->xreDirectory); |
michael@0 | 57 | SetAllocatedString(this->minVersion, aAppData->minVersion); |
michael@0 | 58 | SetAllocatedString(this->maxVersion, aAppData->maxVersion); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | if (aAppData->size > offsetof(nsXREAppData, crashReporterURL)) { |
michael@0 | 62 | SetAllocatedString(this->crashReporterURL, aAppData->crashReporterURL); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | if (aAppData->size > offsetof(nsXREAppData, UAName)) { |
michael@0 | 66 | SetAllocatedString(this->UAName, aAppData->UAName); |
michael@0 | 67 | } |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | ScopedAppData::~ScopedAppData() |
michael@0 | 71 | { |
michael@0 | 72 | SetAllocatedString(this->vendor, nullptr); |
michael@0 | 73 | SetAllocatedString(this->name, nullptr); |
michael@0 | 74 | SetAllocatedString(this->version, nullptr); |
michael@0 | 75 | SetAllocatedString(this->buildID, nullptr); |
michael@0 | 76 | SetAllocatedString(this->ID, nullptr); |
michael@0 | 77 | SetAllocatedString(this->copyright, nullptr); |
michael@0 | 78 | SetAllocatedString(this->profile, nullptr); |
michael@0 | 79 | |
michael@0 | 80 | NS_IF_RELEASE(this->directory); |
michael@0 | 81 | |
michael@0 | 82 | SetStrongPtr(this->xreDirectory, (nsIFile*) nullptr); |
michael@0 | 83 | SetAllocatedString(this->minVersion, nullptr); |
michael@0 | 84 | SetAllocatedString(this->maxVersion, nullptr); |
michael@0 | 85 | |
michael@0 | 86 | SetAllocatedString(this->crashReporterURL, nullptr); |
michael@0 | 87 | SetAllocatedString(this->UAName, nullptr); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | } // namespace mozilla |