[M120 Migration] Migrate platform language related patches. 84/309484/2
authorjiangyuwei <yuwei.jiang@samsung.com>
Thu, 11 Apr 2024 08:37:22 +0000 (16:37 +0800)
committerBot Blink <blinkbot@samsung.com>
Fri, 12 Apr 2024 19:31:39 +0000 (19:31 +0000)
1.Provide current platform language for navigator.language

Web App uses navigator.language to set language information.
But sometimes get wrong language value when user change
language in system menu.
So change language set by always listening VCONFKEY_LANGSET key.

2.Fix crash in PlatformLanguageChanged,
if destructor called before it, may cause crash.

Reference:
 - https://review.tizen.org/gerrit/293445/

Change-Id: I37d76fa4bfddc297493765d47025ca57739ed58b
Signed-off-by: jiangyuwei <yuwei.jiang@samsung.com>
content/renderer/render_thread_impl.cc
third_party/blink/public/platform/platform.h
third_party/blink/renderer/core/frame/navigator_language.cc
third_party/blink/renderer/platform/exported/platform.cc
third_party/blink/renderer/platform/language.cc
third_party/blink/renderer/platform/language.h
tizen_src/chromium_impl/content/browser/selection/selection_controller_efl.cc

index 2ea05a9..2b8189a 100644 (file)
 #include "base/test/clang_profiling.h"
 #endif
 
+#if BUILDFLAG(IS_TIZEN)
+#include "base/trace_event/trace_event.h"
+#endif
+
 namespace content {
 
 namespace {
@@ -726,6 +730,11 @@ RenderThreadImpl::~RenderThreadImpl() {
 }
 
 void RenderThreadImpl::Shutdown() {
+#if BUILDFLAG(IS_TIZEN)
+  TTRACE_WEB("RenderThreadImpl::Shutdown");
+  blink_platform_impl_->UnregisterLanguageChangedCallback();
+#endif
+
   ChildThreadImpl::Shutdown();
   // In a multi-process mode, we immediately exit the renderer.
   // Historically we had a graceful shutdown sequence here but it was
index 9e15a53..b68ce44 100644 (file)
@@ -154,6 +154,9 @@ class BLINK_PLATFORM_EXPORT Platform {
   static void InitializeMainThread(
       Platform*,
       scheduler::WebThreadScheduler* main_thread_scheduler);
+#if BUILDFLAG(IS_TIZEN)
+  static void UnregisterLanguageChangedCallback();
+#endif
   static Platform* Current();
 
   // This is another entry point for embedders that only require simple
index 36018e4..131ad10 100644 (file)
@@ -36,6 +36,9 @@ NavigatorLanguage::NavigatorLanguage(ExecutionContext* execution_context)
     : execution_context_(execution_context) {}
 
 AtomicString NavigatorLanguage::language() {
+#if BUILDFLAG(IS_TIZEN)
+  return DefaultLanguage();
+#endif
   return AtomicString(languages().front());
 }
 
index 5b21544..e9b7444 100644 (file)
@@ -298,6 +298,12 @@ void Platform::UnsetMainThreadTaskRunnerForTesting() {
       ->SetMainThreadTaskRunnerForTesting(nullptr);
 }
 
+#if BUILDFLAG(IS_TIZEN)
+void Platform::UnregisterLanguageChangedCallback() {
+  StopListeningLanguageChange();
+}
+#endif
+
 Platform* Platform::Current() {
   return g_platform;
 }
index eeb6983..3d076e7 100644 (file)
 #include "third_party/blink/renderer/platform/text/platform_locale.h"
 #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
 #include "third_party/blink/renderer/platform/wtf/thread_specific.h"
+#if BUILDFLAG(IS_TIZEN)
+#include <vconf/vconf.h>
+#include "base/trace_event/trace_event.h"
+#endif
 
 namespace blink {
 
@@ -38,9 +42,22 @@ static String CanonicalizeLanguageIdentifier(const String& language_code) {
   String copied_code = language_code;
   // Platform::defaultLocale() might provide a language code with '_'.
   copied_code.Replace('_', '-');
+#if BUILDFLAG(IS_TIZEN)
+  size_t dot_position = copied_code.find('.');
+  if (dot_position > 0)
+    copied_code.Truncate(dot_position);
+#endif
   return copied_code;
 }
 
+#if BUILDFLAG(IS_TIZEN)
+static bool language_changed_ = false;
+static bool language_changed_callback_registered_ = false;
+static void PlatformLanguageChanged(keynode_t*, void* data) {
+  language_changed_ = true;
+}
+#endif
+
 // Main thread static AtomicString. This can be safely shared across threads.
 const AtomicString* g_platform_language = nullptr;
 
@@ -48,6 +65,23 @@ const AtomicString& PlatformLanguage() {
   DCHECK(g_platform_language->Impl()->IsStatic())
       << "global language string is used from multiple threads, and must be "
          "static";
+#if BUILDFLAG(IS_TIZEN)
+  DEFINE_STATIC_LOCAL(AtomicString, g_vconf_language, ());
+  if (language_changed_) {
+    // Update the platform language from vconf
+    char* lang = vconf_get_str(VCONFKEY_LANGSET);
+    if (lang) {
+      g_vconf_language = AtomicString(CanonicalizeLanguageIdentifier(lang));
+      TTRACE_WEB("PlatformLanguage, get vconf language: %s",
+                 g_vconf_language.GetString().Utf8().c_str());
+      free(lang);
+    }
+    language_changed_ = false;
+  }
+
+  if (!g_vconf_language.empty())
+    return g_vconf_language;
+#endif
   return *g_platform_language;
 }
 
@@ -59,8 +93,26 @@ Vector<AtomicString>& PreferredLanguagesOverride() {
 
 }  // namespace
 
+#if BUILDFLAG(IS_TIZEN)
+void StopListeningLanguageChange() {
+  if (language_changed_callback_registered_)
+    vconf_ignore_key_changed(VCONFKEY_LANGSET, PlatformLanguageChanged);
+
+  language_changed_callback_registered_ = false;
+}
+#endif
+
 void InitializePlatformLanguage() {
   DCHECK(IsMainThread());
+#if BUILDFLAG(IS_TIZEN)
+  if (!language_changed_callback_registered_) {
+    // Register a callback to handle the platform language change
+    vconf_notify_key_changed(VCONFKEY_LANGSET, PlatformLanguageChanged,
+                             nullptr);
+    language_changed_callback_registered_ = true;
+    language_changed_ = true;
+  }
+#endif
   DEFINE_STATIC_LOCAL(
       // We add the platform language as a static string for two reasons:
       // 1. it can be shared across threads.
index 62bd667..4070167 100644 (file)
@@ -45,6 +45,9 @@ PLATFORM_EXPORT wtf_size_t
 IndexOfBestMatchingLanguageInList(const AtomicString& language,
                                   const Vector<AtomicString>& language_list);
 PLATFORM_EXPORT void InitializePlatformLanguage();
+#if BUILDFLAG(IS_TIZEN)
+void StopListeningLanguageChange();
+#endif
 
 }  // namespace blink
 
index c148e38..ee42c7d 100644 (file)
@@ -93,6 +93,11 @@ SelectionControllerEfl::SelectionControllerEfl(RenderWidgetHostViewAura* rwhva)
 SelectionControllerEfl::~SelectionControllerEfl() {
   if (ecore_events_filter_)
     ecore_event_filter_del(ecore_events_filter_);
+
+#if BUILDFLAG(IS_TIZEN)
+  vconf_ignore_key_changed(VCONFKEY_LANGSET, PlatformLanguageChanged);
+#endif
+
   if (GetSelectionStatus())
     ClearSelectionViaEWebView();
   HideHandleAndContextMenu();