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