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.
michael@0 | 1 | /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsIWeakReferenceUtils_h__ |
michael@0 | 7 | #define nsIWeakReferenceUtils_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsCOMPtr.h" |
michael@0 | 10 | #include "nsIWeakReference.h" |
michael@0 | 11 | |
michael@0 | 12 | typedef nsCOMPtr<nsIWeakReference> nsWeakPtr; |
michael@0 | 13 | |
michael@0 | 14 | /** |
michael@0 | 15 | * |
michael@0 | 16 | */ |
michael@0 | 17 | |
michael@0 | 18 | // a type-safe shortcut for calling the |QueryReferent()| member function |
michael@0 | 19 | // T must inherit from nsIWeakReference, but the cast may be ambiguous. |
michael@0 | 20 | template <class T, class DestinationType> |
michael@0 | 21 | inline |
michael@0 | 22 | nsresult |
michael@0 | 23 | CallQueryReferent( T* aSource, DestinationType** aDestination ) |
michael@0 | 24 | { |
michael@0 | 25 | NS_PRECONDITION(aSource, "null parameter"); |
michael@0 | 26 | NS_PRECONDITION(aDestination, "null parameter"); |
michael@0 | 27 | |
michael@0 | 28 | return aSource->QueryReferent(NS_GET_TEMPLATE_IID(DestinationType), |
michael@0 | 29 | reinterpret_cast<void**>(aDestination)); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | |
michael@0 | 33 | class NS_COM_GLUE nsQueryReferent : public nsCOMPtr_helper |
michael@0 | 34 | { |
michael@0 | 35 | public: |
michael@0 | 36 | nsQueryReferent( nsIWeakReference* aWeakPtr, nsresult* error ) |
michael@0 | 37 | : mWeakPtr(aWeakPtr), |
michael@0 | 38 | mErrorPtr(error) |
michael@0 | 39 | { |
michael@0 | 40 | // nothing else to do here |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | virtual nsresult NS_FASTCALL operator()( const nsIID& aIID, void** ) const; |
michael@0 | 44 | |
michael@0 | 45 | private: |
michael@0 | 46 | nsIWeakReference* mWeakPtr; |
michael@0 | 47 | nsresult* mErrorPtr; |
michael@0 | 48 | }; |
michael@0 | 49 | |
michael@0 | 50 | inline |
michael@0 | 51 | const nsQueryReferent |
michael@0 | 52 | do_QueryReferent( nsIWeakReference* aRawPtr, nsresult* error = 0 ) |
michael@0 | 53 | { |
michael@0 | 54 | return nsQueryReferent(aRawPtr, error); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | |
michael@0 | 58 | /** |
michael@0 | 59 | * Deprecated, use |do_GetWeakReference| instead. |
michael@0 | 60 | */ |
michael@0 | 61 | extern NS_COM_GLUE |
michael@0 | 62 | nsIWeakReference* |
michael@0 | 63 | NS_GetWeakReference( nsISupports* , nsresult* aResult=0 ); |
michael@0 | 64 | |
michael@0 | 65 | /** |
michael@0 | 66 | * |do_GetWeakReference| is a convenience function that bundles up all the work needed |
michael@0 | 67 | * to get a weak reference to an arbitrary object, i.e., the |QueryInterface|, test, and |
michael@0 | 68 | * call through to |GetWeakReference|, and put it into your |nsCOMPtr|. |
michael@0 | 69 | * It is specifically designed to cooperate with |nsCOMPtr| (or |nsWeakPtr|) like so: |
michael@0 | 70 | * |nsWeakPtr myWeakPtr = do_GetWeakReference(aPtr);|. |
michael@0 | 71 | */ |
michael@0 | 72 | inline |
michael@0 | 73 | already_AddRefed<nsIWeakReference> |
michael@0 | 74 | do_GetWeakReference( nsISupports* aRawPtr, nsresult* error = 0 ) |
michael@0 | 75 | { |
michael@0 | 76 | return dont_AddRef(NS_GetWeakReference(aRawPtr, error)); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | inline |
michael@0 | 80 | void |
michael@0 | 81 | do_GetWeakReference( nsIWeakReference* aRawPtr, nsresult* error = 0 ) |
michael@0 | 82 | { |
michael@0 | 83 | // This signature exists solely to _stop_ you from doing a bad thing. |
michael@0 | 84 | // Saying |do_GetWeakReference()| on a weak reference itself, |
michael@0 | 85 | // is very likely to be a programmer error. |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | template <class T> |
michael@0 | 89 | inline |
michael@0 | 90 | void |
michael@0 | 91 | do_GetWeakReference( already_AddRefed<T>& ) |
michael@0 | 92 | { |
michael@0 | 93 | // This signature exists solely to _stop_ you from doing the bad thing. |
michael@0 | 94 | // Saying |do_GetWeakReference()| on a pointer that is not otherwise owned by |
michael@0 | 95 | // someone else is an automatic leak. See <http://bugzilla.mozilla.org/show_bug.cgi?id=8221>. |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | template <class T> |
michael@0 | 99 | inline |
michael@0 | 100 | void |
michael@0 | 101 | do_GetWeakReference( already_AddRefed<T>&, nsresult* ) |
michael@0 | 102 | { |
michael@0 | 103 | // This signature exists solely to _stop_ you from doing the bad thing. |
michael@0 | 104 | // Saying |do_GetWeakReference()| on a pointer that is not otherwise owned by |
michael@0 | 105 | // someone else is an automatic leak. See <http://bugzilla.mozilla.org/show_bug.cgi?id=8221>. |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | #endif |