Thu, 15 Jan 2015 15:59:08 +0100
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 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "FrameSequence.h"
8 using namespace mozilla;
9 using namespace mozilla::image;
11 namespace mozilla {
12 namespace image {
14 FrameSequence::~FrameSequence()
15 {
16 ClearFrames();
17 }
19 const FrameDataPair&
20 FrameSequence::GetFrame(uint32_t framenum) const
21 {
22 if (framenum >= mFrames.Length()) {
23 static FrameDataPair empty;
24 return empty;
25 }
27 return mFrames[framenum];
28 }
30 uint32_t
31 FrameSequence::GetNumFrames() const
32 {
33 return mFrames.Length();
34 }
36 void
37 FrameSequence::RemoveFrame(uint32_t framenum)
38 {
39 NS_ABORT_IF_FALSE(framenum < mFrames.Length(), "Deleting invalid frame!");
41 mFrames.RemoveElementAt(framenum);
42 }
44 void
45 FrameSequence::ClearFrames()
46 {
47 // Since FrameDataPair holds an nsAutoPtr to its frame, clearing the mFrames
48 // array also deletes all the frames.
49 mFrames.Clear();
50 }
52 void
53 FrameSequence::InsertFrame(uint32_t framenum, imgFrame* aFrame)
54 {
55 NS_ABORT_IF_FALSE(framenum <= mFrames.Length(), "Inserting invalid frame!");
56 mFrames.InsertElementAt(framenum, aFrame);
57 if (GetNumFrames() > 1) {
58 // If we're creating our second element, we now know we're animated.
59 // Therefore, we need to lock the first frame too.
60 if (GetNumFrames() == 2) {
61 mFrames[0].LockAndGetData();
62 }
64 // Whenever we have more than one frame, we always lock *all* our frames
65 // so we have all the image data pointers.
66 mFrames[framenum].LockAndGetData();
67 }
68 }
70 imgFrame*
71 FrameSequence::SwapFrame(uint32_t framenum, imgFrame* aFrame)
72 {
73 NS_ABORT_IF_FALSE(framenum < mFrames.Length(), "Swapping invalid frame!");
75 FrameDataPair ret;
77 // Steal the imgFrame.
78 if (framenum < mFrames.Length()) {
79 ret = mFrames[framenum];
80 }
82 if (aFrame) {
83 mFrames.ReplaceElementAt(framenum, aFrame);
84 } else {
85 mFrames.RemoveElementAt(framenum);
86 }
88 return ret.Forget();
89 }
91 size_t
92 FrameSequence::SizeOfDecodedWithComputedFallbackIfHeap(gfxMemoryLocation aLocation,
93 MallocSizeOf aMallocSizeOf) const
94 {
95 size_t n = 0;
96 for (uint32_t i = 0; i < mFrames.Length(); ++i) {
97 imgFrame* frame = mFrames.SafeElementAt(i, FrameDataPair());
98 NS_ABORT_IF_FALSE(frame, "Null frame in frame array!");
99 n += frame->SizeOfExcludingThisWithComputedFallbackIfHeap(aLocation, aMallocSizeOf);
100 }
102 return n;
103 }
105 } // namespace image
106 } // namespace mozilla