dom/camera/DOMCameraCapabilities.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: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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 "DOMCameraCapabilities.h"
michael@0 8 #include "nsPIDOMWindow.h"
michael@0 9 #include "nsContentUtils.h"
michael@0 10 #include "mozilla/dom/CameraManagerBinding.h"
michael@0 11 #include "mozilla/dom/CameraCapabilitiesBinding.h"
michael@0 12 #include "Navigator.h"
michael@0 13 #include "CameraCommon.h"
michael@0 14 #include "ICameraControl.h"
michael@0 15 #include "CameraRecorderProfiles.h"
michael@0 16
michael@0 17 namespace mozilla {
michael@0 18 namespace dom {
michael@0 19
michael@0 20 NS_IMPL_CYCLE_COLLECTION_CLASS(CameraCapabilities)
michael@0 21
michael@0 22 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CameraCapabilities)
michael@0 23 NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
michael@0 24 tmp->mRecorderProfiles = JS::UndefinedValue();
michael@0 25 NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
michael@0 26 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
michael@0 27
michael@0 28 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(CameraCapabilities)
michael@0 29 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
michael@0 30 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
michael@0 31 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
michael@0 32
michael@0 33 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(CameraCapabilities)
michael@0 34 NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mRecorderProfiles)
michael@0 35 NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
michael@0 36 NS_IMPL_CYCLE_COLLECTION_TRACE_END
michael@0 37
michael@0 38 NS_IMPL_CYCLE_COLLECTING_ADDREF(CameraCapabilities)
michael@0 39 NS_IMPL_CYCLE_COLLECTING_RELEASE(CameraCapabilities)
michael@0 40
michael@0 41 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CameraCapabilities)
michael@0 42 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
michael@0 43 NS_INTERFACE_MAP_ENTRY(nsISupports)
michael@0 44 NS_INTERFACE_MAP_END
michael@0 45
michael@0 46 /* static */
michael@0 47 bool
michael@0 48 CameraCapabilities::HasSupport(JSContext* aCx, JSObject* aGlobal)
michael@0 49 {
michael@0 50 return Navigator::HasCameraSupport(aCx, aGlobal);
michael@0 51 }
michael@0 52
michael@0 53 CameraCapabilities::CameraCapabilities(nsPIDOMWindow* aWindow)
michael@0 54 : mRecorderProfiles(JS::UndefinedValue())
michael@0 55 , mWindow(aWindow)
michael@0 56 {
michael@0 57 DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
michael@0 58 MOZ_COUNT_CTOR(CameraCapabilities);
michael@0 59 mozilla::HoldJSObjects(this);
michael@0 60 SetIsDOMBinding();
michael@0 61 }
michael@0 62
michael@0 63 CameraCapabilities::~CameraCapabilities()
michael@0 64 {
michael@0 65 DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
michael@0 66 mRecorderProfiles = JS::UndefinedValue();
michael@0 67 mozilla::DropJSObjects(this);
michael@0 68 MOZ_COUNT_DTOR(CameraCapabilities);
michael@0 69 }
michael@0 70
michael@0 71 JSObject*
michael@0 72 CameraCapabilities::WrapObject(JSContext* aCx)
michael@0 73 {
michael@0 74 return CameraCapabilitiesBinding::Wrap(aCx, this);
michael@0 75 }
michael@0 76
michael@0 77 #define LOG_IF_ERROR(rv, param) \
michael@0 78 do { \
michael@0 79 if (NS_FAILED(rv)) { \
michael@0 80 DOM_CAMERA_LOGW("Error %x trying to get " #param "\n", \
michael@0 81 (rv)); \
michael@0 82 } \
michael@0 83 } while(0)
michael@0 84
michael@0 85 nsresult
michael@0 86 CameraCapabilities::TranslateToDictionary(ICameraControl* aCameraControl,
michael@0 87 uint32_t aKey, nsTArray<CameraSize>& aSizes)
michael@0 88 {
michael@0 89 nsresult rv;
michael@0 90 nsTArray<ICameraControl::Size> sizes;
michael@0 91
michael@0 92 rv = aCameraControl->Get(aKey, sizes);
michael@0 93 if (NS_FAILED(rv)) {
michael@0 94 return rv;
michael@0 95 }
michael@0 96
michael@0 97 aSizes.Clear();
michael@0 98 aSizes.SetCapacity(sizes.Length());
michael@0 99 for (uint32_t i = 0; i < sizes.Length(); ++i) {
michael@0 100 CameraSize* s = aSizes.AppendElement();
michael@0 101 s->mWidth = sizes[i].width;
michael@0 102 s->mHeight = sizes[i].height;
michael@0 103 }
michael@0 104
michael@0 105 return NS_OK;
michael@0 106 }
michael@0 107
michael@0 108 nsresult
michael@0 109 CameraCapabilities::Populate(ICameraControl* aCameraControl)
michael@0 110 {
michael@0 111 NS_ENSURE_TRUE(aCameraControl, NS_ERROR_INVALID_ARG);
michael@0 112
michael@0 113 nsresult rv;
michael@0 114
michael@0 115 rv = TranslateToDictionary(aCameraControl, CAMERA_PARAM_SUPPORTED_PREVIEWSIZES, mPreviewSizes);
michael@0 116 LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_PREVIEWSIZES);
michael@0 117
michael@0 118 rv = TranslateToDictionary(aCameraControl, CAMERA_PARAM_SUPPORTED_PICTURESIZES, mPictureSizes);
michael@0 119 LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_PICTURESIZES);
michael@0 120
michael@0 121 rv = TranslateToDictionary(aCameraControl, CAMERA_PARAM_SUPPORTED_JPEG_THUMBNAIL_SIZES, mThumbnailSizes);
michael@0 122 LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_JPEG_THUMBNAIL_SIZES);
michael@0 123
michael@0 124 rv = TranslateToDictionary(aCameraControl, CAMERA_PARAM_SUPPORTED_VIDEOSIZES, mVideoSizes);
michael@0 125 LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_VIDEOSIZES);
michael@0 126
michael@0 127 rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_PICTUREFORMATS, mFileFormats);
michael@0 128 LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_PICTUREFORMATS);
michael@0 129
michael@0 130 rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_WHITEBALANCES, mWhiteBalanceModes);
michael@0 131 LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_WHITEBALANCES);
michael@0 132
michael@0 133 rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_SCENEMODES, mSceneModes);
michael@0 134 LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_SCENEMODES);
michael@0 135
michael@0 136 rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_EFFECTS, mEffects);
michael@0 137 LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_EFFECTS);
michael@0 138
michael@0 139 rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_FLASHMODES, mFlashModes);
michael@0 140 LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_FLASHMODES);
michael@0 141
michael@0 142 rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_FOCUSMODES, mFocusModes);
michael@0 143 LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_FOCUSMODES);
michael@0 144
michael@0 145 rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_ISOMODES, mIsoModes);
michael@0 146 LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_ISOMODES);
michael@0 147
michael@0 148 rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_ZOOMRATIOS, mZoomRatios);
michael@0 149 LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_ZOOMRATIOS);
michael@0 150
michael@0 151 int32_t areas;
michael@0 152 rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_MAXFOCUSAREAS, areas);
michael@0 153 LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_MAXFOCUSAREAS);
michael@0 154 mMaxFocusAreas = areas < 0 ? 0 : areas;
michael@0 155
michael@0 156 rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_MAXMETERINGAREAS, areas);
michael@0 157 LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_MAXMETERINGAREAS);
michael@0 158 mMaxMeteringAreas = areas < 0 ? 0 : areas;
michael@0 159
michael@0 160 int32_t faces;
michael@0 161 rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_MAXDETECTEDFACES, faces);
michael@0 162 LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_MAXDETECTEDFACES);
michael@0 163 mMaxDetectedFaces = faces < 0 ? 0 : faces;
michael@0 164
michael@0 165 rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_MINEXPOSURECOMPENSATION, mMinExposureCompensation);
michael@0 166 LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_MINEXPOSURECOMPENSATION);
michael@0 167
michael@0 168 rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_MAXEXPOSURECOMPENSATION, mMaxExposureCompensation);
michael@0 169 LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_MAXEXPOSURECOMPENSATION);
michael@0 170
michael@0 171 rv = aCameraControl->Get(CAMERA_PARAM_SUPPORTED_EXPOSURECOMPENSATIONSTEP, mExposureCompensationStep);
michael@0 172 LOG_IF_ERROR(rv, CAMERA_PARAM_SUPPORTED_EXPOSURECOMPENSATIONSTEP);
michael@0 173
michael@0 174 mRecorderProfileManager = aCameraControl->GetRecorderProfileManager();
michael@0 175 if (!mRecorderProfileManager) {
michael@0 176 DOM_CAMERA_LOGW("Unable to get recorder profile manager\n");
michael@0 177 } else {
michael@0 178 AutoJSContext js;
michael@0 179
michael@0 180 JS::Rooted<JSObject*> o(js);
michael@0 181 nsresult rv = mRecorderProfileManager->GetJsObject(js, o.address());
michael@0 182 if (NS_FAILED(rv)) {
michael@0 183 DOM_CAMERA_LOGE("Failed to JS-objectify profile manager (%d)\n", rv);
michael@0 184 return rv;
michael@0 185 }
michael@0 186
michael@0 187 mRecorderProfiles = JS::ObjectValue(*o);
michael@0 188 }
michael@0 189
michael@0 190 // For now, always return success, since the presence or absence of capabilities
michael@0 191 // indicates whether or not they are supported.
michael@0 192 return NS_OK;
michael@0 193 }
michael@0 194
michael@0 195 void
michael@0 196 CameraCapabilities::GetPreviewSizes(nsTArray<dom::CameraSize>& retval) const
michael@0 197 {
michael@0 198 retval = mPreviewSizes;
michael@0 199 }
michael@0 200
michael@0 201 void
michael@0 202 CameraCapabilities::GetPictureSizes(nsTArray<dom::CameraSize>& retval) const
michael@0 203 {
michael@0 204 retval = mPictureSizes;
michael@0 205 }
michael@0 206
michael@0 207 void
michael@0 208 CameraCapabilities::GetThumbnailSizes(nsTArray<dom::CameraSize>& retval) const
michael@0 209 {
michael@0 210 retval = mThumbnailSizes;
michael@0 211 }
michael@0 212
michael@0 213 void
michael@0 214 CameraCapabilities::GetVideoSizes(nsTArray<dom::CameraSize>& retval) const
michael@0 215 {
michael@0 216 retval = mVideoSizes;
michael@0 217 }
michael@0 218
michael@0 219 void
michael@0 220 CameraCapabilities::GetFileFormats(nsTArray<nsString>& retval) const
michael@0 221 {
michael@0 222 retval = mFileFormats;
michael@0 223 }
michael@0 224
michael@0 225 void
michael@0 226 CameraCapabilities::GetWhiteBalanceModes(nsTArray<nsString>& retval) const
michael@0 227 {
michael@0 228 retval = mWhiteBalanceModes;
michael@0 229 }
michael@0 230
michael@0 231 void
michael@0 232 CameraCapabilities::GetSceneModes(nsTArray<nsString>& retval) const
michael@0 233 {
michael@0 234 retval = mSceneModes;
michael@0 235 }
michael@0 236
michael@0 237 void
michael@0 238 CameraCapabilities::GetEffects(nsTArray<nsString>& retval) const
michael@0 239 {
michael@0 240 retval = mEffects;
michael@0 241 }
michael@0 242
michael@0 243 void
michael@0 244 CameraCapabilities::GetFlashModes(nsTArray<nsString>& retval) const
michael@0 245 {
michael@0 246 retval = mFlashModes;
michael@0 247 }
michael@0 248
michael@0 249 void
michael@0 250 CameraCapabilities::GetFocusModes(nsTArray<nsString>& retval) const
michael@0 251 {
michael@0 252 retval = mFocusModes;
michael@0 253 }
michael@0 254
michael@0 255 void
michael@0 256 CameraCapabilities::GetZoomRatios(nsTArray<double>& retval) const
michael@0 257 {
michael@0 258 retval = mZoomRatios;
michael@0 259 }
michael@0 260
michael@0 261 uint32_t
michael@0 262 CameraCapabilities::MaxFocusAreas() const
michael@0 263 {
michael@0 264 return mMaxFocusAreas;
michael@0 265 }
michael@0 266
michael@0 267 uint32_t
michael@0 268 CameraCapabilities::MaxMeteringAreas() const
michael@0 269 {
michael@0 270 return mMaxMeteringAreas;
michael@0 271 }
michael@0 272
michael@0 273 uint32_t
michael@0 274 CameraCapabilities::MaxDetectedFaces() const
michael@0 275 {
michael@0 276 return mMaxDetectedFaces;
michael@0 277 }
michael@0 278
michael@0 279 double
michael@0 280 CameraCapabilities::MinExposureCompensation() const
michael@0 281 {
michael@0 282 return mMinExposureCompensation;
michael@0 283 }
michael@0 284
michael@0 285 double
michael@0 286 CameraCapabilities::MaxExposureCompensation() const
michael@0 287 {
michael@0 288 return mMaxExposureCompensation;
michael@0 289 }
michael@0 290
michael@0 291 double
michael@0 292 CameraCapabilities::ExposureCompensationStep() const
michael@0 293 {
michael@0 294 return mExposureCompensationStep;
michael@0 295 }
michael@0 296
michael@0 297 void
michael@0 298 CameraCapabilities::GetRecorderProfiles(JSContext* aCx,
michael@0 299 JS::MutableHandle<JS::Value> aRetval) const
michael@0 300 {
michael@0 301 JS::ExposeValueToActiveJS(mRecorderProfiles);
michael@0 302 aRetval.set(mRecorderProfiles);
michael@0 303 }
michael@0 304
michael@0 305 void
michael@0 306 CameraCapabilities::GetIsoModes(nsTArray<nsString>& retval) const
michael@0 307 {
michael@0 308 retval = mIsoModes;
michael@0 309 }
michael@0 310
michael@0 311 } // namespace dom
michael@0 312 } // namespace mozilla

mercurial