2012-08-01 08:49:59 +04:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
2012-08-17 06:53:45 +04:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-08-01 08:49:59 +04: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-29 10:52:48 +04:00
|
|
|
#include "DOMRequest.h"
|
2013-08-12 12:32:53 +04:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2012-09-13 20:37:14 +04:00
|
|
|
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
|
2013-09-11 00:56:05 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2012-08-01 08:49:59 +04:00
|
|
|
|
2014-01-09 21:39:36 +04:00
|
|
|
#include "js/Value.h"
|
|
|
|
|
2012-08-01 08:49:59 +04:00
|
|
|
USING_BLUETOOTH_NAMESPACE
|
|
|
|
|
2013-08-12 12:32:53 +04:00
|
|
|
already_AddRefed<mozilla::dom::DOMRequest>
|
2014-01-07 06:53:23 +04:00
|
|
|
BluetoothPropertyContainer::FirePropertyAlreadySet(nsPIDOMWindow* aOwner,
|
2013-08-12 12:32:53 +04:00
|
|
|
ErrorResult& aRv)
|
2012-08-01 08:49:59 +04:00
|
|
|
{
|
2013-01-29 10:52:48 +04:00
|
|
|
nsCOMPtr<nsIDOMRequestService> rs =
|
|
|
|
do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
|
2013-08-12 12:32:53 +04:00
|
|
|
if (!rs) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2013-08-12 20:08:03 +04:00
|
|
|
}
|
2013-08-12 12:32:53 +04:00
|
|
|
|
2013-08-12 12:32:53 +04:00
|
|
|
nsRefPtr<mozilla::dom::DOMRequest> request = new DOMRequest(aOwner);
|
2014-01-09 21:39:36 +04:00
|
|
|
rs->FireSuccess(request, JS::UndefinedHandleValue);
|
2013-08-12 12:32:53 +04:00
|
|
|
|
|
|
|
return request.forget();
|
2012-08-01 08:49:59 +04:00
|
|
|
}
|
|
|
|
|
2013-08-12 12:32:53 +04:00
|
|
|
already_AddRefed<mozilla::dom::DOMRequest>
|
2014-01-07 06:53:23 +04:00
|
|
|
BluetoothPropertyContainer::SetProperty(nsPIDOMWindow* aOwner,
|
2012-08-01 08:49:59 +04:00
|
|
|
const BluetoothNamedValue& aProperty,
|
2013-08-12 12:32:53 +04:00
|
|
|
ErrorResult& aRv)
|
2012-08-01 08:49:59 +04:00
|
|
|
{
|
2013-08-12 12:32:53 +04:00
|
|
|
nsRefPtr<mozilla::dom::DOMRequest> request = new DOMRequest(aOwner);
|
|
|
|
nsRefPtr<BluetoothReplyRunnable> task =
|
|
|
|
new BluetoothVoidReplyRunnable(request);
|
|
|
|
|
2012-08-01 08:49:59 +04:00
|
|
|
BluetoothService* bs = BluetoothService::Get();
|
|
|
|
if (!bs) {
|
2013-09-14 02:51:00 +04:00
|
|
|
BT_WARNING("Bluetooth service not available!");
|
2013-08-12 12:32:53 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2012-08-01 08:49:59 +04:00
|
|
|
}
|
2013-01-29 10:52:48 +04:00
|
|
|
|
2013-08-12 12:32:53 +04:00
|
|
|
nsresult rv = bs->SetProperty(mObjectType, aProperty, task);
|
2012-08-01 08:49:59 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2013-08-12 12:32:53 +04:00
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2012-08-01 08:49:59 +04:00
|
|
|
}
|
|
|
|
|
2013-08-12 12:32:53 +04:00
|
|
|
return request.forget();
|
2012-08-01 08:49:59 +04:00
|
|
|
}
|