Permalink
Browse files

Fixing bug 715041. Add support for Idle API. r=bent, jst

  • Loading branch information...
1 parent e4d20a8 commit 7a26a02ee7157928a847abb522ba5e322a4ae0d1 Bonnie Surender committed Jun 29, 2012
Showing with 2,537 additions and 84 deletions.
  1. +19 −0 content/base/public/nsContentUtils.h
  2. +20 −0 content/base/src/nsContentUtils.cpp
  3. +38 −0 dom/base/Navigator.cpp
  4. +495 −5 dom/base/nsGlobalWindow.cpp
  5. +85 −3 dom/base/nsGlobalWindow.h
  6. +6 −3 dom/base/nsPIDOMWindow.h
  7. +8 −0 dom/base/test/Makefile.in
  8. +760 −0 dom/base/test/test_bug715041.xul
  9. +845 −0 dom/base/test/test_bug715041_removal.xul
  10. +1 −0 dom/interfaces/base/Makefile.in
  11. +13 −1 dom/interfaces/base/nsIDOMNavigator.idl
  12. +16 −0 dom/interfaces/base/nsIIdleObserver.idl
  13. +3 −0 modules/libpref/src/init/all.js
  14. +1 −0 widget/Makefile.in
  15. +1 −1 widget/android/nsIdleServiceAndroid.cpp
  16. +16 −1 widget/android/nsIdleServiceAndroid.h
  17. +1 −1 widget/android/nsWidgetFactory.cpp
  18. +1 −1 widget/android/nsWindow.cpp
  19. +2 −3 widget/android/nsWindow.h
  20. +15 −4 widget/cocoa/nsIdleServiceX.h
  21. +1 −1 widget/cocoa/nsWidgetFactory.mm
  22. +1 −1 widget/gonk/nsIdleServiceGonk.cpp
  23. +16 −1 widget/gonk/nsIdleServiceGonk.h
  24. +1 −1 widget/gonk/nsWidgetFactory.cpp
  25. +1 −1 widget/gonk/nsWindow.cpp
  26. +2 −3 widget/gonk/nsWindow.h
  27. +1 −1 widget/gtk2/nsIdleServiceGTK.cpp
  28. +14 −2 widget/gtk2/nsIdleServiceGTK.h
  29. +1 −1 widget/gtk2/nsWidgetFactory.cpp
  30. +3 −3 widget/gtk2/nsWindow.cpp
  31. +4 −0 widget/nsGUIEvent.h
  32. +10 −0 widget/nsIIdleService.idl
  33. +18 −0 widget/nsIIdleServiceInternal.idl
  34. +1 −1 widget/os2/nsIdleServiceOS2.cpp
  35. +15 −4 widget/os2/nsIdleServiceOS2.h
  36. +2 −1 widget/os2/nsWidgetFactory.cpp
  37. +1 −1 widget/qt/nsIdleServiceQt.cpp
  38. +15 −3 widget/qt/nsIdleServiceQt.h
  39. +1 −1 widget/qt/nsWidgetFactory.cpp
  40. +1 −1 widget/qt/nsWindow.cpp
  41. +2 −1 widget/qt/nsWindow.h
  42. +1 −1 widget/windows/nsIdleServiceWin.cpp
  43. +15 −1 widget/windows/nsIdleServiceWin.h
  44. +1 −1 widget/windows/nsWidgetFactory.cpp
  45. +1 −1 widget/windows/nsWindow.cpp
  46. +3 −1 widget/windows/nsWindow.h
  47. +25 −10 widget/xpwidgets/nsIdleService.cpp
  48. +8 −17 widget/xpwidgets/nsIdleService.h
  49. +26 −1 xpcom/glue/nsTObserverArray.h
@@ -1831,6 +1831,11 @@ class nsContentUtils
static bool IsRequestFullScreenAllowed();
/**
+ * Returns true if the idle observers API is enabled.
+ */
+ static bool IsIdleObserverAPIEnabled() { return sIsIdleObserverAPIEnabled; }
+
+ /**
* Returns true if the doc tree branch which contains aDoc contains any
* plugins which we don't control event dispatch for, i.e. do any plugins
* in the same tab as this document receive key events outside of our
@@ -2013,6 +2018,19 @@ class nsContentUtils
static void SplitMimeType(const nsAString& aValue, nsString& aType,
nsString& aParams);
+ /**
+ * Function checks if the user is idle.
+ *
+ * @param aRequestedIdleTimeInMS The idle observer's requested idle time.
+ * @param aUserIsIdle boolean indicating if the user
+ * is currently idle or not. *
+ * @return NS_OK NS_OK returned if the requested idle service and
+ * the current idle time were successfully obtained.
+ * NS_ERROR_FAILURE returned if the the requested
+ * idle service or the current idle were not obtained.
+ */
+ static nsresult IsUserIdle(PRUint32 aRequestedIdleTimeInMS, bool* aUserIsIdle);
+
/**
* Takes a window and a string to check prefs against. Assumes that
* the window is an app window, and that the pref is a comma
@@ -2139,6 +2157,7 @@ class nsContentUtils
static bool sIsFullScreenApiEnabled;
static bool sTrustedFullScreenOnly;
static PRUint32 sHandlingInputTimeout;
+ static bool sIsIdleObserverAPIEnabled;
static nsHtml5StringParser* sHTMLFragmentParser;
static nsIParser* sXMLFragmentParser;
@@ -29,6 +29,7 @@
#include "nsIDocument.h"
#include "nsINodeInfo.h"
#include "nsReadableUtils.h"
+#include "nsIIdleService.h"
#include "nsIDOMDocument.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMNode.h"
@@ -243,6 +244,7 @@ nsString* nsContentUtils::sModifierSeparator = nsnull;
bool nsContentUtils::sInitialized = false;
bool nsContentUtils::sIsFullScreenApiEnabled = false;
bool nsContentUtils::sTrustedFullScreenOnly = true;
+bool nsContentUtils::sIsIdleObserverAPIEnabled = false;
PRUint32 nsContentUtils::sHandlingInputTimeout = 1000;
@@ -418,6 +420,8 @@ nsContentUtils::Init()
Preferences::AddBoolVarCache(&sTrustedFullScreenOnly,
"full-screen-api.allow-trusted-requests-only");
+ sIsIdleObserverAPIEnabled = Preferences::GetBool("dom.idle-observers-api.enabled", true);
+
Preferences::AddUintVarCache(&sHandlingInputTimeout,
"dom.event.handling-user-input-time-limit",
1000);
@@ -869,6 +873,22 @@ nsContentUtils::SplitMimeType(const nsAString& aValue, nsString& aType,
aType.StripWhitespace();
}
+nsresult
+nsContentUtils::IsUserIdle(PRUint32 aRequestedIdleTimeInMS, bool* aUserIsIdle)
+{
+ nsresult rv;
+ nsCOMPtr<nsIIdleService> idleService =
+ do_GetService("@mozilla.org/widget/idleservice;1", &rv);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ PRUint32 idleTimeInMS;
+ rv = idleService->GetIdleTime(&idleTimeInMS);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ *aUserIsIdle = idleTimeInMS >= aRequestedIdleTimeInMS;
+ return NS_OK;
+}
+
/**
* Access a cached parser service. Don't addref. We need only one
* reference to it and this class has that one.
View
@@ -37,6 +37,7 @@
#include "mozilla/ClearOnShutdown.h"
#include "Connection.h"
#include "MobileConnection.h"
+#include "nsIIdleObserver.h"
#ifdef MOZ_MEDIA_NAVIGATOR
#include "MediaManager.h"
@@ -651,6 +652,43 @@ GetVibrationDurationFromJsval(const jsval& aJSVal, JSContext* cx,
} // anonymous namespace
NS_IMETHODIMP
+Navigator::AddIdleObserver(nsIIdleObserver* aIdleObserver)
+{
+ if (!nsContentUtils::IsIdleObserverAPIEnabled()) {
+ NS_WARNING("The IdleObserver API has been disabled.");
+ return NS_OK;
+ }
+
+ NS_ENSURE_ARG_POINTER(aIdleObserver);
+
+ nsCOMPtr<nsPIDOMWindow> win = do_QueryReferent(mWindow);
+ NS_ENSURE_TRUE(win, NS_ERROR_UNEXPECTED);
+ if (NS_FAILED(win->RegisterIdleObserver(aIdleObserver))) {
+ NS_WARNING("Failed to add idle observer.");
+ }
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+Navigator::RemoveIdleObserver(nsIIdleObserver* aIdleObserver)
+{
+ if (!nsContentUtils::IsIdleObserverAPIEnabled()) {
+ NS_WARNING("The IdleObserver API has been disabled");
+ return NS_OK;
+ }
+
+ NS_ENSURE_ARG_POINTER(aIdleObserver);
+
+ nsCOMPtr<nsPIDOMWindow> win = do_QueryReferent(mWindow);
+ NS_ENSURE_TRUE(win, NS_ERROR_UNEXPECTED);
+ if (NS_FAILED(win->UnregisterIdleObserver(aIdleObserver))) {
+ NS_WARNING("Failed to remove idle observer.");
+ }
+ return NS_OK;
+}
+
+NS_IMETHODIMP
Navigator::MozVibrate(const jsval& aPattern, JSContext* cx)
{
nsCOMPtr<nsPIDOMWindow> win = do_QueryReferent(mWindow);
Oops, something went wrong.

0 comments on commit 7a26a02

Please sign in to comment.