Commit graph

75337 commits

Author SHA1 Message Date
Vadim Zeitlin
2ef44570fd Work around bug with out of order JS execution results
Modify the sample to show the correct value of the user agent when using
WebKit backend as this got broken by calling it inside an event handler
executed later but before the idle event handler could dispatch the
result of JS executed from inside WebKit AddScriptMessageHandler()
implementation, resulting in misinterpreting this result ("{}") as the
user agent string.

The real fix is, of course, to deal with the JS execution results coming
out of order in some way.
2023-09-08 01:51:47 +02:00
Vadim Zeitlin
c109f7f593 Implement SetProxy() in wxWebViewChromium too
Update the documentation to mention that it supports it and add an
example showing how to call this function.
2023-09-08 01:34:59 +02:00
Vadim Zeitlin
80ce14910c Initialize wxWebViewChromium members in their declarations
No real changes, but ensure that all of them are always initialized.
2023-09-08 01:34:59 +02:00
Vadim Zeitlin
81283f84dd Merge branch 'master' into webview-chromium-new
This pulls in wxWebView::SetProxy() addition.
2023-09-08 01:34:21 +02:00
Vadim Zeitlin
49b2f9c809 Merge branch 'webview-proxy'
Add wxWebView::SetProxy().

See #23854.
2023-09-08 01:31:04 +02:00
Hartwig Wiesmann
879cc1e574 Fix file history items formatting when loading them from config
Add DoRefreshLabels() to wxFileHistoryBase::Load() to ensure that the
paths are formatted correctly.

Closes #23799.

See #23857.
2023-09-08 01:24:41 +02:00
Vadim Zeitlin
ff5c972b7f Set proxy to the environment variable value for all backends
Don't do it just for Edge one, as WebKit-based one supports it too and
the example code is nicer without the extra checks.
2023-09-07 15:33:39 +02:00
Vadim Zeitlin
0fd6cf99a3 Implement wxWebView::SetProxy() for Edge backend
Currently it can only be called before Create() because it has to be
passed via the additional browser arguments and can't be changed later.
2023-09-07 15:33:39 +02:00
Vadim Zeitlin
7c5d30fb32 Add wxWebView::SetProxy() and implement it for WebKit2 backend
Update the sample to allow specifying the proxy in it.
2023-09-07 15:33:39 +02:00
Vadim Zeitlin
a10ae82250 De TAB-ify Info.plist files
There doesn't seem to be any reason to use hard TABs in them, so don't.

No real changes.
2023-09-06 18:54:32 +02:00
Vadim Zeitlin
285b75bcd4 Remove extra whitespace documentation 2023-09-06 18:52:43 +02:00
Vadim Zeitlin
61bc16fa25 Update CEF-related build instructions
Moslty document that 5 helper applications are now needed under Mac and
not just a single one.
2023-09-06 18:49:57 +02:00
Vadim Zeitlin
9966bfd052 Don't bother setting the cache directory for Chromium
It defaults to $root_cache_path/Cache which is fine and our existing
attempt to set it didn't work (and resulted in an error message) anyhow
as it must be under $root_cache_path now.
2023-09-06 18:30:59 +02:00
Vadim Zeitlin
06c62f9aa4 Create all macOS helper apps required by current CEF version
For some reason we need 5 of them instead of just one now.

At least save some space by using links instead of duplicating the same
file 5 times.
2023-09-06 18:21:29 +02:00
Vadim Zeitlin
4130f7fa67 Add tracing to URL loading functions
No real changes, just make the trace logs more useful.
2023-09-06 18:21:29 +02:00
Vadim Zeitlin
9f11557717 Adjust makefiles to the new CEF framework install name
It is now defined as

@executable_path/../Frameworks/Chromium Embedded Framework.framework/Chromium Embedded Framework

in the framework itself, which means that we don't need to change it at
all for the main application and the wx library it uses.

We still need to change it for the helper application, but the command
doing it must be adjusted.
2023-09-06 03:50:34 +02:00
Vadim Zeitlin
7231a2d771 Fix parallel build of webview_chromium_helper under Mac
Make fix_cef_link target depend on webview_chromium_helper itself,
otherwise it could try to copy this file before it was created.
2023-09-06 03:50:34 +02:00
Vadim Zeitlin
784121a07a Remove apparently accidental condition in webview sample bakefile
"target" doesn't seem to make sense nor be needed here, as removing it
doesn't change anything in the generated files.
2023-09-06 03:50:34 +02:00
Vadim Zeitlin
9f2fce3859 Ensure that libcef.so is loaded first in webview sample
Use --no-as-needed linker flag to make this happen as otherwise it is
still loaded after libc.so (unless LD_PRELOAD is used).
2023-09-06 03:50:34 +02:00
Vadim Zeitlin
c0c345a816 Check that calling CefInitialize() won't hang under Linux
Verify that libcef.so was loaded before libc.so as otherwise calling
CefInitialize() would currently hang the program, see the discussion at
https://magpcss.org/ceforum/viewtopic.php?t=15118
2023-09-06 03:50:34 +02:00
Vadim Zeitlin
68c2a2b96f Also add checks that CefBrowser itself is valid
Further extend the changes of the previous two commits and cover all the
functions using the possibly not yet initialized browser object.
2023-09-06 03:50:34 +02:00
Vadim Zeitlin
8d5bd418ae Add GetHost() helper and check its validity too
This is similar to the previous commit and is done for the same reasons,
but adds checks verifying that CefBrowserHost is valid before using it.
2023-09-06 03:50:34 +02:00
Vadim Zeitlin
09214df74c Add GetMainFrame() helper and check that it's valid
Avoid crashes if some functions are called before the browser is fully
initialized -- this is relatively likely to happen as the existing code
may not wait for wxEVT_WEBVIEW_CREATED before calling them, as must be
done with wxWebViewChromium.
2023-09-06 03:50:34 +02:00
Vadim Zeitlin
92f6f164b3 Add wxEVT_WEBVIEW_CREATED for wxWebViewChromium async creation
wxWebViewChromium creation is asynchronous and the object can't be
really used until OnAfterCreated() is called, so expose this in the
public API via a new event sent when the object becomes actually usable.

As a side effect, add a convenient wxWebViewEvent ctor taking wxWebView
as argument and calling SetEventObject() itself, instead of forcing all
code creating wxWebViewEvents to do it.
2023-09-06 03:50:34 +02:00
Vadim Zeitlin
f1734a29b6 Use compiler-generated wxWebViewEvent default ctor
No real changes, just let the compiler do what it does best and generate
the code for us instead of writing "{}" explicitly.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
704e5f1419 Improve CEF detection in configure
Check for the libraries too and not just for headers.

Also cache the result of the check.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
08d6fe059b Update CEF requirements for the current version
Also don't use "CEF3" any more as "CEF1" doesn't really exist by now any
longer and there is only a single version of CEF.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
b4380b5f9e Use C++14 by default in configure when using CEF
Don't default to C++11 as CEF headers are not compatible with it, so
configure would succeed but the build would then fail.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
7aec5a7e62 Implement browser window resizing correctly under Mac too
While the window was somehow resized on its own under Mac (and only
there) after the initial creation, it didn't have the correct size
initially if we didn't give it to it, so provide a Mac-specific
implementation of wxEVT_SIZE handler too, which fixes this and allows to
remove an ugly Mac-specific workaround from the sample.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
0dffac1829 Add private header for wxWebViewChromium Mac-specific functions
Instead of just declaring the function inline in the common code, do it
in a header included from both common C++ and Mac Objective C++ sources.

No real changes.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
88b0a10f73 Avoid potential crash on shutdown under Mac
We can't wait for OnBeforeClose() to be called in the dtor there, or,
IOW, we can't count on it being called before the object is destroyed
and hence we can't update the flag in it neither.

Don't do it and just hope that the ClientHandler object always gets
destroyed soon after wxWebViewChromium itself anyhow because it's only
referenced by an autorelease pool.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
478975695f Fix compilation of CefAppProtocol-patching code
It's not clear if this really should be doing something as previously
existing code definitely didn't, but it seems like actually storing the
flag should be no worse and at least now it compiles (due to the added
casts to IMP).
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
db255db61c Use C++11 nullptr in CEF helper process in the sample
This fixes its compilation under Mac and also avoids triggering the
check forbidding the use of NULL in the new code.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
dfe4fc858f Add x64 support and improve wxWebViewChromium sample MSVS project
Use variables defined in our .props files instead of hard-coded values
and use DPI aware manifest instead of using "compatibility" one with
which the sample didn't work correctly in high DPI.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
6b04c6ca49 Add CEF includes to x64 configs in wxWebViewChromium MSVS project
This was only done for Win32 configurations before.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
4395a47d40 Remove redundant wxWebViewChromium forward declaration
There is no need to do it just before the full class declaration.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
013940da8f Move ClientHandler to wxCEF namespace
Use "wxCEF" prefix for this class to avoid any conflicts by using
non-wx-prefixed name.

Also replace wxWebViewChromiumImplData with wxCEF::ImplData as this is
shorter and more consistent with ClientHandler.

Finally stop using anonymous namespace for wxBrowserProcessHandler and
wxCefApp, as we can now put them into the same wxCEF namespace.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
e5e727747b Improve waiting for browser close to avoid crash on shutdown
Ensure that CefLifeSpanHandler::OnBeforeClose() is called before
returning from wxWebViewChromium dtor, as otherwise we may try to shut
down CEF before the browser object is destroyed.

Under MSW it's enough to destroy the window ourselves to make this
happen, but under GTK/X11 we need to manually pump the messages, as
OnBeforeClose() is only called when the X event notifying about the
actual window destruction arrives.

Also make the code cleaner by using flags in wxWebViewChromiumImplData
instead of reusing m_clientHandler pointer to indicate that DoClose()
was called.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
ed131c9364 Improve work scheduling logic
Restart the timer if it's already running but its expiration time is
beyond the specified delay, otherwise we could be waiting for too long.

This commit is best viewed ignoring whitespace-only changes.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
dc92de0c3a Don't bother using DeferWindowPos() for resizing one window
This doesn't seem to be necessary, just call SetWindowPos() instead,
this is simpler and has the same effect.

No real changes.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
7dc4abd99f Add ClientHandler::GetWindowHandle() helper
No real changes, just move the code from wxWebViewChromium::OnSize() to
a reusable function.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
efe58535d1 Hide private wxWebViewChromium data into a private struct
No real changes, just a refactoring to make further changes simpler.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
f5e2af9a28 Make wxWebViewChromium work with wxGTK3 and X11
Make browser creation actually work by postponing it until the host
window is realized and so has a valid X11 Window.

Remove unnecessary code manually creating GTK widget and just use the
standard wxGTK wxWindow instead.

Add code for setting the visual compatible with CEF to avoid X11 errors,
see https://github.com/chromiumembedded/cef/issues/3564, with many
thanks to Jiří Janoušek for finding and solving this problem originally.

Adjust the sample to handle wxWebView::Create() failure (not very
gracefully, but still better than just crashing) and to avoid using it
until it is fully created.

Update documentation to mention GTK limitations.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
d3cc4678d5 Add entry hook mechanism and use it for Chromium helper processes
At least when using wxGTK Chromium helper process can't be executed once
GTK is initialized because doing this creates background threads and
Chromium code aborts if there are any threads running.

As we don't want to initialize CEF unconditionally before initializing
GTK in all applications (even those not using CEF), the only solution is
to detect if we need to run a Chromium helper process ourselves before
GTK initialization, i.e. before wxApp creation, which means that it
can't be done via the existing wxModule mechanism because modules are
initialized after creating the global application instance.

So add a way to hijack wxWidgets initialization entirely if some special
command line option (such as Chromium "--type=xxx") is specified and use
it in wxWebViewChromium to call CefExecuteProcess() before initializing
GTK or even wxWidgets itself -- as it won't be needed in a CEF helper
process anyhow.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
89987807df Remove superfluous semicolons from wxWebViewChromiumModule
No real changes, just avoid warnings in gcc pedantic mode.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
6762d5eaa5 Merge branch 'master' into webview-chromium
Merge the changes required by wxWebViewChromium, notably support for the
entry hooks and new wxDynamicLibrary::ListLoaded() Unix implementation.
2023-09-06 03:49:49 +02:00
Vadim Zeitlin
3861ad6b6d Merge branch 'init-data-refactor'
Refactor and improve command line arguments handling during
initialization.

See #23847.
2023-09-06 02:46:51 +02:00
Joan Bruguera Micó
952de605f6 Handle map/unmap events on Wayland's wxGLCanvasEGL
Fixes hiding a wxGLCanvas on Wayland, either directly (`->Show(false)`)
or indirectly (e.g. when it is contained in a wxNotebook).

On Wayland, unlike on X11, to show the canvas on the screen, we need to
create a Wayland subsurface. This subsurface is detached from the GTK
widget associated to the canvas, thus it is not automatically mapped or
unmapped when the associated GTK widget is.
Rather, we need to manually keep it in sync with the widget's state.

Knowing what has to be done to map and unmap the canvas, while dealing
with edge cases properly, is not easy to someone not used to Wayland.
When the canvas is mapped, we have this graph of resources:

  EGL Surface (m_surface)
             |
             |
             v
  wl_egl window (m_wlEGLWindow)
             |
             |
             v
     Canvas wl_surface         GDK's toplevel window wl_surface
       (m_wlSurface)        (gdk_wayland_window_get_wl_surface(w))
              \                   which is shown to the user
               \                         ^
                \                       /
                 \                     /
                  v                   /
          Subsurface (m_wlSubsurface) to overlay
          the canvas onto the toplevel window

A simple way would be to destroy everything (m_surface, m_wlEGLWindow,
m_wlSurface, m_wlSubsurface) on unmap, and re-create it again on map.
Inefficiencies aside, this mostly works. However, it can mess with the
current OpenGL context. For example, suppose we have a (fragile)
program that places a canvas inside one of wxNotebook's tabs, and makes
the OpenGL context current only once at startup (e.g. on wxEVT_SHOW).
Switching between tabs will destroy and re-create the EGL Surface, so
the canvas will not be properly rendered when going back to its tab.

So we need to be smarter, and find some way to hide the subsurface
instead. The obvious way would be to unmap the canvas wl_surface
(m_wlSurface), as according to the Wayland spec., "a sub-surface is
hidden [...] if a NULL wl_buffer is applied [to the canvas surface]."
(https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_subsurface)
However, as far as I can tell, this can't be done. There's no API to
hide an wl_egl window, and directly applying a NULL wl_buffer to the
canvas surface initially hides it, but seems to breaks the associated
window so that it crashes when one attempts to show it again.

So what remains, is destroying the overlay subsurface (m_wlSubsurface).
When doing it, to the spec, "the wl_surface is unmapped immediately.".

And not only does this work, but it also deals with the annoying fact
that on current GTK3 versions, when the GDK's toplevel window is
unmapped, its wl_surface is not just unmapped, but entirely destroyed.
(Side note: This may not have been intended, and has been changed for
GTK4, see: 5d3cec5441)
So we'd have to re-create the subsurface because of this anyway.

So, this works nicely, and as far as I can tell (documentation is a bit
scarce), there's no problem to leaving m_wlSurface (and its associated
m_wlEGLWindow and m_surface) unmapped in this way.

Fixes #22580.

Closes #23835.
2023-09-06 02:45:03 +02:00
Joan Bruguera Micó
19936c2176 Don't clobber std::string_view equality with char *
Make the wxString(std::string_view) constructor explicit.

Otherwise, when comparing a std::string_view with a const char *, the
cast to wxString will be considered as a candidate for the comparison,
ultimately causing an "ambiguous overload for 'operator=='" error.

For example, this sample only builds if the constructor is explicit:

  #include <wx/string.h>
  #include <string_view>

  int main() {
    std::string_view view = "abc";
    const char *str = "abc";
    return view == str;
  }

However, making the constructor explicit will break assignment:

    std::string_view view = "abc";
    wxString s;
    s = view; // Error: no match for "operator="

That we can fix by implementing operator=(std::string_view)

That, however, introduces another ambiguity:

    std::string str = "abc";
    wxString s;
    s = str; // Ambiguous between s = wxString(str)
                              and s = std::string_view(str)

That we can fix by implementing operator=(std::string)

Finally, note that some rather obscure ambiguities remain, such as:

    wxString s;
    s = {"abc", 2}; // Ambiguous between s = wxString("abc", 2)
                                     and s = std::string_view("abc", 2)

Avoiding them is not simple (https://cplusplus.github.io/LWG/issue2946)
and doesn't add much value.

Closes #23834.
2023-09-06 02:44:11 +02:00
Vadim Zeitlin
b3cfab1433 Merge branch 'msw-dont-preprocess-unknown'
Don't preprocess messages for unknown windows in wxMSW.

See #23824.
2023-09-06 02:41:08 +02:00