Skip to content

Commit 9505928

Browse files
trflynn89linusg
authored andcommitted
Browser+LibWebView+WebContent: Add IPC to re[store,size,position] window
Requests to restore, resize, and reposition Browser windows will be coming from the WebContent process rather than the WebDriver process. Add hooks to propagate these requests back up to the Browser. The spec notes "The specification does not guarantee that the resulting window size will exactly match that which was requested", so these new methods return the actual new size/position.
1 parent 71aba39 commit 9505928

File tree

7 files changed

+75
-2
lines changed

7 files changed

+75
-2
lines changed

Userland/Applications/Browser/Tab.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,22 @@ Tab::Tab(BrowserWindow& window)
248248
update_status({}, count_waiting);
249249
};
250250

251+
view().on_restore_window = [this]() {
252+
this->window().show();
253+
this->window().move_to_front();
254+
m_web_content_view->set_system_visibility_state(true);
255+
};
256+
257+
view().on_reposition_window = [this](Gfx::IntPoint const& position) {
258+
this->window().move_to(position);
259+
return this->window().position();
260+
};
261+
262+
view().on_resize_window = [this](Gfx::IntSize const& size) {
263+
this->window().resize(size);
264+
return this->window().size();
265+
};
266+
251267
m_link_context_menu = GUI::Menu::construct();
252268
auto link_default_action = GUI::Action::create("&Open", g_icon_bag.go_to, [this](auto&) {
253269
view().on_link_click(m_link_context_menu_url, "", 0);

Userland/Libraries/LibWebView/OutOfProcessWebView.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,26 @@ void OutOfProcessWebView::notify_server_did_update_resource_count(i32 count_wait
401401
on_resource_status_change(count_waiting);
402402
}
403403

404+
void OutOfProcessWebView::notify_server_did_request_restore_window()
405+
{
406+
if (on_restore_window)
407+
on_restore_window();
408+
}
409+
410+
Gfx::IntPoint OutOfProcessWebView::notify_server_did_request_reposition_window(Gfx::IntPoint const& position)
411+
{
412+
if (on_reposition_window)
413+
return on_reposition_window(position);
414+
return {};
415+
}
416+
417+
Gfx::IntSize OutOfProcessWebView::notify_server_did_request_resize_window(Gfx::IntSize const& size)
418+
{
419+
if (on_resize_window)
420+
return on_resize_window(size);
421+
return {};
422+
}
423+
404424
void OutOfProcessWebView::notify_server_did_request_file(Badge<WebContentClient>, String const& path, i32 request_id)
405425
{
406426
auto file = FileSystemAccessClient::Client::the().try_request_file_read_only_approved(window(), path);
@@ -642,14 +662,19 @@ void OutOfProcessWebView::focusout_event(GUI::FocusEvent&)
642662
client().async_set_has_focus(false);
643663
}
644664

665+
void OutOfProcessWebView::set_system_visibility_state(bool visible)
666+
{
667+
client().async_set_system_visibility_state(visible);
668+
}
669+
645670
void OutOfProcessWebView::show_event(GUI::ShowEvent&)
646671
{
647-
client().async_set_system_visibility_state(true);
672+
set_system_visibility_state(true);
648673
}
649674

650675
void OutOfProcessWebView::hide_event(GUI::HideEvent&)
651676
{
652-
client().async_set_system_visibility_state(false);
677+
set_system_visibility_state(false);
653678
}
654679

655680
}

Userland/Libraries/LibWebView/OutOfProcessWebView.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class OutOfProcessWebView final
8484
void set_window_position(Gfx::IntPoint const&);
8585
void set_window_size(Gfx::IntSize const&);
8686

87+
void set_system_visibility_state(bool visible);
88+
8789
Gfx::ShareableBitmap take_screenshot() const;
8890
Gfx::ShareableBitmap take_element_screenshot(i32 element_id);
8991
Gfx::ShareableBitmap take_document_screenshot();
@@ -110,6 +112,9 @@ class OutOfProcessWebView final
110112
Function<String(const AK::URL& url, Web::Cookie::Source source)> on_get_cookie;
111113
Function<void(const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source)> on_set_cookie;
112114
Function<void(i32 count_waiting)> on_resource_status_change;
115+
Function<void()> on_restore_window;
116+
Function<Gfx::IntPoint(Gfx::IntPoint const&)> on_reposition_window;
117+
Function<Gfx::IntSize(Gfx::IntSize const&)> on_resize_window;
113118

114119
private:
115120
OutOfProcessWebView();
@@ -167,6 +172,9 @@ class OutOfProcessWebView final
167172
virtual String notify_server_did_request_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::Source source) override;
168173
virtual void notify_server_did_set_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source) override;
169174
virtual void notify_server_did_update_resource_count(i32 count_waiting) override;
175+
virtual void notify_server_did_request_restore_window() override;
176+
virtual Gfx::IntPoint notify_server_did_request_reposition_window(Gfx::IntPoint const&) override;
177+
virtual Gfx::IntSize notify_server_did_request_resize_window(Gfx::IntSize const&) override;
170178
virtual void notify_server_did_request_file(Badge<WebContentClient>, String const& path, i32) override;
171179

172180
void request_repaint();

Userland/Libraries/LibWebView/ViewImplementation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class ViewImplementation {
5050
virtual String notify_server_did_request_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::Source source) = 0;
5151
virtual void notify_server_did_set_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source) = 0;
5252
virtual void notify_server_did_update_resource_count(i32 count_waiting) = 0;
53+
virtual void notify_server_did_request_restore_window() = 0;
54+
virtual Gfx::IntPoint notify_server_did_request_reposition_window(Gfx::IntPoint const&) = 0;
55+
virtual Gfx::IntSize notify_server_did_request_resize_window(Gfx::IntSize const&) = 0;
5356
virtual void notify_server_did_request_file(Badge<WebContentClient>, String const& path, i32) = 0;
5457
};
5558

Userland/Libraries/LibWebView/WebContentClient.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,21 @@ void WebContentClient::did_update_resource_count(i32 count_waiting)
200200
m_view.notify_server_did_update_resource_count(count_waiting);
201201
}
202202

203+
void WebContentClient::did_request_restore_window()
204+
{
205+
m_view.notify_server_did_request_restore_window();
206+
}
207+
208+
Messages::WebContentClient::DidRequestRepositionWindowResponse WebContentClient::did_request_reposition_window(Gfx::IntPoint const& position)
209+
{
210+
return m_view.notify_server_did_request_reposition_window(position);
211+
}
212+
213+
Messages::WebContentClient::DidRequestResizeWindowResponse WebContentClient::did_request_resize_window(Gfx::IntSize const& size)
214+
{
215+
return m_view.notify_server_did_request_resize_window(size);
216+
}
217+
203218
void WebContentClient::did_request_file(String const& path, i32 request_id)
204219
{
205220
m_view.notify_server_did_request_file({}, path, request_id);

Userland/Libraries/LibWebView/WebContentClient.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class WebContentClient final
6161
virtual Messages::WebContentClient::DidRequestCookieResponse did_request_cookie(AK::URL const&, u8) override;
6262
virtual void did_set_cookie(AK::URL const&, Web::Cookie::ParsedCookie const&, u8) override;
6363
virtual void did_update_resource_count(i32 count_waiting) override;
64+
virtual void did_request_restore_window() override;
65+
virtual Messages::WebContentClient::DidRequestRepositionWindowResponse did_request_reposition_window(Gfx::IntPoint const&) override;
66+
virtual Messages::WebContentClient::DidRequestResizeWindowResponse did_request_resize_window(Gfx::IntSize const&) override;
6467
virtual void did_request_file(String const& path, i32) override;
6568

6669
ViewImplementation& m_view;

Userland/Services/WebContent/WebContentClient.ipc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ endpoint WebContentClient
3838
did_request_cookie(URL url, u8 source) => (String cookie)
3939
did_set_cookie(URL url, Web::Cookie::ParsedCookie cookie, u8 source) =|
4040
did_update_resource_count(i32 count_waiting) =|
41+
did_request_restore_window() =|
42+
did_request_reposition_window(Gfx::IntPoint position) => (Gfx::IntPoint window_position)
43+
did_request_resize_window(Gfx::IntSize size) => (Gfx::IntSize window_size)
4144
did_request_file(String path, i32 request_id) =|
4245

4346
did_output_js_console_message(i32 message_index) =|

0 commit comments

Comments
 (0)