diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /other-licenses/nsis/Contrib/WebBrowser/Timers.cpp | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'other-licenses/nsis/Contrib/WebBrowser/Timers.cpp')
-rw-r--r-- | other-licenses/nsis/Contrib/WebBrowser/Timers.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/other-licenses/nsis/Contrib/WebBrowser/Timers.cpp b/other-licenses/nsis/Contrib/WebBrowser/Timers.cpp new file mode 100644 index 0000000000..00844b7091 --- /dev/null +++ b/other-licenses/nsis/Contrib/WebBrowser/Timers.cpp @@ -0,0 +1,59 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0.If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include <windows.h> +#include "exdll.h" + +static void APIENTRY TimerCallback(LPVOID NSISFunctionAddr, DWORD, DWORD) { + g_executeCodeSegment((int)NSISFunctionAddr, nullptr); +} + +PLUGINFUNCTION(CreateTimer) { + EXDLL_INIT(); + extra->RegisterPluginCallback(gHInst, NSISPluginCallback); + + TCHAR* funcAddrStr = + (TCHAR*)HeapAlloc(GetProcessHeap(), 0, g_stringsize * sizeof(TCHAR)); + popstring(funcAddrStr); + // Apparently GetFunctionAddress returnes a 1-indexed offset, but + // ExecuteCodeSegment expects a 0-indexed one. Or something. + uintptr_t funcAddr = static_cast<uintptr_t>(_ttoi64(funcAddrStr)) - 1; + HeapFree(GetProcessHeap(), 0, funcAddrStr); + + TCHAR* intervalStr = + (TCHAR*)HeapAlloc(GetProcessHeap(), 0, g_stringsize * sizeof(TCHAR)); + popstring(intervalStr); + long interval = _ttol(intervalStr); + HeapFree(GetProcessHeap(), 0, intervalStr); + + HANDLE timer = CreateWaitableTimer(nullptr, FALSE, nullptr); + if (!timer) { + return; + } + + // The interval we were passed is in milliseconds, so we need to convert it + // to the 100-nanosecond units that SetWaitableTimer expects. We also need to + // make it negative, because that's what signifies a relative offset from now + // instead of an epoch-based time stamp. + LARGE_INTEGER dueTime; + dueTime.QuadPart = -(interval * 10000); + + SetWaitableTimer(timer, &dueTime, interval, TimerCallback, (void*)funcAddr, + FALSE); + + TCHAR timerStr[32] = _T(""); + _ltot_s((long)timer, timerStr, 10); + pushstring(timerStr); +} + +PLUGINFUNCTION(CancelTimer) { + TCHAR* timerStr = + (TCHAR*)HeapAlloc(GetProcessHeap(), 0, g_stringsize * sizeof(TCHAR)); + popstring(timerStr); + HANDLE timer = reinterpret_cast<HANDLE>(_ttoi(timerStr)); + HeapFree(GetProcessHeap(), 0, timerStr); + + CancelWaitableTimer(timer); + CloseHandle(timer); +} |