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.
24 #include <dali/public-api/images/native-image-interface.h>
25 #include <dali/public-api/math/rect.h>
26 #include <dali/public-api/signals/dali-signal.h>
29 #include <dali/public-api/adaptor-framework/native-image-source.h>
30 #include <dali/devel-api/adaptor-framework/web-engine-hit-test.h>
31 #include <dali/devel-api/common/bitwise-enum.h>
38 class WebEngineBackForwardList;
39 class WebEngineCertificate;
40 class WebEngineConsoleMessage;
41 class WebEngineContext;
42 class WebEngineContextMenu;
43 class WebEngineCookieManager;
44 class WebEngineFormRepostDecision;
45 class WebEngineHitTest;
46 class WebEngineHttpAuthHandler;
47 class WebEngineLoadError;
48 class WebEnginePolicyDecision;
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 console message logged.
109 using WebEngineConsoleMessageReceivedCallback = std::function<void(std::unique_ptr<Dali::WebEngineConsoleMessage>)>;
112 * @brief WebView callback related with certificate changed.
114 using WebEngineCertificateCallback = std::function<void(std::unique_ptr<Dali::WebEngineCertificate>)>;
117 * @brief WebView callback related with http authentication.
119 using WebEngineHttpAuthHandlerCallback = std::function<void(std::unique_ptr<Dali::WebEngineHttpAuthHandler>)>;
122 * @brief WebView callback related with context menu shown.
124 using WebEngineContextMenuShownCallback = std::function<void(std::unique_ptr<Dali::WebEngineContextMenu>)>;
127 * @brief WebView callback related with context menu hidden.
129 using WebEngineContextMenuHiddenCallback = std::function<void(std::unique_ptr<Dali::WebEngineContextMenu>)>;
132 * @brief Message result callback when JavaScript is executed with a message.
134 using JavaScriptMessageHandlerCallback = std::function<void(const std::string&)>;
137 * @brief Alert callback when JavaScript alert is called with a message.
138 * It returns true if a pop-up is created successfully, false otherwise.
140 using JavaScriptAlertCallback = std::function<bool(const std::string&)>;
143 * @brief Confirm callback when JavaScript confirm is called with a message.
144 * It returns true if a pop-up is created successfully, false otherwise.
146 using JavaScriptConfirmCallback = std::function<bool(const std::string&)>;
149 * @brief Prompt callback when JavaScript prompt is called with a message
150 * and an optional value that is the default value for the input field.
151 * It returns true if a pop-up is created successfully, false otherwise.
153 using JavaScriptPromptCallback = std::function<bool(const std::string&, const std::string&)>;
156 * @brief WebView callback related with form repost decision.
158 using WebEngineFormRepostDecidedCallback = std::function<void(std::unique_ptr<Dali::WebEngineFormRepostDecision>)>;
161 * @brief WebView callback related with frame rendered.
163 using WebEngineFrameRenderedCallback = std::function<void(void)>;
166 * @brief WebView callback related with response policy would be decided.
168 using WebEngineResponsePolicyDecidedCallback = std::function<void(std::unique_ptr<Dali::WebEnginePolicyDecision>)>;
171 * @brief Hit test callback called after hit test is created asynchronously.
173 using WebEngineHitTestCreatedCallback = std::function<bool(std::unique_ptr<Dali::WebEngineHitTest>)>;
176 * @brief The callback to be called when the web engine received a plain text of current web page.
178 using PlainTextReceivedCallback = std::function<void(const std::string&)>;
181 * @brief Enumeration for the scroll edge.
183 enum class ScrollEdge
185 LEFT, ///< Left edge reached.
186 RIGHT, ///< Right edge reached.
187 TOP, ///< Top edge reached.
188 BOTTOM, ///< Bottom edge reached.
192 * @brief Enumeration that provides the option to find text.
194 enum class FindOption
196 NONE = 0, ///< No search flags, this means a case sensitive, no wrap, forward only search
197 CASE_INSENSITIVE = 1 << 0, ///< Case insensitive search
198 AT_WORD_STARTS = 1 << 1, ///< Search text only at the beginning of the words
199 TREAT_MEDIAL_CAPITAL_AS_WORD_START = 1 << 2, ///< Treat capital letters in the middle of words as word start
200 BACKWARDS = 1 << 3, ///< Search backwards
201 WRAP_AROUND = 1 << 4, ///< If not present the search stops at the end of the document
202 SHOW_OVERLAY = 1 << 5, ///< Show overlay
203 SHOW_FIND_INDICATOR = 1 << 6, ///< Show indicator
204 SHOW_HIGHLIGHT = 1 << 7, ///< Show highlight
208 * @brief Constructor.
210 WebEnginePlugin() = default;
215 virtual ~WebEnginePlugin() = default;
218 * @brief Create WebEngine instance.
220 * @param [in] width The width of Web
221 * @param [in] height The height of Web
222 * @param [in] locale The locale of Web
223 * @param [in] timezoneId The timezoneID of Web
225 virtual void Create(uint32_t width, uint32_t height, const std::string& locale, const std::string& timezoneId) = 0;
228 * @brief Create WebEngine instance.
230 * @param [in] width The width of Web
231 * @param [in] height The height of Web
232 * @param [in] argc The count of application arguments
233 * @param [in] argv The string array of application arguments
235 virtual void Create(uint32_t width, uint32_t height, uint32_t argc, char** argv) = 0;
238 * @brief Destroy WebEngine instance.
240 virtual void Destroy() = 0;
243 * @brief Get settings of WebEngine.
245 virtual WebEngineSettings& GetSettings() const = 0;
248 * @brief Get context of WebEngine.
250 virtual WebEngineContext& GetContext() const = 0;
253 * @brief Get cookie manager of WebEngine.
255 virtual WebEngineCookieManager& GetCookieManager() const = 0;
258 * @brief Get back-forward list of WebEngine.
260 virtual WebEngineBackForwardList& GetBackForwardList() const = 0;
263 * @brief Load a web page based on a given URL.
265 * @param [in] url The URL of the resource to load
267 virtual void LoadUrl(const std::string& url) = 0;
270 * @brief Return the title of the Web.
272 * @return The title of web page
274 virtual std::string GetTitle() const = 0;
277 * @brief Return the Favicon of the Web.
279 * @return Favicon of Dali::PixelData& type
281 virtual Dali::PixelData GetFavicon() const = 0;
284 * @brief Get image to render.
286 virtual NativeImageSourcePtr GetNativeImageSource() = 0;
289 * @brief Return the URL of the Web.
291 * @return Url of string type
293 virtual std::string GetUrl() const = 0;
296 * @brief Load a given string as web contents.
298 * @param [in] htmlString The string to use as the contents of the web page
300 virtual void LoadHtmlString(const std::string& htmlString) = 0;
303 * @brief Load the specified html string as the content of the view overriding current history entry
305 * @param[in] html HTML data to load
306 * @param[in] basicUri Base URL used for relative paths to external objects
307 * @param[in] unreachableUrl URL that could not be reached
309 * @return true if successfully loaded, false otherwise
311 virtual bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl) = 0;
314 * @brief Request loading the given contents by MIME type into the view object
316 * @param[in] contents The content to load
317 * @param[in] contentSize The size of contents (in bytes)
318 * @param[in] mimeType The type of contents, if 0 is given "text/html" is assumed
319 * @param[in] encoding The encoding for contents, if 0 is given "UTF-8" is assumed
320 * @param[in] baseUri The base URI to use for relative resources
322 * @return true if successfully request, false otherwise
324 virtual bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri) = 0;
327 * @brief Reload the Web.
329 virtual void Reload() = 0;
332 * @brief Reload the current page's document without cache
334 virtual bool ReloadWithoutCache() = 0;
337 * @brief Stop loading web contents on the current page.
339 virtual void StopLoading() = 0;
342 * @brief Suspend the operation associated with the view.
344 virtual void Suspend() = 0;
347 * @brief Resume the operation associated with the view object after calling Suspend().
349 virtual void Resume() = 0;
352 * @brief To suspend all url loading
354 virtual void SuspendNetworkLoading() = 0;
357 * @brief To resume new url network loading
359 virtual void ResumeNetworkLoading() = 0;
362 * @brief Add custom header
364 * @param[in] name custom header name to add the custom header
365 * @param[in] value custom header value to add the custom header
367 * @return true if succeeded, false otherwise
369 virtual bool AddCustomHeader(const std::string& name, const std::string& value) = 0;
372 * @brief Remove custom header
374 * @param[in] name custom header name to remove the custom header
376 * @return true if succeeded, false otherwise
378 virtual bool RemoveCustomHeader(const std::string& name) = 0;
381 * @brief Start the inspector server
383 * @param[in] port port number
385 * @return the port number
387 virtual uint32_t StartInspectorServer(uint32_t port) = 0;
390 * @brief Stop the inspector server
392 * @return true if succeeded, false otherwise
394 virtual bool StopInspectorServer() = 0;
397 * @brief Scroll web page of view by deltaX and deltaY.
399 * @param[in] deltaX horizontal offset to scroll
400 * @param[in] deltaY vertical offset to scroll
402 virtual void ScrollBy(int32_t deltaX, int32_t deltaY) = 0;
405 * @brief Scroll edge of view by deltaX and deltaY.
407 * @param[in] deltaX horizontal offset to scroll
408 * @param[in] deltaY vertical offset to scroll
410 * @return true if succeeded, false otherwise
412 virtual bool ScrollEdgeBy(int32_t deltaX, int32_t deltaY) = 0;
415 * @brief Scroll to the specified position of the given view.
417 virtual void SetScrollPosition(int32_t x, int32_t y) = 0;
420 * @brief Get the current scroll position of the given view.
422 virtual Dali::Vector2 GetScrollPosition() const = 0;
425 * @brief Get the possible scroll size of the given view.
427 virtual Dali::Vector2 GetScrollSize() const = 0;
430 * @brief Get the last known content's size.
432 virtual Dali::Vector2 GetContentSize() const = 0;
435 * @brief Return whether forward is possible.
437 * @return True if forward is possible, false otherwise
439 virtual bool CanGoForward() = 0;
442 * @brief Go to forward.
444 virtual void GoForward() = 0;
447 * @brief Return whether backward is possible.
449 * @return True if backward is possible, false otherwise
451 virtual bool CanGoBack() = 0;
456 virtual void GoBack() = 0;
459 * @brief Evaluate JavaScript code represented as a string.
461 * @param[in] script The JavaScript code
462 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
464 virtual void EvaluateJavaScript(const std::string& script, JavaScriptMessageHandlerCallback resultHandler) = 0;
467 * @brief Add a message handler into JavaScript.
469 * @param[in] exposedObjectName The name of exposed object
470 * @param[in] handler The callback function
472 virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, JavaScriptMessageHandlerCallback handler) = 0;
475 * @brief Register a callback for JavaScript alert.
477 * @param[in] callback The callback function
479 virtual void RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback) = 0;
482 * @brief Reply for JavaScript alert.
484 virtual void JavaScriptAlertReply() = 0;
487 * @brief Register a callback for JavaScript confirm.
489 * @param[in] callback The callback function
491 virtual void RegisterJavaScriptConfirmCallback(JavaScriptConfirmCallback callback) = 0;
494 * @brief Reply for JavaScript confirm.
496 virtual void JavaScriptConfirmReply(bool confirmed) = 0;
499 * @brief Register a callback for JavaScript prompt.
501 * @param[in] callback The callback function
503 virtual void RegisterJavaScriptPromptCallback(JavaScriptPromptCallback callback) = 0;
506 * @brief Reply for JavaScript prompt.
508 virtual void JavaScriptPromptReply(const std::string& result) = 0;
511 * @brief Create a new hit test.
513 * @param[in] x the horizontal position to query
514 * @param[in] y the vertical position to query
515 * @param[in] mode the mode of hit test
517 * @return a new hit test object.
519 virtual std::unique_ptr<Dali::WebEngineHitTest> CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode) = 0;
522 * @brief create a hit test asynchronously.
524 * @param[in] x the horizontal position to query
525 * @param[in] y the vertical position to query
526 * @param[in] mode the mode of hit test
527 * @param[in] callback The callback function
529 * @return true if succeeded, false otherwise
531 virtual bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, WebEngineHitTestCreatedCallback callback) = 0;
534 * @brief Clear the history of Web.
536 virtual void ClearHistory() = 0;
539 * @brief Clear all tiles resources of Web.
541 virtual void ClearAllTilesResources() = 0;
544 * @brief Get user agent string.
546 * @return The string value of user agent
548 virtual std::string GetUserAgent() const = 0;
551 * @brief Set user agent string.
553 * @param[in] userAgent The string value of user agent
555 virtual void SetUserAgent(const std::string& userAgent) = 0;
558 * @brief Set size of Web Page.
560 virtual void SetSize(uint32_t width, uint32_t height) = 0;
563 * @brief Set background color of web page.
565 * @param[in] color Background color
567 virtual void SetDocumentBackgroundColor(Dali::Vector4 color) = 0;
570 * @brief Clear tiles when hidden.
572 * @param[in] cleared Whether tiles are cleared or not
574 virtual void ClearTilesWhenHidden(bool cleared) = 0;
577 * @brief Set multiplier of cover area of tile.
579 * @param[in] multiplier The multiplier of cover area
581 virtual void SetTileCoverAreaMultiplier(float multiplier) = 0;
584 * @brief Enable cursor by client.
586 * @param[in] enabled Whether cursor is enabled or not
588 virtual void EnableCursorByClient(bool enabled) = 0;
591 * @brief Get the selected text.
593 * @return the selected text
595 virtual std::string GetSelectedText() const = 0;
598 * @brief Send Touch Events.
600 virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
603 * @brief Send Key Events.
605 virtual bool SendKeyEvent(const KeyEvent& event) = 0;
608 * @brief Support mouse events or not.
609 * @param[in] enabled True if enabled, false othewise.
611 virtual void EnableMouseEvents(bool enabled) = 0;
614 * @brief Support key events or not.
615 * @param[in] enabled True if enabled, false othewise.
617 virtual void EnableKeyEvents(bool enabled) = 0;
621 * @param[in] focused True if focus is gained, false lost.
623 virtual void SetFocus(bool focused) = 0;
626 * @brief Set zoom factor of the current page.
627 * @param[in] zoomFactor a new factor to be set.
629 virtual void SetPageZoomFactor(float zoomFactor) = 0;
632 * @brief Query the current zoom factor of the page。
633 * @return The current page zoom factor.
635 virtual float GetPageZoomFactor() const = 0;
638 * @brief Set the current text zoom level。.
639 * @param[in] zoomFactor a new factor to be set.
641 virtual void SetTextZoomFactor(float zoomFactor) = 0;
644 * @brief Get the current text zoom level.
645 * @return The current text zoom factor.
647 virtual float GetTextZoomFactor() const = 0;
650 * @brief Get the current load progress of the page.
651 * @return The load progress of the page.
653 virtual float GetLoadProgressPercentage() const = 0;
656 * @brief Scale the current page, centered at the given point.
657 * @param[in] scaleFactor a new factor to be scaled.
658 * @param[in] point a center coordinate.
660 virtual void SetScaleFactor(float scaleFactor, Dali::Vector2 point) = 0;
663 * @brief Get the current scale factor of the page.
664 * @return The current scale factor.
666 virtual float GetScaleFactor() const = 0;
669 * @brief Request to activate/deactivate the accessibility usage set by web app.
670 * @param[in] activated Activate accessibility or not.
672 virtual void ActivateAccessibility(bool activated) = 0;
675 * @brief Request to set the current page's visibility.
676 * @param[in] visible Visible or not.
678 * @return true if succeeded, false otherwise
680 virtual bool SetVisibility(bool visible) = 0;
683 * @brief Search and highlight the given string in the document.
684 * @param[in] text The text to find
685 * @param[in] options The options to find
686 * @param[in] maxMatchCount The maximum match count to find
688 * @return true if found & highlighted, false otherwise
690 virtual bool HighlightText(const std::string& text, FindOption options, uint32_t maxMatchCount) = 0;
693 * @brief Add dynamic certificate path.
694 * @param[in] host host that required client authentication
695 * @param[in] certPath the file path stored certificate
697 virtual void AddDynamicCertificatePath(const std::string& host, const std::string& certPath) = 0;
700 * @brief Get snapshot of the specified viewArea of page.
702 * @param[in] viewArea The rectangle of screen shot
703 * @param[in] scaleFactor The scale factor
705 * @return pixel data of screen shot
707 virtual Dali::PixelData GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor) = 0;
710 * @brief Request to get snapshot of the specified viewArea of page asynchronously.
712 * @param[in] viewArea The rectangle of screen shot
713 * @param[in] scaleFactor The scale factor
714 * @param[in] callback The callback for screen shot
716 * @return true if requested successfully, false otherwise
718 virtual bool GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, ScreenshotCapturedCallback callback) = 0;
721 * @brief Asynchronously request to check if there is a video playing in the given view.
723 * @param[in] callback The callback called after checking if video is playing or not
725 * @return true if requested successfully, false otherwise
727 virtual bool CheckVideoPlayingAsynchronously(VideoPlayingCallback callback) = 0;
730 * @brief Set callback which will be called upon geolocation permission request.
732 * @param[in] callback The callback for requesting geolocation permission
734 virtual void RegisterGeolocationPermissionCallback(GeolocationPermissionCallback callback) = 0;
737 * @brief Update display area.
738 * @param[in] displayArea The display area need be updated.
740 virtual void UpdateDisplayArea(Dali::Rect<int32_t> displayArea) = 0;
743 * @brief Enable video hole.
744 * @param[in] enabled True if enabled, false othewise.
746 virtual void EnableVideoHole(bool enabled) = 0;
749 * @brief Send Hover Events.
750 * @param[in] event The hover event would be sent.
752 virtual bool SendHoverEvent(const HoverEvent& event) = 0;
755 * @brief Send Wheel Events.
756 * @param[in] event The wheel event would be sent.
758 virtual bool SendWheelEvent(const WheelEvent& event) = 0;
761 * @brief Connect to this signal to be notified when frame is rendered.
763 * @return A signal object to connect with.
765 virtual WebEngineFrameRenderedSignalType& FrameRenderedSignal() = 0;
768 * @brief Callback to be called when page loading is started.
770 * @param[in] callback
772 virtual void RegisterPageLoadStartedCallback(WebEnginePageLoadCallback callback) = 0;
775 * @brief Callback to be called when page loading is in progress.
777 * @param[in] callback
779 virtual void RegisterPageLoadInProgressCallback(WebEnginePageLoadCallback callback) = 0;
782 * @brief Callback to be called when page loading is finished.
784 * @param[in] callback
786 virtual void RegisterPageLoadFinishedCallback(WebEnginePageLoadCallback callback) = 0;
789 * @brief Callback to be called when an error occurs in page loading.
791 * @param[in] callback
793 virtual void RegisterPageLoadErrorCallback(WebEnginePageLoadErrorCallback callback) = 0;
796 * @brief Callback to be called when scroll edge is reached.
798 * @param[in] callback
800 virtual void RegisterScrollEdgeReachedCallback(WebEngineScrollEdgeReachedCallback callback) = 0;
803 * @brief Callback to be called when url is changed.
805 * @param[in] callback
807 virtual void RegisterUrlChangedCallback(WebEngineUrlChangedCallback callback) = 0;
810 * @brief Callback to be called when form repost decision is requested.
812 * @param[in] callback
814 virtual void RegisterFormRepostDecidedCallback(WebEngineFormRepostDecidedCallback callback) = 0;
817 * @brief Callback to be called when console message will be logged.
819 * @param[in] callback
821 virtual void RegisterConsoleMessageReceivedCallback(WebEngineConsoleMessageReceivedCallback callback) = 0;
824 * @brief Callback to be called when response policy would be decided.
826 * @param[in] callback
828 virtual void RegisterResponsePolicyDecidedCallback(WebEngineResponsePolicyDecidedCallback callback) = 0;
831 * @brief Callback to be called when certificate need be confirmed.
833 * @param[in] callback
835 virtual void RegisterCertificateConfirmedCallback(WebEngineCertificateCallback callback) = 0;
838 * @brief Callback to be called when ssl certificate is changed.
840 * @param[in] callback
842 virtual void RegisterSslCertificateChangedCallback(WebEngineCertificateCallback callback) = 0;
845 * @brief Callback to be called when http authentication need be confirmed.
847 * @param[in] callback
849 virtual void RegisterHttpAuthHandlerCallback(WebEngineHttpAuthHandlerCallback callback) = 0;
852 * @brief Callback to be called when context menu would be shown.
854 * @param[in] callback
856 virtual void RegisterContextMenuShownCallback(WebEngineContextMenuShownCallback callback) = 0;
859 * @brief Callback to be called when context menu would be hidden.
861 * @param[in] callback
863 virtual void RegisterContextMenuHiddenCallback(WebEngineContextMenuHiddenCallback callback) = 0;
866 * @brief Get a plain text of current web page asynchronously.
868 * @param[in] callback The callback function called asynchronously.
870 virtual void GetPlainTextAsynchronously(PlainTextReceivedCallback callback) = 0;
873 // specialization has to be done in the same namespace
875 struct EnableBitMaskOperators<WebEnginePlugin::FindOption>
877 static const bool ENABLE = true;