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