1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/MobileConnectionArray.h"
8 #include "mozilla/dom/MozMobileConnectionArrayBinding.h"
9 #include "mozilla/Preferences.h"
10 #include "nsServiceManagerUtils.h"
12 // Service instantiation
13 #include "ipc/ImsRegIPCService.h"
14 #include "ipc/MobileConnectionIPCService.h"
15 #if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
16 #include "nsIGonkMobileConnectionService.h"
18 #include "nsXULAppAPI.h" // For XRE_GetProcessType()
20 using namespace mozilla::dom
;
22 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(MobileConnectionArray
,
26 NS_IMPL_CYCLE_COLLECTING_ADDREF(MobileConnectionArray
)
27 NS_IMPL_CYCLE_COLLECTING_RELEASE(MobileConnectionArray
)
29 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MobileConnectionArray
)
30 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
31 NS_INTERFACE_MAP_ENTRY(nsISupports
)
34 MobileConnectionArray::MobileConnectionArray(nsPIDOMWindow
* aWindow
)
35 : mLengthInitialized(false)
40 MobileConnectionArray::~MobileConnectionArray()
45 MobileConnectionArray::GetParentObject() const
52 MobileConnectionArray::WrapObject(JSContext
* aCx
)
54 return MozMobileConnectionArrayBinding::Wrap(aCx
, this);
58 MobileConnectionArray::Item(uint32_t aIndex
)
61 return IndexedGetter(aIndex
, unused
);
65 MobileConnectionArray::Length()
67 if (!mLengthInitialized
) {
68 mLengthInitialized
= true;
70 nsCOMPtr
<nsIMobileConnectionService
> service
=
71 do_GetService(NS_MOBILE_CONNECTION_SERVICE_CONTRACTID
);
72 NS_ENSURE_TRUE(service
, 0);
75 nsresult rv
= service
->GetNumItems(&length
);
76 NS_ENSURE_SUCCESS(rv
, 0);
78 mMobileConnections
.SetLength(length
);
81 return mMobileConnections
.Length();
85 MobileConnectionArray::IndexedGetter(uint32_t aIndex
, bool& aFound
)
88 aFound
= aIndex
< Length();
93 if (!mMobileConnections
[aIndex
]) {
94 mMobileConnections
[aIndex
] = new MobileConnection(mWindow
, aIndex
);
97 return mMobileConnections
[aIndex
];
100 already_AddRefed
<nsIMobileConnectionService
>
101 NS_CreateMobileConnectionService()
103 nsCOMPtr
<nsIMobileConnectionService
> service
;
105 if (XRE_GetProcessType() == GeckoProcessType_Content
) {
106 service
= new mozilla::dom::mobileconnection::MobileConnectionIPCService();
108 #if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
109 service
= do_GetService(GONK_MOBILECONNECTION_SERVICE_CONTRACTID
);
113 return service
.forget();
116 already_AddRefed
<nsIImsRegService
>
117 NS_CreateImsRegService()
119 nsCOMPtr
<nsIImsRegService
> service
;
121 if (XRE_GetProcessType() == GeckoProcessType_Content
) {
122 // Could be nullptr if the IMS feature is not enabled by the device.
123 service
= mozilla::dom::mobileconnection::ImsRegIPCService::GetSingleton();
125 // Note: Gonk implementation is provided by OEM Vendor by replacing the
126 // XPCOM component of nsIImsRegService with bundle in parent process.
128 return service
.forget();