Skip to content

Truly independent web browser

Hub+UI/Qt: Show the real DevTools port in the banner

Andreas Kling27766224774b
diff --git a/Services/Hub/Application.cpp b/Services/Hub/Application.cpp
index 2f970fdeef4..1ad1f480678 100644
--- a/Services/Hub/Application.cpp
+++ b/Services/Hub/Application.cpp
@@ -342,7 +342,7 @@ void Application::on_devtools_enabled() const
{
WebView::Application::on_devtools_enabled();
if (auto* ui = ConnectionFromUI::the())
- ui->async_app_did_enable_devtools();
+ ui->async_app_did_enable_devtools(*browser_options().devtools_port);
}
void Application::on_devtools_disabled() const
diff --git a/Services/Hub/HubClient.ipc b/Services/Hub/HubClient.ipc
index e58f98371e9..0bb24133d9d 100644
--- a/Services/Hub/HubClient.ipc
+++ b/Services/Hub/HubClient.ipc
@@ -289,7 +289,7 @@ endpoint HubClient
app_update_tabs_display() =|
app_did_clear_history_since(UnixDateTime since) =|
app_quit_for_signal() =|
- app_did_enable_devtools() =|
+ app_did_enable_devtools(u16 port) =|
app_did_disable_devtools() =|
app_open_urls_in_new_tabs(Vector<URL::URL> urls) =|
app_activate_or_open_tab_with_url(URL::URL url) =|
diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cpp
index 33d2f763d89..9400edba8b0 100644
--- a/UI/Qt/Application.cpp
+++ b/UI/Qt/Application.cpp
@@ -913,6 +913,8 @@ ErrorOr<void> Application::connect_to_hub(Main::Arguments const& arguments)
m_browser_options.urls = move(state.urls);
m_browser_options.raw_urls = move(state.raw_urls);
m_browser_options.devtools_port = state.devtools_port;
+ if (state.devtools_enabled)
+ m_devtools_port = state.devtools_port;
# if defined(AK_OS_MACOS)
set_profile_application_icon(state.profile_identifier, state.profile_identity, state.profile_is_temporary);
# endif
@@ -1128,6 +1130,8 @@ void Application::create_platform_actions()
.blocks_pop_ups = hub.blocks_pop_ups(),
.devtools_enabled = hub.devtools_enabled(),
});
+ if (hub.devtools_enabled())
+ m_devtools_port = WebView::Application::browser_options().devtools_port;
RemoteDownloads::the().set_downloads(Hub::ConnectionFromUI::downloads());
#endif
@@ -2649,15 +2653,17 @@ void Application::report_active_view() const
hub->async_active_view_changed(tab && tab->is_loaded() ? Optional<u64> { tab->view().view_id() } : Optional<u64> {});
}
-void Application::did_enable_devtools() const
+void Application::did_enable_devtools(u16 port)
{
+ m_devtools_port = port;
m_application_actions->devtools_enabled_changed(true);
if (m_active_window)
m_active_window->on_devtools_enabled();
}
-void Application::did_disable_devtools() const
+void Application::did_disable_devtools()
{
+ m_devtools_port = {};
m_application_actions->devtools_enabled_changed(false);
if (m_active_window)
m_active_window->on_devtools_disabled();
diff --git a/UI/Qt/Application.h b/UI/Qt/Application.h
index 72b1b9225d5..cd68ccb31bd 100644
--- a/UI/Qt/Application.h
+++ b/UI/Qt/Application.h
@@ -82,6 +82,8 @@ public:
static Hub::Application& hub() { return Hub::Application::the(); }
static WebView::BrowserOptions const& browser_options() { return WebView::Application::browser_options(); }
#endif
+
+ Optional<u16> devtools_port() const { return m_devtools_port; }
bool has_translator() const;
WebView::MicrophoneAuthorizer* microphone_authorizer() { return m_microphone_authorizer.ptr(); }
// The status to exit with right away, if the browser has nothing for this process to do.
@@ -292,8 +294,8 @@ private:
NonnullRefPtr<BookmarkPromise> display_add_bookmark_folder_dialog(Optional<String const&> default_title = {}, Optional<String const&> target_folder_id = {}) const;
NonnullRefPtr<BookmarkPromise> display_edit_bookmark_folder_dialog(BookmarkItem const& current_folder, Optional<String const&> parent_folder_id) const;
- void did_enable_devtools() const;
- void did_disable_devtools() const;
+ void did_enable_devtools(u16 port);
+ void did_disable_devtools();
void on_recently_closed_entries_changed() const;
void did_clear_history_since(UnixDateTime);
void create_session_store(ByteString const& data_directory, bool persists_sessions);
@@ -303,6 +305,7 @@ private:
static Application* s_the;
String m_command_line;
+ Optional<u16> m_devtools_port;
#ifdef LADYBIRD_HUB_IN_OWN_PROCESS
ErrorOr<void> connect_to_hub(Main::Arguments const&);
diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cpp
index 25636a38bd7..3258c0e85a4 100644
--- a/UI/Qt/BrowserWindow.cpp
+++ b/UI/Qt/BrowserWindow.cpp
@@ -351,8 +351,6 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, IsPopupWindow
// NB: The toolbar is made before the rest of the window, so it learns of the session's downloads once it is all here.
toolbar().update_downloads_button();
- auto const& browser_options = Application::browser_options();
-
// A restored window keeps the session row the store re-adopted for it.
if (restored_session_window_id.has_value())
m_session_window_id = restored_session_window_id;
@@ -470,7 +468,7 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, IsPopupWindow
if (m_current_tab)
focus_widget_for_tab(*m_current_tab).setFocus();
- if (browser_options.devtools_port.has_value())
+ if (Application::the().devtools_port().has_value())
on_devtools_enabled();
}
@@ -738,7 +736,7 @@ void BrowserWindow::rebuild_bookmarks_menu()
void BrowserWindow::on_devtools_enabled()
{
- m_devtools_banner->set_port(Application::browser_options().devtools_port.value_or(0));
+ m_devtools_banner->set_port(*Application::the().devtools_port());
m_devtools_banner->show();
}
diff --git a/UI/Qt/HubConnection.cpp b/UI/Qt/HubConnection.cpp
index 2f0e3fd7f58..abe8e8086dd 100644
--- a/UI/Qt/HubConnection.cpp
+++ b/UI/Qt/HubConnection.cpp
@@ -311,9 +311,9 @@ void HubConnection::app_quit_for_signal()
Application::the().quit_for_signal();
}
-void HubConnection::app_did_enable_devtools()
+void HubConnection::app_did_enable_devtools(u16 port)
{
- Application::the().did_enable_devtools();
+ Application::the().did_enable_devtools(port);
}
void HubConnection::app_did_disable_devtools()
diff --git a/UI/Qt/HubConnection.h b/UI/Qt/HubConnection.h
index e0d2f097a91..d58bf5f27de 100644
--- a/UI/Qt/HubConnection.h
+++ b/UI/Qt/HubConnection.h
@@ -133,7 +133,7 @@ private:
virtual void app_update_tabs_display() override;
virtual void app_did_clear_history_since(UnixDateTime since) override;
virtual void app_quit_for_signal() override;
- virtual void app_did_enable_devtools() override;
+ virtual void app_did_enable_devtools(u16 port) override;
virtual void app_did_disable_devtools() override;
virtual void app_open_urls_in_new_tabs(Vector<URL::URL> urls) override;
virtual void app_activate_or_open_tab_with_url(URL::URL url) override;