[Tizen] Implement some new ewk apis in web engine plugin.
[platform/core/uifw/dali-extension.git] / dali-extension / web-engine-chromium / tizen-web-engine-chromium.h
1 #ifndef DALI_TIZEN_WEB_ENGINE_CHROMIUM_H
2 #define DALI_TIZEN_WEB_ENGINE_CHROMIUM_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <functional>
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>
26
27 #include <tbm_surface.h>
28 #include <unordered_map>
29
30 namespace Dali
31 {
32
33 class PixelData;
34
35 namespace Plugin
36 {
37
38 class WebViewContainerForDali;
39
40 /**
41  * @brief The interface class to represent client of corresponding WebView container (WebViewContainerForDali).
42  */
43 class WebViewContainerClient
44 {
45
46 public:
47
48   /**
49    * @brief Callback function to be called by WebViewContainer when surface is updated.
50    * @param [in] buffer The surface
51    */
52   virtual void UpdateImage( tbm_surface_h buffer ) = 0;
53
54   /**
55    * @brief Callback function to be called by WebViewContainer when page loading is started.
56    */
57   virtual void LoadStarted() = 0;
58
59   /**
60    * @brief Callback function to be called by WebViewContainer when page loading is finished.
61    */
62   virtual void LoadFinished() = 0;
63
64   /**
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
68    */
69   virtual void LoadError( const char* url, int errorCode ) = 0;
70
71   /**
72    * @brief Callback function to be called by WebViewContainer when scroll edge is reached.
73    * @param [in] e Scroll edge reached.
74    */
75   virtual void ScrollEdgeReached( Dali::WebEnginePlugin::ScrollEdge edge ) = 0;
76
77   /**
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
82    */
83   virtual void RunJavaScriptEvaluationResultHandler( size_t key, const char* result ) = 0;
84
85   /**
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
90    */
91   virtual void RunJavaScriptMessageHandler( const std::string& objectName, const std::string& message ) = 0;
92 };
93
94 /**
95  * @brief A class implements WebViewContainerClient and Dali::WebEnginePlugin for tizen chromium.
96  */
97 class TizenWebEngineChromium : public Dali::WebEnginePlugin, public WebViewContainerClient
98 {
99
100 public:
101
102   typedef std::function< void(const std::string&) > JavaScriptCallback;
103
104   /**
105    * @brief Constructor.
106    */
107   TizenWebEngineChromium();
108
109   /**
110    * @brief Destructor.
111    */
112   ~TizenWebEngineChromium() override;
113
114
115   // WebEnginePlugin Interface
116
117   /**
118    * @copydoc Dali::WebEnginePlugin::Create()
119    */
120   void Create( int width, int height, const std::string& locale, const std::string& timezoneID ) override;
121
122   /**
123    * @copydoc Dali::WebEnginePlugin::Create()
124    */
125   void Create( int width, int height, int argc, char** argv ) override;
126
127   /**
128    * @copydoc Dali::WebEnginePlugin::Destroy()
129    */
130   void Destroy() override;
131
132   /**
133    * @copydoc Dali::WebEnginePlugin::GetSettings()
134    */
135   Dali::WebEngineSettings& GetSettings() const override;
136
137   /**
138    * @copydoc Dali::WebEnginePlugin::GetContext()
139    */
140   Dali::WebEngineContext& GetContext() const override;
141
142   /**
143    * @copydoc Dali::WebEnginePlugin::GetCookieManager()
144    */
145   Dali::WebEngineCookieManager& GetCookieManager() const override;
146
147   /**
148    * @copydoc Dali::WebEnginePlugin::GetBackForwardList()
149    */
150   Dali::WebEngineBackForwardList& GetBackForwardList() const override;
151
152   /**
153    * @copydoc Dali::WebEnginePlugin::LoadUrl()
154    */
155   void LoadUrl( const std::string& url ) override;
156
157   /**
158    * @copydoc Dali::WebEnginePlugin::GetNativeImageSource()
159    */
160   NativeImageInterfacePtr GetNativeImageSource() override;
161
162   /**
163    * @copydoc Dali::WebEnginePlugin::GetTitle()
164    */
165   std::string GetTitle() const override;
166
167   /**
168    * @copydoc Dali::WebEnginePlugin::GetFavicon()
169    */
170   Dali::PixelData GetFavicon() const override;
171
172   /**
173    * @copydoc Dali::WebEnginePlugin::GetUrl()
174    */
175   const std::string& GetUrl() override;
176
177   /**
178    * @copydoc Dali::WebEnginePlugin::LoadHtmlString()
179    */
180   void LoadHtmlString( const std::string& string ) override;
181
182   /**
183    * @copydoc Dali::WebEnginePlugin::Reload()
184    */
185   void Reload() override;
186
187   /**
188    * @copydoc Dali::WebEnginePlugin::StopLoading()
189    */
190   void StopLoading() override;
191
192   /**
193    * @copydoc Dali::WebEnginePlugin::Suspend()
194    */
195   void Suspend() override;
196
197   /**
198    * @copydoc Dali::WebEnginePlugin::Resume()
199    */
200   void Resume() override;
201
202   /**
203    * @copydoc Dali::WebEnginePlugin::ScrollBy()
204    */
205   void ScrollBy( int deltaX, int deltaY ) override;
206
207   /**
208    * @copydoc Dali::WebEnginePlugin::SetScrollPosition()
209    */
210   void SetScrollPosition( int x, int y ) override;
211
212   /**
213    * @copydoc Dali::WebEnginePlugin::GetScrollPosition()
214    */
215   void GetScrollPosition( int& x, int& y ) const override;
216
217   /**
218    * @copydoc Dali::WebEnginePlugin::GetScrollSize()
219    */
220   void GetScrollSize( int& width, int& height ) const override;
221
222   /**
223    * @copydoc Dali::WebEnginePlugin::GetContentSize()
224    */
225   void GetContentSize( int& width, int& height ) const override;
226
227   /**
228    * @copydoc Dali::WebEnginePlugin::CanGoForward()
229    */
230   bool CanGoForward() override;
231
232   /**
233    * @copydoc Dali::WebEnginePlugin::GoForward()
234    */
235   void GoForward() override;
236
237   /**
238    * @copydoc Dali::WebEnginePlugin::CanGoBack()
239    */
240   bool CanGoBack() override;
241
242   /**
243    * @copydoc Dali::WebEnginePlugin::GoBack()
244    */
245   void GoBack() override;
246
247   /**
248    * @copydoc Dali::WebEnginePlugin::EvaluateJavaScript()
249    */
250   void EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler ) override;
251
252   /**
253    * @copydoc Dali::WebEnginePlugin::AddJavaScriptMessageHandler()
254    */
255   void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler ) override;
256
257   /**
258    * @copydoc Dali::WebEnginePlugin::ClearAllTilesResources()
259    */
260   void ClearAllTilesResources() override;
261
262   /**
263    * @copydoc Dali::WebEnginePlugin::ClearHistory()
264    */
265   void ClearHistory() override;
266
267   /**
268    * @copydoc Dali::WebEnginePlugin::GetUserAgent()
269    */
270   const std::string& GetUserAgent() const override;
271
272   /**
273    * @copydoc Dali::WebEnginePlugin::SetUserAgent()
274    */
275   void SetUserAgent( const std::string& userAgent ) override;
276
277   /**
278    * @copydoc Dali::WebEnginePlugin::SetSize()
279    */
280   void SetSize( int width, int height ) override;
281
282   /**
283    * @copydoc Dali::WebEnginePlugin::SendTouchEvent()
284    */
285   bool SendTouchEvent( const Dali::TouchEvent& touch ) override;
286
287   /**
288    * @copydoc Dali::WebEnginePlugin::SendKeyEvent()
289    */
290   bool SendKeyEvent( const Dali::KeyEvent& event ) override;
291
292   /**
293    * @copydoc Dali::WebEnginePlugin::SetFocus()
294    */
295   void SetFocus( bool focused ) override;
296
297   /**
298    * @copydoc Dali::WebEnginePlugin::PageLoadStartedSignal()
299    */
300   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal() override;
301
302   /**
303    * @copydoc Dali::WebEnginePlugin::PageLoadFinishedSignal()
304    */
305   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal() override;
306
307   /**
308    * @copydoc Dali::WebEnginePlugin::PageLoadErrorSignal()
309    */
310   Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() override;
311
312   /**
313    * @copydoc Dali::WebEnginePlugin::ScrollEdgeReachedSignal()
314    */
315   Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal() override;
316
317
318   // WebViewContainerClient Interface
319
320
321   /**
322    * @copydoc Dali::Plugin::WebViewContainerClient::UpdateImage()
323    */
324   void UpdateImage( tbm_surface_h buffer ) override;
325
326   /**
327    * @copydoc Dali::Plugin::WebViewContainerClient::LoadStarted()
328    */
329   void LoadStarted() override;
330
331   /**
332    * @copydoc Dali::Plugin::WebViewContainerClient::LoadFinished()
333    */
334   void LoadFinished() override;
335
336   /**
337    * @copydoc Dali::Plugin::WebViewContainerClient::LoadError()
338    */
339   void LoadError( const char* url, int errorCode ) override;
340
341   /**
342    * @copydoc Dali::Plugin::WebViewContainerClient::ScrollEdgeReached()
343    */
344   void ScrollEdgeReached( Dali::WebEnginePlugin::ScrollEdge edge ) override;
345
346   /**
347    * @copydoc Dali::Plugin::WebViewContainerClient::RunJavaScriptEvaluationResultHandler()
348    */
349   void RunJavaScriptEvaluationResultHandler( size_t key, const char* result ) override;
350
351   /**
352    * @copydoc Dali::Plugin::WebViewContainerClient::RunJavaScriptMessageHandler()
353    */
354   void RunJavaScriptMessageHandler( const std::string& objectName, const std::string& message ) override;
355
356 private:
357
358   WebViewContainerForDali*                                mWebViewContainer;
359   Dali::NativeImageSourcePtr                              mDaliImageSrc;
360   std::string                                             mUrl;
361   size_t                                                  mJavaScriptEvaluationCount;
362
363   Dali::WebEnginePlugin::WebEnginePageLoadSignalType      mLoadStartedSignal;
364   Dali::WebEnginePlugin::WebEnginePageLoadSignalType      mLoadFinishedSignal;
365   Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType mLoadErrorSignal;
366
367   Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType mScrollEdgeReachedSignal;
368
369   std::unordered_map< size_t, JavaScriptCallback >        mJavaScriptEvaluationResultHandlers;
370   std::unordered_map< std::string, JavaScriptCallback >   mJavaScriptMessageHandlers;
371 };
372 } // namespace Plugin
373 } // namespace Dali
374
375 #endif