From 968ef5e0c0f3fac16b6e33c8444cb152351757d8 Mon Sep 17 00:00:00 2001 From: B2G Bumper Bot Date: Fri, 27 Mar 2015 08:40:29 -0700 Subject: [PATCH 01/43] Bumping gaia.json for 2 gaia revision(s) a=gaia-bump ======== https://hg.mozilla.org/integration/gaia-central/rev/529a4dc689d0 Author: Eli Perelman Desc: Merge pull request #29201 from eliperelman/bug-1147949 Bug 1147949 - Bumping gaia-raptor to v1.2.2 a=npotb r=rwood ======== https://hg.mozilla.org/integration/gaia-central/rev/e033b6584b31 Author: Eli Perelman Desc: Bug 1147949 - Bumping gaia-raptor to v1.2.2 a=npotb r=rwood --- b2g/config/gaia.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/b2g/config/gaia.json b/b2g/config/gaia.json index 85a40bb6590f..1ca7e5a51d7c 100644 --- a/b2g/config/gaia.json +++ b/b2g/config/gaia.json @@ -1,9 +1,9 @@ { "git": { - "git_revision": "9cc496cecc37d7a29f9279827cdf6e4891211f67", + "git_revision": "2a4f05fce803758037b4600d52cc7b695f14cf6f", "remote": "https://git.mozilla.org/releases/gaia.git", "branch": "" }, - "revision": "9e79307fd6bcade07847b92d42948a6a6a334f79", + "revision": "529a4dc689d0f550f56e403f9fdd8aadd5ee5f12", "repo_path": "integration/gaia-central" } From 48555d6fecda92de48836ac104108f656602f4a4 Mon Sep 17 00:00:00 2001 From: B2G Bumper Bot Date: Fri, 27 Mar 2015 08:43:29 -0700 Subject: [PATCH 02/43] Bumping manifests a=b2g-bump --- b2g/config/dolphin/sources.xml | 2 +- b2g/config/emulator-ics/sources.xml | 2 +- b2g/config/emulator-jb/sources.xml | 2 +- b2g/config/emulator-kk/sources.xml | 2 +- b2g/config/emulator-l/sources.xml | 2 +- b2g/config/emulator/sources.xml | 2 +- b2g/config/flame-kk/sources.xml | 2 +- b2g/config/flame/sources.xml | 2 +- b2g/config/nexus-4/sources.xml | 2 +- b2g/config/nexus-5-l/sources.xml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/b2g/config/dolphin/sources.xml b/b2g/config/dolphin/sources.xml index b10343b76bb5..e08af37457d7 100644 --- a/b2g/config/dolphin/sources.xml +++ b/b2g/config/dolphin/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator-ics/sources.xml b/b2g/config/emulator-ics/sources.xml index 67cef928d532..26f7d1182aff 100644 --- a/b2g/config/emulator-ics/sources.xml +++ b/b2g/config/emulator-ics/sources.xml @@ -19,7 +19,7 @@ - + diff --git a/b2g/config/emulator-jb/sources.xml b/b2g/config/emulator-jb/sources.xml index 81e05baf0801..c83aacea9dbb 100644 --- a/b2g/config/emulator-jb/sources.xml +++ b/b2g/config/emulator-jb/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/emulator-kk/sources.xml b/b2g/config/emulator-kk/sources.xml index c0b8414fca82..f9e7e329f414 100644 --- a/b2g/config/emulator-kk/sources.xml +++ b/b2g/config/emulator-kk/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator-l/sources.xml b/b2g/config/emulator-l/sources.xml index 8289f658423a..e62c3d5f274c 100644 --- a/b2g/config/emulator-l/sources.xml +++ b/b2g/config/emulator-l/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator/sources.xml b/b2g/config/emulator/sources.xml index 67cef928d532..26f7d1182aff 100644 --- a/b2g/config/emulator/sources.xml +++ b/b2g/config/emulator/sources.xml @@ -19,7 +19,7 @@ - + diff --git a/b2g/config/flame-kk/sources.xml b/b2g/config/flame-kk/sources.xml index 218d323e3bc2..5d0b6846739c 100644 --- a/b2g/config/flame-kk/sources.xml +++ b/b2g/config/flame-kk/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/flame/sources.xml b/b2g/config/flame/sources.xml index e5efa8526740..c1c928162e29 100644 --- a/b2g/config/flame/sources.xml +++ b/b2g/config/flame/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/nexus-4/sources.xml b/b2g/config/nexus-4/sources.xml index ad340ad1623d..ed697414331b 100644 --- a/b2g/config/nexus-4/sources.xml +++ b/b2g/config/nexus-4/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/nexus-5-l/sources.xml b/b2g/config/nexus-5-l/sources.xml index d7cd587777ba..65648affde46 100644 --- a/b2g/config/nexus-5-l/sources.xml +++ b/b2g/config/nexus-5-l/sources.xml @@ -15,7 +15,7 @@ - + From 11d72f7806c4e5e91d02e4d119748e5068e8b41e Mon Sep 17 00:00:00 2001 From: B2G Bumper Bot Date: Fri, 27 Mar 2015 08:55:08 -0700 Subject: [PATCH 03/43] Bumping gaia.json for 2 gaia revision(s) a=gaia-bump ======== https://hg.mozilla.org/integration/gaia-central/rev/97a01eae9436 Author: Wilson Page Desc: Merge pull request #28991 from wilsonpage/1144830 Bug 1144830 - [Camera] Multiple volume-rocker presses ignores countdown timer and takes pictures during countdown ======== https://hg.mozilla.org/integration/gaia-central/rev/3be76c654cc8 Author: Wilson Page Desc: Bug 1144830 - [Camera] Multiple volume-rocker presses ignores countdown timer and takes pictures during countdown --- b2g/config/gaia.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/b2g/config/gaia.json b/b2g/config/gaia.json index 1ca7e5a51d7c..318d565aa1fa 100644 --- a/b2g/config/gaia.json +++ b/b2g/config/gaia.json @@ -1,9 +1,9 @@ { "git": { - "git_revision": "2a4f05fce803758037b4600d52cc7b695f14cf6f", + "git_revision": "0e7c8ade48129b3e03c5de8ae0452fd1f756535c", "remote": "https://git.mozilla.org/releases/gaia.git", "branch": "" }, - "revision": "529a4dc689d0f550f56e403f9fdd8aadd5ee5f12", + "revision": "97a01eae94361363300254b54e53e2ac0f0b9d38", "repo_path": "integration/gaia-central" } From 80266d21126724eb7e659923dd6ef752d419d5c3 Mon Sep 17 00:00:00 2001 From: B2G Bumper Bot Date: Fri, 27 Mar 2015 08:57:41 -0700 Subject: [PATCH 04/43] Bumping manifests a=b2g-bump --- b2g/config/dolphin/sources.xml | 2 +- b2g/config/emulator-ics/sources.xml | 2 +- b2g/config/emulator-jb/sources.xml | 2 +- b2g/config/emulator-kk/sources.xml | 2 +- b2g/config/emulator-l/sources.xml | 2 +- b2g/config/emulator/sources.xml | 2 +- b2g/config/flame-kk/sources.xml | 2 +- b2g/config/flame/sources.xml | 2 +- b2g/config/nexus-4/sources.xml | 2 +- b2g/config/nexus-5-l/sources.xml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/b2g/config/dolphin/sources.xml b/b2g/config/dolphin/sources.xml index e08af37457d7..84464b784b8a 100644 --- a/b2g/config/dolphin/sources.xml +++ b/b2g/config/dolphin/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator-ics/sources.xml b/b2g/config/emulator-ics/sources.xml index 26f7d1182aff..af4b384e7350 100644 --- a/b2g/config/emulator-ics/sources.xml +++ b/b2g/config/emulator-ics/sources.xml @@ -19,7 +19,7 @@ - + diff --git a/b2g/config/emulator-jb/sources.xml b/b2g/config/emulator-jb/sources.xml index c83aacea9dbb..53dd1284bf22 100644 --- a/b2g/config/emulator-jb/sources.xml +++ b/b2g/config/emulator-jb/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/emulator-kk/sources.xml b/b2g/config/emulator-kk/sources.xml index f9e7e329f414..25eccf8de183 100644 --- a/b2g/config/emulator-kk/sources.xml +++ b/b2g/config/emulator-kk/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator-l/sources.xml b/b2g/config/emulator-l/sources.xml index e62c3d5f274c..9559a0d3830e 100644 --- a/b2g/config/emulator-l/sources.xml +++ b/b2g/config/emulator-l/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator/sources.xml b/b2g/config/emulator/sources.xml index 26f7d1182aff..af4b384e7350 100644 --- a/b2g/config/emulator/sources.xml +++ b/b2g/config/emulator/sources.xml @@ -19,7 +19,7 @@ - + diff --git a/b2g/config/flame-kk/sources.xml b/b2g/config/flame-kk/sources.xml index 5d0b6846739c..c3b345667f71 100644 --- a/b2g/config/flame-kk/sources.xml +++ b/b2g/config/flame-kk/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/flame/sources.xml b/b2g/config/flame/sources.xml index c1c928162e29..ca15af3bc9cb 100644 --- a/b2g/config/flame/sources.xml +++ b/b2g/config/flame/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/nexus-4/sources.xml b/b2g/config/nexus-4/sources.xml index ed697414331b..a1b6aeb2526d 100644 --- a/b2g/config/nexus-4/sources.xml +++ b/b2g/config/nexus-4/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/nexus-5-l/sources.xml b/b2g/config/nexus-5-l/sources.xml index 65648affde46..d36e0e65f4e0 100644 --- a/b2g/config/nexus-5-l/sources.xml +++ b/b2g/config/nexus-5-l/sources.xml @@ -15,7 +15,7 @@ - + From 576426e43ee1c45405273d2dc533f8312b5d5109 Mon Sep 17 00:00:00 2001 From: Bevis Tseng Date: Wed, 31 Dec 2014 10:52:25 +0800 Subject: [PATCH 05/43] Bug 1114935 - Part 1: Define new nsIIccService/nsIGonkIccService to replace nsIIccProvider. r=echen --- dom/icc/Assertions.cpp | 6 +- dom/icc/interfaces/moz.build | 2 + dom/icc/interfaces/nsIGonkIccService.idl | 16 ++ dom/icc/interfaces/nsIIccProvider.idl | 137 +--------- dom/icc/interfaces/nsIIccService.idl | 315 +++++++++++++++++++++++ 5 files changed, 339 insertions(+), 137 deletions(-) create mode 100644 dom/icc/interfaces/nsIGonkIccService.idl create mode 100644 dom/icc/interfaces/nsIIccService.idl diff --git a/dom/icc/Assertions.cpp b/dom/icc/Assertions.cpp index 0f9c7a07a33e..d228b5ac9964 100644 --- a/dom/icc/Assertions.cpp +++ b/dom/icc/Assertions.cpp @@ -3,15 +3,15 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/dom/MozIccBinding.h" -#include "nsIIccProvider.h" +#include "nsIIccService.h" namespace mozilla { namespace dom { namespace icc { #define ASSERT_EQUALITY(webidlType, webidlState, xpidlState) \ - static_assert(static_cast(webidlType::webidlState) == nsIIccProvider::xpidlState, \ - #webidlType "::" #webidlState " should equal to nsIIccProvider::" #xpidlState) + static_assert(static_cast(webidlType::webidlState) == nsIIcc::xpidlState, \ + #webidlType "::" #webidlState " should equal to nsIIccService::" #xpidlState) /** * Enum IccCardState diff --git a/dom/icc/interfaces/moz.build b/dom/icc/interfaces/moz.build index 1bd27608e7bf..b95992c5919a 100644 --- a/dom/icc/interfaces/moz.build +++ b/dom/icc/interfaces/moz.build @@ -7,10 +7,12 @@ XPIDL_SOURCES += [ 'nsIIccInfo.idl', 'nsIIccProvider.idl', + 'nsIIccService.idl', ] if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk' and CONFIG['MOZ_B2G_RIL']: XPIDL_SOURCES += [ + 'nsIGonkIccService.idl', 'nsIIccMessenger.idl', ] diff --git a/dom/icc/interfaces/nsIGonkIccService.idl b/dom/icc/interfaces/nsIGonkIccService.idl new file mode 100644 index 000000000000..3a15bf541616 --- /dev/null +++ b/dom/icc/interfaces/nsIGonkIccService.idl @@ -0,0 +1,16 @@ +/* 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 "nsIIccService.idl" + +[scriptable, uuid(a037b8a2-b027-11e4-9496-c3b7af59a512)] +interface nsIGonkIccService : nsIIccService +{ + // TODO: Bug 1114938 - Refactor STK in MozIcc.webidl with IPDL: + // void notifyStkCommand(in unsigned long aServiceId, in jsval aStkcommand); + // void notifyStkSessionEnd(in unsigned long aServiceId); + void notifyCardStateChanged(in unsigned long aServiceId, in unsigned long aCardState); + void notifyIccInfoChanged(in unsigned long aServiceId, in jsval aIccInfo); + void notifyImsiChanged(in unsigned long aServiceId, in DOMString aImsi); +}; diff --git a/dom/icc/interfaces/nsIIccProvider.idl b/dom/icc/interfaces/nsIIccProvider.idl index 94f09d05d3b1..ec3d01ef0933 100644 --- a/dom/icc/interfaces/nsIIccProvider.idl +++ b/dom/icc/interfaces/nsIIccProvider.idl @@ -7,15 +7,7 @@ interface nsIDOMDOMRequest; interface nsIDOMWindow; interface nsIIccInfo; - -[scriptable, uuid(7c0ada3d-d8d4-493e-9243-fa3df39855e4)] -interface nsIIccListener : nsISupports -{ - void notifyStkCommand(in DOMString aMessage); - void notifyStkSessionEnd(); - void notifyCardStateChanged(); - void notifyIccInfoChanged(); -}; +interface nsIIccListener; [scriptable, uuid(6136acab-b50e-494a-a86d-df392a032897)] interface nsIIccChannelCallback : nsISupports @@ -58,83 +50,9 @@ interface nsIIccChannelCallback : nsISupports /** * XPCOM component (in the content process) that provides the ICC information. */ -[scriptable, uuid(a203cd2e-2280-4d8e-a687-42b745d322c1)] +[scriptable, uuid(7dd6e186-b007-11e4-9b7e-7717d7863cb8)] interface nsIIccProvider : nsISupports { - // MUST match enum IccCardState in MozIcc.webidl! - const unsigned long CARD_STATE_UNKNOWN = 0; - const unsigned long CARD_STATE_READY = 1; - const unsigned long CARD_STATE_PIN_REQUIRED = 2; - const unsigned long CARD_STATE_PUK_REQUIRED = 3; - const unsigned long CARD_STATE_PERMANENT_BLOCKED = 4; - const unsigned long CARD_STATE_PERSONALIZATION_IN_PROGRESS = 5; - const unsigned long CARD_STATE_PERSONALIZATION_READY = 6; - const unsigned long CARD_STATE_NETWORK_LOCKED = 7; - const unsigned long CARD_STATE_NETWORK_SUBSET_LOCKED = 8; - const unsigned long CARD_STATE_CORPORATE_LOCKED = 9; - const unsigned long CARD_STATE_SERVICE_PROVIDER_LOCKED = 10; - const unsigned long CARD_STATE_SIM_LOCKED = 11; - const unsigned long CARD_STATE_NETWORK_PUK_REQUIRED = 12; - const unsigned long CARD_STATE_NETWORK_SUBSET_PUK_REQUIRED = 13; - const unsigned long CARD_STATE_CORPORATE_PUK_REQUIRED = 14; - const unsigned long CARD_STATE_SERVICE_PROVIDER_PUK_REQUIRED = 15; - const unsigned long CARD_STATE_SIM_PUK_REQUIRED = 16; - const unsigned long CARD_STATE_NETWORK1_LOCKED = 17; - const unsigned long CARD_STATE_NETWORK2_LOCKED = 18; - const unsigned long CARD_STATE_HRPD_NETWORK_LOCKED = 19; - const unsigned long CARD_STATE_RUIM_CORPORATE_LOCKED = 20; - const unsigned long CARD_STATE_RUIM_SERVICE_PROVIDER_LOCKED = 21; - const unsigned long CARD_STATE_RUIM_LOCKED = 22; - const unsigned long CARD_STATE_NETWORK1_PUK_REQUIRED = 23; - const unsigned long CARD_STATE_NETWORK2_PUK_REQUIRED = 24; - const unsigned long CARD_STATE_HRPD_NETWORK_PUK_REQUIRED = 25; - const unsigned long CARD_STATE_RUIM_CORPORATE_PUK_REQUIRED = 26; - const unsigned long CARD_STATE_RUIM_SERVICE_PROVIDER_PUK_REQUIRED = 27; - const unsigned long CARD_STATE_RUIM_PUK_REQUIRED = 28; - const unsigned long CARD_STATE_ILLEGAL = 29; - - const unsigned long CARD_STATE_UNDETECTED = 4294967295; // UINT32_MAX - - // MUST match with enum IccLockType in MozIcc.webidl - const unsigned long CARD_LOCK_TYPE_PIN = 0; - const unsigned long CARD_LOCK_TYPE_PIN2 = 1; - const unsigned long CARD_LOCK_TYPE_PUK = 2; - const unsigned long CARD_LOCK_TYPE_PUK2 = 3; - const unsigned long CARD_LOCK_TYPE_NCK = 4; - const unsigned long CARD_LOCK_TYPE_NSCK = 5; - const unsigned long CARD_LOCK_TYPE_NCK1 = 6; - const unsigned long CARD_LOCK_TYPE_NCK2 = 7; - const unsigned long CARD_LOCK_TYPE_HNCK = 8; - const unsigned long CARD_LOCK_TYPE_CCK = 9; - const unsigned long CARD_LOCK_TYPE_SPCK = 10; - const unsigned long CARD_LOCK_TYPE_PCK = 11; - const unsigned long CARD_LOCK_TYPE_RCCK = 12; - const unsigned long CARD_LOCK_TYPE_RSPCK = 13; - const unsigned long CARD_LOCK_TYPE_NCK_PUK = 14; - const unsigned long CARD_LOCK_TYPE_NSCK_PUK = 15; - const unsigned long CARD_LOCK_TYPE_NCK1_PUK = 16; - const unsigned long CARD_LOCK_TYPE_NCK2_PUK = 17; - const unsigned long CARD_LOCK_TYPE_HNCK_PUK = 18; - const unsigned long CARD_LOCK_TYPE_CCK_PUK = 19; - const unsigned long CARD_LOCK_TYPE_SPCK_PUK = 20; - const unsigned long CARD_LOCK_TYPE_PCK_PUK = 21; - const unsigned long CARD_LOCK_TYPE_RCCK_PUK = 22; - const unsigned long CARD_LOCK_TYPE_RSPCK_PUK = 23; - const unsigned long CARD_LOCK_TYPE_FDN = 24; - - // MUST match with enum IccContactType in MozIcc.webidl - const unsigned long CARD_CONTACT_TYPE_ADN = 0; - const unsigned long CARD_CONTACT_TYPE_FDN = 1; - const unsigned long CARD_CONTACT_TYPE_SDN = 2; - - // MUST match with enum IccMvnoType in MozIcc.webidl - const unsigned long CARD_MVNO_TYPE_IMSI = 0; - const unsigned long CARD_MVNO_TYPE_SPN = 1; - const unsigned long CARD_MVNO_TYPE_GID = 2; - - // MUST match with enum IccService in MozIcc.webidl - const unsigned long CARD_SERVICE_FDN = 0; - /** * Called when a content process registers receiving unsolicited messages from * RadioInterfaceLayer in the chrome process. Only a content process that has @@ -143,18 +61,6 @@ interface nsIIccProvider : nsISupports void registerIccMsg(in unsigned long clientId, in nsIIccListener listener); void unregisterIccMsg(in unsigned long clientId, in nsIIccListener listener); - /** - * UICC Information - */ - nsIIccInfo getIccInfo(in unsigned long clientId); - - /** - * Card State - * - * One of the nsIIccProvider.CARD_STATE_* values. - */ - unsigned long getCardState(in unsigned long clientId); - /** * STK interfaces. */ @@ -173,31 +79,6 @@ interface nsIIccProvider : nsISupports in nsIDOMWindow window, in jsval event); - /** - * Card lock interfaces. - */ - nsIDOMDOMRequest getCardLockEnabled(in unsigned long clientId, - in nsIDOMWindow window, - in unsigned long lockType); - nsIDOMDOMRequest unlockCardLock(in unsigned long clientId, - in nsIDOMWindow window, - in unsigned long lockType, - in DOMString password, - [optional] in DOMString newPin); - nsIDOMDOMRequest setCardLockEnabled(in unsigned long clientId, - in nsIDOMWindow window, - in unsigned long lockType, - in DOMString password, - in boolean enabled); - nsIDOMDOMRequest changeCardLockPassword(in unsigned long clientId, - in nsIDOMWindow window, - in unsigned long lockType, - in DOMString password, - in DOMString newPassword); - nsIDOMDOMRequest getCardLockRetryCount(in unsigned long clientId, - in nsIDOMWindow window, - in unsigned long lockType); - /** * Phonebook interfaces. */ @@ -211,7 +92,7 @@ interface nsIIccProvider : nsISupports in jsval contact, in DOMString pin2); -/** + /** * Secure Card Icc communication channel */ void iccOpenChannel(in unsigned long clientId, @@ -238,16 +119,4 @@ interface nsIIccProvider : nsISupports void iccCloseChannel(in unsigned long clientId, in long channel, in nsIIccChannelCallback callback); - - /** - * Helpers - */ - nsIDOMDOMRequest matchMvno(in unsigned long clientId, - in nsIDOMWindow window, - in unsigned long mvnoType, - in DOMString mvnoData); - - nsISupports getServiceState(in unsigned long clientId, - in nsIDOMWindow window, - in unsigned long service); }; diff --git a/dom/icc/interfaces/nsIIccService.idl b/dom/icc/interfaces/nsIIccService.idl new file mode 100644 index 000000000000..a59362388fb9 --- /dev/null +++ b/dom/icc/interfaces/nsIIccService.idl @@ -0,0 +1,315 @@ +/* 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 "nsISupports.idl" + +interface nsIIcc; +interface nsIIccInfo; + +[scriptable, uuid(7c0ada3d-d8d4-493e-9243-fa3df39855e4)] +interface nsIIccListener : nsISupports +{ + void notifyStkCommand(in DOMString aMessage); + void notifyStkSessionEnd(); + void notifyCardStateChanged(); + void notifyIccInfoChanged(); +}; + +/** + * A callback interface for handling asynchronous response. + */ +[scriptable, uuid(b0e2899a-adc3-11e4-89cf-1b60eaa35b06)] +interface nsIIccCallback : nsISupports +{ + /** + * The success callback with no result required: + * |unlockCardLock|, |setCardLockEnabled| and |changeCardLockPassword|. + */ + void notifySuccess(); + + /** + * The success callback with boolean response: + * |getCardLockEnabled|, |matchMvno|, and |getServiceStateEnabled|. + */ + void notifySuccessWithBoolean(in boolean aResult); + + /** + * The success callback of |getCardLockRetryCount|. + * + * @param aCount + * The number of remaining retries. -1 if unknown. + */ + void notifyGetCardLockRetryCount(in long aCount); + + /** + * The error callback of |getCardLockEnabled|, |getCardLockRetryCount|, + * |matchMvno|, and |getServiceStateEnabled|. + * + * @param aErrorMsg + * The error message. + */ + void notifyError(in DOMString aErrorMsg); + + /** + * The error callback of |unlockCardLock|, |setCardLockEnabled| and + * |changeCardLockPassword|. + * + * @param aErrorMsg + * The error message. + * @param aRetryCount + * The number of remaining retries. -1 if unknown. + */ + void notifyCardLockError(in DOMString aErrorMsg, in long aRetryCount); +}; + +/** + * XPCOM Service for the selection of the ICC to be accessed. + */ +[scriptable, uuid(6590a04c-9ca4-11e4-ae95-570876ecc428)] +interface nsIIccService : nsISupports +{ + /** + * Get Icc instance with specified Service Id. + * + * @param aServiceId + * Started from 0 to nsIMobileConnectionService.numItems - 1; + * + * @return a nsIcc instance. + */ + nsIIcc getIccByServiceId(in unsigned long aServiceId); +}; + +/** + * XPCOM component that provides the access to the selected ICC. + */ +[scriptable, uuid(38a5bbe2-add6-11e4-ba9e-e390d1d19195)] +interface nsIIcc : nsISupports +{ + /** + * Card State Constants + * + * Note: MUST be matched with enum IccCardState in MozIcc.webidl! + */ + const unsigned long CARD_STATE_UNKNOWN = 0; + const unsigned long CARD_STATE_READY = 1; + const unsigned long CARD_STATE_PIN_REQUIRED = 2; + const unsigned long CARD_STATE_PUK_REQUIRED = 3; + const unsigned long CARD_STATE_PERMANENT_BLOCKED = 4; + const unsigned long CARD_STATE_PERSONALIZATION_IN_PROGRESS = 5; + const unsigned long CARD_STATE_PERSONALIZATION_READY = 6; + const unsigned long CARD_STATE_NETWORK_LOCKED = 7; + const unsigned long CARD_STATE_NETWORK_SUBSET_LOCKED = 8; + const unsigned long CARD_STATE_CORPORATE_LOCKED = 9; + const unsigned long CARD_STATE_SERVICE_PROVIDER_LOCKED = 10; + const unsigned long CARD_STATE_SIM_LOCKED = 11; + const unsigned long CARD_STATE_NETWORK_PUK_REQUIRED = 12; + const unsigned long CARD_STATE_NETWORK_SUBSET_PUK_REQUIRED = 13; + const unsigned long CARD_STATE_CORPORATE_PUK_REQUIRED = 14; + const unsigned long CARD_STATE_SERVICE_PROVIDER_PUK_REQUIRED = 15; + const unsigned long CARD_STATE_SIM_PUK_REQUIRED = 16; + const unsigned long CARD_STATE_NETWORK1_LOCKED = 17; + const unsigned long CARD_STATE_NETWORK2_LOCKED = 18; + const unsigned long CARD_STATE_HRPD_NETWORK_LOCKED = 19; + const unsigned long CARD_STATE_RUIM_CORPORATE_LOCKED = 20; + const unsigned long CARD_STATE_RUIM_SERVICE_PROVIDER_LOCKED = 21; + const unsigned long CARD_STATE_RUIM_LOCKED = 22; + const unsigned long CARD_STATE_NETWORK1_PUK_REQUIRED = 23; + const unsigned long CARD_STATE_NETWORK2_PUK_REQUIRED = 24; + const unsigned long CARD_STATE_HRPD_NETWORK_PUK_REQUIRED = 25; + const unsigned long CARD_STATE_RUIM_CORPORATE_PUK_REQUIRED = 26; + const unsigned long CARD_STATE_RUIM_SERVICE_PROVIDER_PUK_REQUIRED = 27; + const unsigned long CARD_STATE_RUIM_PUK_REQUIRED = 28; + const unsigned long CARD_STATE_ILLEGAL = 29; + + const unsigned long CARD_STATE_UNDETECTED = 4294967295; // UINT32_MAX + + /** + * Card Lock Constants + * + * Note: MUST be matched with enum IccLockType in MozIcc.webidl! + */ + const unsigned long CARD_LOCK_TYPE_PIN = 0; + const unsigned long CARD_LOCK_TYPE_PIN2 = 1; + const unsigned long CARD_LOCK_TYPE_PUK = 2; + const unsigned long CARD_LOCK_TYPE_PUK2 = 3; + const unsigned long CARD_LOCK_TYPE_NCK = 4; + const unsigned long CARD_LOCK_TYPE_NSCK = 5; + const unsigned long CARD_LOCK_TYPE_NCK1 = 6; + const unsigned long CARD_LOCK_TYPE_NCK2 = 7; + const unsigned long CARD_LOCK_TYPE_HNCK = 8; + const unsigned long CARD_LOCK_TYPE_CCK = 9; + const unsigned long CARD_LOCK_TYPE_SPCK = 10; + const unsigned long CARD_LOCK_TYPE_PCK = 11; + const unsigned long CARD_LOCK_TYPE_RCCK = 12; + const unsigned long CARD_LOCK_TYPE_RSPCK = 13; + const unsigned long CARD_LOCK_TYPE_NCK_PUK = 14; + const unsigned long CARD_LOCK_TYPE_NSCK_PUK = 15; + const unsigned long CARD_LOCK_TYPE_NCK1_PUK = 16; + const unsigned long CARD_LOCK_TYPE_NCK2_PUK = 17; + const unsigned long CARD_LOCK_TYPE_HNCK_PUK = 18; + const unsigned long CARD_LOCK_TYPE_CCK_PUK = 19; + const unsigned long CARD_LOCK_TYPE_SPCK_PUK = 20; + const unsigned long CARD_LOCK_TYPE_PCK_PUK = 21; + const unsigned long CARD_LOCK_TYPE_RCCK_PUK = 22; + const unsigned long CARD_LOCK_TYPE_RSPCK_PUK = 23; + const unsigned long CARD_LOCK_TYPE_FDN = 24; + + /** + * Contact Type Constants + * + * Note: MUST be matched with enum IccContactType in MozIcc.webidl! + */ + const unsigned long CARD_CONTACT_TYPE_ADN = 0; + const unsigned long CARD_CONTACT_TYPE_FDN = 1; + const unsigned long CARD_CONTACT_TYPE_SDN = 2; + + /** + * MVNO Type Constants + * + * Note: MUST be matched with enum IccMvnoType in MozIcc.webidl! + */ + const unsigned long CARD_MVNO_TYPE_IMSI = 0; + const unsigned long CARD_MVNO_TYPE_SPN = 1; + const unsigned long CARD_MVNO_TYPE_GID = 2; + + /** + * Card Service Constants + * + * Note: MUST be matched with enum IccService in MozIcc.webidl! + */ + const unsigned long CARD_SERVICE_FDN = 0; + + /** + * Called to register icc-related changes. + * + * 'mobileconnection' permission is required to register. + */ + void registerListener(in nsIIccListener aListener); + void unregisterListener(in nsIIccListener aListener); + + /** + * Information stored in this ICC. + */ + readonly attribute nsIIccInfo iccInfo; + + /** + * Indicates the state of this ICC. + * + * One of the CARD_STATE_* values. + */ + readonly attribute unsigned long cardState; + + /** + * Get the status of an ICC lock (e.g. the PIN lock). + * + * @param aLockType + * One of the CARD_LOCK_TYPE_* values. + * @param aCallback + * An instance of nsIIccCallback: + * nsIIccCallback::notifySuccessWithBoolean() if success. + * nsIIccCallback::notifyError(), otherwise. + */ + void getCardLockEnabled(in unsigned long aLockType, + in nsIIccCallback aCallback); + + /** + * Unlock a card lock. + * + * @param aLockType + * One of the CARD_LOCK_TYPE_* values. + * @param aPassword + * The password of this lock. + * @param aNewPin (Optional) + * The new PIN to be set after PUK/PUK2 is unlock. + * @param aCallback + * An instance of nsIIccCallback: + * nsIIccCallback::notifySuccess() if success. + * nsIIccCallback::notifyCardLockError(), otherwise. + */ + void unlockCardLock(in unsigned long aLockType, + in DOMString aPassword, + in DOMString aNewPin, + in nsIIccCallback aCallback); + + /** + * Enable/Disable a card lock. + * + * @param aLockType + * One of the CARD_LOCK_TYPE_* values. + * @param aPassword + * The password of this lock. + * @param aEnabled. + * True to enable the lock. False to disable, otherwise. + * @param aCallback + * An instance of nsIIccCallback: + * nsIIccCallback::notifySuccess() if success. + * nsIIccCallback::notifyCardLockError(), otherwise. + */ + void setCardLockEnabled(in unsigned long aLockType, + in DOMString aPassword, + in boolean aEnabled, + in nsIIccCallback aCallback); + + /** + * Change the password of a card lock. + * + * @param aLockType + * One of the CARD_LOCK_TYPE_* values. + * @param aPassword + * The password of this lock. + * @param aNewPassword. + * The new password of this lock. + * @param aCallback + * An instance of nsIIccCallback: + * nsIIccCallback::notifySuccess() if success. + * nsIIccCallback::notifyCardLockError(), otherwise. + */ + void changeCardLockPassword(in unsigned long aLockType, + in DOMString aPassword, + in DOMString aNewPassword, + in nsIIccCallback aCallback); + + /** + * Get the number of remaining tries of a lock. + * + * @param aLockType + * One of the CARD_LOCK_TYPE_* values. + * @param aCallback + * An instance of nsIIccCallback: + * nsIIccCallback::notifyGetCardLockRetryCount() if success. + * nsIIccCallback::notifyError(), otherwise. + */ + void getCardLockRetryCount(in unsigned long aLockType, + in nsIIccCallback aCallback); + + /** + * Verify whether the passed data (matchData) matches with some ICC's field + * according to the mvno type (mvnoType). + * + * @param aMvnoType + * One of CARD_MVNO_TYPE_* values. + * @param aMvnoData + * Data to be compared with ICC's field. + * @param aCallback + * An instance of nsIIccCallback: + * nsIIccCallback::notifySuccessWithBoolean() if success. + * nsIIccCallback::notifyError(), otherwise. + */ + void matchMvno(in unsigned long aMvnoType, + in DOMString aMvnoData, + in nsIIccCallback aCallback); + + /** + * Retrieve the the availability of an icc service. + * + * @param aService + * One of CARD_SERVICE_* values. + * @param aCallback + * An instance of nsIIccCallback: + * nsIIccCallback::notifySuccessWithBoolean() if success. + * nsIIccCallback::notifyError(), otherwise. + */ + void getServiceStateEnabled(in unsigned long aService, + in nsIIccCallback aCallback); +}; From a74633a3daffaaf71e22ce5d9700816787bfeb03 Mon Sep 17 00:00:00 2001 From: Bevis Tseng Date: Tue, 6 Jan 2015 13:32:08 +0800 Subject: [PATCH 06/43] Bug 1114935 - Part 2: Add Gonk Implementation of nsIIccService. r=echen --- b2g/installer/package-manifest.in | 2 + dom/icc/gonk/IccService.js | 437 +++++++++++++++++++++++++ dom/icc/gonk/IccService.manifest | 6 + dom/icc/moz.build | 4 + dom/system/gonk/RadioInterfaceLayer.js | 20 +- 5 files changed, 459 insertions(+), 10 deletions(-) create mode 100644 dom/icc/gonk/IccService.js create mode 100644 dom/icc/gonk/IccService.manifest diff --git a/b2g/installer/package-manifest.in b/b2g/installer/package-manifest.in index 9c8b06d8cf1f..f83ef86a1722 100644 --- a/b2g/installer/package-manifest.in +++ b/b2g/installer/package-manifest.in @@ -483,6 +483,8 @@ #if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL) @RESPATH@/components/CellBroadcastService.js @RESPATH@/components/CellBroadcastService.manifest +@BINPATH@/components/IccService.js +@BINPATH@/components/IccService.manifest @RESPATH@/components/MmsService.js @RESPATH@/components/MmsService.manifest @RESPATH@/components/MobileMessageDatabaseService.js diff --git a/dom/icc/gonk/IccService.js b/dom/icc/gonk/IccService.js new file mode 100644 index 000000000000..fa4ce0459d45 --- /dev/null +++ b/dom/icc/gonk/IccService.js @@ -0,0 +1,437 @@ +/* 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/. */ + +"use strict"; + +const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; + +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); +Cu.import("resource://gre/modules/Services.jsm"); + +var RIL = {}; +Cu.import("resource://gre/modules/ril_consts.js", RIL); + +const GONK_ICCSERVICE_CONTRACTID = "@mozilla.org/icc/gonkiccservice;1"; +const GONK_ICCSERVICE_CID = Components.ID("{df854256-9554-11e4-a16c-c39e8d106c26}"); + +const NS_XPCOM_SHUTDOWN_OBSERVER_ID = "xpcom-shutdown"; +const NS_PREFBRANCH_PREFCHANGE_TOPIC_ID = "nsPref:changed"; + +const kPrefRilDebuggingEnabled = "ril.debugging.enabled"; +const kPrefRilNumRadioInterfaces = "ril.numRadioInterfaces"; + +XPCOMUtils.defineLazyServiceGetter(this, "gRadioInterfaceLayer", + "@mozilla.org/ril;1", + "nsIRadioInterfaceLayer"); + +let DEBUG = RIL.DEBUG_RIL; +function debug(s) { + dump("IccService: " + s); +} + +function IccInfo() {} +IccInfo.prototype = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsIIccInfo]), + + // nsIIccInfo + + iccType: null, + iccid: null, + mcc: null, + mnc: null, + spn: null, + isDisplayNetworkNameRequired: false, + isDisplaySpnRequired: false +}; + +function GsmIccInfo() {} +GsmIccInfo.prototype = { + __proto__: IccInfo.prototype, + QueryInterface: XPCOMUtils.generateQI([Ci.nsIGsmIccInfo, + Ci.nsIIccInfo]), + + // nsIGsmIccInfo + + msisdn: null +}; + +function CdmaIccInfo() {} +CdmaIccInfo.prototype = { + __proto__: IccInfo.prototype, + QueryInterface: XPCOMUtils.generateQI([Ci.nsICdmaIccInfo, + Ci.nsIIccInfo]), + + // nsICdmaIccInfo + + mdn: null, + prlVersion: 0 +}; + +function IccService() { + this._iccs = []; + + let numClients = gRadioInterfaceLayer.numRadioInterfaces; + for (let i = 0; i < numClients; i++) { + this._iccs.push(new Icc(gRadioInterfaceLayer.getRadioInterface(i))); + } + + this._updateDebugFlag(); + + Services.prefs.addObserver(kPrefRilDebuggingEnabled, this, false); + Services.obs.addObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false); +} +IccService.prototype = { + classID: GONK_ICCSERVICE_CID, + + classInfo: XPCOMUtils.generateCI({classID: GONK_ICCSERVICE_CID, + contractID: GONK_ICCSERVICE_CONTRACTID, + classDescription: "IccService", + interfaces: [Ci.nsIIccService, + Ci.nsIGonkIccService], + flags: Ci.nsIClassInfo.SINGLETON}), + + QueryInterface: XPCOMUtils.generateQI([Ci.nsIIccService, + Ci.nsIGonkIccService, + Ci.nsIObserver]), + + // An array of Icc instances. + _iccs: null, + + _updateDebugFlag: function() { + try { + DEBUG = DEBUG || + Services.prefs.getBoolPref(kPrefRilDebuggingEnabled); + } catch (e) {} + }, + + /** + * nsIIccService interface. + */ + getIccByServiceId: function(aServiceId) { + let icc = this._iccs[aServiceId]; + if (!icc) { + throw Cr.NS_ERROR_UNEXPECTED; + } + + return icc; + }, + + /** + * nsIGonkIccService interface. + */ + notifyCardStateChanged: function(aServiceId, aCardState) { + if (DEBUG) { + debug("notifyCardStateChanged for service Id: " + aServiceId + + ", CardState: " + aCardState); + } + + this.getIccByServiceId(aServiceId)._updateCardState(aCardState); + }, + + notifyIccInfoChanged: function(aServiceId, aIccInfo) { + if (DEBUG) { + debug("notifyIccInfoChanged for service Id: " + aServiceId + + ", IccInfo: " + JSON.stringify(aIccInfo)); + } + + this.getIccByServiceId(aServiceId)._updateIccInfo(aIccInfo); + }, + + notifyImsiChanged: function(aServiceId, aImsi) { + if (DEBUG) { + debug("notifyImsiChanged for service Id: " + aServiceId + + ", Imsi: " + aImsi); + } + + let icc = this.getIccByServiceId(aServiceId); + icc._imsi = aImsi; + }, + + /** + * nsIObserver interface. + */ + observe: function(aSubject, aTopic, aData) { + switch (aTopic) { + case NS_PREFBRANCH_PREFCHANGE_TOPIC_ID: + if (aData === kPrefRilDebuggingEnabled) { + this._updateDebugFlag(); + } + break; + case NS_XPCOM_SHUTDOWN_OBSERVER_ID: + Services.prefs.removeObserver(kPrefRilDebuggingEnabled, this); + Services.obs.removeObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID); + break; + } + } +}; + +function Icc(aRadioInterface) { + this._radioInterface = aRadioInterface; + this._listeners = []; +} +Icc.prototype = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsIIcc]), + + _radioInterface: null, + _imsi: null, + _listeners: null, + + _updateCardState: function(aCardState) { + if (this.cardState != aCardState) { + this.cardState = aCardState; + } + + this._deliverListenerEvent("notifyCardStateChanged"); + }, + + // An utility function to copy objects. + _updateInfo: function(aSrcInfo, aDestInfo) { + for (let key in aSrcInfo) { + aDestInfo[key] = aSrcInfo[key]; + } + }, + + /** + * We need to consider below cases when update iccInfo: + * 1. Should clear iccInfo to null if there is no card detected. + * 2. Need to create corresponding object based on iccType. + */ + _updateIccInfo: function(aIccInfo) { + // Card is not detected, clear iccInfo to null. + if (!aIccInfo || !aIccInfo.iccid) { + if (this.iccInfo) { + if (DEBUG) { + debug("Card is not detected, clear iccInfo to null."); + } + this.iccInfo = null; + this._deliverListenerEvent("notifyIccInfoChanged"); + } + return; + } + + // If iccInfo is null, new corresponding object based on iccType. + if (!this.iccInfo || + this.iccInfo.iccType != aIccInfo.iccType) { + if (aIccInfo.iccType === "ruim" || aIccInfo.iccType === "csim") { + this.iccInfo = new CdmaIccInfo(); + } else if (aIccInfo.iccType === "sim" || aIccInfo.iccType === "usim") { + this.iccInfo = new GsmIccInfo(); + } else { + this.iccInfo = new IccInfo(); + } + } + + this._updateInfo(aIccInfo, this.iccInfo); + + this._deliverListenerEvent("notifyIccInfoChanged"); + + // Update lastKnownSimMcc. + if (aIccInfo.mcc) { + try { + Services.prefs.setCharPref("ril.lastKnownSimMcc", + aIccInfo.mcc.toString()); + } catch (e) {} + } + }, + + _deliverListenerEvent: function(aName, aArgs) { + let listeners = this._listeners.slice(); + for (let listener of listeners) { + if (this._listeners.indexOf(listener) === -1) { + continue; + } + let handler = listener[aName]; + if (typeof handler != "function") { + throw new Error("No handler for " + aName); + } + try { + handler.apply(listener, aArgs); + } catch (e) { + if (DEBUG) { + debug("listener for " + aName + " threw an exception: " + e); + } + } + } + }, + + _modifyCardLock: function(aOperation, aOptions, aCallback) { + this._radioInterface.sendWorkerMessage(aOperation, + aOptions, + (aResponse) => { + if (aResponse.errorMsg) { + let retryCount = + (aResponse.retryCount !== undefined) ? aResponse.retryCount : -1; + aCallback.notifyCardLockError(aResponse.errorMsg, retryCount); + return; + } + + aCallback.notifySuccess(); + }); + }, + + /** + * Helper to match the MVNO pattern with IMSI. + * + * Note: Characters 'x' and 'X' in MVNO are skipped and not compared. + * E.g., if the aMvnoData passed is '310260x10xxxxxx', then the + * function returns true only if imsi has the same first 6 digits, 8th + * and 9th digit. + * + * @param aMvnoData + * MVNO pattern. + * @param aImsi + * IMSI of this ICC. + * + * @return true if matched. + */ + _isImsiMatches: function(aMvnoData, aImsi) { + // This should not be an error, but a mismatch. + if (aMvnoData.length > aImsi.length) { + return false; + } + + for (let i = 0; i < aMvnoData.length; i++) { + let c = aMvnoData[i]; + if ((c !== 'x') && (c !== 'X') && (c !== aImsi[i])) { + return false; + } + } + return true; + }, + + /** + * nsIIcc interface. + */ + iccInfo: null, + cardState: Ci.nsIIcc.CARD_STATE_UNKNOWN, + + registerListener: function(aListener) { + if (this._listeners.indexOf(aListener) >= 0) { + throw Cr.NS_ERROR_UNEXPECTED; + } + + this._listeners.push(aListener); + }, + + unregisterListener: function(aListener) { + let index = this._listeners.indexOf(aListener); + if (index >= 0) { + this._listeners.splice(index, 1); + } + }, + + getCardLockEnabled: function(aLockType, aCallback) { + this._radioInterface.sendWorkerMessage("iccGetCardLockEnabled", + { lockType: aLockType }, + (aResponse) => { + if (aResponse.errorMsg) { + aCallback.notifyError(aResponse.errorMsg); + return; + } + + aCallback.notifySuccessWithBoolean(aResponse.enabled); + }); + }, + + unlockCardLock: function(aLockType, aPassword, aNewPin, aCallback) { + this._modifyCardLock("iccUnlockCardLock", + { lockType: aLockType, + password: aPassword, + newPin: aNewPin }, + aCallback); + }, + + setCardLockEnabled: function(aLockType, aPassword, aEnabled, aCallback) { + this._modifyCardLock("iccSetCardLockEnabled", + { lockType: aLockType, + password: aPassword, + enabled: aEnabled }, + aCallback); + }, + + changeCardLockPassword: function(aLockType, aPassword, aNewPassword, aCallback) { + this._modifyCardLock("iccChangeCardLockPassword", + { lockType: aLockType, + password: aPassword, + newPassword: aNewPassword, }, + aCallback); + }, + + getCardLockRetryCount: function(aLockType, aCallback) { + this._radioInterface.sendWorkerMessage("iccGetCardLockRetryCount", + { lockType: aLockType }, + (aResponse) => { + if (aResponse.errorMsg) { + aCallback.notifyError(aResponse.errorMsg); + return; + } + + aCallback.notifyGetCardLockRetryCount(aResponse.retryCount); + }); + }, + + matchMvno: function(aMvnoType, aMvnoData, aCallback) { + if (!aMvnoData) { + aCallback.notifyError(RIL.GECKO_ERROR_INVALID_PARAMETER); + return; + } + + switch (aMvnoType) { + case Ci.nsIIcc.CARD_MVNO_TYPE_IMSI: + let imsi = this._imsi; + if (!imsi) { + aCallback.notifyError(RIL.GECKO_ERROR_GENERIC_FAILURE); + break; + } + aCallback.notifySuccessWithBoolean( + this._isImsiMatches(aMvnoData, imsi)); + break; + case Ci.nsIIcc.CARD_MVNO_TYPE_SPN: + let spn = this.iccInfo && this.iccInfo.spn; + if (!spn) { + aCallback.notifyError(RIL.GECKO_ERROR_GENERIC_FAILURE); + break; + } + aCallback.notifySuccessWithBoolean(spn == aMvnoData); + break; + case Ci.nsIIcc.CARD_MVNO_TYPE_GID: + this._radioInterface.sendWorkerMessage("getGID1", + null, + (aResponse) => { + let gid = aResponse.gid1; + let mvnoDataLength = aMvnoData.length; + + if (!gid) { + aCallback.notifyError(RIL.GECKO_ERROR_GENERIC_FAILURE); + } else if (mvnoDataLength > gid.length) { + aCallback.notifySuccessWithBoolean(false); + } else { + let result = + gid.substring(0, mvnoDataLength).toLowerCase() == + aMvnoData.toLowerCase(); + aCallback.notifySuccessWithBoolean(result); + } + }); + break; + default: + aCallback.notifyError(RIL.GECKO_ERROR_MODE_NOT_SUPPORTED); + break; + } + }, + + getServiceStateEnabled: function(aService, aCallback) { + this._radioInterface.sendWorkerMessage("getIccServiceState", + { service: aService }, + (aResponse) => { + if (aResponse.errorMsg) { + aCallback.notifyError(aResponse.errorMsg); + return; + } + + aCallback.notifySuccessWithBoolean(aResponse.result); + }); + } +}; + +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([IccService]); diff --git a/dom/icc/gonk/IccService.manifest b/dom/icc/gonk/IccService.manifest new file mode 100644 index 000000000000..dcff16c67635 --- /dev/null +++ b/dom/icc/gonk/IccService.manifest @@ -0,0 +1,6 @@ +# 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/. + +component {df854256-9554-11e4-a16c-c39e8d106c26} IccService.js +contract @mozilla.org/icc/gonkiccservice;1 {df854256-9554-11e4-a16c-c39e8d106c26} \ No newline at end of file diff --git a/dom/icc/moz.build b/dom/icc/moz.build index 9421feb10d9f..709a7eae37bb 100644 --- a/dom/icc/moz.build +++ b/dom/icc/moz.build @@ -26,6 +26,10 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk' and CONFIG['MOZ_B2G_RIL']: EXTRA_JS_MODULES += [ 'gonk/StkProactiveCmdFactory.jsm', ] + EXTRA_COMPONENTS += [ + 'gonk/IccService.js', + 'gonk/IccService.manifest', + ] FAIL_ON_WARNINGS = True diff --git a/dom/system/gonk/RadioInterfaceLayer.js b/dom/system/gonk/RadioInterfaceLayer.js index 06ae761883f2..e1a88e9362b5 100644 --- a/dom/system/gonk/RadioInterfaceLayer.js +++ b/dom/system/gonk/RadioInterfaceLayer.js @@ -127,6 +127,10 @@ function debug(s) { dump("-*- RadioInterfaceLayer: " + s + "\n"); } +XPCOMUtils.defineLazyServiceGetter(this, "gIccService", + "@mozilla.org/icc/gonkiccservice;1", + "nsIGonkIccService"); + XPCOMUtils.defineLazyServiceGetter(this, "gMobileMessageService", "@mozilla.org/mobilemessage/mobilemessageservice;1", "nsIMobileMessageService"); @@ -886,8 +890,8 @@ IccInfo.prototype = { mcc: null, mnc: null, spn: null, - isDisplayNetworkNameRequired: null, - isDisplaySpnRequired: null + isDisplayNetworkNameRequired: false, + isDisplaySpnRequired: false }; function GsmIccInfo() {} @@ -1916,6 +1920,8 @@ RadioInterface.prototype = { case "cardstatechange": this.rilContext.cardState = message.cardState; gRadioEnabledController.receiveCardState(this.clientId); + gIccService.notifyCardStateChanged(this.clientId, + this.rilContext.cardState); gMessageManager.sendIccMessage("RIL:CardStateChanged", this.clientId, message); break; @@ -1933,6 +1939,7 @@ RadioInterface.prototype = { break; case "iccimsi": this.rilContext.imsi = message.imsi; + gIccService.notifyImsiChanged(this.clientId, this.rilContext.imsi); break; case "iccmbdn": this.handleIccMbdn(message); @@ -2245,14 +2252,7 @@ RadioInterface.prototype = { gMessageManager.sendIccMessage("RIL:IccInfoChanged", this.clientId, message.iccid ? message : null); - - // Update lastKnownSimMcc. - if (message.mcc) { - try { - Services.prefs.setCharPref("ril.lastKnownSimMcc", - message.mcc.toString()); - } catch (e) {} - } + gIccService.notifyIccInfoChanged(this.clientId, this.rilContext.iccInfo); // Update lastKnownHomeNetwork. if (message.mcc && message.mnc) { From 3d463ac8400557cb2e0199c1a2185996fc38db60 Mon Sep 17 00:00:00 2001 From: Bevis Tseng Date: Wed, 7 Jan 2015 14:53:21 +0800 Subject: [PATCH 07/43] Bug 1114935 - Part 3: Define new IPDL Protocol for nsIIccService. r=echen --- dom/icc/ipc/PIcc.ipdl | 111 +++++++++++++++++++++++++++++++++++ dom/icc/ipc/PIccRequest.ipdl | 61 +++++++++++++++++++ dom/icc/ipc/PIccTypes.ipdlh | 24 ++++++++ dom/icc/moz.build | 6 ++ dom/ipc/PContent.ipdl | 4 ++ 5 files changed, 206 insertions(+) create mode 100644 dom/icc/ipc/PIcc.ipdl create mode 100644 dom/icc/ipc/PIccRequest.ipdl create mode 100644 dom/icc/ipc/PIccTypes.ipdlh diff --git a/dom/icc/ipc/PIcc.ipdl b/dom/icc/ipc/PIcc.ipdl new file mode 100644 index 000000000000..88edc2b17fdc --- /dev/null +++ b/dom/icc/ipc/PIcc.ipdl @@ -0,0 +1,111 @@ +/* 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 protocol PContent; +include protocol PIccRequest; +include PIccTypes; + +using struct mozilla::void_t from "ipc/IPCMessageUtils.h"; + +namespace mozilla { +namespace dom { +namespace icc { + +union OptionalIccInfoData +{ + void_t; + IccInfoData; +}; + +struct GetCardLockEnabledRequest +{ + uint32_t lockType; +}; + +struct UnlockCardLockRequest +{ + uint32_t lockType; + nsString password; + nsString newPin; +}; + +struct SetCardLockEnabledRequest +{ + uint32_t lockType; + nsString password; + bool enabled; +}; + +struct ChangeCardLockPasswordRequest +{ + uint32_t lockType; + nsString password; + nsString newPassword; +}; + +struct GetCardLockRetryCountRequest +{ + uint32_t lockType; +}; + +struct MatchMvnoRequest +{ + uint32_t mvnoType; + nsString mvnoData; +}; + +struct GetServiceStateEnabledRequest +{ + uint32_t service; +}; + +union IccRequest +{ + GetCardLockEnabledRequest; + UnlockCardLockRequest; + SetCardLockEnabledRequest; + ChangeCardLockPasswordRequest; + GetCardLockRetryCountRequest; + MatchMvnoRequest; + GetServiceStateEnabledRequest; +}; + +sync protocol PIcc +{ + manager PContent; + manages PIccRequest; + +child: + /** + * Notify CardStateChanged with updated CardState. + */ + NotifyCardStateChanged(uint32_t aCardState); + + /** + * Notify IccInfoChanged with updated IccInfo. + */ + NotifyIccInfoChanged(OptionalIccInfoData aInfoData); + +parent: + /** + * Sent when the child no longer needs to use PIcc. + */ + __delete__(); + + /** + * Sent when the child makes an asynchronous request to the parent. + */ + PIccRequest(IccRequest aRequest); + + /** + * Sync call to initialize the updated IccInfo/CardState. + */ + sync Init() + returns (OptionalIccInfoData aInfoData, uint32_t aCardState); + +}; + +} // namespace icc +} // namespace dom +} // namespace mozilla \ No newline at end of file diff --git a/dom/icc/ipc/PIccRequest.ipdl b/dom/icc/ipc/PIccRequest.ipdl new file mode 100644 index 000000000000..afe2c386491c --- /dev/null +++ b/dom/icc/ipc/PIccRequest.ipdl @@ -0,0 +1,61 @@ +/* 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 protocol PIcc; +include PIccTypes; + +namespace mozilla { +namespace dom { +namespace icc { + +struct IccReplySuccess +{ +}; + +struct IccReplySuccessWithBoolean +{ + bool result; +}; + +struct IccReplyCardLockRetryCount +{ + int32_t count; +}; + +struct IccReplyError +{ + nsString message; +}; + +struct IccReplyCardLockError +{ + int32_t retryCount; + nsString message; +}; + +union IccReply +{ + // Success + IccReplySuccess; + IccReplySuccessWithBoolean; + IccReplyCardLockRetryCount; + // Error + IccReplyError; + IccReplyCardLockError; +}; + +protocol PIccRequest +{ + manager PIcc; + +child: + /** + * Sent when the asynchronous request has completed. + */ + __delete__(IccReply response); +}; + +} // namespace icc +} // namespace dom +} // namespace mozilla \ No newline at end of file diff --git a/dom/icc/ipc/PIccTypes.ipdlh b/dom/icc/ipc/PIccTypes.ipdlh new file mode 100644 index 000000000000..1a463f8ebc51 --- /dev/null +++ b/dom/icc/ipc/PIccTypes.ipdlh @@ -0,0 +1,24 @@ +/* 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/. */ + +namespace mozilla { +namespace dom { +namespace icc { + +struct IccInfoData +{ + nsString iccType; + nsString iccid; + nsString mcc; + nsString mnc; + nsString spn; + bool isDisplayNetworkNameRequired; + bool isDisplaySpnRequired; + nsString phoneNumber; + int32_t prlVersion; +}; + +} // namespace icc +} // namespace dom +} // namespace mozilla \ No newline at end of file diff --git a/dom/icc/moz.build b/dom/icc/moz.build index 709a7eae37bb..68021f067a20 100644 --- a/dom/icc/moz.build +++ b/dom/icc/moz.build @@ -22,6 +22,12 @@ UNIFIED_SOURCES += [ 'IccManager.cpp', ] +IPDL_SOURCES += [ + 'ipc/PIcc.ipdl', + 'ipc/PIccRequest.ipdl', + 'ipc/PIccTypes.ipdlh', +] + if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk' and CONFIG['MOZ_B2G_RIL']: EXTRA_JS_MODULES += [ 'gonk/StkProactiveCmdFactory.jsm', diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index 26354d71fae1..3528b1359c9c 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -21,6 +21,7 @@ include protocol PFileDescriptorSet; include protocol PFMRadio; include protocol PFileSystemRequest; include protocol PHal; +include protocol PIcc; include protocol PProcessHangMonitor; include protocol PImageBridge; include protocol PMemoryReportRequest; @@ -379,6 +380,7 @@ prio(normal upto urgent) sync protocol PContent manages PFileDescriptorSet; manages PFMRadio; manages PHal; + manages PIcc; manages PMemoryReportRequest; manages PMobileConnection; manages PNecko; @@ -656,6 +658,8 @@ parent: PHal(); + PIcc(uint32_t serviceId); + PMobileConnection(uint32_t clientId); PNecko(); From 77e154f569c7f9dbcc6b57f7211aa3798894c2b6 Mon Sep 17 00:00:00 2001 From: Bevis Tseng Date: Wed, 7 Jan 2015 19:25:22 +0800 Subject: [PATCH 08/43] Bug 1114935 - Part 4.1: Add Support of nsIIccInfo to IccInfo. r=echen --- dom/icc/IccInfo.cpp | 234 ++++++++++++++++++++++++++++---------------- dom/icc/IccInfo.h | 38 +++++-- 2 files changed, 177 insertions(+), 95 deletions(-) diff --git a/dom/icc/IccInfo.cpp b/dom/icc/IccInfo.cpp index e651e6077d10..ce032eedcf7b 100644 --- a/dom/icc/IccInfo.cpp +++ b/dom/icc/IccInfo.cpp @@ -4,6 +4,7 @@ #include "mozilla/dom/IccInfo.h" +#include "mozilla/dom/icc/PIccTypes.h" #include "nsPIDOMWindow.h" #define CONVERT_STRING_TO_NULLABLE_ENUM(_string, _enumType, _enum) \ @@ -20,29 +21,110 @@ using namespace mozilla::dom; +using mozilla::dom::icc::IccInfoData; + // IccInfo -NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(IccInfo, mWindow, mIccInfo) +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(IccInfo, mWindow) NS_IMPL_CYCLE_COLLECTING_ADDREF(IccInfo) NS_IMPL_CYCLE_COLLECTING_RELEASE(IccInfo) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IccInfo) + NS_INTERFACE_MAP_ENTRY(nsIIccInfo) NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY - NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END IccInfo::IccInfo(nsPIDOMWindow* aWindow) : mWindow(aWindow) { + mIccType.SetIsVoid(true); + mIccid.SetIsVoid(true); + mMcc.SetIsVoid(true); + mMnc.SetIsVoid(true); + mSpn.SetIsVoid(true); +} + +IccInfo::IccInfo(const IccInfoData& aData) +{ + mIccType = aData.iccType(); + mIccid = aData.iccid(); + mMcc = aData.mcc(); + mMnc = aData.mnc(); + mSpn = aData.spn(); + mIsDisplayNetworkNameRequired = aData.isDisplayNetworkNameRequired(); + mIsDisplaySpnRequired = aData.isDisplaySpnRequired(); +} + +// nsIIccInfo + +NS_IMETHODIMP +IccInfo::GetIccType(nsAString & aIccType) +{ + aIccType = mIccType; + return NS_OK; +} + +NS_IMETHODIMP +IccInfo::GetIccid(nsAString & aIccid) +{ + aIccid = mIccid; + return NS_OK; +} + +NS_IMETHODIMP +IccInfo::GetMcc(nsAString & aMcc) +{ + aMcc = mMcc; + return NS_OK; +} + +NS_IMETHODIMP +IccInfo::GetMnc(nsAString & aMnc) +{ + aMnc = mMnc; + return NS_OK; +} + +NS_IMETHODIMP +IccInfo::GetSpn(nsAString & aSpn) +{ + aSpn = mSpn; + return NS_OK; +} + +NS_IMETHODIMP +IccInfo::GetIsDisplayNetworkNameRequired(bool *aIsDisplayNetworkNameRequired) +{ + *aIsDisplayNetworkNameRequired = mIsDisplayNetworkNameRequired; + return NS_OK; +} + +NS_IMETHODIMP +IccInfo::GetIsDisplaySpnRequired(bool *aIsDisplaySpnRequired) +{ + *aIsDisplaySpnRequired = mIsDisplaySpnRequired; + return NS_OK; } void IccInfo::Update(nsIIccInfo* aInfo) { - mIccInfo = aInfo; + NS_ASSERTION(aInfo, "aInfo is null"); + + aInfo->GetIccType(mIccType); + aInfo->GetIccid(mIccid); + aInfo->GetMcc(mMcc); + aInfo->GetMnc(mMnc); + aInfo->GetSpn(mSpn); + aInfo->GetIsDisplayNetworkNameRequired( + &mIsDisplayNetworkNameRequired); + aInfo->GetIsDisplaySpnRequired( + &mIsDisplaySpnRequired); } +// WebIDL implementation + JSObject* IccInfo::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { @@ -52,15 +134,9 @@ IccInfo::WrapObject(JSContext* aCx, JS::Handle aGivenProto) Nullable IccInfo::GetIccType() const { - if (!mIccInfo) { - return Nullable(); - } - - nsAutoString type; Nullable iccType; - mIccInfo->GetIccType(type); - CONVERT_STRING_TO_NULLABLE_ENUM(type, IccType, iccType); + CONVERT_STRING_TO_NULLABLE_ENUM(mIccType, IccType, iccType); return iccType; } @@ -68,96 +144,76 @@ IccInfo::GetIccType() const void IccInfo::GetIccid(nsAString& aIccId) const { - if (!mIccInfo) { - aIccId.SetIsVoid(true); - return; - } - - mIccInfo->GetIccid(aIccId); + aIccId = mIccid; } void IccInfo::GetMcc(nsAString& aMcc) const { - if (!mIccInfo) { - aMcc.SetIsVoid(true); - return; - } - - mIccInfo->GetMcc(aMcc); + aMcc = mMcc; } void IccInfo::GetMnc(nsAString& aMnc) const { - if (!mIccInfo) { - aMnc.SetIsVoid(true); - return; - } - - mIccInfo->GetMnc(aMnc); + aMnc = mMnc; } void IccInfo::GetSpn(nsAString& aSpn) const { - if (!mIccInfo) { - aSpn.SetIsVoid(true); - return; - } - - mIccInfo->GetSpn(aSpn); + aSpn = mSpn; } bool IccInfo::IsDisplayNetworkNameRequired() const { - if (!mIccInfo) { - return false; - } - - bool isDisplayNetworkNameRequired; - mIccInfo->GetIsDisplayNetworkNameRequired(&isDisplayNetworkNameRequired); - - return isDisplayNetworkNameRequired; + return mIsDisplayNetworkNameRequired; } bool IccInfo::IsDisplaySpnRequired() const { - if (!mIccInfo) { - return false; - } - - bool isDisplaySpnRequired; - mIccInfo->GetIsDisplaySpnRequired(&isDisplaySpnRequired); - - return isDisplaySpnRequired; + return mIsDisplaySpnRequired; } // GsmIccInfo -NS_IMPL_CYCLE_COLLECTION_INHERITED(GsmIccInfo, IccInfo, mGsmIccInfo) - -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(GsmIccInfo) -NS_INTERFACE_MAP_END_INHERITING(IccInfo) - -NS_IMPL_ADDREF_INHERITED(GsmIccInfo, IccInfo) -NS_IMPL_RELEASE_INHERITED(GsmIccInfo, IccInfo) +NS_IMPL_ISUPPORTS_INHERITED(GsmIccInfo, IccInfo, nsIGsmIccInfo) GsmIccInfo::GsmIccInfo(nsPIDOMWindow* aWindow) : IccInfo(aWindow) { + mPhoneNumber.SetIsVoid(true); } +GsmIccInfo::GsmIccInfo(const IccInfoData& aData) + : IccInfo(aData) +{ + mPhoneNumber = aData.phoneNumber(); +} + +// nsIGsmIccInfo + +NS_IMETHODIMP +GsmIccInfo::GetMsisdn(nsAString & aMsisdn) +{ + aMsisdn = mPhoneNumber; + return NS_OK; +} + +// WebIDL implementation + void GsmIccInfo::Update(nsIGsmIccInfo* aInfo) { + MOZ_ASSERT(aInfo); nsCOMPtr iccInfo = do_QueryInterface(aInfo); MOZ_ASSERT(iccInfo); IccInfo::Update(iccInfo); - mGsmIccInfo = aInfo; + + aInfo->GetMsisdn(mPhoneNumber); } JSObject* @@ -169,39 +225,57 @@ GsmIccInfo::WrapObject(JSContext* aCx, JS::Handle aGivenProto) void GsmIccInfo::GetMsisdn(nsAString& aMsisdn) const { - if (!mGsmIccInfo) { - aMsisdn.SetIsVoid(true); - return; - } - - mGsmIccInfo->GetMsisdn(aMsisdn); + aMsisdn = mPhoneNumber; } // CdmaIccInfo -NS_IMPL_CYCLE_COLLECTION_INHERITED(CdmaIccInfo, IccInfo, mCdmaIccInfo) - -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(CdmaIccInfo) -NS_INTERFACE_MAP_END_INHERITING(IccInfo) - -NS_IMPL_ADDREF_INHERITED(CdmaIccInfo, IccInfo) -NS_IMPL_RELEASE_INHERITED(CdmaIccInfo, IccInfo) +NS_IMPL_ISUPPORTS_INHERITED(CdmaIccInfo, IccInfo, nsICdmaIccInfo) CdmaIccInfo::CdmaIccInfo(nsPIDOMWindow* aWindow) : IccInfo(aWindow) { + mPhoneNumber.SetIsVoid(true); +} + +CdmaIccInfo::CdmaIccInfo(const IccInfoData& aData) + : IccInfo(aData) +{ + mPhoneNumber = aData.phoneNumber(); + mPrlVersion = aData.prlVersion(); +} + +// nsICdmaIccInfo + +NS_IMETHODIMP +CdmaIccInfo::GetMdn(nsAString & aMdn) +{ + aMdn = mPhoneNumber; + return NS_OK; +} + +NS_IMETHODIMP +CdmaIccInfo::GetPrlVersion(int32_t *aPrlVersion) +{ + *aPrlVersion = mPrlVersion; + return NS_OK; } void CdmaIccInfo::Update(nsICdmaIccInfo* aInfo) { + MOZ_ASSERT(aInfo); nsCOMPtr iccInfo = do_QueryInterface(aInfo); MOZ_ASSERT(iccInfo); IccInfo::Update(iccInfo); - mCdmaIccInfo = aInfo; + + aInfo->GetMdn(mPhoneNumber); + aInfo->GetPrlVersion(&mPrlVersion); } +// WebIDL implementation + JSObject* CdmaIccInfo::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { @@ -211,23 +285,11 @@ CdmaIccInfo::WrapObject(JSContext* aCx, JS::Handle aGivenProto) void CdmaIccInfo::GetMdn(nsAString& aMdn) const { - if (!mCdmaIccInfo) { - aMdn.SetIsVoid(true); - return; - } - - mCdmaIccInfo->GetMdn(aMdn); + aMdn = mPhoneNumber; } int32_t CdmaIccInfo::PrlVersion() const { - if (!mCdmaIccInfo) { - return 0; - } - - int32_t prlVersion; - mCdmaIccInfo->GetPrlVersion(&prlVersion); - - return prlVersion; + return mPrlVersion; } diff --git a/dom/icc/IccInfo.h b/dom/icc/IccInfo.h index a934ae6130e7..a9b35a1aeff3 100644 --- a/dom/icc/IccInfo.h +++ b/dom/icc/IccInfo.h @@ -14,14 +14,20 @@ class nsPIDOMWindow; namespace mozilla { namespace dom { -class IccInfo : public nsISupports +namespace icc { +class IccInfoData; +} // namespace icc + +class IccInfo : public nsIIccInfo , public nsWrapperCache { public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IccInfo) + NS_DECL_NSIICCINFO explicit IccInfo(nsPIDOMWindow* aWindow); + explicit IccInfo(const icc::IccInfoData& aData); void Update(nsIIccInfo* aInfo); @@ -61,18 +67,30 @@ public: protected: virtual ~IccInfo() {} -protected: nsCOMPtr mWindow; - nsCOMPtr mIccInfo; + // To prevent compiling error in OS_WIN in auto-generated UnifiedBindingsXX.cpp, + // we have all data fields expended here instead of having a data member of + // |IccInfoData| defined in PIccTypes.h which indirectly includes "windows.h" + // See 925382 for the restriction of including "windows.h" in UnifiedBindings.cpp. + nsString mIccType; + nsString mIccid; + nsString mMcc; + nsString mMnc; + nsString mSpn; + bool mIsDisplayNetworkNameRequired; + bool mIsDisplaySpnRequired; }; class GsmIccInfo final : public IccInfo + , public nsIGsmIccInfo { public: NS_DECL_ISUPPORTS_INHERITED - NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(GsmIccInfo, IccInfo) + NS_FORWARD_NSIICCINFO(IccInfo::) + NS_DECL_NSIGSMICCINFO explicit GsmIccInfo(nsPIDOMWindow* aWindow); + explicit GsmIccInfo(const icc::IccInfoData& aData); void Update(nsIGsmIccInfo* aInfo); @@ -88,17 +106,19 @@ public: private: ~GsmIccInfo() {} -private: - nsCOMPtr mGsmIccInfo; + nsString mPhoneNumber; }; class CdmaIccInfo final : public IccInfo + , public nsICdmaIccInfo { public: NS_DECL_ISUPPORTS_INHERITED - NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CdmaIccInfo, IccInfo) + NS_FORWARD_NSIICCINFO(IccInfo::) + NS_DECL_NSICDMAICCINFO explicit CdmaIccInfo(nsPIDOMWindow* aWindow); + explicit CdmaIccInfo(const icc::IccInfoData& aData); void Update(nsICdmaIccInfo* aInfo); @@ -117,8 +137,8 @@ public: private: ~CdmaIccInfo() {} -private: - nsCOMPtr mCdmaIccInfo; + nsString mPhoneNumber; + int32_t mPrlVersion; }; } // namespace dom From 1cba772979d8ab5411af7dd4f6af656630994cbc Mon Sep 17 00:00:00 2001 From: Bevis Tseng Date: Wed, 7 Jan 2015 16:58:35 +0800 Subject: [PATCH 09/43] Bug 1114935 - Part 4.2: Add IPC Implementation of nsIIccService. r=echen --- dom/icc/ipc/IccChild.cpp | 310 ++++++++++++++++++++++++++++++++ dom/icc/ipc/IccChild.h | 86 +++++++++ dom/icc/ipc/IccIPCService.cpp | 56 ++++++ dom/icc/ipc/IccIPCService.h | 35 ++++ dom/icc/ipc/IccParent.cpp | 320 ++++++++++++++++++++++++++++++++++ dom/icc/ipc/IccParent.h | 107 ++++++++++++ dom/icc/moz.build | 8 + dom/ipc/ContentChild.cpp | 27 +++ dom/ipc/ContentChild.h | 7 + dom/ipc/ContentParent.cpp | 23 +++ dom/ipc/ContentParent.h | 5 +- 11 files changed, 983 insertions(+), 1 deletion(-) create mode 100644 dom/icc/ipc/IccChild.cpp create mode 100644 dom/icc/ipc/IccChild.h create mode 100644 dom/icc/ipc/IccIPCService.cpp create mode 100644 dom/icc/ipc/IccIPCService.h create mode 100644 dom/icc/ipc/IccParent.cpp create mode 100644 dom/icc/ipc/IccParent.h diff --git a/dom/icc/ipc/IccChild.cpp b/dom/icc/ipc/IccChild.cpp new file mode 100644 index 000000000000..df988183966e --- /dev/null +++ b/dom/icc/ipc/IccChild.cpp @@ -0,0 +1,310 @@ +/* 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 "mozilla/dom/icc/IccChild.h" +#include "IccInfo.h" + +using mozilla::dom::IccInfo; + +namespace mozilla { +namespace dom { +namespace icc { + +/** + * PIccChild Implementation. + */ + +IccChild::IccChild() + : mCardState(nsIIcc::CARD_STATE_UNKNOWN) + , mIsAlive(true) +{ + MOZ_COUNT_CTOR(IccChild); +} + +IccChild::~IccChild() +{ + MOZ_COUNT_DTOR(IccChild); +} + +void +IccChild::Init() +{ + OptionalIccInfoData infoData; + + bool rv = SendInit(&infoData, &mCardState); + NS_ENSURE_TRUE_VOID(rv); + + UpdateIccInfo(infoData); +} + +void +IccChild::Shutdown(){ + if (mIsAlive) { + mIsAlive = false; + Send__delete__(this); + } + + mListeners.Clear(); + mIccInfo = nullptr; + mCardState = nsIIcc::CARD_STATE_UNKNOWN; +} + +void +IccChild::ActorDestroy(ActorDestroyReason why) +{ + mIsAlive = false; +} + +bool +IccChild::RecvNotifyCardStateChanged(const uint32_t& aCardState) +{ + mCardState = aCardState; + + for (int32_t i = 0; i < mListeners.Count(); i++) { + mListeners[i]->NotifyCardStateChanged(); + } + + return true; +} + +bool +IccChild::RecvNotifyIccInfoChanged(const OptionalIccInfoData& aInfoData) +{ + UpdateIccInfo(aInfoData); + + for (int32_t i = 0; i < mListeners.Count(); i++) { + mListeners[i]->NotifyIccInfoChanged(); + } + + return true; +} + +PIccRequestChild* +IccChild::AllocPIccRequestChild(const IccRequest& aRequest) +{ + MOZ_CRASH("Caller is supposed to manually construct a request!"); +} + +bool +IccChild::DeallocPIccRequestChild(PIccRequestChild* aActor) +{ + delete aActor; + return true; +} + +bool +IccChild::SendRequest(const IccRequest& aRequest, nsIIccCallback* aRequestReply) +{ + NS_ENSURE_TRUE(mIsAlive, false); + + // Deallocated in IccChild::DeallocPIccRequestChild(). + IccRequestChild* actor = new IccRequestChild(aRequestReply); + SendPIccRequestConstructor(actor, aRequest); + + return true; +} + +void +IccChild::UpdateIccInfo(const OptionalIccInfoData& aInfoData) { + if (aInfoData.type() == OptionalIccInfoData::Tvoid_t) { + mIccInfo = nullptr; + return; + } + + NS_ENSURE_TRUE_VOID(aInfoData.type() == OptionalIccInfoData::TIccInfoData); + + nsRefPtr iccInfo; + const IccInfoData& infoData = aInfoData.get_IccInfoData(); + if (infoData.iccType().EqualsLiteral("sim") + || infoData.iccType().EqualsLiteral("usim")) { + iccInfo = new GsmIccInfo(infoData); + } else if (infoData.iccType().EqualsLiteral("ruim") + || infoData.iccType().EqualsLiteral("csim")){ + iccInfo = new CdmaIccInfo(infoData); + } else { + iccInfo = new IccInfo(infoData); + } + + // We update the orignal one instead of replacing with a new one + // if the IccType is the same. + if (mIccInfo) { + nsString oldIccType; + nsString newIccType; + mIccInfo->GetIccType(oldIccType); + iccInfo->GetIccType(newIccType); + + if (oldIccType.Equals(newIccType)) { + mIccInfo->Update(iccInfo); + return; + } + } + + mIccInfo = iccInfo; +} + +/** + * nsIIcc Implementation. + */ + +NS_IMPL_ISUPPORTS(IccChild, nsIIcc) + +NS_IMETHODIMP +IccChild::RegisterListener(nsIIccListener *aListener) +{ + NS_ENSURE_TRUE(!mListeners.Contains(aListener), NS_ERROR_UNEXPECTED); + + mListeners.AppendObject(aListener); + return NS_OK; +} + +NS_IMETHODIMP +IccChild::UnregisterListener(nsIIccListener *aListener) +{ + NS_ENSURE_TRUE(mListeners.Contains(aListener), NS_ERROR_UNEXPECTED); + + mListeners.RemoveObject(aListener); + return NS_OK; +} + +NS_IMETHODIMP +IccChild::GetIccInfo(nsIIccInfo** aIccInfo) +{ + nsCOMPtr info(mIccInfo); + info.forget(aIccInfo); + return NS_OK; +} + +NS_IMETHODIMP +IccChild::GetCardState(uint32_t* aCardState) +{ + *aCardState = mCardState; + return NS_OK; +} + +NS_IMETHODIMP +IccChild::GetCardLockEnabled(uint32_t aLockType, + nsIIccCallback* aRequestReply) +{ + return SendRequest(GetCardLockEnabledRequest(aLockType), aRequestReply) + ? NS_OK : NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +IccChild::UnlockCardLock(uint32_t aLockType, + const nsAString& aPassword, + const nsAString& aNewPin, + nsIIccCallback* aRequestReply) +{ + return SendRequest(UnlockCardLockRequest(aLockType, + nsString(aPassword), + nsString(aNewPin)), + aRequestReply) + ? NS_OK : NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +IccChild::SetCardLockEnabled(uint32_t aLockType, + const nsAString& aPassword, + bool aEnabled, + nsIIccCallback* aRequestReply) +{ + return SendRequest(SetCardLockEnabledRequest(aLockType, + nsString(aPassword), + aEnabled), + aRequestReply) + ? NS_OK : NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +IccChild::ChangeCardLockPassword(uint32_t aLockType, + const nsAString& aPassword, + const nsAString& aNewPassword, + nsIIccCallback* aRequestReply) +{ + return SendRequest(ChangeCardLockPasswordRequest(aLockType, + nsString(aPassword), + nsString(aNewPassword)), + aRequestReply) + ? NS_OK : NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +IccChild::GetCardLockRetryCount(uint32_t aLockType, + nsIIccCallback* aRequestReply) +{ + return SendRequest(GetCardLockRetryCountRequest(aLockType), aRequestReply) + ? NS_OK : NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +IccChild::MatchMvno(uint32_t aMvnoType, + const nsAString& aMvnoData, + nsIIccCallback* aRequestReply) +{ + return SendRequest(MatchMvnoRequest(aMvnoType, nsString(aMvnoData)), + aRequestReply) + ? NS_OK : NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +IccChild::GetServiceStateEnabled(uint32_t aService, + nsIIccCallback* aRequestReply) +{ + return SendRequest(GetServiceStateEnabledRequest(aService), + aRequestReply) + ? NS_OK : NS_ERROR_FAILURE; +} + +/** + * PIccRequestChild Implementation. + */ + +IccRequestChild::IccRequestChild(nsIIccCallback* aRequestReply) + : mRequestReply(aRequestReply) +{ + MOZ_COUNT_CTOR(IccRequestChild); + MOZ_ASSERT(aRequestReply); +} + +bool +IccRequestChild::Recv__delete__(const IccReply& aResponse) +{ + MOZ_ASSERT(mRequestReply); + + switch(aResponse.type()) { + case IccReply::TIccReplySuccess: + return NS_SUCCEEDED(mRequestReply->NotifySuccess()); + case IccReply::TIccReplySuccessWithBoolean: { + const IccReplySuccessWithBoolean& resultWithBoolean + = aResponse.get_IccReplySuccessWithBoolean(); + return NS_SUCCEEDED( + mRequestReply->NotifySuccessWithBoolean(resultWithBoolean.result())); + } + case IccReply::TIccReplyCardLockRetryCount: { + const IccReplyCardLockRetryCount& retryCount + = aResponse.get_IccReplyCardLockRetryCount(); + return NS_SUCCEEDED( + mRequestReply->NotifyGetCardLockRetryCount(retryCount.count())); + } + case IccReply::TIccReplyError: { + const IccReplyError& error = aResponse.get_IccReplyError(); + return NS_SUCCEEDED(mRequestReply->NotifyError(error.message())); + } + case IccReply::TIccReplyCardLockError: { + const IccReplyCardLockError& error + = aResponse.get_IccReplyCardLockError(); + return NS_SUCCEEDED( + mRequestReply->NotifyCardLockError(error.message(), + error.retryCount())); + } + default: + MOZ_CRASH("Received invalid response type!"); + } + + return true; +} + +} // namespace icc +} // namespace dom +} // namespace mozilla \ No newline at end of file diff --git a/dom/icc/ipc/IccChild.h b/dom/icc/ipc/IccChild.h new file mode 100644 index 000000000000..5d5f3b0d90de --- /dev/null +++ b/dom/icc/ipc/IccChild.h @@ -0,0 +1,86 @@ +/* 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_icc_IccChild_h +#define mozilla_dom_icc_IccChild_h + +#include "mozilla/dom/icc/PIccChild.h" +#include "mozilla/dom/icc/PIccRequestChild.h" +#include "nsIIccService.h" + +namespace mozilla { +namespace dom { + +class IccInfo; + +namespace icc { + +class IccChild final : public PIccChild + , public nsIIcc +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIICC + + explicit IccChild(); + +void + Init(); + + void + Shutdown(); + +protected: + virtual void + ActorDestroy(ActorDestroyReason why) override; + + virtual PIccRequestChild* + AllocPIccRequestChild(const IccRequest& aRequest) override; + + virtual bool + DeallocPIccRequestChild(PIccRequestChild* aActor) override; + + virtual bool + RecvNotifyCardStateChanged(const uint32_t& aCardState) override; + + virtual bool + RecvNotifyIccInfoChanged(const OptionalIccInfoData& aInfoData) override; + +private: + ~IccChild(); + + void + UpdateIccInfo(const OptionalIccInfoData& aInfoData); + + bool + SendRequest(const IccRequest& aRequest, nsIIccCallback* aRequestReply); + + nsCOMArray mListeners; + nsRefPtr mIccInfo; + uint32_t mCardState; + bool mIsAlive; +}; + +class IccRequestChild final : public PIccRequestChild +{ +public: + explicit IccRequestChild(nsIIccCallback* aRequestReply); + +protected: + virtual bool + Recv__delete__(const IccReply& aReply) override; + +private: + virtual ~IccRequestChild() { + MOZ_COUNT_DTOR(IccRequestChild); + } + + nsCOMPtr mRequestReply; +}; + +} // namespace icc +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_icc_IccChild_h diff --git a/dom/icc/ipc/IccIPCService.cpp b/dom/icc/ipc/IccIPCService.cpp new file mode 100644 index 000000000000..64b4e43ddfc0 --- /dev/null +++ b/dom/icc/ipc/IccIPCService.cpp @@ -0,0 +1,56 @@ +/* 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 "IccIPCService.h" + +#include "mozilla/dom/ContentChild.h" +#include "mozilla/Preferences.h" + +namespace mozilla { +namespace dom { +namespace icc { + +NS_IMPL_ISUPPORTS(IccIPCService, nsIIccService) + +IccIPCService::IccIPCService() +{ + int32_t numRil = Preferences::GetInt("ril.numRadioInterfaces", 1); + mIccs.SetLength(numRil); +} + +IccIPCService::~IccIPCService() +{ + uint32_t count = mIccs.Length(); + for (uint32_t i = 0; i < count; i++) { + if (mIccs[i]) { + mIccs[i]->Shutdown(); + } + } +} + +NS_IMETHODIMP +IccIPCService::GetIccByServiceId(uint32_t aServiceId, nsIIcc** aIcc) +{ + NS_ENSURE_TRUE(aServiceId < mIccs.Length(), NS_ERROR_INVALID_ARG); + + if (!mIccs[aServiceId]) { + nsRefPtr child = new IccChild(); + + // |SendPIccConstructor| adds another reference to the child + // actor and removes in |DeallocPIccChild|. + ContentChild::GetSingleton()->SendPIccConstructor(child, aServiceId); + child->Init(); + + mIccs[aServiceId] = child; + } + + nsCOMPtr icc(mIccs[aServiceId]); + icc.forget(aIcc); + + return NS_OK; +} + +} // namespace icc +} // namespace dom +} // namespace mozilla diff --git a/dom/icc/ipc/IccIPCService.h b/dom/icc/ipc/IccIPCService.h new file mode 100644 index 000000000000..0eb086158c3c --- /dev/null +++ b/dom/icc/ipc/IccIPCService.h @@ -0,0 +1,35 @@ +/* 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_icc_IccIPCService_h +#define mozilla_dom_icc_IccIPCService_h + +#include "nsCOMPtr.h" +#include "nsIIccService.h" + +namespace mozilla { +namespace dom { +namespace icc { + +class IccChild; + +class IccIPCService final : public nsIIccService +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIICCSERVICE + + IccIPCService(); + +private: + ~IccIPCService(); + + nsTArray> mIccs; +}; + +} // namespace icc +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_icc_IccIPCService_h \ No newline at end of file diff --git a/dom/icc/ipc/IccParent.cpp b/dom/icc/ipc/IccParent.cpp new file mode 100644 index 000000000000..f6f996cddc2b --- /dev/null +++ b/dom/icc/ipc/IccParent.cpp @@ -0,0 +1,320 @@ +/* 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 "mozilla/dom/icc/IccParent.h" +#include "nsIIccService.h" +#include "IccInfo.h" + +using mozilla::dom::IccInfo; + +namespace mozilla { +namespace dom { +namespace icc { + +namespace { + +static void +GetIccInfoDataFromIccInfo(nsIIccInfo* aInInfo, IccInfoData& aOutData) { + aInInfo->GetIccType(aOutData.iccType()); + aInInfo->GetIccid(aOutData.iccid()); + aInInfo->GetMcc(aOutData.mcc()); + aInInfo->GetMnc(aOutData.mnc()); + aInInfo->GetSpn(aOutData.spn()); + aInInfo->GetIsDisplayNetworkNameRequired( + &aOutData.isDisplayNetworkNameRequired()); + aInInfo->GetIsDisplaySpnRequired( + &aOutData.isDisplaySpnRequired()); + + nsCOMPtr gsmIccInfo(do_QueryInterface(aInInfo)); + if (gsmIccInfo) { + gsmIccInfo->GetMsisdn(aOutData.phoneNumber()); + } + + nsCOMPtr cdmaIccInfo(do_QueryInterface(aInInfo)); + if (cdmaIccInfo) { + cdmaIccInfo->GetMdn(aOutData.phoneNumber()); + cdmaIccInfo->GetPrlVersion(&aOutData.prlVersion()); + } +} + +} // anonymous namespace + +/** + * PIccParent Implementation. + */ + +IccParent::IccParent(uint32_t aServiceId) +{ + MOZ_COUNT_CTOR(IccParent); + + nsCOMPtr service = + do_GetService(ICC_SERVICE_CONTRACTID); + + NS_ASSERTION(service, "Failed to get IccService!"); + + service->GetIccByServiceId(aServiceId, getter_AddRefs(mIcc)); + + NS_ASSERTION(mIcc, "Failed to get Icc with specified serviceId."); + + mIcc->RegisterListener(this); +} + +void +IccParent::ActorDestroy(ActorDestroyReason aWhy) +{ + if (mIcc) { + mIcc->UnregisterListener(this); + mIcc = nullptr; + } +} + +bool +IccParent::RecvInit(OptionalIccInfoData* aInfoData, + uint32_t* aCardState) +{ + NS_ENSURE_TRUE(mIcc, false); + + nsresult rv = mIcc->GetCardState(aCardState); + NS_ENSURE_SUCCESS(rv, false); + + nsCOMPtr iccInfo; + rv = mIcc->GetIccInfo(getter_AddRefs(iccInfo)); + NS_ENSURE_SUCCESS(rv, false); + + if (iccInfo) { + IccInfoData data; + GetIccInfoDataFromIccInfo(iccInfo, data); + *aInfoData = OptionalIccInfoData(data); + + return true; + } + + *aInfoData = OptionalIccInfoData(void_t()); + + return true; +} + +PIccRequestParent* +IccParent::AllocPIccRequestParent(const IccRequest& aRequest) +{ + NS_ASSERTION(mIcc, "AllocPIccRequestParent after actor was destroyed!"); + + IccRequestParent* actor = new IccRequestParent(mIcc); + // Add an extra ref for IPDL. Will be released in + // IccParent::DeallocPIccRequestParent(). + actor->AddRef(); + return actor; +} + +bool +IccParent::DeallocPIccRequestParent(PIccRequestParent* aActor) +{ + // IccRequestParent is refcounted, must not be freed manually. + static_cast(aActor)->Release(); + return true; +} + +bool +IccParent::RecvPIccRequestConstructor(PIccRequestParent* aActor, + const IccRequest& aRequest) +{ + NS_ASSERTION(mIcc, "RecvPIccRequestConstructor after actor was destroyed!"); + + IccRequestParent* actor = static_cast(aActor); + + switch (aRequest.type()) { + case IccRequest::TGetCardLockEnabledRequest: + return actor->DoRequest(aRequest.get_GetCardLockEnabledRequest()); + case IccRequest::TUnlockCardLockRequest: + return actor->DoRequest(aRequest.get_UnlockCardLockRequest()); + case IccRequest::TSetCardLockEnabledRequest: + return actor->DoRequest(aRequest.get_SetCardLockEnabledRequest()); + case IccRequest::TChangeCardLockPasswordRequest: + return actor->DoRequest(aRequest.get_ChangeCardLockPasswordRequest()); + case IccRequest::TGetCardLockRetryCountRequest: + return actor->DoRequest(aRequest.get_GetCardLockRetryCountRequest()); + case IccRequest::TMatchMvnoRequest: + return actor->DoRequest(aRequest.get_MatchMvnoRequest()); + case IccRequest::TGetServiceStateEnabledRequest: + return actor->DoRequest(aRequest.get_GetServiceStateEnabledRequest()); + default: + MOZ_CRASH("Received invalid request type!"); + } + + return true; +} + +/** + * nsIIccListener Implementation. + */ + +NS_IMPL_ISUPPORTS(IccParent, nsIIccListener) + +NS_IMETHODIMP +IccParent::NotifyStkCommand(const nsAString & aMessage) +{ + // Bug 1114938 - [B2G][ICC] Refactor STK in MozIcc.webidl with IPDL. + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +IccParent::NotifyStkSessionEnd() +{ + // Bug 1114938 - [B2G][ICC] Refactor STK in MozIcc.webidl with IPDL. + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +IccParent::NotifyCardStateChanged() +{ + NS_ENSURE_TRUE(mIcc, NS_ERROR_FAILURE); + + uint32_t cardState; + nsresult rv = mIcc->GetCardState(&cardState); + NS_ENSURE_SUCCESS(rv, rv); + + return SendNotifyCardStateChanged(cardState) ? NS_OK : NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +IccParent::NotifyIccInfoChanged() +{ + NS_ENSURE_TRUE(mIcc, NS_ERROR_FAILURE); + + nsCOMPtr iccInfo; + nsresult rv = mIcc->GetIccInfo(getter_AddRefs(iccInfo)); + NS_ENSURE_SUCCESS(rv, rv); + + if (!iccInfo) { + return SendNotifyIccInfoChanged(OptionalIccInfoData(void_t())) + ? NS_OK : NS_ERROR_FAILURE; + } + + IccInfoData data; + GetIccInfoDataFromIccInfo(iccInfo, data); + + return SendNotifyIccInfoChanged(OptionalIccInfoData(data)) + ? NS_OK : NS_ERROR_FAILURE; +} + +/** + * PIccRequestParent Implementation. + */ + +IccRequestParent::IccRequestParent(nsIIcc* aIcc) + : mIcc(aIcc) +{ + MOZ_COUNT_CTOR(IccRequestParent); +} + +void +IccRequestParent::ActorDestroy(ActorDestroyReason aWhy) +{ + mIcc = nullptr; +} + +bool +IccRequestParent::DoRequest(const GetCardLockEnabledRequest& aRequest) +{ + return NS_SUCCEEDED(mIcc->GetCardLockEnabled(aRequest.lockType(), + this)); +} + +bool +IccRequestParent::DoRequest(const UnlockCardLockRequest& aRequest) +{ + return NS_SUCCEEDED(mIcc->UnlockCardLock(aRequest.lockType(), + aRequest.password(), + aRequest.newPin(), + this)); +} + +bool +IccRequestParent::DoRequest(const SetCardLockEnabledRequest& aRequest) +{ + return NS_SUCCEEDED(mIcc->SetCardLockEnabled(aRequest.lockType(), + aRequest.password(), + aRequest.enabled(), + this)); +} + +bool +IccRequestParent::DoRequest(const ChangeCardLockPasswordRequest& aRequest) +{ + return NS_SUCCEEDED(mIcc->ChangeCardLockPassword(aRequest.lockType(), + aRequest.password(), + aRequest.newPassword(), + this)); +} + +bool +IccRequestParent::DoRequest(const GetCardLockRetryCountRequest& aRequest) +{ + return NS_SUCCEEDED(mIcc->GetCardLockRetryCount(aRequest.lockType(), + this)); +} + +bool +IccRequestParent::DoRequest(const MatchMvnoRequest& aRequest) +{ + return NS_SUCCEEDED(mIcc->MatchMvno(aRequest.mvnoType(), + aRequest.mvnoData(), + this)); +} + +bool +IccRequestParent::DoRequest(const GetServiceStateEnabledRequest& aRequest) +{ + return NS_SUCCEEDED(mIcc->GetServiceStateEnabled(aRequest.service(), + this)); +} + +nsresult +IccRequestParent::SendReply(const IccReply& aReply) +{ + NS_ENSURE_TRUE(mIcc, NS_ERROR_FAILURE); + + return Send__delete__(this, aReply) ? NS_OK : NS_ERROR_FAILURE; +} + +/** + * nsIIccCallback Implementation. + */ + +NS_IMPL_ISUPPORTS(IccRequestParent, nsIIccCallback) + +NS_IMETHODIMP +IccRequestParent::NotifySuccess() +{ + return SendReply(IccReplySuccess()); +} + +NS_IMETHODIMP +IccRequestParent::NotifySuccessWithBoolean(bool aResult) +{ + return SendReply(IccReplySuccessWithBoolean(aResult)); +} + +NS_IMETHODIMP +IccRequestParent::NotifyGetCardLockRetryCount(int32_t aCount) +{ + return SendReply(IccReplyCardLockRetryCount(aCount)); +} + +NS_IMETHODIMP +IccRequestParent::NotifyError(const nsAString & aErrorMsg) +{ + return SendReply(IccReplyError(nsString(aErrorMsg))); +} + +NS_IMETHODIMP +IccRequestParent::NotifyCardLockError(const nsAString & aErrorMsg, + int32_t aRetryCount) +{ + return SendReply(IccReplyCardLockError(aRetryCount, nsString(aErrorMsg))); +} + +} // namespace icc +} // namespace dom +} // namespace mozilla \ No newline at end of file diff --git a/dom/icc/ipc/IccParent.h b/dom/icc/ipc/IccParent.h new file mode 100644 index 000000000000..68013dbe0726 --- /dev/null +++ b/dom/icc/ipc/IccParent.h @@ -0,0 +1,107 @@ +/* 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_icc_IccParent_h +#define mozilla_dom_icc_IccParent_h + +#include "mozilla/dom/icc/PIccParent.h" +#include "mozilla/dom/icc/PIccRequestParent.h" +#include "nsIIccService.h" + +namespace mozilla { +namespace dom { +namespace icc { + +class IccParent final : public PIccParent + , public nsIIccListener +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIICCLISTENER + + explicit IccParent(uint32_t aServiceId); + +protected: + virtual + ~IccParent() + { + MOZ_COUNT_DTOR(IccParent); + } + + virtual void + ActorDestroy(ActorDestroyReason aWhy) override; + + virtual bool + RecvInit( + OptionalIccInfoData* aInfoData, + uint32_t* aCardState) override; + + virtual PIccRequestParent* + AllocPIccRequestParent(const IccRequest& aRequest) override; + + virtual bool + DeallocPIccRequestParent(PIccRequestParent* aActor) override; + + virtual bool + RecvPIccRequestConstructor(PIccRequestParent* aActor, + const IccRequest& aRequest) override; + +private: + IccParent(); + nsCOMPtr mIcc; +}; + +class IccRequestParent final : public PIccRequestParent + , public nsIIccCallback +{ + friend class IccParent; + +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIICCCALLBACK + + explicit IccRequestParent(nsIIcc* icc); + +protected: + virtual void + ActorDestroy(ActorDestroyReason why) override; + +private: + ~IccRequestParent() + { + MOZ_COUNT_DTOR(IccRequestParent); + } + + bool + DoRequest(const GetCardLockEnabledRequest& aRequest); + + bool + DoRequest(const UnlockCardLockRequest& aRequest); + + bool + DoRequest(const SetCardLockEnabledRequest& aRequest); + + bool + DoRequest(const ChangeCardLockPasswordRequest& aRequest); + + bool + DoRequest(const GetCardLockRetryCountRequest& aRequest); + + bool + DoRequest(const MatchMvnoRequest& aRequest); + + bool + DoRequest(const GetServiceStateEnabledRequest& aRequest); + + nsresult + SendReply(const IccReply& aReply); + + nsCOMPtr mIcc; +}; + +} // namespace icc +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_icc_IccParent_h diff --git a/dom/icc/moz.build b/dom/icc/moz.build index 68021f067a20..6184ac370958 100644 --- a/dom/icc/moz.build +++ b/dom/icc/moz.build @@ -13,6 +13,11 @@ EXPORTS.mozilla.dom += [ 'IccManager.h', ] +EXPORTS.mozilla.dom.icc += [ + 'ipc/IccChild.h', + 'ipc/IccParent.h', +] + UNIFIED_SOURCES += [ 'Assertions.cpp', 'Icc.cpp', @@ -20,6 +25,9 @@ UNIFIED_SOURCES += [ "IccInfo.cpp", 'IccListener.cpp', 'IccManager.cpp', + 'ipc/IccChild.cpp', + 'ipc/IccIPCService.cpp', + 'ipc/IccParent.cpp', ] IPDL_SOURCES += [ diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index 0fbd709416cf..fa2dc2125bbd 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -150,6 +150,7 @@ #include "mozilla/dom/File.h" #include "mozilla/dom/cellbroadcast/CellBroadcastIPCService.h" +#include "mozilla/dom/icc/IccChild.h" #include "mozilla/dom/mobileconnection/MobileConnectionChild.h" #include "mozilla/dom/mobilemessage/SmsChild.h" #include "mozilla/dom/devicestorage/DeviceStorageRequestChild.h" @@ -183,6 +184,7 @@ using namespace mozilla::docshell; using namespace mozilla::dom::bluetooth; using namespace mozilla::dom::cellbroadcast; using namespace mozilla::dom::devicestorage; +using namespace mozilla::dom::icc; using namespace mozilla::dom::ipc; using namespace mozilla::dom::mobileconnection; using namespace mozilla::dom::mobilemessage; @@ -1467,6 +1469,31 @@ ContentChild::DeallocPHalChild(PHalChild* aHal) return true; } +PIccChild* +ContentChild::SendPIccConstructor(PIccChild* aActor, + const uint32_t& aServiceId) +{ + // Add an extra ref for IPDL. Will be released in + // ContentChild::DeallocPIccChild(). + static_cast(aActor)->AddRef(); + return PContentChild::SendPIccConstructor(aActor, aServiceId); +} + +PIccChild* +ContentChild::AllocPIccChild(const uint32_t& aServiceId) +{ + NS_NOTREACHED("No one should be allocating PIccChild actors"); + return nullptr; +} + +bool +ContentChild::DeallocPIccChild(PIccChild* aActor) +{ + // IccChild is refcounted, must not be freed manually. + static_cast(aActor)->Release(); + return true; +} + asmjscache::PAsmJSCacheEntryChild* ContentChild::AllocPAsmJSCacheEntryChild( const asmjscache::OpenMode& aOpenMode, diff --git a/dom/ipc/ContentChild.h b/dom/ipc/ContentChild.h index c65fbd23a378..df1daa8c2a1c 100644 --- a/dom/ipc/ContentChild.h +++ b/dom/ipc/ContentChild.h @@ -173,6 +173,13 @@ public: virtual PHalChild* AllocPHalChild() override; virtual bool DeallocPHalChild(PHalChild*) override; + PIccChild* + SendPIccConstructor(PIccChild* aActor, const uint32_t& aServiceId); + virtual PIccChild* + AllocPIccChild(const uint32_t& aClientId) override; + virtual bool + DeallocPIccChild(PIccChild* aActor) override; + virtual PMemoryReportRequestChild* AllocPMemoryReportRequestChild(const uint32_t& aGeneration, const bool& aAnonymize, diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index a71cbd581174..1ab7538507c9 100755 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -51,6 +51,7 @@ #include "mozilla/dom/bluetooth/PBluetoothParent.h" #include "mozilla/dom/cellbroadcast/CellBroadcastParent.h" #include "mozilla/dom/devicestorage/DeviceStorageRequestParent.h" +#include "mozilla/dom/icc/IccParent.h" #include "mozilla/dom/mobileconnection/MobileConnectionParent.h" #include "mozilla/dom/mobilemessage/SmsParent.h" #include "mozilla/dom/power/PowerManagerService.h" @@ -224,6 +225,7 @@ using namespace CrashReporter; using namespace mozilla::dom::bluetooth; using namespace mozilla::dom::cellbroadcast; using namespace mozilla::dom::devicestorage; +using namespace mozilla::dom::icc; using namespace mozilla::dom::indexedDB; using namespace mozilla::dom::power; using namespace mozilla::dom::mobileconnection; @@ -3387,6 +3389,27 @@ ContentParent::DeallocPHalParent(hal_sandbox::PHalParent* aHal) return true; } +PIccParent* +ContentParent::AllocPIccParent(const uint32_t& aServiceId) +{ + if (!AssertAppProcessPermission(this, "mobileconnection")) { + return nullptr; + } + IccParent* parent = new IccParent(aServiceId); + // We release this ref in DeallocPIccParent(). + parent->AddRef(); + + return parent; +} + +bool +ContentParent::DeallocPIccParent(PIccParent* aActor) +{ + // IccParent is refcounted, must not be freed manually. + static_cast(aActor)->Release(); + return true; +} + PMemoryReportRequestParent* ContentParent::AllocPMemoryReportRequestParent(const uint32_t& aGeneration, const bool &aAnonymize, diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index 95756dfb9174..24272705974d 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -550,6 +550,9 @@ private: virtual bool DeallocPHalParent(PHalParent*) override; + virtual PIccParent* AllocPIccParent(const uint32_t& aServiceId) override; + virtual bool DeallocPIccParent(PIccParent* aActor) override; + virtual PMemoryReportRequestParent* AllocPMemoryReportRequestParent(const uint32_t& aGeneration, const bool &aAnonymize, @@ -743,7 +746,7 @@ private: OptionalURIParams* aURI) override; virtual bool RecvNotifyKeywordSearchLoading(const nsString &aProvider, - const nsString &aKeyword) override; + const nsString &aKeyword) override; virtual void ProcessingError(Result aCode, const char* aMsgName) override; From e511c8773171ffd7f982d1fe63a5ff9746f0d027 Mon Sep 17 00:00:00 2001 From: Bevis Tseng Date: Tue, 13 Jan 2015 18:03:44 +0800 Subject: [PATCH 10/43] Bug 1114935 - Part 5.1: Bind new nsIccService into MozIcc. r=echen, r=hsinyi --HG-- extra : histedit_source : c4f30cabe18e4a2ef4f6a34745e95d46c5baaff7 --- dom/icc/Icc.cpp | 124 +++++++++++++-------- dom/icc/Icc.h | 12 +- dom/icc/IccCallback.cpp | 135 +++++++++++++++++++++++ dom/icc/IccCallback.h | 64 +++++++++++ dom/icc/IccListener.cpp | 40 ++++++- dom/icc/IccListener.h | 6 +- dom/icc/IccManager.cpp | 22 ++++ dom/icc/IccManager.h | 3 +- dom/icc/interfaces/nsIGonkIccService.idl | 5 + dom/icc/interfaces/nsIIccService.idl | 14 +++ dom/icc/moz.build | 1 + dom/webidl/MozIcc.webidl | 15 ++- layout/build/nsLayoutModule.cpp | 5 + 13 files changed, 385 insertions(+), 61 deletions(-) create mode 100644 dom/icc/IccCallback.cpp create mode 100644 dom/icc/IccCallback.h diff --git a/dom/icc/Icc.cpp b/dom/icc/Icc.cpp index 956afcac94e9..5f026b1cbcd2 100644 --- a/dom/icc/Icc.cpp +++ b/dom/icc/Icc.cpp @@ -4,6 +4,7 @@ #include "mozilla/dom/Icc.h" +#include "IccCallback.h" #include "mozilla/dom/DOMRequest.h" #include "mozilla/dom/IccInfo.h" #include "mozilla/dom/MozStkCommandEvent.h" @@ -11,10 +12,13 @@ #include "mozilla/dom/ScriptSettings.h" #include "nsIIccInfo.h" #include "nsIIccProvider.h" +#include "nsIIccService.h" #include "nsJSON.h" #include "nsRadioInterfaceLayer.h" #include "nsServiceManagerUtils.h" +using mozilla::dom::icc::IccCallback; + namespace mozilla { namespace dom { @@ -50,9 +54,10 @@ NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper) NS_IMPL_ADDREF_INHERITED(Icc, DOMEventTargetHelper) NS_IMPL_RELEASE_INHERITED(Icc, DOMEventTargetHelper) -Icc::Icc(nsPIDOMWindow* aWindow, long aClientId, nsIIccInfo* aIccInfo) +Icc::Icc(nsPIDOMWindow* aWindow, long aClientId, nsIIcc* aHandler, nsIIccInfo* aIccInfo) : mLive(true) , mClientId(aClientId) + , mHandler(aHandler) { BindToOwner(aWindow); @@ -79,6 +84,7 @@ Icc::Shutdown() { mIccInfo.SetNull(); mProvider = nullptr; + mHandler = nullptr; mLive = false; } @@ -170,10 +176,10 @@ Icc::GetCardState() const { Nullable result; - uint32_t cardState = nsIIccProvider::CARD_STATE_UNDETECTED; - if (mProvider && - NS_SUCCEEDED(mProvider->GetCardState(mClientId, &cardState)) && - cardState != nsIIccProvider::CARD_STATE_UNDETECTED) { + uint32_t cardState = nsIIcc::CARD_STATE_UNDETECTED; + if (mHandler && + NS_SUCCEEDED(mHandler->GetCardState(&cardState)) && + cardState != nsIIcc::CARD_STATE_UNDETECTED) { MOZ_ASSERT(cardState < static_cast(IccCardState::EndGuard_)); result.SetValue(static_cast(cardState)); } @@ -249,72 +255,78 @@ Icc::SendStkEventDownload(const JSContext* aCx, JS::Handle aEvent, already_AddRefed Icc::GetCardLock(IccLockType aLockType, ErrorResult& aRv) { - if (!mProvider) { + if (!mHandler) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } - nsRefPtr request; - nsresult rv = mProvider->GetCardLockEnabled(mClientId, GetOwner(), - static_cast(aLockType), - getter_AddRefs(request)); + nsRefPtr request = new DOMRequest(GetOwner()); + // TODO: Bug 1125018 - Simplify The Result of GetCardLock and + // getCardLockRetryCount in MozIcc.webidl without a wrapper object. + nsRefPtr requestCallback = + new IccCallback(GetOwner(), request, true); + nsresult rv = mHandler->GetCardLockEnabled(static_cast(aLockType), + requestCallback); if (NS_FAILED(rv)) { aRv.Throw(rv); return nullptr; } - return request.forget().downcast(); + return request.forget(); } already_AddRefed Icc::UnlockCardLock(const IccUnlockCardLockOptions& aOptions, ErrorResult& aRv) { - if (!mProvider) { + if (!mHandler) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } - nsRefPtr request; + nsRefPtr request = new DOMRequest(GetOwner()); + nsRefPtr requestCallback = + new IccCallback(GetOwner(), request); const nsString& password = IsPukCardLockType(aOptions.mLockType) ? aOptions.mPuk : aOptions.mPin; - nsresult rv = mProvider->UnlockCardLock(mClientId, GetOwner(), - static_cast(aOptions.mLockType), - password, aOptions.mNewPin, - getter_AddRefs(request)); + nsresult rv = + mHandler->UnlockCardLock(static_cast(aOptions.mLockType), + password, aOptions.mNewPin, requestCallback); if (NS_FAILED(rv)) { aRv.Throw(rv); return nullptr; } - return request.forget().downcast(); + return request.forget(); } already_AddRefed Icc::SetCardLock(const IccSetCardLockOptions& aOptions, ErrorResult& aRv) { - if (!mProvider) { + if (!mHandler) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } nsresult rv; - nsRefPtr request; + nsRefPtr request = new DOMRequest(GetOwner()); + nsRefPtr requestCallback = + new IccCallback(GetOwner(), request); if (aOptions.mEnabled.WasPassed()) { // Enable card lock. const nsString& password = (aOptions.mLockType == IccLockType::Fdn) ? aOptions.mPin2 : aOptions.mPin; - rv = mProvider->SetCardLockEnabled(mClientId, GetOwner(), - static_cast(aOptions.mLockType), - password, aOptions.mEnabled.Value(), - getter_AddRefs(request)); + rv = + mHandler->SetCardLockEnabled(static_cast(aOptions.mLockType), + password, aOptions.mEnabled.Value(), + requestCallback); } else { // Change card lock password. - rv = mProvider->ChangeCardLockPassword(mClientId, GetOwner(), - static_cast(aOptions.mLockType), - aOptions.mPin, aOptions.mNewPin, - getter_AddRefs(request)); + rv = + mHandler->ChangeCardLockPassword(static_cast(aOptions.mLockType), + aOptions.mPin, aOptions.mNewPin, + requestCallback); } if (NS_FAILED(rv)) { @@ -322,27 +334,28 @@ Icc::SetCardLock(const IccSetCardLockOptions& aOptions, ErrorResult& aRv) return nullptr; } - return request.forget().downcast(); + return request.forget(); } already_AddRefed Icc::GetCardLockRetryCount(IccLockType aLockType, ErrorResult& aRv) { - if (!mProvider) { + if (!mHandler) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } - nsRefPtr request; - nsresult rv = mProvider->GetCardLockRetryCount(mClientId, GetOwner(), - static_cast(aLockType), - getter_AddRefs(request)); + nsRefPtr request = new DOMRequest(GetOwner()); + nsRefPtr requestCallback = + new IccCallback(GetOwner(), request); + nsresult rv = mHandler->GetCardLockRetryCount(static_cast(aLockType), + requestCallback); if (NS_FAILED(rv)) { aRv.Throw(rv); return nullptr; } - return request.forget().downcast(); + return request.forget(); } already_AddRefed @@ -392,41 +405,54 @@ already_AddRefed Icc::MatchMvno(IccMvnoType aMvnoType, const nsAString& aMvnoData, ErrorResult& aRv) { - if (!mProvider) { + if (!mHandler) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } - nsRefPtr request; - nsresult rv = mProvider->MatchMvno(mClientId, GetOwner(), - static_cast(aMvnoType), - aMvnoData, getter_AddRefs(request)); + nsRefPtr request = new DOMRequest(GetOwner()); + nsRefPtr requestCallback = + new IccCallback(GetOwner(), request); + nsresult rv = mHandler->MatchMvno(static_cast(aMvnoType), + aMvnoData, requestCallback); if (NS_FAILED(rv)) { aRv.Throw(rv); return nullptr; } - return request.forget().downcast(); + return request.forget(); } already_AddRefed Icc::GetServiceState(IccService aService, ErrorResult& aRv) { - if (!mProvider) { + if (!mHandler) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } - nsCOMPtr supports; - nsresult rv = mProvider->GetServiceState(mClientId, GetOwner(), - static_cast(aService), - getter_AddRefs(supports)); - if (NS_FAILED(rv)) { - aRv.Throw(rv); + nsCOMPtr global = do_QueryInterface(GetOwner()); + if (!global) { return nullptr; } - nsCOMPtr promise = do_QueryInterface(supports); + nsRefPtr promise = Promise::Create(global, aRv); + if (aRv.Failed()) { + return nullptr; + } + + nsRefPtr requestCallback = + new IccCallback(GetOwner(), promise); + + nsresult rv = + mHandler->GetServiceStateEnabled(static_cast(aService), + requestCallback); + + if (NS_FAILED(rv)) { + promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR); + // fall-through to return promise. + } + return promise.forget(); } diff --git a/dom/icc/Icc.h b/dom/icc/Icc.h index afc7bb6f61b1..fa43b571870f 100644 --- a/dom/icc/Icc.h +++ b/dom/icc/Icc.h @@ -8,6 +8,7 @@ #include "mozilla/dom/MozIccBinding.h" #include "mozilla/DOMEventTargetHelper.h" +class nsIIcc; class nsIIccInfo; class nsIIccProvider; @@ -25,7 +26,8 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Icc, DOMEventTargetHelper) NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper) - Icc(nsPIDOMWindow* aWindow, long aClientId, nsIIccInfo* aIccInfo); + Icc(nsPIDOMWindow* aWindow, long aClientId, + nsIIcc* aHandler, nsIIccInfo* aIccInfo); void Shutdown(); @@ -111,14 +113,20 @@ public: IMPL_EVENT_HANDLER(stksessionend) private: + // Put definition of the destructor in Icc.cpp to ensure forward declaration + // of nsIIccProvider, nsIIcc for the auto-generated .cpp file (i.e., + // MozIccManagerBinding.cpp) that includes this header. ~Icc(); bool mLive; uint32_t mClientId; nsString mIccId; - // mProvider is a xpcom service and will be released at shutdown, so it + // mProvider is a xpcom service and will be released at Shutdown(), so it // doesn't need to be cycle collected. nsCOMPtr mProvider; + // mHandler will be released at Shutdown(), so there is no need to join cycle + // collection. + nsCOMPtr mHandler; Nullable mIccInfo; }; diff --git a/dom/icc/IccCallback.cpp b/dom/icc/IccCallback.cpp new file mode 100644 index 000000000000..ab71f39e223c --- /dev/null +++ b/dom/icc/IccCallback.cpp @@ -0,0 +1,135 @@ +/* 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 "IccCallback.h" + +#include "mozilla/dom/IccCardLockError.h" +#include "mozilla/dom/MozIccBinding.h" +#include "mozilla/dom/Promise.h" +#include "mozilla/dom/ToJSValue.h" +#include "nsJSUtils.h" +#include "nsServiceManagerUtils.h" + +namespace mozilla { +namespace dom { +namespace icc { + +NS_IMPL_ISUPPORTS(IccCallback, nsIIccCallback) + +IccCallback::IccCallback(nsPIDOMWindow* aWindow, DOMRequest* aRequest, + bool aIsCardLockEnabled) + : mWindow(aWindow) + , mRequest(aRequest) + , mIsCardLockEnabled(aIsCardLockEnabled) +{ +} + +IccCallback::IccCallback(nsPIDOMWindow* aWindow, Promise* aPromise) + : mWindow(aWindow) + , mPromise(aPromise) +{ +} + +nsresult +IccCallback::NotifySuccess(JS::Handle aResult) +{ + nsCOMPtr rs = + do_GetService(DOMREQUEST_SERVICE_CONTRACTID); + NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE); + + return rs->FireSuccessAsync(mRequest, aResult); +} + +nsresult +IccCallback::NotifyGetCardLockEnabled(bool aResult) +{ + IccCardLockStatus result; + result.mEnabled.Construct(aResult); + + AutoJSAPI jsapi; + if (NS_WARN_IF(!jsapi.Init(mWindow))) { + return NS_ERROR_FAILURE; + } + + JSContext* cx = jsapi.cx(); + JS::Rooted jsResult(cx); + if (!ToJSValue(cx, result, &jsResult)) { + JS_ClearPendingException(cx); + return NS_ERROR_TYPE_ERR; + } + + return NotifySuccess(jsResult); +} + +NS_IMETHODIMP +IccCallback::NotifySuccess() +{ + return NotifySuccess(JS::UndefinedHandleValue); +} + +NS_IMETHODIMP +IccCallback::NotifySuccessWithBoolean(bool aResult) +{ + if (mPromise) { + mPromise->MaybeResolve(aResult ? JS::TrueHandleValue : JS::FalseHandleValue); + return NS_OK; + } + + return mIsCardLockEnabled + ? NotifyGetCardLockEnabled(aResult) + : NotifySuccess(aResult ? JS::TrueHandleValue : JS::FalseHandleValue); +} + +NS_IMETHODIMP +IccCallback::NotifyGetCardLockRetryCount(int32_t aCount) +{ + // TODO: Bug 1125018 - Simplify The Result of GetCardLock and + // getCardLockRetryCount in MozIcc.webidl without a wrapper object. + IccCardLockRetryCount result; + result.mRetryCount.Construct(aCount); + + AutoJSAPI jsapi; + if (NS_WARN_IF(!jsapi.Init(mWindow))) { + return NS_ERROR_FAILURE; + } + + JSContext* cx = jsapi.cx(); + JS::Rooted jsResult(cx); + if (!ToJSValue(cx, result, &jsResult)) { + JS_ClearPendingException(cx); + return NS_ERROR_TYPE_ERR; + } + + return NotifySuccess(jsResult); +} + +NS_IMETHODIMP +IccCallback::NotifyError(const nsAString & aErrorMsg) +{ + if (mPromise) { + mPromise->MaybeRejectBrokenly(aErrorMsg); + return NS_OK; + } + + nsCOMPtr rs = + do_GetService(DOMREQUEST_SERVICE_CONTRACTID); + NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE); + + return rs->FireErrorAsync(mRequest, aErrorMsg); +} + +NS_IMETHODIMP +IccCallback::NotifyCardLockError(const nsAString & aErrorMsg, + int32_t aRetryCount) +{ + nsRefPtr error = + new IccCardLockError(mWindow, aErrorMsg, aRetryCount); + mRequest->FireDetailedError(error); + + return NS_OK; +} + +} // namespace icc +} // namespace dom +} // namespace mozilla \ No newline at end of file diff --git a/dom/icc/IccCallback.h b/dom/icc/IccCallback.h new file mode 100644 index 000000000000..f0ad0578d0ab --- /dev/null +++ b/dom/icc/IccCallback.h @@ -0,0 +1,64 @@ +/* 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_icc_IccCallback_h +#define mozilla_dom_icc_IccCallback_h + +#include "nsCOMPtr.h" +#include "nsIIccService.h" + +namespace mozilla { +namespace dom { + +class DOMRequest; +class Promise; + +namespace icc { + +/** + * A callback object for handling asynchronous request/response. This object is + * created when an asynchronous request is made and should be destroyed after + * Notify*Success/Error is called. + * The modules hold the reference of IccCallback in OOP mode and non-OOP mode + * are different. + * - OOP mode: IccRequestChild + * - non-OOP mode: IccService + * The reference should be released after Notify*Success/Error is called. + */ +class IccCallback final : public nsIIccCallback +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIICCCALLBACK + + // TODO: Bug 1125018 - Simplify The Result of GetCardLock and + // getCardLockRetryCount in MozIcc.webidl without a wrapper object. + IccCallback(nsPIDOMWindow* aWindow, DOMRequest* aRequest, + bool aIsCardLockEnabled = false); + IccCallback(nsPIDOMWindow* aWindow, Promise* aPromise); + +private: + ~IccCallback() {} + + nsresult + NotifySuccess(JS::Handle aResult); + + // TODO: Bug 1125018 - Simplify The Result of GetCardLock and + // getCardLockRetryCount in MozIcc.webidl without a wrapper object. + nsresult + NotifyGetCardLockEnabled(bool aResult); + + nsCOMPtr mWindow; + nsRefPtr mRequest; + nsRefPtr mPromise; + // TODO: Bug 1125018 - Simplify The Result of GetCardLock and + // getCardLockRetryCount in MozIcc.webidl without a wrapper object. + bool mIsCardLockEnabled; +}; + +} // namespace icc +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_icc_IccCallback_h diff --git a/dom/icc/IccListener.cpp b/dom/icc/IccListener.cpp index 911974c9bcce..7474a321738d 100644 --- a/dom/icc/IccListener.cpp +++ b/dom/icc/IccListener.cpp @@ -20,6 +20,8 @@ IccListener::IccListener(IccManager* aIccManager, uint32_t aClientId) { MOZ_ASSERT(mIccManager); + // TODO: Bug 1114938, Refactor STK in MozIcc.webidl with IPDL. + // Remove the registration to IccProvider. mProvider = do_GetService(NS_RILCONTENTHELPER_CONTRACTID); if (!mProvider) { @@ -27,17 +29,34 @@ IccListener::IccListener(IccManager* aIccManager, uint32_t aClientId) return; } + nsCOMPtr iccService = do_GetService(ICC_SERVICE_CONTRACTID); + + if (!iccService) { + NS_WARNING("Could not acquire nsIIccService!"); + return; + } + + iccService->GetIccByServiceId(mClientId, getter_AddRefs(mHandler)); + if (!mHandler) { + NS_WARNING("Could not acquire nsIIcc!"); + return; + } + nsCOMPtr iccInfo; - mProvider->GetIccInfo(mClientId, getter_AddRefs(iccInfo)); + mHandler->GetIccInfo(getter_AddRefs(iccInfo)); if (iccInfo) { nsString iccId; iccInfo->GetIccid(iccId); if (!iccId.IsEmpty()) { - mIcc = new Icc(mIccManager->GetOwner(), mClientId, iccInfo); + mIcc = new Icc(mIccManager->GetOwner(), mClientId, mHandler, iccInfo); } } - DebugOnly rv = mProvider->RegisterIccMsg(mClientId, this); + DebugOnly rv = mHandler->RegisterListener(this); + NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), + "Failed registering icc listener with Icc Handler"); + + rv = mProvider->RegisterIccMsg(mClientId, this); NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed registering icc messages with provider"); } @@ -50,11 +69,18 @@ IccListener::~IccListener() void IccListener::Shutdown() { + // TODO: Bug 1114938, Refactor STK in MozIcc.webidl with IPDL. + // Remove the unregistration to IccProvider. if (mProvider) { mProvider->UnregisterIccMsg(mClientId, this); mProvider = nullptr; } + if (mHandler) { + mHandler->UnregisterListener(this); + mHandler = nullptr; + } + if (mIcc) { mIcc->Shutdown(); mIcc = nullptr; @@ -98,8 +124,12 @@ IccListener::NotifyCardStateChanged() NS_IMETHODIMP IccListener::NotifyIccInfoChanged() { + if (!mHandler) { + return NS_OK; + } + nsCOMPtr iccInfo; - mProvider->GetIccInfo(mClientId, getter_AddRefs(iccInfo)); + mHandler->GetIccInfo(getter_AddRefs(iccInfo)); // Create/delete icc object based on current iccInfo. // 1. If the mIcc is nullptr and iccInfo has valid data, create icc object and @@ -111,7 +141,7 @@ IccListener::NotifyIccInfoChanged() nsString iccId; iccInfo->GetIccid(iccId); if (!iccId.IsEmpty()) { - mIcc = new Icc(mIccManager->GetOwner(), mClientId, iccInfo); + mIcc = new Icc(mIccManager->GetOwner(), mClientId, mHandler, iccInfo); mIccManager->NotifyIccAdd(iccId); mIcc->NotifyEvent(NS_LITERAL_STRING("iccinfochange")); } diff --git a/dom/icc/IccListener.h b/dom/icc/IccListener.h index c55c27ae2dd7..c0531cde2a39 100644 --- a/dom/icc/IccListener.h +++ b/dom/icc/IccListener.h @@ -7,6 +7,7 @@ #include "nsAutoPtr.h" #include "nsIIccProvider.h" +#include "nsIIccService.h" namespace mozilla { namespace dom { @@ -42,9 +43,12 @@ private: // IccListener, this will release the reference and break the cycle. nsRefPtr mIcc; nsRefPtr mIccManager; - // mProvider is a xpcom service and will be released at shutdown, so it + // mProvider is a xpcom service and will be released at Shutdown(), so it // doesn't need to be cycle collected. nsCOMPtr mProvider; + // mHandler will be released at Shutdown(), there is no need to join cycle + // collection. + nsCOMPtr mHandler; }; } // namespace dom diff --git a/dom/icc/IccManager.cpp b/dom/icc/IccManager.cpp index 40845b3e97ce..b914c1b3fb08 100644 --- a/dom/icc/IccManager.cpp +++ b/dom/icc/IccManager.cpp @@ -10,6 +10,12 @@ #include "mozilla/dom/IccChangeEvent.h" #include "mozilla/Preferences.h" #include "nsIIccInfo.h" +// Service instantiation +#include "ipc/IccIPCService.h" +#if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL) +#include "nsIGonkIccService.h" +#endif +#include "nsXULAppAPI.h" // For XRE_GetProcessType() using namespace mozilla::dom; @@ -129,3 +135,19 @@ IccManager::GetIccById(const nsAString& aIccId) const } return nullptr; } + +already_AddRefed +NS_CreateIccService() +{ + nsCOMPtr service; + + if (XRE_GetProcessType() == GeckoProcessType_Content) { + service = new mozilla::dom::icc::IccIPCService(); +#if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL) + } else { + service = do_GetService(GONK_ICC_SERVICE_CONTRACTID); +#endif + } + + return service.forget(); +} diff --git a/dom/icc/IccManager.h b/dom/icc/IccManager.h index 7d753d117f20..91850685d1b1 100644 --- a/dom/icc/IccManager.h +++ b/dom/icc/IccManager.h @@ -7,7 +7,6 @@ #include "mozilla/DOMEventTargetHelper.h" #include "nsCycleCollectionParticipant.h" -#include "nsIIccProvider.h" #include "nsTArrayHelpers.h" namespace mozilla { @@ -25,7 +24,7 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IccManager, DOMEventTargetHelper) - IccManager(nsPIDOMWindow* aWindow); + explicit IccManager(nsPIDOMWindow* aWindow); void Shutdown(); diff --git a/dom/icc/interfaces/nsIGonkIccService.idl b/dom/icc/interfaces/nsIGonkIccService.idl index 3a15bf541616..890b1c98551b 100644 --- a/dom/icc/interfaces/nsIGonkIccService.idl +++ b/dom/icc/interfaces/nsIGonkIccService.idl @@ -4,6 +4,11 @@ #include "nsIIccService.idl" +%{C++ +#define GONK_ICC_SERVICE_CONTRACTID \ + "@mozilla.org/icc/gonkiccservice;1" +%} + [scriptable, uuid(a037b8a2-b027-11e4-9496-c3b7af59a512)] interface nsIGonkIccService : nsIIccService { diff --git a/dom/icc/interfaces/nsIIccService.idl b/dom/icc/interfaces/nsIIccService.idl index a59362388fb9..b40b3ddb8b8f 100644 --- a/dom/icc/interfaces/nsIIccService.idl +++ b/dom/icc/interfaces/nsIIccService.idl @@ -63,6 +63,15 @@ interface nsIIccCallback : nsISupports void notifyCardLockError(in DOMString aErrorMsg, in long aRetryCount); }; +%{C++ +#define ICC_SERVICE_CID \ + { 0xbab0277a, 0x900e, 0x11e4, { 0x80, 0xc7, 0xdb, 0xd7, 0xad, 0x05, 0x24, 0x01 } } +#define ICC_SERVICE_CONTRACTID \ + "@mozilla.org/icc/iccservice;1" + +template struct already_AddRefed; +%} + /** * XPCOM Service for the selection of the ICC to be accessed. */ @@ -80,6 +89,11 @@ interface nsIIccService : nsISupports nsIIcc getIccByServiceId(in unsigned long aServiceId); }; +%{C++ +already_AddRefed +NS_CreateIccService(); +%} + /** * XPCOM component that provides the access to the selected ICC. */ diff --git a/dom/icc/moz.build b/dom/icc/moz.build index 6184ac370958..257dc9a75267 100644 --- a/dom/icc/moz.build +++ b/dom/icc/moz.build @@ -21,6 +21,7 @@ EXPORTS.mozilla.dom.icc += [ UNIFIED_SOURCES += [ 'Assertions.cpp', 'Icc.cpp', + 'IccCallback.cpp', 'IccCardLockError.cpp', "IccInfo.cpp", 'IccListener.cpp', diff --git a/dom/webidl/MozIcc.webidl b/dom/webidl/MozIcc.webidl index afe1f4c8c239..d2cab4f47dd1 100644 --- a/dom/webidl/MozIcc.webidl +++ b/dom/webidl/MozIcc.webidl @@ -129,6 +129,16 @@ dictionary IccSetCardLockOptions // Necessary for lock types: "pin", "fdn" }; +dictionary IccCardLockStatus +{ + boolean enabled; // True when CardLock is enabled. +}; + +dictionary IccCardLockRetryCount +{ + long retryCount; // The number of remaining retries. -1 if unkown. +}; + [Pref="dom.icc.enabled", CheckPermissions="mobileconnection", AvailableIn="CertifiedApps"] @@ -247,6 +257,7 @@ interface MozIcc : EventTarget * The request's result will be an object containing * information about the specified lock's status. * e.g. {enabled: true}. + * @see IccCardLockStatus. */ [Throws] DOMRequest getCardLock(IccLockType lockType); @@ -289,8 +300,8 @@ interface MozIcc : EventTarget * * @return a DOMRequest. * The request's result will be an object containing the number of - * remaining retries. - * e.g. {retryCount: 3}. + * remaining retries. e.g. {retryCount: 3}. + * @see IccCardLockRetryCount. */ [Throws] DOMRequest getCardLockRetryCount(IccLockType lockType); diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index eb8f8d6be63a..c801285e39fb 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -213,6 +213,7 @@ static void Shutdown(); #include "mozilla/dom/nsCSPService.h" #include "mozilla/dom/nsCSPContext.h" #include "nsICellBroadcastService.h" +#include "nsIIccService.h" #include "nsISmsService.h" #include "nsIMmsService.h" #include "nsIMobileConnectionService.h" @@ -338,6 +339,7 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsICellBroadcastService, NS_CreateCellBroadcastService) NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsISmsService, NS_CreateSmsService) #endif +NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIIccService, NS_CreateIccService) NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIMmsService, NS_CreateMmsService) NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIMobileMessageService, NS_CreateMobileMessageService) @@ -798,6 +800,7 @@ NS_DEFINE_NAMED_CID(NS_VOICEMAIL_SERVICE_CID); NS_DEFINE_NAMED_CID(NS_MOBILE_CONNECTION_SERVICE_CID); NS_DEFINE_NAMED_CID(SMS_SERVICE_CID); #endif +NS_DEFINE_NAMED_CID(ICC_SERVICE_CID); NS_DEFINE_NAMED_CID(MMS_SERVICE_CID); NS_DEFINE_NAMED_CID(MOBILE_MESSAGE_SERVICE_CID); NS_DEFINE_NAMED_CID(MOBILE_MESSAGE_DATABASE_SERVICE_CID); @@ -1092,6 +1095,7 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = { { &kCELLBROADCAST_SERVICE_CID, false, nullptr, nsICellBroadcastServiceConstructor }, { &kSMS_SERVICE_CID, false, nullptr, nsISmsServiceConstructor }, #endif + { &kICC_SERVICE_CID, false, nullptr, nsIIccServiceConstructor }, { &kMMS_SERVICE_CID, false, nullptr, nsIMmsServiceConstructor }, { &kMOBILE_MESSAGE_SERVICE_CID, false, nullptr, nsIMobileMessageServiceConstructor }, { &kMOBILE_MESSAGE_DATABASE_SERVICE_CID, false, nullptr, nsIMobileMessageDatabaseServiceConstructor }, @@ -1255,6 +1259,7 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = { { CELLBROADCAST_SERVICE_CONTRACTID, &kCELLBROADCAST_SERVICE_CID }, { SMS_SERVICE_CONTRACTID, &kSMS_SERVICE_CID }, #endif + { ICC_SERVICE_CONTRACTID, &kICC_SERVICE_CID }, { MMS_SERVICE_CONTRACTID, &kMMS_SERVICE_CID }, { MOBILE_MESSAGE_SERVICE_CONTRACTID, &kMOBILE_MESSAGE_SERVICE_CID }, { MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID, &kMOBILE_MESSAGE_DATABASE_SERVICE_CID }, From 48e31d5050603c4d730e39a90b026c7e49b57d59 Mon Sep 17 00:00:00 2001 From: Bevis Tseng Date: Wed, 14 Jan 2015 14:43:32 +0800 Subject: [PATCH 11/43] Bug 1114935 - Part 5.2: Build MozIccManager by default. r=echen, r=htsai, r=glandium --HG-- extra : histedit_source : fb9d199f31d4d57d30d670d49044d54f71eba95a --- b2g/installer/package-manifest.in | 2 +- browser/installer/package-manifest.in | 1 + dom/base/Navigator.cpp | 17 +++++++---------- dom/base/Navigator.h | 10 +++------- dom/moz.build | 2 +- dom/webidl/moz.build | 12 ++++-------- 6 files changed, 17 insertions(+), 27 deletions(-) diff --git a/b2g/installer/package-manifest.in b/b2g/installer/package-manifest.in index f83ef86a1722..98a2d63abbcc 100644 --- a/b2g/installer/package-manifest.in +++ b/b2g/installer/package-manifest.in @@ -178,7 +178,6 @@ @RESPATH@/components/dom_system_gonk.xpt #endif #ifdef MOZ_B2G_RIL -@RESPATH@/components/dom_icc.xpt @RESPATH@/components/dom_wappush.xpt @RESPATH@/components/dom_mobileconnection.xpt #endif @@ -218,6 +217,7 @@ @RESPATH@/components/dom_permissionsettings.xpt @RESPATH@/components/dom_sidebar.xpt @RESPATH@/components/dom_cellbroadcast.xpt +@RESPATH@/components/dom_icc.xpt @RESPATH@/components/dom_mobilemessage.xpt @RESPATH@/components/dom_storage.xpt @RESPATH@/components/dom_stylesheets.xpt diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in index ed37c49ac74f..2228be6f2801 100644 --- a/browser/installer/package-manifest.in +++ b/browser/installer/package-manifest.in @@ -215,6 +215,7 @@ @RESPATH@/components/dom_network.xpt @RESPATH@/components/dom_notification.xpt @RESPATH@/components/dom_html.xpt +@RESPATH@/components/dom_icc.xpt @RESPATH@/components/dom_offline.xpt @RESPATH@/components/dom_json.xpt @RESPATH@/components/dom_power.xpt diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index 30fce35e7118..3e8bfe083aa7 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -36,6 +36,7 @@ #include "mozilla/dom/WakeLock.h" #include "mozilla/dom/power/PowerManagerService.h" #include "mozilla/dom/CellBroadcast.h" +#include "mozilla/dom/IccManager.h" #include "mozilla/dom/MobileMessageManager.h" #include "mozilla/dom/ServiceWorkerContainer.h" #include "mozilla/dom/Telephony.h" @@ -53,7 +54,6 @@ #include "nsIMobileIdentityService.h" #endif #ifdef MOZ_B2G_RIL -#include "mozilla/dom/IccManager.h" #include "mozilla/dom/MobileConnectionArray.h" #endif #include "nsIIdleObserver.h" @@ -177,6 +177,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBatteryManager) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPowerManager) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCellBroadcast) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIccManager) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMobileMessageManager) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTelephony) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVoicemail) @@ -184,7 +185,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConnection) #ifdef MOZ_B2G_RIL NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMobileConnections) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIccManager) #endif #ifdef MOZ_B2G_BT NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBluetooth) @@ -250,6 +250,11 @@ Navigator::Invalidate() mCellBroadcast = nullptr; } + if (mIccManager) { + mIccManager->Shutdown(); + mIccManager = nullptr; + } + if (mMobileMessageManager) { mMobileMessageManager->Shutdown(); mMobileMessageManager = nullptr; @@ -277,11 +282,6 @@ Navigator::Invalidate() if (mMobileConnections) { mMobileConnections = nullptr; } - - if (mIccManager) { - mIccManager->Shutdown(); - mIccManager = nullptr; - } #endif #ifdef MOZ_B2G_BT @@ -1707,8 +1707,6 @@ Navigator::GetMozVoicemail(ErrorResult& aRv) return mVoicemail; } -#ifdef MOZ_B2G_RIL - IccManager* Navigator::GetMozIccManager(ErrorResult& aRv) { @@ -1724,7 +1722,6 @@ Navigator::GetMozIccManager(ErrorResult& aRv) return mIccManager; } -#endif // MOZ_B2G_RIL #ifdef MOZ_GAMEPAD void diff --git a/dom/base/Navigator.h b/dom/base/Navigator.h index fe99c242b58d..ca1498159f32 100644 --- a/dom/base/Navigator.h +++ b/dom/base/Navigator.h @@ -44,10 +44,6 @@ class ServiceWorkerContainer; } } -#ifdef MOZ_B2G_RIL -class nsIDOMMozIccManager; -#endif // MOZ_B2G_RIL - //***************************************************************************** // Navigator: Script "navigator" object //***************************************************************************** @@ -88,12 +84,12 @@ class BluetoothManager; #endif // MOZ_B2G_BT #ifdef MOZ_B2G_RIL -class IccManager; class MobileConnectionArray; #endif class PowerManager; class CellBroadcast; +class IccManager; class Telephony; class Voicemail; class TVManager; @@ -224,6 +220,7 @@ public: ErrorResult& aRv); DesktopNotificationCenter* GetMozNotification(ErrorResult& aRv); CellBroadcast* GetMozCellBroadcast(ErrorResult& aRv); + IccManager* GetMozIccManager(ErrorResult& aRv); MobileMessageManager* GetMozMobileMessage(); Telephony* GetMozTelephony(ErrorResult& aRv); Voicemail* GetMozVoicemail(ErrorResult& aRv); @@ -243,7 +240,6 @@ public: #endif #ifdef MOZ_B2G_RIL MobileConnectionArray* GetMozMobileConnections(ErrorResult& aRv); - IccManager* GetMozIccManager(ErrorResult& aRv); #endif // MOZ_B2G_RIL #ifdef MOZ_GAMEPAD void GetGamepads(nsTArray >& aGamepads, ErrorResult& aRv); @@ -353,6 +349,7 @@ private: #endif nsRefPtr mPowerManager; nsRefPtr mCellBroadcast; + nsRefPtr mIccManager; nsRefPtr mMobileMessageManager; nsRefPtr mTelephony; nsRefPtr mVoicemail; @@ -360,7 +357,6 @@ private: nsRefPtr mConnection; #ifdef MOZ_B2G_RIL nsRefPtr mMobileConnections; - nsRefPtr mIccManager; #endif #ifdef MOZ_B2G_BT nsRefPtr mBluetooth; diff --git a/dom/moz.build b/dom/moz.build index 9ef5a69d8318..a4a1092b3d53 100644 --- a/dom/moz.build +++ b/dom/moz.build @@ -64,6 +64,7 @@ DIRS += [ 'fmradio', 'geolocation', 'html', + 'icc', 'json', 'jsurl', 'asmjscache', @@ -122,7 +123,6 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk': if CONFIG['MOZ_B2G_RIL']: DIRS += [ - 'icc', 'wappush', ] diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index e4d3f5dbc45d..d476d12fa95e 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -229,6 +229,7 @@ WEBIDL_FILES = [ 'HTMLTrackElement.webidl', 'HTMLUListElement.webidl', 'HTMLVideoElement.webidl', + 'IccCardLockError.webidl', 'IDBCursor.webidl', 'IDBDatabase.webidl', 'IDBEnvironment.webidl', @@ -287,6 +288,9 @@ WEBIDL_FILES = [ 'MozActivity.webidl', 'MozCellBroadcast.webidl', 'MozCellBroadcastMessage.webidl', + 'MozIcc.webidl', + 'MozIccInfo.webidl', + 'MozIccManager.webidl', 'MozMmsMessage.webidl', 'MozMobileCellInfo.webidl', 'MozMobileConnection.webidl', @@ -651,14 +655,6 @@ if CONFIG['MOZ_B2G_BT']: 'BluetoothManager.webidl', ] -if CONFIG['MOZ_B2G_RIL']: - WEBIDL_FILES += [ - 'IccCardLockError.webidl', - 'MozIcc.webidl', - 'MozIccInfo.webidl', - 'MozIccManager.webidl', - ] - if CONFIG['MOZ_NFC']: WEBIDL_FILES += [ 'MozIsoDepTech.webidl', From 0ff5646c33dbe030ca227e2278d2ce9c47c5ebe6 Mon Sep 17 00:00:00 2001 From: Bevis Tseng Date: Thu, 15 Jan 2015 18:12:23 +0800 Subject: [PATCH 12/43] Bug 1114935 - Part 6.1: Migration in RIL-internal Modules. r=echen --HG-- extra : histedit_source : 2c578ec4de601576072908153f9453fb0acd9971 --- dom/mobilemessage/gonk/MmsService.js | 2 +- dom/mobilemessage/gonk/SmsService.js | 2 +- dom/system/gonk/RILContentHelper.js | 2 +- dom/system/gonk/RadioInterfaceLayer.js | 6 +- dom/system/gonk/nsIRadioInterfaceLayer.idl | 2 +- dom/system/gonk/ril_consts.js | 10 +-- .../tests/test_ril_worker_icc_CardState.js | 70 +++++++++---------- 7 files changed, 47 insertions(+), 47 deletions(-) diff --git a/dom/mobilemessage/gonk/MmsService.js b/dom/mobilemessage/gonk/MmsService.js index 3fa167b76bbc..405e9818d5eb 100644 --- a/dom/mobilemessage/gonk/MmsService.js +++ b/dom/mobilemessage/gonk/MmsService.js @@ -406,7 +406,7 @@ MmsConnection.prototype = { if (DEBUG) debug("Error! Radio is disabled when sending MMS."); errorStatus = _HTTP_STATUS_RADIO_DISABLED; } else if (this.radioInterface.rilContext.cardState != - Ci.nsIIccProvider.CARD_STATE_READY) { + Ci.nsIIcc.CARD_STATE_READY) { if (DEBUG) debug("Error! SIM card is not ready when sending MMS."); errorStatus = _HTTP_STATUS_NO_SIM_CARD; } diff --git a/dom/mobilemessage/gonk/SmsService.js b/dom/mobilemessage/gonk/SmsService.js index f38933a9120e..359855232c5d 100644 --- a/dom/mobilemessage/gonk/SmsService.js +++ b/dom/mobilemessage/gonk/SmsService.js @@ -886,7 +886,7 @@ SmsService.prototype = { if (DEBUG) debug("Error! Radio is disabled when sending SMS."); errorCode = Ci.nsIMobileMessageCallback.RADIO_DISABLED_ERROR; } else if (gRadioInterfaces[aServiceId].rilContext.cardState != - Ci.nsIIccProvider.CARD_STATE_READY) { + Ci.nsIIcc.CARD_STATE_READY) { if (DEBUG) debug("Error! SIM card is not ready when sending SMS."); errorCode = Ci.nsIMobileMessageCallback.NO_SIM_CARD_ERROR; } diff --git a/dom/system/gonk/RILContentHelper.js b/dom/system/gonk/RILContentHelper.js index 655d4c115c19..fd8c1169b8a1 100644 --- a/dom/system/gonk/RILContentHelper.js +++ b/dom/system/gonk/RILContentHelper.js @@ -134,7 +134,7 @@ function RILContentHelper() { this.rilContexts = []; for (let clientId = 0; clientId < this.numClients; clientId++) { this.rilContexts[clientId] = { - cardState: Ci.nsIIccProvider.CARD_STATE_UNKNOWN, + cardState: Ci.nsIIcc.CARD_STATE_UNKNOWN, iccInfo: null }; } diff --git a/dom/system/gonk/RadioInterfaceLayer.js b/dom/system/gonk/RadioInterfaceLayer.js index e1a88e9362b5..8f918bc3f941 100644 --- a/dom/system/gonk/RadioInterfaceLayer.js +++ b/dom/system/gonk/RadioInterfaceLayer.js @@ -1686,7 +1686,7 @@ function RadioInterface(aClientId, aWorkerMessenger) { aWorkerMessenger.registerClient(aClientId, this); this.rilContext = { - cardState: Ci.nsIIccProvider.CARD_STATE_UNKNOWN, + cardState: Ci.nsIIcc.CARD_STATE_UNKNOWN, iccInfo: null, imsi: null }; @@ -1784,8 +1784,8 @@ RadioInterface.prototype = { isCardPresent: function() { let cardState = this.rilContext.cardState; - return cardState !== Ci.nsIIccProvider.CARD_STATE_UNDETECTED && - cardState !== Ci.nsIIccProvider.CARD_STATE_UNKNOWN; + return cardState !== Ci.nsIIcc.CARD_STATE_UNDETECTED && + cardState !== Ci.nsIIcc.CARD_STATE_UNKNOWN; }, /** diff --git a/dom/system/gonk/nsIRadioInterfaceLayer.idl b/dom/system/gonk/nsIRadioInterfaceLayer.idl index f20564c7aac9..c36d2bdc5047 100644 --- a/dom/system/gonk/nsIRadioInterfaceLayer.idl +++ b/dom/system/gonk/nsIRadioInterfaceLayer.idl @@ -25,7 +25,7 @@ interface nsIRilNetworkInterface : nsINetworkInterface interface nsIRilContext : nsISupports { /** - * One of the nsIIccProvider.CARD_STATE_* values. + * One of the nsIIcc.CARD_STATE_* values. */ readonly attribute unsigned long cardState; diff --git a/dom/system/gonk/ril_consts.js b/dom/system/gonk/ril_consts.js index 7f706f4b420d..a34e077e4100 100644 --- a/dom/system/gonk/ril_consts.js +++ b/dom/system/gonk/ril_consts.js @@ -2577,7 +2577,7 @@ this.GECKO_RADIOSTATE_DISABLED = 1; // Only used in ril_worker.js this.GECKO_CARDSTATE_UNINITIALIZED = 4294967294; // UINT32_MAX - 1 -// See nsIIccProvider::CARD_STATE_* +// See nsIIcc::CARD_STATE_* this.GECKO_CARDSTATE_UNDETECTED = 4294967295; // UINT32_MAX this.GECKO_CARDSTATE_UNKNOWN = 0; this.GECKO_CARDSTATE_READY = 1; @@ -2610,7 +2610,7 @@ this.GECKO_CARDSTATE_RUIM_SERVICE_PROVIDER_PUK_REQUIRED = 27; this.GECKO_CARDSTATE_RUIM_PUK_REQUIRED = 28; this.GECKO_CARDSTATE_ILLEGAL = 29; -// See nsIIccProvider::CARD_LOCK_TYPE_* +// See nsIIcc::CARD_LOCK_TYPE_* this.GECKO_CARDLOCK_PIN = 0; this.GECKO_CARDLOCK_PIN2 = 1; this.GECKO_CARDLOCK_PUK = 2; @@ -2653,17 +2653,17 @@ GECKO_CARDLOCK_TO_SEL_CODE[GECKO_CARDLOCK_SPCK] = ICC_SEL_CODE_PH_SP_PIN; // TODO: Bug 1116072: identify the mapping between RIL_PERSOSUBSTATE_SIM_SIM @ // ril.h and TS 27.007, clause 8.65 for GECKO_CARDLOCK_PCK. -// See nsIIccProvider::CARD_CONTACT_TYPE_* +// See nsIIcc::CARD_CONTACT_TYPE_* this.GECKO_CARDCONTACT_TYPE_ADN = 0; this.GECKO_CARDCONTACT_TYPE_FDN = 1; this.GECKO_CARDCONTACT_TYPE_SDN = 2; -// See nsIIccProvider::CARD_MVNO_TYPE_* +// See nsIIcc::CARD_MVNO_TYPE_* this.GECKO_CARDMVNO_TYPE_IMSI = 0; this.GECKO_CARDMVNO_TYPE_SPN = 1; this.GECKO_CARDMVNO_TYPE_GID = 2; -// See nsIIccProvider::CARD_MVNO_TYPE_* +// See nsIIcc::CARD_SERVICE_* this.GECKO_CARDSERVICE_FDN = 0; // See ril.h RIL_PersoSubstate diff --git a/dom/system/gonk/tests/test_ril_worker_icc_CardState.js b/dom/system/gonk/tests/test_ril_worker_icc_CardState.js index 75ebc30a9a83..788df5073f7e 100644 --- a/dom/system/gonk/tests/test_ril_worker_icc_CardState.js +++ b/dom/system/gonk/tests/test_ril_worker_icc_CardState.js @@ -33,65 +33,65 @@ add_test(function test_personalization_state() { // Test GSM personalization state. testPersonalization(false, CARD_PERSOSUBSTATE_SIM_NETWORK, - Ci.nsIIccProvider.CARD_STATE_NETWORK_LOCKED); + Ci.nsIIcc.CARD_STATE_NETWORK_LOCKED); testPersonalization(false, CARD_PERSOSUBSTATE_SIM_NETWORK_SUBSET, - Ci.nsIIccProvider.CARD_STATE_NETWORK_SUBSET_LOCKED); + Ci.nsIIcc.CARD_STATE_NETWORK_SUBSET_LOCKED); testPersonalization(false, CARD_PERSOSUBSTATE_SIM_CORPORATE, - Ci.nsIIccProvider.CARD_STATE_CORPORATE_LOCKED); + Ci.nsIIcc.CARD_STATE_CORPORATE_LOCKED); testPersonalization(false, CARD_PERSOSUBSTATE_SIM_SERVICE_PROVIDER, - Ci.nsIIccProvider.CARD_STATE_SERVICE_PROVIDER_LOCKED); + Ci.nsIIcc.CARD_STATE_SERVICE_PROVIDER_LOCKED); testPersonalization(false, CARD_PERSOSUBSTATE_SIM_SIM, - Ci.nsIIccProvider.CARD_STATE_SIM_LOCKED); + Ci.nsIIcc.CARD_STATE_SIM_LOCKED); testPersonalization(false, CARD_PERSOSUBSTATE_SIM_NETWORK_PUK, - Ci.nsIIccProvider.CARD_STATE_NETWORK_PUK_REQUIRED); + Ci.nsIIcc.CARD_STATE_NETWORK_PUK_REQUIRED); testPersonalization(false, CARD_PERSOSUBSTATE_SIM_NETWORK_SUBSET_PUK, - Ci.nsIIccProvider.CARD_STATE_NETWORK_SUBSET_PUK_REQUIRED); + Ci.nsIIcc.CARD_STATE_NETWORK_SUBSET_PUK_REQUIRED); testPersonalization(false, CARD_PERSOSUBSTATE_SIM_CORPORATE_PUK, - Ci.nsIIccProvider.CARD_STATE_CORPORATE_PUK_REQUIRED); + Ci.nsIIcc.CARD_STATE_CORPORATE_PUK_REQUIRED); testPersonalization(false, CARD_PERSOSUBSTATE_SIM_SERVICE_PROVIDER_PUK, - Ci.nsIIccProvider.CARD_STATE_SERVICE_PROVIDER_PUK_REQUIRED); + Ci.nsIIcc.CARD_STATE_SERVICE_PROVIDER_PUK_REQUIRED); testPersonalization(false, CARD_PERSOSUBSTATE_SIM_SIM_PUK, - Ci.nsIIccProvider.CARD_STATE_SIM_PUK_REQUIRED); + Ci.nsIIcc.CARD_STATE_SIM_PUK_REQUIRED); testPersonalization(false, CARD_PERSOSUBSTATE_UNKNOWN, - Ci.nsIIccProvider.CARD_STATE_UNKNOWN); + Ci.nsIIcc.CARD_STATE_UNKNOWN); testPersonalization(false, CARD_PERSOSUBSTATE_IN_PROGRESS, - Ci.nsIIccProvider.CARD_STATE_PERSONALIZATION_IN_PROGRESS); + Ci.nsIIcc.CARD_STATE_PERSONALIZATION_IN_PROGRESS); testPersonalization(false, CARD_PERSOSUBSTATE_READY, - Ci.nsIIccProvider.CARD_STATE_PERSONALIZATION_READY); + Ci.nsIIcc.CARD_STATE_PERSONALIZATION_READY); // Test CDMA personalization state. testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_NETWORK1, - Ci.nsIIccProvider.CARD_STATE_NETWORK1_LOCKED); + Ci.nsIIcc.CARD_STATE_NETWORK1_LOCKED); testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_NETWORK2, - Ci.nsIIccProvider.CARD_STATE_NETWORK2_LOCKED); + Ci.nsIIcc.CARD_STATE_NETWORK2_LOCKED); testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_HRPD, - Ci.nsIIccProvider.CARD_STATE_HRPD_NETWORK_LOCKED); + Ci.nsIIcc.CARD_STATE_HRPD_NETWORK_LOCKED); testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_CORPORATE, - Ci.nsIIccProvider.CARD_STATE_RUIM_CORPORATE_LOCKED); + Ci.nsIIcc.CARD_STATE_RUIM_CORPORATE_LOCKED); testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_SERVICE_PROVIDER, - Ci.nsIIccProvider.CARD_STATE_RUIM_SERVICE_PROVIDER_LOCKED); + Ci.nsIIcc.CARD_STATE_RUIM_SERVICE_PROVIDER_LOCKED); testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_RUIM, - Ci.nsIIccProvider.CARD_STATE_RUIM_LOCKED); + Ci.nsIIcc.CARD_STATE_RUIM_LOCKED); testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_NETWORK1_PUK, - Ci.nsIIccProvider.CARD_STATE_NETWORK1_PUK_REQUIRED); + Ci.nsIIcc.CARD_STATE_NETWORK1_PUK_REQUIRED); testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_NETWORK2_PUK, - Ci.nsIIccProvider.CARD_STATE_NETWORK2_PUK_REQUIRED); + Ci.nsIIcc.CARD_STATE_NETWORK2_PUK_REQUIRED); testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_HRPD_PUK, - Ci.nsIIccProvider.CARD_STATE_HRPD_NETWORK_PUK_REQUIRED); + Ci.nsIIcc.CARD_STATE_HRPD_NETWORK_PUK_REQUIRED); testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_CORPORATE_PUK, - Ci.nsIIccProvider.CARD_STATE_RUIM_CORPORATE_PUK_REQUIRED); + Ci.nsIIcc.CARD_STATE_RUIM_CORPORATE_PUK_REQUIRED); testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_SERVICE_PROVIDER_PUK, - Ci.nsIIccProvider.CARD_STATE_RUIM_SERVICE_PROVIDER_PUK_REQUIRED); + Ci.nsIIcc.CARD_STATE_RUIM_SERVICE_PROVIDER_PUK_REQUIRED); testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_RUIM_PUK, - Ci.nsIIccProvider.CARD_STATE_RUIM_PUK_REQUIRED); + Ci.nsIIcc.CARD_STATE_RUIM_PUK_REQUIRED); testPersonalization(true, CARD_PERSOSUBSTATE_UNKNOWN, - Ci.nsIIccProvider.CARD_STATE_UNKNOWN); + Ci.nsIIcc.CARD_STATE_UNKNOWN); testPersonalization(true, CARD_PERSOSUBSTATE_IN_PROGRESS, - Ci.nsIIccProvider.CARD_STATE_PERSONALIZATION_IN_PROGRESS); + Ci.nsIIcc.CARD_STATE_PERSONALIZATION_IN_PROGRESS); testPersonalization(true, CARD_PERSOSUBSTATE_READY, - Ci.nsIIccProvider.CARD_STATE_PERSONALIZATION_READY); + Ci.nsIIcc.CARD_STATE_PERSONALIZATION_READY); run_next_test(); }); @@ -121,17 +121,17 @@ add_test(function test_card_app_state() { } testCardAppState(CARD_APPSTATE_ILLEGAL, - Ci.nsIIccProvider.CARD_STATE_ILLEGAL); + Ci.nsIIcc.CARD_STATE_ILLEGAL); testCardAppState(CARD_APPSTATE_PIN, - Ci.nsIIccProvider.CARD_STATE_PIN_REQUIRED); + Ci.nsIIcc.CARD_STATE_PIN_REQUIRED); testCardAppState(CARD_APPSTATE_PUK, - Ci.nsIIccProvider.CARD_STATE_PUK_REQUIRED); + Ci.nsIIcc.CARD_STATE_PUK_REQUIRED); testCardAppState(CARD_APPSTATE_READY, - Ci.nsIIccProvider.CARD_STATE_READY); + Ci.nsIIcc.CARD_STATE_READY); testCardAppState(CARD_APPSTATE_UNKNOWN, - Ci.nsIIccProvider.CARD_STATE_UNKNOWN); + Ci.nsIIcc.CARD_STATE_UNKNOWN); testCardAppState(CARD_APPSTATE_DETECTED, - Ci.nsIIccProvider.CARD_STATE_UNKNOWN); + Ci.nsIIcc.CARD_STATE_UNKNOWN); run_next_test(); }); @@ -159,7 +159,7 @@ add_test(function test_icc_permanent_blocked() { }; ril._processICCStatus(iccStatus); - equal(ril.cardState, Ci.nsIIccProvider.CARD_STATE_PERMANENT_BLOCKED); + equal(ril.cardState, Ci.nsIIcc.CARD_STATE_PERMANENT_BLOCKED); } testPermanentBlocked(1, From 7e83037bdab589a38165d4c48353d4061a6b17e6 Mon Sep 17 00:00:00 2001 From: Bevis Tseng Date: Thu, 15 Jan 2015 18:19:01 +0800 Subject: [PATCH 13/43] Bug 1114935 - Part 6.2: Migration in MobileConnection. r=echen --HG-- extra : histedit_source : c1c51efa5413f09418e2f88edca054fcd9917229 --- dom/mobileconnection/MobileConnection.cpp | 52 +++++++++-------------- dom/mobileconnection/MobileConnection.h | 17 ++------ 2 files changed, 24 insertions(+), 45 deletions(-) diff --git a/dom/mobileconnection/MobileConnection.cpp b/dom/mobileconnection/MobileConnection.cpp index e639cffbf8d3..5ec69798df83 100644 --- a/dom/mobileconnection/MobileConnection.cpp +++ b/dom/mobileconnection/MobileConnection.cpp @@ -15,6 +15,7 @@ #include "mozilla/Preferences.h" #include "mozilla/Services.h" #include "nsIDOMDOMRequest.h" +#include "nsIIccInfo.h" #include "nsIPermissionManager.h" #include "nsIVariant.h" #include "nsJSON.h" @@ -22,10 +23,6 @@ #include "nsRadioInterfaceLayer.h" #include "nsServiceManagerUtils.h" -#ifdef MOZ_B2G_RIL -#include "nsIIccInfo.h" -#endif // MOZ_B2G_RIL - #define MOBILECONN_ERROR_INVALID_PARAMETER NS_LITERAL_STRING("InvalidParameter") #define MOBILECONN_ERROR_INVALID_PASSWORD NS_LITERAL_STRING("InvalidPassword") @@ -49,18 +46,14 @@ using namespace mozilla::dom; using namespace mozilla::dom::mobileconnection; class MobileConnection::Listener final : public nsIMobileConnectionListener -#ifdef MOZ_B2G_RIL - , public nsIIccListener -#endif // MOZ_B2G_RIL + , public nsIIccListener { MobileConnection* mMobileConnection; public: NS_DECL_ISUPPORTS NS_FORWARD_SAFE_NSIMOBILECONNECTIONLISTENER(mMobileConnection) -#ifdef MOZ_B2G_RIL NS_FORWARD_SAFE_NSIICCLISTENER(mMobileConnection) -#endif // MOZ_B2G_RIL explicit Listener(MobileConnection* aMobileConnection) : mMobileConnection(aMobileConnection) @@ -81,12 +74,8 @@ private: } }; -#ifdef MOZ_B2G_RIL NS_IMPL_ISUPPORTS(MobileConnection::Listener, nsIMobileConnectionListener, nsIIccListener) -#else -NS_IMPL_ISUPPORTS(MobileConnection::Listener, nsIMobileConnectionListener) -#endif // MOZ_B2G_RIL NS_IMPL_CYCLE_COLLECTION_CLASS(MobileConnection) @@ -98,6 +87,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MobileConnection, // down. NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVoice) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mData) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIccHandler) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(MobileConnection, @@ -105,6 +95,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(MobileConnection, tmp->Shutdown(); NS_IMPL_CYCLE_COLLECTION_UNLINK(mVoice) NS_IMPL_CYCLE_COLLECTION_UNLINK(mData) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mIccHandler) NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(MobileConnection) @@ -136,15 +127,9 @@ MobileConnection::MobileConnection(nsPIDOMWindow* aWindow, uint32_t aClientId) nsresult rv = service->GetItemByServiceId(mClientId, getter_AddRefs(mMobileConnection)); -#ifdef MOZ_B2G_RIL - mIcc = do_GetService(NS_RILCONTENTHELPER_CONTRACTID); - if (NS_FAILED(rv) || !mMobileConnection || !mIcc) { - NS_WARNING("Could not acquire nsIMobileConnection or nsIIccProvider!"); -#else if (NS_FAILED(rv) || !mMobileConnection) { NS_WARNING("Could not acquire nsIMobileConnection!"); -#endif // MOZ_B2G_RIL return; } @@ -159,12 +144,21 @@ MobileConnection::MobileConnection(nsPIDOMWindow* aWindow, uint32_t aClientId) UpdateVoice(); UpdateData(); -#ifdef MOZ_B2G_RIL - rv = mIcc->RegisterIccMsg(mClientId, mListener); + nsCOMPtr iccService = do_GetService(ICC_SERVICE_CONTRACTID); + + if (iccService) { + iccService->GetIccByServiceId(mClientId, getter_AddRefs(mIccHandler)); + } + + if (!mIccHandler) { + NS_WARNING("Could not acquire nsIMobileConnection or nsIIcc!"); + return; + } + + rv = mIccHandler->RegisterListener(mListener); NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed registering icc messages with service"); UpdateIccId(); -#endif // MOZ_B2G_RIL } } @@ -176,11 +170,9 @@ MobileConnection::Shutdown() mMobileConnection->UnregisterListener(mListener); } -#ifdef MOZ_B2G_RIL - if (mIcc) { - mIcc->UnregisterIccMsg(mClientId, mListener); + if (mIccHandler) { + mIccHandler->UnregisterListener(mListener); } -#endif // MOZ_B2G_RIL mListener->Disconnect(); mListener = nullptr; @@ -246,11 +238,10 @@ MobileConnection::UpdateData() bool MobileConnection::UpdateIccId() { -#ifdef MOZ_B2G_RIL nsAutoString iccId; nsCOMPtr iccInfo; - if (mIcc && - NS_SUCCEEDED(mIcc->GetIccInfo(mClientId, getter_AddRefs(iccInfo))) && + if (mIccHandler && + NS_SUCCEEDED(mIccHandler->GetIccInfo(getter_AddRefs(iccInfo))) && iccInfo) { iccInfo->GetIccid(iccId); } else { @@ -261,7 +252,6 @@ MobileConnection::UpdateIccId() mIccId = iccId; return true; } -#endif // MOZ_B2G_RIL return false; } @@ -1134,7 +1124,6 @@ MobileConnection::NotifyNetworkSelectionModeChanged() return NS_OK; } -#ifdef MOZ_B2G_RIL // nsIIccListener NS_IMETHODIMP @@ -1171,4 +1160,3 @@ MobileConnection::NotifyIccInfoChanged() return asyncDispatcher->PostDOMEvent(); } -#endif // MOZ_B2G_RIL diff --git a/dom/mobileconnection/MobileConnection.h b/dom/mobileconnection/MobileConnection.h index ff12e2c7a407..837695529913 100644 --- a/dom/mobileconnection/MobileConnection.h +++ b/dom/mobileconnection/MobileConnection.h @@ -11,21 +11,16 @@ #include "mozilla/dom/MobileNetworkInfo.h" #include "mozilla/dom/MozMobileConnectionBinding.h" #include "nsCycleCollectionParticipant.h" +#include "nsIIccService.h" #include "nsIMobileConnectionService.h" #include "nsWeakPtr.h" -#ifdef MOZ_B2G_RIL -#include "nsIIccProvider.h" -#endif // MOZ_B2G_RIL - namespace mozilla { namespace dom { class MobileConnection final : public DOMEventTargetHelper - , private nsIMobileConnectionListener -#ifdef MOZ_B2G_RIL - , private nsIIccListener -#endif // MOZ_B2G_RIL + , private nsIMobileConnectionListener + , private nsIIccListener { /** * Class MobileConnection doesn't actually expose @@ -40,9 +35,7 @@ class MobileConnection final : public DOMEventTargetHelper public: NS_DECL_ISUPPORTS_INHERITED NS_DECL_NSIMOBILECONNECTIONLISTENER -#ifdef MOZ_B2G_RIL NS_DECL_NSIICCLISTENER -#endif // MOZ_B2G_RIL NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper) NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MobileConnection, DOMEventTargetHelper) @@ -169,9 +162,7 @@ private: uint32_t mClientId; nsString mIccId; nsCOMPtr mMobileConnection; -#ifdef MOZ_B2G_RIL - nsCOMPtr mIcc; -#endif // MOZ_B2G_RIL + nsCOMPtr mIccHandler; nsRefPtr mListener; nsRefPtr mVoice; nsRefPtr mData; From b36101cd618cc963de07bc00c0b7068efebce5e5 Mon Sep 17 00:00:00 2001 From: Bevis Tseng Date: Thu, 15 Jan 2015 18:22:08 +0800 Subject: [PATCH 14/43] Bug 1114935 - Part 6.3: Migration in Bluetooth. r=btian --HG-- extra : histedit_source : b7f3f1d46e62b84ccae5d080193e549af6373b0c --- dom/bluetooth/BluetoothRilListener.cpp | 17 ++++++++++------- dom/bluetooth/BluetoothRilListener.h | 2 +- .../bluedroid/hfp/BluetoothHfpManager.cpp | 13 ++++++++----- dom/bluetooth/bluez/BluetoothHfpManager.cpp | 13 ++++++++----- dom/bluetooth2/BluetoothRilListener.cpp | 17 ++++++++++------- dom/bluetooth2/BluetoothRilListener.h | 2 +- .../bluedroid/hfp/BluetoothHfpManager.cpp | 13 ++++++++----- dom/bluetooth2/bluez/BluetoothHfpManager.cpp | 13 ++++++++----- 8 files changed, 54 insertions(+), 36 deletions(-) diff --git a/dom/bluetooth/BluetoothRilListener.cpp b/dom/bluetooth/BluetoothRilListener.cpp index cfade813bfb3..716c6b4f6340 100644 --- a/dom/bluetooth/BluetoothRilListener.cpp +++ b/dom/bluetooth/BluetoothRilListener.cpp @@ -7,12 +7,11 @@ #include "BluetoothRilListener.h" #include "BluetoothHfpManager.h" -#include "nsIIccProvider.h" +#include "nsIIccService.h" #include "nsIMobileConnectionInfo.h" #include "nsIMobileConnectionService.h" #include "nsITelephonyCallInfo.h" #include "nsITelephonyService.h" -#include "nsRadioInterfaceLayer.h" // For NS_RILCONTENTHELPER_CONTRACTID. #include "nsServiceManagerUtils.h" #include "nsString.h" @@ -60,15 +59,19 @@ IccListener::Listen(bool aStart) { NS_ENSURE_TRUE(mOwner, false); - nsCOMPtr provider = - do_GetService(NS_RILCONTENTHELPER_CONTRACTID); - NS_ENSURE_TRUE(provider, false); + nsCOMPtr service = + do_GetService(ICC_SERVICE_CONTRACTID); + NS_ENSURE_TRUE(service, false); + + nsCOMPtr icc; + service->GetIccByServiceId(mOwner->mClientId, getter_AddRefs(icc)); + NS_ENSURE_TRUE(icc, false); nsresult rv; if (aStart) { - rv = provider->RegisterIccMsg(mOwner->mClientId, this); + rv = icc->RegisterListener(this); } else { - rv = provider->UnregisterIccMsg(mOwner->mClientId, this); + rv = icc->UnregisterListener(this); } return NS_SUCCEEDED(rv); diff --git a/dom/bluetooth/BluetoothRilListener.h b/dom/bluetooth/BluetoothRilListener.h index 76d6cb838958..3fae176bfb17 100644 --- a/dom/bluetooth/BluetoothRilListener.h +++ b/dom/bluetooth/BluetoothRilListener.h @@ -11,7 +11,7 @@ #include "nsAutoPtr.h" -#include "nsIIccProvider.h" +#include "nsIIccService.h" #include "nsIMobileConnectionService.h" #include "nsITelephonyCallInfo.h" #include "nsITelephonyService.h" diff --git a/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp b/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp index 311da74db409..db7f99569c2a 100644 --- a/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp +++ b/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp @@ -17,14 +17,13 @@ #include "nsContentUtils.h" #include "nsIAudioManager.h" #include "nsIIccInfo.h" -#include "nsIIccProvider.h" +#include "nsIIccService.h" #include "nsIMobileConnectionInfo.h" #include "nsIMobileConnectionService.h" #include "nsIMobileNetworkInfo.h" #include "nsIObserverService.h" #include "nsISettingsService.h" #include "nsITelephonyService.h" -#include "nsRadioInterfaceLayer.h" #include "nsServiceManagerUtils.h" #include "nsThreadUtils.h" #include "mozilla/dom/BindingUtils.h" @@ -726,12 +725,16 @@ BluetoothHfpManager::HandleVoiceConnectionChanged(uint32_t aClientId) void BluetoothHfpManager::HandleIccInfoChanged(uint32_t aClientId) { - nsCOMPtr icc = - do_GetService(NS_RILCONTENTHELPER_CONTRACTID); + nsCOMPtr service = + do_GetService(ICC_SERVICE_CONTRACTID); + NS_ENSURE_TRUE_VOID(service); + + nsCOMPtr icc; + service->GetIccByServiceId(aClientId, getter_AddRefs(icc)); NS_ENSURE_TRUE_VOID(icc); nsCOMPtr iccInfo; - icc->GetIccInfo(aClientId, getter_AddRefs(iccInfo)); + icc->GetIccInfo(getter_AddRefs(iccInfo)); NS_ENSURE_TRUE_VOID(iccInfo); nsCOMPtr gsmIccInfo = do_QueryInterface(iccInfo); diff --git a/dom/bluetooth/bluez/BluetoothHfpManager.cpp b/dom/bluetooth/bluez/BluetoothHfpManager.cpp index 7ec2ef6b45af..44902714f531 100644 --- a/dom/bluetooth/bluez/BluetoothHfpManager.cpp +++ b/dom/bluetooth/bluez/BluetoothHfpManager.cpp @@ -28,12 +28,11 @@ #ifdef MOZ_B2G_RIL #include "nsIIccInfo.h" -#include "nsIIccProvider.h" +#include "nsIIccService.h" #include "nsIMobileConnectionInfo.h" #include "nsIMobileConnectionService.h" #include "nsIMobileNetworkInfo.h" #include "nsITelephonyService.h" -#include "nsRadioInterfaceLayer.h" #endif /** @@ -664,12 +663,16 @@ BluetoothHfpManager::HandleVoiceConnectionChanged(uint32_t aClientId) void BluetoothHfpManager::HandleIccInfoChanged(uint32_t aClientId) { - nsCOMPtr icc = - do_GetService(NS_RILCONTENTHELPER_CONTRACTID); + nsCOMPtr service = + do_GetService(ICC_SERVICE_CONTRACTID); + NS_ENSURE_TRUE_VOID(service); + + nsCOMPtr icc; + service->GetIccByServiceId(aClientId, getter_AddRefs(icc)); NS_ENSURE_TRUE_VOID(icc); nsCOMPtr iccInfo; - icc->GetIccInfo(aClientId, getter_AddRefs(iccInfo)); + icc->GetIccInfo(getter_AddRefs(iccInfo)); NS_ENSURE_TRUE_VOID(iccInfo); nsCOMPtr gsmIccInfo = do_QueryInterface(iccInfo); diff --git a/dom/bluetooth2/BluetoothRilListener.cpp b/dom/bluetooth2/BluetoothRilListener.cpp index f6237480ecfe..a13f1520c26c 100644 --- a/dom/bluetooth2/BluetoothRilListener.cpp +++ b/dom/bluetooth2/BluetoothRilListener.cpp @@ -7,11 +7,10 @@ #include "BluetoothRilListener.h" #include "BluetoothHfpManager.h" -#include "nsIIccProvider.h" +#include "nsIIccService.h" #include "nsIMobileConnectionInfo.h" #include "nsIMobileConnectionService.h" #include "nsITelephonyService.h" -#include "nsRadioInterfaceLayer.h" // For NS_RILCONTENTHELPER_CONTRACTID. #include "nsServiceManagerUtils.h" #include "nsString.h" @@ -59,15 +58,19 @@ IccListener::Listen(bool aStart) { NS_ENSURE_TRUE(mOwner, false); - nsCOMPtr provider = - do_GetService(NS_RILCONTENTHELPER_CONTRACTID); - NS_ENSURE_TRUE(provider, false); + nsCOMPtr service = + do_GetService(ICC_SERVICE_CONTRACTID); + NS_ENSURE_TRUE(service, false); + + nsCOMPtr icc; + service->GetIccByServiceId(mOwner->mClientId, getter_AddRefs(icc)); + NS_ENSURE_TRUE(icc, false); nsresult rv; if (aStart) { - rv = provider->RegisterIccMsg(mOwner->mClientId, this); + rv = icc->RegisterListener(this); } else { - rv = provider->UnregisterIccMsg(mOwner->mClientId, this); + rv = icc->UnregisterListener(this); } return NS_SUCCEEDED(rv); diff --git a/dom/bluetooth2/BluetoothRilListener.h b/dom/bluetooth2/BluetoothRilListener.h index 11ce91173c44..1768528d686a 100644 --- a/dom/bluetooth2/BluetoothRilListener.h +++ b/dom/bluetooth2/BluetoothRilListener.h @@ -11,7 +11,7 @@ #include "nsAutoPtr.h" -#include "nsIIccProvider.h" +#include "nsIIccService.h" #include "nsIMobileConnectionService.h" #include "nsITelephonyCallInfo.h" #include "nsITelephonyService.h" diff --git a/dom/bluetooth2/bluedroid/hfp/BluetoothHfpManager.cpp b/dom/bluetooth2/bluedroid/hfp/BluetoothHfpManager.cpp index 8df64b58046b..7c06c302a173 100644 --- a/dom/bluetooth2/bluedroid/hfp/BluetoothHfpManager.cpp +++ b/dom/bluetooth2/bluedroid/hfp/BluetoothHfpManager.cpp @@ -17,14 +17,13 @@ #include "nsContentUtils.h" #include "nsIAudioManager.h" #include "nsIIccInfo.h" -#include "nsIIccProvider.h" +#include "nsIIccService.h" #include "nsIMobileConnectionInfo.h" #include "nsIMobileConnectionService.h" #include "nsIMobileNetworkInfo.h" #include "nsIObserverService.h" #include "nsISettingsService.h" #include "nsITelephonyService.h" -#include "nsRadioInterfaceLayer.h" #include "nsServiceManagerUtils.h" #include "nsThreadUtils.h" #include "mozilla/dom/BindingUtils.h" @@ -710,12 +709,16 @@ BluetoothHfpManager::HandleVoiceConnectionChanged(uint32_t aClientId) void BluetoothHfpManager::HandleIccInfoChanged(uint32_t aClientId) { - nsCOMPtr icc = - do_GetService(NS_RILCONTENTHELPER_CONTRACTID); + nsCOMPtr service = + do_GetService(ICC_SERVICE_CONTRACTID); + NS_ENSURE_TRUE_VOID(service); + + nsCOMPtr icc; + service->GetIccByServiceId(aClientId, getter_AddRefs(icc)); NS_ENSURE_TRUE_VOID(icc); nsCOMPtr iccInfo; - icc->GetIccInfo(aClientId, getter_AddRefs(iccInfo)); + icc->GetIccInfo(getter_AddRefs(iccInfo)); NS_ENSURE_TRUE_VOID(iccInfo); nsCOMPtr gsmIccInfo = do_QueryInterface(iccInfo); diff --git a/dom/bluetooth2/bluez/BluetoothHfpManager.cpp b/dom/bluetooth2/bluez/BluetoothHfpManager.cpp index ccb6b573e8fb..ea6a98dbaf64 100644 --- a/dom/bluetooth2/bluez/BluetoothHfpManager.cpp +++ b/dom/bluetooth2/bluez/BluetoothHfpManager.cpp @@ -28,12 +28,11 @@ #ifdef MOZ_B2G_RIL #include "nsIIccInfo.h" -#include "nsIIccProvider.h" +#include "nsIIccService.h" #include "nsIMobileConnectionInfo.h" #include "nsIMobileConnectionService.h" #include "nsIMobileNetworkInfo.h" #include "nsITelephonyService.h" -#include "nsRadioInterfaceLayer.h" #endif /** @@ -664,12 +663,16 @@ BluetoothHfpManager::HandleVoiceConnectionChanged(uint32_t aClientId) void BluetoothHfpManager::HandleIccInfoChanged(uint32_t aClientId) { - nsCOMPtr icc = - do_GetService(NS_RILCONTENTHELPER_CONTRACTID); + nsCOMPtr service = + do_GetService(ICC_SERVICE_CONTRACTID); + NS_ENSURE_TRUE_VOID(service); + + nsCOMPtr icc; + service->GetIccByServiceId(aClientId, getter_AddRefs(icc)); NS_ENSURE_TRUE_VOID(icc); nsCOMPtr iccInfo; - icc->GetIccInfo(aClientId, getter_AddRefs(iccInfo)); + icc->GetIccInfo(getter_AddRefs(iccInfo)); NS_ENSURE_TRUE_VOID(iccInfo); nsCOMPtr gsmIccInfo = do_QueryInterface(iccInfo); From 355e7228b0408c35f3cdce9f8b81850de8d24e18 Mon Sep 17 00:00:00 2001 From: Bevis Tseng Date: Thu, 15 Jan 2015 18:34:03 +0800 Subject: [PATCH 15/43] Bug 1114935 - Part 6.4: Migration in Payment. r=ferjmoreno --HG-- extra : histedit_source : 112b550aa3259489d820a442b99157d90a18f6e0 --- b2g/components/PaymentProviderStrategy.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/b2g/components/PaymentProviderStrategy.js b/b2g/components/PaymentProviderStrategy.js index 67876f4b5a16..e51e13927b95 100644 --- a/b2g/components/PaymentProviderStrategy.js +++ b/b2g/components/PaymentProviderStrategy.js @@ -11,9 +11,9 @@ const PREF_DEBUG = "dom.payment.debug"; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Services.jsm"); -XPCOMUtils.defineLazyServiceGetter(this, "iccProvider", - "@mozilla.org/ril/content-helper;1", - "nsIIccProvider"); +XPCOMUtils.defineLazyServiceGetter(this, "gIccService", + "@mozilla.org/icc/iccservice;1", + "nsIIccService"); XPCOMUtils.defineLazyServiceGetter(this, "gRil", "@mozilla.org/ril;1", @@ -148,7 +148,8 @@ PaymentProviderStrategy.prototype = { if (!this._iccInfo) { this._iccInfo = []; for (let i = 0; i < gRil.numRadioInterfaces; i++) { - let info = iccProvider.getIccInfo(i); + let icc = gIccService.getIccByServiceId(i); + let info = icc && icc.iccInfo; if (!info) { LOGE("Tried to get the ICC info for an invalid service ID " + i); continue; From 90b1f53ab1e7a9b98387e0a8535d750f6eddab39 Mon Sep 17 00:00:00 2001 From: Bevis Tseng Date: Thu, 15 Jan 2015 18:36:29 +0800 Subject: [PATCH 16/43] Bug 1114935 - Part 6.5: Migration in OperatorApps.jsm. r=fabrice --HG-- extra : histedit_source : af9fd222ff684a06952f5f4ba896694cbb8006fe --- dom/apps/OperatorApps.jsm | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/dom/apps/OperatorApps.jsm b/dom/apps/OperatorApps.jsm index e6360cd6c2f0..ebf124ccee6f 100644 --- a/dom/apps/OperatorApps.jsm +++ b/dom/apps/OperatorApps.jsm @@ -21,9 +21,9 @@ Cu.import("resource://gre/modules/Task.jsm"); let Path = OS.Path; #ifdef MOZ_B2G_RIL -XPCOMUtils.defineLazyServiceGetter(this, "iccProvider", - "@mozilla.org/ril/content-helper;1", - "nsIIccProvider"); +XPCOMUtils.defineLazyServiceGetter(this, "gIccService", + "@mozilla.org/icc/iccservice;1", + "nsIIccService"); #endif function debug(aMsg) { @@ -69,17 +69,18 @@ let iccListener = { notifyIccInfoChanged: function() { // TODO: Bug 927709 - OperatorApps for multi-sim - // In Multi-sim, there is more than one client in iccProvider. Each - // client represents a icc service. To maintain the backward compatibility + // In Multi-sim, there is more than one client in IccService. Each + // client represents a icc handle. To maintain the backward compatibility // with single sim, we always use client 0 for now. Adding support for // multiple sim will be addressed in bug 927709, if needed. let clientId = 0; - let iccInfo = iccProvider.getIccInfo(clientId); + let icc = gIccService.getIccByServiceId(clientId); + let iccInfo = icc && icc.iccInfo; if (iccInfo && iccInfo.mcc && iccInfo.mnc) { let mcc = iccInfo.mcc; let mnc = iccInfo.mnc; debug("******* iccListener cardIccInfo MCC-MNC: " + mcc + "-" + mnc); - iccProvider.unregisterIccMsg(clientId, this); + icc.unregisterListener(this); OperatorAppsRegistry._installOperatorApps(mcc, mnc); debug("Broadcast message first-run-with-sim"); @@ -105,13 +106,14 @@ this.OperatorAppsRegistry = { try { yield this._initializeSourceDir(); // TODO: Bug 927709 - OperatorApps for multi-sim - // In Multi-sim, there is more than one client in iccProvider. Each - // client represents a icc service. To maintain the backward + // In Multi-sim, there is more than one client in IccService. Each + // client represents a icc handle. To maintain the backward // compatibility with single sim, we always use client 0 for now. // Adding support for multiple sim will be addressed in bug 927709, if // needed. let clientId = 0; - let iccInfo = iccProvider.getIccInfo(clientId); + let icc = gIccService.getIccByServiceId(clientId); + let iccInfo = icc && icc.iccInfo; let mcc = 0; let mnc = 0; if (iccInfo && iccInfo.mcc) { @@ -128,7 +130,7 @@ this.OperatorAppsRegistry = { mnc: mnc }); } else { - iccProvider.registerIccMsg(clientId, iccListener); + icc.registerListener(iccListener); } } catch (e) { debug("Error Initializing OperatorApps. " + e); From ccd20872ec7ee8505ed643e89bff22282c948a12 Mon Sep 17 00:00:00 2001 From: Bevis Tseng Date: Thu, 15 Jan 2015 18:40:01 +0800 Subject: [PATCH 17/43] Bug 1114935 - Part 6.6: Migration in PushService.jsm. r=nsm --HG-- extra : histedit_source : d738f21877abff326fffd9e2c7551c3529c49eb2 --- dom/push/PushService.jsm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dom/push/PushService.jsm b/dom/push/PushService.jsm index 1276eaac74d4..c375751e0a77 100644 --- a/dom/push/PushService.jsm +++ b/dom/push/PushService.jsm @@ -1775,14 +1775,15 @@ this.PushService = { let nm = Cc["@mozilla.org/network/manager;1"].getService(Ci.nsINetworkManager); if (nm.active && nm.active.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE) { - let icc = Cc["@mozilla.org/ril/content-helper;1"].getService(Ci.nsIIccProvider); + let iccService = Cc["@mozilla.org/icc/iccservice;1"].getService(Ci.nsIIccService); // TODO: Bug 927721 - PushService for multi-sim - // In Multi-sim, there is more than one client in iccProvider. Each - // client represents a icc service. To maintain backward compatibility + // In Multi-sim, there is more than one client in iccService. Each + // client represents a icc handle. To maintain backward compatibility // with single sim, we always use client 0 for now. Adding support // for multiple sim will be addressed in bug 927721, if needed. let clientId = 0; - let iccInfo = icc.getIccInfo(clientId); + let icc = iccService.getIccByServiceId(clientId); + let iccInfo = icc && icc.iccInfo; if (iccInfo) { debug("Running on mobile data"); From 2f0ec1d1f8a504dd703e4d4b174e6f220b3d7939 Mon Sep 17 00:00:00 2001 From: Bevis Tseng Date: Thu, 15 Jan 2015 18:42:24 +0800 Subject: [PATCH 18/43] Bug 1114935 - Part 6.7: Migration in PhoneNumberUtils.jsm. r=gwagner --HG-- extra : histedit_source : e811e200a1b736542cecb7d1bd007e3a096b0f2e --- dom/phonenumberutils/PhoneNumberUtils.jsm | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/dom/phonenumberutils/PhoneNumberUtils.jsm b/dom/phonenumberutils/PhoneNumberUtils.jsm index c5c09ecff5b7..478e6f67905a 100644 --- a/dom/phonenumberutils/PhoneNumberUtils.jsm +++ b/dom/phonenumberutils/PhoneNumberUtils.jsm @@ -23,9 +23,9 @@ XPCOMUtils.defineLazyModuleGetter(this, "MCC_ISO3166_TABLE", XPCOMUtils.defineLazyServiceGetter(this, "mobileConnection", "@mozilla.org/mobileconnection/mobileconnectionservice;1", "nsIMobileConnectionService"); -XPCOMUtils.defineLazyServiceGetter(this, "icc", - "@mozilla.org/ril/content-helper;1", - "nsIIccProvider"); +XPCOMUtils.defineLazyServiceGetter(this, "gIccService", + "@mozilla.org/icc/iccservice;1", + "nsIIccService"); #endif this.PhoneNumberUtils = { @@ -46,8 +46,8 @@ this.PhoneNumberUtils = { #ifdef MOZ_B2G_RIL // TODO: Bug 926740 - PhoneNumberUtils for multisim - // In Multi-sim, there is more than one client in - // iccProvider/mobileConnectionProvider. Each client represents a + // In Multi-sim, there is more than one client in + // iccService/mobileConnectionService. Each client represents a // icc/mobileConnection service. To maintain the backward compatibility with // single sim, we always use client 0 for now. Adding support for multiple // sim will be addressed in bug 926740, if needed. @@ -61,7 +61,8 @@ this.PhoneNumberUtils = { } // Get SIM mcc - let iccInfo = icc.getIccInfo(clientId); + let icc = gIccService.getIccByServiceId(clientId); + let iccInfo = icc && icc.iccInfo; if (!mcc && iccInfo && iccInfo.mcc) { mcc = iccInfo.mcc; } From ecded588490650776507e175de7ec6e25408eedd Mon Sep 17 00:00:00 2001 From: Bevis Tseng Date: Thu, 15 Jan 2015 18:46:08 +0800 Subject: [PATCH 19/43] Bug 1114935 - Part 6.8: Migration in MobileIdentityManager.jsm. r=ferjmoreno --HG-- extra : histedit_source : ad7bf3600fcfc62e489562a7607f4710b79c5938 --- services/mobileid/MobileIdentityManager.jsm | 25 ++++++----- .../tests/xpcshell/test_mobileid_manager.js | 44 ++++++++++++------- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/services/mobileid/MobileIdentityManager.jsm b/services/mobileid/MobileIdentityManager.jsm index cefb6a4a10a9..339341bbb5f2 100644 --- a/services/mobileid/MobileIdentityManager.jsm +++ b/services/mobileid/MobileIdentityManager.jsm @@ -56,9 +56,9 @@ XPCOMUtils.defineLazyServiceGetter(this, "Ril", "@mozilla.org/ril;1", "nsIRadioInterfaceLayer"); -XPCOMUtils.defineLazyServiceGetter(this, "IccProvider", - "@mozilla.org/ril/content-helper;1", - "nsIIccProvider"); +XPCOMUtils.defineLazyServiceGetter(this, "IccService", + "@mozilla.org/icc/iccservice;1", + "nsIIccService"); XPCOMUtils.defineLazyServiceGetter(this, "MobileConnectionService", "@mozilla.org/mobileconnection/mobileconnectionservice;1", @@ -116,11 +116,11 @@ this.MobileIdentityManager = { return Ril; }, - get iccProvider() { - if (this._iccProvider) { - return this._iccProvider; + get iccService() { + if (this._iccService) { + return this._iccService; } - return IccProvider; + return IccService; }, get mobileConnectionService() { @@ -153,8 +153,10 @@ this.MobileIdentityManager = { // We don't need to keep listening for changes until we rebuild the // cache again. for (let i = 0; i < self._iccInfo.length; i++) { - self.iccProvider.unregisterIccMsg(self._iccInfo[i].clientId, - iccListener); + let icc = self.iccService.getIccByServiceId(i); + if (icc) { + icc.unregisterListener(iccListener); + } } self._iccInfo = null; @@ -214,7 +216,10 @@ this.MobileIdentityManager = { // We need to subscribe to ICC change notifications so we can refresh // the cache if any change is observed. - this.iccProvider.registerIccMsg(i, iccListener); + let icc = this.iccService.getIccByServiceId(i); + if (icc) { + icc.registerListener(iccListener); + } } return this._iccInfo; diff --git a/services/mobileid/tests/xpcshell/test_mobileid_manager.js b/services/mobileid/tests/xpcshell/test_mobileid_manager.js index cbd8e0a9bb50..edd3e3d5fb05 100644 --- a/services/mobileid/tests/xpcshell/test_mobileid_manager.js +++ b/services/mobileid/tests/xpcshell/test_mobileid_manager.js @@ -1002,13 +1002,19 @@ add_test(function() { } }; - MobileIdentityManager._iccProvider = { + MobileIdentityManager._iccService = { + _iccs: [], _listeners: [], - registerIccMsg: function(aClientId, aIccListener) { - this._listeners.push(aIccListener); - }, - unregisterIccMsg: function() { - this._listeners.pop(); + getIccByServiceId: function(aClientId) { + let self = this; + this_iccs.push({ + registerListener: function(aIccListener) { + self._listeners.push(aIccListener); + }, + unregisterListener: function() { + self._listeners.pop(); + } + }); } }; @@ -1027,17 +1033,17 @@ add_test(function() { } // We should have listeners for each valid icc. - do_check_eq(MobileIdentityManager._iccProvider._listeners.length, 2); + do_check_eq(MobileIdentityManager._iccService._listeners.length, 2); // We can mock an ICC change event at this point. - MobileIdentityManager._iccProvider._listeners[0].notifyIccInfoChanged(); + MobileIdentityManager._iccService._listeners[0].notifyIccInfoChanged(); // After the ICC change event the caches should be null. do_check_null(MobileIdentityManager._iccInfo); do_check_null(MobileIdentityManager._iccIds); // And we should have unregistered all listeners for ICC change events. - do_check_eq(MobileIdentityManager._iccProvider._listeners.length, 0); + do_check_eq(MobileIdentityManager._iccService._listeners.length, 0); do_test_finished(); run_next_test(); @@ -1104,13 +1110,19 @@ add_test(function() { } }; - MobileIdentityManager._iccProvider = { + MobileIdentityManager._iccService = { + _iccs: [], _listeners: [], - registerIccMsg: function(aClientId, aIccListener) { - this._listeners.push(aIccListener); - }, - unregisterIccMsg: function() { - this._listeners.pop(); + getIccByServiceId: function(aClientId) { + let self = this; + this_iccs.push({ + registerListener: function(aIccListener) { + self._listeners.push(aIccListener); + }, + unregisterListener: function() { + self._listeners.pop(); + } + }); } }; @@ -1121,7 +1133,7 @@ add_test(function() { do_check_eq(MobileIdentityManager._iccIds.length, 0); // We should have listeners for each valid icc. - do_check_eq(MobileIdentityManager._iccProvider._listeners.length, 0); + do_check_eq(MobileIdentityManager._iccService._listeners.length, 0); do_test_finished(); run_next_test(); From a7cd6b1d8960a862387e9da08761a46865f0988a Mon Sep 17 00:00:00 2001 From: Bevis Tseng Date: Fri, 13 Feb 2015 14:46:49 +0800 Subject: [PATCH 20/43] Bug 1114935 - Part 7: Add Backward Compatibility for v2.2 binary implementation. r=echen --HG-- extra : histedit_source : bd9d8cc9cbaeb6c7eb3aa1add377dbb5eef50ebb --- dom/icc/IccManager.cpp | 9 +- dom/system/gonk/RILContentHelper.js | 485 ++++++++++++--------- dom/system/gonk/RadioInterfaceLayer.js | 1 + dom/system/gonk/nsIRadioInterfaceLayer.idl | 10 + 4 files changed, 300 insertions(+), 205 deletions(-) diff --git a/dom/icc/IccManager.cpp b/dom/icc/IccManager.cpp index b914c1b3fb08..e7b616b73af6 100644 --- a/dom/icc/IccManager.cpp +++ b/dom/icc/IccManager.cpp @@ -13,6 +13,8 @@ // Service instantiation #include "ipc/IccIPCService.h" #if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL) +#include "nsIRadioInterfaceLayer.h" +#include "nsRadioInterfaceLayer.h" #include "nsIGonkIccService.h" #endif #include "nsXULAppAPI.h" // For XRE_GetProcessType() @@ -145,7 +147,12 @@ NS_CreateIccService() service = new mozilla::dom::icc::IccIPCService(); #if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL) } else { - service = do_GetService(GONK_ICC_SERVICE_CONTRACTID); + nsCOMPtr ril = + do_GetService(NS_RADIOINTERFACELAYER_CONTRACTID); + nsCOMPtr ril_new(do_QueryInterface(ril)); + + service = (ril_new) ? do_GetService(GONK_ICC_SERVICE_CONTRACTID) + : do_GetService(NS_RILCONTENTHELPER_CONTRACTID); #endif } diff --git a/dom/system/gonk/RILContentHelper.js b/dom/system/gonk/RILContentHelper.js index fd8c1169b8a1..78471b273527 100644 --- a/dom/system/gonk/RILContentHelper.js +++ b/dom/system/gonk/RILContentHelper.js @@ -98,8 +98,8 @@ IccInfo.prototype = { mcc: null, mnc: null, spn: null, - isDisplayNetworkNameRequired: null, - isDisplaySpnRequired: null + isDisplayNetworkNameRequired: false, + isDisplaySpnRequired: false }; function GsmIccInfo() {} @@ -131,8 +131,10 @@ function RILContentHelper() { this.numClients = gNumRadioInterfaces; if (DEBUG) debug("Number of clients: " + this.numClients); + this._iccs = []; this.rilContexts = []; for (let clientId = 0; clientId < this.numClients; clientId++) { + this._iccs.push(new Icc(this, clientId)); this.rilContexts[clientId] = { cardState: Ci.nsIIcc.CARD_STATE_UNKNOWN, iccInfo: null @@ -141,6 +143,7 @@ function RILContentHelper() { this.initDOMRequestHelper(/* aWindow */ null, RIL_IPC_MSG_NAMES); this._windowsMap = []; + this._requestMap = []; this._iccListeners = []; this._iccChannelCallback = []; @@ -153,12 +156,14 @@ RILContentHelper.prototype = { __proto__: DOMRequestIpcHelper.prototype, QueryInterface: XPCOMUtils.generateQI([Ci.nsIIccProvider, + Ci.nsIIccService, Ci.nsIObserver, Ci.nsISupportsWeakReference]), classID: RILCONTENTHELPER_CID, classInfo: XPCOMUtils.generateCI({classID: RILCONTENTHELPER_CID, classDescription: "RILContentHelper", - interfaces: [Ci.nsIIccProvider]}), + interfaces: [Ci.nsIIccProvider, + Ci.nsIIccService]}), updateDebugFlag: function() { try { @@ -206,6 +211,8 @@ RILContentHelper.prototype = { _windowsMap: null, + _requestMap: null, + rilContexts: null, getRilContext: function(clientId) { @@ -234,142 +241,6 @@ RILContentHelper.prototype = { * nsIIccProvider */ - getIccInfo: function(clientId) { - let context = this.getRilContext(clientId); - return context && context.iccInfo; - }, - - getCardState: function(clientId) { - let context = this.getRilContext(clientId); - return context && context.cardState; - }, - - matchMvno: function(clientId, window, mvnoType, mvnoData) { - if (window == null) { - throw Components.Exception("Can't get window object", - Cr.NS_ERROR_UNEXPECTED); - } - - let request = Services.DOMRequest.createRequest(window); - let requestId = this.getRequestId(request); - - cpmm.sendAsyncMessage("RIL:MatchMvno", { - clientId: clientId, - data: { - requestId: requestId, - mvnoType: mvnoType, - mvnoData: mvnoData - } - }); - return request; - }, - - getCardLockEnabled: function(clientId, window, lockType) { - if (window == null) { - throw Components.Exception("Can't get window object", - Cr.NS_ERROR_UNEXPECTED); - } - - let request = Services.DOMRequest.createRequest(window); - let requestId = this.getRequestId(request); - this._windowsMap[requestId] = window; - - cpmm.sendAsyncMessage("RIL:GetCardLockEnabled", { - clientId: clientId, - data: { - lockType: lockType, - requestId: requestId - } - }); - return request; - }, - - unlockCardLock: function(clientId, window, lockType, password, newPin) { - if (window == null) { - throw Components.Exception("Can't get window object", - Cr.NS_ERROR_UNEXPECTED); - } - - let request = Services.DOMRequest.createRequest(window); - let requestId = this.getRequestId(request); - this._windowsMap[requestId] = window; - - cpmm.sendAsyncMessage("RIL:UnlockCardLock", { - clientId: clientId, - data: { - lockType: lockType, - password: password, - newPin: newPin, - requestId: requestId - } - }); - return request; - }, - - setCardLockEnabled: function(clientId, window, lockType, password, enabled) { - if (window == null) { - throw Components.Exception("Can't get window object", - Cr.NS_ERROR_UNEXPECTED); - } - - let request = Services.DOMRequest.createRequest(window); - let requestId = this.getRequestId(request); - this._windowsMap[requestId] = window; - - cpmm.sendAsyncMessage("RIL:SetCardLockEnabled", { - clientId: clientId, - data: { - lockType: lockType, - password: password, - enabled: enabled, - requestId: requestId - } - }); - return request; - }, - - changeCardLockPassword: function(clientId, window, lockType, password, - newPassword) { - if (window == null) { - throw Components.Exception("Can't get window object", - Cr.NS_ERROR_UNEXPECTED); - } - - let request = Services.DOMRequest.createRequest(window); - let requestId = this.getRequestId(request); - this._windowsMap[requestId] = window; - - cpmm.sendAsyncMessage("RIL:ChangeCardLockPassword", { - clientId: clientId, - data: { - lockType: lockType, - password: password, - newPassword: newPassword, - requestId: requestId - } - }); - return request; - }, - - getCardLockRetryCount: function(clientId, window, lockType) { - if (window == null) { - throw Components.Exception("Can't get window object", - Cr.NS_ERROR_UNEXPECTED); - } - let request = Services.DOMRequest.createRequest(window); - let requestId = this.getRequestId(request); - this._windowsMap[requestId] = window; - - cpmm.sendAsyncMessage("RIL:GetCardLockRetryCount", { - clientId: clientId, - data: { - lockType: lockType, - requestId: requestId - } - }); - return request; - }, - sendStkResponse: function(clientId, window, command, response) { if (window == null) { throw Components.Exception("Can't get window object", @@ -545,27 +416,6 @@ RILContentHelper.prototype = { return request; }, - getServiceState: function(clientId, window, service) { - if (window == null) { - throw Components.Exception("Can't get window object", - Cr.NS_ERROR_UNEXPECTED); - } - - return new window.Promise((resolve, reject) => { - let requestId = - this.getPromiseResolverId({resolve: resolve, reject: reject}); - this._windowsMap[requestId] = window; - - cpmm.sendAsyncMessage("RIL:GetServiceState", { - clientId: clientId, - data: { - requestId: requestId, - service: service - } - }); - }); - }, - _iccListeners: null, registerListener: function(listenerType, clientId, listener) { @@ -721,62 +571,56 @@ RILContentHelper.prototype = { case "RIL:CardStateChanged": if (this.rilContexts[clientId].cardState != data.cardState) { this.rilContexts[clientId].cardState = data.cardState; - this._deliverEvent(clientId, - "_iccListeners", - "notifyCardStateChanged", - null); + this._deliverIccEvent(clientId, + "notifyCardStateChanged", + null); } break; case "RIL:IccInfoChanged": this.updateIccInfo(clientId, data); - this._deliverEvent(clientId, - "_iccListeners", - "notifyIccInfoChanged", - null); + this._deliverIccEvent(clientId, + "notifyIccInfoChanged", + null); break; case "RIL:GetCardLockResult": { let requestId = data.requestId; - let requestWindow = this._windowsMap[requestId]; - delete this._windowsMap[requestId]; + let callback = this._requestMap[requestId]; + delete this._requestMap[requestId]; if (data.errorMsg) { - this.fireRequestError(requestId, data.errorMsg); + callback.notifyError(data.errorMsg); break; } - this.fireRequestSuccess(requestId, - Cu.cloneInto({ enabled: data.enabled }, - requestWindow)); + callback.notifySuccessWithBoolean(data.enabled); break; } case "RIL:SetUnlockCardLockResult": { let requestId = data.requestId; - let requestWindow = this._windowsMap[requestId]; - delete this._windowsMap[requestId]; + let callback = this._requestMap[requestId]; + delete this._requestMap[requestId]; if (data.errorMsg) { - let cardLockError = new requestWindow.IccCardLockError(data.errorMsg, - data.retryCount); - this.fireRequestDetailedError(requestId, cardLockError); + let retryCount = + (data.retryCount !== undefined) ? data.retryCount : -1; + callback.notifyCardLockError(data.errorMsg, retryCount); break; } - this.fireRequestSuccess(requestId, null); + callback.notifySuccess(); break; } case "RIL:CardLockRetryCount": { let requestId = data.requestId; - let requestWindow = this._windowsMap[requestId]; - delete this._windowsMap[requestId]; + let callback = this._requestMap[requestId]; + delete this._requestMap[requestId]; if (data.errorMsg) { - this.fireRequestError(data.requestId, data.errorMsg); + callback.notifyError(data.errorMsg); break; } - this.fireRequestSuccess(data.requestId, - Cu.cloneInto({ retryCount: data.retryCount }, - requestWindow)); + callback.notifyGetCardLockRetryCount(data.retryCount); break; } case "RIL:StkCommand": @@ -801,12 +645,30 @@ RILContentHelper.prototype = { case "RIL:UpdateIccContact": this.handleUpdateIccContact(data); break; - case "RIL:MatchMvno": - this.handleSimpleRequest(data.requestId, data.errorMsg, data.result); + case "RIL:MatchMvno": { + let requestId = data.requestId; + let callback = this._requestMap[requestId]; + delete this._requestMap[requestId]; + + if (data.errorMsg) { + callback.notifyError(data.errorMsg); + break; + } + callback.notifySuccessWithBoolean(data.result); break; - case "RIL:GetServiceState": - this.handleGetServiceState(data); + } + case "RIL:GetServiceState": { + let requestId = data.requestId; + let callback = this._requestMap[requestId]; + delete this._requestMap[requestId]; + + if (data.errorMsg) { + callback.notifyError(data.errorMsg); + break; + } + callback.notifySuccessWithBoolean(data.result); break; + } } }, @@ -909,20 +771,6 @@ RILContentHelper.prototype = { this.fireRequestSuccess(message.requestId, contact); }, - handleGetServiceState: function(message) { - let requestId = message.requestId; - let requestWindow = this._windowsMap[requestId]; - delete this._windowsMap[requestId]; - - let resolver = this.takePromiseResolver(requestId); - if (message.errorMsg) { - resolver.reject(new requestWindow.DOMError(message.errorMsg)); - return; - } - - resolver.resolve(message.result); - }, - _deliverEvent: function(clientId, listenerType, name, args) { if (!this[listenerType]) { return; @@ -947,6 +795,235 @@ RILContentHelper.prototype = { if (DEBUG) debug("listener for " + name + " threw an exception: " + e); } } + }, + + /** + * nsIIccService interface. + */ + + _iccs: null, // An array of Icc instances. + + getIccByServiceId: function(serviceId) { + let icc = this._iccs[serviceId]; + if (!icc) { + throw Cr.NS_ERROR_UNEXPECTED; + } + + return icc; + }, + + /** + * Bridge APIs from nsIIccService to nsIIccProvider + */ + + _deliverIccEvent: function(clientId, name, args) { + let icc = this._iccs[clientId]; + if (!icc) { + if (DEBUG) debug("_deliverIccEvent: Invalid clientId: " + clientId); + return; + } + + icc.deliverListenerEvent(name, args); + }, + + getIccInfo: function(clientId) { + let context = this.getRilContext(clientId); + return context && context.iccInfo; + }, + + getCardState: function(clientId) { + let context = this.getRilContext(clientId); + return context && context.cardState; + }, + + matchMvno: function(clientId, mvnoType, mvnoData, callback) { + let requestId = UUIDGenerator.generateUUID().toString(); + this._requestMap[requestId] = callback; + + cpmm.sendAsyncMessage("RIL:MatchMvno", { + clientId: clientId, + data: { + requestId: requestId, + mvnoType: mvnoType, + mvnoData: mvnoData + } + }); + }, + + getCardLockEnabled: function(clientId, lockType, callback) { + let requestId = UUIDGenerator.generateUUID().toString(); + this._requestMap[requestId] = callback; + + cpmm.sendAsyncMessage("RIL:GetCardLockEnabled", { + clientId: clientId, + data: { + lockType: lockType, + requestId: requestId + } + }); + }, + + unlockCardLock: function(clientId, lockType, password, newPin, callback) { + let requestId = UUIDGenerator.generateUUID().toString(); + this._requestMap[requestId] = callback; + + cpmm.sendAsyncMessage("RIL:UnlockCardLock", { + clientId: clientId, + data: { + lockType: lockType, + password: password, + newPin: newPin, + requestId: requestId + } + }); + }, + + setCardLockEnabled: function(clientId, lockType, password, enabled, callback) { + let requestId = UUIDGenerator.generateUUID().toString(); + this._requestMap[requestId] = callback; + + cpmm.sendAsyncMessage("RIL:SetCardLockEnabled", { + clientId: clientId, + data: { + lockType: lockType, + password: password, + enabled: enabled, + requestId: requestId + } + }); + }, + + changeCardLockPassword: function(clientId, lockType, password, newPassword, + callback) { + let requestId = UUIDGenerator.generateUUID().toString(); + this._requestMap[requestId] = callback; + + cpmm.sendAsyncMessage("RIL:ChangeCardLockPassword", { + clientId: clientId, + data: { + lockType: lockType, + password: password, + newPassword: newPassword, + requestId: requestId + } + }); + }, + + getCardLockRetryCount: function(clientId, lockType, callback) { + let requestId = UUIDGenerator.generateUUID().toString(); + this._requestMap[requestId] = callback; + + cpmm.sendAsyncMessage("RIL:GetCardLockRetryCount", { + clientId: clientId, + data: { + lockType: lockType, + requestId: requestId + } + }); + }, + + getServiceStateEnabled: function(clientId, service, callback) { + let requestId = UUIDGenerator.generateUUID().toString(); + this._requestMap[requestId] = callback; + + cpmm.sendAsyncMessage("RIL:GetServiceState", { + clientId: clientId, + data: { + requestId: requestId, + service: service + } + }); + } +}; + +function Icc(aIccProvider, aClientId) { + this._iccProvider = aIccProvider; + this._clientId = aClientId; + this._listeners = []; +} +Icc.prototype = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsIIcc]), + + _iccProvider: null, + _clientId: -1, + _listeners: null, + + deliverListenerEvent: function(aName, aArgs) { + let listeners = this._listeners.slice(); + for (let listener of listeners) { + if (this._listeners.indexOf(listener) === -1) { + continue; + } + let handler = listener[aName]; + if (typeof handler != "function") { + throw new Error("No handler for " + aName); + } + try { + handler.apply(listener, aArgs); + } catch (e) { + if (DEBUG) { + debug("listener for " + aName + " threw an exception: " + e); + } + } + } + }, + + /** + * nsIIcc interface. + */ + registerListener: function(aListener) { + if (this._listeners.indexOf(aListener) >= 0) { + throw Cr.NS_ERROR_UNEXPECTED; + } + + this._listeners.push(aListener); + cpmm.sendAsyncMessage("RIL:RegisterIccMsg"); + }, + + unregisterListener: function(aListener) { + let index = this._listeners.indexOf(aListener); + if (index >= 0) { + this._listeners.splice(index, 1); + } + }, + + get iccInfo() { + return this._iccProvider.getIccInfo(this._clientId); + }, + + get cardState() { + return this._iccProvider.getCardState(this._clientId); + }, + + getCardLockEnabled: function(aLockType, aCallback) { + this._iccProvider.getCardLockEnabled(this._clientId, aLockType, aCallback); + }, + + unlockCardLock: function(aLockType, aPassword, aNewPin, aCallback) { + this._iccProvider.unlockCardLock(this._clientId, aLockType, + aPassword, aNewPin, aCallback); + }, + + setCardLockEnabled: function(aLockType, aPassword, aEnabled, aCallback) { + this._iccProvider.setCardLockEnabled(this._clientId, aLockType, + aPassword, aEnabled, aCallback); + }, + + changeCardLockPassword: function(aLockType, aPassword, aNewPassword, aCallback) { + this._iccProvider.changeCardLockPassword(this._clientId, aLockType, + aPassword, aNewPassword, aCallback); + }, + + getCardLockRetryCount: function(aLockType, aCallback) { + this._iccProvider.getCardLockRetryCount(this._clientId, aLockType, aCallback); + }, + + matchMvno: function(aMvnoType, aMvnoData, aCallback) { + this._iccProvider.matchMvno(this._clientId, aMvnoType, aMvnoData, aCallback); + }, + + getServiceStateEnabled: function(aService, aCallback) { + this._iccProvider.getServiceStateEnabled(this._clientId, aService, aCallback); } }; diff --git a/dom/system/gonk/RadioInterfaceLayer.js b/dom/system/gonk/RadioInterfaceLayer.js index 8f918bc3f941..83a827eb91cf 100644 --- a/dom/system/gonk/RadioInterfaceLayer.js +++ b/dom/system/gonk/RadioInterfaceLayer.js @@ -1439,6 +1439,7 @@ RadioInterfaceLayer.prototype = { interfaces: [Ci.nsIRadioInterfaceLayer]}), QueryInterface: XPCOMUtils.generateQI([Ci.nsIRadioInterfaceLayer, + Ci.nsIRadioInterfaceLayer_new, Ci.nsIObserver]), /** diff --git a/dom/system/gonk/nsIRadioInterfaceLayer.idl b/dom/system/gonk/nsIRadioInterfaceLayer.idl index c36d2bdc5047..db4c56a9c8a4 100644 --- a/dom/system/gonk/nsIRadioInterfaceLayer.idl +++ b/dom/system/gonk/nsIRadioInterfaceLayer.idl @@ -79,3 +79,13 @@ interface nsIRadioInterfaceLayer : nsISupports void setMicrophoneMuted(in boolean muted); }; + + +/** + * Helper Interface to define new APIs of nsIRadioInterfaceLayer during + * ril-interfaces frozen phase. + */ +[scriptable, uuid(f8ec63da-c22e-11e4-89f3-b767dae42a13)] +interface nsIRadioInterfaceLayer_new : nsIRadioInterfaceLayer +{ +}; From 20a12fcc38e45aed3b2941b18f94a14d3876e32e Mon Sep 17 00:00:00 2001 From: Bevis Tseng Date: Fri, 13 Feb 2015 15:05:37 +0800 Subject: [PATCH 21/43] Bug 1114935 - Part 8: Mark TODO items for deprecating RILContentHelper. r=echen --HG-- extra : histedit_source : e0798b1d557e71945b2190ac1f6ff4c46a199313 --- dom/icc/IccManager.cpp | 2 ++ dom/icc/interfaces/moz.build | 2 +- dom/system/gonk/RILContentHelper.manifest | 2 ++ dom/system/gonk/RadioInterfaceLayer.js | 17 +++++++++++++++-- dom/system/gonk/moz.build | 4 ++-- .../tests/marionette/test_ril_code_quality.py | 5 +++-- 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/dom/icc/IccManager.cpp b/dom/icc/IccManager.cpp index e7b616b73af6..6f4426517163 100644 --- a/dom/icc/IccManager.cpp +++ b/dom/icc/IccManager.cpp @@ -13,6 +13,7 @@ // Service instantiation #include "ipc/IccIPCService.h" #if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL) +// TODO: Bug 815526, deprecate RILContentHelper. #include "nsIRadioInterfaceLayer.h" #include "nsRadioInterfaceLayer.h" #include "nsIGonkIccService.h" @@ -147,6 +148,7 @@ NS_CreateIccService() service = new mozilla::dom::icc::IccIPCService(); #if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL) } else { + // TODO: Bug 815526, deprecate RILContentHelper. nsCOMPtr ril = do_GetService(NS_RADIOINTERFACELAYER_CONTRACTID); nsCOMPtr ril_new(do_QueryInterface(ril)); diff --git a/dom/icc/interfaces/moz.build b/dom/icc/interfaces/moz.build index b95992c5919a..9c5a1fa64351 100644 --- a/dom/icc/interfaces/moz.build +++ b/dom/icc/interfaces/moz.build @@ -6,7 +6,7 @@ XPIDL_SOURCES += [ 'nsIIccInfo.idl', - 'nsIIccProvider.idl', + 'nsIIccProvider.idl', # TODO: Bug 815526, deprecate RILContentHelper. 'nsIIccService.idl', ] diff --git a/dom/system/gonk/RILContentHelper.manifest b/dom/system/gonk/RILContentHelper.manifest index fbfb1a1f64b1..c9a871ba583e 100644 --- a/dom/system/gonk/RILContentHelper.manifest +++ b/dom/system/gonk/RILContentHelper.manifest @@ -13,6 +13,8 @@ # limitations under the License. # RILContentHelper.js +# TODO: Bug 815526, deprecate RILContentHelper: +# To be removed from b2g/installer/package-manifest.in as well. component {472816e1-1fd6-4405-996c-806f9ea68174} RILContentHelper.js contract @mozilla.org/ril/content-helper;1 {472816e1-1fd6-4405-996c-806f9ea68174} category profile-after-change RILContentHelper @mozilla.org/ril/content-helper;1 diff --git a/dom/system/gonk/RadioInterfaceLayer.js b/dom/system/gonk/RadioInterfaceLayer.js index 83a827eb91cf..fd1057818c2c 100644 --- a/dom/system/gonk/RadioInterfaceLayer.js +++ b/dom/system/gonk/RadioInterfaceLayer.js @@ -87,6 +87,7 @@ const NETWORK_TYPE_MOBILE_SUPL = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL const NETWORK_TYPE_MOBILE_IMS = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_IMS; const NETWORK_TYPE_MOBILE_DUN = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_DUN; +// TODO: Bug 815526, deprecate RILContentHelper. const RIL_IPC_ICCMANAGER_MSG_NAMES = [ "RIL:GetRilContext", "RIL:SendStkResponse", @@ -181,6 +182,7 @@ XPCOMUtils.defineLazyGetter(this, "gStkCmdFactory", function() { return stk.StkProactiveCmdFactory; }); +// TODO: Bug 815526, deprecate RILContentHelper. XPCOMUtils.defineLazyGetter(this, "gMessageManager", function() { return { QueryInterface: XPCOMUtils.generateQI([Ci.nsIMessageListener, @@ -1427,7 +1429,7 @@ function RadioInterfaceLayer() { Services.obs.addObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false); Services.prefs.addObserver(kPrefRilDebuggingEnabled, this, false); - gMessageManager.init(this); + gMessageManager.init(this); // TODO: Bug 815526, deprecate RILContentHelper. gRadioEnabledController.init(this); gDataConnectionManager.init(this); } @@ -1439,7 +1441,7 @@ RadioInterfaceLayer.prototype = { interfaces: [Ci.nsIRadioInterfaceLayer]}), QueryInterface: XPCOMUtils.generateQI([Ci.nsIRadioInterfaceLayer, - Ci.nsIRadioInterfaceLayer_new, + Ci.nsIRadioInterfaceLayer_new, // TODO: Bug 815526, deprecate RILContentHelper. Ci.nsIObserver]), /** @@ -1681,6 +1683,7 @@ function RadioInterface(aClientId, aWorkerMessenger) { this.clientId = aClientId; this.workerMessenger = { send: aWorkerMessenger.send.bind(aWorkerMessenger, aClientId), + // TODO: Bug 815526, deprecate RILContentHelper. sendWithIPCMessage: aWorkerMessenger.sendWithIPCMessage.bind(aWorkerMessenger, aClientId), }; @@ -1791,6 +1794,8 @@ RadioInterface.prototype = { /** * Process a message from the content process. + * + * TODO: Bug 815526, deprecate RILContentHelper */ receiveMessage: function(msg) { switch (msg.name) { @@ -1923,6 +1928,7 @@ RadioInterface.prototype = { gRadioEnabledController.receiveCardState(this.clientId); gIccService.notifyCardStateChanged(this.clientId, this.rilContext.cardState); + // TODO: Bug 815526, deprecate RILContentHelper. gMessageManager.sendIccMessage("RIL:CardStateChanged", this.clientId, message); break; @@ -1952,6 +1958,7 @@ RadioInterface.prototype = { this.handleStkProactiveCommand(message); break; case "stksessionend": + // TODO: Bug 815526, deprecate RILContentHelper. gMessageManager.sendIccMessage("RIL:StkSessionEnd", this.clientId, null); break; case "cdma-info-rec-received": @@ -1967,6 +1974,7 @@ RadioInterface.prototype = { // and not compared. E.g., if the mvnoData passed is '310260x10xxxxxx', // then the function returns true only if imsi has the same first 6 digits, // 8th and 9th digit. + // TODO: Bug 815526, deprecate RILContentHelper. isImsiMatches: function(mvnoData) { let imsi = this.rilContext.imsi; @@ -1984,6 +1992,7 @@ RadioInterface.prototype = { return true; }, + // TODO: Bug 815526, deprecate RILContentHelper. matchMvno: function(target, message) { if (DEBUG) this.debug("matchMvno: " + JSON.stringify(message)); @@ -2221,6 +2230,8 @@ RadioInterface.prototype = { handleIccInfoChange: function(message) { let oldSpn = this.rilContext.iccInfo ? this.rilContext.iccInfo.spn : null; + // TODO: Bug 815526, deprecate RILContentHelper: + // Move the logic of updating iccInfo to IccService.js. if (!message || !message.iccid) { // If iccInfo is already `null`, don't have to clear it and send // RIL:IccInfoChanged. @@ -2250,6 +2261,7 @@ RadioInterface.prototype = { // RIL:IccInfoChanged corresponds to a DOM event that gets fired only // when iccInfo has changed. + // TODO: Bug 815526, deprecate RILContentHelper. gMessageManager.sendIccMessage("RIL:IccInfoChanged", this.clientId, message.iccid ? message : null); @@ -2281,6 +2293,7 @@ RadioInterface.prototype = { .notifyStkProactiveCommand(iccId, gStkCmdFactory.createCommand(message)); } + // TODO: Bug 815526, deprecate RILContentHelper. gMessageManager.sendIccMessage("RIL:StkCommand", this.clientId, message); }, diff --git a/dom/system/gonk/moz.build b/dom/system/gonk/moz.build index 1a88c4c22154..c52f5149ee5c 100644 --- a/dom/system/gonk/moz.build +++ b/dom/system/gonk/moz.build @@ -89,8 +89,8 @@ if CONFIG['MOZ_B2G_RIL']: 'nsIRadioInterfaceLayer.idl', ] EXTRA_COMPONENTS += [ - 'RILContentHelper.js', - 'RILContentHelper.manifest', + 'RILContentHelper.js', # TODO: Bug 815526, deprecate RILContentHelper. + 'RILContentHelper.manifest', # TODO: Bug 815526, deprecate RILContentHelper. 'RILSystemMessengerHelper.js', 'RILSystemMessengerHelper.manifest', ] diff --git a/dom/system/gonk/tests/marionette/test_ril_code_quality.py b/dom/system/gonk/tests/marionette/test_ril_code_quality.py index f9221391f54d..1002b99486f7 100644 --- a/dom/system/gonk/tests/marionette/test_ril_code_quality.py +++ b/dom/system/gonk/tests/marionette/test_ril_code_quality.py @@ -2,7 +2,7 @@ The test performs the static code analysis check by JSHint. Target js files: -- RILContentHelper.js +- RILContentHelper.js TODO: Bug 815526, deprecate RILContentHelper. - RadioInterfaceLayer.js - ril_worker.js - ril_consts.js @@ -100,7 +100,7 @@ class ResourceUriFileReader: URI_PREFIX = 'resource://gre/' URI_PATH = { - 'RILContentHelper.js': 'components/RILContentHelper.js', + 'RILContentHelper.js': 'components/RILContentHelper.js', #TODO: Bug 815526, deprecate RILContentHelper. 'RadioInterfaceLayer.js': 'components/RadioInterfaceLayer.js', 'ril_worker.js': 'modules/ril_worker.js', 'ril_consts.js': 'modules/ril_consts.js', @@ -354,6 +354,7 @@ class TestRILCodeQuality(MarionetteTestCase): def tearDown(self): MarionetteTestCase.tearDown(self) + # TODO: Bug 815526, deprecate RILContentHelper. def test_RILContentHelper(self): self._check('RILContentHelper.js') From e8389f584ad9494ce388cb5190005ee202a759ff Mon Sep 17 00:00:00 2001 From: Mike de Boer Date: Fri, 27 Mar 2015 14:31:50 +0100 Subject: [PATCH 22/43] Bug 1132301: Part 1 - share button should emit notifications when it is added to or removed from a customizable area. r=mixedpuppy --- .../customizableui/CustomizableWidgets.jsm | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/browser/components/customizableui/CustomizableWidgets.jsm b/browser/components/customizableui/CustomizableWidgets.jsm index 1124e1946b02..45e3c92d2f32 100644 --- a/browser/components/customizableui/CustomizableWidgets.jsm +++ b/browser/components/customizableui/CustomizableWidgets.jsm @@ -413,6 +413,31 @@ const CustomizableWidgets = [ node.setAttribute("removable", "true"); node.setAttribute("observes", "Social:PageShareOrMark"); node.setAttribute("command", "Social:SharePage"); + + let listener = { + onWidgetAdded: (aWidgetId) => { + if (aWidgetId != this.id) + return; + + Services.obs.notifyObservers(null, "social:" + this.id + "-added", null); + }, + + onWidgetRemoved: aWidgetId => { + if (aWidgetId != this.id) + return; + + Services.obs.notifyObservers(null, "social:" + this.id + "-removed", null); + }, + + onWidgetInstanceRemoved: (aWidgetId, aDoc) => { + if (aWidgetId != this.id || aDoc != aDocument) + return; + + CustomizableUI.removeListener(listener); + } + }; + CustomizableUI.addListener(listener); + return node; } }, { From e7a9008b10de5c2628fc270b81cf5b17c99f6f1b Mon Sep 17 00:00:00 2001 From: Mike de Boer Date: Fri, 27 Mar 2015 14:31:53 +0100 Subject: [PATCH 23/43] Bug 1132301: Part 2 - add navigator.mozLoop methods to allow interaction between Loop and the Social API. r=Standard8,mixedpuppy --- browser/components/loop/MozLoopAPI.jsm | 199 +++++++++++++++++- .../loop/test/mochitest/browser.ini | 1 + .../mochitest/browser_mozLoop_socialShare.js | 139 ++++++++++++ .../components/loop/test/mochitest/head.js | 28 +++ 4 files changed, 363 insertions(+), 4 deletions(-) create mode 100644 browser/components/loop/test/mochitest/browser_mozLoop_socialShare.js diff --git a/browser/components/loop/MozLoopAPI.jsm b/browser/components/loop/MozLoopAPI.jsm index 68a8f03b39be..a33044c7c11c 100644 --- a/browser/components/loop/MozLoopAPI.jsm +++ b/browser/components/loop/MozLoopAPI.jsm @@ -27,6 +27,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", "resource://gre/modules/PluralForm.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "UITour", "resource:///modules/UITour.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "Social", + "resource:///modules/Social.jsm"); XPCOMUtils.defineLazyGetter(this, "appInfo", function() { return Cc["@mozilla.org/xre/app-info;1"] .getService(Ci.nsIXULAppInfo) @@ -199,6 +201,10 @@ function injectLoopAPI(targetWindow) { let roomsAPI; let callsAPI; let savedWindowListeners = new Map(); + let socialProviders; + const kShareWidgetId = "social-share-button"; + let socialShareButtonListenersAdded = false; + let api = { /** @@ -912,20 +918,205 @@ function injectLoopAPI(targetWindow) { value: function(windowId, active) { MozLoopService.setScreenShareState(windowId, active); } + }, + + /** + * Checks if the Social Share widget is available in any of the registered + * widget areas (navbar, MenuPanel, etc). + * + * @return {Boolean} `true` if the widget is available and `false` when it's + * still in the Customization palette. + */ + isSocialShareButtonAvailable: { + enumerable: true, + writable: true, + value: function() { + let win = Services.wm.getMostRecentWindow("navigator:browser"); + if (!win || !win.CustomizableUI) { + return false; + } + + let widget = win.CustomizableUI.getWidget(kShareWidgetId); + if (widget) { + if (!socialShareButtonListenersAdded) { + let eventName = "social:" + kShareWidgetId; + Services.obs.addObserver(onShareWidgetChanged, eventName + "-added", false); + Services.obs.addObserver(onShareWidgetChanged, eventName + "-removed", false); + socialShareButtonListenersAdded = true; + } + return !!widget.areaType; + } + + return false; + } + }, + + /** + * Add the Social Share widget to the navbar area, but only when it's not + * located anywhere else than the Customization palette. + */ + addSocialShareButton: { + enumerable: true, + writable: true, + value: function() { + // Don't do anything if the button is already available. + if (api.isSocialShareButtonAvailable.value()) { + return; + } + + let win = Services.wm.getMostRecentWindow("navigator:browser"); + if (!win || !win.CustomizableUI) { + return; + } + win.CustomizableUI.addWidgetToArea(kShareWidgetId, win.CustomizableUI.AREA_NAVBAR); + } + }, + + /** + * Activates the Social Share panel with the Social Provider panel opened + * when the popup open. + */ + addSocialShareProvider: { + enumerable: true, + writable: true, + value: function() { + // Don't do anything if the button is _not_ available. + if (!api.isSocialShareButtonAvailable.value()) { + return; + } + + let win = Services.wm.getMostRecentWindow("navigator:browser"); + if (!win || !win.SocialShare) { + return; + } + win.SocialShare.showDirectory(); + } + }, + + /** + * Returns a sorted list of Social Providers that can share URLs. See + * `updateSocialProvidersCache()` for more information. + * + * @return {Array} Sorted list of share-capable Social Providers. + */ + getSocialShareProviders: { + enumerable: true, + writable: true, + value: function() { + if (socialProviders) { + return socialProviders; + } + return updateSocialProvidersCache(); + } + }, + + /** + * Share a room URL through a Social Provider with the provided title message. + * This action will open the share panel, which is anchored to the Social + * Share widget. + * + * @param {String} providerOrigin Identifier of the targeted Social Provider + * @param {String} roomURL URL that points to the standalone client + * @param {String} title Message that augments the URL inside the + * share message + * @param {String} [body] Optional longer message to be displayed + * similar to the body of an email + */ + socialShareRoom: { + enumerable: true, + writable: true, + value: function(providerOrigin, roomURL, title, body = null) { + let win = Services.wm.getMostRecentWindow("navigator:browser"); + if (!win || !win.SocialShare) { + return; + } + + let graphData = { + url: roomURL, + title: title + }; + if (body) { + graphData.body = body; + } + win.SocialShare.sharePage(providerOrigin, graphData); + } } }; - function onStatusChanged(aSubject, aTopic, aData) { - let event = new targetWindow.CustomEvent("LoopStatusChanged"); + /** + * Send an event to the content window to indicate that the state on the chrome + * side was updated. + * + * @param {name} name Name of the event, defaults to 'LoopStatusChanged' + */ + function sendEvent(name = "LoopStatusChanged") { + let event = new targetWindow.CustomEvent(name); targetWindow.dispatchEvent(event); - }; + } + + function onStatusChanged(aSubject, aTopic, aData) { + sendEvent(); + } function onDOMWindowDestroyed(aSubject, aTopic, aData) { if (targetWindow && aSubject != targetWindow) return; Services.obs.removeObserver(onDOMWindowDestroyed, "dom-window-destroyed"); Services.obs.removeObserver(onStatusChanged, "loop-status-changed"); - }; + // Stop listening for changes in the social provider list, if necessary. + if (socialProviders) + Services.obs.removeObserver(updateSocialProvidersCache, "social:providers-changed"); + if (socialShareButtonListenersAdded) { + let eventName = "social:" + kShareWidgetId; + Services.obs.removeObserver(onShareWidgetChanged, eventName + "-added"); + Services.obs.removeObserver(onShareWidgetChanged, eventName + "-removed"); + } + } + + function onShareWidgetChanged(aSubject, aTopic, aData) { + sendEvent("LoopShareWidgetChanged"); + } + + /** + * Retrieves a list of Social Providers from the Social API that are explicitly + * capable of sharing URLs. + * It also adds a listener that is fired whenever a new Provider is added or + * removed. + * + * @return {Array} Sorted list of share-capable Social Providers. + */ + function updateSocialProvidersCache() { + let providers = []; + + for (let provider of Social.providers) { + if (!provider.shareURL) { + continue; + } + + // Only pass the relevant data on to content. + providers.push({ + iconURL: provider.iconURL, + name: provider.name, + origin: provider.origin + }); + } + + let providersWasSet = !!socialProviders; + // Replace old with new. + socialProviders = cloneValueInto(providers.sort((a, b) => + a.name.toLowerCase().localeCompare(b.name.toLowerCase())), targetWindow); + + // Start listening for changes in the social provider list, if we're not + // doing that yet. + if (!providersWasSet) { + Services.obs.addObserver(updateSocialProvidersCache, "social:providers-changed", false); + } else { + // Dispatch an event to content to let stores freshen-up. + sendEvent("LoopSocialProvidersChanged"); + } + + return socialProviders; + } let contentObj = Cu.createObjectIn(targetWindow); Object.defineProperties(contentObj, api); diff --git a/browser/components/loop/test/mochitest/browser.ini b/browser/components/loop/test/mochitest/browser.ini index a499988fb06a..d25f580b25ea 100644 --- a/browser/components/loop/test/mochitest/browser.ini +++ b/browser/components/loop/test/mochitest/browser.ini @@ -22,6 +22,7 @@ skip-if = buildapp == 'mulet' [browser_mozLoop_pluralStrings.js] [browser_mozLoop_sharingListeners.js] skip-if = e10s +[browser_mozLoop_socialShare.js] [browser_mozLoop_telemetry.js] skip-if = e10s [browser_toolbarbutton.js] diff --git a/browser/components/loop/test/mochitest/browser_mozLoop_socialShare.js b/browser/components/loop/test/mochitest/browser_mozLoop_socialShare.js new file mode 100644 index 000000000000..7659dd8ee862 --- /dev/null +++ b/browser/components/loop/test/mochitest/browser_mozLoop_socialShare.js @@ -0,0 +1,139 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * This is an integration test from navigator.mozLoop through to the end + * effects - rather than just testing MozLoopAPI alone. + */ + +Cu.import("resource://gre/modules/Promise.jsm"); +const {SocialService} = Cu.import("resource://gre/modules/SocialService.jsm", {}); + +add_task(loadLoopPanel); + +const kShareWidgetId = "social-share-button"; +const kShareProvider = { + name: "provider 1", + origin: "https://example.com", + workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js", + iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png", + shareURL: "https://example.com/browser/browser/base/content/test/social/share.html" +}; +const kShareProviderInvalid = { + name: "provider 1", + origin: "https://example2.com" +}; + +add_task(function* test_mozLoop_isSocialShareButtonAvailable() { + Assert.ok(gMozLoopAPI, "mozLoop should exist"); + + // First make sure the Social Share button is not available. This is probably + // already the case, but make it explicit here. + CustomizableUI.removeWidgetFromArea(kShareWidgetId); + + Assert.ok(!gMozLoopAPI.isSocialShareButtonAvailable(), + "Social Share button should not be available"); + + // Add the widget to the navbar. + CustomizableUI.addWidgetToArea(kShareWidgetId, CustomizableUI.AREA_NAVBAR); + + Assert.ok(gMozLoopAPI.isSocialShareButtonAvailable(), + "Social Share button should be available"); + + // Add the widget to the MenuPanel. + CustomizableUI.addWidgetToArea(kShareWidgetId, CustomizableUI.AREA_PANEL); + + Assert.ok(gMozLoopAPI.isSocialShareButtonAvailable(), + "Social Share button should still be available"); + + // Test button removal during the same session. + CustomizableUI.removeWidgetFromArea(kShareWidgetId); + + Assert.ok(!gMozLoopAPI.isSocialShareButtonAvailable(), + "Social Share button should not be available"); +}); + +add_task(function* test_mozLoop_addSocialShareButton() { + gMozLoopAPI.addSocialShareButton(); + + Assert.ok(gMozLoopAPI.isSocialShareButtonAvailable(), + "Social Share button should be available"); + + let widget = CustomizableUI.getWidget(kShareWidgetId); + Assert.strictEqual(widget.areaType, CustomizableUI.TYPE_TOOLBAR, + "Social Share button should be placed in the navbar"); + + CustomizableUI.removeWidgetFromArea(kShareWidgetId); +}); + +add_task(function* test_mozLoop_addSocialShareProvider() { + gMozLoopAPI.addSocialShareButton(); + + gMozLoopAPI.addSocialShareProvider(); + + yield promiseWaitForCondition(() => SocialShare.panel.state == "open"); + + Assert.equal(SocialShare.iframe.getAttribute("src"), "about:providerdirectory", + "Provider directory page should be visible"); + + SocialShare.panel.hidePopup(); + CustomizableUI.removeWidgetFromArea(kShareWidgetId); +}); + +add_task(function* test_mozLoop_getSocialShareProviders() { + Assert.strictEqual(gMozLoopAPI.getSocialShareProviders().length, 0, + "Provider list should be empty initially"); + + // Add a provider. + yield new Promise(resolve => SocialService.addProvider(kShareProvider, resolve)); + + let providers = gMozLoopAPI.getSocialShareProviders(); + Assert.strictEqual(providers.length, 1, + "The newly added provider should be part of the list"); + let provider = providers[0]; + Assert.strictEqual(provider.iconURL, kShareProvider.iconURL, "Icon URLs should match"); + Assert.strictEqual(provider.name, kShareProvider.name, "Names should match"); + Assert.strictEqual(provider.origin, kShareProvider.origin, "Origins should match"); + + // Add another provider that should not be picked up by Loop. + yield new Promise(resolve => SocialService.addProvider(kShareProviderInvalid, resolve)); + + providers = gMozLoopAPI.getSocialShareProviders(); + Assert.strictEqual(providers.length, 1, + "The newly added provider should not be part of the list"); + + // Let's add a valid second provider object. + let provider2 = Object.create(kShareProvider); + provider2.name = "Wildly different name"; + provider2.origin = "https://example3.com"; + yield new Promise(resolve => SocialService.addProvider(provider2, resolve)); + + providers = gMozLoopAPI.getSocialShareProviders(); + Assert.strictEqual(providers.length, 2, + "The newly added provider should be part of the list"); + Assert.strictEqual(providers[1].name, provider2.name, + "Providers should be ordered alphabetically"); + + // Remove the second valid provider. + yield new Promise(resolve => SocialService.disableProvider(provider2.origin, resolve)); + providers = gMozLoopAPI.getSocialShareProviders(); + Assert.strictEqual(providers.length, 1, + "The uninstalled provider should not be part of the list"); + Assert.strictEqual(providers[0].name, kShareProvider.name, "Names should match"); +}); + +add_task(function* test_mozLoop_socialShareRoom() { + gMozLoopAPI.addSocialShareButton(); + + gMozLoopAPI.socialShareRoom(kShareProvider.origin, "https://someroom.com", "Some Title"); + + yield promiseWaitForCondition(() => SocialShare.panel.state == "open"); + + Assert.equal(SocialShare.iframe.getAttribute("origin"), kShareProvider.origin, + "Origins should match"); + Assert.equal(SocialShare.iframe.getAttribute("src"), kShareProvider.shareURL, + "Provider's share page should be displayed"); + + SocialShare.panel.hidePopup(); + CustomizableUI.removeWidgetFromArea(kShareWidgetId); +}); diff --git a/browser/components/loop/test/mochitest/head.js b/browser/components/loop/test/mochitest/head.js index 086b53fd3e71..2b80ff6ec9ae 100644 --- a/browser/components/loop/test/mochitest/head.js +++ b/browser/components/loop/test/mochitest/head.js @@ -71,6 +71,34 @@ function promiseGetMozLoopAPI() { }); } +function waitForCondition(condition, nextTest, errorMsg) { + var tries = 0; + var interval = setInterval(function() { + if (tries >= 30) { + ok(false, errorMsg); + moveOn(); + } + var conditionPassed; + try { + conditionPassed = condition(); + } catch (e) { + ok(false, e + "\n" + e.stack); + conditionPassed = false; + } + if (conditionPassed) { + moveOn(); + } + tries++; + }, 100); + var moveOn = function() { clearInterval(interval); nextTest(); }; +} + +function promiseWaitForCondition(aConditionFn) { + let deferred = Promise.defer(); + waitForCondition(aConditionFn, deferred.resolve, "Condition didn't pass."); + return deferred.promise; +} + /** * Loads the loop panel by clicking the button and waits for its open to complete. * It also registers From adaaa3af82f92a7dbe4e9e67d886825c18012fc2 Mon Sep 17 00:00:00 2001 From: Mike de Boer Date: Fri, 27 Mar 2015 14:31:55 +0100 Subject: [PATCH 24/43] Bug 1132301: Part 3 - hide the Loop dropdowns when the content window loses focus, so mouseLeave workarounds can be removed. r=Standard8 --- browser/components/loop/content/js/panel.js | 6 ++---- browser/components/loop/content/js/panel.jsx | 6 ++---- browser/components/loop/content/shared/js/mixins.js | 7 +++++-- browser/components/loop/test/desktop-local/panel_test.js | 1 + 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/browser/components/loop/content/js/panel.js b/browser/components/loop/content/js/panel.js index 22711093142a..37a363c4bcf9 100644 --- a/browser/components/loop/content/js/panel.js +++ b/browser/components/loop/content/js/panel.js @@ -167,8 +167,7 @@ loop.panel = (function(_, mozL10n) { React.createElement("span", null, availabilityText), React.createElement("i", {className: availabilityStatus}) ), - React.createElement("ul", {className: availabilityDropdown, - onMouseLeave: this.hideDropdownMenu}, + React.createElement("ul", {className: availabilityDropdown}, React.createElement("li", {onClick: this.changeAvailability("available"), className: "dropdown-menu-item dnd-make-available"}, React.createElement("i", {className: "status status-available"}), @@ -345,8 +344,7 @@ loop.panel = (function(_, mozL10n) { React.createElement("div", {className: "settings-menu dropdown"}, React.createElement("a", {className: "button-settings", onClick: this.showDropdownMenu, title: mozL10n.get("settings_menu_button_tooltip")}), - React.createElement("ul", {className: cx({"dropdown-menu": true, hide: !this.state.showMenu}), - onMouseLeave: this.hideDropdownMenu}, + React.createElement("ul", {className: cx({"dropdown-menu": true, hide: !this.state.showMenu})}, React.createElement(SettingsDropdownEntry, {label: mozL10n.get("settings_menu_item_settings"), onClick: this.handleClickSettingsEntry, displayed: false, diff --git a/browser/components/loop/content/js/panel.jsx b/browser/components/loop/content/js/panel.jsx index ca0c600177a4..543c2d976572 100644 --- a/browser/components/loop/content/js/panel.jsx +++ b/browser/components/loop/content/js/panel.jsx @@ -167,8 +167,7 @@ loop.panel = (function(_, mozL10n) { {availabilityText}

-