From 9a8c741a6f89a6a80f62d427c6d4b2f578cc45a8 Mon Sep 17 00:00:00 2001 From: badcel <1218031+badcel@users.noreply.github.com> Date: Wed, 11 Jan 2023 15:13:28 +0100 Subject: [PATCH] Add WebKit2 --- docs/docs/libraries.md | 24 +++-- readme.md | 20 ++-- src/GenerateLibs.fsx | 30 +++--- src/GirCore.sln | 93 +++++++++++++++++++ .../JavaScriptCore-5.0.csproj | 11 +++ src/Libs/JavaScriptCore-5.0/Public/Module.cs | 19 ++++ src/Libs/Soup-3.0/Public/Module.cs | 19 ++++ src/Libs/Soup-3.0/Soup-3.0.csproj | 11 +++ src/Libs/WebKit2-5.0/Public/Module.cs | 21 +++++ .../WebKit2-5.0/Public/UserContentManager.cs | 27 ++++++ src/Libs/WebKit2-5.0/Public/UserScript.cs | 12 +++ src/Libs/WebKit2-5.0/Public/WebView.cs | 27 ++++++ src/Libs/WebKit2-5.0/WebKit2-5.0.csproj | 13 +++ .../WebKit2WebExtension-5.0/Public/Module.cs | 21 +++++ .../WebKit2WebExtension-5.0.csproj | 13 +++ .../JavascriptCall/JavascriptCall.csproj | 14 +++ .../WebKit2-5.0/JavascriptCall/Program.cs | 46 +++++++++ .../JavascriptCallback.csproj | 14 +++ .../WebKit2-5.0/JavascriptCallback/Program.cs | 51 ++++++++++ 19 files changed, 456 insertions(+), 30 deletions(-) create mode 100644 src/Libs/JavaScriptCore-5.0/JavaScriptCore-5.0.csproj create mode 100644 src/Libs/JavaScriptCore-5.0/Public/Module.cs create mode 100644 src/Libs/Soup-3.0/Public/Module.cs create mode 100644 src/Libs/Soup-3.0/Soup-3.0.csproj create mode 100644 src/Libs/WebKit2-5.0/Public/Module.cs create mode 100644 src/Libs/WebKit2-5.0/Public/UserContentManager.cs create mode 100644 src/Libs/WebKit2-5.0/Public/UserScript.cs create mode 100644 src/Libs/WebKit2-5.0/Public/WebView.cs create mode 100644 src/Libs/WebKit2-5.0/WebKit2-5.0.csproj create mode 100644 src/Libs/WebKit2WebExtension-5.0/Public/Module.cs create mode 100644 src/Libs/WebKit2WebExtension-5.0/WebKit2WebExtension-5.0.csproj create mode 100644 src/Samples/WebKit2-5.0/JavascriptCall/JavascriptCall.csproj create mode 100644 src/Samples/WebKit2-5.0/JavascriptCall/Program.cs create mode 100644 src/Samples/WebKit2-5.0/JavascriptCallback/JavascriptCallback.csproj create mode 100644 src/Samples/WebKit2-5.0/JavascriptCallback/Program.cs diff --git a/docs/docs/libraries.md b/docs/docs/libraries.md index 75b0047a8..19b6feef9 100644 --- a/docs/docs/libraries.md +++ b/docs/docs/libraries.md @@ -1,6 +1,6 @@ # Libraries -Currently there are multiple libraries planned to be integrated deeply into linux: [Gtk], [WebkitGTK], [libshumate] [libadwaita], [GIO], [gstreamer]. +Currently there are multiple libraries available to get started with C# development for Linux: [Gtk], [WebkitGTK], [libshumate] [libadwaita], [GIO], [gstreamer]. ## GTK [Gtk] is the toolkit which is used to display windows and widgets on the screen. The widgets can be added directly in code or described through an xml file. @@ -9,26 +9,34 @@ Supported widgets are for example: Windows, dialogs, labels, images, spinner, pr ![A picture of an example gtk application][GtkApp] +Visit the [GTK samples](https://github.com/gircore/gir.core/tree/main/src/Samples/Gtk-4.0) to get an overview. + ## libadwaita [libadwaita] extends GTK with new widgets to comply to the GNOME human interface guidelines. Additionally it supports mobile devices meaning full blown applications automatically adopt their UI to different view modes, if the available space changes. +Visit the [libadwaita samples](https://github.com/gircore/gir.core/tree/main/src/Samples/Adw-1/) to get an overview. + ## GIO [GIO] is a library to allow easy access to input / output operations. Currently there is initial support for [DBus] operations. DBus is a standardized IPC-Framework which all major linux desktops use for interprocess communication. -## Gstreamer -[Gstreamer] is a multimedia library to play back various media format via a flexible pipelining system. The code to playback a movie is in the [samples](https://github.com/gircore/gir.core/blob/develop/Samples/GStreamer/Play.cs). +Visit the [GIO samples](https://github.com/gircore/gir.core/tree/main/src/Samples/Gio-2.0/) to get an overview. + +## GStreamer +[GStreamer] is a multimedia library to play back various media format via a flexible pipelining system. ![A picture of the Tears of Steel project played via gstreamer][GstSintel] (Homepage of the free movie: https://mango.blender.org/) -## WebkitGTK (planned) -[WebkitGTK] is a browser component for GTK and can be used to embed the webkit webengine into an application as a widget. There is support for the web inspector and several settings to tweak the webview to your needs. +Visit the [GStreamer samples](https://github.com/gircore/gir.core/tree/main/src/Samples/Gst-1.0/) to get an overview. + +## WebKitGTK +[WebKitGTK] is a browser component for GTK and can be used to embed the webkit webengine into an application as a widget. There is support for the web inspector and several settings to tweak the webview to your needs. WebKitGTK only supports Linux. The bindings make it easy to: * Embed javascript into a webpage * Call a javascript function * Callback from the webpage into the C# code. -![A picture of an example gtk application with visible webpage][GtkAppBrowser] +Visit the [WebKit samples](https://github.com/gircore/gir.core/tree/main/src/Samples/WebKit2-5.0/) to get an overview. ## libshumate (planned) [libshumate] is map component for GTK and can be used to embed maps into an application widget. By default it uses openstreetmap. @@ -37,12 +45,12 @@ The bindings make it easy to: [GIO]: https://developer.gnome.org/gio/stable/ [libadwaita]: https://gitlab.gnome.org/GNOME/libadwaita [libshumate]: https://gitlab.gnome.org/GNOME/libshumate/ -[WebkitGTK]: https://webkitgtk.org/ +[WebKitGTK]: https://webkitgtk.org/ [Gtk]: https://gtk.org [Gimp]: https://gimp.org [Gnome]: https://gnome.org [Xfce]: https://xfce.org -[Gstreamer]: https://gstreamer.freedesktop.org/ +[GStreamer]: https://gstreamer.freedesktop.org/ [GtkApp]: img/GtkApp.png "Example GtkApp" [GstSintel]: img/GstSintel.png "Gstreamer playing back Tears of Steel (https://mango.blender.org/)" \ No newline at end of file diff --git a/readme.md b/readme.md index e02c7d569..1e676bf62 100644 --- a/readme.md +++ b/readme.md @@ -16,7 +16,7 @@ This project aims to provide a complete set of APIs for writing rich cross-platf * **Extensibility:** Allows 3rd party developers to write bindings for other GObject-based libraries, achieving full interoperability between them. ## Status -We are currently in a period of heavy iteration over the core internals of the project. The code is under heavy development and not ready for production. There are some pre release nuget packages available for testing purposes. Feel free to visit the [nuget organization][GirCoreNuget] to get an overview. +The code is under development and not ready for production use. There are nuget packages available. The API is subject to change as long as version 1.0 is not released. Feel free to visit the [nuget organization][GirCoreNuget] to get an overview. ## Supported Libraries @@ -30,8 +30,8 @@ We are currently in a period of heavy iteration over the core internals of the p | [Gio-2.0][GioNuget] | Library for high level application functionality | Partial | | [GdkPixbuf-2.0][GdkPixbufNuget] | Image loading in various formats | Partial | | libshumate | Library to display maps | Planned | -| WebKitGTK | Browser Engine | [Planned](https://github.com/gircore/gir.core/issues/568) | -| JavaScriptCore | JavaScript engine for WebKit | Planned | +| [WebKit2-5.0][WebKit2Nuget] | Browser engine (Linux only) | Partial | +| [JavaScriptCore-5.0][JavaScriptCoreNuget] | JavaScript engine for WebKit (Linux only) | Partial | ## Get Involved @@ -72,21 +72,23 @@ The code in the library folder is not complete because most of the code is gener [GIO]: https://developer.gnome.org/gio/stable/ [GObject]: https://developer.gnome.org/gobject/stable/ [GTK]: https://gtk.org/ -[libhandy]: https://source.puri.sm/Librem5/libhandy +[libhandy]: https://source.puri.sm/Librem5/libhandy/ [WebKitGTK]: https://webkitgtk.org/ [JavaScriptCore]: https://webkitgtk.org/reference/jsc-glib/stable/index.html [dbus]: https://www.freedesktop.org/wiki/Software/dbus/ -[libchamplain]: https://wiki.gnome.org/Projects/libchamplain -[GtkSharp]: https://github.com/GtkSharp/GtkSharp -[GdkPixbuf]: https://gitlab.gnome.org/GNOME/gdk-pixbuf -[GirCoreNuget]: https://www.nuget.org/profiles/GirCore +[libchamplain]: https://wiki.gnome.org/Projects/libchamplain/ +[GtkSharp]: https://github.com/GtkSharp/GtkSharp/ +[GdkPixbuf]: https://gitlab.gnome.org/GNOME/gdk-pixbuf/ +[GirCoreNuget]: https://www.nuget.org/profiles/GirCore/ [Gtk4Nuget]: https://www.nuget.org/packages/GirCore.Gtk-4.0/ [GstNuget]: https://www.nuget.org/packages/GirCore.Gst-1.0/ [CairoNuget]: https://www.nuget.org/packages/GirCore.Cairo-1.0/ [PangoNuget]: https://www.nuget.org/packages/GirCore.Pango-1.0/ [GioNuget]: https://www.nuget.org/packages/GirCore.Gio-2.0/ [GdkPixbufNuget]: https://www.nuget.org/packages/GirCore.GdkPixbuf-2.0/ -[LibadwaitaNuget]: https://www.nuget.org/packages/GirCore.Adw-1 +[LibadwaitaNuget]: https://www.nuget.org/packages/GirCore.Adw-1/ +[WebKit2Nuget]: https://www.nuget.org/packages/GirCore.WebKit2-5.0/ +[JavaScriptCoreNuget]: https://www.nuget.org/packages/GirCore.JavaScriptCore-5.0/ ## Licensing terms Gir.Core is licensed under the terms of the MIT-License. Please see the [license file](license.txt) for further information. diff --git a/src/GenerateLibs.fsx b/src/GenerateLibs.fsx index e27a7cea4..473c1826b 100644 --- a/src/GenerateLibs.fsx +++ b/src/GenerateLibs.fsx @@ -3,25 +3,29 @@ open SimpleExec let girFiles = [| - "GLib-2.0.gir" - "GObject-2.0.gir" - "Gio-2.0.gir" + "Adw-1.gir" "cairo-1.0.gir" - "Pango-1.0.gir" - "HarfBuzz-0.0.gir" + "freetype2-2.0.gir" + "Gdk-4.0.gir" "GdkPixbuf-2.0.gir" + "Gio-2.0.gir" + "GLib-2.0.gir" + "GObject-2.0.gir" + "Graphene-1.0.gir" + "Gsk-4.0.gir" "Gst-1.0.gir" - "GstBase-1.0.gir" - "GstVideo-1.0.gir" "GstAudio-1.0.gir" + "GstBase-1.0.gir" "GstPbutils-1.0.gir" - "PangoCairo-1.0.gir" - "Gdk-4.0.gir" - "Graphene-1.0.gir" - "Gsk-4.0.gir" + "GstVideo-1.0.gir" "Gtk-4.0.gir" - "Adw-1.gir" - "freetype2-2.0.gir" + "HarfBuzz-0.0.gir" + "JavaScriptCore-5.0.gir" + "Pango-1.0.gir" + "PangoCairo-1.0.gir" + "Soup-3.0.gir" + "WebKit2-5.0.gir" + "WebKit2WebExtension-5.0.gir" |] |> String.concat " " diff --git a/src/GirCore.sln b/src/GirCore.sln index 2e46fab9e..bd1877bb6 100644 --- a/src/GirCore.sln +++ b/src/GirCore.sln @@ -177,6 +177,20 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Window", "Samples\Adw-1\Win EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "freetype2-2.0", "Libs\freetype2-2.0\freetype2-2.0.csproj", "{29C4FE32-0609-45EE-9C16-E4E50CA66B81}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebKit2-5.0", "Libs\WebKit2-5.0\WebKit2-5.0.csproj", "{E9CC2642-BCA7-4BF6-9AE4-3B03C3A56FB3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JavaScriptCore-5.0", "Libs\JavaScriptCore-5.0\JavaScriptCore-5.0.csproj", "{BD15BF89-69FB-494F-890C-7FB9767C4E4B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebKit2WebExtension-5.0", "Libs\WebKit2WebExtension-5.0\WebKit2WebExtension-5.0.csproj", "{FA8F1775-0D58-4727-A168-6111773A43A3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Soup-3.0", "Libs\Soup-3.0\Soup-3.0.csproj", "{A464F066-1DA1-4A3C-B79E-2AA4B116D49E}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WebKit2-5.0", "WebKit2-5.0", "{825BF602-98A7-45E7-A2C9-9E68160B7DF3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JavascriptCall", "Samples\WebKit2-5.0\JavascriptCall\JavascriptCall.csproj", "{9670582B-4E32-48AA-B62B-DA659E6AB4A1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JavascriptCallback", "Samples\WebKit2-5.0\JavascriptCallback\JavascriptCallback.csproj", "{1AF16CCD-2220-4F60-A68F-622F186BEA8F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -694,6 +708,78 @@ Global {29C4FE32-0609-45EE-9C16-E4E50CA66B81}.Release|x64.Build.0 = Release|Any CPU {29C4FE32-0609-45EE-9C16-E4E50CA66B81}.Release|x86.ActiveCfg = Release|Any CPU {29C4FE32-0609-45EE-9C16-E4E50CA66B81}.Release|x86.Build.0 = Release|Any CPU + {E9CC2642-BCA7-4BF6-9AE4-3B03C3A56FB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E9CC2642-BCA7-4BF6-9AE4-3B03C3A56FB3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E9CC2642-BCA7-4BF6-9AE4-3B03C3A56FB3}.Debug|x64.ActiveCfg = Debug|Any CPU + {E9CC2642-BCA7-4BF6-9AE4-3B03C3A56FB3}.Debug|x64.Build.0 = Debug|Any CPU + {E9CC2642-BCA7-4BF6-9AE4-3B03C3A56FB3}.Debug|x86.ActiveCfg = Debug|Any CPU + {E9CC2642-BCA7-4BF6-9AE4-3B03C3A56FB3}.Debug|x86.Build.0 = Debug|Any CPU + {E9CC2642-BCA7-4BF6-9AE4-3B03C3A56FB3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E9CC2642-BCA7-4BF6-9AE4-3B03C3A56FB3}.Release|Any CPU.Build.0 = Release|Any CPU + {E9CC2642-BCA7-4BF6-9AE4-3B03C3A56FB3}.Release|x64.ActiveCfg = Release|Any CPU + {E9CC2642-BCA7-4BF6-9AE4-3B03C3A56FB3}.Release|x64.Build.0 = Release|Any CPU + {E9CC2642-BCA7-4BF6-9AE4-3B03C3A56FB3}.Release|x86.ActiveCfg = Release|Any CPU + {E9CC2642-BCA7-4BF6-9AE4-3B03C3A56FB3}.Release|x86.Build.0 = Release|Any CPU + {BD15BF89-69FB-494F-890C-7FB9767C4E4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BD15BF89-69FB-494F-890C-7FB9767C4E4B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BD15BF89-69FB-494F-890C-7FB9767C4E4B}.Debug|x64.ActiveCfg = Debug|Any CPU + {BD15BF89-69FB-494F-890C-7FB9767C4E4B}.Debug|x64.Build.0 = Debug|Any CPU + {BD15BF89-69FB-494F-890C-7FB9767C4E4B}.Debug|x86.ActiveCfg = Debug|Any CPU + {BD15BF89-69FB-494F-890C-7FB9767C4E4B}.Debug|x86.Build.0 = Debug|Any CPU + {BD15BF89-69FB-494F-890C-7FB9767C4E4B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BD15BF89-69FB-494F-890C-7FB9767C4E4B}.Release|Any CPU.Build.0 = Release|Any CPU + {BD15BF89-69FB-494F-890C-7FB9767C4E4B}.Release|x64.ActiveCfg = Release|Any CPU + {BD15BF89-69FB-494F-890C-7FB9767C4E4B}.Release|x64.Build.0 = Release|Any CPU + {BD15BF89-69FB-494F-890C-7FB9767C4E4B}.Release|x86.ActiveCfg = Release|Any CPU + {BD15BF89-69FB-494F-890C-7FB9767C4E4B}.Release|x86.Build.0 = Release|Any CPU + {FA8F1775-0D58-4727-A168-6111773A43A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FA8F1775-0D58-4727-A168-6111773A43A3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FA8F1775-0D58-4727-A168-6111773A43A3}.Debug|x64.ActiveCfg = Debug|Any CPU + {FA8F1775-0D58-4727-A168-6111773A43A3}.Debug|x64.Build.0 = Debug|Any CPU + {FA8F1775-0D58-4727-A168-6111773A43A3}.Debug|x86.ActiveCfg = Debug|Any CPU + {FA8F1775-0D58-4727-A168-6111773A43A3}.Debug|x86.Build.0 = Debug|Any CPU + {FA8F1775-0D58-4727-A168-6111773A43A3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FA8F1775-0D58-4727-A168-6111773A43A3}.Release|Any CPU.Build.0 = Release|Any CPU + {FA8F1775-0D58-4727-A168-6111773A43A3}.Release|x64.ActiveCfg = Release|Any CPU + {FA8F1775-0D58-4727-A168-6111773A43A3}.Release|x64.Build.0 = Release|Any CPU + {FA8F1775-0D58-4727-A168-6111773A43A3}.Release|x86.ActiveCfg = Release|Any CPU + {FA8F1775-0D58-4727-A168-6111773A43A3}.Release|x86.Build.0 = Release|Any CPU + {A464F066-1DA1-4A3C-B79E-2AA4B116D49E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A464F066-1DA1-4A3C-B79E-2AA4B116D49E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A464F066-1DA1-4A3C-B79E-2AA4B116D49E}.Debug|x64.ActiveCfg = Debug|Any CPU + {A464F066-1DA1-4A3C-B79E-2AA4B116D49E}.Debug|x64.Build.0 = Debug|Any CPU + {A464F066-1DA1-4A3C-B79E-2AA4B116D49E}.Debug|x86.ActiveCfg = Debug|Any CPU + {A464F066-1DA1-4A3C-B79E-2AA4B116D49E}.Debug|x86.Build.0 = Debug|Any CPU + {A464F066-1DA1-4A3C-B79E-2AA4B116D49E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A464F066-1DA1-4A3C-B79E-2AA4B116D49E}.Release|Any CPU.Build.0 = Release|Any CPU + {A464F066-1DA1-4A3C-B79E-2AA4B116D49E}.Release|x64.ActiveCfg = Release|Any CPU + {A464F066-1DA1-4A3C-B79E-2AA4B116D49E}.Release|x64.Build.0 = Release|Any CPU + {A464F066-1DA1-4A3C-B79E-2AA4B116D49E}.Release|x86.ActiveCfg = Release|Any CPU + {A464F066-1DA1-4A3C-B79E-2AA4B116D49E}.Release|x86.Build.0 = Release|Any CPU + {9670582B-4E32-48AA-B62B-DA659E6AB4A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9670582B-4E32-48AA-B62B-DA659E6AB4A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9670582B-4E32-48AA-B62B-DA659E6AB4A1}.Debug|x64.ActiveCfg = Debug|Any CPU + {9670582B-4E32-48AA-B62B-DA659E6AB4A1}.Debug|x64.Build.0 = Debug|Any CPU + {9670582B-4E32-48AA-B62B-DA659E6AB4A1}.Debug|x86.ActiveCfg = Debug|Any CPU + {9670582B-4E32-48AA-B62B-DA659E6AB4A1}.Debug|x86.Build.0 = Debug|Any CPU + {9670582B-4E32-48AA-B62B-DA659E6AB4A1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9670582B-4E32-48AA-B62B-DA659E6AB4A1}.Release|Any CPU.Build.0 = Release|Any CPU + {9670582B-4E32-48AA-B62B-DA659E6AB4A1}.Release|x64.ActiveCfg = Release|Any CPU + {9670582B-4E32-48AA-B62B-DA659E6AB4A1}.Release|x64.Build.0 = Release|Any CPU + {9670582B-4E32-48AA-B62B-DA659E6AB4A1}.Release|x86.ActiveCfg = Release|Any CPU + {9670582B-4E32-48AA-B62B-DA659E6AB4A1}.Release|x86.Build.0 = Release|Any CPU + {1AF16CCD-2220-4F60-A68F-622F186BEA8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1AF16CCD-2220-4F60-A68F-622F186BEA8F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1AF16CCD-2220-4F60-A68F-622F186BEA8F}.Debug|x64.ActiveCfg = Debug|Any CPU + {1AF16CCD-2220-4F60-A68F-622F186BEA8F}.Debug|x64.Build.0 = Debug|Any CPU + {1AF16CCD-2220-4F60-A68F-622F186BEA8F}.Debug|x86.ActiveCfg = Debug|Any CPU + {1AF16CCD-2220-4F60-A68F-622F186BEA8F}.Debug|x86.Build.0 = Debug|Any CPU + {1AF16CCD-2220-4F60-A68F-622F186BEA8F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1AF16CCD-2220-4F60-A68F-622F186BEA8F}.Release|Any CPU.Build.0 = Release|Any CPU + {1AF16CCD-2220-4F60-A68F-622F186BEA8F}.Release|x64.ActiveCfg = Release|Any CPU + {1AF16CCD-2220-4F60-A68F-622F186BEA8F}.Release|x64.Build.0 = Release|Any CPU + {1AF16CCD-2220-4F60-A68F-622F186BEA8F}.Release|x86.ActiveCfg = Release|Any CPU + {1AF16CCD-2220-4F60-A68F-622F186BEA8F}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {BF7F9B0B-CB43-4161-BFAD-C6EE479FC86B} = {386AE10F-B7AC-4C97-AC5C-202D3662A868} @@ -749,5 +835,12 @@ Global {98F22FA8-3E06-47D0-9516-64BDF61407D6} = {1F2E4087-585C-4B48-8E3D-700D949A15DB} {3647E5F6-E194-4CAD-B387-948CD90FD5DC} = {98F22FA8-3E06-47D0-9516-64BDF61407D6} {29C4FE32-0609-45EE-9C16-E4E50CA66B81} = {386AE10F-B7AC-4C97-AC5C-202D3662A868} + {E9CC2642-BCA7-4BF6-9AE4-3B03C3A56FB3} = {386AE10F-B7AC-4C97-AC5C-202D3662A868} + {BD15BF89-69FB-494F-890C-7FB9767C4E4B} = {386AE10F-B7AC-4C97-AC5C-202D3662A868} + {FA8F1775-0D58-4727-A168-6111773A43A3} = {386AE10F-B7AC-4C97-AC5C-202D3662A868} + {A464F066-1DA1-4A3C-B79E-2AA4B116D49E} = {386AE10F-B7AC-4C97-AC5C-202D3662A868} + {825BF602-98A7-45E7-A2C9-9E68160B7DF3} = {1F2E4087-585C-4B48-8E3D-700D949A15DB} + {9670582B-4E32-48AA-B62B-DA659E6AB4A1} = {825BF602-98A7-45E7-A2C9-9E68160B7DF3} + {1AF16CCD-2220-4F60-A68F-622F186BEA8F} = {825BF602-98A7-45E7-A2C9-9E68160B7DF3} EndGlobalSection EndGlobal diff --git a/src/Libs/JavaScriptCore-5.0/JavaScriptCore-5.0.csproj b/src/Libs/JavaScriptCore-5.0/JavaScriptCore-5.0.csproj new file mode 100644 index 000000000..1900df161 --- /dev/null +++ b/src/Libs/JavaScriptCore-5.0/JavaScriptCore-5.0.csproj @@ -0,0 +1,11 @@ + + + + + + + GirCore.JavaScriptCore-5.0 + JavaScriptCore + C# bindings for JavaScriptCore. + + diff --git a/src/Libs/JavaScriptCore-5.0/Public/Module.cs b/src/Libs/JavaScriptCore-5.0/Public/Module.cs new file mode 100644 index 000000000..41d809b00 --- /dev/null +++ b/src/Libs/JavaScriptCore-5.0/Public/Module.cs @@ -0,0 +1,19 @@ +namespace JavaScriptCore; + +public class Module +{ + private static bool IsInitialized; + + public static void Initialize() + { + if (IsInitialized) + return; + + GObject.Module.Initialize(); + + Internal.ImportResolver.RegisterAsDllImportResolver(); + Internal.TypeRegistration.RegisterTypes(); + + IsInitialized = true; + } +} diff --git a/src/Libs/Soup-3.0/Public/Module.cs b/src/Libs/Soup-3.0/Public/Module.cs new file mode 100644 index 000000000..54c25407f --- /dev/null +++ b/src/Libs/Soup-3.0/Public/Module.cs @@ -0,0 +1,19 @@ +namespace Soup; + +public class Module +{ + private static bool IsInitialized; + + public static void Initialize() + { + if (IsInitialized) + return; + + Gio.Module.Initialize(); + + Internal.ImportResolver.RegisterAsDllImportResolver(); + Internal.TypeRegistration.RegisterTypes(); + + IsInitialized = true; + } +} diff --git a/src/Libs/Soup-3.0/Soup-3.0.csproj b/src/Libs/Soup-3.0/Soup-3.0.csproj new file mode 100644 index 000000000..0075f6d5e --- /dev/null +++ b/src/Libs/Soup-3.0/Soup-3.0.csproj @@ -0,0 +1,11 @@ + + + + + + + GirCore.Soup-3.0 + Soup + C# bindings for Soup. + + diff --git a/src/Libs/WebKit2-5.0/Public/Module.cs b/src/Libs/WebKit2-5.0/Public/Module.cs new file mode 100644 index 000000000..bf526b81b --- /dev/null +++ b/src/Libs/WebKit2-5.0/Public/Module.cs @@ -0,0 +1,21 @@ +namespace WebKit2; + +public class Module +{ + private static bool IsInitialized; + + public static void Initialize() + { + if (IsInitialized) + return; + + Gtk.Module.Initialize(); + JavaScriptCore.Module.Initialize(); + Soup.Module.Initialize(); + + Internal.ImportResolver.RegisterAsDllImportResolver(); + Internal.TypeRegistration.RegisterTypes(); + + IsInitialized = true; + } +} diff --git a/src/Libs/WebKit2-5.0/Public/UserContentManager.cs b/src/Libs/WebKit2-5.0/Public/UserContentManager.cs new file mode 100644 index 000000000..9127b8165 --- /dev/null +++ b/src/Libs/WebKit2-5.0/Public/UserContentManager.cs @@ -0,0 +1,27 @@ +using System; + +namespace WebKit2; + +public partial class UserContentManager +{ + //TODO: Is this method obsolete and the users can write it themself? + //As JavaScriptResult is a record this method must be kept as long as public API for records is not generated + public bool RegisterScriptMessageHandler(string name, Action callback) + { + void OnMessageReceived(UserContentManager obj, ScriptMessageReceivedSignalArgs args) + { + var jsValue = Internal.JavascriptResult.GetJsValue(args.JsResult.Handle); + var value = GObject.Internal.ObjectWrapper.WrapHandle(jsValue, false); + + callback(value); + } + + ScriptMessageReceivedSignal.Connect(this, OnMessageReceived, false, name); + + if (RegisterScriptMessageHandler(name)) + return true; + + ScriptMessageReceivedSignal.Disconnect(this, OnMessageReceived); + return false; + } +} diff --git a/src/Libs/WebKit2-5.0/Public/UserScript.cs b/src/Libs/WebKit2-5.0/Public/UserScript.cs new file mode 100644 index 000000000..ed4b8fefd --- /dev/null +++ b/src/Libs/WebKit2-5.0/Public/UserScript.cs @@ -0,0 +1,12 @@ +using System; + +namespace WebKit2; + +public partial class UserScript +{ + //TODO: Should be generated automatically for records + public static UserScript New(string source, UserContentInjectedFrames injectedFrames, UserScriptInjectionTime injectionTime) + { + return new UserScript(Internal.UserScript.New(source, injectedFrames, injectionTime, IntPtr.Zero, IntPtr.Zero)); + } +} diff --git a/src/Libs/WebKit2-5.0/Public/WebView.cs b/src/Libs/WebKit2-5.0/Public/WebView.cs new file mode 100644 index 000000000..5d2eba27c --- /dev/null +++ b/src/Libs/WebKit2-5.0/Public/WebView.cs @@ -0,0 +1,27 @@ +using System; +using System.Threading.Tasks; + +namespace WebKit2; + +public partial class WebView +{ + //TODO: Async methods should be generated automatically + public Task RunJavascriptAsync(string script) + { + var tcs = new TaskCompletionSource(); + + void Callback(IntPtr sourceObject, IntPtr res, IntPtr userData) + { + var jsResult = Internal.WebView.RunJavascriptFinish(sourceObject, res, out var error); + GLib.Error.ThrowOnError(error); + + var jsValue = Internal.JavascriptResult.GetJsValue(jsResult); + var value = GObject.Internal.ObjectWrapper.WrapHandle(jsValue, false); + tcs.SetResult(value); + } + + Internal.WebView.RunJavascript(Handle, script, IntPtr.Zero, Callback, IntPtr.Zero); + + return tcs.Task; + } +} diff --git a/src/Libs/WebKit2-5.0/WebKit2-5.0.csproj b/src/Libs/WebKit2-5.0/WebKit2-5.0.csproj new file mode 100644 index 000000000..da76405ae --- /dev/null +++ b/src/Libs/WebKit2-5.0/WebKit2-5.0.csproj @@ -0,0 +1,13 @@ + + + + + + + + + GirCore.WebKit2-5.0 + WebKit2 + C# bindings for WebKit2. + + diff --git a/src/Libs/WebKit2WebExtension-5.0/Public/Module.cs b/src/Libs/WebKit2WebExtension-5.0/Public/Module.cs new file mode 100644 index 000000000..15cd74572 --- /dev/null +++ b/src/Libs/WebKit2WebExtension-5.0/Public/Module.cs @@ -0,0 +1,21 @@ +namespace WebKit2WebExtension; + +public class Module +{ + private static bool IsInitialized; + + public static void Initialize() + { + if (IsInitialized) + return; + + Gtk.Module.Initialize(); + JavaScriptCore.Module.Initialize(); + Soup.Module.Initialize(); + + Internal.ImportResolver.RegisterAsDllImportResolver(); + Internal.TypeRegistration.RegisterTypes(); + + IsInitialized = true; + } +} diff --git a/src/Libs/WebKit2WebExtension-5.0/WebKit2WebExtension-5.0.csproj b/src/Libs/WebKit2WebExtension-5.0/WebKit2WebExtension-5.0.csproj new file mode 100644 index 000000000..e955d7f8a --- /dev/null +++ b/src/Libs/WebKit2WebExtension-5.0/WebKit2WebExtension-5.0.csproj @@ -0,0 +1,13 @@ + + + + + + + + + GirCore.WebKit2WebExtension-5.0 + WebKit2WebExtension + C# bindings for WebKit2WebExtension. + + diff --git a/src/Samples/WebKit2-5.0/JavascriptCall/JavascriptCall.csproj b/src/Samples/WebKit2-5.0/JavascriptCall/JavascriptCall.csproj new file mode 100644 index 000000000..2305ba417 --- /dev/null +++ b/src/Samples/WebKit2-5.0/JavascriptCall/JavascriptCall.csproj @@ -0,0 +1,14 @@ + + + + + + + + + Exe + net7.0 + enable + + + diff --git a/src/Samples/WebKit2-5.0/JavascriptCall/Program.cs b/src/Samples/WebKit2-5.0/JavascriptCall/Program.cs new file mode 100644 index 000000000..51f8be68c --- /dev/null +++ b/src/Samples/WebKit2-5.0/JavascriptCall/Program.cs @@ -0,0 +1,46 @@ +#pragma warning disable CA1416 + +WebKit2.Module.Initialize(); + +var application = Gtk.Application.New("org.gir.core", Gio.ApplicationFlags.FlagsNone); +application.OnActivate += (sender, _) => +{ + var webView = WebKit2.WebView.New(); + webView.HeightRequest = 500; + webView.WidthRequest = 500; + + var ucm = webView.GetUserContentManager(); + ucm.AddScript(WebKit2.UserScript.New( + source: "function testFunc() { return 'Success' }", + injectedFrames: WebKit2.UserContentInjectedFrames.AllFrames, + injectionTime: WebKit2.UserScriptInjectionTime.End) + ); + + webView.OnLoadChanged += async (view, signalArgs) => + { + if (signalArgs.LoadEvent != WebKit2.LoadEvent.Finished) + return; + + var result = await webView.RunJavascriptAsync("testFunc()"); + System.Console.WriteLine(result.ToString()); //Writes "Success" into the console + }; + + webView.LoadHtml( + content: """ + + + Javascript Demo + Demo content + + """, + baseUri: null + ); + + var window = Gtk.ApplicationWindow.New((Gtk.Application) sender); + window.Title = "WebKit Demo"; + window.SetChild(webView); + window.Show(); +}; +return application.Run(); + +#pragma warning restore CA1416 diff --git a/src/Samples/WebKit2-5.0/JavascriptCallback/JavascriptCallback.csproj b/src/Samples/WebKit2-5.0/JavascriptCallback/JavascriptCallback.csproj new file mode 100644 index 000000000..2305ba417 --- /dev/null +++ b/src/Samples/WebKit2-5.0/JavascriptCallback/JavascriptCallback.csproj @@ -0,0 +1,14 @@ + + + + + + + + + Exe + net7.0 + enable + + + diff --git a/src/Samples/WebKit2-5.0/JavascriptCallback/Program.cs b/src/Samples/WebKit2-5.0/JavascriptCallback/Program.cs new file mode 100644 index 000000000..e472144a9 --- /dev/null +++ b/src/Samples/WebKit2-5.0/JavascriptCallback/Program.cs @@ -0,0 +1,51 @@ +#pragma warning disable CA1416 + +WebKit2.Module.Initialize(); + +var application = Gtk.Application.New("org.gir.core", Gio.ApplicationFlags.FlagsNone); +application.OnActivate += (sender, args) => +{ + var webView = WebKit2.WebView.New(); + webView.HeightRequest = 500; + webView.WidthRequest = 500; + + var ucm = webView.GetUserContentManager(); + ucm.AddScript(WebKit2.UserScript.New( + source: """ + (function(globalContext) { + globalContext.document.getElementById("inputId").onclick = function () { + var message = { myProp : "Success" }; //Message is a new object + window.webkit.messageHandlers["handlerId"].postMessage(message); + }; + })(this) + """, + injectedFrames: WebKit2.UserContentInjectedFrames.AllFrames, + injectionTime: WebKit2.UserScriptInjectionTime.End) + ); + ucm.RegisterScriptMessageHandler("handlerId", value => + { + System.Diagnostics.Debug.Assert(value.IsObject(), "Returned value is expected to be an object"); + + var result = value.ObjectGetProperty("myProp"); + System.Console.WriteLine(result.ToString()); //Writes "Success" into the console + }); + + webView.LoadHtml( + content: """ + + + Javascript Demo + + + """, + baseUri: null + ); + + var window = Gtk.ApplicationWindow.New((Gtk.Application) sender); + window.Title = "WebKit Demo"; + window.SetChild(webView); + window.Show(); +}; +return application.Run(); + +#pragma warning restore CA1416