webview_win32.h
The Windows webview backend (Edge WebView2).
#include <sonore/webview_win32.h>- 2types
- 15other declarations
- Guides: The web editor
On this page
Design notes
Creates a child HWND the host can embed, hosts a WebView2 inside it, injects the window.sonore bridge before any page script runs, and pumps parameter and meter updates into the page on a timer.
Design notes that are load-bearing:
- WebView2 comes up ASYNCHRONOUSLY (environment -> controller -> webview, each via a COM completion handler). Every public method therefore has to work BEFORE the webview exists: HTML, size and pending updates are stored and applied on arrival. A DAW opens and closes editors far faster than Edge initialises, so "not ready yet" is the normal case, not an edge one.
- The runtime may be ABSENT (older Windows without the Edge WebView2 Runtime). That degrades to a plain message in the child window, never a failed plugin load, and never a silent black rectangle.
- The webview is created with a per-plugin user-data folder under %LOCALAPPDATA%. Without an explicit folder WebView2 tries to write beside the host EXE, which fails in Program Files and takes the whole editor down with it.
- The page is served from memory, as the answer to a request for an address of the plugin's own that never leaves the process (https://<plugin>.sonore.invalid/editor.html, loadPage), so a generated UI is entirely self-contained, reloads like any page, and has an origin of its own: localStorage works and is kept per plugin. And it STAYS the page: every navigation away from it is cancelled (webviewMayNavigate in gui.h), in the page and in its frames, and window.open opens nothing. Before, a link or a script could take the view to a remote site, which then held window.sonore and set parameters; and a window.open popup was a top-level Edge window that outlived the editor.
Types 2
template <typename Interface, typename Arg1, typename Arg2> class ComCallback final : public Interface
One-method COM callback, refcounted. WebView2's creation API hands results back through these; a template keeps the three we need to one implementation.
A webview embedded in a child window.
Lifetime: create() makes the HWND immediately (so the host can embed it right away) and kicks off WebView2 creation; the page arrives later. destroy() tears everything down in the reverse order.
Functions 7
- fn
inline std::wstring widen(const std::string& s)win32::widen · webview_win32.h:70 - fn
inline std::string narrow(const wchar_t* s)win32::narrow · webview_win32.h:78 - fn
inline LRESULT CALLBACK hostWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)win32::hostWndProc · webview_win32.h:87 - fn
inline HINSTANCE thisModule()THIS module, not the host EXE.win32::thisModule · webview_win32.h:99 - fn
inline std::wstring& windowClassNameStorage()The child window class name, unique to THIS module.win32::windowClassNameStorage · webview_win32.h:125 - fn
inline const wchar_t* windowClassName()win32::windowClassName · webview_win32.h:130 - fn
inline ATOM registerWindowClass()win32::registerWindowClass · webview_win32.h:132
Aliases 8
- using
using EnvHandler = ComCallback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, HRESULT, ICoreWebView2Environment*>win32::EnvHandler · webview_win32.h:202 - using
using ControllerHandler = ComCallback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler, HRESULT, ICoreWebView2Controller*>win32::ControllerHandler · webview_win32.h:204 - using
using SuspendHandler = ComCallback<ICoreWebView2TrySuspendCompletedHandler, HRESULT, BOOL>win32::SuspendHandler · webview_win32.h:206 - using
using MessageHandler = ComCallback<ICoreWebView2WebMessageReceivedEventHandler, ICoreWebView2*, ICoreWebView2WebMessageReceivedEventArgs*>win32::MessageHandler · webview_win32.h:207 - using
using KeyHandler = ComCallback<ICoreWebView2AcceleratorKeyPressedEventHandler, ICoreWebView2Controller*, ICoreWebView2AcceleratorKeyPressedEventArgs*>win32::KeyHandler · webview_win32.h:209 - using
using NewWindowHandler = ComCallback<ICoreWebView2NewWindowRequestedEventHandler, ICoreWebView2*, ICoreWebView2NewWindowRequestedEventArgs*>win32::NewWindowHandler · webview_win32.h:214 - using
using ResourceHandler = ComCallback<ICoreWebView2WebResourceRequestedEventHandler, ICoreWebView2*, ICoreWebView2WebResourceRequestedEventArgs*>win32::ResourceHandler · webview_win32.h:216