Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Eto.Gtk webview crashing with webkit2gtk-4.1 #2482

Merged
merged 2 commits into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Eto.Gtk/Eto.Gtk.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<RootNamespace>Eto.GtkSharp</RootNamespace>
<DefineConstants>$(DefineConstants);GTK3;GTKCORE</DefineConstants>
Expand Down
1 change: 1 addition & 0 deletions src/Eto.Gtk/Forms/Controls/TextAreaHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Eto.Forms;
using Eto.Drawing;
using Eto.GtkSharp.Drawing;
using Range = Eto.Forms.Range;

namespace Eto.GtkSharp.Forms.Controls
{
Expand Down
77 changes: 76 additions & 1 deletion src/Eto.Gtk/NativeMethods.cs
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


using System;
using System.Runtime.InteropServices;
using System.Text;
Expand Down Expand Up @@ -32,6 +32,31 @@ public struct FcFontSet

static class NMWindows
{

#if NETCOREAPP

static NMWindows()
{
NativeLibrary.SetDllImportResolver(typeof(NMWindows).Assembly, (name, assembly, path) =>
{
// Use custom import resolver for libwebkit2gtk
// Try loading 4.1 first, if that fails, return to default handling
if (name == libwebkit)
{
IntPtr result = IntPtr.Zero;
if (!NativeLibrary.TryLoad("libwebkit2gtk-4.1.so.0", assembly, path, out result))
{
return IntPtr.Zero;
}

return result;
}

return IntPtr.Zero;
});
}
#endif

#if GTK2
const string plat = "win32-";
#elif GTK3
Expand Down Expand Up @@ -226,6 +251,31 @@ static class NMWindows

static class NMLinux
{

#if NETCOREAPP

static NMLinux()
{
NativeLibrary.SetDllImportResolver(typeof(NMLinux).Assembly, (name, assembly, path) =>
{
// Use custom import resolver for libwebkit2gtk
// Try loading 4.1 first, if that fails, return to default handling
if (name == libwebkit)
{
IntPtr result = IntPtr.Zero;
if (!NativeLibrary.TryLoad("libwebkit2gtk-4.1.so.0", assembly, path, out result))
{
return IntPtr.Zero;
}

return result;
}

return IntPtr.Zero;
});
}
#endif

#if GTK2
const string plat = "x11-";
#elif GTK3
Expand Down Expand Up @@ -420,6 +470,31 @@ static class NMLinux

static class NMMac
{

#if NETCOREAPP

static NMMac()
{
NativeLibrary.SetDllImportResolver(typeof(NMMac).Assembly, (name, assembly, path) =>
{
// Use custom import resolver for libwebkit2gtk
// Try loading 4.1 first, if that fails, return to default handling
if (name == libwebkit)
{
IntPtr result = IntPtr.Zero;
if (!NativeLibrary.TryLoad("libwebkit2gtk-4.1.so.0", assembly, path, out result))
{
return IntPtr.Zero;
}

return result;
}

return IntPtr.Zero;
});
}
#endif

#if GTK2
const string plat = "quartz-";
#elif GTK3
Expand Down
25 changes: 25 additions & 0 deletions src/Eto.Gtk/NativeMethods.tt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,31 @@ namespace Eto.GtkSharp

static class <#= pclass[i] #>
{

#if NETCOREAPP

static <#= pclass[i] #>()
{
NativeLibrary.SetDllImportResolver(typeof(<#= pclass[i] #>).Assembly, (name, assembly, path) =>
{
// Use custom import resolver for libwebkit2gtk
// Try loading 4.1 first, if that fails, return to default handling
if (name == libwebkit)
{
IntPtr result = IntPtr.Zero;
if (!NativeLibrary.TryLoad("libwebkit2gtk-4.1.so.0", assembly, path, out result))
{
return IntPtr.Zero;
}

return result;
}

return IntPtr.Zero;
});
}
#endif

#if GTK2
const string plat = "<#= plat[i] #>";
#elif GTK3
Expand Down
2 changes: 1 addition & 1 deletion test/Eto.Test/Eto.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>$(DefineConstants);PCL</DefineConstants>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Text;
using System.IO;
using Range = Eto.Forms.Range;

namespace Eto.Test.UnitTests.Forms.Controls
{
Expand Down
1 change: 1 addition & 0 deletions test/Eto.Test/UnitTests/Forms/Controls/TextAreaTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Eto.Forms;
using NUnit.Framework;
using Range = Eto.Forms.Range;

namespace Eto.Test.UnitTests.Forms.Controls
{
Expand Down
1 change: 1 addition & 0 deletions test/Eto.Test/UnitTests/Forms/Controls/TextBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Eto.Forms;
using System.Threading.Tasks;
using System.Collections.Generic;
using Range = Eto.Forms.Range;

namespace Eto.Test.UnitTests.Forms.Controls
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using Eto.Forms;
using NUnit.Framework;
using Range = Eto.Forms.Range;

namespace Eto.Test.UnitTests.Forms.Controls
{
Expand Down