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 WebEngineContextMenuItem;
43 class WebEngineCookieManager;
44 class WebEngineFormRepostDecision;
45 class WebEngineHitTest;
46 class WebEngineHttpAuthHandler;
47 class WebEngineLoadError;
48 class WebEnginePolicyDecision;
49 class WebEngineRequestInterceptor;
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 WebEngine signal type related with page loading.
64 using WebEnginePageLoadSignalType = Signal<void(const std::string&)>;
67 * @brief WebView signal type related with page loading error.
69 using WebEnginePageLoadErrorSignalType = Signal<void(std::shared_ptr<Dali::WebEngineLoadError>)>;
71 // forward declaration.
72 enum class ScrollEdge;
75 * @brief WebView signal type related with scroll edge reached.
77 using WebEngineScrollEdgeReachedSignalType = Signal<void(const ScrollEdge)>;
80 * @brief WebView signal type related with page url changed.
82 using WebEngineUrlChangedSignalType = Signal<void(const std::string&)>;
85 * @brief WebView signal type related with screen captured.
87 using ScreenshotCapturedCallback = std::function<void(Dali::PixelData)>;
90 * @brief WebView signal type related with geolocation permission.
91 * Host and protocol of security origin will be provided when requesting
92 * geolocation permission.
93 * It returns true if a pop-up is created successfully, false otherwise.
95 using GeolocationPermissionCallback = std::function<bool(const std::string&, const std::string&)>;
98 * @brief WebView signal type related with video playing.
100 using VideoPlayingCallback = std::function<void(bool)>;
103 * @brief WebView signal type related with http request interceptor.
105 using WebEngineRequestInterceptorSignalType = Signal<void(std::shared_ptr<Dali::WebEngineRequestInterceptor>)>;
108 * @brief WebView signal type related with console message will be logged.
110 using WebEngineConsoleMessageSignalType = Signal<void(std::shared_ptr<Dali::WebEngineConsoleMessage>)>;
113 * @brief WebView signal type related with certificate changed.
115 using WebEngineCertificateSignalType = Signal<void(std::shared_ptr<Dali::WebEngineCertificate>)>;
118 * @brief WebView signal type related with http authentication.
120 using WebEngineHttpAuthHandlerSignalType = Signal<void(std::shared_ptr<Dali::WebEngineHttpAuthHandler>)>;
123 * @brief WebView signal type related with context menu customized.
125 using WebEngineContextMenuCustomizedSignalType = Signal<void(std::shared_ptr<Dali::WebEngineContextMenu>)>;
128 * @brief WebView signal type related with context menu item selected.
130 using WebEngineContextMenuItemSelectedSignalType = Signal<void(std::shared_ptr<Dali::WebEngineContextMenuItem>)>;
133 * @brief Alert callback when JavaScript alert is called with a message.
134 * It returns true if a pop-up is created successfully, false otherwise.
136 using JavaScriptAlertCallback = std::function<bool(const std::string&)>;
139 * @brief Confirm callback when JavaScript confirm is called with a message.
140 * It returns true if a pop-up is created successfully, false otherwise.
142 using JavaScriptConfirmCallback = std::function<bool(const std::string&)>;
145 * @brief Prompt callback when JavaScript prompt is called with a message
146 * and an optional value that is the default value for the input field.
147 * It returns true if a pop-up is created successfully, false otherwise.
149 using JavaScriptPromptCallback = std::function<bool(const std::string&, const std::string&)>;
152 * @brief WebView signal type related with form repost decision.
154 using WebEngineFormRepostDecisionSignalType = Signal<void(std::shared_ptr<Dali::WebEngineFormRepostDecision>)>;
157 * @brief WebView signal type related with frame rendered.
159 using WebEngineFrameRenderedSignalType = Signal<void(void)>;
162 * @brief WebView signal type related with response policy would be decided.
164 using WebEngineResponsePolicyDecisionSignalType = Signal<void(std::shared_ptr<Dali::WebEnginePolicyDecision>)>;
167 * @brief Hit test callback called after hit test is created asynchronously.
169 using WebEngineHitTestCreatedCallback = std::function<bool(std::unique_ptr<Dali::WebEngineHitTest>)>;
172 * @brief Enumeration for the scroll edge.
174 enum class ScrollEdge
176 LEFT, ///< Left edge reached.
177 RIGHT, ///< Right edge reached.
178 TOP, ///< Top edge reached.
179 BOTTOM, ///< Bottom edge reached.
183 * @brief Enumeration that provides the option to find text.
185 enum class FindOption
187 NONE = 0, ///< No search flags, this means a case sensitive, no wrap, forward only search
188 CASE_INSENSITIVE = 1 << 0, ///< Case insensitive search
189 AT_WORD_STARTS = 1 << 1, ///< Search text only at the beginning of the words
190 TREAT_MEDIAL_CAPITAL_AS_WORD_START = 1 << 2, ///< Treat capital letters in the middle of words as word start
191 BACKWARDS = 1 << 3, ///< Search backwards
192 WRAP_AROUND = 1 << 4, ///< If not present the search stops at the end of the document
193 SHOW_OVERLAY = 1 << 5, ///< Show overlay
194 SHOW_FIND_INDICATOR = 1 << 6, ///< Show indicator
195 SHOW_HIGHLIGHT = 1 << 7, ///< Show highlight
199 * @brief Constructor.
201 WebEnginePlugin() = default;
206 virtual ~WebEnginePlugin() = default;
209 * @brief Create WebEngine instance.
211 * @param [in] width The width of Web
212 * @param [in] height The height of Web
213 * @param [in] locale The locale of Web
214 * @param [in] timezoneId The timezoneID of Web
216 virtual void Create(uint32_t width, uint32_t height, const std::string& locale, const std::string& timezoneId) = 0;
219 * @brief Create WebEngine instance.
221 * @param [in] width The width of Web
222 * @param [in] height The height of Web
223 * @param [in] argc The count of application arguments
224 * @param [in] argv The string array of application arguments
226 virtual void Create(uint32_t width, uint32_t height, uint32_t argc, char** argv) = 0;
229 * @brief Destroy WebEngine instance.
231 virtual void Destroy() = 0;
234 * @brief Get settings of WebEngine.
236 virtual WebEngineSettings& GetSettings() const = 0;
239 * @brief Get context of WebEngine.
241 virtual WebEngineContext& GetContext() const = 0;
244 * @brief Get cookie manager of WebEngine.
246 virtual WebEngineCookieManager& GetCookieManager() const = 0;
249 * @brief Get back-forward list of WebEngine.
251 virtual WebEngineBackForwardList& GetBackForwardList() const = 0;
254 * @brief Load a web page based on a given URL.
256 * @param [in] url The URL of the resource to load
258 virtual void LoadUrl(const std::string& url) = 0;
261 * @brief Return the title of the Web.
263 * @return The title of web page
265 virtual std::string GetTitle() const = 0;
268 * @brief Return the Favicon of the Web.
270 * @return Favicon of Dali::PixelData& type
272 virtual Dali::PixelData GetFavicon() const = 0;
275 * @brief Get image to render.
277 virtual NativeImageInterfacePtr GetNativeImageSource() = 0;
280 * @brief Return the URL of the Web.
282 * @return Url of string type
284 virtual const std::string& GetUrl() = 0;
287 * @brief Load a given string as web contents.
289 * @param [in] htmlString The string to use as the contents of the web page
291 virtual void LoadHtmlString(const std::string& htmlString) = 0;
294 * @brief Load the specified html string as the content of the view overriding current history entry
296 * @param[in] html HTML data to load
297 * @param[in] basicUri Base URL used for relative paths to external objects
298 * @param[in] unreachableUrl URL that could not be reached
300 * @return true if successfully loaded, false otherwise
302 virtual bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl) = 0;
305 * @brief Request loading the given contents by MIME type into the view object
307 * @param[in] contents The content to load
308 * @param[in] contentSize The size of contents (in bytes)
309 * @param[in] mimeType The type of contents, if 0 is given "text/html" is assumed
310 * @param[in] encoding The encoding for contents, if 0 is given "UTF-8" is assumed
311 * @param[in] baseUri The base URI to use for relative resources
313 * @return true if successfully request, false otherwise
315 virtual bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri) = 0;
318 * @brief Reload the Web.
320 virtual void Reload() = 0;
323 * @brief Reload the current page's document without cache
325 virtual bool ReloadWithoutCache() = 0;
328 * @brief Stop loading web contents on the current page.
330 virtual void StopLoading() = 0;
333 * @brief Suspend the operation associated with the view.
335 virtual void Suspend() = 0;
338 * @brief Resume the operation associated with the view object after calling Suspend().
340 virtual void Resume() = 0;
343 * @brief To suspend all url loading
345 virtual void SuspendNetworkLoading() = 0;
348 * @brief To resume new url network loading
350 virtual void ResumeNetworkLoading() = 0;
353 * @brief Add custom header
355 * @param[in] name custom header name to add the custom header
356 * @param[in] value custom header value to add the custom header
358 * @return true if succeeded, false otherwise
360 virtual bool AddCustomHeader(const std::string& name, const std::string& value) = 0;
363 * @brief Remove custom header
365 * @param[in] name custom header name to remove the custom header
367 * @return true if succeeded, false otherwise
369 virtual bool RemoveCustomHeader(const std::string& name) = 0;
372 * @brief Start the inspector server
374 * @param[in] port port number
376 * @return the port number
378 virtual uint32_t StartInspectorServer(uint32_t port) = 0;
381 * @brief Stop the inspector server
383 * @return true if succeeded, false otherwise
385 virtual bool StopInspectorServer() = 0;
388 * @brief Scroll web page of view by deltaX and deltaY.
390 * @param[in] deltaX horizontal offset to scroll
391 * @param[in] deltaY vertical offset to scroll
393 virtual void ScrollBy(int32_t deltaX, int32_t deltaY) = 0;
396 * @brief Scroll edge of view by deltaX and deltaY.
398 * @param[in] deltaX horizontal offset to scroll
399 * @param[in] deltaY vertical offset to scroll
401 * @return true if succeeded, false otherwise
403 virtual bool ScrollEdgeBy(int32_t deltaX, int32_t deltaY) = 0;
406 * @brief Scroll to the specified position of the given view.
408 virtual void SetScrollPosition(int32_t x, int32_t y) = 0;
411 * @brief Get the current scroll position of the given view.
413 virtual Dali::Vector2 GetScrollPosition() const = 0;
416 * @brief Get the possible scroll size of the given view.
418 virtual Dali::Vector2 GetScrollSize() const = 0;
421 * @brief Get the last known content's size.
423 virtual Dali::Vector2 GetContentSize() const = 0;
426 * @brief Return whether forward is possible.
428 * @return True if forward is possible, false otherwise
430 virtual bool CanGoForward() = 0;
433 * @brief Go to forward.
435 virtual void GoForward() = 0;
438 * @brief Return whether backward is possible.
440 * @return True if backward is possible, false otherwise
442 virtual bool CanGoBack() = 0;
447 virtual void GoBack() = 0;
450 * @brief Evaluate JavaScript code represented as a string.
452 * @param[in] script The JavaScript code
453 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
455 virtual void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler) = 0;
458 * @brief Add a message handler into JavaScript.
460 * @param[in] exposedObjectName The name of exposed object
461 * @param[in] handler The callback function
463 virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler) = 0;
466 * @brief Register a callback for JavaScript alert.
468 * @param[in] callback The callback function
470 virtual void RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback) = 0;
473 * @brief Reply for JavaScript alert.
475 virtual void JavaScriptAlertReply() = 0;
478 * @brief Register a callback for JavaScript confirm.
480 * @param[in] callback The callback function
482 virtual void RegisterJavaScriptConfirmCallback(JavaScriptConfirmCallback callback) = 0;
485 * @brief Reply for JavaScript confirm.
487 virtual void JavaScriptConfirmReply(bool confirmed) = 0;
490 * @brief Register a callback for JavaScript prompt.
492 * @param[in] callback The callback function
494 virtual void RegisterJavaScriptPromptCallback(JavaScriptPromptCallback callback) = 0;
497 * @brief Reply for JavaScript prompt.
499 virtual void JavaScriptPromptReply(const std::string& result) = 0;
502 * @brief Create a new hit test.
504 * @param[in] x the horizontal position to query
505 * @param[in] y the vertical position to query
506 * @param[in] mode the mode of hit test
508 * @return a new hit test object.
510 virtual std::unique_ptr<Dali::WebEngineHitTest> CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode) = 0;
513 * @brief create a hit test asynchronously.
515 * @param[in] x the horizontal position to query
516 * @param[in] y the vertical position to query
517 * @param[in] mode the mode of hit test
518 * @param[in] callback The callback function
520 * @return true if succeeded, false otherwise
522 virtual bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, WebEngineHitTestCreatedCallback callback) = 0;
525 * @brief Clear the history of Web.
527 virtual void ClearHistory() = 0;
530 * @brief Clear all tiles resources of Web.
532 virtual void ClearAllTilesResources() = 0;
535 * @brief Get user agent string.
537 * @return The string value of user agent
539 virtual const std::string& GetUserAgent() const = 0;
542 * @brief Set user agent string.
544 * @param[in] userAgent The string value of user agent
546 virtual void SetUserAgent(const std::string& userAgent) = 0;
549 * @brief Set size of Web Page.
551 virtual void SetSize(uint32_t width, uint32_t height) = 0;
554 * @brief Set background color of web page.
556 * @param[in] color Background color
558 virtual void SetDocumentBackgroundColor(Dali::Vector4 color) = 0;
561 * @brief Clear tiles when hidden.
563 * @param[in] cleared Whether tiles are cleared or not
565 virtual void ClearTilesWhenHidden(bool cleared) = 0;
568 * @brief Set multiplier of cover area of tile.
570 * @param[in] multiplier The multiplier of cover area
572 virtual void SetTileCoverAreaMultiplier(float multiplier) = 0;
575 * @brief Enable cursor by client.
577 * @param[in] enabled Whether cursor is enabled or not
579 virtual void EnableCursorByClient(bool enabled) = 0;
582 * @brief Get the selected text.
584 * @return the selected text
586 virtual std::string GetSelectedText() const = 0;
589 * @brief Send Touch Events.
591 virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
594 * @brief Send Key Events.
596 virtual bool SendKeyEvent(const KeyEvent& event) = 0;
599 * @brief Support mouse events or not.
600 * @param[in] enabled True if enabled, false othewise.
602 virtual void EnableMouseEvents(bool enabled) = 0;
605 * @brief Support key events or not.
606 * @param[in] enabled True if enabled, false othewise.
608 virtual void EnableKeyEvents(bool enabled) = 0;
612 * @param[in] focused True if focus is gained, false lost.
614 virtual void SetFocus(bool focused) = 0;
617 * @brief Set zoom factor of the current page.
618 * @param[in] zoomFactor a new factor to be set.
620 virtual void SetPageZoomFactor(float zoomFactor) = 0;
623 * @brief Query the current zoom factor of the page。
624 * @return The current page zoom factor.
626 virtual float GetPageZoomFactor() const = 0;
629 * @brief Set the current text zoom level。.
630 * @param[in] zoomFactor a new factor to be set.
632 virtual void SetTextZoomFactor(float zoomFactor) = 0;
635 * @brief Get the current text zoom level.
636 * @return The current text zoom factor.
638 virtual float GetTextZoomFactor() const = 0;
641 * @brief Get the current load progress of the page.
642 * @return The load progress of the page.
644 virtual float GetLoadProgressPercentage() const = 0;
647 * @brief Scale the current page, centered at the given point.
648 * @param[in] scaleFactor a new factor to be scaled.
649 * @param[in] point a center coordinate.
651 virtual void SetScaleFactor(float scaleFactor, Dali::Vector2 point) = 0;
654 * @brief Get the current scale factor of the page.
655 * @return The current scale factor.
657 virtual float GetScaleFactor() const = 0;
660 * @brief Request to activate/deactivate the accessibility usage set by web app.
661 * @param[in] activated Activate accessibility or not.
663 virtual void ActivateAccessibility(bool activated) = 0;
666 * @brief Request to set the current page's visibility.
667 * @param[in] visible Visible or not.
669 * @return true if succeeded, false otherwise
671 virtual bool SetVisibility(bool visible) = 0;
674 * @brief Search and highlight the given string in the document.
675 * @param[in] text The text to find
676 * @param[in] options The options to find
677 * @param[in] maxMatchCount The maximum match count to find
679 * @return true if found & highlighted, false otherwise
681 virtual bool HighlightText(const std::string& text, FindOption options, uint32_t maxMatchCount) = 0;
684 * @brief Add dynamic certificate path.
685 * @param[in] host host that required client authentication
686 * @param[in] certPath the file path stored certificate
688 virtual void AddDynamicCertificatePath(const std::string& host, const std::string& certPath) = 0;
691 * @brief Get snapshot of the specified viewArea of page.
693 * @param[in] viewArea The rectangle of screen shot
694 * @param[in] scaleFactor The scale factor
696 * @return pixel data of screen shot
698 virtual Dali::PixelData GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor) = 0;
701 * @brief Request to get snapshot of the specified viewArea of page asynchronously.
703 * @param[in] viewArea The rectangle of screen shot
704 * @param[in] scaleFactor The scale factor
705 * @param[in] callback The callback for screen shot
707 * @return true if requested successfully, false otherwise
709 virtual bool GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, ScreenshotCapturedCallback callback) = 0;
712 * @brief Asynchronously request to check if there is a video playing in the given view.
714 * @param[in] callback The callback called after checking if video is playing or not
716 * @return true if requested successfully, false otherwise
718 virtual bool CheckVideoPlayingAsynchronously(VideoPlayingCallback callback) = 0;
721 * @brief Set callback which will be called upon geolocation permission request.
723 * @param[in] callback The callback for requesting geolocation permission
725 virtual void RegisterGeolocationPermissionCallback(GeolocationPermissionCallback callback) = 0;
728 * @brief Update display area.
729 * @param[in] displayArea The display area need be updated.
731 virtual void UpdateDisplayArea(Dali::Rect<int32_t> displayArea) = 0;
734 * @brief Enable video hole.
735 * @param[in] enabled True if enabled, false othewise.
737 virtual void EnableVideoHole(bool enabled) = 0;
740 * @brief Send Hover Events.
741 * @param[in] event The hover event would be sent.
743 virtual bool SendHoverEvent(const HoverEvent& event) = 0;
746 * @brief Send Wheel Events.
747 * @param[in] event The wheel event would be sent.
749 virtual bool SendWheelEvent(const WheelEvent& event) = 0;
752 * @brief Connect to this signal to be notified when page loading is started.
754 * @return A signal object to connect with.
756 virtual WebEnginePageLoadSignalType& PageLoadStartedSignal() = 0;
759 * @brief Connect to this signal to be notified when page loading is in progress.
761 * @return A signal object to connect with.
763 virtual WebEnginePageLoadSignalType& PageLoadInProgressSignal() = 0;
766 * @brief Connect to this signal to be notified when page loading is finished.
768 * @return A signal object to connect with.
770 virtual WebEnginePageLoadSignalType& PageLoadFinishedSignal() = 0;
773 * @brief Connect to this signal to be notified when an error occurs in page loading.
775 * @return A signal object to connect with.
777 virtual WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() = 0;
780 * @brief Connect to this signal to be notified when scroll edge is reached.
782 * @return A signal object to connect with.
784 virtual WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal() = 0;
787 * @brief Connect to this signal to be notified when url is changed.
789 * @return A signal object to connect with.
791 virtual WebEngineUrlChangedSignalType& UrlChangedSignal() = 0;
794 * @brief Connect to this signal to be notified when form repost decision is requested.
796 * @return A signal object to connect with.
798 virtual WebEngineFormRepostDecisionSignalType& FormRepostDecisionSignal() = 0;
801 * @brief Connect to this signal to be notified when frame is rendered.
803 * @return A signal object to connect with.
805 virtual WebEngineFrameRenderedSignalType& FrameRenderedSignal() = 0;
808 * @brief Connect to this signal to be notified when http request need be intercepted.
810 * @return A signal object to connect with.
812 virtual WebEngineRequestInterceptorSignalType& RequestInterceptorSignal() = 0;
815 * @brief Connect to this signal to be notified when console message will be logged.
817 * @return A signal object to connect with.
819 virtual WebEngineConsoleMessageSignalType& ConsoleMessageSignal() = 0;
822 * @brief Connect to this signal to be notified when response policy would be decided.
824 * @return A signal object to connect with.
826 virtual WebEngineResponsePolicyDecisionSignalType& ResponsePolicyDecisionSignal() = 0;
829 * @brief Connect to this signal to be notified when certificate need be confirmed.
831 * @return A signal object to connect with.
833 virtual WebEngineCertificateSignalType& CertificateConfirmSignal() = 0;
836 * @brief Connect to this signal to be notified when ssl certificate is changed.
838 * @return A signal object to connect with.
840 virtual WebEngineCertificateSignalType& SslCertificateChangedSignal() = 0;
843 * @brief Connect to this signal to be notified when http authentication need be confirmed.
845 * @return A signal object to connect with.
847 virtual WebEngineHttpAuthHandlerSignalType& HttpAuthHandlerSignal() = 0;
850 * @brief Connect to this signal to be notified when context menu would be customized.
852 * @return A signal object to connect with.
854 virtual WebEngineContextMenuCustomizedSignalType& ContextMenuCustomizedSignal() = 0;
857 * @brief Connect to this signal to be notified when context menu item is selected.
859 * @return A signal object to connect with.
861 virtual WebEngineContextMenuItemSelectedSignalType& ContextMenuItemSelectedSignal() = 0;
864 // specialization has to be done in the same namespace
866 struct EnableBitMaskOperators<WebEnginePlugin::FindOption>
868 static const bool ENABLE = true;