[WRTjs][VD] Reduce IS_TIZEN_TV compile flag #4 65/306265/2
authorDongHyun Song <dh81.song@samsung.com>
Mon, 19 Feb 2024 08:26:09 +0000 (17:26 +0900)
committerDongHyun Song <dh81.song@samsung.com>
Fri, 23 Feb 2024 05:37:19 +0000 (14:37 +0900)
Remove IS_TIZEN_TV on TV profile's file handlers.

Change-Id: I56843c1e5aeab42426f782a9156abacae9b86993
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
wrt/src/browser/native_web_runtime.cc
wrt/src/browser/net/tv/encrypted_file_url_loader.cc
wrt/src/browser/net/tv/encrypted_file_url_loader.h
wrt/src/browser/net/wrt_file_url_loader.cc
wrt/src/browser/net/wrt_file_url_loader.h
wrt/src/browser/net/wrt_proxying_url_loader_factory.cc
wrt/src/browser/net/wrt_proxying_url_loader_factory.h
wrt/src/browser/tv/native_web_runtime_delegate_tv.cc
wrt/src/browser/tv/native_web_runtime_delegate_tv.h

index f6389c2..e22c311 100644 (file)
@@ -142,7 +142,6 @@ void NativeWebRuntime::Initialize() {
     runtime_delegate_->Initialize();
 
   app_data.Initialize();
-  InitializeWRTFileURLLoader();
   LocaleManager::GetInstance();
   resource_manager_.reset(new ResourceManager);
 
index 6e678ee..01de7ec 100755 (executable)
@@ -303,4 +303,11 @@ void CreateEncryptedFileURLLoader(
                      request, std::move(loader), std::move(client)));
 }
 
+void SetEncryptedFileUrlCallbacks() {
+  WRTProxyingURLLoaderFactory::SetUrlParser(
+      base::BindRepeating(&ParseEncryptedURL));
+  WRTProxyingURLLoaderFactory::SetEncryptedFileLoader(
+      base::BindRepeating(&CreateEncryptedFileURLLoader));
+}
+
 }  // namespace wrt
index 843bfe4..6150fb7 100755 (executable)
@@ -20,6 +20,7 @@ void CreateEncryptedFileURLLoader(
     const network::ResourceRequest& request,
     mojo::PendingReceiver<network::mojom::URLLoader> loader,
     mojo::PendingRemote<network::mojom::URLLoaderClient> client);
+void SetEncryptedFileUrlCallbacks();
 
 }  // namespace wrt
 
index 67545a4..fbf7a13 100644 (file)
 #include "wrt/src/common/application_data.h"
 #include "wrt/src/common/constants.h"
 
-#if BUILDFLAG(IS_TIZEN_TV)
-#include <tzplatform_config.h>
-#endif
-
 namespace wrt {
 
 namespace {
 
 constexpr size_t kDefaultFileUrlPipeSize = 65536;
 
+FileRequestIntercepter file_request_intercepter;
+
 bool ShouldOverrideMimeType(const GURL& url,
                             std::string& new_mime_type,
                             std::string& new_charset_type) {
@@ -73,44 +71,6 @@ bool ShouldOverrideMimeType(const GURL& url,
 
 }  // namespace
 
-#if BUILDFLAG(IS_TIZEN_TV)
-std::vector<std::string> allowed_path_list;
-std::vector<std::string> allowed_sub_path_list;
-
-void SetAllowedPath() {
-  auto pkg_id = ApplicationData::GetInstance().GetPackageID();
-  auto rw_base_path = std::string(tzplatform_getenv(TZ_SYS_RW_APP));
-
-  // this path should be first for early return
-  allowed_path_list.push_back(rw_base_path + "/" + pkg_id);
-
-  allowed_path_list.push_back("/opt/media/");
-  allowed_path_list.push_back("/media/");
-
-  allowed_path_list.push_back("/opt/usr/home/owner/share/");
-  allowed_path_list.push_back("/home/owner/share/");
-
-  allowed_path_list.push_back("/opt/usr/home/owner/content/");
-  allowed_path_list.push_back("/home/owner/content/");
-  allowed_path_list.push_back("/usr/share/feedback/");
-
-  allowed_path_list.push_back("/opt/usr/home/owner/apps_rw/" + pkg_id);
-  allowed_path_list.push_back("/home/owner/apps_rw/" + pkg_id);
-
-  allowed_path_list.push_back("/usr/bin/emps/empPepperPlugins/");
-  allowed_path_list.push_back("/bin/emps/empPepperPlugins/");
-  allowed_path_list.push_back(rw_base_path + "/appbinarymanager/");
-
-  allowed_path_list.push_back("/tmp/");
-  allowed_path_list.push_back("/opt/share/");
-  allowed_path_list.push_back(rw_base_path + "/pepper/");
-
-  // this path is for allowed sub path
-  allowed_sub_path_list.push_back("/shared/res");
-  allowed_sub_path_list.push_back("/shared/data");
-}
-#endif
-
 class WRTFileURLLoader : public network::mojom::URLLoader {
  public:
   static void CreateAndStart(
@@ -143,26 +103,6 @@ class WRTFileURLLoader : public network::mojom::URLLoader {
   WRTFileURLLoader() = default;
   ~WRTFileURLLoader() override = default;
 
-#if BUILDFLAG(IS_TIZEN_TV)
-  bool IsAllowedPath(const base::FilePath& path) {
-    for (auto allowed_path : allowed_path_list) {
-      if (base::StartsWith(path.value(), allowed_path,
-                           base::CompareCase::SENSITIVE)) {
-        return true;
-      }
-    }
-
-    for (auto allowed_path : allowed_sub_path_list) {
-      if (path.value().find(allowed_path) != std::string::npos) {
-        return true;
-      }
-    }
-
-    LOG(ERROR) << "Invalid access : " << path;
-    return false;
-  }
-#endif
-
   void Start(
       const network::ResourceRequest& request,
       mojo::PendingReceiver<network::mojom::URLLoader> loader,
@@ -182,12 +122,13 @@ class WRTFileURLLoader : public network::mojom::URLLoader {
       return;
     }
 
-#if BUILDFLAG(IS_TIZEN_TV)
-    if (!IsAllowedPath(path)) {
-      OnClientComplete(net::ERR_ACCESS_DENIED);
-      return;
+    if (!file_request_intercepter.is_null()) {
+      if (!file_request_intercepter.Run(path)) {
+        OnClientComplete(net::ERR_ACCESS_DENIED);
+        return;
+      }
     }
-#endif
+
     std::string new_mime_type;
     std::string new_charset_type;
     if (ShouldOverrideMimeType(request.url, new_mime_type, new_charset_type)) {
@@ -315,10 +256,8 @@ class WRTFileURLLoader : public network::mojom::URLLoader {
   uint64_t total_bytes_written_ = 0;
 };
 
-void InitializeWRTFileURLLoader() {
-#if BUILDFLAG(IS_TIZEN_TV)
-  SetAllowedPath();
-#endif
+void SetFileRequestIntercepter(const FileRequestIntercepter intercepter) {
+  file_request_intercepter = intercepter;
 }
 
 void CreateWRTFileURLLoader(
index df651cf..0146205 100755 (executable)
 
 namespace wrt {
 
-void InitializeWRTFileURLLoader();
-
 void CreateWRTFileURLLoader(
     const network::ResourceRequest& request,
     mojo::PendingReceiver<network::mojom::URLLoader> loader,
     mojo::PendingRemote<network::mojom::URLLoaderClient> client);
 
+using FileRequestIntercepter =
+    base::RepeatingCallback<bool(const base::FilePath&)>;
+void SetFileRequestIntercepter(const FileRequestIntercepter intercepter);
+
 }  // namespace wrt
 
 #endif  // BROWSER_NET_WRT_FILE_URL_LOADER_H_
index 2bfc26c..82cee17 100644 (file)
@@ -2,18 +2,13 @@
 
 #include "base/no_destructor.h"
 #include "content/browser/data_url_loader_factory.h"
-#include "wrt/src/browser/net/wrt_file_url_loader.h"
-
-#if BUILDFLAG(IS_TIZEN_TV)
 #include "electron/shell/browser/browser.h"
-#include "wrt/src/browser/net/tv/encrypted_file_url_loader.h"
-#endif
+#include "wrt/src/browser/net/wrt_file_url_loader.h"
 
 namespace wrt {
 
 namespace {
 
-#if !BUILDFLAG(IS_TIZEN_TV)
 WRTProxyingURL ParseURLInternal(const GURL& url) {
   std::string url_str = url.possibly_invalid_spec();
   std::string orignal_str = url_str;
@@ -33,7 +28,10 @@ WRTProxyingURL ParseURLInternal(const GURL& url) {
   else
     return WRTProxyingURL(GURL());
 }
-#endif
+
+WRTProxyingURLLoaderFactory::UrlParser url_parser =
+    base::BindRepeating(&ParseURLInternal);
+WRTProxyingURLLoaderFactory::EncryptedFileLoader encrypted_file_loader;
 
 }  // namespace
 
@@ -44,6 +42,17 @@ ResourceManager& WRTProxyingURLLoaderFactory::GetResourceManager() {
 }
 
 // static
+void WRTProxyingURLLoaderFactory::SetUrlParser(const UrlParser& paraser) {
+  url_parser = paraser;
+}
+
+// static
+void WRTProxyingURLLoaderFactory::SetEncryptedFileLoader(
+    const EncryptedFileLoader& loader) {
+  encrypted_file_loader = loader;
+}
+
+// static
 WRTProxyingURL WRTProxyingURLLoaderFactory::ParseURL(const GURL& url) {
   auto& resource_manager = WRTProxyingURLLoaderFactory::GetResourceManager();
   if (!resource_manager.AllowedResource(url.possibly_invalid_spec())) {
@@ -51,11 +60,7 @@ WRTProxyingURL WRTProxyingURLLoaderFactory::ParseURL(const GURL& url) {
                << "] was blocked by WARP";
     return GURL("about:blank");
   }
-#if BUILDFLAG(IS_TIZEN_TV)
-  return ParseEncryptedURL(url);
-#else
-  return ParseURLInternal(url);
-#endif
+  return url_parser.Run(url);
 }
 
 WRTProxyingURLLoaderFactory::WRTProxyingURLLoaderFactory(
@@ -93,19 +98,15 @@ void WRTProxyingURLLoaderFactory::CreateLoaderAndStart(
   if (parsed_url.is_valid())
     request.url = parsed_url;
 
-#if BUILDFLAG(IS_TIZEN_TV)
   if (electron::Browser::Get()->is_quitting()) {
     LOG(INFO) << "ignore request : " << request.url.possibly_invalid_spec();
     return;
   }
-  if (proxying_url.encrypted()) {
-    CreateEncryptedFileURLLoader(
-        request, std::move(loader), std::move(client));
+  if (proxying_url.encrypted() && !encrypted_file_loader.is_null()) {
+    encrypted_file_loader.Run(request, std::move(loader), std::move(client));
     return;
   }
-#else
   LOG(INFO) << "url : " << request.url.possibly_invalid_spec();
-#endif
 
   // Check if user has intercepted this scheme.
   auto it = intercepted_handlers_.find(request.url.scheme());
index 98636a1..611c323 100755 (executable)
@@ -30,8 +30,15 @@ class WRTProxyingURL {
 class WRTProxyingURLLoaderFactory
     : public network::mojom::URLLoaderFactory {
  public:
+  using UrlParser = base::RepeatingCallback<WRTProxyingURL(const GURL&)>;
+  using EncryptedFileLoader = base::RepeatingCallback<void(
+      const network::ResourceRequest&,
+      mojo::PendingReceiver<network::mojom::URLLoader>,
+      mojo::PendingRemote<network::mojom::URLLoaderClient>)>;
   static ResourceManager& GetResourceManager();
   static WRTProxyingURL ParseURL(const GURL& url);
+  static void SetUrlParser(const UrlParser& parser);
+  static void SetEncryptedFileLoader(const EncryptedFileLoader& loader);
 
   WRTProxyingURLLoaderFactory(
       const electron::HandlersMap& intercepted_handlers,
index e3e20bc..675bb13 100644 (file)
@@ -46,6 +46,8 @@
 #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/net/wrt_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"
@@ -275,6 +277,12 @@ void NativeWebRuntimeDelegateTV::Initialize(void* data) {
   app_id_ = app_data.app_id();
   auto extension_manager = XWalkExtensionManager::GetInstance();
   extension_manager->RegisterUpgradableExtensions();
+
+  SetAllowedPath();
+  SetFileRequestIntercepter(base::BindRepeating(
+      &NativeWebRuntimeDelegateTV::IsAllowedPath, base::Unretained(this)));
+  SetEncryptedFileUrlCallbacks();
+
   initialized_ = true;
 }
 
@@ -745,4 +753,53 @@ bool NativeWebRuntimeDelegateTV::BlockNavigation(const std::string& url) {
   return true;
 }
 
+void NativeWebRuntimeDelegateTV::SetAllowedPath() {
+  auto pkg_id = ApplicationData::GetInstance().GetPackageID();
+  auto rw_base_path = std::string(tzplatform_getenv(TZ_SYS_RW_APP));
+
+  // this path should be first for early return
+  allowed_path_list_.push_back(rw_base_path + "/" + pkg_id);
+
+  allowed_path_list_.push_back("/opt/media/");
+  allowed_path_list_.push_back("/media/");
+
+  allowed_path_list_.push_back("/opt/usr/home/owner/share/");
+  allowed_path_list_.push_back("/home/owner/share/");
+
+  allowed_path_list_.push_back("/opt/usr/home/owner/content/");
+  allowed_path_list_.push_back("/home/owner/content/");
+  allowed_path_list_.push_back("/usr/share/feedback/");
+
+  allowed_path_list_.push_back("/opt/usr/home/owner/apps_rw/" + pkg_id);
+  allowed_path_list_.push_back("/home/owner/apps_rw/" + pkg_id);
+
+  allowed_path_list_.push_back("/usr/bin/emps/empPepperPlugins/");
+  allowed_path_list_.push_back("/bin/emps/empPepperPlugins/");
+  allowed_path_list_.push_back(rw_base_path + "/appbinarymanager/");
+
+  allowed_path_list_.push_back("/tmp/");
+  allowed_path_list_.push_back("/opt/share/");
+  allowed_path_list_.push_back(rw_base_path + "/pepper/");
+
+  // this path is for allowed sub path
+  allowed_sub_path_list_.push_back("/shared/res");
+  allowed_sub_path_list_.push_back("/shared/data");
+}
+
+bool NativeWebRuntimeDelegateTV::IsAllowedPath(const base::FilePath& path) {
+  for (const auto& allowed_path : allowed_path_list_) {
+    if (base::StartsWith(path.value(), allowed_path,
+                         base::CompareCase::SENSITIVE)) {
+      return true;
+    }
+  }
+  for (const auto& allowed_path : allowed_sub_path_list_) {
+    if (path.value().find(allowed_path) != std::string::npos) {
+      return true;
+    }
+  }
+  LOG(ERROR) << "Invalid access : " << path;
+  return false;
+}
+
 }  // namespace wrt
index 43bde92..a6a658d 100644 (file)
@@ -78,6 +78,8 @@ class NativeWebRuntimeDelegateTV : public WRTProfileDelegate {
   void ApplyHalfWindow(std::string half_window_option);
   void ClearTmpFolder();
   void EarlyLoadUrlIfHostedApp();
+  bool IsAllowedPath(const base::FilePath& path);
+  void SetAllowedPath();
   void SetD2dServiceMessageListener();
   void SetDiskCache(bool enable);
   std::string CheckPrivilege(const std::string& privilege);
@@ -94,6 +96,8 @@ class NativeWebRuntimeDelegateTV : public WRTProfileDelegate {
   bool power_callback_registered_ = false;
   bool has_payload_data_ = false;
   std::set<std::string> privileges_cache_;
+  std::vector<std::string> allowed_path_list_;
+  std::vector<std::string> allowed_sub_path_list_;
 };
 
 }  // namespace wrt