1 #ifndef DALI_WEB_ENGINE_H
2 #define DALI_WEB_ENGINE_H
5 * Copyright (c) 2024 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/object/base-handle.h>
25 #include <dali/devel-api/adaptor-framework/accessibility.h>
26 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-plugin.h>
27 #include <dali/public-api/dali-adaptor-common.h>
31 class WebEngineContext;
32 class WebEngineCookieManager;
39 } // namespace Adaptor
41 } // namespace Internal
44 * @brief Proxy class to dynamically load, use and unload web engine plugin.
46 * The purpose of this class is to dynamically load the web engine plugin if and when its needed.
47 * So we don't slow down every application startup if they never need web engine.
49 class DALI_ADAPTOR_API WebEngine : public BaseHandle
63 * @brief Create a new instance of a WebEngine.
65 static WebEngine New();
68 * @brief Get context of WebEngine.
70 static Dali::WebEngineContext* GetContext();
73 * @brief Get cookie manager of WebEngine.
75 static Dali::WebEngineCookieManager* GetCookieManager();
78 * @brief Copy constructor.
80 * @param[in] WebEngine WebEngine to copy. The copied WebEngine will point at the same implementation
82 WebEngine(const WebEngine& WebEngine);
85 * @brief Assignment operator.
87 * @param[in] WebEngine The WebEngine to assign from.
88 * @return The updated WebEngine.
90 WebEngine& operator=(const WebEngine& WebEngine);
93 * @brief Move constructor.
95 * @param[in] WebEngine WebEngine to move. The moved WebEngine will point at the same implementation
97 WebEngine(WebEngine&& WebEngine);
100 * @brief Move assignment operator.
102 * @param[in] WebEngine The WebEngine to assign from.
103 * @return The updated WebEngine.
105 WebEngine& operator=(WebEngine&& WebEngine);
108 * @brief Downcast a handle to WebEngine handle.
110 * If handle points to a WebEngine the downcast produces valid
111 * handle. If not the returned handle is left uninitialized.
113 * @param[in] handle Handle to an object
114 * @return Handle to a WebEngine or an uninitialized handle
116 static WebEngine DownCast(BaseHandle handle);
119 * @brief Create WebEngine instance.
121 * @param [in] width The width of Web
122 * @param [in] height The height of Web
123 * @param [in] locale The locale of Web
124 * @param [in] timezoneId The timezoneID of Web
126 void Create(uint32_t width, uint32_t height, const std::string& locale, const std::string& timezoneId);
129 * @brief Create WebEngine instance.
131 * @param [in] width The width of Web
132 * @param [in] height The height of Web
133 * @param [in] argc The count of application arguments
134 * @param [in] argv The string array of application arguments
136 void Create(uint32_t width, uint32_t height, uint32_t argc, char** argv);
139 * @brief Destroy WebEngine instance.
144 * @brief Gets web engine plugin.
146 Dali::WebEnginePlugin* GetPlugin() const;
149 * @brief Get native image source to render.
151 NativeImageSourcePtr GetNativeImageSource();
154 * @brief Change orientation.
156 void ChangeOrientation(int orientation);
159 * @brief Get settings of WebEngine.
161 Dali::WebEngineSettings& GetSettings() const;
164 * @brief Get back-forward list of WebEngine.
166 Dali::WebEngineBackForwardList& GetBackForwardList() const;
169 * @brief Load a web page based on a given URL.
171 * @param [in] url The URL of the resource to load
173 void LoadUrl(const std::string& url);
176 * @brief Return the title of the Web.
178 * @return The title of web page
180 std::string GetTitle() const;
183 * @brief Return the Favicon of the Web.
185 * @return FavIcon of Dali::PixelData& type
187 Dali::PixelData GetFavicon() const;
190 * @brief Get the url.
192 std::string GetUrl() const;
195 * @brief Load a given string as web contents.
197 * @param [in] htmlString The string to use as the contents of the web page
199 void LoadHtmlString(const std::string& htmlString);
202 * @brief Load the specified html string as the content of the view overriding current history entry
204 * @param[in] html HTML data to load
205 * @param[in] basicUri Base URL used for relative paths to external objects
206 * @param[in] unreachableUrl URL that could not be reached
208 * @return true if successfully loaded, false otherwise
210 bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl);
213 * @brief Request loading the given contents by MIME type into the view object
215 * @param[in] contents The content to load
216 * @param[in] contentSize The size of contents (in bytes)
217 * @param[in] mimeType The type of contents, if 0 is given "text/html" is assumed
218 * @param[in] encoding The encoding for contents, if 0 is given "UTF-8" is assumed
219 * @param[in] baseUri The base URI to use for relative resources
221 * @return true if successfully request, false otherwise
223 bool LoadContents(const int8_t* contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri);
226 * @brief Reload the Web.
231 * @brief Reload the current page's document without cache
233 bool ReloadWithoutCache();
236 * @brief Stop loading web contents on the current page.
241 * @brief Suspend the operation associated with the view.
246 * @brief Resume the operation associated with the view object after calling Suspend().
251 * @brief To suspend all url loading
253 void SuspendNetworkLoading();
256 * @brief To resume new url network loading
258 void ResumeNetworkLoading();
261 * @brief Add custom header
263 * @param[in] name custom header name to add the custom header
264 * @param[in] value custom header value to add the custom header
266 * @return true if succeeded, false otherwise
268 bool AddCustomHeader(const std::string& name, const std::string& value);
271 * @brief Remove custom header
273 * @param[in] name custom header name to remove the custom header
275 * @return true if succeeded, false otherwise
277 bool RemoveCustomHeader(const std::string& name);
280 * @brief Start the inspector server
282 * @param[in] port port number
284 * @return the port number
286 uint32_t StartInspectorServer(uint32_t port);
289 * @brief Stop the inspector server
291 * @return true if succeeded, false otherwise
293 bool StopInspectorServer();
296 * @brief Scroll web page of view by deltaX and deltaY.
298 * @param[in] deltaX horizontal offset to scroll
299 * @param[in] deltaY vertical offset to scroll
301 void ScrollBy(int32_t deltaX, int32_t deltaY);
304 * @brief Scroll edge of view by deltaX and deltaY.
306 * @param[in] deltaX horizontal offset to scroll
307 * @param[in] deltaY vertical offset to scroll
309 * @return true if succeeded, false otherwise
311 bool ScrollEdgeBy(int32_t deltaX, int32_t deltaY);
314 * @brief Set an absolute scroll of the given view.
316 void SetScrollPosition(int32_t x, int32_t y);
319 * @brief Get the current scroll position of the given view.
321 Dali::Vector2 GetScrollPosition() const;
324 * @brief Get the possible scroll size of the given view.
326 Dali::Vector2 GetScrollSize() const;
329 * @brief Get the last known content's size.
331 Dali::Vector2 GetContentSize() const;
334 * @brief Return whether forward is possible.
336 * @return True if forward is possible, false otherwise
341 * @brief Go to forward.
346 * @brief Return whether backward is possible.
348 * @return True if backward is possible, false otherwise
358 * @brief Evaluate JavaScript code represented as a string.
360 * @param[in] script The JavaScript code
361 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
363 void EvaluateJavaScript(const std::string& script, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback resultHandler);
366 * @brief Add a message handler into JavaScript.
368 * @param[in] exposedObjectName The name of exposed object
369 * @param[in] handler The callback function
371 void AddJavaScriptMessageHandler(const std::string& exposedObjectName, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback handler);
374 * @brief Register a callback for JavaScript alert.
376 * @param[in] callback The callback function
378 void RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback);
381 * @brief Reply for JavaScript alert.
383 void JavaScriptAlertReply();
386 * @brief Register a callback for JavaScript confirm.
388 * @param[in] callback The callback function
390 void RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback);
393 * @brief Reply for JavaScript confirm.
394 * @param[in] confirmed True if confirmed, false otherwise.
396 void JavaScriptConfirmReply(bool confirmed);
399 * @brief Register a callback for JavaScript prompt.
401 * @param[in] callback The callback function
403 void RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback);
406 * @brief Reply for JavaScript prompt.
407 * @param[in] result The result returned from input-field in prompt popup.
409 void JavaScriptPromptReply(const std::string& result);
412 * @brief Create a new hit test.
414 * @param[in] x the horizontal position to query
415 * @param[in] y the vertical position to query
416 * @param[in] mode the mode of hit test
418 * @return a new hit test object
420 std::unique_ptr<Dali::WebEngineHitTest> CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode);
423 * @brief create a hit test asynchronously.
425 * @param[in] x the horizontal position to query
426 * @param[in] y the vertical position to query
427 * @param[in] mode the mode of hit test
428 * @param[in] callback the callback function
430 * @return true if succeeded, false otherwise
432 bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback);
435 * @brief Clear the history of Web.
440 * @brief Clear all tiles resources of Web.
442 void ClearAllTilesResources();
445 * @brief Get user agent string.
447 * @return The string value of user agent
449 std::string GetUserAgent() const;
452 * @brief Set user agent string.
454 * @param[in] userAgent The string value of user agent
456 void SetUserAgent(const std::string& userAgent);
459 * @brief Set the size of Web Pages.
461 void SetSize(uint32_t width, uint32_t height);
464 * @brief Set background color of web page.
466 * @param[in] color Background color
468 void SetDocumentBackgroundColor(Dali::Vector4 color);
471 * @brief Clear tiles when hidden.
473 * @param[in] cleared Whether tiles are cleared or not
475 void ClearTilesWhenHidden(bool cleared);
478 * @brief Set multiplier of cover area of tile.
480 * @param[in] multiplier The multiplier of cover area
482 void SetTileCoverAreaMultiplier(float multiplier);
485 * @brief Enable cursor by client.
487 * @param[in] enabled Whether cursor is enabled or not
489 void EnableCursorByClient(bool enabled);
492 * @brief Get the selected text.
494 * @return the selected text
496 std::string GetSelectedText() const;
499 * @brief Send Touch Events.
501 bool SendTouchEvent(const TouchEvent& touch);
504 * @brief Send key Events.
506 bool SendKeyEvent(const KeyEvent& event);
510 * @param[in] focused True if web view is focused, false otherwise
512 void SetFocus(bool focused);
515 * @brief Enable/disable mouse events. The default is enabled.
517 * @param[in] enabled True if mouse events are enabled, false otherwise
519 void EnableMouseEvents(bool enabled);
522 * @brief Enable/disable key events. The default is enabled.
524 * @param[in] enabled True if key events are enabled, false otherwise
526 void EnableKeyEvents(bool enabled);
529 * @brief Set zoom factor of the current page.
530 * @param[in] zoomFactor a new factor to be set.
532 void SetPageZoomFactor(float zoomFactor);
535 * @brief Query the current zoom factor of the page。
536 * @return The current page zoom factor.
538 float GetPageZoomFactor() const;
541 * @brief Set the current text zoom level。.
542 * @param[in] zoomFactor a new factor to be set.
544 void SetTextZoomFactor(float zoomFactor);
547 * @brief Get the current text zoom level.
548 * @return The current text zoom factor.
550 float GetTextZoomFactor() const;
553 * @brief Get the current load progress of the page.
554 * @return The load progress of the page.
556 float GetLoadProgressPercentage() const;
559 * @brief Scale the current page, centered at the given point.
560 * @param[in] scaleFactor a new factor to be scaled.
561 * @param[in] point a center coordinate.
563 void SetScaleFactor(float scaleFactor, Dali::Vector2 point);
566 * @brief Get the current scale factor of the page.
567 * @return The current scale factor.
569 float GetScaleFactor() const;
572 * @brief Request to activate/deactivate the accessibility usage set by web app.
573 * @param[in] activated Activate accessibility or not.
575 void ActivateAccessibility(bool activated);
578 * @brief Get the accessibility address (bus and path) for embedding.
579 * @return Accessibility address of the root web content element.
581 Accessibility::Address GetAccessibilityAddress();
584 * @brief Request to set the current page's visibility.
585 * @param[in] visible Visible or not.
587 * @return true if changed successfully, false otherwise
589 bool SetVisibility(bool visible);
592 * @brief Search and highlights the given string in the document.
593 * @param[in] text The text to find
594 * @param[in] options The options to find
595 * @param[in] maxMatchCount The maximum match count to find
597 * @return true if found & highlighted, false otherwise
599 bool HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount);
602 * @brief Add dynamic certificate path.
603 * @param[in] host host that required client authentication
604 * @param[in] certPath the file path stored certificate
606 void AddDynamicCertificatePath(const std::string& host, const std::string& certPath);
609 * @brief Get snapshot of the specified viewArea of page.
611 * @param[in] viewArea The rectangle of screen shot
612 * @param[in] scaleFactor The scale factor
614 * @return pixel data of screen shot
616 Dali::PixelData GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor);
619 * @brief Request to get snapshot of the specified viewArea of page asynchronously.
621 * @param[in] viewArea The rectangle of screen shot
622 * @param[in] scaleFactor The scale factor
623 * @param[in] callback The callback for screen shot
625 * @return true if requested successfully, false otherwise
627 bool GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback);
630 * @brief Asynchronous request to check if there is a video playing in the given view.
632 * @param[in] callback The callback called after checking if video is playing or not
634 * @return true if requested successfully, false otherwise
636 bool CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback);
639 * @brief Set callback which alled upon geolocation permission request.
641 * @param[in] callback The callback for requesting geolocation permission
643 void RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback);
646 * @brief Update display area.
647 * @param[in] displayArea The area to display web page
649 void UpdateDisplayArea(Dali::Rect<int32_t> displayArea);
652 * @brief Enable video hole.
653 * @param[in] enabled True if video hole is enabled, false otherwise
655 void EnableVideoHole(bool enabled);
658 * @brief Send hover events.
659 * @param[in] event The hover event would be sent.
661 bool SendHoverEvent(const HoverEvent& event);
664 * @brief Send wheel events.
665 * @param[in] event The wheel event would be sent.
667 bool SendWheelEvent(const WheelEvent& event);
670 * @brief Exit full-screen.
672 void ExitFullscreen();
675 * @brief Callback to be called when frame would be rendered.
677 * @param[in] callback
679 void RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback);
682 * @brief Callback to be called when page loading is started.
684 * @param[in] callback
686 void RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
689 * @brief Callback to be called when page loading is in progress.
691 * @param[in] callback
693 void RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
696 * @brief Callback to be called when page loading is finished.
698 * @param[in] callback
700 void RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
703 * @brief Callback to be called when an error occurs in page loading.
705 * @param[in] callback
707 void RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback);
710 * @brief Callback to be called when scroll edge is reached.
712 * @param[in] callback
714 void RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback);
717 * @brief Callback to be called when url is changed.
719 * @param[in] callback
721 void RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback);
724 * @brief Callback to be called when form repost decision is requested.
726 * @param[in] callback
728 void RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback);
731 * @brief Callback to be called when console message will be logged.
733 * @param[in] callback
735 void RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback);
738 * @brief Callback to be called when response policy would be decided.
740 * @param[in] callback
742 void RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback);
745 * @brief Callback to be called when navigation policy would be decided.
747 * @param[in] callback
749 void RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback);
752 * @brief Callback to be called when new window policy would be decided.
754 * @param[in] callback
756 void RegisterNewWindowPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNewWindowPolicyDecidedCallback callback);
759 * @brief Callback to be called when a new window would be created.
761 * @param[in] callback
763 void RegisterNewWindowCreatedCallback(Dali::WebEnginePlugin::WebEngineNewWindowCreatedCallback callback);
766 * @brief Callback to be called when certificate need be confirmed.
768 * @param[in] callback
770 void RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
773 * @brief Callback to be called when ssl certificate is changed.
775 * @param[in] callback
777 void RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
780 * @brief Callback to be called when http authentication need be confirmed.
782 * @param[in] callback
784 void RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback);
787 * @brief Callback to be called when context menu would be shown.
789 * @param[in] callback
791 void RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback);
794 * @brief Callback to be called when context menu would be hidden.
796 * @param[in] callback
798 void RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback);
801 * @brief Callback to be called when fullscreen would be entered.
803 * @param[in] callback
805 void RegisterFullscreenEnteredCallback(Dali::WebEnginePlugin::WebEngineFullscreenEnteredCallback callback);
808 * @brief Callback to be called when fullscreen would be exited.
810 * @param[in] callback
812 void RegisterFullscreenExitedCallback(Dali::WebEnginePlugin::WebEngineFullscreenExitedCallback callback);
815 * @brief Callback to be called when text would be found.
817 * @param[in] callback
819 void RegisterTextFoundCallback(Dali::WebEnginePlugin::WebEngineTextFoundCallback callback);
822 * @brief Get a plain text of current web page asynchronously.
824 * @param[in] callback The callback function called asynchronously.
826 void GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback);
828 private: // Not intended for application developers
830 * @brief Internal constructor
832 explicit DALI_INTERNAL WebEngine(Internal::Adaptor::WebEngine* internal);
837 #endif // DALI_WEB_ENGINE_H