1 #ifndef DALI_TIZEN_WEB_ENGINE_CHROMIUM_H
2 #define DALI_TIZEN_WEB_ENGINE_CHROMIUM_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali/devel-api/adaptor-framework/web-engine-plugin.h>
25 #include <dali/public-api/images/native-image-interface.h>
27 #include <tbm_surface.h>
28 #include <unordered_map>
38 class WebViewContainerForDali;
41 * @brief The interface class to represent client of corresponding WebView container (WebViewContainerForDali).
43 class WebViewContainerClient
49 * @brief Callback function to be called by WebViewContainer when surface is updated.
50 * @param [in] buffer The surface
52 virtual void UpdateImage( tbm_surface_h buffer ) = 0;
55 * @brief Callback function to be called by WebViewContainer when page loading is started.
57 virtual void LoadStarted() = 0;
60 * @brief Callback function to be called by WebViewContainer when page loading is finished.
62 virtual void LoadFinished() = 0;
65 * @brief Callback function to be called by WebViewContainer when an error occurs in page loading.
66 * @param [in] url Failing URL for this error
67 * @param [in] errorCode The error code
69 virtual void LoadError( const char* url, int errorCode ) = 0;
72 * @brief Callback function to be called by WebViewContainer when scroll edge is reached.
73 * @param [in] e Scroll edge reached.
75 virtual void ScrollEdgeReached( Dali::WebEnginePlugin::ScrollEdge edge ) = 0;
78 * @brief Callback function to be called by WebViewContainer when it gets JavaScript evalution result.
79 * @param [in] key An unsigned integer representing the result handler
80 * @param [in] result Result string from JavaScript runtime
81 * @see Dali::Plugin::TizenWebEngineChromium::EvaluateJavaScript
83 virtual void RunJavaScriptEvaluationResultHandler( size_t key, const char* result ) = 0;
86 * @brief Callback function to be called by WebViewContainer when a message handler is called from JavaScript runtime.
87 * @param [in] objectName Exposed object name of the message handler
88 * @param [in] message Message from JavaScript runtime
89 * @see Dali::Plugin::TizenWebEngineChromium::AddJavaScriptMessageHandler
91 virtual void RunJavaScriptMessageHandler( const std::string& objectName, const std::string& message ) = 0;
95 * @brief A class implements WebViewContainerClient and Dali::WebEnginePlugin for tizen chromium.
97 class TizenWebEngineChromium : public Dali::WebEnginePlugin, public WebViewContainerClient
102 typedef std::function< void(const std::string&) > JavaScriptCallback;
105 * @brief Constructor.
107 TizenWebEngineChromium();
112 ~TizenWebEngineChromium() override;
115 // WebEnginePlugin Interface
118 * @copydoc Dali::WebEnginePlugin::Create()
120 void Create( int width, int height, const std::string& locale, const std::string& timezoneID ) override;
123 * @copydoc Dali::WebEnginePlugin::Create()
125 void Create( int width, int height, int argc, char** argv ) override;
128 * @copydoc Dali::WebEnginePlugin::Destroy()
130 void Destroy() override;
133 * @copydoc Dali::WebEnginePlugin::GetSettings()
135 Dali::WebEngineSettings& GetSettings() const override;
138 * @copydoc Dali::WebEnginePlugin::GetContext()
140 Dali::WebEngineContext& GetContext() const override;
143 * @copydoc Dali::WebEnginePlugin::GetCookieManager()
145 Dali::WebEngineCookieManager& GetCookieManager() const override;
148 * @copydoc Dali::WebEnginePlugin::GetBackForwardList()
150 Dali::WebEngineBackForwardList& GetBackForwardList() const override;
153 * @copydoc Dali::WebEnginePlugin::LoadUrl()
155 void LoadUrl( const std::string& url ) override;
158 * @copydoc Dali::WebEnginePlugin::GetNativeImageSource()
160 NativeImageInterfacePtr GetNativeImageSource() override;
163 * @copydoc Dali::WebEnginePlugin::GetTitle()
165 std::string GetTitle() const override;
168 * @copydoc Dali::WebEnginePlugin::GetFavicon()
170 Dali::PixelData GetFavicon() const override;
173 * @copydoc Dali::WebEnginePlugin::GetUrl()
175 const std::string& GetUrl() override;
178 * @copydoc Dali::WebEnginePlugin::LoadHtmlString()
180 void LoadHtmlString( const std::string& string ) override;
183 * @copydoc Dali::WebEnginePlugin::Reload()
185 void Reload() override;
188 * @copydoc Dali::WebEnginePlugin::StopLoading()
190 void StopLoading() override;
193 * @copydoc Dali::WebEnginePlugin::Suspend()
195 void Suspend() override;
198 * @copydoc Dali::WebEnginePlugin::Resume()
200 void Resume() override;
203 * @copydoc Dali::WebEnginePlugin::ScrollBy()
205 void ScrollBy( int deltaX, int deltaY ) override;
208 * @copydoc Dali::WebEnginePlugin::SetScrollPosition()
210 void SetScrollPosition( int x, int y ) override;
213 * @copydoc Dali::WebEnginePlugin::GetScrollPosition()
215 void GetScrollPosition( int& x, int& y ) const override;
218 * @copydoc Dali::WebEnginePlugin::GetScrollSize()
220 void GetScrollSize( int& width, int& height ) const override;
223 * @copydoc Dali::WebEnginePlugin::GetContentSize()
225 void GetContentSize( int& width, int& height ) const override;
228 * @copydoc Dali::WebEnginePlugin::CanGoForward()
230 bool CanGoForward() override;
233 * @copydoc Dali::WebEnginePlugin::GoForward()
235 void GoForward() override;
238 * @copydoc Dali::WebEnginePlugin::CanGoBack()
240 bool CanGoBack() override;
243 * @copydoc Dali::WebEnginePlugin::GoBack()
245 void GoBack() override;
248 * @copydoc Dali::WebEnginePlugin::EvaluateJavaScript()
250 void EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler ) override;
253 * @copydoc Dali::WebEnginePlugin::AddJavaScriptMessageHandler()
255 void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler ) override;
258 * @copydoc Dali::WebEnginePlugin::ClearAllTilesResources()
260 void ClearAllTilesResources() override;
263 * @copydoc Dali::WebEnginePlugin::ClearHistory()
265 void ClearHistory() override;
268 * @copydoc Dali::WebEnginePlugin::GetUserAgent()
270 const std::string& GetUserAgent() const override;
273 * @copydoc Dali::WebEnginePlugin::SetUserAgent()
275 void SetUserAgent( const std::string& userAgent ) override;
278 * @copydoc Dali::WebEnginePlugin::SetSize()
280 void SetSize( int width, int height ) override;
283 * @copydoc Dali::WebEnginePlugin::SendTouchEvent()
285 bool SendTouchEvent( const Dali::TouchEvent& touch ) override;
288 * @copydoc Dali::WebEnginePlugin::SendKeyEvent()
290 bool SendKeyEvent( const Dali::KeyEvent& event ) override;
293 * @copydoc Dali::WebEnginePlugin::SetFocus()
295 void SetFocus( bool focused ) override;
298 * @copydoc Dali::WebEnginePlugin::PageLoadStartedSignal()
300 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal() override;
303 * @copydoc Dali::WebEnginePlugin::PageLoadFinishedSignal()
305 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal() override;
308 * @copydoc Dali::WebEnginePlugin::PageLoadErrorSignal()
310 Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() override;
313 * @copydoc Dali::WebEnginePlugin::ScrollEdgeReachedSignal()
315 Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal() override;
318 // WebViewContainerClient Interface
322 * @copydoc Dali::Plugin::WebViewContainerClient::UpdateImage()
324 void UpdateImage( tbm_surface_h buffer ) override;
327 * @copydoc Dali::Plugin::WebViewContainerClient::LoadStarted()
329 void LoadStarted() override;
332 * @copydoc Dali::Plugin::WebViewContainerClient::LoadFinished()
334 void LoadFinished() override;
337 * @copydoc Dali::Plugin::WebViewContainerClient::LoadError()
339 void LoadError( const char* url, int errorCode ) override;
342 * @copydoc Dali::Plugin::WebViewContainerClient::ScrollEdgeReached()
344 void ScrollEdgeReached( Dali::WebEnginePlugin::ScrollEdge edge ) override;
347 * @copydoc Dali::Plugin::WebViewContainerClient::RunJavaScriptEvaluationResultHandler()
349 void RunJavaScriptEvaluationResultHandler( size_t key, const char* result ) override;
352 * @copydoc Dali::Plugin::WebViewContainerClient::RunJavaScriptMessageHandler()
354 void RunJavaScriptMessageHandler( const std::string& objectName, const std::string& message ) override;
358 WebViewContainerForDali* mWebViewContainer;
359 Dali::NativeImageSourcePtr mDaliImageSrc;
361 size_t mJavaScriptEvaluationCount;
363 Dali::WebEnginePlugin::WebEnginePageLoadSignalType mLoadStartedSignal;
364 Dali::WebEnginePlugin::WebEnginePageLoadSignalType mLoadFinishedSignal;
365 Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType mLoadErrorSignal;
367 Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType mScrollEdgeReachedSignal;
369 std::unordered_map< size_t, JavaScriptCallback > mJavaScriptEvaluationResultHandlers;
370 std::unordered_map< std::string, JavaScriptCallback > mJavaScriptMessageHandlers;
372 } // namespace Plugin