michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "Compatibility.h" michael@0: michael@0: #include "nsWinUtils.h" michael@0: #include "Statistics.h" michael@0: michael@0: #include "mozilla/Preferences.h" michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::a11y; michael@0: michael@0: /** michael@0: * Return true if module version is lesser than the given version. michael@0: */ michael@0: bool michael@0: IsModuleVersionLessThan(HMODULE aModuleHandle, DWORD aMajor, DWORD aMinor) michael@0: { michael@0: wchar_t fileName[MAX_PATH]; michael@0: ::GetModuleFileNameW(aModuleHandle, fileName, MAX_PATH); michael@0: michael@0: DWORD dummy = 0; michael@0: DWORD length = ::GetFileVersionInfoSizeW(fileName, &dummy); michael@0: michael@0: LPBYTE versionInfo = new BYTE[length]; michael@0: ::GetFileVersionInfoW(fileName, 0, length, versionInfo); michael@0: michael@0: UINT uLen; michael@0: VS_FIXEDFILEINFO* fixedFileInfo = nullptr; michael@0: ::VerQueryValueW(versionInfo, L"\\", (LPVOID*)&fixedFileInfo, &uLen); michael@0: DWORD dwFileVersionMS = fixedFileInfo->dwFileVersionMS; michael@0: DWORD dwFileVersionLS = fixedFileInfo->dwFileVersionLS; michael@0: delete [] versionInfo; michael@0: michael@0: DWORD dwLeftMost = HIWORD(dwFileVersionMS); michael@0: DWORD dwSecondRight = HIWORD(dwFileVersionLS); michael@0: return (dwLeftMost < aMajor || michael@0: (dwLeftMost == aMajor && dwSecondRight < aMinor)); michael@0: } michael@0: michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // Compatibility michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: uint32_t Compatibility::sConsumers = Compatibility::UNKNOWN; michael@0: michael@0: void michael@0: Compatibility::Init() michael@0: { michael@0: // Note we collect some AT statistics/telemetry here for convenience. michael@0: michael@0: HMODULE jawsHandle = ::GetModuleHandleW(L"jhook"); michael@0: if (jawsHandle) michael@0: sConsumers |= (IsModuleVersionLessThan(jawsHandle, 8, 2173)) ? michael@0: OLDJAWS : JAWS; michael@0: michael@0: if (::GetModuleHandleW(L"gwm32inc")) michael@0: sConsumers |= WE; michael@0: michael@0: if (::GetModuleHandleW(L"dolwinhk")) michael@0: sConsumers |= DOLPHIN; michael@0: michael@0: if (::GetModuleHandleW(L"STSA32")) michael@0: sConsumers |= SEROTEK; michael@0: michael@0: if (::GetModuleHandleW(L"nvdaHelperRemote")) michael@0: sConsumers |= NVDA; michael@0: michael@0: if (::GetModuleHandleW(L"OsmHooks")) michael@0: sConsumers |= COBRA; michael@0: michael@0: if (::GetModuleHandleW(L"WebFinderRemote")) michael@0: sConsumers |= ZOOMTEXT; michael@0: michael@0: if (::GetModuleHandleW(L"Kazahook")) michael@0: sConsumers |= KAZAGURU; michael@0: michael@0: if (::GetModuleHandleW(L"TextExtractorImpl32") || michael@0: ::GetModuleHandleW(L"TextExtractorImpl64")) michael@0: sConsumers |= YOUDAO; michael@0: michael@0: if (::GetModuleHandleW(L"uiautomation") || michael@0: ::GetModuleHandleW(L"uiautomationcore")) michael@0: sConsumers |= UIAUTOMATION; michael@0: michael@0: // If we have a known consumer remove the unknown bit. michael@0: if (sConsumers != Compatibility::UNKNOWN) michael@0: sConsumers ^= Compatibility::UNKNOWN; michael@0: michael@0: // Gather telemetry michael@0: uint32_t temp = sConsumers; michael@0: for (int i = 0; temp; i++) { michael@0: if (temp & 0x1) michael@0: statistics::A11yConsumers(i); michael@0: michael@0: temp >>= 1; michael@0: } michael@0: michael@0: // Turn off new tab switching for Jaws and WE. michael@0: if (sConsumers & (JAWS | OLDJAWS | WE)) { michael@0: // Check to see if the pref for disallowing CtrlTab is already set. If so, michael@0: // bail out (respect the user settings). If not, set it. michael@0: if (!Preferences::HasUserValue("browser.ctrlTab.disallowForScreenReaders")) michael@0: Preferences::SetBool("browser.ctrlTab.disallowForScreenReaders", true); michael@0: } michael@0: } michael@0: