2424#include < cef3/cef/include/cef_values.h>
2525#include < SString.h>
2626#include < audiopolicy.h>
27- #include < condition_variable>
2827#include < functional>
2928#include < memory>
3029#include < mmdeviceapi.h>
3130#include < mutex>
3231#include < cstdint>
32+ #include < chrono>
3333#define GetNextSibling (hwnd ) GetWindow(hwnd, GW_HWNDNEXT) // Re-define the conflicting macro
3434#define GetFirstChild (hwnd ) GetTopWindow(hwnd)
3535
@@ -43,12 +43,6 @@ namespace WebViewAuth
4343 bool HandleInputFocus (CWebView*, CefRefPtr<CefListValue>, const bool );
4444}
4545
46- enum class ECefThreadState
47- {
48- Running = 0 , // CEF thread is currently running
49- Wait // CEF thread is waiting for the main thread
50- };
51-
5246class CWebView : public CWebViewInterface ,
5347 private CefClient,
5448 private CefRenderHandler,
@@ -71,6 +65,7 @@ class CWebView : public CWebViewInterface,
7165 void SetWebBrowserEvents (CWebBrowserEventsInterface* pInterface);
7266 void ClearWebBrowserEvents (CWebBrowserEventsInterface* pInterface);
7367 void CloseBrowser ();
68+ bool EnsureBrowserCreated (); // Lazy creation: creates browser on first use
7469 CefRefPtr<CefBrowser> GetCefBrowser () { return m_pWebView; };
7570
7671 bool IsBeingDestroyed () { return m_bBeingDestroyed; }
@@ -211,7 +206,6 @@ class CWebView : public CWebViewInterface,
211206 CefRefPtr<CefMenuModel> model) override ;
212207
213208private:
214- void ResumeCefThread ();
215209 void QueueBrowserEvent (const char * name, std::function<void (CWebBrowserEventsInterface*)>&& fn);
216210
217211 struct FEventTarget
@@ -270,29 +264,37 @@ class CWebView : public CWebViewInterface,
270264 CefRefPtr<CefBrowser> m_pWebView;
271265 CWebBrowserItem* m_pWebBrowserRenderItem;
272266
273- std::atomic_bool m_bBeingDestroyed;
274- bool m_bIsLocal;
275- bool m_bIsRenderingPaused;
276- bool m_bIsTransparent;
277- POINT m_vecMousePosition;
278- bool m_mouseButtonStates[3 ];
279- SString m_CurrentTitle;
280- float m_fVolume;
281- std::map<SString, SString> m_Properties;
282- bool m_bHasInputFocus;
283- std::set<std::string> m_AjaxHandlers;
284- std::shared_ptr<FEventTarget> m_pEventTarget;
267+ std::atomic_bool m_bBeingDestroyed;
268+ bool m_bIsLocal;
269+ bool m_bIsRenderingPaused;
270+ bool m_bIsTransparent;
271+ bool m_bBrowserCreated = false ; // Lazy creation: tracks if CEF browser has been created
272+ SString m_strPendingURL; // Lazy creation: URL to load when browser is ready
273+ bool m_bPendingURLFilterEnabled = true ;
274+ SString m_strPendingPostData;
275+ bool m_bPendingURLEncoded = true ;
276+ POINT m_vecMousePosition;
277+ POINT m_vecPendingMousePosition; // Pending position for throttled mouse move
278+ bool m_bHasPendingMouseMove = false ; // Whether there's a pending throttled mouse move
279+ std::chrono::steady_clock::time_point m_lastMouseMoveTime; // For mouse move throttling
280+ bool m_mouseButtonStates[3 ];
281+ SString m_CurrentTitle;
282+ float m_fVolume;
283+ std::map<SString, SString> m_Properties;
284+ bool m_bHasInputFocus;
285+ std::set<std::string> m_AjaxHandlers;
286+ std::shared_ptr<FEventTarget> m_pEventTarget;
285287
286288 struct
287289 {
288- bool changed = false ;
289- std::mutex dataMutex;
290- ECefThreadState cefThreadState = ECefThreadState::Running;
291- std::condition_variable cefThreadCv;
292-
293- const void * buffer ;
294- int width, height ;
295- CefRenderHandler::RectList dirtyRects ;
290+ bool changed = false ;
291+ std::mutex dataMutex;
292+
293+ // Main frame buffer - we now own this buffer (copied in OnPaint)
294+ std::unique_ptr<byte[]> buffer;
295+ size_t bufferSize = 0 ;
296+ int width = 0 ;
297+ int height = 0 ;
296298
297299 CefRect popupRect;
298300 bool popupShown = false ;
0 commit comments