Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Bug 1207221 - Do not prevent the system app from vibrating when it is…
Browse files Browse the repository at this point in the history
… hidden. r=bz r=dhylands
  • Loading branch information
gabrielesvelto committed Nov 17, 2015
1 parent 6f05771 commit d758582
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
20 changes: 14 additions & 6 deletions dom/base/Navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,13 +774,25 @@ 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
Expand Down Expand Up @@ -853,12 +865,8 @@ Navigator::Vibrate(const nsTArray<uint32_t>& aPattern)
}

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;
}

Expand Down
6 changes: 6 additions & 0 deletions hal/Hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ AssertMainProcess()
MOZ_ASSERT(GeckoProcessType_Default == XRE_GetProcessType());
}

#if !defined(MOZ_WIDGET_GONK)

bool
WindowIsActive(nsIDOMWindow* aWindow)
{
Expand All @@ -103,6 +105,8 @@ WindowIsActive(nsIDOMWindow* aWindow)
return !document->Hidden();
}

#endif // !defined(MOZ_WIDGET_GONK)

StaticAutoPtr<WindowIdentifier::IDArrayType> gLastIDToVibrate;

void InitLastIDToVibrate()
Expand All @@ -124,6 +128,7 @@ 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
Expand All @@ -134,6 +139,7 @@ Vibrate(const nsTArray<uint32_t>& pattern, const WindowIdentifier &id)
HAL_LOG("Vibrate: Window is inactive, dropping vibrate.");
return;
}
#endif // !defined(MOZ_WIDGET_GONK)

if (!InSandbox()) {
if (!gLastIDToVibrate) {
Expand Down

0 comments on commit d758582

Please sign in to comment.