widget/xpwidgets/GfxInfoCollector.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* vim: se cin sw=2 ts=2 et : */
     2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     3  *
     4  * This Source Code Form is subject to the terms of the Mozilla Public
     5  * License, v. 2.0. If a copy of the MPL was not distributed with this
     6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     8 #ifndef __mozilla_widget_GfxInfoCollector_h__
     9 #define __mozilla_widget_GfxInfoCollector_h__
    11 #include "mozilla/Attributes.h"
    12 #include "nsStringFwd.h"
    13 #include "js/RootingAPI.h"
    15 namespace mozilla {
    16 namespace widget {
    19 /* this is handy wrapper around JSAPI to make it more pleasant to use.
    20  * We collect the JSAPI errors and so that callers don't need to */
    21 class MOZ_STACK_CLASS InfoObject
    22 {
    23   friend class GfxInfoBase;
    25   public:
    26   void DefineProperty(const char *name, int value);
    27   void DefineProperty(const char *name, nsAString &value);
    28   void DefineProperty(const char *name, const char *value);
    30   private:
    31   // We need to ensure that this object lives on the stack so that GC sees it properly
    32   InfoObject(JSContext *aCx);
    33   InfoObject(InfoObject&);
    35   JSContext *mCx;
    36   JS::Rooted<JSObject*> mObj;
    37   bool mOk;
    38 };
    40 /*
    42    Here's an example usage:
    44    class Foo {
    45    Foo::Foo() : mInfoCollector(this, &Foo::GetAweseomeness) {}
    47    void GetAwesomeness(InfoObject &obj) {
    48      obj.DefineProperty("awesome", mAwesome);
    49    }
    51    int mAwesome;
    53    GfxInfoCollector<Foo> mInfoCollector;
    54    }
    56    This will define a property on the object
    57    returned from calling getInfo() on a
    58    GfxInfo object. e.g.
    60        gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo);
    61        info = gfxInfo.getInfo();
    62        if (info.awesome)
    63           alert(info.awesome);
    65 */
    67 class GfxInfoCollectorBase
    68 {
    69   public:
    70   GfxInfoCollectorBase();
    71   virtual void GetInfo(InfoObject &obj) = 0;
    72   virtual ~GfxInfoCollectorBase();
    73 };
    75 template<class T>
    76 class GfxInfoCollector : public GfxInfoCollectorBase
    77 {
    78   public:
    79   GfxInfoCollector(T* aPointer, void (T::*aFunc)(InfoObject &obj)) : mPointer(aPointer), mFunc(aFunc) {
    80   }
    81   virtual void GetInfo(InfoObject &obj) {
    82     (mPointer->*mFunc)(obj);
    83   }
    85   protected:
    86   T* mPointer;
    87   void (T::*mFunc)(InfoObject &obj);
    89 };
    91 }
    92 }
    94 #endif

mercurial