0af9cbe2ebb6bd7a5d33b9979018be444ca46dcd
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / web-engine / web-engine.h
1 #ifndef DALI_WEB_ENGINE_H
2 #define DALI_WEB_ENGINE_H
3
4 /*
5  * Copyright (c) 2022 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-handle.h>
23
24 //INTERNAL INCLUDES
25 #include <dali/devel-api/adaptor-framework/accessibility.h>
26 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-plugin.h>
27 #include <dali/public-api/dali-adaptor-common.h>
28
29 namespace Dali
30 {
31 namespace Internal
32 {
33 namespace Adaptor
34 {
35 class WebEngine;
36 } // namespace Adaptor
37
38 } // namespace Internal
39
40 /**
41  * @brief Proxy class to dynamically load, use and unload web engine plugin.
42  *
43  * The purpose of this class is to dynamically load the web engine plugin if and when its needed.
44  * So we don't slow down every application startup if they never need web engine.
45  */
46 class DALI_ADAPTOR_API WebEngine : public BaseHandle
47 {
48 public:
49   /**
50    * @brief Constructor.
51    */
52   WebEngine();
53
54   /**
55    * @brief Destructor.
56    */
57   ~WebEngine();
58
59   /**
60    * @brief Create a new instance of a WebEngine.
61    */
62   static WebEngine New();
63
64   /**
65    * @brief Get context of WebEngine.
66    */
67   static Dali::WebEngineContext* GetContext();
68
69   /**
70    * @brief Get cookie manager of WebEngine.
71    */
72   static Dali::WebEngineCookieManager* GetCookieManager();
73
74   /**
75    * @brief Copy constructor.
76    *
77    * @param[in] WebEngine WebEngine to copy. The copied WebEngine will point at the same implementation
78    */
79   WebEngine(const WebEngine& WebEngine);
80
81   /**
82    * @brief Assignment operator.
83    *
84    * @param[in] WebEngine The WebEngine to assign from.
85    * @return The updated WebEngine.
86    */
87   WebEngine& operator=(const WebEngine& WebEngine);
88
89   /**
90    * @brief Downcast a handle to WebEngine handle.
91    *
92    * If handle points to a WebEngine the downcast produces valid
93    * handle. If not the returned handle is left uninitialized.
94    *
95    * @param[in] handle Handle to an object
96    * @return Handle to a WebEngine or an uninitialized handle
97    */
98   static WebEngine DownCast(BaseHandle handle);
99
100   /**
101    * @brief Create WebEngine instance.
102    *
103    * @param [in] width The width of Web
104    * @param [in] height The height of Web
105    * @param [in] locale The locale of Web
106    * @param [in] timezoneId The timezoneID of Web
107    */
108   void Create(uint32_t width, uint32_t height, const std::string& locale, const std::string& timezoneId);
109
110   /**
111    * @brief Create WebEngine instance.
112    *
113    * @param [in] width The width of Web
114    * @param [in] height The height of Web
115    * @param [in] argc The count of application arguments
116    * @param [in] argv The string array of application arguments
117    */
118   void Create(uint32_t width, uint32_t height, uint32_t argc, char** argv);
119
120   /**
121    * @brief Destroy WebEngine instance.
122    */
123   void Destroy();
124
125   /**
126    * @brief Get native image source to render.
127    */
128   NativeImageSourcePtr GetNativeImageSource();
129
130   /**
131    * @brief Get settings of WebEngine.
132    */
133   Dali::WebEngineSettings& GetSettings() const;
134
135   /**
136    * @brief Get back-forward list of WebEngine.
137    */
138   Dali::WebEngineBackForwardList& GetBackForwardList() const;
139
140   /**
141    * @brief Load a web page based on a given URL.
142    *
143    * @param [in] url The URL of the resource to load
144    */
145   void LoadUrl(const std::string& url);
146
147   /**
148    * @brief Return the title of the Web.
149    *
150    * @return The title of web page
151    */
152   std::string GetTitle() const;
153
154   /**
155    * @brief Return the Favicon of the Web.
156    *
157    * @return FavIcon of Dali::PixelData& type
158    */
159   Dali::PixelData GetFavicon() const;
160
161   /**
162    * @brief Get the url.
163    */
164   std::string GetUrl() const;
165
166   /**
167    * @brief Load a given string as web contents.
168    *
169    * @param [in] htmlString The string to use as the contents of the web page
170    */
171   void LoadHtmlString(const std::string& htmlString);
172
173   /**
174    * @brief Load the specified html string as the content of the view overriding current history entry
175    *
176    * @param[in] html HTML data to load
177    * @param[in] basicUri Base URL used for relative paths to external objects
178    * @param[in] unreachableUrl URL that could not be reached
179    *
180    * @return true if successfully loaded, false otherwise
181    */
182   bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl);
183
184   /**
185    * @brief Request loading the given contents by MIME type into the view object
186    *
187    * @param[in] contents The content to load
188    * @param[in] contentSize The size of contents (in bytes)
189    * @param[in] mimeType The type of contents, if 0 is given "text/html" is assumed
190    * @param[in] encoding The encoding for contents, if 0 is given "UTF-8" is assumed
191    * @param[in] baseUri The base URI to use for relative resources
192    *
193    * @return true if successfully request, false otherwise
194    */
195   bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri);
196
197   /**
198    * @brief Reload the Web.
199    */
200   void Reload();
201
202   /**
203    * @brief Reload the current page's document without cache
204    */
205   bool ReloadWithoutCache();
206
207   /**
208    * @brief Stop loading web contents on the current page.
209    */
210   void StopLoading();
211
212   /**
213    * @brief Suspend the operation associated with the view.
214    */
215   void Suspend();
216
217   /**
218    * @brief Resume the operation associated with the view object after calling Suspend().
219    */
220   void Resume();
221
222   /**
223    * @brief To suspend all url loading
224    */
225   void SuspendNetworkLoading();
226
227   /**
228    * @brief To resume new url network loading
229    */
230   void ResumeNetworkLoading();
231
232   /**
233    * @brief Add custom header
234    *
235    * @param[in] name custom header name to add the custom header
236    * @param[in] value custom header value to add the custom header
237    *
238    * @return true if succeeded, false otherwise
239    */
240   bool AddCustomHeader(const std::string& name, const std::string& value);
241
242   /**
243    * @brief Remove custom header
244    *
245    * @param[in] name custom header name to remove the custom header
246    *
247    * @return true if succeeded, false otherwise
248    */
249   bool RemoveCustomHeader(const std::string& name);
250
251   /**
252    * @brief Start the inspector server
253    *
254    * @param[in] port port number
255    *
256    * @return the port number
257    */
258   uint32_t StartInspectorServer(uint32_t port);
259
260   /**
261    * @brief Stop the inspector server
262    *
263    * @return true if succeeded, false otherwise
264    */
265   bool StopInspectorServer();
266
267   /**
268    * @brief Scroll web page of view by deltaX and deltaY.
269    *
270    * @param[in] deltaX horizontal offset to scroll
271    * @param[in] deltaY vertical offset to scroll
272    */
273   void ScrollBy(int32_t deltaX, int32_t deltaY);
274
275   /**
276    * @brief Scroll edge of view by deltaX and deltaY.
277    *
278    * @param[in] deltaX horizontal offset to scroll
279    * @param[in] deltaY vertical offset to scroll
280    *
281    * @return true if succeeded, false otherwise
282    */
283   bool ScrollEdgeBy(int32_t deltaX, int32_t deltaY);
284
285   /**
286    * @brief Set an absolute scroll of the given view.
287    */
288   void SetScrollPosition(int32_t x, int32_t y);
289
290   /**
291    * @brief Get the current scroll position of the given view.
292    */
293   Dali::Vector2 GetScrollPosition() const;
294
295   /**
296    * @brief Get the possible scroll size of the given view.
297    */
298   Dali::Vector2 GetScrollSize() const;
299
300   /**
301    * @brief Get the last known content's size.
302    */
303   Dali::Vector2 GetContentSize() const;
304
305   /**
306    * @brief Return whether forward is possible.
307    *
308    * @return True if forward is possible, false otherwise
309    */
310   bool CanGoForward();
311
312   /**
313    * @brief Go to forward.
314    */
315   void GoForward();
316
317   /**
318    * @brief Return whether backward is possible.
319    *
320    * @return True if backward is possible, false otherwise
321    */
322   bool CanGoBack();
323
324   /**
325    * @brief Go to back.
326    */
327   void GoBack();
328
329   /**
330    * @brief Evaluate JavaScript code represented as a string.
331    *
332    * @param[in] script The JavaScript code
333    * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
334    */
335   void EvaluateJavaScript(const std::string& script, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback resultHandler);
336
337   /**
338    * @brief Add a message handler into JavaScript.
339    *
340    * @param[in] exposedObjectName The name of exposed object
341    * @param[in] handler The callback function
342    */
343   void AddJavaScriptMessageHandler(const std::string& exposedObjectName, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback handler);
344
345   /**
346    * @brief Register a callback for JavaScript alert.
347    *
348    * @param[in] callback The callback function
349    */
350   void RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback);
351
352   /**
353    * @brief Reply for JavaScript alert.
354    */
355   void JavaScriptAlertReply();
356
357   /**
358    * @brief Register a callback for JavaScript confirm.
359    *
360    * @param[in] callback The callback function
361    */
362   void RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback);
363
364   /**
365    * @brief Reply for JavaScript confirm.
366    * @param[in] confirmed True if confirmed, false otherwise.
367    */
368   void JavaScriptConfirmReply(bool confirmed);
369
370   /**
371    * @brief Register a callback for JavaScript prompt.
372    *
373    * @param[in] callback The callback function
374    */
375   void RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback);
376
377   /**
378    * @brief Reply for JavaScript prompt.
379    * @param[in] result The result returned from input-field in prompt popup.
380    */
381   void JavaScriptPromptReply(const std::string& result);
382
383   /**
384    * @brief Create a new hit test.
385    *
386    * @param[in] x the horizontal position to query
387    * @param[in] y the vertical position to query
388    * @param[in] mode the mode of hit test
389    *
390    * @return a new hit test object
391    */
392   std::unique_ptr<Dali::WebEngineHitTest> CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode);
393
394   /**
395    * @brief create a hit test asynchronously.
396    *
397    * @param[in] x the horizontal position to query
398    * @param[in] y the vertical position to query
399    * @param[in] mode the mode of hit test
400    * @param[in] callback the callback function
401    *
402    * @return true if succeeded, false otherwise
403    */
404   bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback);
405
406   /**
407    * @brief Clear the history of Web.
408    */
409   void ClearHistory();
410
411   /**
412    * @brief Clear all tiles resources of Web.
413    */
414   void ClearAllTilesResources();
415
416   /**
417    * @brief Get user agent string.
418    *
419    * @return The string value of user agent
420    */
421   std::string GetUserAgent() const;
422
423   /**
424    * @brief Set user agent string.
425    *
426    * @param[in] userAgent The string value of user agent
427    */
428   void SetUserAgent(const std::string& userAgent);
429
430   /**
431    * @brief Set the size of Web Pages.
432    */
433   void SetSize(uint32_t width, uint32_t height);
434
435   /**
436    * @brief Set background color of web page.
437    *
438    * @param[in] color Background color
439    */
440   void SetDocumentBackgroundColor(Dali::Vector4 color);
441
442   /**
443    * @brief Clear tiles when hidden.
444    *
445    * @param[in] cleared Whether tiles are cleared or not
446    */
447   void ClearTilesWhenHidden(bool cleared);
448
449   /**
450    * @brief Set multiplier of cover area of tile.
451    *
452    * @param[in] multiplier The multiplier of cover area
453    */
454   void SetTileCoverAreaMultiplier(float multiplier);
455
456   /**
457    * @brief Enable cursor by client.
458    *
459    * @param[in] enabled Whether cursor is enabled or not
460    */
461   void EnableCursorByClient(bool enabled);
462
463   /**
464    * @brief Get the selected text.
465    *
466    * @return the selected text
467    */
468   std::string GetSelectedText() const;
469
470   /**
471    * @brief Send Touch Events.
472    */
473   bool SendTouchEvent(const TouchEvent& touch);
474
475   /**
476    * @brief Send key Events.
477    */
478   bool SendKeyEvent(const KeyEvent& event);
479
480   /**
481    * @brief Set focus.
482    * @param[in] focused True if web view is focused, false otherwise
483    */
484   void SetFocus(bool focused);
485
486   /**
487    * @brief Enable/disable mouse events. The default is enabled.
488    *
489    * @param[in] enabled True if mouse events are enabled, false otherwise
490    */
491   void EnableMouseEvents(bool enabled);
492
493   /**
494    * @brief Enable/disable key events. The default is enabled.
495    *
496    * @param[in] enabled True if key events are enabled, false otherwise
497    */
498   void EnableKeyEvents(bool enabled);
499
500   /**
501    * @brief Set zoom factor of the current page.
502    * @param[in] zoomFactor a new factor to be set.
503    */
504   void SetPageZoomFactor(float zoomFactor);
505
506   /**
507    * @brief Query the current zoom factor of the page。
508    * @return The current page zoom factor.
509    */
510   float GetPageZoomFactor() const;
511
512   /**
513    * @brief Set the current text zoom level。.
514    * @param[in] zoomFactor a new factor to be set.
515    */
516   void SetTextZoomFactor(float zoomFactor);
517
518   /**
519    * @brief Get the current text zoom level.
520    * @return The current text zoom factor.
521    */
522   float GetTextZoomFactor() const;
523
524   /**
525    * @brief Get the current load progress of the page.
526    * @return The load progress of the page.
527    */
528   float GetLoadProgressPercentage() const;
529
530   /**
531    * @brief Scale the current page, centered at the given point.
532    * @param[in] scaleFactor a new factor to be scaled.
533    * @param[in] point a center coordinate.
534    */
535   void SetScaleFactor(float scaleFactor, Dali::Vector2 point);
536
537   /**
538    * @brief Get the current scale factor of the page.
539    * @return The current scale factor.
540    */
541   float GetScaleFactor() const;
542
543   /**
544    * @brief Request to activate/deactivate the accessibility usage set by web app.
545    * @param[in] activated Activate accessibility or not.
546    */
547   void ActivateAccessibility(bool activated);
548
549   /**
550    * @brief Get the accessibility address (bus and path) for embedding.
551    * @return Accessibility address of the root web content element.
552    */
553   Accessibility::Address GetAccessibilityAddress();
554
555   /**
556    * @brief Request to set the current page's visibility.
557    * @param[in] visible Visible or not.
558    *
559    * @return true if changed successfully, false otherwise
560    */
561   bool SetVisibility(bool visible);
562
563   /**
564    * @brief Search and highlights the given string in the document.
565    * @param[in] text The text to find
566    * @param[in] options The options to find
567    * @param[in] maxMatchCount The maximum match count to find
568    *
569    * @return true if found & highlighted, false otherwise
570    */
571   bool HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount);
572
573   /**
574    * @brief Add dynamic certificate path.
575    * @param[in] host host that required client authentication
576    * @param[in] certPath the file path stored certificate
577    */
578   void AddDynamicCertificatePath(const std::string& host, const std::string& certPath);
579
580   /**
581    * @brief Get snapshot of the specified viewArea of page.
582    *
583    * @param[in] viewArea The rectangle of screen shot
584    * @param[in] scaleFactor The scale factor
585    *
586    * @return pixel data of screen shot
587    */
588   Dali::PixelData GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor);
589
590   /**
591    * @brief Request to get snapshot of the specified viewArea of page asynchronously.
592    *
593    * @param[in] viewArea The rectangle of screen shot
594    * @param[in] scaleFactor The scale factor
595    * @param[in] callback The callback for screen shot
596    *
597    * @return true if requested successfully, false otherwise
598    */
599   bool GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback);
600
601   /**
602    * @brief Asynchronous request to check if there is a video playing in the given view.
603    *
604    * @param[in] callback The callback called after checking if video is playing or not
605    *
606    * @return true if requested successfully, false otherwise
607    */
608   bool CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback);
609
610   /**
611    * @brief Set callback which alled upon geolocation permission request.
612    *
613    * @param[in] callback The callback for requesting geolocation permission
614    */
615   void RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback);
616
617   /**
618    * @brief Update display area.
619    * @param[in] displayArea The area to display web page
620    */
621   void UpdateDisplayArea(Dali::Rect<int32_t> displayArea);
622
623   /**
624    * @brief Enable video hole.
625    * @param[in] enabled True if video hole is enabled, false otherwise
626    */
627   void EnableVideoHole(bool enabled);
628
629   /**
630    * @brief Send hover events.
631    * @param[in] event The hover event would be sent.
632    */
633   bool SendHoverEvent(const HoverEvent& event);
634
635   /**
636    * @brief Send wheel events.
637    * @param[in] event The wheel event would be sent.
638    */
639   bool SendWheelEvent(const WheelEvent& event);
640
641   /**
642    * @brief Connect to this signal to be notified when frame is rendered.
643    *
644    * @return A signal object to connect with.
645    */
646   Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& FrameRenderedSignal();
647
648   /**
649    * @brief Callback to be called when page loading is started.
650    *
651    * @param[in] callback
652    */
653   void RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
654
655   /**
656    * @brief Callback to be called when page loading is in progress.
657    *
658    * @param[in] callback
659    */
660   void RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
661
662   /**
663    * @brief Callback to be called when page loading is finished.
664    *
665    * @param[in] callback
666    */
667   void RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
668
669   /**
670    * @brief Callback to be called when an error occurs in page loading.
671    *
672    * @param[in] callback
673    */
674   void RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback);
675
676   /**
677    * @brief Callback to be called when scroll edge is reached.
678    *
679    * @param[in] callback
680    */
681   void RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback);
682
683   /**
684    * @brief Callback to be called when url is changed.
685    *
686    * @param[in] callback
687    */
688   void RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback);
689
690   /**
691    * @brief Callback to be called when form repost decision is requested.
692    *
693    * @param[in] callback
694    */
695   void RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback);
696
697   /**
698    * @brief Callback to be called when console message will be logged.
699    *
700    * @param[in] callback
701    */
702   void RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback);
703
704   /**
705    * @brief Callback to be called when response policy would be decided.
706    *
707    * @param[in] callback
708    */
709   void RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback);
710
711   /**
712    * @brief Callback to be called when navigation policy would be decided.
713    *
714    * @param[in] callback
715    */
716   void RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback);
717
718   /**
719    * @brief Callback to be called when certificate need be confirmed.
720    *
721    * @param[in] callback
722    */
723   void RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
724
725   /**
726    * @brief Callback to be called when ssl certificate is changed.
727    *
728    * @param[in] callback
729    */
730   void RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
731
732   /**
733    * @brief Callback to be called when http authentication need be confirmed.
734    *
735    * @param[in] callback
736    */
737   void RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback);
738
739   /**
740    * @brief Callback to be called when context menu would be shown.
741    *
742    * @param[in] callback
743    */
744   void RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback);
745
746   /**
747    * @brief Callback to be called when context menu would be hidden.
748    *
749    * @param[in] callback
750    */
751   void RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback);
752
753   /**
754    * @brief Get a plain text of current web page asynchronously.
755    *
756    * @param[in] callback The callback function called asynchronously.
757    */
758   void GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback);
759
760 private: // Not intended for application developers
761   /**
762    * @brief Internal constructor
763    */
764   explicit DALI_INTERNAL WebEngine(Internal::Adaptor::WebEngine* internal);
765 };
766
767 } // namespace Dali
768
769 #endif // DALI_WEB_ENGINE_H