Binding XWalkExtension for Efl classes 64/290164/7
authorDongHyun Song <dh81.song@samsung.com>
Tue, 21 Mar 2023 04:07:58 +0000 (13:07 +0900)
committerBot Blink <blinkbot@samsung.com>
Thu, 23 Mar 2023 12:16:19 +0000 (12:16 +0000)
XWalkExtension will be common component for EWK based runtime, not
only WRT.
XWalkExtension will be applied if xwalk-extension-json-path is
defined by runtime side.

This work proceeds in the following steps:
 1) Remove WRT dependency and apply delegations
    https://review.tizen.org/gerrit/287731/
 2) Move files to tizen_src and build integration
    https://review.tizen.org/gerrit/289970/
 3) Binding XWalkExtension for Efl classes <------- current
 4) Introduce interfaces to enable XWalkExtensions

Change-Id: I70f9b9026a08d3b185b05a19a6df3fa2b6b82791
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
12 files changed:
tizen_src/chromium_impl/components/xwalk_extensions/browser/xwalk_extension_manager.cc
tizen_src/chromium_impl/components/xwalk_extensions/browser/xwalk_extension_manager.h
tizen_src/ewk/efl_integration/BUILD.gn
tizen_src/ewk/efl_integration/browser/xwalk_extension_browser_efl.cc [new file with mode: 0644]
tizen_src/ewk/efl_integration/browser/xwalk_extension_browser_efl.h [new file with mode: 0644]
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/content_browser_client_efl.cc
tizen_src/ewk/efl_integration/content_browser_client_efl.h
tizen_src/ewk/efl_integration/content_main_delegate_efl.cc
tizen_src/ewk/efl_integration/renderer/content_renderer_client_efl.cc
wrt/src/renderer/wrt_render_frame_observer.cc

index 1af1fa1..ace3201 100644 (file)
@@ -89,6 +89,16 @@ void XWalkExtensionManager::SetPreloadHandle(
   preload_handle_[lib_path] = handle;
 }
 
+void XWalkExtensionManager::LoadExtensionsByJsonPath(
+    const std::string& json_path) {
+  if (is_loaded_by_json_path_)
+    return;
+
+  std::set<std::string> files;
+  ParseMetadata(json_path, &files, XWALK_EXTENSION_PATH);
+  is_loaded_by_json_path_ = true;
+}
+
 void XWalkExtensionManager::LoadUIAppExtensions() {
   if (is_loaded_for_web_app_)
     return;
index b37fd42..4714510 100644 (file)
@@ -40,6 +40,7 @@ class XWalkExtensionManager : public mojom::XWalkExtensionBrowser {
 
   void ClearPreloadHandle(const std::string& lib_path);
   void GetRuntimeVariable(const char* key, char* value, size_t value_len);
+  void LoadExtensionsByJsonPath(const std::string& json_path);
   void LoadUIAppExtensions();
   void LoadServiceAppExtensions();
   void LoadUserExtensions(const std::string& app_path);
@@ -107,6 +108,7 @@ class XWalkExtensionManager : public mojom::XWalkExtensionBrowser {
   virtual std::string HandleRuntimeMessageInternal(
       const std::string& type, const std::string& value);
 
+  bool is_loaded_by_json_path_ = false;
   bool is_loaded_for_service_app_ = false;
   bool is_loaded_for_web_app_ = false;
 
index dcdf97b..a374f4a 100644 (file)
@@ -376,6 +376,8 @@ shared_library("chromium-ewk") {
     "browser/webdata/web_data_service.h",
     "browser/webdata/web_data_service_factory.cc",
     "browser/webdata/web_data_service_factory.h",
+    "browser/xwalk_extension_browser_efl.cc",
+    "browser/xwalk_extension_browser_efl.h",
     "common/content_client_efl.cc",
     "common/content_client_efl.h",
     "common/content_switches_efl.cc",
diff --git a/tizen_src/ewk/efl_integration/browser/xwalk_extension_browser_efl.cc b/tizen_src/ewk/efl_integration/browser/xwalk_extension_browser_efl.cc
new file mode 100644 (file)
index 0000000..08f29dc
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "tizen_src/ewk/efl_integration/browser/xwalk_extension_browser_efl.h"
+
+#include "base/logging.h"
+
+namespace content {
+
+std::string XWalkExtensionBrowserEfl::HandleRuntimeMessageInternal(
+    const std::string& type, const std::string& value) {
+  LOG(INFO) << "type : " << type;
+  // TODO(dh81.song)
+  // According to xwalk extensions, this might handle internal messages.
+  return std::string();
+}
+
+}  // namespace content
\ No newline at end of file
diff --git a/tizen_src/ewk/efl_integration/browser/xwalk_extension_browser_efl.h b/tizen_src/ewk/efl_integration/browser/xwalk_extension_browser_efl.h
new file mode 100644 (file)
index 0000000..ba63942
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BROWSER_XWALK_EXTENSION_BROWSER_EFL_H_
+#define BROWSER_XWALK_EXTENSION_BROWSER_EFL_H_
+
+#include "tizen_src/chromium_impl/components/xwalk_extensions/common/xwalk_extension_browser_delegate.h"
+
+namespace content {
+
+class XWalkExtensionBrowserEfl : public wrt::XWalkExtensionBrowserDelegate {
+ public:
+  XWalkExtensionBrowserEfl() {}
+  ~XWalkExtensionBrowserEfl() override {}
+
+ private:
+  // XWalkExtensionBrowserDelegate
+  std::string HandleRuntimeMessageInternal(
+      const std::string& type, const std::string& value) override;
+};
+
+}  // namespace content
+
+#endif  // BROWSER_XWALK_EXTENSION_BROWSER_EFL_H_
\ No newline at end of file
index f401f44..c8c3e05 100644 (file)
@@ -36,6 +36,7 @@ const char kWidgetEncodedBundle[] = "widget-encoded-bundle";
 
 const char kEwkEnableMobileFeaturesForDesktop[] =
     "ewk-enable-mobile-features-for-desktop";
+const char kXWalkExtensionJsonPath[] = "xwalk-extension-json-path";
 
 #if defined(TIZEN_PEPPER_EXTENSIONS)
 const char kEnableTrustedPepperPlugins[] = "enable-trusted-pepper-plugins";
index a070dbb..a608320 100644 (file)
@@ -36,6 +36,7 @@ CONTENT_EXPORT extern const char kTizenAppVersion[];
 CONTENT_EXPORT extern const char kWidgetScale[];
 CONTENT_EXPORT extern const char kWidgetTheme[];
 CONTENT_EXPORT extern const char kWidgetEncodedBundle[];
+CONTENT_EXPORT extern const char kXWalkExtensionJsonPath[];
 
 // Turns on a bunch of settings (mostly on blink::WebView) for which there is no
 // command line switches. This allows desktop "ubrowser --mobile" to have
index 40463e5..e93b875 100644 (file)
@@ -24,6 +24,7 @@
 #include "components/error_page/common/localized_error.h"
 #include "components/navigation_interception/intercept_navigation_throttle.h"
 #include "components/password_manager/content/browser/content_password_manager_driver_factory.h"
+#include "components/xwalk_extensions/browser/xwalk_extension_manager.h"
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/navigation_handle.h"
 #include "content/public/browser/render_process_host.h"
@@ -643,6 +644,19 @@ ContentBrowserClientEfl::CreateURLLoaderThrottles(
   return result;
 }
 
+void ContentBrowserClientEfl::ExposeInterfacesToRenderer(
+    service_manager::BinderRegistry* registry,
+    blink::AssociatedInterfaceRegistry* associated_registry,
+    content::RenderProcessHost* render_process_host) {
+  if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
+          switches::kXWalkExtensionJsonPath)) {
+    return;
+  }
+  registry->AddInterface(
+      base::BindRepeating(&wrt::XWalkExtensionManager::Bind),
+      content::GetUIThreadTaskRunner({}));
+}
+
 #if BUILDFLAG(IS_TIZEN_TV)
 base::OnceClosure ContentBrowserClientEfl::SelectClientCertificate(
     WebContents* web_contents,
index 286c737..bdb8fde 100644 (file)
@@ -108,6 +108,10 @@ class ContentBrowserClientEfl : public ContentBrowserClient {
                       ResourceContext* context,
                       int render_process_id,
                       int render_frame_id);
+  void ExposeInterfacesToRenderer(
+      service_manager::BinderRegistry* registry,
+      blink::AssociatedInterfaceRegistry* associated_registry,
+      RenderProcessHost* render_process_host) override;
   void OverrideWebkitPrefs(WebContents* web_contents,
                            blink::web_pref::WebPreferences* prefs);
   void RenderProcessWillLaunch(RenderProcessHost* host) override;
index d69d015..7024865 100644 (file)
@@ -5,7 +5,10 @@
 #include "content_main_delegate_efl.h"
 
 #include "base/path_service.h"
+#include "browser/xwalk_extension_browser_efl.h"
 #include "command_line_efl.h"
+#include "common/content_switches_efl.h"
+#include "components/xwalk_extensions/browser/xwalk_extension_manager.h"
 #include "content/browser/gpu/gpu_main_thread_factory.h"
 #include "content/browser/gpu/gpu_process_host.h"
 #include "content/common/locale_efl.h"
@@ -90,6 +93,18 @@ void ContentMainDelegateEfl::PreSandboxStartupBrowser() {
 
   // needed for gpu thread
   content::RegisterGpuMainThreadFactory(CreateInProcessGpuThread);
+
+  // switches::kXWalkExtensionJsonPath SHOULD be set before MainDelegate init.
+  auto json_path =
+      base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+          switches::kXWalkExtensionJsonPath);
+  if (!json_path.empty()) {
+    auto* extension_manager = wrt::XWalkExtensionManager::GetInstance();
+    extension_manager->LoadExtensionsByJsonPath(json_path);
+    extension_manager->PreloadExtensions();
+    extension_manager->SetDelegate(
+        std::make_unique<XWalkExtensionBrowserEfl>());
+  }
 }
 
 void ContentMainDelegateEfl::PreSandboxStartup() {
index d7a5992..7342715 100644 (file)
@@ -17,6 +17,7 @@
 #include "common/content_switches_efl.h"
 #include "common/render_messages_ewk.h"
 #include "components/visitedlink/renderer/visitedlink_reader.h"
+#include "components/xwalk_extensions/renderer/xwalk_extension_renderer_controller.h"
 #include "content/common/locale_efl.h"
 #include "content/common/paths_efl.h"
 #include "content/public/common/content_switches.h"
@@ -93,9 +94,14 @@ static const float maximum_legible_scale = 2.0f;
 static const float minimum_page_scale_for_mobile = 0.25f;
 static const float maximum_page_scale_for_mobile = 5.f;
 
-#if defined(TIZEN_PEPPER_EXTENSIONS)
 namespace {
 
+bool ShouldRegisterXWalkExtension(int world_id) {
+  return world_id == 0 && base::CommandLine::ForCurrentProcess()->HasSwitch(
+                              switches::kXWalkExtensionJsonPath);
+}
+
+#if defined(TIZEN_PEPPER_EXTENSIONS)
 bool CreateTrustedPepperPlugin(content::RenderFrame* render_frame,
                                const blink::WebPluginParams& params,
                                blink::WebPlugin** plugin) {
@@ -114,9 +120,9 @@ bool CreateTrustedPepperPlugin(content::RenderFrame* render_frame,
 
   return false;
 }
+#endif  // defined(TIZEN_PEPPER_EXTENSIONS)
 
 }  // namespace
-#endif  // defined(TIZEN_PEPPER_EXTENSIONS)
 
 /* LCOV_EXCL_START */
 ContentRendererClientEfl::ContentRendererClientEfl() {}
@@ -162,6 +168,15 @@ void ContentRendererClientEfl::RenderThreadStarted() {
 
   if (!command_line.HasSwitch(switches::kSingleProcess))
     LocaleEfl::Initialize();
+
+  if (command_line.HasSwitch(switches::kXWalkExtensionJsonPath)) {
+    wrt::XWalkExtensionRendererController::GetInstance().SetPrivilegeChecker(
+        base::BindRepeating([]() -> bool {
+          // TODO(dh81.song)
+          // necessary to decide whether allow webapis for external URLs
+          return true;
+        }));
+  }
 }
 
 void ContentRendererClientEfl::RenderFrameCreated(content::RenderFrame* render_frame) {
@@ -253,6 +268,9 @@ void ContentRendererClientEfl::DidCreateScriptContext(
     content::RenderFrame* render_frame,
     v8::Handle<v8::Context> context,
     int world_id) {
+  if (ShouldRegisterXWalkExtension(world_id))
+    wrt::XWalkExtensionRendererController::DidCreateScriptContext(context);
+
   if (!widget_)
     return;
 
@@ -281,6 +299,9 @@ void ContentRendererClientEfl::WillReleaseScriptContext(
     blink::WebFrame* frame,
     v8::Handle<v8::Context> context,
     int world_id) {
+  if (ShouldRegisterXWalkExtension(world_id))
+    wrt::XWalkExtensionRendererController::WillReleaseScriptContext(context);
+
   if (widget_)
     widget_->StopSession(context);
 }
index 6dc8a3e..665f616 100755 (executable)
@@ -55,7 +55,7 @@ blink::WebElement GetFocusedElement(blink::WebView* web_view) {
   return GetFocusedElement(focused_frame);
 }
 
-bool shouldRegisterXWalkExtension(int world_id) {
+bool ShouldRegisterXWalkExtension(int world_id) {
   return (world_id == 0);
 }
 
@@ -106,7 +106,7 @@ void WRTRenderFrameObserver::DidCreateScriptContext(
   electron::ElectronRenderFrameObserver::DidCreateScriptContext(
       context, world_id);
 
-  if (shouldRegisterXWalkExtension(world_id))
+  if (ShouldRegisterXWalkExtension(world_id))
     XWalkExtensionRendererController::DidCreateScriptContext(context);
 }
 
@@ -115,7 +115,7 @@ void WRTRenderFrameObserver::WillReleaseScriptContext(
   electron::ElectronRenderFrameObserver::WillReleaseScriptContext(
       context, world_id);
 
-  if (shouldRegisterXWalkExtension(world_id))
+  if (ShouldRegisterXWalkExtension(world_id))
     XWalkExtensionRendererController::WillReleaseScriptContext(context);
 }