From 2e6472f3b462ababb9ca08bad32791cde888e412 Mon Sep 17 00:00:00 2001 From: "huayong.xu" Date: Tue, 26 Jul 2022 10:39:38 +0800 Subject: [PATCH] Add an API for getting web view when request is intercepted. Change-Id: I0d50749897eace0b290ee87f1fff7c61bbcd4f1c --- dali-extension/web-engine-chromium/file.list | 1 + .../tizen-web-engine-chromium.cpp | 2369 +++++++------------- .../tizen-web-engine-chromium.h | 450 ++-- .../tizen-web-engine-manager.cpp | 124 + .../web-engine-chromium/tizen-web-engine-manager.h | 75 + .../tizen-web-engine-request-interceptor.cpp | 10 + .../tizen-web-engine-request-interceptor.h | 8 + 7 files changed, 1197 insertions(+), 1840 deletions(-) mode change 100644 => 100755 dali-extension/web-engine-chromium/tizen-web-engine-chromium.h create mode 100755 dali-extension/web-engine-chromium/tizen-web-engine-manager.cpp create mode 100755 dali-extension/web-engine-chromium/tizen-web-engine-manager.h mode change 100644 => 100755 dali-extension/web-engine-chromium/tizen-web-engine-request-interceptor.h diff --git a/dali-extension/web-engine-chromium/file.list b/dali-extension/web-engine-chromium/file.list index c53b12f..561bc85 100755 --- a/dali-extension/web-engine-chromium/file.list +++ b/dali-extension/web-engine-chromium/file.list @@ -13,6 +13,7 @@ web_engine_chromium_plugin_src_files = \ $(extension_src_dir)/web-engine-chromium/tizen-web-engine-hit-test.cpp \ $(extension_src_dir)/web-engine-chromium/tizen-web-engine-http-auth-handler.cpp \ $(extension_src_dir)/web-engine-chromium/tizen-web-engine-load-error.cpp \ + $(extension_src_dir)/web-engine-chromium/tizen-web-engine-manager.cpp \ $(extension_src_dir)/web-engine-chromium/tizen-web-engine-policy-decision.cpp \ $(extension_src_dir)/web-engine-chromium/tizen-web-engine-request-interceptor.cpp \ $(extension_src_dir)/web-engine-chromium/tizen-web-engine-security-origin.cpp \ diff --git a/dali-extension/web-engine-chromium/tizen-web-engine-chromium.cpp b/dali-extension/web-engine-chromium/tizen-web-engine-chromium.cpp index daf13db..d3f6e91 100755 --- a/dali-extension/web-engine-chromium/tizen-web-engine-chromium.cpp +++ b/dali-extension/web-engine-chromium/tizen-web-engine-chromium.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,32 +20,26 @@ #include "tizen-web-engine-back-forward-list.h" #include "tizen-web-engine-certificate.h" #include "tizen-web-engine-console-message.h" -#include "tizen-web-engine-context.h" #include "tizen-web-engine-context-menu.h" #include "tizen-web-engine-context-menu-item.h" -#include "tizen-web-engine-cookie-manager.h" #include "tizen-web-engine-form-repost-decision.h" #include "tizen-web-engine-hit-test.h" #include "tizen-web-engine-http-auth-handler.h" #include "tizen-web-engine-load-error.h" +#include "tizen-web-engine-manager.h" #include "tizen-web-engine-policy-decision.h" #include "tizen-web-engine-settings.h" #include #include -#include -#include -#include #include #include #include #include -#include #include #include -#include #include using namespace Dali; @@ -100,1888 +94,1179 @@ Ret ExecuteCallbackReturn(Callback callback, std::unique_ptr arg) } // Anonymous namespace -class WebViewContainerClientPair -{ -public: - WebViewContainerClientPair(WebViewContainerClient* client, Evas_Object* webView) - { - mClient = client; - mWebView = webView; - } - - WebViewContainerClient* mClient; - Evas_Object* mWebView; -}; - -// -// A class for managing multiple WebViews -// -class WebEngineManager +class TBMSurfaceSourceInitializer { public: - static WebEngineManager& Get() - { - static WebEngineManager instance; - return instance; - } - - WebEngineManager(WebEngineManager const&) = delete; - - void operator=(WebEngineManager const&) = delete; - - Ecore_Evas* GetWindow() - { - return mWindow; - } - - Dali::WebEngineContext* GetContext() - { - return mWebEngineContext.get(); - } - - Dali::WebEngineCookieManager* GetCookieManager() - { - return mWebEngineCookieManager.get(); - } - - void AddContainerClient(WebViewContainerClient* client, Evas_Object* webView) - { - mContainerClients.push_back(WebViewContainerClientPair(client, webView)); - } - - void RemoveContainerClient(Evas_Object* webView) + explicit TBMSurfaceSourceInitializer(NativeImageSourcePtr& imageSrc, uint32_t width, uint32_t height) { - for (auto it = mContainerClients.begin(); it != mContainerClients.end();) + mSurface = tbm_surface_create(width, height, TBM_FORMAT_ARGB8888); + if (!mSurface) { - if ((*it).mWebView == webView) - { - mContainerClients.erase(it); - break; - } - else - { - ++it; - } + DALI_LOG_ERROR("Failed to create tbm surface."); } + + Any tbmSource(mSurface); + imageSrc = NativeImageSource::New(tbmSource); + Any emptySource(0); + imageSrc->SetSource(emptySource); } - WebViewContainerClient* FindContainerClient(Evas_Object* o) + ~TBMSurfaceSourceInitializer() { - for (auto& webViewClient : mContainerClients) + if (mSurface) { - if (webViewClient.mWebView == o) + if (tbm_surface_destroy(mSurface) != TBM_SURFACE_ERROR_NONE) { - return webViewClient.mClient; + DALI_LOG_ERROR("Failed to destroy tbm surface."); } } - return nullptr; } private: - WebEngineManager() : mSlotDelegate(this) - { - elm_init(0, 0); - ewk_init(); - mWindow = ecore_evas_new("wayland_egl", 0, 0, 1, 1, 0); - - Ewk_Context* context = ewk_context_default_get(); - mWebEngineContext.reset(new TizenWebEngineContext(context)); - - Ewk_Cookie_Manager* manager = ewk_context_cookie_manager_get(context); - mWebEngineCookieManager.reset(new TizenWebEngineCookieManager(manager)); - LifecycleController::Get().TerminateSignal().Connect(mSlotDelegate, &WebEngineManager::OnTerminated); - } - - void OnTerminated() - { - for (auto it = mContainerClients.begin(); it != mContainerClients.end(); it++) - { - evas_object_del(it->mWebView); - } - mContainerClients.clear(); - ecore_evas_free(mWindow); - ewk_shutdown(); - elm_shutdown(); - DALI_LOG_RELEASE_INFO("#WebEngineManager is destroyed fully.\n"); - } - - SlotDelegate mSlotDelegate; - std::unique_ptr mWebEngineContext; - std::unique_ptr mWebEngineCookieManager; - Ecore_Evas* mWindow; - std::vector mContainerClients; + tbm_surface_h mSurface; }; -class WebViewContainerForDali +TizenWebEngineChromium::TizenWebEngineChromium() + : mWebView(nullptr) + , mWidth(0) + , mHeight(0) + , mJavaScriptEvaluationCount(0) { -public: - WebViewContainerForDali(WebViewContainerClient& client, uint32_t width, uint32_t height) - : mWebView(nullptr) - , mClient(client) - , mWidth(width) - , mHeight(height) - , mWebEngineSettings(nullptr) - , mWebEngineBackForwardList(nullptr) - { - InitWebView(0, nullptr); - WebEngineManager::Get().AddContainerClient(&mClient, mWebView); - } +} - WebViewContainerForDali(WebViewContainerClient& client, uint32_t width, uint32_t height, uint32_t argc, char** argv) - : mWebView(nullptr) - , mClient(client) - , mWidth(width) - , mHeight(height) - , mWebEngineSettings(nullptr) - , mWebEngineBackForwardList(nullptr) - { - InitWebView(argc, argv); - WebEngineManager::Get().AddContainerClient(&mClient, mWebView); - } +TizenWebEngineChromium::~TizenWebEngineChromium() +{ + Destroy(); +} - ~WebViewContainerForDali() - { - WebEngineManager::Get().RemoveContainerClient(mWebView); - evas_object_del(mWebView); - } +void TizenWebEngineChromium::Create(uint32_t width, uint32_t height, const std::string& locale, const std::string& timezoneID) +{ + mWidth = width; + mHeight = height; + InitWebView(0, nullptr); + WebEngineManager::Get().Add(mWebView, this); + TBMSurfaceSourceInitializer initializer(mDaliImageSrc, mWidth, mHeight); +} - void InitWebView(uint32_t argc, char** argv) - { - if (argc > 0) - { - ewk_set_arguments(argc, argv); - } +void TizenWebEngineChromium::Create(uint32_t width, uint32_t height, uint32_t argc, char** argv) +{ + mWidth = width; + mHeight = height; + InitWebView(argc, argv); + WebEngineManager::Get().Add(mWebView, this); + TBMSurfaceSourceInitializer initializer(mDaliImageSrc, mWidth, mHeight); +} - Ecore_Wl2_Window* win = AnyCast(Adaptor::Get().GetNativeWindowHandle()); - Ewk_Context* context = ewk_context_default_get(); - ewk_context_max_refresh_rate_set(context, 60); - mWebView = ewk_view_add(ecore_evas_get(WebEngineManager::Get().GetWindow())); - ewk_view_offscreen_rendering_enabled_set(mWebView, true); - ewk_view_ime_window_set(mWebView, win); - - Ewk_Settings* settings = ewk_view_settings_get(mWebView); - mWebEngineSettings.reset(new TizenWebEngineSettings(settings)); - - Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(mWebView); - mWebEngineBackForwardList.reset(new TizenWebEngineBackForwardList(backForwardList)); - - ewk_settings_viewport_meta_tag_set(settings, false); - - evas_object_smart_callback_add(mWebView, "offscreen,frame,rendered", - &WebViewContainerForDali::OnFrameRendered, - &mClient); - evas_object_smart_callback_add(mWebView, "load,started", - &WebViewContainerForDali::OnLoadStarted, - &mClient); - evas_object_smart_callback_add(mWebView, "load,progress", - &WebViewContainerForDali::OnLoadInProgress, - &mClient); - evas_object_smart_callback_add(mWebView, "load,finished", - &WebViewContainerForDali::OnLoadFinished, - &mClient); - evas_object_smart_callback_add(mWebView, "load,error", - &WebViewContainerForDali::OnLoadError, - &mClient); - evas_object_smart_callback_add(mWebView, "url,changed", - &WebViewContainerForDali::OnUrlChanged, - &mClient); - evas_object_smart_callback_add(mWebView, "console,message", - &WebViewContainerForDali::OnConsoleMessageReceived, - &mClient); - evas_object_smart_callback_add(mWebView, "edge,left", - &WebViewContainerForDali::OnEdgeLeft, - &mClient); - evas_object_smart_callback_add(mWebView, "edge,right", - &WebViewContainerForDali::OnEdgeRight, - &mClient); - evas_object_smart_callback_add(mWebView, "edge,top", - &WebViewContainerForDali::OnEdgeTop, - &mClient); - evas_object_smart_callback_add(mWebView, "edge,bottom", - &WebViewContainerForDali::OnEdgeBottom, - &mClient); - evas_object_smart_callback_add(mWebView, "form,repost,warning,show", - &WebViewContainerForDali::OnFormRepostDecided, - &mClient); - evas_object_smart_callback_add(mWebView, "policy,response,decide", - &WebViewContainerForDali::OnResponsePolicyDecided, - &mClient); - evas_object_smart_callback_add(mWebView, "policy,navigation,decide", - &WebViewContainerForDali::OnNavigationPolicyDecided, - &mClient); - evas_object_smart_callback_add(mWebView, "request,certificate,confirm", - &WebViewContainerForDali::OnCertificateConfirmed, - &mClient); - evas_object_smart_callback_add(mWebView, "ssl,certificate,changed", - &WebViewContainerForDali::OnSslCertificateChanged, - &mClient); - evas_object_smart_callback_add(mWebView, "contextmenu,show", - &WebViewContainerForDali::OnContextMenuShown, - &mClient); - evas_object_smart_callback_add(mWebView, "contextmenu,hide", - &WebViewContainerForDali::OnContextMenuHidden, - &mClient); - - ewk_view_authentication_callback_set(mWebView, &WebViewContainerForDali::OnAuthenticationChallenge, &mClient); - - evas_object_resize(mWebView, mWidth, mHeight); - evas_object_show(mWebView); - } +void TizenWebEngineChromium::Destroy() +{ + mJavaScriptEvaluationResultHandlers.clear(); + mJavaScriptMessageHandlers.clear(); - void LoadUrl(const std::string& url) - { - ewk_view_url_set(mWebView, url.c_str()); - } + WebEngineManager::Get().Remove(mWebView); + evas_object_del(mWebView); +} - void LoadHtml(const std::string& html) - { - ewk_view_html_string_load(mWebView, html.c_str(), 0, 0); - } +void TizenWebEngineChromium::LoadUrl(const std::string& path) +{ + ewk_view_url_set(mWebView, path.c_str()); +} - std::string GetUrl() - { - const char* url = ewk_view_url_get(mWebView); - return url ? std::string(url) : std::string(); - } +std::string TizenWebEngineChromium::GetTitle() const +{ + const char* title = ewk_view_title_get(mWebView); + return title ? std::string(title) : std::string(); +} - bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, - const std::string& unreachableUrl) +Dali::PixelData TizenWebEngineChromium::GetFavicon() const +{ + Evas_Object* iconObject = ewk_view_favicon_get(mWebView); + if (!iconObject) { - char* cBasicUri = basicUri.length() ? (char *)basicUri.c_str() : nullptr; - char* cUnreachableUrl = unreachableUrl.length() ? (char *)unreachableUrl.c_str() : nullptr; - return ewk_view_html_string_override_current_entry_load(mWebView, html.c_str(), cBasicUri, cUnreachableUrl); + return Dali::PixelData(); } + return ConvertImageColorSpace(iconObject); +} - bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, - const std::string& encoding, const std::string& baseUri) - { - char* cMimeType = mimeType.length() ? (char *)mimeType.c_str() : nullptr; - char* cEncoding = encoding.length() ? (char *)encoding.c_str() : nullptr; - char* cBaseUri = baseUri.length() ? (char *)baseUri.c_str() : nullptr; - return ewk_view_contents_set(mWebView, contents.c_str(), contentSize, cMimeType, cEncoding, cBaseUri); - } +NativeImageSourcePtr TizenWebEngineChromium::GetNativeImageSource() +{ + return mDaliImageSrc; +} - std::string GetTitle() - { - const char* title = ewk_view_title_get(mWebView); - return title ? std::string(title) : std::string(); - } +std::string TizenWebEngineChromium::GetUrl() const +{ + const char* url = ewk_view_url_get(mWebView); + return url ? std::string(url) : std::string(); +} - Dali::PixelData GetFavicon() - { - Evas_Object* iconObject = ewk_view_favicon_get(mWebView); - if (!iconObject) - { - return Dali::PixelData(); - } - return ConvertImageColorSpace(iconObject); - } +void TizenWebEngineChromium::LoadHtmlString(const std::string& html) +{ + ewk_view_html_string_load(mWebView, html.c_str(), 0, 0); +} - void Reload() - { - ewk_view_reload(mWebView); - } +bool TizenWebEngineChromium::LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl) +{ + char* cBasicUri = basicUri.length() ? (char *)basicUri.c_str() : nullptr; + char* cUnreachableUrl = unreachableUrl.length() ? (char *)unreachableUrl.c_str() : nullptr; + return ewk_view_html_string_override_current_entry_load(mWebView, html.c_str(), cBasicUri, cUnreachableUrl); +} - void StopLoading() - { - ewk_view_stop(mWebView); - } +bool TizenWebEngineChromium::LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, + const std::string& encoding, const std::string& baseUri) +{ + char* cMimeType = mimeType.length() ? (char *)mimeType.c_str() : nullptr; + char* cEncoding = encoding.length() ? (char *)encoding.c_str() : nullptr; + char* cBaseUri = baseUri.length() ? (char *)baseUri.c_str() : nullptr; + return ewk_view_contents_set(mWebView, contents.c_str(), contentSize, cMimeType, cEncoding, cBaseUri); +} - bool ReloadWithoutCache() - { - return ewk_view_reload_bypass_cache(mWebView); - } +void TizenWebEngineChromium::Reload() +{ + ewk_view_reload(mWebView); +} - void Suspend() - { - ewk_view_suspend(mWebView); - } +bool TizenWebEngineChromium::ReloadWithoutCache() +{ + return ewk_view_reload_bypass_cache(mWebView); +} - void Resume() - { - ewk_view_resume(mWebView); - } +void TizenWebEngineChromium::StopLoading() +{ + ewk_view_stop(mWebView); +} - void SuspendNetworkLoading() - { - ewk_view_suspend_network_loading(mWebView); - } +void TizenWebEngineChromium::Suspend() +{ + ewk_view_suspend(mWebView); +} - void ResumeNetworkLoading() - { - ewk_view_resume_network_loading(mWebView); - } +void TizenWebEngineChromium::Resume() +{ + ewk_view_resume(mWebView); +} - bool AddCustomHeader(const std::string& name, const std::string& value) - { - return ewk_view_custom_header_add(mWebView, name.c_str(), value.c_str()); - } +void TizenWebEngineChromium::SuspendNetworkLoading() +{ + ewk_view_suspend_network_loading(mWebView); +} - bool RemoveCustomHeader(const std::string& name) - { - return ewk_view_custom_header_remove(mWebView, name.c_str()); - } +void TizenWebEngineChromium::ResumeNetworkLoading() +{ + ewk_view_resume_network_loading(mWebView); +} - uint32_t StartInspectorServer(uint32_t port) - { - return ewk_view_inspector_server_start(mWebView, port); - } +bool TizenWebEngineChromium::AddCustomHeader(const std::string& name, const std::string& value) +{ + return ewk_view_custom_header_add(mWebView, name.c_str(), value.c_str()); +} - bool StopInspectorServer() - { - return ewk_view_inspector_server_stop(mWebView); - } +bool TizenWebEngineChromium::RemoveCustomHeader(const std::string& name) +{ + return ewk_view_custom_header_remove(mWebView, name.c_str()); +} - void ScrollBy(int32_t deltaX, int32_t deltaY) - { - ewk_view_scroll_by(mWebView, deltaX, deltaY); - } +uint32_t TizenWebEngineChromium::StartInspectorServer(uint32_t port) +{ + return ewk_view_inspector_server_start(mWebView, port); +} - bool ScrollEdgeBy(int32_t deltaX, int32_t deltaY) - { - return ewk_view_edge_scroll_by(mWebView, deltaX, deltaY); - } +bool TizenWebEngineChromium::StopInspectorServer() +{ + return ewk_view_inspector_server_stop(mWebView); +} - void SetScrollPosition(int32_t x, int32_t y) - { - ewk_view_scroll_set(mWebView, x, y); - } +void TizenWebEngineChromium::ScrollBy(int32_t deltaX, int32_t deltaY) +{ + ewk_view_scroll_by(mWebView, deltaX, deltaY); +} - Dali::Vector2 GetScrollPosition() const - { - int x = 0, y = 0; - ewk_view_scroll_pos_get(mWebView, &x, &y); - return Dali::Vector2(x, y); - } +bool TizenWebEngineChromium::ScrollEdgeBy(int32_t deltaX, int32_t deltaY) +{ + return ewk_view_edge_scroll_by(mWebView, deltaX, deltaY); +} - Dali::Vector2 GetScrollSize() const - { - int width = 0, height = 0; - ewk_view_scroll_size_get(mWebView, &width, &height); - return Dali::Vector2(width, height); - } +void TizenWebEngineChromium::SetScrollPosition(int32_t x, int32_t y) +{ + ewk_view_scroll_set(mWebView, x, y); +} - Dali::Vector2 GetContentSize() const - { - int width = 0, height = 0; - ewk_view_contents_size_get(mWebView, &width, &height); - return Dali::Vector2(width, height); - } +Dali::Vector2 TizenWebEngineChromium::GetScrollPosition() const +{ + int x = 0, y = 0; + ewk_view_scroll_pos_get(mWebView, &x, &y); + return Dali::Vector2(x, y); +} - void GoBack() - { - ewk_view_back(mWebView); - } +Dali::Vector2 TizenWebEngineChromium::GetScrollSize() const +{ + int width = 0, height = 0; + ewk_view_scroll_size_get(mWebView, &width, &height); + return Dali::Vector2(width, height); +} - void GoForward() - { - ewk_view_forward(mWebView); - } +Dali::Vector2 TizenWebEngineChromium::GetContentSize() const +{ + int width = 0, height = 0; + ewk_view_contents_size_get(mWebView, &width, &height); + return Dali::Vector2(width, height); +} - bool CanGoBack() - { - return ewk_view_back_possible(mWebView); - } +bool TizenWebEngineChromium::CanGoForward() +{ + return ewk_view_forward_possible(mWebView); +} - bool CanGoForward() - { - return ewk_view_forward_possible(mWebView); - } +void TizenWebEngineChromium::GoForward() +{ + ewk_view_forward(mWebView); +} - void EvaluateJavaScript(size_t key, const std::string& script) - { - ewk_view_script_execute(mWebView, script.c_str(), OnEvaluateJavaScript, (void*)key); - } +bool TizenWebEngineChromium::CanGoBack() +{ + return ewk_view_back_possible(mWebView); +} - void AddJavaScriptMessageHandler(const std::string& exposedObjectName) - { - // |jsFunctionName| is fixed as "postMessage" so we don't use this. - ewk_view_javascript_message_handler_add(mWebView, &WebViewContainerForDali::OnJavaScriptMessage, exposedObjectName.c_str()); - } +void TizenWebEngineChromium::GoBack() +{ + ewk_view_back(mWebView); +} - void RegisterJavaScriptAlertCallback() - { - ewk_view_javascript_alert_callback_set(mWebView, &WebViewContainerForDali::OnJavaScriptAlert, 0); - } +void TizenWebEngineChromium::EvaluateJavaScript(const std::string& script, JavaScriptMessageHandlerCallback resultHandler) +{ + bool badAlloc = false; - void JavaScriptAlertReply() + try { - ewk_view_javascript_alert_reply(mWebView); + mJavaScriptEvaluationResultHandlers.emplace(mJavaScriptEvaluationCount, resultHandler); } - - void RegisterJavaScriptConfirmCallback() + catch (std::bad_alloc& e) { - ewk_view_javascript_confirm_callback_set(mWebView, &WebViewContainerForDali::OnJavaScriptConfirm, 0); + badAlloc = true; + DALI_LOG_ERROR("Too many ongoing JavaScript evaluations."); } - void JavaScriptConfirmReply(bool confirmed) + if (!badAlloc) { - ewk_view_javascript_confirm_reply(mWebView, confirmed); + ewk_view_script_execute(mWebView, script.c_str(), &TizenWebEngineChromium::OnEvaluateJavaScript, (void*)mJavaScriptEvaluationCount); + mJavaScriptEvaluationCount++; } +} - void RegisterJavaScriptPromptCallback() +void TizenWebEngineChromium::AddJavaScriptMessageHandler(const std::string& exposedObjectName, JavaScriptMessageHandlerCallback handler) +{ + if (mJavaScriptMessageHandlers.emplace(exposedObjectName, handler).second) { - ewk_view_javascript_prompt_callback_set(mWebView, &WebViewContainerForDali::OnJavaScriptPrompt, 0); + ewk_view_javascript_message_handler_add(mWebView, &TizenWebEngineChromium::OnJavaScriptMessage, exposedObjectName.c_str()); } - - void JavaScriptPromptReply(const std::string& result) + else { - ewk_view_javascript_prompt_reply(mWebView, result.c_str()); + DALI_LOG_ERROR("Callback for (%s) already exists.", exposedObjectName.c_str()); } +} - void ClearHistory() - { - ewk_view_back_forward_list_clear(mWebView); - } +void TizenWebEngineChromium::RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback) +{ + mJavaScriptAlertCallback = callback; + ewk_view_javascript_alert_callback_set(mWebView, &TizenWebEngineChromium::OnJavaScriptAlert, this); +} - void ClearAllTilesResources() - { - ewk_view_clear_all_tiles_resources(mWebView); - } +void TizenWebEngineChromium::JavaScriptAlertReply() +{ + ewk_view_javascript_alert_reply(mWebView); +} - std::string GetUserAgent() - { - const char* agent = ewk_view_user_agent_get(mWebView); - return agent ? std::string(agent) : std::string(); - } +void TizenWebEngineChromium::RegisterJavaScriptConfirmCallback(JavaScriptConfirmCallback callback) +{ + mJavaScriptConfirmCallback = callback; + ewk_view_javascript_confirm_callback_set(mWebView, &TizenWebEngineChromium::OnJavaScriptConfirm, this); +} - void SetUserAgent(const std::string& userAgent) - { - ewk_view_user_agent_set(mWebView, userAgent.c_str()); - } - - Dali::WebEngineSettings& GetSettings() - { - static TizenWebEngineSettings dummy(nullptr); - return mWebEngineSettings ? *mWebEngineSettings : dummy; - } - - Dali::WebEngineBackForwardList& GetBackForwardList() - { - static TizenWebEngineBackForwardList dummy(nullptr); - return mWebEngineBackForwardList ? *mWebEngineBackForwardList : dummy; - } - - std::unique_ptr CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode) - { - // sync... - Evas* evas = ecore_evas_get(WebEngineManager::Get().GetWindow()); - Ewk_Hit_Test* hitTest = ewk_view_hit_test_new(mWebView, x, y, (int)mode); - std::unique_ptr webHitTest(new TizenWebEngineHitTest(hitTest, evas, true)); - return webHitTest; - } - - bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode) - { - // async... - return ewk_view_hit_test_request(mWebView, x, y, (int)mode, - &WebViewContainerForDali::OnHitTestCreated, - &mClient); - } - - void SetSize(uint32_t width, uint32_t height) - { - mWidth = width; - mHeight = height; - evas_object_resize(mWebView, mWidth, mHeight); - } - - void EnableMouseEvents(bool enabled) - { - ewk_view_mouse_events_enabled_set(mWebView, enabled); - } - - void EnableKeyEvents(bool enabled) - { - ewk_view_key_events_enabled_set(mWebView, enabled); - } - - void SetDocumentBackgroundColor(Dali::Vector4 color) - { - ewk_view_bg_color_set(mWebView, color.r * 255, color.g * 255, color.b * 255, color.a * 255); - } - - void ClearTilesWhenHidden(bool cleared) - { - ewk_view_clear_tiles_on_hide_enabled_set(mWebView, cleared); - } - - void SetTileCoverAreaMultiplier(float multiplier) - { - ewk_view_tile_cover_area_multiplier_set(mWebView, multiplier); - } - - void EnableCursorByClient(bool enabled) - { - ewk_view_set_cursor_by_client(mWebView, enabled); - } - - std::string GetSelectedText() const - { - const char* text = ewk_view_text_selection_text_get(mWebView); - return text ? std::string(text) : std::string(); - } - - bool SendTouchEvent(const TouchEvent& touch) - { -#if defined(OS_TIZEN_TV) - return FeedMouseEvent(touch); -#else - return FeedTouchEvent(touch); -#endif - } - - bool SendKeyEvent(const Dali::KeyEvent& keyEvent) - { - void* evasKeyEvent = 0; - if (keyEvent.GetState() == Dali::KeyEvent::DOWN) - { - Evas_Event_Key_Down downEvent; - memset(&downEvent, 0, sizeof(Evas_Event_Key_Down)); - downEvent.key = keyEvent.GetKeyName().c_str(); - downEvent.string = keyEvent.GetKeyString().c_str(); - evasKeyEvent = static_cast(&downEvent); - ewk_view_send_key_event(mWebView, evasKeyEvent, true); - } - else - { - Evas_Event_Key_Up upEvent; - memset(&upEvent, 0, sizeof(Evas_Event_Key_Up)); - upEvent.key = keyEvent.GetKeyName().c_str(); - upEvent.string = keyEvent.GetKeyString().c_str(); - evasKeyEvent = static_cast(&upEvent); - ewk_view_send_key_event(mWebView, evasKeyEvent, false); - } - return false; - } - - bool SendWheelEvent(const WheelEvent& wheel) - { - Eina_Bool direction = wheel.GetDirection() ? false : true; - int step = wheel.GetDelta(); - float x = wheel.GetPoint().x; - float y = wheel.GetPoint().y; - ewk_view_feed_mouse_wheel(mWebView, direction, step, x, y); - return false; - } - - bool SendHoverEvent(const HoverEvent& hover) - { - return false; - } - - void SetFocus(bool focused) - { - ecore_evas_focus_set(WebEngineManager::Get().GetWindow(), focused); - ewk_view_focus_set(mWebView, focused); - } - - bool SetPageZoomFactor(float zoomFactor) - { - return ewk_view_page_zoom_set(mWebView, zoomFactor); - } - - float GetPageZoomFactor() const - { - return ewk_view_page_zoom_get(mWebView); - } - - bool SetTextZoomFactor(float zoomFactor) - { - return ewk_view_text_zoom_set(mWebView, zoomFactor); - } - - float GetTextZoomFactor() const - { - return ewk_view_text_zoom_get(mWebView); - } - - float GetLoadProgressPercentage() const - { - return ewk_view_load_progress_get(mWebView); - } - - bool SetScaleFactor(float scaleFactor, Dali::Vector2 point) - { - return ewk_view_scale_set(mWebView, scaleFactor, point.x, point.y); - } - - float GetScaleFactor() const - { - return ewk_view_scale_get(mWebView); - } - - void ActivateAccessibility(bool activated) - { - ewk_view_atk_deactivation_by_app(mWebView, !activated); - } - - Accessibility::Address GetAccessibilityAddress() - { - static const char plugIdKey[] = "__PlugID"; - static const char rootPath[] = "root"; - - std::string_view plugId; - - if (auto* data = static_cast(evas_object_data_get(mWebView, plugIdKey))) - { - plugId = {data}; - } - - // We expect plugId to be of the form ":1.23:/org/a11y/atspi/accessible/root" - auto pos = plugId.rfind(':'); - if (pos == std::string_view::npos || pos == 0) - { - DALI_LOG_ERROR("Cannot parse PlugID set by Chromium: %s = \"%s\"", plugIdKey, plugId.data()); - return {}; - } - - return {std::string{plugId.substr(0, pos)}, rootPath}; - } - - bool SetVisibility(bool visible) - { - return ewk_view_visibility_set(mWebView, visible); - } - - bool HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount) - { - return ewk_view_text_find(mWebView, text.c_str(), (Ewk_Find_Options)options, maxMatchCount); - } - - void AddDynamicCertificatePath(const std::string& host, const std::string& certPath) - { - ewk_view_add_dynamic_certificate_path(mWebView, host.c_str(), certPath.c_str()); - } - - Dali::PixelData GetScreenshot(Dali::Rect viewArea, float scaleFactor) - { - Eina_Rectangle rect; - EINA_RECTANGLE_SET(&rect, viewArea.x, viewArea.y, viewArea.width, viewArea.height); - Evas *evas = ecore_evas_get(WebEngineManager::Get().GetWindow()); - Evas_Object *snapShotObject = ewk_view_screenshot_contents_get(mWebView, rect, scaleFactor, evas); - if (!snapShotObject) - { - return Dali::PixelData(); - } - return ConvertImageColorSpace(snapShotObject); - } - - bool GetScreenshotAsynchronously(Dali::Rect viewArea, float scaleFactor) - { - Eina_Rectangle rect; - EINA_RECTANGLE_SET(&rect, viewArea.x, viewArea.y, viewArea.width, viewArea.height); - Evas *evas = ecore_evas_get(WebEngineManager::Get().GetWindow()); - return ewk_view_screenshot_contents_get_async(mWebView, rect, scaleFactor, evas, &WebViewContainerForDali::OnScreenshotCaptured, &mClient); - } - - bool CheckVideoPlayingAsynchronously() - { - return ewk_view_is_video_playing(mWebView, &WebViewContainerForDali::OnVideoPlaying, &mClient); - } - - void RegisterGeolocationPermissionCallback() - { - ewk_view_geolocation_permission_callback_set(mWebView, &WebViewContainerForDali::OnGeolocationPermission, &mClient); - } - - void UpdateDisplayArea(Dali::Rect displayArea) - { - evas_object_move(mWebView, displayArea.x, displayArea.y); - SetSize(displayArea.width, displayArea.height); - evas_object_geometry_set(mWebView, displayArea.x, displayArea.y, displayArea.width, displayArea.height); - } - - void EnableVideoHole(bool enabled) - { - Ecore_Wl2_Window* win = AnyCast(Adaptor::Get().GetNativeWindowHandle()); - ewk_view_set_support_video_hole(mWebView, win, enabled, EINA_FALSE); - } - - void GetPlainTextAsynchronously() - { - ewk_view_plain_text_get(mWebView, &WebViewContainerForDali::OnPlainTextReceived, &mClient); - } - -private: - static Dali::PixelData ConvertImageColorSpace(Evas_Object* image) - { - // color-space is argb8888. - uint8_t* pixelBuffer = (uint8_t*)evas_object_image_data_get(image, false); - if (!pixelBuffer) - { - return Dali::PixelData(); - } - - int width = 0, height = 0; - evas_object_image_size_get(image, &width, &height); - - uint32_t bufferSize = width * height * 4; - uint8_t* convertedBuffer = new uint8_t[bufferSize]; - - // convert the color-space to rgba8888. - for (uint32_t i = 0; i < bufferSize; i += 4) - { - convertedBuffer[i] = pixelBuffer[i + 1]; - convertedBuffer[i + 1] = pixelBuffer[i + 2]; - convertedBuffer[i + 2] = pixelBuffer[i + 3]; - convertedBuffer[i + 3] = pixelBuffer[i]; - } - - return Dali::PixelData::New(convertedBuffer, bufferSize, width, height, - Dali::Pixel::Format::RGBA8888, - Dali::PixelData::ReleaseFunction::DELETE_ARRAY); - } - - static void OnFrameRendered(void* data, Evas_Object*, void* buffer) - { - auto client = static_cast(data); - client->UpdateImage(static_cast(buffer)); - } - - static void OnLoadStarted(void* data, Evas_Object*, void*) - { - auto client = static_cast(data); - client->LoadStarted(); - } - - static void OnLoadInProgress(void* data, Evas_Object*, void*) - { - auto client = static_cast(data); - client->LoadInProgress(); - } - - static void OnLoadFinished(void* data, Evas_Object*, void*) - { - auto client = static_cast(data); - client->LoadFinished(); - } - - static void OnLoadError(void* data, Evas_Object*, void* rawError) - { - auto client = static_cast(data); - Ewk_Error* error = static_cast(rawError); - std::unique_ptr loadError(new TizenWebEngineLoadError(error)); - client->LoadError(std::move(loadError)); - } - - static void OnUrlChanged(void* data, Evas_Object*, void* newUrl) - { - auto client = static_cast(data); - std::string url = static_cast(newUrl); - client->UrlChanged(url); - } - - static void OnConsoleMessageReceived(void* data, Evas_Object*, void* eventInfo) - { - auto client = static_cast(data); - Ewk_Console_Message* message = static_cast(eventInfo); - std::unique_ptr webConsoleMessage(new TizenWebEngineConsoleMessage(message)); - client->ConsoleMessageReceived(std::move(webConsoleMessage)); - } - - static void OnPlainTextReceived(Evas_Object* o, const char* plainText, void* data) - { - auto client = static_cast(data); - std::string resultText; - - if (plainText != nullptr) - { - resultText = std::string(plainText); - } - - client->PlainTextRecieved(resultText); - } - - static void OnEdgeLeft(void* data, Evas_Object*, void*) - { - auto client = static_cast(data); - client->ScrollEdgeReached(Dali::WebEnginePlugin::ScrollEdge::LEFT); - } - - static void OnEdgeRight(void* data, Evas_Object*, void*) - { - auto client = static_cast(data); - client->ScrollEdgeReached(Dali::WebEnginePlugin::ScrollEdge::RIGHT); - } - - static void OnEdgeTop(void* data, Evas_Object*, void*) - { - auto client = static_cast(data); - client->ScrollEdgeReached(Dali::WebEnginePlugin::ScrollEdge::TOP); - } - - static void OnEdgeBottom(void* data, Evas_Object*, void*) - { - auto client = static_cast(data); - client->ScrollEdgeReached(Dali::WebEnginePlugin::ScrollEdge::BOTTOM); - } - - static void OnFormRepostDecided(void* data, Evas_Object*, void* eventInfo) - { - auto client = static_cast(data); - Ewk_Form_Repost_Decision_Request* decisionRequest = static_cast(eventInfo); - std::unique_ptr webDecisionRequest(new TizenWebEngineFormRepostDecision(decisionRequest)); - client->RequestFormRepostDecided(std::move(webDecisionRequest)); - } - - static void OnScreenshotCaptured(Evas_Object* image, void* data) - { - auto client = static_cast(data); - Dali::PixelData pixelData = ConvertImageColorSpace(image); - client->ScreenshotCaptured(pixelData); - } - - static void OnVideoPlaying(Evas_Object*, Eina_Bool isPlaying, void* data) - { - auto client = static_cast(data); - client->VideoPlaying(isPlaying); - } - - static Eina_Bool OnGeolocationPermission(Evas_Object*, Ewk_Geolocation_Permission_Request* request, void* data) - { - auto client = static_cast(data); - const Ewk_Security_Origin* securityOrigin = ewk_geolocation_permission_request_origin_get(request); - std::string host = ewk_security_origin_host_get(securityOrigin); - std::string protocol = ewk_security_origin_protocol_get(securityOrigin); - return client->GeolocationPermission(host, protocol); - } - - static void OnResponsePolicyDecided(void* data, Evas_Object*, void* policy) - { - auto client = static_cast(data); - Ewk_Policy_Decision* policyDecision = static_cast(policy); - std::unique_ptr webPolicyDecision(new TizenWebEnginePolicyDecision(policyDecision)); - client->ResponsePolicyDecided(std::move(webPolicyDecision)); - } - - static void OnNavigationPolicyDecided(void* data, Evas_Object*, void* policy) - { - auto client = static_cast(data); - Ewk_Policy_Decision* policyDecision = static_cast(policy); - std::unique_ptr webPolicyDecision(new TizenWebEnginePolicyDecision(policyDecision)); - client->NavigationPolicyDecided(std::move(webPolicyDecision)); - } - - static void OnCertificateConfirmed(void* data, Evas_Object*, void* eventInfo) - { - auto client = static_cast(data); - Ewk_Certificate_Policy_Decision* policyDecision = static_cast(eventInfo); - std::unique_ptr webPolicyDecision(new TizenWebEngineCertificate(policyDecision)); - client->CertificateConfirmed(std::move(webPolicyDecision)); - } - - static void OnSslCertificateChanged(void* data, Evas_Object*, void* eventInfo) - { - auto client = static_cast(data); - Ewk_Certificate_Info* info = static_cast(eventInfo); - std::unique_ptr webCertiInfo(new TizenWebEngineCertificate(info)); - client->SslCertificateChanged(std::move(webCertiInfo)); - } - - static void OnAuthenticationChallenge(Evas_Object*, Ewk_Auth_Challenge* authChallenge, void* data) - { - auto client = static_cast(data); - std::unique_ptr authHandler(new TizenWebEngineHttpAuthHandler(authChallenge)); - client->AuthenticationChallenge(std::move(authHandler)); - } - - static void OnContextMenuShown(void* data, Evas_Object*, void* eventInfo) - { - auto client = static_cast(data); - Ewk_Context_Menu* menu = (Ewk_Context_Menu*)eventInfo; - std::unique_ptr contextMenu(new TizenWebEngineContextMenu(menu)); - client->ContextMenuShown(std::move(contextMenu)); - } - - static void OnContextMenuHidden(void* data, Evas_Object*, void* eventInfo) - { - auto client = static_cast(data); - Ewk_Context_Menu* menu = (Ewk_Context_Menu*)eventInfo; - std::unique_ptr contextMenu(new TizenWebEngineContextMenu(menu)); - client->ContextMenuHidden(std::move(contextMenu)); - } - - static void OnEvaluateJavaScript(Evas_Object* o, const char* result, void* data) - { - auto client = WebEngineManager::Get().FindContainerClient(o); - if (client) - { - client->RunJavaScriptEvaluationResultHandler((size_t)data, result); - } - } - - static void OnJavaScriptMessage(Evas_Object* o, Ewk_Script_Message message) - { - auto client = WebEngineManager::Get().FindContainerClient(o); - if (client) - { - client->RunJavaScriptMessageHandler(message.name, static_cast(message.body)); - } - } - - static Eina_Bool OnJavaScriptAlert(Evas_Object* o, const char* alert_text, void*) - { - bool result = false; - auto client = WebEngineManager::Get().FindContainerClient(o); - if (client) - { - result = client->JavaScriptAlert(const_cast(alert_text)); - } - return result; - } - - static Eina_Bool OnJavaScriptConfirm(Evas_Object* o, const char* message, void*) - { - bool result = false; - auto client = WebEngineManager::Get().FindContainerClient(o); - if (client) - { - result = client->JavaScriptConfirm(const_cast(message)); - } - return result; - } - - static Eina_Bool OnJavaScriptPrompt(Evas_Object* o, const char* message, const char* default_value, void*) - { - bool result = false; - auto client = WebEngineManager::Get().FindContainerClient(o); - if (client) - { - result = client->JavaScriptPrompt(const_cast(message), const_cast(default_value)); - } - return result; - } - - static void OnHitTestCreated(Evas_Object*, int x, int y, int hitTestMode, Ewk_Hit_Test* hitTest, void* data) - { - auto client = static_cast(data); - Evas* evas = ecore_evas_get(WebEngineManager::Get().GetWindow()); - std::unique_ptr webHitTest(new TizenWebEngineHitTest(hitTest, evas, false)); - client->HitTestCreated(std::move(webHitTest)); - } - - bool FeedTouchEvent(const TouchEvent& touch) - { - Ewk_Touch_Event_Type type = EWK_TOUCH_START; - Evas_Touch_Point_State state = EVAS_TOUCH_POINT_DOWN; - switch (touch.GetState(0)) - { - case PointState::DOWN: - { - type = EWK_TOUCH_START; - state = EVAS_TOUCH_POINT_DOWN; - break; - } - case PointState::UP: - { - type = EWK_TOUCH_END; - state = EVAS_TOUCH_POINT_UP; - break; - } - case PointState::MOTION: - { - type = EWK_TOUCH_MOVE; - state = EVAS_TOUCH_POINT_MOVE; - break; - } - case PointState::INTERRUPTED: - { - type = EWK_TOUCH_CANCEL; - state = EVAS_TOUCH_POINT_CANCEL; - break; - } - default: - { - break; - } - } - - Eina_List* pointList = 0; - Ewk_Touch_Point point; - point.id = 0; - point.x = touch.GetScreenPosition(0).x; - point.y = touch.GetScreenPosition(0).y; - point.state = state; - pointList = eina_list_append(pointList, &point); - - ewk_view_feed_touch_event(mWebView, type, pointList, 0); - eina_list_free(pointList); - return false; - } - - bool FeedMouseEvent(const TouchEvent& touch) - { - Ewk_Mouse_Button_Type type = (Ewk_Mouse_Button_Type)0; - switch (touch.GetMouseButton(0)) - { - case MouseButton::PRIMARY: - { - type = EWK_Mouse_Button_Left; - break; - } - case MouseButton::TERTIARY: - { - type = EWK_Mouse_Button_Middle; - break; - } - case MouseButton::SECONDARY: - { - type = EWK_Mouse_Button_Right; - break; - } - default: - { - break; - } - } - - switch (touch.GetState(0)) - { - case PointState::DOWN: - { - float x = touch.GetScreenPosition(0).x; - float y = touch.GetScreenPosition(0).y; - ewk_view_feed_mouse_down(mWebView, type, x, y); - break; - } - case PointState::UP: - { - float x = touch.GetScreenPosition(0).x; - float y = touch.GetScreenPosition(0).y; - ewk_view_feed_mouse_up(mWebView, type, x, y); - break; - } - case PointState::MOTION: - { - float x = touch.GetScreenPosition(0).x; - float y = touch.GetScreenPosition(0).y; - ewk_view_feed_mouse_move(mWebView, x, y); - break; - } - default: - { - break; - } - } - return false; - } +void TizenWebEngineChromium::JavaScriptConfirmReply(bool confirmed) +{ + ewk_view_javascript_confirm_reply(mWebView, confirmed); +} -private: - Evas_Object* mWebView; - WebViewContainerClient& mClient; +void TizenWebEngineChromium::RegisterJavaScriptPromptCallback(JavaScriptPromptCallback callback) +{ + mJavaScriptPromptCallback = callback; + ewk_view_javascript_prompt_callback_set(mWebView, &TizenWebEngineChromium::OnJavaScriptPrompt, this); +} - uint32_t mWidth; - uint32_t mHeight; +void TizenWebEngineChromium::JavaScriptPromptReply(const std::string& result) +{ + ewk_view_javascript_prompt_reply(mWebView, result.c_str()); +} - std::unique_ptr mWebEngineSettings; - std::unique_ptr mWebEngineBackForwardList; -}; +void TizenWebEngineChromium::ClearHistory() +{ + ewk_view_back_forward_list_clear(mWebView); +} -class TBMSurfaceSourceInitializer +void TizenWebEngineChromium::ClearAllTilesResources() { -public: - explicit TBMSurfaceSourceInitializer(NativeImageSourcePtr& imageSrc, uint32_t width, uint32_t height) - { - mSurface = tbm_surface_create(width, height, TBM_FORMAT_ARGB8888); - if (!mSurface) - { - DALI_LOG_ERROR("Failed to create tbm surface."); - } + ewk_view_clear_all_tiles_resources(mWebView); +} - Any tbmSource(mSurface); - imageSrc = NativeImageSource::New(tbmSource); - Any emptySource(0); - imageSrc->SetSource(emptySource); - } +std::string TizenWebEngineChromium::GetUserAgent() const +{ + const char* agent = ewk_view_user_agent_get(mWebView); + return agent ? std::string(agent) : std::string(); +} - ~TBMSurfaceSourceInitializer() - { - if (mSurface) - { - if (tbm_surface_destroy(mSurface) != TBM_SURFACE_ERROR_NONE) - { - DALI_LOG_ERROR("Failed to destroy tbm surface."); - } - } - } +void TizenWebEngineChromium::SetUserAgent(const std::string& userAgent) +{ + ewk_view_user_agent_set(mWebView, userAgent.c_str()); +} -private: - tbm_surface_h mSurface; -}; +Dali::WebEngineSettings& TizenWebEngineChromium::GetSettings() const +{ + static TizenWebEngineSettings dummy(nullptr); + return mWebEngineSettings ? *mWebEngineSettings : dummy; +} -TizenWebEngineChromium::TizenWebEngineChromium() - : mWebViewContainer(0) - , mJavaScriptEvaluationCount(0) +Dali::WebEngineBackForwardList& TizenWebEngineChromium::GetBackForwardList() const { + static TizenWebEngineBackForwardList dummy(nullptr); + return mWebEngineBackForwardList ? *mWebEngineBackForwardList : dummy; } -TizenWebEngineChromium::~TizenWebEngineChromium() +std::unique_ptr TizenWebEngineChromium::CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode) { - Destroy(); + // sync... + Evas* evas = ecore_evas_get(WebEngineManager::Get().GetWindow()); + Ewk_Hit_Test* hitTest = ewk_view_hit_test_new(mWebView, x, y, (int)mode); + std::unique_ptr webHitTest(new TizenWebEngineHitTest(hitTest, evas, true)); + return webHitTest; } -void TizenWebEngineChromium::Create(uint32_t width, uint32_t height, const std::string& locale, const std::string& timezoneID) +bool TizenWebEngineChromium::CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, WebEngineHitTestCreatedCallback callback) { - mWebViewContainer = new WebViewContainerForDali(*this, width, height); - TBMSurfaceSourceInitializer initializer(mDaliImageSrc, width, height); + mHitTestCreatedCallback = callback; + bool result = ewk_view_hit_test_request(mWebView, x, y, (int)mode, &TizenWebEngineChromium::OnHitTestCreated, this); + return result; } -void TizenWebEngineChromium::Create(uint32_t width, uint32_t height, uint32_t argc, char** argv) +void TizenWebEngineChromium::SetSize(uint32_t width, uint32_t height) { - mWebViewContainer = new WebViewContainerForDali(*this, width, height, argc, argv); - TBMSurfaceSourceInitializer initializer(mDaliImageSrc, width, height); + mWidth = width; + mHeight = height; + evas_object_resize(mWebView, mWidth, mHeight); } -void TizenWebEngineChromium::Destroy() +void TizenWebEngineChromium::SetDocumentBackgroundColor(Dali::Vector4 color) { - if (mWebViewContainer) - { - mJavaScriptEvaluationResultHandlers.clear(); - mJavaScriptMessageHandlers.clear(); - - delete mWebViewContainer; - mWebViewContainer = 0; - } + ewk_view_bg_color_set(mWebView, color.r * 255, color.g * 255, color.b * 255, color.a * 255); } -void TizenWebEngineChromium::LoadUrl(const std::string& path) +void TizenWebEngineChromium::ClearTilesWhenHidden(bool cleared) { - if (mWebViewContainer) - { - mWebViewContainer->LoadUrl(path); - } + ewk_view_clear_tiles_on_hide_enabled_set(mWebView, cleared); } -std::string TizenWebEngineChromium::GetTitle() const +void TizenWebEngineChromium::SetTileCoverAreaMultiplier(float multiplier) { - return mWebViewContainer ? mWebViewContainer->GetTitle() : std::string(); + ewk_view_tile_cover_area_multiplier_set(mWebView, multiplier); } -Dali::PixelData TizenWebEngineChromium::GetFavicon() const +void TizenWebEngineChromium::EnableCursorByClient(bool enabled) { - return mWebViewContainer ? mWebViewContainer->GetFavicon() : Dali::PixelData(); + ewk_view_set_cursor_by_client(mWebView, enabled); } -NativeImageSourcePtr TizenWebEngineChromium::GetNativeImageSource() +std::string TizenWebEngineChromium::GetSelectedText() const { - return mDaliImageSrc; + const char* text = ewk_view_text_selection_text_get(mWebView); + return text ? std::string(text) : std::string(); } -std::string TizenWebEngineChromium::GetUrl() const +bool TizenWebEngineChromium::SendTouchEvent(const Dali::TouchEvent& touch) { - return mWebViewContainer ? mWebViewContainer->GetUrl() : std::string(); +#if defined(OS_TIZEN_TV) + return FeedMouseEvent(touch); +#else + return FeedTouchEvent(touch); +#endif } -void TizenWebEngineChromium::LoadHtmlString(const std::string& html) +bool TizenWebEngineChromium::SendKeyEvent(const Dali::KeyEvent& keyEvent) { - if (mWebViewContainer) + void* evasKeyEvent = 0; + if (keyEvent.GetState() == Dali::KeyEvent::DOWN) { - mWebViewContainer->LoadHtml(html); + Evas_Event_Key_Down downEvent; + memset(&downEvent, 0, sizeof(Evas_Event_Key_Down)); + downEvent.key = keyEvent.GetKeyName().c_str(); + downEvent.string = keyEvent.GetKeyString().c_str(); + evasKeyEvent = static_cast(&downEvent); + ewk_view_send_key_event(mWebView, evasKeyEvent, true); } -} - -bool TizenWebEngineChromium::LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, - const std::string& unreachableUrl) -{ - if (mWebViewContainer) + else { - return mWebViewContainer->LoadHtmlStringOverrideCurrentEntry(html, basicUri, unreachableUrl); + Evas_Event_Key_Up upEvent; + memset(&upEvent, 0, sizeof(Evas_Event_Key_Up)); + upEvent.key = keyEvent.GetKeyName().c_str(); + upEvent.string = keyEvent.GetKeyString().c_str(); + evasKeyEvent = static_cast(&upEvent); + ewk_view_send_key_event(mWebView, evasKeyEvent, false); } return false; } -bool TizenWebEngineChromium::LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, - const std::string& encoding, const std::string& baseUri) +bool TizenWebEngineChromium::SendHoverEvent(const Dali::HoverEvent& event) { - if (mWebViewContainer) - { - return mWebViewContainer->LoadContents(contents, contentSize, mimeType, encoding, baseUri); - } return false; } -void TizenWebEngineChromium::Reload() +bool TizenWebEngineChromium::SendWheelEvent(const Dali::WheelEvent& wheel) { - if (mWebViewContainer) - { - mWebViewContainer->Reload(); - } + Eina_Bool direction = wheel.GetDirection() ? false : true; + int step = wheel.GetDelta(); + float x = wheel.GetPoint().x; + float y = wheel.GetPoint().y; + ewk_view_feed_mouse_wheel(mWebView, direction, step, x, y); + return false; } -bool TizenWebEngineChromium::ReloadWithoutCache() +void TizenWebEngineChromium::SetFocus(bool focused) { - if (mWebViewContainer) - { - return mWebViewContainer->ReloadWithoutCache(); - } - return false; + ecore_evas_focus_set(WebEngineManager::Get().GetWindow(), focused); + ewk_view_focus_set(mWebView, focused); } -void TizenWebEngineChromium::StopLoading() +void TizenWebEngineChromium::EnableMouseEvents(bool enabled) { - if (mWebViewContainer) - { - mWebViewContainer->StopLoading(); - } + ewk_view_mouse_events_enabled_set(mWebView, enabled); } -void TizenWebEngineChromium::Suspend() +void TizenWebEngineChromium::EnableKeyEvents(bool enabled) { - if (mWebViewContainer) - { - mWebViewContainer->Suspend(); - } + ewk_view_key_events_enabled_set(mWebView, enabled); } -void TizenWebEngineChromium::Resume() +void TizenWebEngineChromium::SetPageZoomFactor(float zoomFactor) { - if (mWebViewContainer) - { - mWebViewContainer->Resume(); - } + ewk_view_page_zoom_set(mWebView, zoomFactor); } -void TizenWebEngineChromium::SuspendNetworkLoading() +float TizenWebEngineChromium::GetPageZoomFactor() const { - if (mWebViewContainer) - { - mWebViewContainer->SuspendNetworkLoading(); - } + return ewk_view_page_zoom_get(mWebView); } -void TizenWebEngineChromium::ResumeNetworkLoading() +void TizenWebEngineChromium::SetTextZoomFactor(float zoomFactor) { - if (mWebViewContainer) - { - mWebViewContainer->ResumeNetworkLoading(); - } + ewk_view_text_zoom_set(mWebView, zoomFactor); } -bool TizenWebEngineChromium::AddCustomHeader(const std::string& name, const std::string& value) +float TizenWebEngineChromium::GetTextZoomFactor() const { - if (mWebViewContainer) - { - return mWebViewContainer->AddCustomHeader(name, value); - } - return false; + return ewk_view_text_zoom_get(mWebView); } -bool TizenWebEngineChromium::RemoveCustomHeader(const std::string& name) +float TizenWebEngineChromium::GetLoadProgressPercentage() const { - if (mWebViewContainer) - { - return mWebViewContainer->RemoveCustomHeader(name); - } - return false; + return ewk_view_load_progress_get(mWebView); } -uint32_t TizenWebEngineChromium::StartInspectorServer(uint32_t port) +void TizenWebEngineChromium::SetScaleFactor(float scaleFactor, Dali::Vector2 point) { - if (mWebViewContainer) - { - return mWebViewContainer->StartInspectorServer(port); - } - return 0; + ewk_view_scale_set(mWebView, scaleFactor, point.x, point.y); } -bool TizenWebEngineChromium::StopInspectorServer() +float TizenWebEngineChromium::GetScaleFactor() const { - if (mWebViewContainer) - { - return mWebViewContainer->StopInspectorServer(); - } - return false; + return ewk_view_scale_get(mWebView); } -void TizenWebEngineChromium::ScrollBy(int32_t deltaX, int32_t deltaY) +void TizenWebEngineChromium::ActivateAccessibility(bool activated) { - if (mWebViewContainer) - { - mWebViewContainer->ScrollBy(deltaX, deltaY); - } + ewk_view_atk_deactivation_by_app(mWebView, !activated); } -bool TizenWebEngineChromium::ScrollEdgeBy(int32_t deltaX, int32_t deltaY) +Accessibility::Address TizenWebEngineChromium::GetAccessibilityAddress() { - if (mWebViewContainer) + static const char plugIdKey[] = "__PlugID"; + static const char rootPath[] = "root"; + + std::string_view plugId; + + if (auto* data = static_cast(evas_object_data_get(mWebView, plugIdKey))) { - return mWebViewContainer->ScrollEdgeBy(deltaX, deltaY); + plugId = {data}; } - return false; -} -void TizenWebEngineChromium::SetScrollPosition(int32_t x, int32_t y) -{ - if (mWebViewContainer) + // We expect plugId to be of the form ":1.23:/org/a11y/atspi/accessible/root" + auto pos = plugId.rfind(':'); + if (pos == std::string_view::npos || pos == 0) { - mWebViewContainer->SetScrollPosition(x, y); + DALI_LOG_ERROR("Cannot parse PlugID set by Chromium: %s = \"%s\"", plugIdKey, plugId.data()); + return {}; } + + return {std::string{plugId.substr(0, pos)}, rootPath}; } -Dali::Vector2 TizenWebEngineChromium::GetScrollPosition() const +bool TizenWebEngineChromium::SetVisibility(bool visible) { - return mWebViewContainer ? mWebViewContainer->GetScrollPosition() : Dali::Vector2::ZERO; + return ewk_view_visibility_set(mWebView, visible); } -Dali::Vector2 TizenWebEngineChromium::GetScrollSize() const +bool TizenWebEngineChromium::HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount) { - return mWebViewContainer ? mWebViewContainer->GetScrollSize() : Dali::Vector2::ZERO; + return ewk_view_text_find(mWebView, text.c_str(), (Ewk_Find_Options)options, maxMatchCount); } -Dali::Vector2 TizenWebEngineChromium::GetContentSize() const +void TizenWebEngineChromium::AddDynamicCertificatePath(const std::string& host, const std::string& certPath) { - return mWebViewContainer ? mWebViewContainer->GetContentSize() : Dali::Vector2::ZERO; + ewk_view_add_dynamic_certificate_path(mWebView, host.c_str(), certPath.c_str()); } -bool TizenWebEngineChromium::CanGoForward() +Dali::PixelData TizenWebEngineChromium::GetScreenshot(Dali::Rect viewArea, float scaleFactor) { - if (mWebViewContainer) + Eina_Rectangle rect; + EINA_RECTANGLE_SET(&rect, viewArea.x, viewArea.y, viewArea.width, viewArea.height); + Evas *evas = ecore_evas_get(WebEngineManager::Get().GetWindow()); + Evas_Object *snapShotObject = ewk_view_screenshot_contents_get(mWebView, rect, scaleFactor, evas); + if (!snapShotObject) { - return mWebViewContainer->CanGoForward(); + return Dali::PixelData(); } - return false; + return ConvertImageColorSpace(snapShotObject); } -void TizenWebEngineChromium::GoForward() +bool TizenWebEngineChromium::GetScreenshotAsynchronously(Dali::Rect viewArea, float scaleFactor, ScreenshotCapturedCallback callback) { - if (mWebViewContainer) - { - mWebViewContainer->GoForward(); - } + Eina_Rectangle rect; + EINA_RECTANGLE_SET(&rect, viewArea.x, viewArea.y, viewArea.width, viewArea.height); + Evas *evas = ecore_evas_get(WebEngineManager::Get().GetWindow()); + return ewk_view_screenshot_contents_get_async(mWebView, rect, scaleFactor, evas, &TizenWebEngineChromium::OnScreenshotCaptured, this); } -bool TizenWebEngineChromium::CanGoBack() +bool TizenWebEngineChromium::CheckVideoPlayingAsynchronously(VideoPlayingCallback callback) { - if (mWebViewContainer) - { - return mWebViewContainer->CanGoBack(); - } - return false; + return ewk_view_is_video_playing(mWebView, &TizenWebEngineChromium::OnVideoPlaying, this); } -void TizenWebEngineChromium::GoBack() +void TizenWebEngineChromium::GetPlainTextAsynchronously(PlainTextReceivedCallback callback) { - if (mWebViewContainer) - { - mWebViewContainer->GoBack(); - } + mPlainTextReceivedCallback = callback; + ewk_view_plain_text_get(mWebView, &TizenWebEngineChromium::OnPlainTextReceived, this); } -void TizenWebEngineChromium::EvaluateJavaScript(const std::string& script, JavaScriptMessageHandlerCallback resultHandler) +void TizenWebEngineChromium::RegisterGeolocationPermissionCallback(GeolocationPermissionCallback callback) { - if (mWebViewContainer) - { - bool badAlloc = false; - - try - { - mJavaScriptEvaluationResultHandlers.emplace(mJavaScriptEvaluationCount, resultHandler); - } - catch (std::bad_alloc& e) - { - badAlloc = true; - DALI_LOG_ERROR("Too many ongoing JavaScript evaluations."); - } - - if (!badAlloc) - { - mWebViewContainer->EvaluateJavaScript(mJavaScriptEvaluationCount++, script); - } - } + ewk_view_geolocation_permission_callback_set(mWebView, &TizenWebEngineChromium::OnGeolocationPermission, this); } -void TizenWebEngineChromium::AddJavaScriptMessageHandler(const std::string& exposedObjectName, JavaScriptMessageHandlerCallback handler) +void TizenWebEngineChromium::UpdateDisplayArea(Dali::Rect displayArea) { - if (mWebViewContainer) - { - if (mJavaScriptMessageHandlers.emplace(exposedObjectName, handler).second) - { - mWebViewContainer->AddJavaScriptMessageHandler(exposedObjectName); - } - else - { - DALI_LOG_ERROR("Callback for (%s) already exists.", exposedObjectName.c_str()); - } - } + evas_object_move(mWebView, displayArea.x, displayArea.y); + SetSize(displayArea.width, displayArea.height); + evas_object_geometry_set(mWebView, displayArea.x, displayArea.y, displayArea.width, displayArea.height); } -void TizenWebEngineChromium::RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback) +void TizenWebEngineChromium::EnableVideoHole(bool enabled) { - if (!mWebViewContainer) - return; - - mJavaScriptAlertCallback = callback; - mWebViewContainer->RegisterJavaScriptAlertCallback(); + Ecore_Wl2_Window* win = AnyCast(Adaptor::Get().GetNativeWindowHandle()); + ewk_view_set_support_video_hole(mWebView, win, enabled, EINA_FALSE); } -void TizenWebEngineChromium::JavaScriptAlertReply() +Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& TizenWebEngineChromium::FrameRenderedSignal() { - if (mWebViewContainer) - { - mWebViewContainer->JavaScriptAlertReply(); - } + return mFrameRenderedSignal; } -void TizenWebEngineChromium::RegisterJavaScriptConfirmCallback(JavaScriptConfirmCallback callback) +void TizenWebEngineChromium::RegisterPageLoadStartedCallback(WebEnginePageLoadCallback callback) { - if (!mWebViewContainer) - return; - - mJavaScriptConfirmCallback = callback; - mWebViewContainer->RegisterJavaScriptConfirmCallback(); + mLoadStartedCallback = callback; } -void TizenWebEngineChromium::JavaScriptConfirmReply(bool confirmed) +void TizenWebEngineChromium::RegisterPageLoadInProgressCallback(WebEnginePageLoadCallback callback) { - if (mWebViewContainer) - { - mWebViewContainer->JavaScriptConfirmReply(confirmed); - } + mLoadInProgressCallback = callback; } -void TizenWebEngineChromium::RegisterJavaScriptPromptCallback(JavaScriptPromptCallback callback) +void TizenWebEngineChromium::RegisterPageLoadFinishedCallback(WebEnginePageLoadCallback callback) { - if (!mWebViewContainer) - return; - - mJavaScriptPromptCallback = callback; - mWebViewContainer->RegisterJavaScriptPromptCallback(); + mLoadFinishedCallback = callback; } -void TizenWebEngineChromium::JavaScriptPromptReply(const std::string& result) +void TizenWebEngineChromium::RegisterPageLoadErrorCallback(WebEnginePageLoadErrorCallback callback) { - if (mWebViewContainer) - { - mWebViewContainer->JavaScriptPromptReply(result); - } + mLoadErrorCallback = callback; } -void TizenWebEngineChromium::ClearHistory() +void TizenWebEngineChromium::RegisterScrollEdgeReachedCallback(WebEngineScrollEdgeReachedCallback callback) { - if (mWebViewContainer) - { - mWebViewContainer->ClearHistory(); - } + mScrollEdgeReachedCallback = callback; } -void TizenWebEngineChromium::ClearAllTilesResources() +void TizenWebEngineChromium::RegisterUrlChangedCallback(WebEngineUrlChangedCallback callback) { - if (mWebViewContainer) - { - mWebViewContainer->ClearAllTilesResources(); - } + mUrlChangedCallback = callback; } -std::string TizenWebEngineChromium::GetUserAgent() const +void TizenWebEngineChromium::RegisterFormRepostDecidedCallback(WebEngineFormRepostDecidedCallback callback) { - return mWebViewContainer ? mWebViewContainer->GetUserAgent() : std::string(); + mFormRepostDecidedCallback = callback; } -void TizenWebEngineChromium::SetUserAgent(const std::string& userAgent) +void TizenWebEngineChromium::RegisterConsoleMessageReceivedCallback(WebEngineConsoleMessageReceivedCallback callback) { - if (mWebViewContainer) - { - mWebViewContainer->SetUserAgent(userAgent); - } + mConsoleMessageReceivedCallback = callback; } -Dali::WebEngineSettings& TizenWebEngineChromium::GetSettings() const +void TizenWebEngineChromium::RegisterResponsePolicyDecidedCallback(WebEngineResponsePolicyDecidedCallback callback) { - if (mWebViewContainer) - { - return mWebViewContainer->GetSettings(); - } - - DALI_LOG_ERROR("WebViewContainer is null."); - static TizenWebEngineSettings dummy(nullptr); - return dummy; + mResponsePolicyDecidedCallback = callback; } -Dali::WebEngineBackForwardList& TizenWebEngineChromium::GetBackForwardList() const +void TizenWebEngineChromium::RegisterNavigationPolicyDecidedCallback(WebEngineNavigationPolicyDecidedCallback callback) { - if (mWebViewContainer) - { - return mWebViewContainer->GetBackForwardList(); - } - - DALI_LOG_ERROR("WebViewContainer is null."); - static TizenWebEngineBackForwardList dummy(nullptr); - return dummy; + mNavigationPolicyDecidedCallback = callback; } -std::unique_ptr TizenWebEngineChromium::CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode) +void TizenWebEngineChromium::RegisterCertificateConfirmedCallback(WebEngineCertificateCallback callback) { - if (mWebViewContainer) - { - return mWebViewContainer->CreateHitTest(x, y, mode); - } - return nullptr; + mCertificateConfirmedCallback = callback; } -bool TizenWebEngineChromium::CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, WebEngineHitTestCreatedCallback callback) +void TizenWebEngineChromium::RegisterSslCertificateChangedCallback(WebEngineCertificateCallback callback) { - bool result = false; - if (mWebViewContainer) - { - mHitTestCreatedCallback = callback; - result = mWebViewContainer->CreateHitTestAsynchronously(x, y, mode); - } - return result; + mSslCertificateChangedCallback = callback; } -void TizenWebEngineChromium::SetSize(uint32_t width, uint32_t height) +void TizenWebEngineChromium::RegisterHttpAuthHandlerCallback(WebEngineHttpAuthHandlerCallback callback) { - if (mWebViewContainer) - { - mWebViewContainer->SetSize(width, height); - } + mHttpAuthHandlerCallback = callback; } -void TizenWebEngineChromium::SetDocumentBackgroundColor(Dali::Vector4 color) +void TizenWebEngineChromium::RegisterContextMenuShownCallback(WebEngineContextMenuShownCallback callback) { - if(mWebViewContainer) - { - mWebViewContainer->SetDocumentBackgroundColor(color); - } + mContextMenuShownCallback = callback; } -void TizenWebEngineChromium::ClearTilesWhenHidden(bool cleared) +void TizenWebEngineChromium::RegisterContextMenuHiddenCallback(WebEngineContextMenuHiddenCallback callback) { - if(mWebViewContainer) - { - mWebViewContainer->ClearTilesWhenHidden(cleared); - } + mContextMenuHiddenCallback = callback; } -void TizenWebEngineChromium::SetTileCoverAreaMultiplier(float multiplier) +void TizenWebEngineChromium::RunJavaScriptEvaluationResultHandler(size_t key, const char* result) { - if(mWebViewContainer) + auto handler = mJavaScriptEvaluationResultHandlers.find(key); + if (handler == mJavaScriptEvaluationResultHandlers.end()) { - mWebViewContainer->SetTileCoverAreaMultiplier(multiplier); + return; } -} -void TizenWebEngineChromium::EnableCursorByClient(bool enabled) -{ - if(mWebViewContainer) + if (handler->second) { - mWebViewContainer->EnableCursorByClient(enabled); + std::string stored(result); + handler->second(stored); } -} -std::string TizenWebEngineChromium::GetSelectedText() const -{ - return mWebViewContainer? mWebViewContainer->GetSelectedText() : std::string(); + mJavaScriptEvaluationResultHandlers.erase(handler); } -bool TizenWebEngineChromium::SendTouchEvent(const Dali::TouchEvent& touch) +void TizenWebEngineChromium::RunJavaScriptMessageHandler(const std::string& objectName, const std::string& message) { - if(mWebViewContainer) + auto handler = mJavaScriptMessageHandlers.find(objectName); + if (handler == mJavaScriptMessageHandlers.end()) { - return mWebViewContainer->SendTouchEvent(touch); + return; } - return false; + + handler->second(message); } -bool TizenWebEngineChromium::SendKeyEvent(const Dali::KeyEvent& event) +bool TizenWebEngineChromium::JavaScriptAlert(const std::string& alert_text) { - if (mWebViewContainer) - { - return mWebViewContainer->SendKeyEvent(event); - } - return false; + return ExecuteCallbackReturn(mJavaScriptAlertCallback, alert_text); } -void TizenWebEngineChromium::SetFocus(bool focused) +bool TizenWebEngineChromium::JavaScriptConfirm(const std::string& message) { - if (mWebViewContainer) - { - return mWebViewContainer->SetFocus(focused); - } + return ExecuteCallbackReturn(mJavaScriptConfirmCallback, message); } -void TizenWebEngineChromium::EnableMouseEvents(bool enabled) +bool TizenWebEngineChromium::JavaScriptPrompt(const std::string& message, const std::string& default_value) { - if(mWebViewContainer) - { - mWebViewContainer->EnableMouseEvents(enabled); - } + return ExecuteCallbackReturn(mJavaScriptPromptCallback, message, default_value); } -void TizenWebEngineChromium::EnableKeyEvents(bool enabled) +void TizenWebEngineChromium::ScreenshotCaptured(Dali::PixelData pixelData) { - if(mWebViewContainer) - { - mWebViewContainer->EnableKeyEvents(enabled); - } + DALI_LOG_RELEASE_INFO("#ScreenshotCaptured.\n"); + ExecuteCallback(mScreenshotCapturedCallback, pixelData); } -void TizenWebEngineChromium::SetPageZoomFactor(float zoomFactor) +void TizenWebEngineChromium::VideoPlaying(bool isPlaying) { - if (mWebViewContainer) - { - mWebViewContainer->SetPageZoomFactor(zoomFactor); - } + ExecuteCallback(mVideoPlayingCallback, isPlaying); } -float TizenWebEngineChromium::GetPageZoomFactor() const +bool TizenWebEngineChromium::GeolocationPermission(const std::string& host, const std::string& protocol) { - if (mWebViewContainer) - { - return mWebViewContainer->GetPageZoomFactor(); - } - return 0.0f; + return ExecuteCallbackReturn(mGeolocationPermissionCallback, host, protocol); } -void TizenWebEngineChromium::SetTextZoomFactor(float zoomFactor) +bool TizenWebEngineChromium::HitTestCreated(std::unique_ptr hitTest) { - if (mWebViewContainer) - { - mWebViewContainer->SetTextZoomFactor(zoomFactor); - } + return ExecuteCallbackReturn(mHitTestCreatedCallback, std::move(hitTest)); } -float TizenWebEngineChromium::GetTextZoomFactor() const +void TizenWebEngineChromium::PlainTextRecieved(const std::string& plainText) { - if (mWebViewContainer) - { - return mWebViewContainer->GetTextZoomFactor(); - } - return 0.0f; + ExecuteCallback(mPlainTextReceivedCallback, plainText); } -float TizenWebEngineChromium::GetLoadProgressPercentage() const -{ - if (mWebViewContainer) - { - return mWebViewContainer->GetLoadProgressPercentage(); +void TizenWebEngineChromium::InitWebView(uint32_t argc, char** argv) +{ + if (argc > 0) + { + ewk_set_arguments(argc, argv); + } + + Ecore_Wl2_Window* win = AnyCast(Adaptor::Get().GetNativeWindowHandle()); + Ewk_Context* context = ewk_context_default_get(); + ewk_context_max_refresh_rate_set(context, 60); + mWebView = ewk_view_add(ecore_evas_get(WebEngineManager::Get().GetWindow())); + ewk_view_offscreen_rendering_enabled_set(mWebView, true); + ewk_view_ime_window_set(mWebView, win); + + Ewk_Settings* settings = ewk_view_settings_get(mWebView); + mWebEngineSettings.reset(new TizenWebEngineSettings(settings)); + + Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(mWebView); + mWebEngineBackForwardList.reset(new TizenWebEngineBackForwardList(backForwardList)); + + ewk_settings_viewport_meta_tag_set(settings, false); + + evas_object_smart_callback_add(mWebView, "offscreen,frame,rendered", + &TizenWebEngineChromium::OnFrameRendered, + this); + evas_object_smart_callback_add(mWebView, "load,started", + &TizenWebEngineChromium::OnLoadStarted, + this); + evas_object_smart_callback_add(mWebView, "load,progress", + &TizenWebEngineChromium::OnLoadInProgress, + this); + evas_object_smart_callback_add(mWebView, "load,finished", + &TizenWebEngineChromium::OnLoadFinished, + this); + evas_object_smart_callback_add(mWebView, "load,error", + &TizenWebEngineChromium::OnLoadError, + this); + evas_object_smart_callback_add(mWebView, "url,changed", + &TizenWebEngineChromium::OnUrlChanged, + this); + evas_object_smart_callback_add(mWebView, "console,message", + &TizenWebEngineChromium::OnConsoleMessageReceived, + this); + evas_object_smart_callback_add(mWebView, "edge,left", + &TizenWebEngineChromium::OnEdgeLeft, + this); + evas_object_smart_callback_add(mWebView, "edge,right", + &TizenWebEngineChromium::OnEdgeRight, + this); + evas_object_smart_callback_add(mWebView, "edge,top", + &TizenWebEngineChromium::OnEdgeTop, + this); + evas_object_smart_callback_add(mWebView, "edge,bottom", + &TizenWebEngineChromium::OnEdgeBottom, + this); + evas_object_smart_callback_add(mWebView, "form,repost,warning,show", + &TizenWebEngineChromium::OnFormRepostDecided, + this); + evas_object_smart_callback_add(mWebView, "policy,response,decide", + &TizenWebEngineChromium::OnResponsePolicyDecided, + this); + evas_object_smart_callback_add(mWebView, "policy,navigation,decide", + &TizenWebEngineChromium::OnNavigationPolicyDecided, + this); + evas_object_smart_callback_add(mWebView, "request,certificate,confirm", + &TizenWebEngineChromium::OnCertificateConfirmed, + this); + evas_object_smart_callback_add(mWebView, "ssl,certificate,changed", + &TizenWebEngineChromium::OnSslCertificateChanged, + this); + evas_object_smart_callback_add(mWebView, "contextmenu,show", + &TizenWebEngineChromium::OnContextMenuShown, + this); + evas_object_smart_callback_add(mWebView, "contextmenu,hide", + &TizenWebEngineChromium::OnContextMenuHidden, + this); + + ewk_view_authentication_callback_set(mWebView, &TizenWebEngineChromium::OnAuthenticationChallenged, this); + + evas_object_resize(mWebView, mWidth, mHeight); + evas_object_show(mWebView); +} + +bool TizenWebEngineChromium::FeedMouseEvent(const TouchEvent& touch) +{ + Ewk_Mouse_Button_Type type = (Ewk_Mouse_Button_Type)0; + switch (touch.GetMouseButton(0)) + { + case MouseButton::PRIMARY: + { + type = EWK_Mouse_Button_Left; + break; + } + case MouseButton::TERTIARY: + { + type = EWK_Mouse_Button_Middle; + break; + } + case MouseButton::SECONDARY: + { + type = EWK_Mouse_Button_Right; + break; + } + default: + { + break; + } } - return 0.0f; -} -void TizenWebEngineChromium::SetScaleFactor(float scaleFactor, Dali::Vector2 point) -{ - if (mWebViewContainer) + switch (touch.GetState(0)) { - mWebViewContainer->SetScaleFactor(scaleFactor, point); + case PointState::DOWN: + { + float x = touch.GetScreenPosition(0).x; + float y = touch.GetScreenPosition(0).y; + ewk_view_feed_mouse_down(mWebView, type, x, y); + break; + } + case PointState::UP: + { + float x = touch.GetScreenPosition(0).x; + float y = touch.GetScreenPosition(0).y; + ewk_view_feed_mouse_up(mWebView, type, x, y); + break; + } + case PointState::MOTION: + { + float x = touch.GetScreenPosition(0).x; + float y = touch.GetScreenPosition(0).y; + ewk_view_feed_mouse_move(mWebView, x, y); + break; + } + default: + { + break; + } } + return false; } -float TizenWebEngineChromium::GetScaleFactor() const +bool TizenWebEngineChromium::FeedTouchEvent(const TouchEvent& touch) { - if (mWebViewContainer) + Ewk_Touch_Event_Type type = EWK_TOUCH_START; + Evas_Touch_Point_State state = EVAS_TOUCH_POINT_DOWN; + switch (touch.GetState(0)) { - return mWebViewContainer->GetScaleFactor(); + case PointState::DOWN: + { + type = EWK_TOUCH_START; + state = EVAS_TOUCH_POINT_DOWN; + break; + } + case PointState::UP: + { + type = EWK_TOUCH_END; + state = EVAS_TOUCH_POINT_UP; + break; + } + case PointState::MOTION: + { + type = EWK_TOUCH_MOVE; + state = EVAS_TOUCH_POINT_MOVE; + break; + } + case PointState::INTERRUPTED: + { + type = EWK_TOUCH_CANCEL; + state = EVAS_TOUCH_POINT_CANCEL; + break; + } + default: + { + break; + } } - return 0.0f; + + Eina_List* pointList = 0; + Ewk_Touch_Point point; + point.id = 0; + point.x = touch.GetScreenPosition(0).x; + point.y = touch.GetScreenPosition(0).y; + point.state = state; + pointList = eina_list_append(pointList, &point); + + ewk_view_feed_touch_event(mWebView, type, pointList, 0); + eina_list_free(pointList); + return false; } -void TizenWebEngineChromium::ActivateAccessibility(bool activated) +Dali::PixelData TizenWebEngineChromium::ConvertImageColorSpace(Evas_Object* image) { - if (mWebViewContainer) + // color-space is argb8888. + uint8_t* pixelBuffer = (uint8_t*)evas_object_image_data_get(image, false); + if (!pixelBuffer) { - mWebViewContainer->ActivateAccessibility(activated); + return Dali::PixelData(); } -} -Accessibility::Address TizenWebEngineChromium::GetAccessibilityAddress() -{ - if (mWebViewContainer) + int width = 0, height = 0; + evas_object_image_size_get(image, &width, &height); + + uint32_t bufferSize = width * height * 4; + uint8_t* convertedBuffer = new uint8_t[bufferSize]; + + // convert the color-space to rgba8888. + for (uint32_t i = 0; i < bufferSize; i += 4) { - return mWebViewContainer->GetAccessibilityAddress(); + convertedBuffer[i] = pixelBuffer[i + 1]; + convertedBuffer[i + 1] = pixelBuffer[i + 2]; + convertedBuffer[i + 2] = pixelBuffer[i + 3]; + convertedBuffer[i + 3] = pixelBuffer[i]; } - return {}; + + return Dali::PixelData::New(convertedBuffer, bufferSize, width, height, + Dali::Pixel::Format::RGBA8888, + Dali::PixelData::ReleaseFunction::DELETE_ARRAY); } -bool TizenWebEngineChromium::SetVisibility(bool visible) +void TizenWebEngineChromium::OnFrameRendered(void* data, Evas_Object*, void* buffer) { - if (mWebViewContainer) - { - return mWebViewContainer->SetVisibility(visible); - } - return false; + auto pThis = static_cast(data); + pThis->UpdateImage(static_cast(buffer)); } -bool TizenWebEngineChromium::HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount) +void TizenWebEngineChromium::OnLoadStarted(void* data, Evas_Object*, void*) { - if (mWebViewContainer) - { - return mWebViewContainer->HighlightText(text, options, maxMatchCount); - } - return false; + auto pThis = static_cast(data); + pThis->LoadStarted(); } -void TizenWebEngineChromium::AddDynamicCertificatePath(const std::string& host, const std::string& certPath) +void TizenWebEngineChromium::OnLoadInProgress(void* data, Evas_Object*, void*) { - if (mWebViewContainer) - { - mWebViewContainer->AddDynamicCertificatePath(host, certPath); - } + auto pThis = static_cast(data); + pThis->LoadInProgress(); } -Dali::PixelData TizenWebEngineChromium::GetScreenshot(Dali::Rect viewArea, float scaleFactor) +void TizenWebEngineChromium::OnLoadFinished(void* data, Evas_Object*, void*) { - if (mWebViewContainer) - { - return mWebViewContainer->GetScreenshot(viewArea, scaleFactor); - } - return Dali::PixelData(); + auto pThis = static_cast(data); + pThis->LoadFinished(); } -bool TizenWebEngineChromium::GetScreenshotAsynchronously(Dali::Rect viewArea, float scaleFactor, ScreenshotCapturedCallback callback) +void TizenWebEngineChromium::OnLoadError(void* data, Evas_Object*, void* rawError) { - if (mWebViewContainer) - { - mScreenshotCapturedCallback = callback; - return mWebViewContainer->GetScreenshotAsynchronously(viewArea, scaleFactor); - } - return false; + auto pThis = static_cast(data); + Ewk_Error* error = static_cast(rawError); + std::unique_ptr loadError(new TizenWebEngineLoadError(error)); + pThis->LoadError(std::move(loadError)); } -bool TizenWebEngineChromium::CheckVideoPlayingAsynchronously(VideoPlayingCallback callback) +void TizenWebEngineChromium::OnUrlChanged(void* data, Evas_Object*, void* newUrl) { - if (mWebViewContainer) - { - mVideoPlayingCallback = callback; - return mWebViewContainer->CheckVideoPlayingAsynchronously(); - } - return false; + auto pThis = static_cast(data); + std::string url = static_cast(newUrl); + pThis->UrlChanged(url); } -void TizenWebEngineChromium::RegisterGeolocationPermissionCallback(GeolocationPermissionCallback callback) +void TizenWebEngineChromium::OnConsoleMessageReceived(void* data, Evas_Object*, void* eventInfo) { - if (mWebViewContainer) - { - mGeolocationPermissionCallback = callback; - mWebViewContainer->RegisterGeolocationPermissionCallback(); - } + auto pThis = static_cast(data); + Ewk_Console_Message* message = static_cast(eventInfo); + std::unique_ptr webConsoleMessage(new TizenWebEngineConsoleMessage(message)); + pThis->ConsoleMessageReceived(std::move(webConsoleMessage)); } -void TizenWebEngineChromium::UpdateDisplayArea(Dali::Rect displayArea) +void TizenWebEngineChromium::OnEdgeLeft(void* data, Evas_Object*, void*) { - if (mWebViewContainer) - { - mWebViewContainer->UpdateDisplayArea(displayArea); - } + auto pThis = static_cast(data); + pThis->ScrollEdgeReached(Dali::WebEnginePlugin::ScrollEdge::LEFT); } -void TizenWebEngineChromium::EnableVideoHole(bool enabled) +void TizenWebEngineChromium::OnEdgeRight(void* data, Evas_Object*, void*) { - if (mWebViewContainer) - { - return mWebViewContainer->EnableVideoHole(enabled); - } + auto pThis = static_cast(data); + pThis->ScrollEdgeReached(Dali::WebEnginePlugin::ScrollEdge::RIGHT); } -bool TizenWebEngineChromium::SendHoverEvent(const Dali::HoverEvent& event) +void TizenWebEngineChromium::OnEdgeTop(void* data, Evas_Object*, void*) { - if(mWebViewContainer) - { - return mWebViewContainer->SendHoverEvent( event ); - } - return false; + auto pThis = static_cast(data); + pThis->ScrollEdgeReached(Dali::WebEnginePlugin::ScrollEdge::TOP); } -bool TizenWebEngineChromium::SendWheelEvent( const Dali::WheelEvent& event ) +void TizenWebEngineChromium::OnEdgeBottom(void* data, Evas_Object*, void*) { - if(mWebViewContainer) - { - return mWebViewContainer->SendWheelEvent( event ); - } - return false; + auto pThis = static_cast(data); + pThis->ScrollEdgeReached(Dali::WebEnginePlugin::ScrollEdge::BOTTOM); } -Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& TizenWebEngineChromium::FrameRenderedSignal() +void TizenWebEngineChromium::OnFormRepostDecided(void* data, Evas_Object*, void* eventInfo) { - return mFrameRenderedSignal; + auto pThis = static_cast(data); + Ewk_Form_Repost_Decision_Request* decisionRequest = static_cast(eventInfo); + std::unique_ptr webDecisionRequest(new TizenWebEngineFormRepostDecision(decisionRequest)); + pThis->RequestFormRepostDecided(std::move(webDecisionRequest)); } -void TizenWebEngineChromium::RegisterPageLoadStartedCallback(WebEnginePageLoadCallback callback) +void TizenWebEngineChromium::OnResponsePolicyDecided(void* data, Evas_Object*, void* policy) { - mLoadStartedCallback = callback; + auto pThis = static_cast(data); + Ewk_Policy_Decision* policyDecision = static_cast(policy); + std::unique_ptr webPolicyDecision(new TizenWebEnginePolicyDecision(policyDecision)); + pThis->ResponsePolicyDecided(std::move(webPolicyDecision)); } -void TizenWebEngineChromium::RegisterPageLoadInProgressCallback(WebEnginePageLoadCallback callback) +void TizenWebEngineChromium::OnNavigationPolicyDecided(void* data, Evas_Object*, void* policy) { - mLoadInProgressCallback = callback; + auto pThis = static_cast(data); + Ewk_Policy_Decision* policyDecision = static_cast(policy); + std::unique_ptr webPolicyDecision(new TizenWebEnginePolicyDecision(policyDecision)); + pThis->NavigationPolicyDecided(std::move(webPolicyDecision)); } -void TizenWebEngineChromium::RegisterPageLoadFinishedCallback(WebEnginePageLoadCallback callback) +void TizenWebEngineChromium::OnCertificateConfirmed(void* data, Evas_Object*, void* eventInfo) { - mLoadFinishedCallback = callback; + auto pThis = static_cast(data); + Ewk_Certificate_Policy_Decision* policyDecision = static_cast(eventInfo); + std::unique_ptr webPolicyDecision(new TizenWebEngineCertificate(policyDecision)); + pThis->CertificateConfirmed(std::move(webPolicyDecision)); } -void TizenWebEngineChromium::RegisterPageLoadErrorCallback(WebEnginePageLoadErrorCallback callback) +void TizenWebEngineChromium::OnSslCertificateChanged(void* data, Evas_Object*, void* eventInfo) { - mLoadErrorCallback = callback; + auto pThis = static_cast(data); + Ewk_Certificate_Info* info = static_cast(eventInfo); + std::unique_ptr webCertiInfo(new TizenWebEngineCertificate(info)); + pThis->SslCertificateChanged(std::move(webCertiInfo)); } -void TizenWebEngineChromium::RegisterScrollEdgeReachedCallback(WebEngineScrollEdgeReachedCallback callback) +void TizenWebEngineChromium::OnContextMenuShown(void* data, Evas_Object*, void* eventInfo) { - mScrollEdgeReachedCallback = callback; + auto pThis = static_cast(data); + Ewk_Context_Menu* menu = (Ewk_Context_Menu*)eventInfo; + std::unique_ptr contextMenu(new TizenWebEngineContextMenu(menu)); + pThis->ContextMenuShown(std::move(contextMenu)); } -void TizenWebEngineChromium::RegisterUrlChangedCallback(WebEngineUrlChangedCallback callback) +void TizenWebEngineChromium::OnContextMenuHidden(void* data, Evas_Object*, void* eventInfo) { - mUrlChangedCallback = callback; + auto pThis = static_cast(data); + Ewk_Context_Menu* menu = (Ewk_Context_Menu*)eventInfo; + std::unique_ptr contextMenu(new TizenWebEngineContextMenu(menu)); + pThis->ContextMenuHidden(std::move(contextMenu)); } -void TizenWebEngineChromium::RegisterFormRepostDecidedCallback(WebEngineFormRepostDecidedCallback callback) +void TizenWebEngineChromium::OnAuthenticationChallenged(Evas_Object*, Ewk_Auth_Challenge* authChallenge, void* data) { - mFormRepostDecidedCallback = callback; + auto pThis = static_cast(data); + std::unique_ptr authHandler(new TizenWebEngineHttpAuthHandler(authChallenge)); + pThis->AuthenticationChallenged(std::move(authHandler)); } -void TizenWebEngineChromium::RegisterConsoleMessageReceivedCallback(WebEngineConsoleMessageReceivedCallback callback) +void TizenWebEngineChromium::OnEvaluateJavaScript(Evas_Object* o, const char* result, void* data) { - mConsoleMessageReceivedCallback = callback; + auto plugin = WebEngineManager::Get().Find(o); + if (plugin) + { + auto pThis = static_cast(plugin); + pThis->RunJavaScriptEvaluationResultHandler((size_t)data, result); + } } -void TizenWebEngineChromium::RegisterResponsePolicyDecidedCallback(WebEngineResponsePolicyDecidedCallback callback) +void TizenWebEngineChromium::OnJavaScriptMessage(Evas_Object* o, Ewk_Script_Message message) { - mResponsePolicyDecidedCallback = callback; + auto plugin = WebEngineManager::Get().Find(o); + if (plugin) + { + auto pThis = static_cast(plugin); + pThis->RunJavaScriptMessageHandler(message.name, static_cast(message.body)); + } } -void TizenWebEngineChromium::RegisterNavigationPolicyDecidedCallback(WebEngineNavigationPolicyDecidedCallback callback) +Eina_Bool TizenWebEngineChromium::OnJavaScriptAlert(Evas_Object* o, const char* alert_text, void* data) { - mNavigationPolicyDecidedCallback = callback; + bool result = false; + auto pThis = static_cast(data); + if (pThis) + { + result = pThis->JavaScriptAlert(const_cast(alert_text)); + } + return result; } -void TizenWebEngineChromium::RegisterCertificateConfirmedCallback(WebEngineCertificateCallback callback) +Eina_Bool TizenWebEngineChromium::OnJavaScriptConfirm(Evas_Object* o, const char* message, void* data) { - mCertificateConfirmedCallback = callback; + bool result = false; + auto pThis = static_cast(data); + if (pThis) + { + result = pThis->JavaScriptConfirm(const_cast(message)); + } + return result; } -void TizenWebEngineChromium::RegisterSslCertificateChangedCallback(WebEngineCertificateCallback callback) +Eina_Bool TizenWebEngineChromium::OnJavaScriptPrompt(Evas_Object* o, const char* message, const char* default_value, void* data) { - mSslCertificateChangedCallback = callback; + bool result = false; + auto pThis = static_cast(data); + if (pThis) + { + result = pThis->JavaScriptPrompt(const_cast(message), const_cast(default_value)); + } + return result; } -void TizenWebEngineChromium::RegisterHttpAuthHandlerCallback(WebEngineHttpAuthHandlerCallback callback) +void TizenWebEngineChromium::OnHitTestCreated(Evas_Object*, int x, int y, int hitTestMode, Ewk_Hit_Test* hitTest, void* data) { - mHttpAuthHandlerCallback = callback; + auto pThis = static_cast(data); + Evas* evas = ecore_evas_get(WebEngineManager::Get().GetWindow()); + std::unique_ptr webHitTest(new TizenWebEngineHitTest(hitTest, evas, false)); + pThis->HitTestCreated(std::move(webHitTest)); } -void TizenWebEngineChromium::RegisterContextMenuShownCallback(WebEngineContextMenuShownCallback callback) +void TizenWebEngineChromium::OnScreenshotCaptured(Evas_Object* image, void* data) { - mContextMenuShownCallback = callback; + auto pThis = static_cast(data); + Dali::PixelData pixelData = ConvertImageColorSpace(image); + pThis->ScreenshotCaptured(pixelData); } -void TizenWebEngineChromium::RegisterContextMenuHiddenCallback(WebEngineContextMenuHiddenCallback callback) +void TizenWebEngineChromium::OnVideoPlaying(Evas_Object*, Eina_Bool isPlaying, void* data) { - mContextMenuHiddenCallback = callback; + auto pThis = static_cast(data); + pThis->VideoPlaying(isPlaying); } -void TizenWebEngineChromium::GetPlainTextAsynchronously(PlainTextReceivedCallback callback) +void TizenWebEngineChromium::OnPlainTextReceived(Evas_Object* o, const char* plainText, void* data) { - if (mWebViewContainer) + auto pThis = static_cast(data); + std::string resultText; + + if (plainText != nullptr) { - mPlainTextReceivedCallback = callback; - mWebViewContainer->GetPlainTextAsynchronously(); + resultText = std::string(plainText); } + + pThis->PlainTextRecieved(resultText); +} + +Eina_Bool TizenWebEngineChromium::OnGeolocationPermission(Evas_Object*, Ewk_Geolocation_Permission_Request* request, void* data) +{ + auto pThis = static_cast(data); + const Ewk_Security_Origin* securityOrigin = ewk_geolocation_permission_request_origin_get(request); + std::string host = ewk_security_origin_host_get(securityOrigin); + std::string protocol = ewk_security_origin_protocol_get(securityOrigin); + return pThis->GeolocationPermission(host, protocol); } -// WebViewContainerClient Interface void TizenWebEngineChromium::UpdateImage(tbm_surface_h buffer) { if (!buffer) @@ -1991,7 +1276,6 @@ void TizenWebEngineChromium::UpdateImage(tbm_surface_h buffer) Any source(buffer); mDaliImageSrc->SetSource(source); Dali::Stage::GetCurrent().KeepRendering(0.0f); - mFrameRenderedSignal.Emit(); } @@ -2067,9 +1351,9 @@ void TizenWebEngineChromium::SslCertificateChanged(std::unique_ptr handler) +void TizenWebEngineChromium::AuthenticationChallenged(std::unique_ptr handler) { - DALI_LOG_RELEASE_INFO("#AuthenticationChallenge.\n"); + DALI_LOG_RELEASE_INFO("#AuthenticationChallenged.\n"); ExecuteCallback(mHttpAuthHandlerCallback, std::move(handler)); } @@ -2085,88 +1369,9 @@ void TizenWebEngineChromium::ContextMenuHidden(std::unique_ptrsecond) - { - std::string stored(result); - handler->second(stored); - } - - mJavaScriptEvaluationResultHandlers.erase(handler); -} - -void TizenWebEngineChromium::RunJavaScriptMessageHandler(const std::string& objectName, const std::string& message) -{ - auto handler = mJavaScriptMessageHandlers.find(objectName); - if (handler == mJavaScriptMessageHandlers.end()) - { - return; - } - - handler->second(message); -} - -bool TizenWebEngineChromium::JavaScriptAlert(const std::string& alert_text) -{ - return ExecuteCallbackReturn(mJavaScriptAlertCallback, alert_text); -} - -bool TizenWebEngineChromium::JavaScriptConfirm(const std::string& message) -{ - return ExecuteCallbackReturn(mJavaScriptConfirmCallback, message); -} - -bool TizenWebEngineChromium::JavaScriptPrompt(const std::string& message, const std::string& default_value) -{ - return ExecuteCallbackReturn(mJavaScriptPromptCallback, message, default_value); -} - -void TizenWebEngineChromium::ScreenshotCaptured(Dali::PixelData pixelData) -{ - DALI_LOG_RELEASE_INFO("#ScreenshotCaptured.\n"); - ExecuteCallback(mScreenshotCapturedCallback, pixelData); -} - -void TizenWebEngineChromium::VideoPlaying(bool isPlaying) -{ - ExecuteCallback(mVideoPlayingCallback, isPlaying); -} - -bool TizenWebEngineChromium::GeolocationPermission(const std::string& host, const std::string& protocol) -{ - return ExecuteCallbackReturn(mGeolocationPermissionCallback, host, protocol); -} - -bool TizenWebEngineChromium::HitTestCreated(std::unique_ptr hitTest) -{ - return ExecuteCallbackReturn(mHitTestCreatedCallback, std::move(hitTest)); -} - -void TizenWebEngineChromium::PlainTextRecieved(const std::string& plainText) -{ - ExecuteCallback(mPlainTextReceivedCallback, plainText); -} - } // namespace Plugin } // namespace Dali -extern "C" DALI_EXPORT_API Dali::WebEngineContext* GetWebEngineContext() -{ - return Dali::Plugin::WebEngineManager::Get().GetContext(); -} - -extern "C" DALI_EXPORT_API Dali::WebEngineCookieManager* GetWebEngineCookieManager() -{ - return Dali::Plugin::WebEngineManager::Get().GetCookieManager(); -} - extern "C" DALI_EXPORT_API Dali::WebEnginePlugin* CreateWebEnginePlugin() { return new Dali::Plugin::TizenWebEngineChromium(); diff --git a/dali-extension/web-engine-chromium/tizen-web-engine-chromium.h b/dali-extension/web-engine-chromium/tizen-web-engine-chromium.h old mode 100644 new mode 100755 index 5c39102..df5782c --- a/dali-extension/web-engine-chromium/tizen-web-engine-chromium.h +++ b/dali-extension/web-engine-chromium/tizen-web-engine-chromium.h @@ -19,10 +19,14 @@ */ // EXTERNAL INCLUDES +#include + #include #include #include +#include + #include #include #include @@ -35,207 +39,11 @@ class PixelData; namespace Plugin { -class WebViewContainerForDali; /** - * @brief The interface class to represent client of corresponding WebView - * container (WebViewContainerForDali). + * @brief A class implements Dali::WebEnginePlugin for tizen chromium. */ -class WebViewContainerClient -{ -public: - /** - * @brief Callback function to be called by WebViewContainer when surface is - * updated. - * @param [in] buffer The surface - */ - virtual void UpdateImage(tbm_surface_h buffer) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when page loading - * is started. - */ - virtual void LoadStarted() = 0; - - /** - * @brief Callback function to be called by WebViewContainer when page loading - * is in progress. - */ - virtual void LoadInProgress() = 0; - - /** - * @brief Callback function to be called by WebViewContainer when page loading - * is finished. - */ - virtual void LoadFinished() = 0; - - /** - * @brief Callback function to be called by WebViewContainer when an error - * occurs in page loading. - * @param [in] error The error when loading a page. - */ - virtual void LoadError(std::unique_ptr error) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when scroll edge - * is reached. - * @param [in] edge Scroll edge reached. - */ - virtual void ScrollEdgeReached(Dali::WebEnginePlugin::ScrollEdge edge) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when form repost - * policy would be decided. - * @param [in] decision The decision policy to show warning when form repost. - */ - virtual void RequestFormRepostDecided(std::unique_ptr decision) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when url is - * changed. - * @param [in] url New url after url is changed. - */ - virtual void UrlChanged(const std::string& url) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when console - * message is logged out. - * @param [in] message Message need be logged out. - */ - virtual void ConsoleMessageReceived(std::unique_ptr message) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when http response - * policy would be decided. - * @param [in] decision Policy need be decided. - */ - virtual void ResponsePolicyDecided(std::unique_ptr decision) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when navigation - * policy would be decided. - * @param [in] decision Policy need be decided. - */ - virtual void NavigationPolicyDecided(std::unique_ptr decision) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when certificate - * need be confirmed. - * @param [in] confirm Policy confirm request. - */ - virtual void CertificateConfirmed(std::unique_ptr confirm) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when certificate - * is changed. - * @param [in] info Certificate information. - */ - virtual void SslCertificateChanged(std::unique_ptr info) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when - * authentication need be confirmed. - * @param [in] handler Http authentication challenge handler. - */ - virtual void AuthenticationChallenge(std::unique_ptr handler) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when context menu - * would be shown. - * @param [in] menu Menu would be shown. - */ - virtual void ContextMenuShown(std::unique_ptr menu) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when context menu - * would be hidden. - * @param [in] menu Menu would be hidden. - */ - virtual void ContextMenuHidden(std::unique_ptr menu) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when it gets - * JavaScript evalution result. - * @param [in] key An unsigned integer representing the result handler - * @param [in] result Result string from JavaScript runtime - * @see Dali::Plugin::TizenWebEngineChromium::EvaluateJavaScript - */ - virtual void RunJavaScriptEvaluationResultHandler(size_t key, const char* result) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when a message - * handler is called from JavaScript runtime. - * @param [in] objectName Exposed object name of the message handler - * @param [in] message Message from JavaScript runtime - * @see Dali::Plugin::TizenWebEngineChromium::AddJavaScriptMessageHandler - */ - virtual void RunJavaScriptMessageHandler(const std::string& objectName, const std::string& message) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when javascript - * alert is running. - * @param [in] alertText Alert text - * @return true if a pop-up is shown, false otherwise - */ - virtual bool JavaScriptAlert(const std::string& alert_text) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when javascript - * confirm is running. - * @param [in] message Message that need be confirmed - * @return true if a pop-up is shown, false otherwise - */ - virtual bool JavaScriptConfirm(const std::string& message) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when javascript - * prompt is running. - * @param [in] message Message that need be promted - * @param [in] defaultValue Default value that need be promted - * @return true if a pop-up is shown, false otherwise - */ - virtual bool JavaScriptPrompt(const std::string& message, const std::string& default_value) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when screen shot - * is captured. - * @param [in] pixelData Pixel data captured - */ - virtual void ScreenshotCaptured(Dali::PixelData pixelData) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when video is - * playing. - * @param [in] isPlaying Video is playing or not - */ - virtual void VideoPlaying(bool isPlaying) = 0; - - /** - * @brief Callback function to be called by WebViewContainer when requesting - * geolocation permissions with host and protocol provided. - * @param [in] host Host that requests geolocation permission - * @param [in] protocol Protocol that requests geolocation permission - * @return true if a pop-up is shown, false otherwise - */ - virtual bool GeolocationPermission(const std::string& host, const std::string& protocol) = 0; - - /** - * @brief Callback function to be called by WebViewContainer after hit test is created. - */ - virtual bool HitTestCreated(std::unique_ptr hitTest) = 0; - - /** - * @brief Callback function to be called by WebViewContainer as a result of getting plain text. - * @param [in] plainText The obtained plain text. - */ - virtual void PlainTextRecieved(const std::string& plainText) = 0; -}; - -/** - * @brief A class implements WebViewContainerClient and Dali::WebEnginePlugin - * for tizen chromium. - */ -class TizenWebEngineChromium : public Dali::WebEnginePlugin, public WebViewContainerClient +class TizenWebEngineChromium : public Dali::WebEnginePlugin { public: /** @@ -730,147 +538,271 @@ public: */ void GetPlainTextAsynchronously(PlainTextReceivedCallback callback) override; - // WebViewContainerClient Interface +private: + static Dali::PixelData ConvertImageColorSpace(Evas_Object* image); + + static void OnFrameRendered(void* data, Evas_Object*, void* buffer); + + static void OnLoadStarted(void* data, Evas_Object*, void*); + + static void OnLoadInProgress(void* data, Evas_Object*, void*); + + static void OnLoadFinished(void* data, Evas_Object*, void*); + + static void OnLoadError(void* data, Evas_Object*, void* rawError); + + static void OnUrlChanged(void* data, Evas_Object*, void* newUrl); + + static void OnConsoleMessageReceived(void* data, Evas_Object*, void* eventInfo); + + static void OnEdgeLeft(void* data, Evas_Object*, void*); + + static void OnEdgeRight(void* data, Evas_Object*, void*); + + static void OnEdgeTop(void* data, Evas_Object*, void*); + + static void OnEdgeBottom(void* data, Evas_Object*, void*); + + static void OnFormRepostDecided(void* data, Evas_Object*, void* eventInfo); + + static void OnResponsePolicyDecided(void* data, Evas_Object*, void* policy); + + static void OnNavigationPolicyDecided(void* data, Evas_Object*, void* policy); + + static void OnCertificateConfirmed(void* data, Evas_Object*, void* eventInfo); + + static void OnSslCertificateChanged(void* data, Evas_Object*, void* eventInfo); + + static void OnContextMenuShown(void* data, Evas_Object*, void* eventInfo); + + static void OnContextMenuHidden(void* data, Evas_Object*, void* eventInfo); + + static void OnAuthenticationChallenged(Evas_Object*, Ewk_Auth_Challenge* authChallenge, void* data); + + static void OnEvaluateJavaScript(Evas_Object* o, const char* result, void* data); + + static void OnJavaScriptMessage(Evas_Object* o, Ewk_Script_Message message); + + static Eina_Bool OnJavaScriptAlert(Evas_Object* o, const char* alert_text, void*); + + static Eina_Bool OnJavaScriptConfirm(Evas_Object* o, const char* message, void*); + + static Eina_Bool OnJavaScriptPrompt(Evas_Object* o, const char* message, const char* default_value, void*); + + static void OnHitTestCreated(Evas_Object*, int x, int y, int hitTestMode, Ewk_Hit_Test* hitTest, void* data); + + static void OnScreenshotCaptured(Evas_Object* image, void* data); + + static void OnVideoPlaying(Evas_Object*, Eina_Bool isPlaying, void* data); + + static void OnPlainTextReceived(Evas_Object* o, const char* plainText, void* data); + + static Eina_Bool OnGeolocationPermission(Evas_Object*, Ewk_Geolocation_Permission_Request* request, void* data); /** - * @copydoc Dali::Plugin::WebViewContainerClient::UpdateImage() + * @brief Callback function to be called by WebViewContainer when surface is + * updated. + * @param [in] buffer The surface */ - void UpdateImage(tbm_surface_h buffer) override; + void UpdateImage(tbm_surface_h buffer); /** - * @copydoc Dali::Plugin::WebViewContainerClient::LoadStarted() + * @brief Callback function to be called by WebViewContainer when page loading + * is started. */ - void LoadStarted() override; + void LoadStarted(); /** - * @copydoc Dali::Plugin::WebViewContainerClient::LoadInProgress() + * @brief Callback function to be called by WebViewContainer when page loading + * is in progress. */ - void LoadInProgress() override; + void LoadInProgress(); /** - * @copydoc Dali::Plugin::WebViewContainerClient::LoadFinished() + * @brief Callback function to be called by WebViewContainer when page loading + * is finished. */ - void LoadFinished() override; + void LoadFinished(); /** - * @copydoc Dali::Plugin::WebViewContainerClient::LoadError() + * @brief Callback function to be called by WebViewContainer when an error + * occurs in page loading. + * @param [in] error The error when loading a page. */ - void LoadError(std::unique_ptr error) override; + void LoadError(std::unique_ptr error); /** - * @copydoc Dali::Plugin::WebViewContainerClient::ScrollEdgeReached() + * @brief Callback function to be called by WebViewContainer when scroll edge + * is reached. + * @param [in] edge Scroll edge reached. */ - void ScrollEdgeReached(Dali::WebEnginePlugin::ScrollEdge edge) override; + void ScrollEdgeReached(Dali::WebEnginePlugin::ScrollEdge edge); /** - * @copydoc Dali::Plugin::WebViewContainerClient::RequestFormRepostDecided() + * @brief Callback function to be called by WebViewContainer when form repost + * policy would be decided. + * @param [in] decision The decision policy to show warning when form repost. */ - void RequestFormRepostDecided(std::unique_ptr decision) override; + void RequestFormRepostDecided(std::unique_ptr decision); /** - * @copydoc Dali::Plugin::WebViewContainerClient::ResponsePolicyDecided() + * @brief Callback function to be called by WebViewContainer when http response + * policy would be decided. + * @param [in] decision Policy need be decided. */ - void ResponsePolicyDecided(std::unique_ptr policy) override; + void ResponsePolicyDecided(std::unique_ptr policy); /** - * @copydoc Dali::Plugin::WebViewContainerClient::NavigationPolicyDecided() + * @brief Callback function to be called by WebViewContainer when navigation + * policy would be decided. + * @param [in] decision Policy need be decided. */ - void NavigationPolicyDecided(std::unique_ptr policy) override; + void NavigationPolicyDecided(std::unique_ptr policy); /** - * @copydoc Dali::Plugin::WebViewContainerClient::UrlChanged() + * @brief Callback function to be called by WebViewContainer when url is + * changed. + * @param [in] url New url after url is changed. */ - void UrlChanged(const std::string& url) override; + void UrlChanged(const std::string& url); /** - * @copydoc Dali::Plugin::WebViewContainerClient::ConsoleMessageReceived() + * @brief Callback function to be called by WebViewContainer when console + * message is logged out. + * @param [in] message Message need be logged out. */ - void ConsoleMessageReceived(std::unique_ptr message) override; + void ConsoleMessageReceived(std::unique_ptr message); /** - * @copydoc Dali::Plugin::WebViewContainerClient::CertificateConfirmed() + * @brief Callback function to be called by WebViewContainer when certificate + * need be confirmed. + * @param [in] confirm Policy confirm request. */ - void CertificateConfirmed(std::unique_ptr confirm) override; + void CertificateConfirmed(std::unique_ptr confirm); /** - * @copydoc Dali::Plugin::WebViewContainerClient::SslCertificateChanged() + * @brief Callback function to be called by WebViewContainer when certificate + * is changed. + * @param [in] info Certificate information. */ - void SslCertificateChanged(std::unique_ptr info) override; + void SslCertificateChanged(std::unique_ptr info); /** - * @copydoc Dali::Plugin::WebViewContainerClient::AuthenticationChallenge() + * @brief Callback function to be called by WebViewContainer when + * authentication need be confirmed. + * @param [in] handler Http authentication challenge handler. */ - void AuthenticationChallenge(std::unique_ptr handler) override; + void AuthenticationChallenged(std::unique_ptr handler); /** - * @copydoc Dali::Plugin::WebViewContainerClient::ContextMenuShown() + * @brief Callback function to be called by WebViewContainer when context menu + * would be shown. + * @param [in] menu Menu would be shown. */ - void ContextMenuShown(std::unique_ptr menu) override; + void ContextMenuShown(std::unique_ptr menu); /** - * @copydoc Dali::Plugin::WebViewContainerClient::ContextMenuHidden() + * @brief Callback function to be called by WebViewContainer when context menu + * would be hidden. + * @param [in] menu Menu would be hidden. */ - void ContextMenuHidden(std::unique_ptr menu) override; + void ContextMenuHidden(std::unique_ptr menu); /** - * @copydoc - * Dali::Plugin::WebViewContainerClient::RunJavaScriptEvaluationResultHandler() + * @brief Callback function to be called by WebViewContainer when it gets + * JavaScript evalution result. + * @param [in] key An unsigned integer representing the result handler + * @param [in] result Result string from JavaScript runtime + * @see Dali::Plugin::TizenWebEngineChromium::EvaluateJavaScript */ - void RunJavaScriptEvaluationResultHandler(size_t key, const char* result) override; + void RunJavaScriptEvaluationResultHandler(size_t key, const char* result); /** - * @copydoc - * Dali::Plugin::WebViewContainerClient::RunJavaScriptMessageHandler() + * @brief Callback function to be called by WebViewContainer when a message + * handler is called from JavaScript runtime. + * @param [in] objectName Exposed object name of the message handler + * @param [in] message Message from JavaScript runtime + * @see Dali::Plugin::TizenWebEngineChromium::AddJavaScriptMessageHandler */ - void RunJavaScriptMessageHandler(const std::string& objectName, const std::string& message) override; + void RunJavaScriptMessageHandler(const std::string& objectName, const std::string& message); /** - * @copydoc Dali::Plugin::WebViewContainerClient::JavaScriptAlert() + * @brief Callback function to be called by WebViewContainer when javascript + * alert is running. + * @param [in] alertText Alert text + * @return true if a pop-up is shown, false otherwise */ - bool JavaScriptAlert(const std::string& alert_text) override; + bool JavaScriptAlert(const std::string& alert_text); /** - * @copydoc Dali::Plugin::WebViewContainerClient::JavaScriptConfirm() + * @brief Callback function to be called by WebViewContainer when javascript + * confirm is running. + * @param [in] message Message that need be confirmed + * @return true if a pop-up is shown, false otherwise */ - bool JavaScriptConfirm(const std::string& message) override; + bool JavaScriptConfirm(const std::string& message); /** - * @copydoc Dali::Plugin::WebViewContainerClient::JavaScriptPrompt() + * @brief Callback function to be called by WebViewContainer when javascript + * prompt is running. + * @param [in] message Message that need be promted + * @param [in] defaultValue Default value that need be promted + * @return true if a pop-up is shown, false otherwise */ - bool JavaScriptPrompt(const std::string& message, const std::string& default_value) override; + bool JavaScriptPrompt(const std::string& message, const std::string& default_value); /** - * @copydoc Dali::Plugin::WebViewContainerClient::ScreenshotCaptured() + * @brief Callback function to be called by WebViewContainer when screen shot + * is captured. + * @param [in] pixelData Pixel data captured */ - void ScreenshotCaptured(Dali::PixelData pixelData) override; + void ScreenshotCaptured(Dali::PixelData pixelData); /** - * @copydoc Dali::Plugin::WebViewContainerClient::VideoPlaying() + * @brief Callback function to be called by WebViewContainer when video is + * playing. + * @param [in] isPlaying Video is playing or not */ - void VideoPlaying(bool isPlaying) override; + void VideoPlaying(bool isPlaying); /** - * @copydoc Dali::Plugin::WebViewContainerClient::GeolocationPermission() + * @brief Callback function to be called by WebViewContainer when requesting + * geolocation permissions with host and protocol provided. + * @param [in] host Host that requests geolocation permission + * @param [in] protocol Protocol that requests geolocation permission + * @return true if a pop-up is shown, false otherwise */ - bool GeolocationPermission(const std::string& host, const std::string& protocol) override; + bool GeolocationPermission(const std::string& host, const std::string& protocol); /** - * @copydoc Dali::Plugin::WebViewContainerClient::HitTestCreated() + * @brief Callback function to be called by WebViewContainer after hit test is created. */ - bool HitTestCreated(std::unique_ptr hitTest) override; + bool HitTestCreated(std::unique_ptr hitTest); /** - * @copydoc Dali::Plugin::WebViewContainerClient::PlainTextRecieved() + * @brief Callback function to be called by WebViewContainer as a result of getting plain text. + * @param [in] plainText The obtained plain text. */ - void PlainTextRecieved(const std::string& plainText) override; + void PlainTextRecieved(const std::string& plainText); -private: - WebViewContainerForDali* mWebViewContainer; - Dali::NativeImageSourcePtr mDaliImageSrc; - size_t mJavaScriptEvaluationCount; + void InitWebView(uint32_t argc, char** argv); + + bool FeedMouseEvent(const TouchEvent& touch); + + bool FeedTouchEvent(const TouchEvent& touch); + + // ewk web view. + Evas_Object* mWebView; + uint32_t mWidth; + uint32_t mHeight; + std::unique_ptr mWebEngineBackForwardList; + std::unique_ptr mWebEngineSettings; - WebEngineFrameRenderedSignalType mFrameRenderedSignal; + // render. + Dali::NativeImageSourcePtr mDaliImageSrc; + WebEngineFrameRenderedSignalType mFrameRenderedSignal; + // callback. WebEnginePageLoadCallback mLoadStartedCallback; WebEnginePageLoadCallback mLoadInProgressCallback; WebEnginePageLoadCallback mLoadFinishedCallback; @@ -895,6 +827,8 @@ private: GeolocationPermissionCallback mGeolocationPermissionCallback; PlainTextReceivedCallback mPlainTextReceivedCallback; + // javascript. + size_t mJavaScriptEvaluationCount; std::unordered_map mJavaScriptEvaluationResultHandlers; std::unordered_map mJavaScriptMessageHandlers; }; diff --git a/dali-extension/web-engine-chromium/tizen-web-engine-manager.cpp b/dali-extension/web-engine-chromium/tizen-web-engine-manager.cpp new file mode 100755 index 0000000..5d4a9f8 --- /dev/null +++ b/dali-extension/web-engine-chromium/tizen-web-engine-manager.cpp @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "tizen-web-engine-manager.h" + +#include "tizen-web-engine-context.h" +#include "tizen-web-engine-cookie-manager.h" + +#include + +#include +#include + +#include +#include +#include + +namespace Dali +{ +namespace Plugin +{ + +WebEngineManager& WebEngineManager::Get() +{ + static WebEngineManager instance; + return instance; +} + +WebEngineManager::WebEngineManager() + : mSlotDelegate(this) +{ + elm_init(0, 0); + ewk_init(); + mWindow = ecore_evas_new("wayland_egl", 0, 0, 1, 1, 0); + + Ewk_Context* context = ewk_context_default_get(); + mWebEngineContext.reset(new TizenWebEngineContext(context)); + + Ewk_Cookie_Manager* manager = ewk_context_cookie_manager_get(context); + mWebEngineCookieManager.reset(new TizenWebEngineCookieManager(manager)); + Dali::LifecycleController::Get().TerminateSignal().Connect(mSlotDelegate, &WebEngineManager::OnTerminated); +} + +Ecore_Evas* WebEngineManager::GetWindow() +{ + return mWindow; +} + +Dali::WebEngineContext* WebEngineManager::GetContext() +{ + return mWebEngineContext.get(); +} + +Dali::WebEngineCookieManager* WebEngineManager::GetCookieManager() +{ + return mWebEngineCookieManager.get(); +} + +void WebEngineManager::Add(Evas_Object* webView, Dali::WebEnginePlugin* engine) +{ + mWebEngines[webView] = engine; +} + +void WebEngineManager::Remove(Evas_Object* webView) +{ + auto iter = mWebEngines.find(webView); + if (iter != mWebEngines.end()) + { + mWebEngines.erase(iter); + } +} + +Dali::WebEnginePlugin* WebEngineManager::Find(Evas_Object* webView) +{ + auto iter = mWebEngines.find(webView); + if (iter != mWebEngines.end()) + { + return iter->second; + } + else + { + return nullptr; + } +} + +void WebEngineManager::OnTerminated() +{ + for (auto it = mWebEngines.begin(); it != mWebEngines.end(); it++) + { + evas_object_del(it->first); + } + mWebEngines.clear(); + ecore_evas_free(mWindow); + ewk_shutdown(); + elm_shutdown(); + DALI_LOG_RELEASE_INFO("#WebEngineManager is destroyed fully.\n"); +} + +} // namespace Plugin +} // namespace Dali + +extern "C" DALI_EXPORT_API Dali::WebEngineContext* GetWebEngineContext() +{ + return Dali::Plugin::WebEngineManager::Get().GetContext(); +} + +extern "C" DALI_EXPORT_API Dali::WebEngineCookieManager* GetWebEngineCookieManager() +{ + return Dali::Plugin::WebEngineManager::Get().GetCookieManager(); +} diff --git a/dali-extension/web-engine-chromium/tizen-web-engine-manager.h b/dali-extension/web-engine-chromium/tizen-web-engine-manager.h new file mode 100755 index 0000000..97dd009 --- /dev/null +++ b/dali-extension/web-engine-chromium/tizen-web-engine-manager.h @@ -0,0 +1,75 @@ +#ifndef DALI_PLUGIN_TIZEN_WEB_ENGINE_MANAGER_H +#define DALI_PLUGIN_TIZEN_WEB_ENGINE_MANAGER_H + +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include +#include + +#include +#include + +#include +#include + +namespace Dali +{ +namespace Plugin +{ + +/** + * @brief A class for managing multiple web views + */ +class WebEngineManager +{ +public: + static WebEngineManager& Get(); + + WebEngineManager(WebEngineManager const&) = delete; + + void operator=(WebEngineManager const&) = delete; + + Ecore_Evas* GetWindow(); + + Dali::WebEngineContext* GetContext(); + + Dali::WebEngineCookieManager* GetCookieManager(); + + void Add(Evas_Object* webView, Dali::WebEnginePlugin* engine); + + void Remove(Evas_Object* webView); + + Dali::WebEnginePlugin* Find(Evas_Object* o); + +private: + WebEngineManager(); + + void OnTerminated(); + + SlotDelegate mSlotDelegate; + std::unique_ptr mWebEngineContext; + std::unique_ptr mWebEngineCookieManager; + Ecore_Evas* mWindow; + std::map mWebEngines; +}; + +} // namespace Plugin +} // namespace Dali + +#endif // DALI_PLUGIN_TIZEN_WEB_ENGINE_MANAGER_H diff --git a/dali-extension/web-engine-chromium/tizen-web-engine-request-interceptor.cpp b/dali-extension/web-engine-chromium/tizen-web-engine-request-interceptor.cpp index 2ae44b5..9e631b4 100755 --- a/dali-extension/web-engine-chromium/tizen-web-engine-request-interceptor.cpp +++ b/dali-extension/web-engine-chromium/tizen-web-engine-request-interceptor.cpp @@ -16,6 +16,9 @@ */ #include "tizen-web-engine-request-interceptor.h" +#include "tizen-web-engine-manager.h" + +#include namespace Dali { @@ -25,6 +28,8 @@ namespace Plugin TizenWebEngineRequestInterceptor::TizenWebEngineRequestInterceptor(Ewk_Intercept_Request* interceptor) : ewkRequestInterceptor(interceptor) { + ewkWebView = ewk_intercept_request_view_get(ewkRequestInterceptor); + const char* url = ewk_intercept_request_url_get(ewkRequestInterceptor); if (url) { @@ -50,6 +55,11 @@ TizenWebEngineRequestInterceptor::~TizenWebEngineRequestInterceptor() { } +Dali::WebEnginePlugin* TizenWebEngineRequestInterceptor::GetWebEngine() const +{ + return WebEngineManager::Get().Find(ewkWebView); +} + std::string TizenWebEngineRequestInterceptor::GetUrl() const { return requestUrl; diff --git a/dali-extension/web-engine-chromium/tizen-web-engine-request-interceptor.h b/dali-extension/web-engine-chromium/tizen-web-engine-request-interceptor.h old mode 100644 new mode 100755 index 2659bcb..d9ef678 --- a/dali-extension/web-engine-chromium/tizen-web-engine-request-interceptor.h +++ b/dali-extension/web-engine-chromium/tizen-web-engine-request-interceptor.h @@ -21,6 +21,8 @@ // EXTERNAL INCLUDES #include +#include + #include #include #include @@ -52,6 +54,11 @@ public: virtual ~TizenWebEngineRequestInterceptor() final; /** + * @copydoc Dali::WebEngineRequestInterceptor::GetWebEngine() + */ + Dali::WebEnginePlugin* GetWebEngine() const override; + + /** * @copydoc Dali::WebEngineRequestInterceptor::GetUrl() */ std::string GetUrl() const override; @@ -137,6 +144,7 @@ private: private: Ewk_Intercept_Request* ewkRequestInterceptor; + Evas_Object* ewkWebView; std::string requestUrl; std::string requestMethod; Dali::Property::Map requestHeaders; -- 2.7.4