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.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef AudioListener_h_
8 #define AudioListener_h_
10 #include "nsWrapperCache.h"
11 #include "nsCycleCollectionParticipant.h"
12 #include "mozilla/Attributes.h"
13 #include "nsAutoPtr.h"
14 #include "ThreeDPoint.h"
15 #include "AudioContext.h"
16 #include "PannerNode.h"
17 #include "WebAudioUtils.h"
18 #include "js/TypeDecls.h"
19 #include "mozilla/MemoryReporting.h"
21 namespace mozilla {
23 namespace dom {
25 class AudioListener MOZ_FINAL : public nsWrapperCache
26 {
27 public:
28 explicit AudioListener(AudioContext* aContext);
30 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AudioListener)
31 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AudioListener)
33 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
35 AudioContext* GetParentObject() const
36 {
37 return mContext;
38 }
40 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
42 double DopplerFactor() const
43 {
44 return mDopplerFactor;
45 }
46 void SetDopplerFactor(double aDopplerFactor)
47 {
48 if (WebAudioUtils::FuzzyEqual(mDopplerFactor, aDopplerFactor)) {
49 return;
50 }
51 mDopplerFactor = aDopplerFactor;
52 SendDoubleParameterToStream(PannerNode::LISTENER_DOPPLER_FACTOR, mDopplerFactor);
53 }
55 double SpeedOfSound() const
56 {
57 return mSpeedOfSound;
58 }
59 void SetSpeedOfSound(double aSpeedOfSound)
60 {
61 if (WebAudioUtils::FuzzyEqual(mSpeedOfSound, aSpeedOfSound)) {
62 return;
63 }
64 mSpeedOfSound = aSpeedOfSound;
65 SendDoubleParameterToStream(PannerNode::LISTENER_SPEED_OF_SOUND, mSpeedOfSound);
66 }
68 void SetPosition(double aX, double aY, double aZ)
69 {
70 if (WebAudioUtils::FuzzyEqual(mPosition.x, aX) &&
71 WebAudioUtils::FuzzyEqual(mPosition.y, aY) &&
72 WebAudioUtils::FuzzyEqual(mPosition.z, aZ)) {
73 return;
74 }
75 mPosition.x = aX;
76 mPosition.y = aY;
77 mPosition.z = aZ;
78 SendThreeDPointParameterToStream(PannerNode::LISTENER_POSITION, mPosition);
79 }
81 const ThreeDPoint& Position() const
82 {
83 return mPosition;
84 }
86 void SetOrientation(double aX, double aY, double aZ,
87 double aXUp, double aYUp, double aZUp);
89 const ThreeDPoint& Velocity() const
90 {
91 return mVelocity;
92 }
94 void SetVelocity(double aX, double aY, double aZ)
95 {
96 if (WebAudioUtils::FuzzyEqual(mVelocity.x, aX) &&
97 WebAudioUtils::FuzzyEqual(mVelocity.y, aY) &&
98 WebAudioUtils::FuzzyEqual(mVelocity.z, aZ)) {
99 return;
100 }
101 mVelocity.x = aX;
102 mVelocity.y = aY;
103 mVelocity.z = aZ;
104 SendThreeDPointParameterToStream(PannerNode::LISTENER_VELOCITY, mVelocity);
105 UpdatePannersVelocity();
106 }
108 void RegisterPannerNode(PannerNode* aPannerNode);
109 void UnregisterPannerNode(PannerNode* aPannerNode);
111 private:
112 void SendDoubleParameterToStream(uint32_t aIndex, double aValue);
113 void SendThreeDPointParameterToStream(uint32_t aIndex, const ThreeDPoint& aValue);
114 void UpdatePannersVelocity();
116 private:
117 friend class PannerNode;
118 nsRefPtr<AudioContext> mContext;
119 ThreeDPoint mPosition;
120 ThreeDPoint mFrontVector;
121 ThreeDPoint mRightVector;
122 ThreeDPoint mVelocity;
123 double mDopplerFactor;
124 double mSpeedOfSound;
125 nsTArray<WeakPtr<PannerNode> > mPanners;
126 };
128 }
129 }
131 #endif