diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /other-licenses/nsis/Contrib/WebBrowser/Timers.cpp | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
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); +} |