How to implement a connection to web backend with WPE webkit #552
Replies: 1 comment
-
|
I made some advances in that matter, thought I'd share them here for anyone to refer to.
Direct answer : in the source code of the custom launcher / browser. Detailed answer: A collection of minimal examples can be found here and were actually made by the author of the aforementioned video. They are supposed to be minimal launchers with different ways of making backend connection. Now the problem is, while I managed to compile (most) of them (see more right after), I'm unable to make them properly work so far. I only get the mouse to show up; the web pages don't render.
To cross compile, I sourced the environment from the yocto generated sdk, and I used the following cmake_minimum_required(VERSION 3.10)
project(server C CXX)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
# Set the sysroot
set(CMAKE_SYSROOT <path_to_yocto_generated_sdk>/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi)
# Set the cross compiler
set(CMAKE_C_COMPILER <path_to_yocto_generated_sdk>/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER <path_to_yocto_generated_sdk>/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++)
# Set pkg-config
set(PKG_CONFIG_EXECUTABLE <path_to_yocto_generated_sdk>/x86_64-pokysdk-linux/usr/bin/pkg-config)
set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT})
set(ENV{PKG_CONFIG_LIBDIR} ${CMAKE_SYSROOT}/usr/lib/pkgconfig:${CMAKE_SYSROOT}/usr/share/pkgconfig)
# Search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Search for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
find_package(PkgConfig REQUIRED)
pkg_check_modules(WPE_WEBKIT REQUIRED cogcore) # swap with wpewebkit-2.0 if cog not needed
# Source files
file(GLOB SOURCES
"server.c"
)
add_executable(${PROJECT_NAME}
server.c
)
target_include_directories(${PROJECT_NAME}
PRIVATE ${WPE_WEBKIT_INCLUDE_DIRS}
)
target_link_libraries(${PROJECT_NAME}
${WPE_WEBKIT_LIBRARIES}
)Now, I encountered an issue when first generating with this CMakeLists.txt : pkg was complaining about a missing xxf86vm dependency for egl ; so I went on and modified Now what I have managed to do tho, is to make a backend connection using uri scheme handlers by adding them directly to the cog sources and then compiling them with yocto. Here is a /*
* cog.c
* Copyright (C) 2021 Igalia S.L.
* Copyright (C) 2018 Eduardo Lima <[email protected]>
* Copyright (C) 2017-2018 Adrian Perez <[email protected]>
*
* SPDX-License-Identifier: MIT
*/
#include "cog-launcher.h"
static void
print_module_info(GIOExtension *extension, void *userdata G_GNUC_UNUSED)
{
g_info(" %s - %d/%s",
g_io_extension_get_name(extension),
g_io_extension_get_priority(extension),
g_type_name(g_io_extension_get_type(extension)));
}
static void
handle_echo_request(WebKitURISchemeRequest *request, void *userdata)
{
const char *request_uri = webkit_uri_scheme_request_get_uri(request);
g_print("Request URI: %s (%s)\n", request_uri, webkit_uri_scheme_request_get_http_method(request));
g_autoptr(GBytes) data = g_bytes_new(request_uri, strlen(request_uri));
g_autoptr(GInputStream) stream = g_memory_input_stream_new_from_bytes(data);
g_autoptr(SoupMessageHeaders) headers = soup_message_headers_new(SOUP_MESSAGE_HEADERS_RESPONSE);
soup_message_headers_replace(headers, "Access-Control-Allow-Origin", "*");
soup_message_headers_replace(headers, "Access-Control-Allow-Methods", "GET");
g_autoptr(WebKitURISchemeResponse) response = webkit_uri_scheme_response_new(stream, g_bytes_get_size(data));
webkit_uri_scheme_response_set_http_headers(response, g_steal_pointer(&headers));
webkit_uri_scheme_response_set_content_type(response, "text/plain");
webkit_uri_scheme_response_set_status(response, 200, NULL);
webkit_uri_scheme_request_finish_with_response(request, response);
}
static void
configure_web_context(WebKitWebContext *context)
{
g_print("Configuring web context FROM CALLBACK\n");
webkit_web_context_register_uri_scheme(context, "echo", handle_echo_request, NULL, NULL);
WebKitSecurityManager *manager = webkit_web_context_get_security_manager(context);
webkit_security_manager_register_uri_scheme_as_cors_enabled(manager, "echo");
}
static void
on_launcher_activate(CogLauncher *launcher, gpointer user_data)
{
g_print("Launcher activate\n");
CogShell *shell = cog_launcher_get_shell(launcher);
if (shell != NULL) {
WebKitWebContext *context = cog_shell_get_web_context(shell);
if (context != NULL) {
configure_web_context(context);
}
}
}
int
main(int argc, char *argv[])
{
g_set_application_name("Cog");
g_info("%s:", COG_MODULES_PLATFORM_EXTENSION_POINT);
cog_modules_foreach(COG_MODULES_PLATFORM, print_module_info, NULL);
// We need to check whether we'll use automation mode before creating the launcher
gboolean automated = FALSE;
for (int i = 1; i < argc; i++) {
if (g_str_equal("--automation", argv[i])) {
automated = TRUE;
break;
}
}
CogSessionType sessionType = automated ? COG_SESSION_AUTOMATED : COG_SESSION_REGULAR;
CogLauncher *launcher = cog_launcher_new(sessionType);
if (launcher == NULL) {
g_print("launcher is null!");
return 1;
}
// Connect to startup signal
g_signal_connect(launcher, "activate", G_CALLBACK(on_launcher_activate), NULL);
g_autoptr(GApplication) app = G_APPLICATION(launcher);
return g_application_run(app, argc, argv);
}Now I feel like this may be a discussion that should be moved to the cog repo.... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Background : I have successfully built a yocto image with Mesa VC4 driver, DRM and wpebackend-fdo for the raspeberry pi 3b+ following these guidelines.
I'm able to run cog and to display my own html file on the framebuffer.
Now, I watched this video which mentions how to make connection with the backend, notably through URI Scheme handlers.
Some basics are however unclear to me:
webkit_web_context_register_uri_scheme(....) ;Additionally , the following minimal browser code is also presented:
How can I cross compile this?
Should things rather be compiled within the yocto build directly?
I'm sorry, aside from using cog directly, I found very little (if none at all) resources and working examples, even after hours of searching...
Beta Was this translation helpful? Give feedback.
All reactions