layout/xul/nsPopupSetFrame.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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 #include "nsPopupSetFrame.h"
michael@0 7 #include "nsGkAtoms.h"
michael@0 8 #include "nsCOMPtr.h"
michael@0 9 #include "nsIContent.h"
michael@0 10 #include "nsPresContext.h"
michael@0 11 #include "nsStyleContext.h"
michael@0 12 #include "nsBoxLayoutState.h"
michael@0 13 #include "nsIScrollableFrame.h"
michael@0 14 #include "nsIRootBox.h"
michael@0 15 #include "nsMenuPopupFrame.h"
michael@0 16
michael@0 17 nsIFrame*
michael@0 18 NS_NewPopupSetFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
michael@0 19 {
michael@0 20 return new (aPresShell) nsPopupSetFrame (aPresShell, aContext);
michael@0 21 }
michael@0 22
michael@0 23 NS_IMPL_FRAMEARENA_HELPERS(nsPopupSetFrame)
michael@0 24
michael@0 25 void
michael@0 26 nsPopupSetFrame::Init(nsIContent* aContent,
michael@0 27 nsIFrame* aParent,
michael@0 28 nsIFrame* aPrevInFlow)
michael@0 29 {
michael@0 30 nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
michael@0 31
michael@0 32 // Normally the root box is our grandparent, but in case of wrapping
michael@0 33 // it can be our great-grandparent.
michael@0 34 nsIRootBox *rootBox = nsIRootBox::GetRootBox(PresContext()->GetPresShell());
michael@0 35 if (rootBox) {
michael@0 36 rootBox->SetPopupSetFrame(this);
michael@0 37 }
michael@0 38 }
michael@0 39
michael@0 40 nsIAtom*
michael@0 41 nsPopupSetFrame::GetType() const
michael@0 42 {
michael@0 43 return nsGkAtoms::popupSetFrame;
michael@0 44 }
michael@0 45
michael@0 46 nsresult
michael@0 47 nsPopupSetFrame::AppendFrames(ChildListID aListID,
michael@0 48 nsFrameList& aFrameList)
michael@0 49 {
michael@0 50 if (aListID == kPopupList) {
michael@0 51 AddPopupFrameList(aFrameList);
michael@0 52 return NS_OK;
michael@0 53 }
michael@0 54 return nsBoxFrame::AppendFrames(aListID, aFrameList);
michael@0 55 }
michael@0 56
michael@0 57 nsresult
michael@0 58 nsPopupSetFrame::RemoveFrame(ChildListID aListID,
michael@0 59 nsIFrame* aOldFrame)
michael@0 60 {
michael@0 61 if (aListID == kPopupList) {
michael@0 62 RemovePopupFrame(aOldFrame);
michael@0 63 return NS_OK;
michael@0 64 }
michael@0 65 return nsBoxFrame::RemoveFrame(aListID, aOldFrame);
michael@0 66 }
michael@0 67
michael@0 68 nsresult
michael@0 69 nsPopupSetFrame::InsertFrames(ChildListID aListID,
michael@0 70 nsIFrame* aPrevFrame,
michael@0 71 nsFrameList& aFrameList)
michael@0 72 {
michael@0 73 if (aListID == kPopupList) {
michael@0 74 AddPopupFrameList(aFrameList);
michael@0 75 return NS_OK;
michael@0 76 }
michael@0 77 return nsBoxFrame::InsertFrames(aListID, aPrevFrame, aFrameList);
michael@0 78 }
michael@0 79
michael@0 80 nsresult
michael@0 81 nsPopupSetFrame::SetInitialChildList(ChildListID aListID,
michael@0 82 nsFrameList& aChildList)
michael@0 83 {
michael@0 84 if (aListID == kPopupList) {
michael@0 85 NS_ASSERTION(mPopupList.IsEmpty(),
michael@0 86 "SetInitialChildList on non-empty child list");
michael@0 87 AddPopupFrameList(aChildList);
michael@0 88 return NS_OK;
michael@0 89 }
michael@0 90 return nsBoxFrame::SetInitialChildList(aListID, aChildList);
michael@0 91 }
michael@0 92
michael@0 93 const nsFrameList&
michael@0 94 nsPopupSetFrame::GetChildList(ChildListID aListID) const
michael@0 95 {
michael@0 96 if (kPopupList == aListID) {
michael@0 97 return mPopupList;
michael@0 98 }
michael@0 99 return nsBoxFrame::GetChildList(aListID);
michael@0 100 }
michael@0 101
michael@0 102 void
michael@0 103 nsPopupSetFrame::GetChildLists(nsTArray<ChildList>* aLists) const
michael@0 104 {
michael@0 105 nsBoxFrame::GetChildLists(aLists);
michael@0 106 mPopupList.AppendIfNonempty(aLists, kPopupList);
michael@0 107 }
michael@0 108
michael@0 109 void
michael@0 110 nsPopupSetFrame::DestroyFrom(nsIFrame* aDestructRoot)
michael@0 111 {
michael@0 112 mPopupList.DestroyFramesFrom(aDestructRoot);
michael@0 113
michael@0 114 // Normally the root box is our grandparent, but in case of wrapping
michael@0 115 // it can be our great-grandparent.
michael@0 116 nsIRootBox *rootBox = nsIRootBox::GetRootBox(PresContext()->GetPresShell());
michael@0 117 if (rootBox) {
michael@0 118 rootBox->SetPopupSetFrame(nullptr);
michael@0 119 }
michael@0 120
michael@0 121 nsBoxFrame::DestroyFrom(aDestructRoot);
michael@0 122 }
michael@0 123
michael@0 124 NS_IMETHODIMP
michael@0 125 nsPopupSetFrame::DoLayout(nsBoxLayoutState& aState)
michael@0 126 {
michael@0 127 // lay us out
michael@0 128 nsresult rv = nsBoxFrame::DoLayout(aState);
michael@0 129
michael@0 130 // lay out all of our currently open popups.
michael@0 131 for (nsFrameList::Enumerator e(mPopupList); !e.AtEnd(); e.Next()) {
michael@0 132 nsMenuPopupFrame* popupChild = static_cast<nsMenuPopupFrame*>(e.get());
michael@0 133 popupChild->LayoutPopup(aState, nullptr, nullptr, false);
michael@0 134 }
michael@0 135
michael@0 136 return rv;
michael@0 137 }
michael@0 138
michael@0 139 void
michael@0 140 nsPopupSetFrame::RemovePopupFrame(nsIFrame* aPopup)
michael@0 141 {
michael@0 142 NS_PRECONDITION((aPopup->GetStateBits() & NS_FRAME_OUT_OF_FLOW) &&
michael@0 143 aPopup->GetType() == nsGkAtoms::menuPopupFrame,
michael@0 144 "removing wrong type of frame in popupset's ::popupList");
michael@0 145
michael@0 146 mPopupList.DestroyFrame(aPopup);
michael@0 147 }
michael@0 148
michael@0 149 void
michael@0 150 nsPopupSetFrame::AddPopupFrameList(nsFrameList& aPopupFrameList)
michael@0 151 {
michael@0 152 #ifdef DEBUG
michael@0 153 for (nsFrameList::Enumerator e(aPopupFrameList); !e.AtEnd(); e.Next()) {
michael@0 154 NS_ASSERTION((e.get()->GetStateBits() & NS_FRAME_OUT_OF_FLOW) &&
michael@0 155 e.get()->GetType() == nsGkAtoms::menuPopupFrame,
michael@0 156 "adding wrong type of frame in popupset's ::popupList");
michael@0 157 }
michael@0 158 #endif
michael@0 159 mPopupList.InsertFrames(nullptr, nullptr, aPopupFrameList);
michael@0 160 }

mercurial