Z#1363
Open
Premiermoney wants to merge 44 commits into
Open
Conversation
When compiling in C++23 mode using Clang, compilation failed in ~unique_ptr() due to user_script::impl being an incomplete type. Issue was observed with Clang 16 and 18 on Linux/macOS, with C++23 set via CMAKE_CXX_STANDARD. C++20 and earlier did not yield an error. The issue could not be observed with GCC 13.2 and 14.2 on Linux.
* Disable clang-tidy misc-include-cleaner rule * Disable clang-tidy performance-enum-size rule * Avoid performance-avoid-endl clang-tidy issue * Remove some instances of "static" keyword * Suppress misc-use-anonymous-namespace in tests * Avoid bugprone-empty-catch
Generate IDs that match line numbers in the CSV file, making it more convenient to work with the file and review changes made to it. Not the most correct way to do it but it gets the job done.
Add a modern Python binding
…definition in 'api.h' (webview#1236)
Re-enables code syntax highlighting in code editors for files that enable
code based on whether platform/backend-specific macros are defined.
Example:
#if defined(WEBVIEW_PLATFORM_LINUX) && defined(WEBVIEW_GTK)
#endif
Without the macros.h header, WEBVIEW_PLATFORM_LINUX and WEBVIEW_GTK would
by default appear to be undefined in code editors.
Limits the CI test timeout to 60s.
Amalgamation script now fails by default when a header can't be found.
Missing headers can be explicitly allowed with a comment:
#include "xyz.h" // amalgamate(skip)
This is currently only used for MS WebView2 header "WebView2.h".
Inputs can now also be paths to directories in which any file or
directory will be handled as an input. Inputs are handled recursively.
The amalgamated header is now not only generated in CI in order to test
the script itself, but the common use cases for the header are now
tested by building a simple program for different platforms against the
generated header.
Some "#if/ifdef" around "#include" were useless after amalgamation
and have instead been added into each header.
Some macro names and "#endif" comments have been fixed/updated.
"webview.cc" has been updated to include "webview/webview.h" instead
of the deprecated header. This also allows the amalgamation script to
produce slightly cleaner output.
The ubuntu-20.04 image is scheduled for removal and this change is to avoid disruption.
This work makes some changes that are necessary for lowering the minimum required C++ standard on Windows from C++14 to C++11. I can't recall why cxx_std_14 was set instead of cxx_std_11 for the MSWebView2::headers CMake target but it may have been under the wrong belief that it wouldn't work with cxx_std_11. Now it does appear to work with the MinGW distributions we test with so making this change seems reasonable to me. Some code for Windows were using C++14 features and have been replaced to be compatible with C++11. While at it, the move constructor and assignment operator of com_init_wrapper should have been marked as noexcept and has therefore been marked as such.
Avoids some excess dispatching on Windows while organizing code better.
* add refactor methods * refactor m_script_is_init to m_is_init_script_added
- fixes a default sizing glitch behaviour at variance across Linux desktop environments - refactors gtk_webkitgtk to a more standardised backend code flow
- Fixes a visual issue where the default size was set before the user size, causing a rendering glitch - Refactors win32_edge to a more standardised backend code flow
- Fixes an issue where the window was not showing if the user did not set a size - Refactors cocoa_webkit to a more standardised backend code flow
* refactor * refactor and fix visual glitch * Refactor cocoa-webkit and fix no show default size * Revert spacing in string function to match upstream * clarify a comment * Fix branch merge error * refactor dispatch_size_default and m_owns_window * refactor m_owns window for win32_edge * refactor m_owns window for cocoa_webkit * Refactor set_size in engine_base * rename default_size_guard to set_default_size_guard * rename to m_has_window_init_started * Enforce window_init and window_settings signatures as common virtual methods in engine_base * tidy up after all parent refactors were merged * revert virtual window_init and window_settings due to them being called in constructor
There has been a problem for some time where the first test that cold-starts an MS WebView2 instance in a GitHub Actions environment may be severely delayed and result in a timeout. The delay has been observed to range from nearly no time to a minute or longer. While this doesn't solve the root cause, it should at least alleviate some pain due to timeouts. This work does the following: * Separates unit tests from functional tests. They're now in separate source files and are compiled into separate executables. This is not strictly necessary but organizes tests a bit better. * The CMake configuration for the test driver now supports setting a normal timeout value as well as an additional timeout value that takes precedence whenever a test prints a matching string to standard output/error. * Adds a dummy warm-up test that runs first only on Windows with a longer timeout using the mechanism described above.
This work refactors code that uses Objective-C runtime invocations and
makes such code more manageable.
This initial work essentially does the following:
* Extracts code from the Cocoa/WebKit browser backend file
(cocoa_webkit.hh) into separate files.
* Wraps Objective-C method calls (messaging) into C++ functions.
Some convenience functions were added where it makes sense, e.g. class
factory functions and some variants that can work with C++ standard
library types.
* Replaces all instances of objc::msg_send*() in cocoa_webkit.hh with
wrapper functions.
An example with Objective-C runtime invocations that are hard to manage:
objc::msg_send<id>(
objc::msg_send<id>(
"NSWindow"_cls,
"alloc"_sel),
"initWithContentRect:styleMask:backing:defer:"_sel,
CGRectMake(0, 0, 0, 0),
NSWindowStyleMaskTitled,
NSBackingStoreBuffered,
NO)
With a refactor, code such as the above can be written in a cleaner way:
NSWindow_init_with_content_rect(
NSWindow_alloc(),
NSRectMake(0, 0, 0, 0),
NSWindowStyleMaskTitled,
NSBackingStoreBuffered,
false)
Equivalent code that calls a convenience function that returns an
autoreleased instance:
objc::retain(
NSWindow_with_content_rect(
NSRectMake(0, 0, 0, 0),
NSWindowStyleMaskTitled,
NSBackingStoreBuffered,
false))
Names of types and wrapper functions should closely match the original
names.
The following rules were used when naming the wrapper functions:
* Property:
* Getter: Class_get_propertyName
* Setter: Class_set_propertyName
* Method: Class_methodName
(note: method names are sometimes prefixed with "set")
* Since method names/messages can include colons (":"), consider
whether to cut the name there or replace ":" with "_" to avoid
ambiguity and clashing names.
Other accompanying changes:
* Rename objc::autoreleased to objc::autorelease and return self
* Fix "setInspectable:" invocation
The "setInspectable:" message was previously sent to a WKWebView
instance with the boolean value incorrectly having the type NSNumber*
instead of BOOL.
Since we always wanted to enable inspection and the value
passed was always non-zero, the behavior remains unchanged.
* Pull symbols from objc::literals namespace into cocoa/webkit namespace
Justified by the fact that these literals are used everywhere in
these namespaces.
* Remove objc::literal symbol pollution from the detail namespace
* Add macOS backend into separate cocoa_webkit namespace and pull
symbols from the cocoa/webkit namespaces into the new namespace:
* Eliminates excess "using namespace (cocoa|webkit)" within functions.
* Avoids polluting the existing detail namespace.
The _cls, _sel and _str UDL operators/suffixes have been removed to avoid a messy situation. The UDLs can't cleanly be used without "using namespace", which adds noise to functions, and when used at namespace scope then we pollute the namespace. The UDLs are so widely in the cocoa and webkit namespaces that noise/pollution seems to be unavoidable. I wanted to move _str from the objc::literals namespace into the cocoa::literals namespace where it's more appropriate since it instantiates the NSString class; however, it would've been inaccessible without "using namespace cocoa::literals". cocoa::literals could pull in everything from objc::literals, and webkit::literals could pull in everything from cocoa::literals and objc::literals. This is not too bad because the literals are used everywhere within the cocoa and webkit namespaces. However, that doesn't solve the need for "using namespace x::literals" within the cocoa and webkit namespaces where functions are defined, which somewhat defeats the purpose of having the UDLs in a separate namespace. One way or another it seems like it'll get messy. Instead the UDLs have been replaced with the regular functions objc::get_class(), objc::selector() and NSString_stringWithUTF8String(). This eliminates the whole issue with noise and pollution at the cost of more verbose code. Browser backend code does however not become more verbose by this change as it doesn't directly use the UDLs. While NSString_stringWithUTF8String is certainly more verbose than _str, it isn't used so frequently that it's an issue. In conclusion, the UDL operators were removed so that noise and pollution related to them could be eliminated, even at a cost of slightly increased code verbosity in locations that do not need to be touched very often. Other changes: * Removed unnecessary C-style casts to "Class" and "id". Since the UDLs were replaced and the new functions return the correct types unlike the UDLs, no more casting is needed.
Correctness and code readability in the macOS browser backend has been improved: * Calls to objc_setAssociatedObject() have been wrapped, reducing duplicate code. * OBJC_ASSOCIATION_ASSIGN has been replaced with OBJC_ASSOCIATION_RETAIN with an appropriate Objective-C type (NSValue *) rather than casting an unrelated type to id. * Adds NSValue_valueWithPointer() and NSValue_getValue() for holding pointers in an NSValue. * Removed an unnecessary assert() that was also missing the cassert header inclusion.
Passing a flag in the constructor of engine_base is less error-prone.
Removes some details about expected behavior of webview_set_size() due
to inconsistencies observed when using GTK 4.
The documentation states the following:
GTK 4 can set a default/initial window size if done early enough;
otherwise, this function has no effect. GTK 4 (unlike 3) can't
resize a window after it has been set up.
Observations when calling webview_set_size() with WEBVIEW_HINT_NONE:
Ubuntu | GTK | Window | Can set new size?
-- | --- | ------- | -----------------
24.04.2 | 4.14.2 | X11 | If different from what was previously set
24.04.2 | 4.14.2 | Wayland | If user hasn't resized by hand
24.04.2 | 3.24.41 | X11 | Yes
24.04.2 | 3.24.41 | Wayland | Yes
22.04.5 | 4.6.9 | X11 | If different from what was previously set
22.04.5 | 4.6.9 | Wayland | Yes
22.04.5 | 3.24.33 | X11 | Yes
22.04.5 | 3.24.33 | Wayland | Yes
gtk_widget_set_size_request() was called when WEBVIEW_HINT_FIXED was passed into webview_set_size(). That function is meant to set a minimum size. Instead we can call gtk_window_set_default_size() (GTK 4) or gtk_window_resize() (GTK 3).
When char is unsigned, the comparison "c >= 0" can emit a warning (GCC):
comparison is always true due to limited range of data type
[-Wtype-limits]
On some architectures such as aarch64/ARM64, char is unsigned by
default, so the above comparison is redundant and will always evaluate
to true.
To enable the warning, specify either the -Wextra or -Wtype-limits
compiler flag. -Wall and -Wpedantic are not enough to enable the
warning (GCC 14/Clang 20).
No warning is emitted for architectures where char is signed by default
(e.g. x86-64), but if we specify that char is unsigned using the
--unsigned-char compiler flag then the warning is emitted.
By casting c to unsigned char, we can remove the redundant comparison
and make the compiler happy.
Co-authored-by: Christian Rüegg <[email protected]>
Co-authored-by: Steffen André Langnes <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.