1 #ifndef DALI_WEB_ENGINE_PLUGIN_H
2 #define DALI_WEB_ENGINE_PLUGIN_H
5 * Copyright (c) 2022 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.
22 #include <dali/public-api/images/native-image-interface.h>
23 #include <dali/public-api/math/rect.h>
24 #include <dali/public-api/signals/dali-signal.h>
29 #include <dali/devel-api/adaptor-framework/accessibility.h>
30 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-hit-test.h>
31 #include <dali/devel-api/common/bitwise-enum.h>
32 #include <dali/public-api/adaptor-framework/native-image-source.h>
39 class WebEngineBackForwardList;
40 class WebEngineCertificate;
41 class WebEngineConsoleMessage;
42 class WebEngineContext;
43 class WebEngineContextMenu;
44 class WebEngineCookieManager;
45 class WebEngineFormRepostDecision;
46 class WebEngineHitTest;
47 class WebEngineHttpAuthHandler;
48 class WebEngineLoadError;
49 class WebEnginePolicyDecision;
50 class WebEngineSettings;
55 * @brief WebEnginePlugin is an abstract interface, used by dali-adaptor to access WebEngine plugin.
56 * A concrete implementation must be created for each platform and provided as dynamic library.
62 * @brief WebView signal type related with frame rendered.
64 using WebEngineFrameRenderedSignalType = Signal<void(void)>;
67 * @brief WebEngine callback related with page loading.
69 using WebEnginePageLoadCallback = std::function<void(const std::string&)>;
72 * @brief WebView callback related with page loading error.
74 using WebEnginePageLoadErrorCallback = std::function<void(std::unique_ptr<Dali::WebEngineLoadError>)>;
76 // forward declaration.
77 enum class ScrollEdge;
80 * @brief WebView callback related with scroll edge reached.
82 using WebEngineScrollEdgeReachedCallback = std::function<void(const ScrollEdge)>;
85 * @brief WebView callback related with page url changed.
87 using WebEngineUrlChangedCallback = std::function<void(const std::string&)>;
90 * @brief WebView callback related with screen captured.
92 using ScreenshotCapturedCallback = std::function<void(Dali::PixelData)>;
95 * @brief WebView callback related with geolocation permission.
96 * Host and protocol of security origin will be provided when requesting
97 * geolocation permission.
98 * It returns true if a pop-up is created successfully, false otherwise.
100 using GeolocationPermissionCallback = std::function<bool(const std::string&, const std::string&)>;
103 * @brief WebView callback related with video playing.
105 using VideoPlayingCallback = std::function<void(bool)>;
108 * @brief WebView callback related with console message logged.
110 using WebEngineConsoleMessageReceivedCallback = std::function<void(std::unique_ptr<Dali::WebEngineConsoleMessage>)>;
113 * @brief WebView callback related with certificate changed.
115 using WebEngineCertificateCallback = std::function<void(std::unique_ptr<Dali::WebEngineCertificate>)>;
118 * @brief WebView callback related with http authentication.
120 using WebEngineHttpAuthHandlerCallback = std::function<void(std::unique_ptr<Dali::WebEngineHttpAuthHandler>)>;
123 * @brief WebView callback related with context menu shown.
125 using WebEngineContextMenuShownCallback = std::function<void(std::unique_ptr<Dali::WebEngineContextMenu>)>;
128 * @brief WebView callback related with context menu hidden.
130 using WebEngineContextMenuHiddenCallback = std::function<void(std::unique_ptr<Dali::WebEngineContextMenu>)>;
133 * @brief Message result callback when JavaScript is executed with a message.
135 using JavaScriptMessageHandlerCallback = std::function<void(const std::string&)>;
138 * @brief Alert callback when JavaScript alert is called with a message.
139 * It returns true if a pop-up is created successfully, false otherwise.
141 using JavaScriptAlertCallback = std::function<bool(const std::string&)>;
144 * @brief Confirm callback when JavaScript confirm is called with a message.
145 * It returns true if a pop-up is created successfully, false otherwise.
147 using JavaScriptConfirmCallback = std::function<bool(const std::string&)>;
150 * @brief Prompt callback when JavaScript prompt is called with a message
151 * and an optional value that is the default value for the input field.
152 * It returns true if a pop-up is created successfully, false otherwise.
154 using JavaScriptPromptCallback = std::function<bool(const std::string&, const std::string&)>;
157 * @brief WebView callback related with form repost decision.
159 using WebEngineFormRepostDecidedCallback = std::function<void(std::unique_ptr<Dali::WebEngineFormRepostDecision>)>;
162 * @brief WebView callback related with frame rendered.
164 using WebEngineFrameRenderedCallback = std::function<void(void)>;
167 * @brief WebView callback related with response policy would be decided.
169 using WebEngineResponsePolicyDecidedCallback = std::function<void(std::unique_ptr<Dali::WebEnginePolicyDecision>)>;
172 * @brief WebView callback related with navigation policy would be decided.
174 using WebEngineNavigationPolicyDecidedCallback = std::function<void(std::unique_ptr<Dali::WebEnginePolicyDecision>)>;
177 * @brief Hit test callback called after hit test is created asynchronously.
179 using WebEngineHitTestCreatedCallback = std::function<bool(std::unique_ptr<Dali::WebEngineHitTest>)>;
182 * @brief The callback to be called when the web engine received a plain text of current web page.
184 using PlainTextReceivedCallback = std::function<void(const std::string&)>;
187 * @brief Enumeration for the scroll edge.
189 enum class ScrollEdge
191 LEFT, ///< Left edge reached.
192 RIGHT, ///< Right edge reached.
193 TOP, ///< Top edge reached.
194 BOTTOM, ///< Bottom edge reached.
198 * @brief Enumeration that provides the option to find text.
200 enum class FindOption
202 NONE = 0, ///< No search flags, this means a case sensitive, no wrap, forward only search
203 CASE_INSENSITIVE = 1 << 0, ///< Case insensitive search
204 AT_WORD_STARTS = 1 << 1, ///< Search text only at the beginning of the words
205 TREAT_MEDIAL_CAPITAL_AS_WORD_START = 1 << 2, ///< Treat capital letters in the middle of words as word start
206 BACKWARDS = 1 << 3, ///< Search backwards
207 WRAP_AROUND = 1 << 4, ///< If not present the search stops at the end of the document
208 SHOW_OVERLAY = 1 << 5, ///< Show overlay
209 SHOW_FIND_INDICATOR = 1 << 6, ///< Show indicator
210 SHOW_HIGHLIGHT = 1 << 7, ///< Show highlight
214 * @brief Constructor.
216 WebEnginePlugin() = default;
221 virtual ~WebEnginePlugin() = default;
224 * @brief Create WebEngine instance.
226 * @param [in] width The width of Web
227 * @param [in] height The height of Web
228 * @param [in] locale The locale of Web
229 * @param [in] timezoneId The timezoneID of Web
231 virtual void Create(uint32_t width, uint32_t height, const std::string& locale, const std::string& timezoneId) = 0;
234 * @brief Create WebEngine instance.
236 * @param [in] width The width of Web
237 * @param [in] height The height of Web
238 * @param [in] argc The count of application arguments
239 * @param [in] argv The string array of application arguments
241 virtual void Create(uint32_t width, uint32_t height, uint32_t argc, char** argv) = 0;
244 * @brief Destroy WebEngine instance.
246 virtual void Destroy() = 0;
249 * @brief Get settings of WebEngine.
251 virtual WebEngineSettings& GetSettings() const = 0;
254 * @brief Get back-forward list of WebEngine.
256 virtual WebEngineBackForwardList& GetBackForwardList() const = 0;
259 * @brief Load a web page based on a given URL.
261 * @param [in] url The URL of the resource to load
263 virtual void LoadUrl(const std::string& url) = 0;
266 * @brief Return the title of the Web.
268 * @return The title of web page
270 virtual std::string GetTitle() const = 0;
273 * @brief Return the Favicon of the Web.
275 * @return Favicon of Dali::PixelData& type
277 virtual Dali::PixelData GetFavicon() const = 0;
280 * @brief Get image to render.
282 virtual NativeImageSourcePtr GetNativeImageSource() = 0;
285 * @brief Return the URL of the Web.
287 * @return Url of string type
289 virtual std::string GetUrl() const = 0;
292 * @brief Load a given string as web contents.
294 * @param [in] htmlString The string to use as the contents of the web page
296 virtual void LoadHtmlString(const std::string& htmlString) = 0;
299 * @brief Load the specified html string as the content of the view overriding current history entry
301 * @param[in] html HTML data to load
302 * @param[in] basicUri Base URL used for relative paths to external objects
303 * @param[in] unreachableUrl URL that could not be reached
305 * @return true if successfully loaded, false otherwise
307 virtual bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl) = 0;
310 * @brief Request loading the given contents by MIME type into the view object
312 * @param[in] contents The content to load
313 * @param[in] contentSize The size of contents (in bytes)
314 * @param[in] mimeType The type of contents, if 0 is given "text/html" is assumed
315 * @param[in] encoding The encoding for contents, if 0 is given "UTF-8" is assumed
316 * @param[in] baseUri The base URI to use for relative resources
318 * @return true if successfully request, false otherwise
320 virtual bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri) = 0;
323 * @brief Reload the Web.
325 virtual void Reload() = 0;
328 * @brief Reload the current page's document without cache
330 virtual bool ReloadWithoutCache() = 0;
333 * @brief Stop loading web contents on the current page.
335 virtual void StopLoading() = 0;
338 * @brief Suspend the operation associated with the view.
340 virtual void Suspend() = 0;
343 * @brief Resume the operation associated with the view object after calling Suspend().
345 virtual void Resume() = 0;
348 * @brief To suspend all url loading
350 virtual void SuspendNetworkLoading() = 0;
353 * @brief To resume new url network loading
355 virtual void ResumeNetworkLoading() = 0;
358 * @brief Add custom header
360 * @param[in] name custom header name to add the custom header
361 * @param[in] value custom header value to add the custom header
363 * @return true if succeeded, false otherwise
365 virtual bool AddCustomHeader(const std::string& name, const std::string& value) = 0;
368 * @brief Remove custom header
370 * @param[in] name custom header name to remove the custom header
372 * @return true if succeeded, false otherwise
374 virtual bool RemoveCustomHeader(const std::string& name) = 0;
377 * @brief Start the inspector server
379 * @param[in] port port number
381 * @return the port number
383 virtual uint32_t StartInspectorServer(uint32_t port) = 0;
386 * @brief Stop the inspector server
388 * @return true if succeeded, false otherwise
390 virtual bool StopInspectorServer() = 0;
393 * @brief Scroll web page of view by deltaX and deltaY.
395 * @param[in] deltaX horizontal offset to scroll
396 * @param[in] deltaY vertical offset to scroll
398 virtual void ScrollBy(int32_t deltaX, int32_t deltaY) = 0;
401 * @brief Scroll edge of view by deltaX and deltaY.
403 * @param[in] deltaX horizontal offset to scroll
404 * @param[in] deltaY vertical offset to scroll
406 * @return true if succeeded, false otherwise
408 virtual bool ScrollEdgeBy(int32_t deltaX, int32_t deltaY) = 0;
411 * @brief Scroll to the specified position of the given view.
413 virtual void SetScrollPosition(int32_t x, int32_t y) = 0;
416 * @brief Get the current scroll position of the given view.
418 virtual Dali::Vector2 GetScrollPosition() const = 0;
421 * @brief Get the possible scroll size of the given view.
423 virtual Dali::Vector2 GetScrollSize() const = 0;
426 * @brief Get the last known content's size.
428 virtual Dali::Vector2 GetContentSize() const = 0;
431 * @brief Return whether forward is possible.
433 * @return True if forward is possible, false otherwise
435 virtual bool CanGoForward() = 0;
438 * @brief Go to forward.
440 virtual void GoForward() = 0;
443 * @brief Return whether backward is possible.
445 * @return True if backward is possible, false otherwise
447 virtual bool CanGoBack() = 0;
452 virtual void GoBack() = 0;
455 * @brief Evaluate JavaScript code represented as a string.
457 * @param[in] script The JavaScript code
458 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
460 virtual void EvaluateJavaScript(const std::string& script, JavaScriptMessageHandlerCallback resultHandler) = 0;
463 * @brief Add a message handler into JavaScript.
465 * @param[in] exposedObjectName The name of exposed object
466 * @param[in] handler The callback function
468 virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, JavaScriptMessageHandlerCallback handler) = 0;
471 * @brief Register a callback for JavaScript alert.
473 * @param[in] callback The callback function
475 virtual void RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback) = 0;
478 * @brief Reply for JavaScript alert.
480 virtual void JavaScriptAlertReply() = 0;
483 * @brief Register a callback for JavaScript confirm.
485 * @param[in] callback The callback function
487 virtual void RegisterJavaScriptConfirmCallback(JavaScriptConfirmCallback callback) = 0;
490 * @brief Reply for JavaScript confirm.
492 virtual void JavaScriptConfirmReply(bool confirmed) = 0;
495 * @brief Register a callback for JavaScript prompt.
497 * @param[in] callback The callback function
499 virtual void RegisterJavaScriptPromptCallback(JavaScriptPromptCallback callback) = 0;
502 * @brief Reply for JavaScript prompt.
504 virtual void JavaScriptPromptReply(const std::string& result) = 0;
507 * @brief Create a new hit test.
509 * @param[in] x the horizontal position to query
510 * @param[in] y the vertical position to query
511 * @param[in] mode the mode of hit test
513 * @return a new hit test object.
515 virtual std::unique_ptr<Dali::WebEngineHitTest> CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode) = 0;
518 * @brief create a hit test asynchronously.
520 * @param[in] x the horizontal position to query
521 * @param[in] y the vertical position to query
522 * @param[in] mode the mode of hit test
523 * @param[in] callback The callback function
525 * @return true if succeeded, false otherwise
527 virtual bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, WebEngineHitTestCreatedCallback callback) = 0;
530 * @brief Clear the history of Web.
532 virtual void ClearHistory() = 0;
535 * @brief Clear all tiles resources of Web.
537 virtual void ClearAllTilesResources() = 0;
540 * @brief Get user agent string.
542 * @return The string value of user agent
544 virtual std::string GetUserAgent() const = 0;
547 * @brief Set user agent string.
549 * @param[in] userAgent The string value of user agent
551 virtual void SetUserAgent(const std::string& userAgent) = 0;
554 * @brief Set size of Web Page.
556 virtual void SetSize(uint32_t width, uint32_t height) = 0;
559 * @brief Set background color of web page.
561 * @param[in] color Background color
563 virtual void SetDocumentBackgroundColor(Dali::Vector4 color) = 0;
566 * @brief Clear tiles when hidden.
568 * @param[in] cleared Whether tiles are cleared or not
570 virtual void ClearTilesWhenHidden(bool cleared) = 0;
573 * @brief Set multiplier of cover area of tile.
575 * @param[in] multiplier The multiplier of cover area
577 virtual void SetTileCoverAreaMultiplier(float multiplier) = 0;
580 * @brief Enable cursor by client.
582 * @param[in] enabled Whether cursor is enabled or not
584 virtual void EnableCursorByClient(bool enabled) = 0;
587 * @brief Get the selected text.
589 * @return the selected text
591 virtual std::string GetSelectedText() const = 0;
594 * @brief Send Touch Events.
596 virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
599 * @brief Send Key Events.
601 virtual bool SendKeyEvent(const KeyEvent& event) = 0;
604 * @brief Support mouse events or not.
605 * @param[in] enabled True if enabled, false othewise.
607 virtual void EnableMouseEvents(bool enabled) = 0;
610 * @brief Support key events or not.
611 * @param[in] enabled True if enabled, false othewise.
613 virtual void EnableKeyEvents(bool enabled) = 0;
617 * @param[in] focused True if focus is gained, false lost.
619 virtual void SetFocus(bool focused) = 0;
622 * @brief Set zoom factor of the current page.
623 * @param[in] zoomFactor a new factor to be set.
625 virtual void SetPageZoomFactor(float zoomFactor) = 0;
628 * @brief Query the current zoom factor of the page。
629 * @return The current page zoom factor.
631 virtual float GetPageZoomFactor() const = 0;
634 * @brief Set the current text zoom level。.
635 * @param[in] zoomFactor a new factor to be set.
637 virtual void SetTextZoomFactor(float zoomFactor) = 0;
640 * @brief Get the current text zoom level.
641 * @return The current text zoom factor.
643 virtual float GetTextZoomFactor() const = 0;
646 * @brief Get the current load progress of the page.
647 * @return The load progress of the page.
649 virtual float GetLoadProgressPercentage() const = 0;
652 * @brief Scale the current page, centered at the given point.
653 * @param[in] scaleFactor a new factor to be scaled.
654 * @param[in] point a center coordinate.
656 virtual void SetScaleFactor(float scaleFactor, Dali::Vector2 point) = 0;
659 * @brief Get the current scale factor of the page.
660 * @return The current scale factor.
662 virtual float GetScaleFactor() const = 0;
665 * @brief Request to activate/deactivate the accessibility usage set by web app.
666 * @param[in] activated Activate accessibility or not.
668 virtual void ActivateAccessibility(bool activated) = 0;
671 * @brief Get the accessibility address (bus and path) for embedding.
672 * @return Accessibility address of the root web content element.
674 virtual Accessibility::Address GetAccessibilityAddress() = 0;
677 * @brief Request to set the current page's visibility.
678 * @param[in] visible Visible or not.
680 * @return true if succeeded, false otherwise
682 virtual bool SetVisibility(bool visible) = 0;
685 * @brief Search and highlight the given string in the document.
686 * @param[in] text The text to find
687 * @param[in] options The options to find
688 * @param[in] maxMatchCount The maximum match count to find
690 * @return true if found & highlighted, false otherwise
692 virtual bool HighlightText(const std::string& text, FindOption options, uint32_t maxMatchCount) = 0;
695 * @brief Add dynamic certificate path.
696 * @param[in] host host that required client authentication
697 * @param[in] certPath the file path stored certificate
699 virtual void AddDynamicCertificatePath(const std::string& host, const std::string& certPath) = 0;
702 * @brief Get snapshot of the specified viewArea of page.
704 * @param[in] viewArea The rectangle of screen shot
705 * @param[in] scaleFactor The scale factor
707 * @return pixel data of screen shot
709 virtual Dali::PixelData GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor) = 0;
712 * @brief Request to get snapshot of the specified viewArea of page asynchronously.
714 * @param[in] viewArea The rectangle of screen shot
715 * @param[in] scaleFactor The scale factor
716 * @param[in] callback The callback for screen shot
718 * @return true if requested successfully, false otherwise
720 virtual bool GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, ScreenshotCapturedCallback callback) = 0;
723 * @brief Asynchronously request to check if there is a video playing in the given view.
725 * @param[in] callback The callback called after checking if video is playing or not
727 * @return true if requested successfully, false otherwise
729 virtual bool CheckVideoPlayingAsynchronously(VideoPlayingCallback callback) = 0;
732 * @brief Set callback which will be called upon geolocation permission request.
734 * @param[in] callback The callback for requesting geolocation permission
736 virtual void RegisterGeolocationPermissionCallback(GeolocationPermissionCallback callback) = 0;
739 * @brief Update display area.
740 * @param[in] displayArea The display area need be updated.
742 virtual void UpdateDisplayArea(Dali::Rect<int32_t> displayArea) = 0;
745 * @brief Enable video hole.
746 * @param[in] enabled True if enabled, false othewise.
748 virtual void EnableVideoHole(bool enabled) = 0;
751 * @brief Send Hover Events.
752 * @param[in] event The hover event would be sent.
754 virtual bool SendHoverEvent(const HoverEvent& event) = 0;
757 * @brief Send Wheel Events.
758 * @param[in] event The wheel event would be sent.
760 virtual bool SendWheelEvent(const WheelEvent& event) = 0;
763 * @brief Connect to this signal to be notified when frame is rendered.
765 * @return A signal object to connect with.
767 virtual WebEngineFrameRenderedSignalType& FrameRenderedSignal() = 0;
770 * @brief Callback to be called when page loading is started.
772 * @param[in] callback
774 virtual void RegisterPageLoadStartedCallback(WebEnginePageLoadCallback callback) = 0;
777 * @brief Callback to be called when page loading is in progress.
779 * @param[in] callback
781 virtual void RegisterPageLoadInProgressCallback(WebEnginePageLoadCallback callback) = 0;
784 * @brief Callback to be called when page loading is finished.
786 * @param[in] callback
788 virtual void RegisterPageLoadFinishedCallback(WebEnginePageLoadCallback callback) = 0;
791 * @brief Callback to be called when an error occurs in page loading.
793 * @param[in] callback
795 virtual void RegisterPageLoadErrorCallback(WebEnginePageLoadErrorCallback callback) = 0;
798 * @brief Callback to be called when scroll edge is reached.
800 * @param[in] callback
802 virtual void RegisterScrollEdgeReachedCallback(WebEngineScrollEdgeReachedCallback callback) = 0;
805 * @brief Callback to be called when url is changed.
807 * @param[in] callback
809 virtual void RegisterUrlChangedCallback(WebEngineUrlChangedCallback callback) = 0;
812 * @brief Callback to be called when form repost decision is requested.
814 * @param[in] callback
816 virtual void RegisterFormRepostDecidedCallback(WebEngineFormRepostDecidedCallback callback) = 0;
819 * @brief Callback to be called when console message will be logged.
821 * @param[in] callback
823 virtual void RegisterConsoleMessageReceivedCallback(WebEngineConsoleMessageReceivedCallback callback) = 0;
826 * @brief Callback to be called when response policy would be decided.
828 * @param[in] callback
830 virtual void RegisterResponsePolicyDecidedCallback(WebEngineResponsePolicyDecidedCallback callback) = 0;
833 * @brief Callback to be called when navigation policy would be decided.
835 * @param[in] callback
837 virtual void RegisterNavigationPolicyDecidedCallback(WebEngineNavigationPolicyDecidedCallback callback) = 0;
840 * @brief Callback to be called when certificate need be confirmed.
842 * @param[in] callback
844 virtual void RegisterCertificateConfirmedCallback(WebEngineCertificateCallback callback) = 0;
847 * @brief Callback to be called when ssl certificate is changed.
849 * @param[in] callback
851 virtual void RegisterSslCertificateChangedCallback(WebEngineCertificateCallback callback) = 0;
854 * @brief Callback to be called when http authentication need be confirmed.
856 * @param[in] callback
858 virtual void RegisterHttpAuthHandlerCallback(WebEngineHttpAuthHandlerCallback callback) = 0;
861 * @brief Callback to be called when context menu would be shown.
863 * @param[in] callback
865 virtual void RegisterContextMenuShownCallback(WebEngineContextMenuShownCallback callback) = 0;
868 * @brief Callback to be called when context menu would be hidden.
870 * @param[in] callback
872 virtual void RegisterContextMenuHiddenCallback(WebEngineContextMenuHiddenCallback callback) = 0;
875 * @brief Get a plain text of current web page asynchronously.
877 * @param[in] callback The callback function called asynchronously.
879 virtual void GetPlainTextAsynchronously(PlainTextReceivedCallback callback) = 0;
882 // specialization has to be done in the same namespace
884 struct EnableBitMaskOperators<WebEnginePlugin::FindOption>
886 static const bool ENABLE = true;