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