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