mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 10:27:36 +00:00
LibWeb: Make Web::PageClient GC-allocated
This is a first step towards simplifying the ownership model of Web::Page. Soon Web::Page will store its WebClient as a NonnullGCPtr to help solve lifetime issues of the client being destroyed before the page.
This commit is contained in:
parent
5c0cd0f484
commit
6e6f3a9a8f
11 changed files with 45 additions and 17 deletions
|
@ -39,6 +39,11 @@ void PageClient::set_use_gpu_painter()
|
|||
s_use_gpu_painter = true;
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<PageClient> PageClient::create(JS::VM& vm, PageHost& page_host, u64 id)
|
||||
{
|
||||
return vm.heap().allocate_without_realm<PageClient>(page_host, id);
|
||||
}
|
||||
|
||||
PageClient::PageClient(PageHost& owner, u64 id)
|
||||
: m_owner(owner)
|
||||
, m_page(make<Web::Page>(*this))
|
||||
|
|
|
@ -17,11 +17,10 @@
|
|||
namespace WebContent {
|
||||
|
||||
class PageClient final : public Web::PageClient {
|
||||
AK_MAKE_NONCOPYABLE(PageClient);
|
||||
AK_MAKE_NONMOVABLE(PageClient);
|
||||
JS_CELL(PageClient, Web::PageClient);
|
||||
|
||||
public:
|
||||
PageClient(PageHost&, u64 id);
|
||||
static JS::NonnullGCPtr<PageClient> create(JS::VM& vm, PageHost& page_host, u64 id);
|
||||
|
||||
static void set_use_gpu_painter();
|
||||
|
||||
|
@ -60,6 +59,8 @@ public:
|
|||
void set_user_style(String source);
|
||||
|
||||
private:
|
||||
PageClient(PageHost&, u64 id);
|
||||
|
||||
// ^PageClient
|
||||
virtual bool is_connection_open() const override;
|
||||
virtual Gfx::Palette palette() const override;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||
#include <LibWeb/HTML/TraversableNavigable.h>
|
||||
#include <WebContent/ConnectionFromClient.h>
|
||||
#include <WebContent/PageClient.h>
|
||||
|
@ -23,7 +24,7 @@ PageHost::PageHost(ConnectionFromClient& client)
|
|||
|
||||
PageClient& PageHost::create_page()
|
||||
{
|
||||
m_pages.set(m_next_id, make<PageClient>(*this, m_next_id));
|
||||
m_pages.set(m_next_id, PageClient::create(Web::Bindings::main_thread_vm(), *this, m_next_id));
|
||||
++m_next_id;
|
||||
return *m_pages.get(m_next_id - 1).value();
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <AK/Function.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <LibJS/Heap/Handle.h>
|
||||
#include <WebContent/Forward.h>
|
||||
|
||||
namespace WebContent {
|
||||
|
@ -34,7 +35,7 @@ private:
|
|||
explicit PageHost(ConnectionFromClient&);
|
||||
|
||||
ConnectionFromClient& m_client;
|
||||
HashMap<u64, NonnullOwnPtr<PageClient>> m_pages;
|
||||
HashMap<u64, JS::Handle<PageClient>> m_pages;
|
||||
u64 m_next_id { 0 };
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue