[M108 Migration][HBBTV] Implement ewk_context_register_jsplugin_mime_types API 84/289084/5
authorfr.fang <fr.fang@samsung.com>
Tue, 28 Feb 2023 12:20:54 +0000 (20:20 +0800)
committerBot Blink <blinkbot@samsung.com>
Wed, 1 Mar 2023 12:59:14 +0000 (12:59 +0000)
This is required to prevent the renderer from creating frames to handle JS
plugins mimetypes, if those mime types are supported by the renderer by default.

Reference:
https://review.tizen.org/gerrit/#/c/282683

Change-Id: I4ffbcccac84b5dc0ec531fbbcf67de18bef9e569
Signed-off-by: fr.fang <fr.fang@samsung.com>
21 files changed:
third_party/blink/common/mime_util/mime_util.cc
third_party/blink/public/common/mime_util/mime_util.h
third_party/blink/public/web/web_security_policy.h
third_party/blink/renderer/core/html/html_object_element.cc
third_party/blink/renderer/core/html/html_plugin_element.cc
third_party/blink/renderer/platform/network/mime/mime_type_registry.cc
third_party/blink/renderer/platform/network/mime/mime_type_registry.h
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/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.h
tizen_src/ewk/efl_integration/wrt/hbbtv_widget.cc
tizen_src/ewk/efl_integration/wrt/hbbtv_widget.h
tizen_src/ewk/efl_integration/wrt/hbbtv_widget_host.cc
tizen_src/ewk/efl_integration/wrt/hbbtv_widget_host.h

index a3a7b9e..cac1bee 100644 (file)
@@ -125,6 +125,11 @@ class MimeUtil {
 
   bool IsSupportedMimeType(const std::string& mime_type) const;
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  void RegisterJavascriptPluginMimeTypes(const std::string& mime_type);
+  bool IsSupportedJavascriptPluginMimeType(const std::string& mime_type) const;
+#endif
+
  private:
   friend struct base::LazyInstanceTraitsBase<MimeUtil>;
 
@@ -136,6 +141,9 @@ class MimeUtil {
   MimeTypes non_image_types_;
   MimeTypes unsupported_text_types_;
   MimeTypes javascript_types_;
+#if BUILDFLAG(IS_TIZEN_TV)
+  MimeTypes javascript_plugin_types_;
+#endif
 };
 
 MimeUtil::MimeUtil() {
@@ -200,6 +208,22 @@ bool MimeUtil::IsSupportedMimeType(const std::string& mime_type) const {
          IsSupportedNonImageMimeType(mime_type);
 }
 
+#if BUILDFLAG(IS_TIZEN_TV)
+void MimeUtil::RegisterJavascriptPluginMimeTypes(
+    const std::string& mime_types) {
+  std::stringstream stream(mime_types);
+  std::string mime_type;
+  while (std::getline(stream, mime_type, ','))
+    javascript_plugin_types_.insert(base::ToLowerASCII(mime_type));
+}
+
+bool MimeUtil::IsSupportedJavascriptPluginMimeType(
+    const std::string& mime_type) const {
+  return javascript_plugin_types_.find(base::ToLowerASCII(mime_type)) !=
+         javascript_plugin_types_.end();
+}
+#endif
+
 // This variable is Leaky because it is accessed from WorkerPool threads.
 static base::LazyInstance<MimeUtil>::Leaky g_mime_util =
     LAZY_INSTANCE_INITIALIZER;
@@ -230,4 +254,13 @@ bool IsSupportedMimeType(const std::string& mime_type) {
   return g_mime_util.Get().IsSupportedMimeType(mime_type);
 }
 
+#if BUILDFLAG(IS_TIZEN_TV)
+void RegisterJavascriptPluginMimeTypes(const std::string& mime_type) {
+  g_mime_util.Get().RegisterJavascriptPluginMimeTypes(mime_type);
+}
+
+bool IsSupportedJavascriptPluginMimeType(const std::string& mime_type) {
+  return g_mime_util.Get().IsSupportedJavascriptPluginMimeType(mime_type);
+}
+#endif
 }  // namespace blink
index 9675518..037936e 100644 (file)
@@ -6,6 +6,7 @@
 #define THIRD_PARTY_BLINK_PUBLIC_COMMON_MIME_UTIL_MIME_UTIL_H_
 
 #include <string>
+#include "build/build_config.h"
 #include "third_party/blink/public/common/common_export.h"
 
 namespace blink {
@@ -23,6 +24,11 @@ bool BLINK_COMMON_EXPORT IsJSONMimeType(const std::string& mime_type);
 
 // Convenience function.
 bool BLINK_COMMON_EXPORT IsSupportedMimeType(const std::string& mime_type);
+#if BUILDFLAG(IS_TIZEN_TV)
+void BLINK_COMMON_EXPORT RegisterJavascriptPluginMimeTypes(const std::string&);
+bool BLINK_COMMON_EXPORT
+IsSupportedJavascriptPluginMimeType(const std::string&);
+#endif
 
 }  // namespace blink
 
index f134b97..e0a7094 100644 (file)
@@ -132,7 +132,7 @@ class BLINK_EXPORT WebSecurityPolicy {
   // 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.
+  // Registers a non-HTTP URL scheme which can be sent CORS requests.
   BLINK_EXPORT static void RegisterURLSchemeAsCORSEnabled(const WebString&);
 #endif
 
index 98010b5..f3b0121 100644 (file)
@@ -105,7 +105,12 @@ void HTMLObjectElement::ParseAttribute(
     // specified?
     ReloadPluginOnAttributeChange(name);
   } else if (name == html_names::kDataAttr) {
+#if BUILDFLAG(IS_TIZEN_TV)
+    if (!MIMETypeRegistry::IsSupportedJavaScriptPluginMIMEType(service_type_))
+      url_ = StripLeadingAndTrailingHTMLSpaces(params.new_value);
+#else
     SetUrl(StripLeadingAndTrailingHTMLSpaces(params.new_value));
+#endif
     if (GetLayoutObject() && IsImageType()) {
       SetNeedsPluginUpdate(true);
       if (!image_loader_)
index e62d977..cbf08b5 100644 (file)
@@ -534,6 +534,10 @@ bool HTMLPlugInElement::IsFocusableStyle() const {
 
 HTMLPlugInElement::ObjectContentType HTMLPlugInElement::GetObjectContentType()
     const {
+#if BUILDFLAG(IS_TIZEN_TV)
+  if (MIMETypeRegistry::IsSupportedJavaScriptPluginMIMEType(service_type_))
+    return ObjectContentType::kNone;
+#endif
   String mime_type = service_type_;
   KURL url = GetDocument().CompleteURL(url_);
   if (mime_type.empty()) {
index 646a485..19fce52 100644 (file)
@@ -259,4 +259,10 @@ bool MIMETypeRegistry::IsPlainTextMIMEType(const String& mime_type) {
            EqualIgnoringASCIICase(mime_type, "text/xsl"));
 }
 
+#if BUILDFLAG(IS_TIZEN_TV)
+bool MIMETypeRegistry::IsSupportedJavaScriptPluginMIMEType(
+    const String& mime_type) {
+  return IsSupportedJavascriptPluginMimeType(ToASCIIOrEmpty(mime_type));
+}
+#endif
 }  // namespace blink
index 845c8b5..edce9a6 100644 (file)
@@ -121,6 +121,11 @@ class PLATFORM_EXPORT MIMETypeRegistry {
 
   // Checks to see if a mime type is suitable for being loaded as plain text.
   static bool IsPlainTextMIMEType(const String& mime_type);
+#if BUILDFLAG(IS_TIZEN_TV)
+  // Check to see if a mime type is a valid registered JavaScript plugin mime
+  // type.
+  static bool IsSupportedJavaScriptPluginMIMEType(const String&);
+#endif
 };
 
 }  // namespace blink
index 230c974..5e8a04a 100644 (file)
@@ -18,6 +18,8 @@ const char kInjectedBundlePath[] = "injected-bundle-path";
 const char kApplicationType[] = "application-type";
 // CORS enabled URL schemes
 const char kCORSEnabledURLSchemes[] = "cors-enabled-url-schemes";
+// JS plugin mime types
+const char kJSPluginMimeTypes[] = "jsplugin-mime-types";
 #endif
 
 // Widget Info
index 75318c7..569fe0d 100644 (file)
@@ -23,6 +23,8 @@ CONTENT_EXPORT extern const char kInjectedBundlePath[];
 CONTENT_EXPORT extern const char kApplicationType[];
 // CORS enabled url schemes
 CONTENT_EXPORT extern const char kCORSEnabledURLSchemes[];
+// JS plugin mime types
+CONTENT_EXPORT extern const char kJSPluginMimeTypes[];
 #endif
 CONTENT_EXPORT extern const char kTizenAppId[];
 CONTENT_EXPORT extern const char kTizenAppVersion[];
index 6162bc0..c3430cd 100644 (file)
@@ -255,6 +255,9 @@ IPC_MESSAGE_CONTROL2(EwkProcessMsg_SetExtensibleAPI,
 IPC_MESSAGE_ROUTED0(EwkHostMsg_DidNotAllowScript)
 
 #if BUILDFLAG(IS_TIZEN_TV)
+IPC_MESSAGE_CONTROL1(HbbtvMsg_RegisterJSPluginMimeTypes,
+                     std::string /* mime types */)
+
 IPC_MESSAGE_CONTROL1(HbbtvMsg_RegisterURLSchemesAsCORSEnabled,
                      std::string /* scheme */)
 
index a85d627..5940a6f 100644 (file)
@@ -989,6 +989,17 @@ void EWebContext::SetApplicationType(
   }
 }
 
+void EWebContext::RegisterJSPluginMimeTypes(const Eina_List* mime_types_list) {
+  std::string mime_types;
+  const Eina_List* it;
+  const void* mime_type;
+  EINA_LIST_FOREACH(mime_types_list, it, mime_type) {
+    mime_types += static_cast<const char*>(mime_type);
+    mime_types += ",";
+  }
+  HbbtvWidgetHost::Get().RegisterJSPluginMimeTypes(mime_types);
+}
+
 void EWebContext::RegisterURLSchemesAsCORSEnabled(
     const Eina_List* schemes_list) {
   std::string schemes;
index 8d3d772..c97389e 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 RegisterJSPluginMimeTypes(const Eina_List*);
   void RegisterURLSchemesAsCORSEnabled(const Eina_List* schemes_list);
 #endif
 
index cd5a2e9..b685586 100644 (file)
@@ -340,6 +340,10 @@ Ewk_Application_Type Ewk_Context::GetApplicationType() const {
   return impl->GetApplicationType();
 }
 
+void Ewk_Context::RegisterJSPluginMimeTypes(const Eina_List* mime_types) {
+  impl->RegisterJSPluginMimeTypes(mime_types);
+}
+
 void Ewk_Context::RegisterURLSchemesAsCORSEnabled(
     const Eina_List* schemes_list) {
   impl->RegisterURLSchemesAsCORSEnabled(schemes_list);
index 1748281..83991a0 100644 (file)
@@ -159,6 +159,8 @@ struct Ewk_Context : public base::RefCounted<Ewk_Context> {
   void SetApplicationType(const Ewk_Application_Type application_type);
   Ewk_Application_Type GetApplicationType() const;
 
+  // Registers JS plugins mime types
+  void RegisterJSPluginMimeTypes(const Eina_List*);
   // Registers url scheme as CORS enabled for HBBTV
   void RegisterURLSchemesAsCORSEnabled(const Eina_List* schemes_list);
 #endif
index 2eee282..2d20da3 100644 (file)
@@ -883,7 +883,13 @@ void ewk_context_register_url_schemes_as_cors_enabled(Ewk_Context* context, cons
 
 void ewk_context_register_jsplugin_mime_types(Ewk_Context* context, const Eina_List* mime_types)
 {
-  LOG_EWK_API_MOCKUP();
+#if BUILDFLAG(IS_TIZEN_TV)
+  EINA_SAFETY_ON_NULL_RETURN(context);
+  EINA_SAFETY_ON_NULL_RETURN(mime_types);
+  context->RegisterJSPluginMimeTypes(mime_types);
+#else
+  LOG_EWK_API_MOCKUP("Only for Tizen TV");
+#endif
 }
 
 void ewk_context_websdi_set(Eina_Bool enable)
index 3c0120d..fd006f5 100644 (file)
 #include "components/autofill/core/common/password_generation_util.h"
 #endif
 
-#include "renderer/content_renderer_client_efl.h"
 #include "common/navigation_policy_params.h"
 #include "content/common/wrt/wrt_url_parse.h"
+#include "renderer/content_renderer_client_efl.h"
+#include "wrt/hbbtv_widget.h"
 #include "wrt/wrtwidget.h"
 
 #if BUILDFLAG(IS_TIZEN_TV)
@@ -180,15 +181,28 @@ void ContentRendererClientEfl::DidCreateScriptContext(
     content::RenderFrame* render_frame,
     v8::Handle<v8::Context> context,
     int world_id) {
-  if (widget_) {
-    widget_->StartSession(context, render_frame->GetRoutingID(),
-                          render_frame->GetWebFrame()
-                              ->GetDocument()
-                              .BaseURL()
-                              .GetString()
-                              .Utf8()
-                              .c_str());
+  if (!widget_)
+    return;
+
+#if BUILDFLAG(IS_TIZEN_TV)
+  if (widget_->GetType() == V8Widget::Type::HBBTV) {
+    const base::CommandLine& command_line =
+        *base::CommandLine::ForCurrentProcess();
+    if (command_line.HasSwitch(switches::kJSPluginMimeTypes)) {
+      static_cast<HbbtvWidget*>(widget_.get())
+          ->RegisterJSPluginMimeTypes(
+              command_line.GetSwitchValueASCII(switches::kJSPluginMimeTypes));
+    }
   }
+#endif
+
+  widget_->StartSession(context, render_frame->GetRoutingID(),
+                        render_frame->GetWebFrame()
+                            ->GetDocument()
+                            .BaseURL()
+                            .GetString()
+                            .Utf8()
+                            .c_str());
 }
 
 void ContentRendererClientEfl::WillReleaseScriptContext(
index 29d4835..241e105 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) {};
+  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,
index 93f5a49..1c49ba3 100644 (file)
@@ -9,6 +9,7 @@
 #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/common/mime_util/mime_util.h"
 #include "third_party/blink/public/web/web_security_policy.h"
 #include "wrt/hbbtv_dynamicplugin.h"
 
@@ -20,6 +21,8 @@ class HbbtvRenderThreadObserver : public content::RenderThreadObserver {
   bool OnControlMessageReceived(const IPC::Message& message) override {
     bool handled = true;
     IPC_BEGIN_MESSAGE_MAP(HbbtvRenderThreadObserver, message)
+    IPC_MESSAGE_FORWARD(HbbtvMsg_RegisterJSPluginMimeTypes, hbbtv_widget_,
+                        HbbtvWidget::RegisterJSPluginMimeTypes)
     IPC_MESSAGE_FORWARD(HbbtvMsg_RegisterURLSchemesAsCORSEnabled, hbbtv_widget_,
                         HbbtvWidget::RegisterURLSchemesAsCORSEnabled)
     IPC_MESSAGE_UNHANDLED(handled = false)
@@ -60,6 +63,11 @@ content::RenderThreadObserver* HbbtvWidget::GetObserver() {
   return observer_.get();
 }
 
+void HbbtvWidget::RegisterJSPluginMimeTypes(std::string mime_types) {
+  LOG(INFO) << "mime_types = " << mime_types;
+  blink::RegisterJavascriptPluginMimeTypes(mime_types);
+}
+
 void HbbtvWidget::RegisterURLSchemesAsCORSEnabled(std::string schemes) {
   LOG(INFO) << "schemes = " << schemes;
   if (schemes_ == schemes)
index 9329bcf..08a41ad 100644 (file)
@@ -20,6 +20,7 @@ class HbbtvWidget : public V8Widget {
   ~HbbtvWidget() override;
 
   content::RenderThreadObserver* GetObserver() override;
+  void RegisterJSPluginMimeTypes(std::string);
   void RegisterURLSchemesAsCORSEnabled(std::string scheme);
 
  private:
index 1505311..a665f3b 100644 (file)
@@ -39,6 +39,19 @@ HbbtvWidgetHost& HbbtvWidgetHost::Get() {
   return g_hbbtv_widget_host_getter.Get().Host();
 }
 
+void HbbtvWidgetHost::RegisterJSPluginMimeTypes(const std::string& mime_types) {
+  if (mime_types_ == mime_types)
+    return;
+
+  LOG(INFO) << "mime types " << mime_types;
+  mime_types_ = mime_types;
+  SendToAllRenderers(new HbbtvMsg_RegisterJSPluginMimeTypes(mime_types));
+}
+
+const std::string& HbbtvWidgetHost::GetJSPluginMimeTypes() {
+  return mime_types_;
+}
+
 void HbbtvWidgetHost::RegisterURLSchemesAsCORSEnabled(
     const std::string& schemes) {
   if (cors_enabled_url_schemes_ == schemes)
index 096c385..c15148c 100644 (file)
@@ -14,6 +14,9 @@ class HbbtvWidgetHost {
   static HbbtvWidgetHost& Get();
   ~HbbtvWidgetHost();
 
+  void RegisterJSPluginMimeTypes(const std::string&);
+  const std::string& GetJSPluginMimeTypes();
+
   void RegisterURLSchemesAsCORSEnabled(const std::string& schemes);
   const std::string& GetCORSEnabledURLSchemes();
 
@@ -21,6 +24,7 @@ class HbbtvWidgetHost {
   HbbtvWidgetHost();
 
   std::string cors_enabled_url_schemes_;
+  std::string mime_types_;
   friend class HbbtvWidgetHostGetter;
 };