tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

xpcAccessibilityService.h (1959B)


      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 
      5 #ifndef mozilla_a11y_xpcAccessibilityService_h_
      6 #define mozilla_a11y_xpcAccessibilityService_h_
      7 
      8 #include "nsIAccessibilityService.h"
      9 #include "nsITimer.h"
     10 
     11 class xpcAccessibilityService : public nsIAccessibilityService {
     12 public:
     13  NS_DECL_ISUPPORTS
     14  NS_DECL_NSIACCESSIBILITYSERVICE
     15 
     16  /**
     17   * Return true if xpc accessibility service is in use.
     18   */
     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;
     25  }
     26 
     27 protected:
     28  virtual ~xpcAccessibilityService() {
     29    if (mShutdownTimer) {
     30      mShutdownTimer->Cancel();
     31      mShutdownTimer = nullptr;
     32    }
     33    gXPCAccessibilityService = nullptr;
     34  }
     35 
     36 private:
     37  // xpcAccessibilityService creation is controlled by friend
     38  // NS_GetAccessibilityService, keep constructor private.
     39  xpcAccessibilityService() = default;
     40 
     41  nsCOMPtr<nsITimer> mShutdownTimer;
     42 
     43  /**
     44   * Reference for xpc accessibility service instance.
     45   */
     46  static xpcAccessibilityService* gXPCAccessibilityService;
     47 
     48  /**
     49   * Used to shutdown nsAccessibilityService if xpcom accessible service is not
     50   * in use any more.
     51   */
     52  static void ShutdownCallback(nsITimer* aTimer, void* aClosure);
     53 
     54  friend nsresult NS_GetAccessibilityService(nsIAccessibilityService** aResult);
     55 };
     56 
     57 // for component registration
     58 // {3b265b69-f813-48ff-880d-d88d101af404}
     59 #define NS_ACCESSIBILITY_SERVICE_CID \
     60  {0x3b265b69, 0xf813, 0x48ff, {0x88, 0x0d, 0xd8, 0x8d, 0x10, 0x1a, 0xf4, 0x04}}
     61 
     62 extern nsresult NS_GetAccessibilityService(nsIAccessibilityService** aResult);
     63 
     64 #endif