X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fweb-engine%2Fcommon%2Fweb-engine-impl.cpp;h=87e1f6e68c8376939a4f61a97b16635e2b9f5160;hb=39e92ce9125526ae5d32882de44f01b03d27dc5a;hp=dd1a7d116c532490f164303ec54a58ffd38a3d23;hpb=0d4adf79c0991f674775be199b1f6be17f525ce0;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/dali/internal/web-engine/common/web-engine-impl.cpp b/dali/internal/web-engine/common/web-engine-impl.cpp old mode 100755 new mode 100644 index dd1a7d11..87e1f6e --- a/dali/internal/web-engine/common/web-engine-impl.cpp +++ b/dali/internal/web-engine/common/web-engine-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -26,17 +26,16 @@ // INTERNAL INCLUDES #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -53,10 +52,6 @@ constexpr char const* const kPluginFullNamePrefix = "libdali2-web-engine-"; constexpr char const* const kPluginFullNamePostfix = "-plugin.so"; constexpr char const* const kPluginFullNameDefault = "libdali2-web-engine-plugin.so"; -// Note: Dali WebView policy does not allow to use multiple web engines in an application. -// So once pluginName is set to non-empty string, it will not change. -std::string pluginName; - std::string MakePluginName(const char* environmentName) { std::stringstream fullName; @@ -71,103 +66,227 @@ Dali::BaseHandle Create() Dali::TypeRegistration type(typeid(Dali::WebEngine), typeid(Dali::BaseHandle), Create); -} // unnamed namespace - -WebEnginePtr WebEngine::New() +/** + * @brief Control the WebEnginePlugin library lifecycle. + * Hold the plugin library handle in static singletone. + * It will makes library handle alives during all WebEngine resources create & destory. + */ +struct WebEnginePluginObject { - WebEngine* instance = new WebEngine(); +public: + static WebEnginePluginObject& GetInstance() + { + static WebEnginePluginObject gPluginHandle; + return gPluginHandle; + } - if(!instance->Initialize()) + /** + * @brief Converts an handle to a bool. + * + * This is useful for checking whether the WebEnginePluginObject succes to load library. + * @note We don't check mHandle because it is possible that mHandle load is success but + * Create/Destroy API load failed. + */ + explicit operator bool() const { - delete instance; - return nullptr; + return mLoadSucceeded; } - return instance; -} + bool InitializeContextHandle() + { + if(!mHandle) + { + return false; + } -WebEngine::WebEngine() -: mPlugin(NULL), - mHandle(NULL), - mCreateWebEnginePtr(NULL), - mDestroyWebEnginePtr(NULL) -{ -} + if(!mGetWebEngineContextPtr) + { + mGetWebEngineContextPtr = reinterpret_cast(dlsym(mHandle, "GetWebEngineContext")); + if(!mGetWebEngineContextPtr) + { + DALI_LOG_ERROR("Can't load symbol GetWebEngineContext(), error: %s\n", dlerror()); + return false; + } + } -WebEngine::~WebEngine() -{ - if(mHandle != NULL) + return true; + } + + bool InitializeCookieManagerHandle() { - if(mDestroyWebEnginePtr != NULL) + if(!mHandle) { - mPlugin->Destroy(); - mDestroyWebEnginePtr(mPlugin); + return false; } - dlclose(mHandle); + if(!mGetWebEngineCookieManagerPtr) + { + mGetWebEngineCookieManagerPtr = reinterpret_cast(dlsym(mHandle, "GetWebEngineCookieManager")); + if(!mGetWebEngineCookieManagerPtr) + { + DALI_LOG_ERROR("Can't load symbol GetWebEngineCookieManager(), error: %s\n", dlerror()); + return false; + } + } + + return true; } -} -bool WebEngine::InitializePluginHandle() -{ - if(pluginName.length() == 0) +private: + // Private constructor / destructor + WebEnginePluginObject() + : mLoadSucceeded{false}, + mHandle{nullptr}, + mCreateWebEnginePtr{nullptr}, + mDestroyWebEnginePtr{nullptr}, + mGetWebEngineContextPtr{nullptr}, + mGetWebEngineCookieManagerPtr{nullptr} { - // pluginName is not initialized yet. + std::string pluginName; const char* name = EnvironmentVariable::GetEnvironmentVariable(DALI_ENV_WEB_ENGINE_NAME); if(name) { pluginName = MakePluginName(name); - mHandle = dlopen(pluginName.c_str(), RTLD_LAZY); - if(mHandle) - { - return true; - } } - pluginName = std::string(kPluginFullNameDefault); + else + { + pluginName = std::string(kPluginFullNameDefault); + } + + mHandle = dlopen(pluginName.c_str(), RTLD_LAZY); + if(!mHandle) + { + DALI_LOG_ERROR("Can't load %s : %s\n", pluginName.c_str(), dlerror()); + return; + } + + mCreateWebEnginePtr = reinterpret_cast(dlsym(mHandle, "CreateWebEnginePlugin")); + if(mCreateWebEnginePtr == nullptr) + { + DALI_LOG_ERROR("Can't load symbol CreateWebEnginePlugin(), error: %s\n", dlerror()); + return; + } + + mDestroyWebEnginePtr = reinterpret_cast(dlsym(mHandle, "DestroyWebEnginePlugin")); + if(mDestroyWebEnginePtr == nullptr) + { + DALI_LOG_ERROR("Can't load symbol DestroyWebEnginePlugin(), error: %s\n", dlerror()); + return; + } + + mLoadSucceeded = true; } - mHandle = dlopen(pluginName.c_str(), RTLD_LAZY); - if(!mHandle) + ~WebEnginePluginObject() { - DALI_LOG_ERROR("Can't load %s : %s\n", pluginName.c_str(), dlerror()); - return false; + if(mHandle) + { + dlclose(mHandle); + mHandle = nullptr; + mLoadSucceeded = false; + } } - return true; + WebEnginePluginObject(const WebEnginePluginObject&) = delete; + WebEnginePluginObject(WebEnginePluginObject&&) = delete; + WebEnginePluginObject& operator=(const WebEnginePluginObject&) = delete; + WebEnginePluginObject& operator=(WebEnginePluginObject&&) = delete; + +private: + bool mLoadSucceeded; ///< True if library loaded successfully. False otherwise. + +public: + using CreateWebEngineFunction = Dali::WebEnginePlugin* (*)(); + using DestroyWebEngineFunction = void (*)(Dali::WebEnginePlugin* plugin); + + using GetWebEngineContext = Dali::WebEngineContext* (*)(); + using GetWebEngineCookieManager = Dali::WebEngineCookieManager* (*)(); + + void* mHandle; ///< Handle for the loaded library + CreateWebEngineFunction mCreateWebEnginePtr; ///< Function to create plugin instance + DestroyWebEngineFunction mDestroyWebEnginePtr; ///< Function to destroy plugin instance + + GetWebEngineContext mGetWebEngineContextPtr; ///< Function to get WebEngineContext + GetWebEngineCookieManager mGetWebEngineCookieManagerPtr; ///< Function to get WebEngineCookieManager +}; + +} // unnamed namespace + +WebEnginePtr WebEngine::New() +{ + WebEngine* instance = new WebEngine(); + if(!instance->Initialize()) + { + delete instance; + return nullptr; + } + + return instance; } -bool WebEngine::Initialize() +Dali::WebEngineContext* WebEngine::GetContext() { - char* error = NULL; + if(!WebEnginePluginObject::GetInstance().InitializeContextHandle()) + { + return nullptr; + } - if(!InitializePluginHandle()) + if(WebEnginePluginObject::GetInstance().mGetWebEngineContextPtr) { - return false; + return WebEnginePluginObject::GetInstance().mGetWebEngineContextPtr(); } - mCreateWebEnginePtr = reinterpret_cast(dlsym(mHandle, "CreateWebEnginePlugin")); - if(mCreateWebEnginePtr == NULL) + return nullptr; +} + +Dali::WebEngineCookieManager* WebEngine::GetCookieManager() +{ + if(!WebEnginePluginObject::GetInstance().InitializeCookieManagerHandle()) { - DALI_LOG_ERROR("Can't load symbol CreateWebEnginePlugin(), error: %s\n", error); - return false; + return nullptr; } - mDestroyWebEnginePtr = reinterpret_cast(dlsym(mHandle, "DestroyWebEnginePlugin")); + if(WebEnginePluginObject::GetInstance().mGetWebEngineCookieManagerPtr) + { + return WebEnginePluginObject::GetInstance().mGetWebEngineCookieManagerPtr(); + } - if(mDestroyWebEnginePtr == NULL) + return nullptr; +} + +WebEngine::WebEngine() +: mPlugin(nullptr) +{ +} + +WebEngine::~WebEngine() +{ + if(mPlugin != nullptr) { - DALI_LOG_ERROR("Can't load symbol DestroyWebEnginePlugin(), error: %s\n", error); - return false; + mPlugin->Destroy(); + // Check whether plugin load sccess or not. + if(DALI_LIKELY(WebEnginePluginObject::GetInstance())) + { + WebEnginePluginObject::GetInstance().mDestroyWebEnginePtr(mPlugin); + } + mPlugin = nullptr; } +} - mPlugin = mCreateWebEnginePtr(); +bool WebEngine::Initialize() +{ + // Check whether plugin load sccess or not. + if(!WebEnginePluginObject::GetInstance()) + { + return false; + } - if(mPlugin == NULL) + mPlugin = WebEnginePluginObject::GetInstance().mCreateWebEnginePtr(); + if(mPlugin == nullptr) { DALI_LOG_ERROR("Can't create the WebEnginePlugin object\n"); return false; } - return true; } @@ -186,24 +305,19 @@ void WebEngine::Destroy() mPlugin->Destroy(); } -Dali::NativeImageInterfacePtr WebEngine::GetNativeImageSource() +Dali::WebEnginePlugin* WebEngine::GetPlugin() const { - return mPlugin->GetNativeImageSource(); + return mPlugin; } -Dali::WebEngineSettings& WebEngine::GetSettings() const +Dali::NativeImageSourcePtr WebEngine::GetNativeImageSource() { - return mPlugin->GetSettings(); -} - -Dali::WebEngineContext& WebEngine::GetContext() const -{ - return mPlugin->GetContext(); + return mPlugin->GetNativeImageSource(); } -Dali::WebEngineCookieManager& WebEngine::GetCookieManager() const +Dali::WebEngineSettings& WebEngine::GetSettings() const { - return mPlugin->GetCookieManager(); + return mPlugin->GetSettings(); } Dali::WebEngineBackForwardList& WebEngine::GetBackForwardList() const @@ -226,12 +340,12 @@ Dali::PixelData WebEngine::GetFavicon() const return mPlugin->GetFavicon(); } -const std::string& WebEngine::GetUrl() +std::string WebEngine::GetUrl() const { return mPlugin->GetUrl(); } -const std::string& WebEngine::GetUserAgent() const +std::string WebEngine::GetUserAgent() const { return mPlugin->GetUserAgent(); } @@ -251,7 +365,7 @@ bool WebEngine::LoadHtmlStringOverrideCurrentEntry(const std::string& html, cons return mPlugin->LoadHtmlStringOverrideCurrentEntry(html, basicUri, unreachableUrl); } -bool WebEngine::LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri) +bool WebEngine::LoadContents(const int8_t* contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri) { return mPlugin->LoadContents(contents, contentSize, mimeType, encoding, baseUri); } @@ -401,12 +515,12 @@ void WebEngine::GoBack() mPlugin->GoBack(); } -void WebEngine::EvaluateJavaScript(const std::string& script, std::function resultHandler) +void WebEngine::EvaluateJavaScript(const std::string& script, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback resultHandler) { mPlugin->EvaluateJavaScript(script, resultHandler); } -void WebEngine::AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function handler) +void WebEngine::AddJavaScriptMessageHandler(const std::string& exposedObjectName, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback handler) { mPlugin->AddJavaScriptMessageHandler(exposedObjectName, handler); } @@ -516,6 +630,11 @@ void WebEngine::ActivateAccessibility(bool activated) mPlugin->ActivateAccessibility(activated); } +Accessibility::Address WebEngine::GetAccessibilityAddress() +{ + return mPlugin->GetAccessibilityAddress(); +} + bool WebEngine::SetVisibility(bool visible) { return mPlugin->SetVisibility(visible); @@ -571,84 +690,94 @@ bool WebEngine::SendWheelEvent(const Dali::WheelEvent& event) return mPlugin->SendWheelEvent(event); } -Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadStartedSignal() +void WebEngine::RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback) +{ + mPlugin->RegisterFrameRenderedCallback(callback); +} + +void WebEngine::RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback) +{ + mPlugin->RegisterPageLoadStartedCallback(callback); +} + +void WebEngine::RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback) { - return mPlugin->PageLoadStartedSignal(); + mPlugin->RegisterPageLoadInProgressCallback(callback); } -Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadInProgressSignal() +void WebEngine::RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback) { - return mPlugin->PageLoadInProgressSignal(); + mPlugin->RegisterPageLoadFinishedCallback(callback); } -Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadFinishedSignal() +void WebEngine::RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback) { - return mPlugin->PageLoadFinishedSignal(); + mPlugin->RegisterPageLoadErrorCallback(callback); } -Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& WebEngine::PageLoadErrorSignal() +void WebEngine::RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback) { - return mPlugin->PageLoadErrorSignal(); + mPlugin->RegisterScrollEdgeReachedCallback(callback); } -Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& WebEngine::ScrollEdgeReachedSignal() +void WebEngine::RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback) { - return mPlugin->ScrollEdgeReachedSignal(); + mPlugin->RegisterUrlChangedCallback(callback); } -Dali::WebEnginePlugin::WebEngineUrlChangedSignalType& WebEngine::UrlChangedSignal() +void WebEngine::RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback) { - return mPlugin->UrlChangedSignal(); + mPlugin->RegisterFormRepostDecidedCallback(callback); } -Dali::WebEnginePlugin::WebEngineFormRepostDecisionSignalType& WebEngine::FormRepostDecisionSignal() +void WebEngine::RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback) { - return mPlugin->FormRepostDecisionSignal(); + mPlugin->RegisterConsoleMessageReceivedCallback(callback); } -Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& WebEngine::FrameRenderedSignal() +void WebEngine::RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback) { - return mPlugin->FrameRenderedSignal(); + mPlugin->RegisterResponsePolicyDecidedCallback(callback); } -Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& WebEngine::RequestInterceptorSignal() +void WebEngine::RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback) { - return mPlugin->RequestInterceptorSignal(); + mPlugin->RegisterNavigationPolicyDecidedCallback(callback); } -Dali::WebEnginePlugin::WebEngineConsoleMessageSignalType& WebEngine::ConsoleMessageSignal() +void WebEngine::RegisterNewWindowCreatedCallback(Dali::WebEnginePlugin::WebEngineNewWindowCreatedCallback callback) { - return mPlugin->ConsoleMessageSignal(); + mPlugin->RegisterNewWindowCreatedCallback(callback); } -Dali::WebEnginePlugin::WebEngineResponsePolicyDecisionSignalType& WebEngine::ResponsePolicyDecisionSignal() +void WebEngine::RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback) { - return mPlugin->ResponsePolicyDecisionSignal(); + mPlugin->RegisterCertificateConfirmedCallback(callback); } -Dali::WebEnginePlugin::WebEngineCertificateSignalType& WebEngine::CertificateConfirmSignal() +void WebEngine::RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback) { - return mPlugin->CertificateConfirmSignal(); + mPlugin->RegisterSslCertificateChangedCallback(callback); } -Dali::WebEnginePlugin::WebEngineCertificateSignalType& WebEngine::SslCertificateChangedSignal() +void WebEngine::RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback) { - return mPlugin->SslCertificateChangedSignal(); + mPlugin->RegisterHttpAuthHandlerCallback(callback); } -Dali::WebEnginePlugin::WebEngineHttpAuthHandlerSignalType& WebEngine::HttpAuthHandlerSignal() +void WebEngine::RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback) { - return mPlugin->HttpAuthHandlerSignal(); + mPlugin->RegisterContextMenuShownCallback(callback); } -Dali::WebEnginePlugin::WebEngineContextMenuCustomizedSignalType& WebEngine::ContextMenuCustomizedSignal() +void WebEngine::RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback) { - return mPlugin->ContextMenuCustomizedSignal(); + mPlugin->RegisterContextMenuHiddenCallback(callback); } -Dali::WebEnginePlugin::WebEngineContextMenuItemSelectedSignalType& WebEngine::ContextMenuItemSelectedSignal() +void WebEngine::GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback) { - return mPlugin->ContextMenuItemSelectedSignal(); + mPlugin->GetPlainTextAsynchronously(callback); } } // namespace Adaptor