diff options
author | Andreas Kling <kling@serenityos.org> | 2020-06-17 17:31:42 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-17 20:09:44 +0200 |
commit | c45c5ded342b9c530207222bd620f4ee0d4af601 (patch) | |
tree | d618d658e770286139bad37222a8cf68e8669e61 /Demos/WebView | |
parent | de12cf6821679c900ced1c8164741bfefbde97b0 (diff) | |
download | serenity-c45c5ded342b9c530207222bd620f4ee0d4af601.zip |
WebContent: Start work on browser process separation :^)
The "WebContent" service provides a very restricted instance of LibWeb
running as an unprivileged user account. This will be used to implement
process separation in Browser, among other things.
This first cut of the service only spawns a single WebContent process
when someone connects to /tmp/portal/webcontent. We will soon switch
this over to spawning a new process for each connection.
Since this feature is very immature, we'll be bringing it up inside of
Demos/WebView as a separate demo program. Eventually this will become
a reusable widget that anyone can embed and easily get out-of-process
web content in their GUI.
This is pretty, pretty cool! :^)
Diffstat (limited to 'Demos/WebView')
-rw-r--r-- | Demos/WebView/CMakeLists.txt | 13 | ||||
-rw-r--r-- | Demos/WebView/WebContentClient.cpp | 53 | ||||
-rw-r--r-- | Demos/WebView/WebContentClient.h | 51 | ||||
-rw-r--r-- | Demos/WebView/WebContentView.cpp | 75 | ||||
-rw-r--r-- | Demos/WebView/WebContentView.h | 53 | ||||
-rw-r--r-- | Demos/WebView/main.cpp | 45 |
6 files changed, 290 insertions, 0 deletions
diff --git a/Demos/WebView/CMakeLists.txt b/Demos/WebView/CMakeLists.txt new file mode 100644 index 0000000000..cf139cff1a --- /dev/null +++ b/Demos/WebView/CMakeLists.txt @@ -0,0 +1,13 @@ +set(SOURCES + main.cpp + WebContentView.cpp + WebContentClient.cpp +) + +set(GENERATED_SOURCES + ../../Services/WebContent/WebContentClientEndpoint.h + ../../Services/WebContent/WebContentServerEndpoint.h +) + +serenity_bin(WebView) +target_link_libraries(WebView LibGUI) diff --git a/Demos/WebView/WebContentClient.cpp b/Demos/WebView/WebContentClient.cpp new file mode 100644 index 0000000000..1f2c847e09 --- /dev/null +++ b/Demos/WebView/WebContentClient.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "WebContentClient.h" +#include "WebContentView.h" +#include <AK/SharedBuffer.h> + +WebContentClient::WebContentClient(WebContentView& view) + : IPC::ServerConnection<WebContentClientEndpoint, WebContentServerEndpoint>(*this, "/tmp/portal/webcontent") + , m_view(view) +{ + handshake(); +} + +void WebContentClient::handshake() +{ + auto response = send_sync<Messages::WebContentServer::Greet>(); + set_my_client_id(response->client_id()); +} + +void WebContentClient::handle(const Messages::WebContentClient::DidPaint& message) +{ + dbg() << "handle: WebContentClient::DidPaint! content_rect=" << message.content_rect() << ", shbuf_id=" << message.shbuf_id(); + m_view.notify_server_did_paint({}, message.shbuf_id()); +} + +void WebContentClient::handle(const Messages::WebContentClient::DidFinishLoad& message) +{ + dbg() << "handle: WebContentClient::DidFinishLoad! url=" << message.url(); +} diff --git a/Demos/WebView/WebContentClient.h b/Demos/WebView/WebContentClient.h new file mode 100644 index 0000000000..ed9e9b41f4 --- /dev/null +++ b/Demos/WebView/WebContentClient.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include <AK/HashMap.h> +#include <LibIPC/ServerConnection.h> +#include <WebContent/WebContentClientEndpoint.h> +#include <WebContent/WebContentServerEndpoint.h> + +class WebContentView; + +class WebContentClient + : public IPC::ServerConnection<WebContentClientEndpoint, WebContentServerEndpoint> + , public WebContentClientEndpoint { + C_OBJECT(WebContentClient); + +public: + virtual void handshake() override; + +private: + WebContentClient(WebContentView&); + + virtual void handle(const Messages::WebContentClient::DidPaint&) override; + virtual void handle(const Messages::WebContentClient::DidFinishLoad&) override; + + WebContentView& m_view; +}; diff --git a/Demos/WebView/WebContentView.cpp b/Demos/WebView/WebContentView.cpp new file mode 100644 index 0000000000..0cb87d5dae --- /dev/null +++ b/Demos/WebView/WebContentView.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "WebContentView.h" +#include "WebContentClient.h" +#include <AK/SharedBuffer.h> +#include <LibGUI/Painter.h> +#include <LibGfx/SystemTheme.h> + +WebContentView::WebContentView() +{ + m_client = WebContentClient::construct(*this); + client().post_message(Messages::WebContentServer::UpdateSystemTheme(Gfx::current_system_theme_buffer_id())); +} + +WebContentView::~WebContentView() +{ +} + +void WebContentView::load(const URL& url) +{ + client().post_message(Messages::WebContentServer::LoadURL(url)); +} + +void WebContentView::paint_event(GUI::PaintEvent& event) +{ + GUI::Painter painter(*this); + painter.add_clip_rect(event.rect()); + ASSERT(m_bitmap); + painter.blit({ 0, 0 }, *m_bitmap, m_bitmap->rect()); +} + +void WebContentView::resize_event(GUI::ResizeEvent& event) +{ + GUI::Widget::resize_event(event); + auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, event.size()); + m_bitmap = bitmap->to_bitmap_backed_by_shared_buffer(); + m_bitmap->shared_buffer()->share_with(client().server_pid()); + client().post_message(Messages::WebContentServer::SetViewportRect(Gfx::IntRect({ 0, 0 }, event.size()))); + client().post_message(Messages::WebContentServer::Paint(m_bitmap->rect(), m_bitmap->shbuf_id())); +} + +void WebContentView::notify_server_did_paint(Badge<WebContentClient>, i32 shbuf_id) +{ + if (m_bitmap->shbuf_id() == shbuf_id) + update(); +} + +WebContentClient& WebContentView::client() +{ + return *m_client; +} diff --git a/Demos/WebView/WebContentView.h b/Demos/WebView/WebContentView.h new file mode 100644 index 0000000000..353b9d9c02 --- /dev/null +++ b/Demos/WebView/WebContentView.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include <LibGUI/Widget.h> + +class WebContentClient; + +class WebContentView final : public GUI::Widget { + C_OBJECT(WebContentView); + +public: + virtual ~WebContentView() override; + + void load(const URL&); + + void notify_server_did_paint(Badge<WebContentClient>, i32 shbuf_id); + +private: + WebContentView(); + + virtual void paint_event(GUI::PaintEvent&) override; + virtual void resize_event(GUI::ResizeEvent&) override; + + WebContentClient& client(); + + RefPtr<WebContentClient> m_client; + RefPtr<Gfx::Bitmap> m_bitmap; +}; diff --git a/Demos/WebView/main.cpp b/Demos/WebView/main.cpp new file mode 100644 index 0000000000..9afac30fcc --- /dev/null +++ b/Demos/WebView/main.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "WebContentView.h" +#include <AK/URL.h> +#include <LibGUI/Application.h> +#include <LibGUI/Widget.h> +#include <LibGUI/Window.h> + +int main(int argc, char** argv) +{ + GUI::Application app(argc, argv); + auto window = GUI::Window::construct(); + auto& view = window->set_main_widget<WebContentView>(); + window->set_title("WebContentView"); + window->set_rect(100, 100, 640, 480); + window->show(); + + view.load("file:///res/html/misc/welcome.html"); + + return app.exec(); +} |