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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "CameraRecorderProfiles.h" |
michael@0 | 6 | #include "jsapi.h" |
michael@0 | 7 | #include "CameraCommon.h" |
michael@0 | 8 | |
michael@0 | 9 | using namespace mozilla; |
michael@0 | 10 | |
michael@0 | 11 | /** |
michael@0 | 12 | * Video profile implementation. |
michael@0 | 13 | */ |
michael@0 | 14 | RecorderVideoProfile::RecorderVideoProfile(uint32_t aCameraId, uint32_t aQualityIndex) |
michael@0 | 15 | : mCameraId(aCameraId) |
michael@0 | 16 | , mQualityIndex(aQualityIndex) |
michael@0 | 17 | { |
michael@0 | 18 | DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | RecorderVideoProfile::~RecorderVideoProfile() |
michael@0 | 22 | { |
michael@0 | 23 | DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | nsresult |
michael@0 | 27 | RecorderVideoProfile::GetJsObject(JSContext* aCx, JSObject** aObject) |
michael@0 | 28 | { |
michael@0 | 29 | NS_ENSURE_TRUE(aObject, NS_ERROR_INVALID_ARG); |
michael@0 | 30 | |
michael@0 | 31 | JS::Rooted<JSObject*> o(aCx, JS_NewObject(aCx, nullptr, JS::NullPtr(), JS::NullPtr())); |
michael@0 | 32 | NS_ENSURE_TRUE(o, NS_ERROR_OUT_OF_MEMORY); |
michael@0 | 33 | |
michael@0 | 34 | const char* codec = GetCodecName(); |
michael@0 | 35 | NS_ENSURE_TRUE(codec, NS_ERROR_FAILURE); |
michael@0 | 36 | |
michael@0 | 37 | JS::Rooted<JSString*> s(aCx, JS_NewStringCopyZ(aCx, codec)); |
michael@0 | 38 | JS::Rooted<JS::Value> v(aCx, STRING_TO_JSVAL(s)); |
michael@0 | 39 | if (!JS_SetProperty(aCx, o, "codec", v)) { |
michael@0 | 40 | return NS_ERROR_FAILURE; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | if (mBitrate != -1) { |
michael@0 | 44 | v = INT_TO_JSVAL(mBitrate); |
michael@0 | 45 | if (!JS_SetProperty(aCx, o, "bitrate", v)) { |
michael@0 | 46 | return NS_ERROR_FAILURE; |
michael@0 | 47 | } |
michael@0 | 48 | } |
michael@0 | 49 | if (mFramerate != -1) { |
michael@0 | 50 | v = INT_TO_JSVAL(mFramerate); |
michael@0 | 51 | if (!JS_SetProperty(aCx, o, "framerate", v)) { |
michael@0 | 52 | return NS_ERROR_FAILURE; |
michael@0 | 53 | } |
michael@0 | 54 | } |
michael@0 | 55 | if (mWidth != -1) { |
michael@0 | 56 | v = INT_TO_JSVAL(mWidth); |
michael@0 | 57 | if (!JS_SetProperty(aCx, o, "width", v)) { |
michael@0 | 58 | return NS_ERROR_FAILURE; |
michael@0 | 59 | } |
michael@0 | 60 | } |
michael@0 | 61 | if (mHeight != -1) { |
michael@0 | 62 | v = INT_TO_JSVAL(mHeight); |
michael@0 | 63 | if (!JS_SetProperty(aCx, o, "height", v)) { |
michael@0 | 64 | return NS_ERROR_FAILURE; |
michael@0 | 65 | } |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | *aObject = o; |
michael@0 | 69 | return NS_OK; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | /** |
michael@0 | 73 | * Audio profile implementation. |
michael@0 | 74 | */ |
michael@0 | 75 | RecorderAudioProfile::RecorderAudioProfile(uint32_t aCameraId, uint32_t aQualityIndex) |
michael@0 | 76 | : mCameraId(aCameraId) |
michael@0 | 77 | , mQualityIndex(aQualityIndex) |
michael@0 | 78 | { |
michael@0 | 79 | DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | RecorderAudioProfile::~RecorderAudioProfile() |
michael@0 | 83 | { |
michael@0 | 84 | DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | nsresult |
michael@0 | 88 | RecorderAudioProfile::GetJsObject(JSContext* aCx, JSObject** aObject) |
michael@0 | 89 | { |
michael@0 | 90 | NS_ENSURE_TRUE(aObject, NS_ERROR_INVALID_ARG); |
michael@0 | 91 | |
michael@0 | 92 | JS::Rooted<JSObject*> o(aCx, JS_NewObject(aCx, nullptr, JS::NullPtr(), JS::NullPtr())); |
michael@0 | 93 | NS_ENSURE_TRUE(o, NS_ERROR_OUT_OF_MEMORY); |
michael@0 | 94 | |
michael@0 | 95 | const char* codec = GetCodecName(); |
michael@0 | 96 | NS_ENSURE_TRUE(codec, NS_ERROR_FAILURE); |
michael@0 | 97 | |
michael@0 | 98 | JS::Rooted<JSString*> s(aCx, JS_NewStringCopyZ(aCx, codec)); |
michael@0 | 99 | JS::Rooted<JS::Value> v(aCx, STRING_TO_JSVAL(s)); |
michael@0 | 100 | if (!JS_SetProperty(aCx, o, "codec", v)) { |
michael@0 | 101 | return NS_ERROR_FAILURE; |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | if (mBitrate != -1) { |
michael@0 | 105 | v = INT_TO_JSVAL(mBitrate); |
michael@0 | 106 | if (!JS_SetProperty(aCx, o, "bitrate", v)) { |
michael@0 | 107 | return NS_ERROR_FAILURE; |
michael@0 | 108 | } |
michael@0 | 109 | } |
michael@0 | 110 | if (mSamplerate != -1) { |
michael@0 | 111 | v = INT_TO_JSVAL(mSamplerate); |
michael@0 | 112 | if (!JS_SetProperty(aCx, o, "samplerate", v)) { |
michael@0 | 113 | return NS_ERROR_FAILURE; |
michael@0 | 114 | } |
michael@0 | 115 | } |
michael@0 | 116 | if (mChannels != -1) { |
michael@0 | 117 | v = INT_TO_JSVAL(mChannels); |
michael@0 | 118 | if (!JS_SetProperty(aCx, o, "channels", v)) { |
michael@0 | 119 | return NS_ERROR_FAILURE; |
michael@0 | 120 | } |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | *aObject = o; |
michael@0 | 124 | return NS_OK; |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | /** |
michael@0 | 128 | * Recorder Profile |
michael@0 | 129 | */ |
michael@0 | 130 | RecorderProfile::RecorderProfile(uint32_t aCameraId, uint32_t aQualityIndex) |
michael@0 | 131 | : mCameraId(aCameraId) |
michael@0 | 132 | , mQualityIndex(aQualityIndex) |
michael@0 | 133 | , mName(nullptr) |
michael@0 | 134 | { |
michael@0 | 135 | DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this); |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | RecorderProfile::~RecorderProfile() |
michael@0 | 139 | { |
michael@0 | 140 | DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this); |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | /** |
michael@0 | 144 | * Recorder profile manager implementation. |
michael@0 | 145 | */ |
michael@0 | 146 | RecorderProfileManager::RecorderProfileManager(uint32_t aCameraId) |
michael@0 | 147 | : mCameraId(aCameraId) |
michael@0 | 148 | { |
michael@0 | 149 | DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this); |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | RecorderProfileManager::~RecorderProfileManager() |
michael@0 | 153 | { |
michael@0 | 154 | DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this); |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | nsresult |
michael@0 | 158 | RecorderProfileManager::GetJsObject(JSContext* aCx, JSObject** aObject) const |
michael@0 | 159 | { |
michael@0 | 160 | NS_ENSURE_TRUE(aObject, NS_ERROR_INVALID_ARG); |
michael@0 | 161 | |
michael@0 | 162 | JS::Rooted<JSObject*> o(aCx, JS_NewObject(aCx, nullptr, JS::NullPtr(), JS::NullPtr())); |
michael@0 | 163 | if (!o) { |
michael@0 | 164 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | for (uint32_t q = 0; q < GetMaxQualityIndex(); ++q) { |
michael@0 | 168 | if (!IsSupported(q)) { |
michael@0 | 169 | continue; |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | nsRefPtr<RecorderProfile> profile = Get(q); |
michael@0 | 173 | if (!profile) { |
michael@0 | 174 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | const char* profileName = profile->GetName(); |
michael@0 | 178 | if (!profileName) { |
michael@0 | 179 | // don't allow anonymous recorder profiles |
michael@0 | 180 | continue; |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | JS::Rooted<JSObject*> p(aCx); |
michael@0 | 184 | nsresult rv = profile->GetJsObject(aCx, p.address()); |
michael@0 | 185 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 186 | JS::Rooted<JS::Value> v(aCx, OBJECT_TO_JSVAL(p)); |
michael@0 | 187 | |
michael@0 | 188 | if (!JS_SetProperty(aCx, o, profileName, v)) { |
michael@0 | 189 | return NS_ERROR_FAILURE; |
michael@0 | 190 | } |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | *aObject = o; |
michael@0 | 194 | return NS_OK; |
michael@0 | 195 | } |