2012-07-31 21:49:59 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
2012-08-16 19:53:45 -07:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-07-31 21:49:59 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "base/basictypes.h"
|
|
|
|
#include "BluetoothPropertyContainer.h"
|
|
|
|
#include "BluetoothService.h"
|
2013-01-28 22:52:48 -08:00
|
|
|
#include "DOMRequest.h"
|
2013-08-12 01:32:53 -07:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2012-09-13 09:37:14 -07:00
|
|
|
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
|
2013-09-10 13:56:05 -07:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2012-07-31 21:49:59 -07:00
|
|
|
|
2014-01-09 09:39:36 -08:00
|
|
|
#include "js/Value.h"
|
|
|
|
|
2012-07-31 21:49:59 -07:00
|
|
|
USING_BLUETOOTH_NAMESPACE
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<mozilla::dom::DOMRequest>
|
2014-01-06 18:53:23 -08:00
|
|
|
BluetoothPropertyContainer::FirePropertyAlreadySet(nsPIDOMWindow* aOwner,
|
2013-08-12 01:32:53 -07:00
|
|
|
ErrorResult& aRv)
|
2012-07-31 21:49:59 -07:00
|
|
|
{
|
2013-01-28 22:52:48 -08:00
|
|
|
nsCOMPtr<nsIDOMRequestService> rs =
|
|
|
|
do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
|
2013-08-12 01:32:53 -07:00
|
|
|
if (!rs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2013-08-12 09:08:03 -07:00
|
|
|
}
|
2013-08-12 01:32:53 -07:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
nsRefPtr<mozilla::dom::DOMRequest> request = new DOMRequest(aOwner);
|
2014-01-09 09:39:36 -08:00
|
|
|
rs->FireSuccess(request, JS::UndefinedHandleValue);
|
2013-08-12 01:32:53 -07:00
|
|
|
|
|
|
|
return request.forget();
|
2012-07-31 21:49:59 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
already_AddRefed<mozilla::dom::DOMRequest>
|
2014-01-06 18:53:23 -08:00
|
|
|
BluetoothPropertyContainer::SetProperty(nsPIDOMWindow* aOwner,
|
2012-07-31 21:49:59 -07:00
|
|
|
const BluetoothNamedValue& aProperty,
|
2013-08-12 01:32:53 -07:00
|
|
|
ErrorResult& aRv)
|
2012-07-31 21:49:59 -07:00
|
|
|
{
|
2013-08-12 01:32:53 -07:00
|
|
|
nsRefPtr<mozilla::dom::DOMRequest> request = new DOMRequest(aOwner);
|
|
|
|
nsRefPtr<BluetoothReplyRunnable> task =
|
|
|
|
new BluetoothVoidReplyRunnable(request);
|
|
|
|
|
2012-07-31 21:49:59 -07:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
|
|
|
if (!bs) {
|
2013-09-13 15:51:00 -07:00
|
|
|
BT_WARNING("Bluetooth service not available!");
|
2013-08-12 01:32:53 -07:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2012-07-31 21:49:59 -07:00
|
|
|
}
|
2013-01-28 22:52:48 -08:00
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
nsresult rv = bs->SetProperty(mObjectType, aProperty, task);
|
2012-07-31 21:49:59 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2013-08-12 01:32:53 -07:00
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2012-07-31 21:49:59 -07:00
|
|
|
}
|
|
|
|
|
2013-08-12 01:32:53 -07:00
|
|
|
return request.forget();
|
2012-07-31 21:49:59 -07:00
|
|
|
}
|