Bug 1890277: part 2) Add `require-trusted-types-for` directive to CSP parser, guarded...
[gecko.git] / accessible / xpcom / xpcAccessibilityService.h
blob04c23e7075d228edd98a31433d64b66450ee9406
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/. */
5 #ifndef mozilla_a11y_xpcAccessibilityService_h_
6 #define mozilla_a11y_xpcAccessibilityService_h_
8 #include "nsIAccessibilityService.h"
9 #include "nsITimer.h"
11 class xpcAccessibilityService : public nsIAccessibilityService {
12 public:
13 NS_DECL_ISUPPORTS
14 NS_DECL_NSIACCESSIBILITYSERVICE
16 /**
17 * Return true if xpc accessibility service is in use.
19 static bool IsInUse() {
20 // When ref count goes down to 1 (held internally as a static reference),
21 // it means that there are no more external references and thus it is not in
22 // use.
23 return gXPCAccessibilityService ? gXPCAccessibilityService->mRefCnt > 1
24 : false;
27 protected:
28 virtual ~xpcAccessibilityService() {
29 if (mShutdownTimer) {
30 mShutdownTimer->Cancel();
31 mShutdownTimer = nullptr;
33 gXPCAccessibilityService = nullptr;
36 private:
37 // xpcAccessibilityService creation is controlled by friend
38 // NS_GetAccessibilityService, keep constructor private.
39 xpcAccessibilityService() = default;
41 nsCOMPtr<nsITimer> mShutdownTimer;
43 /**
44 * Reference for xpc accessibility service instance.
46 static xpcAccessibilityService* gXPCAccessibilityService;
48 /**
49 * Used to shutdown nsAccessibilityService if xpcom accessible service is not
50 * in use any more.
52 static void ShutdownCallback(nsITimer* aTimer, void* aClosure);
54 friend nsresult NS_GetAccessibilityService(nsIAccessibilityService** aResult);
57 // for component registration
58 // {3b265b69-f813-48ff-880d-d88d101af404}
59 #define NS_ACCESSIBILITY_SERVICE_CID \
60 { \
61 0x3b265b69, 0xf813, 0x48ff, { \
62 0x88, 0x0d, 0xd8, 0x8d, 0x10, 0x1a, 0xf4, 0x04 \
63 } \
66 extern nsresult NS_GetAccessibilityService(nsIAccessibilityService** aResult);
68 #endif