[M108 Migration][VD][HBBTV][API] Support DVB scheme for HBBTV 46/289046/2
authorfr.fang <fr.fang@samsung.com>
Tue, 28 Feb 2023 01:15:08 +0000 (09:15 +0800)
committerBot Blink <blinkbot@samsung.com>
Tue, 28 Feb 2023 10:35:30 +0000 (10:35 +0000)
1.This CL implement api ewk_context_register_url_schemes_as_cors_enabled.
With this CL, WebEngine can parse dvb url host as CORS.
2.Remove WRT dependency of injected bundle, only HbbTV uses it.
3.Fix the loss of IPC message caused by multithreading.

This patch includes :
1) Added protection for NULL message in IPC.
   There was no exception handling for the NULL message
   in low memory situation.
2) Fix the issue the deleted message is used again.
   When multiple render process exit ,the message is deleted
   after it send to one render process.
   Copy the message before it is sent to render process.

References:
https://review.tizen.org/gerrit/#/c/251270/
https://review.tizen.org/gerrit/#/c/250990
https://review.tizen.org/gerrit/#/c/255829

Change-Id: Iaf0084a385649fda71d2c0856398b0c26458c919
Signed-off-by: fr.fang <fr.fang@samsung.com>
26 files changed:
ipc/ipc_channel_mojo.cc
third_party/blink/public/web/web_security_policy.h
third_party/blink/renderer/core/exported/web_security_policy.cc
third_party/blink/renderer/platform/weborigin/scheme_registry.cc
third_party/blink/renderer/platform/weborigin/scheme_registry.h
tizen_src/ewk/efl_integration/BUILD.gn
tizen_src/ewk/efl_integration/common/content_switches_efl.cc
tizen_src/ewk/efl_integration/common/content_switches_efl.h
tizen_src/ewk/efl_integration/common/render_messages_ewk.h
tizen_src/ewk/efl_integration/content_browser_client_efl.cc
tizen_src/ewk/efl_integration/eweb_context.cc
tizen_src/ewk/efl_integration/eweb_context.h
tizen_src/ewk/efl_integration/private/ewk_context_private.cc
tizen_src/ewk/efl_integration/private/ewk_context_private.h
tizen_src/ewk/efl_integration/public/ewk_context.cc
tizen_src/ewk/efl_integration/renderer/content_renderer_client_efl.cc
tizen_src/ewk/efl_integration/wrt/dynamicplugin.cc
tizen_src/ewk/efl_integration/wrt/dynamicplugin.h
tizen_src/ewk/efl_integration/wrt/hbbtv_dynamicplugin.cc [new file with mode: 0644]
tizen_src/ewk/efl_integration/wrt/hbbtv_dynamicplugin.h [new file with mode: 0644]
tizen_src/ewk/efl_integration/wrt/hbbtv_widget.cc [new file with mode: 0644]
tizen_src/ewk/efl_integration/wrt/hbbtv_widget.h [new file with mode: 0644]
tizen_src/ewk/efl_integration/wrt/hbbtv_widget_host.cc [new file with mode: 0644]
tizen_src/ewk/efl_integration/wrt/hbbtv_widget_host.h [new file with mode: 0644]
tizen_src/ewk/efl_integration/wrt/v8widget.cc
tizen_src/ewk/efl_integration/wrt/wrt_widget_host.cc

index 2189911..2aabd6e 100644 (file)
@@ -268,12 +268,6 @@ void ChannelMojo::OnAssociatedInterfaceRequest(
 }
 
 bool ChannelMojo::Send(Message* message) {
-  DVLOG(2) << "sending message @" << message << " on channel @" << this
-           << " with type " << message->type();
-#if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED)
-  Logging::GetInstance()->OnSendMessage(message);
-#endif
-
   std::unique_ptr<Message> scoped_message = base::WrapUnique(message);
   if (!message_reader_)
     return false;
@@ -326,6 +320,10 @@ MojoResult ChannelMojo::ReadFromMessageAttachmentSet(
   DCHECK(!*handles);
 
   MojoResult result = MOJO_RESULT_OK;
+#if BUILDFLAG(IS_TIZEN_TV)
+  if (!message)
+    return MOJO_RESULT_INVALID_ARGUMENT;
+#endif
   if (!message->HasAttachments())
     return result;
 
index 0d2516e..f134b97 100644 (file)
@@ -131,6 +131,10 @@ class BLINK_EXPORT WebSecurityPolicy {
   // renderer whether the script content has changed rather than relying on a
   // response time match from the network cache.
   static void RegisterURLSchemeAsCodeCacheWithHashing(const WebString&);
+#if BUILDFLAG(IS_TIZEN_TV)
+    // Registers a non-HTTP URL scheme which can be sent CORS requests.
+  BLINK_EXPORT static void RegisterURLSchemeAsCORSEnabled(const WebString&);
+#endif
 
  private:
   WebSecurityPolicy() = delete;
index f6782f5..0a39346 100644 (file)
@@ -157,5 +157,10 @@ void WebSecurityPolicy::RegisterURLSchemeAsCodeCacheWithHashing(
     const WebString& scheme) {
   SchemeRegistry::RegisterURLSchemeAsCodeCacheWithHashing(scheme);
 }
-
+#if BUILDFLAG(IS_TIZEN_TV)
+void WebSecurityPolicy::RegisterURLSchemeAsCORSEnabled(
+    const WebString& scheme) {
+  SchemeRegistry::RegisterURLSchemeAsCORSEnabled(scheme);
+}
+#endif
 }  // namespace blink
index 4eadf46..d8d2a37 100644 (file)
@@ -270,6 +270,13 @@ bool SchemeRegistry::ShouldTreatURLSchemeAsAllowingServiceWorkers(
   return GetURLSchemesRegistry().service_worker_schemes.Contains(scheme);
 }
 
+#if BUILDFLAG(IS_TIZEN_TV)
+void SchemeRegistry::RegisterURLSchemeAsCORSEnabled(const String& scheme) {
+  DCHECK_EQ(scheme, scheme.LowerASCII());
+  GetMutableURLSchemesRegistry().cors_enabled_schemes.insert(scheme);
+}
+#endif
+
 void SchemeRegistry::RegisterURLSchemeAsSupportingFetchAPI(
     const String& scheme) {
   DCHECK_EQ(scheme, scheme.LowerASCII());
index fa56039..ef51319 100644 (file)
@@ -76,6 +76,9 @@ class PLATFORM_EXPORT SchemeRegistry {
       const String& scheme);
 
   static bool ShouldTreatURLSchemeAsCorsEnabled(const String& scheme);
+#if BUILDFLAG(IS_TIZEN_TV)
+  static void RegisterURLSchemeAsCORSEnabled(const String& scheme);
+#endif
 
   // Serialize the registered schemes in a comma-separated list.
   static String ListOfCorsEnabledURLSchemes();
index 2624586..78b2eb7 100755 (executable)
@@ -615,6 +615,12 @@ shared_library("chromium-ewk") {
     sources += [
       "common/application_type.cc",
       "common/application_type.h",
+      "wrt/hbbtv_dynamicplugin.cc",
+      "wrt/hbbtv_dynamicplugin.h",
+      "wrt/hbbtv_widget.cc",
+      "wrt/hbbtv_widget.h",
+      "wrt/hbbtv_widget_host.cc",
+      "wrt/hbbtv_widget_host.h",
     ]
   }
 
index d7f83f9..230c974 100644 (file)
@@ -16,6 +16,8 @@ const char kInjectedBundlePath[] = "injected-bundle-path";
 #if BUILDFLAG(IS_TIZEN_TV)
 // Save ApplicationType in command line.
 const char kApplicationType[] = "application-type";
+// CORS enabled URL schemes
+const char kCORSEnabledURLSchemes[] = "cors-enabled-url-schemes";
 #endif
 
 // Widget Info
index ff0b1a2..75318c7 100644 (file)
@@ -21,6 +21,8 @@ CONTENT_EXPORT extern const char kInjectedBundlePath[];
 #if BUILDFLAG(IS_TIZEN_TV)
 // Save ApplicationType in command line.
 CONTENT_EXPORT extern const char kApplicationType[];
+// CORS enabled url schemes
+CONTENT_EXPORT extern const char kCORSEnabledURLSchemes[];
 #endif
 CONTENT_EXPORT extern const char kTizenAppId[];
 CONTENT_EXPORT extern const char kTizenAppVersion[];
index ecc54df..6162bc0 100644 (file)
@@ -253,3 +253,9 @@ IPC_MESSAGE_CONTROL2(EwkProcessMsg_SetExtensibleAPI,
                      bool /* enable */)
 
 IPC_MESSAGE_ROUTED0(EwkHostMsg_DidNotAllowScript)
+
+#if BUILDFLAG(IS_TIZEN_TV)
+IPC_MESSAGE_CONTROL1(HbbtvMsg_RegisterURLSchemesAsCORSEnabled,
+                     std::string /* scheme */)
+
+#endif
index 5107d5a..a3c723d 100644 (file)
 #include "content/browser/speech/tizen_speech_recognition_manager_delegate.h"
 #endif
 
+#if BUILDFLAG(IS_TIZEN_TV)
+#include "wrt/hbbtv_widget_host.h"
+#endif
+
 using web_contents_utils::WebContentsFromFrameID;
 using web_contents_utils::WebContentsFromViewID;
 using web_contents_utils::WebViewFromWebContents;
@@ -121,6 +125,13 @@ void AppendExtraCommandLineSwitchesInternal(base::CommandLine* command_line,
   command_line->AppendSwitchASCII(
       switches::kApplicationType,
       base::NumberToString(static_cast<int>(application_type)));
+
+  const std::string& cors_enabled_url_schemes =
+      HbbtvWidgetHost::Get().GetCORSEnabledURLSchemes();
+  if (!cors_enabled_url_schemes.empty()) {
+    command_line->AppendSwitchASCII(switches::kCORSEnabledURLSchemes,
+                                    cors_enabled_url_schemes);
+  }
 #endif
 
   const std::string& injectedBundlePath = context->GetInjectedBundlePath();
@@ -134,17 +145,6 @@ void AppendExtraCommandLineSwitchesInternal(base::CommandLine* command_line,
   command_line->AppendSwitchASCII(switches::kTizenAppId, tizen_app_id);
   command_line->AppendSwitchASCII(switches::kTizenAppVersion,
                                   context->GetTizenAppVersion());
-
-  double scale = context->GetWidgetScale();
-  command_line->AppendSwitchASCII(switches::kWidgetScale,
-                                  base::NumberToString(scale));
-
-  const std::string& widget_theme = context->GetWidgetTheme();
-  command_line->AppendSwitchASCII(switches::kWidgetTheme, widget_theme);
-
-  const std::string& widget_encoded_bundle = context->GetWidgetEncodedBundle();
-  command_line->AppendSwitchASCII(switches::kWidgetEncodedBundle,
-                                  widget_encoded_bundle);
 }
 
 void DispatchPopupBlockedOnUIThread(int render_process_id,
index 1af63b7..a85d627 100644 (file)
@@ -52,7 +52,6 @@
 #include "ewk_global_data.h"
 #include "private/ewk_favicon_database_private.h"
 #include "private/ewk_security_origin_private.h"
-#include "wrt/dynamicplugin.h"
 #include "wrt/wrt_widget_host.h"
 
 #if BUILDFLAG(IS_TIZEN)
@@ -67,6 +66,8 @@
 
 #if BUILDFLAG(IS_TIZEN_TV)
 #include "common/application_type.h"
+#include "wrt/hbbtv_dynamicplugin.h"
+#include "wrt/hbbtv_widget_host.h"
 #endif
 
 using content::BrowserThread;
@@ -264,14 +265,15 @@ void EWebContext::SetTizenAppId(const std::string& tizen_app_id) {
     // because it is handled in crosswalk side in single process mode.
     content::GetGenericZygote()->DropProcessPrivileges(tizen_app_id_);
   }
-#if !defined(EWK_BRINGUP)  // FIXME: m108 bringup
-  // Set DynamicPlugin to convert file scheme(file://) for Tizen HbbTV.
+#if BUILDFLAG(IS_TIZEN_TV)
+  // Set DynamicPlugin to convert file scheme(file://) for HbbTV
   // Important: WRT doesn't use 'injected bundle' anymore
-  if (!tizen_app_id_.empty() && !injected_bundle_path_.empty()) {
-    DynamicPlugin* plugin = &DynamicPlugin::Get(V8Widget::Type::WRT);
+  if (application_type_ == EWK_APPLICATION_TYPE_HBBTV &&
+      !injected_bundle_path_.empty()) {
+    auto* plugin = &HbbtvDynamicPlugin::Get();
     plugin->Init(injected_bundle_path_);
   }
-#endif  // EWK_BRINGUP
+#endif  // IS_TIZEN_TV
 #endif  // IS_TIZEN
 }
 
@@ -986,6 +988,19 @@ void EWebContext::SetApplicationType(
       break;
   }
 }
+
+void EWebContext::RegisterURLSchemesAsCORSEnabled(
+    const Eina_List* schemes_list) {
+  std::string schemes;
+  const Eina_List* it;
+  const void* scheme;
+  EINA_LIST_FOREACH(schemes_list, it, scheme) {
+    schemes += static_cast<const char*>(scheme);
+    schemes += ",";
+  }
+
+  HbbtvWidgetHost::Get().RegisterURLSchemesAsCORSEnabled(schemes);
+}
 #endif
 
 void EWebContext::SetMaxRefreshRate(int max_refresh_rate) {
index a2162df..8d3d772 100644 (file)
@@ -202,6 +202,7 @@ class EWebContext {
 #if BUILDFLAG(IS_TIZEN_TV)
   void SetApplicationType(const Ewk_Application_Type application_type);
   Ewk_Application_Type GetApplicationType() const { return application_type_; }
+  void RegisterURLSchemesAsCORSEnabled(const Eina_List* schemes_list);
 #endif
 
   void EnableAppControl(bool enabled);
index 1215b15..cd5a2e9 100644 (file)
@@ -339,6 +339,11 @@ void Ewk_Context::SetApplicationType(
 Ewk_Application_Type Ewk_Context::GetApplicationType() const {
   return impl->GetApplicationType();
 }
+
+void Ewk_Context::RegisterURLSchemesAsCORSEnabled(
+    const Eina_List* schemes_list) {
+  impl->RegisterURLSchemesAsCORSEnabled(schemes_list);
+}
 #endif
 
 void Ewk_Context::SetMaxRefreshRate(int max_refresh_rate) {
index 294f21e..1748281 100644 (file)
@@ -158,6 +158,9 @@ struct Ewk_Context : public base::RefCounted<Ewk_Context> {
   // Application Type
   void SetApplicationType(const Ewk_Application_Type application_type);
   Ewk_Application_Type GetApplicationType() const;
+
+  // Registers url scheme as CORS enabled for HBBTV
+  void RegisterURLSchemesAsCORSEnabled(const Eina_List* schemes_list);
 #endif
 
   void EnableAppControl(bool enabled);
index 438dc40..64da8fa 100644 (file)
@@ -859,7 +859,13 @@ Eina_Bool ewk_context_check_accessible_path_callback_set(Ewk_Context* context, E
 
 void ewk_context_register_url_schemes_as_cors_enabled(Ewk_Context* context, const Eina_List* schemes)
 {
-  LOG_EWK_API_MOCKUP();
+#if BUILDFLAG(IS_TIZEN_TV)
+  EINA_SAFETY_ON_NULL_RETURN(context);
+  EINA_SAFETY_ON_NULL_RETURN(schemes);
+  context->RegisterURLSchemesAsCORSEnabled(schemes);
+#else
+  LOG_EWK_API_MOCKUP("Only for Tizen TV");
+#endif
 }
 
 void ewk_context_register_jsplugin_mime_types(Ewk_Context* context, const Eina_List* mime_types)
index 2e0016e..3c0120d 100644 (file)
@@ -102,6 +102,10 @@ void ContentRendererClientEfl::RenderThreadStarted() {
 
   if (command_line.HasSwitch(switches::kInjectedBundlePath)) {
     V8Widget::Type type = V8Widget::Type::WRT;
+#if BUILDFLAG(IS_TIZEN_TV)
+    if (content::IsHbbTV())
+      type = V8Widget::Type::HBBTV;
+#endif
     widget_.reset(V8Widget::CreateWidget(type, command_line));
     if (widget_->GetObserver())
       thread->AddObserver(widget_->GetObserver());
index 4520178..5900e9d 100644 (file)
@@ -9,6 +9,9 @@
 #include "base/logging.h"
 #include "common/content_switches_efl.h"
 #include "wrt/wrt_dynamicplugin.h"
+#if BUILDFLAG(IS_TIZEN_TV)
+#include "wrt/hbbtv_dynamicplugin.h"
+#endif
 
 namespace {
 const char* const kStartSessionFunction = "DynamicPluginStartSession";
@@ -113,5 +116,10 @@ DynamicPlugin::~DynamicPlugin() {
 }
 
 DynamicPlugin& DynamicPlugin::Get(V8Widget::Type type) {
+#if BUILDFLAG(IS_TIZEN_TV)
+  if (type == V8Widget::Type::HBBTV)
+    return HbbtvDynamicPlugin::Get();
+#endif
+  DCHECK_EQ(type, V8Widget::Type::WRT);
   return WrtDynamicPlugin::Get();
 }
index c822bd9..29d4835 100644 (file)
@@ -24,7 +24,7 @@ class DynamicPlugin {
   virtual bool InitRenderer(const std::string& injected_bundle_path);
 
   // Interface for WebApp URL Conversion
-  virtual void SetWidgetInfo(const std::string& tizen_app_id) = 0;
+  virtual void SetWidgetInfo(const std::string& tizen_app_id) {};
   virtual bool CanHandleParseUrl(const std::string& scheme) const = 0;
   virtual void ParseURL(std::string* old_url,
                         std::string* new_url,
diff --git a/tizen_src/ewk/efl_integration/wrt/hbbtv_dynamicplugin.cc b/tizen_src/ewk/efl_integration/wrt/hbbtv_dynamicplugin.cc
new file mode 100644 (file)
index 0000000..6ddfb90
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright 2023 Samsung Electronics. All rights resemicPlugin::ParseURL
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "wrt/hbbtv_dynamicplugin.h"
+
+namespace {
+const char* const kHbbtvUrlParsingFunction = "DynamicHbbTVUrlParsing";
+const char* const kHbbtvGetFileDecryptedDataBuffer =
+    "DynamicHbbTVGetFileDecryptedDataBuffer";
+}  // namespace
+
+HbbtvDynamicPlugin::HbbtvDynamicPlugin()
+    : DynamicPlugin(),
+      parse_hbbtv_url_(nullptr),
+      get_file_decrypted_data_buffer_(nullptr) {}
+
+bool HbbtvDynamicPlugin::Init(const std::string& injected_bundle_path) {
+  if (!DynamicPlugin::Init(injected_bundle_path))
+    return false;
+  parse_hbbtv_url_ =
+      reinterpret_cast<HbbtvParseUrlFun>(GetFunction(kHbbtvUrlParsingFunction));
+  get_file_decrypted_data_buffer_ =
+      reinterpret_cast<HbbtvGetFileDecryptedDataBufferFun>(
+          GetFunction(kHbbtvGetFileDecryptedDataBuffer));
+  return parse_hbbtv_url_ && get_file_decrypted_data_buffer_;
+}
+
+void HbbtvDynamicPlugin::ParseURL(std::string* old_url,
+                                  std::string* new_url,
+                                  const char* tizen_app_id,
+                                  bool* is_decrypted_file) {
+  if (!parse_hbbtv_url_)
+    return;
+
+  parse_hbbtv_url_(old_url, new_url, tizen_app_id, is_decrypted_file);
+}
+
+HbbtvDynamicPlugin::~HbbtvDynamicPlugin() {}
+
+HbbtvDynamicPlugin& HbbtvDynamicPlugin::Get() {
+  static HbbtvDynamicPlugin dynamic_plugin;
+  return dynamic_plugin;
+}
diff --git a/tizen_src/ewk/efl_integration/wrt/hbbtv_dynamicplugin.h b/tizen_src/ewk/efl_integration/wrt/hbbtv_dynamicplugin.h
new file mode 100644 (file)
index 0000000..ba69e20
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright 2023 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef EWK_EFL_INTEGRATION_WRT_HBBTV_DYNAMICPLUGIN_H_
+#define EWK_EFL_INTEGRATION_WRT_HBBTV_DYNAMICPLUGIN_H_
+
+#include <string>
+#include <vector>
+#include "wrt/dynamicplugin.h"
+
+typedef void (*HbbtvParseUrlFun)(std::string* old_url,
+                                 std::string* new_url,
+                                 const char* tizen_app_id,
+                                 bool* is_decrypted_file);
+typedef bool (*HbbtvGetFileDecryptedDataBufferFun)(const std::string* url,
+                                                   std::vector<char>* data);
+
+class HbbtvDynamicPlugin : public DynamicPlugin {
+ public:
+  bool Init(const std::string& injected_bundle_path) override;
+  bool CanHandleParseUrl(const std::string& scheme) const override {
+    return true;
+  }
+  void ParseURL(std::string* old_url,
+                std::string* new_url,
+                const char* tizen_app_id,
+                bool* is_decrypted_file = nullptr) override;
+
+  static HbbtvDynamicPlugin& Get();
+  ~HbbtvDynamicPlugin() override;
+
+ private:
+  HbbtvDynamicPlugin();
+
+  HbbtvDynamicPlugin(const HbbtvDynamicPlugin&) = delete;
+  HbbtvDynamicPlugin& operator=(const HbbtvDynamicPlugin&) = delete;
+
+  HbbtvParseUrlFun parse_hbbtv_url_;
+  HbbtvGetFileDecryptedDataBufferFun get_file_decrypted_data_buffer_;
+};
+
+#endif  // EWK_EFL_INTEGRATION_WRT_WRT_DYNAMICPLUGIN_H_
diff --git a/tizen_src/ewk/efl_integration/wrt/hbbtv_widget.cc b/tizen_src/ewk/efl_integration/wrt/hbbtv_widget.cc
new file mode 100644 (file)
index 0000000..93f5a49
--- /dev/null
@@ -0,0 +1,75 @@
+// Copyright 2023 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "hbbtv_widget.h"
+
+#include "command_line_efl.h"
+#include "common/content_switches_efl.h"
+#include "common/render_messages_ewk.h"
+#include "content/public/renderer/render_thread.h"
+#include "content/renderer/render_thread_impl.h"
+#include "third_party/blink/public/web/web_security_policy.h"
+#include "wrt/hbbtv_dynamicplugin.h"
+
+class HbbtvRenderThreadObserver : public content::RenderThreadObserver {
+ public:
+  explicit HbbtvRenderThreadObserver(HbbtvWidget* hbbtv_widget)
+      : hbbtv_widget_(hbbtv_widget) {}
+
+  bool OnControlMessageReceived(const IPC::Message& message) override {
+    bool handled = true;
+    IPC_BEGIN_MESSAGE_MAP(HbbtvRenderThreadObserver, message)
+    IPC_MESSAGE_FORWARD(HbbtvMsg_RegisterURLSchemesAsCORSEnabled, hbbtv_widget_,
+                        HbbtvWidget::RegisterURLSchemesAsCORSEnabled)
+    IPC_MESSAGE_UNHANDLED(handled = false)
+    IPC_END_MESSAGE_MAP()
+    return handled;
+  }
+
+ private:
+  HbbtvWidget* hbbtv_widget_;
+};
+
+HbbtvWidget::HbbtvWidget(const base::CommandLine& command_line)
+    : V8Widget(V8Widget::Type::HBBTV) {
+  DCHECK(content::RenderThread::Get())
+      << "HbbtvWidget must be constructed on the render thread";
+
+  id_ = command_line.GetSwitchValueASCII(switches::kTizenAppId);
+  if (id_.empty())
+    return;
+  observer_.reset(new HbbtvRenderThreadObserver(this));
+
+  std::string injected_bundle_path =
+      command_line.GetSwitchValueASCII(switches::kInjectedBundlePath);
+  CHECK(!injected_bundle_path.empty());
+  HbbtvDynamicPlugin::Get().InitRenderer(injected_bundle_path);
+  SetPlugin(&HbbtvDynamicPlugin::Get());
+
+  if (command_line.HasSwitch(switches::kCORSEnabledURLSchemes)) {
+    std::string cors_enabled_url_schemes =
+        command_line.GetSwitchValueASCII(switches::kCORSEnabledURLSchemes);
+    RegisterURLSchemesAsCORSEnabled(cors_enabled_url_schemes);
+  }
+}
+
+HbbtvWidget::~HbbtvWidget() {}
+
+content::RenderThreadObserver* HbbtvWidget::GetObserver() {
+  return observer_.get();
+}
+
+void HbbtvWidget::RegisterURLSchemesAsCORSEnabled(std::string schemes) {
+  LOG(INFO) << "schemes = " << schemes;
+  if (schemes_ == schemes)
+    return;
+
+  schemes_ = schemes;
+  std::stringstream stream(schemes);
+  std::string scheme;
+  while (std::getline(stream, scheme, ',')) {
+    blink::WebSecurityPolicy::RegisterURLSchemeAsCORSEnabled(
+        blink::WebString::FromUTF8(scheme));
+  }
+}
diff --git a/tizen_src/ewk/efl_integration/wrt/hbbtv_widget.h b/tizen_src/ewk/efl_integration/wrt/hbbtv_widget.h
new file mode 100644 (file)
index 0000000..9329bcf
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright 2023 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef EWK_EFL_INTEGRATION_WRT_HBBTV_WIDGET_H_
+#define EWK_EFL_INTEGRATION_WRT_HBBTV_WIDGET_H_
+
+#include <string>
+
+#include "content/public/renderer/render_thread_observer.h"
+#include "url/gurl.h"
+#include "wrt/v8widget.h"
+
+class HbbtvRenderThreadObserver;
+
+// Have to be created on the RenderThread.
+class HbbtvWidget : public V8Widget {
+ public:
+  HbbtvWidget(const base::CommandLine& command_line);
+  ~HbbtvWidget() override;
+
+  content::RenderThreadObserver* GetObserver() override;
+  void RegisterURLSchemesAsCORSEnabled(std::string scheme);
+
+ private:
+  std::string schemes_;
+  std::unique_ptr<HbbtvRenderThreadObserver> observer_;
+};
+
+#endif  // EWK_EFL_INTEGRATION_WRT_HBBTV_WIDGET_H_
diff --git a/tizen_src/ewk/efl_integration/wrt/hbbtv_widget_host.cc b/tizen_src/ewk/efl_integration/wrt/hbbtv_widget_host.cc
new file mode 100644 (file)
index 0000000..1505311
--- /dev/null
@@ -0,0 +1,55 @@
+// Copyright 2023 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "hbbtv_widget_host.h"
+
+#include "base/lazy_instance.h"
+#include "common/render_messages_ewk.h"
+#include "content/public/browser/render_process_host.h"
+
+using content::RenderProcessHost;
+
+HbbtvWidgetHost::HbbtvWidgetHost() {}
+
+HbbtvWidgetHost::~HbbtvWidgetHost() {}
+
+class HbbtvWidgetHostGetter {
+ public:
+  HbbtvWidgetHost& Host() { return host_; }
+
+ private:
+  HbbtvWidgetHost host_;
+};
+
+void SendToAllRenderers(IPC::Message* message) {
+  content::RenderProcessHost::iterator it =
+      content::RenderProcessHost::AllHostsIterator();
+  while (!it.IsAtEnd()) {
+    it.GetCurrentValue()->Send(new IPC::Message(*message));
+    it.Advance();
+  }
+  delete message;
+}
+
+base::LazyInstance<HbbtvWidgetHostGetter>::Leaky g_hbbtv_widget_host_getter =
+    LAZY_INSTANCE_INITIALIZER;
+
+HbbtvWidgetHost& HbbtvWidgetHost::Get() {
+  return g_hbbtv_widget_host_getter.Get().Host();
+}
+
+void HbbtvWidgetHost::RegisterURLSchemesAsCORSEnabled(
+    const std::string& schemes) {
+  if (cors_enabled_url_schemes_ == schemes)
+    return;
+
+  cors_enabled_url_schemes_ = schemes;
+  LOG(INFO) << "schemes = " << schemes;
+  SendToAllRenderers(
+      new HbbtvMsg_RegisterURLSchemesAsCORSEnabled(cors_enabled_url_schemes_));
+}
+
+const std::string& HbbtvWidgetHost::GetCORSEnabledURLSchemes() {
+  return cors_enabled_url_schemes_;
+}
diff --git a/tizen_src/ewk/efl_integration/wrt/hbbtv_widget_host.h b/tizen_src/ewk/efl_integration/wrt/hbbtv_widget_host.h
new file mode 100644 (file)
index 0000000..096c385
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright 2023 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef EWK_EFL_INTEGRATION_WRT_HBBTV_WIDGET_HOST
+#define EWK_EFL_INTEGRATION_WRT_HBBTV_WIDGET_HOST
+
+#include <string>
+
+class HbbtvWidgetHostGetter;
+
+class HbbtvWidgetHost {
+ public:
+  static HbbtvWidgetHost& Get();
+  ~HbbtvWidgetHost();
+
+  void RegisterURLSchemesAsCORSEnabled(const std::string& schemes);
+  const std::string& GetCORSEnabledURLSchemes();
+
+ private:
+  HbbtvWidgetHost();
+
+  std::string cors_enabled_url_schemes_;
+  friend class HbbtvWidgetHostGetter;
+};
+
+#endif  // EWK_EFL_INTEGRATION_WRT_HBBTV_WIDGET_HOST
index e2b99b5..80b92ea 100644 (file)
@@ -7,10 +7,17 @@
 #include "base/notreached.h"
 #include "wrt/dynamicplugin.h"
 #include "wrt/wrtwidget.h"
+#if BUILDFLAG(IS_TIZEN_TV)
+#include "wrt/hbbtv_widget.h"
+#endif
 
 // static
 V8Widget* V8Widget::CreateWidget(Type type,
                                  const base::CommandLine& command_line) {
+#if BUILDFLAG(IS_TIZEN_TV)
+  if (type == Type::HBBTV)
+    return new HbbtvWidget(command_line);
+#endif
   return new WrtWidget(command_line);
 }
 
index 53a4e2d..1513e10 100644 (file)
@@ -25,10 +25,11 @@ bool SendToAllRenderers(IPC::Message* message) {
   content::RenderProcessHost::iterator it =
       content::RenderProcessHost::AllHostsIterator();
   while (!it.IsAtEnd()) {
-    if (it.GetCurrentValue()->Send(message))
+    if (it.GetCurrentValue()->Send(new IPC::Message(*message)))
       result = true;
     it.Advance();
   }
+  delete message;
   return result;
 }