1 #ifndef DALI_WEB_ENGINE_PLUGIN_H
2 #define DALI_WEB_ENGINE_PLUGIN_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
26 #include <dali/devel-api/adaptor-framework/web-engine-hit-test.h>
27 #include <dali/devel-api/common/bitwise-enum.h>
28 #include <dali/public-api/images/native-image-interface.h>
29 #include <dali/public-api/math/rect.h>
30 #include <dali/public-api/signals/dali-signal.h>
37 class WebEngineBackForwardList;
38 class WebEngineCertificate;
39 class WebEngineConsoleMessage;
40 class WebEngineContext;
41 class WebEngineContextMenu;
42 class WebEngineCookieManager;
43 class WebEngineFormRepostDecision;
44 class WebEngineHitTest;
45 class WebEngineHttpAuthHandler;
46 class WebEngineLoadError;
47 class WebEnginePolicyDecision;
48 class WebEngineRequestInterceptor;
49 class WebEngineSettings;
54 * @brief WebEnginePlugin is an abstract interface, used by dali-adaptor to access WebEngine plugin.
55 * A concrete implementation must be created for each platform and provided as dynamic library.
61 * @brief WebView signal type related with frame rendered.
63 using WebEngineFrameRenderedSignalType = Signal<void(void)>;
66 * @brief WebEngine callback related with page loading.
68 using WebEnginePageLoadCallback = std::function<void(const std::string&)>;
71 * @brief WebView callback related with page loading error.
73 using WebEnginePageLoadErrorCallback = std::function<void(std::unique_ptr<Dali::WebEngineLoadError>)>;
75 // forward declaration.
76 enum class ScrollEdge;
79 * @brief WebView callback related with scroll edge reached.
81 using WebEngineScrollEdgeReachedCallback = std::function<void(const ScrollEdge)>;
84 * @brief WebView callback related with page url changed.
86 using WebEngineUrlChangedCallback = std::function<void(const std::string&)>;
89 * @brief WebView callback related with screen captured.
91 using ScreenshotCapturedCallback = std::function<void(Dali::PixelData)>;
94 * @brief WebView callback related with geolocation permission.
95 * Host and protocol of security origin will be provided when requesting
96 * geolocation permission.
97 * It returns true if a pop-up is created successfully, false otherwise.
99 using GeolocationPermissionCallback = std::function<bool(const std::string&, const std::string&)>;
102 * @brief WebView callback related with video playing.
104 using VideoPlayingCallback = std::function<void(bool)>;
107 * @brief WebView callback related with http request interceptor.
109 using WebEngineRequestInterceptorCallback = std::function<void(std::unique_ptr<Dali::WebEngineRequestInterceptor>)>;
112 * @brief WebView callback related with console message logged.
114 using WebEngineConsoleMessageReceivedCallback = std::function<void(std::unique_ptr<Dali::WebEngineConsoleMessage>)>;
117 * @brief WebView callback related with certificate changed.
119 using WebEngineCertificateCallback = std::function<void(std::unique_ptr<Dali::WebEngineCertificate>)>;
122 * @brief WebView callback related with http authentication.
124 using WebEngineHttpAuthHandlerCallback = std::function<void(std::unique_ptr<Dali::WebEngineHttpAuthHandler>)>;
127 * @brief WebView callback related with context menu shown.
129 using WebEngineContextMenuShownCallback = std::function<void(std::unique_ptr<Dali::WebEngineContextMenu>)>;
132 * @brief WebView callback related with context menu hidden.
134 using WebEngineContextMenuHiddenCallback = std::function<void(std::unique_ptr<Dali::WebEngineContextMenu>)>;
137 * @brief Message result callback when JavaScript is executed with a message.
139 using JavaScriptMessageHandlerCallback = std::function<void(const std::string&)>;
142 * @brief Alert callback when JavaScript alert is called with a message.
143 * It returns true if a pop-up is created successfully, false otherwise.
145 using JavaScriptAlertCallback = std::function<bool(const std::string&)>;
148 * @brief Confirm callback when JavaScript confirm is called with a message.
149 * It returns true if a pop-up is created successfully, false otherwise.
151 using JavaScriptConfirmCallback = std::function<bool(const std::string&)>;
154 * @brief Prompt callback when JavaScript prompt is called with a message
155 * and an optional value that is the default value for the input field.
156 * It returns true if a pop-up is created successfully, false otherwise.
158 using JavaScriptPromptCallback = std::function<bool(const std::string&, const std::string&)>;
161 * @brief WebView callback related with form repost decision.
163 using WebEngineFormRepostDecidedCallback = std::function<void(std::unique_ptr<Dali::WebEngineFormRepostDecision>)>;
166 * @brief WebView callback related with frame rendered.
168 using WebEngineFrameRenderedCallback = std::function<void(void)>;
171 * @brief WebView callback related with response policy would be decided.
173 using WebEngineResponsePolicyDecidedCallback = std::function<void(std::unique_ptr<Dali::WebEnginePolicyDecision>)>;
176 * @brief Hit test callback called after hit test is created asynchronously.
178 using WebEngineHitTestCreatedCallback = std::function<bool(std::unique_ptr<Dali::WebEngineHitTest>)>;
181 * @brief The callback to be called when the web engine received a plain text of current web page.
183 using PlainTextReceivedCallback = std::function<void(const std::string&)>;
186 * @brief Enumeration for the scroll edge.
188 enum class ScrollEdge
190 LEFT, ///< Left edge reached.
191 RIGHT, ///< Right edge reached.
192 TOP, ///< Top edge reached.
193 BOTTOM, ///< Bottom edge reached.
197 * @brief Enumeration that provides the option to find text.
199 enum class FindOption
201 NONE = 0, ///< No search flags, this means a case sensitive, no wrap, forward only search
202 CASE_INSENSITIVE = 1 << 0, ///< Case insensitive search
203 AT_WORD_STARTS = 1 << 1, ///< Search text only at the beginning of the words
204 TREAT_MEDIAL_CAPITAL_AS_WORD_START = 1 << 2, ///< Treat capital letters in the middle of words as word start
205 BACKWARDS = 1 << 3, ///< Search backwards
206 WRAP_AROUND = 1 << 4, ///< If not present the search stops at the end of the document
207 SHOW_OVERLAY = 1 << 5, ///< Show overlay
208 SHOW_FIND_INDICATOR = 1 << 6, ///< Show indicator
209 SHOW_HIGHLIGHT = 1 << 7, ///< Show highlight
213 * @brief Constructor.
215 WebEnginePlugin() = default;
220 virtual ~WebEnginePlugin() = default;
223 * @brief Create WebEngine instance.
225 * @param [in] width The width of Web
226 * @param [in] height The height of Web
227 * @param [in] locale The locale of Web
228 * @param [in] timezoneId The timezoneID of Web
230 virtual void Create(uint32_t width, uint32_t height, const std::string& locale, const std::string& timezoneId) = 0;
233 * @brief Create WebEngine instance.
235 * @param [in] width The width of Web
236 * @param [in] height The height of Web
237 * @param [in] argc The count of application arguments
238 * @param [in] argv The string array of application arguments
240 virtual void Create(uint32_t width, uint32_t height, uint32_t argc, char** argv) = 0;
243 * @brief Destroy WebEngine instance.
245 virtual void Destroy() = 0;
248 * @brief Get settings of WebEngine.
250 virtual WebEngineSettings& GetSettings() const = 0;
253 * @brief Get context of WebEngine.
255 virtual WebEngineContext& GetContext() const = 0;
258 * @brief Get cookie manager of WebEngine.
260 virtual WebEngineCookieManager& GetCookieManager() const = 0;
263 * @brief Get back-forward list of WebEngine.
265 virtual WebEngineBackForwardList& GetBackForwardList() const = 0;
268 * @brief Load a web page based on a given URL.
270 * @param [in] url The URL of the resource to load
272 virtual void LoadUrl(const std::string& url) = 0;
275 * @brief Return the title of the Web.
277 * @return The title of web page
279 virtual std::string GetTitle() const = 0;
282 * @brief Return the Favicon of the Web.
284 * @return Favicon of Dali::PixelData& type
286 virtual Dali::PixelData GetFavicon() const = 0;
289 * @brief Get image to render.
291 virtual NativeImageInterfacePtr GetNativeImageSource() = 0;
294 * @brief Return the URL of the Web.
296 * @return Url of string type
298 virtual std::string GetUrl() const = 0;
301 * @brief Load a given string as web contents.
303 * @param [in] htmlString The string to use as the contents of the web page
305 virtual void LoadHtmlString(const std::string& htmlString) = 0;
308 * @brief Load the specified html string as the content of the view overriding current history entry
310 * @param[in] html HTML data to load
311 * @param[in] basicUri Base URL used for relative paths to external objects
312 * @param[in] unreachableUrl URL that could not be reached
314 * @return true if successfully loaded, false otherwise
316 virtual bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl) = 0;
319 * @brief Request loading the given contents by MIME type into the view object
321 * @param[in] contents The content to load
322 * @param[in] contentSize The size of contents (in bytes)
323 * @param[in] mimeType The type of contents, if 0 is given "text/html" is assumed
324 * @param[in] encoding The encoding for contents, if 0 is given "UTF-8" is assumed
325 * @param[in] baseUri The base URI to use for relative resources
327 * @return true if successfully request, false otherwise
329 virtual bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri) = 0;
332 * @brief Reload the Web.
334 virtual void Reload() = 0;
337 * @brief Reload the current page's document without cache
339 virtual bool ReloadWithoutCache() = 0;
342 * @brief Stop loading web contents on the current page.
344 virtual void StopLoading() = 0;
347 * @brief Suspend the operation associated with the view.
349 virtual void Suspend() = 0;
352 * @brief Resume the operation associated with the view object after calling Suspend().
354 virtual void Resume() = 0;
357 * @brief To suspend all url loading
359 virtual void SuspendNetworkLoading() = 0;
362 * @brief To resume new url network loading
364 virtual void ResumeNetworkLoading() = 0;
367 * @brief Add custom header
369 * @param[in] name custom header name to add the custom header
370 * @param[in] value custom header value to add the custom header
372 * @return true if succeeded, false otherwise
374 virtual bool AddCustomHeader(const std::string& name, const std::string& value) = 0;
377 * @brief Remove custom header
379 * @param[in] name custom header name to remove the custom header
381 * @return true if succeeded, false otherwise
383 virtual bool RemoveCustomHeader(const std::string& name) = 0;
386 * @brief Start the inspector server
388 * @param[in] port port number
390 * @return the port number
392 virtual uint32_t StartInspectorServer(uint32_t port) = 0;
395 * @brief Stop the inspector server
397 * @return true if succeeded, false otherwise
399 virtual bool StopInspectorServer() = 0;
402 * @brief Scroll web page of view by deltaX and deltaY.
404 * @param[in] deltaX horizontal offset to scroll
405 * @param[in] deltaY vertical offset to scroll
407 virtual void ScrollBy(int32_t deltaX, int32_t deltaY) = 0;
410 * @brief Scroll edge of view by deltaX and deltaY.
412 * @param[in] deltaX horizontal offset to scroll
413 * @param[in] deltaY vertical offset to scroll
415 * @return true if succeeded, false otherwise
417 virtual bool ScrollEdgeBy(int32_t deltaX, int32_t deltaY) = 0;
420 * @brief Scroll to the specified position of the given view.
422 virtual void SetScrollPosition(int32_t x, int32_t y) = 0;
425 * @brief Get the current scroll position of the given view.
427 virtual Dali::Vector2 GetScrollPosition() const = 0;
430 * @brief Get the possible scroll size of the given view.
432 virtual Dali::Vector2 GetScrollSize() const = 0;
435 * @brief Get the last known content's size.
437 virtual Dali::Vector2 GetContentSize() const = 0;
440 * @brief Return whether forward is possible.
442 * @return True if forward is possible, false otherwise
444 virtual bool CanGoForward() = 0;
447 * @brief Go to forward.
449 virtual void GoForward() = 0;
452 * @brief Return whether backward is possible.
454 * @return True if backward is possible, false otherwise
456 virtual bool CanGoBack() = 0;
461 virtual void GoBack() = 0;
464 * @brief Evaluate JavaScript code represented as a string.
466 * @param[in] script The JavaScript code
467 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
469 virtual void EvaluateJavaScript(const std::string& script, JavaScriptMessageHandlerCallback resultHandler) = 0;
472 * @brief Add a message handler into JavaScript.
474 * @param[in] exposedObjectName The name of exposed object
475 * @param[in] handler The callback function
477 virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, JavaScriptMessageHandlerCallback handler) = 0;
480 * @brief Register a callback for JavaScript alert.
482 * @param[in] callback The callback function
484 virtual void RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback) = 0;
487 * @brief Reply for JavaScript alert.
489 virtual void JavaScriptAlertReply() = 0;
492 * @brief Register a callback for JavaScript confirm.
494 * @param[in] callback The callback function
496 virtual void RegisterJavaScriptConfirmCallback(JavaScriptConfirmCallback callback) = 0;
499 * @brief Reply for JavaScript confirm.
501 virtual void JavaScriptConfirmReply(bool confirmed) = 0;
504 * @brief Register a callback for JavaScript prompt.
506 * @param[in] callback The callback function
508 virtual void RegisterJavaScriptPromptCallback(JavaScriptPromptCallback callback) = 0;
511 * @brief Reply for JavaScript prompt.
513 virtual void JavaScriptPromptReply(const std::string& result) = 0;
516 * @brief Create a new hit test.
518 * @param[in] x the horizontal position to query
519 * @param[in] y the vertical position to query
520 * @param[in] mode the mode of hit test
522 * @return a new hit test object.
524 virtual std::unique_ptr<Dali::WebEngineHitTest> CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode) = 0;
527 * @brief create a hit test asynchronously.
529 * @param[in] x the horizontal position to query
530 * @param[in] y the vertical position to query
531 * @param[in] mode the mode of hit test
532 * @param[in] callback The callback function
534 * @return true if succeeded, false otherwise
536 virtual bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, WebEngineHitTestCreatedCallback callback) = 0;
539 * @brief Clear the history of Web.
541 virtual void ClearHistory() = 0;
544 * @brief Clear all tiles resources of Web.
546 virtual void ClearAllTilesResources() = 0;
549 * @brief Get user agent string.
551 * @return The string value of user agent
553 virtual std::string GetUserAgent() const = 0;
556 * @brief Set user agent string.
558 * @param[in] userAgent The string value of user agent
560 virtual void SetUserAgent(const std::string& userAgent) = 0;
563 * @brief Set size of Web Page.
565 virtual void SetSize(uint32_t width, uint32_t height) = 0;
568 * @brief Set background color of web page.
570 * @param[in] color Background color
572 virtual void SetDocumentBackgroundColor(Dali::Vector4 color) = 0;
575 * @brief Clear tiles when hidden.
577 * @param[in] cleared Whether tiles are cleared or not
579 virtual void ClearTilesWhenHidden(bool cleared) = 0;
582 * @brief Set multiplier of cover area of tile.
584 * @param[in] multiplier The multiplier of cover area
586 virtual void SetTileCoverAreaMultiplier(float multiplier) = 0;
589 * @brief Enable cursor by client.
591 * @param[in] enabled Whether cursor is enabled or not
593 virtual void EnableCursorByClient(bool enabled) = 0;
596 * @brief Get the selected text.
598 * @return the selected text
600 virtual std::string GetSelectedText() const = 0;
603 * @brief Send Touch Events.
605 virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
608 * @brief Send Key Events.
610 virtual bool SendKeyEvent(const KeyEvent& event) = 0;
613 * @brief Support mouse events or not.
614 * @param[in] enabled True if enabled, false othewise.
616 virtual void EnableMouseEvents(bool enabled) = 0;
619 * @brief Support key events or not.
620 * @param[in] enabled True if enabled, false othewise.
622 virtual void EnableKeyEvents(bool enabled) = 0;
626 * @param[in] focused True if focus is gained, false lost.
628 virtual void SetFocus(bool focused) = 0;
631 * @brief Set zoom factor of the current page.
632 * @param[in] zoomFactor a new factor to be set.
634 virtual void SetPageZoomFactor(float zoomFactor) = 0;
637 * @brief Query the current zoom factor of the page。
638 * @return The current page zoom factor.
640 virtual float GetPageZoomFactor() const = 0;
643 * @brief Set the current text zoom level。.
644 * @param[in] zoomFactor a new factor to be set.
646 virtual void SetTextZoomFactor(float zoomFactor) = 0;
649 * @brief Get the current text zoom level.
650 * @return The current text zoom factor.
652 virtual float GetTextZoomFactor() const = 0;
655 * @brief Get the current load progress of the page.
656 * @return The load progress of the page.
658 virtual float GetLoadProgressPercentage() const = 0;
661 * @brief Scale the current page, centered at the given point.
662 * @param[in] scaleFactor a new factor to be scaled.
663 * @param[in] point a center coordinate.
665 virtual void SetScaleFactor(float scaleFactor, Dali::Vector2 point) = 0;
668 * @brief Get the current scale factor of the page.
669 * @return The current scale factor.
671 virtual float GetScaleFactor() const = 0;
674 * @brief Request to activate/deactivate the accessibility usage set by web app.
675 * @param[in] activated Activate accessibility or not.
677 virtual void ActivateAccessibility(bool activated) = 0;
680 * @brief Request to set the current page's visibility.
681 * @param[in] visible Visible or not.
683 * @return true if succeeded, false otherwise
685 virtual bool SetVisibility(bool visible) = 0;
688 * @brief Search and highlight the given string in the document.
689 * @param[in] text The text to find
690 * @param[in] options The options to find
691 * @param[in] maxMatchCount The maximum match count to find
693 * @return true if found & highlighted, false otherwise
695 virtual bool HighlightText(const std::string& text, FindOption options, uint32_t maxMatchCount) = 0;
698 * @brief Add dynamic certificate path.
699 * @param[in] host host that required client authentication
700 * @param[in] certPath the file path stored certificate
702 virtual void AddDynamicCertificatePath(const std::string& host, const std::string& certPath) = 0;
705 * @brief Get snapshot of the specified viewArea of page.
707 * @param[in] viewArea The rectangle of screen shot
708 * @param[in] scaleFactor The scale factor
710 * @return pixel data of screen shot
712 virtual Dali::PixelData GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor) = 0;
715 * @brief Request to get snapshot of the specified viewArea of page asynchronously.
717 * @param[in] viewArea The rectangle of screen shot
718 * @param[in] scaleFactor The scale factor
719 * @param[in] callback The callback for screen shot
721 * @return true if requested successfully, false otherwise
723 virtual bool GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, ScreenshotCapturedCallback callback) = 0;
726 * @brief Asynchronously request to check if there is a video playing in the given view.
728 * @param[in] callback The callback called after checking if video is playing or not
730 * @return true if requested successfully, false otherwise
732 virtual bool CheckVideoPlayingAsynchronously(VideoPlayingCallback callback) = 0;
735 * @brief Set callback which will be called upon geolocation permission request.
737 * @param[in] callback The callback for requesting geolocation permission
739 virtual void RegisterGeolocationPermissionCallback(GeolocationPermissionCallback callback) = 0;
742 * @brief Update display area.
743 * @param[in] displayArea The display area need be updated.
745 virtual void UpdateDisplayArea(Dali::Rect<int32_t> displayArea) = 0;
748 * @brief Enable video hole.
749 * @param[in] enabled True if enabled, false othewise.
751 virtual void EnableVideoHole(bool enabled) = 0;
754 * @brief Send Hover Events.
755 * @param[in] event The hover event would be sent.
757 virtual bool SendHoverEvent(const HoverEvent& event) = 0;
760 * @brief Send Wheel Events.
761 * @param[in] event The wheel event would be sent.
763 virtual bool SendWheelEvent(const WheelEvent& event) = 0;
766 * @brief Connect to this signal to be notified when frame is rendered.
768 * @return A signal object to connect with.
770 virtual WebEngineFrameRenderedSignalType& FrameRenderedSignal() = 0;
773 * @brief Callback to be called when page loading is started.
775 * @param[in] callback
777 virtual void RegisterPageLoadStartedCallback(WebEnginePageLoadCallback callback) = 0;
780 * @brief Callback to be called when page loading is in progress.
782 * @param[in] callback
784 virtual void RegisterPageLoadInProgressCallback(WebEnginePageLoadCallback callback) = 0;
787 * @brief Callback to be called when page loading is finished.
789 * @param[in] callback
791 virtual void RegisterPageLoadFinishedCallback(WebEnginePageLoadCallback callback) = 0;
794 * @brief Callback to be called when an error occurs in page loading.
796 * @param[in] callback
798 virtual void RegisterPageLoadErrorCallback(WebEnginePageLoadErrorCallback callback) = 0;
801 * @brief Callback to be called when scroll edge is reached.
803 * @param[in] callback
805 virtual void RegisterScrollEdgeReachedCallback(WebEngineScrollEdgeReachedCallback callback) = 0;
808 * @brief Callback to be called when url is changed.
810 * @param[in] callback
812 virtual void RegisterUrlChangedCallback(WebEngineUrlChangedCallback callback) = 0;
815 * @brief Callback to be called when form repost decision is requested.
817 * @param[in] callback
819 virtual void RegisterFormRepostDecidedCallback(WebEngineFormRepostDecidedCallback callback) = 0;
822 * @brief Callback to be called when http request need be intercepted.
824 * @param[in] callback
826 virtual void RegisterRequestInterceptorCallback(WebEngineRequestInterceptorCallback callback) = 0;
829 * @brief Callback to be called when console message will be logged.
831 * @param[in] callback
833 virtual void RegisterConsoleMessageReceivedCallback(WebEngineConsoleMessageReceivedCallback callback) = 0;
836 * @brief Callback to be called when response policy would be decided.
838 * @param[in] callback
840 virtual void RegisterResponsePolicyDecidedCallback(WebEngineResponsePolicyDecidedCallback callback) = 0;
843 * @brief Callback to be called when certificate need be confirmed.
845 * @param[in] callback
847 virtual void RegisterCertificateConfirmedCallback(WebEngineCertificateCallback callback) = 0;
850 * @brief Callback to be called when ssl certificate is changed.
852 * @param[in] callback
854 virtual void RegisterSslCertificateChangedCallback(WebEngineCertificateCallback callback) = 0;
857 * @brief Callback to be called when http authentication need be confirmed.
859 * @param[in] callback
861 virtual void RegisterHttpAuthHandlerCallback(WebEngineHttpAuthHandlerCallback callback) = 0;
864 * @brief Callback to be called when context menu would be shown.
866 * @param[in] callback
868 virtual void RegisterContextMenuShownCallback(WebEngineContextMenuShownCallback callback) = 0;
871 * @brief Callback to be called when context menu would be hidden.
873 * @param[in] callback
875 virtual void RegisterContextMenuHiddenCallback(WebEngineContextMenuHiddenCallback callback) = 0;
878 * @brief Get a plain text of current web page asynchronously.
880 * @param[in] callback The callback function called asynchronously.
882 virtual void GetPlainTextAsynchronously(PlainTextReceivedCallback callback) = 0;
885 // specialization has to be done in the same namespace
887 struct EnableBitMaskOperators<WebEnginePlugin::FindOption>
889 static const bool ENABLE = true;