Bug 888595: Convert BluetoothManager bindings to WebIDL, r=bzbarsky,echou

This patch converts the BluetoothManager to WebIDL and removes the
old XPIDL bindings. The only user of BluetoothManager is the class
Navigator, which has been adapted to the change.

--HG--
extra : rebase_source : 4bdc77b3923d4ca6ec820c12454a295010382839
This commit is contained in:
Thomas Zimmermann 2013-08-12 10:31:58 +02:00
parent 9183bf3a61
commit 9735683b39
12 changed files with 114 additions and 94 deletions

View File

@ -59,7 +59,6 @@
#include "Telephony.h"
#endif
#ifdef MOZ_B2G_BT
#include "nsIDOMBluetoothManager.h"
#include "BluetoothManager.h"
#endif
#include "nsIDOMCameraManager.h"
@ -1249,7 +1248,7 @@ Navigator::GetMozMobileConnection(ErrorResult& aRv)
#endif // MOZ_B2G_RIL
#ifdef MOZ_B2G_BT
nsIDOMBluetoothManager*
bluetooth::BluetoothManager*
Navigator::GetMozBluetooth(ErrorResult& aRv)
{
if (!mBluetooth) {
@ -1276,7 +1275,7 @@ Navigator::EnsureMessagesManager()
nsresult rv;
nsCOMPtr<nsIDOMNavigatorSystemMessages> messageManager =
do_CreateInstance("@mozilla.org/system-message-manager;1", &rv);
nsCOMPtr<nsIDOMGlobalPropertyInitializer> gpi =
do_QueryInterface(messageManager);
NS_ENSURE_TRUE(gpi, NS_ERROR_FAILURE);

View File

@ -39,10 +39,6 @@ class nsIDOMMozVoicemail;
class nsIDOMMozIccManager;
#endif // MOZ_B2G_RIL
#ifdef MOZ_B2G_BT
class nsIDOMBluetoothManager;
#endif // MOZ_B2G_BT
#include "nsIDOMNavigatorSystemMessages.h"
#include "DOMCameraManager.h"
@ -91,6 +87,12 @@ class Telephony;
} // namespace Telephony;
#endif
#ifdef MOZ_B2G_BT
namespace bluetooth {
class BluetoothManager;
} // namespace bluetooth
#endif // MOZ_B2G_BT
namespace power {
class PowerManager;
} // namespace power
@ -229,7 +231,7 @@ public:
void GetGamepads(nsTArray<nsRefPtr<Gamepad> >& aGamepads, ErrorResult& aRv);
#endif // MOZ_GAMEPAD
#ifdef MOZ_B2G_BT
nsIDOMBluetoothManager* GetMozBluetooth(ErrorResult& aRv);
bluetooth::BluetoothManager* GetMozBluetooth(ErrorResult& aRv);
#endif // MOZ_B2G_BT
#ifdef MOZ_TIME_MANAGER
time::TimeManager* GetMozTime(ErrorResult& aRv);
@ -324,7 +326,7 @@ private:
nsRefPtr<icc::IccManager> mIccManager;
#endif
#ifdef MOZ_B2G_BT
nsCOMPtr<nsIDOMBluetoothManager> mBluetooth;
nsCOMPtr<bluetooth::BluetoothManager> mBluetooth;
#endif
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
nsRefPtr<system::AudioChannelManager> mAudioChannelManager;

View File

@ -236,7 +236,6 @@ using mozilla::dom::workers::ResolveWorkerClasses;
#endif
#ifdef MOZ_B2G_BT
#include "BluetoothManager.h"
#include "BluetoothAdapter.h"
#include "BluetoothDevice.h"
#endif
@ -639,8 +638,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
#endif
#ifdef MOZ_B2G_BT
NS_DEFINE_CLASSINFO_DATA(BluetoothManager, nsEventTargetSH,
EVENTTARGET_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(BluetoothAdapter, nsEventTargetSH,
EVENTTARGET_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(BluetoothDevice, nsEventTargetSH,
@ -1537,10 +1534,6 @@ nsDOMClassInfo::Init()
#endif
#ifdef MOZ_B2G_BT
DOM_CLASSINFO_MAP_BEGIN(BluetoothManager, nsIDOMBluetoothManager)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMBluetoothManager)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(BluetoothAdapter, nsIDOMBluetoothAdapter)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMBluetoothAdapter)
DOM_CLASSINFO_MAP_END

View File

@ -137,7 +137,6 @@ DOMCI_CLASS(FMRadio)
#endif
#ifdef MOZ_B2G_BT
DOMCI_CLASS(BluetoothManager)
DOMCI_CLASS(BluetoothAdapter)
DOMCI_CLASS(BluetoothDevice)
#endif

View File

@ -150,6 +150,11 @@ DOMInterfaces = {
'headerFile': 'BatteryManager.h'
},
'BluetoothManager': {
'nativeType': 'mozilla::dom::bluetooth::BluetoothManager',
'headerFile': 'BluetoothManager.h'
},
'CallEvent': {
'nativeType': 'mozilla::dom::telephony::CallEvent',
'headerFile': 'CallEvent.h',
@ -1739,14 +1744,13 @@ addExternalIface('imgIRequest', nativeType='imgIRequest', notflattened=True)
addExternalIface('LockedFile')
addExternalIface('MediaList')
addExternalIface('MenuBuilder', nativeType='nsIMenuBuilder', notflattened=True)
addExternalIface('MozBluetoothManager', nativeType='nsIDOMBluetoothManager')
addExternalIface('MozBoxObject', nativeType='nsIBoxObject')
addExternalIface('MozCellBroadcast')
addExternalIface('MozConnection', headerFile='nsIDOMConnection.h')
addExternalIface('MozControllers', nativeType='nsIControllers')
addExternalIface('MozFrameLoader', nativeType='nsIFrameLoader', notflattened=True)
addExternalIface('MozIccManager', headerFile='nsIDOMIccManager.h')
addExternalIface('MozMediaStreamOptions', nativeType='nsIMediaStreamOptions',
addExternalIface('MozMediaStreamOptions', nativeType='nsIMediaStreamOptions',
headerFile='nsIDOMNavigatorUserMedia.h')
addExternalIface('MozMobileConnection', headerFile='nsIDOMMobileConnection.h')
addExternalIface('MozMobileMessageManager', headerFile='nsIDOMMobileMessageManager.h')

View File

@ -18,16 +18,14 @@
#include "nsThreadUtils.h"
#include "mozilla/Util.h"
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
#include "mozilla/dom/BluetoothManagerBinding.h"
using namespace mozilla;
USING_BLUETOOTH_NAMESPACE
DOMCI_DATA(BluetoothManager, BluetoothManager)
NS_INTERFACE_MAP_BEGIN(BluetoothManager)
NS_INTERFACE_MAP_ENTRY(nsIDOMBluetoothManager)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(BluetoothManager)
// QueryInterface implementation for BluetoothManager
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BluetoothManager)
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
NS_IMPL_ADDREF_INHERITED(BluetoothManager, nsDOMEventTargetHelper)
@ -93,9 +91,11 @@ private:
};
BluetoothManager::BluetoothManager(nsPIDOMWindow *aWindow)
: BluetoothPropertyContainer(BluetoothObjectType::TYPE_MANAGER)
: nsDOMEventTargetHelper(aWindow)
, BluetoothPropertyContainer(BluetoothObjectType::TYPE_MANAGER)
{
MOZ_ASSERT(aWindow);
MOZ_ASSERT(IsDOMBinding());
BindToOwner(aWindow);
mPath.AssignLiteral("/");
@ -124,37 +124,44 @@ BluetoothManager::SetPropertyByValue(const BluetoothNamedValue& aValue)
#endif
}
NS_IMETHODIMP
BluetoothManager::GetEnabled(bool* aEnabled)
bool
BluetoothManager::GetEnabled(ErrorResult& aRv)
{
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
*aEnabled = bs->IsEnabled();
return NS_OK;
}
NS_IMETHODIMP
BluetoothManager::GetDefaultAdapter(nsIDOMDOMRequest** aAdapter)
{
nsCOMPtr<nsIDOMRequestService> rs =
do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMDOMRequest> request;
nsresult rv = rs->CreateRequest(GetOwner(), getter_AddRefs(request));
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<BluetoothReplyRunnable> results = new GetAdapterTask(this, request);
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
if (NS_FAILED(bs->GetDefaultAdapterPathInternal(results))) {
return NS_ERROR_FAILURE;
if (!bs) {
aRv.Throw(NS_ERROR_FAILURE);
return false;
}
request.forget(aAdapter);
return NS_OK;
return bs->IsEnabled();
}
already_AddRefed<dom::DOMRequest>
BluetoothManager::GetDefaultAdapter(ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
if (!win) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<DOMRequest> request = new DOMRequest(win);
nsRefPtr<BluetoothReplyRunnable> results =
new GetAdapterTask(this, request);
BluetoothService* bs = BluetoothService::Get();
if (!bs) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsresult rv = bs->GetDefaultAdapterPathInternal(results);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
return request.forget();
}
// static
@ -208,19 +215,20 @@ BluetoothManager::Notify(const BluetoothSignal& aData)
}
}
NS_IMETHODIMP
BluetoothManager::IsConnected(uint16_t aProfileId, bool* aConnected)
bool
BluetoothManager::IsConnected(uint16_t aProfileId, ErrorResult& aRv)
{
BluetoothService* bs = BluetoothService::Get();
if (!bs) {
NS_WARNING("BluetoothService not available!");
return NS_ERROR_FAILURE;
aRv.Throw(NS_ERROR_FAILURE);
return false;
}
*aConnected = bs->IsConnected(aProfileId);
return NS_OK;
return bs->IsConnected(aProfileId);
}
NS_IMPL_EVENT_HANDLER(BluetoothManager, enabled)
NS_IMPL_EVENT_HANDLER(BluetoothManager, disabled)
NS_IMPL_EVENT_HANDLER(BluetoothManager, adapteradded)
JSObject*
BluetoothManager::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
{
return BluetoothManagerBinding::Wrap(aCx, aScope, this);
}

View File

@ -11,23 +11,25 @@
#include "BluetoothCommon.h"
#include "BluetoothPropertyContainer.h"
#include "nsDOMEventTargetHelper.h"
#include "nsIDOMBluetoothManager.h"
#include "mozilla/Observer.h"
#include "nsISupportsImpl.h"
namespace mozilla {
namespace dom {
class DOMRequest;
}
}
BEGIN_BLUETOOTH_NAMESPACE
class BluetoothNamedValue;
class BluetoothManager : public nsDOMEventTargetHelper
, public nsIDOMBluetoothManager
, public BluetoothSignalObserver
, public BluetoothPropertyContainer
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMBLUETOOTHMANAGER
NS_REALLY_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper)
// Never returns null
static already_AddRefed<BluetoothManager>
@ -35,6 +37,24 @@ public:
static bool CheckPermission(nsPIDOMWindow* aWindow);
void Notify(const BluetoothSignal& aData);
virtual void SetPropertyByValue(const BluetoothNamedValue& aValue) MOZ_OVERRIDE;
bool GetEnabled(ErrorResult& aRv);
bool IsConnected(uint16_t aProfileId, ErrorResult& aRv);
already_AddRefed<DOMRequest> GetDefaultAdapter(ErrorResult& aRv);
IMPL_EVENT_HANDLER(enabled);
IMPL_EVENT_HANDLER(disabled);
IMPL_EVENT_HANDLER(adapteradded);
nsPIDOMWindow* GetParentObject() const
{
return GetOwner();
}
virtual JSObject*
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
private:
BluetoothManager(nsPIDOMWindow* aWindow);
~BluetoothManager();

View File

@ -21,7 +21,6 @@ if CONFIG['MOZ_B2G_BT']:
'nsIDOMBluetoothAdapter.idl',
'nsIDOMBluetoothDevice.idl',
'nsIDOMBluetoothDeviceEvent.idl',
'nsIDOMBluetoothManager.idl',
'nsIDOMBluetoothStatusChangedEvent.idl',
]

View File

@ -1,24 +0,0 @@
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* 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 "nsIDOMEventTarget.idl"
interface nsIDOMDOMRequest;
interface nsIDOMBluetoothAdapter;
[scriptable, builtinclass, uuid(303a262a-1dd1-486d-a108-d8c582e86765)]
interface nsIDOMBluetoothManager : nsIDOMEventTarget
{
readonly attribute bool enabled;
nsIDOMDOMRequest getDefaultAdapter();
bool isConnected(in unsigned short aProfile);
[implicit_jscontext] attribute jsval onenabled;
[implicit_jscontext] attribute jsval ondisabled;
[implicit_jscontext] attribute jsval onadapteradded;
};

View File

@ -0,0 +1,21 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
interface BluetoothManager : EventTarget {
[Throws]
readonly attribute boolean enabled;
[SetterThrows]
attribute EventHandler onenabled;
[SetterThrows]
attribute EventHandler ondisabled;
[SetterThrows]
attribute EventHandler onadapteradded;
[Throws]
boolean isConnected(unsigned short aProfile);
[Creator, Throws]
DOMRequest? getDefaultAdapter();
};

View File

@ -295,11 +295,9 @@ partial interface Navigator {
#endif // MOZ_GAMEPAD
#ifdef MOZ_B2G_BT
// nsIDOMNavigatorBluetooth
interface MozBluetoothManager;
partial interface Navigator {
[Throws, Func="Navigator::HasBluetoothSupport"]
readonly attribute MozBluetoothManager mozBluetooth;
readonly attribute BluetoothManager mozBluetooth;
};
#endif // MOZ_B2G_BT

View File

@ -476,6 +476,7 @@ webidl_files += \
ifdef MOZ_B2G_BT
webidl_files += \
BluetoothDeviceEvent.webidl \
BluetoothManager.webidl \
BluetoothStatusChangedEvent.webidl \
$(NULL)
endif