Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1180555 - Handle PBAP replies and pass the results through IPC to…
Browse files Browse the repository at this point in the history
… PbapManager. r=btian
  • Loading branch information
JaminLiu committed Aug 21, 2015
1 parent fbe977c commit a9c14d5
Show file tree
Hide file tree
Showing 14 changed files with 602 additions and 9 deletions.
115 changes: 109 additions & 6 deletions dom/bluetooth/BluetoothPbapRequestHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "BluetoothService.h"

#include "mozilla/dom/BluetoothPbapRequestHandleBinding.h"
#include "mozilla/dom/ContentChild.h"

using namespace mozilla;
using namespace dom;
Expand Down Expand Up @@ -49,26 +50,128 @@ already_AddRefed<DOMRequest>
BluetoothPbapRequestHandle::ReplyTovCardPulling(Blob& aBlob,
ErrorResult& aRv)
{
// TODO: Implement this function (Bug 1180555)
return nullptr;
nsCOMPtr<nsPIDOMWindow> win = GetParentObject();
if (!win) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}

nsRefPtr<DOMRequest> request = new DOMRequest(win);
nsRefPtr<BluetoothVoidReplyRunnable> result =
new BluetoothVoidReplyRunnable(request);

BluetoothService* bs = BluetoothService::Get();
if (!bs) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}

if (XRE_GetProcessType() == GeckoProcessType_Default) {
// In-process reply
bs->ReplyTovCardPulling(&aBlob, result);
} else {
ContentChild *cc = ContentChild::GetSingleton();
if (!cc) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}

BlobChild* actor = cc->GetOrCreateActorForBlob(&aBlob);
if (!actor) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}

bs->ReplyTovCardPulling(nullptr, actor, result);
}

return request.forget();
}

already_AddRefed<DOMRequest>
BluetoothPbapRequestHandle::ReplyToPhonebookPulling(Blob& aBlob,
uint16_t phonebookSize,
ErrorResult& aRv)
{
// TODO: Implement this function (Bug 1180555)
return nullptr;
nsCOMPtr<nsPIDOMWindow> win = GetParentObject();
if (!win) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}

nsRefPtr<DOMRequest> request = new DOMRequest(win);
nsRefPtr<BluetoothVoidReplyRunnable> result =
new BluetoothVoidReplyRunnable(request);

BluetoothService* bs = BluetoothService::Get();
if (!bs) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}

if (XRE_GetProcessType() == GeckoProcessType_Default) {
// In-process reply
bs->ReplyToPhonebookPulling(&aBlob, phonebookSize, result);
} else {
ContentChild *cc = ContentChild::GetSingleton();
if (!cc) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}

BlobChild* actor = cc->GetOrCreateActorForBlob(&aBlob);
if (!actor) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}

bs->ReplyToPhonebookPulling(nullptr, actor, phonebookSize, result);
}

return request.forget();
}

already_AddRefed<DOMRequest>
BluetoothPbapRequestHandle::ReplyTovCardListing(Blob& aBlob,
uint16_t phonebookSize,
ErrorResult& aRv)
{
// TODO: Implement this function (Bug 1180555)
return nullptr;
nsCOMPtr<nsPIDOMWindow> win = GetParentObject();
if (!win) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}

nsRefPtr<DOMRequest> request = new DOMRequest(win);
nsRefPtr<BluetoothVoidReplyRunnable> result =
new BluetoothVoidReplyRunnable(request);

BluetoothService* bs = BluetoothService::Get();
if (!bs) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}

if (XRE_GetProcessType() == GeckoProcessType_Default) {
// In-process reply
bs->ReplyTovCardListing(&aBlob, phonebookSize, result);
} else {
ContentChild *cc = ContentChild::GetSingleton();
if (!cc) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}

BlobChild* actor = cc->GetOrCreateActorForBlob(&aBlob);
if (!actor) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}

bs->ReplyTovCardListing(nullptr, actor, phonebookSize, result);
}

return request.forget();
}

JSObject*
Expand Down
35 changes: 32 additions & 3 deletions dom/bluetooth/bluedroid/BluetoothPbapManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "BluetoothUuid.h"
#include "ObexBase.h"

#include "mozilla/dom/ipc/BlobParent.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Services.h"
#include "mozilla/StaticPtr.h"
Expand Down Expand Up @@ -752,20 +753,48 @@ BluetoothPbapManager::PackPropertiesMask(uint8_t* aData, int aSize)
return propSelector;
}

void
BluetoothPbapManager::ReplyToPullPhonebook(BlobParent* aActor,
uint16_t aPhonebookSize)
{
nsRefPtr<BlobImpl> impl = aActor->GetBlobImpl();
nsRefPtr<Blob> blob = Blob::Create(nullptr, impl);

ReplyToPullPhonebook(blob.get(), aPhonebookSize);
}

void
BluetoothPbapManager::ReplyToPullPhonebook(Blob* aBlob, uint16_t aPhonebookSize)
{
// TODO: Implement this function (Bug 1180556)
}

void
BluetoothPbapManager::ReplyToPullvCardListing(
Blob* aBlob,
uint16_t aPhonebookSize)
BluetoothPbapManager::ReplyToPullvCardListing(BlobParent* aActor,
uint16_t aPhonebookSize)
{
nsRefPtr<BlobImpl> impl = aActor->GetBlobImpl();
nsRefPtr<Blob> blob = Blob::Create(nullptr, impl);

ReplyToPullvCardListing(blob.get(), aPhonebookSize);
}

void
BluetoothPbapManager::ReplyToPullvCardListing(Blob* aBlob,
uint16_t aPhonebookSize)
{
// TODO: Implement this function (Bug 1180556)
}

void
BluetoothPbapManager::ReplyToPullvCardEntry(BlobParent* aActor)
{
nsRefPtr<BlobImpl> impl = aActor->GetBlobImpl();
nsRefPtr<Blob> blob = Blob::Create(nullptr, impl);

ReplyToPullvCardEntry(blob.get());
}

void
BluetoothPbapManager::ReplyToPullvCardEntry(Blob* aBlob)
{
Expand Down
44 changes: 44 additions & 0 deletions dom/bluetooth/bluedroid/BluetoothPbapManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace mozilla {
namespace dom {
class Blob;
class BlobParent;
}
}

Expand Down Expand Up @@ -62,8 +63,51 @@ class BluetoothPbapManager : public BluetoothSocketObserver

static BluetoothPbapManager* Get();
bool Listen();

/**
* Reply vCard object to the *IPC* 'pullphonebook' request.
*
* @param aActor [in] a blob actor containing the vCard objects
* @param aPhonebookSize [in] the number of vCard indexes in the blob
*/
void ReplyToPullPhonebook(BlobParent* aActor, uint16_t aPhonebookSize);

/**
* Reply vCard object to the *in-process* 'pullphonebook' request.
*
* @param aBlob [in] a blob contained the vCard objects
* @param aPhonebookSize [in] the number of vCard indexes in the blob
*/
void ReplyToPullPhonebook(Blob* aBlob, uint16_t aPhonebookSize);

/**
* Reply vCard object to the *IPC* 'pullvcardlisting' request.
*
* @param aActor [in] a blob actor containing the vCard objects
* @param aPhonebookSize [in] the number of vCard indexes in the blob
*/
void ReplyToPullvCardListing(BlobParent* aActor, uint16_t aPhonebookSize);

/**
* Reply vCard object to the *in-process* 'pullvcardlisting' request.
*
* @param aBlob [in] a blob contained the vCard objects
* @param aPhonebookSize [in] the number of vCard indexes in the blob
*/
void ReplyToPullvCardListing(Blob* aBlob, uint16_t aPhonebookSize);

/**
* Reply vCard object to the *IPC* 'pullvcardentry' request.
*
* @param aActor [in] a blob actor containing the vCard objects
*/
void ReplyToPullvCardEntry(BlobParent* aActor);

/**
* Reply vCard object to the *in-process* 'pullvcardentry' request.
*
* @param aBlob [in] a blob contained the vCard objects
*/
void ReplyToPullvCardEntry(Blob* aBlob);

protected:
Expand Down
103 changes: 103 additions & 0 deletions dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,109 @@ BluetoothServiceBluedroid::IsScoConnected(BluetoothReplyRunnable* aRunnable)
DispatchReplySuccess(aRunnable, BluetoothValue(hfp->IsScoConnected()));
}

void
BluetoothServiceBluedroid::ReplyTovCardPulling(
BlobParent* aBlobParent,
BlobChild* aBlobChild,
BluetoothReplyRunnable* aRunnable)
{
BluetoothPbapManager* pbap = BluetoothPbapManager::Get();
if (!pbap) {
DispatchReplyError(aRunnable,
NS_LITERAL_STRING("Reply to vCardPulling failed"));
return;
}

pbap->ReplyToPullvCardEntry(aBlobParent);
DispatchReplySuccess(aRunnable);
}

void
BluetoothServiceBluedroid::ReplyTovCardPulling(
Blob* aBlob,
BluetoothReplyRunnable* aRunnable)
{
BluetoothPbapManager* pbap = BluetoothPbapManager::Get();
if (!pbap) {
DispatchReplyError(aRunnable,
NS_LITERAL_STRING("Reply to vCardPulling failed"));
return;
}

pbap->ReplyToPullvCardEntry(aBlob);
DispatchReplySuccess(aRunnable);
}

void
BluetoothServiceBluedroid::ReplyToPhonebookPulling(
BlobParent* aBlobParent,
BlobChild* aBlobChild,
uint16_t aPhonebookSize,
BluetoothReplyRunnable* aRunnable)
{
BluetoothPbapManager* pbap = BluetoothPbapManager::Get();
if (!pbap) {
DispatchReplyError(aRunnable,
NS_LITERAL_STRING("Reply to Phonebook Pulling failed"));
return;
}

pbap->ReplyToPullPhonebook(aBlobParent, aPhonebookSize);
DispatchReplySuccess(aRunnable);
}

void
BluetoothServiceBluedroid::ReplyToPhonebookPulling(
Blob* aBlob,
uint16_t aPhonebookSize,
BluetoothReplyRunnable* aRunnable)
{
BluetoothPbapManager* pbap = BluetoothPbapManager::Get();
if (!pbap) {
DispatchReplyError(aRunnable,
NS_LITERAL_STRING("Reply to Phonebook Pulling failed"));
return;
}

pbap->ReplyToPullPhonebook(aBlob, aPhonebookSize);
DispatchReplySuccess(aRunnable);
}

void
BluetoothServiceBluedroid::ReplyTovCardListing(
BlobParent* aBlobParent,
BlobChild* aBlobChild,
uint16_t aPhonebookSize,
BluetoothReplyRunnable* aRunnable)
{
BluetoothPbapManager* pbap = BluetoothPbapManager::Get();
if (!pbap) {
DispatchReplyError(aRunnable,
NS_LITERAL_STRING("Reply to vCard Listing failed"));
return;
}

pbap->ReplyToPullvCardListing(aBlobParent, aPhonebookSize);
DispatchReplySuccess(aRunnable);
}

void
BluetoothServiceBluedroid::ReplyTovCardListing(
Blob* aBlob,
uint16_t aPhonebookSize,
BluetoothReplyRunnable* aRunnable)
{
BluetoothPbapManager* pbap = BluetoothPbapManager::Get();
if (!pbap) {
DispatchReplyError(aRunnable,
NS_LITERAL_STRING("Reply to vCard Listing failed"));
return;
}

pbap->ReplyToPullvCardListing(aBlob, aPhonebookSize);
DispatchReplySuccess(aRunnable);
}

void
BluetoothServiceBluedroid::SendMetaData(const nsAString& aTitle,
const nsAString& aArtist,
Expand Down
Loading

0 comments on commit a9c14d5

Please sign in to comment.