|
1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ |
|
2 /* vim: set ts=2 et sw=2 tw=80: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #include "base/basictypes.h" |
|
8 #include "BluetoothPropertyContainer.h" |
|
9 #include "BluetoothService.h" |
|
10 #include "DOMRequest.h" |
|
11 #include "mozilla/ErrorResult.h" |
|
12 #include "mozilla/dom/bluetooth/BluetoothTypes.h" |
|
13 #include "nsServiceManagerUtils.h" |
|
14 |
|
15 #include "js/Value.h" |
|
16 |
|
17 USING_BLUETOOTH_NAMESPACE |
|
18 |
|
19 already_AddRefed<mozilla::dom::DOMRequest> |
|
20 BluetoothPropertyContainer::FirePropertyAlreadySet(nsPIDOMWindow* aOwner, |
|
21 ErrorResult& aRv) |
|
22 { |
|
23 nsCOMPtr<nsIDOMRequestService> rs = |
|
24 do_GetService(DOMREQUEST_SERVICE_CONTRACTID); |
|
25 if (!rs) { |
|
26 aRv.Throw(NS_ERROR_FAILURE); |
|
27 return nullptr; |
|
28 } |
|
29 |
|
30 nsRefPtr<mozilla::dom::DOMRequest> request = new DOMRequest(aOwner); |
|
31 rs->FireSuccess(request, JS::UndefinedHandleValue); |
|
32 |
|
33 return request.forget(); |
|
34 } |
|
35 |
|
36 already_AddRefed<mozilla::dom::DOMRequest> |
|
37 BluetoothPropertyContainer::SetProperty(nsPIDOMWindow* aOwner, |
|
38 const BluetoothNamedValue& aProperty, |
|
39 ErrorResult& aRv) |
|
40 { |
|
41 nsRefPtr<mozilla::dom::DOMRequest> request = new DOMRequest(aOwner); |
|
42 nsRefPtr<BluetoothReplyRunnable> task = |
|
43 new BluetoothVoidReplyRunnable(request); |
|
44 |
|
45 BluetoothService* bs = BluetoothService::Get(); |
|
46 if (!bs) { |
|
47 BT_WARNING("Bluetooth service not available!"); |
|
48 aRv.Throw(NS_ERROR_FAILURE); |
|
49 return nullptr; |
|
50 } |
|
51 |
|
52 nsresult rv = bs->SetProperty(mObjectType, aProperty, task); |
|
53 if (NS_FAILED(rv)) { |
|
54 aRv.Throw(rv); |
|
55 return nullptr; |
|
56 } |
|
57 |
|
58 return request.forget(); |
|
59 } |