NS_IMETHOD Handle(const nsAString& aName, JS::Handle<JS::Value> aResult) { RefPtr<AudioManager> audioManager = AudioManager::GetInstance(); MOZ_ASSERT(audioManager); for (uint32_t idx = 0; idx < MOZ_ARRAY_LENGTH(gVolumeData); ++idx) { NS_ConvertASCIItoUTF16 volumeType(gVolumeData[idx].mChannelName); if (StringBeginsWith(aName, volumeType)) { uint32_t device = GetDeviceFromSettingName(aName); MOZ_ASSERT(device != AUDIO_DEVICE_NONE); if (aResult.isInt32()) { int32_t stream = gVolumeData[idx].mStreamType; uint32_t volIndex = aResult.toInt32(); nsresult rv = audioManager->ValidateVolumeIndex(stream, volIndex); if (NS_WARN_IF(NS_FAILED(rv))) { mPromiseHolder.Reject("Error : invalid volume index.", __func__); return rv; } audioManager->SetStreamVolumeForDevice(stream, volIndex, device); } if (++mInitCounter == MOZ_ARRAY_LENGTH(kAudioDeviceInfos) * MOZ_ARRAY_LENGTH(gVolumeData)) { mPromiseHolder.Resolve(true, __func__); } return NS_OK; } } mPromiseHolder.Reject("Error : unexpected audio init event.", __func__); return NS_OK; }
NS_IMETHODIMP MobileMessageManager::Delete(JS::Handle<JS::Value> aParam, JSContext* aCx, nsIDOMDOMRequest** aRequest) { // We expect Int32, SmsMessage, MmsMessage, Int32[], SmsMessage[], MmsMessage[] if (!aParam.isObject() && !aParam.isInt32()) { return NS_ERROR_INVALID_ARG; } nsresult rv = NS_OK; int32_t id, *idArray; uint32_t size; if (aParam.isInt32()) { // Single Integer Message ID id = aParam.toInt32(); size = 1; idArray = &id; } else if (!JS_IsArrayObject(aCx, &aParam.toObject())) { // Single SmsMessage/MmsMessage object rv = GetMessageId(aCx, aParam, &id); NS_ENSURE_SUCCESS(rv, rv); size = 1; idArray = &id; } else { // Int32[], SmsMessage[], or MmsMessage[] JS::Rooted<JSObject*> ids(aCx, &aParam.toObject()); JS_ALWAYS_TRUE(JS_GetArrayLength(aCx, ids, &size)); nsAutoArrayPtr<int32_t> idAutoArray(new int32_t[size]); JS::Rooted<JS::Value> idJsValue(aCx); for (uint32_t i = 0; i < size; i++) { if (!JS_GetElement(aCx, ids, i, &idJsValue)) { return NS_ERROR_INVALID_ARG; } if (idJsValue.isInt32()) { idAutoArray[i] = idJsValue.toInt32(); } else if (idJsValue.isObject()) { rv = GetMessageId(aCx, idJsValue, &id); NS_ENSURE_SUCCESS(rv, rv); idAutoArray[i] = id; } } idArray = idAutoArray.forget(); } nsCOMPtr<nsIMobileMessageDatabaseService> dbService = do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID); NS_ENSURE_TRUE(dbService, NS_ERROR_FAILURE); nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner()); nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request); rv = dbService->DeleteMessage(idArray, size, msgCallback); NS_ENSURE_SUCCESS(rv, rv); request.forget(aRequest); return NS_OK; }