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