-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[linux] Add support for WebKit2GTK 2.36+ features #2151
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//go:build linux | ||
|
||
package linux | ||
|
||
/* | ||
#cgo linux pkg-config: webkit2gtk-4.0 | ||
#include "webkit2/webkit2.h" | ||
*/ | ||
import "C" | ||
import ( | ||
"fmt" | ||
|
||
"github.com/wailsapp/wails/v2/pkg/options" | ||
"github.com/wailsapp/wails/v2/pkg/options/linux" | ||
) | ||
|
||
func validateWebKit2Version(options *options.App) { | ||
if C.webkit_get_major_version() == 2 && C.webkit_get_minor_version() >= webkit2MinMinorVersion { | ||
return | ||
} | ||
|
||
msg := linux.DefaultMessages() | ||
if options.Linux != nil && options.Linux.Messages != nil { | ||
msg = options.Linux.Messages | ||
} | ||
|
||
v := fmt.Sprintf("2.%d.0", webkit2MinMinorVersion) | ||
showModalDialogAndExit("WebKit2GTK", fmt.Sprintf(msg.WebKit2GTKMinRequired, v)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//go:build linux && webkit2_36 | ||
|
||
package linux | ||
|
||
/* | ||
#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.0 libsoup-2.4 | ||
|
||
#include "gtk/gtk.h" | ||
#include "webkit2/webkit2.h" | ||
#include "libsoup/soup.h" | ||
*/ | ||
import "C" | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
"unsafe" | ||
|
||
"github.com/wailsapp/wails/v2/internal/frontend/assetserver" | ||
) | ||
|
||
const webkit2MinMinorVersion = 36 | ||
|
||
func webkit_uri_scheme_request_get_http_method(req *C.WebKitURISchemeRequest) string { | ||
method := C.GoString(C.webkit_uri_scheme_request_get_http_method(req)) | ||
return strings.ToUpper(method) | ||
} | ||
|
||
func webkit_uri_scheme_request_get_http_headers(req *C.WebKitURISchemeRequest) http.Header { | ||
hdrs := C.webkit_uri_scheme_request_get_http_headers(req) | ||
|
||
var iter C.SoupMessageHeadersIter | ||
C.soup_message_headers_iter_init(&iter, hdrs) | ||
|
||
var name *C.char | ||
var value *C.char | ||
|
||
h := http.Header{} | ||
for C.soup_message_headers_iter_next(&iter, &name, &value) != 0 { | ||
h.Add(C.GoString(name), C.GoString(value)) | ||
} | ||
|
||
return h | ||
} | ||
|
||
func webkit_uri_scheme_request_finish(req *C.WebKitURISchemeRequest, code int, header http.Header, stream *C.GInputStream, streamLength int64) error { | ||
resp := C.webkit_uri_scheme_response_new(stream, C.gint64(streamLength)) | ||
defer C.g_object_unref(C.gpointer(resp)) | ||
|
||
cReason := C.CString(http.StatusText(code)) | ||
C.webkit_uri_scheme_response_set_status(resp, C.guint(code), cReason) | ||
C.free(unsafe.Pointer(cReason)) | ||
|
||
cMimeType := C.CString(header.Get(assetserver.HeaderContentType)) | ||
C.webkit_uri_scheme_response_set_content_type(resp, cMimeType) | ||
C.free(unsafe.Pointer(cMimeType)) | ||
|
||
hdrs := C.soup_message_headers_new(C.SOUP_MESSAGE_HEADERS_RESPONSE) | ||
for name, values := range header { | ||
cName := C.CString(name) | ||
for _, value := range values { | ||
cValue := C.CString(value) | ||
C.soup_message_headers_append(hdrs, cName, cValue) | ||
C.free(unsafe.Pointer(cValue)) | ||
} | ||
C.free(unsafe.Pointer(cName)) | ||
} | ||
|
||
C.webkit_uri_scheme_response_set_http_headers(resp, hdrs) | ||
|
||
C.webkit_uri_scheme_request_finish_with_response(req, resp) | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//go:build linux && !webkit2_36 | ||
|
||
package linux | ||
|
||
/* | ||
#cgo linux pkg-config: gtk+-3.0 webkit2gtk-4.0 | ||
|
||
#include "gtk/gtk.h" | ||
#include "webkit2/webkit2.h" | ||
*/ | ||
import "C" | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"unsafe" | ||
|
||
"github.com/wailsapp/wails/v2/internal/frontend/assetserver" | ||
) | ||
|
||
const webkit2MinMinorVersion = 0 | ||
|
||
func webkit_uri_scheme_request_get_http_method(_ *C.WebKitURISchemeRequest) string { | ||
return http.MethodGet | ||
} | ||
|
||
func webkit_uri_scheme_request_get_http_headers(_ *C.WebKitURISchemeRequest) http.Header { | ||
return http.Header{} | ||
} | ||
|
||
func webkit_uri_scheme_request_finish(req *C.WebKitURISchemeRequest, code int, header http.Header, stream *C.GInputStream, streamLength int64) error { | ||
if code != http.StatusOK { | ||
return fmt.Errorf("StatusCodes not supported: %d - %s", code, http.StatusText(code)) | ||
} | ||
|
||
cMimeType := C.CString(header.Get(assetserver.HeaderContentType)) | ||
C.webkit_uri_scheme_request_finish(req, stream, C.gint64(streamLength), cMimeType) | ||
C.free(unsafe.Pointer(cMimeType)) | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,24 +249,24 @@ dynamically with an `http.Handler` or hook into the request chain with an `asset | |
|
||
Not all features of an `http.Request` are currently supported, please see the following feature matrix: | ||
|
||
| Feature | Win | Mac | Lin | | ||
| ----------------------- | --- | --- | --- | | ||
| GET | ✅ | ✅ | ✅ | | ||
| POST | ✅ | ✅ | ❌ | | ||
| PUT | ✅ | ✅ | ❌ | | ||
| PATCH | ✅ | ✅ | ❌ | | ||
| DELETE | ✅ | ✅ | ❌ | | ||
| Request Headers | ✅ | ✅ | ❌ | | ||
| Request Body | ✅ | ✅ | ❌ | | ||
| Request Body Streaming | ❌ | ❌ | ❌ | | ||
| Response StatusCodes | ✅ | ✅ | ❌ | | ||
| Response Headers | ✅ | ✅ | ❌ | | ||
| Response Body | ✅ | ✅ | ✅ | | ||
| Response Body Streaming | ❌ | ❌ | ✅ | | ||
| WebSockets | ❌ | ❌ | ❌ | | ||
|
||
NOTE: Linux is currently very limited due to targeting a WebKit2GTK Version < 2.36.0. In the future some features will be | ||
supported by the introduction of WebKit2GTK 2.36.0+ support. | ||
| Feature | Win | Mac | Lin | | ||
| ----------------------- | --- | --- | ------ | | ||
| GET | ✅ | ✅ | ✅ | | ||
| POST | ✅ | ✅ | ✅ [^1] | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @leaanthony , @misitebao does anybody of you know if that footnotes do work with our docs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your best bet it to open branches on the repo itself then PRs will auto-deploy so you can see :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yeah, always forget about that 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm just seen your other PR and it seems footnotes are there for the next version docs: https://622b4565.wails.pages.dev/docs/next/reference/options#assetserver There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh my bad! I wondered why it looked like nothing had happened. The superscript 1 is super hard to click and it jumps to the bottom of the page. How about a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry already merged 😔, but will open another PR to improve that. |
||
| PUT | ✅ | ✅ | ✅ [^1] | | ||
| PATCH | ✅ | ✅ | ✅ [^1] | | ||
| DELETE | ✅ | ✅ | ✅ [^1] | | ||
| Request Headers | ✅ | ✅ | ✅ [^1] | | ||
| Request Body | ✅ | ✅ | ❌ | | ||
| Request Body Streaming | ❌ | ❌ | ❌ | | ||
| Response StatusCodes | ✅ | ✅ | ✅ [^1] | | ||
| Response Headers | ✅ | ✅ | ✅ [^1] | | ||
| Response Body | ✅ | ✅ | ✅ | | ||
| Response Body Streaming | ❌ | ❌ | ✅ | | ||
| WebSockets | ❌ | ❌ | ❌ | | ||
| HTTP Redirects 30x | ✅ | ❌ | ❌ | | ||
|
||
[^1]: This requires WebKit2GTK 2.36+ support and your app needs to be build with the build tag `webkit2_36` to activate support for this feature. This also bumps the minimum requirement of WebKit2GTK to 2.36 for your app. | ||
|
||
Name: AssetServer<br/> | ||
Type: `*assetserver.Options` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
libsoup
a new dependency that we need to add to our website and package manager code? It looks like it's already installed in Ubuntu 22.04 but might not be for others?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WebKit2GTK uses
libsoup
internally, so I think it should not be possible to have WebKit2GTK installed without this dependency. But maybe it's better to be on the safe side and add it.I'll add that as soon as we have merged the CLI refactoring so it doesn't interfere with that. Are you fine with that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah sure, though I suspect you are right: it's probably installed by webkit2gtk anyway so no need to specify it 👍