1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/bluetooth/BluetoothPropertyContainer.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,59 @@ 1.4 +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "base/basictypes.h" 1.11 +#include "BluetoothPropertyContainer.h" 1.12 +#include "BluetoothService.h" 1.13 +#include "DOMRequest.h" 1.14 +#include "mozilla/ErrorResult.h" 1.15 +#include "mozilla/dom/bluetooth/BluetoothTypes.h" 1.16 +#include "nsServiceManagerUtils.h" 1.17 + 1.18 +#include "js/Value.h" 1.19 + 1.20 +USING_BLUETOOTH_NAMESPACE 1.21 + 1.22 +already_AddRefed<mozilla::dom::DOMRequest> 1.23 +BluetoothPropertyContainer::FirePropertyAlreadySet(nsPIDOMWindow* aOwner, 1.24 + ErrorResult& aRv) 1.25 +{ 1.26 + nsCOMPtr<nsIDOMRequestService> rs = 1.27 + do_GetService(DOMREQUEST_SERVICE_CONTRACTID); 1.28 + if (!rs) { 1.29 + aRv.Throw(NS_ERROR_FAILURE); 1.30 + return nullptr; 1.31 + } 1.32 + 1.33 + nsRefPtr<mozilla::dom::DOMRequest> request = new DOMRequest(aOwner); 1.34 + rs->FireSuccess(request, JS::UndefinedHandleValue); 1.35 + 1.36 + return request.forget(); 1.37 +} 1.38 + 1.39 +already_AddRefed<mozilla::dom::DOMRequest> 1.40 +BluetoothPropertyContainer::SetProperty(nsPIDOMWindow* aOwner, 1.41 + const BluetoothNamedValue& aProperty, 1.42 + ErrorResult& aRv) 1.43 +{ 1.44 + nsRefPtr<mozilla::dom::DOMRequest> request = new DOMRequest(aOwner); 1.45 + nsRefPtr<BluetoothReplyRunnable> task = 1.46 + new BluetoothVoidReplyRunnable(request); 1.47 + 1.48 + BluetoothService* bs = BluetoothService::Get(); 1.49 + if (!bs) { 1.50 + BT_WARNING("Bluetooth service not available!"); 1.51 + aRv.Throw(NS_ERROR_FAILURE); 1.52 + return nullptr; 1.53 + } 1.54 + 1.55 + nsresult rv = bs->SetProperty(mObjectType, aProperty, task); 1.56 + if (NS_FAILED(rv)) { 1.57 + aRv.Throw(rv); 1.58 + return nullptr; 1.59 + } 1.60 + 1.61 + return request.forget(); 1.62 +}