-
Notifications
You must be signed in to change notification settings - Fork 64
Description
Describe the feature/enhancement you need
All objects in WebView2.h have vtbl structs and macro based helpers for a flat C API (e.g. ICoreWebView2_get_Settings). Additionally constructor functions like CreateCoreWebView2EnvironmentWithOptions are provided. One parameter of this function is ICoreWebView2EnvironmentOptions * which has to be constructed by the library user of customization is needed.
WebView2EnvironmentOptions.h provides declarations for a default implementation, however this header is incompatible with C (no #if defined(__cplusplus)). Therefore one would have to create the interface implementation manually. Sadly, the ICoreWebView2EnvironmentOptions hierarchy of objects is particularly hard to work with from C side, as each variant of ICoreWebView2EnvironmentOptions{1-8} inherits IUnknown instead of its previous sibling. When creating a single EnvironmentOptions implementation of all interface versions from C side one has to provide 8 different QueryInterface, AddRef and Release implementations to account for the varying offsets of self depending on the currently used interface (usually with CONTAINING_RECORD).
From a developer perspective this unnecessarily leaves a lot to be desired, especially as most of the the WebView2 API is already very usable from C. Ideally a C function similar to the WebView2.h flat API would allow creating a default ICoreWebView2EnvironmentOptions implementation.
The scenario/use case where you would use this feature
I am implementing cross platform WebView bindings for different backends and WebView2 is one of them. Due to external reasons the code is and must stay C based. This feature would significantly reduce the code overhead of providing a Options implementation from C without resorting to C++.
Additionally it would simplify library implementers life as they no longer have to provide a custom implementation, for example here.
How important is this request to you?
Nice to have. There are other ways to tackle this, but having official API support would be beneficial.
Suggested implementation
To alleviate this issue I propose to make WebView2EnvironmentOptions.h C complatible and provide a constructor function CreateCoreWebView2EnvironmentOptions which returns a default Options object which then allows working with the flat C helpers from WebView2.
An implementation could wrap all of the current WebView2EnvironmentOptions.h code in
#if defined(__cplusplus)
// code so far
#endif
extern ICoreWebView2EnvironmentOptions * CreateCoreWebView2EnvironmentOptions();This could then be used in C like
ICoreWebView2EnvironmentOptions * options = CreateCoreWebView2EnvironmentOptions();
ICoreWebView2EnvironmentOptions8 * options8;
ICoreWebView2EnvironmentOptions_QueryInterface(options, &IID_ICoreWebView2EnvironmentOptions8, &options8);
ICoreWebView2EnvironmentOptions8_put_ScrollBarStyle(options8, COREWEBVIEW2_SCROLLBAR_STYLE_FLUENT_OVERLAY);
CreateCoreWebView2EnvironmentWithOptions(..., options, ...);