Bug 988111 - Unregister Bluetooth signal handler when BT objects were disconnected from owner window. r=echou, f=shuang

This commit is contained in:
Jamin Liu 2014-04-01 08:58:56 -04:00
Родитель 356f132f9d
Коммит ff14390381
6 изменённых файлов: 36 добавлений и 3 удалений

Просмотреть файл

@ -173,7 +173,6 @@ BluetoothAdapter::BluetoothAdapter(nsPIDOMWindow* aWindow,
MOZ_ASSERT(aWindow);
MOZ_ASSERT(IsDOMBinding());
BindToOwner(aWindow);
const InfallibleTArray<BluetoothNamedValue>& values =
aValue.get_ArrayOfBluetoothNamedValue();
for (uint32_t i = 0; i < values.Length(); ++i) {
@ -194,6 +193,16 @@ BluetoothAdapter::~BluetoothAdapter()
bs->UnregisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_ADAPTER), this);
}
void
BluetoothAdapter::DisconnectFromOwner()
{
nsDOMEventTargetHelper::DisconnectFromOwner();
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE_VOID(bs);
bs->UnregisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_ADAPTER), this);
}
void
BluetoothAdapter::Unroot()
{

Просмотреть файл

@ -46,6 +46,8 @@ public:
void Unroot();
virtual void SetPropertyByValue(const BluetoothNamedValue& aValue) MOZ_OVERRIDE;
virtual void DisconnectFromOwner() MOZ_OVERRIDE;
void GetAddress(nsString& aAddress) const
{
aAddress = mAddress;

Просмотреть файл

@ -57,7 +57,6 @@ BluetoothDevice::BluetoothDevice(nsPIDOMWindow* aWindow,
MOZ_ASSERT(aWindow);
MOZ_ASSERT(IsDOMBinding());
BindToOwner(aWindow);
const InfallibleTArray<BluetoothNamedValue>& values =
aValue.get_ArrayOfBluetoothNamedValue();
for (uint32_t i = 0; i < values.Length(); ++i) {
@ -78,6 +77,16 @@ BluetoothDevice::~BluetoothDevice()
Unroot();
}
void
BluetoothDevice::DisconnectFromOwner()
{
nsDOMEventTargetHelper::DisconnectFromOwner();
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE_VOID(bs);
bs->UnregisterBluetoothSignalHandler(mAddress, this);
}
void
BluetoothDevice::Root()
{

Просмотреть файл

@ -87,6 +87,8 @@ public:
virtual JSObject*
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
virtual void DisconnectFromOwner() MOZ_OVERRIDE;
private:
BluetoothDevice(nsPIDOMWindow* aOwner, const nsAString& aAdapterPath,
const BluetoothValue& aValue);

Просмотреть файл

@ -105,7 +105,6 @@ BluetoothManager::BluetoothManager(nsPIDOMWindow *aWindow)
MOZ_ASSERT(aWindow);
MOZ_ASSERT(IsDOMBinding());
BindToOwner(aWindow);
mPath.AssignLiteral("/");
BluetoothService* bs = BluetoothService::Get();
@ -120,6 +119,16 @@ BluetoothManager::~BluetoothManager()
bs->UnregisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_MANAGER), this);
}
void
BluetoothManager::DisconnectFromOwner()
{
nsDOMEventTargetHelper::DisconnectFromOwner();
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE_VOID(bs);
bs->UnregisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_MANAGER), this);
}
void
BluetoothManager::SetPropertyByValue(const BluetoothNamedValue& aValue)
{

Просмотреть файл

@ -55,6 +55,8 @@ public:
virtual JSObject*
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
virtual void DisconnectFromOwner() MOZ_OVERRIDE;
private:
BluetoothManager(nsPIDOMWindow* aWindow);
~BluetoothManager();