LibWebView+WebContent: Monitor for system time zone changes

This creates a TimeZoneWatcher in the UI process to inform all open
WebContent processes when the time zone changes. The WebContent process
will clear its time zone cache to retrieve a fresh zone the next time
it is asked for one.
This commit is contained in:
Timothy Flynn 2024-08-24 12:15:20 -04:00 committed by Andreas Kling
parent 577efcdc32
commit d8c69a0e9e
Notes: github-actions[bot] 2024-08-25 07:48:36 +00:00
5 changed files with 31 additions and 0 deletions

View file

@ -6,6 +6,8 @@
#include <AK/Debug.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/Environment.h>
#include <LibCore/TimeZoneWatcher.h>
#include <LibImageDecoderClient/Client.h>
#include <LibWebView/Application.h>
#include <LibWebView/URL.h>
@ -20,6 +22,22 @@ Application::Application()
VERIFY(!s_the);
s_the = this;
// No need to monitor the system time zone if the TZ environment variable is set, as it overrides system preferences.
if (!Core::Environment::has("TZ"sv)) {
if (auto time_zone_watcher = Core::TimeZoneWatcher::create(); time_zone_watcher.is_error()) {
warnln("Unable to monitor system time zone: {}", time_zone_watcher.error());
} else {
m_time_zone_watcher = time_zone_watcher.release_value();
m_time_zone_watcher->on_time_zone_changed = []() {
WebContentClient::for_each_client([&](WebView::WebContentClient& client) {
client.async_system_time_zone_changed();
return IterationDecision::Continue;
});
};
}
}
m_process_manager.on_process_exited = [this](Process&& process) {
process_did_exit(move(process));
};

View file

@ -9,6 +9,7 @@
#include <AK/Badge.h>
#include <AK/Swift.h>
#include <LibCore/EventLoop.h>
#include <LibCore/Forward.h>
#include <LibMain/Main.h>
#include <LibURL/URL.h>
#include <LibWebView/Options.h>
@ -69,6 +70,8 @@ private:
ChromeOptions m_chrome_options;
WebContentOptions m_web_content_options;
OwnPtr<Core::TimeZoneWatcher> m_time_zone_watcher;
Core::EventLoop m_event_loop;
ProcessManager m_process_manager;
bool m_in_shutdown { false };

View file

@ -16,6 +16,7 @@
#include <LibGfx/SystemTheme.h>
#include <LibJS/Heap/Heap.h>
#include <LibJS/Runtime/ConsoleObject.h>
#include <LibUnicode/TimeZone.h>
#include <LibWeb/ARIA/RoleType.h>
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/CSS/StyleComputer.h>
@ -1169,4 +1170,9 @@ void ConnectionFromClient::enable_inspector_prototype(u64)
Web::HTML::Window::set_inspector_object_exposed(true);
}
void ConnectionFromClient::system_time_zone_changed()
{
Unicode::clear_system_time_zone_cache();
}
}

View file

@ -145,6 +145,8 @@ private:
virtual void paste(u64 page_id, String const& text) override;
virtual void system_time_zone_changed() override;
void report_finished_handling_input_event(u64 page_id, bool event_was_handled);
NonnullOwnPtr<PageHost> m_page_host;

View file

@ -115,4 +115,6 @@ endpoint WebContentServer
set_user_style(u64 page_id, String source) =|
enable_inspector_prototype(u64 page_id) =|
system_time_zone_changed() =|
}