Bug 925638 - Patch 2/3: implement new webidl functions, r=echou

This commit is contained in:
Ben Tian 2013-10-16 10:38:13 +08:00
parent fb3b6b0e37
commit d551eb0740
12 changed files with 256 additions and 0 deletions

View File

@ -878,6 +878,75 @@ BluetoothAdapter::IsScoConnected(ErrorResult& aRv)
return request.forget();
}
already_AddRefed<DOMRequest>
BluetoothAdapter::AnswerWaitingCall(ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
if (!win) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<DOMRequest> request = new DOMRequest(win);
nsRefPtr<BluetoothVoidReplyRunnable> results =
new BluetoothVoidReplyRunnable(request);
BluetoothService* bs = BluetoothService::Get();
if (!bs) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
bs->AnswerWaitingCall(results);
return request.forget();
}
already_AddRefed<DOMRequest>
BluetoothAdapter::IgnoreWaitingCall(ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
if (!win) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<DOMRequest> request = new DOMRequest(win);
nsRefPtr<BluetoothVoidReplyRunnable> results =
new BluetoothVoidReplyRunnable(request);
BluetoothService* bs = BluetoothService::Get();
if (!bs) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
bs->IgnoreWaitingCall(results);
return request.forget();
}
already_AddRefed<DOMRequest>
BluetoothAdapter::ToggleCalls(ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
if (!win) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<DOMRequest> request = new DOMRequest(win);
nsRefPtr<BluetoothVoidReplyRunnable> results =
new BluetoothVoidReplyRunnable(request);
BluetoothService* bs = BluetoothService::Get();
if (!bs) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
bs->ToggleCalls(results);
return request.forget();
}
already_AddRefed<DOMRequest>
BluetoothAdapter::SendMediaMetaData(const MediaMetaData& aMediaMetaData, ErrorResult& aRv)
{

View File

@ -137,6 +137,10 @@ public:
already_AddRefed<DOMRequest> DisconnectSco(ErrorResult& aRv);
already_AddRefed<DOMRequest> IsScoConnected(ErrorResult& aRv);
already_AddRefed<DOMRequest> AnswerWaitingCall(ErrorResult& aRv);
already_AddRefed<DOMRequest> IgnoreWaitingCall(ErrorResult& aRv);
already_AddRefed<DOMRequest> ToggleCalls(ErrorResult& aRv);
already_AddRefed<DOMRequest>
SendMediaMetaData(const MediaMetaData& aMediaMetaData, ErrorResult& aRv);
already_AddRefed<DOMRequest>

View File

@ -1493,6 +1493,42 @@ BluetoothHfpManager::UpdateSecondNumber(const nsAString& aNumber)
UpdateCIND(CINDType::CALLSETUP, CallSetupState::INCOMING, true);
}
void
BluetoothHfpManager::AnswerWaitingCall()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mPhoneType == PhoneType::CDMA);
// Pick up second call. First call is held now.
mCdmaSecondCall.mState = nsITelephonyProvider::CALL_STATE_CONNECTED;
UpdateCIND(CINDType::CALLSETUP, CallSetupState::NO_CALLSETUP, true);
sCINDItems[CINDType::CALLHELD].value = CallHeldState::ONHOLD_ACTIVE;
SendCommand("+CIEV: ", CINDType::CALLHELD);
}
void
BluetoothHfpManager::IgnoreWaitingCall()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mPhoneType == PhoneType::CDMA);
mCdmaSecondCall.Reset();
UpdateCIND(CINDType::CALLSETUP, CallSetupState::NO_CALLSETUP, true);
}
void
BluetoothHfpManager::ToggleCalls()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mPhoneType == PhoneType::CDMA);
// Toggle acitve and held calls
mCdmaSecondCall.mState = (mCdmaSecondCall.IsActive()) ?
nsITelephonyProvider::CALL_STATE_HELD :
nsITelephonyProvider::CALL_STATE_CONNECTED;
}
void
BluetoothHfpManager::OnSocketConnectSuccess(BluetoothSocket* aSocket)
{

View File

@ -123,6 +123,9 @@ public:
// CDMA-specific functions
void UpdateSecondNumber(const nsAString& aNumber);
void AnswerWaitingCall();
void IgnoreWaitingCall();
void ToggleCalls();
private:
class CloseScoTask;

View File

@ -266,6 +266,15 @@ public:
virtual void
IsScoConnected(BluetoothReplyRunnable* aRunnable) = 0;
virtual void
AnswerWaitingCall(BluetoothReplyRunnable* aRunnable) = 0;
virtual void
IgnoreWaitingCall(BluetoothReplyRunnable* aRunnable) = 0;
virtual void
ToggleCalls(BluetoothReplyRunnable* aRunnable) = 0;
virtual void
SendMetaData(const nsAString& aTitle,
const nsAString& aArtist,

View File

@ -226,6 +226,12 @@ BluetoothParent::RecvPBluetoothRequestConstructor(
return actor->DoRequest(aRequest.get_DisconnectScoRequest());
case Request::TIsScoConnectedRequest:
return actor->DoRequest(aRequest.get_IsScoConnectedRequest());
case Request::TAnswerWaitingCallRequest:
return actor->DoRequest(aRequest.get_AnswerWaitingCallRequest());
case Request::TIgnoreWaitingCallRequest:
return actor->DoRequest(aRequest.get_IgnoreWaitingCallRequest());
case Request::TToggleCallsRequest:
return actor->DoRequest(aRequest.get_ToggleCallsRequest());
case Request::TSendMetaDataRequest:
return actor->DoRequest(aRequest.get_SendMetaDataRequest());
case Request::TSendPlayStatusRequest:
@ -575,6 +581,39 @@ BluetoothRequestParent::DoRequest(const IsScoConnectedRequest& aRequest)
return true;
}
bool
BluetoothRequestParent::DoRequest(const AnswerWaitingCallRequest& aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TAnswerWaitingCallRequest);
mService->AnswerWaitingCall(mReplyRunnable.get());
return true;
}
bool
BluetoothRequestParent::DoRequest(const IgnoreWaitingCallRequest& aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TAnswerWaitingCallRequest);
mService->IgnoreWaitingCall(mReplyRunnable.get());
return true;
}
bool
BluetoothRequestParent::DoRequest(const ToggleCallsRequest& aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TAnswerWaitingCallRequest);
mService->ToggleCalls(mReplyRunnable.get());
return true;
}
bool
BluetoothRequestParent::DoRequest(const SendMetaDataRequest& aRequest)
{

View File

@ -190,6 +190,15 @@ protected:
bool
DoRequest(const IsScoConnectedRequest& aRequest);
bool
DoRequest(const AnswerWaitingCallRequest& aRequest);
bool
DoRequest(const IgnoreWaitingCallRequest& aRequest);
bool
DoRequest(const ToggleCallsRequest& aRequest);
bool
DoRequest(const SendMetaDataRequest& aRequest);

View File

@ -328,6 +328,27 @@ BluetoothServiceChildProcess::IsScoConnected(BluetoothReplyRunnable* aRunnable)
SendRequest(aRunnable, IsScoConnectedRequest());
}
void
BluetoothServiceChildProcess::AnswerWaitingCall(
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, AnswerWaitingCallRequest());
}
void
BluetoothServiceChildProcess::IgnoreWaitingCall(
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, IgnoreWaitingCallRequest());
}
void
BluetoothServiceChildProcess::ToggleCalls(
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, ToggleCallsRequest());
}
void
BluetoothServiceChildProcess::SendMetaData(const nsAString& aTitle,
const nsAString& aArtist,

View File

@ -149,6 +149,15 @@ public:
virtual void
IsScoConnected(BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual void
AnswerWaitingCall(BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual void
IgnoreWaitingCall(BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual void
ToggleCalls(BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual void
SendMetaData(const nsAString& aTitle,
const nsAString& aArtist,

View File

@ -134,6 +134,18 @@ struct IsScoConnectedRequest
{
};
struct AnswerWaitingCallRequest
{
};
struct IgnoreWaitingCallRequest
{
};
struct ToggleCallsRequest
{
};
struct SendMetaDataRequest
{
nsString title;
@ -175,6 +187,9 @@ union Request
ConnectScoRequest;
DisconnectScoRequest;
IsScoConnectedRequest;
AnswerWaitingCallRequest;
IgnoreWaitingCallRequest;
ToggleCallsRequest;
SendMetaDataRequest;
SendPlayStatusRequest;
};

View File

@ -2631,6 +2631,39 @@ BluetoothDBusService::IsConnected(const uint16_t aServiceUuid)
return profile->IsConnected();
}
void
BluetoothDBusService::AnswerWaitingCall(BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->AnswerWaitingCall();
DispatchBluetoothReply(aRunnable, BluetoothValue(true), EmptyString());
}
void
BluetoothDBusService::IgnoreWaitingCall(BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->IgnoreWaitingCall();
DispatchBluetoothReply(aRunnable, BluetoothValue(true), EmptyString());
}
void
BluetoothDBusService::ToggleCalls(BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->ToggleCalls();
DispatchBluetoothReply(aRunnable, BluetoothValue(true), EmptyString());
}
class OnUpdateSdpRecordsRunnable : public nsRunnable
{
public:

View File

@ -132,6 +132,15 @@ public:
virtual void
IsScoConnected(BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual void
AnswerWaitingCall(BluetoothReplyRunnable* aRunnable);
virtual void
IgnoreWaitingCall(BluetoothReplyRunnable* aRunnable);
virtual void
ToggleCalls(BluetoothReplyRunnable* aRunnable);
virtual void
SendMetaData(const nsAString& aTitle,
const nsAString& aArtist,