xpcAccessibilityService.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  3. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #ifndef mozilla_a11y_xpcAccessibilityService_h_
  5. #define mozilla_a11y_xpcAccessibilityService_h_
  6. #include "nsIAccessibilityService.h"
  7. #include "nsCOMPtr.h"
  8. #include "nsITimer.h"
  9. class xpcAccessibilityService : public nsIAccessibleRetrieval
  10. {
  11. public:
  12. NS_DECL_ISUPPORTS
  13. NS_DECL_NSIACCESSIBILITYSERVICE
  14. NS_DECL_NSIACCESSIBLERETRIEVAL
  15. /**
  16. * Return true if xpc accessibility service is in use.
  17. */
  18. static bool IsInUse() {
  19. // When ref count goes down to 1 (held internally as a static reference),
  20. // it means that there are no more external references and thus it is not in
  21. // use.
  22. return gXPCAccessibilityService ? gXPCAccessibilityService->mRefCnt > 1 : false;
  23. }
  24. protected:
  25. virtual ~xpcAccessibilityService() {
  26. if (mShutdownTimer) {
  27. mShutdownTimer->Cancel();
  28. mShutdownTimer = nullptr;
  29. }
  30. gXPCAccessibilityService = nullptr;
  31. }
  32. private:
  33. // xpcAccessibilityService creation is controlled by friend
  34. // NS_GetAccessibilityService, keep constructor private.
  35. xpcAccessibilityService() { };
  36. nsCOMPtr<nsITimer> mShutdownTimer;
  37. /**
  38. * Reference for xpc accessibility service instance.
  39. */
  40. static xpcAccessibilityService* gXPCAccessibilityService;
  41. /**
  42. * Used to shutdown nsAccessibilityService if xpcom accessible service is not
  43. * in use any more.
  44. */
  45. static void ShutdownCallback(nsITimer* aTimer, void* aClosure);
  46. friend nsresult NS_GetAccessibilityService(nsIAccessibilityService** aResult);
  47. };
  48. // for component registration
  49. // {3b265b69-f813-48ff-880d-d88d101af404}
  50. #define NS_ACCESSIBILITY_SERVICE_CID \
  51. { 0x3b265b69, 0xf813, 0x48ff, { 0x88, 0x0d, 0xd8, 0x8d, 0x10, 0x1a, 0xf4, 0x04 } }
  52. extern nsresult
  53. NS_GetAccessibilityService(nsIAccessibilityService** aResult);
  54. #endif