11/*
22 * DISTRHO Plugin Framework (DPF)
3- * Copyright (C) 2012-2025 Filipe Coelho <falktx@falktx.com>
3+ * Copyright (C) 2012-2026 Filipe Coelho <falktx@falktx.com>
44 *
55 * Permission to use, copy, modify, and/or distribute this software for any purpose with
66 * or without fee is hereby granted, provided that the above copyright notice and this
@@ -35,7 +35,7 @@ using DISTRHO_NAMESPACE::WebView;
3535START_NAMESPACE_DISTRHO
3636#endif
3737
38- WebView* webview_choc_create (const WEB_VIEW_NAMESPACE::WebViewOptions& opts);
38+ WebView* webview_choc_create (const char * url, const WEB_VIEW_NAMESPACE::WebViewOptions& opts);
3939void webview_choc_destroy (WebView*);
4040void * webview_choc_handle (WebView*);
4141void webview_choc_eval (WebView*, const char * js);
@@ -60,34 +60,33 @@ START_NAMESPACE_DGL
6060START_NAMESPACE_DISTRHO
6161#endif
6262
63- WebView* webview_choc_create (const WEB_VIEW_NAMESPACE::WebViewOptions& opts)
63+ WebView* webview_choc_create (const char * const url, const WEB_VIEW_NAMESPACE::WebViewOptions& opts)
6464{
6565 WebView::Options wopts;
66- wopts.acceptsFirstMouseClick = true ;
6766 wopts.enableDebugMode = true ;
67+ wopts.transparentBackground = true ;
68+ wopts.webviewIsReady = [url, opts](WebView& webview){
69+ if (const WEB_VIEW_NAMESPACE::WebViewMessageCallback callback = opts.callback )
70+ {
71+ webview.addInitScript (" function postMessage(m){window.chrome.webview.postMessage(m);}" );
72+ webview.bind ([opts](std::string& value) {
73+ opts.callback (opts.callbackPtr , value.data ());
74+ });
75+ }
76+ else
77+ {
78+ webview.addInitScript (" function postMessage(m){}" );
79+ }
80+
81+ if (opts.initialJS != nullptr )
82+ webview.addInitScript (opts.initialJS );
83+
84+ webview.navigate (url);
85+ };
6886
6987 std::unique_ptr<WebView> webview = std::make_unique<WebView>(wopts);
7088 DISTRHO_SAFE_ASSERT_RETURN (webview->loadedOK (), nullptr );
7189
72- if (const WEB_VIEW_NAMESPACE::WebViewMessageCallback callback = opts.callback )
73- {
74- webview->addInitScript (" function postMessage(m){window.chrome.webview.postMessage(m);}" );
75-
76- void * const callbackPtr = opts.callbackPtr ;
77- webview->bind ([callback, callbackPtr](const std::string& value) {
78- char * const data = strdup (value.data ());
79- callback (callbackPtr, data);
80- std::free (data);
81- });
82- }
83- else
84- {
85- webview->addInitScript (" function postMessage(m){}" );
86- }
87-
88- if (opts.initialJS != nullptr )
89- webview->addInitScript (opts.initialJS );
90-
9190 return webview.release ();
9291}
9392
0 commit comments