Bug 1207221 - Do not prevent the system app from vibrating when it is hidden. r=bz r=dhylands
authorGabriele Svelto <gsvelto@mozilla.com>
Tue, 17 Nov 2015 10:18:38 +0100
changeset 308145 5106b290f12aee0277425a66135eac73c059b81a
parent 308144 b5dca1e99e6676d3117cc297a89f26d3fceeb4ae
child 308146 b58eb56c2a07ff1054d8f52ac3a66573842dcf5b
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, dhylands
bugs1207221
milestone45.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 1207221 - Do not prevent the system app from vibrating when it is hidden. r=bz r=dhylands
dom/base/Navigator.cpp
hal/Hal.cpp
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -769,23 +769,35 @@ private:
   nsWeakPtr mWindow;
   nsWeakPtr mDocument;
 };
 
 NS_IMPL_ISUPPORTS(VibrateWindowListener, nsIDOMEventListener)
 
 StaticRefPtr<VibrateWindowListener> gVibrateWindowListener;
 
+static bool
+MayVibrate(nsIDocument* doc) {
+#if MOZ_WIDGET_GONK
+  if (XRE_IsParentProcess()) {
+    return true; // The system app can always vibrate
+  }
+#endif // MOZ_WIDGET_GONK
+
+  // Hidden documents cannot start or stop a vibration.
+  return (doc && !doc->Hidden());
+}
+
 NS_IMETHODIMP
 VibrateWindowListener::HandleEvent(nsIDOMEvent* aEvent)
 {
   nsCOMPtr<nsIDocument> doc =
     do_QueryInterface(aEvent->InternalDOMEvent()->GetTarget());
 
-  if (!doc || doc->Hidden()) {
+  if (!MayVibrate(doc)) {
     // It's important that we call CancelVibrate(), not Vibrate() with an
     // empty list, because Vibrate() will fail if we're no longer focused, but
     // CancelVibrate() will succeed, so long as nobody else has started a new
     // vibration pattern.
     nsCOMPtr<nsIDOMWindow> window = do_QueryReferent(mWindow);
     hal::CancelVibrate(window);
     RemoveListener();
     gVibrateWindowListener = nullptr;
@@ -848,22 +860,18 @@ Navigator::Vibrate(uint32_t aDuration)
 bool
 Navigator::Vibrate(const nsTArray<uint32_t>& aPattern)
 {
   if (!mWindow) {
     return false;
   }
 
   nsCOMPtr<nsIDocument> doc = mWindow->GetExtantDoc();
-  if (!doc) {
-    return false;
-  }
-
-  if (doc->Hidden()) {
-    // Hidden documents cannot start or stop a vibration.
+
+  if (!MayVibrate(doc)) {
     return false;
   }
 
   nsTArray<uint32_t> pattern(aPattern);
 
   if (pattern.Length() > sMaxVibrateListLen) {
     pattern.SetLength(sMaxVibrateListLen);
   }
--- a/hal/Hal.cpp
+++ b/hal/Hal.cpp
@@ -86,28 +86,32 @@ InSandbox()
 }
 
 void
 AssertMainProcess()
 {
   MOZ_ASSERT(GeckoProcessType_Default == XRE_GetProcessType());
 }
 
+#if !defined(MOZ_WIDGET_GONK)
+
 bool
 WindowIsActive(nsIDOMWindow* aWindow)
 {
   nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aWindow);
   NS_ENSURE_TRUE(window, false);
 
   nsIDocument* document = window->GetDoc();
   NS_ENSURE_TRUE(document, false);
 
   return !document->Hidden();
 }
 
+#endif // !defined(MOZ_WIDGET_GONK)
+
 StaticAutoPtr<WindowIdentifier::IDArrayType> gLastIDToVibrate;
 
 void InitLastIDToVibrate()
 {
   gLastIDToVibrate = new WindowIdentifier::IDArrayType();
   ClearOnShutdown(&gLastIDToVibrate);
 }
 
@@ -119,26 +123,28 @@ Vibrate(const nsTArray<uint32_t>& patter
   Vibrate(pattern, WindowIdentifier(window));
 }
 
 void
 Vibrate(const nsTArray<uint32_t>& pattern, const WindowIdentifier &id)
 {
   AssertMainThread();
 
+#if !defined(MOZ_WIDGET_GONK)
   // Only active windows may start vibrations.  If |id| hasn't gone
   // through the IPC layer -- that is, if our caller is the outside
   // world, not hal_proxy -- check whether the window is active.  If
   // |id| has gone through IPC, don't check the window's visibility;
   // only the window corresponding to the bottommost process has its
   // visibility state set correctly.
   if (!id.HasTraveledThroughIPC() && !WindowIsActive(id.GetWindow())) {
     HAL_LOG("Vibrate: Window is inactive, dropping vibrate.");
     return;
   }
+#endif // !defined(MOZ_WIDGET_GONK)
 
   if (!InSandbox()) {
     if (!gLastIDToVibrate) {
       InitLastIDToVibrate();
     }
     *gLastIDToVibrate = id.AsArray();
   }