summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/timezone/timezone_controller.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/core/timezone/timezone_controller.cc')
-rw-r--r--chromium/third_party/blink/renderer/core/timezone/timezone_controller.cc44
1 files changed, 39 insertions, 5 deletions
diff --git a/chromium/third_party/blink/renderer/core/timezone/timezone_controller.cc b/chromium/third_party/blink/renderer/core/timezone/timezone_controller.cc
index a03e0b81391..1600d8e07c6 100644
--- a/chromium/third_party/blink/renderer/core/timezone/timezone_controller.cc
+++ b/chromium/third_party/blink/renderer/core/timezone/timezone_controller.cc
@@ -6,16 +6,21 @@
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
-#include "services/device/public/mojom/constants.mojom-blink.h"
#include "services/service_manager/public/cpp/connector.h"
#include "third_party/blink/public/common/thread_safe_browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/task_type.h"
+#include "third_party/blink/public/web/web_local_frame.h"
+#include "third_party/blink/renderer/core/frame/frame.h"
+#include "third_party/blink/renderer/core/frame/local_dom_window.h"
+#include "third_party/blink/renderer/core/frame/local_frame.h"
+#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/workers/worker_backing_thread.h"
#include "third_party/blink/renderer/core/workers/worker_or_worklet_global_scope.h"
#include "third_party/blink/renderer/core/workers/worker_thread.h"
#include "third_party/blink/renderer/platform/bindings/v8_per_isolate_data.h"
#include "third_party/blink/renderer/platform/mojo/mojo_helper.h"
+#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/icu/source/common/unicode/char16ptr.h"
#include "third_party/icu/source/i18n/unicode/timezone.h"
#include "v8/include/v8.h"
@@ -33,6 +38,11 @@ void NotifyTimezoneChangeToV8(v8::Isolate* isolate) {
void NotifyTimezoneChangeOnWorkerThread(WorkerThread* worker_thread) {
DCHECK(worker_thread->IsCurrentThread());
NotifyTimezoneChangeToV8(worker_thread->GlobalScope()->GetIsolate());
+ if (RuntimeEnabledFeatures::TimeZoneChangeEventEnabled() &&
+ worker_thread->GlobalScope()->IsWorkerGlobalScope()) {
+ worker_thread->GlobalScope()->DispatchEvent(
+ *Event::Create(event_type_names::kTimezonechange));
+ }
}
String GetTimezoneId(const icu::TimeZone& timezone) {
@@ -48,6 +58,21 @@ String GetCurrentTimezoneId() {
return GetTimezoneId(*timezone.get());
}
+void DispatchTimeZoneChangeEventToFrames() {
+ if (!RuntimeEnabledFeatures::TimeZoneChangeEventEnabled())
+ return;
+
+ for (const Page* page : Page::OrdinaryPages()) {
+ for (Frame* frame = page->MainFrame(); frame;
+ frame = frame->Tree().TraverseNext()) {
+ if (auto* main_local_frame = DynamicTo<LocalFrame>(frame)) {
+ main_local_frame->DomWindow()->DispatchEvent(
+ *Event::Create(event_type_names::kTimezonechange));
+ }
+ }
+ }
+}
+
bool SetIcuTimeZoneAndNotifyV8(const String& timezone_id) {
DCHECK(!timezone_id.IsEmpty());
std::unique_ptr<icu::TimeZone> timezone(icu::TimeZone::createTimeZone(
@@ -62,6 +87,7 @@ bool SetIcuTimeZoneAndNotifyV8(const String& timezone_id) {
NotifyTimezoneChangeToV8(V8PerIsolateData::MainThreadIsolate());
WorkerThread::CallOnAllWorkerThreads(&NotifyTimezoneChangeOnWorkerThread,
TaskType::kInternalDefault);
+ DispatchTimeZoneChangeEventToFrames();
return true;
}
@@ -76,12 +102,16 @@ TimeZoneController::~TimeZoneController() = default;
// static
void TimeZoneController::Init() {
- // Some unit tests may have no message loop ready, so we can't initialize the
- // mojo stuff here. They can initialize those mojo stuff they're interested in
- // later after they got a message loop ready.
+ // TODO(crbug.com/660274): The unit tests should not require this exception.
+ // Currently some unit tests have no message loop ready, so we can't
+ // initialize the mojo stuff here. They can initialize those mojo stuff
+ // they're interested in later after they got a message loop ready.
if (!CanInitializeMojo())
return;
+ // monitor must not use HeapMojoRemote. TimeZoneController is not managed by
+ // Oilpan. monitor is only used to bind receiver_ here and never used
+ // again.
mojo::Remote<device::mojom::blink::TimeZoneMonitor> monitor;
Platform::Current()->GetBrowserInterfaceBroker()->GetInterface(
monitor.BindNewPipeAndPassReceiver());
@@ -107,7 +137,6 @@ TimeZoneController::SetTimeZoneOverride(const String& timezone_id) {
VLOG(1) << "Invalid override timezone id: " << timezone_id;
return nullptr;
}
-
instance().has_timezone_id_override_ = true;
return std::unique_ptr<TimeZoneOverride>(new TimeZoneOverride());
@@ -139,4 +168,9 @@ void TimeZoneController::OnTimeZoneChange(const String& timezone_id) {
SetIcuTimeZoneAndNotifyV8(timezone_id);
}
+// static
+void TimeZoneController::ChangeTimeZoneForTesting(const String& timezone) {
+ instance().OnTimeZoneChange(timezone);
+}
+
} // namespace blink