image/src/FrameSequence.cpp

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

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.

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 #include "FrameSequence.h"
michael@0 7
michael@0 8 using namespace mozilla;
michael@0 9 using namespace mozilla::image;
michael@0 10
michael@0 11 namespace mozilla {
michael@0 12 namespace image {
michael@0 13
michael@0 14 FrameSequence::~FrameSequence()
michael@0 15 {
michael@0 16 ClearFrames();
michael@0 17 }
michael@0 18
michael@0 19 const FrameDataPair&
michael@0 20 FrameSequence::GetFrame(uint32_t framenum) const
michael@0 21 {
michael@0 22 if (framenum >= mFrames.Length()) {
michael@0 23 static FrameDataPair empty;
michael@0 24 return empty;
michael@0 25 }
michael@0 26
michael@0 27 return mFrames[framenum];
michael@0 28 }
michael@0 29
michael@0 30 uint32_t
michael@0 31 FrameSequence::GetNumFrames() const
michael@0 32 {
michael@0 33 return mFrames.Length();
michael@0 34 }
michael@0 35
michael@0 36 void
michael@0 37 FrameSequence::RemoveFrame(uint32_t framenum)
michael@0 38 {
michael@0 39 NS_ABORT_IF_FALSE(framenum < mFrames.Length(), "Deleting invalid frame!");
michael@0 40
michael@0 41 mFrames.RemoveElementAt(framenum);
michael@0 42 }
michael@0 43
michael@0 44 void
michael@0 45 FrameSequence::ClearFrames()
michael@0 46 {
michael@0 47 // Since FrameDataPair holds an nsAutoPtr to its frame, clearing the mFrames
michael@0 48 // array also deletes all the frames.
michael@0 49 mFrames.Clear();
michael@0 50 }
michael@0 51
michael@0 52 void
michael@0 53 FrameSequence::InsertFrame(uint32_t framenum, imgFrame* aFrame)
michael@0 54 {
michael@0 55 NS_ABORT_IF_FALSE(framenum <= mFrames.Length(), "Inserting invalid frame!");
michael@0 56 mFrames.InsertElementAt(framenum, aFrame);
michael@0 57 if (GetNumFrames() > 1) {
michael@0 58 // If we're creating our second element, we now know we're animated.
michael@0 59 // Therefore, we need to lock the first frame too.
michael@0 60 if (GetNumFrames() == 2) {
michael@0 61 mFrames[0].LockAndGetData();
michael@0 62 }
michael@0 63
michael@0 64 // Whenever we have more than one frame, we always lock *all* our frames
michael@0 65 // so we have all the image data pointers.
michael@0 66 mFrames[framenum].LockAndGetData();
michael@0 67 }
michael@0 68 }
michael@0 69
michael@0 70 imgFrame*
michael@0 71 FrameSequence::SwapFrame(uint32_t framenum, imgFrame* aFrame)
michael@0 72 {
michael@0 73 NS_ABORT_IF_FALSE(framenum < mFrames.Length(), "Swapping invalid frame!");
michael@0 74
michael@0 75 FrameDataPair ret;
michael@0 76
michael@0 77 // Steal the imgFrame.
michael@0 78 if (framenum < mFrames.Length()) {
michael@0 79 ret = mFrames[framenum];
michael@0 80 }
michael@0 81
michael@0 82 if (aFrame) {
michael@0 83 mFrames.ReplaceElementAt(framenum, aFrame);
michael@0 84 } else {
michael@0 85 mFrames.RemoveElementAt(framenum);
michael@0 86 }
michael@0 87
michael@0 88 return ret.Forget();
michael@0 89 }
michael@0 90
michael@0 91 size_t
michael@0 92 FrameSequence::SizeOfDecodedWithComputedFallbackIfHeap(gfxMemoryLocation aLocation,
michael@0 93 MallocSizeOf aMallocSizeOf) const
michael@0 94 {
michael@0 95 size_t n = 0;
michael@0 96 for (uint32_t i = 0; i < mFrames.Length(); ++i) {
michael@0 97 imgFrame* frame = mFrames.SafeElementAt(i, FrameDataPair());
michael@0 98 NS_ABORT_IF_FALSE(frame, "Null frame in frame array!");
michael@0 99 n += frame->SizeOfExcludingThisWithComputedFallbackIfHeap(aLocation, aMallocSizeOf);
michael@0 100 }
michael@0 101
michael@0 102 return n;
michael@0 103 }
michael@0 104
michael@0 105 } // namespace image
michael@0 106 } // namespace mozilla

mercurial