[Tizen] Implement some new ewk apis in web engine plugin.
[platform/core/uifw/dali-extension.git] / dali-extension / web-engine-lwe / tizen-web-engine-lwe.h
1 #ifndef DALI_TIZEN_WEB_ENGINE_LWE_H
2 #define DALI_TIZEN_WEB_ENGINE_LWE_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 <string.h>
23 #include <vector>
24 #include <dali/devel-api/adaptor-framework/event-thread-callback.h>
25 #include <dali/devel-api/threading/mutex.h>
26 #include <dali/public-api/adaptor-framework/native-image-source.h>
27 #include <dali/public-api/adaptor-framework/timer.h>
28 #include <dali/devel-api/adaptor-framework/web-engine-plugin.h>
29 #include <LWEWebView.h>
30 #include <list>
31
32 #ifndef DALI_USE_TBMSURFACE
33 #define DALI_USE_TBMSURFACE
34 #endif
35
36 #ifdef DALI_USE_TBMSURFACE
37 #include <tbm_surface.h>
38 #else
39 #include <dali/public-api/images/buffer-image.h>
40 #endif
41
42 namespace Dali
43 {
44
45 class PixelData;
46
47 namespace Plugin
48 {
49
50 /**
51  * @brief Implementation of the Tizen WebEngineLWE class which has Tizen platform dependency.
52  */
53 class TizenWebEngineLWE : public Dali::WebEnginePlugin, public Dali::ConnectionTracker
54 {
55 public:
56
57   /**
58    * @brief Constructor.
59    */
60   TizenWebEngineLWE();
61
62   /**
63    * @brief Destructor.
64    */
65   virtual ~TizenWebEngineLWE();
66
67   /**
68    * @copydoc Dali::WebEnginePlugin::Create()
69    */
70   void Create( int width, int height, const std::string& locale, const std::string& timezoneId ) override;
71
72   /**
73    * @copydoc Dali::WebEnginePlugin::GetSettings()
74    */
75   Dali::WebEngineSettings& GetSettings() const override;
76
77   /**
78    * @copydoc Dali::WebEnginePlugin::GetContext()
79    */
80   Dali::WebEngineContext& GetContext() const override;
81
82   /**
83    * @copydoc Dali::WebEnginePlugin::GetCookieManager()
84    */
85   Dali::WebEngineCookieManager& GetCookieManager() const override;
86
87   /**
88    * @copydoc Dali::WebEnginePlugin::GetBackForwardList()
89    */
90   Dali::WebEngineBackForwardList& GetBackForwardList() const override;
91
92   /**
93    * @copydoc Dali::WebEnginePlugin::Create()
94    */
95   void Create( int width, int height, int argc, char** argv ) override;
96
97   /**
98    * @copydoc Dali::WebEnginePlugin::Destroy()
99    */
100   void Destroy() override;
101
102   /**
103    * @copydoc Dali::WebEnginePlugin::GetNativeImageSource()
104    */
105   Dali::NativeImageInterfacePtr GetNativeImageSource() override;
106
107   /**
108    * @copydoc Dali::WebEnginePlugin::LoadUrl()
109    */
110   void LoadUrl( const std::string& url ) override;
111
112   /**
113    * @copydoc Dali::WebEnginePlugin::GetTitle()
114    */
115   std::string GetTitle() const override;
116
117   /**
118    * @copydoc Dali::WebEnginePlugin::GetFavicon()
119    */
120   Dali::PixelData GetFavicon() const override;
121
122   /**
123    * @copydoc Dali::WebEnginePlugin::GetUrl()
124    */
125   const std::string& GetUrl() override;
126
127   /**
128    * @copydoc Dali::WebEnginePlugin::LoadHTMLString()
129    */
130   void LoadHtmlString( const std::string& string ) override;
131
132   /**
133    * @copydoc Dali::WebEnginePlugin::Reload()
134    */
135   void Reload() override;
136
137   /**
138    * @copydoc Dali::WebEnginePlugin::StopLoading()
139    */
140   void StopLoading() override;
141
142   /**
143    * @copydoc Dali::WebEnginePlugin::Suspend()
144    */
145   void Suspend() override;
146
147   /**
148    * @copydoc Dali::WebEnginePlugin::Resume()
149    */
150   void Resume() override;
151
152   /**
153    * @copydoc Dali::WebEnginePlugin::ScrollBy()
154    */
155   void ScrollBy( int deltaX, int deltaY ) override;
156
157   /**
158    * @copydoc Dali::WebEnginePlugin::SetScrollPosition()
159    */
160   void SetScrollPosition( int x, int y ) override;
161
162   /**
163    * @copydoc Dali::WebEnginePlugin::GetScrollPosition()
164    */
165   void GetScrollPosition( int& x, int& y ) const override;
166
167   /**
168    * @copydoc Dali::WebEnginePlugin::GetScrollSize()
169    */
170   void GetScrollSize( int& width, int& height ) const override;
171
172   /**
173    * @copydoc Dali::WebEnginePlugin::GetContentSize()
174    */
175   void GetContentSize( int& width, int& height ) const override;
176
177   /**
178    * @copydoc Dali::WebEnginePlugin::GoBack()
179    */
180   void GoBack() override;
181
182   /**
183    * @copydoc Dali::WebEnginePlugin::GoForward()
184    */
185   void GoForward() override;
186
187   /**
188    * @copydoc Dali::WebEnginePlugin::CanGoBack()
189    */
190   bool CanGoBack() override;
191
192   /**
193    * @copydoc Dali::WebEnginePlugin::CanGoForward()
194    */
195   bool CanGoForward() override;
196
197   /**
198    * @copydoc Dali::WebEnginePlugin::EvaluateJavaScript()
199    */
200   void EvaluateJavaScript( const std::string& script, std::function< void(const std::string&) > resultHandler ) override;
201
202   /**
203    * @copydoc Dali::WebEnginePlugin::AddJavaScriptMessageHandler()
204    */
205   void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void(const std::string&) > handler ) override;
206
207   /**
208    * @copydoc Dali::WebEnginePlugin::ClearAllTilesResources()
209    */
210   void ClearAllTilesResources() override;
211
212   /**
213    * @copydoc Dali::WebEnginePlugin::ClearHistory()
214    */
215   void ClearHistory() override;
216
217   /**
218    * @copydoc Dali::WebEnginePlugin::GetUserAgent()
219    */
220   const std::string& GetUserAgent() const override;
221
222   /**
223    * @copydoc Dali::WebEnginePlugin::SetUserAgent()
224    */
225   void SetUserAgent( const std::string& userAgent ) override;
226
227   /**
228    * @copydoc Dali::WebEnginePlugin::SetSize()
229    */
230   void SetSize( int width, int height ) override;
231
232   /**
233    * @copydoc Dali::WebEnginePlugin::SendTouchEvent()
234    */
235   bool SendTouchEvent( const Dali::TouchEvent& touch ) override;
236
237   /**
238    * @copydoc Dali::WebEnginePlugin::SendKeyEvent()
239    */
240   bool SendKeyEvent( const Dali::KeyEvent& event ) override;
241
242   /**
243    * @copydoc Dali::WebEnginePlugin::SetFocus()
244    */
245   void SetFocus( bool focused ) override;
246
247   /**
248    * @copydoc Dali::WebEnginePlugin::PageLoadStartedSignal()
249    */
250   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal() override
251   {
252     return mPageLoadStartedSignal;
253   }
254
255   /**
256    * @copydoc Dali::WebEnginePlugin::PageLoadFinishedSignal()
257    */
258   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal() override
259   {
260     return mPageLoadFinishedSignal;
261   }
262
263   /**
264    * @copydoc Dali::WebEnginePlugin::PageLoadErrorSignal()
265    */
266   Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() override
267   {
268     return mPageLoadErrorSignal;
269   }
270
271   /**
272    * @copydoc Dali::WebEnginePlugin::ScrollEdgeReachedSignal()
273    */
274   Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal() override
275   {
276     return mScrollEdgeReachedSignal;
277   }
278
279 private:
280
281   void UpdateBuffer();
282
283   void DestroyInstance();
284
285   void DispatchMouseDownEvent(float x, float y);
286
287   void DispatchMouseUpEvent(float x, float y);
288
289   void DispatchMouseMoveEvent(float x, float y, bool isLButtonPressed, bool isRButtonPressed);
290
291   void DispatchKeyDownEvent(LWE::KeyValue keyCode);
292
293   void DispatchKeyPressEvent(LWE::KeyValue keyCode);
294
295   void DispatchKeyUpEvent(LWE::KeyValue keyCode);
296
297 private:
298
299   std::string                mUrl;
300   size_t                     mOutputWidth;
301   size_t                     mOutputHeight;
302   size_t                     mOutputStride;
303   uint8_t*                   mOutputBuffer;
304   bool                       mIsMouseLbuttonDown;
305   bool                       mCanGoBack;
306   bool                       mCanGoForward;
307   pthread_mutex_t            mOutputBufferMutex;
308   LWE::WebContainer*         mWebContainer;
309 #ifdef DALI_USE_TBMSURFACE
310   tbm_surface_h              mTbmSurface;
311   Dali::NativeImageSourcePtr mNativeImageSourcePtr;
312 #else
313   Dali::BufferImage          mBufferImage;
314 #endif
315
316   std::function<void(LWE::WebContainer*, const LWE::WebContainer::RenderResult&)> mOnRenderedHandler;
317   std::function<void(LWE::WebContainer*, LWE::ResourceError)> mOnReceivedError;
318   std::function<void(LWE::WebContainer*, const std::string&)> mOnPageFinishedHandler;
319   std::function<void(LWE::WebContainer*, const std::string&)> mOnPageStartedHandler;
320   std::function<void(LWE::WebContainer*, const std::string&)> mOnLoadResourceHandler;
321
322   EventThreadCallback                                     mUpdateBufferTrigger;
323   Dali::WebEnginePlugin::WebEnginePageLoadSignalType      mPageLoadStartedSignal;
324   Dali::WebEnginePlugin::WebEnginePageLoadSignalType      mPageLoadFinishedSignal;
325   Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType mPageLoadErrorSignal;
326   Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType mScrollEdgeReachedSignal;
327 };
328
329 } // namespace Plugin
330 } // namespace Dali;
331
332 #endif