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: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
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 NS_SMILINSTANCETIME_H_ |
michael@0 | 7 | #define NS_SMILINSTANCETIME_H_ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsSMILTimeValue.h" |
michael@0 | 10 | #include "nsAutoPtr.h" |
michael@0 | 11 | |
michael@0 | 12 | class nsSMILInterval; |
michael@0 | 13 | class nsSMILTimeContainer; |
michael@0 | 14 | class nsSMILTimeValueSpec; |
michael@0 | 15 | |
michael@0 | 16 | //---------------------------------------------------------------------- |
michael@0 | 17 | // nsSMILInstanceTime |
michael@0 | 18 | // |
michael@0 | 19 | // An instant in document simple time that may be used in creating a new |
michael@0 | 20 | // interval. |
michael@0 | 21 | // |
michael@0 | 22 | // For an overview of how this class is related to other SMIL time classes see |
michael@0 | 23 | // the documentation in nsSMILTimeValue.h |
michael@0 | 24 | // |
michael@0 | 25 | // These objects are owned by an nsSMILTimedElement but MAY also be referenced |
michael@0 | 26 | // by: |
michael@0 | 27 | // |
michael@0 | 28 | // a) nsSMILIntervals that belong to the same nsSMILTimedElement and which refer |
michael@0 | 29 | // to the nsSMILInstanceTimes which form the interval endpoints; and/or |
michael@0 | 30 | // b) nsSMILIntervals that belong to other nsSMILTimedElements but which need to |
michael@0 | 31 | // update dependent instance times when they change or are deleted. |
michael@0 | 32 | // E.g. for begin='a.begin', 'a' needs to inform dependent |
michael@0 | 33 | // nsSMILInstanceTimes if its begin time changes. This notification is |
michael@0 | 34 | // performed by the nsSMILInterval. |
michael@0 | 35 | |
michael@0 | 36 | class nsSMILInstanceTime MOZ_FINAL |
michael@0 | 37 | { |
michael@0 | 38 | public: |
michael@0 | 39 | // Instance time source. Times generated by events, syncbase relationships, |
michael@0 | 40 | // and DOM calls behave differently in some circumstances such as when a timed |
michael@0 | 41 | // element is reset. |
michael@0 | 42 | enum nsSMILInstanceTimeSource { |
michael@0 | 43 | // No particularly significant source, e.g. offset time, 'indefinite' |
michael@0 | 44 | SOURCE_NONE, |
michael@0 | 45 | // Generated by a DOM call such as beginElement |
michael@0 | 46 | SOURCE_DOM, |
michael@0 | 47 | // Generated by a syncbase relationship |
michael@0 | 48 | SOURCE_SYNCBASE, |
michael@0 | 49 | // Generated by an event |
michael@0 | 50 | SOURCE_EVENT |
michael@0 | 51 | }; |
michael@0 | 52 | |
michael@0 | 53 | nsSMILInstanceTime(const nsSMILTimeValue& aTime, |
michael@0 | 54 | nsSMILInstanceTimeSource aSource = SOURCE_NONE, |
michael@0 | 55 | nsSMILTimeValueSpec* aCreator = nullptr, |
michael@0 | 56 | nsSMILInterval* aBaseInterval = nullptr); |
michael@0 | 57 | |
michael@0 | 58 | void Unlink(); |
michael@0 | 59 | void HandleChangedInterval(const nsSMILTimeContainer* aSrcContainer, |
michael@0 | 60 | bool aBeginObjectChanged, |
michael@0 | 61 | bool aEndObjectChanged); |
michael@0 | 62 | void HandleDeletedInterval(); |
michael@0 | 63 | void HandleFilteredInterval(); |
michael@0 | 64 | |
michael@0 | 65 | const nsSMILTimeValue& Time() const { return mTime; } |
michael@0 | 66 | const nsSMILTimeValueSpec* GetCreator() const { return mCreator; } |
michael@0 | 67 | |
michael@0 | 68 | bool IsDynamic() const { return !!(mFlags & kDynamic); } |
michael@0 | 69 | bool IsFixedTime() const { return !(mFlags & kMayUpdate); } |
michael@0 | 70 | bool FromDOM() const { return !!(mFlags & kFromDOM); } |
michael@0 | 71 | |
michael@0 | 72 | bool ShouldPreserve() const; |
michael@0 | 73 | void UnmarkShouldPreserve(); |
michael@0 | 74 | |
michael@0 | 75 | void AddRefFixedEndpoint(); |
michael@0 | 76 | void ReleaseFixedEndpoint(); |
michael@0 | 77 | |
michael@0 | 78 | void DependentUpdate(const nsSMILTimeValue& aNewTime) |
michael@0 | 79 | { |
michael@0 | 80 | NS_ABORT_IF_FALSE(!IsFixedTime(), |
michael@0 | 81 | "Updating an instance time that is not expected to be updated"); |
michael@0 | 82 | mTime = aNewTime; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | bool IsDependent() const { return !!mBaseInterval; } |
michael@0 | 86 | bool IsDependentOn(const nsSMILInstanceTime& aOther) const; |
michael@0 | 87 | const nsSMILInterval* GetBaseInterval() const { return mBaseInterval; } |
michael@0 | 88 | const nsSMILInstanceTime* GetBaseTime() const; |
michael@0 | 89 | |
michael@0 | 90 | bool SameTimeAndBase(const nsSMILInstanceTime& aOther) const |
michael@0 | 91 | { |
michael@0 | 92 | return mTime == aOther.mTime && GetBaseTime() == aOther.GetBaseTime(); |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | // Get and set a serial number which may be used by a containing class to |
michael@0 | 96 | // control the sort order of otherwise similar instance times. |
michael@0 | 97 | uint32_t Serial() const { return mSerial; } |
michael@0 | 98 | void SetSerial(uint32_t aIndex) { mSerial = aIndex; } |
michael@0 | 99 | |
michael@0 | 100 | NS_INLINE_DECL_REFCOUNTING(nsSMILInstanceTime) |
michael@0 | 101 | |
michael@0 | 102 | private: |
michael@0 | 103 | // Private destructor, to discourage deletion outside of Release(): |
michael@0 | 104 | ~nsSMILInstanceTime(); |
michael@0 | 105 | |
michael@0 | 106 | void SetBaseInterval(nsSMILInterval* aBaseInterval); |
michael@0 | 107 | |
michael@0 | 108 | nsSMILTimeValue mTime; |
michael@0 | 109 | |
michael@0 | 110 | // Internal flags used to represent the behaviour of different instance times |
michael@0 | 111 | enum { |
michael@0 | 112 | // Indicates that this instance time was generated by an event or a DOM |
michael@0 | 113 | // call. Such instance times require special handling when (i) the owning |
michael@0 | 114 | // element is reset, (ii) when they are to be added as a new end instance |
michael@0 | 115 | // times (as per SMIL's event sensitivity contraints), and (iii) when |
michael@0 | 116 | // a backwards seek is performed and the timing model is reconstructed. |
michael@0 | 117 | kDynamic = 1, |
michael@0 | 118 | |
michael@0 | 119 | // Indicates that this instance time is referred to by an |
michael@0 | 120 | // nsSMILTimeValueSpec and as such may be updated. Such instance time should |
michael@0 | 121 | // not be filtered out by the nsSMILTimedElement even if they appear to be |
michael@0 | 122 | // in the past as they may be updated to a future time. |
michael@0 | 123 | kMayUpdate = 2, |
michael@0 | 124 | |
michael@0 | 125 | // Indicates that this instance time was generated from the DOM as opposed |
michael@0 | 126 | // to an nsSMILTimeValueSpec. When a 'begin' or 'end' attribute is set or |
michael@0 | 127 | // reset we should clear all the instance times that have been generated by |
michael@0 | 128 | // that attribute (and hence an nsSMILTimeValueSpec), but not those from the |
michael@0 | 129 | // DOM. |
michael@0 | 130 | kFromDOM = 4, |
michael@0 | 131 | |
michael@0 | 132 | // Indicates that this instance time was used as the endpoint of an interval |
michael@0 | 133 | // that has been filtered or removed. However, since it is a dynamic time it |
michael@0 | 134 | // should be preserved and not filtered. |
michael@0 | 135 | kWasDynamicEndpoint = 8 |
michael@0 | 136 | }; |
michael@0 | 137 | uint8_t mFlags; // Combination of kDynamic, kMayUpdate, etc. |
michael@0 | 138 | mutable bool mVisited; // Cycle tracking |
michael@0 | 139 | |
michael@0 | 140 | // Additional reference count to determine if this instance time is currently |
michael@0 | 141 | // used as a fixed endpoint in any intervals. Instance times that are used in |
michael@0 | 142 | // this way should not be removed when the owning nsSMILTimedElement removes |
michael@0 | 143 | // instance times in response to a restart or in an attempt to free up memory |
michael@0 | 144 | // by filtering out old instance times. |
michael@0 | 145 | // |
michael@0 | 146 | // Instance times are only shared in a few cases, namely: |
michael@0 | 147 | // a) early ends, |
michael@0 | 148 | // b) zero-duration intervals, |
michael@0 | 149 | // c) momentarily whilst establishing new intervals and updating the current |
michael@0 | 150 | // interval, and |
michael@0 | 151 | // d) trimmed intervals |
michael@0 | 152 | // Hence the limited range of a uint16_t should be more than adequate. |
michael@0 | 153 | uint16_t mFixedEndpointRefCnt; |
michael@0 | 154 | |
michael@0 | 155 | uint32_t mSerial; // A serial number used by the containing class to |
michael@0 | 156 | // specify the sort order for instance times with the |
michael@0 | 157 | // same mTime. |
michael@0 | 158 | |
michael@0 | 159 | nsSMILTimeValueSpec* mCreator; // The nsSMILTimeValueSpec object that created |
michael@0 | 160 | // us. (currently only needed for syncbase |
michael@0 | 161 | // instance times.) |
michael@0 | 162 | nsSMILInterval* mBaseInterval; // Interval from which this time is derived |
michael@0 | 163 | // (only used for syncbase instance times) |
michael@0 | 164 | }; |
michael@0 | 165 | |
michael@0 | 166 | #endif // NS_SMILINSTANCETIME_H_ |