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 | #include "base/basictypes.h" |
michael@0 | 7 | #include "ipc/IPCMessageUtils.h" |
michael@0 | 8 | #include "mozilla/dom/DOMRect.h" |
michael@0 | 9 | #include "mozilla/dom/NotifyPaintEvent.h" |
michael@0 | 10 | #include "mozilla/dom/PaintRequest.h" |
michael@0 | 11 | #include "mozilla/GfxMessageUtils.h" |
michael@0 | 12 | #include "nsContentUtils.h" |
michael@0 | 13 | |
michael@0 | 14 | namespace mozilla { |
michael@0 | 15 | namespace dom { |
michael@0 | 16 | |
michael@0 | 17 | NotifyPaintEvent::NotifyPaintEvent(EventTarget* aOwner, |
michael@0 | 18 | nsPresContext* aPresContext, |
michael@0 | 19 | WidgetEvent* aEvent, |
michael@0 | 20 | uint32_t aEventType, |
michael@0 | 21 | nsInvalidateRequestList* aInvalidateRequests) |
michael@0 | 22 | : Event(aOwner, aPresContext, aEvent) |
michael@0 | 23 | { |
michael@0 | 24 | if (mEvent) { |
michael@0 | 25 | mEvent->message = aEventType; |
michael@0 | 26 | } |
michael@0 | 27 | if (aInvalidateRequests) { |
michael@0 | 28 | mInvalidateRequests.MoveElementsFrom(aInvalidateRequests->mRequests); |
michael@0 | 29 | } |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | NS_INTERFACE_MAP_BEGIN(NotifyPaintEvent) |
michael@0 | 33 | NS_INTERFACE_MAP_ENTRY(nsIDOMNotifyPaintEvent) |
michael@0 | 34 | NS_INTERFACE_MAP_END_INHERITING(Event) |
michael@0 | 35 | |
michael@0 | 36 | NS_IMPL_ADDREF_INHERITED(NotifyPaintEvent, Event) |
michael@0 | 37 | NS_IMPL_RELEASE_INHERITED(NotifyPaintEvent, Event) |
michael@0 | 38 | |
michael@0 | 39 | nsRegion |
michael@0 | 40 | NotifyPaintEvent::GetRegion() |
michael@0 | 41 | { |
michael@0 | 42 | nsRegion r; |
michael@0 | 43 | if (!nsContentUtils::IsCallerChrome()) { |
michael@0 | 44 | return r; |
michael@0 | 45 | } |
michael@0 | 46 | for (uint32_t i = 0; i < mInvalidateRequests.Length(); ++i) { |
michael@0 | 47 | r.Or(r, mInvalidateRequests[i].mRect); |
michael@0 | 48 | r.SimplifyOutward(10); |
michael@0 | 49 | } |
michael@0 | 50 | return r; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | NS_IMETHODIMP |
michael@0 | 54 | NotifyPaintEvent::GetBoundingClientRect(nsIDOMClientRect** aResult) |
michael@0 | 55 | { |
michael@0 | 56 | *aResult = BoundingClientRect().take(); |
michael@0 | 57 | return NS_OK; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | already_AddRefed<DOMRect> |
michael@0 | 61 | NotifyPaintEvent::BoundingClientRect() |
michael@0 | 62 | { |
michael@0 | 63 | nsRefPtr<DOMRect> rect = new DOMRect(ToSupports(this)); |
michael@0 | 64 | |
michael@0 | 65 | if (mPresContext) { |
michael@0 | 66 | rect->SetLayoutRect(GetRegion().GetBounds()); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | return rect.forget(); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | NS_IMETHODIMP |
michael@0 | 73 | NotifyPaintEvent::GetClientRects(nsIDOMClientRectList** aResult) |
michael@0 | 74 | { |
michael@0 | 75 | *aResult = ClientRects().take(); |
michael@0 | 76 | return NS_OK; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | already_AddRefed<DOMRectList> |
michael@0 | 80 | NotifyPaintEvent::ClientRects() |
michael@0 | 81 | { |
michael@0 | 82 | nsISupports* parent = ToSupports(this); |
michael@0 | 83 | nsRefPtr<DOMRectList> rectList = new DOMRectList(parent); |
michael@0 | 84 | |
michael@0 | 85 | nsRegion r = GetRegion(); |
michael@0 | 86 | nsRegionRectIterator iter(r); |
michael@0 | 87 | for (const nsRect* rgnRect = iter.Next(); rgnRect; rgnRect = iter.Next()) { |
michael@0 | 88 | nsRefPtr<DOMRect> rect = new DOMRect(parent); |
michael@0 | 89 | |
michael@0 | 90 | rect->SetLayoutRect(*rgnRect); |
michael@0 | 91 | rectList->Append(rect); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | return rectList.forget(); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | NS_IMETHODIMP |
michael@0 | 98 | NotifyPaintEvent::GetPaintRequests(nsISupports** aResult) |
michael@0 | 99 | { |
michael@0 | 100 | nsRefPtr<PaintRequestList> requests = PaintRequests(); |
michael@0 | 101 | requests.forget(aResult); |
michael@0 | 102 | return NS_OK; |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | already_AddRefed<PaintRequestList> |
michael@0 | 106 | NotifyPaintEvent::PaintRequests() |
michael@0 | 107 | { |
michael@0 | 108 | Event* parent = this; |
michael@0 | 109 | nsRefPtr<PaintRequestList> requests = new PaintRequestList(parent); |
michael@0 | 110 | |
michael@0 | 111 | if (nsContentUtils::IsCallerChrome()) { |
michael@0 | 112 | for (uint32_t i = 0; i < mInvalidateRequests.Length(); ++i) { |
michael@0 | 113 | nsRefPtr<PaintRequest> r = new PaintRequest(parent); |
michael@0 | 114 | r->SetRequest(mInvalidateRequests[i]); |
michael@0 | 115 | requests->Append(r); |
michael@0 | 116 | } |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | return requests.forget(); |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | NS_IMETHODIMP_(void) |
michael@0 | 123 | NotifyPaintEvent::Serialize(IPC::Message* aMsg, |
michael@0 | 124 | bool aSerializeInterfaceType) |
michael@0 | 125 | { |
michael@0 | 126 | if (aSerializeInterfaceType) { |
michael@0 | 127 | IPC::WriteParam(aMsg, NS_LITERAL_STRING("notifypaintevent")); |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | Event::Serialize(aMsg, false); |
michael@0 | 131 | |
michael@0 | 132 | uint32_t length = mInvalidateRequests.Length(); |
michael@0 | 133 | IPC::WriteParam(aMsg, length); |
michael@0 | 134 | for (uint32_t i = 0; i < length; ++i) { |
michael@0 | 135 | IPC::WriteParam(aMsg, mInvalidateRequests[i].mRect); |
michael@0 | 136 | IPC::WriteParam(aMsg, mInvalidateRequests[i].mFlags); |
michael@0 | 137 | } |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | NS_IMETHODIMP_(bool) |
michael@0 | 141 | NotifyPaintEvent::Deserialize(const IPC::Message* aMsg, void** aIter) |
michael@0 | 142 | { |
michael@0 | 143 | NS_ENSURE_TRUE(Event::Deserialize(aMsg, aIter), false); |
michael@0 | 144 | |
michael@0 | 145 | uint32_t length = 0; |
michael@0 | 146 | NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &length), false); |
michael@0 | 147 | mInvalidateRequests.SetCapacity(length); |
michael@0 | 148 | for (uint32_t i = 0; i < length; ++i) { |
michael@0 | 149 | nsInvalidateRequestList::Request req; |
michael@0 | 150 | NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &req.mRect), false); |
michael@0 | 151 | NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &req.mFlags), false); |
michael@0 | 152 | mInvalidateRequests.AppendElement(req); |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | return true; |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | } // namespace dom |
michael@0 | 159 | } // namespace mozilla |
michael@0 | 160 | |
michael@0 | 161 | using namespace mozilla; |
michael@0 | 162 | using namespace mozilla::dom; |
michael@0 | 163 | |
michael@0 | 164 | nsresult |
michael@0 | 165 | NS_NewDOMNotifyPaintEvent(nsIDOMEvent** aInstancePtrResult, |
michael@0 | 166 | EventTarget* aOwner, |
michael@0 | 167 | nsPresContext* aPresContext, |
michael@0 | 168 | WidgetEvent* aEvent, |
michael@0 | 169 | uint32_t aEventType, |
michael@0 | 170 | nsInvalidateRequestList* aInvalidateRequests) |
michael@0 | 171 | { |
michael@0 | 172 | NotifyPaintEvent* it = new NotifyPaintEvent(aOwner, aPresContext, aEvent, |
michael@0 | 173 | aEventType, aInvalidateRequests); |
michael@0 | 174 | NS_ADDREF(it); |
michael@0 | 175 | *aInstancePtrResult = static_cast<Event*>(it); |
michael@0 | 176 | return NS_OK; |
michael@0 | 177 | } |