Compatibility.h (4207B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef COMPATIBILITY_MANAGER_H 8 #define COMPATIBILITY_MANAGER_H 9 10 #include <windows.h> 11 #include "nsTArray.h" 12 #include "nsString.h" 13 14 #include <stdint.h> 15 16 namespace mozilla::a11y { 17 18 enum class SuppressionReasons : uint8_t { 19 None = 0, 20 Clipboard = 1 << 0, 21 SnapLayouts = 1 << 1, 22 }; 23 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(SuppressionReasons); 24 25 /** 26 * Used to get compatibility modes. Note, modes are computed at accessibility 27 * start up time and aren't changed during lifetime. 28 */ 29 class Compatibility { 30 public: 31 /** 32 * Return true if JAWS mode is enabled. 33 */ 34 static bool IsJAWS() { return !!(sConsumers & (JAWS | OLDJAWS)); } 35 36 /** 37 * Return true if using an e10s incompatible Jaws. 38 */ 39 static bool IsOldJAWS() { return !!(sConsumers & OLDJAWS); } 40 41 /** 42 * Return true if WE mode is enabled. 43 */ 44 static bool IsWE() { return !!(sConsumers & WE); } 45 46 /** 47 * Return true if Dolphin mode is enabled. 48 */ 49 static bool IsDolphin() { return !!(sConsumers & DOLPHIN); } 50 51 /** 52 * Return true if JAWS, ZoomText or ZoomText Fusion 2021 or later is being 53 * used. These products share common code for interacting with Firefox and 54 * all require window emulation to be enabled. 55 */ 56 static bool IsVisperoShared() { return !!(sConsumers & VISPEROSHARED); } 57 58 /* 59 * Returns true if the instantiator is a known screen reader. 60 */ 61 static bool IsKnownScreenReader() { 62 return IsJAWS() || IsDolphin() || IsVisperoShared() || 63 !!(sConsumers & NVDA); 64 } 65 66 /** 67 * Return a string describing sConsumers suitable for about:support. 68 * Exposed through nsIXULRuntime.accessibilityInstantiator. 69 */ 70 static void GetHumanReadableConsumersStr(nsAString& aResult); 71 72 /** 73 * Initialize compatibility mode information. 74 */ 75 static void Init(); 76 77 static void GetUiaClientPids(nsTArray<DWORD>& aPids); 78 79 /** 80 * return true if a known, non-UIA a11y consumer is present 81 */ 82 static bool HasKnownNonUiaConsumer(); 83 84 /** 85 * Return true if a module's version is lesser than the given version. 86 * Generally, the version should be provided using the MAKE_FILE_VERSION 87 * macro. 88 * If the version information cannot be retrieved, true is returned; i.e. 89 * no version information implies an earlier version. 90 */ 91 static bool IsModuleVersionLessThan(HMODULE aModuleHandle, 92 unsigned long long aVersion); 93 94 static void SuppressA11yForClipboardCopy(); 95 static void SuppressA11yForSnapLayouts(); 96 static bool IsA11ySuppressed() { 97 return A11ySuppressionReasons() != SuppressionReasons::None; 98 } 99 static SuppressionReasons A11ySuppressionReasons(); 100 101 /** 102 * Returns true if Gecko's native UI Automation implementation is enabled. 103 * This is primarily configured via the accessibility.uia.enable pref. 104 * However, it might be disabled if Gecko detects known incompatible clients 105 * which would otherwise break. 106 */ 107 static bool IsUiaEnabled(); 108 109 private: 110 Compatibility(); 111 Compatibility(const Compatibility&); 112 Compatibility& operator=(const Compatibility&); 113 114 static void InitConsumers(); 115 116 /** 117 * List of detected consumers of a11y (used for statistics/telemetry and 118 * compat) 119 */ 120 enum { 121 NVDA = 1 << 0, 122 JAWS = 1 << 1, 123 OLDJAWS = 1 << 2, 124 WE = 1 << 3, 125 DOLPHIN = 1 << 4, 126 SEROTEK = 1 << 5, 127 COBRA = 1 << 6, 128 ZOOMTEXT = 1 << 7, 129 KAZAGURU = 1 << 8, 130 YOUDAO = 1 << 9, 131 UNKNOWN = 1 << 10, 132 UIAUTOMATION = 1 << 11, 133 VISPEROSHARED = 1 << 12 134 }; 135 #define CONSUMERS_ENUM_LEN 13 136 137 private: 138 static uint32_t sConsumers; 139 }; 140 141 } // namespace mozilla::a11y 142 143 // Convert the 4 (decimal) components of a DLL version number into a 144 // single unsigned long long, as needed by 145 // mozilla::a11y::Compatibility::IsModuleVersionLessThan. 146 #define MAKE_FILE_VERSION(a, b, c, d) \ 147 ((a##ULL << 48) + (b##ULL << 32) + (c##ULL << 16) + d##ULL) 148 149 #endif