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