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