057b831b11115af3eb1738be4e8ce2b1f311cdc8
[platform/core/uifw/dali-adaptor.git] / dali / internal / web-engine / common / web-engine-impl.h
1 #ifndef DALI_WEB_ENGINE_IMPL_H
2 #define DALI_WEB_ENGINE_IMPL_H
3
4 /*
5  * Copyright (c) 2021 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 <dali/public-api/object/base-object.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/devel-api/adaptor-framework/web-engine-plugin.h>
26 #include <dali/devel-api/adaptor-framework/web-engine.h>
27
28 namespace Dali
29 {
30 // forward declaration
31 class WebEngineBackForwardList;
32 class WebEngineContext;
33 class WebEngineCookieManager;
34 class WebEngineSettings;
35
36 namespace Internal
37 {
38 namespace Adaptor
39 {
40 class WebEngine;
41
42 typedef IntrusivePtr<WebEngine> WebEnginePtr;
43
44 /**
45  * @brief WebEngine class is used for Web.
46  */
47 class WebEngine : public Dali::BaseObject
48 {
49 public:
50   /**
51    * @brief Creates a new WebEngine handle
52    *
53    * @return WebEngine pointer
54    */
55   static WebEnginePtr New();
56
57   /**
58    * @copydoc Dali::WebEngine::Create()
59    */
60   void Create(int width, int height, const std::string& locale, const std::string& timezoneId);
61
62   /**
63    * @copydoc Dali::WebEngine::Create()
64    */
65   void Create(int width, int height, int argc, char** argv);
66
67   /**
68    * @copydoc Dali::WebEngine::Destroy()
69    */
70   void Destroy();
71
72   /**
73    * @copydoc Dali::WebEngine::GetNativeImageSource()
74    */
75   Dali::NativeImageInterfacePtr GetNativeImageSource();
76
77   /**
78    * @copydoc Dali::WebEngine::GetSettings()
79    */
80   Dali::WebEngineSettings& GetSettings() const;
81
82   /**
83    * @copydoc Dali::WebEngine::GetContext()
84    */
85   Dali::WebEngineContext& GetContext() const;
86
87   /**
88    * @copydoc Dali::WebEngine::GetCookieManager()
89    */
90   Dali::WebEngineCookieManager& GetCookieManager() const;
91
92   /**
93    * @copydoc Dali::WebEngine::GetBackForwardList()
94    */
95   Dali::WebEngineBackForwardList& GetBackForwardList() const;
96
97   /**
98    * @copydoc Dali::WebEngine::LoadUrl()
99    */
100   void LoadUrl(const std::string& url);
101
102   /**
103    * @copydoc Dali::WebEngine::GetTitle()
104    */
105   std::string GetTitle() const;
106
107   /**
108    * @copydoc Dali::WebEngine::GetFavicon()
109    */
110   Dali::PixelData GetFavicon() const;
111
112   /**
113    * @copydoc Dali::WebEngine::GetUrl()
114    */
115   const std::string& GetUrl();
116
117   /**
118    * @copydoc Dali::WebEngine::GetUserAgent()
119    */
120   const std::string& GetUserAgent() const;
121
122   /**
123    * @copydoc Dali::WebEngine::SetUserAgent()
124    */
125   void SetUserAgent(const std::string& userAgent);
126
127   /**
128    * @copydoc Dali::WebEngine::LoadHtmlString()
129    */
130   void LoadHtmlString(const std::string& htmlString);
131
132   /**
133    * @copydoc Dali::WebEngine::Reload()
134    */
135   void Reload();
136
137   /**
138    * @copydoc Dali::WebEngine::StopLoading()
139    */
140   void StopLoading();
141
142   /**
143    * @copydoc Dali::WebEngine::Suspend()
144    */
145   void Suspend();
146
147   /**
148    * @copydoc Dali::WebEngine::Resume()
149    */
150   void Resume();
151
152   /**
153    * @copydoc Dali::WebEngine::ScrollBy()
154    */
155   void ScrollBy(int deltaX, int deltaY);
156
157   /**
158    * @copydoc Dali::WebEngine::SetScrollPosition()
159    */
160   void SetScrollPosition(int x, int y);
161
162   /**
163    * @copydoc Dali::WebEngine::GetScrollPosition()
164    */
165   Dali::Vector2 GetScrollPosition() const;
166
167   /**
168    * @copydoc Dali::WebEngine::GetScrollSize()
169    */
170   Dali::Vector2 GetScrollSize() const;
171
172   /**
173    * @copydoc Dali::WebEngine::GetContentSize()
174    */
175   Dali::Vector2 GetContentSize() const;
176
177   /**
178         * @copydoc Dali::WebEngine::RegisterJavaScriptAlertCallback()
179         */
180   void RegisterJavaScriptAlertCallback( Dali::WebEnginePlugin::JavaScriptAlertCallback callback );
181
182   /**
183    * @copydoc Dali::WebEngine::JavaScriptAlertReply()
184    */
185   void JavaScriptAlertReply();
186
187   /**
188    * @copydoc Dali::WebEngine::RegisterJavaScriptConfirmCallback()
189    */
190   void RegisterJavaScriptConfirmCallback( Dali::WebEnginePlugin::JavaScriptConfirmCallback callback );
191
192   /**
193    * @copydoc Dali::WebEngine::JavaScriptConfirmReply()
194    */
195   void JavaScriptConfirmReply( bool confirmed );
196
197   /**
198    * @copydoc Dali::WebEngine::RegisterJavaScriptPromptCallback()
199    */
200   void RegisterJavaScriptPromptCallback( Dali::WebEnginePlugin::JavaScriptPromptCallback callback );
201
202   /**
203    * @copydoc Dali::WebEngine::JavaScriptPromptReply()
204    */
205   void JavaScriptPromptReply( const std::string& result );
206
207   /**
208    * @copydoc Dali::WebEngine::CanGoForward()
209    */
210   bool CanGoForward();
211
212   /**
213    * @copydoc Dali::WebEngine::GoForward()
214    */
215   void GoForward();
216
217   /**
218    * @copydoc Dali::WebEngine::CanGoBack()
219    */
220   bool CanGoBack();
221
222   /**
223    * @copydoc Dali::WebEngine::GoBack()
224    */
225   void GoBack();
226
227   /**
228    * @copydoc Dali::WebEngine::EvaluateJavaScript()
229    */
230   void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler);
231
232   /**
233    * @copydoc Dali::WebEngine::AddJavaScriptMessageHandler()
234    */
235   void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
236
237   /**
238    * @copydoc Dali::WebEngine::ClearAllTilesResources()
239    */
240   void ClearAllTilesResources();
241
242   /**
243    * @copydoc Dali::WebEngine::ClearHistory()
244    */
245   void ClearHistory();
246
247   /**
248    * @copydoc Dali::WebEngine::SetSize()
249    */
250   void SetSize(int width, int height);
251
252   /**
253    * @copydoc Dali::WebEngine::SendTouchEvent()
254    */
255   bool SendTouchEvent(const Dali::TouchEvent& touch);
256
257   /**
258    * @copydoc Dali::WebEngine::SendKeyEvent()
259    */
260   bool SendKeyEvent(const Dali::KeyEvent& event);
261
262   /**
263    * @copydoc Dali::WebEngine::SetFocus()
264    */
265   void SetFocus(bool focused);
266
267   /**
268    * @copydoc Dali::WebEngine::UpdateDisplayArea()
269    */
270   void UpdateDisplayArea(Dali::Rect<int> displayArea);
271
272   /**
273    * @copydoc Dali::WebEngine::EnableVideoHole()
274    */
275   void EnableVideoHole(bool enabled);
276
277   /**
278    * @copydoc Dali::WebEngine::PageLoadStartedSignal()
279    */
280   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal();
281
282   /**
283    * @copydoc Dali::WebEngine::PageLoadProgressSignal()
284    */
285   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadInProgressSignal();
286
287   /**
288    * @copydoc Dali::WebEngine::PageLoadFinishedSignal()
289    */
290   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal();
291
292   /**
293    * @copydoc Dali::WebEngine::PageLoadErrorSignal()
294    */
295   Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal();
296
297   /**
298    * @copydoc Dali::WebEngine::ScrollEdgeReachedSignal()
299    */
300   Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
301
302   /**
303    * @copydoc Dali::WebEngine::UrlChangedSignal()
304    */
305   Dali::WebEnginePlugin::WebEngineUrlChangedSignalType& UrlChangedSignal();
306
307 private:
308   /**
309    * @brief Constructor.
310    */
311   WebEngine();
312
313   /**
314    * @brief Destructor.
315    */
316   virtual ~WebEngine();
317
318   // Undefined copy constructor
319   WebEngine(const WebEngine& WebEngine);
320
321   // Undefined assignment operator
322   WebEngine& operator=(const WebEngine& WebEngine);
323
324   /**
325    * @brief Initializes member data.
326    *
327    * @return Whether the initialization succeed or not.
328    */
329   bool Initialize();
330
331   /**
332    * @brief Initializes library handle by loading web engine plugin.
333    *
334    * @return Whether the initialization succeed or not.
335    */
336   bool InitializePluginHandle();
337
338 private:
339   typedef Dali::WebEnginePlugin* (*CreateWebEngineFunction)();
340   typedef void (*DestroyWebEngineFunction)(Dali::WebEnginePlugin* plugin);
341
342   Dali::WebEnginePlugin*   mPlugin;              ///< WebEnginePlugin instance
343   void*                    mHandle;              ///< Handle for the loaded library
344   CreateWebEngineFunction  mCreateWebEnginePtr;  ///< Function to create plugin instance
345   DestroyWebEngineFunction mDestroyWebEnginePtr; ///< Function to destroy plugin instance
346 };
347
348 } // namespace Adaptor
349 } // namespace Internal
350
351 inline static Internal::Adaptor::WebEngine& GetImplementation(Dali::WebEngine& webEngine)
352 {
353   DALI_ASSERT_ALWAYS(webEngine && "WebEngine handle is empty.");
354
355   BaseObject& handle = webEngine.GetBaseObject();
356
357   return static_cast<Internal::Adaptor::WebEngine&>(handle);
358 }
359
360 inline static const Internal::Adaptor::WebEngine& GetImplementation(const Dali::WebEngine& webEngine)
361 {
362   DALI_ASSERT_ALWAYS(webEngine && "WebEngine handle is empty.");
363
364   const BaseObject& handle = webEngine.GetBaseObject();
365
366   return static_cast<const Internal::Adaptor::WebEngine&>(handle);
367 }
368
369 } // namespace Dali
370
371 #endif