xpcom/glue/AppData.h

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.

     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 #ifndef mozilla_AppData_h
     7 #define mozilla_AppData_h
     9 #include "nsXREAppData.h"
    10 #include "nscore.h"
    11 #include "nsStringGlue.h"
    12 #include "nsISupportsUtils.h"
    14 namespace mozilla {
    16 // Like nsXREAppData, but releases all strong refs/allocated memory
    17 // in the destructor.
    18 class NS_COM_GLUE ScopedAppData : public nsXREAppData
    19 {
    20 public:
    21   ScopedAppData() { Zero(); this->size = sizeof(*this); }
    23   ScopedAppData(const nsXREAppData* aAppData);
    25   void Zero() { memset(this, 0, sizeof(*this)); }
    27   ~ScopedAppData();
    28 };
    30 /**
    31  * Given "str" is holding a string allocated with NS_Alloc, or null:
    32  * replace the value in "str" with a new value.
    33  *
    34  * @param newvalue Null is permitted. The string is cloned with
    35  *                 NS_strdup
    36  */
    37 void SetAllocatedString(const char *&str, const char *newvalue);
    39 /**
    40  * Given "str" is holding a string allocated with NS_Alloc, or null:
    41  * replace the value in "str" with a new value.
    42  *
    43  * @param newvalue If "newvalue" is the empty string, "str" will be set
    44  *                 to null.
    45  */
    46 void SetAllocatedString(const char *&str, const nsACString &newvalue);
    48 template<class T>
    49 void SetStrongPtr(T *&ptr, T* newvalue)
    50 {
    51   NS_IF_RELEASE(ptr);
    52   ptr = newvalue;
    53   NS_IF_ADDREF(ptr);
    54 }
    56 } // namespace mozilla
    58 #endif

mercurial