void SpeechRecognition::ProcessTestEventRequest(nsISupports* aSubject, const nsAString& aEventName) { if (aEventName.EqualsLiteral("EVENT_START")) { ErrorResult err; Start(err); } else if (aEventName.EqualsLiteral("EVENT_STOP")) { Stop(); } else if (aEventName.EqualsLiteral("EVENT_ABORT")) { Abort(); } else if (aEventName.EqualsLiteral("EVENT_AUDIO_ERROR")) { DispatchError(SpeechRecognition::EVENT_AUDIO_ERROR, SpeechRecognitionErrorCode::Audio_capture, // TODO different codes? NS_LITERAL_STRING("AUDIO_ERROR test event")); } else if (aEventName.EqualsLiteral("EVENT_AUDIO_DATA")) { StartRecording(static_cast<DOMMediaStream*>(aSubject)); } else { NS_ASSERTION(mTestConfig.mFakeRecognitionService, "Got request for fake recognition service event, but " TEST_PREFERENCE_FAKE_RECOGNITION_SERVICE " is unset"); // let the fake recognition service handle the request } return; }
NS_IMETHODIMP FileIOObject::OnStopRequest(nsIRequest* aRequest, nsISupports* aContext, nsresult aStatus) { // If we're here as a result of a call from Abort(), // simply ignore the request. if (aRequest != mChannel) return NS_OK; // Cancel the progress event timer ClearProgressEventTimer(); // FileIOObject must be in DONE stage after an operation mReadyState = 2; nsString successEvent, termEvent; nsresult rv = DoOnStopRequest(aRequest, aContext, aStatus, successEvent, termEvent); NS_ENSURE_SUCCESS(rv, rv); // Set the status field as appropriate if (NS_FAILED(aStatus)) { DispatchError(aStatus, termEvent); return NS_OK; } // Dispatch event to signify end of a successful operation DispatchProgressEvent(successEvent); DispatchProgressEvent(termEvent); return NS_OK; }
void BluetoothDaemonAvrcpInterface::Init( BluetoothAvrcpNotificationHandler* aNotificationHandler, BluetoothAvrcpResultHandler* aRes) { MOZ_ASSERT(mModule); // Set notification handler _before_ registering the module. It could // happen that we receive notifications, before the result handler runs. mModule->SetNotificationHandler(aNotificationHandler); InitResultHandler* res; if (aRes) { res = new InitResultHandler(aRes); } else { // We don't need a result handler if the caller is not interested. res = nullptr; } nsresult rv = mModule->RegisterModule( BluetoothDaemonAvrcpModule::SERVICE_ID, BluetoothDaemonAvrcpModule::MAX_NUM_CLIENTS, 0x00, res); if (NS_FAILED(rv) && aRes) { DispatchError(aRes, rv); } }
nsresult FileReader::OnLoadEnd(nsresult aStatus) { // Cancel the progress event timer ClearProgressEventTimer(); // FileReader must be in DONE stage after an operation mReadyState = DONE; nsAutoString successEvent, termEvent; nsresult rv = DoOnLoadEnd(aStatus, successEvent, termEvent); NS_ENSURE_SUCCESS(rv, rv); // Set the status field as appropriate if (NS_FAILED(aStatus)) { DispatchError(aStatus, termEvent); return NS_OK; } // Dispatch event to signify end of a successful operation DispatchProgressEvent(successEvent); DispatchProgressEvent(termEvent); return NS_OK; }
void BluetoothDaemonAvrcpInterface::ListPlayerAppValueRsp( int aNumVal, uint8_t* aPVals, BluetoothAvrcpResultHandler* aRes) { MOZ_ASSERT(mModule); nsresult rv = mModule->ListPlayerAppValueRspCmd(aNumVal, aPVals, aRes); if (NS_FAILED(rv)) { DispatchError(aRes, rv); } }
void BluetoothDaemonAvrcpInterface::DispatchError( BluetoothAvrcpResultHandler* aRes, nsresult aRv) { BluetoothStatus status; if (NS_WARN_IF(NS_FAILED(Convert(aRv, status)))) { status = STATUS_FAIL; } DispatchError(aRes, status); }
void BluetoothDaemonAvrcpInterface::SetVolume( uint8_t aVolume, BluetoothAvrcpResultHandler* aRes) { MOZ_ASSERT(mModule); nsresult rv = mModule->SetVolumeCmd(aVolume, aRes); if (NS_FAILED(rv)) { DispatchError(aRes, rv); } }
void BluetoothDaemonAvrcpInterface::SetPlayerAppValueRsp( BluetoothAvrcpStatus aRspStatus, BluetoothAvrcpResultHandler* aRes) { MOZ_ASSERT(mModule); nsresult rv = mModule->SetPlayerAppValueRspCmd(aRspStatus, aRes); if (NS_FAILED(rv)) { DispatchError(aRes, rv); } }
void BluetoothDaemonAvrcpInterface::GetElementAttrRsp( uint8_t aNumAttr, const BluetoothAvrcpElementAttribute* aAttr, BluetoothAvrcpResultHandler* aRes) { MOZ_ASSERT(mModule); nsresult rv = mModule->GetElementAttrRspCmd(aNumAttr, aAttr, aRes); if (NS_FAILED(rv)) { DispatchError(aRes, rv); } }
void BluetoothDaemonAvrcpInterface::ListPlayerAppAttrRsp( int aNumAttr, const BluetoothAvrcpPlayerAttribute* aPAttrs, BluetoothAvrcpResultHandler* aRes) { MOZ_ASSERT(mModule); nsresult rv = mModule->ListPlayerAppAttrRspCmd(aNumAttr, aPAttrs, aRes); if (NS_FAILED(rv)) { DispatchError(aRes, rv); } }
void BluetoothDaemonAvrcpInterface::Cleanup( BluetoothAvrcpResultHandler* aRes) { MOZ_ASSERT(mModule); nsresult rv = mModule->UnregisterModule( BluetoothDaemonAvrcpModule::SERVICE_ID, new CleanupResultHandler(mModule, aRes)); if (NS_FAILED(rv)) { DispatchError(aRes, rv); } }
void BluetoothDaemonAvrcpInterface::GetPlayerAppValueRsp( uint8_t aNumAttrs, const uint8_t* aIds, const uint8_t* aValues, BluetoothAvrcpResultHandler* aRes) { MOZ_ASSERT(mModule); nsresult rv = mModule->GetPlayerAppValueRspCmd(aNumAttrs, aIds, aValues, aRes); if (NS_FAILED(rv)) { DispatchError(aRes, rv); } }
void BluetoothDaemonAvrcpInterface::GetPlayStatusRsp( ControlPlayStatus aPlayStatus, uint32_t aSongLen, uint32_t aSongPos, BluetoothAvrcpResultHandler* aRes) { MOZ_ASSERT(mModule); nsresult rv = mModule->GetPlayStatusRspCmd(aPlayStatus, aSongLen, aSongPos, aRes); if (NS_FAILED(rv)) { DispatchError(aRes, rv); } }
void BluetoothDaemonAvrcpInterface::RegisterNotificationRsp( BluetoothAvrcpEvent aEvent, BluetoothAvrcpNotification aType, const BluetoothAvrcpNotificationParam& aParam, BluetoothAvrcpResultHandler* aRes) { MOZ_ASSERT(mModule); nsresult rv = mModule->RegisterNotificationRspCmd(aEvent, aType, aParam, aRes); if (NS_FAILED(rv)) { DispatchError(aRes, rv); } }
void SpeechRecognition::ProcessTestEventRequest(nsISupports* aSubject, const nsAString& aEventName) { if (aEventName.EqualsLiteral("EVENT_ABORT")) { Abort(); } else if (aEventName.EqualsLiteral("EVENT_AUDIO_ERROR")) { DispatchError(SpeechRecognition::EVENT_AUDIO_ERROR, SpeechRecognitionErrorCode::Audio_capture, // TODO different codes? NS_LITERAL_STRING("AUDIO_ERROR test event")); } else { NS_ASSERTION(MediaPrefs::WebSpeechFakeRecognitionService(), "Got request for fake recognition service event, but " TEST_PREFERENCE_FAKE_RECOGNITION_SERVICE " is unset"); // let the fake recognition service handle the request } }
void SpeechRecognition::ProcessTestEventRequest(nsISupports* aSubject, const nsAString& aEventName) { if (aEventName.EqualsLiteral("EVENT_ABORT")) { Abort(); } else if (aEventName.EqualsLiteral("EVENT_AUDIO_ERROR")) { DispatchError( SpeechRecognition::EVENT_AUDIO_ERROR, SpeechRecognitionErrorCode::Audio_capture, // TODO different codes? NS_LITERAL_STRING("AUDIO_ERROR test event")); } else { NS_ASSERTION(StaticPrefs::MediaWebspeechTextFakeRecognitionService(), "Got request for fake recognition service event, but " "media.webspeech.test.fake_recognition_service is unset"); // let the fake recognition service handle the request } }
NS_IMETHODIMP SpeechRecognition::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData) { MOZ_ASSERT(NS_IsMainThread(), "Observer invoked off the main thread"); if (!strcmp(aTopic, NS_TIMER_CALLBACK_TOPIC) && StateBetween(STATE_IDLE, STATE_WAITING_FOR_SPEECH)) { DispatchError(SpeechRecognition::EVENT_AUDIO_ERROR, SpeechRecognitionErrorCode::No_speech, NS_LITERAL_STRING("No speech detected (timeout)")); } else if (!strcmp(aTopic, SPEECH_RECOGNITION_TEST_END_TOPIC)) { nsCOMPtr<nsIObserverService> obs = services::GetObserverService(); obs->RemoveObserver(this, SPEECH_RECOGNITION_TEST_EVENT_REQUEST_TOPIC); obs->RemoveObserver(this, SPEECH_RECOGNITION_TEST_END_TOPIC); } else if (mTestConfig.mFakeFSMEvents && !strcmp(aTopic, SPEECH_RECOGNITION_TEST_EVENT_REQUEST_TOPIC)) { ProcessTestEventRequest(aSubject, nsDependentString(aData)); } return NS_OK; }
nsresult FileReader::DoOnLoadEnd(nsresult aStatus, nsAString& aSuccessEvent, nsAString& aTerminationEvent) { // Make sure we drop all the objects that could hold files open now. nsCOMPtr<nsIAsyncInputStream> stream; mAsyncStream.swap(stream); RefPtr<Blob> blob; mBlob.swap(blob); // Clear out the data if necessary if (NS_FAILED(aStatus)) { FreeFileData(); return NS_OK; } // In case we read a different number of bytes, we can assume that the // underlying storage has changed. We should not continue. if (mDataLen != mTotal) { DispatchError(NS_ERROR_FAILURE, aTerminationEvent); FreeFileData(); return NS_ERROR_FAILURE; } aSuccessEvent = NS_LITERAL_STRING(LOAD_STR); aTerminationEvent = NS_LITERAL_STRING(LOADEND_STR); nsresult rv = NS_OK; switch (mDataFormat) { case FILE_AS_ARRAYBUFFER: { AutoJSAPI jsapi; nsCOMPtr<nsIGlobalObject> globalObject; if (NS_IsMainThread()) { globalObject = do_QueryInterface(GetParentObject()); } else { MOZ_ASSERT(mWorkerPrivate); MOZ_ASSERT(mBusyCount); globalObject = mWorkerPrivate->GlobalScope(); } if (!globalObject || !jsapi.Init(globalObject)) { FreeFileData(); return NS_ERROR_FAILURE; } RootResultArrayBuffer(); mResultArrayBuffer = JS_NewArrayBufferWithContents(jsapi.cx(), mDataLen, mFileData); if (!mResultArrayBuffer) { JS_ClearPendingException(jsapi.cx()); rv = NS_ERROR_OUT_OF_MEMORY; } else { mFileData = nullptr; // Transfer ownership } break; } case FILE_AS_BINARY: break; //Already accumulated mResult case FILE_AS_TEXT: if (!mFileData) { if (mDataLen) { rv = NS_ERROR_OUT_OF_MEMORY; break; } rv = GetAsText(blob, mCharset, "", mDataLen, mResult); break; } rv = GetAsText(blob, mCharset, mFileData, mDataLen, mResult); break; case FILE_AS_DATAURL: rv = GetAsDataURL(blob, mFileData, mDataLen, mResult); break; } mResult.SetIsVoid(false); FreeFileData(); return rv; }
// Throws an exception corresponding to the given Win32 Error code. // GUID is the CLSID of the component throwing error. HRESULT CCOMError::DispatchWin32Error(DWORD error, REFCLSID clsid, LPCTSTR source, DWORD helpContext, LPCTSTR helpFileName) { // Dispatch the requested error message return DispatchError(HRESULT_FROM_WIN32(error), clsid, source, NULL, helpContext, helpFileName); }