dom/events/DeviceMotionEvent.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: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "mozilla/dom/DeviceMotionEvent.h"
michael@0 8 #include "nsContentUtils.h"
michael@0 9
michael@0 10 namespace mozilla {
michael@0 11 namespace dom {
michael@0 12
michael@0 13 /******************************************************************************
michael@0 14 * DeviceMotionEvent
michael@0 15 *****************************************************************************/
michael@0 16
michael@0 17 NS_IMPL_CYCLE_COLLECTION_INHERITED(DeviceMotionEvent, Event,
michael@0 18 mAcceleration,
michael@0 19 mAccelerationIncludingGravity,
michael@0 20 mRotationRate)
michael@0 21
michael@0 22 NS_IMPL_ADDREF_INHERITED(DeviceMotionEvent, Event)
michael@0 23 NS_IMPL_RELEASE_INHERITED(DeviceMotionEvent, Event)
michael@0 24
michael@0 25 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DeviceMotionEvent)
michael@0 26 NS_INTERFACE_MAP_END_INHERITING(Event)
michael@0 27
michael@0 28 void
michael@0 29 DeviceMotionEvent::InitDeviceMotionEvent(
michael@0 30 const nsAString& aType,
michael@0 31 bool aCanBubble,
michael@0 32 bool aCancelable,
michael@0 33 const DeviceAccelerationInit& aAcceleration,
michael@0 34 const DeviceAccelerationInit& aAccelIncludingGravity,
michael@0 35 const DeviceRotationRateInit& aRotationRate,
michael@0 36 Nullable<double> aInterval,
michael@0 37 ErrorResult& aRv)
michael@0 38 {
michael@0 39 aRv = Event::InitEvent(aType, aCanBubble, aCancelable);
michael@0 40 if (aRv.Failed()) {
michael@0 41 return;
michael@0 42 }
michael@0 43
michael@0 44 mAcceleration = new DeviceAcceleration(this, aAcceleration.mX,
michael@0 45 aAcceleration.mY,
michael@0 46 aAcceleration.mZ);
michael@0 47
michael@0 48 mAccelerationIncludingGravity =
michael@0 49 new DeviceAcceleration(this, aAccelIncludingGravity.mX,
michael@0 50 aAccelIncludingGravity.mY,
michael@0 51 aAccelIncludingGravity.mZ);
michael@0 52
michael@0 53 mRotationRate = new DeviceRotationRate(this, aRotationRate.mAlpha,
michael@0 54 aRotationRate.mBeta,
michael@0 55 aRotationRate.mGamma);
michael@0 56 mInterval = aInterval;
michael@0 57 }
michael@0 58
michael@0 59 already_AddRefed<DeviceMotionEvent>
michael@0 60 DeviceMotionEvent::Constructor(const GlobalObject& aGlobal,
michael@0 61 const nsAString& aType,
michael@0 62 const DeviceMotionEventInit& aEventInitDict,
michael@0 63 ErrorResult& aRv)
michael@0 64 {
michael@0 65 nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
michael@0 66 nsRefPtr<DeviceMotionEvent> e = new DeviceMotionEvent(t, nullptr, nullptr);
michael@0 67 aRv = e->InitEvent(aType, aEventInitDict.mBubbles, aEventInitDict.mCancelable);
michael@0 68 if (aRv.Failed()) {
michael@0 69 return nullptr;
michael@0 70 }
michael@0 71 bool trusted = e->Init(t);
michael@0 72
michael@0 73 e->mAcceleration = new DeviceAcceleration(e,
michael@0 74 aEventInitDict.mAcceleration.mX,
michael@0 75 aEventInitDict.mAcceleration.mY,
michael@0 76 aEventInitDict.mAcceleration.mZ);
michael@0 77
michael@0 78 e->mAccelerationIncludingGravity = new DeviceAcceleration(e,
michael@0 79 aEventInitDict.mAccelerationIncludingGravity.mX,
michael@0 80 aEventInitDict.mAccelerationIncludingGravity.mY,
michael@0 81 aEventInitDict.mAccelerationIncludingGravity.mZ);
michael@0 82
michael@0 83 e->mRotationRate = new DeviceRotationRate(e,
michael@0 84 aEventInitDict.mRotationRate.mAlpha,
michael@0 85 aEventInitDict.mRotationRate.mBeta,
michael@0 86 aEventInitDict.mRotationRate.mGamma);
michael@0 87
michael@0 88 e->mInterval = aEventInitDict.mInterval;
michael@0 89 e->SetTrusted(trusted);
michael@0 90
michael@0 91 return e.forget();
michael@0 92 }
michael@0 93
michael@0 94 /******************************************************************************
michael@0 95 * DeviceAcceleration
michael@0 96 *****************************************************************************/
michael@0 97
michael@0 98 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(DeviceAcceleration, mOwner)
michael@0 99
michael@0 100 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DeviceAcceleration, AddRef)
michael@0 101 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(DeviceAcceleration, Release)
michael@0 102
michael@0 103 DeviceAcceleration::DeviceAcceleration(DeviceMotionEvent* aOwner,
michael@0 104 Nullable<double> aX,
michael@0 105 Nullable<double> aY,
michael@0 106 Nullable<double> aZ)
michael@0 107 : mOwner(aOwner)
michael@0 108 , mX(aX)
michael@0 109 , mY(aY)
michael@0 110 , mZ(aZ)
michael@0 111 {
michael@0 112 SetIsDOMBinding();
michael@0 113 }
michael@0 114
michael@0 115 DeviceAcceleration::~DeviceAcceleration()
michael@0 116 {
michael@0 117 }
michael@0 118
michael@0 119 /******************************************************************************
michael@0 120 * DeviceRotationRate
michael@0 121 *****************************************************************************/
michael@0 122
michael@0 123 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(DeviceRotationRate, mOwner)
michael@0 124
michael@0 125 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DeviceRotationRate, AddRef)
michael@0 126 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(DeviceRotationRate, Release)
michael@0 127
michael@0 128 DeviceRotationRate::DeviceRotationRate(DeviceMotionEvent* aOwner,
michael@0 129 Nullable<double> aAlpha,
michael@0 130 Nullable<double> aBeta,
michael@0 131 Nullable<double> aGamma)
michael@0 132 : mOwner(aOwner)
michael@0 133 , mAlpha(aAlpha)
michael@0 134 , mBeta(aBeta)
michael@0 135 , mGamma(aGamma)
michael@0 136 {
michael@0 137 SetIsDOMBinding();
michael@0 138 }
michael@0 139
michael@0 140 DeviceRotationRate::~DeviceRotationRate()
michael@0 141 {
michael@0 142 }
michael@0 143
michael@0 144 } // namespace dom
michael@0 145 } // namespace mozilla
michael@0 146
michael@0 147 using namespace mozilla;
michael@0 148 using namespace mozilla::dom;
michael@0 149
michael@0 150 nsresult
michael@0 151 NS_NewDOMDeviceMotionEvent(nsIDOMEvent** aInstancePtrResult,
michael@0 152 EventTarget* aOwner,
michael@0 153 nsPresContext* aPresContext,
michael@0 154 WidgetEvent* aEvent)
michael@0 155 {
michael@0 156 NS_ENSURE_ARG_POINTER(aInstancePtrResult);
michael@0 157
michael@0 158 DeviceMotionEvent* it = new DeviceMotionEvent(aOwner, aPresContext, aEvent);
michael@0 159 NS_ADDREF(it);
michael@0 160 *aInstancePtrResult = static_cast<Event*>(it);
michael@0 161 return NS_OK;
michael@0 162 }

mercurial