From 56c7b7feb31327b914fac15d6b0707cc531c64d3 Mon Sep 17 00:00:00 2001 From: DongHyun Song Date: Tue, 21 Mar 2023 13:07:58 +0900 Subject: [PATCH] Binding XWalkExtension for Efl classes 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 --- .../browser/xwalk_extension_manager.cc | 10 +++++++++ .../browser/xwalk_extension_manager.h | 2 ++ tizen_src/ewk/efl_integration/BUILD.gn | 2 ++ .../browser/xwalk_extension_browser_efl.cc | 19 ++++++++++++++++ .../browser/xwalk_extension_browser_efl.h | 25 ++++++++++++++++++++++ .../efl_integration/common/content_switches_efl.cc | 1 + .../efl_integration/common/content_switches_efl.h | 1 + .../efl_integration/content_browser_client_efl.cc | 14 ++++++++++++ .../efl_integration/content_browser_client_efl.h | 4 ++++ .../efl_integration/content_main_delegate_efl.cc | 15 +++++++++++++ .../renderer/content_renderer_client_efl.cc | 25 ++++++++++++++++++++-- wrt/src/renderer/wrt_render_frame_observer.cc | 6 +++--- 12 files changed, 119 insertions(+), 5 deletions(-) create mode 100644 tizen_src/ewk/efl_integration/browser/xwalk_extension_browser_efl.cc create mode 100644 tizen_src/ewk/efl_integration/browser/xwalk_extension_browser_efl.h diff --git a/tizen_src/chromium_impl/components/xwalk_extensions/browser/xwalk_extension_manager.cc b/tizen_src/chromium_impl/components/xwalk_extensions/browser/xwalk_extension_manager.cc index 1af1fa1..ace3201 100644 --- a/tizen_src/chromium_impl/components/xwalk_extensions/browser/xwalk_extension_manager.cc +++ b/tizen_src/chromium_impl/components/xwalk_extensions/browser/xwalk_extension_manager.cc @@ -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 files; + ParseMetadata(json_path, &files, XWALK_EXTENSION_PATH); + is_loaded_by_json_path_ = true; +} + void XWalkExtensionManager::LoadUIAppExtensions() { if (is_loaded_for_web_app_) return; diff --git a/tizen_src/chromium_impl/components/xwalk_extensions/browser/xwalk_extension_manager.h b/tizen_src/chromium_impl/components/xwalk_extensions/browser/xwalk_extension_manager.h index b37fd42..4714510 100644 --- a/tizen_src/chromium_impl/components/xwalk_extensions/browser/xwalk_extension_manager.h +++ b/tizen_src/chromium_impl/components/xwalk_extensions/browser/xwalk_extension_manager.h @@ -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; diff --git a/tizen_src/ewk/efl_integration/BUILD.gn b/tizen_src/ewk/efl_integration/BUILD.gn index dcdf97b..a374f4a 100644 --- a/tizen_src/ewk/efl_integration/BUILD.gn +++ b/tizen_src/ewk/efl_integration/BUILD.gn @@ -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 index 0000000..08f29dc --- /dev/null +++ b/tizen_src/ewk/efl_integration/browser/xwalk_extension_browser_efl.cc @@ -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 index 0000000..ba63942 --- /dev/null +++ b/tizen_src/ewk/efl_integration/browser/xwalk_extension_browser_efl.h @@ -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 diff --git a/tizen_src/ewk/efl_integration/common/content_switches_efl.cc b/tizen_src/ewk/efl_integration/common/content_switches_efl.cc index f401f44..c8c3e05 100644 --- a/tizen_src/ewk/efl_integration/common/content_switches_efl.cc +++ b/tizen_src/ewk/efl_integration/common/content_switches_efl.cc @@ -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"; diff --git a/tizen_src/ewk/efl_integration/common/content_switches_efl.h b/tizen_src/ewk/efl_integration/common/content_switches_efl.h index a070dbb..a608320 100644 --- a/tizen_src/ewk/efl_integration/common/content_switches_efl.h +++ b/tizen_src/ewk/efl_integration/common/content_switches_efl.h @@ -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 diff --git a/tizen_src/ewk/efl_integration/content_browser_client_efl.cc b/tizen_src/ewk/efl_integration/content_browser_client_efl.cc index 40463e5..e93b875 100644 --- a/tizen_src/ewk/efl_integration/content_browser_client_efl.cc +++ b/tizen_src/ewk/efl_integration/content_browser_client_efl.cc @@ -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, diff --git a/tizen_src/ewk/efl_integration/content_browser_client_efl.h b/tizen_src/ewk/efl_integration/content_browser_client_efl.h index 286c737..bdb8fde 100644 --- a/tizen_src/ewk/efl_integration/content_browser_client_efl.h +++ b/tizen_src/ewk/efl_integration/content_browser_client_efl.h @@ -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; diff --git a/tizen_src/ewk/efl_integration/content_main_delegate_efl.cc b/tizen_src/ewk/efl_integration/content_main_delegate_efl.cc index d69d015..7024865 100644 --- a/tizen_src/ewk/efl_integration/content_main_delegate_efl.cc +++ b/tizen_src/ewk/efl_integration/content_main_delegate_efl.cc @@ -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()); + } } void ContentMainDelegateEfl::PreSandboxStartup() { diff --git a/tizen_src/ewk/efl_integration/renderer/content_renderer_client_efl.cc b/tizen_src/ewk/efl_integration/renderer/content_renderer_client_efl.cc index d7a5992..7342715 100644 --- a/tizen_src/ewk/efl_integration/renderer/content_renderer_client_efl.cc +++ b/tizen_src/ewk/efl_integration/renderer/content_renderer_client_efl.cc @@ -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 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 context, int world_id) { + if (ShouldRegisterXWalkExtension(world_id)) + wrt::XWalkExtensionRendererController::WillReleaseScriptContext(context); + if (widget_) widget_->StopSession(context); } diff --git a/wrt/src/renderer/wrt_render_frame_observer.cc b/wrt/src/renderer/wrt_render_frame_observer.cc index 6dc8a3e..665f616 100755 --- a/wrt/src/renderer/wrt_render_frame_observer.cc +++ b/wrt/src/renderer/wrt_render_frame_observer.cc @@ -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); } -- 2.7.4