--- a/dom/camera/DOMCameraControl.cpp
+++ b/dom/camera/DOMCameraControl.cpp
@@ -126,54 +126,16 @@ StartRecordingHelper::HandleEvent(nsIDOM
nsString eventType;
aEvent->GetType(eventType);
mState = eventType.EqualsLiteral("success");
return NS_OK;
}
NS_IMPL_ISUPPORTS(mozilla::StartRecordingHelper, nsIDOMEventListener)
-class mozilla::RecorderPosterHelper : public nsIDOMEventListener
-{
-public:
- NS_DECL_ISUPPORTS
- NS_DECL_NSIDOMEVENTLISTENER
-
- explicit RecorderPosterHelper(nsDOMCameraControl* aDOMCameraControl)
- : mDOMCameraControl(aDOMCameraControl)
- , mState(CameraControlListener::kPosterFailed)
- {
- MOZ_COUNT_CTOR(RecorderPosterHelper);
- }
-
-protected:
- virtual ~RecorderPosterHelper()
- {
- MOZ_COUNT_DTOR(RecorderPosterHelper);
- mDOMCameraControl->OnRecorderStateChange(mState, 0, 0);
- }
-
-protected:
- nsRefPtr<nsDOMCameraControl> mDOMCameraControl;
- CameraControlListener::RecorderState mState;
-};
-
-NS_IMETHODIMP
-RecorderPosterHelper::HandleEvent(nsIDOMEvent* aEvent)
-{
- nsString eventType;
- aEvent->GetType(eventType);
- if (eventType.EqualsLiteral("success")) {
- mState = CameraControlListener::kPosterCreated;
- }
- return NS_OK;
-}
-
-NS_IMPL_ISUPPORTS(mozilla::RecorderPosterHelper, nsIDOMEventListener)
-
nsDOMCameraControl::DOMCameraConfiguration::DOMCameraConfiguration()
: CameraConfiguration()
, mMaxFocusAreas(0)
, mMaxMeteringAreas(0)
{
MOZ_COUNT_CTOR(nsDOMCameraControl::DOMCameraConfiguration);
}
@@ -792,28 +754,21 @@ nsDOMCameraControl::StartRecording(const
{
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
nsRefPtr<Promise> promise = CreatePromise(aRv);
if (aRv.Failed()) {
return nullptr;
}
- // Must supply both the poster path and storage area or neither
- if (aOptions.mPosterFilepath.IsEmpty() ==
- static_cast<bool>(aOptions.mPosterStorageArea.get())) {
- promise->MaybeReject(NS_ERROR_ILLEGAL_VALUE);
- return promise.forget();
- }
-
// If we are trying to start recording, already recording or are still
// waiting for a poster to be created/fail, we need to wait
if (mStartRecordingPromise || mRecording ||
mRecordingStoppedDeferred ||
- !mOptions.mPosterFilepath.IsEmpty()) {
+ mOptions.mCreatePoster) {
promise->MaybeReject(NS_ERROR_IN_PROGRESS);
return promise.forget();
}
aRv = NotifyRecordingStatusChange(NS_LITERAL_STRING("starting"));
if (aRv.Failed()) {
return nullptr;
}
@@ -846,26 +801,25 @@ nsDOMCameraControl::OnCreatedFileDescrip
nsresult rv = NS_ERROR_FAILURE;
if (!mCameraControl) {
rv = NS_ERROR_NOT_AVAILABLE;
} else if (!mRecording) {
// Race condition where StopRecording comes in before we issue
// the start recording request to Gonk
rv = NS_ERROR_ABORT;
- mOptions.mPosterFilepath.Truncate();
- mOptions.mPosterStorageArea = nullptr;
+ mOptions.mCreatePoster = false;
} else if (aSucceeded && mDSFileDescriptor->mFileDescriptor.IsValid()) {
ICameraControl::StartRecordingOptions o;
o.rotation = mOptions.mRotation;
o.maxFileSizeBytes = mOptions.mMaxFileSizeBytes;
o.maxVideoLengthMs = mOptions.mMaxVideoLengthMs;
o.autoEnableLowLightTorch = mOptions.mAutoEnableLowLightTorch;
- o.createPoster = !mOptions.mPosterFilepath.IsEmpty();
+ o.createPoster = mOptions.mCreatePoster;
rv = mCameraControl->StartRecording(mDSFileDescriptor.get(), &o);
if (NS_SUCCEEDED(rv)) {
return;
}
}
OnUserError(CameraControlListener::kInStartRecording, rv);
@@ -1341,41 +1295,33 @@ nsDOMCameraControl::OnPreviewStateChange
DispatchPreviewStateEvent(aState);
}
void
nsDOMCameraControl::OnPoster(BlobImpl* aPoster)
{
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
MOZ_ASSERT(NS_IsMainThread());
- MOZ_ASSERT(!mOptions.mPosterFilepath.IsEmpty());
-
- // Destructor will trigger an error notification if any step fails
- nsRefPtr<RecorderPosterHelper> listener = new RecorderPosterHelper(this);
- if (NS_WARN_IF(!aPoster)) {
- return;
- }
+ MOZ_ASSERT(mOptions.mCreatePoster);
nsRefPtr<Blob> blob = Blob::Create(GetParentObject(), aPoster);
if (NS_WARN_IF(!blob)) {
+ OnRecorderStateChange(CameraControlListener::kPosterFailed, 0, 0);
return;
}
- if (NS_WARN_IF(!mOptions.mPosterStorageArea)) {
- return;
- }
+ BlobEventInit eventInit;
+ eventInit.mData = blob;
- ErrorResult rv;
- nsRefPtr<DOMRequest> request =
- mOptions.mPosterStorageArea->AddNamed(blob, mOptions.mPosterFilepath, rv);
- if (NS_WARN_IF(rv.Failed())) {
- return;
- }
+ nsRefPtr<BlobEvent> event = BlobEvent::Constructor(this,
+ NS_LITERAL_STRING("poster"),
+ eventInit);
- RegisterStorageRequestEvents(request, listener);
+ DispatchTrustedEvent(event);
+ OnRecorderStateChange(CameraControlListener::kPosterCreated, 0, 0);
}
void
nsDOMCameraControl::OnRecorderStateChange(CameraControlListener::RecorderState aState,
int32_t aArg, int32_t aTrackNum)
{
// For now, we do nothing with 'aStatus' and 'aTrackNum'.
DOM_CAMERA_LOGT("%s:%d : this=%p, state=%u\n", __func__, __LINE__, this, aState);
@@ -1392,35 +1338,33 @@ nsDOMCameraControl::OnRecorderStateChang
promise->MaybeResolve(JS::UndefinedHandleValue);
}
state = NS_LITERAL_STRING("Started");
}
break;
case CameraControlListener::kRecorderStopped:
- if (!mOptions.mPosterFilepath.IsEmpty()) {
+ if (mOptions.mCreatePoster) {
mRecordingStoppedDeferred = true;
return;
}
NotifyRecordingStatusChange(NS_LITERAL_STRING("shutdown"));
state = NS_LITERAL_STRING("Stopped");
break;
case CameraControlListener::kPosterCreated:
state = NS_LITERAL_STRING("PosterCreated");
- mOptions.mPosterFilepath.Truncate();
- mOptions.mPosterStorageArea = nullptr;
+ mOptions.mCreatePoster = false;
break;
case CameraControlListener::kPosterFailed:
state = NS_LITERAL_STRING("PosterFailed");
- mOptions.mPosterFilepath.Truncate();
- mOptions.mPosterStorageArea = nullptr;
+ mOptions.mCreatePoster = false;
break;
case CameraControlListener::kRecorderPaused:
state = NS_LITERAL_STRING("Paused");
break;
case CameraControlListener::kRecorderResumed:
state = NS_LITERAL_STRING("Resumed");
@@ -1454,17 +1398,17 @@ nsDOMCameraControl::OnRecorderStateChang
default:
MOZ_ASSERT_UNREACHABLE("Unanticipated video recorder error");
return;
}
DispatchStateEvent(NS_LITERAL_STRING("recorderstatechange"), state);
- if (mRecordingStoppedDeferred && mOptions.mPosterFilepath.IsEmpty()) {
+ if (mRecordingStoppedDeferred && !mOptions.mCreatePoster) {
mRecordingStoppedDeferred = false;
OnRecorderStateChange(CameraControlListener::kRecorderStopped, 0, 0);
}
}
void
nsDOMCameraControl::OnConfigurationChange(DOMCameraConfiguration* aConfiguration)
{