1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-21 01:24:21 +00:00

Merge branch 'develop' into feature/linux_webview_handleJavascriptEvaluationCallback_jassert_fix

This commit is contained in:
kaz saita 2025-12-17 10:25:32 +09:00 committed by GitHub
commit d05224a91f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
110 changed files with 1144 additions and 1025 deletions

View file

@ -264,6 +264,44 @@ public:
JUCE_DECLARE_SINGLETON_SINGLETHREADED_MINIMAL_INLINE (WebKitSymbols)
private:
struct DylibHandle
{
DylibHandle() = default;
explicit DylibHandle (const char* str)
: DylibHandle (str, RTLD_NOW | RTLD_LOCAL) {}
DylibHandle (const char* str, int flags)
: handle (dlopen (str, flags)) {}
~DylibHandle()
{
if (handle != nullptr)
dlclose (handle);
}
DylibHandle (DylibHandle&& other) noexcept
: handle (std::exchange (other.handle, nullptr)) {}
DylibHandle& operator= (DylibHandle&& other) noexcept
{
auto local = std::move (other);
std::swap (local.handle, handle);
return *this;
}
void* getFunction (const char* name) const
{
jassert (handle != nullptr);
return dlsym (handle, name);
}
explicit operator bool() const { return handle != nullptr; }
private:
void* handle = nullptr;
};
WebKitSymbols() = default;
~WebKitSymbols()
@ -285,7 +323,7 @@ private:
}
template <typename FuncPtr>
bool loadSymbols (DynamicLibrary& lib, SymbolBinding<FuncPtr> binding)
bool loadSymbols (DylibHandle& lib, SymbolBinding<FuncPtr> binding)
{
if (auto* func = lib.getFunction (binding.name))
{
@ -297,7 +335,7 @@ private:
}
template <typename FuncPtr, typename... Args>
bool loadSymbols (DynamicLibrary& lib, SymbolBinding<FuncPtr> binding, Args... args)
bool loadSymbols (DylibHandle& lib, SymbolBinding<FuncPtr> binding, Args... args)
{
return loadSymbols (lib, binding) && loadSymbols (lib, args...);
}
@ -395,20 +433,24 @@ private:
bool openWebKitAndDependencyLibraries (const WebKitAndDependencyLibraryNames& names)
{
if (webkitLib.open (names.webkitLib) && jsLib.open (names.jsLib) && soupLib.open (names.soupLib))
if ( (webkitLib = DylibHandle (names.webkitLib, RTLD_NOW | RTLD_LOCAL | RTLD_NODELETE))
&& (jsLib = DylibHandle (names.jsLib))
&& (soupLib = DylibHandle (names.soupLib)))
{
return true;
}
for (auto* l : { &webkitLib, &jsLib, &soupLib })
l->close();
*l = {};
return false;
}
//==============================================================================
DynamicLibrary webkitLib, jsLib, soupLib;
DylibHandle webkitLib, jsLib, soupLib;
DynamicLibrary gtkLib { "libgtk-3.so" },
glib { "libglib-2.0.so" };
DylibHandle gtkLib { "libgtk-3.so" },
glib { "libglib-2.0.so" };
const bool webKitIsAvailable = ( openWebKitAndDependencyLibraries ({ "libwebkit2gtk-4.1.so",
"libjavascriptcoregtk-4.1.so",
@ -915,14 +957,14 @@ public:
if (response->resource.has_value())
{
auto* streamBytes = wk.juce_g_bytes_new (response->resource->data.data(),
static_cast<gsize> (response->resource->data.size()));
static_cast<gsize> (response->resource->data.size()));
ScopeGuard bytesScope { [&] { wk.juce_g_bytes_unref (streamBytes); } };
auto* stream = wk.juce_g_memory_input_stream_new_from_bytes (streamBytes);
ScopeGuard streamScope { [&] { wk.juce_g_object_unref (stream); } };
auto* webkitResponse = wk.juce_webkit_uri_scheme_response_new (stream,
static_cast<gint64> (response->resource->data.size()));
static_cast<gint64> (response->resource->data.size()));
ScopeGuard webkitResponseScope { [&] { wk.juce_g_object_unref (webkitResponse); } };
wk.juce_soup_message_headers_append (headers, "Content-Type", response->resource->mimeType.toRawUTF8());
@ -994,52 +1036,48 @@ public:
WebKitNavigationAction* action,
WebKitPolicyDecision* decision)
{
if (decision != nullptr && frameName.isEmpty())
{
WebKitSymbols::getInstance()->juce_g_object_ref (decision);
decisions.add (decision);
if (decision == nullptr || ! frameName.isEmpty())
return false;
DynamicObject::Ptr params = new DynamicObject;
WebKitSymbols::getInstance()->juce_g_object_ref (decision);
decisions.add (decision);
params->setProperty ("url", getURIStringForAction (action));
params->setProperty ("decision_id", (int64) decision);
CommandReceiver::sendCommand (outChannel, "pageAboutToLoad", var (params.get()));
DynamicObject::Ptr params = new DynamicObject;
return true;
}
params->setProperty ("url", getURIStringForAction (action));
params->setProperty ("decision_id", (int64) decision);
CommandReceiver::sendCommand (outChannel, "pageAboutToLoad", var (params.get()));
return false;
return true;
}
bool onNewWindow (String /*frameName*/,
WebKitNavigationAction* action,
WebKitPolicyDecision* decision)
{
if (decision != nullptr)
{
DynamicObject::Ptr params = new DynamicObject;
if (decision == nullptr)
return false;
params->setProperty ("url", getURIStringForAction (action));
CommandReceiver::sendCommand (outChannel, "newWindowAttemptingToLoad", var (params.get()));
DynamicObject::Ptr params = new DynamicObject;
// never allow new windows
WebKitSymbols::getInstance()->juce_webkit_policy_decision_ignore (decision);
params->setProperty ("url", getURIStringForAction (action));
CommandReceiver::sendCommand (outChannel, "newWindowAttemptingToLoad", var (params.get()));
return true;
}
// never allow new windows
WebKitSymbols::getInstance()->juce_webkit_policy_decision_ignore (decision);
return false;
return true;
}
void onLoadChanged (WebKitLoadEvent loadEvent)
{
if (loadEvent == WEBKIT_LOAD_FINISHED)
{
DynamicObject::Ptr params = new DynamicObject;
if (loadEvent != WEBKIT_LOAD_FINISHED)
return;
params->setProperty ("url", String (WebKitSymbols::getInstance()->juce_webkit_web_view_get_uri (webview)));
CommandReceiver::sendCommand (outChannel, "pageFinishedLoading", var (params.get()));
}
DynamicObject::Ptr params = new DynamicObject;
params->setProperty ("url", String (WebKitSymbols::getInstance()->juce_webkit_web_view_get_uri (webview)));
CommandReceiver::sendCommand (outChannel, "pageFinishedLoading", var (params.get()));
}
bool onDecidePolicy (WebKitPolicyDecision* decision,
@ -1202,7 +1240,7 @@ private:
return;
}
const auto jsValueResult = [&]() -> std::tuple<std::optional<var>, String>
const auto jsValueResult = std::invoke ([&]() -> std::tuple<std::optional<var>, String>
{
auto* jsValue = wk.juce_webkit_javascript_result_get_js_value (jsResult.get());
@ -1210,7 +1248,7 @@ private:
return { std::nullopt, String{} };
return { fromJSCValue (jsValue), String{} };
}();
});
owner->handleEvaluationCallback (std::get<0> (jsValueResult), std::get<1> (jsValueResult));
}
@ -1320,7 +1358,7 @@ public:
return;
}
const auto result = [&]
const auto result = std::invoke ([&]
{
using Error = EvaluationResult::Error;
@ -1333,7 +1371,7 @@ public:
}
return EvaluationResult { params->hasPayload ? params->payload : var::undefined() };
}();
});
auto& cb = evaluationCallbacks.front();
cb (result);
@ -1394,14 +1432,14 @@ public:
return;
}
receiver.reset (new CommandReceiver (this, inChannel));
receiver = std::make_unique<CommandReceiver> (static_cast<Responder*> (this), inChannel);
pfds.push_back ({ threadControl[0], POLLIN, 0 });
pfds.push_back ({ receiver->getFd(), POLLIN, 0 });
startThread();
xembed.reset (new XEmbedComponent (windowHandle));
xembed = std::make_unique<XEmbedComponent> (windowHandle);
browser.addAndMakeVisible (xembed.get());
}
@ -1492,7 +1530,7 @@ private:
kill (childProcess, SIGTERM);
waitpid (childProcess, &status, 0);
if (WIFEXITED (status))
if (WIFEXITED (status) || WIFSIGNALED (status) || WIFSTOPPED (status))
break;
}
}