Support policy decision in web engine.
[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::LoadHtmlStringOverrideCurrentEntry()
134    */
135   bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl);
136
137   /**
138    * @copydoc Dali::WebEngine::LoadContents()
139    */
140   bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri);
141
142   /**
143    * @copydoc Dali::WebEngine::Reload()
144    */
145   void Reload();
146
147   /**
148    * @copydoc Dali::WebEngine::ReloadWithoutCache()
149    */
150   bool ReloadWithoutCache();
151
152   /**
153    * @copydoc Dali::WebEngine::StopLoading()
154    */
155   void StopLoading();
156
157   /**
158    * @copydoc Dali::WebEngine::Suspend()
159    */
160   void Suspend();
161
162   /**
163    * @copydoc Dali::WebEngine::Resume()
164    */
165   void Resume();
166
167   /**
168    * @copydoc Dali::WebEngine::SuspendNetworkLoading()
169    */
170   void SuspendNetworkLoading();
171
172   /**
173    * @copydoc Dali::WebEngine::ResumeNetworkLoading()
174    */
175   void ResumeNetworkLoading();
176
177   /**
178    * @copydoc Dali::WebEngine::AddCustomHeader()
179    */
180   bool AddCustomHeader(const std::string& name, const std::string& value);
181
182   /**
183    * @copydoc Dali::WebEngine::RemoveCustomHeader()
184    */
185   bool RemoveCustomHeader(const std::string& name);
186
187   /**
188    * @copydoc Dali::WebEngine::StartInspectorServer()
189    */
190   uint32_t StartInspectorServer(uint32_t port);
191
192   /**
193    * @copydoc Dali::WebEngine::StopInspectorServer()
194    */
195   bool StopInspectorServer();
196
197   /**
198    * @copydoc Dali::WebEngine::ScrollBy()
199    */
200   void ScrollBy(int deltaX, int deltaY);
201
202   /**
203    * @copydoc Dali::WebEngine::ScrollEdgeBy()
204    */
205   bool ScrollEdgeBy(int deltaX, int deltaY);
206
207   /**
208    * @copydoc Dali::WebEngine::SetScrollPosition()
209    */
210   void SetScrollPosition(int x, int y);
211
212   /**
213    * @copydoc Dali::WebEngine::GetScrollPosition()
214    */
215   Dali::Vector2 GetScrollPosition() const;
216
217   /**
218    * @copydoc Dali::WebEngine::GetScrollSize()
219    */
220   Dali::Vector2 GetScrollSize() const;
221
222   /**
223    * @copydoc Dali::WebEngine::GetContentSize()
224    */
225   Dali::Vector2 GetContentSize() const;
226
227   /**
228    * @copydoc Dali::WebEngine::RegisterJavaScriptAlertCallback()
229    */
230   void RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback);
231
232   /**
233    * @copydoc Dali::WebEngine::JavaScriptAlertReply()
234    */
235   void JavaScriptAlertReply();
236
237   /**
238    * @copydoc Dali::WebEngine::RegisterJavaScriptConfirmCallback()
239    */
240   void RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback);
241
242   /**
243    * @copydoc Dali::WebEngine::JavaScriptConfirmReply()
244    */
245   void JavaScriptConfirmReply(bool confirmed);
246
247   /**
248    * @copydoc Dali::WebEngine::RegisterJavaScriptPromptCallback()
249    */
250   void RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback);
251
252   /**
253    * @copydoc Dali::WebEngine::JavaScriptPromptReply()
254    */
255   void JavaScriptPromptReply(const std::string& result);
256
257   /**
258    * @copydoc Dali::WebEngine::CanGoForward()
259    */
260   bool CanGoForward();
261
262   /**
263    * @copydoc Dali::WebEngine::GoForward()
264    */
265   void GoForward();
266
267   /**
268    * @copydoc Dali::WebEngine::CanGoBack()
269    */
270   bool CanGoBack();
271
272   /**
273    * @copydoc Dali::WebEngine::GoBack()
274    */
275   void GoBack();
276
277   /**
278    * @copydoc Dali::WebEngine::EvaluateJavaScript()
279    */
280   void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler);
281
282   /**
283    * @copydoc Dali::WebEngine::AddJavaScriptMessageHandler()
284    */
285   void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
286
287   /**
288    * @copydoc Dali::WebEngine::ClearAllTilesResources()
289    */
290   void ClearAllTilesResources();
291
292   /**
293    * @copydoc Dali::WebEngine::ClearHistory()
294    */
295   void ClearHistory();
296
297   /**
298    * @copydoc Dali::WebEngine::SetSize()
299    */
300   void SetSize(int width, int height);
301
302   /**
303    * @copydoc Dali::WebEngine::EnableMouseEvents()
304    */
305   void EnableMouseEvents(bool enabled);
306
307   /**
308    * @copydoc Dali::WebEngine::EnableKeyEvents()
309    */
310   void EnableKeyEvents(bool enabled);
311
312   /**
313    * @copydoc Dali::WebEngine::SetDocumentBackgroundColor()
314    */
315   void SetDocumentBackgroundColor(Dali::Vector4 color);
316
317   /**
318    * @copydoc Dali::WebEngine::ClearTilesWhenHidden()
319    */
320   void ClearTilesWhenHidden(bool cleared);
321
322   /**
323    * @copydoc Dali::WebEngine::SetTileCoverAreaMultiplier()
324    */
325   void SetTileCoverAreaMultiplier(float multiplier);
326
327   /**
328    * @copydoc Dali::WebEngine::EnableCursorByClient()
329    */
330   void EnableCursorByClient(bool enabled);
331
332   /**
333    * @copydoc Dali::WebEngine::GetSelectedText()
334    */
335   std::string GetSelectedText() const;
336
337   /**
338    * @copydoc Dali::WebEngine::SendTouchEvent()
339    */
340   bool SendTouchEvent(const Dali::TouchEvent& touch);
341
342   /**
343    * @copydoc Dali::WebEngine::SendKeyEvent()
344    */
345   bool SendKeyEvent(const Dali::KeyEvent& event);
346
347   /**
348    * @copydoc Dali::WebEngine::SetFocus()
349    */
350   void SetFocus(bool focused);
351
352   /**
353    * @copydoc Dali::WebEngine::SetPageZoomFactor()
354    */
355   void SetPageZoomFactor(float zoomFactor);
356
357   /**
358    * @copydoc Dali::WebEngine::GetPageZoomFactor()
359    */
360   float GetPageZoomFactor() const;
361
362   /**
363    * @copydoc Dali::WebEngine::SetTextZoomFactor()
364    */
365   void SetTextZoomFactor(float zoomFactor);
366
367   /**
368    * @copydoc Dali::WebEngine::GetTextZoomFactor()
369    */
370   float GetTextZoomFactor() const;
371
372   /**
373    * @copydoc Dali::WebEngine::GetLoadProgressPercentage()
374    */
375   float GetLoadProgressPercentage() const;
376
377   /**
378    * @copydoc Dali::WebEngine::SetScaleFactor()
379    */
380   void SetScaleFactor(float scaleFactor, Dali::Vector2 point);
381
382   /**
383    * @copydoc Dali::WebEngine::GetScaleFactor()
384    */
385   float GetScaleFactor() const;
386
387   /**
388    * @copydoc Dali::WebEngine::ActivateAccessibility()
389    */
390   void ActivateAccessibility(bool activated);
391
392   /**
393    * @copydoc Dali::WebEngine::SetVisibility()
394    */
395   bool SetVisibility(bool visible);
396
397   /**
398    * @copydoc Dali::WebEngine::HighlightText()
399    */
400   bool HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount);
401
402   /**
403    * @copydoc Dali::WebEngine::AddDynamicCertificatePath()
404    */
405   void AddDynamicCertificatePath(const std::string& host, const std::string& certPath);
406
407   /**
408    * @copydoc Dali::WebEngine::GetScreenshot()
409    */
410   Dali::PixelData GetScreenshot(Dali::Rect<int> viewArea, float scaleFactor);
411
412   /**
413    * @copydoc Dali::WebEngine::GetScreenshotAsync()
414    */
415   bool GetScreenshotAsynchronously(Dali::Rect<int> viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback);
416
417   /**
418    * @copydoc Dali::WebEngine::IsVideoPlaying()
419    */
420   bool CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback);
421
422   /**
423    * @copydoc Dali::WebEngine::RegisterGeolocationPermissionCallback()
424    */
425   void RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback);
426
427   /**
428    * @copydoc Dali::WebEngine::UpdateDisplayArea()
429    */
430   void UpdateDisplayArea(Dali::Rect<int> displayArea);
431
432   /**
433    * @copydoc Dali::WebEngine::EnableVideoHole()
434    */
435   void EnableVideoHole(bool enabled);
436
437   /**
438    * @copydoc Dali::WebEngine::SendHoverEvent()
439    */
440   bool SendHoverEvent(const Dali::HoverEvent& event);
441
442   /**
443    * @copydoc Dali::WebEngine::SendWheelEvent()
444    */
445   bool SendWheelEvent(const Dali::WheelEvent& event);
446
447   /**
448    * @copydoc Dali::WebEngine::PageLoadStartedSignal()
449    */
450   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal();
451
452   /**
453    * @copydoc Dali::WebEngine::PageLoadProgressSignal()
454    */
455   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadInProgressSignal();
456
457   /**
458    * @copydoc Dali::WebEngine::PageLoadFinishedSignal()
459    */
460   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal();
461
462   /**
463    * @copydoc Dali::WebEngine::PageLoadErrorSignal()
464    */
465   Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal();
466
467   /**
468    * @copydoc Dali::WebEngine::ScrollEdgeReachedSignal()
469    */
470   Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
471
472   /**
473    * @copydoc Dali::WebEngine::UrlChangedSignal()
474    */
475   Dali::WebEnginePlugin::WebEngineUrlChangedSignalType& UrlChangedSignal();
476
477   /**
478    * @copydoc Dali::WebEngine::FormRepostDecisionSignal()
479    */
480   Dali::WebEnginePlugin::WebEngineFormRepostDecisionSignalType& FormRepostDecisionSignal();
481
482   /**
483    * @copydoc Dali::WebEngine::FrameRenderedSignal()
484    */
485   Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& FrameRenderedSignal();
486
487   /**
488    * @copydoc Dali::WebEngine::RequestInterceptorSignal()
489    */
490   Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& RequestInterceptorSignal();
491
492   /**
493    @copydoc Dali::WebEngine::ConsoleMessageSignal()
494    */
495   Dali::WebEnginePlugin::WebEngineConsoleMessageSignalType& ConsoleMessageSignal();
496
497   /**
498    @copydoc Dali::WebEngine::PolicyDecisionSignal()
499    */
500   Dali::WebEnginePlugin::WebEnginePolicyDecisionSignalType& PolicyDecisionSignal();
501
502 private:
503   /**
504    * @brief Constructor.
505    */
506   WebEngine();
507
508   /**
509    * @brief Destructor.
510    */
511   virtual ~WebEngine();
512
513   // Undefined copy constructor
514   WebEngine(const WebEngine& WebEngine);
515
516   // Undefined assignment operator
517   WebEngine& operator=(const WebEngine& WebEngine);
518
519   /**
520    * @brief Initializes member data.
521    *
522    * @return Whether the initialization succeed or not.
523    */
524   bool Initialize();
525
526   /**
527    * @brief Initializes library handle by loading web engine plugin.
528    *
529    * @return Whether the initialization succeed or not.
530    */
531   bool InitializePluginHandle();
532
533 private:
534   typedef Dali::WebEnginePlugin* (*CreateWebEngineFunction)();
535   typedef void (*DestroyWebEngineFunction)(Dali::WebEnginePlugin* plugin);
536
537   Dali::WebEnginePlugin*   mPlugin;              ///< WebEnginePlugin instance
538   void*                    mHandle;              ///< Handle for the loaded library
539   CreateWebEngineFunction  mCreateWebEnginePtr;  ///< Function to create plugin instance
540   DestroyWebEngineFunction mDestroyWebEnginePtr; ///< Function to destroy plugin instance
541 };
542
543 } // namespace Adaptor
544 } // namespace Internal
545
546 inline static Internal::Adaptor::WebEngine& GetImplementation(Dali::WebEngine& webEngine)
547 {
548   DALI_ASSERT_ALWAYS(webEngine && "WebEngine handle is empty.");
549
550   BaseObject& handle = webEngine.GetBaseObject();
551
552   return static_cast<Internal::Adaptor::WebEngine&>(handle);
553 }
554
555 inline static const Internal::Adaptor::WebEngine& GetImplementation(const Dali::WebEngine& webEngine)
556 {
557   DALI_ASSERT_ALWAYS(webEngine && "WebEngine handle is empty.");
558
559   const BaseObject& handle = webEngine.GetBaseObject();
560
561   return static_cast<const Internal::Adaptor::WebEngine&>(handle);
562 }
563
564 } // namespace Dali
565
566 #endif