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: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef mozilla_HoldDropJSObjects_h |
michael@0 | 8 | #define mozilla_HoldDropJSObjects_h |
michael@0 | 9 | |
michael@0 | 10 | #include "mozilla/TypeTraits.h" |
michael@0 | 11 | #include "nsCycleCollectionParticipant.h" |
michael@0 | 12 | |
michael@0 | 13 | class nsISupports; |
michael@0 | 14 | class nsScriptObjectTracer; |
michael@0 | 15 | |
michael@0 | 16 | // Only HoldJSObjects and DropJSObjects should be called directly. |
michael@0 | 17 | |
michael@0 | 18 | namespace mozilla { |
michael@0 | 19 | namespace cyclecollector { |
michael@0 | 20 | |
michael@0 | 21 | // These methods are defined in nsCycleCollector.cpp |
michael@0 | 22 | void HoldJSObjectsImpl(void* aHolder, nsScriptObjectTracer* aTracer); |
michael@0 | 23 | void HoldJSObjectsImpl(nsISupports* aHolder); |
michael@0 | 24 | void DropJSObjectsImpl(void* aHolder); |
michael@0 | 25 | void DropJSObjectsImpl(nsISupports* aHolder); |
michael@0 | 26 | |
michael@0 | 27 | } // namespace cyclecollector |
michael@0 | 28 | |
michael@0 | 29 | |
michael@0 | 30 | template<class T, bool isISupports=IsBaseOf<nsISupports, T>::value> |
michael@0 | 31 | struct HoldDropJSObjectsHelper |
michael@0 | 32 | { |
michael@0 | 33 | static void Hold(T* aHolder) |
michael@0 | 34 | { |
michael@0 | 35 | cyclecollector::HoldJSObjectsImpl(aHolder, NS_CYCLE_COLLECTION_PARTICIPANT(T)); |
michael@0 | 36 | } |
michael@0 | 37 | static void Drop(T* aHolder) |
michael@0 | 38 | { |
michael@0 | 39 | cyclecollector::DropJSObjectsImpl(aHolder); |
michael@0 | 40 | } |
michael@0 | 41 | }; |
michael@0 | 42 | |
michael@0 | 43 | template<class T> |
michael@0 | 44 | struct HoldDropJSObjectsHelper<T, true> |
michael@0 | 45 | { |
michael@0 | 46 | static void Hold(T* aHolder) |
michael@0 | 47 | { |
michael@0 | 48 | cyclecollector::HoldJSObjectsImpl(ToSupports(aHolder)); |
michael@0 | 49 | } |
michael@0 | 50 | static void Drop(T* aHolder) |
michael@0 | 51 | { |
michael@0 | 52 | cyclecollector::DropJSObjectsImpl(ToSupports(aHolder)); |
michael@0 | 53 | } |
michael@0 | 54 | }; |
michael@0 | 55 | |
michael@0 | 56 | |
michael@0 | 57 | template<class T> |
michael@0 | 58 | void HoldJSObjects(T* aHolder) |
michael@0 | 59 | { |
michael@0 | 60 | HoldDropJSObjectsHelper<T>::Hold(aHolder); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | template<class T> |
michael@0 | 64 | void DropJSObjects(T* aHolder) |
michael@0 | 65 | { |
michael@0 | 66 | HoldDropJSObjectsHelper<T>::Drop(aHolder); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | } // namespace mozilla |
michael@0 | 70 | |
michael@0 | 71 | #endif // mozilla_HoldDropJSObjects_h |