Merge m-c to inbound. a=merge
authorRyan VanderMeulen <ryanvm@gmail.com>
Tue, 16 Jun 2015 14:48:48 -0400
changeset 279925 4f381552336d56fd7befc57dc9bfd08a1f2650bf
parent 279924 a08167680328806db2ef8e0ce185ad7d265c9f0f (current diff)
parent 279909 27caa5299f9f1bacf8a92b898837edf360b3b212 (diff)
child 279926 09eddb99e5e21e3c77f6beb02111fa31bd69e34f
child 279979 0086cb0ada91f77c6f0dcc115ca8b5051c2869ee
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmerge
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Merge m-c to inbound. a=merge CLOSED TREE
--- a/b2g/config/aries/sources.xml
+++ b/b2g/config/aries/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="e862ab9177af664f00b4522e2350f4cb13866d73">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <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="94516f787d477dc307e4566f415e0d2f0794f6b9"/>
--- 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="e862ab9177af664f00b4522e2350f4cb13866d73">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <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="94516f787d477dc307e4566f415e0d2f0794f6b9"/>
--- 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="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia.git" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="platform_hardware_ril" path="hardware/ril" remote="b2g" revision="87a2d8ab9248540910e56921654367b78a587095"/>
   <project name="platform_external_qemu" path="external/qemu" remote="b2g" revision="9d0e5057ee5404a31ec1bf76131cb11336a7c3b6"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <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="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="94516f787d477dc307e4566f415e0d2f0794f6b9"/>
   <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="e862ab9177af664f00b4522e2350f4cb13866d73">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <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="94516f787d477dc307e4566f415e0d2f0794f6b9"/>
--- 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="61e82f99bb8bc78d52b5717e9a2481ec7267fa33">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <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="94516f787d477dc307e4566f415e0d2f0794f6b9"/>
--- 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="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia.git" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="platform_hardware_ril" path="hardware/ril" remote="b2g" revision="87a2d8ab9248540910e56921654367b78a587095"/>
   <project name="platform_external_qemu" path="external/qemu" remote="b2g" revision="9d0e5057ee5404a31ec1bf76131cb11336a7c3b6"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <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="e862ab9177af664f00b4522e2350f4cb13866d73">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <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="94516f787d477dc307e4566f415e0d2f0794f6b9"/>
--- a/b2g/config/gaia.json
+++ b/b2g/config/gaia.json
@@ -1,9 +1,9 @@
 {
     "git": {
-        "git_revision": "c92e9d14022f0191f8ccdaadf1752352cde97be0", 
+        "git_revision": "9d42e94446f2dc01b519172b6d75d81d4d435bdc", 
         "remote": "https://git.mozilla.org/releases/gaia.git", 
         "branch": ""
     }, 
-    "revision": "d9efff50aff6c261c55cfdff66e4fedd81250e0b", 
+    "revision": "1518b9e2a13a377444083e4bb970bd701e2633c9", 
     "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="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="94516f787d477dc307e4566f415e0d2f0794f6b9"/>
   <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="61e82f99bb8bc78d52b5717e9a2481ec7267fa33">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="c92e9d14022f0191f8ccdaadf1752352cde97be0"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="9d42e94446f2dc01b519172b6d75d81d4d435bdc"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="3477513bcd385571aa01c0d074849e35bd5e2376"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="46da1a05ac04157669685246d70ac59d48699c9e"/>
   <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="94516f787d477dc307e4566f415e0d2f0794f6b9"/>
--- a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
@@ -59,61 +59,90 @@
     if (!sBtInterface || !IsEnabled()) {                               \
       DispatchReplyError(runnable,                                     \
         NS_LITERAL_STRING("Bluetooth is not ready"));                  \
       return;                                                          \
     }                                                                  \
   } while(0)
 
 #ifndef MOZ_B2G_BT_API_V1
-
 #define ENSURE_GATT_MGR_IS_READY_VOID(gatt, runnable)                  \
   do {                                                                 \
     if (!gatt) {                                                       \
       DispatchReplyError(runnable,                                     \
         NS_LITERAL_STRING("GattManager is not ready"));                \
       return;                                                          \
     }                                                                  \
   } while(0)
+#else
+  // Missing in Bluetooth v1
+#endif
+
+#ifndef MOZ_B2G_BT_API_V1
+// Missing in Bluetooth v2
+#else
+// Audio: Major service class = 0x100 (Bit 21 is set)
+#define SET_AUDIO_BIT(cod)               (cod |= 0x200000)
+// Rendering: Major service class = 0x20 (Bit 18 is set)
+#define SET_RENDERING_BIT(cod)           (cod |= 0x40000)
+#endif
 
 using namespace mozilla;
 using namespace mozilla::ipc;
 USING_BLUETOOTH_NAMESPACE
 
 static nsString sAdapterBdAddress;
 static nsString sAdapterBdName;
+
 static bool sAdapterDiscoverable(false);
 static bool sAdapterDiscovering(false);
-static bool sAdapterEnabled(false);
+
 // InfallibleTArray is an alias for nsTArray.
 static InfallibleTArray<nsString> sAdapterBondedAddressArray;
 
+static BluetoothInterface* sBtInterface;
+
+static nsTArray<nsRefPtr<BluetoothProfileController> > sControllerArray;
+static InfallibleTArray<BluetoothNamedValue> sRemoteDevicesPack;
+static nsTArray<int> sRequestedDeviceCountArray;
+
+static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sSetPropertyRunnableArray;
+static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sGetDeviceRunnableArray;
+
+static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sBondingRunnableArray;
+static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sUnbondingRunnableArray;
+static bool sIsRestart(false);
+static bool sIsFirstTimeToggleOffBt(false);
+
+#ifndef MOZ_B2G_BT_API_V1
+static bool sAdapterEnabled(false);
+
 // Use a static hash table to keep the name of remote device during the pairing
 // procedure. In this manner, BT service and adapter can get the name of paired
 // device name when bond state changed.
 // The hash Key is BD address, the Value is remote BD name.
 static nsDataHashtable<nsStringHashKey, nsString> sPairingNameTable;
 
-static BluetoothInterface* sBtInterface;
-static nsTArray<nsRefPtr<BluetoothProfileController> > sControllerArray;
-static InfallibleTArray<BluetoothNamedValue> sRemoteDevicesPack;
-static nsTArray<int> sRequestedDeviceCountArray;
 static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sChangeAdapterStateRunnableArray;
 static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sChangeDiscoveryRunnableArray;
-static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sSetPropertyRunnableArray;
-static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sGetDeviceRunnableArray;
 static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sFetchUuidsRunnableArray;
-static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sBondingRunnableArray;
-static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sUnbondingRunnableArray;
-static bool sIsRestart(false);
-static bool sIsFirstTimeToggleOffBt(false);
-
-/**
- *  Static callback functions
+#else
+// Missing in Bluetooth v1
+#endif
+
+#ifndef MOZ_B2G_BT_API_V1
+// Missing in Bluetooth v2
+#else
+static uint32_t sAdapterDiscoverableTimeout(0);
+#endif
+
+/*
+ *  Static methods
  */
+
 ControlPlayStatus
 BluetoothServiceBluedroid::PlayStatusStringToControlPlayStatus(
   const nsAString& aPlayStatus)
 {
   ControlPlayStatus playStatus = ControlPlayStatus::PLAYSTATUS_UNKNOWN;
   if (aPlayStatus.EqualsLiteral("STOPPED")) {
     playStatus = ControlPlayStatus::PLAYSTATUS_STOPPED;
   } else if (aPlayStatus.EqualsLiteral("PLAYING")) {
@@ -126,19 +155,139 @@ BluetoothServiceBluedroid::PlayStatusStr
     playStatus = ControlPlayStatus::PLAYSTATUS_REV_SEEK;
   } else if (aPlayStatus.EqualsLiteral("ERROR")) {
     playStatus = ControlPlayStatus::PLAYSTATUS_ERROR;
   }
 
   return playStatus;
 }
 
-/**
- *  Static functions
- */
+#ifndef MOZ_B2G_BT_API_V1
+// Missing in Bluetooth v2
+#else
+void
+BluetoothServiceBluedroid::ClassToIcon(uint32_t aClass, nsAString& aRetIcon)
+{
+  switch ((aClass & 0x1f00) >> 8) {
+    case 0x01:
+      aRetIcon.AssignLiteral("computer");
+      break;
+    case 0x02:
+      switch ((aClass & 0xfc) >> 2) {
+        case 0x01:
+        case 0x02:
+        case 0x03:
+        case 0x05:
+          aRetIcon.AssignLiteral("phone");
+          break;
+        case 0x04:
+          aRetIcon.AssignLiteral("modem");
+          break;
+      }
+      break;
+    case 0x03:
+      aRetIcon.AssignLiteral("network-wireless");
+      break;
+    case 0x04:
+      switch ((aClass & 0xfc) >> 2) {
+        case 0x01:
+        case 0x02:
+        case 0x06:
+          aRetIcon.AssignLiteral("audio-card");
+          break;
+        case 0x0b:
+        case 0x0c:
+        case 0x0d:
+          aRetIcon.AssignLiteral("camera-video");
+          break;
+        default:
+          aRetIcon.AssignLiteral("audio-card");
+          break;
+      }
+      break;
+    case 0x05:
+      switch ((aClass & 0xc0) >> 6) {
+        case 0x00:
+          switch ((aClass && 0x1e) >> 2) {
+            case 0x01:
+            case 0x02:
+              aRetIcon.AssignLiteral("input-gaming");
+              break;
+          }
+          break;
+        case 0x01:
+          aRetIcon.AssignLiteral("input-keyboard");
+          break;
+        case 0x02:
+          switch ((aClass && 0x1e) >> 2) {
+            case 0x05:
+              aRetIcon.AssignLiteral("input-tablet");
+              break;
+            default:
+              aRetIcon.AssignLiteral("input-mouse");
+              break;
+          }
+      }
+      break;
+    case 0x06:
+      if (aClass & 0x80) {
+        aRetIcon.AssignLiteral("printer");
+        break;
+      }
+      if (aClass & 0x20) {
+        aRetIcon.AssignLiteral("camera-photo");
+        break;
+      }
+      break;
+  }
+
+  if (aRetIcon.IsEmpty()) {
+    if (HAS_AUDIO(aClass)) {
+      /**
+       * Property 'Icon' may be missed due to CoD of major class is TOY(0x08).
+       * But we need to assign Icon as audio-card if service class is 'Audio'.
+       * This is for PTS test case TC_AG_COD_BV_02_I. As HFP specification
+       * defines that service class is 'Audio' can be considered as HFP HF.
+       */
+      aRetIcon.AssignLiteral("audio-card");
+    } else {
+      BT_LOGR("No icon to match class: %x", aClass);
+    }
+  }
+}
+
+static void
+ReplyStatusError(BluetoothReplyRunnable* aBluetoothReplyRunnable,
+                 BluetoothStatus aStatusCode, const nsAString& aCustomMsg)
+{
+  MOZ_ASSERT(aBluetoothReplyRunnable, "Reply runnable is nullptr");
+
+  BT_LOGR("error code(%d)", aStatusCode);
+
+  nsAutoString replyError;
+  replyError.Assign(aCustomMsg);
+
+  if (aStatusCode == STATUS_BUSY) {
+    replyError.AppendLiteral(":BT_STATUS_BUSY");
+  } else if (aStatusCode == STATUS_NOT_READY) {
+    replyError.AppendLiteral(":BT_STATUS_NOT_READY");
+  } else if (aStatusCode == STATUS_DONE) {
+    replyError.AppendLiteral(":BT_STATUS_DONE");
+  } else if (aStatusCode == STATUS_AUTH_FAILURE) {
+    replyError.AppendLiteral(":BT_STATUS_AUTH_FAILURE");
+  } else if (aStatusCode == STATUS_RMT_DEV_DOWN) {
+    replyError.AppendLiteral(":BT_STATUS_RMT_DEV_DOWN");
+  } else if (aStatusCode == STATUS_FAIL) {
+    replyError.AppendLiteral(":BT_STATUS_FAIL");
+  }
+
+  DispatchReplyError(aBluetoothReplyRunnable, replyError);
+}
+#endif
+
 class BluetoothServiceBluedroid::EnableResultHandler final
   : public BluetoothResultHandler
 {
 public:
   void OnError(BluetoothStatus aStatus) override
   {
     MOZ_ASSERT(NS_IsMainThread());
 
@@ -189,17 +338,21 @@ class BluetoothServiceBluedroid::InitRes
   : public BluetoothResultHandler
 {
 public:
   void Init() override
   {
     static void (* const sInitManager[])(BluetoothProfileResultHandler*) = {
       BluetoothHfpManager::InitHfpInterface,
       BluetoothA2dpManager::InitA2dpInterface,
+#ifndef MOZ_B2G_BT_API_V1
       BluetoothGattManager::InitGattInterface
+#else
+      // Missing in Bluetooth v1
+#endif
     };
 
     MOZ_ASSERT(NS_IsMainThread());
 
     // Register all the bluedroid callbacks before enable() get called
     // It is required to register a2dp callbacks before a2dp media task starts up.
     // If any interface cannot be initialized, turn on bluetooth core anyway.
     nsRefPtr<ProfileInitResultHandler> res =
@@ -249,17 +402,22 @@ class BluetoothServiceBluedroid::Disable
 {
 public:
   void OnError(BluetoothStatus aStatus) override
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     BT_LOGR("BluetoothInterface::Disable failed: %d", aStatus);
 
+#ifndef MOZ_B2G_BT_API_V1
     BluetoothService::AcknowledgeToggleBt(true);
+#else
+    // Always make progress; even on failures
+    BluetoothService::AcknowledgeToggleBt(false);
+#endif
   }
 };
 
 nsresult
 BluetoothServiceBluedroid::StopGonkBluetooth()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
@@ -274,47 +432,49 @@ BluetoothServiceBluedroid::StopGonkBluet
     return NS_OK;
   }
 
   sBtInterface->Disable(new DisableResultHandler());
 
   return NS_OK;
 }
 
-/**
+/*
  *  Member functions
  */
+
 BluetoothServiceBluedroid::BluetoothServiceBluedroid()
 {
   sBtInterface = BluetoothInterface::GetInstance();
   if (!sBtInterface) {
     BT_LOGR("Error! Failed to get instance of bluetooth interface");
   }
 }
 
 BluetoothServiceBluedroid::~BluetoothServiceBluedroid()
 {
 }
 
+#ifndef MOZ_B2G_BT_API_V1
 nsresult
 BluetoothServiceBluedroid::StartInternal(BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // aRunnable will be a nullptr while startup
-  if(aRunnable) {
+  if (aRunnable) {
     sChangeAdapterStateRunnableArray.AppendElement(aRunnable);
   }
 
   nsresult ret = StartGonkBluetooth();
   if (NS_FAILED(ret)) {
     BluetoothService::AcknowledgeToggleBt(false);
 
     // Reject Promise
-    if(aRunnable) {
+    if (aRunnable) {
       DispatchReplyError(aRunnable, NS_LITERAL_STRING("StartBluetoothError"));
       sChangeAdapterStateRunnableArray.RemoveElement(aRunnable);
     }
 
     BT_LOGR("Error");
   }
 
   return ret;
@@ -347,40 +507,70 @@ BluetoothServiceBluedroid::StopInternal(
       sProfiles[i]->Disconnect(nullptr);
     } else if (!profileName.EqualsLiteral("OPP") &&
                !profileName.EqualsLiteral("PBAP")) {
       sProfiles[i]->Reset();
     }
   }
 
   // aRunnable will be a nullptr during starup and shutdown
-  if(aRunnable) {
+  if (aRunnable) {
     sChangeAdapterStateRunnableArray.AppendElement(aRunnable);
   }
 
   nsresult ret = StopGonkBluetooth();
   if (NS_FAILED(ret)) {
     BluetoothService::AcknowledgeToggleBt(true);
 
     // Reject Promise
-    if(aRunnable) {
+    if (aRunnable) {
       DispatchReplyError(aRunnable, NS_LITERAL_STRING("StopBluetoothError"));
       sChangeAdapterStateRunnableArray.RemoveElement(aRunnable);
     }
 
     BT_LOGR("Error");
   }
 
   return ret;
 }
+#else
+nsresult
+BluetoothServiceBluedroid::StartInternal()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  nsresult ret = StartGonkBluetooth();
+  if (NS_FAILED(ret)) {
+    BluetoothService::AcknowledgeToggleBt(false);
+    BT_LOGR("Error");
+  }
+
+  return ret;
+}
+
+nsresult
+BluetoothServiceBluedroid::StopInternal()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  nsresult ret = StopGonkBluetooth();
+  if (NS_FAILED(ret)) {
+    BluetoothService::AcknowledgeToggleBt(true);
+    BT_LOGR("Error");
+  }
+
+  return ret;
+}
+#endif
 
 //
 // GATT Client
 //
 
+#ifndef MOZ_B2G_BT_API_V1
 void
 BluetoothServiceBluedroid::StartLeScanInternal(
   const nsTArray<nsString>& aServiceUuids,
   BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
   ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
 
@@ -579,377 +769,17 @@ BluetoothServiceBluedroid::GattClientWri
 
   BluetoothGattManager* gatt = BluetoothGattManager::Get();
   ENSURE_GATT_MGR_IS_READY_VOID(gatt, aRunnable);
 
   gatt->WriteDescriptorValue(aAppUuid, aServiceId, aCharacteristicId,
                              aDescriptorId, aValue, aRunnable);
 }
 #else
-
-// Audio: Major service class = 0x100 (Bit 21 is set)
-#define SET_AUDIO_BIT(cod)               (cod |= 0x200000)
-// Rendering: Major service class = 0x20 (Bit 18 is set)
-#define SET_RENDERING_BIT(cod)           (cod |= 0x40000)
-
-using namespace mozilla;
-using namespace mozilla::ipc;
-USING_BLUETOOTH_NAMESPACE
-
-static nsString sAdapterBdAddress;
-static nsString sAdapterBdName;
-static InfallibleTArray<nsString> sAdapterBondedAddressArray;
-static BluetoothInterface* sBtInterface;
-static nsTArray<nsRefPtr<BluetoothProfileController> > sControllerArray;
-static InfallibleTArray<BluetoothNamedValue> sRemoteDevicesPack;
-static nsTArray<int> sRequestedDeviceCountArray;
-static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sSetPropertyRunnableArray;
-static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sGetDeviceRunnableArray;
-static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sBondingRunnableArray;
-static nsTArray<nsRefPtr<BluetoothReplyRunnable> > sUnbondingRunnableArray;
-static bool sAdapterDiscoverable(false);
-static bool sAdapterDiscovering(false);
-static bool sIsRestart(false);
-static bool sIsFirstTimeToggleOffBt(false);
-static uint32_t sAdapterDiscoverableTimeout(0);
-
-/**
- *  Static callback functions
- */
-void
-BluetoothServiceBluedroid::ClassToIcon(uint32_t aClass, nsAString& aRetIcon)
-{
-  switch ((aClass & 0x1f00) >> 8) {
-    case 0x01:
-      aRetIcon.AssignLiteral("computer");
-      break;
-    case 0x02:
-      switch ((aClass & 0xfc) >> 2) {
-        case 0x01:
-        case 0x02:
-        case 0x03:
-        case 0x05:
-          aRetIcon.AssignLiteral("phone");
-          break;
-        case 0x04:
-          aRetIcon.AssignLiteral("modem");
-          break;
-      }
-      break;
-    case 0x03:
-      aRetIcon.AssignLiteral("network-wireless");
-      break;
-    case 0x04:
-      switch ((aClass & 0xfc) >> 2) {
-        case 0x01:
-        case 0x02:
-        case 0x06:
-          aRetIcon.AssignLiteral("audio-card");
-          break;
-        case 0x0b:
-        case 0x0c:
-        case 0x0d:
-          aRetIcon.AssignLiteral("camera-video");
-          break;
-        default:
-          aRetIcon.AssignLiteral("audio-card");
-          break;
-      }
-      break;
-    case 0x05:
-      switch ((aClass & 0xc0) >> 6) {
-        case 0x00:
-          switch ((aClass && 0x1e) >> 2) {
-            case 0x01:
-            case 0x02:
-              aRetIcon.AssignLiteral("input-gaming");
-              break;
-          }
-          break;
-        case 0x01:
-          aRetIcon.AssignLiteral("input-keyboard");
-          break;
-        case 0x02:
-          switch ((aClass && 0x1e) >> 2) {
-            case 0x05:
-              aRetIcon.AssignLiteral("input-tablet");
-              break;
-            default:
-              aRetIcon.AssignLiteral("input-mouse");
-              break;
-          }
-      }
-      break;
-    case 0x06:
-      if (aClass & 0x80) {
-        aRetIcon.AssignLiteral("printer");
-        break;
-      }
-      if (aClass & 0x20) {
-        aRetIcon.AssignLiteral("camera-photo");
-        break;
-      }
-      break;
-  }
-
-  if (aRetIcon.IsEmpty()) {
-    if (HAS_AUDIO(aClass)) {
-      /**
-       * Property 'Icon' may be missed due to CoD of major class is TOY(0x08).
-       * But we need to assign Icon as audio-card if service class is 'Audio'.
-       * This is for PTS test case TC_AG_COD_BV_02_I. As HFP specification
-       * defines that service class is 'Audio' can be considered as HFP HF.
-       */
-      aRetIcon.AssignLiteral("audio-card");
-    } else {
-      BT_LOGR("No icon to match class: %x", aClass);
-    }
-  }
-}
-
-ControlPlayStatus
-BluetoothServiceBluedroid::PlayStatusStringToControlPlayStatus(
-  const nsAString& aPlayStatus)
-{
-  ControlPlayStatus playStatus = ControlPlayStatus::PLAYSTATUS_UNKNOWN;
-  if (aPlayStatus.EqualsLiteral("STOPPED")) {
-    playStatus = ControlPlayStatus::PLAYSTATUS_STOPPED;
-  } else if (aPlayStatus.EqualsLiteral("PLAYING")) {
-    playStatus = ControlPlayStatus::PLAYSTATUS_PLAYING;
-  } else if (aPlayStatus.EqualsLiteral("PAUSED")) {
-    playStatus = ControlPlayStatus::PLAYSTATUS_PAUSED;
-  } else if (aPlayStatus.EqualsLiteral("FWD_SEEK")) {
-    playStatus = ControlPlayStatus::PLAYSTATUS_FWD_SEEK;
-  } else if (aPlayStatus.EqualsLiteral("REV_SEEK")) {
-    playStatus = ControlPlayStatus::PLAYSTATUS_REV_SEEK;
-  } else if (aPlayStatus.EqualsLiteral("ERROR")) {
-    playStatus = ControlPlayStatus::PLAYSTATUS_ERROR;
-  }
-
-  return playStatus;
-}
-
-/**
- *  Static functions
- */
-class BluetoothServiceBluedroid::EnableResultHandler final
-  : public BluetoothResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BT_LOGR("BluetoothInterface::Enable failed: %d", aStatus);
-
-    BluetoothService::AcknowledgeToggleBt(false);
-  }
-};
-
-/* |ProfileInitResultHandler| collect the results of all profile
- * result handlers and calls |Proceed| after all results handlers
- * have been run.
- */
-class BluetoothServiceBluedroid::ProfileInitResultHandler final
-: public BluetoothProfileResultHandler
-{
-public:
-  ProfileInitResultHandler(unsigned char aNumProfiles)
-  : mNumProfiles(aNumProfiles)
-  {
-    MOZ_ASSERT(mNumProfiles);
-  }
-
-  void Init() override
-  {
-    if (!(--mNumProfiles)) {
-      Proceed();
-    }
-  }
-
-  void OnError(nsresult aResult) override
-  {
-    if (!(--mNumProfiles)) {
-      Proceed();
-    }
-  }
-
-private:
-  void Proceed() const
-  {
-    sBtInterface->Enable(new EnableResultHandler());
-  }
-
-  unsigned char mNumProfiles;
-};
-
-class BluetoothServiceBluedroid::InitResultHandler final
-  : public BluetoothResultHandler
-{
-public:
-  void Init() override
-  {
-    static void (* const sInitManager[])(BluetoothProfileResultHandler*) = {
-      BluetoothHfpManager::InitHfpInterface,
-      BluetoothA2dpManager::InitA2dpInterface
-    };
-
-    MOZ_ASSERT(NS_IsMainThread());
-
-    // Register all the bluedroid callbacks before enable() get called
-    // It is required to register a2dp callbacks before a2dp media task starts up.
-    // If any interface cannot be initialized, turn on bluetooth core anyway.
-    nsRefPtr<ProfileInitResultHandler> res =
-      new ProfileInitResultHandler(MOZ_ARRAY_LENGTH(sInitManager));
-
-    for (size_t i = 0; i < MOZ_ARRAY_LENGTH(sInitManager); ++i) {
-      sInitManager[i](res);
-    }
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BT_LOGR("BluetoothInterface::Init failed: %d", aStatus);
-
-    sBtInterface = nullptr;
-
-    BluetoothService::AcknowledgeToggleBt(false);
-  }
-};
-
-nsresult
-BluetoothServiceBluedroid::StartGonkBluetooth()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NS_ENSURE_TRUE(sBtInterface, NS_ERROR_FAILURE);
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-
-  if (bs->IsEnabled()) {
-    // Keep current enable status
-    BluetoothService::AcknowledgeToggleBt(true);
-    return NS_OK;
-  }
-
-  sBtInterface->Init(reinterpret_cast<BluetoothServiceBluedroid*>(bs),
-                     new InitResultHandler());
-
-  return NS_OK;
-}
-
-class BluetoothServiceBluedroid::DisableResultHandler final
-  : public BluetoothResultHandler
-{
-public:
-  void OnError(BluetoothStatus aStatus) override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    BT_LOGR("BluetoothInterface::Disable failed: %d", aStatus);
-
-    // Always make progress; even on failures
-    BluetoothService::AcknowledgeToggleBt(false);
-  }
-};
-
-nsresult
-BluetoothServiceBluedroid::StopGonkBluetooth()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  NS_ENSURE_TRUE(sBtInterface, NS_ERROR_FAILURE);
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
-
-  if (!bs->IsEnabled()) {
-    // Keep current enable status
-    BluetoothService::AcknowledgeToggleBt(false);
-    return NS_OK;
-  }
-
-  sBtInterface->Disable(new DisableResultHandler());
-
-  return NS_OK;
-}
-
-static void
-ReplyStatusError(BluetoothReplyRunnable* aBluetoothReplyRunnable,
-                 BluetoothStatus aStatusCode, const nsAString& aCustomMsg)
-{
-  MOZ_ASSERT(aBluetoothReplyRunnable, "Reply runnable is nullptr");
-
-  BT_LOGR("error code(%d)", aStatusCode);
-
-  nsAutoString replyError;
-  replyError.Assign(aCustomMsg);
-
-  if (aStatusCode == STATUS_BUSY) {
-    replyError.AppendLiteral(":BT_STATUS_BUSY");
-  } else if (aStatusCode == STATUS_NOT_READY) {
-    replyError.AppendLiteral(":BT_STATUS_NOT_READY");
-  } else if (aStatusCode == STATUS_DONE) {
-    replyError.AppendLiteral(":BT_STATUS_DONE");
-  } else if (aStatusCode == STATUS_AUTH_FAILURE) {
-    replyError.AppendLiteral(":BT_STATUS_AUTH_FAILURE");
-  } else if (aStatusCode == STATUS_RMT_DEV_DOWN) {
-    replyError.AppendLiteral(":BT_STATUS_RMT_DEV_DOWN");
-  } else if (aStatusCode == STATUS_FAIL) {
-    replyError.AppendLiteral(":BT_STATUS_FAIL");
-  }
-
-  DispatchReplyError(aBluetoothReplyRunnable, replyError);
-}
-
-/**
- *  Member functions
- */
-BluetoothServiceBluedroid::BluetoothServiceBluedroid()
-{
-  sBtInterface = BluetoothInterface::GetInstance();
-  if (!sBtInterface) {
-    BT_LOGR("Error! Failed to get instance of bluetooth interface");
-  }
-}
-
-BluetoothServiceBluedroid::~BluetoothServiceBluedroid()
-{
-}
-
-nsresult
-BluetoothServiceBluedroid::StartInternal()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  nsresult ret = StartGonkBluetooth();
-  if (NS_FAILED(ret)) {
-    BluetoothService::AcknowledgeToggleBt(false);
-    BT_LOGR("Error");
-  }
-
-  return ret;
-}
-
-nsresult
-BluetoothServiceBluedroid::StopInternal()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  nsresult ret = StopGonkBluetooth();
-  if (NS_FAILED(ret)) {
-    BluetoothService::AcknowledgeToggleBt(true);
-    BT_LOGR("Error");
-  }
-
-  return ret;
-}
+// Missing in Bluetooth v1
 #endif
 
 #ifndef MOZ_B2G_BT_API_V1
 nsresult
 BluetoothServiceBluedroid::GetAdaptersInternal(
   BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
@@ -1034,61 +864,48 @@ public:
   GetRemoteDevicePropertiesResultHandler(const nsAString& aDeviceAddress)
   : mDeviceAddress(aDeviceAddress)
   { }
 
   void OnError(BluetoothStatus aStatus) override
   {
     MOZ_ASSERT(NS_IsMainThread());
 
-#ifndef MOZ_B2G_BT_API_V1
     BT_WARNING("GetRemoteDeviceProperties(%s) failed: %d",
                NS_ConvertUTF16toUTF8(mDeviceAddress).get(), aStatus);
 
     /* dispatch result after final pending operation */
     if (--sRequestedDeviceCountArray[0] == 0) {
       if (!sGetDeviceRunnableArray.IsEmpty()) {
+#ifndef MOZ_B2G_BT_API_V1
         DispatchReplyError(sGetDeviceRunnableArray[0],
           NS_LITERAL_STRING("GetRemoteDeviceProperties failed"));
+#else
+        DispatchReplySuccess(sGetDeviceRunnableArray[0], sRemoteDevicesPack);
+#endif
         sGetDeviceRunnableArray.RemoveElementAt(0);
       }
 
       sRequestedDeviceCountArray.RemoveElementAt(0);
       sRemoteDevicesPack.Clear();
     }
-#else
-    BT_WARNING("GetRemoteDeviceProperties(%s) failed: %d",
-               mDeviceAddress.get(), aStatus);
-
-    /* dispatch result after final pending operation */
-    if (--sRequestedDeviceCountArray[0] == 0) {
-      if (!sGetDeviceRunnableArray.IsEmpty()) {
-        DispatchReplySuccess(sGetDeviceRunnableArray[0], sRemoteDevicesPack);
-        sGetDeviceRunnableArray.RemoveElementAt(0);
-      }
-
-      sRequestedDeviceCountArray.RemoveElementAt(0);
-      sRemoteDevicesPack.Clear();
-    }
-#endif
   }
 
 private:
   nsString mDeviceAddress;
 };
 
 nsresult
 BluetoothServiceBluedroid::GetConnectedDevicePropertiesInternal(
   uint16_t aServiceUuid, BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   ENSURE_BLUETOOTH_IS_READY(aRunnable, NS_OK);
 
-#ifndef MOZ_B2G_BT_API_V1
   BluetoothProfileManagerBase* profile =
     BluetoothUuidHelper::GetBluetoothProfileManager(aServiceUuid);
   if (!profile) {
     DispatchReplyError(aRunnable, NS_LITERAL_STRING(ERR_UNKNOWN_PROFILE));
     return NS_OK;
   }
 
   nsTArray<nsString> deviceAddresses;
@@ -1099,39 +916,16 @@ BluetoothServiceBluedroid::GetConnectedD
   }
 
   int requestedDeviceCount = deviceAddresses.Length();
   if (requestedDeviceCount == 0) {
     InfallibleTArray<BluetoothNamedValue> emptyArr;
     DispatchReplySuccess(aRunnable, emptyArr);
     return NS_OK;
   }
-#else
-  BluetoothProfileManagerBase* profile =
-    BluetoothUuidHelper::GetBluetoothProfileManager(aServiceUuid);
-  if (!profile) {
-    InfallibleTArray<BluetoothNamedValue> emptyArr;
-    DispatchReplyError(aRunnable, NS_LITERAL_STRING(ERR_UNKNOWN_PROFILE));
-    return NS_OK;
-  }
-
-  nsTArray<nsString> deviceAddresses;
-  if (profile->IsConnected()) {
-    nsString address;
-    profile->GetAddress(address);
-    deviceAddresses.AppendElement(address);
-  }
-
-  int requestedDeviceCount = deviceAddresses.Length();
-  if (requestedDeviceCount == 0) {
-    InfallibleTArray<BluetoothNamedValue> emptyArr;
-    DispatchReplySuccess(aRunnable, emptyArr);
-    return NS_OK;
-  }
-#endif
 
   sRequestedDeviceCountArray.AppendElement(requestedDeviceCount);
   sGetDeviceRunnableArray.AppendElement(aRunnable);
 
   for (int i = 0; i < requestedDeviceCount; i++) {
     // Retrieve all properties of devices
     sBtInterface->GetRemoteDeviceProperties(deviceAddresses[i],
       new GetRemoteDevicePropertiesResultHandler(deviceAddresses[i]));
@@ -1143,24 +937,24 @@ BluetoothServiceBluedroid::GetConnectedD
 nsresult
 BluetoothServiceBluedroid::GetPairedDevicePropertiesInternal(
   const nsTArray<nsString>& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   ENSURE_BLUETOOTH_IS_READY(aRunnable, NS_OK);
 
+  int requestedDeviceCount = aDeviceAddress.Length();
+
 #ifndef MOZ_B2G_BT_API_V1
-  int requestedDeviceCount = aDeviceAddress.Length();
   if (requestedDeviceCount == 0) {
     DispatchReplySuccess(aRunnable);
     return NS_OK;
   }
 #else
-  int requestedDeviceCount = aDeviceAddress.Length();
   if (requestedDeviceCount == 0) {
     DispatchReplySuccess(aRunnable, InfallibleTArray<BluetoothNamedValue>());
     return NS_OK;
   }
 
   sRequestedDeviceCountArray.AppendElement(requestedDeviceCount);
   sGetDeviceRunnableArray.AppendElement(aRunnable);
 #endif
@@ -1383,21 +1177,21 @@ public:
   CreateBondResultHandler(BluetoothReplyRunnable* aRunnable)
   : mRunnable(aRunnable)
   {
     MOZ_ASSERT(mRunnable);
   }
 
   void OnError(BluetoothStatus aStatus) override
   {
+    sBondingRunnableArray.RemoveElement(mRunnable);
+
 #ifndef MOZ_B2G_BT_API_V1
-    sBondingRunnableArray.RemoveElement(mRunnable);
     DispatchReplyError(mRunnable, aStatus);
 #else
-    sBondingRunnableArray.RemoveElement(mRunnable);
     ReplyStatusError(mRunnable, aStatus, NS_LITERAL_STRING("CreatedPairedDevice"));
 #endif
   }
 
 private:
   nsRefPtr<BluetoothReplyRunnable> mRunnable;
 };
 
@@ -1424,21 +1218,21 @@ public:
   RemoveBondResultHandler(BluetoothReplyRunnable* aRunnable)
   : mRunnable(aRunnable)
   {
     MOZ_ASSERT(mRunnable);
   }
 
   void OnError(BluetoothStatus aStatus) override
   {
+    sUnbondingRunnableArray.RemoveElement(mRunnable);
+
 #ifndef MOZ_B2G_BT_API_V1
-    sUnbondingRunnableArray.RemoveElement(mRunnable);
     DispatchReplyError(mRunnable, aStatus);
 #else
-    sUnbondingRunnableArray.RemoveElement(mRunnable);
     ReplyStatusError(mRunnable, aStatus, NS_LITERAL_STRING("RemoveDevice"));
 #endif
   }
 
 private:
   nsRefPtr<BluetoothReplyRunnable> mRunnable;
 };
 
@@ -1453,39 +1247,43 @@ BluetoothServiceBluedroid::RemoveDeviceI
   sUnbondingRunnableArray.AppendElement(aRunnable);
 
   sBtInterface->RemoveBond(aDeviceAddress,
                            new RemoveBondResultHandler(aRunnable));
 
   return NS_OK;
 }
 
-#ifndef MOZ_B2G_BT_API_V1
 class BluetoothServiceBluedroid::PinReplyResultHandler final
   : public BluetoothResultHandler
 {
 public:
   PinReplyResultHandler(BluetoothReplyRunnable* aRunnable)
   : mRunnable(aRunnable)
   { }
 
   void PinReply() override
   {
     DispatchReplySuccess(mRunnable);
   }
 
   void OnError(BluetoothStatus aStatus) override
   {
+#ifndef MOZ_B2G_BT_API_V1
     DispatchReplyError(mRunnable, aStatus);
+#else
+    ReplyStatusError(mRunnable, aStatus, NS_LITERAL_STRING("SetPinCode"));
+#endif
   }
 
 private:
   BluetoothReplyRunnable* mRunnable;
 };
 
+#ifndef MOZ_B2G_BT_API_V1
 void
 BluetoothServiceBluedroid::PinReplyInternal(
   const nsAString& aDeviceAddress, bool aAccept,
   const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
@@ -1497,38 +1295,16 @@ BluetoothServiceBluedroid::PinReplyInter
 void
 BluetoothServiceBluedroid::SetPinCodeInternal(
   const nsAString& aDeviceAddress, const nsAString& aPinCode,
   BluetoothReplyRunnable* aRunnable)
 {
   // Lecagy method used by BlueZ only.
 }
 #else
-class BluetoothServiceBluedroid::PinReplyResultHandler final
-  : public BluetoothResultHandler
-{
-public:
-  PinReplyResultHandler(BluetoothReplyRunnable* aRunnable)
-  : mRunnable(aRunnable)
-  { }
-
-  void PinReply() override
-  {
-    DispatchReplySuccess(mRunnable);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    ReplyStatusError(mRunnable, aStatus, NS_LITERAL_STRING("SetPinCode"));
-  }
-
-private:
-  BluetoothReplyRunnable* mRunnable;
-};
-
 bool
 BluetoothServiceBluedroid::SetPinCodeInternal(
   const nsAString& aDeviceAddress, const nsAString& aPinCode,
   BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   ENSURE_BLUETOOTH_IS_READY(aRunnable, false);
@@ -1553,39 +1329,44 @@ bool
 BluetoothServiceBluedroid::SetPasskeyInternal(
   const nsAString& aDeviceAddress, uint32_t aPasskey,
   BluetoothReplyRunnable* aRunnable)
 {
   return true;
 }
 #endif
 
-#ifndef MOZ_B2G_BT_API_V1
 class BluetoothServiceBluedroid::SspReplyResultHandler final
   : public BluetoothResultHandler
 {
 public:
   SspReplyResultHandler(BluetoothReplyRunnable* aRunnable)
   : mRunnable(aRunnable)
   { }
 
   void SspReply() override
   {
     DispatchReplySuccess(mRunnable);
   }
 
   void OnError(BluetoothStatus aStatus) override
   {
+#ifndef MOZ_B2G_BT_API_V1
     DispatchReplyError(mRunnable, aStatus);
+#else
+    ReplyStatusError(mRunnable, aStatus,
+                     NS_LITERAL_STRING("SetPairingConfirmation"));
+#endif
   }
 
 private:
   BluetoothReplyRunnable* mRunnable;
 };
 
+#ifndef MOZ_B2G_BT_API_V1
 void
 BluetoothServiceBluedroid::SspReplyInternal(
   const nsAString& aDeviceAddress, BluetoothSspVariant aVariant,
   bool aAccept, BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
@@ -1597,39 +1378,16 @@ BluetoothServiceBluedroid::SspReplyInter
 void
 BluetoothServiceBluedroid::SetPairingConfirmationInternal(
   const nsAString& aDeviceAddress, bool aConfirm,
   BluetoothReplyRunnable* aRunnable)
 {
   // Lecagy method used by BlueZ only.
 }
 #else
-class BluetoothServiceBluedroid::SspReplyResultHandler final
-  : public BluetoothResultHandler
-{
-public:
-  SspReplyResultHandler(BluetoothReplyRunnable* aRunnable)
-  : mRunnable(aRunnable)
-  { }
-
-  void SspReply() override
-  {
-    DispatchReplySuccess(mRunnable);
-  }
-
-  void OnError(BluetoothStatus aStatus) override
-  {
-    ReplyStatusError(mRunnable, aStatus,
-                     NS_LITERAL_STRING("SetPairingConfirmation"));
-  }
-
-private:
-  BluetoothReplyRunnable* mRunnable;
-};
-
 bool
 BluetoothServiceBluedroid::SetPairingConfirmationInternal(
   const nsAString& aDeviceAddress, bool aConfirm,
   BluetoothReplyRunnable* aRunnable)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   ENSURE_BLUETOOTH_IS_READY(aRunnable, false);
@@ -1654,48 +1412,36 @@ BluetoothServiceBluedroid::SetAuthorizat
 
 nsresult
 BluetoothServiceBluedroid::PrepareAdapterInternal()
 {
   return NS_OK;
 }
 #endif
 
-#ifndef MOZ_B2G_BT_API_V1
 void
 BluetoothServiceBluedroid::NextBluetoothProfileController()
-#else
-static void
-NextBluetoothProfileController()
-#endif
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // Remove the completed task at the head
   NS_ENSURE_FALSE_VOID(sControllerArray.IsEmpty());
   sControllerArray.RemoveElementAt(0);
 
   // Start the next task if task array is not empty
   if (!sControllerArray.IsEmpty()) {
     sControllerArray[0]->StartSession();
   }
 }
 
-#ifndef MOZ_B2G_BT_API_V1
 void
 BluetoothServiceBluedroid::ConnectDisconnect(
   bool aConnect, const nsAString& aDeviceAddress,
   BluetoothReplyRunnable* aRunnable,
   uint16_t aServiceUuid, uint32_t aCod)
-#else
-static void
-ConnectDisconnect(bool aConnect, const nsAString& aDeviceAddress,
-                  BluetoothReplyRunnable* aRunnable,
-                  uint16_t aServiceUuid, uint32_t aCod = 0)
-#endif
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aRunnable);
 
   BluetoothProfileController* controller =
     new BluetoothProfileController(aConnect, aDeviceAddress, aRunnable,
                                    NextBluetoothProfileController,
                                    aServiceUuid, aCod);
@@ -2821,26 +2567,26 @@ BluetoothServiceBluedroid::SspRequestNot
 #endif
 }
 
 void
 BluetoothServiceBluedroid::BondStateChangedNotification(
   BluetoothStatus aStatus, const nsAString& aRemoteBdAddr,
   BluetoothBondState aState)
 {
-#ifndef MOZ_B2G_BT_API_V1
   MOZ_ASSERT(NS_IsMainThread());
 
   if (aState == BOND_STATE_BONDING) {
     // No need to handle bonding state
     return;
   }
 
   BT_LOGR("Bond state: %d status: %d", aState, aStatus);
 
+#ifndef MOZ_B2G_BT_API_V1
   bool bonded = (aState == BOND_STATE_BONDED);
   if (aStatus != STATUS_SUCCESS) {
     if (!bonded) { // Active/passive pair failed
       BT_LOGR("Pair failed! Abort pairing.");
 
       // Notify adapter of pairing aborted
       DistributeSignal(NS_LITERAL_STRING(PAIRING_ABORTED_ID),
                        NS_LITERAL_STRING(KEY_ADAPTER));
@@ -2904,23 +2650,16 @@ BluetoothServiceBluedroid::BondStateChan
   if (bonded && !sBondingRunnableArray.IsEmpty()) {
     DispatchReplySuccess(sBondingRunnableArray[0]);
     sBondingRunnableArray.RemoveElementAt(0);
   } else if (!bonded && !sUnbondingRunnableArray.IsEmpty()) {
     DispatchReplySuccess(sUnbondingRunnableArray[0]);
     sUnbondingRunnableArray.RemoveElementAt(0);
   }
 #else
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (aState == BOND_STATE_BONDING) {
-    // No need to handle bonding state
-    return;
-  }
-
   if (aState == BOND_STATE_BONDED &&
       sAdapterBondedAddressArray.Contains(aRemoteBdAddr)) {
     // See bug 940271 for more details about this case.
     return;
   }
 
   switch (aStatus) {
     case STATUS_SUCCESS:
@@ -3018,28 +2757,24 @@ void
 BluetoothServiceBluedroid::LeTestModeNotification(BluetoothStatus aStatus,
                                                   uint16_t aNumPackets)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // FIXME: This will be implemented in the later patchset
 }
 
-#ifndef MOZ_B2G_BT_API_V1
-// TODO: Support EnergyInfoNotification
-#else
 void
 BluetoothServiceBluedroid::EnergyInfoNotification(
   const BluetoothActivityEnergyInfo& aInfo)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // FIXME: This will be implemented in the later patchset
 }
-#endif
 
 void
 BluetoothServiceBluedroid::BackendErrorNotification(bool aCrashed)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!aCrashed) {
     return;
--- a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.h
+++ b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.h
@@ -2,64 +2,79 @@
 /* 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/. */
 
 #ifndef mozilla_dom_bluetooth_bluetoothservicebluedroid_h__
 #define mozilla_dom_bluetooth_bluetoothservicebluedroid_h__
 
-#ifndef MOZ_B2G_BT_API_V1
-
 #include "BluetoothCommon.h"
 #include "BluetoothInterface.h"
 #include "BluetoothService.h"
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 class BluetoothServiceBluedroid : public BluetoothService
                                 , public BluetoothNotificationHandler
 {
   class CancelDiscoveryResultHandler;
   class CreateBondResultHandler;
   class DisableResultHandler;
   class EnableResultHandler;
   class GetRemoteDevicePropertiesResultHandler;
+#ifndef MOZ_B2G_BT_API_V1
   class GetRemoteServicesResultHandler;
+#else
+  // Missing in Bluetooth v1
+#endif
   class InitResultHandler;
   class PinReplyResultHandler;
   class ProfileDeinitResultHandler;
   class ProfileInitResultHandler;
   class RemoveBondResultHandler;
   class SetAdapterPropertyDiscoverableResultHandler;
   class SetAdapterPropertyResultHandler;
   class SspReplyResultHandler;
   class StartDiscoveryResultHandler;
 
 public:
   BluetoothServiceBluedroid();
   ~BluetoothServiceBluedroid();
 
+#ifndef MOZ_B2G_BT_API_V1
   virtual nsresult StartInternal(BluetoothReplyRunnable* aRunnable);
   virtual nsresult StopInternal(BluetoothReplyRunnable* aRunnable);
+#else
+  virtual nsresult StartInternal();
+  virtual nsresult StopInternal();
+#endif
 
-  virtual nsresult
-  GetAdaptersInternal(BluetoothReplyRunnable* aRunnable);
+#ifndef MOZ_B2G_BT_API_V1
+  virtual nsresult GetAdaptersInternal(BluetoothReplyRunnable* aRunnable);
+#else
+  virtual nsresult GetDefaultAdapterPathInternal(
+    BluetoothReplyRunnable* aRunnable);
+#endif
 
   virtual nsresult
   GetConnectedDevicePropertiesInternal(uint16_t aProfileId,
                                        BluetoothReplyRunnable* aRunnable);
 
   virtual nsresult
   GetPairedDevicePropertiesInternal(const nsTArray<nsString>& aDeviceAddress,
                                     BluetoothReplyRunnable* aRunnable);
 
+#ifndef MOZ_B2G_BT_API_V1
   virtual nsresult
   FetchUuidsInternal(const nsAString& aDeviceAddress,
                      BluetoothReplyRunnable* aRunnable) override;
+#else
+  // Missing in Bluetooth v1
+#endif
 
   virtual void StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable);
   virtual void StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable);
 
   virtual nsresult
   SetProperty(BluetoothObjectType aType,
               const BluetoothNamedValue& aValue,
               BluetoothReplyRunnable* aRunnable);
@@ -77,51 +92,84 @@ public:
   CreatePairedDeviceInternal(const nsAString& aDeviceAddress,
                              int aTimeout,
                              BluetoothReplyRunnable* aRunnable);
 
   virtual nsresult
   RemoveDeviceInternal(const nsAString& aDeviceObjectPath,
                        BluetoothReplyRunnable* aRunnable);
 
+#ifndef MOZ_B2G_BT_API_V1
   virtual void
   PinReplyInternal(const nsAString& aDeviceAddress,
                    bool aAccept,
                    const nsAString& aPinCode,
                    BluetoothReplyRunnable* aRunnable);
 
   virtual void
   SspReplyInternal(const nsAString& aDeviceAddress,
                    BluetoothSspVariant aVariant,
                    bool aAccept,
                    BluetoothReplyRunnable* aRunnable);
-
   virtual void
   SetPinCodeInternal(const nsAString& aDeviceAddress,
                      const nsAString& aPinCode,
                      BluetoothReplyRunnable* aRunnable);
 
   virtual void
   SetPasskeyInternal(const nsAString& aDeviceAddress,
                      uint32_t aPasskey,
                      BluetoothReplyRunnable* aRunnable);
 
   virtual void
   SetPairingConfirmationInternal(const nsAString& aDeviceAddress,
                                  bool aConfirm,
                                  BluetoothReplyRunnable* aRunnable);
+#else
+  virtual bool
+  SetAuthorizationInternal(const nsAString& aDeviceAddress, bool aAllow,
+                           BluetoothReplyRunnable* aRunnable);
+
+  virtual bool
+  SetPinCodeInternal(const nsAString& aDeviceAddress,
+                     const nsAString& aPinCode,
+                     BluetoothReplyRunnable* aRunnable);
+
+  virtual bool
+  SetPasskeyInternal(const nsAString& aDeviceAddress,
+                     uint32_t aPasskey,
+                     BluetoothReplyRunnable* aRunnable);
+
+  virtual bool
+  SetPairingConfirmationInternal(const nsAString& aDeviceAddress,
+                                 bool aConfirm,
+                                 BluetoothReplyRunnable* aRunnable);
+#endif
+
+#ifndef MOZ_B2G_BT_API_V1
+  // Missing in Bluetooth v2
+#else
+  virtual nsresult
+  PrepareAdapterInternal();
+#endif
 
   virtual void
   Connect(const nsAString& aDeviceAddress,
           uint32_t aCod,
           uint16_t aServiceUuid,
           BluetoothReplyRunnable* aRunnable);
 
+#ifndef MOZ_B2G_BT_API_V1
   virtual bool
   IsConnected(uint16_t aProfileId);
+#else
+  virtual void
+  IsConnected(const uint16_t aServiceUuid,
+              BluetoothReplyRunnable* aRunnable) override;
+#endif
 
   virtual void
   Disconnect(const nsAString& aDeviceAddress, uint16_t aServiceUuid,
              BluetoothReplyRunnable* aRunnable);
 
   virtual void
   SendFile(const nsAString& aDeviceAddress,
            BlobParent* aBlobParent,
@@ -186,16 +234,17 @@ public:
   virtual nsresult
   SendInputMessage(const nsAString& aDeviceAddresses,
                    const nsAString& aMessage) override;
 
   //
   // GATT Client
   //
 
+#ifndef MOZ_B2G_BT_API_V1
   virtual void StartLeScanInternal(const nsTArray<nsString>& aServiceUuids,
                                    BluetoothReplyRunnable* aRunnable);
 
   virtual void StopLeScanInternal(const nsAString& aScanUuid,
                                   BluetoothReplyRunnable* aRunnable);
 
   virtual void
   ConnectGattClientInternal(const nsAString& aAppUuid,
@@ -261,16 +310,19 @@ public:
   virtual void
   GattClientWriteDescriptorValueInternal(
     const nsAString& aAppUuid,
     const BluetoothGattServiceId& aServiceId,
     const BluetoothGattId& aCharacteristicId,
     const BluetoothGattId& aDescriptorId,
     const nsTArray<uint8_t>& aValue,
     BluetoothReplyRunnable* aRunnable) override;
+#else
+  // Missing in Bluetooth v1
+#endif
 
   //
   // Bluetooth notifications
   //
 
   virtual void AdapterStateChangedNotification(bool aState) override;
   virtual void AdapterPropertiesNotification(
     BluetoothStatus aStatus, int aNumProperties,
@@ -301,259 +353,45 @@ public:
                                            const nsAString& aRemoteBdAddr,
                                            bool aState) override;
 
   virtual void DutModeRecvNotification(uint16_t aOpcode,
                                        const uint8_t* aBuf,
                                        uint8_t aLen) override;
   virtual void LeTestModeNotification(BluetoothStatus aStatus,
                                       uint16_t aNumPackets) override;
+
+  virtual void EnergyInfoNotification(
+    const BluetoothActivityEnergyInfo& aInfo) override;
+
   virtual void BackendErrorNotification(bool aCrashed) override;
 
   virtual void CompleteToggleBt(bool aEnabled) override;
+
 protected:
   static nsresult StartGonkBluetooth();
   static nsresult StopGonkBluetooth();
 
+  static ControlPlayStatus PlayStatusStringToControlPlayStatus(
+    const nsAString& aPlayStatus);
+
   static void ConnectDisconnect(bool aConnect,
                                 const nsAString& aDeviceAddress,
                                 BluetoothReplyRunnable* aRunnable,
                                 uint16_t aServiceUuid, uint32_t aCod = 0);
   static void NextBluetoothProfileController();
-  static ControlPlayStatus PlayStatusStringToControlPlayStatus(
-    const nsAString& aPlayStatus);
-};
 
-END_BLUETOOTH_NAMESPACE
-
+#ifndef MOZ_B2G_BT_API_V1
+  // Missing in Bluetooth v2
 #else
-
-#include "BluetoothCommon.h"
-#include "BluetoothInterface.h"
-#include "BluetoothService.h"
-
-BEGIN_BLUETOOTH_NAMESPACE
-
-class BluetoothServiceBluedroid : public BluetoothService
-                                , public BluetoothNotificationHandler
-{
-  class CancelDiscoveryResultHandler;
-  class CreateBondResultHandler;
-  class DisableResultHandler;
-  class EnableResultHandler;
-  class GetRemoteDevicePropertiesResultHandler;
-  class InitResultHandler;
-  class PinReplyResultHandler;
-  class ProfileDeinitResultHandler;
-  class ProfileInitResultHandler;
-  class RemoveBondResultHandler;
-  class SetAdapterPropertyDiscoverableResultHandler;
-  class SetAdapterPropertyResultHandler;
-  class SspReplyResultHandler;
-  class StartDiscoveryResultHandler;
-
-public:
-  BluetoothServiceBluedroid();
-  ~BluetoothServiceBluedroid();
-
-  virtual nsresult StartInternal();
-  virtual nsresult StopInternal();
-
-  virtual nsresult GetDefaultAdapterPathInternal(
-                                             BluetoothReplyRunnable* aRunnable);
-
-  virtual nsresult GetConnectedDevicePropertiesInternal(uint16_t aProfileId,
-                                             BluetoothReplyRunnable* aRunnable);
-
-  virtual nsresult GetPairedDevicePropertiesInternal(
-                                     const nsTArray<nsString>& aDeviceAddress,
-                                     BluetoothReplyRunnable* aRunnable);
-
-  virtual void StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable);
-  virtual void StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable);
-
-  virtual nsresult
-  SetProperty(BluetoothObjectType aType,
-              const BluetoothNamedValue& aValue,
-              BluetoothReplyRunnable* aRunnable);
-
-  virtual nsresult
-  GetServiceChannel(const nsAString& aDeviceAddress,
-                    const nsAString& aServiceUuid,
-                    BluetoothProfileManagerBase* aManager);
-
-  virtual bool
-  UpdateSdpRecords(const nsAString& aDeviceAddress,
-                   BluetoothProfileManagerBase* aManager);
-
-  virtual nsresult
-  CreatePairedDeviceInternal(const nsAString& aDeviceAddress,
-                             int aTimeout,
-                             BluetoothReplyRunnable* aRunnable);
-
-  virtual nsresult
-  RemoveDeviceInternal(const nsAString& aDeviceObjectPath,
-                       BluetoothReplyRunnable* aRunnable);
-
-  virtual bool
-  SetPinCodeInternal(const nsAString& aDeviceAddress, const nsAString& aPinCode,
-                     BluetoothReplyRunnable* aRunnable);
-
-  virtual bool
-  SetPasskeyInternal(const nsAString& aDeviceAddress, uint32_t aPasskey,
-                     BluetoothReplyRunnable* aRunnable);
-
-  virtual bool
-  SetPairingConfirmationInternal(const nsAString& aDeviceAddress, bool aConfirm,
-                                 BluetoothReplyRunnable* aRunnable);
-
-  virtual bool
-  SetAuthorizationInternal(const nsAString& aDeviceAddress, bool aAllow,
-                           BluetoothReplyRunnable* aRunnable);
-
-  virtual nsresult
-  PrepareAdapterInternal();
-
-  virtual void
-  Connect(const nsAString& aDeviceAddress,
-          uint32_t aCod,
-          uint16_t aServiceUuid,
-          BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  Disconnect(const nsAString& aDeviceAddress, uint16_t aServiceUuid,
-             BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  IsConnected(const uint16_t aServiceUuid,
-              BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  SendFile(const nsAString& aDeviceAddress,
-           BlobParent* aBlobParent,
-           BlobChild* aBlobChild,
-           BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  SendFile(const nsAString& aDeviceAddress,
-           Blob* aBlob,
-           BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  StopSendingFile(const nsAString& aDeviceAddress,
-                  BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ConfirmReceivingFile(const nsAString& aDeviceAddress, bool aConfirm,
-                       BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ConnectSco(BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  DisconnectSco(BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  IsScoConnected(BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  AnswerWaitingCall(BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  IgnoreWaitingCall(BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  ToggleCalls(BluetoothReplyRunnable* aRunnable);
-
-  virtual void
-  SendMetaData(const nsAString& aTitle,
-               const nsAString& aArtist,
-               const nsAString& aAlbum,
-               int64_t aMediaNumber,
-               int64_t aTotalMediaCount,
-               int64_t aDuration,
-               BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  SendPlayStatus(int64_t aDuration,
-                 int64_t aPosition,
-                 const nsAString& aPlayStatus,
-                 BluetoothReplyRunnable* aRunnable) override;
-
-  virtual void
-  UpdatePlayStatus(uint32_t aDuration,
-                   uint32_t aPosition,
-                   ControlPlayStatus aPlayStatus) override;
-
-  virtual nsresult
-  SendSinkMessage(const nsAString& aDeviceAddresses,
-                  const nsAString& aMessage) override;
-
-  virtual nsresult
-  SendInputMessage(const nsAString& aDeviceAddresses,
-                   const nsAString& aMessage) override;
-
-  //
-  // Bluetooth notifications
-  //
-
-  virtual void AdapterStateChangedNotification(bool aState) override;
-  virtual void AdapterPropertiesNotification(
-    BluetoothStatus aStatus, int aNumProperties,
-    const BluetoothProperty* aProperties) override;
-
-  virtual void RemoteDevicePropertiesNotification(
-    BluetoothStatus aStatus, const nsAString& aBdAddr,
-    int aNumProperties, const BluetoothProperty* aProperties) override;
-
-  virtual void DeviceFoundNotification(
-    int aNumProperties, const BluetoothProperty* aProperties) override;
-
-  virtual void DiscoveryStateChangedNotification(bool aState) override;
-
-  virtual void PinRequestNotification(const nsAString& aRemoteBdAddr,
-                                      const nsAString& aBdName,
-                                      uint32_t aCod) override;
-  virtual void SspRequestNotification(const nsAString& aRemoteBdAddr,
-                                      const nsAString& aBdName,
-                                      uint32_t aCod,
-                                      BluetoothSspVariant aPairingVariant,
-                                      uint32_t aPassKey) override;
-
-  virtual void BondStateChangedNotification(
-    BluetoothStatus aStatus, const nsAString& aRemoteBdAddr,
-    BluetoothBondState aState) override;
-  virtual void AclStateChangedNotification(BluetoothStatus aStatus,
-                                           const nsAString& aRemoteBdAddr,
-                                           bool aState) override;
-
-  virtual void DutModeRecvNotification(uint16_t aOpcode,
-                                       const uint8_t* aBuf,
-                                       uint8_t aLen) override;
-  virtual void LeTestModeNotification(BluetoothStatus aStatus,
-                                      uint16_t aNumPackets) override;
-
-  virtual void EnergyInfoNotification(
-    const BluetoothActivityEnergyInfo& aInfo) override;
-
-  virtual void BackendErrorNotification(bool aCrashed) override;
-  virtual void CompleteToggleBt(bool aEnabled) override;
-
-protected:
-  static nsresult StartGonkBluetooth();
-  static nsresult StopGonkBluetooth();
   static bool EnsureBluetoothHalLoad();
 
   static void ClassToIcon(uint32_t aClass, nsAString& aRetIcon);
 
-  static ControlPlayStatus PlayStatusStringToControlPlayStatus(
-    const nsAString& aPlayStatus);
-
   uint16_t UuidToServiceClassInt(const BluetoothUuid& mUuid);
 
   static bool IsConnected(const nsAString& aRemoteBdAddr);
+#endif
 };
 
 END_BLUETOOTH_NAMESPACE
 
 #endif
-
-#endif
--- a/dom/media/platforms/gonk/GonkDecoderModule.cpp
+++ b/dom/media/platforms/gonk/GonkDecoderModule.cpp
@@ -61,14 +61,15 @@ GonkDecoderModule::DecoderNeedsConversio
 }
 
 bool
 GonkDecoderModule::SupportsMimeType(const nsACString& aMimeType)
 {
   return aMimeType.EqualsLiteral("audio/mp4a-latm") ||
     aMimeType.EqualsLiteral("audio/3gpp") ||
     aMimeType.EqualsLiteral("audio/amr-wb") ||
+    aMimeType.EqualsLiteral("audio/mpeg") ||
     aMimeType.EqualsLiteral("video/mp4") ||
     aMimeType.EqualsLiteral("video/mp4v-es") ||
     aMimeType.EqualsLiteral("video/avc") ||
     aMimeType.EqualsLiteral("video/3gpp");
 }
 } // namespace mozilla
--- a/dom/secureelement/gonk/UiccConnector.js
+++ b/dom/secureelement/gonk/UiccConnector.js
@@ -323,17 +323,17 @@ UiccConnector.prototype = {
     this._SEListeners.push(listener);
     // immediately notify listener about the current state
     listener.notifySEPresenceChanged(SE.TYPE_UICC, this._isPresent);
   },
 
   unregisterListener: function(listener) {
     let idx = this._SEListeners.indexOf(listener);
     if (idx !== -1) {
-      this._listeners.splice(idx, 1);
+      this._SEListeners.splice(idx, 1);
     }
   },
 
   /**
    * nsIIccListener interface methods.
    */
   notifyStkCommand: function() {},
 
--- a/layout/base/FrameLayerBuilder.cpp
+++ b/layout/base/FrameLayerBuilder.cpp
@@ -46,63 +46,16 @@ using namespace mozilla::layers;
 using namespace mozilla::gfx;
 
 namespace mozilla {
 
 class PaintedDisplayItemLayerUserData;
 
 static nsTHashtable<nsPtrHashKey<FrameLayerBuilder::DisplayItemData>>* sAliveDisplayItemDatas;
 
-static const nsIntSize kRegionTileSize(128, 128);
-
-/**
- * An alternative to nsIntRegion that keeps the region simple by snapping all
- * accumulated rects outwards to tiles. It keeps track of the bounds of the
- * true unsimplified region so that the result still has the bounds you'd
- * expect.
- * This approach doesn't guarantee a maximum number of rectangles in the
- * region, but it has the advantage that region simplification doesn't merge
- * rectangles that are very far apart; the simplification impact is local.
- * This representation also has the property of being canonical: the result
- * is independent of the order in which the rectangles are added.
- */
-struct nsIntRegionSimplifiedToTiles
-{
-  nsIntRegionSimplifiedToTiles(const nsIntPoint& aTileOrigin,
-                               const nsIntSize& aTileSize)
-    : mTileOrigin(aTileOrigin)
-    , mTileSize(aTileSize)
-  {}
-
-  nsIntRegion Get() const { return mRegion.Intersect(mBounds); }
-
-  void Accumulate(const nsIntRect& aRect)
-  {
-    mBounds = mBounds.Union(aRect);
-    nsIntRect rect = aRect - mTileOrigin;
-    rect.InflateToMultiple(mTileSize);
-    mRegion.OrWith(rect + mTileOrigin);
-  }
-
-  bool IsEmpty() const { return mBounds.IsEmpty(); }
-  void SetEmpty()
-  { mRegion.SetEmpty(); mBounds.SetEmpty(); }
-  nsIntRegion Intersect(const nsIntRegion& aRegion) const
-  { return Get().Intersect(aRegion); }
-  bool Intersects(const nsIntRect& aRect) const
-  { return mRegion.Intersects(mBounds.Intersect(aRect)); }
-  nsIntRect GetBounds() const { return mBounds; }
-
-private:
-  nsIntRegion mRegion;
-  nsIntRect mBounds;
-  nsIntPoint mTileOrigin;
-  nsIntSize mTileSize;
-};
-
 FrameLayerBuilder::DisplayItemData::DisplayItemData(LayerManagerData* aParent, uint32_t aKey,
                                                     Layer* aLayer, nsIFrame* aFrame)
 
   : mParent(aParent)
   , mLayer(aLayer)
   , mDisplayItemKey(aKey)
   , mItem(nullptr)
   , mUsed(true)
@@ -328,36 +281,31 @@ struct AssignedDisplayItem
  * We use a stack here because as much as possible we want to
  * assign display items to existing PaintedLayers, and to the lowest
  * PaintedLayer in z-order. This reduces the number of layers and
  * makes it more likely a display item will be rendered to an opaque
  * layer, giving us the best chance of getting subpixel AA.
  */
 class PaintedLayerData {
 public:
-  PaintedLayerData(const nsIFrame* aAnimatedGeometryRoot,
-                   const nsPoint& aTopLeft,
-                   const nsIntPoint& aSnappedOffset) :
-    mVisibleRegion(aSnappedOffset, kRegionTileSize),
-    mAnimatedGeometryRoot(aAnimatedGeometryRoot),
-    mAnimatedGeometryRootOffset(aTopLeft),
+  PaintedLayerData() :
+    mAnimatedGeometryRoot(nullptr),
     mFixedPosFrameForLayerData(nullptr),
     mReferenceFrame(nullptr),
     mLayer(nullptr),
     mIsSolidColorInVisibleRegion(false),
     mFontSmoothingBackgroundColor(NS_RGBA(0,0,0,0)),
     mSingleItemFixedToViewport(false),
     mNeedComponentAlpha(false),
     mForceTransparentSurface(false),
     mHideAllLayersBelow(false),
     mOpaqueForAnimatedGeometryRootParent(false),
     mImage(nullptr),
     mCommonClipCount(-1),
-    mNewChildLayersIndex(-1),
-    mVisibleAboveRegion(aSnappedOffset, kRegionTileSize)
+    mNewChildLayersIndex(-1)
   {}
 
 #ifdef MOZ_DUMP_PAINTING
   /**
    * Keep track of important decisions for debugging.
    */
   nsCString mLog;
 
@@ -424,17 +372,17 @@ public:
   bool VisibleRegionIntersects(const nsIntRegion& aRegion) const
   { return !mVisibleRegion.Intersect(aRegion).IsEmpty(); }
 
   /**
    * The region of visible content in the layer, relative to the
    * container layer (which is at the snapped top-left of the display
    * list reference frame).
    */
-  nsIntRegionSimplifiedToTiles mVisibleRegion;
+  nsIntRegion  mVisibleRegion;
   /**
    * The region of visible content in the layer that is opaque.
    * Same coordinate system as mVisibleRegion.
    */
   nsIntRegion  mOpaqueRegion;
   /**
    * The definitely-hit region for this PaintedLayer.
    */
@@ -565,17 +513,17 @@ public:
    * The union of all the bounds of the display items in this layer.
    */
   nsIntRect mBounds;
   /**
    * The region of visible content above the layer and below the
    * next PaintedLayerData currently in the stack, if any.
    * This is a conservative approximation: it contains the true region.
    */
-  nsIntRegionSimplifiedToTiles mVisibleAboveRegion;
+  nsIntRegion mVisibleAboveRegion;
   /**
    * All the display items that have been assigned to this painted layer.
    * These items get added by Accumulate().
    */
   nsTArray<AssignedDisplayItem> mAssignedDisplayItems;
 
 };
 
@@ -642,18 +590,17 @@ class PaintedLayerDataTree;
  * stack, in z-order, and the clip rects of the child nodes are allowed to
  * intersect with the visible region or visible above region of their parent
  * node's PaintedLayerDatas.
  */
 class PaintedLayerDataNode {
 public:
   PaintedLayerDataNode(PaintedLayerDataTree& aTree,
                        PaintedLayerDataNode* aParent,
-                       const nsIFrame* aAnimatedGeometryRoot,
-                       const nsIntPoint& aSnappedOffset);
+                       const nsIFrame* aAnimatedGeometryRoot);
   ~PaintedLayerDataNode();
 
   const nsIFrame* AnimatedGeometryRoot() const { return mAnimatedGeometryRoot; }
 
   /**
    * Whether this node's contents can potentially intersect aRect.
    * aRect is in our tree's ContainerState's coordinate space.
    */
@@ -741,17 +688,16 @@ protected:
    * Pass off opaque background color searching to our parent node, if we have
    * one.
    */
   nscolor FindOpaqueBackgroundColorInParentNode() const;
 
   PaintedLayerDataTree& mTree;
   PaintedLayerDataNode* mParent;
   const nsIFrame* mAnimatedGeometryRoot;
-  const nsIntPoint mSnappedAnimatedGeometryRootOffset;
 
   /**
    * Our contents: a PaintedLayerData stack and our child nodes.
    */
   nsTArray<PaintedLayerData> mPaintedLayerDataStack;
 
   /**
    * UniquePtr is used here in the sense of "unique ownership", i.e. there is
@@ -767,17 +713,17 @@ protected:
 
   /**
    * The region that's covered between our "background" and the bottom of
    * mPaintedLayerDataStack. This is used to indicate whether we can pull
    * a background color from our parent node. If mVisibleAboveBackgroundRegion
    * should be considered infinite, mAllDrawingAboveBackground will be true and
    * the value of mVisibleAboveBackgroundRegion will be meaningless.
    */
-  nsIntRegionSimplifiedToTiles mVisibleAboveBackgroundRegion;
+  nsIntRegion mVisibleAboveBackgroundRegion;
 
   /**
    * Our clip, if we have any. If not, that means we can move anywhere, and
    * mHasClip will be false and mClipRect will be meaningless.
    */
   nsIntRect mClipRect;
   bool mHasClip;
 
@@ -1037,30 +983,19 @@ public:
   {
     if (aSnap && mSnappingEnabled) {
       return ScaleRegionToNearestPixels(aRegion);
     }
     return aRegion.ScaleToOutsidePixels(mParameters.mXScale, mParameters.mYScale,
                                         mAppUnitsPerDevPixel);
   }
 
-  nsIntPoint SnapPointToPixels(const nsPoint& aPoint) const
-  {
-    return aPoint.ScaleToNearestPixels(mParameters.mXScale, mParameters.mYScale,
-                                       mAppUnitsPerDevPixel);
-  }
-
   nsIFrame* GetContainerFrame() const { return mContainerFrame; }
   nsDisplayListBuilder* Builder() const { return mBuilder; }
 
-  nsIntPoint GetSnappedOffsetToContainerReferenceFrame(const nsIFrame* aFrame)
-  {
-    return SnapPointToPixels(aFrame->GetOffsetToCrossDoc(mContainerReferenceFrame));
-  }
-
   /**
    * Sets aOuterVisibleRegion as aLayer's visible region. aOuterVisibleRegion
    * is in the coordinate space of the container reference frame.
    * aLayerContentsVisibleRect, if non-null, is in the layer's own
    * coordinate system.
    */
   void SetOuterVisibleRegionForLayer(Layer* aLayer,
                                      const nsIntRegion& aOuterVisibleRegion,
@@ -2558,41 +2493,38 @@ PaintedLayerData::GetContainerForImageLa
     return nullptr;
   }
 
   return mImage->GetContainer(mLayer->Manager(), aBuilder);
 }
 
 PaintedLayerDataNode::PaintedLayerDataNode(PaintedLayerDataTree& aTree,
                                            PaintedLayerDataNode* aParent,
-                                           const nsIFrame* aAnimatedGeometryRoot,
-                                           const nsIntPoint& aSnappedOffset)
+                                           const nsIFrame* aAnimatedGeometryRoot)
   : mTree(aTree)
   , mParent(aParent)
   , mAnimatedGeometryRoot(aAnimatedGeometryRoot)
-  , mVisibleAboveBackgroundRegion(aSnappedOffset, kRegionTileSize)
   , mAllDrawingAboveBackground(false)
 {
   MOZ_ASSERT(nsLayoutUtils::IsAncestorFrameCrossDoc(mTree.Builder()->RootReferenceFrame(), mAnimatedGeometryRoot));
   mHasClip = mTree.IsClippedWithRespectToParentAnimatedGeometryRoot(mAnimatedGeometryRoot, &mClipRect);
 }
 
 PaintedLayerDataNode::~PaintedLayerDataNode()
 {
   MOZ_ASSERT(mPaintedLayerDataStack.IsEmpty());
   MOZ_ASSERT(mChildren.IsEmpty());
 }
 
 PaintedLayerDataNode*
 PaintedLayerDataNode::AddChildNodeFor(const nsIFrame* aAnimatedGeometryRoot)
 {
   MOZ_ASSERT(mTree.GetParentAnimatedGeometryRoot(aAnimatedGeometryRoot) == mAnimatedGeometryRoot);
-  nsIntPoint snappedOffset = mTree.ContState().GetSnappedOffsetToContainerReferenceFrame(aAnimatedGeometryRoot);
   UniquePtr<PaintedLayerDataNode> child =
-    MakeUnique<PaintedLayerDataNode>(mTree, this, aAnimatedGeometryRoot, snappedOffset);
+    MakeUnique<PaintedLayerDataNode>(mTree, this, aAnimatedGeometryRoot);
   mChildren.AppendElement(Move(child));
   return mChildren.LastElement().get();
 }
 
 template<typename NewPaintedLayerCallbackType>
 PaintedLayerData*
 PaintedLayerDataNode::FindPaintedLayerFor(const nsIntRect& aVisibleRect,
                                           NewPaintedLayerCallbackType aNewPaintedLayerCallback)
@@ -2658,20 +2590,21 @@ PaintedLayerDataNode::Finish(bool aParen
     }
   }
   mTree.NodeWasFinished(mAnimatedGeometryRoot);
 }
 
 void
 PaintedLayerDataNode::AddToVisibleAboveRegion(const nsIntRect& aRect)
 {
-  nsIntRegionSimplifiedToTiles& visibleAboveRegion = mPaintedLayerDataStack.IsEmpty()
+  nsIntRegion& visibleAboveRegion = mPaintedLayerDataStack.IsEmpty()
     ? mVisibleAboveBackgroundRegion
     : mPaintedLayerDataStack.LastElement().mVisibleAboveRegion;
-  visibleAboveRegion.Accumulate(aRect);
+  visibleAboveRegion.Or(visibleAboveRegion, aRect);
+  visibleAboveRegion.SimplifyOutward(8);
 }
 
 void
 PaintedLayerDataNode::SetAllDrawingAbove()
 {
   PopAllPaintedLayerData();
   mAllDrawingAboveBackground = true;
   mVisibleAboveBackgroundRegion.SetEmpty();
@@ -2679,17 +2612,17 @@ PaintedLayerDataNode::SetAllDrawingAbove
 
 void
 PaintedLayerDataNode::PopPaintedLayerData()
 {
   MOZ_ASSERT(!mPaintedLayerDataStack.IsEmpty());
   size_t lastIndex = mPaintedLayerDataStack.Length() - 1;
   PaintedLayerData& data = mPaintedLayerDataStack[lastIndex];
   mTree.ContState().FinishPaintedLayerData(data, [this, &data, lastIndex]() {
-    return this->FindOpaqueBackgroundColor(data.mVisibleRegion.Get(), lastIndex);
+    return this->FindOpaqueBackgroundColor(data.mVisibleRegion, lastIndex);
   });
   mPaintedLayerDataStack.RemoveElementAt(lastIndex);
 }
 
 void
 PaintedLayerDataNode::PopAllPaintedLayerData()
 {
   while (!mPaintedLayerDataStack.IsEmpty()) {
@@ -2836,18 +2769,17 @@ PaintedLayerDataTree::EnsureNodeFor(cons
   if (node) {
     return node;
   }
 
   const nsIFrame* parentAnimatedGeometryRoot = GetParentAnimatedGeometryRoot(aAnimatedGeometryRoot);
   if (!parentAnimatedGeometryRoot) {
     MOZ_ASSERT(!mRoot);
     MOZ_ASSERT(aAnimatedGeometryRoot == Builder()->RootReferenceFrame());
-    nsIntPoint snappedOffset = ContState().GetSnappedOffsetToContainerReferenceFrame(aAnimatedGeometryRoot);
-    mRoot = MakeUnique<PaintedLayerDataNode>(*this, nullptr, aAnimatedGeometryRoot, snappedOffset);
+    mRoot = MakeUnique<PaintedLayerDataNode>(*this, nullptr, aAnimatedGeometryRoot);
     node = mRoot.get();
   } else {
     PaintedLayerDataNode* parentNode = EnsureNodeFor(parentAnimatedGeometryRoot);
     MOZ_ASSERT(parentNode);
     node = parentNode->AddChildNodeFor(aAnimatedGeometryRoot);
   }
   MOZ_ASSERT(node);
   mNodes.Put(aAnimatedGeometryRoot, node);
@@ -3108,22 +3040,22 @@ void ContainerState::FinishPaintedLayerD
   if (!layer) {
     // We couldn't optimize to an image layer or a color layer above.
     layer = data->mLayer;
     layer->SetClipRect(Nothing());
     FLB_LOG_PAINTED_LAYER_DECISION(data, "  Selected painted layer=%p\n", layer.get());
   }
 
   if (mLayerBuilder->IsBuildingRetainedLayers()) {
-    newLayerEntry->mVisibleRegion = data->mVisibleRegion.Get();
+    newLayerEntry->mVisibleRegion = data->mVisibleRegion;
     newLayerEntry->mOpaqueRegion = data->mOpaqueRegion;
     newLayerEntry->mHideAllLayersBelow = data->mHideAllLayersBelow;
     newLayerEntry->mOpaqueForAnimatedGeometryRootParent = data->mOpaqueForAnimatedGeometryRootParent;
   } else {
-    SetOuterVisibleRegionForLayer(layer, data->mVisibleRegion.Get());
+    SetOuterVisibleRegionForLayer(layer, data->mVisibleRegion);
   }
 
   nsIntRect layerBounds = data->mBounds;
   layerBounds.MoveBy(-GetTranslationForPaintedLayer(data->mLayer));
   layer->SetLayerBounds(layerBounds);
 
 #ifdef MOZ_DUMP_PAINTING
   if (!data->mLog.IsEmpty()) {
@@ -3131,17 +3063,17 @@ void ContainerState::FinishPaintedLayerD
       containingPld->mLayer->AddExtraDumpInfo(nsCString(data->mLog));
     } else {
       layer->AddExtraDumpInfo(nsCString(data->mLog));
     }
   }
 #endif
 
   nsIntRegion transparentRegion;
-  transparentRegion.Sub(data->mVisibleRegion.Get(), data->mOpaqueRegion);
+  transparentRegion.Sub(data->mVisibleRegion, data->mOpaqueRegion);
   bool isOpaque = transparentRegion.IsEmpty();
   // For translucent PaintedLayers, try to find an opaque background
   // color that covers the entire area beneath it so we can pull that
   // color into this layer to make it opaque.
   if (layer == data->mLayer) {
     nscolor backgroundColor = NS_RGBA(0,0,0,0);
     if (!isOpaque) {
       backgroundColor = aFindOpaqueBackgroundColor();
@@ -3171,24 +3103,24 @@ void ContainerState::FinishPaintedLayerD
     userData->mForcedBackgroundColor = backgroundColor;
 
     userData->mFontSmoothingBackgroundColor = data->mFontSmoothingBackgroundColor;
 
     // use a mask layer for rounded rect clipping.
     // data->mCommonClipCount may be -1 if we haven't put any actual
     // drawable items in this layer (i.e. it's only catching events).
     int32_t commonClipCount = std::max(0, data->mCommonClipCount);
-    SetupMaskLayer(layer, data->mItemClip, data->mVisibleRegion.Get(), commonClipCount);
+    SetupMaskLayer(layer, data->mItemClip, data->mVisibleRegion, commonClipCount);
     // copy commonClipCount to the entry
     FrameLayerBuilder::PaintedLayerItemsEntry* entry = mLayerBuilder->
       GetPaintedLayerItemsEntry(static_cast<PaintedLayer*>(layer.get()));
     entry->mCommonClipCount = commonClipCount;
   } else {
     // mask layer for image and color layers
-    SetupMaskLayer(layer, data->mItemClip, data->mVisibleRegion.Get());
+    SetupMaskLayer(layer, data->mItemClip, data->mVisibleRegion);
   }
 
   uint32_t flags = 0;
   nsIWidget* widget = mContainerReferenceFrame->PresContext()->GetRootWidget();
   // See bug 941095. Not quite ready to disable this.
   bool hidpi = false && widget && widget->GetDefaultScale().scale >= 2;
   if (hidpi) {
     flags |= Layer::CONTENT_DISABLE_SUBPIXEL_AA;
@@ -3314,33 +3246,33 @@ PaintedLayerData::Accumulate(ContainerSt
   }
 
   bool clipMatches = mItemClip == aClip;
   mItemClip = aClip;
 
   mAssignedDisplayItems.AppendElement(AssignedDisplayItem(aItem, aClip, aLayerState));
 
   if (!mIsSolidColorInVisibleRegion && mOpaqueRegion.Contains(aVisibleRect) &&
-      mVisibleRegion.Get().Contains(aVisibleRect) && !mImage) {
+      mVisibleRegion.Contains(aVisibleRect) && !mImage) {
     // A very common case! Most pages have a PaintedLayer with the page
     // background (opaque) visible and most or all of the page content over the
     // top of that background.
     // The rest of this method won't do anything. mVisibleRegion and mOpaqueRegion
     // don't need updating. mVisibleRegion contains aVisibleRect already,
     // mOpaqueRegion contains aVisibleRect and therefore whatever the opaque
     // region of the item is. mVisibleRegion must contain mOpaqueRegion
     // and therefore aVisibleRect.
     return;
   }
 
   /* Mark as available for conversion to image layer if this is a nsDisplayImage and
    * it's the only thing visible in this layer.
    */
-  if (nsIntRegion(aVisibleRect).Contains(mVisibleRegion.Get()) &&
-      aClippedOpaqueRegion.Contains(mVisibleRegion.Get()) &&
+  if (nsIntRegion(aVisibleRect).Contains(mVisibleRegion) &&
+      aClippedOpaqueRegion.Contains(mVisibleRegion) &&
       aItem->SupportsOptimizingToImage()) {
     mImage = static_cast<nsDisplayImageContainer*>(aItem);
     FLB_LOG_PAINTED_LAYER_DECISION(this, "  Tracking image: nsDisplayImageContainer covers the layer\n");
   } else if (mImage) {
     FLB_LOG_PAINTED_LAYER_DECISION(this, "  No longer tracking image\n");
     mImage = nullptr;
   }
 
@@ -3372,30 +3304,31 @@ PaintedLayerData::Accumulate(ContainerSt
       }
     }
     if (isUniform) {
       if (isFirstVisibleItem) {
         // This color is all we have
         mSolidColor = uniformColor;
         mIsSolidColorInVisibleRegion = true;
       } else if (mIsSolidColorInVisibleRegion &&
-                 mVisibleRegion.Get().IsEqual(nsIntRegion(aVisibleRect)) &&
+                 mVisibleRegion.IsEqual(nsIntRegion(aVisibleRect)) &&
                  clipMatches) {
         // we can just blend the colors together
         mSolidColor = NS_ComposeColors(mSolidColor, uniformColor);
       } else {
         FLB_LOG_PAINTED_LAYER_DECISION(this, "  Layer not a solid color: Can't blend colors togethers\n");
         mIsSolidColorInVisibleRegion = false;
       }
     } else {
       FLB_LOG_PAINTED_LAYER_DECISION(this, "  Layer is not a solid color: Display item is not uniform over the visible bound\n");
       mIsSolidColorInVisibleRegion = false;
     }
 
-    mVisibleRegion.Accumulate(aVisibleRect);
+    mVisibleRegion.Or(mVisibleRegion, aVisibleRect);
+    mVisibleRegion.SimplifyOutward(4);
   }
 
   if (!aClippedOpaqueRegion.IsEmpty()) {
     nsIntRegionRectIterator iter(aClippedOpaqueRegion);
     for (const nsIntRect* r = iter.Next(); r; r = iter.Next()) {
       // We don't use SimplifyInward here since it's not defined exactly
       // what it will discard. For our purposes the most important case
       // is a large opaque background at the bottom of z-order (e.g.,
@@ -3431,17 +3364,19 @@ PaintedLayerData::Accumulate(ContainerSt
 
 PaintedLayerData
 ContainerState::NewPaintedLayerData(nsDisplayItem* aItem,
                                     const nsIntRect& aVisibleRect,
                                     const nsIFrame* aAnimatedGeometryRoot,
                                     const nsPoint& aTopLeft,
                                     bool aShouldFixToViewport)
 {
-  PaintedLayerData data(aAnimatedGeometryRoot, aTopLeft, SnapPointToPixels(aTopLeft));
+  PaintedLayerData data;
+  data.mAnimatedGeometryRoot = aAnimatedGeometryRoot;
+  data.mAnimatedGeometryRootOffset = aTopLeft;
   data.mFixedPosFrameForLayerData =
     FindFixedPosFrameForLayerData(aAnimatedGeometryRoot, aShouldFixToViewport);
   data.mReferenceFrame = aItem->ReferenceFrame();
   data.mSingleItemFixedToViewport = aShouldFixToViewport;
 
   data.mNewChildLayersIndex = mNewChildLayers.Length();
   NewLayerEntry* newLayerEntry = mNewChildLayers.AppendElement();
   newLayerEntry->mAnimatedGeometryRoot = aAnimatedGeometryRoot;
--- a/layout/reftests/bugs/reftest.list
+++ b/layout/reftests/bugs/reftest.list
@@ -420,17 +420,17 @@ skip-if((B2G&&browserIsRemote)||Mulet) =
 == 322436-1.html 322436-1-ref.html
 == 322461-1.xml 322461-1-ref.html
 == 323656-1.html 323656-1-ref.html
 == 323656-2.html 323656-2-ref.html
 == 323656-3.html 323656-3-ref.html
 == 323656-4.html 323656-4-ref.html
 == 323656-5.svg 323656-5-ref.svg
 == 323656-6.html 323656-6-ref.html
-fuzzy-if(Android,5,283) == 325292-1.html 325292-1-ref.html
+fuzzy-if(Android,2,140) == 325292-1.html 325292-1-ref.html
 == 325486-1.html 325486-1-ref.html
 == 328111-1.html 328111-1-ref.html
 random == 328829-1.xhtml 328829-1-ref.xhtml # bug 369046 (intermittent)
 == 328829-2.xhtml 328829-2-ref.xhtml
 == 329359-1.html 329359-1-ref.html
 == 331809-1.html 331809-1-ref.html # bug 580499 is blacked out
 == 332360.html 332360-ref.html
 == 332360-ltr.html 332360-ltr-ref.html
@@ -690,17 +690,17 @@ skip-if(B2G||Mulet) == 378937-1.html 378
 == 379316-1.html 379316-1-ref.html
 skip-if(B2G||Mulet) fails-if(Android) random-if(cocoaWidget) random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) fuzzy-if(/^Windows\x20NT\x206\.2/.test(http.oscpu),1,170) fuzzy-if(gtkWidget,1,191) == 379316-2.html 379316-2-ref.html # bug 379786 # Initial mulet triage: parity with B2G/B2G Desktop
 == 379328-1.html 379328-1-ref.html
 == 379349-1a.xhtml 379349-1-ref.xhtml
 == 379349-1b.xhtml 379349-1-ref.xhtml
 == 379349-1c.xhtml 379349-1-ref.xhtml
 == 379349-2a.xhtml 379349-2-ref.xhtml
 == 379349-2b.xhtml 379349-2-ref.xhtml
-skip-if(B2G||Mulet) fuzzy-if(Android,5,283) == 379349-3a.xhtml 379349-3-ref.xhtml # Initial mulet triage: parity with B2G/B2G Desktop
+skip-if(B2G||Mulet) fuzzy-if(Android,2,140) == 379349-3a.xhtml 379349-3-ref.xhtml # Initial mulet triage: parity with B2G/B2G Desktop
 skip-if(B2G||Mulet) fuzzy-if(Android,2,140) == 379349-3b.xhtml 379349-3-ref.xhtml # Initial mulet triage: parity with B2G/B2G Desktop
 == 379361-1.html 379361-1-ref.html
 == 379361-2.html 379361-2-ref.html
 == 379361-3.html 379361-3-ref.html
 == 379461-1.xhtml 379461-1.html
 == 379461-2.xhtml 379461-2.html
 skip-if(B2G||Mulet) == 379461-3-container-xhtml.html 379461-3-container-html.html # Initial mulet triage: parity with B2G/B2G Desktop
 skip-if(B2G||Mulet) fails-if(Android) != 379461-3-container-xhtml.html 379461-3-container-blank.html # there is a scrollbar # Initial mulet triage: parity with B2G/B2G Desktop
@@ -1399,30 +1399,30 @@ skip-if(B2G||Mulet) == 502447-1.html 502
 == 502942-1.html 502942-1-ref.html
 == 503364-1a.html 503364-1-ref.html
 == 503364-1b.html 503364-1-ref.html
 # Reftest for bug 503531 marked as failing; should be re-enabled when
 # bug 607548 gets resolved.
 needs-focus fails == 503531-1.html 503531-1-ref.html
 == 504032-1.html 504032-1-ref.html
 == 505743-1.html about:blank
-skip-if(B2G||Mulet) fuzzy-if(Android,5,2806) == 506481-1.html 506481-1-ref.html # Initial mulet triage: parity with B2G/B2G Desktop
+skip-if(B2G||Mulet) fuzzy-if(Android,5,2800) == 506481-1.html 506481-1-ref.html # Initial mulet triage: parity with B2G/B2G Desktop
 == 507187-1.html 507187-1-ref.html
 == 507487-1.html 507487-1-ref.html
 == 507487-2.xhtml 507487-2-ref.xhtml
 == 507762-1.html 507762-1-ref.html
 == 507762-2.html 507762-2-ref.html
 == 507762-3.html 507762-1-ref.html
 == 507762-4.html 507762-2-ref.html
 skip-if(B2G||Mulet) random-if(cocoaWidget) == 508816-1.xul 508816-1-ref.xul # Bug 631982 # Initial mulet triage: parity with B2G/B2G Desktop
 skip-if(B2G||Mulet) == 508816-2.html 508816-2-ref.html # Initial mulet triage: parity with B2G/B2G Desktop
 skip-if((B2G&&browserIsRemote)||Mulet) == 508908-1.xul 508908-1-ref.xul # bug 974780 # Initial mulet triage: parity with B2G/B2G Desktop
 == 508919-1.xhtml 508919-1-ref.xhtml
 == 509155-1.xhtml 509155-1-ref.xhtml
-skip-if(B2G||Mulet) fuzzy-if(Android,5,2555) == 512410.html 512410-ref.html # Initial mulet triage: parity with B2G/B2G Desktop
+skip-if(B2G||Mulet) fuzzy-if(Android,5,1656) == 512410.html 512410-ref.html # Initial mulet triage: parity with B2G/B2G Desktop
 == 512631-1.html 512631-1-ref.html
 == 513153-1a.html 513153-1-ref.html
 == 513153-1b.html 513153-1-ref.html
 == 513153-2a.html 513153-2-ref.html
 == 513153-2b.html 513153-2-ref.html
 skip-if((B2G&&browserIsRemote)||Mulet) == 513318-1.xul 513318-1-ref.xul # bug 974780 # Initial mulet triage: parity with B2G/B2G Desktop
 skip-if(B2G||Mulet) fails-if(Android) != 513318-2.xul 513318-2-ref.xul # Initial mulet triage: parity with B2G/B2G Desktop
 == 514917-1.html 514917-1-ref.html
@@ -1653,19 +1653,19 @@ fuzzy-if(Android&&AndroidVersion>=15,8,3
 == 630835-1.html about:blank
 == 631352-1.html 631352-1-ref.html
 skip-if(!haveTestPlugin) skip-if(B2G||Mulet) fails-if(Android) fuzzy-if(winWidget&&!layersGPUAccelerated,102,535)  == 632423-1.html 632423-1-ref.html # Initial mulet triage: parity with B2G/B2G Desktop
 skip-if(Android||B2G||Mulet) random-if(winWidget) == 632781-verybig.html 632781-ref.html # Initial mulet triage: parity with B2G/B2G Desktop
 == 632781-normalsize.html 632781-ref.html
 fuzzy-if(d2d&&/^Windows\x20NT\x206\.2/.test(http.oscpu),1,559) == 633344-1.html 633344-1-ref.html # bug 1103623
 == 634232-1.html 634232-1-ref.html
 fails-if(Android&&AndroidVersion<17&&AndroidVersion!=10) == 635302-1.html 635302-1-ref.html
-fuzzy(1,68) skip-if(B2G||Mulet) == 635373-1.html 635373-1-ref.html # Initial mulet triage: parity with B2G/B2G Desktop
-skip-if(B2G||Mulet) random-if(d2d) fuzzy-if(winWidget&&!d2d,1,61) == 635373-2.html 635373-2-ref.html # Initial mulet triage: parity with B2G/B2G Desktop
-skip-if(B2G||Mulet) random-if(d2d) fuzzy-if(winWidget&&!d2d,1,60) == 635373-3.html 635373-3-ref.html # Initial mulet triage: parity with B2G/B2G Desktop
+fuzzy(1,68) skip-if(B2G||Mulet) fails-if(Android) == 635373-1.html 635373-1-ref.html # Initial mulet triage: parity with B2G/B2G Desktop
+skip-if(B2G||Mulet) random-if(d2d) fails-if(Android) fuzzy-if(winWidget&&!d2d,1,61) == 635373-2.html 635373-2-ref.html # Initial mulet triage: parity with B2G/B2G Desktop
+skip-if(B2G||Mulet) random-if(d2d) fails-if(Android) fuzzy-if(winWidget&&!d2d,1,60) == 635373-3.html 635373-3-ref.html # Initial mulet triage: parity with B2G/B2G Desktop
 HTTP(..) == 635639-1.html 635639-1-ref.html
 HTTP(..) == 635639-2.html 635639-2-ref.html
 random == 637597-1.html 637597-1-ref.html # bug 637597 was never really fixed!
 fuzzy-if(Android&&AndroidVersion>=15,8,500) == 637852-1.html 637852-1-ref.html
 fuzzy-if(Android&&AndroidVersion>=15,8,500) == 637852-2.html 637852-2-ref.html
 fuzzy-if(Android&&AndroidVersion>=15,8,500) == 637852-3.html 637852-3-ref.html
 skip-if(B2G||Mulet) == 641770-1.html 641770-1-ref.html # Initial mulet triage: parity with B2G/B2G Desktop
 == 641856-1.html 641856-1-ref.html
--- a/layout/reftests/text-overflow/reftest.list
+++ b/layout/reftests/text-overflow/reftest.list
@@ -1,15 +1,15 @@
 skip-if(B2G||Mulet) == ellipsis-font-fallback.html ellipsis-font-fallback-ref.html # Initial mulet triage: parity with B2G/B2G Desktop
 == line-clipping.html line-clipping-ref.html
 fuzzy-if(Android,16,244) skip-if(B2G||Mulet) HTTP(..) == marker-basic.html marker-basic-ref.html  # Bug 1128229 # Initial mulet triage: parity with B2G/B2G Desktop
 skip-if(B2G||Mulet) HTTP(..) == marker-string.html marker-string-ref.html # Initial mulet triage: parity with B2G/B2G Desktop
 skip-if(Android||B2G) HTTP(..) == bidi-simple.html bidi-simple-ref.html # Fails on Android due to anti-aliasing
 skip-if(!gtkWidget) fuzzy-if(gtkWidget,1,104) HTTP(..) == bidi-simple-scrolled.html bidi-simple-scrolled-ref.html # Fails on Windows and OSX due to anti-aliasing
-skip-if(B2G||Mulet) fuzzy-if(Android&&AndroidVersion<15,9,2545) fuzzy-if(Android&&AndroidVersion>=15,24,4000) fuzzy-if(cocoaWidget,1,40) fuzzy-if(!layersGPUAccelerated,102,2070) HTTP(..) == scroll-rounding.html scroll-rounding-ref.html # bug 760264 # Initial mulet triage: parity with B2G/B2G Desktop
+skip-if(B2G||Mulet) fuzzy-if(Android&&AndroidVersion<15,9,2545) fuzzy-if(Android&&AndroidVersion>=15,24,4000) fuzzy-if(cocoaWidget,1,40) fuzzy-if(asyncPanZoom&&!layersGPUAccelerated,102,1770) HTTP(..) == scroll-rounding.html scroll-rounding-ref.html # bug 760264 # Initial mulet triage: parity with B2G/B2G Desktop
 fuzzy-if(OSX==1008,1,1) HTTP(..) == anonymous-block.html anonymous-block-ref.html
 skip-if(B2G||Mulet) HTTP(..) == false-marker-overlap.html false-marker-overlap-ref.html # Initial mulet triage: parity with B2G/B2G Desktop
 HTTP(..) == visibility-hidden.html visibility-hidden-ref.html
 skip-if(B2G||Mulet) fuzzy-if(asyncPanZoom&&!layersGPUAccelerated,102,1724) HTTP(..) == block-padding.html block-padding-ref.html # Initial mulet triage: parity with B2G/B2G Desktop
 HTTP(..) == quirks-decorations.html quirks-decorations-ref.html
 HTTP(..) == quirks-line-height.html quirks-line-height-ref.html
 HTTP(..) == standards-decorations.html standards-decorations-ref.html
 HTTP(..) == standards-line-height.html standards-line-height-ref.html
--- a/layout/reftests/transform-3d/reftest.list
+++ b/layout/reftests/transform-3d/reftest.list
@@ -6,17 +6,17 @@
 # Check that the perspectve() transform function results in some visual changes
 != rotatex-perspective-1a.html rotatex-1-ref.html
 # Check that -moz-perspective results in visual changes to child transformed elements
 != rotatex-perspective-1b.html rotatex-1-ref.html
 # -moz-perspective should only apply to child elements
 == rotatex-perspective-1c.html rotatex-1-ref.html
 == rotatex-perspective-3a.html rotatex-perspective-3-ref.html
 == scalez-1a.html scalez-1-ref.html
-fuzzy-if(cocoaWidget,17,3) fuzzy-if(!layersGPUAccelerated,102,243) == preserve3d-1a.html preserve3d-1-ref.html
+fuzzy-if(cocoaWidget,17,3) == preserve3d-1a.html preserve3d-1-ref.html
 == preserve3d-1b.html about:blank
 == preserve3d-clipped.html about:blank
 == preserve3d-2a.html preserve3d-2-ref.html
 == preserve3d-2b.html preserve3d-2-ref.html
 == preserve3d-2c.html preserve3d-2-ref.html
 == preserve3d-2d.html preserve3d-2-ref.html
 == preserve3d-3a.html preserve3d-3-ref.html
 skip-if(B2G||Mulet) == preserve3d-4a.html green-rect.html # Initial mulet triage: parity with B2G/B2G Desktop
--- a/layout/reftests/w3c-css/submitted/flexbox/reftest.list
+++ b/layout/reftests/w3c-css/submitted/flexbox/reftest.list
@@ -63,17 +63,17 @@ fuzzy-if(Android,158,32) == flexbox-alig
 == flexbox-basic-fieldset-horiz-001.xhtml flexbox-basic-fieldset-horiz-001-ref.xhtml
 == flexbox-basic-fieldset-vert-001.xhtml  flexbox-basic-fieldset-vert-001-ref.xhtml
 == flexbox-basic-iframe-horiz-001.xhtml   flexbox-basic-iframe-horiz-001-ref.xhtml
 == flexbox-basic-iframe-vert-001.xhtml    flexbox-basic-iframe-vert-001-ref.xhtml
 == flexbox-basic-img-horiz-001.xhtml      flexbox-basic-img-horiz-001-ref.xhtml
 == flexbox-basic-img-vert-001.xhtml       flexbox-basic-img-vert-001-ref.xhtml
 == flexbox-basic-textarea-horiz-001.xhtml flexbox-basic-textarea-horiz-001-ref.xhtml
 == flexbox-basic-textarea-vert-001.xhtml  flexbox-basic-textarea-vert-001-ref.xhtml
-fuzzy-if(cocoaWidget,1,300) == flexbox-basic-video-horiz-001.xhtml    flexbox-basic-video-horiz-001-ref.xhtml
+== flexbox-basic-video-horiz-001.xhtml    flexbox-basic-video-horiz-001-ref.xhtml
 == flexbox-basic-video-vert-001.xhtml     flexbox-basic-video-vert-001-ref.xhtml
 
 # Tests for "page-break-before" / "page-break-after" on a flex item
 == flexbox-break-request-horiz-001a.html flexbox-break-request-horiz-001-ref.html
 == flexbox-break-request-horiz-001b.html flexbox-break-request-horiz-001-ref.html
 == flexbox-break-request-horiz-002a.html flexbox-break-request-horiz-002-ref.html
 == flexbox-break-request-horiz-002b.html flexbox-break-request-horiz-002-ref.html
 == flexbox-break-request-vert-001a.html  flexbox-break-request-vert-001-ref.html
--- a/toolkit/devtools/server/actors/webconsole.js
+++ b/toolkit/devtools/server/actors/webconsole.js
@@ -806,28 +806,24 @@ WebConsoleActor.prototype =
     let evalInfo = this.evalWithDebugger(input, evalOptions);
     let evalResult = evalInfo.result;
     let helperResult = evalInfo.helperResult;
 
     let result, errorMessage, errorGrip = null;
     if (evalResult) {
       if ("return" in evalResult) {
         result = evalResult.return;
-      }
-      else if ("yield" in evalResult) {
+      } else if ("yield" in evalResult) {
         result = evalResult.yield;
-      }
-      else if ("throw" in evalResult) {
+      } else if ("throw" in evalResult) {
         let error = evalResult.throw;
         errorGrip = this.createValueGrip(error);
-        let errorToString = evalInfo.window
-                            .evalInGlobalWithBindings("ex + ''", {ex: error});
-        if (errorToString && typeof errorToString.return == "string") {
-          errorMessage = errorToString.return;
-        }
+        errorMessage = error && (typeof error === "object")
+          ? error.unsafeDereference().toString()
+          : "" + error;
       }
     }
 
     // If a value is encountered that the debugger server doesn't support yet,
     // the console should remain functional.
     let resultGrip;
     try {
       resultGrip = this.createValueGrip(result);
--- a/toolkit/devtools/webconsole/test/test_jsterm_queryselector.html
+++ b/toolkit/devtools/webconsole/test/test_jsterm_queryselector.html
@@ -18,17 +18,21 @@ let gState;
 function evaluateJS(input) {
   return new Promise((resolve) => gState.client.evaluateJS(input, resolve));
 }
 
 function startTest() {
   removeEventListener("load", startTest);
   attachConsole([], state => {
     gState = state;
-    let tests = [checkQuerySelectorAll, checkQuerySelectorAllNotExist];
+    let tests = [
+      checkQuerySelectorAll,
+      checkQuerySelectorAllNotExist,
+      checkQuerySelectorAllException
+    ];
     runTests(tests, testEnd);
   }, true);
 }
 
 let checkQuerySelectorAll = Task.async(function*() {
   info ("$$ returns an array");
   let response = yield evaluateJS("$$('body')");
   basicResultCheck(response, "$$('body')", {
@@ -49,16 +53,33 @@ let checkQuerySelectorAllNotExist = Task
     class: "Array",
     preview: {
       length: 0
     }
   });
   nextTest();
 });
 
+let checkQuerySelectorAllException = Task.async(function*() {
+  info ("$$ returns an exception if an invalid selector was provided");
+  let response = yield evaluateJS("$$(':foo')");
+  checkObject(response, {
+    input: "$$(':foo')",
+    exceptionMessage: "SyntaxError: An invalid or illegal string was specified",
+    exception: {
+      preview: {
+        kind: "DOMException",
+        name: "SyntaxError",
+        message: "An invalid or illegal string was specified"
+      }
+    }
+  });
+  nextTest();
+});
+
 function basicResultCheck(response, input, output) {
   checkObject(response, {
     from: gState.actor,
     input: input,
     result: output,
   });
   ok(!response.exception, "no eval exception");
   ok(!response.helperResult, "no helper result");
--- a/toolkit/themes/shared/aboutSupport.css
+++ b/toolkit/themes/shared/aboutSupport.css
@@ -29,22 +29,22 @@ button {
 }
 
 table {
   background-color: var(--aboutSupport-table-background);
   color: var(--in-content-text-color);
   font: message-box;
   text-align: start;
   width: 100%;
-  border: 1px solid var(--in-content-table-border-color);
+  border: 1px solid var(--in-content-border-color);
   border-spacing: 0px;
 }
 
 th, td {
-  border: 1px solid var(--in-content-table-border-color);
+  border: 1px solid var(--in-content-border-color);
   padding: 4px;
 }
 
 thead th {
   text-align: center;
 }
 
 th {
@@ -77,17 +77,17 @@ td {
 .pref-value {
   width: 30%;
   white-space: nowrap;
   overflow: hidden;
 }
 
 #action-box {
   background-color: var(--aboutSupport-table-background);
-  border: 1px solid var(--in-content-table-border-color);
+  border: 1px solid var(--in-content-border-color);
   color: var(--in-content-text-color);
   float: right;
   margin-top: 2em;
   margin-bottom: 20px;
   -moz-margin-start: 20px;
   -moz-margin-end: 0;
   padding: 16px;
   width: 30%;