Merge m-c to fx-team a=merge CLOSED TREE
authorWes Kocher <wkocher@mozilla.com>
Wed, 18 Mar 2015 16:04:40 -0700
changeset 234375 cf1060d8ce9f7cfaa1ab9be4a6c062f8de5abd95
parent 234374 9dd325adf18b9269d750ca14d263d17308835c47 (current diff)
parent 234357 09f6642f7d242f6063b08d41b47715b2e6647657 (diff)
child 234376 75865c5deec88c09700470f483ebb287d47d22c3
child 234432 db07f0b48a2d87cc721b4b84cf8a29cb8f2f3c63
child 234497 ce9a9426c9c1abdc2180e12363a67e8097d52ba2
push id57106
push userkwierso@gmail.com
push dateThu, 19 Mar 2015 00:33:47 +0000
treeherdermozilla-inbound@75865c5deec8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmerge
milestone39.0a1
first release with
nightly linux32
cf1060d8ce9f / 39.0a1 / 20150319030202 / files
nightly linux64
cf1060d8ce9f / 39.0a1 / 20150319030202 / files
nightly mac
cf1060d8ce9f / 39.0a1 / 20150319030202 / files
nightly win32
cf1060d8ce9f / 39.0a1 / 20150319030202 / files
nightly win64
cf1060d8ce9f / 39.0a1 / 20150319030202 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Merge m-c to fx-team a=merge CLOSED TREE
dom/icc/IccCallback.cpp
dom/icc/IccCallback.h
dom/icc/gonk/IccService.js
dom/icc/gonk/IccService.manifest
dom/icc/interfaces/nsIGonkIccService.idl
dom/icc/interfaces/nsIIccService.idl
dom/icc/ipc/IccChild.cpp
dom/icc/ipc/IccChild.h
dom/icc/ipc/IccIPCService.cpp
dom/icc/ipc/IccIPCService.h
dom/icc/ipc/IccParent.cpp
dom/icc/ipc/IccParent.h
dom/icc/ipc/PIcc.ipdl
dom/icc/ipc/PIccRequest.ipdl
dom/icc/ipc/PIccTypes.ipdlh
dom/media/MediaPromise.cpp
--- a/b2g/chrome/content/settings.js
+++ b/b2g/chrome/content/settings.js
@@ -517,16 +517,17 @@ let settingsToObserve = {
   'gfx.layerscope.enabled': false,
   'layers.draw-borders': false,
   'layers.draw-tile-borders': false,
   'layers.dump': false,
   'layers.enable-tiles': true,
   'layers.effect.invert': false,
   'layers.effect.grayscale': false,
   'layers.effect.contrast': "0.0",
+  'network.debugging.enabled': false,
   'privacy.donottrackheader.enabled': false,
   'ril.debugging.enabled': false,
   'ril.radio.disabled': false,
   'ril.mms.requestReadReport.enabled': {
     prefName: 'dom.mms.requestReadReport',
     defaultValue: true
   },
   'ril.mms.requestStatusReport.enabled': {
--- a/b2g/components/PaymentProviderStrategy.js
+++ b/b2g/components/PaymentProviderStrategy.js
@@ -6,19 +6,19 @@
 
 const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
 
 const PREF_DEBUG = "dom.payment.debug";
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
-XPCOMUtils.defineLazyServiceGetter(this, "gIccService",
-                                   "@mozilla.org/icc/iccservice;1",
-                                   "nsIIccService");
+XPCOMUtils.defineLazyServiceGetter(this, "iccProvider",
+                                   "@mozilla.org/ril/content-helper;1",
+                                   "nsIIccProvider");
 
 XPCOMUtils.defineLazyServiceGetter(this, "gRil",
                                    "@mozilla.org/ril;1",
                                    "nsIRadioInterfaceLayer");
 
 XPCOMUtils.defineLazyServiceGetter(this, "gSettingsService",
                                    "@mozilla.org/settingsService;1",
                                    "nsISettingsService");
@@ -143,18 +143,17 @@ PaymentProviderStrategy.prototype = {
   set paymentServiceId(aServiceId) {
     this._settings.paymentServiceId = aServiceId;
   },
 
   get iccInfo() {
     if (!this._iccInfo) {
       this._iccInfo = [];
       for (let i = 0; i < gRil.numRadioInterfaces; i++) {
-        let icc = gIccService.getIccByServiceId(i);
-        let info = icc && icc.iccInfo;
+        let info = iccProvider.getIccInfo(i);
         if (!info) {
           LOGE("Tried to get the ICC info for an invalid service ID " + i);
           continue;
         }
 
         this._iccInfo.push({
           iccId: info.iccid,
           mcc: info.mcc,
--- a/b2g/config/dolphin/sources.xml
+++ b/b2g/config/dolphin/sources.xml
@@ -10,17 +10,17 @@
   <!--original fetch url was git://codeaurora.org/-->
   <remote fetch="https://git.mozilla.org/external/caf" name="caf"/>
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="ef937d1aca7c4cf89ecb5cc43ae8c21c2000a9db">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="b8051d370ddf4e5bd8e7d8a19fb9eeb5fd6ffb39"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="c39e15f631de80c69467fda0d4ea0bcda9e194ca"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="86cd7486d8e50eaac8ef6fe2f51f09d25194577b"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="ed2cf97a6c37a4bbd0bbbbffe06ec7136d8c79ff"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="40f5ce12859076b63307480ff2f0bbdf42bbf258"/>
--- a/b2g/config/emulator-ics/sources.xml
+++ b/b2g/config/emulator-ics/sources.xml
@@ -14,17 +14,17 @@
   <!--original fetch url was git://github.com/apitrace/-->
   <remote fetch="https://git.mozilla.org/external/apitrace" name="apitrace"/>
   <default remote="caf" revision="refs/tags/android-4.0.4_r2.1" sync-j="4"/>
   <!-- Gonk specific things and forks -->
   <project name="platform_build" path="build" remote="b2g" revision="173b3104bfcbd23fc9dccd4b0035fc49aae3d444">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
   <project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
-  <project name="gaia.git" path="gaia" remote="mozillaorg" revision="b8051d370ddf4e5bd8e7d8a19fb9eeb5fd6ffb39"/>
+  <project name="gaia.git" path="gaia" remote="mozillaorg" revision="c39e15f631de80c69467fda0d4ea0bcda9e194ca"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="86cd7486d8e50eaac8ef6fe2f51f09d25194577b"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="platform_hardware_ril" path="hardware/ril" remote="b2g" revision="93f9ba577f68d772093987c2f1c0a4ae293e1802"/>
   <project name="platform_external_qemu" path="external/qemu" remote="b2g" revision="527d1c939ee57deb7192166e56e2a3fffa8cb087"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="ed2cf97a6c37a4bbd0bbbbffe06ec7136d8c79ff"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="34ea6163f9f0e0122fb0bb03607eccdca31ced7a"/>
   <!-- Stock Android things -->
   <project name="platform/abi/cpp" path="abi/cpp" revision="dd924f92906085b831bf1cbbc7484d3c043d613c"/>
--- a/b2g/config/emulator-jb/sources.xml
+++ b/b2g/config/emulator-jb/sources.xml
@@ -12,17 +12,17 @@
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="4efd19d199ae52656604f794c5a77518400220fd">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="b8051d370ddf4e5bd8e7d8a19fb9eeb5fd6ffb39"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="c39e15f631de80c69467fda0d4ea0bcda9e194ca"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="86cd7486d8e50eaac8ef6fe2f51f09d25194577b"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="ed2cf97a6c37a4bbd0bbbbffe06ec7136d8c79ff"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="40f5ce12859076b63307480ff2f0bbdf42bbf258"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
   <!-- Stock Android things -->
   <project groups="linux" name="platform/prebuilts/clang/linux-x86/3.1" path="prebuilts/clang/linux-x86/3.1" revision="5c45f43419d5582949284eee9cef0c43d866e03b"/>
   <project groups="linux" name="platform/prebuilts/clang/linux-x86/3.2" path="prebuilts/clang/linux-x86/3.2" revision="3748b4168e7bd8d46457d4b6786003bc6a5223ce"/>
--- a/b2g/config/emulator-kk/sources.xml
+++ b/b2g/config/emulator-kk/sources.xml
@@ -10,17 +10,17 @@
   <!--original fetch url was git://codeaurora.org/-->
   <remote fetch="https://git.mozilla.org/external/caf" name="caf"/>
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="ef937d1aca7c4cf89ecb5cc43ae8c21c2000a9db">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="b8051d370ddf4e5bd8e7d8a19fb9eeb5fd6ffb39"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="c39e15f631de80c69467fda0d4ea0bcda9e194ca"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="86cd7486d8e50eaac8ef6fe2f51f09d25194577b"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="ed2cf97a6c37a4bbd0bbbbffe06ec7136d8c79ff"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="40f5ce12859076b63307480ff2f0bbdf42bbf258"/>
--- a/b2g/config/emulator-l/sources.xml
+++ b/b2g/config/emulator-l/sources.xml
@@ -10,17 +10,17 @@
   <!--original fetch url was git://codeaurora.org/-->
   <remote fetch="https://git.mozilla.org/external/caf" name="caf"/>
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="52775e03a2d8532429dff579cb2cd56718e488c3">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="b8051d370ddf4e5bd8e7d8a19fb9eeb5fd6ffb39"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="c39e15f631de80c69467fda0d4ea0bcda9e194ca"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="86cd7486d8e50eaac8ef6fe2f51f09d25194577b"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="ed2cf97a6c37a4bbd0bbbbffe06ec7136d8c79ff"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="40f5ce12859076b63307480ff2f0bbdf42bbf258"/>
--- a/b2g/config/emulator/sources.xml
+++ b/b2g/config/emulator/sources.xml
@@ -14,17 +14,17 @@
   <!--original fetch url was git://github.com/apitrace/-->
   <remote fetch="https://git.mozilla.org/external/apitrace" name="apitrace"/>
   <default remote="caf" revision="refs/tags/android-4.0.4_r2.1" sync-j="4"/>
   <!-- Gonk specific things and forks -->
   <project name="platform_build" path="build" remote="b2g" revision="173b3104bfcbd23fc9dccd4b0035fc49aae3d444">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
   <project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
-  <project name="gaia.git" path="gaia" remote="mozillaorg" revision="b8051d370ddf4e5bd8e7d8a19fb9eeb5fd6ffb39"/>
+  <project name="gaia.git" path="gaia" remote="mozillaorg" revision="c39e15f631de80c69467fda0d4ea0bcda9e194ca"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="86cd7486d8e50eaac8ef6fe2f51f09d25194577b"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="platform_hardware_ril" path="hardware/ril" remote="b2g" revision="93f9ba577f68d772093987c2f1c0a4ae293e1802"/>
   <project name="platform_external_qemu" path="external/qemu" remote="b2g" revision="527d1c939ee57deb7192166e56e2a3fffa8cb087"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="ed2cf97a6c37a4bbd0bbbbffe06ec7136d8c79ff"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="34ea6163f9f0e0122fb0bb03607eccdca31ced7a"/>
   <!-- Stock Android things -->
   <project name="platform/abi/cpp" path="abi/cpp" revision="dd924f92906085b831bf1cbbc7484d3c043d613c"/>
--- a/b2g/config/flame-kk/sources.xml
+++ b/b2g/config/flame-kk/sources.xml
@@ -10,17 +10,17 @@
   <!--original fetch url was git://codeaurora.org/-->
   <remote fetch="https://git.mozilla.org/external/caf" name="caf"/>
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="ef937d1aca7c4cf89ecb5cc43ae8c21c2000a9db">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="b8051d370ddf4e5bd8e7d8a19fb9eeb5fd6ffb39"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="c39e15f631de80c69467fda0d4ea0bcda9e194ca"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="86cd7486d8e50eaac8ef6fe2f51f09d25194577b"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="ed2cf97a6c37a4bbd0bbbbffe06ec7136d8c79ff"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="40f5ce12859076b63307480ff2f0bbdf42bbf258"/>
--- a/b2g/config/flame/sources.xml
+++ b/b2g/config/flame/sources.xml
@@ -12,17 +12,17 @@
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="4efd19d199ae52656604f794c5a77518400220fd">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="b8051d370ddf4e5bd8e7d8a19fb9eeb5fd6ffb39"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="c39e15f631de80c69467fda0d4ea0bcda9e194ca"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="86cd7486d8e50eaac8ef6fe2f51f09d25194577b"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="ed2cf97a6c37a4bbd0bbbbffe06ec7136d8c79ff"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="40f5ce12859076b63307480ff2f0bbdf42bbf258"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
   <!-- Stock Android things -->
   <project groups="linux" name="platform/prebuilts/clang/linux-x86/3.1" path="prebuilts/clang/linux-x86/3.1" revision="e95b4ce22c825da44d14299e1190ea39a5260bde"/>
   <project groups="linux" name="platform/prebuilts/clang/linux-x86/3.2" path="prebuilts/clang/linux-x86/3.2" revision="471afab478649078ad7c75ec6b252481a59e19b8"/>
--- a/b2g/config/gaia.json
+++ b/b2g/config/gaia.json
@@ -1,9 +1,9 @@
 {
     "git": {
-        "git_revision": "b8051d370ddf4e5bd8e7d8a19fb9eeb5fd6ffb39", 
+        "git_revision": "c39e15f631de80c69467fda0d4ea0bcda9e194ca", 
         "remote": "https://git.mozilla.org/releases/gaia.git", 
         "branch": ""
     }, 
-    "revision": "18a7681ac7c78cd21cc22de6ea1746fcab1c2f62", 
+    "revision": "a7732a117f9499b15cc27c022a11cd75ef71f477", 
     "repo_path": "integration/gaia-central"
 }
--- a/b2g/config/nexus-4/sources.xml
+++ b/b2g/config/nexus-4/sources.xml
@@ -12,17 +12,17 @@
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="4efd19d199ae52656604f794c5a77518400220fd">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="b8051d370ddf4e5bd8e7d8a19fb9eeb5fd6ffb39"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="c39e15f631de80c69467fda0d4ea0bcda9e194ca"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="86cd7486d8e50eaac8ef6fe2f51f09d25194577b"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="ed2cf97a6c37a4bbd0bbbbffe06ec7136d8c79ff"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="40f5ce12859076b63307480ff2f0bbdf42bbf258"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
   <!-- Stock Android things -->
   <project groups="linux" name="platform/prebuilts/clang/linux-x86/3.1" path="prebuilts/clang/linux-x86/3.1" revision="5c45f43419d5582949284eee9cef0c43d866e03b"/>
   <project groups="linux" name="platform/prebuilts/clang/linux-x86/3.2" path="prebuilts/clang/linux-x86/3.2" revision="3748b4168e7bd8d46457d4b6786003bc6a5223ce"/>
--- a/b2g/config/nexus-5-l/sources.xml
+++ b/b2g/config/nexus-5-l/sources.xml
@@ -10,17 +10,17 @@
   <!--original fetch url was git://codeaurora.org/-->
   <remote fetch="https://git.mozilla.org/external/caf" name="caf"/>
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="52775e03a2d8532429dff579cb2cd56718e488c3">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="b8051d370ddf4e5bd8e7d8a19fb9eeb5fd6ffb39"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="c39e15f631de80c69467fda0d4ea0bcda9e194ca"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="86cd7486d8e50eaac8ef6fe2f51f09d25194577b"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="ed2cf97a6c37a4bbd0bbbbffe06ec7136d8c79ff"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="40f5ce12859076b63307480ff2f0bbdf42bbf258"/>
--- a/b2g/installer/package-manifest.in
+++ b/b2g/installer/package-manifest.in
@@ -173,16 +173,17 @@
 @RESPATH@/components/dom_audiochannel.xpt
 @RESPATH@/components/dom_base.xpt
 @RESPATH@/components/dom_system.xpt
 #ifdef MOZ_WIDGET_GONK
 @RESPATH@/components/dom_wifi.xpt
 @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
 #ifdef MOZ_B2G_BT
 @RESPATH@/components/dom_bluetooth.xpt
 #endif
 #ifdef MOZ_B2G_CAMERA
 @BINPATH@/components/dom_camera.xpt
@@ -212,17 +213,16 @@
 @RESPATH@/components/dom_power.xpt
 @RESPATH@/components/dom_quota.xpt
 @RESPATH@/components/dom_range.xpt
 @RESPATH@/components/dom_security.xpt
 @RESPATH@/components/dom_settings.xpt
 @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
 @RESPATH@/components/dom_telephony.xpt
 @RESPATH@/components/dom_threads.xpt
 @RESPATH@/components/dom_traversal.xpt
 @RESPATH@/components/dom_tv.xpt
 @RESPATH@/components/dom_views.xpt
@@ -478,18 +478,16 @@
 @RESPATH@/components/ResourceStatsManager.js
 @RESPATH@/components/ResourceStatsManager.manifest
 #endif // MOZ_WIDGET_GONK
 
 ; RIL
 #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
 @RESPATH@/components/MobileMessageDatabaseService.manifest
 #ifndef DISABLE_MOZ_RIL_GEOLOC
 @RESPATH@/components/MobileConnectionService.js
 @RESPATH@/components/MobileConnectionService.manifest
 @RESPATH@/components/RadioInterfaceLayer.js
--- a/browser/components/test/browser_polaris_prefs.js
+++ b/browser/components/test/browser_polaris_prefs.js
@@ -36,16 +36,25 @@ add_task(function* test_default_values()
   Assert.ok(!Services.prefs.getBoolPref(PREF_TPUI), PREF_TPUI + "is disabled by default.");
 });
 
 add_task(function* test_changing_pref_changes_tracking() {
   if (!isNightly()) {
     ok(true, "Skipping test, not Nightly")
     return;
   }
+
+  // Register a cleanup function for all the prefs affected by this entire test file.
+  registerCleanupFunction(function () {
+    Services.prefs.clearUserPref(POLARIS_ENABLED);
+    for (let pref of prefs) {
+      Services.prefs.clearUserPref(pref);
+    }
+  });
+
   function* testPref(pref) {
     Services.prefs.setBoolPref(POLARIS_ENABLED, true);
     yield assertPref(pref, true);
     Services.prefs.setBoolPref(POLARIS_ENABLED, false);
     // We don't clear the DNT pref if Polaris is disabled.
     if (pref != PREF_DNT) {
       yield assertPref(pref, false);
     } else {
--- a/browser/devtools/webconsole/test/browser.ini
+++ b/browser/devtools/webconsole/test/browser.ini
@@ -76,16 +76,17 @@ support-files =
   test-console-replaced-api.html
   test-console.html
   test-console-table.html
   test-console-output-02.html
   test-console-output-03.html
   test-console-output-04.html
   test-console-output-dom-elements.html
   test-console-output-events.html
+  test-console-output-regexp.html
   test-console-column.html
   test-consoleiframes.html
   test-certificate-messages.html
   test-data.json
   test-data.json^headers^
   test-duplicate-error.html
   test-encoding-ISO-8859-1.html
   test-error.html
@@ -364,16 +365,17 @@ skip-if = e10s # Bug 1042253 - webconsol
 [browser_webconsole_output_06.js]
 [browser_webconsole_output_dom_elements_01.js]
 [browser_webconsole_output_dom_elements_02.js]
 skip-if = e10s # Bug 1042253 - webconsole e10s tests (Linux debug timeout)
 [browser_webconsole_output_dom_elements_03.js]
 [browser_webconsole_output_dom_elements_04.js]
 skip-if = e10s # Bug 1042253 - webconsole e10s tests (Linux debug timeout)
 [browser_webconsole_output_events.js]
+[browser_webconsole_output_regexp.js]
 [browser_webconsole_output_table.js]
 [browser_console_variables_view_highlighter.js]
 [browser_webconsole_start_netmon_first.js]
 [browser_webconsole_console_trace_duplicates.js]
 [browser_webconsole_cd_iframe.js]
 [browser_webconsole_autocomplete_crossdomain_iframe.js]
 [browser_webconsole_console_custom_styles.js]
 [browser_webconsole_console_api_stackframe.js]
new file mode 100644
--- /dev/null
+++ b/browser/devtools/webconsole/test/browser_webconsole_output_regexp.js
@@ -0,0 +1,34 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+// Test the webconsole output for various types of objects.
+
+const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console-output-regexp.html";
+
+let dateNow = Date.now();
+
+let inputTests = [
+  // 0
+  {
+    input: "/foo/igym",
+    output: "/foo/gimy",
+    printOutput: "Error: source called",
+    inspectable: true,
+  },
+];
+
+function test() {
+  requestLongerTimeout(2);
+  Task.spawn(function*() {
+    let {tab} = yield loadTab(TEST_URI);
+    let hud = yield openConsole(tab);
+    return checkOutputForInputs(hud, inputTests);
+  }).then(finishUp);
+}
+
+function finishUp() {
+  inputTests = dateNow = null;
+  finishTest();
+}
new file mode 100644
--- /dev/null
+++ b/browser/devtools/webconsole/test/test-console-output-regexp.html
@@ -0,0 +1,23 @@
+<!DOCTYPE HTML>
+<html dir="ltr" lang="en-US">
+<head>
+  <meta charset="utf-8">
+  <title>Test the web console output for RegExp</title>
+  <!--
+  - Any copyright is dedicated to the Public Domain.
+  - http://creativecommons.org/publicdomain/zero/1.0/
+  -->
+</head>
+<body>
+  <p>hello world!</p>
+
+  <script type="text/javascript">
+Object.defineProperty(RegExp.prototype, "flags", {
+  get: function() { throw Error("flags called"); }
+})
+Object.defineProperty(RegExp.prototype, "source", {
+  get: function() { throw Error("source called"); },
+})
+  </script>
+</body>
+</html>
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -210,17 +210,16 @@
 @RESPATH@/components/dom_css.xpt
 @RESPATH@/components/dom_devicestorage.xpt
 @RESPATH@/components/dom_events.xpt
 @RESPATH@/components/dom_geolocation.xpt
 @RESPATH@/components/dom_media.xpt
 @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
 @RESPATH@/components/dom_quota.xpt
 @RESPATH@/components/dom_range.xpt
 @RESPATH@/components/dom_security.xpt
 @RESPATH@/components/dom_settings.xpt
 @RESPATH@/components/dom_permissionsettings.xpt
--- a/dom/apps/OperatorApps.jsm
+++ b/dom/apps/OperatorApps.jsm
@@ -16,19 +16,19 @@ Cu.import("resource://gre/modules/Webapp
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/osfile.jsm");
 Cu.import("resource://gre/modules/AppsUtils.jsm");
 Cu.import("resource://gre/modules/Task.jsm");
 
 let Path = OS.Path;
 
 #ifdef MOZ_B2G_RIL
-XPCOMUtils.defineLazyServiceGetter(this, "gIccService",
-                                   "@mozilla.org/icc/iccservice;1",
-                                   "nsIIccService");
+XPCOMUtils.defineLazyServiceGetter(this, "iccProvider",
+                                   "@mozilla.org/ril/content-helper;1",
+                                   "nsIIccProvider");
 #endif
 
 function debug(aMsg) {
   //dump("-*-*- OperatorApps.jsm : " + aMsg + "\n");
 }
 
 // Single Variant source dir will be set in PREF_SINGLE_VARIANT_DIR
 // preference.
@@ -64,28 +64,27 @@ let iccListener = {
   notifyStkCommand: function() {},
 
   notifyStkSessionEnd: function() {},
 
   notifyCardStateChanged: function() {},
 
   notifyIccInfoChanged: function() {
     // TODO: Bug 927709 - OperatorApps for multi-sim
-    // In Multi-sim, there is more than one client in IccService. Each
-    // client represents a icc handle. To maintain the backward compatibility
+    // In Multi-sim, there is more than one client in iccProvider. Each
+    // client represents a icc 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 927709, if needed.
     let clientId = 0;
-    let icc = gIccService.getIccByServiceId(clientId);
-    let iccInfo = icc && icc.iccInfo;
+    let iccInfo = iccProvider.getIccInfo(clientId);
     if (iccInfo && iccInfo.mcc && iccInfo.mnc) {
       let mcc = iccInfo.mcc;
       let mnc = iccInfo.mnc;
       debug("******* iccListener cardIccInfo MCC-MNC: " + mcc + "-" + mnc);
-      icc.unregisterListener(this);
+      iccProvider.unregisterIccMsg(clientId, this);
       OperatorAppsRegistry._installOperatorApps(mcc, mnc);
 
       debug("Broadcast message first-run-with-sim");
       let messenger = Cc["@mozilla.org/system-message-internal;1"]
                         .getService(Ci.nsISystemMessagesInternal);
       messenger.broadcastMessage("first-run-with-sim", { mcc: mcc,
                                                          mnc: mnc });
     }
@@ -101,41 +100,40 @@ this.OperatorAppsRegistry = {
     debug("init");
 #ifdef MOZ_B2G_RIL
     if (isFirstRunWithSIM()) {
       debug("First Run with SIM");
       Task.spawn(function() {
         try {
           yield this._initializeSourceDir();
           // TODO: Bug 927709 - OperatorApps for multi-sim
-          // In Multi-sim, there is more than one client in IccService. Each
-          // client represents a icc handle. To maintain the backward
+          // In Multi-sim, there is more than one client in iccProvider. Each
+          // client represents a icc 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 927709, if
           // needed.
           let clientId = 0;
-          let icc = gIccService.getIccByServiceId(clientId);
-          let iccInfo = icc && icc.iccInfo;
+          let iccInfo = iccProvider.getIccInfo(clientId);
           let mcc = 0;
           let mnc = 0;
           if (iccInfo && iccInfo.mcc) {
             mcc = iccInfo.mcc;
           }
           if (iccInfo && iccInfo.mnc) {
             mnc = iccInfo.mnc;
           }
           if (mcc && mnc) {
             this._installOperatorApps(mcc, mnc);
             let messenger = Cc["@mozilla.org/system-message-internal;1"]
                               .getService(Ci.nsISystemMessagesInternal);
             messenger.broadcastMessage("first-run-with-sim", { mcc: mcc,
                                                                mnc: mnc });
 
           } else {
-            icc.registerListener(iccListener);
+            iccProvider.registerIccMsg(clientId, iccListener);
           }
         } catch (e) {
           debug("Error Initializing OperatorApps. " + e);
         }
       }.bind(this));
     } else {
       debug("No First Run with SIM");
     }
--- a/dom/base/Console.cpp
+++ b/dom/base/Console.cpp
@@ -1152,18 +1152,18 @@ Console::ProcessCallData(ConsoleCallData
   event.mInnerID.Construct();
 
   MOZ_ASSERT(aData->mIDType != ConsoleCallData::eUnknown);
   if (aData->mIDType == ConsoleCallData::eString) {
     event.mID.Value().SetAsString() = aData->mOuterIDString;
     event.mInnerID.Value().SetAsString() = aData->mInnerIDString;
   } else {
     MOZ_ASSERT(aData->mIDType == ConsoleCallData::eNumber);
-    event.mID.Value().SetAsUnsignedLong() = aData->mOuterIDNumber;
-    event.mInnerID.Value().SetAsUnsignedLong() = aData->mInnerIDNumber;
+    event.mID.Value().SetAsUnsignedLongLong() = aData->mOuterIDNumber;
+    event.mInnerID.Value().SetAsUnsignedLongLong() = aData->mInnerIDNumber;
   }
 
   event.mLevel = aData->mMethodString;
   event.mFilename = frame.mFilename;
   event.mLineNumber = frame.mLineNumber;
   event.mColumnNumber = frame.mColumnNumber;
   event.mFunctionName = frame.mFunctionName;
   event.mTimeStamp = aData->mTimeStamp;
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -31,17 +31,16 @@
 #include "nsUnicharUtils.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Telemetry.h"
 #include "BatteryManager.h"
 #include "mozilla/dom/PowerManager.h"
 #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"
 #include "mozilla/dom/Voicemail.h"
 #include "mozilla/dom/TVManager.h"
 #include "mozilla/dom/VRDevice.h"
 #include "mozilla/Hal.h"
 #include "nsISiteSpecificUserAgent.h"
@@ -49,16 +48,17 @@
 #include "mozilla/StaticPtr.h"
 #include "Connection.h"
 #include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
 #include "nsGlobalWindow.h"
 #ifdef MOZ_B2G
 #include "nsIMobileIdentityService.h"
 #endif
 #ifdef MOZ_B2G_RIL
+#include "mozilla/dom/IccManager.h"
 #include "mozilla/dom/MobileConnectionArray.h"
 #endif
 #include "nsIIdleObserver.h"
 #include "nsIPermissionManager.h"
 #include "nsMimeTypes.h"
 #include "nsNetUtil.h"
 #include "nsIHttpChannel.h"
 #include "nsIHttpChannelInternal.h"
@@ -172,24 +172,24 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPlugins)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMimeTypes)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGeolocation)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNotification)
   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)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTVManager)
   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)
 #endif
 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAudioChannelManager)
 #endif
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCameraManager)
@@ -245,21 +245,16 @@ Navigator::Invalidate()
     mPowerManager->Shutdown();
     mPowerManager = nullptr;
   }
 
   if (mCellBroadcast) {
     mCellBroadcast = nullptr;
   }
 
-  if (mIccManager) {
-    mIccManager->Shutdown();
-    mIccManager = nullptr;
-  }
-
   if (mMobileMessageManager) {
     mMobileMessageManager->Shutdown();
     mMobileMessageManager = nullptr;
   }
 
   if (mTelephony) {
     mTelephony = nullptr;
   }
@@ -277,16 +272,21 @@ Navigator::Invalidate()
     mConnection->Shutdown();
     mConnection = nullptr;
   }
 
 #ifdef MOZ_B2G_RIL
   if (mMobileConnections) {
     mMobileConnections = nullptr;
   }
+
+  if (mIccManager) {
+    mIccManager->Shutdown();
+    mIccManager = nullptr;
+  }
 #endif
 
 #ifdef MOZ_B2G_BT
   if (mBluetooth) {
     mBluetooth = nullptr;
   }
 #endif
 
@@ -1702,31 +1702,34 @@ Navigator::GetMozVoicemail(ErrorResult& 
     }
 
     mVoicemail = Voicemail::Create(mWindow, aRv);
   }
 
   return mVoicemail;
 }
 
+#ifdef MOZ_B2G_RIL
+
 IccManager*
 Navigator::GetMozIccManager(ErrorResult& aRv)
 {
   if (!mIccManager) {
     if (!mWindow) {
       aRv.Throw(NS_ERROR_UNEXPECTED);
       return nullptr;
     }
     NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
 
     mIccManager = new IccManager(mWindow);
   }
 
   return mIccManager;
 }
+#endif // MOZ_B2G_RIL
 
 #ifdef MOZ_GAMEPAD
 void
 Navigator::GetGamepads(nsTArray<nsRefPtr<Gamepad> >& aGamepads,
                        ErrorResult& aRv)
 {
   if (!mWindow) {
     aRv.Throw(NS_ERROR_UNEXPECTED);
--- a/dom/base/Navigator.h
+++ b/dom/base/Navigator.h
@@ -39,16 +39,20 @@ class MediaDevices;
 struct MediaStreamConstraints;
 class WakeLock;
 class ArrayBufferViewOrBlobOrStringOrFormData;
 struct MobileIdOptions;
 class ServiceWorkerContainer;
 }
 }
 
+#ifdef MOZ_B2G_RIL
+class nsIDOMMozIccManager;
+#endif // MOZ_B2G_RIL
+
 //*****************************************************************************
 // Navigator: Script "navigator" object
 //*****************************************************************************
 
 namespace mozilla {
 namespace dom {
 
 namespace battery {
@@ -79,22 +83,22 @@ class Connection;
 
 #ifdef MOZ_B2G_BT
 namespace bluetooth {
 class BluetoothManager;
 } // namespace bluetooth
 #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;
 
 namespace time {
 class TimeManager;
 } // namespace time
 
@@ -215,17 +219,16 @@ public:
                                              ErrorResult& aRv);
   nsDOMDeviceStorage* GetDeviceStorage(const nsAString& aType,
                                        ErrorResult& aRv);
   void GetDeviceStorages(const nsAString& aType,
                          nsTArray<nsRefPtr<nsDOMDeviceStorage> >& aStores,
                          ErrorResult& aRv);
   DesktopNotificationCenter* GetMozNotification(ErrorResult& aRv);
   CellBroadcast* GetMozCellBroadcast(ErrorResult& aRv);
-  IccManager* GetMozIccManager(ErrorResult& aRv);
   MobileMessageManager* GetMozMobileMessage();
   Telephony* GetMozTelephony(ErrorResult& aRv);
   Voicemail* GetMozVoicemail(ErrorResult& aRv);
   TVManager* GetTv();
   network::Connection* GetConnection(ErrorResult& aRv);
   nsDOMCameraManager* GetMozCameras(ErrorResult& aRv);
   MediaDevices* GetMediaDevices(ErrorResult& aRv);
   void MozSetMessageHandler(const nsAString& aType,
@@ -235,16 +238,17 @@ public:
   void MozSetMessageHandlerPromise(Promise& aPromise, ErrorResult& aRv);
 
 #ifdef MOZ_B2G
   already_AddRefed<Promise> GetMobileIdAssertion(const MobileIdOptions& options,
                                                  ErrorResult& aRv);
 #endif
 #ifdef MOZ_B2G_RIL
   MobileConnectionArray* GetMozMobileConnections(ErrorResult& aRv);
+  IccManager* GetMozIccManager(ErrorResult& aRv);
 #endif // MOZ_B2G_RIL
 #ifdef MOZ_GAMEPAD
   void GetGamepads(nsTArray<nsRefPtr<Gamepad> >& aGamepads, ErrorResult& aRv);
 #endif // MOZ_GAMEPAD
   already_AddRefed<Promise> GetVRDevices(ErrorResult& aRv);
 #ifdef MOZ_B2G_FM
   FMRadio* GetMozFMRadio(ErrorResult& aRv);
 #endif
@@ -344,24 +348,24 @@ private:
   nsRefPtr<Geolocation> mGeolocation;
   nsRefPtr<DesktopNotificationCenter> mNotification;
   nsRefPtr<battery::BatteryManager> mBatteryManager;
 #ifdef MOZ_B2G_FM
   nsRefPtr<FMRadio> mFMRadio;
 #endif
   nsRefPtr<PowerManager> mPowerManager;
   nsRefPtr<CellBroadcast> mCellBroadcast;
-  nsRefPtr<IccManager> mIccManager;
   nsRefPtr<MobileMessageManager> mMobileMessageManager;
   nsRefPtr<Telephony> mTelephony;
   nsRefPtr<Voicemail> mVoicemail;
   nsRefPtr<TVManager> mTVManager;
   nsRefPtr<network::Connection> mConnection;
 #ifdef MOZ_B2G_RIL
   nsRefPtr<MobileConnectionArray> mMobileConnections;
+  nsRefPtr<IccManager> mIccManager;
 #endif
 #ifdef MOZ_B2G_BT
   nsRefPtr<bluetooth::BluetoothManager> mBluetooth;
 #endif
 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
   nsRefPtr<system::AudioChannelManager> mAudioChannelManager;
 #endif
   nsRefPtr<nsDOMCameraManager> mCameraManager;
--- a/dom/bluetooth/BluetoothRilListener.cpp
+++ b/dom/bluetooth/BluetoothRilListener.cpp
@@ -2,21 +2,22 @@
 /* vim: set ts=2 et sw=2 tw=80: */
 /* 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 "BluetoothRilListener.h"
 
 #include "BluetoothHfpManager.h"
-#include "nsIIccService.h"
+#include "nsIIccProvider.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"
 
 USING_BLUETOOTH_NAMESPACE
 
 /**
  *  IccListener
  */
@@ -54,29 +55,25 @@ IccListener::NotifyCardStateChanged()
   return NS_OK;
 }
 
 bool
 IccListener::Listen(bool aStart)
 {
   NS_ENSURE_TRUE(mOwner, false);
 
-  nsCOMPtr<nsIIccService> service =
-    do_GetService(ICC_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(service, false);
-
-  nsCOMPtr<nsIIcc> icc;
-  service->GetIccByServiceId(mOwner->mClientId, getter_AddRefs(icc));
-  NS_ENSURE_TRUE(icc, false);
+  nsCOMPtr<nsIIccProvider> provider =
+    do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
+  NS_ENSURE_TRUE(provider, false);
 
   nsresult rv;
   if (aStart) {
-    rv = icc->RegisterListener(this);
+    rv = provider->RegisterIccMsg(mOwner->mClientId, this);
   } else {
-    rv = icc->UnregisterListener(this);
+    rv = provider->UnregisterIccMsg(mOwner->mClientId, this);
   }
 
   return NS_SUCCEEDED(rv);
 }
 
 void
 IccListener::SetOwner(BluetoothRilListener *aOwner)
 {
--- a/dom/bluetooth/BluetoothRilListener.h
+++ b/dom/bluetooth/BluetoothRilListener.h
@@ -6,17 +6,17 @@
 
 #ifndef mozilla_dom_bluetooth_bluetoothrillistener_h__
 #define mozilla_dom_bluetooth_bluetoothrillistener_h__
 
 #include "BluetoothCommon.h"
 
 #include "nsAutoPtr.h"
 
-#include "nsIIccService.h"
+#include "nsIIccProvider.h"
 #include "nsIMobileConnectionService.h"
 #include "nsITelephonyCallInfo.h"
 #include "nsITelephonyService.h"
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 class BluetoothRilListener;
 
--- a/dom/bluetooth/bluedroid/BluetoothA2dpHALInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothA2dpHALInterface.cpp
@@ -21,17 +21,17 @@ typedef
 static nsresult
 DispatchBluetoothA2dpHALResult(
   BluetoothA2dpResultHandler* aRes,
   void (BluetoothA2dpResultHandler::*aMethod)(),
   BluetoothStatus aStatus)
 {
   MOZ_ASSERT(aRes);
 
-  nsRunnable* runnable;
+  nsRefPtr<nsRunnable> runnable;
 
   if (aStatus == STATUS_SUCCESS) {
     runnable = new BluetoothA2dpHALResultRunnable(aRes, aMethod);
   } else {
     runnable = new BluetoothA2dpHALErrorRunnable(aRes,
       &BluetoothA2dpResultHandler::OnError, aStatus);
   }
   nsresult rv = NS_DispatchToMainThread(runnable);
--- a/dom/bluetooth/bluedroid/BluetoothAvrcpHALInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothAvrcpHALInterface.cpp
@@ -21,17 +21,17 @@ typedef
 static nsresult
 DispatchBluetoothAvrcpHALResult(
   BluetoothAvrcpResultHandler* aRes,
   void (BluetoothAvrcpResultHandler::*aMethod)(),
   BluetoothStatus aStatus)
 {
   MOZ_ASSERT(aRes);
 
-  nsRunnable* runnable;
+  nsRefPtr<nsRunnable> runnable;
 
   if (aStatus == STATUS_SUCCESS) {
     runnable = new BluetoothAvrcpHALResultRunnable(aRes, aMethod);
   } else {
     runnable = new BluetoothAvrcpHALErrorRunnable(aRes,
       &BluetoothAvrcpResultHandler::OnError, aStatus);
   }
   nsresult rv = NS_DispatchToMainThread(runnable);
--- a/dom/bluetooth/bluedroid/BluetoothHALInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothHALInterface.cpp
@@ -74,17 +74,17 @@ typedef
 
 static nsresult
 DispatchBluetoothHALResult(BluetoothResultHandler* aRes,
                            void (BluetoothResultHandler::*aMethod)(),
                            BluetoothStatus aStatus)
 {
   MOZ_ASSERT(aRes);
 
-  nsRunnable* runnable;
+  nsRefPtr<nsRunnable> runnable;
 
   if (aStatus == STATUS_SUCCESS) {
     runnable = new BluetoothHALResultRunnable(aRes, aMethod);
   } else {
     runnable = new BluetoothHALErrorRunnable(
       aRes, &BluetoothResultHandler::OnError, aStatus);
   }
   nsresult rv = NS_DispatchToMainThread(runnable);
--- a/dom/bluetooth/bluedroid/BluetoothHandsfreeHALInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothHandsfreeHALInterface.cpp
@@ -21,17 +21,17 @@ typedef
 static nsresult
 DispatchBluetoothHandsfreeHALResult(
   BluetoothHandsfreeResultHandler* aRes,
   void (BluetoothHandsfreeResultHandler::*aMethod)(),
   BluetoothStatus aStatus)
 {
   MOZ_ASSERT(aRes);
 
-  nsRunnable* runnable;
+  nsRefPtr<nsRunnable> runnable;
 
   if (aStatus == STATUS_SUCCESS) {
     runnable = new BluetoothHandsfreeHALResultRunnable(aRes, aMethod);
   } else {
     runnable = new BluetoothHandsfreeHALErrorRunnable(aRes,
       &BluetoothHandsfreeResultHandler::OnError, aStatus);
   }
   nsresult rv = NS_DispatchToMainThread(runnable);
--- a/dom/bluetooth/bluedroid/BluetoothSocketHALInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothSocketHALInterface.cpp
@@ -32,17 +32,17 @@ typedef
 static nsresult
 DispatchBluetoothSocketHALResult(
   BluetoothSocketResultHandler* aRes,
   void (BluetoothSocketResultHandler::*aMethod)(int), int aArg,
   BluetoothStatus aStatus)
 {
   MOZ_ASSERT(aRes);
 
-  nsRunnable* runnable;
+  nsRefPtr<nsRunnable> runnable;
 
   if (aStatus == STATUS_SUCCESS) {
     runnable = new BluetoothSocketHALIntResultRunnable(aRes, aMethod, aArg);
   } else {
     runnable = new BluetoothSocketHALErrorRunnable(aRes,
       &BluetoothSocketResultHandler::OnError, aStatus);
   }
   nsresult rv = NS_DispatchToMainThread(runnable);
@@ -55,17 +55,17 @@ DispatchBluetoothSocketHALResult(
 static nsresult
 DispatchBluetoothSocketHALResult(
   BluetoothSocketResultHandler* aRes,
   void (BluetoothSocketResultHandler::*aMethod)(int, const nsAString&, int),
   int aArg1, const nsAString& aArg2, int aArg3, BluetoothStatus aStatus)
 {
   MOZ_ASSERT(aRes);
 
-  nsRunnable* runnable;
+  nsRefPtr<nsRunnable> runnable;
 
   if (aStatus == STATUS_SUCCESS) {
     runnable = new BluetoothSocketHALIntStringIntResultRunnable(
       aRes, aMethod, aArg1, aArg2, aArg3);
   } else {
     runnable = new BluetoothSocketHALErrorRunnable(aRes,
       &BluetoothSocketResultHandler::OnError, aStatus);
   }
--- a/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp
+++ b/dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp
@@ -12,23 +12,24 @@
 
 #include "jsapi.h"
 #include "mozilla/dom/bluetooth/BluetoothTypes.h"
 #include "mozilla/Services.h"
 #include "mozilla/StaticPtr.h"
 #include "nsContentUtils.h"
 #include "nsIAudioManager.h"
 #include "nsIIccInfo.h"
-#include "nsIIccService.h"
+#include "nsIIccProvider.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"
 #include "mozilla/dom/SettingChangeNotificationBinding.h"
 
 #define MOZSETTINGS_CHANGED_ID               "mozsettings-changed"
 #define AUDIO_VOLUME_BT_SCO_ID               "audio.volume.bt_sco"
 
@@ -719,26 +720,22 @@ BluetoothHfpManager::HandleVoiceConnecti
     BT_WARNING("The operator name was longer than 16 characters. We cut it.");
     mOperatorName.Left(mOperatorName, 16);
   }
 }
 
 void
 BluetoothHfpManager::HandleIccInfoChanged(uint32_t aClientId)
 {
-  nsCOMPtr<nsIIccService> service =
-    do_GetService(ICC_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE_VOID(service);
-
-  nsCOMPtr<nsIIcc> icc;
-  service->GetIccByServiceId(aClientId, getter_AddRefs(icc));
+  nsCOMPtr<nsIIccProvider> icc =
+    do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
   NS_ENSURE_TRUE_VOID(icc);
 
   nsCOMPtr<nsIIccInfo> iccInfo;
-  icc->GetIccInfo(getter_AddRefs(iccInfo));
+  icc->GetIccInfo(aClientId, getter_AddRefs(iccInfo));
   NS_ENSURE_TRUE_VOID(iccInfo);
 
   nsCOMPtr<nsIGsmIccInfo> gsmIccInfo = do_QueryInterface(iccInfo);
   NS_ENSURE_TRUE_VOID(gsmIccInfo);
   gsmIccInfo->GetMsisdn(mMsisdn);
 }
 
 void
--- a/dom/bluetooth/bluez/BluetoothHfpManager.cpp
+++ b/dom/bluetooth/bluez/BluetoothHfpManager.cpp
@@ -23,21 +23,22 @@
 #include "nsIObserverService.h"
 #include "nsISettingsService.h"
 #include "nsServiceManagerUtils.h"
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/SettingChangeNotificationBinding.h"
 
 #ifdef MOZ_B2G_RIL
 #include "nsIIccInfo.h"
-#include "nsIIccService.h"
+#include "nsIIccProvider.h"
 #include "nsIMobileConnectionInfo.h"
 #include "nsIMobileConnectionService.h"
 #include "nsIMobileNetworkInfo.h"
 #include "nsITelephonyService.h"
+#include "nsRadioInterfaceLayer.h"
 #endif
 
 /**
  * BRSF bitmask of AG supported features. See 4.34.1 "Bluetooth Defined AT
  * Capabilities" in Bluetooth hands-free profile 1.6
  */
 #define BRSF_BIT_THREE_WAY_CALLING         1
 #define BSRF_BIT_EC_NR_FUNCTION            (1 << 1)
@@ -658,26 +659,22 @@ BluetoothHfpManager::HandleVoiceConnecti
     BT_WARNING("The operator name was longer than 16 characters. We cut it.");
     mOperatorName.Left(mOperatorName, 16);
   }
 }
 
 void
 BluetoothHfpManager::HandleIccInfoChanged(uint32_t aClientId)
 {
-  nsCOMPtr<nsIIccService> service =
-    do_GetService(ICC_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE_VOID(service);
-
-  nsCOMPtr<nsIIcc> icc;
-  service->GetIccByServiceId(aClientId, getter_AddRefs(icc));
+  nsCOMPtr<nsIIccProvider> icc =
+    do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
   NS_ENSURE_TRUE_VOID(icc);
 
   nsCOMPtr<nsIIccInfo> iccInfo;
-  icc->GetIccInfo(getter_AddRefs(iccInfo));
+  icc->GetIccInfo(aClientId, getter_AddRefs(iccInfo));
   NS_ENSURE_TRUE_VOID(iccInfo);
 
   nsCOMPtr<nsIGsmIccInfo> gsmIccInfo = do_QueryInterface(iccInfo);
   NS_ENSURE_TRUE_VOID(gsmIccInfo);
   gsmIccInfo->GetMsisdn(mMsisdn);
 }
 #endif // MOZ_B2G_RIL
 
--- a/dom/bluetooth2/BluetoothRilListener.cpp
+++ b/dom/bluetooth2/BluetoothRilListener.cpp
@@ -2,20 +2,21 @@
 /* vim: set ts=2 et sw=2 tw=80: */
 /* 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 "BluetoothRilListener.h"
 
 #include "BluetoothHfpManager.h"
-#include "nsIIccService.h"
+#include "nsIIccProvider.h"
 #include "nsIMobileConnectionInfo.h"
 #include "nsIMobileConnectionService.h"
 #include "nsITelephonyService.h"
+#include "nsRadioInterfaceLayer.h" // For NS_RILCONTENTHELPER_CONTRACTID.
 #include "nsServiceManagerUtils.h"
 #include "nsString.h"
 
 USING_BLUETOOTH_NAMESPACE
 
 /**
  *  IccListener
  */
@@ -53,29 +54,25 @@ IccListener::NotifyCardStateChanged()
   return NS_OK;
 }
 
 bool
 IccListener::Listen(bool aStart)
 {
   NS_ENSURE_TRUE(mOwner, false);
 
-  nsCOMPtr<nsIIccService> service =
-    do_GetService(ICC_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(service, false);
-
-  nsCOMPtr<nsIIcc> icc;
-  service->GetIccByServiceId(mOwner->mClientId, getter_AddRefs(icc));
-  NS_ENSURE_TRUE(icc, false);
+  nsCOMPtr<nsIIccProvider> provider =
+    do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
+  NS_ENSURE_TRUE(provider, false);
 
   nsresult rv;
   if (aStart) {
-    rv = icc->RegisterListener(this);
+    rv = provider->RegisterIccMsg(mOwner->mClientId, this);
   } else {
-    rv = icc->UnregisterListener(this);
+    rv = provider->UnregisterIccMsg(mOwner->mClientId, this);
   }
 
   return NS_SUCCEEDED(rv);
 }
 
 void
 IccListener::SetOwner(BluetoothRilListener *aOwner)
 {
--- a/dom/bluetooth2/BluetoothRilListener.h
+++ b/dom/bluetooth2/BluetoothRilListener.h
@@ -6,17 +6,17 @@
 
 #ifndef mozilla_dom_bluetooth_bluetoothrillistener_h__
 #define mozilla_dom_bluetooth_bluetoothrillistener_h__
 
 #include "BluetoothCommon.h"
 
 #include "nsAutoPtr.h"
 
-#include "nsIIccService.h"
+#include "nsIIccProvider.h"
 #include "nsIMobileConnectionService.h"
 #include "nsITelephonyCallInfo.h"
 #include "nsITelephonyService.h"
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 class BluetoothRilListener;
 
--- a/dom/bluetooth2/bluedroid/hfp/BluetoothHfpManager.cpp
+++ b/dom/bluetooth2/bluedroid/hfp/BluetoothHfpManager.cpp
@@ -12,23 +12,24 @@
 
 #include "jsapi.h"
 #include "mozilla/dom/bluetooth/BluetoothTypes.h"
 #include "mozilla/Services.h"
 #include "mozilla/StaticPtr.h"
 #include "nsContentUtils.h"
 #include "nsIAudioManager.h"
 #include "nsIIccInfo.h"
-#include "nsIIccService.h"
+#include "nsIIccProvider.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"
 #include "mozilla/dom/SettingChangeNotificationBinding.h"
 
 #define MOZSETTINGS_CHANGED_ID               "mozsettings-changed"
 #define AUDIO_VOLUME_BT_SCO_ID               "audio.volume.bt_sco"
 
@@ -704,26 +705,22 @@ BluetoothHfpManager::HandleVoiceConnecti
     BT_WARNING("The operator name was longer than 16 characters. We cut it.");
     mOperatorName.Left(mOperatorName, 16);
   }
 }
 
 void
 BluetoothHfpManager::HandleIccInfoChanged(uint32_t aClientId)
 {
-  nsCOMPtr<nsIIccService> service =
-    do_GetService(ICC_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE_VOID(service);
-
-  nsCOMPtr<nsIIcc> icc;
-  service->GetIccByServiceId(aClientId, getter_AddRefs(icc));
+  nsCOMPtr<nsIIccProvider> icc =
+    do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
   NS_ENSURE_TRUE_VOID(icc);
 
   nsCOMPtr<nsIIccInfo> iccInfo;
-  icc->GetIccInfo(getter_AddRefs(iccInfo));
+  icc->GetIccInfo(aClientId, getter_AddRefs(iccInfo));
   NS_ENSURE_TRUE_VOID(iccInfo);
 
   nsCOMPtr<nsIGsmIccInfo> gsmIccInfo = do_QueryInterface(iccInfo);
   NS_ENSURE_TRUE_VOID(gsmIccInfo);
   gsmIccInfo->GetMsisdn(mMsisdn);
 }
 
 void
--- a/dom/bluetooth2/bluez/BluetoothHfpManager.cpp
+++ b/dom/bluetooth2/bluez/BluetoothHfpManager.cpp
@@ -23,21 +23,22 @@
 #include "nsIObserverService.h"
 #include "nsISettingsService.h"
 #include "nsServiceManagerUtils.h"
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/SettingChangeNotificationBinding.h"
 
 #ifdef MOZ_B2G_RIL
 #include "nsIIccInfo.h"
-#include "nsIIccService.h"
+#include "nsIIccProvider.h"
 #include "nsIMobileConnectionInfo.h"
 #include "nsIMobileConnectionService.h"
 #include "nsIMobileNetworkInfo.h"
 #include "nsITelephonyService.h"
+#include "nsRadioInterfaceLayer.h"
 #endif
 
 /**
  * BRSF bitmask of AG supported features. See 4.34.1 "Bluetooth Defined AT
  * Capabilities" in Bluetooth hands-free profile 1.6
  */
 #define BRSF_BIT_THREE_WAY_CALLING         1
 #define BSRF_BIT_EC_NR_FUNCTION            (1 << 1)
@@ -658,26 +659,22 @@ BluetoothHfpManager::HandleVoiceConnecti
     BT_WARNING("The operator name was longer than 16 characters. We cut it.");
     mOperatorName.Left(mOperatorName, 16);
   }
 }
 
 void
 BluetoothHfpManager::HandleIccInfoChanged(uint32_t aClientId)
 {
-  nsCOMPtr<nsIIccService> service =
-    do_GetService(ICC_SERVICE_CONTRACTID);
-  NS_ENSURE_TRUE_VOID(service);
-
-  nsCOMPtr<nsIIcc> icc;
-  service->GetIccByServiceId(aClientId, getter_AddRefs(icc));
+  nsCOMPtr<nsIIccProvider> icc =
+    do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
   NS_ENSURE_TRUE_VOID(icc);
 
   nsCOMPtr<nsIIccInfo> iccInfo;
-  icc->GetIccInfo(getter_AddRefs(iccInfo));
+  icc->GetIccInfo(aClientId, getter_AddRefs(iccInfo));
   NS_ENSURE_TRUE_VOID(iccInfo);
 
   nsCOMPtr<nsIGsmIccInfo> gsmIccInfo = do_QueryInterface(iccInfo);
   NS_ENSURE_TRUE_VOID(gsmIccInfo);
   gsmIccInfo->GetMsisdn(mMsisdn);
 }
 #endif // MOZ_B2G_RIL
 
--- a/dom/events/Event.cpp
+++ b/dom/events/Event.cpp
@@ -975,17 +975,17 @@ Event::GetOffsetCoords(nsPresContext* aP
                        WidgetEvent* aEvent,
                        LayoutDeviceIntPoint aPoint,
                        CSSIntPoint aDefaultPoint)
 {
   if (!aEvent->mFlags.mIsBeingDispatched) {
     return GetPageCoords(aPresContext, aEvent, aPoint, aDefaultPoint);
   }
   nsCOMPtr<nsIContent> content = do_QueryInterface(aEvent->target);
-  if (!content) {
+  if (!content || !aPresContext) {
     return CSSIntPoint(0, 0);
   }
   nsCOMPtr<nsIPresShell> shell = aPresContext->GetPresShell();
   if (!shell) {
     return CSSIntPoint(0, 0);
   }
   shell->FlushPendingNotifications(Flush_Layout);
   nsIFrame* frame = content->GetPrimaryFrame();
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -1997,16 +1997,17 @@ EventStateManager::DoScrollZoom(nsIFrame
       // positive adjustment to decrease zoom, negative to increase
       int32_t change = (adjustment > 0) ? -1 : 1;
 
       if (Preferences::GetBool("browser.zoom.full") || content->OwnerDoc()->IsSyntheticDocument()) {
         ChangeFullZoom(change);
       } else {
         ChangeTextSize(change);
       }
+      EnsureDocument(mPresContext);
       nsContentUtils::DispatchChromeEvent(mDocument, static_cast<nsIDocument*>(mDocument),
                                           NS_LITERAL_STRING("ZoomChangeUsingMouseWheel"),
                                           true, true);
     }
 }
 
 static nsIFrame*
 GetParentFrameToScroll(nsIFrame* aFrame)
new file mode 100644
--- /dev/null
+++ b/dom/events/crashtests/1143972-1.html
@@ -0,0 +1,12 @@
+<!DOCTYPE HTML>
+<script>
+var x;
+function doTest() {
+  f.contentDocument.body.onclick = function (event) {
+    x = event.offsetX;
+  }
+  f.contentDocument.body.dispatchEvent(f.contentWindow.ev);
+}
+</script>
+<iframe id="f" style="display:none" onload="doTest()"
+        src="data:text/html,<script>var ev = new MouseEvent('click', {clientX:0, clientY:0})</script>"></iframe>
--- a/dom/events/crashtests/crashtests.list
+++ b/dom/events/crashtests/crashtests.list
@@ -3,13 +3,14 @@ load 116206-1.html
 load 135345-1.html
 load 422009-1.xhtml
 load 457776-1.html
 load 496308-1.html
 load 682637-1.html
 load 1033343.html
 load 1035654-1.html
 load 1035654-2.html
+load 1143972-1.html
 needs-focus load 1072137-1.html
 load eventctor-nulldictionary.html
 load eventctor-nullstorage.html
 load recursive-onload.html
 load recursive-DOMNodeInserted.html
--- a/dom/events/test/window_bug659071.html
+++ b/dom/events/test/window_bug659071.html
@@ -43,19 +43,26 @@ function runTests()
        "failed to reset zoom");
     synthesizeWheel(video, 10, 10,
       { deltaMode: WheelEvent.DOM_DELTA_LINE, ctrlKey: true,
         deltaX: 0, deltaY: 1.0, lineOrPageDeltaX: 0, lineOrPageDeltaY: 1 });
     hitEventLoop(function () {
       isnot(SpecialPowers.getFullZoom(window), 1.0,
              "failed to zoom by ctrl+wheel");
 
-      synthesizeKey("0", { accelKey: true });
-      SpecialPowers.clearUserPref("mousewheel.with_control.action");
+      synthesizeWheel(video, 10, 10,
+        { deltaMode: WheelEvent.DOM_DELTA_LINE, ctrlKey: true,
+          deltaX: 0, deltaY: 1.0, lineOrPageDeltaX: 0, lineOrPageDeltaY: -1 });
+      hitEventLoop(function () {
+        is(SpecialPowers.getFullZoom(window), 1.0,
+           "failed to reset zoom");
 
-      hitEventLoop(window.opener.finish, 20);
+        SpecialPowers.clearUserPref("mousewheel.with_control.action");
+
+        hitEventLoop(window.opener.finish, 20);
+      }, 20);
     }, 20);
   }, 20);
 }
 
 </script>
 </body>
 </html>
--- a/dom/icc/Assertions.cpp
+++ b/dom/icc/Assertions.cpp
@@ -1,22 +1,22 @@
 /* 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/MozIccBinding.h"
-#include "nsIIccService.h"
+#include "nsIIccProvider.h"
 
 namespace mozilla {
 namespace dom {
 namespace icc {
 
 #define ASSERT_EQUALITY(webidlType, webidlState, xpidlState) \
-  static_assert(static_cast<uint32_t>(webidlType::webidlState) == nsIIcc::xpidlState, \
-  #webidlType "::" #webidlState " should equal to nsIIccService::" #xpidlState)
+  static_assert(static_cast<uint32_t>(webidlType::webidlState) == nsIIccProvider::xpidlState, \
+  #webidlType "::" #webidlState " should equal to nsIIccProvider::" #xpidlState)
 
 /**
  * Enum IccCardState
  */
 #define ASSERT_ICC_CARD_STATE_EQUALITY(webidlState, xpidlState) \
   ASSERT_EQUALITY(IccCardState, webidlState, xpidlState)
 
 ASSERT_ICC_CARD_STATE_EQUALITY(Unknown, CARD_STATE_UNKNOWN);
--- a/dom/icc/Icc.cpp
+++ b/dom/icc/Icc.cpp
@@ -1,29 +1,25 @@
 /* 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.h"
 
-#include "IccCallback.h"
 #include "mozilla/dom/DOMRequest.h"
 #include "mozilla/dom/IccInfo.h"
 #include "mozilla/dom/MozStkCommandEvent.h"
 #include "mozilla/dom/Promise.h"
 #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 {
 
 namespace {
 
 bool
 IsPukCardLockType(IccLockType aLockType)
 {
@@ -49,20 +45,19 @@ IsPukCardLockType(IccLockType aLockType)
 NS_IMPL_CYCLE_COLLECTION_INHERITED(Icc, DOMEventTargetHelper, mIccInfo)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(Icc)
 NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
 
 NS_IMPL_ADDREF_INHERITED(Icc, DOMEventTargetHelper)
 NS_IMPL_RELEASE_INHERITED(Icc, DOMEventTargetHelper)
 
-Icc::Icc(nsPIDOMWindow* aWindow, long aClientId, nsIIcc* aHandler, nsIIccInfo* aIccInfo)
+Icc::Icc(nsPIDOMWindow* aWindow, long aClientId, nsIIccInfo* aIccInfo)
   : mLive(true)
   , mClientId(aClientId)
-  , mHandler(aHandler)
 {
   BindToOwner(aWindow);
 
   mProvider = do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
 
   if (aIccInfo) {
     aIccInfo->GetIccid(mIccId);
     UpdateIccInfo(aIccInfo);
@@ -79,17 +74,16 @@ Icc::~Icc()
 {
 }
 
 void
 Icc::Shutdown()
 {
   mIccInfo.SetNull();
   mProvider = nullptr;
-  mHandler = nullptr;
   mLive = false;
 }
 
 nsresult
 Icc::NotifyEvent(const nsAString& aName)
 {
   return DispatchTrustedEvent(aName);
 }
@@ -171,20 +165,20 @@ Icc::GetIccInfo(Nullable<OwningMozIccInf
   aIccInfo = mIccInfo;
 }
 
 Nullable<IccCardState>
 Icc::GetCardState() const
 {
   Nullable<IccCardState> result;
 
-  uint32_t cardState = nsIIcc::CARD_STATE_UNDETECTED;
-  if (mHandler &&
-      NS_SUCCEEDED(mHandler->GetCardState(&cardState)) &&
-      cardState != nsIIcc::CARD_STATE_UNDETECTED) {
+  uint32_t cardState = nsIIccProvider::CARD_STATE_UNDETECTED;
+  if (mProvider &&
+      NS_SUCCEEDED(mProvider->GetCardState(mClientId, &cardState)) &&
+      cardState != nsIIccProvider::CARD_STATE_UNDETECTED) {
     MOZ_ASSERT(cardState < static_cast<uint32_t>(IccCardState::EndGuard_));
     result.SetValue(static_cast<IccCardState>(cardState));
   }
 
   return result;
 }
 
 void
@@ -250,117 +244,110 @@ Icc::SendStkEventDownload(const JSContex
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
   }
 }
 
 already_AddRefed<DOMRequest>
 Icc::GetCardLock(IccLockType aLockType, ErrorResult& aRv)
 {
-  if (!mHandler) {
+  if (!mProvider) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
-  nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
-  // TODO: Bug 1125018 - Simplify The Result of GetCardLock and
-  // getCardLockRetryCount in MozIcc.webidl without a wrapper object.
-  nsRefPtr<IccCallback> requestCallback =
-    new IccCallback(GetOwner(), request, true);
-  nsresult rv = mHandler->GetCardLockEnabled(static_cast<uint32_t>(aLockType),
-                                             requestCallback);
+  nsRefPtr<nsIDOMDOMRequest> request;
+  nsresult rv = mProvider->GetCardLockEnabled(mClientId, GetOwner(),
+                                              static_cast<uint32_t>(aLockType),
+                                              getter_AddRefs(request));
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return nullptr;
   }
 
-  return request.forget();
+  return request.forget().downcast<DOMRequest>();
 }
 
 already_AddRefed<DOMRequest>
 Icc::UnlockCardLock(const IccUnlockCardLockOptions& aOptions, ErrorResult& aRv)
 {
-  if (!mHandler) {
+  if (!mProvider) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
-  nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
-  nsRefPtr<IccCallback> requestCallback =
-    new IccCallback(GetOwner(), request);
+  nsRefPtr<nsIDOMDOMRequest> request;
   const nsString& password = IsPukCardLockType(aOptions.mLockType)
                            ? aOptions.mPuk : aOptions.mPin;
-  nsresult rv =
-    mHandler->UnlockCardLock(static_cast<uint32_t>(aOptions.mLockType),
-                             password, aOptions.mNewPin, requestCallback);
+  nsresult rv = mProvider->UnlockCardLock(mClientId, GetOwner(),
+                                          static_cast<uint32_t>(aOptions.mLockType),
+                                          password, aOptions.mNewPin,
+                                          getter_AddRefs(request));
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return nullptr;
   }
 
-  return request.forget();
+  return request.forget().downcast<DOMRequest>();
 }
 
 already_AddRefed<DOMRequest>
 Icc::SetCardLock(const IccSetCardLockOptions& aOptions, ErrorResult& aRv)
 {
-  if (!mHandler) {
+  if (!mProvider) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
   nsresult rv;
-  nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
-  nsRefPtr<IccCallback> requestCallback =
-    new IccCallback(GetOwner(), request);
+  nsRefPtr<nsIDOMDOMRequest> request;
 
   if (aOptions.mEnabled.WasPassed()) {
     // Enable card lock.
     const nsString& password = (aOptions.mLockType == IccLockType::Fdn) ?
                                aOptions.mPin2 : aOptions.mPin;
 
-    rv =
-      mHandler->SetCardLockEnabled(static_cast<uint32_t>(aOptions.mLockType),
-                                   password, aOptions.mEnabled.Value(),
-                                   requestCallback);
+    rv = mProvider->SetCardLockEnabled(mClientId, GetOwner(),
+                                       static_cast<uint32_t>(aOptions.mLockType),
+                                       password, aOptions.mEnabled.Value(),
+                                       getter_AddRefs(request));
   } else {
     // Change card lock password.
-    rv =
-      mHandler->ChangeCardLockPassword(static_cast<uint32_t>(aOptions.mLockType),
-                                       aOptions.mPin, aOptions.mNewPin,
-                                       requestCallback);
+    rv = mProvider->ChangeCardLockPassword(mClientId, GetOwner(),
+                                           static_cast<uint32_t>(aOptions.mLockType),
+                                           aOptions.mPin, aOptions.mNewPin,
+                                           getter_AddRefs(request));
   }
 
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return nullptr;
   }
 
-  return request.forget();
+  return request.forget().downcast<DOMRequest>();
 }
 
 already_AddRefed<DOMRequest>
 Icc::GetCardLockRetryCount(IccLockType aLockType, ErrorResult& aRv)
 {
-  if (!mHandler) {
+  if (!mProvider) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
-  nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
-  nsRefPtr<IccCallback> requestCallback =
-    new IccCallback(GetOwner(), request);
-  nsresult rv = mHandler->GetCardLockRetryCount(static_cast<uint32_t>(aLockType),
-                                                requestCallback);
+  nsRefPtr<nsIDOMDOMRequest> request;
+  nsresult rv = mProvider->GetCardLockRetryCount(mClientId, GetOwner(),
+                                                 static_cast<uint32_t>(aLockType),
+                                                 getter_AddRefs(request));
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return nullptr;
   }
 
-  return request.forget();
+  return request.forget().downcast<DOMRequest>();
 }
 
 already_AddRefed<DOMRequest>
 Icc::ReadContacts(IccContactType aContactType, ErrorResult& aRv)
 {
   if (!mProvider) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
@@ -400,61 +387,48 @@ Icc::UpdateContact(const JSContext* aCx,
 
   return request.forget().downcast<DOMRequest>();
 }
 
 already_AddRefed<DOMRequest>
 Icc::MatchMvno(IccMvnoType aMvnoType, const nsAString& aMvnoData,
                ErrorResult& aRv)
 {
-  if (!mHandler) {
+  if (!mProvider) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
-  nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
-  nsRefPtr<IccCallback> requestCallback =
-    new IccCallback(GetOwner(), request);
-  nsresult rv = mHandler->MatchMvno(static_cast<uint32_t>(aMvnoType),
-                                    aMvnoData, requestCallback);
+  nsRefPtr<nsIDOMDOMRequest> request;
+  nsresult rv = mProvider->MatchMvno(mClientId, GetOwner(),
+                                     static_cast<uint32_t>(aMvnoType),
+                                     aMvnoData, getter_AddRefs(request));
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return nullptr;
   }
 
-  return request.forget();
+  return request.forget().downcast<DOMRequest>();
 }
 
 already_AddRefed<Promise>
 Icc::GetServiceState(IccService aService, ErrorResult& aRv)
 {
-  if (!mHandler) {
+  if (!mProvider) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
-  if (!global) {
-    return nullptr;
-  }
-
-  nsRefPtr<Promise> promise = Promise::Create(global, aRv);
-  if (aRv.Failed()) {
+  nsCOMPtr<nsISupports> supports;
+  nsresult rv = mProvider->GetServiceState(mClientId, GetOwner(),
+                                           static_cast<uint32_t>(aService),
+                                           getter_AddRefs(supports));
+  if (NS_FAILED(rv)) {
+    aRv.Throw(rv);
     return nullptr;
   }
 
-  nsRefPtr<IccCallback> requestCallback =
-    new IccCallback(GetOwner(), promise);
-
-  nsresult rv =
-    mHandler->GetServiceStateEnabled(static_cast<uint32_t>(aService),
-                                     requestCallback);
-
-  if (NS_FAILED(rv)) {
-    promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
-    // fall-through to return promise.
-  }
-
+  nsCOMPtr<Promise> promise = do_QueryInterface(supports);
   return promise.forget();
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/icc/Icc.h
+++ b/dom/icc/Icc.h
@@ -3,17 +3,16 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_Icc_h
 #define mozilla_dom_Icc_h
 
 #include "mozilla/dom/MozIccBinding.h"
 #include "mozilla/DOMEventTargetHelper.h"
 
-class nsIIcc;
 class nsIIccInfo;
 class nsIIccProvider;
 
 namespace mozilla {
 namespace dom {
 
 class DOMRequest;
 class OwningMozIccInfoOrMozGsmIccInfoOrMozCdmaIccInfo;
@@ -21,18 +20,17 @@ class Promise;
 
 class Icc MOZ_FINAL : public DOMEventTargetHelper
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Icc, DOMEventTargetHelper)
   NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
 
-  Icc(nsPIDOMWindow* aWindow, long aClientId,
-      nsIIcc* aHandler, nsIIccInfo* aIccInfo);
+  Icc(nsPIDOMWindow* aWindow, long aClientId, nsIIccInfo* aIccInfo);
 
   void
   Shutdown();
 
   nsresult
   NotifyEvent(const nsAString& aName);
 
   nsresult
@@ -108,29 +106,23 @@ public:
   GetServiceState(IccService aService, ErrorResult& aRv);
 
   IMPL_EVENT_HANDLER(iccinfochange)
   IMPL_EVENT_HANDLER(cardstatechange)
   IMPL_EVENT_HANDLER(stkcommand)
   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<nsIIccProvider> mProvider;
-  // mHandler will be released at Shutdown(), so there is no need to join cycle
-  // collection.
-  nsCOMPtr<nsIIcc> mHandler;
   Nullable<OwningMozIccInfoOrMozGsmIccInfoOrMozCdmaIccInfo> mIccInfo;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_icc_Icc_h
deleted file mode 100644
--- a/dom/icc/IccCallback.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-/* 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<JS::Value> aResult)
-{
-  nsCOMPtr<nsIDOMRequestService> 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<JS::Value> 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<JS::Value> 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<nsIDOMRequestService> 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<IccCardLockError> error =
-    new IccCardLockError(mWindow, aErrorMsg, aRetryCount);
-  mRequest->FireDetailedError(error);
-
-  return NS_OK;
-}
-
-} // namespace icc
-} // namespace dom
-} // namespace mozilla
\ No newline at end of file
deleted file mode 100644
--- a/dom/icc/IccCallback.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/* 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 MOZ_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<JS::Value> aResult);
-
-  // TODO: Bug 1125018 - Simplify The Result of GetCardLock and
-  // getCardLockRetryCount in MozIcc.webidl without a wrapper object.
-  nsresult
-  NotifyGetCardLockEnabled(bool aResult);
-
-  nsCOMPtr<nsPIDOMWindow> mWindow;
-  nsRefPtr<DOMRequest> mRequest;
-  nsRefPtr<Promise> 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
--- a/dom/icc/IccInfo.cpp
+++ b/dom/icc/IccInfo.cpp
@@ -1,296 +1,233 @@
 /* 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/IccInfo.h"
 
-#include "mozilla/dom/icc/PIccTypes.h"
 #include "nsPIDOMWindow.h"
 
 #define CONVERT_STRING_TO_NULLABLE_ENUM(_string, _enumType, _enum)      \
 {                                                                       \
   uint32_t i = 0;                                                       \
   for (const EnumEntry* entry = _enumType##Values::strings;             \
        entry->value;                                                    \
        ++entry, ++i) {                                                  \
     if (_string.EqualsASCII(entry->value)) {                            \
       _enum.SetValue(static_cast<_enumType>(i));                        \
     }                                                                   \
   }                                                                     \
 }
 
 using namespace mozilla::dom;
 
-using mozilla::dom::icc::IccInfoData;
-
 // IccInfo
 
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(IccInfo, mWindow)
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(IccInfo, mWindow, mIccInfo)
 
 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)
 {
-  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);
+  mIccInfo = aInfo;
 }
 
-// WebIDL implementation
-
 JSObject*
 IccInfo::WrapObject(JSContext* aCx)
 {
   return MozIccInfoBinding::Wrap(aCx, this);
 }
 
 Nullable<IccType>
 IccInfo::GetIccType() const
 {
+  if (!mIccInfo) {
+    return Nullable<IccType>();
+  }
+
+  nsAutoString type;
   Nullable<IccType> iccType;
 
-  CONVERT_STRING_TO_NULLABLE_ENUM(mIccType, IccType, iccType);
+  mIccInfo->GetIccType(type);
+  CONVERT_STRING_TO_NULLABLE_ENUM(type, IccType, iccType);
 
   return iccType;
 }
 
 void
 IccInfo::GetIccid(nsAString& aIccId) const
 {
-  aIccId = mIccid;
+  if (!mIccInfo) {
+    aIccId.SetIsVoid(true);
+    return;
+  }
+
+  mIccInfo->GetIccid(aIccId);
 }
 
 void
 IccInfo::GetMcc(nsAString& aMcc) const
 {
-  aMcc = mMcc;
+  if (!mIccInfo) {
+    aMcc.SetIsVoid(true);
+    return;
+  }
+
+  mIccInfo->GetMcc(aMcc);
 }
 
 void
 IccInfo::GetMnc(nsAString& aMnc) const
 {
-  aMnc = mMnc;
+  if (!mIccInfo) {
+    aMnc.SetIsVoid(true);
+    return;
+  }
+
+  mIccInfo->GetMnc(aMnc);
 }
 
 void
 IccInfo::GetSpn(nsAString& aSpn) const
 {
-  aSpn = mSpn;
+  if (!mIccInfo) {
+    aSpn.SetIsVoid(true);
+    return;
+  }
+
+  mIccInfo->GetSpn(aSpn);
 }
 
 bool
 IccInfo::IsDisplayNetworkNameRequired() const
 {
-  return mIsDisplayNetworkNameRequired;
+  if (!mIccInfo) {
+    return false;
+  }
+
+  bool isDisplayNetworkNameRequired;
+  mIccInfo->GetIsDisplayNetworkNameRequired(&isDisplayNetworkNameRequired);
+
+  return isDisplayNetworkNameRequired;
 }
 
 bool
 IccInfo::IsDisplaySpnRequired() const
 {
+  if (!mIccInfo) {
+    return false;
+  }
 
-  return mIsDisplaySpnRequired;
+  bool isDisplaySpnRequired;
+  mIccInfo->GetIsDisplaySpnRequired(&isDisplaySpnRequired);
+
+  return isDisplaySpnRequired;
 }
 
 // GsmIccInfo
 
-NS_IMPL_ISUPPORTS_INHERITED(GsmIccInfo, IccInfo, nsIGsmIccInfo)
+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)
 
 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<nsIIccInfo> iccInfo = do_QueryInterface(aInfo);
   MOZ_ASSERT(iccInfo);
 
   IccInfo::Update(iccInfo);
-
-  aInfo->GetMsisdn(mPhoneNumber);
+  mGsmIccInfo = aInfo;
 }
 
 JSObject*
 GsmIccInfo::WrapObject(JSContext* aCx)
 {
   return MozGsmIccInfoBinding::Wrap(aCx, this);
 }
 
 void
 GsmIccInfo::GetMsisdn(nsAString& aMsisdn) const
 {
-  aMsisdn = mPhoneNumber;
+  if (!mGsmIccInfo) {
+    aMsisdn.SetIsVoid(true);
+    return;
+  }
+
+  mGsmIccInfo->GetMsisdn(aMsisdn);
 }
 
 // CdmaIccInfo
 
-NS_IMPL_ISUPPORTS_INHERITED(CdmaIccInfo, IccInfo, nsICdmaIccInfo)
+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)
 
 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<nsIIccInfo> iccInfo = do_QueryInterface(aInfo);
   MOZ_ASSERT(iccInfo);
 
   IccInfo::Update(iccInfo);
-
-  aInfo->GetMdn(mPhoneNumber);
-  aInfo->GetPrlVersion(&mPrlVersion);
+  mCdmaIccInfo = aInfo;
 }
 
-// WebIDL implementation
-
 JSObject*
 CdmaIccInfo::WrapObject(JSContext* aCx)
 {
   return MozCdmaIccInfoBinding::Wrap(aCx, this);
 }
 
 void
 CdmaIccInfo::GetMdn(nsAString& aMdn) const
 {
-  aMdn = mPhoneNumber;
+  if (!mCdmaIccInfo) {
+    aMdn.SetIsVoid(true);
+    return;
+  }
+
+  mCdmaIccInfo->GetMdn(aMdn);
 }
 
 int32_t
 CdmaIccInfo::PrlVersion() const
 {
-  return mPrlVersion;
+  if (!mCdmaIccInfo) {
+    return 0;
+  }
+
+  int32_t prlVersion;
+  mCdmaIccInfo->GetPrlVersion(&prlVersion);
+
+  return prlVersion;
 }
--- a/dom/icc/IccInfo.h
+++ b/dom/icc/IccInfo.h
@@ -9,30 +9,24 @@
 #include "nsIIccInfo.h"
 #include "nsWrapperCache.h"
 
 class nsPIDOMWindow;
 
 namespace mozilla {
 namespace dom {
 
-namespace icc {
-class IccInfoData;
-} // namespace icc
-
-class IccInfo : public nsIIccInfo
+class IccInfo : public nsISupports
               , 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);
 
   nsPIDOMWindow*
   GetParentObject() const
   {
     return mWindow;
@@ -62,68 +56,54 @@ public:
   IsDisplayNetworkNameRequired() const;
 
   bool
   IsDisplaySpnRequired() const;
 
 protected:
   virtual ~IccInfo() {}
 
+protected:
   nsCOMPtr<nsPIDOMWindow> mWindow;
-  // 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;
+  nsCOMPtr<nsIIccInfo> mIccInfo;
 };
 
 class GsmIccInfo MOZ_FINAL : public IccInfo
-                           , public nsIGsmIccInfo
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
-  NS_FORWARD_NSIICCINFO(IccInfo::)
-  NS_DECL_NSIGSMICCINFO
+  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(GsmIccInfo, IccInfo)
 
   explicit GsmIccInfo(nsPIDOMWindow* aWindow);
-  explicit GsmIccInfo(const icc::IccInfoData& aData);
 
   void
   Update(nsIGsmIccInfo* aInfo);
 
   // WrapperCache
   virtual JSObject*
   WrapObject(JSContext* aCx) MOZ_OVERRIDE;
 
   // MozCdmaIccInfo WebIDL
   void
   GetMsisdn(nsAString& aMsisdn) const;
 
 private:
   ~GsmIccInfo() {}
 
-  nsString mPhoneNumber;
+private:
+  nsCOMPtr<nsIGsmIccInfo> mGsmIccInfo;
 };
 
 class CdmaIccInfo MOZ_FINAL : public IccInfo
-                            , public nsICdmaIccInfo
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
-  NS_FORWARD_NSIICCINFO(IccInfo::)
-  NS_DECL_NSICDMAICCINFO
+  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CdmaIccInfo, IccInfo)
 
   explicit CdmaIccInfo(nsPIDOMWindow* aWindow);
-  explicit CdmaIccInfo(const icc::IccInfoData& aData);
 
   void
   Update(nsICdmaIccInfo* aInfo);
 
   // WrapperCache
   virtual JSObject*
   WrapObject(JSContext* aCx) MOZ_OVERRIDE;
 
@@ -132,17 +112,17 @@ public:
   GetMdn(nsAString& aMdn) const;
 
   int32_t
   PrlVersion() const;
 
 private:
   ~CdmaIccInfo() {}
 
-  nsString mPhoneNumber;
-  int32_t mPrlVersion;
+private:
+  nsCOMPtr<nsICdmaIccInfo> mCdmaIccInfo;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_IccInfo_h
 
--- a/dom/icc/IccListener.cpp
+++ b/dom/icc/IccListener.cpp
@@ -15,77 +15,51 @@ using namespace mozilla::dom;
 NS_IMPL_ISUPPORTS(IccListener, nsIIccListener)
 
 IccListener::IccListener(IccManager* aIccManager, uint32_t aClientId)
   : mClientId(aClientId)
   , mIccManager(aIccManager)
 {
   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) {
     NS_WARNING("Could not acquire nsIIccProvider!");
     return;
   }
 
-  nsCOMPtr<nsIIccService> 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<nsIIccInfo> iccInfo;
-  mHandler->GetIccInfo(getter_AddRefs(iccInfo));
+  mProvider->GetIccInfo(mClientId, getter_AddRefs(iccInfo));
   if (iccInfo) {
     nsString iccId;
     iccInfo->GetIccid(iccId);
     if (!iccId.IsEmpty()) {
-      mIcc = new Icc(mIccManager->GetOwner(), mClientId, mHandler, iccInfo);
+      mIcc = new Icc(mIccManager->GetOwner(), mClientId, iccInfo);
     }
   }
 
-  DebugOnly<nsresult> rv = mHandler->RegisterListener(this);
-  NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
-                   "Failed registering icc listener with Icc Handler");
-
-  rv = mProvider->RegisterIccMsg(mClientId, this);
+  DebugOnly<nsresult> rv = mProvider->RegisterIccMsg(mClientId, this);
   NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
                    "Failed registering icc messages with provider");
 }
 
 IccListener::~IccListener()
 {
   Shutdown();
 }
 
 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;
   }
 
   mIccManager = nullptr;
 }
 
@@ -119,34 +93,30 @@ IccListener::NotifyCardStateChanged()
   }
 
   return mIcc->NotifyEvent(NS_LITERAL_STRING("cardstatechange"));
 }
 
 NS_IMETHODIMP
 IccListener::NotifyIccInfoChanged()
 {
-  if (!mHandler) {
-    return NS_OK;
-  }
-
   nsCOMPtr<nsIIccInfo> iccInfo;
-  mHandler->GetIccInfo(getter_AddRefs(iccInfo));
+  mProvider->GetIccInfo(mClientId, 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
   //    notify mIccManager a new icc is added.
   // 2. If the mIcc is not nullptr and iccInfo becomes to null, delete existed
   //    icc object and notify mIccManager the icc is removed.
   if (!mIcc) {
     if (iccInfo) {
       nsString iccId;
       iccInfo->GetIccid(iccId);
       if (!iccId.IsEmpty()) {
-        mIcc = new Icc(mIccManager->GetOwner(), mClientId, mHandler, iccInfo);
+        mIcc = new Icc(mIccManager->GetOwner(), mClientId, iccInfo);
         mIccManager->NotifyIccAdd(iccId);
         mIcc->NotifyEvent(NS_LITERAL_STRING("iccinfochange"));
       }
     }
   } else {
     mIcc->UpdateIccInfo(iccInfo);
     mIcc->NotifyEvent(NS_LITERAL_STRING("iccinfochange"));
     if (!iccInfo) {
--- a/dom/icc/IccListener.h
+++ b/dom/icc/IccListener.h
@@ -2,17 +2,16 @@
  * 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_IccListener_h
 #define mozilla_dom_IccListener_h
 
 #include "nsAutoPtr.h"
 #include "nsIIccProvider.h"
-#include "nsIIccService.h"
 
 namespace mozilla {
 namespace dom {
 
 class IccManager;
 class Icc;
 
 class IccListener MOZ_FINAL : public nsIIccListener
@@ -38,20 +37,17 @@ private:
 private:
   uint32_t mClientId;
   // We did not setup 'mIcc' and 'mIccManager' being a participant of cycle
   // collection is because in Navigator->Invalidate() it will call
   // mIccManager->Shutdown(), then IccManager will call Shutdown() of each
   // IccListener, this will release the reference and break the cycle.
   nsRefPtr<Icc> mIcc;
   nsRefPtr<IccManager> 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<nsIIccProvider> mProvider;
-  // mHandler will be released at Shutdown(), there is no need to join cycle
-  // collection.
-  nsCOMPtr<nsIIcc> mHandler;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_IccListener_h
--- a/dom/icc/IccManager.cpp
+++ b/dom/icc/IccManager.cpp
@@ -5,25 +5,16 @@
 #include "IccManager.h"
 #include "mozilla/dom/MozIccManagerBinding.h"
 #include "Icc.h"
 #include "IccListener.h"
 #include "mozilla/AsyncEventDispatcher.h"
 #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)
-// TODO: Bug 815526, deprecate RILContentHelper.
-#include "nsIRadioInterfaceLayer.h"
-#include "nsRadioInterfaceLayer.h"
-#include "nsIGonkIccService.h"
-#endif
-#include "nsXULAppAPI.h" // For XRE_GetProcessType()
 
 using namespace mozilla::dom;
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(IccManager)
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IccManager,
                                                   DOMEventTargetHelper)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
@@ -133,30 +124,8 @@ IccManager::GetIccById(const nsAString& 
   for (i = 0; i < mIccListeners.Length(); ++i) {
     Icc* icc = mIccListeners[i]->GetIcc();
     if (icc && aIccId == icc->GetIccId()) {
       return icc;
     }
   }
   return nullptr;
 }
-
-already_AddRefed<nsIIccService>
-NS_CreateIccService()
-{
-  nsCOMPtr<nsIIccService> service;
-
-  if (XRE_GetProcessType() == GeckoProcessType_Content) {
-    service = new mozilla::dom::icc::IccIPCService();
-#if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
-  } else {
-    // TODO: Bug 815526, deprecate RILContentHelper.
-    nsCOMPtr <nsIRadioInterfaceLayer> ril =
-      do_GetService(NS_RADIOINTERFACELAYER_CONTRACTID);
-    nsCOMPtr <nsIRadioInterfaceLayer_new> ril_new(do_QueryInterface(ril));
-
-    service = (ril_new) ? do_GetService(GONK_ICC_SERVICE_CONTRACTID)
-                        : do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
-#endif
-  }
-
-  return service.forget();
-}
--- a/dom/icc/IccManager.h
+++ b/dom/icc/IccManager.h
@@ -2,16 +2,17 @@
  * 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_IccManager_h
 #define mozilla_dom_IccManager_h
 
 #include "mozilla/DOMEventTargetHelper.h"
 #include "nsCycleCollectionParticipant.h"
+#include "nsIIccProvider.h"
 #include "nsTArrayHelpers.h"
 
 namespace mozilla {
 namespace dom {
 
 class Icc;
 class IccListener;
 
@@ -19,17 +20,17 @@ class IccManager MOZ_FINAL : public DOME
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
 
   NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IccManager, DOMEventTargetHelper)
 
-  explicit IccManager(nsPIDOMWindow* aWindow);
+  IccManager(nsPIDOMWindow* aWindow);
 
   void
   Shutdown();
 
   nsresult
   NotifyIccAdd(const nsAString& aIccId);
 
   nsresult
deleted file mode 100644
--- a/dom/icc/gonk/IccService.js
+++ /dev/null
@@ -1,437 +0,0 @@
-/* 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]);
deleted file mode 100644
--- a/dom/icc/gonk/IccService.manifest
+++ /dev/null
@@ -1,6 +0,0 @@
-# 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
--- a/dom/icc/interfaces/moz.build
+++ b/dom/icc/interfaces/moz.build
@@ -1,19 +1,17 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
 XPIDL_SOURCES += [
     'nsIIccInfo.idl',
-    'nsIIccProvider.idl', # TODO: Bug 815526, deprecate RILContentHelper.
-    'nsIIccService.idl',
+    'nsIIccProvider.idl',
 ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk' and CONFIG['MOZ_B2G_RIL']:
     XPIDL_SOURCES += [
-        'nsIGonkIccService.idl',
         'nsIIccMessenger.idl',
     ]
 
 XPIDL_MODULE = 'dom_icc'
deleted file mode 100644
--- a/dom/icc/interfaces/nsIGonkIccService.idl
+++ /dev/null
@@ -1,21 +0,0 @@
-/* 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"
-
-%{C++
-#define GONK_ICC_SERVICE_CONTRACTID \
-        "@mozilla.org/icc/gonkiccservice;1"
-%}
-
-[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);
-};
--- a/dom/icc/interfaces/nsIIccProvider.idl
+++ b/dom/icc/interfaces/nsIIccProvider.idl
@@ -2,17 +2,25 @@
  * 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 nsIDOMDOMRequest;
 interface nsIDOMWindow;
 interface nsIIccInfo;
-interface nsIIccListener;
+
+[scriptable, uuid(7c0ada3d-d8d4-493e-9243-fa3df39855e4)]
+interface nsIIccListener : nsISupports
+{
+  void notifyStkCommand(in DOMString aMessage);
+  void notifyStkSessionEnd();
+  void notifyCardStateChanged();
+  void notifyIccInfoChanged();
+};
 
 [scriptable, uuid(6136acab-b50e-494a-a86d-df392a032897)]
 interface nsIIccChannelCallback : nsISupports
 {
   /**
    * Callback function to notify on successfully opening a logical channel.
    *
    * @param channel
@@ -45,28 +53,114 @@ interface nsIIccChannelCallback : nsISup
    *
    */
   void notifyError(in DOMString error);
 };
 
 /**
  * XPCOM component (in the content process) that provides the ICC information.
  */
-[scriptable, uuid(7dd6e186-b007-11e4-9b7e-7717d7863cb8)]
+[scriptable, uuid(a203cd2e-2280-4d8e-a687-42b745d322c1)]
 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
    * the 'mobileconnection' permission is allowed to register.
    */
   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.
    */
   void sendStkResponse(in unsigned long clientId,
                        in nsIDOMWindow window,
                        in jsval command,
                        in jsval response);
   void sendStkMenuSelection(in unsigned long clientId,
                             in nsIDOMWindow window,
@@ -75,29 +169,54 @@ interface nsIIccProvider : nsISupports
   void sendStkTimerExpiration(in unsigned long clientId,
                               in nsIDOMWindow window,
                               in jsval timer);
   void sendStkEventDownload(in unsigned long clientId,
                             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.
    */
   nsIDOMDOMRequest readContacts(in unsigned long clientId,
                                 in nsIDOMWindow window,
                                 in unsigned long contactType);
 
   nsIDOMDOMRequest updateContact(in unsigned long clientId,
                                  in nsIDOMWindow window,
                                  in unsigned long contactType,
                                  in jsval contact,
                                  in DOMString pin2);
 
-  /**
+/**
    * Secure Card Icc communication channel
    */
   void iccOpenChannel(in unsigned long clientId,
                       in DOMString aid,
                       in nsIIccChannelCallback callback);
 
   /**
    * Exchange Command APDU (C-APDU) with SIM on the given logical channel.
@@ -114,9 +233,21 @@ interface nsIIccProvider : nsISupports
                        in octet p2,
                        in short p3,
                        in DOMString data,
                        in nsIIccChannelCallback callback);
 
   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);
 };
deleted file mode 100644
--- a/dom/icc/interfaces/nsIIccService.idl
+++ /dev/null
@@ -1,329 +0,0 @@
-/* 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);
-};
-
-%{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<typename T> struct already_AddRefed;
-%}
-
-/**
- * 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);
-};
-
-%{C++
-already_AddRefed<nsIIccService>
-NS_CreateIccService();
-%}
-
-/**
- * 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);
-};
deleted file mode 100644
--- a/dom/icc/ipc/IccChild.cpp
+++ /dev/null
@@ -1,310 +0,0 @@
-/* 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> 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<nsIIccInfo> 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
deleted file mode 100644
--- a/dom/icc/ipc/IccChild.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/* 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 MOZ_FINAL : public PIccChild
-                         , public nsIIcc
-{
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIICC
-
-  explicit IccChild();
-
-  void
-  Init();
-
-  void
-  Shutdown();
-
-protected:
-  virtual void
-  ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;
-
-  virtual PIccRequestChild*
-  AllocPIccRequestChild(const IccRequest& aRequest) MOZ_OVERRIDE;
-
-  virtual bool
-  DeallocPIccRequestChild(PIccRequestChild* aActor) MOZ_OVERRIDE;
-
-  virtual bool
-  RecvNotifyCardStateChanged(const uint32_t& aCardState) MOZ_OVERRIDE;
-
-  virtual bool
-  RecvNotifyIccInfoChanged(const OptionalIccInfoData& aInfoData) MOZ_OVERRIDE;
-
-private:
-  // MOZ_FINAL suppresses -Werror,-Wdelete-non-virtual-dtor
-  ~IccChild();
-
-  void
-  UpdateIccInfo(const OptionalIccInfoData& aInfoData);
-
-  bool
-  SendRequest(const IccRequest& aRequest, nsIIccCallback* aRequestReply);
-
-  nsCOMArray<nsIIccListener> mListeners;
-  nsRefPtr<IccInfo> mIccInfo;
-  uint32_t mCardState;
-  bool mIsAlive;
-};
-
-class IccRequestChild MOZ_FINAL : public PIccRequestChild
-{
-public:
-  explicit IccRequestChild(nsIIccCallback* aRequestReply);
-
-protected:
-  virtual bool
-  Recv__delete__(const IccReply& aReply) MOZ_OVERRIDE;
-
-private:
-  // MOZ_FINAL suppresses -Werror,-Wdelete-non-virtual-dtor
-  virtual ~IccRequestChild() {
-    MOZ_COUNT_DTOR(IccRequestChild);
-  }
-
-  nsCOMPtr<nsIIccCallback> mRequestReply;
-};
-
-} // namespace icc
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_icc_IccChild_h
deleted file mode 100644
--- a/dom/icc/ipc/IccIPCService.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/* 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<IccChild> 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<nsIIcc> icc(mIccs[aServiceId]);
-  icc.forget(aIcc);
-
-  return NS_OK;
-}
-
-} // namespace icc
-} // namespace dom
-} // namespace mozilla
deleted file mode 100644
--- a/dom/icc/ipc/IccIPCService.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* 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 MOZ_FINAL : public nsIIccService
-{
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIICCSERVICE
-
-  IccIPCService();
-
-private:
-  // MOZ_FINAL suppresses -Werror,-Wdelete-non-virtual-dtor
-  ~IccIPCService();
-
-  nsTArray<nsRefPtr<IccChild>> mIccs;
-};
-
-} // namespace icc
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_icc_IccIPCService_h
\ No newline at end of file
deleted file mode 100644
--- a/dom/icc/ipc/IccParent.cpp
+++ /dev/null
@@ -1,320 +0,0 @@
-/* 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<nsIGsmIccInfo> gsmIccInfo(do_QueryInterface(aInInfo));
-  if (gsmIccInfo) {
-    gsmIccInfo->GetMsisdn(aOutData.phoneNumber());
-  }
-
-  nsCOMPtr<nsICdmaIccInfo> 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<nsIIccService> 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<nsIIccInfo> 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<IccRequestParent*>(aActor)->Release();
-  return true;
-}
-
-bool
-IccParent::RecvPIccRequestConstructor(PIccRequestParent* aActor,
-                                      const IccRequest& aRequest)
-{
-  NS_ASSERTION(mIcc, "RecvPIccRequestConstructor after actor was destroyed!");
-
-  IccRequestParent* actor = static_cast<IccRequestParent*>(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<nsIIccInfo> 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
deleted file mode 100644
--- a/dom/icc/ipc/IccParent.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/* 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 MOZ_FINAL : public PIccParent
-                          , public nsIIccListener
-{
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIICCLISTENER
-
-  explicit IccParent(uint32_t aServiceId);
-
-protected:
-  virtual
-  // MOZ_FINAL suppresses -Werror,-Wdelete-non-virtual-dtor
-  ~IccParent()
-  {
-    MOZ_COUNT_DTOR(IccParent);
-  }
-
-  virtual void
-  ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
-
-  virtual bool
-  RecvInit(
-          OptionalIccInfoData* aInfoData,
-          uint32_t* aCardState) MOZ_OVERRIDE;
-
-  virtual PIccRequestParent*
-  AllocPIccRequestParent(const IccRequest& aRequest) MOZ_OVERRIDE;
-
-  virtual bool
-  DeallocPIccRequestParent(PIccRequestParent* aActor) MOZ_OVERRIDE;
-
-  virtual bool
-  RecvPIccRequestConstructor(PIccRequestParent* aActor,
-                             const IccRequest& aRequest) MOZ_OVERRIDE;
-
-private:
-  IccParent();
-  nsCOMPtr<nsIIcc> mIcc;
-};
-
-class IccRequestParent MOZ_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) MOZ_OVERRIDE;
-
-private:
-  // MOZ_FINAL suppresses -Werror,-Wdelete-non-virtual-dtor
-  ~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<nsIIcc> mIcc;
-};
-
-} // namespace icc
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_icc_IccParent_h
deleted file mode 100644
--- a/dom/icc/ipc/PIcc.ipdl
+++ /dev/null
@@ -1,111 +0,0 @@
-/* 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
deleted file mode 100644
--- a/dom/icc/ipc/PIccRequest.ipdl
+++ /dev/null
@@ -1,61 +0,0 @@
-/* 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
deleted file mode 100644
--- a/dom/icc/ipc/PIccTypes.ipdlh
+++ /dev/null
@@ -1,24 +0,0 @@
-/* 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
--- a/dom/icc/moz.build
+++ b/dom/icc/moz.build
@@ -8,48 +8,29 @@ DIRS += ['interfaces']
 
 EXPORTS.mozilla.dom += [
     'Icc.h',
     'IccCardLockError.h',
     'IccInfo.h',
     'IccManager.h',
 ]
 
-EXPORTS.mozilla.dom.icc += [
-    'ipc/IccChild.h',
-    'ipc/IccParent.h',
-]
-
 UNIFIED_SOURCES += [
     'Assertions.cpp',
     'Icc.cpp',
-    'IccCallback.cpp',
     'IccCardLockError.cpp',
     "IccInfo.cpp",
     'IccListener.cpp',
     'IccManager.cpp',
-    'ipc/IccChild.cpp',
-    'ipc/IccIPCService.cpp',
-    'ipc/IccParent.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',
     ]
-    EXTRA_COMPONENTS += [
-        'gonk/IccService.js',
-        'gonk/IccService.manifest',
-    ]
 
 FAIL_ON_WARNINGS = True
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 
 LOCAL_INCLUDES += [
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -143,17 +143,16 @@
 
 #ifdef MOZ_NUWA_PROCESS
 #include <setjmp.h>
 #include "ipc/Nuwa.h"
 #endif
 
 #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"
 #include "mozilla/dom/PFileSystemRequestChild.h"
 #include "mozilla/dom/FileSystemTaskBase.h"
 #include "mozilla/dom/bluetooth/PBluetoothChild.h"
 #include "mozilla/dom/PFMRadioChild.h"
 #include "mozilla/ipc/InputStreamUtils.h"
@@ -176,17 +175,16 @@
 #include "mozilla/net/NeckoMessageUtils.h"
 #include "mozilla/RemoteSpellCheckEngineChild.h"
 
 using namespace mozilla;
 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;
 using namespace mozilla::dom::telephony;
 using namespace mozilla::dom::voicemail;
 using namespace mozilla::embedding;
 using namespace mozilla::hal_sandbox;
 using namespace mozilla::ipc;
@@ -1450,41 +1448,16 @@ ContentChild::AllocPHalChild()
 
 bool
 ContentChild::DeallocPHalChild(PHalChild* aHal)
 {
     delete 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<IccChild*>(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<IccChild*>(aActor)->Release();
-    return true;
-}
-
 asmjscache::PAsmJSCacheEntryChild*
 ContentChild::AllocPAsmJSCacheEntryChild(
                                     const asmjscache::OpenMode& aOpenMode,
                                     const asmjscache::WriteParams& aWriteParams,
                                     const IPC::Principal& aPrincipal)
 {
     NS_NOTREACHED("Should never get here!");
     return nullptr;
--- a/dom/ipc/ContentChild.h
+++ b/dom/ipc/ContentChild.h
@@ -167,23 +167,16 @@ public:
     AllocPCrashReporterChild(const mozilla::dom::NativeThreadId& id,
                              const uint32_t& processType) MOZ_OVERRIDE;
     virtual bool
     DeallocPCrashReporterChild(PCrashReporterChild*) MOZ_OVERRIDE;
 
     virtual PHalChild* AllocPHalChild() MOZ_OVERRIDE;
     virtual bool DeallocPHalChild(PHalChild*) MOZ_OVERRIDE;
 
-    PIccChild*
-    SendPIccConstructor(PIccChild* aActor, const uint32_t& aServiceId);
-    virtual PIccChild*
-    AllocPIccChild(const uint32_t& aClientId) MOZ_OVERRIDE;
-    virtual bool
-    DeallocPIccChild(PIccChild* aActor) MOZ_OVERRIDE;
-
     virtual PMemoryReportRequestChild*
     AllocPMemoryReportRequestChild(const uint32_t& aGeneration,
                                    const bool& aAnonymize,
                                    const bool& aMinimizeMemoryUsage,
                                    const MaybeFileDesc& aDMDFile) MOZ_OVERRIDE;
     virtual bool
     DeallocPMemoryReportRequestChild(PMemoryReportRequestChild* actor) MOZ_OVERRIDE;
 
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -46,17 +46,16 @@
 #include "mozilla/dom/PContentBridgeParent.h"
 #include "mozilla/dom/PCycleCollectWithLogsParent.h"
 #include "mozilla/dom/PFMRadioParent.h"
 #include "mozilla/dom/PMemoryReportRequestParent.h"
 #include "mozilla/dom/asmjscache/AsmJSCache.h"
 #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"
 #include "mozilla/dom/quota/QuotaManager.h"
 #include "mozilla/dom/telephony/TelephonyParent.h"
 #include "mozilla/dom/time/DateCacheCleaner.h"
 #include "mozilla/dom/voicemail/VoicemailParent.h"
 #include "mozilla/embedding/printingui/PrintingParent.h"
@@ -220,17 +219,16 @@ using base::ChildPrivileges;
 using base::KillProcess;
 
 #ifdef MOZ_CRASHREPORTER
 using namespace CrashReporter;
 #endif
 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;
 using namespace mozilla::dom::mobilemessage;
 using namespace mozilla::dom::telephony;
 using namespace mozilla::dom::voicemail;
 using namespace mozilla::embedding;
 using namespace mozilla::hal;
@@ -3377,37 +3375,16 @@ ContentParent::AllocPHalParent()
 
 bool
 ContentParent::DeallocPHalParent(hal_sandbox::PHalParent* aHal)
 {
     delete 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<IccParent*>(aActor)->Release();
-    return true;
-}
-
 PMemoryReportRequestParent*
 ContentParent::AllocPMemoryReportRequestParent(const uint32_t& aGeneration,
                                                const bool &aAnonymize,
                                                const bool &aMinimizeMemoryUsage,
                                                const MaybeFileDesc &aDMDFile)
 {
     MemoryReportRequestParent* parent = new MemoryReportRequestParent();
     return parent;
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -544,19 +544,16 @@ private:
     virtual bool RecvGetRandomValues(const uint32_t& length,
                                      InfallibleTArray<uint8_t>* randomValues) MOZ_OVERRIDE;
 
     virtual bool RecvIsSecureURI(const uint32_t& aType, const URIParams& aURI,
                                  const uint32_t& aFlags, bool* aIsSecureURI) MOZ_OVERRIDE;
 
     virtual bool DeallocPHalParent(PHalParent*) MOZ_OVERRIDE;
 
-    virtual PIccParent* AllocPIccParent(const uint32_t& aServiceId) MOZ_OVERRIDE;
-    virtual bool DeallocPIccParent(PIccParent* aActor) MOZ_OVERRIDE;
-
     virtual PMemoryReportRequestParent*
     AllocPMemoryReportRequestParent(const uint32_t& aGeneration,
                                     const bool &aAnonymize,
                                     const bool &aMinimizeMemoryUsage,
                                     const MaybeFileDesc &aDMDFile) MOZ_OVERRIDE;
     virtual bool DeallocPMemoryReportRequestParent(PMemoryReportRequestParent* actor) MOZ_OVERRIDE;
 
     virtual PCycleCollectWithLogsParent*
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -16,17 +16,16 @@ include protocol PCycleCollectWithLogs;
 include protocol PCrashReporter;
 include protocol PDocAccessible;
 include protocol PExternalHelperApp;
 include protocol PDeviceStorageRequest;
 include protocol PFileDescriptorSet;
 include protocol PFMRadio;
 include protocol PFileSystemRequest;
 include protocol PHal;
-include protocol PIcc;
 include protocol PProcessHangMonitor;
 include protocol PImageBridge;
 include protocol PMemoryReportRequest;
 include protocol PMobileConnection;
 include protocol PNecko;
 include protocol PPluginModule;
 include protocol PPrinting;
 include protocol POfflineCacheUpdate;
@@ -366,17 +365,16 @@ prio(normal upto urgent) sync protocol P
     manages PCycleCollectWithLogs;
     manages PDocAccessible;
     manages PDeviceStorageRequest;
     manages PFileSystemRequest;
     manages PExternalHelperApp;
     manages PFileDescriptorSet;
     manages PFMRadio;
     manages PHal;
-    manages PIcc;
     manages PMemoryReportRequest;
     manages PMobileConnection;
     manages PNecko;
     manages POfflineCacheUpdate;
     manages PPrinting;
     manages PScreenManager;
     manages PSms;
     manages PSpeechSynthesis;
@@ -641,18 +639,16 @@ parent:
 
     async GetSystemMemory(uint64_t getterId);
 
     sync IsSecureURI(uint32_t type, URIParams uri, uint32_t flags)
         returns (bool isSecureURI);
 
     PHal();
 
-    PIcc(uint32_t serviceId);
-
     PMobileConnection(uint32_t clientId);
 
     PNecko();
 
     PPrinting();
 
     prio(high) sync PScreenManager()
         returns (uint32_t numberOfScreens,
--- a/dom/ipc/preload.js
+++ b/dom/ipc/preload.js
@@ -70,16 +70,17 @@ const BrowserElementIsPreloaded = true;
   Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci["nsIScriptSecurityManager"]);
   Cc["@mozilla.org/storage/service;1"].getService(Ci["mozIStorageService"]);
   Cc["@mozilla.org/system-info;1"].getService(Ci["nsIPropertyBag2"]);
   Cc["@mozilla.org/thread-manager;1"].getService(Ci["nsIThreadManager"]);
   Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci["nsIAppStartup"]);
   Cc["@mozilla.org/uriloader;1"].getService(Ci["nsIURILoader"]);
   Cc["@mozilla.org/cspcontext;1"].createInstance(Ci["nsIContentSecurityPolicy"]);
   Cc["@mozilla.org/settingsManager;1"].createInstance(Ci["nsISupports"]);
+  Cc["@mozilla.org/webapps;1"].createInstance(Ci["nsISupports"]);
 
   /* Applications Specific Helper */
   try {
     if (Services.prefs.getBoolPref("dom.sysmsg.enabled")) {
       Cc["@mozilla.org/system-message-manager;1"].getService(Ci["nsIDOMNavigatorSystemMessages"]);
     }
   } catch(e) {
   }
new file mode 100644
--- /dev/null
+++ b/dom/media/AbstractThread.cpp
@@ -0,0 +1,44 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* 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 "AbstractThread.h"
+
+#include "MediaTaskQueue.h"
+#include "nsThreadUtils.h"
+
+namespace mozilla {
+
+template<>
+nsresult
+AbstractThreadImpl<MediaTaskQueue>::Dispatch(already_AddRefed<nsIRunnable> aRunnable)
+{
+  RefPtr<nsIRunnable> r(aRunnable);
+  return mTarget->ForceDispatch(r);
+}
+
+template<>
+nsresult
+AbstractThreadImpl<nsIThread>::Dispatch(already_AddRefed<nsIRunnable> aRunnable)
+{
+  nsCOMPtr<nsIRunnable> r = aRunnable;
+  return mTarget->Dispatch(r, NS_DISPATCH_NORMAL);
+}
+
+template<>
+bool
+AbstractThreadImpl<MediaTaskQueue>::IsCurrentThreadIn()
+{
+  return mTarget->IsCurrentThreadIn();
+}
+
+template<>
+bool
+AbstractThreadImpl<nsIThread>::IsCurrentThreadIn()
+{
+  return NS_GetCurrentThread() == mTarget;
+}
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/media/AbstractThread.h
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* 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/. */
+
+#if !defined(AbstractThread_h_)
+#define AbstractThread_h_
+
+#include "nscore.h"
+#include "nsIRunnable.h"
+#include "nsISupportsImpl.h"
+#include "nsIThread.h"
+#include "nsRefPtr.h"
+
+namespace mozilla {
+
+/*
+ * We often want to run tasks on a target that guarantees that events will never
+ * run in parallel. There are various target types that achieve this - namely
+ * nsIThread and MediaTaskQueue. Note that nsIThreadPool (which implements
+ * nsIEventTarget) does not have this property, so we do not want to use
+ * nsIEventTarget for this purpose. This class encapsulates the specifics of
+ * the structures we might use here and provides a consistent interface.
+ *
+ * Use AbstractThread::Create() to instantiate an AbstractThread. Note that
+ * if you use different types than the ones currently supported (MediaTaskQueue
+ * and nsIThread), you'll need to implement the relevant guts in
+ * AbstractThread.cpp to avoid linkage errors.
+ */
+class AbstractThread
+{
+public:
+  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AbstractThread);
+  virtual nsresult Dispatch(already_AddRefed<nsIRunnable> aRunnable) = 0;
+  virtual bool IsCurrentThreadIn() = 0;
+
+  template<typename TargetType> static AbstractThread* Create(TargetType* aTarget);
+protected:
+  virtual ~AbstractThread() {}
+};
+
+template<typename TargetType>
+class AbstractThreadImpl : public AbstractThread
+{
+public:
+  explicit AbstractThreadImpl(TargetType* aTarget) : mTarget(aTarget) {}
+  virtual nsresult Dispatch(already_AddRefed<nsIRunnable> aRunnable);
+  virtual bool IsCurrentThreadIn();
+private:
+  nsRefPtr<TargetType> mTarget;
+};
+
+template<typename TargetType>
+AbstractThread*
+AbstractThread::Create(TargetType* aTarget)
+{
+  return new AbstractThreadImpl<TargetType>(aTarget);
+};
+
+} // namespace mozilla
+
+#endif
deleted file mode 100644
--- a/dom/media/MediaPromise.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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 "MediaPromise.h"
-
-#include "MediaTaskQueue.h"
-#include "nsThreadUtils.h"
-
-namespace mozilla {
-namespace detail {
-
-nsresult
-DispatchMediaPromiseRunnable(MediaTaskQueue* aTaskQueue, nsIRunnable* aRunnable)
-{
-  return aTaskQueue->ForceDispatch(aRunnable);
-}
-
-nsresult
-DispatchMediaPromiseRunnable(nsIEventTarget* aEventTarget, nsIRunnable* aRunnable)
-{
-  return aEventTarget->Dispatch(aRunnable, NS_DISPATCH_NORMAL);
-}
-
-void
-AssertOnThread(MediaTaskQueue* aQueue)
-{
-  MOZ_ASSERT(aQueue->IsCurrentThreadIn());
-}
-
-void AssertOnThread(nsIEventTarget* aTarget)
-{
-  nsCOMPtr<nsIThread> targetThread = do_QueryInterface(aTarget);
-  MOZ_ASSERT(targetThread, "Don't know how to deal with threadpools etc here");
-  MOZ_ASSERT(NS_GetCurrentThread() == targetThread);
-}
-
-}
-} // namespace mozilla
--- a/dom/media/MediaPromise.h
+++ b/dom/media/MediaPromise.h
@@ -4,52 +4,40 @@
  * 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/. */
 
 #if !defined(MediaPromise_h_)
 #define MediaPromise_h_
 
 #include "prlog.h"
 
+#include "AbstractThread.h"
+
 #include "nsTArray.h"
 #include "nsThreadUtils.h"
 
 #include "mozilla/DebugOnly.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/Monitor.h"
 #include "mozilla/unused.h"
 
 /* Polyfill __func__ on MSVC for consumers to pass to the MediaPromise API. */
 #ifdef _MSC_VER
 #define __func__ __FUNCTION__
 #endif
 
-class nsIEventTarget;
 namespace mozilla {
 
 extern PRLogModuleInfo* gMediaPromiseLog;
 
 #define PROMISE_LOG(x, ...) \
   MOZ_ASSERT(gMediaPromiseLog); \
   PR_LOG(gMediaPromiseLog, PR_LOG_DEBUG, (x, ##__VA_ARGS__))
 
-class MediaTaskQueue;
-namespace detail {
-
-nsresult DispatchMediaPromiseRunnable(MediaTaskQueue* aQueue, nsIRunnable* aRunnable);
-nsresult DispatchMediaPromiseRunnable(nsIEventTarget* aTarget, nsIRunnable* aRunnable);
-
-#ifdef DEBUG
-void AssertOnThread(MediaTaskQueue* aQueue);
-void AssertOnThread(nsIEventTarget* aTarget);
-#endif
-
-} // namespace detail
-
 /*
  * A promise manages an asynchronous request that may or may not be able to be
  * fulfilled immediately. When an API returns a promise, the consumer may attach
  * callbacks to be invoked (asynchronously, on a specified thread) when the
  * request is either completed (resolved) or cannot be completed (rejected).
  *
  * When IsExclusive is true, the MediaPromise does a release-mode assertion that
  * there is at most one call to either Then(...) or ChainTo(...).
@@ -213,22 +201,21 @@ protected:
   }
 
   template<typename ThisType, typename ValueType>
   static void InvokeCallbackMethod(ThisType* aThisVal, void(ThisType::*aMethod)(), ValueType aValue)
   {
       ((*aThisVal).*aMethod)();
   }
 
-  template<typename TargetType, typename ThisType,
-           typename ResolveMethodType, typename RejectMethodType>
+  template<typename ThisType, typename ResolveMethodType, typename RejectMethodType>
   class ThenValue : public ThenValueBase
   {
   public:
-    ThenValue(TargetType* aResponseTarget, ThisType* aThisVal,
+    ThenValue(AbstractThread* aResponseTarget, ThisType* aThisVal,
               ResolveMethodType aResolveMethod, RejectMethodType aRejectMethod,
               const char* aCallSite)
       : ThenValueBase(aCallSite)
       , mResponseTarget(aResponseTarget)
       , mThisVal(aThisVal)
       , mResolveMethod(aResolveMethod)
       , mRejectMethod(aRejectMethod) {}
 
@@ -238,32 +225,32 @@ protected:
       MOZ_ASSERT(!aPromise->IsPending());
       bool resolved = aPromise->mResolveValue.isSome();
       nsRefPtr<nsRunnable> runnable =
         resolved ? static_cast<nsRunnable*>(new (typename ThenValueBase::ResolveRunnable)(this, aPromise->mResolveValue.ref()))
                  : static_cast<nsRunnable*>(new (typename ThenValueBase::RejectRunnable)(this, aPromise->mRejectValue.ref()));
       PROMISE_LOG("%s Then() call made from %s [Runnable=%p, Promise=%p, ThenValue=%p]",
                   resolved ? "Resolving" : "Rejecting", ThenValueBase::mCallSite,
                   runnable.get(), aPromise, this);
-      nsresult rv = detail::DispatchMediaPromiseRunnable(mResponseTarget, runnable);
-      unused << rv;
+      nsresult rv = mResponseTarget->Dispatch(runnable.forget());
 
       // NB: mDisconnected is only supposed to be accessed on the dispatch
       // thread. However, we require the consumer to have disconnected any
       // oustanding promise requests _before_ initiating shutdown on the
       // thread or task queue. So the only non-buggy scenario for dispatch
       // failing involves the target thread being unable to manipulate the
       // ThenValue (since it's been disconnected), so it's safe to read here.
       MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv) || Consumer::mDisconnected);
+      unused << rv;
     }
 
 #ifdef DEBUG
   void AssertOnDispatchThread()
   {
-    detail::AssertOnThread(mResponseTarget);
+    MOZ_ASSERT(mResponseTarget->IsCurrentThreadIn());
   }
 #else
   void AssertOnDispatchThread() {}
 #endif
 
   virtual void Disconnect() MOZ_OVERRIDE
   {
     AssertOnDispatchThread();
@@ -307,35 +294,34 @@ protected:
       // Null out mThisVal after invoking the callback so that any references are
       // released predictably on the dispatch thread. Otherwise, it would be
       // released on whatever thread last drops its reference to the ThenValue,
       // which may or may not be ok.
       mThisVal = nullptr;
     }
 
   private:
-    nsRefPtr<TargetType> mResponseTarget; // May be released on any thread.
+    nsRefPtr<AbstractThread> mResponseTarget; // May be released on any thread.
     nsRefPtr<ThisType> mThisVal; // Only accessed and refcounted on dispatch thread.
     ResolveMethodType mResolveMethod;
     RejectMethodType mRejectMethod;
   };
 public:
 
   template<typename TargetType, typename ThisType,
            typename ResolveMethodType, typename RejectMethodType>
   already_AddRefed<Consumer> RefableThen(TargetType* aResponseTarget, const char* aCallSite, ThisType* aThisVal,
                                          ResolveMethodType aResolveMethod, RejectMethodType aRejectMethod)
   {
     MutexAutoLock lock(mMutex);
     MOZ_DIAGNOSTIC_ASSERT(!IsExclusive || !mHaveConsumer);
     mHaveConsumer = true;
-    nsRefPtr<ThenValueBase> thenValue = new ThenValue<TargetType, ThisType, ResolveMethodType,
-                                                      RejectMethodType>(aResponseTarget, aThisVal,
-                                                                        aResolveMethod, aRejectMethod,
-                                                                        aCallSite);
+    nsRefPtr<AbstractThread> responseTarget = AbstractThread::Create(aResponseTarget);
+    nsRefPtr<ThenValueBase> thenValue = new ThenValue<ThisType, ResolveMethodType, RejectMethodType>(
+                                              responseTarget, aThisVal, aResolveMethod, aRejectMethod, aCallSite);
     PROMISE_LOG("%s invoking Then() [this=%p, thenValue=%p, aThisVal=%p, isPending=%d]",
                 aCallSite, this, thenValue.get(), aThisVal, (int) IsPending());
     if (!IsPending()) {
       thenValue->Dispatch(this);
     } else {
       mThenValues.AppendElement(thenValue);
     }
 
@@ -659,19 +645,20 @@ private:
   nsRefPtr<typename PromiseType::Private> mProxyPromise;
   nsAutoPtr<MethodCallBase<PromiseType>> mMethodCall;
 };
 
 template<typename PromiseType, typename TargetType>
 static nsRefPtr<PromiseType>
 ProxyInternal(TargetType* aTarget, MethodCallBase<PromiseType>* aMethodCall, const char* aCallerName)
 {
+  nsRefPtr<AbstractThread> target = AbstractThread::Create(aTarget);
   nsRefPtr<typename PromiseType::Private> p = new (typename PromiseType::Private)(aCallerName);
   nsRefPtr<ProxyRunnable<PromiseType>> r = new ProxyRunnable<PromiseType>(p, aMethodCall);
-  nsresult rv = detail::DispatchMediaPromiseRunnable(aTarget, r);
+  nsresult rv = target->Dispatch(r.forget());
   MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   unused << rv;
   return Move(p);
 }
 
 } // namespace detail
 
 template<typename PromiseType, typename TargetType, typename ThisType>
--- a/dom/media/moz.build
+++ b/dom/media/moz.build
@@ -76,16 +76,17 @@ XPIDL_SOURCES += [
     'nsIDOMNavigatorUserMedia.idl',
     'nsIMediaManager.idl',
 ]
 
 XPIDL_MODULE = 'dom_media'
 
 EXPORTS += [
     'AbstractMediaDecoder.h',
+    'AbstractThread.h',
     'AudioBufferUtils.h',
     'AudioChannelFormat.h',
     'AudioCompactor.h',
     'AudioMixer.h',
     'AudioSampleFormat.h',
     'AudioSegment.h',
     'AudioStream.h',
     'BufferMediaResource.h',
@@ -156,16 +157,17 @@ EXPORTS.mozilla.dom += [
     'TextTrackRegion.h',
     'VideoPlaybackQuality.h',
     'VideoStreamTrack.h',
     'VideoTrack.h',
     'VideoTrackList.h',
 ]
 
 UNIFIED_SOURCES += [
+    'AbstractThread.cpp',
     'AudioChannelFormat.cpp',
     'AudioCompactor.cpp',
     'AudioSegment.cpp',
     'AudioSink.cpp',
     'AudioStream.cpp',
     'AudioStreamTrack.cpp',
     'AudioTrack.cpp',
     'AudioTrackList.cpp',
@@ -178,17 +180,16 @@ UNIFIED_SOURCES += [
     'Latency.cpp',
     'MediaCache.cpp',
     'MediaData.cpp',
     'MediaDecoder.cpp',
     'MediaDecoderReader.cpp',
     'MediaDecoderStateMachine.cpp',
     'MediaDevices.cpp',
     'MediaManager.cpp',
-    'MediaPromise.cpp',
     'MediaRecorder.cpp',
     'MediaResource.cpp',
     'MediaShutdownManager.cpp',
     'MediaStreamError.cpp',
     'MediaStreamGraph.cpp',
     'MediaStreamTrack.cpp',
     'MediaTaskQueue.cpp',
     'MediaTimer.cpp',
--- a/dom/media/omx/MediaCodecReader.cpp
+++ b/dom/media/omx/MediaCodecReader.cpp
@@ -452,18 +452,23 @@ MediaCodecReader::DecodeAudioDataSync()
   }
   mAudioTrack.mCodec->releaseOutputBuffer(bufferInfo.mIndex);
 
 }
 
 void
 MediaCodecReader::DecodeAudioDataTask()
 {
-  DecodeAudioDataSync();
+  if (AudioQueue().GetSize() == 0 && !AudioQueue().IsFinished()) {
+    DecodeAudioDataSync();
+  }
   MonitorAutoLock al(mAudioTrack.mTrackMonitor);
+  if (mAudioTrack.mAudioPromise.IsEmpty()) {
+    return;
+  }
   if (AudioQueue().GetSize() > 0) {
     nsRefPtr<AudioData> a = AudioQueue().PopFront();
     if (a) {
       if (mAudioTrack.mDiscontinuity) {
         a->mDiscontinuity = true;
         mAudioTrack.mDiscontinuity = false;
       }
       mAudioTrack.mAudioPromise.Resolve(a, __func__);
--- a/dom/media/raw/RawReader.cpp
+++ b/dom/media/raw/RawReader.cpp
@@ -224,17 +224,16 @@ bool RawReader::DecodeVideoFrame(bool &a
                                             -1,
                                             ToIntRect(mPicture));
   if (!v)
     return false;
 
   mVideoQueue.Push(v);
   mCurrentFrame++;
   a.mDecoded++;
-  currentFrameTime += USECS_PER_S / mFrameRate;
 
   return true;
 }
 
 nsRefPtr<MediaDecoderReader::SeekPromise>
 RawReader::Seek(int64_t aTime, int64_t aEndTime)
 {
   nsresult res = SeekInternal(aTime);
--- a/dom/mobileconnection/MobileConnection.cpp
+++ b/dom/mobileconnection/MobileConnection.cpp
@@ -10,24 +10,27 @@
 #include "mozilla/dom/DataErrorEvent.h"
 #include "mozilla/dom/MozClirModeEvent.h"
 #include "mozilla/dom/MozEmergencyCbModeEvent.h"
 #include "mozilla/dom/MozOtaStatusEvent.h"
 #include "mozilla/dom/ToJSValue.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "nsIDOMDOMRequest.h"
-#include "nsIIccInfo.h"
 #include "nsIPermissionManager.h"
 #include "nsIVariant.h"
 #include "nsJSON.h"
 #include "nsJSUtils.h"
 #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")
 
 #ifdef CONVERT_STRING_TO_NULLABLE_ENUM
 #undef CONVERT_STRING_TO_NULLABLE_ENUM
 #endif
 #define CONVERT_STRING_TO_NULLABLE_ENUM(_string, _enumType, _enum)      \
 {                                                                       \
@@ -41,24 +44,28 @@
   }                                                                     \
 }
 
 using mozilla::ErrorResult;
 using namespace mozilla::dom;
 using namespace mozilla::dom::mobileconnection;
 
 class MobileConnection::Listener MOZ_FINAL : public nsIMobileConnectionListener
+#ifdef MOZ_B2G_RIL
                                            , public nsIIccListener
+#endif // MOZ_B2G_RIL
 {
   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)
   {
     MOZ_ASSERT(mMobileConnection);
   }
 
   void Disconnect()
@@ -69,38 +76,40 @@ public:
 
 private:
   ~Listener()
   {
     MOZ_ASSERT(!mMobileConnection);
   }
 };
 
+#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)
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MobileConnection,
                                                   DOMEventTargetHelper)
   // Don't traverse mListener because it doesn't keep any reference to
   // MobileConnection but a raw pointer instead. Neither does mMobileConnection
   // because it's an xpcom service owned object and is only released at shutting
   // 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,
                                                 DOMEventTargetHelper)
   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)
   // MobileConnection does not expose nsIMobileConnectionListener. mListener is
   // the exposed nsIMobileConnectionListener and forwards the calls it receives
   // to us.
 NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
 
@@ -122,57 +131,61 @@ MobileConnection::MobileConnection(nsPID
   // for it explicitly below.
   if (!service) {
     NS_WARNING("Could not acquire nsIMobileConnectionService!");
     return;
   }
 
   nsresult rv = service->GetItemByServiceId(mClientId,
                                             getter_AddRefs(mMobileConnection));
-
-  nsCOMPtr<nsIIccService> iccService = do_GetService(ICC_SERVICE_CONTRACTID);
+#ifdef MOZ_B2G_RIL
+  mIcc = do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
 
-  if (iccService) {
-    iccService->GetIccByServiceId(mClientId, getter_AddRefs(mIccHandler));
-  }
-
-  if (NS_FAILED(rv) || !mMobileConnection || !mIccHandler) {
-    NS_WARNING("Could not acquire nsIMobileConnection or nsIIcc!");
+  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;
   }
 
   mListener = new Listener(this);
   mVoice = new MobileConnectionInfo(GetOwner());
   mData = new MobileConnectionInfo(GetOwner());
 
   if (CheckPermission("mobileconnection")) {
     DebugOnly<nsresult> rv = mMobileConnection->RegisterListener(mListener);
     NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
                      "Failed registering mobile connection messages with service");
     UpdateVoice();
     UpdateData();
 
-    rv = mIccHandler->RegisterListener(mListener);
+#ifdef MOZ_B2G_RIL
+    rv = mIcc->RegisterIccMsg(mClientId, mListener);
     NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
                      "Failed registering icc messages with service");
     UpdateIccId();
+#endif // MOZ_B2G_RIL
   }
 }
 
 void
 MobileConnection::Shutdown()
 {
   if (mListener) {
     if (mMobileConnection) {
       mMobileConnection->UnregisterListener(mListener);
     }
 
-    if (mIccHandler) {
-      mIccHandler->UnregisterListener(mListener);
+#ifdef MOZ_B2G_RIL
+    if (mIcc) {
+      mIcc->UnregisterIccMsg(mClientId, mListener);
     }
+#endif // MOZ_B2G_RIL
 
     mListener->Disconnect();
     mListener = nullptr;
   }
 }
 
 MobileConnection::~MobileConnection()
 {
@@ -228,30 +241,32 @@ MobileConnection::UpdateData()
   nsCOMPtr<nsIMobileConnectionInfo> info;
   mMobileConnection->GetData(getter_AddRefs(info));
   mData->Update(info);
 }
 
 bool
 MobileConnection::UpdateIccId()
 {
+#ifdef MOZ_B2G_RIL
   nsAutoString iccId;
   nsCOMPtr<nsIIccInfo> iccInfo;
-  if (mIccHandler &&
-      NS_SUCCEEDED(mIccHandler->GetIccInfo(getter_AddRefs(iccInfo))) &&
+  if (mIcc &&
+      NS_SUCCEEDED(mIcc->GetIccInfo(mClientId, getter_AddRefs(iccInfo))) &&
       iccInfo) {
     iccInfo->GetIccid(iccId);
   } else {
     iccId.SetIsVoid(true);
   }
 
   if (!mIccId.Equals(iccId)) {
     mIccId = iccId;
     return true;
   }
+#endif // MOZ_B2G_RIL
 
   return false;
 }
 
 nsresult
 MobileConnection::NotifyError(nsIDOMDOMRequest* aRequest, const nsAString& aMessage)
 {
   nsCOMPtr<nsIDOMRequestService> rs = do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
@@ -1114,16 +1129,17 @@ MobileConnection::NotifyLastKnownHomeNet
 }
 
 NS_IMETHODIMP
 MobileConnection::NotifyNetworkSelectionModeChanged()
 {
   return NS_OK;
 }
 
+#ifdef MOZ_B2G_RIL
 // nsIIccListener
 
 NS_IMETHODIMP
 MobileConnection::NotifyStkCommand(const nsAString& aMessage)
 {
   return NS_OK;
 }
 
@@ -1150,8 +1166,9 @@ MobileConnection::NotifyIccInfoChanged()
     return NS_OK;
   }
 
   nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
     new AsyncEventDispatcher(this, NS_LITERAL_STRING("iccchange"), false);
 
   return asyncDispatcher->PostDOMEvent();
 }
+#endif // MOZ_B2G_RIL
--- a/dom/mobileconnection/MobileConnection.h
+++ b/dom/mobileconnection/MobileConnection.h
@@ -6,41 +6,48 @@
 #define mozilla_dom_MobileConnection_h
 
 #include "mozilla/DOMEventTargetHelper.h"
 #include "mozilla/dom/DOMRequest.h"
 #include "mozilla/dom/MobileConnectionInfo.h"
 #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 MOZ_FINAL : public DOMEventTargetHelper
                                  , private nsIMobileConnectionListener
+#ifdef MOZ_B2G_RIL
                                  , private nsIIccListener
+#endif // MOZ_B2G_RIL
 {
   /**
    * Class MobileConnection doesn't actually expose
    * nsIMobileConnectionListener. Instead, it owns an
    * nsIMobileConnectionListener derived instance mListener and passes it to
    * nsIMobileConnectionService. The onreceived events are first delivered to
    * mListener and then forwarded to its owner, MobileConnection. See also bug
    * 775997 comment #51.
    */
   class Listener;
 
 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)
 
   MobileConnection(nsPIDOMWindow *aWindow, uint32_t aClientId);
 
   void
   Shutdown();
@@ -157,17 +164,19 @@ public:
 
 private:
   ~MobileConnection();
 
 private:
   uint32_t mClientId;
   nsString mIccId;
   nsCOMPtr<nsIMobileConnection> mMobileConnection;
-  nsCOMPtr<nsIIcc> mIccHandler;
+#ifdef MOZ_B2G_RIL
+  nsCOMPtr<nsIIccProvider> mIcc;
+#endif // MOZ_B2G_RIL
   nsRefPtr<Listener> mListener;
   nsRefPtr<MobileConnectionInfo> mVoice;
   nsRefPtr<MobileConnectionInfo> mData;
 
   bool
   CheckPermission(const char* aType) const;
 
   void
--- a/dom/mobilemessage/gonk/MmsService.js
+++ b/dom/mobilemessage/gonk/MmsService.js
@@ -401,17 +401,17 @@ MmsConnection.prototype = {
     if (!this.connected) {
       this.pendingCallbacks.push(callback);
 
       let errorStatus;
       if (getRadioDisabledState()) {
         if (DEBUG) debug("Error! Radio is disabled when sending MMS.");
         errorStatus = _HTTP_STATUS_RADIO_DISABLED;
       } else if (this.radioInterface.rilContext.cardState !=
-                 Ci.nsIIcc.CARD_STATE_READY) {
+                 Ci.nsIIccProvider.CARD_STATE_READY) {
         if (DEBUG) debug("Error! SIM card is not ready when sending MMS.");
         errorStatus = _HTTP_STATUS_NO_SIM_CARD;
       }
       if (errorStatus != null) {
         this.flushPendingCallbacks(errorStatus);
         return true;
       }
 
--- a/dom/mobilemessage/gonk/SmsService.js
+++ b/dom/mobilemessage/gonk/SmsService.js
@@ -875,17 +875,17 @@ SmsService.prototype = {
       if (!gPhoneNumberUtils.isPlainPhoneNumber(options.number)) {
         if (DEBUG) debug("Error! Address is invalid when sending SMS: " + options.number);
         errorCode = Ci.nsIMobileMessageCallback.INVALID_ADDRESS_ERROR;
       } else if (radioState == Ci.nsIMobileConnection.MOBILE_RADIO_STATE_UNKNOWN ||
                  radioState == Ci.nsIMobileConnection.MOBILE_RADIO_STATE_DISABLED) {
         if (DEBUG) debug("Error! Radio is disabled when sending SMS.");
         errorCode = Ci.nsIMobileMessageCallback.RADIO_DISABLED_ERROR;
       } else if (gRadioInterfaces[aServiceId].rilContext.cardState !=
-                 Ci.nsIIcc.CARD_STATE_READY) {
+                 Ci.nsIIccProvider.CARD_STATE_READY) {
         if (DEBUG) debug("Error! SIM card is not ready when sending SMS.");
         errorCode = Ci.nsIMobileMessageCallback.NO_SIM_CARD_ERROR;
       }
       if (errorCode) {
         if (aSilent) {
           aRequest.notifySendMessageFailed(errorCode, aSendingMessage);
           return;
         }
--- a/dom/mobilemessage/tests/marionette/head.js
+++ b/dom/mobilemessage/tests/marionette/head.js
@@ -106,62 +106,32 @@ function waitForManagerEvent(aEventName,
     manager.removeEventListener(aEventName, onevent);
     deferred.resolve(aEvent);
   });
 
   return deferred.promise;
 }
 
 /**
- * Wrap DOMRequest onsuccess/onerror events to Promise resolve/reject.
- *
- * Fulfill params: A DOMEvent.
- * Reject params: A DOMEvent.
- *
- * @param aRequest
- *        A DOMRequest instance.
- *
- * @return A deferred promise.
- */
-function wrapDomRequestAsPromise(aRequest) {
-  let deferred = Promise.defer();
-
-  ok(aRequest instanceof DOMRequest,
-     "aRequest is instanceof " + aRequest.constructor);
-
-  aRequest.addEventListener("success", function(aEvent) {
-    deferred.resolve(aEvent);
-  });
-  aRequest.addEventListener("error", function(aEvent) {
-    deferred.reject(aEvent);
-  });
-
-  return deferred.promise;
-}
-
-/**
  * Send a SMS message to a single receiver.  Resolve if it succeeds, reject
  * otherwise.
  *
  * Fulfill params:
  *   message -- the sent SmsMessage.
  *
  * Reject params:
  *   error -- a DOMError.
  *
  * @param aReceiver the address of the receiver.
  * @param aText the text body of the message.
  *
  * @return A deferred promise.
  */
 function sendSmsWithSuccess(aReceiver, aText) {
-  let request = manager.send(aReceiver, aText);
-  return wrapDomRequestAsPromise(request)
-    .then((aEvent) => { return aEvent.target.result; },
-          (aEvent) => { throw aEvent.target.error; });
+  return manager.send(aReceiver, aText);
 }
 
 /**
  * Send a SMS message to a single receiver.
  * Resolve if it fails, reject otherwise.
  *
  * Fulfill params:
  *   {
@@ -175,21 +145,19 @@ function sendSmsWithSuccess(aReceiver, a
  * @param aText the text body of the message.
  *
  * @return A deferred promise.
  */
 function sendSmsWithFailure(aReceiver, aText) {
   let promises = [];
   promises.push(waitForManagerEvent("failed")
     .then((aEvent) => { return aEvent.message; }));
-
-  let request = manager.send(aReceiver, aText);
-  promises.push(wrapDomRequestAsPromise(request)
-    .then((aEvent) => { throw aEvent; },
-          (aEvent) => { return aEvent.target.error; }));
+  promises.push(manager.send(aReceiver, aText)
+    .then((aResult) => { throw aResult; },
+          (aError) => { return aError; }));
 
   return Promise.all(promises)
     .then((aResults) => { return { message: aResults[0],
                                    error: aResults[1] }; });
 }
 
 /**
  * Send a MMS message with specified parameters.  Resolve if it fails, reject
@@ -208,21 +176,19 @@ function sendSmsWithFailure(aReceiver, a
  * @param aSendParameters a MmsSendParameters instance.
  *
  * @return A deferred promise.
  */
 function sendMmsWithFailure(aMmsParameters, aSendParameters) {
   let promises = [];
   promises.push(waitForManagerEvent("failed")
     .then((aEvent) => { return aEvent.message; }));
-
-  let request = manager.sendMMS(aMmsParameters, aSendParameters);
-  promises.push(wrapDomRequestAsPromise(request)
-    .then((aEvent) => { throw aEvent; },
-          (aEvent) => { return aEvent.target.error; }));
+  promises.push(manager.sendMMS(aMmsParameters, aSendParameters)
+    .then((aResult) => { throw aResult; },
+          (aError) => { return aError; }));
 
   return Promise.all(promises)
     .then((aResults) => { return { message: aResults[0],
                                    error: aResults[1] }; });
 }
 
 /**
  * Retrieve message by message id.
@@ -232,19 +198,17 @@ function sendMmsWithFailure(aMmsParamete
  *   event -- a DOMEvent
  *
  * @param aId
  *        A numeric message id.
  *
  * @return A deferred promise.
  */
 function getMessage(aId) {
-  let request = manager.getMessage(aId);
-  return wrapDomRequestAsPromise(request)
-    .then((aEvent) => { return aEvent.target.result; });
+  return manager.getMessage(aId);
 }
 
 /**
  * Retrieve messages from database.
  *
  * Fulfill params:
  *   messages -- an array of {Sms,Mms}Message instances.
  *
@@ -366,24 +330,22 @@ function getThreadById(aThreadId) {
 function deleteMessagesById(aMessageIds) {
   if (!aMessageIds.length) {
     ok(true, "no message to be deleted");
     return [];
   }
 
   let promises = [];
   promises.push(waitForManagerEvent("deleted"));
-
-  let request = manager.delete(aMessageIds);
-  promises.push(wrapDomRequestAsPromise(request));
+  promises.push(manager.delete(aMessageIds));
 
   return Promise.all(promises)
     .then((aResults) => {
       return { deletedInfo: aResults[0],
-               deletedFlags: aResults[1].target.result };
+               deletedFlags: aResults[1] };
     });
 }
 
 /**
  * Delete messages specified from database.
  *
  * Fulfill params:
  *   result -- an array of boolean values indicating whether delesion was
--- a/dom/mobilemessage/tests/marionette/test_getmessage_notfound.js
+++ b/dom/mobilemessage/tests/marionette/test_getmessage_notfound.js
@@ -8,34 +8,32 @@ const TEXT = "Incoming SMS message. Mozi
 const REMOTE = "5559997777";
 
 function getNonExistentMsg(aId) {
   log("Attempting to get non-existent message (id: " + aId + ").");
 
   return getMessage(aId)
     .then(function onresolve() {
       ok(false, "request succeeded when tried to get non-existent sms");
-    }, function onreject(aEvent) {
-      let error = aEvent.target.error;
-      ok(error, "DOMError");
-      is(error.name, "NotFoundError", "error.name");
+    }, function onreject(aError) {
+      ok(aError, "DOMError");
+      is(aError.name, "NotFoundError", "error.name");
     });
 }
 
 function getMsgInvalidId(aId) {
   log("Attempting to get sms with invalid id (id: " + aId + ").");
 
   return getMessage(aId)
     .then(function onresolve() {
       ok(false, "request succeeded when tried to get message with " +
                 "invalid id (id: " + aId + ").");
-    }, function onreject(aEvent) {
-      let error = aEvent.target.error;
-      ok(error, "DOMError");
-      is(error.name, "NotFoundError", "error.name");
+    }, function onreject(aError) {
+      ok(aError, "DOMError");
+      is(aError.name, "NotFoundError", "error.name");
     });
 }
 
 startTestBase(function testCaseMain() {
   let lastMessageId;
 
   return ensureMobileMessage()
 
--- a/dom/mobilemessage/tests/marionette/test_getsegmentinfofortext.js
+++ b/dom/mobilemessage/tests/marionette/test_getsegmentinfofortext.js
@@ -8,26 +8,24 @@ MARIONETTE_HEAD_JS = 'head.js';
 const PDU_MAX_USER_DATA_7BIT = 160;
 
 function test(text, segments, charsPerSegment, charsAvailableInLastSegment) {
   log("Testing '" + text + "' ...");
 
   let domRequest = manager.getSegmentInfoForText(text);
   ok(domRequest, "DOMRequest object returned.");
 
-  return wrapDomRequestAsPromise(domRequest)
-    .then(function(aEvent) {
-      let result = aEvent.target.result;
-      ok(result, "aEvent.target.result = " + JSON.stringify(result));
+  return domRequest.then(function(aResult) {
+    ok(aResult, "result = " + JSON.stringify(aResult));
 
-      is(result.segments, segments, "result.segments");
-      is(result.charsPerSegment, charsPerSegment, "result.charsPerSegment");
-      is(result.charsAvailableInLastSegment, charsAvailableInLastSegment,
-         "result.charsAvailableInLastSegment");
-    });
+    is(aResult.segments, segments, "result.segments");
+    is(aResult.charsPerSegment, charsPerSegment, "result.charsPerSegment");
+    is(aResult.charsAvailableInLastSegment, charsAvailableInLastSegment,
+       "result.charsAvailableInLastSegment");
+  });
 }
 
 startTestCommon(function() {
   // Ensure we always begin with strict 7bit encoding set to false.
   return pushPrefEnv({ set: [["dom.sms.strict7BitEncoding", false]] })
 
     .then(() => test(null,      1, PDU_MAX_USER_DATA_7BIT, (PDU_MAX_USER_DATA_7BIT - "null".length)))
     .then(() => test(undefined, 1, PDU_MAX_USER_DATA_7BIT, (PDU_MAX_USER_DATA_7BIT - "undefined".length)))
--- a/dom/mobilemessage/tests/marionette/test_massive_incoming_delete.js
+++ b/dom/mobilemessage/tests/marionette/test_massive_incoming_delete.js
@@ -1,217 +1,81 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
-MARIONETTE_TIMEOUT = 60000;
-
-SpecialPowers.setBoolPref("dom.sms.enabled", true);
-SpecialPowers.addPermission("sms", true, document);
+MARIONETTE_TIMEOUT = 90000;
+MARIONETTE_HEAD_JS = "head.js";
 
 const SENDER = "5555552368"; // the remote number
 const RECEIVER = "15555215554"; // the emulator's number
-
-let manager = window.navigator.mozMobileMessage;
-let MSG_TEXT = "Mozilla Firefox OS!";
-let SMS_NUMBER = 100;
+const MSG_TEXT = "Mozilla Firefox OS!";
+const SMS_NUMBER = 100;
 
 let SmsList = [];
-let checkDone = true;
-let emulatorReady = true;
-
-let pendingEmulatorCmdCount = 0;
-function sendSmsToEmulator(from, text) {
-  ++pendingEmulatorCmdCount;
-
-  let cmd = "sms send " + from + " " + text;
-  runEmulatorCmd(cmd, function(result) {
-    --pendingEmulatorCmdCount;
-
-    is(result[0], "OK", "Emulator response");
-  });
-}
 
-let tasks = {
-  // List of test fuctions. Each of them should call |tasks.next()| when
-  // completed or |tasks.finish()| to jump to the last one.
-  _tasks: [],
-  _nextTaskIndex: 0,
-
-  push: function(func) {
-    this._tasks.push(func);
-  },
+function sendAllSms() {
+  log("Send " + SMS_NUMBER + " SMS");
 
-  next: function() {
-    let index = this._nextTaskIndex++;
-    let task = this._tasks[index];
-    try {
-      task();
-    } catch (ex) {
-      ok(false, "test task[" + index + "] throws: " + ex);
-      // Run last task as clean up if possible.
-      if (index != this._tasks.length - 1) {
-        this.finish();
-      }
-    }
-  },
+  let promises = [];
 
-  finish: function() {
-    this._tasks[this._tasks.length - 1]();
-  },
-
-  run: function() {
-    this.next();
-  }
-};
-
-function taskNextWrapper() {
-  tasks.next();
-}
-
-function verifySmsExists(incomingSms) {
-  log("Getting SMS (id: " + incomingSms.id + ").");
-  let requestRet = manager.getMessage(incomingSms.id);
-  ok(requestRet, "smsrequest obj returned");
+  // Wait for all "received" event are received.
+  promises.push(waitForManagerEvent("received", function(aEvent) {
+    let message = aEvent.message;
+    log("Received 'onreceived' event.");
+    ok(message, "incoming sms");
+    ok(message.id, "sms id");
+    log("Received SMS (id: " + message.id + ").");
+    ok(message.threadId, "thread id");
+    is(message.body, MSG_TEXT, "msg body");
+    is(message.delivery, "received", "delivery");
+    is(message.deliveryStatus, "success", "deliveryStatus");
+    is(message.read, false, "read");
+    is(message.receiver, RECEIVER, "receiver");
+    is(message.sender, SENDER, "sender");
+    is(message.messageClass, "normal", "messageClass");
+    is(message.deliveryTimestamp, 0, "deliveryTimestamp is 0");
+    SmsList.push(message);
+    return SmsList.length === SMS_NUMBER;
+  }));
 
-  requestRet.onsuccess = function(event) {
-    log("Received 'onsuccess' smsrequest event.");
-    ok(event.target.result, "smsrequest event.target.result");
-    let foundSms = event.target.result;
-    is(foundSms.id, incomingSms.id, "found SMS id matches");
-    is(foundSms.threadId, incomingSms.threadId, "found SMS thread id matches");
-    is(foundSms.body, MSG_TEXT, "found SMS msg text matches");
-    is(foundSms.delivery, "received", "delivery");
-    is(foundSms.deliveryStatus, "success", "deliveryStatus");
-    is(foundSms.read, false, "read");
-    is(foundSms.receiver, RECEIVER, "receiver");
-    is(foundSms.sender, SENDER, "sender");
-    is(foundSms.messageClass, "normal", "messageClass");
-    log("Got SMS (id: " + foundSms.id + ") as expected.");
+  // Generate massive incoming message.
+  for (let i = 0; i < SMS_NUMBER; i++) {
+    promises.push(sendTextSmsToEmulator(SENDER, MSG_TEXT));
+  }
 
-    SmsList.push(incomingSms);
-  };
-
-  requestRet.onerror = function(event) {
-    log("Received 'onerror' smsrequest event.");
-    ok(event.target.error, "domerror obj");
-    is(event.target.error.name, "NotFoundError", "error returned");
-    log("Could not get SMS (id: " + incomingSms.id + ") but should have.");
-    ok(false,"SMS was not found");
-    tasks.finish();
-  };
+  return Promise.all(promises);
 }
 
-let verifDeletedCount = 0;
-function verifySmsDeleted(smsId) {
-  log("Getting SMS (id: " + smsId + ").");
-  let requestRet = manager.getMessage(smsId);
-  ok(requestRet, "smsrequest obj returned");
+function deleteAllSms() {
+  log("Deleting SMS: " + JSON.stringify(SmsList));
+
+  let deleteStart = Date.now();
+  return deleteMessages(SmsList)
+    .then(() => {
+      let deleteDone = Date.now();
+      log("Delete " + SmsList.length + " SMS takes " +
+          (deleteDone - deleteStart) + " ms.");
+    })
+    // Verify SMS Deleted
+    .then(() => {
+      let promises = [];
 
-  requestRet.onsuccess = function(event) {
-    log("Received 'onsuccess' smsrequest event.");
-    ok(event.target.result, "smsrequest event.target.result");
-    let foundSms = event.target.result;
-    is(foundSms.id, smsId, "found SMS id matches");
-    is(foundSms.body, MSG_TEXT, "found SMS msg text matches");
-    log("Got SMS (id: " + foundSms.id + ") but should not have.");
-    ok(false, "SMS was not deleted");
-    tasks.finish();
-  };
+      for (let i = 0; i < SmsList.length; i++) {
+        let smsId = SmsList[i].id;
+        promises.push(getMessage(smsId)
+          .then((aMessageInDB) => {
+            log("Got SMS (id: " + aMessageInDB.id + ") but should not have.");
+            ok(false, "SMS (id: " + aMessageInDB.id + ") was not deleted");
+          }, (aError) => {
+            log("Could not get SMS (id: " + smsId + ") as expected.");
+            is(aError.name, "NotFoundError", "error returned");
+          }));
+      }
 
-  requestRet.onerror = function(event) {
-    log("Received 'onerror' smsrequest event.");
-    ok(event.target.error, "domerror obj");
-    is(event.target.error.name, "NotFoundError", "error returned");
-    log("Could not get SMS (id: " + smsId + ") as expected.");
-    verifDeletedCount++;
-  };
+      return Promise.all(promises);
+    });
 }
 
-tasks.push(function init() {
-  log("Initialize test object.");
-  ok(manager instanceof MozMobileMessageManager,
-     "manager is instance of " + manager.constructor);
-
-  // Callback for incoming sms
-  manager.onreceived = function onreceived(event) {
-    log("Received 'onreceived' event.");
-    let incomingSms = event.message;
-    ok(incomingSms, "incoming sms");
-    ok(incomingSms.id, "sms id");
-    log("Received SMS (id: " + incomingSms.id + ").");
-    ok(incomingSms.threadId, "thread id");
-    is(incomingSms.body, MSG_TEXT, "msg body");
-    is(incomingSms.delivery, "received", "delivery");
-    is(incomingSms.deliveryStatus, "success", "deliveryStatus");
-    is(incomingSms.read, false, "read");
-    is(incomingSms.receiver, RECEIVER, "receiver");
-    is(incomingSms.sender, SENDER, "sender");
-    is(incomingSms.messageClass, "normal", "messageClass");
-    is(incomingSms.deliveryTimestamp, 0, "deliveryTimestamp is 0");
-
-    verifySmsExists(incomingSms);
-  };
-
-  tasks.next();
-});
-
-tasks.push(function sendAllSms() {
-  log("Send " + SMS_NUMBER + " SMS");
-  for (let i = 0; i < SMS_NUMBER; i++) {
-    sendSmsToEmulator(SENDER, MSG_TEXT);
-  }
-
-  waitFor(taskNextWrapper, function() {
-    return (pendingEmulatorCmdCount === 0) && (SmsList.length === SMS_NUMBER);
-  });
+// Start the test
+startTestCommon(function testCaseMain() {
+  return sendAllSms()
+    .then(() => deleteAllSms());
 });
-
-tasks.push(function deleteAllSms() {
-  log("Deleting SMS using smsmsg obj array parameter.");
-  let deleteStart = Date.now();
-  log("deleteStart: " + deleteStart);
-  log("SmsList: " + JSON.stringify(SmsList));
-  let requestRet = manager.delete(SmsList);
-  ok(requestRet,"smsrequest obj returned");
-
-  requestRet.onsuccess = function(event) {
-    let deleteDone = Date.now();
-    log("Delete " + SMS_NUMBER + " SMS takes " + (deleteDone - deleteStart) + " ms.");
-    log("Received 'onsuccess' smsrequest event.");
-    if (event.target.result) {
-      for (let i = 0; i < SmsList.length; i++) {
-        verifySmsDeleted(SmsList[i].id);
-      }
-    } else {
-      log("smsrequest returned false for manager.delete");
-      ok(false, "SMS delete failed");
-    }
-  };
-
-  requestRet.onerror = function(event) {
-    log("Received 'onerror' smsrequest event.");
-    ok(event.target.error, "domerror obj");
-    ok(false, "manager.delete request returned unexpected error: "
-        + event.target.error.name);
-    tasks.finish();
-  };
-
-  waitFor(taskNextWrapper, function() {
-    return verifDeletedCount === SMS_NUMBER;
-  });
-});
-
-// WARNING: All tasks should be pushed before this!!!
-tasks.push(function cleanUp() {
-  if (pendingEmulatorCmdCount) {
-    window.setTimeout(cleanUp, 100);
-    return;
-  }
-
-  manager.onreceived = null;
-  SpecialPowers.removePermission("sms", document);
-  SpecialPowers.clearUserPref("dom.sms.enabled");
-  log("Finish!!!");
-  finish();
-});
-
-// Start the test
-tasks.run();
--- a/dom/mobilemessage/tests/marionette/test_outgoing.js
+++ b/dom/mobilemessage/tests/marionette/test_outgoing.js
@@ -98,34 +98,32 @@ function doSingleRequest(aRequest, aRece
 
       ok(sendingGot, "sending event should have been triggered");
       ok(!sentGot, "sent event should not have been triggered");
       ok(successGot, "success event should have been triggered");
 
       sentGot = true;
     }));
 
-  promises.push(wrapDomRequestAsPromise(aRequest)
-    .then(function(aEvent) {
-      log("  onsuccess event for '" + aReceiver + "' received.");
+  promises.push(aRequest.then(function(aResult) {
+    log("  onsuccess event for '" + aReceiver + "' received.");
 
-      let message = aEvent.target.result;
-      checkMessage(message, "sent", aBody);
-      // Should be mostly identical to sendingMessage.
-      is(message.id, sendingMessage.id, "message.id");
-      is(message.receiver, sendingMessage.receiver, "message.receiver");
-      is(message.body, sendingMessage.body, "message.body");
-      is(message.timestamp, sendingMessage.timestamp, "message.timestamp");
+    checkMessage(aResult, "sent", aBody);
+    // Should be mostly identical to sendingMessage.
+    is(aResult.id, sendingMessage.id, "message.id");
+    is(aResult.receiver, sendingMessage.receiver, "message.receiver");
+    is(aResult.body, sendingMessage.body, "message.body");
+    is(aResult.timestamp, sendingMessage.timestamp, "message.timestamp");
 
-      ok(sendingGot, "sending event should have been triggered");
-      ok(!sentGot, "sent event should not have been triggered");
-      ok(!successGot, "success event should not have been triggered");
+    ok(sendingGot, "sending event should have been triggered");
+    ok(!sentGot, "sent event should not have been triggered");
+    ok(!successGot, "success event should not have been triggered");
 
-      successGot = true;
-    }));
+    successGot = true;
+  }));
 
   return Promise.all(promises);
 }
 
 function doSendMessageAndCheckSuccess(receivers, body) {
   log("Testing sending message(s) to receiver(s): " + JSON.stringify(receivers));
 
   let now = Date.now();
--- a/dom/mobilemessage/tests/marionette/test_segment_info.js
+++ b/dom/mobilemessage/tests/marionette/test_segment_info.js
@@ -18,26 +18,24 @@ function times(str, n) {
 function test(text, segments, charsPerSegment, charsAvailableInLastSegment) {
   // 'text' may contain non-ascii characters, so we're not going to print it on
   // Marionette console to avoid breaking it.
   ok(true, "Testing '" + text + "' ...");
 
   let domRequest = manager.getSegmentInfoForText(text);
   ok(domRequest, "DOMRequest object returned.");
 
-  return wrapDomRequestAsPromise(domRequest)
-    .then(function(aEvent) {
-      let result = aEvent.target.result;
-      ok(result, "aEvent.target.result = " + JSON.stringify(result));
+  return domRequest.then(function(aResult) {
+    ok(aResult, "result = " + JSON.stringify(aResult));
 
-      is(result.segments, segments, "result.segments");
-      is(result.charsPerSegment, charsPerSegment, "result.charsPerSegment");
-      is(result.charsAvailableInLastSegment, charsAvailableInLastSegment,
-         "result.charsAvailableInLastSegment");
-    });
+    is(aResult.segments, segments, "result.segments");
+    is(aResult.charsPerSegment, charsPerSegment, "result.charsPerSegment");
+    is(aResult.charsAvailableInLastSegment, charsAvailableInLastSegment,
+       "result.charsAvailableInLastSegment");
+  });
 }
 
 startTestCommon(function() {
   // Ensure we always begin with strict 7bit encoding set to false.
   return pushPrefEnv({ set: [["dom.sms.strict7BitEncoding", false]] })
 
     // GSM 7Bit Alphabets:
     //
--- a/dom/moz.build
+++ b/dom/moz.build
@@ -59,17 +59,16 @@ DIRS += [
     'encoding',
     'events',
     'fetch',
     'filehandle',
     'filesystem',
     'fmradio',
     'geolocation',
     'html',
-    'icc',
     'json',
     'jsurl',
     'asmjscache',
     'mathml',
     'media',
     'messages',
     'mobileconnection',
     'notification',
@@ -118,16 +117,17 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk
     DIRS += [
         'speakermanager',
         'tethering',
         'wifi',
     ]
 
 if CONFIG['MOZ_B2G_RIL']:
     DIRS += [
+        'icc',
         'wappush',
     ]
 
 if CONFIG['MOZ_PAY']:
     DIRS += ['payment']
 
 if CONFIG['MOZ_GAMEPAD']:
     DIRS += ['gamepad']
--- a/dom/phonenumberutils/PhoneNumberUtils.jsm
+++ b/dom/phonenumberutils/PhoneNumberUtils.jsm
@@ -18,19 +18,19 @@ XPCOMUtils.defineLazyModuleGetter(this, 
                                   "resource://gre/modules/PhoneNumberNormalizer.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "MCC_ISO3166_TABLE",
                                   "resource://gre/modules/mcc_iso3166_table.jsm");
 
 #ifdef MOZ_B2G_RIL
 XPCOMUtils.defineLazyServiceGetter(this, "mobileConnection",
                                    "@mozilla.org/mobileconnection/mobileconnectionservice;1",
                                    "nsIMobileConnectionService");
-XPCOMUtils.defineLazyServiceGetter(this, "gIccService",
-                                   "@mozilla.org/icc/iccservice;1",
-                                   "nsIIccService");
+XPCOMUtils.defineLazyServiceGetter(this, "icc",
+                                   "@mozilla.org/ril/content-helper;1",
+                                   "nsIIccProvider");
 #endif
 
 this.PhoneNumberUtils = {
   init: function() {
     ppmm.addMessageListener(["PhoneNumberService:FuzzyMatch"], this);
   },
   //  1. See whether we have a network mcc
   //  2. If we don't have that, look for the simcard mcc
@@ -41,33 +41,32 @@ this.PhoneNumberUtils = {
   _mcc: '724',
 
   getCountryName: function getCountryName() {
     let mcc;
     let countryName;
 
 #ifdef MOZ_B2G_RIL
     // TODO: Bug 926740 - PhoneNumberUtils for multisim
-    // In Multi-sim, there is more than one client in
-    // iccService/mobileConnectionService. Each client represents a
+    // In Multi-sim, there is more than one client in 
+    // iccProvider/mobileConnectionProvider. 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.
     let clientId = 0;
 
     // Get network mcc
     let connection = mobileConnection.getItemByServiceId(clientId);
     let voice = connection && connection.voice;
     if (voice && voice.network && voice.network.mcc) {
       mcc = voice.network.mcc;
     }
 
     // Get SIM mcc
-    let icc = gIccService.getIccByServiceId(clientId);
-    let iccInfo = icc && icc.iccInfo;
+    let iccInfo = icc.getIccInfo(clientId);
     if (!mcc && iccInfo && iccInfo.mcc) {
       mcc = iccInfo.mcc;
     }
 
     // Attempt to grab last known sim mcc from prefs
     if (!mcc) {
       try {
         mcc = Services.prefs.getCharPref("ril.lastKnownSimMcc");
--- a/dom/plugins/base/nsPluginHost.cpp
+++ b/dom/plugins/base/nsPluginHost.cpp
@@ -806,34 +806,38 @@ nsPluginHost::InstantiatePluginInstance(
   nsresult rv = instanceOwner->Init(ourContent);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   nsPluginTagType tagType;
   rv = instanceOwner->GetTagType(&tagType);
   if (NS_FAILED(rv)) {
+    instanceOwner->Destroy();
     return rv;
   }
 
   if (tagType != nsPluginTagType_Embed &&
       tagType != nsPluginTagType_Applet &&
       tagType != nsPluginTagType_Object) {
+    instanceOwner->Destroy();
     return NS_ERROR_FAILURE;
   }
 
   rv = SetUpPluginInstance(aMimeType, aURL, instanceOwner);
   if (NS_FAILED(rv)) {
+    instanceOwner->Destroy();
     return NS_ERROR_FAILURE;
   }
   const bool isAsyncInit = (rv == NS_PLUGIN_INIT_PENDING);
 
   nsRefPtr<nsNPAPIPluginInstance> instance;
   rv = instanceOwner->GetInstance(getter_AddRefs(instance));
   if (NS_FAILED(rv)) {
+    instanceOwner->Destroy();
     return rv;
   }
 
   // Async init plugins will initiate their own widget creation.
   if (!isAsyncInit && instance) {
     CreateWidget(instanceOwner);
   }
 
--- a/dom/push/PushService.jsm
+++ b/dom/push/PushService.jsm
@@ -1770,25 +1770,24 @@ this.PushService = {
     try {
       if (!prefs.get("udp.wakeupEnabled")) {
         debug("UDP support disabled, we do not send any carrier info");
         throw new Error("UDP disabled");
       }
 
       let nm = Cc["@mozilla.org/network/manager;1"].getService(Ci.nsINetworkManager);
       if (nm.active && nm.active.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE) {
-        let iccService = Cc["@mozilla.org/icc/iccservice;1"].getService(Ci.nsIIccService);
+        let icc = Cc["@mozilla.org/ril/content-helper;1"].getService(Ci.nsIIccProvider);
         // TODO: Bug 927721 - PushService for multi-sim
-        // In Multi-sim, there is more than one client in iccService. Each
-        // client represents a icc handle. To maintain backward compatibility
+        // In Multi-sim, there is more than one client in iccProvider. Each
+        // client represents a icc service. 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 icc = iccService.getIccByServiceId(clientId);
-        let iccInfo = icc && icc.iccInfo;
+        let iccInfo = icc.getIccInfo(clientId);
         if (iccInfo) {
           debug("Running on mobile data");
 
           let ips = {};
           let prefixLengths = {};
           nm.active.getAddresses(ips, prefixLengths);
 
           return {
--- a/dom/system/gonk/NetworkManager.js
+++ b/dom/system/gonk/NetworkManager.js
@@ -33,38 +33,48 @@ XPCOMUtils.defineLazyServiceGetter(this,
 
 const TOPIC_INTERFACE_REGISTERED     = "network-interface-registered";
 const TOPIC_INTERFACE_UNREGISTERED   = "network-interface-unregistered";
 const TOPIC_ACTIVE_CHANGED           = "network-active-changed";
 const TOPIC_PREF_CHANGED             = "nsPref:changed";
 const TOPIC_XPCOM_SHUTDOWN           = "xpcom-shutdown";
 const TOPIC_CONNECTION_STATE_CHANGED = "network-connection-state-changed";
 const PREF_MANAGE_OFFLINE_STATUS     = "network.gonk.manage-offline-status";
+const PREF_NETWORK_DEBUG_ENABLED     = "network.debugging.enabled";
 
 const IPV4_ADDRESS_ANY                 = "0.0.0.0";
 const IPV6_ADDRESS_ANY                 = "::0";
 
 const IPV4_MAX_PREFIX_LENGTH           = 32;
 const IPV6_MAX_PREFIX_LENGTH           = 128;
 
 // Connection Type for Network Information API
 const CONNECTION_TYPE_CELLULAR  = 0;
 const CONNECTION_TYPE_BLUETOOTH = 1;
 const CONNECTION_TYPE_ETHERNET  = 2;
 const CONNECTION_TYPE_WIFI      = 3;
 const CONNECTION_TYPE_OTHER     = 4;
 const CONNECTION_TYPE_NONE      = 5;
 
-let DEBUG = false;
+let debug;
+function updateDebug() {
+  let debugPref = false; // set default value here.
+  try {
+    debugPref = debugPref || Services.prefs.getBoolPref(PREF_NETWORK_DEBUG_ENABLED);
+  } catch (e) {}
 
-// Read debug setting from pref.
-try {
-  let debugPref = Services.prefs.getBoolPref("network.debugging.enabled");
-  DEBUG = DEBUG || debugPref;
-} catch (e) {}
+  if (debugPref) {
+    debug = function(s) {
+      dump("-*- NetworkManager: " + s + "\n");
+    };
+  } else {
+    debug = function(s) {};
+  }
+}
+updateDebug();
 
 function defineLazyRegExp(obj, name, pattern) {
   obj.__defineGetter__(name, function() {
     delete obj[name];
     return obj[name] = new RegExp(pattern);
   });
 }
 
@@ -116,16 +126,17 @@ function NetworkManager() {
 
   try {
     this._manageOfflineStatus =
       Services.prefs.getBoolPref(PREF_MANAGE_OFFLINE_STATUS);
   } catch(ex) {
     // Ignore.
   }
   Services.prefs.addObserver(PREF_MANAGE_OFFLINE_STATUS, this, false);
+  Services.prefs.addObserver(PREF_NETWORK_DEBUG_ENABLED, this, false);
   Services.obs.addObserver(this, TOPIC_XPCOM_SHUTDOWN, false);
 
   this.setAndConfigureActive();
 
   ppmm.addMessageListener('NetworkInterfaceList:ListInterface', this);
 
   // Used in resolveHostname().
   defineLazyRegExp(this, "REGEXP_IPV4", "^\\d{1,3}(?:\\.\\d{1,3}){3}$");
@@ -142,23 +153,28 @@ NetworkManager.prototype = {
                                          Ci.nsIObserver,
                                          Ci.nsISettingsServiceCallback]),
 
   // nsIObserver
 
   observe: function(subject, topic, data) {
     switch (topic) {
       case TOPIC_PREF_CHANGED:
-        this._manageOfflineStatus =
-          Services.prefs.getBoolPref(PREF_MANAGE_OFFLINE_STATUS);
-        debug(PREF_MANAGE_OFFLINE_STATUS + " has changed to " + this._manageOfflineStatus);
+        if (data === PREF_NETWORK_DEBUG_ENABLED) {
+          updateDebug();
+        } else if (data === PREF_MANAGE_OFFLINE_STATUS) {
+          this._manageOfflineStatus =
+            Services.prefs.getBoolPref(PREF_MANAGE_OFFLINE_STATUS);
+          debug(PREF_MANAGE_OFFLINE_STATUS + " has changed to " + this._manageOfflineStatus);
+        }
         break;
       case TOPIC_XPCOM_SHUTDOWN:
         Services.obs.removeObserver(this, TOPIC_XPCOM_SHUTDOWN);
         Services.prefs.removeObserver(PREF_MANAGE_OFFLINE_STATUS, this);
+        Services.prefs.removeObserver(PREF_NETWORK_DEBUG_ENABLED, this);
         break;
     }
   },
 
   receiveMessage: function(aMsg) {
     switch (aMsg.name) {
       case "NetworkInterfaceList:ListInterface": {
         let excludeMms = aMsg.json.excludeMms;
@@ -710,18 +726,18 @@ NetworkManager.prototype = {
         retval.push(aRecord.getNextAddrAsString());
       }
 
       if (!retval.length) {
         deferred.reject(new Error("No valid address after DNS lookup!"));
         return;
       }
 
-      if (DEBUG) debug("hostname is resolved: " + hostname);
-      if (DEBUG) debug("Addresses: " + JSON.stringify(retval));
+      debug("hostname is resolved: " + hostname);
+      debug("Addresses: " + JSON.stringify(retval));
 
       deferred.resolve(retval);
     };
 
     // Bug 1058282 - Explicitly request ipv4 to get around 8.8.8.8 probe at
     // http://androidxref.com/4.3_r2.1/xref/bionic/libc/netbsd/net/getaddrinfo.c#1923
     //
     // Whenever MMS connection is the only network interface, there is no
@@ -848,19 +864,9 @@ let CaptivePortalDetectionHelper = (func
 XPCOMUtils.defineLazyGetter(NetworkManager.prototype, "mRil", function() {
   try {
     return Cc["@mozilla.org/ril;1"].getService(Ci.nsIRadioInterfaceLayer);
   } catch (e) {}
 
   return null;
 });
 
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkManager]);
-
-
-let debug;
-if (DEBUG) {
-  debug = function(s) {
-    dump("-*- NetworkManager: " + s + "\n");
-  };
-} else {
-  debug = function(s) {};
-}
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkManager]);
\ No newline at end of file
--- a/dom/system/gonk/NetworkService.js
+++ b/dom/system/gonk/NetworkService.js
@@ -10,16 +10,20 @@ Cu.import("resource://gre/modules/XPCOMU
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/NetUtil.jsm");
 Cu.import("resource://gre/modules/FileUtils.jsm");
 Cu.import("resource://gre/modules/Promise.jsm");
 
 const NETWORKSERVICE_CONTRACTID = "@mozilla.org/network/service;1";
 const NETWORKSERVICE_CID = Components.ID("{baec696c-c78d-42db-8b44-603f8fbfafb4}");
 
+const TOPIC_PREF_CHANGED             = "nsPref:changed";
+const TOPIC_XPCOM_SHUTDOWN           = "xpcom-shutdown";
+const PREF_NETWORK_DEBUG_ENABLED     = "network.debugging.enabled";
+
 XPCOMUtils.defineLazyServiceGetter(this, "gNetworkWorker",
                                    "@mozilla.org/network/worker;1",
                                    "nsINetworkWorker");
 
 // 1xx - Requested action is proceeding
 const NETD_COMMAND_PROCEEDING   = 100;
 // 2xx - Requested action has been successfully completed
 const NETD_COMMAND_OKAY         = 200;
@@ -30,37 +34,42 @@ const NETD_COMMAND_FAIL         = 400;
 const NETD_COMMAND_ERROR        = 500;
 // 6xx - Unsolicited broadcasts
 const NETD_COMMAND_UNSOLICITED  = 600;
 
 const WIFI_CTRL_INTERFACE = "wl0.1";
 
 const MANUAL_PROXY_CONFIGURATION = 1;
 
-let DEBUG = false;
+let debug;
+function updateDebug() {
+  let debugPref = false; // set default value here.
+  try {
+    debugPref = debugPref || Services.prefs.getBoolPref(PREF_NETWORK_DEBUG_ENABLED);
+  } catch (e) {}
 
-// Read debug setting from pref.
-try {
-  let debugPref = Services.prefs.getBoolPref("network.debugging.enabled");
-  DEBUG = DEBUG || debugPref;
-} catch (e) {}
+  if (debugPref) {
+    debug = function(s) {
+      dump("-*- NetworkService: " + s + "\n");
+    };
+  } else {
+    debug = function(s) {};
+  }
+}
+updateDebug();
 
 function netdResponseType(code) {
   return Math.floor(code / 100) * 100;
 }
 
 function isError(code) {
   let type = netdResponseType(code);
   return (type !== NETD_COMMAND_PROCEEDING && type !== NETD_COMMAND_OKAY);
 }
 
-function debug(msg) {
-  dump("-*- NetworkService: " + msg + "\n");
-}
-
 function Task(id, params, setupFunction) {
   this.id = id;
   this.params = params;
   this.setupFunction = setupFunction;
 }
 
 function NetworkWorkerRequestQueue(networkService) {
   this.networkService = networkService;
@@ -68,45 +77,45 @@ function NetworkWorkerRequestQueue(netwo
 }
 NetworkWorkerRequestQueue.prototype = {
   runQueue: function() {
     if (this.tasks.length === 0) {
       return;
     }
 
     let task = this.tasks[0];
-    if (DEBUG) debug("run task id: " + task.id);
+    debug("run task id: " + task.id);
 
     if (typeof task.setupFunction === 'function') {
       // If setupFunction returns false, skip sending to Network Worker but call
       // handleWorkerMessage() directly with task id, as if the response was
       // returned from Network Worker.
       if (!task.setupFunction()) {
         this.networkService.handleWorkerMessage({id: task.id});
         return;
       }
     }
 
     gNetworkWorker.postMessage(task.params);
   },
 
   enqueue: function(id, params, setupFunction) {
-    if (DEBUG) debug("enqueue id: " + id);
+    debug("enqueue id: " + id);
     this.tasks.push(new Task(id, params, setupFunction));
 
     if (this.tasks.length === 1) {
       this.runQueue();
     }
   },
 
   dequeue: function(id) {
-    if (DEBUG) debug("dequeue id: " + id);
+    debug("dequeue id: " + id);
 
     if (!this.tasks.length || this.tasks[0].id != id) {
-      if (DEBUG) debug("Id " + id + " is not on top of the queue");
+      debug("Id " + id + " is not on top of the queue");
       return;
     }
 
     this.tasks.shift();
     if (this.tasks.length > 0) {
       // Run queue on the next tick.
       Services.tm.currentThread.dispatch(() => {
         this.runQueue();
@@ -116,17 +125,17 @@ NetworkWorkerRequestQueue.prototype = {
 };
 
 
 /**
  * This component watches for network interfaces changing state and then
  * adjusts routes etc. accordingly.
  */
 function NetworkService() {
-  if(DEBUG) debug("Starting net_worker.");
+  debug("Starting net_worker.");
 
   let self = this;
 
   if (gNetworkWorker) {
     let networkListener = {
       onEvent: function(event) {
         self.handleWorkerMessage(event);
       }
@@ -134,30 +143,59 @@ function NetworkService() {
     gNetworkWorker.start(networkListener);
   }
   // Callbacks to invoke when a reply arrives from the net_worker.
   this.controlCallbacks = Object.create(null);
 
   this.addedRoutes = new Map();
   this.netWorkerRequestQueue = new NetworkWorkerRequestQueue(this);
   this.shutdown = false;
-  Services.obs.addObserver(this, "xpcom-shutdown", false);
+
+  Services.prefs.addObserver(PREF_NETWORK_DEBUG_ENABLED, this, false);
+  Services.obs.addObserver(this, TOPIC_XPCOM_SHUTDOWN, false);
 }
 
 NetworkService.prototype = {
   classID:   NETWORKSERVICE_CID,
   classInfo: XPCOMUtils.generateCI({classID: NETWORKSERVICE_CID,
                                     contractID: NETWORKSERVICE_CONTRACTID,
                                     classDescription: "Network Service",
                                     interfaces: [Ci.nsINetworkService]}),
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkService]),
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkService,
+                                         Ci.nsIObserver]),
+
+  addedRoutes: null,
+
+  shutdown: false,
+
+  // nsIObserver
+
+  observe: function(subject, topic, data) {
+    switch (topic) {
+      case TOPIC_PREF_CHANGED:
+        if (data === PREF_NETWORK_DEBUG_ENABLED) {
+          updateDebug();
+        }
+        break;
+      case TOPIC_XPCOM_SHUTDOWN:
+        debug("NetworkService shutdown");
+        this.shutdown = true;
+        if (gNetworkWorker) {
+          gNetworkWorker.shutdown();
+          gNetworkWorker = null;
+        }
+
+        Services.obs.removeObserver(this, TOPIC_XPCOM_SHUTDOWN);
+        Services.prefs.removeObserver(PREF_NETWORK_DEBUG_ENABLED, this);
+        break;
+    }
+  },
 
   // Helpers
 
-  addedRoutes: null,
   idgen: 0,
   controlMessage: function(params, callback, setupFunction) {
     if (this.shutdown) {
       return;
     }
 
     let id = this.idgen++;
     params.id = id;
@@ -173,17 +211,17 @@ NetworkService.prototype = {
     }
 
     if (gNetworkWorker) {
       gNetworkWorker.postMessage(params);
     }
   },
 
   handleWorkerMessage: function(response) {
-    if(DEBUG) debug("NetworkManager received message from worker: " + JSON.stringify(response));
+    debug("NetworkManager received message from worker: " + JSON.stringify(response));
     let id = response.id;
     if (response.broadcast === true) {
       Services.obs.notifyObservers(null, response.topic, response.reason);
       return;
     }
     let callback = this.controlCallbacks[id];
     if (callback) {
       callback.call(this, response);
@@ -191,17 +229,17 @@ NetworkService.prototype = {
     }
 
     this.netWorkerRequestQueue.dequeue(id);
   },
 
   // nsINetworkService
 
   getNetworkInterfaceStats: function(networkName, callback) {
-    if(DEBUG) debug("getNetworkInterfaceStats for " + networkName);
+    debug("getNetworkInterfaceStats for " + networkName);
 
     let file = new FileUtils.File("/proc/net/dev");
     if (!file) {
       callback.networkStatsAvailable(false, 0, 0, Date.now());
       return;
     }
 
     NetUtil.asyncFetch2(file, function(inputStream, status) {
@@ -252,17 +290,17 @@ NetworkService.prototype = {
         return
       }
 
       self._setNetworkInterfaceAlarm(networkName, threshold, callback);
     });
   },
 
   _setNetworkInterfaceAlarm: function(networkName, threshold, callback) {
-    if(DEBUG) debug("setNetworkInterfaceAlarm for " + networkName + " at " + threshold + "bytes");
+    debug("setNetworkInterfaceAlarm for " + networkName + " at " + threshold + "bytes");
 
     let params = {
       cmd: "setNetworkInterfaceAlarm",
       ifname: networkName,
       threshold: threshold
     };
 
     params.report = true;
@@ -273,17 +311,17 @@ NetworkService.prototype = {
         return;
       }
 
       this._enableNetworkInterfaceAlarm(networkName, threshold, callback);
     });
   },
 
   _enableNetworkInterfaceAlarm: function(networkName, threshold, callback) {
-    if(DEBUG) debug("enableNetworkInterfaceAlarm for " + networkName + " at " + threshold + "bytes");
+    debug("enableNetworkInterfaceAlarm for " + networkName + " at " + threshold + "bytes");
 
     let params = {
       cmd: "enableNetworkInterfaceAlarm",
       ifname: networkName,
       threshold: threshold
     };
 
     params.report = true;
@@ -293,32 +331,32 @@ NetworkService.prototype = {
         callback.networkUsageAlarmResult(null);
         return;
       }
       callback.networkUsageAlarmResult(result.reason);
     });
   },
 
   _disableNetworkInterfaceAlarm: function(networkName, callback) {
-    if(DEBUG) debug("disableNetworkInterfaceAlarm for " + networkName);
+    debug("disableNetworkInterfaceAlarm for " + networkName);
 
     let params = {
       cmd: "disableNetworkInterfaceAlarm",
       ifname: networkName,
     };
 
     params.report = true;
 
     this.controlMessage(params, function(result) {
       callback(result);
     });
   },
 
   setWifiOperationMode: function(interfaceName, mode, callback) {
-    if(DEBUG) debug("setWifiOperationMode on " + interfaceName + " to " + mode);
+    debug("setWifiOperationMode on " + interfaceName + " to " + mode);
 
     let params = {
       cmd: "setWifiOperationMode",
       ifname: interfaceName,
       mode: mode
     };
 
     params.report = true;
@@ -337,45 +375,45 @@ NetworkService.prototype = {
       cmd: "removeNetworkRoute",
       ifname: network.name
     };
 
     this.controlMessage(options);
   },
 
   setDNS: function(networkInterface, callback) {
-    if (DEBUG) debug("Going DNS to " + networkInterface.name);
+    debug("Going DNS to " + networkInterface.name);
     let dnses = networkInterface.getDnses();
     let options = {
       cmd: "setDNS",
       ifname: networkInterface.name,
       domain: "mozilla." + networkInterface.name + ".doman",
       dnses: dnses
     };
     this.controlMessage(options, function(result) {
       callback.setDnsResult(result.success ? null : result.reason);
     });
   },
 
   setDefaultRoute: function(network, oldInterface, callback) {
-    if (DEBUG) debug("Going to change default route to " + network.name);
+    debug("Going to change default route to " + network.name);
     let gateways = network.getGateways();
     let options = {
       cmd: "setDefaultRoute",
       ifname: network.name,
       oldIfname: (oldInterface && oldInterface !== network) ? oldInterface.name : null,
       gateways: gateways
     };
     this.controlMessage(options, function(result) {
       callback.nativeCommandResult(!result.error);
     });
   },
 
   removeDefaultRoute: function(network) {
-    if(DEBUG) debug("Remove default route for " + network.name);
+    debug("Remove default route for " + network.name);
     let gateways = network.getGateways();
     let options = {
       cmd: "removeDefaultRoute",
       ifname: network.name,
       gateways: gateways
     };
     this.controlMessage(options);
   },
@@ -390,36 +428,36 @@ NetworkService.prototype = {
     switch (action) {
       case Ci.nsINetworkService.MODIFY_ROUTE_ADD:
         command = 'addHostRoute';
         break;
       case Ci.nsINetworkService.MODIFY_ROUTE_REMOVE:
         command = 'removeHostRoute';
         break;
       default:
-        if (DEBUG) debug('Unknown action: ' + action);
+        debug('Unknown action: ' + action);
         return Promise.reject();
     }
 
     let route = this._routeToString(interfaceName, host, prefixLength, gateway);
     let setupFunc = () => {
       let count = this.addedRoutes.get(route);
-      if (DEBUG) debug(command + ": " + route + " -> " + count);
+      debug(command + ": " + route + " -> " + count);
 
       // Return false if there is no need to send the command to network worker.
       if ((action == Ci.nsINetworkService.MODIFY_ROUTE_ADD && count) ||
           (action == Ci.nsINetworkService.MODIFY_ROUTE_REMOVE &&
            (!count || count > 1))) {
         return false;
       }
 
       return true;
     };
 
-    if (DEBUG) debug(command + " " + host + " on " + interfaceName);
+    debug(command + " " + host + " on " + interfaceName);
     let options = {
       cmd: command,
       ifname: interfaceName,
       gateway: gateway,
       prefixLength: prefixLength,
       ip: host
     };
 
@@ -446,67 +484,67 @@ NetworkService.prototype = {
         }
 
         aResolve();
       }, setupFunc);
     });
   },
 
   addSecondaryRoute: function(ifname, route) {
-    if(DEBUG) debug("Going to add route to secondary table on " + ifname);
+    debug("Going to add route to secondary table on " + ifname);
     let options = {
       cmd: "addSecondaryRoute",
       ifname: ifname,
       ip: route.ip,
       prefix: route.prefix,
       gateway: route.gateway
     };
     this.controlMessage(options);
   },
 
   removeSecondaryRoute: function(ifname, route) {
-    if(DEBUG) debug("Going to remove route from secondary table on " + ifname);
+    debug("Going to remove route from secondary table on " + ifname);
     let options = {
       cmd: "removeSecondaryRoute",
       ifname: ifname,
       ip: route.ip,
       prefix: route.prefix,
       gateway: route.gateway
     };
     this.controlMessage(options);
   },
 
   setNetworkProxy: function(network) {
     try {
       if (!network.httpProxyHost || network.httpProxyHost === "") {
         // Sets direct connection to internet.
         this.clearNetworkProxy();
 
-        if (DEBUG) debug("No proxy support for " + network.name + " network interface.");
+        debug("No proxy support for " + network.name + " network interface.");
         return;
       }
 
-      if (DEBUG) debug("Going to set proxy settings for " + network.name + " network interface.");
+      debug("Going to set proxy settings for " + network.name + " network interface.");
       // Sets manual proxy configuration.
       Services.prefs.setIntPref("network.proxy.type", MANUAL_PROXY_CONFIGURATION);
       // Do not use this proxy server for all protocols.
       Services.prefs.setBoolPref("network.proxy.share_proxy_settings", false);
       Services.prefs.setCharPref("network.proxy.http", network.httpProxyHost);
       Services.prefs.setCharPref("network.proxy.ssl", network.httpProxyHost);
       let port = network.httpProxyPort === 0 ? 8080 : network.httpProxyPort;
       Services.prefs.setIntPref("network.proxy.http_port", port);
       Services.prefs.setIntPref("network.proxy.ssl_port", port);
     } catch(ex) {
-        if (DEBUG) debug("Exception " + ex + ". Unable to set proxy setting for " +
+        debug("Exception " + ex + ". Unable to set proxy setting for " +
                          network.name + " network interface.");
     }
   },
 
   clearNetworkProxy: function() {
-    if (DEBUG) debug("Going to clear all network proxy.");
+    debug("Going to clear all network proxy.");
 
     Services.prefs.clearUserPref("network.proxy.type");
     Services.prefs.clearUserPref("network.proxy.share_proxy_settings");
     Services.prefs.clearUserPref("network.proxy.http");
     Services.prefs.clearUserPref("network.proxy.http_port");
     Services.prefs.clearUserPref("network.proxy.ssl");
     Services.prefs.clearUserPref("network.proxy.ssl_port");
   },
@@ -540,17 +578,17 @@ NetworkService.prototype = {
 
     // The callback function in controlMessage may not be fired immediately.
     this.controlMessage(config, function setWifiTetheringResult(data) {
       let code = data.resultCode;
       let reason = data.resultReason;
       let enable = data.enable;
       let enableString = enable ? "Enable" : "Disable";
 
-      if(DEBUG) debug(enableString + " Wifi tethering result: Code " + code + " reason " + reason);
+      debug(enableString + " Wifi tethering result: Code " + code + " reason " + reason);
 
       if (isError(code)) {
         callback.wifiTetheringEnabledChange("netd command error");
       } else {
         callback.wifiTetheringEnabledChange(null);
       }
     });
   },
@@ -560,29 +598,29 @@ NetworkService.prototype = {
     config.cmd = "setUSBTethering";
     // The callback function in controlMessage may not be fired immediately.
     this.controlMessage(config, function setUsbTetheringResult(data) {
       let code = data.resultCode;
       let reason = data.resultReason;
       let enable = data.enable;
       let enableString = enable ? "Enable" : "Disable";
 
-      if(DEBUG) debug(enableString + " USB tethering result: Code " + code + " reason " + reason);
+      debug(enableString + " USB tethering result: Code " + code + " reason " + reason);
 
       if (isError(code)) {
         callback.usbTetheringEnabledChange("netd command error");
       } else {
         callback.usbTetheringEnabledChange(null);
       }
     });
   },
 
   // Switch usb function by modifying property of persist.sys.usb.config.
   enableUsbRndis: function(enable, callback) {
-    if(DEBUG) debug("enableUsbRndis: " + enable);
+    debug("enableUsbRndis: " + enable);
 
     let params = {
       cmd: "enableUsbRndis",
       enable: enable
     };
     // Ask net work to report the result when this value is set to true.
     if (callback) {
       params.report = true;
@@ -604,17 +642,17 @@ NetworkService.prototype = {
       preExternalIfname: previous.externalIfname,
       curInternalIfname: current.internalIfname,
       curExternalIfname: current.externalIfname
     };
 
     this.controlMessage(params, function(data) {
       let code = data.resultCode;
       let reason = data.resultReason;
-      if(DEBUG) debug("updateUpStream result: Code " + code + " reason " + reason);
+      debug("updateUpStream result: Code " + code + " reason " + reason);
       callback.updateUpStreamResult(!isError(code), data.curExternalIfname);
     });
   },
 
   configureInterface: function(config, callback) {
     let params = {
       cmd: "configureInterface",
       ifname: config.ifname,
@@ -690,27 +728,11 @@ NetworkService.prototype = {
       cmd: "destroyNetwork",
       ifname: interfaceName
     };
 
     this.controlMessage(params, function(result) {
       callback.nativeCommandResult(!result.error);
     });
   },
-
-  shutdown: false,
-
-  observe: function observe(aSubject, aTopic, aData) {
-    switch (aTopic) {
-      case "xpcom-shutdown":
-        debug("NetworkService shutdown");
-        this.shutdown = true;
-        Services.obs.removeObserver(this, "xpcom-shutdown");
-        if (gNetworkWorker) {
-          gNetworkWorker.shutdown();
-          gNetworkWorker = null;
-        }
-        break;
-    }
-  },
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkService]);
--- a/dom/system/gonk/RILContentHelper.js
+++ b/dom/system/gonk/RILContentHelper.js
@@ -93,18 +93,18 @@ IccInfo.prototype = {
 
   // nsIIccInfo
 
   iccType: null,
   iccid: null,
   mcc: null,
   mnc: null,
   spn: null,
-  isDisplayNetworkNameRequired: false,
-  isDisplaySpnRequired: false
+  isDisplayNetworkNameRequired: null,
+  isDisplaySpnRequired: null
 };
 
 function GsmIccInfo() {}
 GsmIccInfo.prototype = {
   __proto__: IccInfo.prototype,
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIGsmIccInfo,
                                          Ci.nsIIccInfo]),
 
@@ -126,49 +126,44 @@ CdmaIccInfo.prototype = {
 };
 
 function RILContentHelper() {
   this.updateDebugFlag();
 
   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,
+      cardState: Ci.nsIIccProvider.CARD_STATE_UNKNOWN,
       iccInfo: null
     };
   }
 
   this.initDOMRequestHelper(/* aWindow */ null, RIL_IPC_MSG_NAMES);
   this._windowsMap = [];
-  this._requestMap = [];
   this._iccListeners = [];
   this._iccChannelCallback = [];
 
   Services.obs.addObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
 
   Services.prefs.addObserver(kPrefRilDebuggingEnabled, this, false);
 }
 
 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,
-                                                 Ci.nsIIccService]}),
+                                    interfaces: [Ci.nsIIccProvider]}),
 
   updateDebugFlag: function() {
     try {
       DEBUG = RIL.DEBUG_CONTENT_HELPER ||
               Services.prefs.getBoolPref(kPrefRilDebuggingEnabled);
     } catch (e) {}
   },
 
@@ -206,18 +201,16 @@ RILContentHelper.prototype = {
       }
     }
 
     this.updateInfo(newInfo, rilContext.iccInfo);
   },
 
   _windowsMap: null,
 
-  _requestMap: null,
-
   rilContexts: null,
 
   getRilContext: function(clientId) {
     // Update ril contexts by sending IPC message to chrome only when the first
     // time we require it. The information will be updated by following info
     // changed messages.
     this.getRilContext = function getRilContext(clientId) {
       return this.rilContexts[clientId];
@@ -236,16 +229,152 @@ RILContentHelper.prototype = {
 
     return this.rilContexts[clientId];
   },
 
   /**
    * 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",
                                   Cr.NS_ERROR_UNEXPECTED);
     }
     response.command = command;
     cpmm.sendAsyncMessage("RIL:SendStkResponse", {
       clientId: clientId,
@@ -411,16 +540,37 @@ RILContentHelper.prototype = {
         contact: iccContact,
         pin2: pin2
       }
     });
 
     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) {
     if (!this[listenerType]) {
       return;
     }
     let listeners = this[listenerType][clientId];
     if (!listeners) {
@@ -566,66 +716,72 @@ RILContentHelper.prototype = {
     }
 
     let data = msg.json.data;
     let clientId = msg.json.clientId;
     switch (msg.name) {
       case "RIL:CardStateChanged":
         if (this.rilContexts[clientId].cardState != data.cardState) {
           this.rilContexts[clientId].cardState = data.cardState;
-          this._deliverIccEvent(clientId,
-                                "notifyCardStateChanged",
-                                null);
+          this._deliverEvent(clientId,
+                             "_iccListeners",
+                             "notifyCardStateChanged",
+                             null);
         }
         break;
       case "RIL:IccInfoChanged":
         this.updateIccInfo(clientId, data);
-        this._deliverIccEvent(clientId,
-                              "notifyIccInfoChanged",
-                              null);
+        this._deliverEvent(clientId,
+                           "_iccListeners",
+                           "notifyIccInfoChanged",
+                           null);
         break;
       case "RIL:GetCardLockResult": {
         let requestId = data.requestId;
-        let callback = this._requestMap[requestId];
-        delete this._requestMap[requestId];
+        let requestWindow = this._windowsMap[requestId];
+        delete this._windowsMap[requestId];
 
         if (data.errorMsg) {
-          callback.notifyError(data.errorMsg);
+          this.fireRequestError(requestId, data.errorMsg);
           break;
         }
 
-        callback.notifySuccessWithBoolean(data.enabled);
+        this.fireRequestSuccess(requestId,
+                                Cu.cloneInto({ enabled: data.enabled },
+                                             requestWindow));
         break;
       }
       case "RIL:SetUnlockCardLockResult": {
         let requestId = data.requestId;
-        let callback = this._requestMap[requestId];
-        delete this._requestMap[requestId];
+        let requestWindow = this._windowsMap[requestId];
+        delete this._windowsMap[requestId];
 
         if (data.errorMsg) {
-          let retryCount =
-            (data.retryCount !== undefined) ? data.retryCount : -1;
-          callback.notifyCardLockError(data.errorMsg, retryCount);
+          let cardLockError = new requestWindow.IccCardLockError(data.errorMsg,
+                                                                 data.retryCount);
+          this.fireRequestDetailedError(requestId, cardLockError);
           break;
         }
 
-        callback.notifySuccess();
+        this.fireRequestSuccess(requestId, null);
         break;
       }
       case "RIL:CardLockRetryCount": {
         let requestId = data.requestId;
-        let callback = this._requestMap[requestId];
-        delete this._requestMap[requestId];
+        let requestWindow = this._windowsMap[requestId];
+        delete this._windowsMap[requestId];
 
         if (data.errorMsg) {
-          callback.notifyError(data.errorMsg);
+          this.fireRequestError(data.requestId, data.errorMsg);
           break;
         }
 
-        callback.notifyGetCardLockRetryCount(data.retryCount);
+        this.fireRequestSuccess(data.requestId,
+                                Cu.cloneInto({ retryCount: data.retryCount },
+                                             requestWindow));
         break;
       }
       case "RIL:StkCommand":
         this._deliverEvent(clientId, "_iccListeners", "notifyStkCommand",
                            [JSON.stringify(data)]);
         break;
       case "RIL:StkSessionEnd":
         this._deliverEvent(clientId, "_iccListeners", "notifyStkSessionEnd", null);
@@ -640,40 +796,22 @@ RILContentHelper.prototype = {
         this.handleIccExchangeAPDU(data);
         break;
       case "RIL:ReadIccContacts":
         this.handleReadIccContacts(data);
         break;
       case "RIL:UpdateIccContact":
         this.handleUpdateIccContact(data);
         break;
-      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);
+      case "RIL:MatchMvno":
+        this.handleSimpleRequest(data.requestId, data.errorMsg, data.result);
         break;
-      }
-      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);
+      case "RIL:GetServiceState":
+        this.handleGetServiceState(data);
         break;
-      }
     }
   },
 
   handleSimpleRequest: function(requestId, errorMsg, result) {
     if (errorMsg) {
       this.fireRequestError(requestId, errorMsg);
     } else {
       this.fireRequestSuccess(requestId, result);
@@ -766,16 +904,30 @@ RILContentHelper.prototype = {
     }
 
     let contact = new window.mozContact(prop);
     contact.id = iccContact.contactId;
 
     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;
     }
     let thisListeners = this[listenerType][clientId];
     if (!thisListeners) {
       return;
     }
@@ -790,241 +942,12 @@ RILContentHelper.prototype = {
         throw new Error("No handler for " + name);
       }
       try {
         handler.apply(listener, args);
       } catch (e) {
         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);
   }
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([RILContentHelper]);
--- a/dom/system/gonk/RILContentHelper.manifest
+++ b/dom/system/gonk/RILContentHelper.manifest
@@ -8,13 +8,11 @@
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # 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
--- a/dom/system/gonk/RadioInterfaceLayer.js
+++ b/dom/system/gonk/RadioInterfaceLayer.js
@@ -82,17 +82,16 @@ const INT32_MAX = 2147483647;
 const NETWORK_TYPE_UNKNOWN     = Ci.nsINetworkInterface.NETWORK_TYPE_UNKNOWN;
 const NETWORK_TYPE_WIFI        = Ci.nsINetworkInterface.NETWORK_TYPE_WIFI;
 const NETWORK_TYPE_MOBILE      = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE;
 const NETWORK_TYPE_MOBILE_MMS  = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS;
 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",
   "RIL:SendStkMenuSelection",
   "RIL:SendStkTimerExpiration",
   "RIL:SendStkEventDownload",
   "RIL:GetCardLockEnabled",
   "RIL:UnlockCardLock",
@@ -123,20 +122,16 @@ function updateDebugFlag() {
   DEBUG = RIL.DEBUG_RIL || debugPref;
 }
 updateDebugFlag();
 
 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");
 
 XPCOMUtils.defineLazyServiceGetter(this, "gSmsService",
                                    "@mozilla.org/sms/gonksmsservice;1",
                                    "nsIGonkSmsService");
 
@@ -177,17 +172,16 @@ XPCOMUtils.defineLazyServiceGetter(this,
                                    "nsIIccMessenger");
 
 XPCOMUtils.defineLazyGetter(this, "gStkCmdFactory", function() {
   let stk = {};
   Cu.import("resource://gre/modules/StkProactiveCmdFactory.jsm", stk);
   return stk.StkProactiveCmdFactory;
 });
 
-// TODO: Bug 815526, deprecate RILContentHelper.
 XPCOMUtils.defineLazyGetter(this, "gMessageManager", function() {
   return {
     QueryInterface: XPCOMUtils.generateQI([Ci.nsIMessageListener,
                                            Ci.nsIObserver]),
 
     ril: null,
 
     // Manage message targets in terms of topic. Only the authorized and
@@ -887,18 +881,18 @@ IccInfo.prototype = {
 
   // nsIIccInfo
 
   iccType: null,
   iccid: null,
   mcc: null,
   mnc: null,
   spn: null,
-  isDisplayNetworkNameRequired: false,
-  isDisplaySpnRequired: false
+  isDisplayNetworkNameRequired: null,
+  isDisplaySpnRequired: null
 };
 
 function GsmIccInfo() {}
 GsmIccInfo.prototype = {
   __proto__: IccInfo.prototype,
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIGsmIccInfo,
                                          Ci.nsIIccInfo]),
 
@@ -1424,29 +1418,28 @@ function RadioInterfaceLayer() {
   this.radioInterfaces = [];
   for (let clientId = 0; clientId < numIfaces; clientId++) {
     this.radioInterfaces.push(new RadioInterface(clientId, workerMessenger));
   }
 
   Services.obs.addObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
   Services.prefs.addObserver(kPrefRilDebuggingEnabled, this, false);
 
-  gMessageManager.init(this); // TODO: Bug 815526, deprecate RILContentHelper.
+  gMessageManager.init(this);
   gRadioEnabledController.init(this);
   gDataConnectionManager.init(this);
 }
 RadioInterfaceLayer.prototype = {
 
   classID:   RADIOINTERFACELAYER_CID,
   classInfo: XPCOMUtils.generateCI({classID: RADIOINTERFACELAYER_CID,
                                     classDescription: "RadioInterfaceLayer",
                                     interfaces: [Ci.nsIRadioInterfaceLayer]}),
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIRadioInterfaceLayer,
-                                         Ci.nsIRadioInterfaceLayer_new, // TODO: Bug 815526, deprecate RILContentHelper.
                                          Ci.nsIObserver]),
 
   /**
    * nsIObserver interface methods.
    */
 
   observe: function(subject, topic, data) {
     switch (topic) {
@@ -1678,24 +1671,23 @@ WorkerMessenger.prototype = {
     }).bind(this));
   }
 };
 
 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),
   };
   aWorkerMessenger.registerClient(aClientId, this);
 
   this.rilContext = {
-    cardState:      Ci.nsIIcc.CARD_STATE_UNKNOWN,
+    cardState:      Ci.nsIIccProvider.CARD_STATE_UNKNOWN,
     iccInfo:        null,
     imsi:           null
   };
 
   this.operatorInfo = {};
 
   let lock = gSettingsService.createLock();
 
@@ -1783,24 +1775,22 @@ RadioInterface.prototype = {
       }
     }
 
     return false;
   },
 
   isCardPresent: function() {
     let cardState = this.rilContext.cardState;
-    return cardState !== Ci.nsIIcc.CARD_STATE_UNDETECTED &&
-      cardState !== Ci.nsIIcc.CARD_STATE_UNKNOWN;
+    return cardState !== Ci.nsIIccProvider.CARD_STATE_UNDETECTED &&
+      cardState !== Ci.nsIIccProvider.CARD_STATE_UNKNOWN;
   },
 
   /**
    * Process a message from the content process.
-   *
-   * TODO: Bug 815526, deprecate RILContentHelper
    */
   receiveMessage: function(msg) {
     switch (msg.name) {
       case "RIL:GetRilContext":
         // This message is sync.
         return this.rilContext;
       case "RIL:GetCardLockEnabled":
         this.workerMessenger.sendWithIPCMessage(msg, "iccGetCardLockEnabled",
@@ -1930,19 +1920,16 @@ RadioInterface.prototype = {
         // gRadioEnabledController should know the radio state for each client,
         // so notify gRadioEnabledController here.
         gRadioEnabledController.notifyRadioStateChanged(this.clientId,
                                                         message.radioState);
         break;
       case "cardstatechange":
         this.rilContext.cardState = message.cardState;
         gRadioEnabledController.receiveCardState(this.clientId);
-        gIccService.notifyCardStateChanged(this.clientId,
-                                           this.rilContext.cardState);
-        // TODO: Bug 815526, deprecate RILContentHelper.
         gMessageManager.sendIccMessage("RIL:CardStateChanged",
                                        this.clientId, message);
         break;
       case "sms-received":
         this.handleSmsReceived(message);
         break;
       case "cellbroadcast-received":
         this.handleCellbroadcastMessageReceived(message);
@@ -1950,45 +1937,42 @@ RadioInterface.prototype = {
       case "nitzTime":
         this.handleNitzTime(message);
         break;
       case "iccinfochange":
         this.handleIccInfoChange(message);
         break;
       case "iccimsi":
         this.rilContext.imsi = message.imsi;
-        gIccService.notifyImsiChanged(this.clientId, this.rilContext.imsi);
         break;
       case "iccmbdn":
         this.handleIccMbdn(message);
         break;
       case "iccmwis":
         this.handleIccMwis(message.mwi);
         break;
       case "stkcommand":
         this.handleStkProactiveCommand(message);
         break;
       case "stksessionend":
-        // TODO: Bug 815526, deprecate RILContentHelper.
         gMessageManager.sendIccMessage("RIL:StkSessionEnd", this.clientId, null);
         break;
       case "cdma-info-rec-received":
         this.handleCdmaInformationRecords(message.records);
         break;
       default:
         throw new Error("Don't know about this message type: " +
                         message.rilMessageType);
     }
   },
 
   // Matches the mvnoData pattern with imsi. Characters 'x' and 'X' are skipped
   // 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;
 
     // This should not be an error, but a mismatch.
     if (mvnoData.length > imsi.length) {
       return false;
     }
 
@@ -1996,17 +1980,16 @@ RadioInterface.prototype = {
       let c = mvnoData[i];
       if ((c !== 'x') && (c !== 'X') && (c !== imsi[i])) {
         return false;
       }
     }
     return true;
   },
 
-  // TODO: Bug 815526, deprecate RILContentHelper.
   matchMvno: function(target, message) {
     if (DEBUG) this.debug("matchMvno: " + JSON.stringify(message));
 
     if (!message || !message.mvnoData) {
       message.errorMsg = RIL.GECKO_ERROR_INVALID_PARAMETER;
     }
 
     if (!message.errorMsg) {
@@ -2234,18 +2217,16 @@ RadioInterface.prototype = {
     // Note: returnNumber and returnMessage is not available from UICC.
     service.notifyStatusChanged(this.clientId, mwi.active, mwi.msgCount,
                                 null, null);
   },
 
   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.
       if (!this.rilContext.iccInfo) {
         return;
       }
 
       // Card is not detected, clear iccInfo to null.
@@ -2265,21 +2246,27 @@ RadioInterface.prototype = {
         return;
       }
 
       this.updateInfo(message, this.rilContext.iccInfo);
     }
 
     // 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);
-    gIccService.notifyIccInfoChanged(this.clientId, this.rilContext.iccInfo);
+
+    // Update lastKnownSimMcc.
+    if (message.mcc) {
+      try {
+        Services.prefs.setCharPref("ril.lastKnownSimMcc",
+                                   message.mcc.toString());
+      } catch (e) {}
+    }
 
     // Update lastKnownHomeNetwork.
     if (message.mcc && message.mnc) {
       let lastKnownHomeNetwork = message.mcc + "-" + message.mnc;
       // Append spn information if available.
       if (message.spn) {
         lastKnownHomeNetwork += "-" + message.spn;
       }
@@ -2297,17 +2284,16 @@ RadioInterface.prototype = {
   handleStkProactiveCommand: function(message) {
     if (DEBUG) this.debug("handleStkProactiveCommand " + JSON.stringify(message));
     let iccId = this.rilContext.iccInfo && this.rilContext.iccInfo.iccid;
     if (iccId) {
       gIccMessenger
         .notifyStkProactiveCommand(iccId,
                                    gStkCmdFactory.createCommand(message));
     }
-    // TODO: Bug 815526, deprecate RILContentHelper.
     gMessageManager.sendIccMessage("RIL:StkCommand", this.clientId, message);
   },
 
   _convertCbGsmGeographicalScope: function(aGeographicalScope) {
     return (aGeographicalScope != null)
       ? aGeographicalScope
       : Ci.nsICellBroadcastService.GSM_GEOGRAPHICAL_SCOPE_INVALID;
   },
--- a/dom/system/gonk/TetheringService.js
+++ b/dom/system/gonk/TetheringService.js
@@ -38,17 +38,19 @@ XPCOMUtils.defineLazyGetter(this, "gRil"
 
   return null;
 });
 
 const TOPIC_INTERFACE_REGISTERED     = "network-interface-registered";
 const TOPIC_INTERFACE_UNREGISTERED   = "network-interface-unregistered";
 const TOPIC_MOZSETTINGS_CHANGED      = "mozsettings-changed";
 const TOPIC_CONNECTION_STATE_CHANGED = "network-connection-state-changed";
+const TOPIC_PREF_CHANGED             = "nsPref:changed";
 const TOPIC_XPCOM_SHUTDOWN           = "xpcom-shutdown";
+const PREF_NETWORK_DEBUG_ENABLED     = "network.debugging.enabled";
 
 const POSSIBLE_USB_INTERFACE_NAME = "rndis0,usb0";
 const DEFAULT_USB_INTERFACE_NAME  = "rndis0";
 const DEFAULT_3G_INTERFACE_NAME   = "rmnet0";
 const DEFAULT_WIFI_INTERFACE_NAME = "wlan0";
 
 // The kernel's proc entry for network lists.
 const KERNEL_NETWORK_ENTRY = "/sys/class/net";
@@ -98,38 +100,40 @@ const DEFAULT_DNS2                     =
 const DEFAULT_WIFI_DHCPSERVER_STARTIP  = "192.168.1.10";
 const DEFAULT_WIFI_DHCPSERVER_ENDIP    = "192.168.1.30";
 
 const SETTINGS_DATA_DEFAULT_SERVICE_ID = "ril.data.defaultServiceId";
 const MOBILE_DUN_CONNECT_TIMEOUT       = 30000;
 const MOBILE_DUN_RETRY_INTERVAL        = 5000;
 const MOBILE_DUN_MAX_RETRIES           = 5;
 
-let DEBUG = false;
-// Read debug setting from pref.
-try {
-  let debugPref = Services.prefs.getBoolPref("network.debugging.enabled");
-  DEBUG = DEBUG || debugPref;
-} catch (e) {}
+let debug;
+function updateDebug() {
+  let debugPref = false; // set default value here.
+  try {
+    debugPref = debugPref || Services.prefs.getBoolPref(PREF_NETWORK_DEBUG_ENABLED);
+  } catch (e) {}
 
-let debug;
-if (DEBUG) {
-  debug = function(s) {
-    dump("-*- TetheringService: " + s + "\n");
-  };
-} else {
-  debug = function(s) {};
+  if (debugPref) {
+    debug = function(s) {
+      dump("-*- TetheringService: " + s + "\n");
+    };
+  } else {
+    debug = function(s) {};
+  }
 }
+updateDebug();
 
 function TetheringService() {
   Services.obs.addObserver(this, TOPIC_XPCOM_SHUTDOWN, false);
   Services.obs.addObserver(this, TOPIC_MOZSETTINGS_CHANGED, false);
   Services.obs.addObserver(this, TOPIC_CONNECTION_STATE_CHANGED, false);
   Services.obs.addObserver(this, TOPIC_INTERFACE_REGISTERED, false);
   Services.obs.addObserver(this, TOPIC_INTERFACE_UNREGISTERED, false);
+  Services.prefs.addObserver(PREF_NETWORK_DEBUG_ENABLED, this, false);
 
   this._dataDefaultServiceId = 0;
 
   // Possible usb tethering interfaces for different gonk platform.
   this.possibleInterface = POSSIBLE_USB_INTERFACE_NAME.split(",");
 
   // Default values for internal and external interfaces.
   this._tetheringInterface = {};
@@ -231,16 +235,21 @@ TetheringService.prototype = {
   _pendingWifiTetheringRequestArgs: null,
 
   // nsIObserver
 
   observe: function(aSubject, aTopic, aData) {
     let network;
 
     switch(aTopic) {
+      case TOPIC_PREF_CHANGED:
+        if (aData === PREF_NETWORK_DEBUG_ENABLED) {
+          updateDebug();
+        }
+        break;
       case TOPIC_MOZSETTINGS_CHANGED:
         if ("wrappedJSObject" in aSubject) {
           aSubject = aSubject.wrappedJSObject;
         }
         this.handle(aSubject.key, aSubject.value);
         break;
       case TOPIC_CONNECTION_STATE_CHANGED:
         network = aSubject.QueryInterface(Ci.nsINetworkInterface);
@@ -265,16 +274,17 @@ TetheringService.prototype = {
         }
         break;
       case TOPIC_XPCOM_SHUTDOWN:
         Services.obs.removeObserver(this, TOPIC_XPCOM_SHUTDOWN);
         Services.obs.removeObserver(this, TOPIC_MOZSETTINGS_CHANGED);
         Services.obs.removeObserver(this, TOPIC_CONNECTION_STATE_CHANGED);
         Services.obs.removeObserver(this, TOPIC_INTERFACE_REGISTERED);
         Services.obs.removeObserver(this, TOPIC_INTERFACE_UNREGISTERED);
+        Services.prefs.removeObserver(PREF_NETWORK_DEBUG_ENABLED, this);
 
         this.dunConnectTimer.cancel();
         this.dunRetryTimer.cancel();
         break;
     }
   },
 
   // nsISettingsServiceCallback
--- a/dom/system/gonk/moz.build
+++ b/dom/system/gonk/moz.build
@@ -84,18 +84,18 @@ EXTRA_JS_MODULES += [
     'systemlibs.js',
 ]
 
 if CONFIG['MOZ_B2G_RIL']:
     XPIDL_SOURCES += [
         'nsIRadioInterfaceLayer.idl',
     ]
     EXTRA_COMPONENTS += [
-        'RILContentHelper.js', # TODO: Bug 815526, deprecate RILContentHelper.
-        'RILContentHelper.manifest', # TODO: Bug 815526, deprecate RILContentHelper.
+        'RILContentHelper.js',
+        'RILContentHelper.manifest',
         'RILSystemMessengerHelper.js',
         'RILSystemMessengerHelper.manifest',
     ]
     EXTRA_JS_MODULES += [
         'ril_consts.js',
         'ril_worker.js',
         'ril_worker_buf_object.js',
         'RILSystemMessenger.jsm',
--- a/dom/system/gonk/nsIRadioInterfaceLayer.idl
+++ b/dom/system/gonk/nsIRadioInterfaceLayer.idl
@@ -20,17 +20,17 @@ interface nsIRilNetworkInterface : nsINe
   readonly attribute DOMString mmsProxy; // Empty string if not set.
   readonly attribute long      mmsPort;  // -1 if not set.
 };
 
 [scriptable, uuid(4441e660-4ad0-11e4-916c-0800200c9a66)]
 interface nsIRilContext : nsISupports
 {
   /**
-   * One of the nsIIcc.CARD_STATE_* values.
+   * One of the nsIIccProvider.CARD_STATE_* values.
    */
   readonly attribute unsigned long cardState;
 
   readonly attribute DOMString imsi;
 
   readonly attribute nsIIccInfo iccInfo;
 };
 
@@ -74,18 +74,8 @@ interface nsIRadioInterfaceLayer : nsISu
    * Select a proper client for dialing emergency call.
    *
    * @return clientId or -1 if none of the clients are avaialble.
    */
   unsigned long getClientIdForEmergencyCall();
 
   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
-{
-};
--- a/dom/system/gonk/ril_consts.js
+++ b/dom/system/gonk/ril_consts.js
@@ -2552,17 +2552,17 @@ this.CALL_FAIL_ERROR_UNSPECIFIED = 0xfff
 
 // See nsIMobileConnection::MOBILE_RADIO_STATE_*
 this.GECKO_RADIOSTATE_UNKNOWN   = -1;
 this.GECKO_RADIOSTATE_ENABLED   = 0;
 this.GECKO_RADIOSTATE_DISABLED  = 1;
 
 // Only used in ril_worker.js
 this.GECKO_CARDSTATE_UNINITIALIZED = 4294967294; // UINT32_MAX - 1
-// See nsIIcc::CARD_STATE_*
+// See nsIIccProvider::CARD_STATE_*
 this.GECKO_CARDSTATE_UNDETECTED = 4294967295; // UINT32_MAX
 this.GECKO_CARDSTATE_UNKNOWN = 0;
 this.GECKO_CARDSTATE_READY = 1;
 this.GECKO_CARDSTATE_PIN_REQUIRED = 2;
 this.GECKO_CARDSTATE_PUK_REQUIRED = 3;
 this.GECKO_CARDSTATE_PERMANENT_BLOCKED = 4;
 this.GECKO_CARDSTATE_PERSONALIZATION_IN_PROGRESS = 5;
 this.GECKO_CARDSTATE_PERSONALIZATION_READY = 6;
@@ -2585,17 +2585,17 @@ this.GECKO_CARDSTATE_RUIM_LOCKED = 22;
 this.GECKO_CARDSTATE_NETWORK1_PUK_REQUIRED = 23;
 this.GECKO_CARDSTATE_NETWORK2_PUK_REQUIRED = 24;
 this.GECKO_CARDSTATE_HRPD_NETWORK_PUK_REQUIRED = 25;
 this.GECKO_CARDSTATE_RUIM_CORPORATE_PUK_REQUIRED = 26;
 this.GECKO_CARDSTATE_RUIM_SERVICE_PROVIDER_PUK_REQUIRED = 27;
 this.GECKO_CARDSTATE_RUIM_PUK_REQUIRED = 28;
 this.GECKO_CARDSTATE_ILLEGAL = 29;
 
-// See nsIIcc::CARD_LOCK_TYPE_*
+// See nsIIccProvider::CARD_LOCK_TYPE_*
 this.GECKO_CARDLOCK_PIN = 0;
 this.GECKO_CARDLOCK_PIN2 = 1;
 this.GECKO_CARDLOCK_PUK = 2;
 this.GECKO_CARDLOCK_PUK2 = 3;
 this.GECKO_CARDLOCK_NCK = 4;
 this.GECKO_CARDLOCK_NSCK = 5;
 this.GECKO_CARDLOCK_NCK1 = 6;
 this.GECKO_CARDLOCK_NCK2 = 7;
@@ -2628,27 +2628,27 @@ GECKO_CARDLOCK_TO_SEL_CODE[GECKO_CARDLOC
 GECKO_CARDLOCK_TO_SEL_CODE[GECKO_CARDLOCK_PUK2] = ICC_SEL_CODE_SIM_PUK2;
 GECKO_CARDLOCK_TO_SEL_CODE[GECKO_CARDLOCK_NCK] = ICC_SEL_CODE_PH_NET_PIN;
 GECKO_CARDLOCK_TO_SEL_CODE[GECKO_CARDLOCK_NSCK] = ICC_SEL_CODE_PH_NETSUB_PIN;
 GECKO_CARDLOCK_TO_SEL_CODE[GECKO_CARDLOCK_CCK] = ICC_SEL_CODE_PH_CORP_PIN;
 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 nsIIcc::CARD_CONTACT_TYPE_*
+// See nsIIccProvider::CARD_CONTACT_TYPE_*
 this.GECKO_CARDCONTACT_TYPE_ADN = 0;
 this.GECKO_CARDCONTACT_TYPE_FDN = 1;
 this.GECKO_CARDCONTACT_TYPE_SDN = 2;
 
-// See nsIIcc::CARD_MVNO_TYPE_*
+// See nsIIccProvider::CARD_MVNO_TYPE_*
 this.GECKO_CARDMVNO_TYPE_IMSI = 0;
 this.GECKO_CARDMVNO_TYPE_SPN = 1;
 this.GECKO_CARDMVNO_TYPE_GID = 2;
 
-// See nsIIcc::CARD_SERVICE_*
+// See nsIIccProvider::CARD_MVNO_TYPE_*
 this.GECKO_CARDSERVICE_FDN = 0;
 
 // See ril.h RIL_PersoSubstate
 this.PERSONSUBSTATE = {};
 PERSONSUBSTATE[CARD_PERSOSUBSTATE_UNKNOWN] = GECKO_CARDSTATE_UNKNOWN;
 PERSONSUBSTATE[CARD_PERSOSUBSTATE_IN_PROGRESS] = GECKO_CARDSTATE_PERSONALIZATION_IN_PROGRESS;
 PERSONSUBSTATE[CARD_PERSOSUBSTATE_READY] = GECKO_CARDSTATE_PERSONALIZATION_READY;
 PERSONSUBSTATE[CARD_PERSOSUBSTATE_SIM_NETWORK] = GECKO_CARDSTATE_NETWORK_LOCKED;
--- a/dom/system/gonk/tests/marionette/test_ril_code_quality.py
+++ b/dom/system/gonk/tests/marionette/test_ril_code_quality.py
@@ -1,13 +1,13 @@
 """
 The test performs the static code analysis check by JSHint.
 
 Target js files:
-- RILContentHelper.js TODO: Bug 815526, deprecate RILContentHelper.
+- RILContentHelper.js
 - RadioInterfaceLayer.js
 - ril_worker.js
 - ril_consts.js
 
 If the js file contains the line of 'importScript()' (Ex: ril_worker.js), the
 test will perform a special merge step before excuting JSHint.
 
 Ex: Script A
@@ -95,17 +95,17 @@ class StringUtility:
 
 
 class ResourceUriFileReader:
 
     """Handle the process of reading the source code from system."""
 
     URI_PREFIX = 'resource://gre/'
     URI_PATH = {
-        'RILContentHelper.js':    'components/RILContentHelper.js', #TODO: Bug 815526, deprecate RILContentHelper.
+        'RILContentHelper.js':    'components/RILContentHelper.js',
         'RadioInterfaceLayer.js': 'components/RadioInterfaceLayer.js',
         'ril_worker.js':          'modules/ril_worker.js',
         'ril_consts.js':          'modules/ril_consts.js',
         'systemlibs.js':          'modules/systemlibs.js',
         'worker_buf.js':          'modules/workers/worker_buf.js',
     }
 
     CODE_OPEN_CHANNEL_BY_URI = '''
@@ -349,17 +349,16 @@ class TestRILCodeQuality(MarionetteTestC
             JSHintEngine(self.marionette,
                          self._read_local_file(self.JSHINT_PATH),
                          self._read_local_file(self.JSHINTRC_PATH)),
             self._get_extended_error_message)
 
     def tearDown(self):
         MarionetteTestCase.tearDown(self)
 
-    # TODO: Bug 815526, deprecate RILContentHelper.
     def test_RILContentHelper(self):
         self._check('RILContentHelper.js')
 
     def test_RadioInterfaceLayer(self):
         self._check('RadioInterfaceLayer.js')
 
     # Bug 936504. Disable the test for 'ril_worker.js'. It sometimes runs very
     # slow and causes the timeout fail on try server.
--- a/dom/system/gonk/tests/test_ril_worker_icc_CardState.js
+++ b/dom/system/gonk/tests/test_ril_worker_icc_CardState.js
@@ -28,75 +28,75 @@ add_test(function test_personalization_s
 
     ril._isCdma = isCdma;
     ril._processICCStatus(iccStatus);
     equal(ril.cardState, geckoCardState);
   }
 
   // Test GSM personalization state.
   testPersonalization(false, CARD_PERSOSUBSTATE_SIM_NETWORK,
-                      Ci.nsIIcc.CARD_STATE_NETWORK_LOCKED);
+                      Ci.nsIIccProvider.CARD_STATE_NETWORK_LOCKED);
   testPersonalization(false, CARD_PERSOSUBSTATE_SIM_NETWORK_SUBSET,
-                      Ci.nsIIcc.CARD_STATE_NETWORK_SUBSET_LOCKED);
+                      Ci.nsIIccProvider.CARD_STATE_NETWORK_SUBSET_LOCKED);
   testPersonalization(false, CARD_PERSOSUBSTATE_SIM_CORPORATE,
-                      Ci.nsIIcc.CARD_STATE_CORPORATE_LOCKED);
+                      Ci.nsIIccProvider.CARD_STATE_CORPORATE_LOCKED);
   testPersonalization(false, CARD_PERSOSUBSTATE_SIM_SERVICE_PROVIDER,
-                      Ci.nsIIcc.CARD_STATE_SERVICE_PROVIDER_LOCKED);
+                      Ci.nsIIccProvider.CARD_STATE_SERVICE_PROVIDER_LOCKED);
   testPersonalization(false, CARD_PERSOSUBSTATE_SIM_SIM,
-                      Ci.nsIIcc.CARD_STATE_SIM_LOCKED);
+                      Ci.nsIIccProvider.CARD_STATE_SIM_LOCKED);
   testPersonalization(false, CARD_PERSOSUBSTATE_SIM_NETWORK_PUK,
-                      Ci.nsIIcc.CARD_STATE_NETWORK_PUK_REQUIRED);
+                      Ci.nsIIccProvider.CARD_STATE_NETWORK_PUK_REQUIRED);
   testPersonalization(false, CARD_PERSOSUBSTATE_SIM_NETWORK_SUBSET_PUK,
-                      Ci.nsIIcc.CARD_STATE_NETWORK_SUBSET_PUK_REQUIRED);
+                      Ci.nsIIccProvider.CARD_STATE_NETWORK_SUBSET_PUK_REQUIRED);
   testPersonalization(false, CARD_PERSOSUBSTATE_SIM_CORPORATE_PUK,
-                      Ci.nsIIcc.CARD_STATE_CORPORATE_PUK_REQUIRED);
+                      Ci.nsIIccProvider.CARD_STATE_CORPORATE_PUK_REQUIRED);
   testPersonalization(false, CARD_PERSOSUBSTATE_SIM_SERVICE_PROVIDER_PUK,
-                      Ci.nsIIcc.CARD_STATE_SERVICE_PROVIDER_PUK_REQUIRED);
+                      Ci.nsIIccProvider.CARD_STATE_SERVICE_PROVIDER_PUK_REQUIRED);
   testPersonalization(false, CARD_PERSOSUBSTATE_SIM_SIM_PUK,
-                      Ci.nsIIcc.CARD_STATE_SIM_PUK_REQUIRED);
+                      Ci.nsIIccProvider.CARD_STATE_SIM_PUK_REQUIRED);
 
   testPersonalization(false, CARD_PERSOSUBSTATE_UNKNOWN,
-                      Ci.nsIIcc.CARD_STATE_UNKNOWN);
+                      Ci.nsIIccProvider.CARD_STATE_UNKNOWN);
   testPersonalization(false, CARD_PERSOSUBSTATE_IN_PROGRESS,
-                      Ci.nsIIcc.CARD_STATE_PERSONALIZATION_IN_PROGRESS);
+                      Ci.nsIIccProvider.CARD_STATE_PERSONALIZATION_IN_PROGRESS);
   testPersonalization(false, CARD_PERSOSUBSTATE_READY,
-                      Ci.nsIIcc.CARD_STATE_PERSONALIZATION_READY);
+                      Ci.nsIIccProvider.CARD_STATE_PERSONALIZATION_READY);
 
   // Test CDMA personalization state.
   testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_NETWORK1,
-                      Ci.nsIIcc.CARD_STATE_NETWORK1_LOCKED);
+                      Ci.nsIIccProvider.CARD_STATE_NETWORK1_LOCKED);
   testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_NETWORK2,
-                      Ci.nsIIcc.CARD_STATE_NETWORK2_LOCKED);
+                      Ci.nsIIccProvider.CARD_STATE_NETWORK2_LOCKED);
   testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_HRPD,
-                      Ci.nsIIcc.CARD_STATE_HRPD_NETWORK_LOCKED);
+                      Ci.nsIIccProvider.CARD_STATE_HRPD_NETWORK_LOCKED);
   testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_CORPORATE,
-                      Ci.nsIIcc.CARD_STATE_RUIM_CORPORATE_LOCKED);
+                      Ci.nsIIccProvider.CARD_STATE_RUIM_CORPORATE_LOCKED);
   testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_SERVICE_PROVIDER,
-                      Ci.nsIIcc.CARD_STATE_RUIM_SERVICE_PROVIDER_LOCKED);
+                      Ci.nsIIccProvider.CARD_STATE_RUIM_SERVICE_PROVIDER_LOCKED);
   testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_RUIM,
-                      Ci.nsIIcc.CARD_STATE_RUIM_LOCKED);
+                      Ci.nsIIccProvider.CARD_STATE_RUIM_LOCKED);
   testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_NETWORK1_PUK,
-                      Ci.nsIIcc.CARD_STATE_NETWORK1_PUK_REQUIRED);
+                      Ci.nsIIccProvider.CARD_STATE_NETWORK1_PUK_REQUIRED);
   testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_NETWORK2_PUK,
-                      Ci.nsIIcc.CARD_STATE_NETWORK2_PUK_REQUIRED);
+                      Ci.nsIIccProvider.CARD_STATE_NETWORK2_PUK_REQUIRED);
   testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_HRPD_PUK,
-                      Ci.nsIIcc.CARD_STATE_HRPD_NETWORK_PUK_REQUIRED);
+                      Ci.nsIIccProvider.CARD_STATE_HRPD_NETWORK_PUK_REQUIRED);
   testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_CORPORATE_PUK,
-                      Ci.nsIIcc.CARD_STATE_RUIM_CORPORATE_PUK_REQUIRED);
+                      Ci.nsIIccProvider.CARD_STATE_RUIM_CORPORATE_PUK_REQUIRED);
   testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_SERVICE_PROVIDER_PUK,
-                      Ci.nsIIcc.CARD_STATE_RUIM_SERVICE_PROVIDER_PUK_REQUIRED);
+                      Ci.nsIIccProvider.CARD_STATE_RUIM_SERVICE_PROVIDER_PUK_REQUIRED);
   testPersonalization(true, CARD_PERSOSUBSTATE_RUIM_RUIM_PUK,
-                      Ci.nsIIcc.CARD_STATE_RUIM_PUK_REQUIRED);
+                      Ci.nsIIccProvider.CARD_STATE_RUIM_PUK_REQUIRED);
 
   testPersonalization(true, CARD_PERSOSUBSTATE_UNKNOWN,
-                      Ci.nsIIcc.CARD_STATE_UNKNOWN);
+                      Ci.nsIIccProvider.CARD_STATE_UNKNOWN);
   testPersonalization(true, CARD_PERSOSUBSTATE_IN_PROGRESS,
-                      Ci.nsIIcc.CARD_STATE_PERSONALIZATION_IN_PROGRESS);
+                      Ci.nsIIccProvider.CARD_STATE_PERSONALIZATION_IN_PROGRESS);
   testPersonalization(true, CARD_PERSOSUBSTATE_READY,
-                      Ci.nsIIcc.CARD_STATE_PERSONALIZATION_READY);
+                      Ci.nsIIccProvider.CARD_STATE_PERSONALIZATION_READY);
 
   run_next_test();
 });
 
 /**
  * Verify SIM app_state in _processICCStatus
  */
 add_test(function test_card_app_state() {
@@ -116,27 +116,27 @@ add_test(function test_card_app_state() 
       }],
     };
 
     ril._processICCStatus(iccStatus);
     equal(ril.cardState, geckoCardState);
   }
 
   testCardAppState(CARD_APPSTATE_ILLEGAL,
-                   Ci.nsIIcc.CARD_STATE_ILLEGAL);
+                   Ci.nsIIccProvider.CARD_STATE_ILLEGAL);
   testCardAppState(CARD_APPSTATE_PIN,
-                   Ci.nsIIcc.CARD_STATE_PIN_REQUIRED);
+                   Ci.nsIIccProvider.CARD_STATE_PIN_REQUIRED);
   testCardAppState(CARD_APPSTATE_PUK,
-                   Ci.nsIIcc.CARD_STATE_PUK_REQUIRED);
+                   Ci.nsIIccProvider.CARD_STATE_PUK_REQUIRED);
   testCardAppState(CARD_APPSTATE_READY,
-                   Ci.nsIIcc.CARD_STATE_READY);
+                   Ci.nsIIccProvider.CARD_STATE_READY);
   testCardAppState(CARD_APPSTATE_UNKNOWN,
-                   Ci.nsIIcc.CARD_STATE_UNKNOWN);
+                   Ci.nsIIccProvider.CARD_STATE_UNKNOWN);
   testCardAppState(CARD_APPSTATE_DETECTED,
-                   Ci.nsIIcc.CARD_STATE_UNKNOWN);
+                   Ci.nsIIccProvider.CARD_STATE_UNKNOWN);
 
   run_next_test();
 });
 
 /**
  * Verify permanent blocked for ICC.
  */
 add_test(function test_icc_permanent_blocked() {
@@ -154,17 +154,17 @@ add_test(function test_icc_permanent_blo
       apps: [
       {
         pin1_replaced: pin1_replaced,
         pin1: pin1
       }]
     };
 
     ril._processICCStatus(iccStatus);
-    equal(ril.cardState, Ci.nsIIcc.CARD_STATE_PERMANENT_BLOCKED);
+    equal(ril.cardState, Ci.nsIIccProvider.CARD_STATE_PERMANENT_BLOCKED);
   }
 
   testPermanentBlocked(1,
                        CARD_PINSTATE_ENABLED_PERM_BLOCKED,
                        CARD_PINSTATE_UNKNOWN);
   testPermanentBlocked(1,
                        CARD_PINSTATE_ENABLED_PERM_BLOCKED,
                        CARD_PINSTATE_ENABLED_PERM_BLOCKED);
--- a/dom/webidl/Console.webidl
+++ b/dom/webidl/Console.webidl
@@ -40,18 +40,18 @@ interface Console {
   [BinaryName="noopMethod"]
   void timelineEnd();
   [BinaryName="noopMethod"]
   void timeStamp();
 };
 
 // This is used to propagate console events to the observers.
 dictionary ConsoleEvent {
-  (unsigned long or DOMString) ID;
-  (unsigned long or DOMString) innerID;
+  (unsigned long long or DOMString) ID;
+  (unsigned long long or DOMString) innerID;
   DOMString level = "";
   DOMString filename = "";
   unsigned long lineNumber = 0;
   unsigned long columnNumber = 0;
   DOMString functionName = "";
   double timeStamp = 0;
   sequence<any> arguments;
 
--- a/dom/webidl/MozIcc.webidl
+++ b/dom/webidl/MozIcc.webidl
@@ -124,26 +124,16 @@ dictionary IccSetCardLockOptions
 
  DOMString? newPin = null; // Used for changing password operation.
                            // Necessary for lock types: "pin", "pin2"
 
  boolean enabled; // Used for enabling/disabling operation.
                   // 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"]
 interface MozIcc : EventTarget
 {
   // Integrated Circuit Card Information.
 
   /**
@@ -252,17 +242,16 @@ interface MozIcc : EventTarget
    *
    * @param lockType
    *        Identifies the lock type.
    *
    * @return a DOMRequest.
    *         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);
 
   /**
    * Unlock a card lock.
    *
    * @param info
@@ -295,18 +284,18 @@ interface MozIcc : EventTarget
   /**
    * Retrieve the number of remaining tries for unlocking the card.
    *
    * @param lockType
    *        Identifies the lock type.
    *
    * @return a DOMRequest.
    *         The request's result will be an object containing the number of
-   *         remaining retries. e.g. {retryCount: 3}.
-   *         @see IccCardLockRetryCount.
+   *         remaining retries.
+   *         e.g. {retryCount: 3}.
    */
   [Throws]
   DOMRequest getCardLockRetryCount(IccLockType lockType);
 
   // Integrated Circuit Card Phonebook Interfaces.
 
   /**
    * Read ICC contacts.
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -224,17 +224,16 @@ WEBIDL_FILES = [
     'HTMLTableSectionElement.webidl',
     'HTMLTemplateElement.webidl',
     'HTMLTextAreaElement.webidl',
     'HTMLTimeElement.webidl',
     'HTMLTitleElement.webidl',
     'HTMLTrackElement.webidl',
     'HTMLUListElement.webidl',
     'HTMLVideoElement.webidl',
-    'IccCardLockError.webidl',
     'IDBCursor.webidl',
     'IDBDatabase.webidl',
     'IDBEnvironment.webidl',
     'IDBFactory.webidl',
     'IDBFileHandle.webidl',
     'IDBFileRequest.webidl',
     'IDBIndex.webidl',
     'IDBKeyRange.webidl',
@@ -283,19 +282,16 @@ WEBIDL_FILES = [
     'MimeType.webidl',
     'MimeTypeArray.webidl',
     'MMICall.webidl',
     'MouseEvent.webidl',
     'MouseScrollEvent.webidl',
     'MozActivity.webidl',
     'MozCellBroadcast.webidl',
     'MozCellBroadcastMessage.webidl',
-    'MozIcc.webidl',
-    'MozIccInfo.webidl',
-    'MozIccManager.webidl',
     'MozMmsMessage.webidl',
     'MozMobileCellInfo.webidl',
     'MozMobileConnection.webidl',
     'MozMobileConnectionArray.webidl',
     'MozMobileConnectionInfo.webidl',
     'MozMobileMessageManager.webidl',
     'MozMobileNetworkInfo.webidl',
     'MozPowerManager.webidl',
@@ -647,16 +643,24 @@ if CONFIG['MOZ_B2G_BT']:
         ]
     else:
         WEBIDL_FILES += [
             'BluetoothAdapter.webidl',
             'BluetoothDevice.webidl',
             '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',
          'MozNDEFRecord.webidl',
          'MozNFC.webidl',
          'MozNFCPeer.webidl',
          'MozNFCTag.webidl',
          'NfcOptions.webidl',
--- a/dom/wifi/test/marionette/head.js
+++ b/dom/wifi/test/marionette/head.js
@@ -446,16 +446,67 @@ let gTestSuite = (function() {
    */
   function requestWifiScan() {
     let request = wifiManager.getNetworks();
     return wrapDomRequestAsPromise(request)
       .then(event => event.target.result);
   }
 
   /**
+   * Import a certificate with nickname and password.
+   *
+   * Resolve when we import certificate successfully; reject when any error
+   * occurs.
+   *
+   * Fulfill params: An object of certificate information.
+   * Reject params: (none)
+   *
+   * @return A deferred promise.
+   */
+  function importCert(certBlob, password, nickname) {
+    let request = wifiManager.importCert(certBlob, password, nickname);
+    return wrapDomRequestAsPromise(request)
+      .then(event => event.target.result);
+  }
+
+  /**
+   * Delete certificate of nickname.
+   *
+   * Resolve when we delete certificate successfully; reject when any error
+   * occurs.
+   *
+   * Fulfill params: (none)
+   * Reject params: (none)
+   *
+   * @return A deferred promise.
+   */
+  function deleteCert(nickname) {
+    let request = wifiManager.deleteCert(nickname);
+    return wrapDomRequestAsPromise(request)
+      .then(event => event.target.result);
+  }
+
+  /**
+   * Get list of imported certificates.
+   *
+   * Resolve when we get certificate list successfully; reject when any error
+   * occurs.
+   *
+   * Fulfill params: Nickname of imported certificate arranged by usage.
+   * Reject params: (none)
+   *
+   * @return A deferred promise.
+   */
+  function getImportedCerts() {
+    let request = wifiManager.getImportedCerts();
+    return wrapDomRequestAsPromise(request)
+      .then(event => event.target.result);
+  }
+
+  /**
    * Request wifi scan and verify the scan result as well.
    *
    * Issue a wifi scan request and check if the result is expected.
    * Since the old APs may be cached and the newly added APs may be
    * still not scan-able, a couple of attempts are acceptable.
    * Resolve if we eventually get the expected scan result; reject otherwise.
    *
    * Fulfill params: The scan result, which is an array of MozWifiNetwork
@@ -1183,16 +1234,19 @@ let gTestSuite = (function() {
   suite.testAssociate = testAssociate;
   suite.getKnownNetworks = getKnownNetworks;
   suite.requestWifiScan = requestWifiScan;
   suite.waitForConnected = waitForConnected;
   suite.forgetNetwork = forgetNetwork;
   suite.waitForTimeout = waitForTimeout;
   suite.waitForRilDataConnected = waitForRilDataConnected;
   suite.requestTetheringEnabled = requestTetheringEnabled;
+  suite.importCert = importCert;
+  suite.getImportedCerts = getImportedCerts;
+  suite.deleteCert = deleteCert;
 
   /**
    * Common test routine.
    *
    * Start a test with the given test case chain. The test environment will be
    * settled down before the test. After the test, all the affected things will
    * be restored.
    *
@@ -1283,10 +1337,66 @@ let gTestSuite = (function() {
         .then(aTestCaseChain)
         .then(restoreToInitialState, function onreject(aReason) {
           return restoreToInitialState()
             .then(() => { throw aReason; }); // Re-throw the orignal reject reason.
         });
     });
   };
 
+  /**
+   * Run test with imported certificate.
+   *
+   * Certificate will be imported and confirmed before running test, and be
+   * deleted after running test.
+   *
+   * Fulfill params: (none)
+   *
+   * @param certBlob
+   *        Certificate content as Blob.
+   * @param password
+   *        Password for importing certificate, only used for importing PKCS#12.
+   * @param nickanem
+   *        Nickname for imported certificate.
+   * @param usage
+   *        Expected usage of imported certificate.
+   * @param aTestCaseChain
+   *        The test case entry point, which can be a function or a promise.
+   *
+   * @return A deferred promise.
+   */
+  suite.doTestWithCertificate = function(certBlob, password, nickname, usage, aTestCaseChain) {
+    return suite.doTest(function() {
+      return ensureWifiEnabled(true)
+      // Import test certificate.
+      .then(() => importCert(certBlob, password, nickname))
+      .then(function(info) {
+        // Check import result.
+        is(info.nickname, nickname, "Imported nickname");
+        for (let i = 0; i < usage.length; i++) {
+          isnot(info.usage.indexOf(usage[i]), -1, "Usage " + usage[i]);
+        }
+      })
+      // Get imported certificate list.
+      .then(getImportedCerts)
+      // Check if certificate exists in imported certificate list.
+      .then(function(list) {
+        for (let i = 0; i < usage.length; i++) {
+          isnot(list[usage[i]].indexOf(nickname), -1,
+                "Certificate \"" + nickname + "\" of usage " + usage[i] + " is imported");
+        }
+      })
+      // Run test case.
+      .then(aTestCaseChain)
+      // Delete imported certificates.
+      .then(() => deleteCert(nickname))
+      // Check if certificate doesn't exist in imported certificate list.
+      .then(getImportedCerts)
+      .then(function(list) {
+        for (let i = 0; i < usage.length; i++) {
+          is(list[usage[i]].indexOf(nickname), -1, "Certificate is deleted");
+        }
+      })
+    });
+  };
+
   return suite;
 })();
--- a/dom/wifi/test/marionette/manifest.ini
+++ b/dom/wifi/test/marionette/manifest.ini
@@ -6,9 +6,12 @@ qemu = true
 [test_wifi_enable.js]
 [test_wifi_scan.js]
 [test_wifi_associate.js]
 [test_wifi_associate_wo_connect.js]
 [test_wifi_auto_connect.js]
 [test_wifi_tethering_wifi_disabled.js]
 [test_wifi_tethering_wifi_inactive.js]
 [test_wifi_tethering_wifi_active.js]
+[test_wifi_manage_server_certificate.js]
+[test_wifi_manage_user_certificate.js]
+[test_wifi_manage_pkcs12_certificate.js]
 [test_wifi_enable_api.js]
new file mode 100644
--- /dev/null
+++ b/dom/wifi/test/marionette/test_wifi_manage_pkcs12_certificate.js
@@ -0,0 +1,338 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
+
+// Binary form of test certificate.
+var testCertInfo = {
+  nickname: 'Test Certificate',
+  password: '12345678',
+  usage: ['UserCert', 'ServerCert'],
+  blob: [0x30, 0x82, 0x09, 0xF1, 0x02, 0x01, 0x03, 0x30,
+        0x82, 0x09, 0xB7, 0x06, 0x09, 0x2A, 0x86, 0x48,
+        0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0xA0, 0x82,
+        0x09, 0xA8, 0x04, 0x82, 0x09, 0xA4, 0x30, 0x82,
+        0x09, 0xA0, 0x30, 0x82, 0x06, 0x9F, 0x06, 0x09,
+        0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07,
+        0x06, 0xA0, 0x82, 0x06, 0x90, 0x30, 0x82, 0x06,
+        0x8C, 0x02, 0x01, 0x00, 0x30, 0x82, 0x06, 0x85,
+        0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
+        0x01, 0x07, 0x01, 0x30, 0x1C, 0x06, 0x0A, 0x2A,
+        0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x0C, 0x01,
+        0x06, 0x30, 0x0E, 0x04, 0x08, 0x13, 0xB5, 0x2F,
+        0x5A, 0xB9, 0x49, 0xE6, 0x0B, 0x02, 0x02, 0x08,
+        0x00, 0x80, 0x82, 0x06, 0x58, 0x35, 0x77, 0x6B,
+        0xBF, 0x5C, 0x06, 0x09, 0xD8, 0xF0, 0x36, 0x06,
+        0x69, 0x8D, 0xA2, 0x86, 0xCF, 0x6B, 0x73, 0x86,
+        0x14, 0xFA, 0x51, 0x9A, 0x87, 0x73, 0x29, 0x71,
+        0xC5, 0xB1, 0x4F, 0xFB, 0xEC, 0x64, 0x84, 0x20,
+        0xFC, 0x06, 0x4A, 0x93, 0x74, 0x01, 0xFB, 0xEB,
+        0x1F, 0xDC, 0xF8, 0xF7, 0xBB, 0xDC, 0x42, 0xA1,
+        0x4A, 0x71, 0xDE, 0x08, 0x33, 0x7A, 0xCA, 0xD3,
+        0xD8, 0x40, 0x24, 0x47, 0xAE, 0x41, 0x42, 0x8E,
+        0xC8, 0x4E, 0xBE, 0x8B, 0xB3, 0xE5, 0x77, 0xAC,
+        0xBD, 0x98, 0x0C, 0x0E, 0x53, 0xBE, 0x38, 0xB7,
+        0xEA, 0xD2, 0x29, 0x35, 0xD2, 0xC4, 0xF4, 0xC7,
+        0xD8, 0xB1, 0x73, 0x2A, 0x13, 0x11, 0x65, 0xF7,
+        0x0C, 0x8B, 0xC0, 0x43, 0xFB, 0x31, 0x6C, 0xD2,
+        0xE4, 0x43, 0x85, 0x51, 0x16, 0xBF, 0x35, 0xB5,
+        0x05, 0x6B, 0x86, 0x11, 0xEA, 0x78, 0x64, 0x9F,
+        0x42, 0x29, 0xB9, 0x79, 0xAF, 0xB0, 0x7C, 0xBF,
+        0xC0, 0x89, 0xAD, 0xC7, 0x37, 0xD2, 0x30, 0x8C,
+        0xDC, 0xF6, 0x77, 0x5E, 0x1F, 0x26, 0x28, 0x8F,
+        0xAC, 0x19, 0x6C, 0xA0, 0x15, 0xC7, 0x12, 0xA3,
+        0x0A, 0xD5, 0xC6, 0x15, 0x60, 0x58, 0x16, 0xB8,
+        0x30, 0x12, 0x3C, 0x78, 0x3C, 0x93, 0x23, 0xA1,
+        0x56, 0x75, 0x0B, 0x77, 0xAA, 0x0B, 0x0B, 0x2B,
+        0x91, 0xB6, 0x41, 0xAB, 0xF5, 0x09, 0x4C, 0x1E,
+        0x36, 0xC0, 0x88, 0xC3, 0x08, 0xF2, 0x65, 0xCB,
+        0x58, 0x8F, 0x94, 0xB4, 0xB4, 0x05, 0xCC, 0x44,
+        0x49, 0x73, 0x1B, 0x25, 0x6F, 0x5D, 0x83, 0xBD,
+        0xF0, 0x70, 0xD0, 0xE8, 0x0D, 0x18, 0x2E, 0x44,
+        0xD7, 0x89, 0x64, 0x6A, 0xED, 0x23, 0x30, 0xDF,
+        0xAD, 0x84, 0x3B, 0x74, 0x2C, 0x0D, 0x2B, 0x51,
+        0x84, 0xA2, 0xA4, 0x9E, 0x42, 0xC3, 0x81, 0x69,
+        0xFA, 0x56, 0x76, 0x9F, 0xD9, 0x02, 0x64, 0x04,
+        0xFE, 0xF0, 0xD9, 0x01, 0xBC, 0xE2, 0xC9, 0xDD,
+        0x88, 0xAC, 0xFA, 0x24, 0x7E, 0xB1, 0xF8, 0x39,
+        0x27, 0xA2, 0xEB, 0xE4, 0x53, 0xC1, 0xF3, 0xFE,
+        0x2D, 0x9A, 0x49, 0x73, 0xFF, 0x7C, 0x8E, 0x39,
+        0xF7, 0x15, 0x27, 0xB3, 0x47, 0x48, 0x92, 0x8C,
+        0x57, 0x60, 0x9C, 0x97, 0xBA, 0x80, 0xD2, 0x25,
+        0x80, 0x94, 0xCE, 0x2C, 0x0C, 0x00, 0x44, 0x8C,
+        0x8C, 0x37, 0x82, 0x5D, 0x5F, 0x62, 0x8B, 0x05,
+        0x6F, 0xB0, 0x07, 0x34, 0xF9, 0xC3, 0xA1, 0x34,
+        0x3D, 0xE4, 0x90, 0xB0, 0x03, 0x59, 0x97, 0x6E,
+        0xFB, 0xF2, 0x92, 0xE5, 0xB5, 0x30, 0x7C, 0x0D,
+        0x3B, 0x8F, 0x90, 0x8E, 0x04, 0x47, 0x01, 0x0E,
+        0x88, 0x50, 0x4A, 0x88, 0xA0, 0xFF, 0xB7, 0x9E,
+        0x2B, 0x2C, 0x98, 0xD0, 0x3E, 0x16, 0x35, 0x5B,
+        0xD5, 0xEA, 0x54, 0x86, 0xE0, 0xFB, 0x9F, 0x2F,
+        0x62, 0x89, 0x36, 0x36, 0x9D, 0x6E, 0x62, 0xCB,
+        0xC8, 0x6C, 0x62, 0x34, 0x8F, 0x66, 0x07, 0x62,
+        0xA7, 0x00, 0x90, 0x31, 0xFA, 0x5D, 0xDD, 0x12,
+        0x33, 0x69, 0xD0, 0x74, 0x0E, 0x0B, 0x42, 0x9A,
+        0xF3, 0x40, 0x7E, 0x3E, 0x48, 0x1D, 0xF2, 0x5C,
+        0x71, 0x0B, 0x78, 0x7E, 0xD5, 0x15, 0xA4, 0x16,
+        0x1E, 0xBD, 0x71, 0x18, 0x87, 0x3A, 0xC9, 0xE3,
+        0x45, 0xEE, 0x70, 0xA2, 0x4C, 0x50, 0xF5, 0x16,
+        0x5C, 0xF8, 0x76, 0xE6, 0x9F, 0x8D, 0x86, 0x41,
+        0x7E, 0xF8, 0x60, 0x3D, 0x75, 0x6D, 0x55, 0x96,
+        0x9E, 0x43, 0x48, 0x82, 0xF7, 0xB6, 0xAC, 0x98,
+        0x6F, 0x10, 0xAA, 0x20, 0x64, 0xD0, 0x7C, 0x25,
+        0x24, 0xF7, 0xD8, 0xA4, 0xCC, 0x2D, 0xBF, 0x85,
+        0x62, 0x6C, 0x4F, 0xFF, 0x9D, 0x71, 0x04, 0x98,
+        0x61, 0xB0, 0xBC, 0x31, 0xC1, 0xE9, 0xB8, 0x29,
+        0xA5, 0xEB, 0xD1, 0x1D, 0x65, 0x8E, 0xAE, 0x38,
+        0x55, 0x65, 0x22, 0xC7, 0xFD, 0x7E, 0xF2, 0x6A,
+        0xB6, 0xB1, 0x51, 0x37, 0x4B, 0x05, 0x8F, 0xA7,
+        0x2D, 0x3F, 0x5C, 0x04, 0x2B, 0xBA, 0x2C, 0x37,
+        0xCA, 0xDE, 0xD5, 0x3E, 0xA0, 0xA5, 0x86, 0x59,
+        0xA7, 0xD7, 0x38, 0x07, 0xFB, 0x79, 0xF6, 0x2D,
+        0xE1, 0xAA, 0x7C, 0xD1, 0x91, 0xBE, 0x39, 0xDF,
+        0x53, 0x3C, 0xD1, 0x44, 0x2C, 0xF9, 0x12, 0x7D,
+        0xB1, 0xCD, 0xF3, 0x35, 0x1F, 0x85, 0xA6, 0x64,
+        0x2F, 0xFD, 0x28, 0xF2, 0x85, 0xA8, 0xA7, 0x1F,
+        0x7F, 0xD9, 0x79, 0x30, 0x9B, 0xFC, 0x69, 0x3A,
+        0x9B, 0x1F, 0x55, 0x70, 0xC9, 0x60, 0x82, 0x3D,
+        0xE9, 0x5A, 0x37, 0x5F, 0x8C, 0xBD, 0x19, 0x5D,
+        0xCC, 0x1C, 0xBE, 0x26, 0x4A, 0xEA, 0x8B, 0x39,
+        0xCE, 0x0D, 0xBD, 0x63, 0x05, 0x98, 0x75, 0xAB,
+        0x08, 0x79, 0x90, 0xC7, 0x20, 0xFF, 0xE4, 0x0D,
+        0xB1, 0xA0, 0x92, 0x2B, 0x0C, 0x4B, 0x0C, 0xDC,
+        0xB9, 0x72, 0x2A, 0xA4, 0xCC, 0xA6, 0x32, 0xA3,
+        0x57, 0x82, 0xB4, 0xB9, 0x0F, 0x81, 0xC5, 0xD9,
+        0x7C, 0xB8, 0x0F, 0x7D, 0xEA, 0x5D, 0xD3, 0xC4,
+        0x2F, 0x31, 0x79, 0x11, 0xAD, 0x36, 0x56, 0x1F,
+        0xFA, 0xE3, 0xCE, 0xD2, 0x29, 0x23, 0xE8, 0x2C,
+        0xDF, 0x7D, 0x94, 0x28, 0x28, 0x9A, 0x0E, 0x64,
+        0xFC, 0x07, 0x11, 0x96, 0x06, 0x1A, 0x39, 0xCD,
+        0x04, 0x37, 0x37, 0xDB, 0xFE, 0x68, 0x37, 0xF5,
+        0x59, 0x54, 0xBC, 0xEF, 0xDB, 0x0C, 0x80, 0xCD,
+        0xD3, 0x46, 0xA8, 0xA2, 0xBE, 0xE0, 0x63, 0x80,
+        0xA1, 0x5F, 0x5D, 0xF1, 0xFB, 0x96, 0x8C, 0x06,
+        0x38, 0xB6, 0xCB, 0x70, 0xB0, 0xFB, 0xD3, 0x26,
+        0xB3, 0x8B, 0xC6, 0x85, 0x34, 0xB7, 0xAB, 0x5F,
+        0x7E, 0xC6, 0xAA, 0x79, 0x5B, 0x48, 0x11, 0x65,
+        0x9E, 0x2A, 0xCD, 0x6A, 0xF0, 0xB2, 0x93, 0xF5,
+        0x2B, 0x88, 0x45, 0xB7, 0xC9, 0xBE, 0x1A, 0x72,
+        0x60, 0x62, 0xA4, 0xA5, 0x3B, 0xC2, 0x1C, 0xC6,
+        0x21, 0x09, 0xA9, 0x40, 0xF6, 0x58, 0x2B, 0xE5,
+        0x70, 0xDC, 0xFC, 0x47, 0x3B, 0x08, 0xEE, 0xA9,
+        0x94, 0x26, 0x43, 0xFE, 0xA7, 0x75, 0xD6, 0x4E,
+        0x52, 0xF6, 0x46, 0xD1, 0x80, 0xEB, 0x3B, 0x8E,
+        0xBE, 0x54, 0x4F, 0xBD, 0x42, 0x0E, 0x41, 0xF9,
+        0x36, 0x7D, 0xB6, 0x7F, 0x99, 0x20, 0xC9, 0x63,
+        0xE7, 0x93, 0x02, 0x62, 0x59, 0x94, 0xCB, 0xC6,
+        0x62, 0xA9, 0x26, 0xE1, 0x1E, 0x03, 0x5A, 0x41,
+        0x2F, 0x43, 0x28, 0x75, 0xB7, 0x0C, 0x02, 0x9C,
+        0x1E, 0xE0, 0x40, 0xB3, 0xE2, 0x9A, 0xED, 0xC6,
+        0x20, 0x49, 0xEC, 0xDD, 0xC5, 0x64, 0x95, 0x83,
+        0x51, 0xAE, 0x46, 0x9D, 0x70, 0x17, 0xC6, 0x47,
+        0xD3, 0x82, 0xCC, 0x6A, 0x5D, 0x93, 0xB2, 0x85,
+        0x5B, 0x25, 0x05, 0xE7, 0x26, 0x2E, 0xD3, 0xDA,
+        0x1C, 0xD9, 0x06, 0xB6, 0x16, 0x69, 0x8C, 0x7F,
+        0xC8, 0xCF, 0x95, 0x18, 0xB5, 0x98, 0xC0, 0x42,
+        0x61, 0xDE, 0x77, 0x41, 0x3A, 0xF6, 0xE1, 0xB0,
+        0xE8, 0x64, 0x4A, 0xC2, 0x58, 0xBE, 0x27, 0xC6,
+        0x9B, 0x0D, 0x47, 0x1A, 0x09, 0x56, 0x7D, 0x2B,
+        0x19, 0x01, 0x88, 0xC7, 0xFB, 0x1E, 0xCF, 0x5E,
+        0xF6, 0xB0, 0x82, 0x87, 0xC0, 0xBE, 0xD6, 0xA5,
+        0xC3, 0xAC, 0x3A, 0x97, 0x88, 0x25, 0x81, 0xAA,
+        0x3A, 0xCE, 0x66, 0x88, 0x0F, 0xC3, 0x02, 0x50,
+        0x1C, 0xC3, 0x2B, 0xBC, 0x53, 0x52, 0xFE, 0xD2,
+        0x3F, 0x50, 0xC8, 0xB2, 0x19, 0x0A, 0x14, 0xB1,
+        0x73, 0x18, 0xB4, 0xDF, 0xBD, 0xED, 0x43, 0xC5,
+        0x91, 0xF4, 0x91, 0xBA, 0x7E, 0xB0, 0x7E, 0xA9,
+        0x43, 0x67, 0x06, 0xCF, 0x51, 0xC1, 0xBF, 0x63,
+        0x7E, 0x91, 0x76, 0xFF, 0x4F, 0x48, 0x91, 0xCF,
+        0xDF, 0x01, 0x4D, 0x7E, 0x81, 0x22, 0xFB, 0x79,
+        0xFC, 0x1D, 0xE3, 0xA7, 0x45, 0x16, 0xFB, 0xF2,
+        0x83, 0xC7, 0xAE, 0xC6, 0xC5, 0x81, 0xDB, 0xA2,
+        0x9F, 0x2F, 0xEA, 0xE6, 0x8E, 0x12, 0x8D, 0x43,
+        0x14, 0x26, 0x25, 0x0E, 0xB4, 0x18, 0xE8, 0x41,
+        0x84, 0xA3, 0x04, 0xDF, 0x97, 0xFF, 0xAA, 0x45,
+        0xEC, 0x18, 0xAA, 0xB1, 0xFC, 0xDC, 0xB9, 0xAB,
+        0xEE, 0xD1, 0xC4, 0x9E, 0x42, 0x3F, 0x5B, 0x8F,
+        0x9F, 0x22, 0xAF, 0xCC, 0x6F, 0xA0, 0x41, 0x41,
+        0xCB, 0xD3, 0xAC, 0x96, 0x20, 0xF1, 0x63, 0x56,
+        0x65, 0xCE, 0x83, 0xC6, 0x62, 0x04, 0x85, 0x16,
+        0x7F, 0x4E, 0xFB, 0xA0, 0x68, 0x11, 0x85, 0x5B,
+        0x51, 0xB6, 0x9F, 0xA2, 0xF5, 0xA1, 0xCF, 0x01,
+        0x9A, 0x80, 0x68, 0xC3, 0xE9, 0x7F, 0x9E, 0x2E,
+        0x83, 0x84, 0xDC, 0x3C, 0x35, 0xCF, 0x24, 0xBF,
+        0xF5, 0x00, 0x91, 0x45, 0x14, 0x65, 0xE0, 0xC5,
+        0x75, 0xDA, 0xEF, 0x14, 0xBD, 0xDB, 0x28, 0x8D,
+        0x30, 0x96, 0xC9, 0xFE, 0xA8, 0x49, 0x76, 0xC9,
+        0xED, 0x90, 0x4C, 0x2E, 0xF1, 0x14, 0x2C, 0xF7,
+        0x13, 0x7C, 0xF1, 0xCC, 0x67, 0xA5, 0x11, 0x55,
+        0xBD, 0x66, 0x13, 0x8A, 0x76, 0xF9, 0xAC, 0xC9,
+        0x51, 0x8A, 0xBB, 0x5D, 0x29, 0xEF, 0xF6, 0x37,
+        0xA0, 0x3E, 0x99, 0x77, 0x6B, 0xE5, 0xCD, 0x06,
+        0xAC, 0x57, 0x07, 0x37, 0x44, 0x3D, 0x5D, 0xD7,
+        0xB6, 0x5C, 0xCB, 0x77, 0xD0, 0x4C, 0x28, 0x9D,
+        0x12, 0x69, 0x5A, 0x68, 0xD1, 0x15, 0x30, 0xC4,
+        0x30, 0xD2, 0x20, 0xDF, 0xD5, 0x73, 0x9F, 0x83,
+        0xE9, 0x4C, 0x55, 0xF5, 0xAF, 0xAA, 0x37, 0xF8,
+        0x28, 0xB6, 0x3F, 0x99, 0x4B, 0x15, 0x1E, 0x40,
+        0xAB, 0x4F, 0x58, 0x3D, 0x3B, 0x81, 0x7D, 0x62,
+        0x28, 0x6E, 0x73, 0x58, 0x50, 0x36, 0x49, 0x01,
+        0xF7, 0x04, 0x3A, 0x23, 0x28, 0xDA, 0x15, 0xC5,
+        0xE3, 0xF6, 0x6F, 0xE1, 0x79, 0x07, 0xFB, 0xAA,
+        0xFF, 0x44, 0x48, 0x53, 0x9E, 0x7F, 0x8D, 0x89,
+        0x88, 0x1A, 0x9A, 0xF9, 0x47, 0x58, 0x20, 0xBB,
+        0x79, 0x4A, 0x2A, 0x14, 0x03, 0x9B, 0x65, 0x4C,
+        0x67, 0x02, 0x02, 0xFE, 0xEB, 0xCD, 0xCB, 0x84,
+        0xF5, 0xCE, 0x32, 0x59, 0xBC, 0xEA, 0xEC, 0xB1,
+        0x3C, 0x22, 0xCF, 0x9D, 0xB0, 0x34, 0x6D, 0xE6,
+        0x5A, 0x37, 0xC0, 0x22, 0xAA, 0xF3, 0xB5, 0x71,
+        0x90, 0x21, 0xE0, 0xB6, 0x19, 0xE9, 0xB3, 0x10,
+        0xCE, 0x5B, 0xF9, 0xD4, 0x25, 0x30, 0x7D, 0xF6,
+        0x7D, 0xB6, 0x16, 0xFC, 0x20, 0x3C, 0x2F, 0x96,
+        0xD5, 0x79, 0x90, 0x88, 0x24, 0x5D, 0x46, 0x64,
+        0x99, 0xC1, 0xF8, 0x7F, 0x96, 0xA7, 0xB5, 0xA9,
+        0x47, 0xA3, 0x14, 0xED, 0x93, 0xED, 0x30, 0x56,
+        0x58, 0xA5, 0xD4, 0x54, 0x2A, 0xF3, 0x89, 0x27,
+        0x7C, 0x55, 0x41, 0x11, 0x27, 0x9D, 0xF6, 0x4D,
+        0xA6, 0xB1, 0x00, 0xE0, 0xB0, 0xF6, 0x1E, 0xAB,
+        0x20, 0x1F, 0xAE, 0x8A, 0x82, 0xA7, 0x49, 0xFC,
+        0xBB, 0x66, 0xAC, 0x97, 0x95, 0x49, 0x29, 0xCB,
+        0x6F, 0xF4, 0xC1, 0xB7, 0x6B, 0xF9, 0x8C, 0x25,
+        0xC6, 0xF0, 0xB5, 0x81, 0xB0, 0xA2, 0x4D, 0xCC,
+        0x2E, 0xD0, 0x13, 0x5F, 0x96, 0x3F, 0xCD, 0xD0,
+        0x52, 0xD1, 0xFE, 0xF9, 0xC2, 0x7E, 0x9D, 0xAB,
+        0xCB, 0x95, 0x0F, 0x27, 0x01, 0x9E, 0x23, 0x6B,
+        0x19, 0xFF, 0x52, 0x55, 0x71, 0x0A, 0xD4, 0xBB,
+        0x43, 0x65, 0x29, 0x66, 0xBE, 0x2D, 0x6C, 0xE3,
+        0x2A, 0x7C, 0xB4, 0x02, 0x32, 0x59, 0x94, 0x80,
+        0x14, 0xE7, 0x62, 0xE4, 0xCE, 0xB0, 0xCA, 0xCA,
+        0x37, 0xD7, 0x0C, 0x68, 0x29, 0xE2, 0x92, 0xE1,
+        0xEB, 0x91, 0xE5, 0xA1, 0x0C, 0xFC, 0x55, 0xCB,
+        0x56, 0xB3, 0x96, 0xFB, 0x64, 0xD9, 0x53, 0x8E,
+        0x82, 0x2B, 0xDF, 0x7F, 0xCB, 0x2A, 0xF6, 0x3C,
+        0xA7, 0x89, 0x52, 0x13, 0x2C, 0x6A, 0x93, 0xA2,
+        0x74, 0xF5, 0x91, 0x00, 0x17, 0xAA, 0x74, 0x45,
+        0x63, 0x5A, 0xE5, 0xC3, 0x16, 0xFC, 0x0E, 0xF7,
+        0xF3, 0xA4, 0x55, 0x8A, 0xA2, 0x60, 0x24, 0x57,
+        0x25, 0x2C, 0x94, 0xE0, 0xF5, 0x32, 0x54, 0x4A,
+        0x2D, 0x63, 0x5F, 0xD8, 0x35, 0x96, 0xBD, 0xFE,
+        0x90, 0x33, 0x17, 0xF6, 0xB5, 0x81, 0x02, 0xFA,
+        0x5C, 0x94, 0x3A, 0xBE, 0x22, 0xB9, 0xFC, 0x3E,
+        0x09, 0xE4, 0x76, 0xD7, 0x03, 0x38, 0x38, 0xC2,
+        0xC2, 0x0D, 0x66, 0x3C, 0xD0, 0x91, 0x5C, 0xF4,
+        0x0E, 0xC2, 0xDE, 0x46, 0x90, 0x2E, 0xF5, 0x22,
+        0xA9, 0x3D, 0x15, 0x20, 0x5F, 0x17, 0x10, 0x5A,
+        0x54, 0x63, 0x93, 0x7B, 0xC3, 0x00, 0x3D, 0x42,
+        0x73, 0xF1, 0xAD, 0xC1, 0xDE, 0x76, 0x18, 0x9C,
+        0x68, 0x17, 0xBF, 0x3B, 0xE0, 0x30, 0x82, 0x02,
+        0xF9, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7,
+        0x0D, 0x01, 0x07, 0x01, 0xA0, 0x82, 0x02, 0xEA,
+        0x04, 0x82, 0x02, 0xE6, 0x30, 0x82, 0x02, 0xE2,
+        0x30, 0x82, 0x02, 0xDE, 0x06, 0x0B, 0x2A, 0x86,
+        0x48, 0x86, 0xF7, 0x0D, 0x01, 0x0C, 0x0A, 0x01,
+        0x02, 0xA0, 0x82, 0x02, 0xA6, 0x30, 0x82, 0x02,
+        0xA2, 0x30, 0x1C, 0x06, 0x0A, 0x2A, 0x86, 0x48,
+        0x86, 0xF7, 0x0D, 0x01, 0x0C, 0x01, 0x03, 0x30,
+        0x0E, 0x04, 0x08, 0x34, 0x37, 0x27, 0x5F, 0xE8,
+        0xD6, 0x00, 0x0D, 0x02, 0x02, 0x08, 0x00, 0x04,
+        0x82, 0x02, 0x80, 0xC0, 0xE6, 0xB1, 0x63, 0x73,
+        0xFC, 0xBF, 0x50, 0xFB, 0x54, 0xCF, 0x67, 0x16,
+        0xF8, 0x28, 0x48, 0x13, 0x7F, 0xF2, 0xBD, 0x66,
+        0x70, 0xC7, 0xF6, 0x01, 0xD0, 0x58, 0xF4, 0xA4,
+        0xD9, 0x45, 0xE2, 0x63, 0x92, 0x7F, 0x78, 0x2B,
+        0xB6, 0xDB, 0x16, 0x44, 0x1D, 0x11, 0xCB, 0xC3,
+        0x20, 0xA9, 0x8A, 0x96, 0x13, 0xB8, 0x6E, 0xF3,
+        0xDA, 0x46, 0x05, 0x2C, 0xF9, 0x67, 0xBB, 0x05,
+        0x88, 0xC0, 0xC8, 0x60, 0x09, 0xA3, 0x82, 0x27,
+        0x33, 0xEB, 0xEE, 0x43, 0x98, 0xE9, 0xE2, 0x24,
+        0xA8, 0x06, 0xD5, 0xFF, 0xF5, 0xC0, 0x79, 0x4B,
+        0x06, 0x40, 0xE6, 0x28, 0xC6, 0x6E, 0x4E, 0x03,
+        0xCC, 0x9B, 0xB6, 0xBD, 0xB6, 0x81, 0x88, 0x5C,
+        0x34, 0x6B, 0x8B, 0x15, 0x23, 0x75, 0x21, 0xAC,
+        0x79, 0xFD, 0xDB, 0x80, 0x1D, 0x20, 0x84, 0xF1,
+        0x47, 0xAF, 0x7B, 0x40, 0x6C, 0xD2, 0x64, 0x52,
+        0x11, 0x1B, 0x01, 0x1E, 0xB5, 0xA9, 0x4B, 0xC4,
+        0x51, 0x54, 0x40, 0xE2, 0xC8, 0xEB, 0x20, 0x48,
+        0x2D, 0x40, 0xF8, 0xC6, 0x58, 0x5A, 0xE3, 0x34,
+        0xD8, 0x79, 0x04, 0xD7, 0xD6, 0x07, 0xF2, 0x12,
+        0x66, 0xC8, 0x31, 0x37, 0x71, 0x60, 0xF4, 0x75,
+        0xDC, 0x60, 0x54, 0x19, 0x6A, 0x75, 0x56, 0xC5,
+        0xA9, 0x67, 0x4A, 0x03, 0x7A, 0xFD, 0x12, 0x59,
+        0x2B, 0x74, 0xE6, 0xA5, 0xE2, 0xF8, 0xBB, 0x1E,
+        0x76, 0x96, 0xD4, 0xD4, 0x3F, 0x8B, 0xAD, 0x90,
+        0xAF, 0x04, 0x41, 0xDB, 0xD8, 0xCC, 0x2D, 0x37,
+        0x06, 0x20, 0x9B, 0xE7, 0x98, 0x87, 0x12, 0xAC,
+        0x70, 0xC9, 0xF4, 0x1C, 0x28, 0xFB, 0x2C, 0x9E,
+        0x18, 0xE1, 0x6D, 0x79, 0x34, 0xBC, 0xAC, 0xCB,
+        0x75, 0x92, 0x7E, 0x8E, 0x7C, 0xA9, 0x0B, 0x86,
+        0x4A, 0x88, 0xFB, 0xE8, 0xBE, 0x6A, 0x32, 0xEF,
+        0x58, 0xCC, 0x4C, 0x89, 0x50, 0xEF, 0xDF, 0xE0,
+        0xDD, 0x35, 0x07, 0x8C, 0x01, 0x8B, 0x57, 0x38,
+        0xB5, 0x64, 0xBB, 0x0A, 0xC2, 0xD8, 0xAB, 0xC5,
+        0x45, 0xA6, 0x83, 0xBF, 0xA6, 0xA2, 0xCC, 0x06,
+        0x64, 0xBE, 0x84, 0x04, 0x55, 0x8E, 0xF4, 0x4C,
+        0xB5, 0xBC, 0xE5, 0x97, 0x2B, 0x3C, 0x42, 0x44,
+        0x91, 0x9B, 0xB2, 0x65, 0x70, 0x02, 0xC5, 0xB7,
+        0x71, 0xB3, 0xF0, 0xAA, 0x46, 0x4F, 0x42, 0x40,
+        0x53, 0x65, 0x89, 0xA5, 0x6C, 0xBC, 0xB5, 0x6C,
+        0x0C, 0x3B, 0x50, 0x46, 0x67, 0xFA, 0x14, 0x68,
+        0x01, 0xE7, 0xA6, 0xD4, 0xB5, 0xD0, 0x82, 0x44,
+        0x92, 0x2C, 0xE3, 0x43, 0x5D, 0x34, 0x7C, 0x04,
+        0xA3, 0x4D, 0x2F, 0x5A, 0x75, 0xE7, 0x0B, 0x64,
+        0xD0, 0xAE, 0x7F, 0xCB, 0xDD, 0x7D, 0x05, 0x88,
+        0x4C, 0x34, 0xBB, 0xF4, 0x00, 0xCE, 0x1C, 0x13,
+        0x4E, 0xA3, 0xE3, 0x60, 0x4B, 0x50, 0x4E, 0xE1,
+        0x26, 0x22, 0x51, 0xD4, 0x32, 0x60, 0xC6, 0x3E,
+        0x7D, 0x4A, 0x3E, 0x56, 0x78, 0xBD, 0x5F, 0x23,
+        0x7F, 0x0A, 0xA0, 0xC1, 0x1A, 0x60, 0xA2, 0x7C,
+        0x9E, 0x17, 0x6F, 0xD8, 0x73, 0x0F, 0x1A, 0x1F,
+        0x47, 0x58, 0x44, 0x20, 0x80, 0xC6, 0x5D, 0x6E,
+        0xEC, 0xFF, 0xCA, 0x65, 0xA1, 0xFB, 0xEE, 0xF2,
+        0x56, 0x1A, 0x16, 0x9E, 0x4D, 0xCA, 0x67, 0x81,
+        0x23, 0xDE, 0xBE, 0x5E, 0x31, 0x56, 0xF0, 0x34,
+        0xBA, 0x12, 0xFC, 0x07, 0x03, 0x96, 0xD2, 0x8E,
+        0xCE, 0xA6, 0xF6, 0x74, 0x07, 0x4F, 0x63, 0x40,
+        0x14, 0x0A, 0xD6, 0x45, 0xB4, 0xF1, 0x72, 0x87,
+        0x34, 0x89, 0x5C, 0x06, 0x1B, 0x8C, 0x0E, 0xA2,
+        0x84, 0x50, 0x12, 0xAD, 0x26, 0x5B, 0x4F, 0x6B,
+        0x23, 0x9D, 0x3C, 0xBB, 0x8A, 0xDA, 0x08, 0x4B,
+        0x93, 0x47, 0x02, 0x96, 0x76, 0xD4, 0x87, 0xE9,
+        0x4B, 0x69, 0x82, 0xD6, 0xCC, 0x69, 0x02, 0xC0,
+        0xA4, 0x75, 0x7A, 0x90, 0xFD, 0xF6, 0xD6, 0x9D,
+        0xE2, 0x4C, 0xB6, 0xFA, 0x61, 0xA5, 0x7C, 0x18,
+        0xEA, 0x84, 0xA1, 0x74, 0x85, 0x2E, 0xCA, 0xF9,
+        0x17, 0x29, 0xFF, 0x67, 0x70, 0xC9, 0x6F, 0xF1,
+        0x41, 0xEF, 0xA1, 0x59, 0x54, 0xA0, 0x99, 0x14,
+        0x48, 0x74, 0x5D, 0x14, 0x3E, 0x04, 0xCE, 0xF7,
+        0x16, 0x9F, 0x8A, 0x41, 0xF4, 0xAE, 0xB3, 0x10,
+        0xCE, 0x19, 0xC2, 0x83, 0x7B, 0xD0, 0x26, 0x1E,
+        0x75, 0x8A, 0x0A, 0x40, 0x4A, 0xB8, 0xE0, 0x5C,
+        0x13, 0x8B, 0xCC, 0x6F, 0xF3, 0x00, 0xB3, 0x64,
+        0x1B, 0x3C, 0x3D, 0x08, 0x3B, 0x9F, 0xD0, 0x9B,
+        0xE5, 0x72, 0x45, 0x96, 0x95, 0x4D, 0x66, 0xC7,
+        0x79, 0x5D, 0x3A, 0x1A, 0x94, 0x64, 0x94, 0x07,
+        0x1A, 0xE8, 0x7C, 0xD1, 0x1C, 0xB1, 0x7E, 0x32,
+        0x28, 0x1A, 0x90, 0x22, 0xD9, 0x86, 0x9B, 0x9C,
+        0x9B, 0x0C, 0x04, 0x31, 0x85, 0x10, 0x42, 0x50,
+        0x40, 0x11, 0x72, 0xAB, 0x94, 0x0C, 0xAF, 0xC3,
+        0x22, 0x1A, 0xC1, 0x31, 0x25, 0x30, 0x23, 0x06,
+        0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01,
+        0x09, 0x15, 0x31, 0x16, 0x04, 0x14, 0xFD, 0x78,
+        0xA7, 0x70, 0x1F, 0x8A, 0xE9, 0x07, 0xB9, 0xCA,
+        0x3C, 0xD1, 0xE8, 0xDC, 0x68, 0xFF, 0x02, 0x61,
+        0x29, 0x97, 0x30, 0x31, 0x30, 0x21, 0x30, 0x09,
+        0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x05,
+        0x00, 0x04, 0x14, 0x22, 0x7E, 0x99, 0x10, 0xB3,
+        0x99, 0x79, 0xE7, 0x14, 0x7F, 0x91, 0x59, 0x24,
+        0x4F, 0x2F, 0xCF, 0xE8, 0x53, 0x1D, 0x0F, 0x04,
+        0x08, 0x30, 0x1E, 0x5C, 0xE4, 0x3C, 0x66, 0xDF,
+        0xB0, 0x02, 0x02, 0x08, 0x00]
+};
+
+gTestSuite.doTestWithCertificate(
+  new Blob([new Uint8Array(testCertInfo.blob)]),
+  testCertInfo.password,
+  testCertInfo.nickname,
+  testCertInfo.usage
+);
new file mode 100644
--- /dev/null
+++ b/dom/wifi/test/marionette/test_wifi_manage_server_certificate.js
@@ -0,0 +1,106 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
+
+// Binary form of test certificate.
+var testCertInfo = {
+  nickname: 'Test Certificate',
+  password: '',
+  usage: ['ServerCert'],
+  blob: [0x30, 0x82, 0x02, 0xae, 0x30, 0x82, 0x02, 0x17,
+        0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00,
+        0x92, 0x49, 0xe2, 0x62, 0x71, 0xf6, 0xc7, 0x92,
+        0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
+        0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30,
+        0x70, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
+        0x04, 0x06, 0x13, 0x02, 0x54, 0x57, 0x31, 0x0f,
+        0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
+        0x06, 0x54, 0x61, 0x69, 0x70, 0x65, 0x69, 0x31,
+        0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a,
+        0x0c, 0x07, 0x4d, 0x6f, 0x7a, 0x69, 0x6c, 0x6c,
+        0x61, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
+        0x04, 0x0b, 0x0c, 0x02, 0x51, 0x41, 0x31, 0x0e,
+        0x30, 0x0c, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,
+        0x05, 0x47, 0x65, 0x72, 0x72, 0x79, 0x31, 0x21,
+        0x30, 0x1f, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
+        0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x12, 0x67,
+        0x63, 0x68, 0x61, 0x6e, 0x67, 0x40, 0x6d, 0x6f,
+        0x7a, 0x69, 0x6c, 0x6c, 0x61, 0x2e, 0x63, 0x6f,
+        0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x34, 0x30,
+        0x35, 0x32, 0x33, 0x30, 0x39, 0x34, 0x32, 0x33,
+        0x37, 0x5a, 0x17, 0x0d, 0x31, 0x37, 0x30, 0x35,
+        0x32, 0x32, 0x30, 0x39, 0x34, 0x32, 0x33, 0x37,
+        0x5a, 0x30, 0x70, 0x31, 0x0b, 0x30, 0x09, 0x06,
+        0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x54, 0x57,
+        0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04,
+        0x08, 0x0c, 0x06, 0x54, 0x61, 0x69, 0x70, 0x65,
+        0x69, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
+        0x04, 0x0a, 0x0c, 0x07, 0x4d, 0x6f, 0x7a, 0x69,
+        0x6c, 0x6c, 0x61, 0x31, 0x0b, 0x30, 0x09, 0x06,
+        0x03, 0x55, 0x04, 0x0b, 0x0c, 0x02, 0x51, 0x41,
+        0x31, 0x0e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x04,
+        0x03, 0x0c, 0x05, 0x47, 0x65, 0x72, 0x72, 0x79,
+        0x31, 0x21, 0x30, 0x1f, 0x06, 0x09, 0x2a, 0x86,
+        0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16,
+        0x12, 0x67, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x40,
+        0x6d, 0x6f, 0x7a, 0x69, 0x6c, 0x6c, 0x61, 0x2e,
+        0x63, 0x6f, 0x6d, 0x30, 0x81, 0x9f, 0x30, 0x0d,
+        0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
+        0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d,
+        0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00,
+        0xd3, 0xdb, 0x54, 0xcc, 0xca, 0x0b, 0xee, 0xf9,
+        0x8a, 0x37, 0x0d, 0x06, 0x8b, 0x20, 0x00, 0x4a,
+        0x55, 0x84, 0x90, 0x1a, 0xb7, 0x9c, 0x91, 0xb2,
+        0x38, 0x6b, 0x8b, 0x32, 0x7a, 0x89, 0x9e, 0x79,
+        0x71, 0x88, 0x43, 0x21, 0x94, 0x18, 0xa8, 0xfc,
+        0xe3, 0x7a, 0x8a, 0xb3, 0xa1, 0xf7, 0x23, 0xe7,
+        0x1a, 0xe3, 0xe7, 0x0d, 0xf1, 0x66, 0x21, 0x58,
+        0x21, 0x85, 0x5b, 0x35, 0xec, 0x68, 0xd2, 0xfd,
+        0x44, 0x76, 0x93, 0x05, 0xbb, 0x89, 0x7d, 0x92,
+        0xf9, 0xce, 0x75, 0xa3, 0xeb, 0x39, 0xc1, 0x7d,
+        0x7e, 0x50, 0xf9, 0xb8, 0x60, 0x61, 0xf7, 0x2f,
+        0x54, 0x39, 0xfe, 0x8a, 0x20, 0xb2, 0x0d, 0x48,
+        0x7f, 0x18, 0x0d, 0x02, 0xcc, 0x7b, 0x8e, 0x31,
+        0xe9, 0xbe, 0xfc, 0x96, 0x2e, 0x63, 0x6f, 0xfa,
+        0x4c, 0xc4, 0xcf, 0x8a, 0xe4, 0x13, 0x67, 0xf1,
+        0xec, 0x3e, 0xd8, 0x23, 0xa1, 0xbf, 0x67, 0x71,
+        0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x50, 0x30,
+        0x4e, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e,
+        0x04, 0x16, 0x04, 0x14, 0x13, 0xe1, 0xac, 0xa4,
+        0x75, 0x3d, 0x2c, 0x5f, 0xe5, 0x41, 0x42, 0x90,
+        0x5a, 0x48, 0x5c, 0x46, 0xbc, 0x24, 0x8e, 0xa1,
+        0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04,
+        0x18, 0x30, 0x16, 0x80, 0x14, 0x13, 0xe1, 0xac,
+        0xa4, 0x75, 0x3d, 0x2c, 0x5f, 0xe5, 0x41, 0x42,
+        0x90, 0x5a, 0x48, 0x5c, 0x46, 0xbc, 0x24, 0x8e,
+        0xa1, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13,
+        0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30,
+        0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
+        0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x81,
+        0x81, 0x00, 0xaa, 0x6b, 0x62, 0x53, 0x74, 0x2a,
+        0x20, 0x76, 0xab, 0xd2, 0x60, 0x06, 0xfd, 0x88,
+        0xf5, 0x1c, 0x85, 0xe6, 0x57, 0xf1, 0xf0, 0x18,
+        0x97, 0x7c, 0x70, 0xb8, 0xb4, 0x7c, 0xcc, 0x58,
+        0x8d, 0xf4, 0x7c, 0xb6, 0x34, 0xcc, 0x15, 0x79,
+        0xaf, 0x75, 0xa9, 0x0b, 0xd1, 0xea, 0xf8, 0x85,
+        0x7c, 0xe8, 0x19, 0xe9, 0x13, 0x90, 0x84, 0x5f,
+        0x21, 0x94, 0x0a, 0x4d, 0x15, 0xef, 0xd1, 0x16,
+        0xd4, 0xba, 0x2c, 0x59, 0x1b, 0x83, 0x23, 0xf5,
+        0xa5, 0xcd, 0xbd, 0xda, 0x32, 0x73, 0x46, 0x49,
+        0x98, 0xf3, 0xfb, 0x50, 0x6e, 0x30, 0xd7, 0x3e,
+        0x31, 0xd6, 0xe8, 0x65, 0x2f, 0x5a, 0xf1, 0x0f,
+        0x7b, 0x0a, 0x21, 0x61, 0x8e, 0x45, 0x29, 0x4f,
+        0x7a, 0x04, 0xda, 0x29, 0xfc, 0x6f, 0xc5, 0x5e,
+        0xee, 0xe1, 0x0f, 0xd5, 0x4b, 0xb7, 0xc9, 0x6a,
+        0x8e, 0x7c, 0x19, 0xef, 0x6e, 0x64, 0x98, 0xfe,
+        0xe3, 0x35]
+};
+
+gTestSuite.doTestWithCertificate(
+  new Blob([new Uint8Array(testCertInfo.blob)]),
+  testCertInfo.password,
+  testCertInfo.nickname,
+  testCertInfo.usage
+);
new file mode 100644
--- /dev/null
+++ b/dom/wifi/test/marionette/test_wifi_manage_user_certificate.js
@@ -0,0 +1,34 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 60000;
+MARIONETTE_HEAD_JS = 'head.js';
+
+// Binary form of test certificate.
+var testCertInfo = {
+  nickname: 'Test Certificate',
+  password: '',
+  usage: ['UserCert'],
+  blob: '-----BEGIN CERTIFICATE-----\n' +
+        'MIICTjCCAbegAwIBAgICNV4wDQYJKoZIhvcNAQEEBQAwgYUxCzAJBgNVBAYTAklU\n' +
+        'MRYwFAYDVQQKEw1aZXJvc2hlbGwubmV0MRAwDgYDVQQLEwdFeGFtcGxlMR0wGwYD\n' +
+        'VQQDExRaZXJvU2hlbGwgRXhhbXBsZSBDQTEtMCsGCSqGSIb3DQEJARYeRnVsdmlv\n' +
+        'LlJpY2NpYXJkaUB6ZXJvc2hlbGwubmV0MB4XDTEzMDMxMTAzMzg1MloXDTE0MDMx\n' +
+        'MTAzMzg1MlowIzEOMAwGA1UECxMFVXNlcnMxETAPBgNVBAMTCGNodWNrbGVlMIGf\n' +
+        'MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDvVzFhQAVqAIHW5DlAhp4FEGEei7k7\n' +
+        'uVUeqkH7JAsww6zmDLg9yZlcZAc95N0lkz022gLXehH2M0R1FOR++nkqofzWfc7w\n' +
+        'n79ith+dU2GQMeKq7vPGDYXpgIkEKbYfzKj3fY3129MlTxJQt1UD/ejz38V8HKgw\n' +
+        'qKSuwo0NVeY66QIDAQABoy4wLDALBgNVHQ8EBAMCBLAwHQYDVR0lBBYwFAYIKwYB\n' +
+        'BQUHAwIGCCsGAQUFBwMEMA0GCSqGSIb3DQEBBAUAA4GBAJWgfX5vYSD7MGZk1rTF\n' +
+        'DSziWYGqpR+Moo3qQ+9qLG8m+XVM9hckWpY31A5sWAeCZCe1SSNLFbbgsaOyPZE2\n' +
+        'NqMyvs61Vszpc2mmWAYT6j2OU2tw8p5pcUZd6eIp7Gc3fLymiX/WoSmilZKmrGUZ\n' +
+        'Q15R+TCpclUsaNrUGjybgaw7\n' +
+        '-----END CERTIFICATE-----'
+};
+
+gTestSuite.doTestWithCertificate(
+  new Blob([testCertInfo.blob]),
+  testCertInfo.password,
+  testCertInfo.nickname,
+  testCertInfo.usage
+);
--- a/dom/workers/ServiceWorkerEvents.cpp
+++ b/dom/workers/ServiceWorkerEvents.cpp
@@ -97,29 +97,37 @@ public:
   FinishResponse(nsMainThreadPtrHandle<nsIInterceptedChannel>& aChannel,
                  InternalResponse* aInternalResponse)
     : mChannel(aChannel)
     , mInternalResponse(aInternalResponse)
   {
   }
 
   NS_IMETHOD
-      Run()
+  Run()
   {
     AssertIsOnMainThread();
 
     nsCOMPtr<nsISupports> infoObj;
     nsresult rv = NS_DeserializeObject(mInternalResponse->GetSecurityInfo(), getter_AddRefs(infoObj));
     if (NS_SUCCEEDED(rv)) {
       rv = mChannel->SetSecurityInfo(infoObj);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     }
 
+    mChannel->SynthesizeStatus(mInternalResponse->GetStatus(), mInternalResponse->GetStatusText());
+
+    nsAutoTArray<InternalHeaders::Entry, 5> entries;
+    mInternalResponse->Headers()->GetEntries(entries);
+    for (uint32_t i = 0; i < entries.Length(); ++i) {
+       mChannel->SynthesizeHeader(entries[i].mName, entries[i].mValue);
+    }
+
     rv = mChannel->FinishSynthesizedResponse();
     NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to finish synthesized response");
     return rv;
   }
 };
 
 class RespondWithHandler MOZ_FINAL : public PromiseNativeHandler
 {
@@ -198,46 +206,57 @@ RespondWithHandler::ResolvedCallback(JSC
   }
 
   nsRefPtr<Response> response;
   nsresult rv = UNWRAP_OBJECT(Response, &aValue.toObject(), response);
   if (NS_FAILED(rv)) {
     return;
   }
 
+  // FIXME(nsm) Bug 1136200 deal with opaque and no-cors (fetch spec 4.2.2.2).
+  if (response->Type() == ResponseType::Error) {
+    return;
+  }
+
+  if (NS_WARN_IF(response->BodyUsed())) {
+    return;
+  }
+
   nsRefPtr<InternalResponse> ir = response->GetInternalResponse();
   if (NS_WARN_IF(!ir)) {
     return;
   }
 
+  nsAutoPtr<RespondWithClosure> closure(new RespondWithClosure(mInterceptedChannel, ir));
   nsCOMPtr<nsIInputStream> body;
   response->GetBody(getter_AddRefs(body));
-  if (NS_WARN_IF(!body) || NS_WARN_IF(response->BodyUsed())) {
-    return;
-  }
-  response->SetBodyUsed();
+  // Errors and redirects may not have a body.
+  if (body) {
+    response->SetBodyUsed();
+
+    nsCOMPtr<nsIOutputStream> responseBody;
+    rv = mInterceptedChannel->GetResponseBody(getter_AddRefs(responseBody));
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return;
+    }
 
-  nsCOMPtr<nsIOutputStream> responseBody;
-  rv = mInterceptedChannel->GetResponseBody(getter_AddRefs(responseBody));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return;
+    nsCOMPtr<nsIEventTarget> stsThread = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
+    if (NS_WARN_IF(!stsThread)) {
+      return;
+    }
+    rv = NS_AsyncCopy(body, responseBody, stsThread, NS_ASYNCCOPY_VIA_READSEGMENTS, 4096,
+                      RespondWithCopyComplete, closure.forget());
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return;
+    }
+  } else {
+    RespondWithCopyComplete(closure.forget(), NS_OK);
   }
 
-  nsAutoPtr<RespondWithClosure> closure(new RespondWithClosure(mInterceptedChannel, ir));
-
-  nsCOMPtr<nsIEventTarget> stsThread = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
-  if (NS_WARN_IF(!stsThread)) {
-    return;
-  }
-  rv = NS_AsyncCopy(body, responseBody, stsThread, NS_ASYNCCOPY_VIA_READSEGMENTS, 4096,
-                    RespondWithCopyComplete, closure.forget());
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return;
-  }
-
+  MOZ_ASSERT(!closure);
   autoCancel.Reset();
 }
 
 void
 RespondWithHandler::RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue)
 {
   CancelRequest();
 }
--- a/dom/workers/test/serviceworkers/fetch/fetch_tests.js
+++ b/dom/workers/test/serviceworkers/fetch/fetch_tests.js
@@ -22,16 +22,29 @@ function fetch(name, onload, onerror, he
 }
 
 fetch('synthesized.txt', function(xhr) {
   my_ok(xhr.status == 200, "load should be successful");
   my_ok(xhr.responseText == "synthesized response body", "load should have synthesized response");
   finish();
 });
 
+fetch('synthesized-404.txt', function(xhr) {
+  my_ok(xhr.status == 404, "load should 404");
+  my_ok(xhr.responseText == "synthesized response body", "404 load should have synthesized response");
+  finish();
+});
+
+fetch('synthesized-headers.txt', function(xhr) {
+  my_ok(xhr.status == 200, "load should be successful");
+  my_ok(xhr.getResponseHeader("X-Custom-Greeting") === "Hello", "custom header should be set");
+  my_ok(xhr.responseText == "synthesized response body", "custom header load should have synthesized response");
+  finish();
+});
+
 fetch('ignored.txt', function(xhr) {
   my_ok(xhr.status == 404, "load should be uninterrupted");
   finish();
 });
 
 fetch('rejected.txt', null, function(xhr) {
   my_ok(xhr.status == 0, "load should not complete");
   finish();
--- a/dom/workers/test/serviceworkers/fetch_event_worker.js
+++ b/dom/workers/test/serviceworkers/fetch_event_worker.js
@@ -1,86 +1,95 @@
 onfetch = function(ev) {
   if (ev.request.url.contains("synthesized.txt")) {
-    var p = new Promise(function(resolve) {
-      var r = new Response("synthesized response body", {});
-      resolve(r);
-    });
-    ev.respondWith(p);
+    ev.respondWith(Promise.resolve(
+      new Response("synthesized response body", {})
+    ));
+  }
+
+  else if (ev.request.url.contains("synthesized-404.txt")) {
+    ev.respondWith(Promise.resolve(
+      new Response("synthesized response body", { status: 404 })
+    ));
+  }
+
+  else if (ev.request.url.contains("synthesized-headers.txt")) {
+    ev.respondWith(Promise.resolve(
+      new Response("synthesized response body", {
+        headers: {
+          "X-Custom-Greeting": "Hello"
+        }
+      })
+    ));
   }
 
   else if (ev.request.url.contains("ignored.txt")) {
   }
 
   else if (ev.request.url.contains("rejected.txt")) {
-    var p = new Promise(function(resolve, reject) {
-      reject();
-    });
-    ev.respondWith(p);
+    ev.respondWith(Promise.reject());
   }
 
   else if (ev.request.url.contains("nonresponse.txt")) {
-    var p = new Promise(function(resolve, reject) {
-      resolve(5);
-    });
-    ev.respondWith(p);
+    ev.respondWith(Promise.resolve(5));
   }
 
   else if (ev.request.url.contains("nonresponse2.txt")) {
-    var p = new Promise(function(resolve, reject) {
-      resolve({});
-    });
-    ev.respondWith(p);
+    ev.respondWith(Promise.resolve({}));
   }
 
   else if (ev.request.url.contains("headers.txt")) {
-    var p = new Promise(function(resolve, reject) {
-      var ok = true;
-      ok &= ev.request.headers.get("X-Test1") == "header1";
-      ok &= ev.request.headers.get("X-Test2") == "header2";
-      var r = new Response(ok.toString(), {});
-      resolve(r);
-    });
-    ev.respondWith(p);    
+    var ok = true;
+    ok &= ev.request.headers.get("X-Test1") == "header1";
+    ok &= ev.request.headers.get("X-Test2") == "header2";
+    ev.respondWith(Promise.resolve(
+      new Response(ok.toString(), {})
+    ));
   }
 
   else if (ev.request.url.contains("nonexistent_image.gif")) {
-    var p = new Promise(function(resolve, reject) {
-      resolve(new Response(atob("R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs"), {}));
-    });
-    ev.respondWith(p);
+    ev.respondWith(Promise.resolve(
+      new Response(atob("R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs"), {
+        headers: {
+          "Content-Type": "image/gif"
+        }
+      })
+    ));
   }
 
   else if (ev.request.url.contains("nonexistent_script.js")) {
-    var p = new Promise(function(resolve, reject) {
-      resolve(new Response("check_intercepted_script();", {}));
-    });
-    ev.respondWith(p);
+    ev.respondWith(Promise.resolve(
+      new Response("check_intercepted_script();", {})
+    ));
   }
 
   else if (ev.request.url.contains("nonexistent_stylesheet.css")) {
-    var p = new Promise(function(resolve, reject) {
-      resolve(new Response("#style-test { background-color: black !important; }", {}));
-    });
-    ev.respondWith(p);
+    ev.respondWith(Promise.resolve(
+      new Response("#style-test { background-color: black !important; }", {
+        headers : {
+          "Content-Type": "text/css"
+        }
+      })
+    ));
   }
 
   else if (ev.request.url.contains("nonexistent_page.html")) {
-    var p = new Promise(function(resolve, reject) {
-      resolve(new Response("<script>window.frameElement.test_result = true;</script>", {}));
-    });
-    ev.respondWith(p);
+    ev.respondWith(Promise.resolve(
+      new Response("<script>window.frameElement.test_result = true;</script>", {
+        headers : {
+          "Content-Type": "text/html"
+        }
+      })
+    ));
   }
 
   else if (ev.request.url.contains("nonexistent_worker_script.js")) {
-    var p = new Promise(function(resolve, reject) {
-      resolve(new Response("postMessage('worker-intercept-success')", {}));
-    });
-    ev.respondWith(p);
+    ev.respondWith(Promise.resolve(
+      new Response("postMessage('worker-intercept-success')", {})
+    ));
   }
 
   else if (ev.request.url.contains("nonexistent_imported_script.js")) {
-    var p = new Promise(function(resolve, reject) {
-      resolve(new Response("check_intercepted_script();", {}));
-    });
-    ev.respondWith(p);
+    ev.respondWith(Promise.resolve(
+      new Response("check_intercepted_script();", {})
+    ));
   }
 }
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/match_all_advanced_worker.js
@@ -0,0 +1,5 @@
+onmessage = function(e) {
+  self.clients.matchAll().then(function(clients) {
+    e.source.postMessage(clients.length);
+  });
+}
--- a/dom/workers/test/serviceworkers/mochitest.ini
+++ b/dom/workers/test/serviceworkers/mochitest.ini
@@ -13,16 +13,17 @@ support-files =
   simpleregister/ready.html
   controller/index.html
   unregister/index.html
   unregister/unregister.html
   workerUpdate/update.html
   sw_clients/simple.html
   sw_clients/service_worker_controlled.html
   match_all_worker.js
+  match_all_advanced_worker.js
   worker_unregister.js
   worker_update.js
   message_posting_worker.js
   fetch/index.html
   fetch/fetch_worker_script.js
   fetch/fetch_tests.js
   fetch/https/index.html
   fetch/https/register.html
@@ -46,16 +47,17 @@ support-files =
   redirect_serviceworker.sjs
 
 [test_unregister.html]
 [test_installation_simple.html]
 [test_fetch_event.html]
 [test_https_fetch.html]
 [test_https_fetch_cloned_response.html]
 [test_match_all.html]
+[test_match_all_advanced.html]
 [test_install_event.html]
 [test_navigator.html]
 [test_scopes.html]
 [test_controller.html]
 [test_workerUpdate.html]
 [test_workerUnregister.html]
 [test_post_message.html]
 [test_post_message_advanced.html]
--- a/dom/workers/test/serviceworkers/test_fetch_event.html
+++ b/dom/workers/test/serviceworkers/test_fetch_event.html
@@ -13,17 +13,21 @@
 <p id="display"></p>
 <div id="content" style="display: none"></div>
 <pre id="test"></pre>
 <script class="testbody" type="text/javascript">
   SimpleTest.requestCompleteLog();
 
   function simpleRegister() {
     var p = navigator.serviceWorker.register("fetch_event_worker.js", { scope: "./fetch" });
-    return p;
+    return p.then(function(swr) {
+      return new Promise(function(resolve) {
+        swr.installing.onstatechange = resolve;
+      });
+    });
   }
 
   function testController() {
     var p = new Promise(function(resolve, reject) {
       window.onmessage = function(e) {
         if (e.data.status == "ok") {
           ok(e.data.result, e.data.message);
         } else if (e.data.status == "done") {
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/test_match_all_advanced.html
@@ -0,0 +1,98 @@
+<!--
+  Any copyright is dedicated to the Public Domain.
+  http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Bug 982726 - Test matchAll with multiple clients</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test"></pre>
+<script class="testbody" type="text/javascript">
+  var client_iframes = [];
+  var registration;
+
+  function start() {
+    return navigator.serviceWorker.register("match_all_advanced_worker.js",
+                                            { scope: "./sw_clients/" }).then(function(swr) {
+      registration = swr;
+      window.onmessage = function (e) {
+        if (e.data === "READY") {
+          ok(registration.active, "Worker is active.");
+          registration.active.postMessage("RUN");
+        }
+      }
+    });
+  }
+
+  function unregister() {
+    return registration.unregister().then(function(result) {
+      ok(result, "Unregister should return true.");
+    });
+  }
+
+
+  function testMatchAll() {
+    var p = new Promise(function(res, rej) {
+      navigator.serviceWorker.onmessage = function (e) {
+        ok(e.data === client_iframes.length, "MatchAll returned the correct number of clients.");
+        res();
+      }
+    });
+
+    content = document.getElementById("content");
+    ok(content, "Parent exists.");
+
+    iframe = document.createElement("iframe");
+    iframe.setAttribute('src', "sw_clients/service_worker_controlled.html");
+    content.appendChild(iframe);
+
+    client_iframes.push(iframe);
+    return p;
+  }
+
+  function removeAndTest() {
+    content = document.getElementById("content");
+    ok(content, "Parent exists.");
+
+    content.removeChild(client_iframes.pop());
+    content.removeChild(client_iframes.pop());
+
+    return testMatchAll();
+  }
+
+  function runTest() {
+    start()
+      .then(testMatchAll)
+      .then(testMatchAll)
+      .then(testMatchAll)
+      .then(removeAndTest)
+      .then(function(e) {
+        content = document.getElementById("content");
+        while (client_iframes.length) {
+          content.removeChild(client_iframes.pop());
+        }
+      }).then(unregister).catch(function(e) {
+        ok(false, "Some test failed with error " + e);
+      }).then(function() {
+        SimpleTest.finish();
+      });
+
+  }
+
+  SimpleTest.waitForExplicitFinish();
+  SpecialPowers.pushPrefEnv({"set": [
+    ["dom.serviceWorkers.exemptFromPerDomainMax", true],
+    ["dom.serviceWorkers.enabled", true],
+    ["dom.serviceWorkers.testing.enabled", true]
+  ]}, runTest);
+</script>
+</pre>
+</body>
+</html>
+
--- a/gfx/layers/LayersLogging.h
+++ b/gfx/layers/LayersLogging.h
@@ -104,16 +104,36 @@ AppendToString(std::stringstream& aStrea
 void
 AppendToString(std::stringstream& aStream, const nsRegion& r,
                const char* pfx="", const char* sfx="");
 
 void
 AppendToString(std::stringstream& aStream, const nsIntRegion& r,
                const char* pfx="", const char* sfx="");
 
+template <typename units>
+void
+AppendToString(std::stringstream& aStream, const mozilla::gfx::IntRegionTyped<units>& r,
+               const char* pfx="", const char* sfx="")
+{
+  typedef mozilla::gfx::IntRegionTyped<units> RegionType;
+
+  aStream << pfx;
+
+  typename RegionType::RectIterator it(r);
+  aStream << "< ";
+  while (const typename RegionType::RectType* sr = it.Next()) {
+    AppendToString(aStream, *sr);
+    aStream << "; ";
+  }
+  aStream << ">";
+
+  aStream << sfx;
+}
+
 void
 AppendToString(std::stringstream& aStream, const EventRegions& e,
                const char* pfx="", const char* sfx="");
 
 void
 AppendToString(std::stringstream& aStream, const nsIntSize& sz,
                const char* pfx="", const char* sfx="");
 
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -191,30 +191,29 @@ APZCTreeManager::UpdateHitTestingTree(Co
   // Make the hit-test tree line up with the layer dump
   printf_stderr("APZCTreeManager (%p)\n", this);
   mRootNode->Dump("  ");
 #endif
 }
 
 // Compute the clip region to be used for a layer with an APZC. This function
 // is only called for layers which actually have scrollable metrics and an APZC.
-static nsIntRegion
+static ParentLayerIntRegion
 ComputeClipRegion(GeckoContentController* aController,
                   const LayerMetricsWrapper& aLayer)
 {
-  nsIntRegion clipRegion;
+  ParentLayerIntRegion clipRegion;
   if (aLayer.GetClipRect()) {
-    clipRegion = nsIntRegion(*aLayer.GetClipRect());
+    clipRegion = ViewAs<ParentLayerPixel>