michael@0: /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "base/basictypes.h" michael@0: #include "BluetoothPropertyContainer.h" michael@0: #include "BluetoothService.h" michael@0: #include "DOMRequest.h" michael@0: #include "mozilla/ErrorResult.h" michael@0: #include "mozilla/dom/bluetooth/BluetoothTypes.h" michael@0: #include "nsServiceManagerUtils.h" michael@0: michael@0: #include "js/Value.h" michael@0: michael@0: USING_BLUETOOTH_NAMESPACE michael@0: michael@0: already_AddRefed michael@0: BluetoothPropertyContainer::FirePropertyAlreadySet(nsPIDOMWindow* aOwner, michael@0: ErrorResult& aRv) michael@0: { michael@0: nsCOMPtr rs = michael@0: do_GetService(DOMREQUEST_SERVICE_CONTRACTID); michael@0: if (!rs) { michael@0: aRv.Throw(NS_ERROR_FAILURE); michael@0: return nullptr; michael@0: } michael@0: michael@0: nsRefPtr request = new DOMRequest(aOwner); michael@0: rs->FireSuccess(request, JS::UndefinedHandleValue); michael@0: michael@0: return request.forget(); michael@0: } michael@0: michael@0: already_AddRefed michael@0: BluetoothPropertyContainer::SetProperty(nsPIDOMWindow* aOwner, michael@0: const BluetoothNamedValue& aProperty, michael@0: ErrorResult& aRv) michael@0: { michael@0: nsRefPtr request = new DOMRequest(aOwner); michael@0: nsRefPtr task = michael@0: new BluetoothVoidReplyRunnable(request); michael@0: michael@0: BluetoothService* bs = BluetoothService::Get(); michael@0: if (!bs) { michael@0: BT_WARNING("Bluetooth service not available!"); michael@0: aRv.Throw(NS_ERROR_FAILURE); michael@0: return nullptr; michael@0: } michael@0: michael@0: nsresult rv = bs->SetProperty(mObjectType, aProperty, task); michael@0: if (NS_FAILED(rv)) { michael@0: aRv.Throw(rv); michael@0: return nullptr; michael@0: } michael@0: michael@0: return request.forget(); michael@0: }