[M120 Migration][XWalkExtension] Support IME in xwalk exension 65/308365/2 submit/tizen/20240326.160017
authorjinbei09 <jinbei09.dai@samsung.com>
Wed, 28 Feb 2024 09:48:13 +0000 (17:48 +0800)
committerBot Blink <blinkbot@samsung.com>
Tue, 26 Mar 2024 15:18:13 +0000 (15:18 +0000)
Due to the reason that pepper plugin will be converted to xwalk plugin
Samsung extended IME PPAPI can't be used. Need to provide IME function in
xwalk plugin.
Call Sequence:
(WRT)
sendRuntimeMessage(js) ->
WRTXWalkExtensionBrowserTV::HandleRuntimeMessageInternal ->
SetIMERecommendedWords/SetIMERecommendedWordsType

(HBBTV)
sendRuntimeMessage(js) ->
XWalkExtensionBrowserEfl::HandleRuntimeMessageInternal ->
SetIMERecommendedWords/SetIMERecommendedWordsType

Support SetIMERecommendedWords and SetIMERecommendedWordsType

Migrated from tizen 8.0:
https://review.tizen.org/gerrit/#/c/platform/framework/web/chromium-efl/+/296727/
https://review.tizen.org/gerrit/#/c/platform/framework/web/chromium-efl/+/298681/

Change-Id: I3323c4f4b1800b651d941291930ce2ef65820805
Signed-off-by: jinbei09 <jinbei09.dai@samsung.com>
(cherry picked from commit f567edbefd181c35e2452d9f14b8534b8882c477)

tizen_src/ewk/efl_integration/browser/xwalk_extension_browser_efl.cc

index 08f29dc..fa12f8a 100644 (file)
@@ -6,11 +6,68 @@
 
 #include "base/logging.h"
 
+#if BUILDFLAG(IS_TIZEN_TV)
+#include "content/browser/renderer_host/render_widget_host_view_aura.h"
+#include "content/browser/renderer_host/rwhv_aura_common_helper_efl.h"
+#include "content/browser/web_contents/web_contents_impl.h"
+#endif
+
 namespace content {
 
+namespace {
+
+#if BUILDFLAG(IS_TIZEN_TV)
+content::RWHVAuraCommonHelperEfl* GetRWHVAEflHelper() {
+  auto* web_contents = content::WebContentsImpl::GetAllWebContents().front();
+  auto* rwhva = static_cast<content::RenderWidgetHostViewAura*>(
+      web_contents->GetRenderWidgetHostView());
+  if (!rwhva || !rwhva->aura_efl_helper()) {
+    LOG(ERROR) << "RWHV is not created yet!";
+    return nullptr;
+  }
+  return rwhva->aura_efl_helper();
+}
+#endif
+
+}  // namespace
+
 std::string XWalkExtensionBrowserEfl::HandleRuntimeMessageInternal(
     const std::string& type, const std::string& value) {
   LOG(INFO) << "type : " << type;
+
+#if BUILDFLAG(IS_TIZEN_TV)
+  if (type == "webapis://appcommon/setIMERecommendedWords") {
+    if (!GetRWHVAEflHelper()) {
+      LOG(ERROR) << "RWHV is not created yet!";
+      return "error";
+    }
+    std::string auto_words = "autoword=";
+    static const char AUTOWORD_ITEM_DELIMETER[] = {0x07, 0x06, 0x00};
+    std::string temp = value;
+    std::size_t found = temp.find_first_of(',');
+    while (found != std::string::npos) {
+      auto_words.append(temp.substr(0, found));
+      auto_words.append(AUTOWORD_ITEM_DELIMETER);
+      temp = temp.substr(found + 1);
+      found = temp.find_first_of(',');
+    }
+    auto_words.append(temp);
+    LOG(INFO) << "auto_words=[" << auto_words << "]";
+    GetRWHVAEflHelper()->SetIMERecommendedWords(auto_words);
+    return "success";
+  } else if (type == "webapis://appcommon/setIMERecommendedType") {
+    if (!GetRWHVAEflHelper()) {
+      LOG(ERROR) << "RWHV is not created yet!";
+      return "error";
+    }
+    GetRWHVAEflHelper()->SetIMERecommendedWordsType(value == "1" ? true
+                                                                 : false);
+    return "success";
+  } else {
+    LOG(ERROR) << "Unknown message type : " << type;
+  }
+#endif
+
   // TODO(dh81.song)
   // According to xwalk extensions, this might handle internal messages.
   return std::string();