widget/xpwidgets/GfxInfoCollector.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 /* vim: se cin sw=2 ts=2 et : */
michael@0 2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 3 *
michael@0 4 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #include "GfxInfoCollector.h"
michael@0 9 #include "jsapi.h"
michael@0 10 #include "nsString.h"
michael@0 11
michael@0 12 using namespace mozilla;
michael@0 13 using namespace widget;
michael@0 14
michael@0 15 void
michael@0 16 InfoObject::DefineProperty(const char *name, int value)
michael@0 17 {
michael@0 18 if (!mOk)
michael@0 19 return;
michael@0 20
michael@0 21 mOk = JS_DefineProperty(mCx, mObj, name, value, JSPROP_ENUMERATE);
michael@0 22 }
michael@0 23
michael@0 24 void
michael@0 25 InfoObject::DefineProperty(const char *name, nsAString &value)
michael@0 26 {
michael@0 27 if (!mOk)
michael@0 28 return;
michael@0 29
michael@0 30 const nsString &flat = PromiseFlatString(value);
michael@0 31 JS::Rooted<JSString*> string(mCx, JS_NewUCStringCopyN(mCx, static_cast<const jschar*>(flat.get()),
michael@0 32 flat.Length()));
michael@0 33 if (!string)
michael@0 34 mOk = false;
michael@0 35
michael@0 36 if (!mOk)
michael@0 37 return;
michael@0 38
michael@0 39 mOk = JS_DefineProperty(mCx, mObj, name, string, JSPROP_ENUMERATE);
michael@0 40 }
michael@0 41
michael@0 42 void
michael@0 43 InfoObject::DefineProperty(const char *name, const char *value)
michael@0 44 {
michael@0 45 nsAutoString string = NS_ConvertASCIItoUTF16(value);
michael@0 46 DefineProperty(name, string);
michael@0 47 }
michael@0 48
michael@0 49 InfoObject::InfoObject(JSContext *aCx) : mCx(aCx), mObj(aCx), mOk(true)
michael@0 50 {
michael@0 51 mObj = JS_NewObject(mCx, nullptr, JS::NullPtr(), JS::NullPtr());
michael@0 52 if (!mObj)
michael@0 53 mOk = false;
michael@0 54 }

mercurial