Add APIs for console message & loading error in web engine.
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / web-engine-plugin.h
1 #ifndef DALI_WEB_ENGINE_PLUGIN_H
2 #define DALI_WEB_ENGINE_PLUGIN_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/common/bitwise-enum.h>
23 #include <dali/public-api/images/native-image-interface.h>
24 #include <dali/public-api/math/rect.h>
25 #include <dali/public-api/signals/dali-signal.h>
26 #include <functional>
27 #include <memory>
28
29 namespace Dali
30 {
31 class KeyEvent;
32 class PixelData;
33 class TouchEvent;
34 class WebEngineBackForwardList;
35 class WebEngineConsoleMessage;
36 class WebEngineContext;
37 class WebEngineCookieManager;
38 class WebEngineFormRepostDecision;
39 class WebEngineRequestInterceptor;
40 class WebEngineLoadError;
41 class WebEngineSettings;
42 class HoverEvent;
43 class WheelEvent;
44
45 /**
46  * @brief WebEnginePlugin is an abstract interface, used by dali-adaptor to access WebEngine plugin.
47  * A concrete implementation must be created for each platform and provided as dynamic library.
48  */
49 class WebEnginePlugin
50 {
51 public:
52   /**
53    * @brief WebEngine signal type related with page loading.
54    */
55   using WebEnginePageLoadSignalType = Signal<void(const std::string&)>;
56
57   /**
58    * @brief WebView signal type related with page loading error.
59    */
60   using WebEnginePageLoadErrorSignalType = Signal<void(std::shared_ptr<Dali::WebEngineLoadError>)>;
61
62   // forward declaration.
63   enum class ScrollEdge;
64
65   /**
66    * @brief WebView signal type related with scroll edge reached.
67    */
68   using WebEngineScrollEdgeReachedSignalType = Signal<void(const ScrollEdge)>;
69
70   /**
71    * @brief WebView signal type related with page url changed.
72    */
73   using WebEngineUrlChangedSignalType = Signal<void(const std::string&)>;
74
75   /**
76    * @brief WebView signal type related with screen captured.
77    */
78   using ScreenshotCapturedCallback = std::function<void(Dali::PixelData)>;
79
80   /**
81    * @brief WebView signal type related with geolocation permission.
82    *  Host and protocol of security origin will be provided when requesting
83    *  geolocation permission.
84    *  It returns true if a pop-up is created successfully, false otherwise.
85    */
86   using GeolocationPermissionCallback = std::function<bool(const std::string&, const std::string&)>;
87
88   /**
89    * @brief WebView signal type related with video playing.
90    */
91   using VideoPlayingCallback = std::function<void(bool)>;
92
93   /**
94    * @brief WebView signal type related with http request interceptor.
95    */
96   using WebEngineRequestInterceptorSignalType = Signal<void(std::shared_ptr<Dali::WebEngineRequestInterceptor>)>;
97
98   /**
99    * @brief WebView signal type related with console message will be logged.
100    */
101   using WebEngineConsoleMessageSignalType = Signal<void(std::shared_ptr<Dali::WebEngineConsoleMessage>)>;
102
103   /**
104    * @brief Alert callback when JavaScript alert is called with a message.
105    *  It returns true if a pop-up is created successfully, false otherwise.
106    */
107   using JavaScriptAlertCallback = std::function<bool(const std::string&)>;
108
109   /**
110    * @brief Confirm callback when JavaScript confirm is called with a message.
111    *  It returns true if a pop-up is created successfully, false otherwise.
112    */
113   using JavaScriptConfirmCallback = std::function<bool(const std::string&)>;
114
115   /**
116    * @brief Prompt callback when JavaScript prompt is called with a message
117    *  and an optional value that is the default value for the input field.
118    *  It returns true if a pop-up is created successfully, false otherwise.
119    */
120   using JavaScriptPromptCallback = std::function<bool(const std::string&, const std::string&)>;
121
122   /**
123    * @brief WebView signal type related with form repost decision.
124    */
125   using WebEngineFormRepostDecisionSignalType = Signal<void(std::shared_ptr<Dali::WebEngineFormRepostDecision>)>;
126
127   /**
128    * @brief WebView signal type related with frame rendered.
129    */
130   using WebEngineFrameRenderedSignalType = Signal<void(void)>;
131
132   /**
133    * @brief Enumeration for the scroll edge.
134    */
135   enum class ScrollEdge
136   {
137     LEFT,   ///< Left edge reached.
138     RIGHT,  ///< Right edge reached.
139     TOP,    ///< Top edge reached.
140     BOTTOM, ///< Bottom edge reached.
141   };
142
143   /**
144    * @brief Enumeration that provides the option to find text.
145    */
146   enum class FindOption
147   {
148     NONE                               = 0,      ///<  No search flags, this means a case sensitive, no wrap, forward only search
149     CASE_INSENSITIVE                   = 1 << 0, ///<  Case insensitive search
150     AT_WORD_STARTS                     = 1 << 1, ///<  Search text only at the beginning of the words
151     TREAT_MEDIAL_CAPITAL_AS_WORD_START = 1 << 2, ///<  Treat capital letters in the middle of words as word start
152     BACKWARDS                          = 1 << 3, ///<  Search backwards
153     WRAP_AROUND                        = 1 << 4, ///<  If not present the search stops at the end of the document
154     SHOW_OVERLAY                       = 1 << 5, ///<  Show overlay
155     SHOW_FIND_INDICATOR                = 1 << 6, ///<  Show indicator
156     SHOW_HIGHLIGHT                     = 1 << 7, ///<  Show highlight
157   };
158
159   /**
160    * @brief Constructor.
161    */
162   WebEnginePlugin() = default;
163
164   /**
165    * @brief Destructor.
166    */
167   virtual ~WebEnginePlugin() = default;
168
169   /**
170    * @brief Create WebEngine instance.
171    *
172    * @param [in] width The width of Web
173    * @param [in] height The height of Web
174    * @param [in] locale The locale of Web
175    * @param [in] timezoneId The timezoneID of Web
176    */
177   virtual void Create(int width, int height, const std::string& locale, const std::string& timezoneId) = 0;
178
179   /**
180    * @brief Create WebEngine instance.
181    *
182    * @param [in] width The width of Web
183    * @param [in] height The height of Web
184    * @param [in] argc The count of application arguments
185    * @param [in] argv The string array of application arguments
186    */
187   virtual void Create(int width, int height, int argc, char** argv) = 0;
188
189   /**
190    * @brief Destroy WebEngine instance.
191    */
192   virtual void Destroy() = 0;
193
194   /**
195    * @brief Get settings of WebEngine.
196    */
197   virtual WebEngineSettings& GetSettings() const = 0;
198
199   /**
200    * @brief Get context of WebEngine.
201    */
202   virtual WebEngineContext& GetContext() const = 0;
203
204   /**
205    * @brief Get cookie manager of WebEngine.
206    */
207   virtual WebEngineCookieManager& GetCookieManager() const = 0;
208
209   /**
210    * @brief Get back-forward list of WebEngine.
211    */
212   virtual WebEngineBackForwardList& GetBackForwardList() const = 0;
213
214   /**
215    * @brief Load a web page based on a given URL.
216    *
217    * @param [in] url The URL of the resource to load
218    */
219   virtual void LoadUrl(const std::string& url) = 0;
220
221   /**
222    * @brief Return the title of the Web.
223    *
224    * @return The title of web page
225    */
226   virtual std::string GetTitle() const = 0;
227
228   /**
229    * @brief Return the Favicon of the Web.
230    *
231    * @return Favicon of Dali::PixelData& type
232    */
233   virtual Dali::PixelData GetFavicon() const = 0;
234
235   /**
236    * @brief Get image to render.
237    */
238   virtual NativeImageInterfacePtr GetNativeImageSource() = 0;
239
240   /**
241    * @brief Returns the URL of the Web.
242    *
243    * @return Url of string type
244    */
245   virtual const std::string& GetUrl() = 0;
246
247   /**
248    * @brief Load a given string as web contents.
249    *
250    * @param [in] htmlString The string to use as the contents of the web page
251    */
252   virtual void LoadHtmlString(const std::string& htmlString) = 0;
253
254   /**
255    * @brief Load the specified html string as the content of the view overriding current history entry
256    *
257    * @param[in] html HTML data to load
258    * @param[in] basicUri Base URL used for relative paths to external objects
259    * @param[in] unreachableUrl URL that could not be reached
260    *
261    * @return true if successfully loaded, false otherwise
262    */
263   virtual bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl) = 0;
264
265   /**
266    * @brief Request loading the given contents by MIME type into the view object
267    *
268    * @param[in] contents The content to load
269    * @param[in] contentSize The size of contents (in bytes)
270    * @param[in] mimeType The type of contents, if 0 is given "text/html" is assumed
271    * @param[in] encoding The encoding for contents, if 0 is given "UTF-8" is assumed
272    * @param[in] baseUri The base URI to use for relative resources
273    *
274    * @return true if successfully request, false otherwise
275    */
276   virtual bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri) = 0;
277
278   /**
279    * @brief Reload the Web.
280    */
281   virtual void Reload() = 0;
282
283   /**
284    * @brief Reload the current page's document without cache
285    */
286   virtual bool ReloadWithoutCache() = 0;
287
288   /**
289    * @brief Stop loading web contents on the current page.
290    */
291   virtual void StopLoading() = 0;
292
293   /**
294    * @brief Suspend the operation associated with the view.
295    */
296   virtual void Suspend() = 0;
297
298   /**
299    * @brief Resume the operation associated with the view object after calling Suspend().
300    */
301   virtual void Resume() = 0;
302
303   /**
304    * @brief To suspend all url loading
305    */
306   virtual void SuspendNetworkLoading() = 0;
307
308   /**
309    * @brief To resume new url network loading
310    */
311   virtual void ResumeNetworkLoading() = 0;
312
313   /**
314    * @brief Add custom header
315    *
316    * @param[in] name custom header name to add the custom header
317    * @param[in] value custom header value to add the custom header
318    *
319    * @return true if succeeded, false otherwise
320    */
321   virtual bool AddCustomHeader(const std::string& name, const std::string& value) = 0;
322
323   /**
324    * @brief Remove custom header
325    *
326    * @param[in] name custom header name to remove the custom header
327    *
328    * @return true if succeeded, false otherwise
329    */
330   virtual bool RemoveCustomHeader(const std::string& name) = 0;
331
332   /**
333    * @brief Start the inspector server
334    *
335    * @param[in] port port number
336    *
337    * @return the port number
338    */
339   virtual uint32_t StartInspectorServer(uint32_t port) = 0;
340
341   /**
342    * @brief Stop the inspector server
343    *
344    * @return true if succeeded, false otherwise
345    */
346   virtual bool StopInspectorServer() = 0;
347
348   /**
349    * @brief Scroll web page of view by deltaX and deltaY.
350    *
351    * @param[in] deltaX horizontal offset to scroll
352    * @param[in] deltaY vertical offset to scroll
353    */
354   virtual void ScrollBy(int deltaX, int deltaY) = 0;
355
356   /**
357    * @brief Scroll edge of view by deltaX and deltaY.
358    *
359    * @param[in] deltaX horizontal offset to scroll
360    * @param[in] deltaY vertical offset to scroll
361    *
362    * @return true if succeeded, false otherwise
363    */
364   virtual bool ScrollEdgeBy(int deltaX, int deltaY) = 0;
365
366   /**
367    * @brief Scroll to the specified position of the given view.
368    */
369   virtual void SetScrollPosition(int x, int y) = 0;
370
371   /**
372    * @brief Get the current scroll position of the given view.
373    */
374   virtual Dali::Vector2 GetScrollPosition() const = 0;
375
376   /**
377    * @brief Get the possible scroll size of the given view.
378    */
379   virtual Dali::Vector2 GetScrollSize() const = 0;
380
381   /**
382    * @brief Get the last known content's size.
383    */
384   virtual Dali::Vector2 GetContentSize() const = 0;
385
386   /**
387    * @brief Return whether forward is possible.
388    *
389    * @return True if forward is possible, false otherwise
390    */
391   virtual bool CanGoForward() = 0;
392
393   /**
394    * @brief Go to forward.
395    */
396   virtual void GoForward() = 0;
397
398   /**
399    * @brief Return whether backward is possible.
400    *
401    * @return True if backward is possible, false otherwise
402    */
403   virtual bool CanGoBack() = 0;
404
405   /**
406    * @brief Go to back.
407    */
408   virtual void GoBack() = 0;
409
410   /**
411    * @brief Evaluates JavaScript code represented as a string.
412    *
413    * @param[in] script The JavaScript code
414    * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
415    */
416   virtual void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler) = 0;
417
418   /**
419    * @brief Add a message handler into JavaScript.
420    *
421    * @param[in] exposedObjectName The name of exposed object
422    * @param[in] handler The callback function
423    */
424   virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler) = 0;
425
426   /**
427    * @brief Register a callback for JavaScript alert.
428    *
429    * @param[in] callback The callback function
430    */
431   virtual void RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback) = 0;
432
433   /**
434    * @brief Reply for JavaScript alert.
435    */
436   virtual void JavaScriptAlertReply() = 0;
437
438   /**
439    * @brief Register a callback for JavaScript confirm.
440    *
441    * @param[in] callback The callback function
442    */
443   virtual void RegisterJavaScriptConfirmCallback(JavaScriptConfirmCallback callback) = 0;
444
445   /**
446    * @brief Reply for JavaScript confirm.
447    */
448   virtual void JavaScriptConfirmReply(bool confirmed) = 0;
449
450   /**
451    * @brief Register a callback for JavaScript prompt.
452    *
453    * @param[in] callback The callback function
454    */
455   virtual void RegisterJavaScriptPromptCallback(JavaScriptPromptCallback callback) = 0;
456
457   /**
458    * @brief Reply for JavaScript prompt.
459    */
460   virtual void JavaScriptPromptReply(const std::string& result) = 0;
461
462   /**
463    * @brief Clear the history of Web.
464    */
465   virtual void ClearHistory() = 0;
466
467   /**
468    * @brief Clear all tiles resources of Web.
469    */
470   virtual void ClearAllTilesResources() = 0;
471
472   /**
473    * @brief Get user agent string.
474    *
475    * @return The string value of user agent
476    */
477   virtual const std::string& GetUserAgent() const = 0;
478
479   /**
480    * @brief Set user agent string.
481    *
482    * @param[in] userAgent The string value of user agent
483    */
484   virtual void SetUserAgent(const std::string& userAgent) = 0;
485
486   /**
487    * @brief Sets size of Web Page.
488    */
489   virtual void SetSize(int width, int height) = 0;
490
491   /**
492    * @brief Set background color of web page.
493    *
494    * @param[in] color Background color
495    */
496   virtual void SetDocumentBackgroundColor(Dali::Vector4 color) = 0;
497
498   /**
499    * @brief Clear tiles when hidden.
500    *
501    * @param[in] cleared Whether tiles are cleared or not
502    */
503   virtual void ClearTilesWhenHidden(bool cleared) = 0;
504
505   /**
506    * @brief Set multiplier of cover area of tile.
507    *
508    * @param[in] multiplier The multiplier of cover area
509    */
510   virtual void SetTileCoverAreaMultiplier(float multiplier) = 0;
511
512   /**
513    * @brief Enable cursor by client.
514    *
515    * @param[in] enabled Whether cursor is enabled or not
516    */
517   virtual void EnableCursorByClient(bool enabled) = 0;
518
519   /**
520    * @brief Get the selected text.
521    *
522    * @return the selected text
523    */
524   virtual std::string GetSelectedText() const = 0;
525
526   /**
527    * @brief Send Touch Events.
528    */
529   virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
530
531   /**
532    * @brief Send Key Events.
533    */
534   virtual bool SendKeyEvent(const KeyEvent& event) = 0;
535
536   /**
537    * @brief Support mouse events or not.
538    * @param[in] enabled True if enabled, false othewise.
539    */
540   virtual void EnableMouseEvents(bool enabled) = 0;
541
542   /**
543    * @brief Support key events or not.
544    * @param[in] enabled True if enabled, false othewise.
545    */
546   virtual void EnableKeyEvents(bool enabled) = 0;
547
548   /**
549    * @brief Set focus.
550    * @param[in] focused True if focus is gained, false lost.
551    */
552   virtual void SetFocus(bool focused) = 0;
553
554   /**
555    * @brief Set zoom factor of the current page.
556    * @param[in] zoomFactor a new factor to be set.
557    */
558   virtual void SetPageZoomFactor(float zoomFactor) = 0;
559
560   /**
561    * @brief Query the current zoom factor of the page。
562    * @return The current page zoom factor.
563    */
564   virtual float GetPageZoomFactor() const = 0;
565
566   /**
567    * @brief Set the current text zoom level。.
568    * @param[in] zoomFactor a new factor to be set.
569    */
570   virtual void SetTextZoomFactor(float zoomFactor) = 0;
571
572   /**
573    * @brief Get the current text zoom level.
574    * @return The current text zoom factor.
575    */
576   virtual float GetTextZoomFactor() const = 0;
577
578   /**
579    * @brief Get the current load progress of the page.
580    * @return The load progress of the page.
581    */
582   virtual float GetLoadProgressPercentage() const = 0;
583
584   /**
585    * @brief Scale the current page, centered at the given point.
586    * @param[in] scaleFactor a new factor to be scaled.
587    * @param[in] point a center coordinate.
588    */
589   virtual void SetScaleFactor(float scaleFactor, Dali::Vector2 point) = 0;
590
591   /**
592    * @brief Get the current scale factor of the page.
593    * @return The current scale factor.
594    */
595   virtual float GetScaleFactor() const = 0;
596
597   /**
598    * @brief Request to activate/deactivate the accessibility usage set by web app.
599    * @param[in] activated Activate accessibility or not.
600    */
601   virtual void ActivateAccessibility(bool activated) = 0;
602
603   /**
604    * @brief Request to set the current page's visibility.
605    * @param[in] visible Visible or not.
606    *
607    * @return true if succeeded, false otherwise
608    */
609   virtual bool SetVisibility(bool visible) = 0;
610
611   /**
612    * @brief Search and highlight the given string in the document.
613    * @param[in] text The text to find
614    * @param[in] options The options to find
615    * @param[in] maxMatchCount The maximum match count to find
616    *
617    * @return true if found & highlighted, false otherwise
618    */
619   virtual bool HighlightText(const std::string& text, FindOption options, uint32_t maxMatchCount) = 0;
620
621   /**
622    * @brief Add dynamic certificate path.
623    * @param[in] host host that required client authentication
624    * @param[in] certPath the file path stored certificate
625    */
626   virtual void AddDynamicCertificatePath(const std::string& host, const std::string& certPath) = 0;
627
628   /**
629    * @brief Get snapshot of the specified viewArea of page.
630    *
631    * @param[in] viewArea The rectangle of screen shot
632    * @param[in] scaleFactor The scale factor
633    *
634    * @return pixel data of screen shot
635    */
636   virtual Dali::PixelData GetScreenshot(Dali::Rect<int> viewArea, float scaleFactor) = 0;
637
638   /**
639    * @brief Request to get snapshot of the specified viewArea of page asynchronously.
640    *
641    * @param[in] viewArea The rectangle of screen shot
642    * @param[in] scaleFactor The scale factor
643    * @param[in] callback The callback for screen shot
644    *
645    * @return true if requested successfully, false otherwise
646    */
647   virtual bool GetScreenshotAsynchronously(Dali::Rect<int> viewArea, float scaleFactor, ScreenshotCapturedCallback callback) = 0;
648
649   /**
650    * @brief Asynchronously request to check if there is a video playing in the given view.
651    *
652    * @param[in] callback The callback called after checking if video is playing or not
653    *
654    * @return true if requested successfully, false otherwise
655    */
656   virtual bool CheckVideoPlayingAsynchronously(VideoPlayingCallback callback) = 0;
657
658   /**
659    * @brief Set callback which will be called upon geolocation permission request.
660    *
661    * @param[in] callback The callback for requesting geolocation permission
662    */
663   virtual void RegisterGeolocationPermissionCallback(GeolocationPermissionCallback callback) = 0;
664
665   /**
666    * @brief Update display area.
667    * @param[in] displayArea The display area need be updated.
668    */
669   virtual void UpdateDisplayArea(Dali::Rect<int> displayArea) = 0;
670
671   /**
672    * @brief Enable video hole.
673    * @param[in] enabled True if enabled, false othewise.
674    */
675   virtual void EnableVideoHole(bool enabled) = 0;
676
677   /**
678    * @brief Send Hover Events.
679    * @param[in] event The hover event would be sent.
680    */
681   virtual bool SendHoverEvent(const HoverEvent& event) = 0;
682
683   /**
684    * @brief Send Wheel Events.
685    * @param[in] event The wheel event would be sent.
686    */
687   virtual bool SendWheelEvent(const WheelEvent& event) = 0;
688
689   /**
690    * @brief Connect to this signal to be notified when page loading is started.
691    *
692    * @return A signal object to connect with.
693    */
694   virtual WebEnginePageLoadSignalType& PageLoadStartedSignal() = 0;
695
696   /**
697    * @brief Connect to this signal to be notified when page loading is in progress.
698    *
699    * @return A signal object to connect with.
700    */
701   virtual WebEnginePageLoadSignalType& PageLoadInProgressSignal() = 0;
702
703   /**
704    * @brief Connect to this signal to be notified when page loading is finished.
705    *
706    * @return A signal object to connect with.
707    */
708   virtual WebEnginePageLoadSignalType& PageLoadFinishedSignal() = 0;
709
710   /**
711    * @brief Connect to this signal to be notified when an error occurs in page loading.
712    *
713    * @return A signal object to connect with.
714    */
715   virtual WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() = 0;
716
717   /**
718    * @brief Connect to this signal to be notified when scroll edge is reached.
719    *
720    * @return A signal object to connect with.
721    */
722   virtual WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal() = 0;
723
724   /**
725    * @brief Connect to this signal to be notified when url is changed.
726    *
727    * @return A signal object to connect with.
728    */
729   virtual WebEngineUrlChangedSignalType& UrlChangedSignal() = 0;
730
731   /**
732    * @brief Connect to this signal to be notified when form repost decision is requested.
733    *
734    * @return A signal object to connect with.
735    */
736   virtual WebEngineFormRepostDecisionSignalType& FormRepostDecisionSignal() = 0;
737
738   /**
739    * @brief Connect to this signal to be notified when frame is rendered.
740    *
741    * @return A signal object to connect with.
742    */
743   virtual WebEngineFrameRenderedSignalType& FrameRenderedSignal() = 0;
744
745   /**
746    * @brief Connects to this signal to be notified when http request need be intercepted.
747    *
748    * @return A signal object to connect with.
749    */
750   virtual WebEngineRequestInterceptorSignalType& RequestInterceptorSignal() = 0;
751
752   /**
753    * @brief Connect to this signal to be notified when console message will be logged.
754    *
755    * @return A signal object to connect with.
756    */
757   virtual WebEngineConsoleMessageSignalType& ConsoleMessageSignal() = 0;
758 };
759
760 // specialization has to be done in the same namespace
761 template<>
762 struct EnableBitMaskOperators<WebEnginePlugin::FindOption>
763 {
764   static const bool ENABLE = true;
765 };
766
767 } // namespace Dali
768
769 #endif