From f612f4fccc19f0065425aa8d58146a325799ef01 Mon Sep 17 00:00:00 2001 From: Mike Habicher Date: Wed, 9 Jan 2013 00:43:50 +0100 Subject: [PATCH] Bug 827503 - use nsMainThreadPtrHolders when passing XPCWrappedJSes around off main thread, r=bholley,jst a=blocking-basecamp+ --- dom/camera/CameraControlImpl.cpp | 15 ++-- dom/camera/CameraControlImpl.h | 139 ++++++++++++++++--------------- dom/camera/GonkCameraControl.cpp | 24 +++--- 3 files changed, 93 insertions(+), 85 deletions(-) diff --git a/dom/camera/CameraControlImpl.cpp b/dom/camera/CameraControlImpl.cpp index fa1de41c86dd..7a266ed5b97f 100644 --- a/dom/camera/CameraControlImpl.cpp +++ b/dom/camera/CameraControlImpl.cpp @@ -196,7 +196,7 @@ CameraControlImpl::Get(JSContext* aCx, uint32_t aKey, JS::Value* aValue) nsresult CameraControlImpl::Set(nsICameraShutterCallback* aOnShutter) { - mOnShutterCb = aOnShutter; + mOnShutterCb = new nsMainThreadPtrHolder(aOnShutter); return NS_OK; } @@ -210,7 +210,7 @@ CameraControlImpl::Get(nsICameraShutterCallback** aOnShutter) nsresult CameraControlImpl::Set(nsICameraClosedCallback* aOnClosed) { - mOnClosedCb = aOnClosed; + mOnClosedCb = new nsMainThreadPtrHolder(aOnClosed); return NS_OK; } @@ -224,7 +224,7 @@ CameraControlImpl::Get(nsICameraClosedCallback** aOnClosed) nsresult CameraControlImpl::Set(nsICameraRecorderStateChange* aOnRecorderStateChange) { - mOnRecorderStateChangeCb = aOnRecorderStateChange; + mOnRecorderStateChangeCb = new nsMainThreadPtrHolder(aOnRecorderStateChange); return NS_OK; } @@ -258,7 +258,7 @@ void CameraControlImpl::OnShutterInternal() { DOM_CAMERA_LOGI("** SNAP **\n"); - if (mOnShutterCb) { + if (mOnShutterCb.get()) { mOnShutterCb->HandleEvent(); } } @@ -277,7 +277,7 @@ void CameraControlImpl::OnClosedInternal() { DOM_CAMERA_LOGI("Camera hardware was closed\n"); - if (mOnClosedCb) { + if (mOnClosedCb.get()) { mOnClosedCb->HandleEvent(); } } @@ -390,9 +390,10 @@ GetPreviewStreamResult::Run() */ MOZ_ASSERT(NS_IsMainThread()); - if (mOnSuccessCb && nsDOMCameraManager::IsWindowStillActive(mWindowId)) { + nsCOMPtr onSuccess = mOnSuccessCb.get(); + if (onSuccess && nsDOMCameraManager::IsWindowStillActive(mWindowId)) { nsCOMPtr stream = new DOMCameraPreview(mCameraControl, mWidth, mHeight, mFramesPerSecond); - mOnSuccessCb->HandleEvent(stream); + onSuccess->HandleEvent(stream); } return NS_OK; } diff --git a/dom/camera/CameraControlImpl.h b/dom/camera/CameraControlImpl.h index 4d6c4034c07d..291b64674a73 100644 --- a/dom/camera/CameraControlImpl.h +++ b/dom/camera/CameraControlImpl.h @@ -5,8 +5,8 @@ #ifndef DOM_CAMERA_CAMERACONTROLIMPL_H #define DOM_CAMERA_CAMERACONTROLIMPL_H -#include "nsCOMPtr.h" #include "nsDOMFile.h" +#include "nsProxyRelease.h" #include "DictionaryHelpers.h" #include "nsIDOMDeviceStorage.h" #include "DOMCameraManager.h" @@ -143,13 +143,13 @@ protected: */ DOMCameraPreview* mDOMPreview; - nsCOMPtr mAutoFocusOnSuccessCb; - nsCOMPtr mAutoFocusOnErrorCb; - nsCOMPtr mTakePictureOnSuccessCb; - nsCOMPtr mTakePictureOnErrorCb; - nsCOMPtr mOnShutterCb; - nsCOMPtr mOnClosedCb; - nsCOMPtr mOnRecorderStateChangeCb; + nsMainThreadPtrHandle mAutoFocusOnSuccessCb; + nsMainThreadPtrHandle mAutoFocusOnErrorCb; + nsMainThreadPtrHandle mTakePictureOnSuccessCb; + nsMainThreadPtrHandle mTakePictureOnErrorCb; + nsMainThreadPtrHandle mOnShutterCb; + nsMainThreadPtrHandle mOnClosedCb; + nsMainThreadPtrHandle mOnRecorderStateChangeCb; private: CameraControlImpl(const CameraControlImpl&) MOZ_DELETE; @@ -161,7 +161,7 @@ class CameraErrorResult : public nsRunnable { public: CameraErrorResult(nsICameraErrorCallback* onError, const nsString& aErrorMsg, uint64_t aWindowId) - : mOnErrorCb(onError) + : mOnErrorCb(new nsMainThreadPtrHolder(onError)) , mErrorMsg(aErrorMsg) , mWindowId(aWindowId) { } @@ -170,14 +170,14 @@ public: { MOZ_ASSERT(NS_IsMainThread()); - if (mOnErrorCb && nsDOMCameraManager::IsWindowStillActive(mWindowId)) { + if (mOnErrorCb.get() && nsDOMCameraManager::IsWindowStillActive(mWindowId)) { mOnErrorCb->HandleEvent(mErrorMsg); } return NS_OK; } protected: - nsCOMPtr mOnErrorCb; + nsMainThreadPtrHandle mOnErrorCb; const nsString mErrorMsg; uint64_t mWindowId; }; @@ -186,7 +186,7 @@ protected: class GetPreviewStreamResult : public nsRunnable { public: - GetPreviewStreamResult(CameraControlImpl* aCameraControl, uint32_t aWidth, uint32_t aHeight, uint32_t aFramesPerSecond, nsICameraPreviewStreamCallback* onSuccess, uint64_t aWindowId) + GetPreviewStreamResult(CameraControlImpl* aCameraControl, uint32_t aWidth, uint32_t aHeight, uint32_t aFramesPerSecond, nsMainThreadPtrHandle& onSuccess, uint64_t aWindowId) : mCameraControl(aCameraControl) , mWidth(aWidth) , mHeight(aHeight) @@ -210,7 +210,7 @@ protected: uint32_t mWidth; uint32_t mHeight; uint32_t mFramesPerSecond; - nsCOMPtr mOnSuccessCb; + nsMainThreadPtrHandle mOnSuccessCb; uint64_t mWindowId; }; @@ -221,8 +221,8 @@ public: GetPreviewStreamTask(CameraControlImpl* aCameraControl, dom::CameraSize aSize, nsICameraPreviewStreamCallback* onSuccess, nsICameraErrorCallback* onError) : mSize(aSize) , mCameraControl(aCameraControl) - , mOnSuccessCb(onSuccess) - , mOnErrorCb(onError) + , mOnSuccessCb(new nsMainThreadPtrHolder(onSuccess)) + , mOnErrorCb(new nsMainThreadPtrHolder(onError)) { DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this); } @@ -236,7 +236,7 @@ public: { nsresult rv = mCameraControl->GetPreviewStreamImpl(this); - if (NS_FAILED(rv) && mOnErrorCb) { + if (NS_FAILED(rv) && mOnErrorCb.get()) { rv = NS_DispatchToMainThread(new CameraErrorResult(mOnErrorCb, NS_LITERAL_STRING("FAILURE"), mCameraControl->GetWindowId())); NS_ENSURE_SUCCESS(rv, rv); } @@ -245,8 +245,8 @@ public: dom::CameraSize mSize; nsRefPtr mCameraControl; - nsCOMPtr mOnSuccessCb; - nsCOMPtr mOnErrorCb; + nsMainThreadPtrHandle mOnSuccessCb; + nsMainThreadPtrHandle mOnErrorCb; }; // Return the autofocus status to JS. Runs on the main thread. @@ -255,7 +255,7 @@ class AutoFocusResult : public nsRunnable public: AutoFocusResult(bool aSuccess, nsICameraAutoFocusCallback* onSuccess, uint64_t aWindowId) : mSuccess(aSuccess) - , mOnSuccessCb(onSuccess) + , mOnSuccessCb(new nsMainThreadPtrHolder(onSuccess)) , mWindowId(aWindowId) { } @@ -265,7 +265,7 @@ public: { MOZ_ASSERT(NS_IsMainThread()); - if (mOnSuccessCb && nsDOMCameraManager::IsWindowStillActive(mWindowId)) { + if (mOnSuccessCb.get() && nsDOMCameraManager::IsWindowStillActive(mWindowId)) { mOnSuccessCb->HandleEvent(mSuccess); } return NS_OK; @@ -273,7 +273,7 @@ public: protected: bool mSuccess; - nsCOMPtr mOnSuccessCb; + nsMainThreadPtrHandle mOnSuccessCb; uint64_t mWindowId; }; @@ -283,8 +283,8 @@ class AutoFocusTask : public nsRunnable public: AutoFocusTask(CameraControlImpl* aCameraControl, nsICameraAutoFocusCallback* onSuccess, nsICameraErrorCallback* onError) : mCameraControl(aCameraControl) - , mOnSuccessCb(onSuccess) - , mOnErrorCb(onError) + , mOnSuccessCb(new nsMainThreadPtrHolder(onSuccess)) + , mOnErrorCb(new nsMainThreadPtrHolder(onError)) { DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this); } @@ -300,7 +300,7 @@ public: nsresult rv = mCameraControl->AutoFocusImpl(this); DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__); - if (NS_FAILED(rv) && mOnErrorCb) { + if (NS_FAILED(rv) && mOnErrorCb.get()) { rv = NS_DispatchToMainThread(new CameraErrorResult(mOnErrorCb, NS_LITERAL_STRING("FAILURE"), mCameraControl->GetWindowId())); NS_ENSURE_SUCCESS(rv, rv); } @@ -308,17 +308,19 @@ public: } nsRefPtr mCameraControl; - nsCOMPtr mOnSuccessCb; - nsCOMPtr mOnErrorCb; + nsMainThreadPtrHandle mOnSuccessCb; + nsMainThreadPtrHandle mOnErrorCb; }; // Return the captured picture to JS. Runs on the main thread. class TakePictureResult : public nsRunnable { public: - TakePictureResult(nsIDOMBlob* aImage, nsICameraTakePictureCallback* onSuccess, uint64_t aWindowId) - : mImage(aImage) - , mOnSuccessCb(onSuccess) + TakePictureResult(uint8_t* aData, uint64_t aLength, const nsAString& aMimeType, nsICameraTakePictureCallback* onSuccess, uint64_t aWindowId) + : mData(aData) + , mLength(aLength) + , mMimeType(aMimeType) + , mOnSuccessCb(new nsMainThreadPtrHolder(onSuccess)) , mWindowId(aWindowId) { DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this); @@ -334,16 +336,21 @@ public: MOZ_ASSERT(NS_IsMainThread()); DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this); - if (mOnSuccessCb && nsDOMCameraManager::IsWindowStillActive(mWindowId)) { - mOnSuccessCb->HandleEvent(mImage); + if (mOnSuccessCb.get() && nsDOMCameraManager::IsWindowStillActive(mWindowId)) { + nsCOMPtr image = new nsDOMMemoryFile(static_cast(mData), static_cast(mLength), mMimeType); + mOnSuccessCb->HandleEvent(image); + } else { + delete[] mData; } DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this); return NS_OK; } protected: - nsCOMPtr mImage; - nsCOMPtr mOnSuccessCb; + uint8_t* mData; + uint64_t mLength; + nsString mMimeType; + nsMainThreadPtrHandle mOnSuccessCb; uint64_t mWindowId; }; @@ -357,8 +364,8 @@ public: , mRotation(aRotation) , mFileFormat(aFileFormat) , mPosition(aPosition) - , mOnSuccessCb(onSuccess) - , mOnErrorCb(onError) + , mOnSuccessCb(new nsMainThreadPtrHolder(onSuccess)) + , mOnErrorCb(new nsMainThreadPtrHolder(onError)) { DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this); } @@ -374,7 +381,7 @@ public: nsresult rv = mCameraControl->TakePictureImpl(this); DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__); - if (NS_FAILED(rv) && mOnErrorCb) { + if (NS_FAILED(rv) && mOnErrorCb.get()) { rv = NS_DispatchToMainThread(new CameraErrorResult(mOnErrorCb, NS_LITERAL_STRING("FAILURE"), mCameraControl->GetWindowId())); NS_ENSURE_SUCCESS(rv, rv); } @@ -386,8 +393,8 @@ public: int32_t mRotation; nsString mFileFormat; dom::CameraPosition mPosition; - nsCOMPtr mOnSuccessCb; - nsCOMPtr mOnErrorCb; + nsMainThreadPtrHandle mOnSuccessCb; + nsMainThreadPtrHandle mOnErrorCb; }; // Return the result of starting recording. Runs on the main thread. @@ -395,7 +402,7 @@ class StartRecordingResult : public nsRunnable { public: StartRecordingResult(nsICameraStartRecordingCallback* onSuccess, uint64_t aWindowId) - : mOnSuccessCb(onSuccess) + : mOnSuccessCb(new nsMainThreadPtrHolder(onSuccess)) , mWindowId(aWindowId) { } @@ -405,14 +412,14 @@ public: { MOZ_ASSERT(NS_IsMainThread()); - if (mOnSuccessCb && nsDOMCameraManager::IsWindowStillActive(mWindowId)) { + if (mOnSuccessCb.get() && nsDOMCameraManager::IsWindowStillActive(mWindowId)) { mOnSuccessCb->HandleEvent(); } return NS_OK; } protected: - nsCOMPtr mOnSuccessCb; + nsMainThreadPtrHandle mOnSuccessCb; uint64_t mWindowId; }; @@ -425,8 +432,8 @@ public: , mOptions(aOptions) , mFolder(aFolder) , mFilename(aFilename) - , mOnSuccessCb(onSuccess) - , mOnErrorCb(onError) + , mOnSuccessCb(new nsMainThreadPtrHolder(onSuccess)) + , mOnErrorCb(new nsMainThreadPtrHolder(onError)) , mWindowId(aWindowId) { DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this); @@ -461,8 +468,8 @@ public: dom::CameraStartRecordingOptions mOptions; nsCOMPtr mFolder; nsString mFilename; - nsCOMPtr mOnSuccessCb; - nsCOMPtr mOnErrorCb; + nsMainThreadPtrHandle mOnSuccessCb; + nsMainThreadPtrHandle mOnErrorCb; uint64_t mWindowId; }; @@ -556,8 +563,8 @@ class GetPreviewStreamVideoModeResult : public nsRunnable { public: GetPreviewStreamVideoModeResult(nsIDOMMediaStream* aStream, nsICameraPreviewStreamCallback* onSuccess) - : mStream(aStream) - , mOnSuccessCb(onSuccess) + : mStream(new nsMainThreadPtrHolder(aStream)) + , mOnSuccessCb(new nsMainThreadPtrHolder(onSuccess)) { DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this); } @@ -571,15 +578,15 @@ public: { MOZ_ASSERT(NS_IsMainThread()); - if (mOnSuccessCb) { + if (mOnSuccessCb.get()) { mOnSuccessCb->HandleEvent(mStream); } return NS_OK; } protected: - nsCOMPtr mStream; - nsCOMPtr mOnSuccessCb; + nsMainThreadPtrHandle mStream; + nsMainThreadPtrHandle mOnSuccessCb; }; // Get the video mode preview stream. @@ -589,8 +596,8 @@ public: GetPreviewStreamVideoModeTask(CameraControlImpl* aCameraControl, dom::CameraRecorderOptions aOptions, nsICameraPreviewStreamCallback* onSuccess, nsICameraErrorCallback* onError) : mCameraControl(aCameraControl) , mOptions(aOptions) - , mOnSuccessCb(onSuccess) - , mOnErrorCb(onError) + , mOnSuccessCb(new nsMainThreadPtrHolder(onSuccess)) + , mOnErrorCb(new nsMainThreadPtrHolder(onError)) { } NS_IMETHOD Run() @@ -599,7 +606,7 @@ public: nsresult rv = mCameraControl->GetPreviewStreamVideoModeImpl(this); DOM_CAMERA_LOGI("%s:%d -- AFTER IMPL : rv = %d\n", __func__, __LINE__, rv); - if (NS_FAILED(rv) && mOnErrorCb) { + if (NS_FAILED(rv) && mOnErrorCb.get()) { rv = NS_DispatchToMainThread(new CameraErrorResult(mOnErrorCb, NS_LITERAL_STRING("FAILURE"), mCameraControl->GetWindowId())); NS_ENSURE_SUCCESS(rv, rv); } @@ -608,8 +615,8 @@ public: nsRefPtr mCameraControl; dom::CameraRecorderOptions mOptions; - nsCOMPtr mOnSuccessCb; - nsCOMPtr mOnErrorCb; + nsMainThreadPtrHandle mOnSuccessCb; + nsMainThreadPtrHandle mOnErrorCb; }; // Return the result of releasing the camera hardware. Runs on the main thread. @@ -617,7 +624,7 @@ class ReleaseHardwareResult : public nsRunnable { public: ReleaseHardwareResult(nsICameraReleaseCallback* onSuccess, uint64_t aWindowId) - : mOnSuccessCb(onSuccess) + : mOnSuccessCb(new nsMainThreadPtrHolder(onSuccess)) , mWindowId(aWindowId) { DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this); @@ -632,14 +639,14 @@ public: { MOZ_ASSERT(NS_IsMainThread()); - if (mOnSuccessCb && nsDOMCameraManager::IsWindowStillActive(mWindowId)) { + if (mOnSuccessCb.get() && nsDOMCameraManager::IsWindowStillActive(mWindowId)) { mOnSuccessCb->HandleEvent(); } return NS_OK; } protected: - nsCOMPtr mOnSuccessCb; + nsMainThreadPtrHandle mOnSuccessCb; uint64_t mWindowId; }; @@ -649,8 +656,8 @@ class ReleaseHardwareTask : public nsRunnable public: ReleaseHardwareTask(CameraControlImpl* aCameraControl, nsICameraReleaseCallback* onSuccess, nsICameraErrorCallback* onError) : mCameraControl(aCameraControl) - , mOnSuccessCb(onSuccess) - , mOnErrorCb(onError) + , mOnSuccessCb(new nsMainThreadPtrHolder(onSuccess)) + , mOnErrorCb(new nsMainThreadPtrHolder(onError)) { DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this); } @@ -666,7 +673,7 @@ public: nsresult rv = mCameraControl->ReleaseHardwareImpl(this); DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__); - if (NS_FAILED(rv) && mOnErrorCb) { + if (NS_FAILED(rv) && mOnErrorCb.get()) { rv = NS_DispatchToMainThread(new CameraErrorResult(mOnErrorCb, NS_LITERAL_STRING("FAILURE"), mCameraControl->GetWindowId())); NS_ENSURE_SUCCESS(rv, rv); } @@ -674,8 +681,8 @@ public: } nsRefPtr mCameraControl; - nsCOMPtr mOnSuccessCb; - nsCOMPtr mOnErrorCb; + nsMainThreadPtrHandle mOnSuccessCb; + nsMainThreadPtrHandle mOnErrorCb; }; // Report that the video recorder state has changed. @@ -683,7 +690,7 @@ class CameraRecorderStateChange : public nsRunnable { public: CameraRecorderStateChange(nsICameraRecorderStateChange* onStateChange, const nsString& aStateMsg, int32_t aStatus, int32_t aTrackNumber, uint64_t aWindowId) - : mOnStateChangeCb(onStateChange) + : mOnStateChangeCb(new nsMainThreadPtrHolder(onStateChange)) , mStateMsg(aStateMsg) , mStatus(aStatus) , mTrackNumber(aTrackNumber) @@ -694,7 +701,7 @@ public: { MOZ_ASSERT(NS_IsMainThread()); - if (mOnStateChangeCb && nsDOMCameraManager::IsWindowStillActive(mWindowId)) { + if (mOnStateChangeCb.get() && nsDOMCameraManager::IsWindowStillActive(mWindowId)) { // For now, just pass the state message and swallow mStatus and mTrackNumber mOnStateChangeCb->HandleStateChange(mStateMsg); } @@ -702,7 +709,7 @@ public: } protected: - nsCOMPtr mOnStateChangeCb; + nsMainThreadPtrHandle mOnStateChangeCb; const nsString mStateMsg; int32_t mStatus; int32_t mTrackNumber; diff --git a/dom/camera/GonkCameraControl.cpp b/dom/camera/GonkCameraControl.cpp index 3d9d61e874ce..f29e20a6ab90 100644 --- a/dom/camera/GonkCameraControl.cpp +++ b/dom/camera/GonkCameraControl.cpp @@ -623,7 +623,8 @@ nsGonkCameraControl::GetPreviewStreamImpl(GetPreviewStreamTask* aGetPreviewStrea SetPreviewSize(aGetPreviewStream->mSize.width, aGetPreviewStream->mSize.height); DOM_CAMERA_LOGI("picture preview: wanted %d x %d, got %d x %d (%d fps, format %d)\n", aGetPreviewStream->mSize.width, aGetPreviewStream->mSize.height, mWidth, mHeight, mFps, mFormat); - nsCOMPtr getPreviewStreamResult = new GetPreviewStreamResult(this, mWidth, mHeight, mFps, aGetPreviewStream->mOnSuccessCb, mWindowId); + nsMainThreadPtrHandle onSuccess = aGetPreviewStream->mOnSuccessCb; + nsCOMPtr getPreviewStreamResult = new GetPreviewStreamResult(this, mWidth, mHeight, mFps, onSuccess, mWindowId); return NS_DispatchToMainThread(getPreviewStreamResult); } @@ -679,16 +680,16 @@ nsGonkCameraControl::StopPreviewImpl(StopPreviewTask* aStopPreview) nsresult nsGonkCameraControl::AutoFocusImpl(AutoFocusTask* aAutoFocus) { - nsCOMPtr cb = mAutoFocusOnSuccessCb; - if (cb) { + nsMainThreadPtrHandle cb = mAutoFocusOnSuccessCb; + if (cb.get()) { /** * We already have a callback, so someone has already * called autoFocus() -- cancel it. */ mAutoFocusOnSuccessCb = nullptr; - nsCOMPtr ecb = mAutoFocusOnErrorCb; + nsMainThreadPtrHandle ecb = mAutoFocusOnErrorCb; mAutoFocusOnErrorCb = nullptr; - if (ecb) { + if (ecb.get()) { nsresult rv = NS_DispatchToMainThread(new CameraErrorResult(ecb, NS_LITERAL_STRING("CANCELLED"), mWindowId)); NS_ENSURE_SUCCESS(rv, rv); } @@ -747,16 +748,16 @@ nsGonkCameraControl::SetupThumbnail(uint32_t aPictureWidth, uint32_t aPictureHei nsresult nsGonkCameraControl::TakePictureImpl(TakePictureTask* aTakePicture) { - nsCOMPtr cb = mTakePictureOnSuccessCb; - if (cb) { + nsMainThreadPtrHandle cb = mTakePictureOnSuccessCb; + if (cb.get()) { /** * We already have a callback, so someone has already * called TakePicture() -- cancel it. */ mTakePictureOnSuccessCb = nullptr; - nsCOMPtr ecb = mTakePictureOnErrorCb; + nsMainThreadPtrHandle ecb = mTakePictureOnErrorCb; mTakePictureOnErrorCb = nullptr; - if (ecb) { + if (ecb.get()) { nsresult rv = NS_DispatchToMainThread(new CameraErrorResult(ecb, NS_LITERAL_STRING("CANCELLED"), mWindowId)); NS_ENSURE_SUCCESS(rv, rv); } @@ -976,8 +977,7 @@ nsGonkCameraControl::TakePictureComplete(uint8_t* aData, uint32_t aLength) memcpy(data, aData, aLength); // TODO: see bug 779144. - nsIDOMBlob* blob = new nsDOMMemoryFile(static_cast(data), static_cast(aLength), NS_LITERAL_STRING("image/jpeg")); - nsCOMPtr takePictureResult = new TakePictureResult(blob, mTakePictureOnSuccessCb, mWindowId); + nsCOMPtr takePictureResult = new TakePictureResult(data, aLength, NS_LITERAL_STRING("image/jpeg"), mTakePictureOnSuccessCb, mWindowId); /** * Remember to set these to null so that we don't hold any extra * references to our document's window. @@ -1335,7 +1335,7 @@ nsGonkCameraControl::ReleaseHardwareImpl(ReleaseHardwareTask* aReleaseHardware) // release the hardware handle GonkCameraHardware::ReleaseHandle(mHwHandle, true /* unregister */); - if (aReleaseHardware && aReleaseHardware->mOnSuccessCb) { + if (aReleaseHardware && aReleaseHardware->mOnSuccessCb.get()) { nsCOMPtr releaseHardwareResult = new ReleaseHardwareResult(aReleaseHardware->mOnSuccessCb, mWindowId); return NS_DispatchToMainThread(releaseHardwareResult); }