1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
2 /* vim: set ts=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 #ifndef mozilla_dom_voicemail_voicemail_h__
8 #define mozilla_dom_voicemail_voicemail_h__
10 #include "mozilla/Attributes.h"
11 #include "mozilla/DOMEventTargetHelper.h"
12 #include "mozilla/ErrorResult.h"
13 #include "nsIVoicemailService.h"
23 class VoicemailStatus
;
25 class Voicemail MOZ_FINAL
: public DOMEventTargetHelper
,
26 private nsIVoicemailListener
29 * Class Voicemail doesn't actually expose nsIVoicemailListener. Instead, it
30 * owns an nsIVoicemailListener derived instance mListener and passes it to
31 * nsIVoicemailService. The onreceived events are first delivered to
32 * mListener and then forwarded to its owner, Voicemail. See also bug 775997
38 NS_DECL_ISUPPORTS_INHERITED
39 NS_DECL_NSIVOICEMAILLISTENER
41 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Voicemail
,
44 static already_AddRefed
<Voicemail
>
45 Create(nsPIDOMWindow
* aOwner
,
52 GetParentObject() const
58 WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
60 already_AddRefed
<VoicemailStatus
>
61 GetStatus(const Optional
<uint32_t>& aServiceId
,
65 GetNumber(const Optional
<uint32_t>& aServiceId
,
67 ErrorResult
& aRv
) const;
70 GetDisplayName(const Optional
<uint32_t>& aServiceId
,
71 nsString
& aDisplayName
,
72 ErrorResult
& aRv
) const;
74 IMPL_EVENT_HANDLER(statuschanged
)
77 Voicemail(nsPIDOMWindow
* aWindow
,
78 nsIVoicemailService
* aService
);
80 // MOZ_FINAL suppresses -Werror,-Wdelete-non-virtual-dtor
84 nsCOMPtr
<nsIVoicemailService
> mService
;
85 nsRefPtr
<Listener
> mListener
;
87 // |mStatuses| keeps all instantiated VoicemailStatus objects as well as the
88 // empty slots for not interested ones. The length of |mStatuses| is decided
89 // in the constructor and is never changed ever since.
90 nsAutoTArray
<nsRefPtr
<VoicemailStatus
>, 1> mStatuses
;
92 // Return a nsIVoicemailProvider instance based on the requests from external
93 // components. Return nullptr if aOptionalServiceId contains an invalid
94 // service id or the default one is just not available.
95 already_AddRefed
<nsIVoicemailProvider
>
96 GetItemByServiceId(const Optional
<uint32_t>& aOptionalServiceId
,
97 uint32_t& aActualServiceId
) const;
99 // Request for a valid VoicemailStatus object based on given service id and
100 // provider. It's the callee's responsibility to ensure the validity of the
102 already_AddRefed
<VoicemailStatus
>
103 GetOrCreateStatus(uint32_t aServiceId
,
104 nsIVoicemailProvider
* aProvider
);
108 } // namespace mozilla
110 #endif // mozilla_dom_voicemail_voicemail_h__