mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
LibWeb+LibWebView+WebContent: Introduce a WebUI framework
When we build internal pages (e.g. about:settings), there is currently quite a lot of boilerplate needed to communicate between the browser and the page. This includes creating IDL for the page and the IPC for every message sent between the processes. These internal pages are also special in that they have privileged access to and control over the browser process. The framework introduced here serves to ease the setup of new internal pages and to reduce the access that WebContent processes have to the browser process. WebUI pages can send requests to the browser process via a `ladybird.sendMessage` API. Responses from the browser are passed through a WebUIMessage event. So, for example, an internal page may: ladybird.sendMessage("getDataFor", { id: 123 }); document.addEventListener("WebUIMessage", event => { if (event.name === "gotData") { console.assert(event.data.id === 123); } }); To handle these messages, we set up a new IPC connection between the browser and WebContent processes. This connection is torn down when the user navigates away from the internal page.
This commit is contained in:
parent
f72d87931f
commit
41aeb9e63a
Notes:
github-actions[bot]
2025-03-28 11:32:17 +00:00
Author: https://github.com/trflynn89
Commit: 41aeb9e63a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4068
25 changed files with 416 additions and 3 deletions
29
Libraries/LibWeb/Internals/WebUI.h
Normal file
29
Libraries/LibWeb/Internals/WebUI.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
#include <LibWeb/Internals/InternalsBase.h>
|
||||
|
||||
namespace Web::Internals {
|
||||
|
||||
class WebUI final : public InternalsBase {
|
||||
WEB_PLATFORM_OBJECT(WebUI, InternalsBase);
|
||||
GC_DECLARE_ALLOCATOR(WebUI);
|
||||
|
||||
public:
|
||||
virtual ~WebUI() override;
|
||||
|
||||
void send_message(String const& name, JS::Value data);
|
||||
|
||||
private:
|
||||
explicit WebUI(JS::Realm&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue