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 WebEngineContext;
36 class WebEngineCookieManager;
37 class WebEngineFormRepostDecision;
38 class WebEngineRequestInterceptor;
39 class WebEngineSettings;
44 * @brief WebEnginePlugin is an abstract interface, used by dali-adaptor to access WebEngine plugin.
45 * A concrete implementation must be created for each platform and provided as dynamic library.
51 * @brief WebEngine signal type related with page loading.
53 using WebEnginePageLoadSignalType = Signal<void(const std::string&)>;
56 * @brief WebView signal type related with page loading error.
58 using WebEnginePageLoadErrorSignalType = Signal<void(const std::string&, int)>;
60 // forward declaration.
61 enum class ScrollEdge;
64 * @brief WebView signal type related with scroll edge reached.
66 using WebEngineScrollEdgeReachedSignalType = Signal<void(const ScrollEdge)>;
69 * @brief WebView signal type related with page url changed.
71 using WebEngineUrlChangedSignalType = Signal<void(const std::string&)>;
74 * @brief WebView signal type related with screen captured.
76 using ScreenshotCapturedCallback = std::function<void(Dali::PixelData)>;
79 * @brief WebView signal type related with geolocation permission.
80 * Host and protocol of security origin will be provided when requesting
81 * geolocation permission.
82 * It returns true if a pop-up is created successfully, false otherwise.
84 using GeolocationPermissionCallback = std::function<bool(const std::string&, const std::string&)>;
87 * @brief WebView signal type related with video playing.
89 using VideoPlayingCallback = std::function<void(bool)>;
92 * @brief WebView signal type related with http request interceptor.
94 using WebEngineRequestInterceptorSignalType = Signal<void(std::shared_ptr<Dali::WebEngineRequestInterceptor>)>;
97 * @brief Alert callback when JavaScript alert is called with a message.
98 * It returns true if a pop-up is created successfully, false otherwise.
100 using JavaScriptAlertCallback = std::function<bool(const std::string&)>;
103 * @brief Confirm callback when JavaScript confirm is called with a message.
104 * It returns true if a pop-up is created successfully, false otherwise.
106 using JavaScriptConfirmCallback = std::function<bool(const std::string&)>;
109 * @brief Prompt callback when JavaScript prompt is called with a message
110 * and an optional value that is the default value for the input field.
111 * It returns true if a pop-up is created successfully, false otherwise.
113 using JavaScriptPromptCallback = std::function<bool(const std::string&, const std::string&)>;
116 * @brief WebView signal type related with form repost decision.
118 using WebEngineFormRepostDecisionSignalType = Signal<void(std::shared_ptr<Dali::WebEngineFormRepostDecision>)>;
121 * @brief WebView signal type related with frame rendered.
123 using WebEngineFrameRenderedSignalType = Signal<void(void)>;
126 * @brief Enumeration for the scroll edge.
128 enum class ScrollEdge
130 LEFT, ///< Left edge reached.
131 RIGHT, ///< Right edge reached.
132 TOP, ///< Top edge reached.
133 BOTTOM, ///< Bottom edge reached.
137 * @brief Enumeration that provides the option to find text.
139 enum class FindOption
141 NONE = 0, ///< No search flags, this means a case sensitive, no wrap, forward only search
142 CASE_INSENSITIVE = 1 << 0, ///< Case insensitive search
143 AT_WORD_STARTS = 1 << 1, ///< Search text only at the beginning of the words
144 TREAT_MEDIAL_CAPITAL_AS_WORD_START = 1 << 2, ///< Treat capital letters in the middle of words as word start
145 BACKWARDS = 1 << 3, ///< Search backwards
146 WRAP_AROUND = 1 << 4, ///< If not present the search stops at the end of the document
147 SHOW_OVERLAY = 1 << 5, ///< Show overlay
148 SHOW_FIND_INDICATOR = 1 << 6, ///< Show indicator
149 SHOW_HIGHLIGHT = 1 << 7, ///< Show highlight
153 * @brief Constructor.
155 WebEnginePlugin() = default;
160 virtual ~WebEnginePlugin() = default;
163 * @brief Creates WebEngine instance.
165 * @param [in] width The width of Web
166 * @param [in] height The height of Web
167 * @param [in] locale The locale of Web
168 * @param [in] timezoneId The timezoneID of Web
170 virtual void Create(int width, int height, const std::string& locale, const std::string& timezoneId) = 0;
173 * @brief Creates WebEngine instance.
175 * @param [in] width The width of Web
176 * @param [in] height The height of Web
177 * @param [in] argc The count of application arguments
178 * @param [in] argv The string array of application arguments
180 virtual void Create(int width, int height, int argc, char** argv) = 0;
183 * @brief Destroys WebEngine instance.
185 virtual void Destroy() = 0;
188 * @brief Get settings of WebEngine.
190 virtual WebEngineSettings& GetSettings() const = 0;
193 * @brief Get context of WebEngine.
195 virtual WebEngineContext& GetContext() const = 0;
198 * @brief Get cookie manager of WebEngine.
200 virtual WebEngineCookieManager& GetCookieManager() const = 0;
203 * @brief Get back-forward list of WebEngine.
205 virtual WebEngineBackForwardList& GetBackForwardList() const = 0;
208 * @brief Loads a web page based on a given URL.
210 * @param [in] url The URL of the resource to load
212 virtual void LoadUrl(const std::string& url) = 0;
215 * @brief Returns the title of the Web.
217 * @return The title of web page
219 virtual std::string GetTitle() const = 0;
222 * @brief Returns the Favicon of the Web.
224 * @return Favicon of Dali::PixelData& type
226 virtual Dali::PixelData GetFavicon() const = 0;
229 * @brief Gets image to render.
231 virtual NativeImageInterfacePtr GetNativeImageSource() = 0;
234 * @brief Returns the URL of the Web.
236 * @return Url of string type
238 virtual const std::string& GetUrl() = 0;
241 * @brief Loads a given string as web contents.
243 * @param [in] htmlString The string to use as the contents of the web page
245 virtual void LoadHtmlString(const std::string& htmlString) = 0;
248 * @brief Load the specified html string as the content of the view overriding current history entry
250 * @param[in] html HTML data to load
251 * @param[in] basicUri Base URL used for relative paths to external objects
252 * @param[in] unreachableUrl URL that could not be reached
254 * @return true if successfully loaded, false otherwise
256 virtual bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl) = 0;
259 * @brief Requests loading the given contents by MIME type into the view object
261 * @param[in] contents The content to load
262 * @param[in] contentSize The size of contents (in bytes)
263 * @param[in] mimeType The type of contents, if 0 is given "text/html" is assumed
264 * @param[in] encoding The encoding for contents, if 0 is given "UTF-8" is assumed
265 * @param[in] baseUri The base URI to use for relative resources
267 * @return true if successfully request, false otherwise
269 virtual bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri) = 0;
272 * @brief Reloads the Web.
274 virtual void Reload() = 0;
277 * @brief Reloads the current page's document without cache
279 virtual bool ReloadWithoutCache() = 0;
282 * @brief Stops loading web contents on the current page.
284 virtual void StopLoading() = 0;
287 * @brief Suspends the operation associated with the view.
289 virtual void Suspend() = 0;
292 * @brief Resumes the operation associated with the view object after calling Suspend().
294 virtual void Resume() = 0;
297 * @brief To suspend all url loading
299 virtual void SuspendNetworkLoading() = 0;
302 * @brief To resume new url network loading
304 virtual void ResumeNetworkLoading() = 0;
307 * @brief Add custom header
309 * @param[in] name custom header name to add the custom header
310 * @param[in] value custom header value to add the custom header
312 * @return true if succeeded, false otherwise
314 virtual bool AddCustomHeader(const std::string& name, const std::string& value) = 0;
317 * @brief Remove custom header
319 * @param[in] name custom header name to remove the custom header
321 * @return true if succeeded, false otherwise
323 virtual bool RemoveCustomHeader(const std::string& name) = 0;
326 * @brief Start the inspector server
328 * @param[in] port port number
330 * @return the port number
332 virtual uint32_t StartInspectorServer(uint32_t port) = 0;
335 * @brief Stop the inspector server
337 * @return true if succeeded, false otherwise
339 virtual bool StopInspectorServer() = 0;
342 * @brief Scrolls web page of view by deltaX and deltaY.
344 * @param[in] deltaX horizontal offset to scroll
345 * @param[in] deltaY vertical offset to scroll
347 virtual void ScrollBy(int deltaX, int deltaY) = 0;
350 * @brief Scrolls edge of view by deltaX and deltaY.
352 * @param[in] deltaX horizontal offset to scroll
353 * @param[in] deltaY vertical offset to scroll
355 * @return true if succeeded, false otherwise
357 virtual bool ScrollEdgeBy(int deltaX, int deltaY) = 0;
360 * @brief Scroll to the specified position of the given view.
362 virtual void SetScrollPosition(int x, int y) = 0;
365 * @brief Gets the current scroll position of the given view.
367 virtual Dali::Vector2 GetScrollPosition() const = 0;
370 * @brief Gets the possible scroll size of the given view.
372 virtual Dali::Vector2 GetScrollSize() const = 0;
375 * @brief Gets the last known content's size.
377 virtual Dali::Vector2 GetContentSize() const = 0;
380 * @brief Returns whether forward is possible.
382 * @return True if forward is possible, false otherwise
384 virtual bool CanGoForward() = 0;
387 * @brief Goes to forward.
389 virtual void GoForward() = 0;
392 * @brief Returns whether backward is possible.
394 * @return True if backward is possible, false otherwise
396 virtual bool CanGoBack() = 0;
399 * @brief Goes to back.
401 virtual void GoBack() = 0;
404 * @brief Evaluates JavaScript code represented as a string.
406 * @param[in] script The JavaScript code
407 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
409 virtual void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler) = 0;
412 * @brief Add a message handler into JavaScript.
414 * @param[in] exposedObjectName The name of exposed object
415 * @param[in] handler The callback function
417 virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler) = 0;
420 * @brief Register a callback for JavaScript alert.
422 * @param[in] callback The callback function
424 virtual void RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback) = 0;
427 * @brief Reply for JavaScript alert.
429 virtual void JavaScriptAlertReply() = 0;
432 * @brief Register a callback for JavaScript confirm.
434 * @param[in] callback The callback function
436 virtual void RegisterJavaScriptConfirmCallback(JavaScriptConfirmCallback callback) = 0;
439 * @brief Reply for JavaScript confirm.
441 virtual void JavaScriptConfirmReply(bool confirmed) = 0;
444 * @brief Register a callback for JavaScript prompt.
446 * @param[in] callback The callback function
448 virtual void RegisterJavaScriptPromptCallback(JavaScriptPromptCallback callback) = 0;
451 * @brief Reply for JavaScript prompt.
453 virtual void JavaScriptPromptReply(const std::string& result) = 0;
456 * @brief Clears the history of Web.
458 virtual void ClearHistory() = 0;
461 * @brief Clears all tiles resources of Web.
463 virtual void ClearAllTilesResources() = 0;
466 * @brief Get user agent string.
468 * @return The string value of user agent
470 virtual const std::string& GetUserAgent() const = 0;
473 * @brief Set user agent string.
475 * @param[in] userAgent The string value of user agent
477 virtual void SetUserAgent(const std::string& userAgent) = 0;
480 * @brief Sets size of Web Page.
482 virtual void SetSize(int width, int height) = 0;
485 * @brief Sets background color of web page.
487 * @param[in] color Background color
489 virtual void SetDocumentBackgroundColor(Dali::Vector4 color) = 0;
492 * @brief Clears tiles when hidden.
494 * @param[in] cleared Whether tiles are cleared or not
496 virtual void ClearTilesWhenHidden(bool cleared) = 0;
499 * @brief Sets multiplier of cover area of tile.
501 * @param[in] multiplier The multiplier of cover area
503 virtual void SetTileCoverAreaMultiplier(float multiplier) = 0;
506 * @brief Enables cursor by client.
508 * @param[in] enabled Whether cursor is enabled or not
510 virtual void EnableCursorByClient(bool enabled) = 0;
513 * @brief Gets the selected text.
515 * @return the selected text
517 virtual std::string GetSelectedText() const = 0;
520 * @brief Sends Touch Events.
522 virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
525 * @brief Sends Key Events.
527 virtual bool SendKeyEvent(const KeyEvent& event) = 0;
530 * @brief Support mouse events or not.
531 * @param[in] enabled True if enabled, false othewise.
533 virtual void EnableMouseEvents(bool enabled) = 0;
536 * @brief Support key events or not.
537 * @param[in] enabled True if enabled, false othewise.
539 virtual void EnableKeyEvents(bool enabled) = 0;
543 * @param[in] focused True if focus is gained, false lost.
545 virtual void SetFocus(bool focused) = 0;
548 * @brief Sets zoom factor of the current page.
549 * @param[in] zoomFactor a new factor to be set.
551 virtual void SetPageZoomFactor(float zoomFactor) = 0;
554 * @brief Queries the current zoom factor of the page。
555 * @return The current page zoom factor.
557 virtual float GetPageZoomFactor() const = 0;
560 * @brief Sets the current text zoom level。.
561 * @param[in] zoomFactor a new factor to be set.
563 virtual void SetTextZoomFactor(float zoomFactor) = 0;
566 * @brief Gets the current text zoom level.
567 * @return The current text zoom factor.
569 virtual float GetTextZoomFactor() const = 0;
572 * @brief Gets the current load progress of the page.
573 * @return The load progress of the page.
575 virtual float GetLoadProgressPercentage() const = 0;
578 * @brief Scales the current page, centered at the given point.
579 * @param[in] scaleFactor a new factor to be scaled.
580 * @param[in] point a center coordinate.
582 virtual void SetScaleFactor(float scaleFactor, Dali::Vector2 point) = 0;
585 * @brief Gets the current scale factor of the page.
586 * @return The current scale factor.
588 virtual float GetScaleFactor() const = 0;
591 * @brief Request to activate/deactivate the accessibility usage set by web app.
592 * @param[in] activated Activate accessibility or not.
594 virtual void ActivateAccessibility(bool activated) = 0;
597 * @brief Request to set the current page's visibility.
598 * @param[in] visible Visible or not.
600 * @return true if succeeded, false otherwise
602 virtual bool SetVisibility(bool visible) = 0;
605 * @brief Searches and highlights the given string in the document.
606 * @param[in] text The text to find
607 * @param[in] options The options to find
608 * @param[in] maxMatchCount The maximum match count to find
610 * @return true if found & highlighted, false otherwise
612 virtual bool HighlightText(const std::string& text, FindOption options, uint32_t maxMatchCount) = 0;
615 * @brief Add dynamic certificate path.
616 * @param[in] host host that required client authentication
617 * @param[in] certPath the file path stored certificate
619 virtual void AddDynamicCertificatePath(const std::string& host, const std::string& certPath) = 0;
622 * @brief Get snapshot of the specified viewArea of page.
624 * @param[in] viewArea The rectangle of screen shot
625 * @param[in] scaleFactor The scale factor
627 * @return pixel data of screen shot
629 virtual Dali::PixelData GetScreenshot(Dali::Rect<int> viewArea, float scaleFactor) = 0;
632 * @brief Request to get snapshot of the specified viewArea of page asynchronously.
634 * @param[in] viewArea The rectangle of screen shot
635 * @param[in] scaleFactor The scale factor
636 * @param[in] callback The callback for screen shot
638 * @return true if requested successfully, false otherwise
640 virtual bool GetScreenshotAsynchronously(Dali::Rect<int> viewArea, float scaleFactor, ScreenshotCapturedCallback callback) = 0;
643 * @brief Asynchronously request to check if there is a video playing in the given view.
645 * @param[in] callback The callback called after checking if video is playing or not
647 * @return true if requested successfully, false otherwise
649 virtual bool CheckVideoPlayingAsynchronously(VideoPlayingCallback callback) = 0;
652 * @brief Sets callback which will be called upon geolocation permission request.
654 * @param[in] callback The callback for requesting geolocation permission
656 virtual void RegisterGeolocationPermissionCallback(GeolocationPermissionCallback callback) = 0;
659 * @brief Update display area.
660 * @param[in] displayArea The display area need be updated.
662 virtual void UpdateDisplayArea(Dali::Rect<int> displayArea) = 0;
665 * @brief Enable video hole.
666 * @param[in] enabled True if enabled, false othewise.
668 virtual void EnableVideoHole(bool enabled) = 0;
671 * @brief Sends Hover Events.
672 * @param[in] event The hover event would be sent.
674 virtual bool SendHoverEvent(const HoverEvent& event) = 0;
677 * @brief Sends Wheel Events.
678 * @param[in] event The wheel event would be sent.
680 virtual bool SendWheelEvent(const WheelEvent& event) = 0;
683 * @brief Connects to this signal to be notified when page loading is started.
685 * @return A signal object to connect with.
687 virtual WebEnginePageLoadSignalType& PageLoadStartedSignal() = 0;
690 * @brief Connects to this signal to be notified when page loading is in progress.
692 * @return A signal object to connect with.
694 virtual WebEnginePageLoadSignalType& PageLoadInProgressSignal() = 0;
697 * @brief Connects to this signal to be notified when page loading is finished.
699 * @return A signal object to connect with.
701 virtual WebEnginePageLoadSignalType& PageLoadFinishedSignal() = 0;
704 * @brief Connects to this signal to be notified when an error occurs in page loading.
706 * @return A signal object to connect with.
708 virtual WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() = 0;
711 * @brief Connects to this signal to be notified when scroll edge is reached.
713 * @return A signal object to connect with.
715 virtual WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal() = 0;
718 * @brief Connects to this signal to be notified when url is changed.
720 * @return A signal object to connect with.
722 virtual WebEngineUrlChangedSignalType& UrlChangedSignal() = 0;
725 * @brief Connects to this signal to be notified when form repost decision is requested.
727 * @return A signal object to connect with.
729 virtual WebEngineFormRepostDecisionSignalType& FormRepostDecisionSignal() = 0;
732 * @brief Connects to this signal to be notified when frame is rendered.
734 * @return A signal object to connect with.
736 virtual WebEngineFrameRenderedSignalType& FrameRenderedSignal() = 0;
739 * @brief Connects to this signal to be notified when http request need be intercepted.
741 * @return A signal object to connect with.
743 virtual WebEngineRequestInterceptorSignalType& RequestInterceptorSignal() = 0;
746 // specialization has to be done in the same namespace
748 struct EnableBitMaskOperators<WebEnginePlugin::FindOption>
750 static const bool ENABLE = true;