7b1675d3b733e692ce0b5ffdb75483773a096685
[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::EnableMouseEvents()
254    */
255   void EnableMouseEvents(bool enabled);
256
257   /**
258    * @copydoc Dali::WebEngine::EnableKeyEvents()
259    */
260   void EnableKeyEvents(bool enabled);
261
262   /**
263    * @copydoc Dali::WebEngine::SetDocumentBackgroundColor()
264    */
265   void SetDocumentBackgroundColor(Dali::Vector4 color);
266
267   /**
268    * @copydoc Dali::WebEngine::ClearTilesWhenHidden()
269    */
270   void ClearTilesWhenHidden(bool cleared);
271
272   /**
273    * @copydoc Dali::WebEngine::SetTileCoverAreaMultiplier()
274    */
275   void SetTileCoverAreaMultiplier(float multiplier);
276
277   /**
278    * @copydoc Dali::WebEngine::EnableCursorByClient()
279    */
280   void EnableCursorByClient(bool enabled);
281
282   /**
283    * @copydoc Dali::WebEngine::GetSelectedText()
284    */
285   std::string GetSelectedText() const;
286
287   /**
288    * @copydoc Dali::WebEngine::SendTouchEvent()
289    */
290   bool SendTouchEvent(const Dali::TouchEvent& touch);
291
292   /**
293    * @copydoc Dali::WebEngine::SendKeyEvent()
294    */
295   bool SendKeyEvent(const Dali::KeyEvent& event);
296
297   /**
298    * @copydoc Dali::WebEngine::SetFocus()
299    */
300   void SetFocus(bool focused);
301
302   /**
303    * @copydoc Dali::WebEngine::UpdateDisplayArea()
304    */
305   void UpdateDisplayArea(Dali::Rect<int> displayArea);
306
307   /**
308    * @copydoc Dali::WebEngine::EnableVideoHole()
309    */
310   void EnableVideoHole(bool enabled);
311
312   /**
313    * @copydoc Dali::WebEngine::SendHoverEvent()
314    */
315   bool SendHoverEvent(const Dali::HoverEvent& event);
316
317   /**
318    * @copydoc Dali::WebEngine::SendWheelEvent()
319    */
320   bool SendWheelEvent(const Dali::WheelEvent& event);
321
322   /**
323    * @copydoc Dali::WebEngine::PageLoadStartedSignal()
324    */
325   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal();
326
327   /**
328    * @copydoc Dali::WebEngine::PageLoadProgressSignal()
329    */
330   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadInProgressSignal();
331
332   /**
333    * @copydoc Dali::WebEngine::PageLoadFinishedSignal()
334    */
335   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal();
336
337   /**
338    * @copydoc Dali::WebEngine::PageLoadErrorSignal()
339    */
340   Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal();
341
342   /**
343    * @copydoc Dali::WebEngine::ScrollEdgeReachedSignal()
344    */
345   Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
346
347   /**
348    * @copydoc Dali::WebEngine::UrlChangedSignal()
349    */
350   Dali::WebEnginePlugin::WebEngineUrlChangedSignalType& UrlChangedSignal();
351
352 private:
353   /**
354    * @brief Constructor.
355    */
356   WebEngine();
357
358   /**
359    * @brief Destructor.
360    */
361   virtual ~WebEngine();
362
363   // Undefined copy constructor
364   WebEngine(const WebEngine& WebEngine);
365
366   // Undefined assignment operator
367   WebEngine& operator=(const WebEngine& WebEngine);
368
369   /**
370    * @brief Initializes member data.
371    *
372    * @return Whether the initialization succeed or not.
373    */
374   bool Initialize();
375
376   /**
377    * @brief Initializes library handle by loading web engine plugin.
378    *
379    * @return Whether the initialization succeed or not.
380    */
381   bool InitializePluginHandle();
382
383 private:
384   typedef Dali::WebEnginePlugin* (*CreateWebEngineFunction)();
385   typedef void (*DestroyWebEngineFunction)(Dali::WebEnginePlugin* plugin);
386
387   Dali::WebEnginePlugin*   mPlugin;              ///< WebEnginePlugin instance
388   void*                    mHandle;              ///< Handle for the loaded library
389   CreateWebEngineFunction  mCreateWebEnginePtr;  ///< Function to create plugin instance
390   DestroyWebEngineFunction mDestroyWebEnginePtr; ///< Function to destroy plugin instance
391 };
392
393 } // namespace Adaptor
394 } // namespace Internal
395
396 inline static Internal::Adaptor::WebEngine& GetImplementation(Dali::WebEngine& webEngine)
397 {
398   DALI_ASSERT_ALWAYS(webEngine && "WebEngine handle is empty.");
399
400   BaseObject& handle = webEngine.GetBaseObject();
401
402   return static_cast<Internal::Adaptor::WebEngine&>(handle);
403 }
404
405 inline static const Internal::Adaptor::WebEngine& GetImplementation(const Dali::WebEngine& webEngine)
406 {
407   DALI_ASSERT_ALWAYS(webEngine && "WebEngine handle is empty.");
408
409   const BaseObject& handle = webEngine.GetBaseObject();
410
411   return static_cast<const Internal::Adaptor::WebEngine&>(handle);
412 }
413
414 } // namespace Dali
415
416 #endif