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.
22 #include <dali/devel-api/common/bitwise-enum.h>
23 #include <dali/public-api/images/native-image-interface.h>
24 #include <dali/public-api/math/rect.h>
25 #include <dali/public-api/signals/dali-signal.h>
34 class WebEngineBackForwardList;
35 class WebEngineCertificate;
36 class WebEngineConsoleMessage;
37 class WebEngineContext;
38 class WebEngineContextMenu;
39 class WebEngineContextMenuItem;
40 class WebEngineCookieManager;
41 class WebEngineFormRepostDecision;
42 class WebEngineHttpAuthHandler;
43 class WebEngineLoadError;
44 class WebEnginePolicyDecision;
45 class WebEngineRequestInterceptor;
46 class WebEngineSettings;
51 * @brief WebEnginePlugin is an abstract interface, used by dali-adaptor to access WebEngine plugin.
52 * A concrete implementation must be created for each platform and provided as dynamic library.
58 * @brief WebEngine signal type related with page loading.
60 using WebEnginePageLoadSignalType = Signal<void(const std::string&)>;
63 * @brief WebView signal type related with page loading error.
65 using WebEnginePageLoadErrorSignalType = Signal<void(std::shared_ptr<Dali::WebEngineLoadError>)>;
67 // forward declaration.
68 enum class ScrollEdge;
71 * @brief WebView signal type related with scroll edge reached.
73 using WebEngineScrollEdgeReachedSignalType = Signal<void(const ScrollEdge)>;
76 * @brief WebView signal type related with page url changed.
78 using WebEngineUrlChangedSignalType = Signal<void(const std::string&)>;
81 * @brief WebView signal type related with screen captured.
83 using ScreenshotCapturedCallback = std::function<void(Dali::PixelData)>;
86 * @brief WebView signal type related with geolocation permission.
87 * Host and protocol of security origin will be provided when requesting
88 * geolocation permission.
89 * It returns true if a pop-up is created successfully, false otherwise.
91 using GeolocationPermissionCallback = std::function<bool(const std::string&, const std::string&)>;
94 * @brief WebView signal type related with video playing.
96 using VideoPlayingCallback = std::function<void(bool)>;
99 * @brief WebView signal type related with http request interceptor.
101 using WebEngineRequestInterceptorSignalType = Signal<void(std::shared_ptr<Dali::WebEngineRequestInterceptor>)>;
104 * @brief WebView signal type related with console message will be logged.
106 using WebEngineConsoleMessageSignalType = Signal<void(std::shared_ptr<Dali::WebEngineConsoleMessage>)>;
109 * @brief WebView signal type related with certificate changed.
111 using WebEngineCertificateSignalType = Signal<void(std::shared_ptr<Dali::WebEngineCertificate>)>;
114 * @brief WebView signal type related with http authentication.
116 using WebEngineHttpAuthHandlerSignalType = Signal<void(std::shared_ptr<Dali::WebEngineHttpAuthHandler>)>;
119 * @brief WebView signal type related with context menu customized.
121 using WebEngineContextMenuCustomizedSignalType = Signal<void(std::shared_ptr<Dali::WebEngineContextMenu>)>;
124 * @brief WebView signal type related with context menu item selected.
126 using WebEngineContextMenuItemSelectedSignalType = Signal<void(std::shared_ptr<Dali::WebEngineContextMenuItem>)>;
129 * @brief Alert callback when JavaScript alert is called with a message.
130 * It returns true if a pop-up is created successfully, false otherwise.
132 using JavaScriptAlertCallback = std::function<bool(const std::string&)>;
135 * @brief Confirm callback when JavaScript confirm is called with a message.
136 * It returns true if a pop-up is created successfully, false otherwise.
138 using JavaScriptConfirmCallback = std::function<bool(const std::string&)>;
141 * @brief Prompt callback when JavaScript prompt is called with a message
142 * and an optional value that is the default value for the input field.
143 * It returns true if a pop-up is created successfully, false otherwise.
145 using JavaScriptPromptCallback = std::function<bool(const std::string&, const std::string&)>;
148 * @brief WebView signal type related with form repost decision.
150 using WebEngineFormRepostDecisionSignalType = Signal<void(std::shared_ptr<Dali::WebEngineFormRepostDecision>)>;
153 * @brief WebView signal type related with frame rendered.
155 using WebEngineFrameRenderedSignalType = Signal<void(void)>;
158 * @brief WebView signal type related with policy would be decided.
160 using WebEnginePolicyDecisionSignalType = Signal<void(std::shared_ptr<Dali::WebEnginePolicyDecision>)>;
163 * @brief Enumeration for the scroll edge.
165 enum class ScrollEdge
167 LEFT, ///< Left edge reached.
168 RIGHT, ///< Right edge reached.
169 TOP, ///< Top edge reached.
170 BOTTOM, ///< Bottom edge reached.
174 * @brief Enumeration that provides the option to find text.
176 enum class FindOption
178 NONE = 0, ///< No search flags, this means a case sensitive, no wrap, forward only search
179 CASE_INSENSITIVE = 1 << 0, ///< Case insensitive search
180 AT_WORD_STARTS = 1 << 1, ///< Search text only at the beginning of the words
181 TREAT_MEDIAL_CAPITAL_AS_WORD_START = 1 << 2, ///< Treat capital letters in the middle of words as word start
182 BACKWARDS = 1 << 3, ///< Search backwards
183 WRAP_AROUND = 1 << 4, ///< If not present the search stops at the end of the document
184 SHOW_OVERLAY = 1 << 5, ///< Show overlay
185 SHOW_FIND_INDICATOR = 1 << 6, ///< Show indicator
186 SHOW_HIGHLIGHT = 1 << 7, ///< Show highlight
190 * @brief Constructor.
192 WebEnginePlugin() = default;
197 virtual ~WebEnginePlugin() = default;
200 * @brief Create WebEngine instance.
202 * @param [in] width The width of Web
203 * @param [in] height The height of Web
204 * @param [in] locale The locale of Web
205 * @param [in] timezoneId The timezoneID of Web
207 virtual void Create(int width, int height, const std::string& locale, const std::string& timezoneId) = 0;
210 * @brief Create WebEngine instance.
212 * @param [in] width The width of Web
213 * @param [in] height The height of Web
214 * @param [in] argc The count of application arguments
215 * @param [in] argv The string array of application arguments
217 virtual void Create(int width, int height, int argc, char** argv) = 0;
220 * @brief Destroy WebEngine instance.
222 virtual void Destroy() = 0;
225 * @brief Get settings of WebEngine.
227 virtual WebEngineSettings& GetSettings() const = 0;
230 * @brief Get context of WebEngine.
232 virtual WebEngineContext& GetContext() const = 0;
235 * @brief Get cookie manager of WebEngine.
237 virtual WebEngineCookieManager& GetCookieManager() const = 0;
240 * @brief Get back-forward list of WebEngine.
242 virtual WebEngineBackForwardList& GetBackForwardList() const = 0;
245 * @brief Load a web page based on a given URL.
247 * @param [in] url The URL of the resource to load
249 virtual void LoadUrl(const std::string& url) = 0;
252 * @brief Return the title of the Web.
254 * @return The title of web page
256 virtual std::string GetTitle() const = 0;
259 * @brief Return the Favicon of the Web.
261 * @return Favicon of Dali::PixelData& type
263 virtual Dali::PixelData GetFavicon() const = 0;
266 * @brief Get image to render.
268 virtual NativeImageInterfacePtr GetNativeImageSource() = 0;
271 * @brief Return the URL of the Web.
273 * @return Url of string type
275 virtual const std::string& GetUrl() = 0;
278 * @brief Load a given string as web contents.
280 * @param [in] htmlString The string to use as the contents of the web page
282 virtual void LoadHtmlString(const std::string& htmlString) = 0;
285 * @brief Load the specified html string as the content of the view overriding current history entry
287 * @param[in] html HTML data to load
288 * @param[in] basicUri Base URL used for relative paths to external objects
289 * @param[in] unreachableUrl URL that could not be reached
291 * @return true if successfully loaded, false otherwise
293 virtual bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl) = 0;
296 * @brief Request loading the given contents by MIME type into the view object
298 * @param[in] contents The content to load
299 * @param[in] contentSize The size of contents (in bytes)
300 * @param[in] mimeType The type of contents, if 0 is given "text/html" is assumed
301 * @param[in] encoding The encoding for contents, if 0 is given "UTF-8" is assumed
302 * @param[in] baseUri The base URI to use for relative resources
304 * @return true if successfully request, false otherwise
306 virtual bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri) = 0;
309 * @brief Reload the Web.
311 virtual void Reload() = 0;
314 * @brief Reload the current page's document without cache
316 virtual bool ReloadWithoutCache() = 0;
319 * @brief Stop loading web contents on the current page.
321 virtual void StopLoading() = 0;
324 * @brief Suspend the operation associated with the view.
326 virtual void Suspend() = 0;
329 * @brief Resume the operation associated with the view object after calling Suspend().
331 virtual void Resume() = 0;
334 * @brief To suspend all url loading
336 virtual void SuspendNetworkLoading() = 0;
339 * @brief To resume new url network loading
341 virtual void ResumeNetworkLoading() = 0;
344 * @brief Add custom header
346 * @param[in] name custom header name to add the custom header
347 * @param[in] value custom header value to add the custom header
349 * @return true if succeeded, false otherwise
351 virtual bool AddCustomHeader(const std::string& name, const std::string& value) = 0;
354 * @brief Remove custom header
356 * @param[in] name custom header name to remove the custom header
358 * @return true if succeeded, false otherwise
360 virtual bool RemoveCustomHeader(const std::string& name) = 0;
363 * @brief Start the inspector server
365 * @param[in] port port number
367 * @return the port number
369 virtual uint32_t StartInspectorServer(uint32_t port) = 0;
372 * @brief Stop the inspector server
374 * @return true if succeeded, false otherwise
376 virtual bool StopInspectorServer() = 0;
379 * @brief Scroll web page of view by deltaX and deltaY.
381 * @param[in] deltaX horizontal offset to scroll
382 * @param[in] deltaY vertical offset to scroll
384 virtual void ScrollBy(int deltaX, int deltaY) = 0;
387 * @brief Scroll edge of view by deltaX and deltaY.
389 * @param[in] deltaX horizontal offset to scroll
390 * @param[in] deltaY vertical offset to scroll
392 * @return true if succeeded, false otherwise
394 virtual bool ScrollEdgeBy(int deltaX, int deltaY) = 0;
397 * @brief Scroll to the specified position of the given view.
399 virtual void SetScrollPosition(int x, int y) = 0;
402 * @brief Get the current scroll position of the given view.
404 virtual Dali::Vector2 GetScrollPosition() const = 0;
407 * @brief Get the possible scroll size of the given view.
409 virtual Dali::Vector2 GetScrollSize() const = 0;
412 * @brief Get the last known content's size.
414 virtual Dali::Vector2 GetContentSize() const = 0;
417 * @brief Return whether forward is possible.
419 * @return True if forward is possible, false otherwise
421 virtual bool CanGoForward() = 0;
424 * @brief Go to forward.
426 virtual void GoForward() = 0;
429 * @brief Return whether backward is possible.
431 * @return True if backward is possible, false otherwise
433 virtual bool CanGoBack() = 0;
438 virtual void GoBack() = 0;
441 * @brief Evaluate JavaScript code represented as a string.
443 * @param[in] script The JavaScript code
444 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
446 virtual void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler) = 0;
449 * @brief Add a message handler into JavaScript.
451 * @param[in] exposedObjectName The name of exposed object
452 * @param[in] handler The callback function
454 virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler) = 0;
457 * @brief Register a callback for JavaScript alert.
459 * @param[in] callback The callback function
461 virtual void RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback) = 0;
464 * @brief Reply for JavaScript alert.
466 virtual void JavaScriptAlertReply() = 0;
469 * @brief Register a callback for JavaScript confirm.
471 * @param[in] callback The callback function
473 virtual void RegisterJavaScriptConfirmCallback(JavaScriptConfirmCallback callback) = 0;
476 * @brief Reply for JavaScript confirm.
478 virtual void JavaScriptConfirmReply(bool confirmed) = 0;
481 * @brief Register a callback for JavaScript prompt.
483 * @param[in] callback The callback function
485 virtual void RegisterJavaScriptPromptCallback(JavaScriptPromptCallback callback) = 0;
488 * @brief Reply for JavaScript prompt.
490 virtual void JavaScriptPromptReply(const std::string& result) = 0;
493 * @brief Clear the history of Web.
495 virtual void ClearHistory() = 0;
498 * @brief Clear all tiles resources of Web.
500 virtual void ClearAllTilesResources() = 0;
503 * @brief Get user agent string.
505 * @return The string value of user agent
507 virtual const std::string& GetUserAgent() const = 0;
510 * @brief Set user agent string.
512 * @param[in] userAgent The string value of user agent
514 virtual void SetUserAgent(const std::string& userAgent) = 0;
517 * @brief Set size of Web Page.
519 virtual void SetSize(int width, int height) = 0;
522 * @brief Set background color of web page.
524 * @param[in] color Background color
526 virtual void SetDocumentBackgroundColor(Dali::Vector4 color) = 0;
529 * @brief Clear tiles when hidden.
531 * @param[in] cleared Whether tiles are cleared or not
533 virtual void ClearTilesWhenHidden(bool cleared) = 0;
536 * @brief Set multiplier of cover area of tile.
538 * @param[in] multiplier The multiplier of cover area
540 virtual void SetTileCoverAreaMultiplier(float multiplier) = 0;
543 * @brief Enable cursor by client.
545 * @param[in] enabled Whether cursor is enabled or not
547 virtual void EnableCursorByClient(bool enabled) = 0;
550 * @brief Get the selected text.
552 * @return the selected text
554 virtual std::string GetSelectedText() const = 0;
557 * @brief Send Touch Events.
559 virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
562 * @brief Send Key Events.
564 virtual bool SendKeyEvent(const KeyEvent& event) = 0;
567 * @brief Support mouse events or not.
568 * @param[in] enabled True if enabled, false othewise.
570 virtual void EnableMouseEvents(bool enabled) = 0;
573 * @brief Support key events or not.
574 * @param[in] enabled True if enabled, false othewise.
576 virtual void EnableKeyEvents(bool enabled) = 0;
580 * @param[in] focused True if focus is gained, false lost.
582 virtual void SetFocus(bool focused) = 0;
585 * @brief Set zoom factor of the current page.
586 * @param[in] zoomFactor a new factor to be set.
588 virtual void SetPageZoomFactor(float zoomFactor) = 0;
591 * @brief Query the current zoom factor of the page。
592 * @return The current page zoom factor.
594 virtual float GetPageZoomFactor() const = 0;
597 * @brief Set the current text zoom level。.
598 * @param[in] zoomFactor a new factor to be set.
600 virtual void SetTextZoomFactor(float zoomFactor) = 0;
603 * @brief Get the current text zoom level.
604 * @return The current text zoom factor.
606 virtual float GetTextZoomFactor() const = 0;
609 * @brief Get the current load progress of the page.
610 * @return The load progress of the page.
612 virtual float GetLoadProgressPercentage() const = 0;
615 * @brief Scale the current page, centered at the given point.
616 * @param[in] scaleFactor a new factor to be scaled.
617 * @param[in] point a center coordinate.
619 virtual void SetScaleFactor(float scaleFactor, Dali::Vector2 point) = 0;
622 * @brief Get the current scale factor of the page.
623 * @return The current scale factor.
625 virtual float GetScaleFactor() const = 0;
628 * @brief Request to activate/deactivate the accessibility usage set by web app.
629 * @param[in] activated Activate accessibility or not.
631 virtual void ActivateAccessibility(bool activated) = 0;
634 * @brief Request to set the current page's visibility.
635 * @param[in] visible Visible or not.
637 * @return true if succeeded, false otherwise
639 virtual bool SetVisibility(bool visible) = 0;
642 * @brief Search and highlight the given string in the document.
643 * @param[in] text The text to find
644 * @param[in] options The options to find
645 * @param[in] maxMatchCount The maximum match count to find
647 * @return true if found & highlighted, false otherwise
649 virtual bool HighlightText(const std::string& text, FindOption options, uint32_t maxMatchCount) = 0;
652 * @brief Add dynamic certificate path.
653 * @param[in] host host that required client authentication
654 * @param[in] certPath the file path stored certificate
656 virtual void AddDynamicCertificatePath(const std::string& host, const std::string& certPath) = 0;
659 * @brief Get snapshot of the specified viewArea of page.
661 * @param[in] viewArea The rectangle of screen shot
662 * @param[in] scaleFactor The scale factor
664 * @return pixel data of screen shot
666 virtual Dali::PixelData GetScreenshot(Dali::Rect<int> viewArea, float scaleFactor) = 0;
669 * @brief Request to get snapshot of the specified viewArea of page asynchronously.
671 * @param[in] viewArea The rectangle of screen shot
672 * @param[in] scaleFactor The scale factor
673 * @param[in] callback The callback for screen shot
675 * @return true if requested successfully, false otherwise
677 virtual bool GetScreenshotAsynchronously(Dali::Rect<int> viewArea, float scaleFactor, ScreenshotCapturedCallback callback) = 0;
680 * @brief Asynchronously request to check if there is a video playing in the given view.
682 * @param[in] callback The callback called after checking if video is playing or not
684 * @return true if requested successfully, false otherwise
686 virtual bool CheckVideoPlayingAsynchronously(VideoPlayingCallback callback) = 0;
689 * @brief Set callback which will be called upon geolocation permission request.
691 * @param[in] callback The callback for requesting geolocation permission
693 virtual void RegisterGeolocationPermissionCallback(GeolocationPermissionCallback callback) = 0;
696 * @brief Update display area.
697 * @param[in] displayArea The display area need be updated.
699 virtual void UpdateDisplayArea(Dali::Rect<int> displayArea) = 0;
702 * @brief Enable video hole.
703 * @param[in] enabled True if enabled, false othewise.
705 virtual void EnableVideoHole(bool enabled) = 0;
708 * @brief Send Hover Events.
709 * @param[in] event The hover event would be sent.
711 virtual bool SendHoverEvent(const HoverEvent& event) = 0;
714 * @brief Send Wheel Events.
715 * @param[in] event The wheel event would be sent.
717 virtual bool SendWheelEvent(const WheelEvent& event) = 0;
720 * @brief Connect to this signal to be notified when page loading is started.
722 * @return A signal object to connect with.
724 virtual WebEnginePageLoadSignalType& PageLoadStartedSignal() = 0;
727 * @brief Connect to this signal to be notified when page loading is in progress.
729 * @return A signal object to connect with.
731 virtual WebEnginePageLoadSignalType& PageLoadInProgressSignal() = 0;
734 * @brief Connect to this signal to be notified when page loading is finished.
736 * @return A signal object to connect with.
738 virtual WebEnginePageLoadSignalType& PageLoadFinishedSignal() = 0;
741 * @brief Connect to this signal to be notified when an error occurs in page loading.
743 * @return A signal object to connect with.
745 virtual WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() = 0;
748 * @brief Connect to this signal to be notified when scroll edge is reached.
750 * @return A signal object to connect with.
752 virtual WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal() = 0;
755 * @brief Connect to this signal to be notified when url is changed.
757 * @return A signal object to connect with.
759 virtual WebEngineUrlChangedSignalType& UrlChangedSignal() = 0;
762 * @brief Connect to this signal to be notified when form repost decision is requested.
764 * @return A signal object to connect with.
766 virtual WebEngineFormRepostDecisionSignalType& FormRepostDecisionSignal() = 0;
769 * @brief Connect to this signal to be notified when frame is rendered.
771 * @return A signal object to connect with.
773 virtual WebEngineFrameRenderedSignalType& FrameRenderedSignal() = 0;
776 * @brief Connect to this signal to be notified when http request need be intercepted.
778 * @return A signal object to connect with.
780 virtual WebEngineRequestInterceptorSignalType& RequestInterceptorSignal() = 0;
783 * @brief Connect to this signal to be notified when console message will be logged.
785 * @return A signal object to connect with.
787 virtual WebEngineConsoleMessageSignalType& ConsoleMessageSignal() = 0;
790 * @brief Connect to this signal to be notified when new policy would be decided.
792 * @return A signal object to connect with.
794 virtual WebEnginePolicyDecisionSignalType& PolicyDecisionSignal() = 0;
797 * @brief Connect to this signal to be notified when certificate need be confirmed.
799 * @return A signal object to connect with.
801 virtual WebEngineCertificateSignalType& CertificateConfirmSignal() = 0;
804 * @brief Connect to this signal to be notified when ssl certificate is changed.
806 * @return A signal object to connect with.
808 virtual WebEngineCertificateSignalType& SslCertificateChangedSignal() = 0;
811 * @brief Connect to this signal to be notified when http authentication need be confirmed.
813 * @return A signal object to connect with.
815 virtual WebEngineHttpAuthHandlerSignalType& HttpAuthHandlerSignal() = 0;
818 * @brief Connect to this signal to be notified when context menu would be customized.
820 * @return A signal object to connect with.
822 virtual WebEngineContextMenuCustomizedSignalType& ContextMenuCustomizedSignal() = 0;
825 * @brief Connect to this signal to be notified when context menu item is selected.
827 * @return A signal object to connect with.
829 virtual WebEngineContextMenuItemSelectedSignalType& ContextMenuItemSelectedSignal() = 0;
832 // specialization has to be done in the same namespace
834 struct EnableBitMaskOperators<WebEnginePlugin::FindOption>
836 static const bool ENABLE = true;