From e8a849ef0c08414626c1e26131216ee618df45e8 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 13 Jun 2018 17:52:19 -0400 Subject: [PATCH] Bug 1468612 - Annotate crash reports with HasDeviceTouchScreen=0/1; r=baku --- dom/events/TouchEvent.cpp | 57 ++++++++++++++++++++++++++------------- dom/events/TouchEvent.h | 1 + 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/dom/events/TouchEvent.cpp b/dom/events/TouchEvent.cpp index 2db173469d32..493214c26d25 100644 --- a/dom/events/TouchEvent.cpp +++ b/dom/events/TouchEvent.cpp @@ -220,6 +220,32 @@ TouchEvent::PrefEnabled(JSContext* aCx, JSObject* aGlobal) return PrefEnabled(docShell); } +// static +bool +TouchEvent::PlatformSupportsTouch() +{ +#if defined(MOZ_WIDGET_ANDROID) + // Touch support is always enabled on android. + return true; +#elif defined(XP_WIN) || defined(MOZ_WIDGET_GTK) + static bool sDidCheckTouchDeviceSupport = false; + static bool sIsTouchDeviceSupportPresent = false; + // On Windows and GTK3 we auto-detect based on device support. + if (!sDidCheckTouchDeviceSupport) { + sDidCheckTouchDeviceSupport = true; + sIsTouchDeviceSupportPresent = WidgetUtils::IsTouchDeviceSupportPresent(); + // But touch events are only actually supported if APZ is enabled. If + // APZ is disabled globally, we can check that once and incorporate that + // into the cached state. If APZ is enabled, we need to further check + // based on the widget, which we do below (and don't cache that result). + sIsTouchDeviceSupportPresent &= gfxPlatform::AsyncPanZoomEnabled(); + } + return sIsTouchDeviceSupportPresent; +#else + return false; +#endif +} + // static bool TouchEvent::PrefEnabled(nsIDocShell* aDocShell) @@ -244,23 +270,20 @@ TouchEvent::PrefEnabled(nsIDocShell* aDocShell) enabled = false; } else { if (sPrefCacheValue == 2) { -#if defined(MOZ_WIDGET_ANDROID) - // Touch support is always enabled on B2G and android. - enabled = true; -#elif defined(XP_WIN) || defined(MOZ_WIDGET_GTK) - static bool sDidCheckTouchDeviceSupport = false; - static bool sIsTouchDeviceSupportPresent = false; - // On Windows and GTK3 we auto-detect based on device support. - if (!sDidCheckTouchDeviceSupport) { - sDidCheckTouchDeviceSupport = true; - sIsTouchDeviceSupportPresent = WidgetUtils::IsTouchDeviceSupportPresent(); - // But touch events are only actually supported if APZ is enabled. If - // APZ is disabled globally, we can check that once and incorporate that - // into the cached state. If APZ is enabled, we need to further check - // based on the widget, which we do below (and don't cache that result). - sIsTouchDeviceSupportPresent &= gfxPlatform::AsyncPanZoomEnabled(); + enabled = PlatformSupportsTouch(); + + static bool firstTime = true; + // The touch screen data seems to be inaccurate in the parent process, + // and we really need the crash annotation in child processes. + if (firstTime && !XRE_IsParentProcess()) { + CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("HasDeviceTouchScreen"), + enabled ? + NS_LITERAL_CSTRING("1") : + NS_LITERAL_CSTRING("0")); + firstTime = false; } - enabled = sIsTouchDeviceSupportPresent; + +#if defined(XP_WIN) || defined(MOZ_WIDGET_GTK) if (enabled && aDocShell) { // APZ might be disabled on this particular widget, in which case // TouchEvent support will also be disabled. Try to detect that. @@ -270,8 +293,6 @@ TouchEvent::PrefEnabled(nsIDocShell* aDocShell) enabled &= pc->GetRootWidget()->AsyncPanZoomEnabled(); } } -#else - enabled = false; #endif } else { enabled = !!sPrefCacheValue; diff --git a/dom/events/TouchEvent.h b/dom/events/TouchEvent.h index 040df3158a55..11c6d3079b51 100644 --- a/dom/events/TouchEvent.h +++ b/dom/events/TouchEvent.h @@ -128,6 +128,7 @@ public: TouchList* aTargetTouches, TouchList* aChangedTouches); + static bool PlatformSupportsTouch(); static bool PrefEnabled(JSContext* aCx, JSObject* aGlobal); static bool PrefEnabled(nsIDocShell* aDocShell);