[M108 Migration][WRTjs][VD] Migrates recent performance patches 42/288942/7
authorDongHyun Song <dh81.song@samsung.com>
Mon, 27 Feb 2023 00:19:44 +0000 (09:19 +0900)
committerBot Blink <blinkbot@samsung.com>
Thu, 2 Mar 2023 09:44:06 +0000 (09:44 +0000)
Reference:
https://review.tizen.org/gerrit/#/c/286009/
https://review.tizen.org/gerrit/#/c/286443/
https://review.tizen.org/gerrit/#/c/286525/
https://review.tizen.org/gerrit/#/c/286567/
https://review.tizen.org/gerrit/#/c/286620/
https://review.tizen.org/gerrit/#/c/287796/
https://review.tizen.org/gerrit/#/c/288066/
https://review.tizen.org/gerrit/#/c/289065/

Change-Id: Iaead7c4e7d19c0a4f9d89d746f5761335bc140c9
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
27 files changed:
packaging/chromium-efl.spec
tizen_src/build/BUILD.gn
wrt/BUILD.gn
wrt/src/app/service_main.cc [changed mode: 0755->0644]
wrt/src/app/tv/wrt_main_delegate_tv.cc [changed mode: 0755->0644]
wrt/src/app/tv/wrt_main_delegate_tv.h [changed mode: 0755->0644]
wrt/src/app/wrt_content_main.cc [changed mode: 0755->0644]
wrt/src/app/wrt_main_delegate.h [changed mode: 0755->0644]
wrt/src/base/platform_info.cc [changed mode: 0755->0644]
wrt/src/base/platform_info.h [changed mode: 0755->0644]
wrt/src/browser/api/tv/wrt_api_tv_extension.cc [changed mode: 0755->0644]
wrt/src/browser/net/wrt_proxying_url_loader_factory.cc [changed mode: 0755->0644]
wrt/src/browser/tv/encrypted_file_handler.cc [changed mode: 0755->0644]
wrt/src/browser/tv/input_device_manager.cc [changed mode: 0755->0644]
wrt/src/browser/tv/input_device_manager.h [changed mode: 0755->0644]
wrt/src/browser/tv/native_web_runtime_delegate_tv.cc [changed mode: 0755->0644]
wrt/src/browser/tv/native_web_runtime_delegate_tv.h [changed mode: 0755->0644]
wrt/src/browser/tv/widget_state.cc [changed mode: 0755->0644]
wrt/src/browser/tv/wrt_native_window_tv.cc [changed mode: 0755->0644]
wrt/src/browser/tv/wrt_native_window_tv.h [changed mode: 0755->0644]
wrt/src/service/wrt_service_launcher.cc [changed mode: 0755->0644]
wrt/src/service/wrt_service_manager.cc [changed mode: 0755->0644]
wrt/src/service/wrt_service_manager.h [changed mode: 0755->0644]
wrt/xwalk_extensions/browser/tv/xwalk_extension_manager_tv.cc [changed mode: 0755->0644]
wrt/xwalk_extensions/browser/tv/xwalk_extension_manager_tv.h [changed mode: 0755->0644]
wrt/xwalk_extensions/browser/xwalk_extension_manager.cc [changed mode: 0755->0644]
wrt/xwalk_extensions/browser/xwalk_extension_manager.h [changed mode: 0755->0644]

index 3de8812..a288c8c 100755 (executable)
@@ -41,6 +41,13 @@ Source1: content_shell.in
 %define __build_chrome 0
 %endif
 
+%if "%{?tizen_profile_name}" == "tv" && %{tizen_version} >= 70
+# Tizen TV 7.0
+%define __enable_capi_thread_booster 1
+%else
+%define __enable_capi_thread_booster 0
+%endif
+
 %{?_use_system_icu: %define __use_system_icu %{_use_system_icu}}
 # Product tv can't utilize system icu due to nacl dependency.
 %if "%{?profile}" != "tv" && %{tizen_version} == 60 && %{?_use_system_icu: 0}%{!?_use_system_icu: 1}
@@ -156,6 +163,10 @@ BuildRequires: pkgconfig(vd-win-util)
 BuildRequires: pkgconfig(WebProduct)
 %endif
 
+%if "%{__enable_capi_thread_booster}" == "1"
+BuildRequires: pkgconfig(capi-boost-tv)
+%endif
+
 # TODO(youngsoo): The binutils-gold crashes mini_browser on the Tizen v3.0 ARM 64 bit images.
 #                 Once fixed, use binutils-gold for all targets on Tizen v3.0.
 %ifnarch aarch64 %{arm} # [M48_2564] Temporary excluding arm architecture for fixing memory issue
@@ -694,7 +705,7 @@ setcap cap_mac_admin=eip %{_bindir}/wrt-service
 
 %if 0%{?__enable_wrt_js}
   %if "%{?profile}" == "tv"
-    %caps(cap_mac_admin,cap_mac_override,cap_setgid,cap_setpcap,cap_setuid,cap_sys_chroot,cap_sys_ptrace,cap_sys_admin=eip) %{_bindir}/wrt
+    %caps(cap_mac_admin,cap_mac_override,cap_setgid,cap_setpcap,cap_setuid,cap_sys_chroot,cap_sys_ptrace,cap_sys_admin,cap_sys_nice=eip) %{_bindir}/wrt
     /etc/notstrip/wrt.notstrip
     %if 0%{?__generate_tpk}
       %{__wrt_resourcedir}/app/*
index a1a4d87..c35acbd 100644 (file)
@@ -507,6 +507,13 @@ config("capi-media-audio-io") {
   }
 }
 
+tizen_pkg_config("capi-boost-tv") {
+  packages = []
+  if (tizen_product_tv && tizen_version >= 70) {
+    packages += [ "capi-boost-tv" ]
+  }
+}
+
 tizen_pkg_config("libcapi-media-audio-io") {
   packages = []
   if (is_tizen) {
index cd5ce9d..b61cb79 100755 (executable)
@@ -312,6 +312,9 @@ config("wrt_config") {
       "//tizen_src/build:ui-gadget-1",
       "//tizen_src/build:vd-win-util",
     ]
+    if (tizen_version >= 70) {
+      configs += [ "//tizen_src/build:capi-boost-tv" ]
+    }
   } else {
     configs += [
       "//tizen_src/build:capi-appfw-watch-application",
old mode 100755 (executable)
new mode 100644 (file)
index aa69b07..325662f
@@ -73,6 +73,7 @@ void ChildCreated() {
 
 void ChildTerminated(int sig_no) {
   LOG(INFO) << "sig_no : " << sig_no;
+  wrt_ipc->SendMessage("CloseDBusConnection", "");
   wrt_ipc.reset();
   child_created = false;
 
@@ -169,8 +170,10 @@ int main(int argc, char* argv[]) {
 
   struct sigaction action;
   action.sa_handler = wrt::ChildTerminated;
+  action.sa_flags = 0;
   sigfillset(&(action.sa_mask));
-  sigaction(SIGCHLD, &action, NULL);
+  if (sigaction(SIGCHLD, &action, NULL) != 0)
+    LOG(ERROR) << "sigaction is fail";
 
   service_app_lifecycle_callback_s ops;
   memset(&ops, 0, sizeof(ops));
old mode 100755 (executable)
new mode 100644 (file)
index d953cfa..a0117a7
@@ -7,19 +7,26 @@
 #include <mutex>
 #include <thread>
 
+#include <aul_proc_group.h>
 #include <dlfcn.h>
+#include <sys/resource.h>
 #include <tzplatform_config.h>
 
 #include "base/logging.h"
 #include "base/threading/thread_id_name_manager.h"
+#include "content/common/zygote/zygote_communication_linux.h"
+#include "content/public/common/zygote/zygote_handle.h"
 #include "wrt/src/base/platform_info.h"
+#include "wrt/src/browser/net/tv/encrypted_file_url_loader.h"
 #include "wrt/src/browser/tv/input_device_manager.h"
 #include "wrt/src/browser/tv/mounter.h"
 #include "wrt/src/browser/tv/native_web_runtime_delegate_tv.h"
 #include "wrt/src/browser/tv/wrt_browser_client_tv.h"
+#include "wrt/src/browser/tv/wrt_native_window_tv.h"
 #include "wrt/src/browser/wrt_native_window.h"
 #include "wrt/src/common/constants.h"
 #include "wrt/src/common/locale_manager.h"
+#include "wrt/src/common/tv/application_data_tv.h"
 #include "wrt/src/renderer/tv/wrt_renderer_client_tv.h"
 #include "wrt/xwalk_extensions/browser/xwalk_extension_manager.h"
 #include "tizen_src/chromium_impl/ui/gl/gl_shared_context_efl.h"
@@ -51,10 +58,10 @@ class ZoneFramework {
 };
 
 const char* kEflWebProcess = "/usr/bin/efl_webprocess";
-const char* kLoaderMode = "-lite";
 const char* kZoneLibPath = LIB_PATH "/libzone.so.5";
 
-std::mutex worker_mutex;
+std::mutex prelaunch_mutex;
+std::mutex reallaunch_mutex;
 std::string prelaunch_pkg_id;
 
 bool CheckWindowManagerReady() {
@@ -108,9 +115,28 @@ void SetSmackLabel(const std::string& pkg_id) {
   }
 }
 
+void SetPriorityAsIdle() {
+  LOG(INFO) << "Set process priority as 0 of process group";
+  setpriority(PRIO_PGRP, 0, 0);
+}
+
+void InitializeBeforeRealLaunch() {
+  XWalkExtensionManager::GetInstance()->PreloadExtensions();
+  std::ignore = PrivilegedService::GetInstance();
+  std::ignore = LocaleManager::GetInstance();
+
+  auto& native_runtime_tv = NativeWebRuntimeDelegateTV::GetInstance();
+  native_runtime_tv.PepperUpdatePluginService();
+  native_runtime_tv.PreloadVconfKeys();
+  native_runtime_tv.PreloadFMS();
+  native_runtime_tv.SubscribePowerState();
+  native_runtime_tv.SetLocaleDir();
+  native_runtime_tv.ClearDeadMount();
+}
+
 }  // namespace
 
-WRTMainDelegateTV::WRTMainDelegateTV() : lazy_initialize_(false) {
+WRTMainDelegateTV::WRTMainDelegateTV() {
   SetExecutablePath(kEflWebProcess);
   SetNoZygote(false);
 }
@@ -121,49 +147,84 @@ absl::optional<int> WRTMainDelegateTV::BasicStartupComplete() {
 }
 
 bool WRTMainDelegateTV::CheckPlatformReady(int argc, char** argv) {
-  for (int i = 1; i < argc; ++i) {
-    if (strcmp(argv[i], kLoaderMode) == 0) {
-      lazy_initialize_ = true;
-      break;
-    }
-  }
   return CheckWindowManagerReady();
 }
 
-bool WRTMainDelegateTV::SupportLazyInitialize() {
-  return lazy_initialize_;
+// static
+void WRTMainDelegateTV::GroupZygoteProcess(bool is_oom) {
+#if defined(ENABLE_PROCESS_GROUP)
+  // Group zygote process with browser process so that OOM score
+  // can be synchronized.
+  auto oom_score_adj_path = base::FilePath("/proc/self/oom_score_adj");
+  std::string oom_score;
+  base::ReadFileToString(oom_score_adj_path, &oom_score);
+  if (is_oom || oom_score == "0") {
+    auto zygote_pid = content::GetGenericZygote()->GetZygotePid();
+    LOG(INFO) << "zygote pid : " << zygote_pid << ", oom score : " << oom_score;
+    // Note. this is workaround!!
+    // If amd has failed dbus communication once with resourced, then, next call
+    // is blocked. But retry can re-connect the dbus.
+    // If already blocked, aul_proc_group_remove() can close the blocked dbus,
+    // if not blocked, this logic is not effective for process grouping.
+    std::ignore = aul_proc_group_remove(zygote_pid);
+    std::ignore = aul_proc_group_add(zygote_pid);
+  }
+#endif
 }
 
-void WRTMainDelegateTV::LoaderCreated() {
-#if !defined(WRT_JS_BRINGUP)
-  base::ThreadIdNameManager::GetInstance()->EnableSelfSmackLabeling();
-#endif
-  WRTNativeWindow::EnsurePlatformWindow();
-  auto* ee = WRTNativeWindow::GetPlatformCanvas();
-  InputDeviceManager::GetInstance()->PreInitialize(ee);
-  GLSharedContextEfl::Initialize(WRTNativeWindow::GetTopWindow());
-  XWalkExtensionManager::GetInstance()->PreloadExtensions();
-  auto& native_runtime_tv = NativeWebRuntimeDelegateTV::GetInstance();
-  native_runtime_tv.PepperUpdatePluginService();
-  native_runtime_tv.SubscribePowerState();
-  native_runtime_tv.SetLocaleDir();
-  native_runtime_tv.ClearDeadMount();
-  std::ignore = PrivilegedService::GetInstance();
-  std::ignore = LocaleManager::GetInstance();
-  worker_mutex.lock();
-  std::thread loader_boost_worker([]() -> void {
-    worker_mutex.lock();
+void WRTMainDelegateTV::CreateWorkers() {
+  prelaunch_mutex.lock();
+  reallaunch_mutex.lock();
+  std::thread prelaunch_worker([]() -> void {
+    // wake-up by preluanch
+    prelaunch_mutex.lock();
+    LOG(INFO) << "prelaunch_worker";
     SetSmackLabel(prelaunch_pkg_id);
-    // PreSetupOnWorker by candidate launch
     NativeWebRuntimeDelegateTV::PreSetupOnWorker();
-    worker_mutex.unlock();
+    prelaunch_mutex.unlock();
+    reallaunch_mutex.lock();
+    reallaunch_mutex.unlock();
+  });
+  prelaunch_worker.detach();
+
+  std::thread reallaunch_worker([]() -> void {
+    InitializeBeforeRealLaunch();
+
+    // wake-up by real launch
+    reallaunch_mutex.lock();
+    LOG(INFO) << "reallaunch_worker";
+    auto& app_data_tv = ApplicationDataTV::GetInstance();
+    if (!app_data_tv.IsHostedApp() && app_data_tv.HasWidgetLicense()) {
+      std::ignore = GetEncryptedFileHandler();
+    }
+    NativeWebRuntimeDelegateTV::GetInstance().BuildPrivilegeCache();
+    XWalkExtensionManager::GetInstance()->PrefetchExtensions();
+    GroupZygoteProcess(false);
+    reallaunch_mutex.unlock();
   });
-  loader_boost_worker.detach();
+  reallaunch_worker.detach();
+
+}
+
+void WRTMainDelegateTV::LoaderCreated() {
+  CreateWorkers();
+
+  auto* ee = WRTNativeWindow::GetPlatformCanvas();
+#if !defined(ENABLE_WRT_JS)
+  GLSharedContextEfl::Initialize(ee);
+#endif
+  InputDeviceManager::GetInstance()->PreInitialize(ee);
+  WRTNativeWindowTV::SetGlobalResourceId(WRTNativeWindow::GetTopWindow());
+  SetPriorityAsIdle();
+}
+
+void WRTMainDelegateTV::LoaderTerminated() {
+  reallaunch_mutex.unlock();
 }
 
 void WRTMainDelegateTV::PrelaunchOnLoader(const std::string& pkg_id) {
   prelaunch_pkg_id = pkg_id;
-  worker_mutex.unlock();
+  prelaunch_mutex.unlock();
 }
 
 content::ContentBrowserClient* WRTMainDelegateTV::CreateContentBrowserClient() {
old mode 100755 (executable)
new mode 100644 (file)
index d277cfa..9f6e274
@@ -14,19 +14,21 @@ class WRTMainDelegateTV : public WRTMainDelegate {
   explicit WRTMainDelegateTV();
   ~WRTMainDelegateTV() {}
 
+  static void GroupZygoteProcess(bool is_oom);
+
  private:
   absl::optional<int> BasicStartupComplete() override;
   bool CheckPlatformReady(int argc, char** argv) override;
   void LoaderCreated() override;
+  void LoaderTerminated() override;
   void PrelaunchOnLoader(const std::string& pkg_id) override;
   bool PreSetup() override;
   absl::optional<int> PostEarlyInitialization(InvokedIn invoked_in) override;
-  bool SupportLazyInitialize() override;
+
+  void CreateWorkers();
 
   content::ContentBrowserClient* CreateContentBrowserClient() override;
   content::ContentRendererClient* CreateContentRendererClient() override;
-
-  bool lazy_initialize_;
 };
 
 }  // namespace wrt
old mode 100755 (executable)
new mode 100644 (file)
index 87ac8d0..dede458
@@ -55,16 +55,9 @@ class WRTContentMain::Loader {
     loader_lifecycle_callback_s callback;
     callback.create = [](bundle* extra, int type, void* user_data) {
       LOG(INFO) << "loader created";
-      ecore_idler_add(
-          [](void* data) {
-            LOG(INFO) << "ContentMain will be initialized in idler.";
-            auto* content_main = static_cast<WRTContentMain*>(data);
-            if (!content_main->main_delegate_->SupportLazyInitialize()) {
-              content_main->Initialize();
-              content_main->main_delegate_->LoaderCreated();
-            }
-            return ECORE_CALLBACK_CANCEL;
-          }, static_cast<Loader*>(user_data)->content_main_);
+      auto* content_main = static_cast<Loader*>(user_data)->content_main_;
+      content_main->Initialize();
+      content_main->main_delegate_->LoaderCreated();
     };
 #if TIZEN_VERSION_AT_LEAST(6, 5, 0)
     callback.prelaunch = [](int argc, char** argv, const char* app_path,
@@ -89,9 +82,7 @@ class WRTContentMain::Loader {
     callback.terminate = [](int argc, char** argv, void* user_data) {
       LOG(INFO) << "loader terminated";
       auto* content_main = static_cast<Loader*>(user_data)->content_main_;
-      if (content_main->main_delegate_->SupportLazyInitialize())
-        content_main->Initialize();
-
+      content_main->main_delegate_->LoaderTerminated();
       for (int i = 0; i < argc; ++i)
         LOG(INFO) << "argv[" << i << "] : " << argv[i];
       base::CommandLine::ForCurrentProcess()->SetProgram(
old mode 100755 (executable)
new mode 100644 (file)
index d46b2c1..2545c0e
@@ -18,8 +18,8 @@ class WRTMainDelegate : public electron::ElectronMainDelegate {
 
   // product specific functions
   virtual bool CheckPlatformReady(int argc, char** argv) { return true; }
-  virtual bool SupportLazyInitialize() { return false; }
   virtual void LoaderCreated() {}
+  virtual void LoaderTerminated() {}
   virtual void PrelaunchOnLoader(const std::string& pkg_id) {}
   virtual bool PreSetup();
 
old mode 100755 (executable)
new mode 100644 (file)
index 141d99e..1b83e4a
@@ -268,6 +268,29 @@ bool IsSignageProduct() {
   auto product_type = GetProductType();
   return "LFD" == product_type || "IWB" == product_type;
 }
+
+bool IsSmartMonitor() {
+  bool bsmart_monitor = false;
+  if (system_info_get_custom_bool(
+          "com.samsung/featureconf/product.smart_monitor_feature_support",
+          &bsmart_monitor) != SYSTEM_INFO_ERROR_NONE) {
+    LOG(WARNING) << "fail to get smart_monitor_feature_support";
+    return false;
+  }
+  return bsmart_monitor;
+}
+
+bool IsVisualControllerSupported() {
+  bool is_supported = false;
+  if (SYSTEM_INFO_ERROR_NONE !=
+      system_info_get_custom_bool(
+          "com.samsung/featureconf/multiview.visual_controller_support",
+          &is_supported)) {
+    LOG(ERROR) << "Fail to get system info: visual_controller_support";
+  }
+  LOG(INFO) << "multiview.visual_controller supported : " << is_supported;
+  return is_supported;
+}
 #endif
 
 }  // namespace wrt
old mode 100755 (executable)
new mode 100644 (file)
index ac49427..cd8b614
@@ -62,7 +62,9 @@ bool GetWallSupport();
 bool IsSignageProduct();
 bool IsUHDAModel();
 bool Is8KPanel();
+bool IsSmartMonitor();
 bool HasLimitQuotaPermission();
+bool IsVisualControllerSupported();
 #endif
 
 }  // namespace wrt
old mode 100755 (executable)
new mode 100644 (file)
index b78337a..dd37c3f
@@ -109,7 +109,7 @@ class WRTCameraInfo {
     Json::Value root;
     Json::Value camera_device_list;
     root["device_count"].append(std::to_string(device_list.count));
-    for (int i = 0; i < device_list.count; i++) {
+    for (unsigned int i = 0; i < device_list.count; i++) {
       Json::Value camera_device_info;
       camera_device_info["type"] = std::to_string(device_list.device[i].type);
       camera_device_info["name"] = std::string(device_list.device[i].name);
old mode 100755 (executable)
new mode 100644 (file)
index 5472984..4f6f751
@@ -46,7 +46,8 @@ ResourceManager& WRTProxyingURLLoaderFactory::GetResourceManager() {
 WRTProxyingURL WRTProxyingURLLoaderFactory::ParseURL(const GURL& url) {
   auto& resource_manager = WRTProxyingURLLoaderFactory::GetResourceManager();
   if (!resource_manager.AllowedResource(url.possibly_invalid_spec())) {
-    LOG(ERROR) << "request was blocked by WARP";
+    LOG(ERROR) << "request[" << url.possibly_invalid_spec()
+               << "] was blocked by WARP";
     return GURL("about:blank");
   }
 #if defined(OS_TIZEN_TV_PRODUCT)
old mode 100755 (executable)
new mode 100644 (file)
index 836f6b9..5a54469
@@ -86,6 +86,7 @@ bool EncryptedFileHandler::LoadLicense() {
     return false;
   }
 
+  LOG(INFO) << "appdrm_load_license() start";
   if (appdrm_load_license(path.AsUTF8Unsafe().c_str(),
                           &license_handle_) != 0) {
     std::string vconfValue =
@@ -96,6 +97,7 @@ bool EncryptedFileHandler::LoadLicense() {
 #endif
     return false;
   }
+  LOG(INFO) << "appdrm_load_license() end";
 
   return true;
 }
old mode 100755 (executable)
new mode 100644 (file)
index 35e0b2c..72a3336
@@ -77,13 +77,12 @@ InputDeviceManager::~InputDeviceManager() {}
 
 void InputDeviceManager::PreInitialize(Ecore_Evas* ee) {
   Ecore_Wl2_Window* wl_win = ecore_evas_wayland2_window_get(ee);
-  wl_surface* surface = ecore_wl2_window_surface_get(wl_win);
-  KeyRouter_RegisterNONEKey(surface);
+  focus_surface_ = ecore_wl2_window_surface_get(wl_win);
+  KeyRouter_RegisterNONEKey(focus_surface_);
+  did_register_none_ = true;
 }
 
 void InputDeviceManager::Initialize(Evas_Object* focus_view) {
-  if (focus_surface_)
-    return;
   SetFocusSurface(focus_view);
   RegisterMandatoryKeys();
 }
@@ -108,6 +107,9 @@ void InputDeviceManager::SetKeyboardFuncKey() {
 }
 
 void InputDeviceManager::SetFocusSurface(Evas_Object* focus_view) {
+  if (focus_surface_)
+    return;
+
   Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(focus_view));
   Ecore_Wl2_Window* wl_window = ecore_evas_wayland2_window_get(ee);
   focus_surface_ = (struct wl_surface*)ecore_wl2_window_surface_get(wl_window);
@@ -118,7 +120,8 @@ void InputDeviceManager::Finalize() {
 }
 
 void InputDeviceManager::RegisterMandatoryKeys() {
-  KeyRouter_RegisterNONEKey(focus_surface_);
+  if (!did_register_none_)
+    KeyRouter_RegisterNONEKey(focus_surface_);
   RegisterKey(default_keys);
 }
 
old mode 100755 (executable)
new mode 100644 (file)
index 95b5997..1b90e21
@@ -71,6 +71,7 @@ class InputDeviceManager {
   FocusSurface* focus_surface_ = nullptr;
   Ecore_Timer* lazy_handler_ = nullptr;
   bool use_functionkey_ = false;
+  bool did_register_none_ = false;
   std::map<std::string, std::tuple<const char*, unsigned>> func_keymap_;
 };
 
old mode 100755 (executable)
new mode 100644 (file)
index 4117021..d0b709d
@@ -16,6 +16,7 @@
 #include <message_port.h>
 #include <pkgmgr-info.h>
 #include <privileged-service/PS_API.h>
+#include <security-manager/security-manager.h>
 #include <tzplatform_config.h>
 
 #include "base/command_line.h"
 #include "tizen_src/chromium_impl/tizen/vconf_handle.h"
 #endif
 #include "tizen_src/ewk/efl_integration/common/application_type.h"
+#if !defined(WRT_JS_BRINGUP)
+#include "tizen_src/ewk/efl_integration/ewk_privilege_checker.h"
+#endif
 #include "v8/include/v8.h"
+#include "wrt/src/app/tv/wrt_main_delegate_tv.h"
 #include "wrt/src/base/platform_info.h"
 #include "wrt/src/browser/native_web_runtime.h"
-#include "wrt/src/browser/net/tv/encrypted_file_url_loader.h"
 #include "wrt/src/browser/tv/ambient_mode.h"
 #include "wrt/src/browser/tv/decorator_window.h"
 #include "wrt/src/browser/tv/mounter.h"
@@ -68,7 +72,8 @@ namespace wrt {
 
 namespace {
 
-#define NEED_CHECK_DEADMOUNT 16
+#define NEED_CHECK_DEADMOUNT \
+  6  // vconf wrt loader init value is -1, 6 plus 1 is 7
 
 const char* kAllowMixedContent =
     "http://samsung.com/tv/metadata/allow.mixedcontent";
@@ -105,7 +110,6 @@ const char* kVideoHoleSupport =
 
 std::unique_ptr<Mounter> tmg_mounter;
 base::Lock worker_thread_lock;
-bool runtime_finalized = false;
 
 bool MountTmgFile(const base::FilePath& tmg_file, bool try_mknod) {
   base::AutoLock lock(worker_thread_lock);
@@ -180,6 +184,7 @@ int ChangeAmbientModeCallback(device_power_state_info* info, void* user_data) {
 bool ShouldRunClearDeadMount() {
 #if !defined(WRT_JS_BRINGUP)
   auto wrtloader_count = VconfHandle(kWrtLoaderCount).Int();
+  LOG(INFO) << "vconf loader_count is " << wrtloader_count;
   if (wrtloader_count < NEED_CHECK_DEADMOUNT) {
     VconfHandle(kWrtLoaderCount).Set((++wrtloader_count), true);
     return false;
@@ -258,6 +263,14 @@ void NativeWebRuntimeDelegateTV::ClearDeadMount() {
   }
 }
 
+NativeWebRuntimeDelegateTV::NativeWebRuntimeDelegateTV() {
+#if !defined(WRT_JS_BRINGUP)
+  content::EwkPrivilegeChecker::GetInstance()->SetPrivilegeChecker(
+      base::BindRepeating(&NativeWebRuntimeDelegateTV::CheckPrivilege,
+                          base::Unretained(this)));
+#endif
+}
+
 void NativeWebRuntimeDelegateTV::Initialize(void* data) {
   ApplicationData::GetInstance().Initialize();
   app_id_ = ApplicationData::GetInstance().app_id();
@@ -265,22 +278,12 @@ void NativeWebRuntimeDelegateTV::Initialize(void* data) {
   extension_manager->ParseUpgradableExtensions();
   extension_manager->RegisterUpgradableExtensions();
   initialized_ = true;
-
-  std::thread worker_on_app([]() -> void {
-    LOG(INFO) << "worker_on_app start";
-    base::AutoLock lock(worker_thread_lock);
-    if (runtime_finalized) return;
-    if (ApplicationDataTV::GetInstance().HasWidgetLicense()) {
-      std::ignore = GetEncryptedFileHandler();
-    }
-    XWalkExtensionManager::GetInstance()->PrefetchExtensions();
-  });
-  worker_on_app.detach();
 }
 
 void NativeWebRuntimeDelegateTV::DidInitialized() {
   VideoSplashScreen::InitializeVSS();
   SetD2dServiceMessageListener();
+  SubscribePowerState();
 
   content::SetApplicationType(content::ApplicationType::TIZENWRT);
   // Drop process privillages while web app is launching
@@ -295,13 +298,72 @@ void NativeWebRuntimeDelegateTV::DidInitialized() {
 
 void NativeWebRuntimeDelegateTV::Finalize() {
   base::AutoLock lock(worker_thread_lock);
-  runtime_finalized = true;
   if (device_power_unsubscribe_state_changed_event(ChangeAmbientModeCallback)
       != POWER_ERROR_NONE)
     LOG(WARNING) << "failed to unregister state changed event callback";
   ClearTmpFolder();
 }
 
+std::string NativeWebRuntimeDelegateTV::CheckPrivilege(
+    const std::string& privilege) {
+  if (!initialized_) {
+    LOG(INFO) << "Not initialized : " << privilege;
+    return "not_found";
+  }
+
+  std::string privilege_exist;
+  if (privilege_cahce_init_) {
+    if (privileges_cache_.find(privilege) != privileges_cache_.end())
+      privilege_exist = "found";
+    else
+      privilege_exist = "not_found";
+  } else {
+    auto& permissions =
+        ApplicationData::GetInstance().permissions_info().GetAPIPermissions();
+    if (permissions.find(privilege) != permissions.end())
+      privilege_exist = "found";
+  }
+
+  LOG(INFO) << "CheckPrivilege : " << privilege << " - " << privilege_exist;
+  return privilege_exist;
+}
+
+void NativeWebRuntimeDelegateTV::BuildPrivilegeCache() {
+  if (!privileges_cache_.empty())
+    return;
+
+  auto app_id = ApplicationData::GetInstance().app_id();
+  char** privileges = nullptr;
+  size_t size = 0;
+  LOG(INFO) << "security_manager_get_app_manifest_policy start";
+  security_manager_get_app_manifest_policy(
+      app_id.c_str(), getuid(), &privileges, &size);
+  LOG(INFO) << "security_manager_get_app_manifest_policy end";
+
+  if (!size)
+    return;
+
+  base::AutoLock lock(worker_thread_lock);
+  for (unsigned int i = 0; i < size; i++) {
+    if (!privileges[i]) continue;
+    LOG(INFO) << "privileges[i] : " << privileges[i];
+    privileges_cache_.insert(std::string(privileges[i]));
+  }
+
+  if (privileges_cache_.size() > 0)
+    privilege_cahce_init_ = true;
+
+  content::GetUIThreadTaskRunner({})->PostTask(
+      FROM_HERE,
+      base::BindOnce(&XWalkExtensionManager::SetCachedPrivileges,
+                     base::Unretained(XWalkExtensionManager::GetInstance())));
+}
+
+std::set<std::string> NativeWebRuntimeDelegateTV::GetPrivilegeCache() {
+  base::AutoLock lock(worker_thread_lock);
+  return privileges_cache_;
+}
+
 std::string NativeWebRuntimeDelegateTV::GetDiskCachePath() {
   return disk_cache_path_;
 }
@@ -360,9 +422,16 @@ void NativeWebRuntimeDelegateTV::ApplyHalfWindow(
 }
 
 void NativeWebRuntimeDelegateTV::SubscribePowerState() {
+  if (power_callback_registered_)
+    return;
+
+  base::AutoLock lock(worker_thread_lock);
   if (device_power_subscribe_state_changed_event(
-      ChangeAmbientModeCallback, this) != POWER_ERROR_NONE)
+      ChangeAmbientModeCallback, this) != POWER_ERROR_NONE) {
     LOG(INFO) << "Can't subscribe power-state-changed event callback";
+    return;
+  }
+  power_callback_registered_ = true;
 }
 
 void NativeWebRuntimeDelegateTV::BeforeAppControlEvent(
@@ -391,19 +460,19 @@ bool NativeWebRuntimeDelegateTV::IsRunningAsBackground() {
 
 void NativeWebRuntimeDelegateTV::HandleLowMemory() {
 #if !defined(WRT_JS_BRINGUP)
-  static bool low_memory_hard_warning = false;
-  int low_memory_status = VconfHandle(VCONFKEY_SYSMAN_LOW_MEMORY).Int();
-  if (low_memory_status == VCONFKEY_SYSMAN_LOW_MEMORY_HARD_WARNING)
-    low_memory_hard_warning = true;
-  if (low_memory_hard_warning && !electron::WindowList::IsEmpty()) {
+  if (electron::Browser::Get()->is_quitting()) {
+    LOG(ERROR) << "app is quiting, just return";
+    return;
+  }
+
+  WRTMainDelegateTV::GroupZygoteProcess(true);
+  if (!electron::WindowList::IsEmpty()) {
     WRTNativeWindow* main_window = WRTNativeWindow::GetMainNativeWindow();
     if (main_window && !main_window->IsEnabled()) {
-      LOG(ERROR) << "Try to terminate itself by low memory";
+      LOG(ERROR) << "Try to terminate itself(bg app) by low memory";
       NativeWebRuntime::GetInstance().RequestQuit();
-      return;
     }
   }
-  low_memory_hard_warning = true;
 #endif
 }
 
@@ -573,7 +642,8 @@ void NativeWebRuntimeDelegateTV::PepperUpdatePluginService() {
 // static
 void NativeWebRuntimeDelegateTV::PreSetupOnWorker() {
   LOG(INFO) << "PreSetupOnWorker";
-  GetInstance().TryMount();
+  if (!ApplicationData::GetInstance().IsHostedApp())
+    GetInstance().TryMount();
   GetInstance().PepperUpdatePluginService();
 }
 
@@ -588,6 +658,8 @@ bool NativeWebRuntimeDelegateTV::IsVideoHoleEnabled() {
 void NativeWebRuntimeDelegateTV::SetLocaleDir() {
   if (locale_dir_binded_)
     return;
+
+  base::AutoLock lock(worker_thread_lock);
   base::FilePath locale_dir;
   base::PathService::Get(PathsEfl::DIR_LOCALE, &locale_dir);
   auto dir = locale_dir.value().c_str();
@@ -596,4 +668,50 @@ void NativeWebRuntimeDelegateTV::SetLocaleDir() {
   locale_dir_binded_ = true;
 }
 
+void NativeWebRuntimeDelegateTV::PreloadVconfKeys() {
+#if !defined(WRT_JS_BRINGUP)
+  LOG(INFO) << "PreloadVconfKeys start";
+  const char* kVconfAccessibilityTts = "db/setting/accessibility/tts";
+  const char* kVconfHomeAppId = "db/appfw/overlay_home_appid";
+  const char* kVconfHwDuid = "db/comss/hwduid";
+  const char* kVconfInspectedAppId = "db/rwi/inspected_appid";
+  const char* kVconfLanguage = "db/menu_widget/language";
+  const char* kVconfRegionFormat = "db/menu_widget/regionformat";
+  const char* kVconfRegionFormatTime = "db/menu_widget/regionformat_time1224";
+  const char* kVconfVoiceTouchAutoMode = "db/voice/vc/voice_touch/automode";
+  const char* kVconfRotationState = "db/sysman/rotation_state";
+
+  const char* kVconfDisplayRotatorStatus = "memory/display_rotator/status";
+  const char* kVconfLowMemory = "memory/sysman/low_memory";
+  const char* kVconfProxy = "memory/dnet/proxy";
+
+  VconfHandle(kVconfAccessibilityTts).Bool();
+  VconfHandle(kVconfHomeAppId).Str();
+  VconfHandle(kVconfHwDuid).Str();
+  VconfHandle(kVconfInspectedAppId).Str();
+  VconfHandle(kVconfLanguage).Str();
+  VconfHandle(kVconfRegionFormat).Str();
+  VconfHandle(kVconfRegionFormatTime).Int();
+  VconfHandle(kVconfVoiceTouchAutoMode).Bool();
+  VconfHandle(kVconfRotationState).Int();
+
+  VconfHandle(kVconfDisplayRotatorStatus).Int();
+  VconfHandle(kVconfLowMemory).Int();
+  VconfHandle(kVconfProxy).Str();
+  LOG(INFO) << "PreloadVconfKeys end";
+#endif
+}
+
+void NativeWebRuntimeDelegateTV::PreloadFMS() {
+  LOG(INFO) << "PreloadFMS start";
+  int width = 0;
+  int height = 0;
+  GetProductDiskCacheSize();
+  GetProductType();
+  GetPanelResolution(&width, &height);
+  GetWebIsolationSupport();
+  IsSmartMonitor();
+  LOG(INFO) << "PreloadFMS end";
+}
+
 }  // namespace wrt
old mode 100755 (executable)
new mode 100644 (file)
index ff94274..8d476e6
@@ -33,6 +33,8 @@ class NativeWebRuntimeDelegateTV : public WRTProfileDelegate {
   void AfterAppControlEvent(const app_control_h app_control);
   void PepperUpdatePluginService();
   void PostEarlyInitialization();
+  void PreloadVconfKeys();
+  void PreloadFMS();
   void SubscribePowerState();
   void TryMount();
 
@@ -53,8 +55,11 @@ class NativeWebRuntimeDelegateTV : public WRTProfileDelegate {
     proxy_info_ = proxy_info;
   }
 
+  void BuildPrivilegeCache();
+  std::set<std::string> GetPrivilegeCache();
+
  private:
-  NativeWebRuntimeDelegateTV() {}
+  NativeWebRuntimeDelegateTV();
   ~NativeWebRuntimeDelegateTV() {}
 
   void DidInitialized() override;
@@ -71,6 +76,7 @@ class NativeWebRuntimeDelegateTV : public WRTProfileDelegate {
   void SetD2dServiceMessageListener();
   void SetDiskCache(bool enable);
   base::FilePath GetTmgFilePath();
+  std::string CheckPrivilege(const std::string& privilege);
 
   std::string app_id_;
   std::string disk_cache_path_;
@@ -80,7 +86,10 @@ class NativeWebRuntimeDelegateTV : public WRTProfileDelegate {
   bool need_try_mount_ = true;
   bool initialized_ = false;
   bool locale_dir_binded_ = false;
+  bool privilege_cahce_init_ = false;
+  bool power_callback_registered_ = false;
   base::FilePath tmg_file_path_;
+  std::set<std::string> privileges_cache_;
 };
 
 }  // namespace wrt
old mode 100755 (executable)
new mode 100644 (file)
index 7366bac..b154e2c
@@ -97,14 +97,13 @@ void WidgetStateProvider::OnURLChanged(std::string url) {
     url.erase(found);
   }
 
-  widget_url = url;
 #if !defined(WRT_JS_BRINGUP)
   std::string vkey = kPrefixVconfKeyWidgetStatus + widget_app_id + "_URL";
-  std::string url_value = VconfHandle(vkey).Str();
-  LOG(INFO) << "vconf key before :" << url_value;
+  LOG(INFO) << "vconf key before :" << widget_url;
   LOG(INFO) << "vconf key after :" << vkey << ", value :" << url;
   VconfHandle(vkey).Set(url, true);
 #endif
+  widget_url = url;
 }
 
 } // namespace wrt
old mode 100755 (executable)
new mode 100644 (file)
index fdf031f..829795c
@@ -132,11 +132,15 @@ const int kMaxWidgetPosition = 4;
 const double kScaleFactorDefault = 1.0;
 const double kScaleFactorLandscapeScale = 0.5625;
 
+unsigned int global_resource_id = 0;
+unsigned int wayland_window_id = 0;
+
 void HandleResourceId(
     void* data, struct tizen_resource* tizen_resource, uint32_t id) {
-  unsigned int* wl_surface_id = static_cast<unsigned int*>(data);
-  *wl_surface_id = id;
+  global_resource_id = id;
   LOG(INFO) << "got global resource id(" << id << ") from server ";
+  auto resource_id = std::to_string(id);
+  setenv("global_resource_id", resource_id.c_str(), true);
 }
 
 void GetScreenResolution(int& width, int& height) {
@@ -267,6 +271,8 @@ bool CanSupportLandscapeScale() {
   return false;
 #else
   auto is_signage = IsSignageProduct();
+  if (!is_signage)
+    return false;
   auto rotate_status = VconfHandle(kMenuOrientation).Int();
   auto& meta_data_info = ApplicationData::GetInstance().meta_data_info();
   auto is_landscape_scale =
@@ -304,6 +310,10 @@ void WRTNativeWindowTV::MoveWindowForeground() {
     ecore_evas_layer_set(ee, foreground_layer);
 }
 
+unsigned int WRTNativeWindowTV::GetGlobalResourceId() {
+  return global_resource_id;
+}
+
 int WRTNativeWindowTV::GetWindowLayer() {
   auto* ee = GetPlatformCanvas();
   if (ee)
@@ -315,8 +325,6 @@ int WRTNativeWindowTV::GetWindowLayer() {
 WRTNativeWindowTV::WRTNativeWindowTV(const gin_helper::Dictionary& options,
                                      electron::NativeWindow* parent)
     : WRTNativeWindow::WRTNativeWindow(options, parent),
-      global_resource_id_(0),
-      wayland_window_id_(0),
       alphaset_(false),
       partial_(false),
       channel_changeable_(false),
@@ -343,6 +351,7 @@ void WRTNativeWindowTV::SetWebContents(content::WebContents* web_contents) {
     return;
 
   top_window_ = GetTopWindow();
+  SetGlobalResourceId(top_window_);
 
 #if defined(TIZEN_PEPPER_EXTENSIONS)
   InitializePepperExtensionSystem();
@@ -355,7 +364,6 @@ void WRTNativeWindowTV::SetWebContents(content::WebContents* web_contents) {
   TvWindowManager::GetInstance()->Initialize(top_window_);
   SetDisplayRotatorCallback();
   CreateMouseCursor(ewk_view);
-  SetGlobalResourceId();
   SetAppMetaDataInfo();
   SetRuntimeVariables();
   SetProxyInfo();
@@ -457,15 +465,17 @@ void WRTNativeWindowTV::CreateMouseCursor(Evas_Object* window) {
   CursorModule_Finalize();
 }
 
-void WRTNativeWindowTV::SetGlobalResourceId() {
-  global_resource_id_ = 0;
+// static
+void WRTNativeWindowTV::SetGlobalResourceId(Evas_Object* top_window) {
+  if (global_resource_id)
+    return;
 
-  Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(top_window_));
+  Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(top_window));
   Ecore_Wl2_Window* wl_window = ecore_evas_wayland2_window_get(ee);
-  wayland_window_id_ =
+  wayland_window_id =
       static_cast<unsigned int>(ecore_wl2_window_id_get(wl_window));
-  LOG(INFO) << "window_ = " << top_window_ << ", wl_window = " << wl_window
-            << ", windowid = " << wayland_window_id_;
+  LOG(INFO) << "window_ = " << top_window << ", wl_window = " << wl_window
+            << ", windowid = " << wayland_window_id;
   struct wl_surface* wl_surface =
       (struct wl_surface*)ecore_wl2_window_surface_get(wl_window);
   Ecore_Wl2_Display* wl2_display = ecore_wl2_connected_display_get(nullptr);
@@ -518,8 +528,7 @@ void WRTNativeWindowTV::SetGlobalResourceId() {
 
   if (tz_resource) {
     wl_proxy_set_queue((struct wl_proxy*)tz_resource, wl_queue);
-    tizen_resource_add_listener(
-      tz_resource, &tz_resource_listener, &global_resource_id_);
+    tizen_resource_add_listener(tz_resource, &tz_resource_listener, nullptr);
     wl_display_roundtrip_queue(wl_display, wl_queue);
   } else
     LOG(ERROR) << "error to find tz_resource";
@@ -761,9 +770,9 @@ void WRTNativeWindowTV::BeforeWindowQuit() {
 void WRTNativeWindowTV::SetRuntimeVariables() {
   auto& runtime = NativeWebRuntime::GetInstance();
 
-  std::string global_resource_id = std::to_string(global_resource_id_);
   LOG(INFO) << "global_resource_id : " << global_resource_id;
-  runtime.SetRuntimeVariable("global_resource_id", global_resource_id);
+  runtime.SetRuntimeVariable("global_resource_id",
+      std::to_string(global_resource_id));
 
   std::ostringstream ostr_window_id;
   ostr_window_id << top_window_;
@@ -1474,7 +1483,7 @@ void WRTNativeWindowTV::SetUpgradeWebapiJson() {
 }
 
 bool WRTNativeWindowTV::IsSameWindowId(const unsigned int window_id) {
-  return (wayland_window_id_ == window_id);
+  return (wayland_window_id == window_id);
 }
 
 void WRTNativeWindowTV::TakeScreenshot(
old mode 100755 (executable)
new mode 100644 (file)
index 6553513..0687715
@@ -41,7 +41,9 @@ class WRTNativeWindowTV : public WRTNativeWindow {
   static void MoveWindowBackground();
   static void MoveWindowForeground();
   static int GetWindowLayer();
+  static unsigned int GetGlobalResourceId();
   static void SetMenuZoomFill(const std::string& enable);
+  static void SetGlobalResourceId(Evas_Object* top_window);
   static bool SetRotation();
 
   explicit WRTNativeWindowTV(const gin_helper::Dictionary& options,
@@ -51,8 +53,6 @@ class WRTNativeWindowTV : public WRTNativeWindow {
   WRTNativeWindowTV(const WRTNativeWindowTV&) = delete;
   WRTNativeWindowTV& operator=(const WRTNativeWindowTV&) = delete;
 
-  unsigned int GetGlobalResourceId() const { return global_resource_id_; }
-
   void DidFinishNavigation(const std::string& url);
   void ExecuteJavaScript(const std::string& script);
   void GetImeAndKeyPadConfig(bool& show_ime_panel,
@@ -102,7 +102,6 @@ class WRTNativeWindowTV : public WRTNativeWindow {
   void SetConformantObject(ConformantStyle style);
   void SetDimScreen();
   void SetDisplayRotatorCallback();
-  void SetGlobalResourceId();
   void SetInvisibleDelivery();
   void SetKeyboardFuncKey();
   void SetKeyEventChecker();
@@ -133,8 +132,6 @@ class WRTNativeWindowTV : public WRTNativeWindow {
 
   base::OneShotTimer suspend_timer_;
   unsigned int suspend_delay_ = 500; // ms
-  unsigned int global_resource_id_;
-  unsigned int wayland_window_id_;
   bool alphaset_;
   bool partial_;
   bool channel_changeable_;
old mode 100755 (executable)
new mode 100644 (file)
index a97a3bc..a5feef5
@@ -113,10 +113,6 @@ bool SendAppControlData(const char* extra_key, const char* extra_value) {
     app_control_add_extra_data(handle, kCommandKey, extra_key);
     app_control_add_extra_data(handle, kCommandValue, extra_value);
   }
-#if defined(OS_TIZEN_TV_PRODUCT)
-  // to disable dynamic boosting
-  app_control_add_extra_data(handle, "Preloading", "true");
-#endif
   ret = app_control_send_launch_request(handle, nullptr, nullptr);
   if (ret != APP_CONTROL_ERROR_NONE) {
     LOG(ERROR) << "Failed to send launch request : " << ret;
old mode 100755 (executable)
new mode 100644 (file)
index 4cfe4ae..e1ac9db
 #include "wrt/src/service/wrt_service.h"
 #include "wrt/xwalk_extensions/browser/xwalk_extension_manager.h"
 
+#if defined(OS_TIZEN_TV_PRODUCT) && TIZEN_VERSION_AT_LEAST(7, 0, 0)
+#include <boost-api.h>
+#endif
+
 namespace wrt {
 
 namespace {
@@ -41,6 +45,19 @@ std::string ConvertEncodedBundle(bundle* bundle_data) {
   return std::string(reinterpret_cast<char*>(encoded_data), bundle_length);
 }
 
+#if defined(OS_TIZEN_TV_PRODUCT) && TIZEN_VERSION_AT_LEAST(7, 0, 0)
+void RequestAsBackgroundProcess() {
+  static bool did_boost_down = false;
+  if (!did_boost_down) {
+    boost_app_info_t app_info;
+    app_info.parent.framework_type = BOOST_APP_FW;
+    app_info.window_type = WINDOW_TYPE_UNDEFINED;
+    app_info.status = BOOST_APP_EVENT_CREATE_REQUEST_PRELOAD;
+    boost_request_by_pid(getpid(), (const boost_info_t *)&app_info);
+    did_boost_down = true;
+  }
+}
+#endif
 }  // namespace
 
 WRTServiceManager::WRTServiceManager() : quit_requested_(false) {
@@ -49,7 +66,7 @@ WRTServiceManager::WRTServiceManager() : quit_requested_(false) {
   ecore_init();
   CreateUvHandlers();
   DelayShutdown();
-  EarlyInitialization();
+  uv_init_threadpool();
 }
 
 WRTServiceManager::~WRTServiceManager() {}
@@ -62,11 +79,6 @@ WRTServiceManager* WRTServiceManager::Get(bool can_create) {
   return manager;
 }
 
-void WRTServiceManager::EarlyInitialization() {
-  uv_init_threadpool();
-  XWalkExtensionManager::GetInstance()->EarlyInitialization();
-}
-
 void WRTServiceManager::Shutdown() {
   LOG(INFO) << "WRTServiceManager is in shutdown!";
   XWalkExtensionManager::GetInstance()->Shutdown();
@@ -374,6 +386,10 @@ void WRTServiceManager::OnServiceStarted(uv_async_t* handle) {
     return;
   }
 
+#if defined(OS_TIZEN_TV_PRODUCT) && TIZEN_VERSION_AT_LEAST(7, 0, 0)
+  RequestAsBackgroundProcess();
+#endif
+
   std::vector<std::string> services;
   uv_mutex_lock(&service_manager->mutex_);
   services.swap(service_manager->prepared_to_start_services_);
old mode 100755 (executable)
new mode 100644 (file)
index 0d852c8..df3fe2f
@@ -72,7 +72,6 @@ class WRTServiceManager {
   void InitAulHandler(int argc, char** argv);
   void CloseUvHandlers();
   void CreateUvHandlers();
-  void EarlyInitialization();
   bool HandleMessageQueue();
 
   uv_async_t handle_adder_;
old mode 100755 (executable)
new mode 100644 (file)
index 1add039..0e2e2ff
 #include "wrt/src/common/app_db.h"
 #include "wrt/src/common/constants.h"
 
+#ifndef XWALK_EXTENSION_PATH
+  #error XWALK_EXTENSION_PATH is not set.
+#endif
+
 namespace wrt {
 
+XWalkExtensionManagerTV::XWalkExtensionManagerTV() {
+  preload_extensions_["widget"] =
+      XWALK_EXTENSION_PATH + std::string("/libwidget_plugin.so");
+
+  lazyload_extensions_["tizen.systeminfo"] =
+      XWALK_EXTENSION_PATH + std::string("/libtizen_systeminfo.so");
+  lazyload_extensions_["webapis.productinfo"] =
+      XWALK_EXTENSION_PATH + std::string("/libwebapis_productinfo.so");
+  lazyload_extensions_["webapis.avplay"] =
+      XWALK_EXTENSION_PATH + std::string("/libwebapis_avplay.so");
+
+  EarlyInitialization();
+}
+
+bool XWalkExtensionManagerTV::OpenTizenCommonExntension() {
+  if (tizen_common_dlhandle_)
+    return true;
+
+  const char* tizen_common = XWALK_EXTENSION_PATH"/libtizen_common.so";
+  tizen_common_dlhandle_ = dlopen(tizen_common, RTLD_LAZY);
+  if (!tizen_common_dlhandle_) {
+    LOG(WARNING) << "fail to dlopen : " << dlerror();
+    return false;
+  }
+  return true;
+}
+
+void XWalkExtensionManagerTV::EarlyInitialization() {
+  if (!OpenTizenCommonExntension())
+    return;
+
+  typedef void (*CreateTaskQueue)(void);
+  auto create_task_queue =
+      (CreateTaskQueue)dlsym(tizen_common_dlhandle_, "CreateTaskQueue");
+  if (!create_task_queue) {
+    LOG(INFO) << "fail to dlsym : " << dlerror();
+    return;
+  }
+  create_task_queue();
+}
+
+void XWalkExtensionManagerTV::SetCachedPrivileges() {
+  if (!OpenTizenCommonExntension())
+    return;
+
+  auto privileges =
+      NativeWebRuntimeDelegateTV::GetInstance().GetPrivilegeCache();
+  if (privileges.empty())
+    return;
+
+  LOG(INFO) << "SetCachedPrivilege";
+  typedef void (*SetCachedPrivilege)(const char*);
+  auto set_privilege =
+      (SetCachedPrivilege)dlsym(tizen_common_dlhandle_, "SetCachedPrivilege");
+  if (!set_privilege) {
+    LOG(INFO) << "fail to dlsym : " << dlerror();
+    return;
+  }
+
+  for (const auto& privilege : privileges)
+    set_privilege(privilege.c_str());
+}
+
 void XWalkExtensionManagerTV::LoadExtensions(
     wrt::ApplicationData::AppType app_type) {
   XWalkExtensionManager::LoadExtensions(app_type);
@@ -166,10 +233,7 @@ std::string XWalkExtensionManagerTV::HandleRuntimeMessageInternal(
     }
     return "failed";
   } else if (type == "tizen://getGlobalResourceId") {
-    if (auto native_window_tv = wrt::WRTNativeWindowTV::GetMainNativeWindow()) {
-      return std::to_string(native_window_tv->GetGlobalResourceId());
-    }
-    return "0";
+    return std::to_string(WRTNativeWindowTV::GetGlobalResourceId());
   } else {
     return XWalkExtensionManager::HandleRuntimeMessageInternal(type, value);
   }
@@ -391,4 +455,18 @@ std::string XWalkExtensionManagerTV::GetUpgradableLibPath(
   return std::string();
 }
 
+void XWalkExtensionManagerTV::PreloadExtensions() {
+  XWalkExtensionManager::PreloadExtensions();
+
+  for (auto& extension : lazyload_extensions_) {
+    LOG(INFO) << "preload name: " << extension.first
+              << ",lib:" << extension.second;
+    void* dlhandle = dlopen(extension.second.c_str(), RTLD_LAZY);
+    if (!dlhandle)
+      LOG(WARNING) << "Fail to load libs : " << dlerror();
+    else
+      preload_handle_[extension.second] = dlhandle;
+  }
+}
+
 }  // namespace wrt
old mode 100755 (executable)
new mode 100644 (file)
index 70a8fa8..07ae27a
@@ -11,7 +11,7 @@ namespace wrt {
 
 class XWalkExtensionManagerTV : public XWalkExtensionManager {
  public:
-  XWalkExtensionManagerTV() {}
+  XWalkExtensionManagerTV();
   ~XWalkExtensionManagerTV() {}
 
  private:
@@ -20,15 +20,19 @@ class XWalkExtensionManagerTV : public XWalkExtensionManager {
   void CreateInstance(const std::string& name,
                       CreateInstanceCallback callback) override;
   void PrefetchExtensions() override;
+  void PreloadExtensions() override;
   void ParseUpgradableExtensions() override;
   void RegisterUpgradableExtensions() override;
+  void SetCachedPrivileges() override;
   void UnloadExtensions() override;
   std::string GetUpgradableLibPath(const std::string& name) override;
   std::string HandleRuntimeMessageInternal(
       const std::string& type, const std::string& value) override;
 
+  void EarlyInitialization();
   bool IsPreloadedExtension(std::string extension_name);
   bool NeedHandleUpgradeWebapiJson();
+  bool OpenTizenCommonExntension();
   void SaveLoadedExtensions();
 
   using ExtensionInfo = std::map<std::string, std::string>;
@@ -41,6 +45,8 @@ class XWalkExtensionManagerTV : public XWalkExtensionManager {
   std::map<std::string, std::vector<std::string>>
       upgradable_extensions_entries_; // "name" : enties[]
   base::Time upgrade_webapi_modified_time_;
+  void* tizen_common_dlhandle_ = nullptr;
+  std::map<std::string, std::string> lazyload_extensions_;
 };
 
 }  // namespace wrt
old mode 100755 (executable)
new mode 100644 (file)
index 3f679e1..9130cc7
@@ -88,10 +88,6 @@ XWalkExtensionManager::XWalkExtensionManager() {
       XWALK_EXTENSION_PATH + std::string("/libtizen_application.so");
   preload_extensions_["xwalk"] =
       XWALK_EXTENSION_PATH + std::string("/libtizen_utils.so");
-#if defined(OS_TIZEN_TV_PRODUCT)
-  preload_extensions_["widget"] =
-      XWALK_EXTENSION_PATH + std::string("/libwidget_plugin.so");
-#endif
 }
 
 XWalkExtensionManager::~XWalkExtensionManager() {}
@@ -222,22 +218,6 @@ void XWalkExtensionManager::UnloadExtensions() {
   extensions_.clear();
 }
 
-void XWalkExtensionManager::EarlyInitialization() {
-  const char* tizen_common = XWALK_EXTENSION_PATH"/libtizen_common.so";
-  void* dlhandle = dlopen(tizen_common, RTLD_LAZY);
-  if (!dlhandle) {
-    LOG(WARNING) << "fail to dlopen : " << dlerror();
-    return;
-  }
-  typedef void (*CreateTaskQueue)(void);
-  auto create_task_queue = (CreateTaskQueue)dlsym(dlhandle, "CreateTaskQueue");
-  if (!create_task_queue) {
-    LOG(WARNING) << "fail to dlsym : " << dlerror();
-    return;
-  }
-  create_task_queue();
-}
-
 bool XWalkExtensionManager::ValidateSymbols(XWalkExtension* extension) {
   auto& name = extension->GetName();
   if (extension_symbols_.find(name) != extension_symbols_.end()) {
old mode 100755 (executable)
new mode 100644 (file)
index f2f4843..578052a
@@ -35,10 +35,8 @@ class XWalkExtensionManager : public mojom::XWalkExtensionBrowser {
   const ExtensionMap& GetExtensions() const { return extensions_; }
   XWalkExtension::Instance* GetExtensionInstance(XW_Instance xw_instance);
 
-  void EarlyInitialization();
   void GetRuntimeVariable(const char* key, char* value, size_t value_len);
   void LoadUserExtensions(const std::string app_path);
-  void PreloadExtensions();
   void RegisterInstance(XWalkExtension::Instance* instance);
   void UnregisterInstance(XWalkExtension::Instance* instance);
 
@@ -50,13 +48,15 @@ class XWalkExtensionManager : public mojom::XWalkExtensionBrowser {
 
   int32_t GetNextInstanceID();
 
-  // product specific functions
+  virtual void PreloadExtensions();
   virtual void LoadExtensions(wrt::ApplicationData::AppType app_type);
   virtual void UnloadExtensions();
 
+  // product specific functions
   virtual void PrefetchExtensions() {}
   virtual void ParseUpgradableExtensions() {}
   virtual void RegisterUpgradableExtensions() {}
+  virtual void SetCachedPrivileges() {}
   virtual std::string GetUpgradableLibPath(const std::string& name) {
     return std::string();
   }