dom/events/NotifyPaintEvent.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.

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

mercurial