Bug 843452 - Part 3-3: MobileConnectionIPCService for content process. r=smaug

This commit is contained in:
Edgar Chen 2014-07-01 18:37:32 +08:00
parent e469a36db6
commit fe8561addc
6 changed files with 494 additions and 0 deletions

View File

@ -139,6 +139,19 @@ MobileConnectionChild::GetNetworkSelectionMode(nsAString& aMode)
aMode = mNetworkSelectionMode;
}
bool
MobileConnectionChild::SendRequest(MobileConnectionRequest aRequest,
nsIMobileConnectionCallback* aRequestCallback)
{
NS_ENSURE_TRUE(mLive, false);
// Deallocated in MobileConnectionChild::DeallocPMobileConnectionRequestChild().
MobileConnectionRequestChild* actor = new MobileConnectionRequestChild(aRequestCallback);
SendPMobileConnectionRequestConstructor(actor, aRequest);
return true;
}
void
MobileConnectionChild::ActorDestroy(ActorDestroyReason why)
{

View File

@ -71,6 +71,10 @@ public:
void
GetNetworkSelectionMode(nsAString& aMode);
bool
SendRequest(MobileConnectionRequest aRequest,
nsIMobileConnectionCallback* aRequestCallback);
protected:
virtual
~MobileConnectionChild()

View File

@ -0,0 +1,394 @@
/* 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 "MobileConnectionIPCService.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/Preferences.h"
#include "mozilla/StaticPtr.h"
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::dom::mobileconnection;
NS_IMPL_ISUPPORTS(MobileConnectionIPCService, nsIMobileConnectionService)
StaticRefPtr<MobileConnectionIPCService> sService;
/* static */MobileConnectionIPCService*
MobileConnectionIPCService::GetSingleton()
{
MOZ_ASSERT(NS_IsMainThread());
if (sService) {
return sService;
}
sService = new MobileConnectionIPCService();
return sService;
}
MobileConnectionIPCService::MobileConnectionIPCService()
{
int32_t numRil = Preferences::GetInt("ril.numRadioInterfaces", 1);
for (int32_t i = 0; i < numRil; i++) {
// Deallocated in ContentChild::DeallocPMobileConnectionChild().
nsRefPtr<MobileConnectionChild> client = new MobileConnectionChild();
NS_ASSERTION(client, "This shouldn't fail!");
ContentChild::GetSingleton()->SendPMobileConnectionConstructor(client, i);
client->Init();
mClients.AppendElement(client);
}
}
MobileConnectionIPCService::~MobileConnectionIPCService()
{
uint32_t count = mClients.Length();
for (uint32_t i = 0; i < count; i++) {
mClients[i]->Shutdown();
}
mClients.Clear();
}
nsresult
MobileConnectionIPCService::SendRequest(uint32_t aClientId,
MobileConnectionRequest aRequest,
nsIMobileConnectionCallback* aRequestCallback)
{
if (aClientId >= mClients.Length()) {
return NS_ERROR_FAILURE;
}
mClients[aClientId]->SendRequest(aRequest, aRequestCallback);
return NS_OK;
}
// nsIMobileConnectionService
NS_IMETHODIMP
MobileConnectionIPCService::RegisterListener(uint32_t aClientId,
nsIMobileConnectionListener* aListener)
{
if (aClientId >= mClients.Length()) {
return NS_ERROR_FAILURE;
}
mClients[aClientId]->RegisterListener(aListener);
return NS_OK;
}
NS_IMETHODIMP
MobileConnectionIPCService::UnregisterListener(uint32_t aClientId,
nsIMobileConnectionListener* aListener)
{
if (aClientId >= mClients.Length()) {
return NS_ERROR_FAILURE;
}
mClients[aClientId]->UnregisterListener(aListener);
return NS_OK;
}
NS_IMETHODIMP
MobileConnectionIPCService::GetLastKnownNetwork(uint32_t aClientId,
nsAString& aLastNetwork)
{
if (aClientId >= mClients.Length()) {
return NS_ERROR_FAILURE;
}
mClients[aClientId]->GetLastNetwork(aLastNetwork);
return NS_OK;
}
NS_IMETHODIMP
MobileConnectionIPCService::GetLastKnownHomeNetwork(uint32_t aClientId,
nsAString& aLastNetwork)
{
if (aClientId >= mClients.Length()) {
return NS_ERROR_FAILURE;
}
mClients[aClientId]->GetLastHomeNetwork(aLastNetwork);
return NS_OK;
}
NS_IMETHODIMP
MobileConnectionIPCService::GetVoiceConnectionInfo(uint32_t aClientId,
nsIMobileConnectionInfo** aInfo)
{
if (aClientId >= mClients.Length()) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIMobileConnectionInfo> info = mClients[aClientId]->GetVoiceInfo();
info.forget(aInfo);
return NS_OK;
}
NS_IMETHODIMP
MobileConnectionIPCService::GetDataConnectionInfo(uint32_t aClientId,
nsIMobileConnectionInfo** aInfo)
{
if (aClientId >= mClients.Length()) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIMobileConnectionInfo> info = mClients[aClientId]->GetDataInfo();
info.forget(aInfo);
return NS_OK;
}
NS_IMETHODIMP
MobileConnectionIPCService::GetIccId(uint32_t aClientId, nsAString& aIccId)
{
if (aClientId >= mClients.Length()) {
return NS_ERROR_FAILURE;
}
mClients[aClientId]->GetIccId(aIccId);
return NS_OK;
}
NS_IMETHODIMP
MobileConnectionIPCService::GetNetworkSelectionMode(uint32_t aClientId,
nsAString& aNetworkSelectionMode)
{
if (aClientId >= mClients.Length()) {
return NS_ERROR_FAILURE;
}
mClients[aClientId]->GetNetworkSelectionMode(aNetworkSelectionMode);
return NS_OK;
}
NS_IMETHODIMP
MobileConnectionIPCService::GetRadioState(uint32_t aClientId,
nsAString& aRadioState)
{
if (aClientId >= mClients.Length()) {
return NS_ERROR_FAILURE;
}
mClients[aClientId]->GetRadioState(aRadioState);
return NS_OK;
}
NS_IMETHODIMP
MobileConnectionIPCService::GetSupportedNetworkTypes(uint32_t aClientId,
nsIVariant** aSupportedTypes)
{
if (aClientId >= mClients.Length()) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIVariant> supportedTypes = mClients[aClientId]->GetSupportedNetworkTypes();
supportedTypes.forget(aSupportedTypes);
return NS_OK;
}
NS_IMETHODIMP
MobileConnectionIPCService::GetNetworks(uint32_t aClientId,
nsIMobileConnectionCallback* aRequest)
{
return SendRequest(aClientId, GetNetworksRequest(), aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::SelectNetwork(uint32_t aClientId,
nsIMobileNetworkInfo* aNetwork,
nsIMobileConnectionCallback* aRequest)
{
nsCOMPtr<nsIMobileNetworkInfo> network = aNetwork;
// We release the ref after serializing process is finished in
// MobileConnectionIPCSerializer.
return SendRequest(aClientId, SelectNetworkRequest(network.forget().take()), aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::SelectNetworkAutomatically(uint32_t aClientId,
nsIMobileConnectionCallback* aRequest)
{
return SendRequest(aClientId, SelectNetworkAutoRequest(), aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::SetPreferredNetworkType(uint32_t aClientId,
const nsAString& aType,
nsIMobileConnectionCallback* aRequest)
{
return SendRequest(aClientId,
SetPreferredNetworkTypeRequest(nsAutoString(aType)),
aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::GetPreferredNetworkType(uint32_t aClientId,
nsIMobileConnectionCallback* aRequest)
{
return SendRequest(aClientId, GetPreferredNetworkTypeRequest(), aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::SetRoamingPreference(uint32_t aClientId,
const nsAString& aMode,
nsIMobileConnectionCallback* aRequest)
{
return SendRequest(aClientId,
SetRoamingPreferenceRequest(nsAutoString(aMode)),
aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::GetRoamingPreference(uint32_t aClientId,
nsIMobileConnectionCallback* aRequest)
{
return SendRequest(aClientId, GetRoamingPreferenceRequest(), aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::SetVoicePrivacyMode(uint32_t aClientId,
bool aEnabled,
nsIMobileConnectionCallback* aRequest)
{
return SendRequest(aClientId, SetVoicePrivacyModeRequest(aEnabled), aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::GetVoicePrivacyMode(uint32_t aClientId,
nsIMobileConnectionCallback* aRequest)
{
return SendRequest(aClientId, GetVoicePrivacyModeRequest(), aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::SendMMI(uint32_t aClientId,
const nsAString& aMmi,
nsIMobileConnectionCallback* aRequest)
{
return SendRequest(aClientId, SendMmiRequest(nsAutoString(aMmi)), aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::CancelMMI(uint32_t aClientId,
nsIMobileConnectionCallback* aRequest)
{
return SendRequest(aClientId, CancelMmiRequest(), aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::SetCallForwarding(uint32_t aClientId,
JS::Handle<JS::Value> aOptions,
nsIMobileConnectionCallback* aRequest)
{
AutoSafeJSContext cx;
IPC::MozCallForwardingOptions options;
if(!options.Init(cx, aOptions)) {
return NS_ERROR_TYPE_ERR;
}
return SendRequest(aClientId, SetCallForwardingRequest(options), aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::GetCallForwarding(uint32_t aClientId,
uint16_t aReason,
nsIMobileConnectionCallback* aRequest)
{
return SendRequest(aClientId, GetCallForwardingRequest(aReason), aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::SetCallBarring(uint32_t aClientId,
JS::Handle<JS::Value> aOptions,
nsIMobileConnectionCallback* aRequest)
{
AutoSafeJSContext cx;
IPC::MozCallBarringOptions options;
if(!options.Init(cx, aOptions)) {
return NS_ERROR_TYPE_ERR;
}
return SendRequest(aClientId, SetCallBarringRequest(options), aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::GetCallBarring(uint32_t aClientId,
JS::Handle<JS::Value> aOptions,
nsIMobileConnectionCallback* aRequest)
{
AutoSafeJSContext cx;
IPC::MozCallBarringOptions options;
if(!options.Init(cx, aOptions)) {
return NS_ERROR_TYPE_ERR;
}
return SendRequest(aClientId, GetCallBarringRequest(options), aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::ChangeCallBarringPassword(uint32_t aClientId,
JS::Handle<JS::Value> aOptions,
nsIMobileConnectionCallback* aRequest)
{
AutoSafeJSContext cx;
IPC::MozCallBarringOptions options;
if(!options.Init(cx, aOptions)) {
return NS_ERROR_TYPE_ERR;
}
return SendRequest(aClientId, ChangeCallBarringPasswordRequest(options), aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::SetCallWaiting(uint32_t aClientId,
bool aEnabled,
nsIMobileConnectionCallback* aRequest)
{
return SendRequest(aClientId, SetCallWaitingRequest(aEnabled), aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::GetCallWaiting(uint32_t aClientId,
nsIMobileConnectionCallback* aRequest)
{
return SendRequest(aClientId, GetCallWaitingRequest(), aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::SetCallingLineIdRestriction(uint32_t aClientId,
uint16_t aMode,
nsIMobileConnectionCallback* aRequest)
{
return SendRequest(aClientId, SetCallingLineIdRestrictionRequest(aMode), aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::GetCallingLineIdRestriction(uint32_t aClientId,
nsIMobileConnectionCallback* aRequest)
{
return SendRequest(aClientId, GetCallingLineIdRestrictionRequest(), aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::ExitEmergencyCbMode(uint32_t aClientId,
nsIMobileConnectionCallback* aRequest)
{
return SendRequest(aClientId, ExitEmergencyCbModeRequest(), aRequest);
}
NS_IMETHODIMP
MobileConnectionIPCService::SetRadioEnabled(uint32_t aClientId,
bool aEnabled,
nsIMobileConnectionCallback* aRequest)
{
return SendRequest(aClientId, SetRadioEnabledRequest(aEnabled), aRequest);
}

View File

@ -0,0 +1,42 @@
/* 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/. */
#ifndef mozilla_dom_mobileconnection_MobileConnectionIPCService_h
#define mozilla_dom_mobileconnection_MobileConnectionIPCService_h
#include "nsCOMPtr.h"
#include "MobileConnectionChild.h"
#include "nsIMobileConnectionService.h"
namespace mozilla {
namespace dom {
namespace mobileconnection {
class MobileConnectionIPCService MOZ_FINAL : public nsIMobileConnectionService
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIMOBILECONNECTIONSERVICE
static MobileConnectionIPCService*
GetSingleton();
private:
MobileConnectionIPCService();
~MobileConnectionIPCService();
/** Send request */
nsresult
SendRequest(uint32_t aClientId, MobileConnectionRequest aRequest,
nsIMobileConnectionCallback* aRequestCallback);
nsTArray<nsRefPtr<MobileConnectionChild>> mClients;
};
} // name space mobileconnection
} // name space dom
} // name space mozilla
#endif // mozilla_dom_mobileconnection_MobileConnectionIPCService_h

View File

@ -17,12 +17,14 @@ EXPORTS.mozilla.dom += [
EXPORTS.mozilla.dom.mobileconnection += [
'ipc/MobileConnectionChild.h',
'ipc/MobileConnectionIPCService.h',
'ipc/MobileConnectionParent.h',
]
SOURCES += [
'DOMMMIError.cpp',
'ipc/MobileConnectionChild.cpp',
'ipc/MobileConnectionIPCService.cpp',
'ipc/MobileConnectionParent.cpp',
'MobileCellInfo.cpp',
'MobileConnection.cpp',

View File

@ -125,6 +125,12 @@ using mozilla::dom::gonk::AudioManager;
using mozilla::system::nsVolumeService;
#endif
#ifdef MOZ_B2G_RIL
#include "nsIMobileConnectionService.h"
#include "mozilla/dom/mobileconnection/MobileConnectionIPCService.h"
using mozilla::dom::mobileconnection::MobileConnectionIPCService;
#endif
#include "AudioChannelAgent.h"
using mozilla::dom::AudioChannelAgent;
@ -797,6 +803,10 @@ NS_DEFINE_NAMED_CID(TELEPHONY_SERVICE_CID);
NS_DEFINE_NAMED_CID(GECKO_MEDIA_PLUGIN_SERVICE_CID);
#ifdef MOZ_B2G_RIL
NS_DEFINE_NAMED_CID(NS_MOBILE_CONNECTION_SERVICE_CID);
#endif
static nsresult
CreateWindowCommandTableConstructor(nsISupports *aOuter,
REFNSIID aIID, void **aResult)
@ -925,6 +935,26 @@ nsEditingCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID,
return commandTable->QueryInterface(aIID, aResult);
}
#ifdef MOZ_B2G_RIL
static nsresult
nsIMobileConnectionServiceConstructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
nsCOMPtr<nsIMobileConnectionService> service;
if (XRE_GetProcessType() == GeckoProcessType_Content) {
service = MobileConnectionIPCService::GetSingleton();
}
if (!service) {
return NS_ERROR_NOT_AVAILABLE;
}
return service->QueryInterface(aIID, aResult);
}
#endif
static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
XPCONNECT_CIDENTRIES
@ -1081,6 +1111,9 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
{ &kNS_ACCESSIBILITY_SERVICE_CID, false, nullptr, CreateA11yService },
#endif
{ &kTELEPHONY_SERVICE_CID, false, nullptr, nsITelephonyServiceConstructor },
#ifdef MOZ_B2G_RIL
{ &kNS_MOBILE_CONNECTION_SERVICE_CID, true, NULL, nsIMobileConnectionServiceConstructor },
#endif
{ nullptr }
};
@ -1238,6 +1271,9 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
#endif
{ TELEPHONY_SERVICE_CONTRACTID, &kTELEPHONY_SERVICE_CID },
{ "@mozilla.org/gecko-media-plugin-service;1", &kGECKO_MEDIA_PLUGIN_SERVICE_CID },
#ifdef MOZ_B2G_RIL
{ NS_MOBILE_CONNECTION_SERVICE_CONTRACTID, &kNS_MOBILE_CONNECTION_SERVICE_CID },
#endif
{ nullptr }
};
@ -1259,6 +1295,9 @@ static const mozilla::Module::CategoryEntry kLayoutCategories[] = {
#endif
#ifdef MOZ_B2G_BT
{ "profile-after-change", "Bluetooth Service", BLUETOOTHSERVICE_CONTRACTID },
#endif
#ifdef MOZ_B2G_RIL
{ "profile-after-change", "MobileConnection Service", NS_MOBILE_CONNECTION_SERVICE_CONTRACTID },
#endif
{ nullptr }
};