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