Bumping manifests a=b2g-bump
[gecko.git] / dom / mobileconnection / MobileConnectionArray.cpp
blob8b76990b4fd3e42117adcfb55b6547dd2620ff37
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"
17 #endif
18 #include "nsXULAppAPI.h" // For XRE_GetProcessType()
20 using namespace mozilla::dom;
22 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(MobileConnectionArray,
23 mWindow,
24 mMobileConnections)
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)
32 NS_INTERFACE_MAP_END
34 MobileConnectionArray::MobileConnectionArray(nsPIDOMWindow* aWindow)
35 : mLengthInitialized(false)
36 , mWindow(aWindow)
40 MobileConnectionArray::~MobileConnectionArray()
44 nsPIDOMWindow*
45 MobileConnectionArray::GetParentObject() const
47 MOZ_ASSERT(mWindow);
48 return mWindow;
51 JSObject*
52 MobileConnectionArray::WrapObject(JSContext* aCx)
54 return MozMobileConnectionArrayBinding::Wrap(aCx, this);
57 MobileConnection*
58 MobileConnectionArray::Item(uint32_t aIndex)
60 bool unused;
61 return IndexedGetter(aIndex, unused);
64 uint32_t
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);
74 uint32_t length = 0;
75 nsresult rv = service->GetNumItems(&length);
76 NS_ENSURE_SUCCESS(rv, 0);
78 mMobileConnections.SetLength(length);
81 return mMobileConnections.Length();
84 MobileConnection*
85 MobileConnectionArray::IndexedGetter(uint32_t aIndex, bool& aFound)
88 aFound = aIndex < Length();
89 if (!aFound) {
90 return nullptr;
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();
107 } else {
108 #if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
109 service = do_GetService(GONK_MOBILECONNECTION_SERVICE_CONTRACTID);
110 #endif
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();