widget/xpwidgets/GfxInfoBase.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.

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 #ifndef __mozilla_widget_GfxInfoBase_h__
michael@0 9 #define __mozilla_widget_GfxInfoBase_h__
michael@0 10
michael@0 11 #include "nsIGfxInfo.h"
michael@0 12 #include "nsCOMPtr.h"
michael@0 13 #include "nsIObserver.h"
michael@0 14 #include "nsWeakReference.h"
michael@0 15 #include "GfxDriverInfo.h"
michael@0 16 #include "nsTArray.h"
michael@0 17 #include "nsString.h"
michael@0 18 #include "GfxInfoCollector.h"
michael@0 19 #include "nsIGfxInfoDebug.h"
michael@0 20 #include "mozilla/Mutex.h"
michael@0 21 #include "js/Value.h"
michael@0 22 #include "mozilla/Attributes.h"
michael@0 23
michael@0 24 namespace mozilla {
michael@0 25 namespace widget {
michael@0 26
michael@0 27 class GfxInfoBase : public nsIGfxInfo,
michael@0 28 public nsIObserver,
michael@0 29 public nsSupportsWeakReference
michael@0 30 #ifdef DEBUG
michael@0 31 , public nsIGfxInfoDebug
michael@0 32 #endif
michael@0 33 {
michael@0 34 public:
michael@0 35 GfxInfoBase();
michael@0 36 virtual ~GfxInfoBase();
michael@0 37
michael@0 38 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 39 NS_DECL_NSIOBSERVER
michael@0 40
michael@0 41 // We only declare a subset of the nsIGfxInfo interface. It's up to derived
michael@0 42 // classes to implement the rest of the interface.
michael@0 43 // Derived classes need to use
michael@0 44 // using GfxInfoBase::GetFeatureStatus;
michael@0 45 // using GfxInfoBase::GetFeatureSuggestedDriverVersion;
michael@0 46 // using GfxInfoBase::GetWebGLParameter;
michael@0 47 // to import the relevant methods into their namespace.
michael@0 48 NS_IMETHOD GetFeatureStatus(int32_t aFeature, int32_t *_retval);
michael@0 49 NS_IMETHOD GetFeatureSuggestedDriverVersion(int32_t aFeature, nsAString & _retval);
michael@0 50 NS_IMETHOD GetWebGLParameter(const nsAString & aParam, nsAString & _retval);
michael@0 51
michael@0 52 NS_IMETHOD GetFailures(uint32_t *failureCount, char ***failures);
michael@0 53 NS_IMETHOD_(void) LogFailure(const nsACString &failure);
michael@0 54 NS_IMETHOD GetInfo(JSContext*, JS::MutableHandle<JS::Value>);
michael@0 55
michael@0 56 // Initialization function. If you override this, you must call this class's
michael@0 57 // version of Init first.
michael@0 58 // We need Init to be called separately from the constructor so we can
michael@0 59 // register as an observer after all derived classes have been constructed
michael@0 60 // and we know we have a non-zero refcount.
michael@0 61 // Ideally, Init() would be void-return, but the rules of
michael@0 62 // NS_GENERIC_FACTORY_CONSTRUCTOR_INIT require it be nsresult return.
michael@0 63 virtual nsresult Init();
michael@0 64
michael@0 65 // only useful on X11
michael@0 66 NS_IMETHOD_(void) GetData() { }
michael@0 67
michael@0 68 static void AddCollector(GfxInfoCollectorBase* collector);
michael@0 69 static void RemoveCollector(GfxInfoCollectorBase* collector);
michael@0 70
michael@0 71 static nsTArray<GfxDriverInfo>* mDriverInfo;
michael@0 72 static bool mDriverInfoObserverInitialized;
michael@0 73
michael@0 74 virtual nsString Model() { return EmptyString(); }
michael@0 75 virtual nsString Hardware() { return EmptyString(); }
michael@0 76 virtual nsString Product() { return EmptyString(); }
michael@0 77 virtual nsString Manufacturer() { return EmptyString(); }
michael@0 78 virtual uint32_t OperatingSystemVersion() { return 0; }
michael@0 79
michael@0 80 protected:
michael@0 81
michael@0 82 virtual nsresult GetFeatureStatusImpl(int32_t aFeature, int32_t* aStatus,
michael@0 83 nsAString& aSuggestedDriverVersion,
michael@0 84 const nsTArray<GfxDriverInfo>& aDriverInfo,
michael@0 85 OperatingSystem* aOS = nullptr);
michael@0 86
michael@0 87 // Gets the driver info table. Used by GfxInfoBase to check for general cases
michael@0 88 // (while subclasses check for more specific ones).
michael@0 89 virtual const nsTArray<GfxDriverInfo>& GetGfxDriverInfo() = 0;
michael@0 90
michael@0 91 private:
michael@0 92 virtual int32_t FindBlocklistedDeviceInList(const nsTArray<GfxDriverInfo>& aDriverInfo,
michael@0 93 nsAString& aSuggestedVersion,
michael@0 94 int32_t aFeature,
michael@0 95 OperatingSystem os);
michael@0 96
michael@0 97 void EvaluateDownloadedBlacklist(nsTArray<GfxDriverInfo>& aDriverInfo);
michael@0 98
michael@0 99 nsCString mFailures[9]; // The choice of 9 is Ehsan's
michael@0 100 uint32_t mFailureCount;
michael@0 101 Mutex mMutex;
michael@0 102
michael@0 103 };
michael@0 104
michael@0 105 }
michael@0 106 }
michael@0 107
michael@0 108 #endif /* __mozilla_widget_GfxInfoBase_h__ */

mercurial