Bug 1243431 - [4.1] Show permission request doorhanger on vibration request. r=margaret
authorEugen Sawin <esawin@mozilla.com>
Thu, 28 Apr 2016 13:11:18 +0200
changeset 296612 379cf1150c6760bee6d3e83f7c0be16c11198e66
parent 296611 0370882039d710629d6b816d396fd64634bd8dee
child 296613 8a9f596c062d1df7b76e1cbc41363ee48f719c7f
push id76405
push useresawin@mozilla.com
push dateMon, 09 May 2016 12:38:54 +0000
treeherdermozilla-inbound@1efb537d42a6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs1243431
milestone49.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
Bug 1243431 - [4.1] Show permission request doorhanger on vibration request. r=margaret
mobile/android/base/java/org/mozilla/gecko/DoorHangerPopup.java
mobile/android/base/java/org/mozilla/gecko/widget/DoorHanger.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/java/org/mozilla/gecko/DoorHangerPopup.java
+++ b/mobile/android/base/java/org/mozilla/gecko/DoorHangerPopup.java
@@ -117,16 +117,18 @@ public class DoorHangerPopup extends Anc
         if (DoorHanger.Type.LOGIN.toString().equals(typeString)) {
             doorhangerType = DoorHanger.Type.LOGIN;
         } else if (DoorHanger.Type.GEOLOCATION.toString().equals(typeString)) {
             doorhangerType = DoorHanger.Type.GEOLOCATION;
         } else if (DoorHanger.Type.DESKTOPNOTIFICATION2.toString().equals(typeString)) {
             doorhangerType = DoorHanger.Type.DESKTOPNOTIFICATION2;
         } else if (DoorHanger.Type.WEBRTC.toString().equals(typeString)) {
             doorhangerType = DoorHanger.Type.WEBRTC;
+        } else if (DoorHanger.Type.VIBRATION.toString().equals(typeString)) {
+            doorhangerType = DoorHanger.Type.VIBRATION;
         }
 
         final DoorhangerConfig config = new DoorhangerConfig(tabId, id, doorhangerType, this);
 
         config.setMessage(json.getString("message"));
         config.setOptions(json.getJSONObject("options"));
 
         final JSONArray buttonArray = json.getJSONArray("buttons");
--- a/mobile/android/base/java/org/mozilla/gecko/widget/DoorHanger.java
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/DoorHanger.java
@@ -34,17 +34,17 @@ public abstract class DoorHanger extends
                 return new LoginDoorHanger(context, config);
             case TRACKING:
                 return new ContentSecurityDoorHanger(context, config, type);
         }
         return new DefaultDoorHanger(context, config, type);
     }
 
     // Doorhanger types created from Gecko are checked against enum strings to determine type.
-    public static enum Type { DEFAULT, LOGIN, TRACKING, GEOLOCATION, DESKTOPNOTIFICATION2, WEBRTC }
+    public static enum Type { DEFAULT, LOGIN, TRACKING, GEOLOCATION, DESKTOPNOTIFICATION2, WEBRTC, VIBRATION }
 
     public interface OnButtonClickListener {
         public void onButtonClick(JSONObject response, DoorHanger doorhanger);
     }
 
     private static final String LOGTAG = "GeckoDoorHanger";
 
     // Divider between doorhangers.
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -379,16 +379,17 @@ var BrowserApp = {
     Services.obs.addObserver(this, "Passwords:Init", false);
     Services.obs.addObserver(this, "FormHistory:Init", false);
     Services.obs.addObserver(this, "android-get-pref", false);
     Services.obs.addObserver(this, "android-set-pref", false);
     Services.obs.addObserver(this, "gather-telemetry", false);
     Services.obs.addObserver(this, "keyword-search", false);
     Services.obs.addObserver(this, "sessionstore-state-purge-complete", false);
     Services.obs.addObserver(this, "Fonts:Reload", false);
+    Services.obs.addObserver(this, "Vibration:Request", false);
 
     Messaging.addListener(this.getHistory.bind(this), "Session:GetHistory");
 
     function showFullScreenWarning() {
       Snackbars.show(Strings.browser.GetStringFromName("alertFullScreenToast"), Snackbars.LENGTH_LONG);
     }
 
     window.addEventListener("fullscreen", function() {
@@ -1945,16 +1946,43 @@ var BrowserApp = {
 
         this.computeAcceptLanguages(osLocale, aData);
         break;
 
       case "Fonts:Reload":
         FontEnumerator.updateFontList();
         break;
 
+      case "Vibration:Request":
+        if (aSubject instanceof Navigator) {
+          let navigator = aSubject;
+          let buttons = [
+            {
+              label: Strings.browser.GetStringFromName("vibrationRequest.denyButton"),
+              callback: function() {
+                navigator.setVibrationPermission(false);
+              }
+            },
+            {
+              label: Strings.browser.GetStringFromName("vibrationRequest.allowButton"),
+              callback: function() {
+                navigator.setVibrationPermission(true);
+              },
+              positive: true
+            }
+          ];
+          let message = Strings.browser.GetStringFromName("vibrationRequest.message");
+          let options = {};
+          // Workaround for bug 1268471.
+          NativeWindow.doorhanger.hide("vibration-request", BrowserApp.selectedTab.id);
+          NativeWindow.doorhanger.show(message, "vibration-request", buttons,
+              BrowserApp.selectedTab.id, options, "VIBRATION");
+        }
+        break;
+
       default:
         dump('BrowserApp.observe: unexpected topic "' + aTopic + '"\n');
         break;
 
     }
   },
 
   /**