1 #ifndef DALI_WEB_ENGINE_H
2 #define DALI_WEB_ENGINE_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/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 Get settings of WebEngine.
156 Dali::WebEngineSettings& GetSettings() const;
159 * @brief Get back-forward list of WebEngine.
161 Dali::WebEngineBackForwardList& GetBackForwardList() const;
164 * @brief Load a web page based on a given URL.
166 * @param [in] url The URL of the resource to load
168 void LoadUrl(const std::string& url);
171 * @brief Return the title of the Web.
173 * @return The title of web page
175 std::string GetTitle() const;
178 * @brief Return the Favicon of the Web.
180 * @return FavIcon of Dali::PixelData& type
182 Dali::PixelData GetFavicon() const;
185 * @brief Get the url.
187 std::string GetUrl() const;
190 * @brief Load a given string as web contents.
192 * @param [in] htmlString The string to use as the contents of the web page
194 void LoadHtmlString(const std::string& htmlString);
197 * @brief Load the specified html string as the content of the view overriding current history entry
199 * @param[in] html HTML data to load
200 * @param[in] basicUri Base URL used for relative paths to external objects
201 * @param[in] unreachableUrl URL that could not be reached
203 * @return true if successfully loaded, false otherwise
205 bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl);
208 * @brief Request loading the given contents by MIME type into the view object
210 * @param[in] contents The content to load
211 * @param[in] contentSize The size of contents (in bytes)
212 * @param[in] mimeType The type of contents, if 0 is given "text/html" is assumed
213 * @param[in] encoding The encoding for contents, if 0 is given "UTF-8" is assumed
214 * @param[in] baseUri The base URI to use for relative resources
216 * @return true if successfully request, false otherwise
218 bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri);
221 * @brief Reload the Web.
226 * @brief Reload the current page's document without cache
228 bool ReloadWithoutCache();
231 * @brief Stop loading web contents on the current page.
236 * @brief Suspend the operation associated with the view.
241 * @brief Resume the operation associated with the view object after calling Suspend().
246 * @brief To suspend all url loading
248 void SuspendNetworkLoading();
251 * @brief To resume new url network loading
253 void ResumeNetworkLoading();
256 * @brief Add custom header
258 * @param[in] name custom header name to add the custom header
259 * @param[in] value custom header value to add the custom header
261 * @return true if succeeded, false otherwise
263 bool AddCustomHeader(const std::string& name, const std::string& value);
266 * @brief Remove custom header
268 * @param[in] name custom header name to remove the custom header
270 * @return true if succeeded, false otherwise
272 bool RemoveCustomHeader(const std::string& name);
275 * @brief Start the inspector server
277 * @param[in] port port number
279 * @return the port number
281 uint32_t StartInspectorServer(uint32_t port);
284 * @brief Stop the inspector server
286 * @return true if succeeded, false otherwise
288 bool StopInspectorServer();
291 * @brief Scroll web page of view by deltaX and deltaY.
293 * @param[in] deltaX horizontal offset to scroll
294 * @param[in] deltaY vertical offset to scroll
296 void ScrollBy(int32_t deltaX, int32_t deltaY);
299 * @brief Scroll edge of view by deltaX and deltaY.
301 * @param[in] deltaX horizontal offset to scroll
302 * @param[in] deltaY vertical offset to scroll
304 * @return true if succeeded, false otherwise
306 bool ScrollEdgeBy(int32_t deltaX, int32_t deltaY);
309 * @brief Set an absolute scroll of the given view.
311 void SetScrollPosition(int32_t x, int32_t y);
314 * @brief Get the current scroll position of the given view.
316 Dali::Vector2 GetScrollPosition() const;
319 * @brief Get the possible scroll size of the given view.
321 Dali::Vector2 GetScrollSize() const;
324 * @brief Get the last known content's size.
326 Dali::Vector2 GetContentSize() const;
329 * @brief Return whether forward is possible.
331 * @return True if forward is possible, false otherwise
336 * @brief Go to forward.
341 * @brief Return whether backward is possible.
343 * @return True if backward is possible, false otherwise
353 * @brief Evaluate JavaScript code represented as a string.
355 * @param[in] script The JavaScript code
356 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
358 void EvaluateJavaScript(const std::string& script, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback resultHandler);
361 * @brief Add a message handler into JavaScript.
363 * @param[in] exposedObjectName The name of exposed object
364 * @param[in] handler The callback function
366 void AddJavaScriptMessageHandler(const std::string& exposedObjectName, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback handler);
369 * @brief Register a callback for JavaScript alert.
371 * @param[in] callback The callback function
373 void RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback);
376 * @brief Reply for JavaScript alert.
378 void JavaScriptAlertReply();
381 * @brief Register a callback for JavaScript confirm.
383 * @param[in] callback The callback function
385 void RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback);
388 * @brief Reply for JavaScript confirm.
389 * @param[in] confirmed True if confirmed, false otherwise.
391 void JavaScriptConfirmReply(bool confirmed);
394 * @brief Register a callback for JavaScript prompt.
396 * @param[in] callback The callback function
398 void RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback);
401 * @brief Reply for JavaScript prompt.
402 * @param[in] result The result returned from input-field in prompt popup.
404 void JavaScriptPromptReply(const std::string& result);
407 * @brief Create a new hit test.
409 * @param[in] x the horizontal position to query
410 * @param[in] y the vertical position to query
411 * @param[in] mode the mode of hit test
413 * @return a new hit test object
415 std::unique_ptr<Dali::WebEngineHitTest> CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode);
418 * @brief create a hit test asynchronously.
420 * @param[in] x the horizontal position to query
421 * @param[in] y the vertical position to query
422 * @param[in] mode the mode of hit test
423 * @param[in] callback the callback function
425 * @return true if succeeded, false otherwise
427 bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback);
430 * @brief Clear the history of Web.
435 * @brief Clear all tiles resources of Web.
437 void ClearAllTilesResources();
440 * @brief Get user agent string.
442 * @return The string value of user agent
444 std::string GetUserAgent() const;
447 * @brief Set user agent string.
449 * @param[in] userAgent The string value of user agent
451 void SetUserAgent(const std::string& userAgent);
454 * @brief Set the size of Web Pages.
456 void SetSize(uint32_t width, uint32_t height);
459 * @brief Set background color of web page.
461 * @param[in] color Background color
463 void SetDocumentBackgroundColor(Dali::Vector4 color);
466 * @brief Clear tiles when hidden.
468 * @param[in] cleared Whether tiles are cleared or not
470 void ClearTilesWhenHidden(bool cleared);
473 * @brief Set multiplier of cover area of tile.
475 * @param[in] multiplier The multiplier of cover area
477 void SetTileCoverAreaMultiplier(float multiplier);
480 * @brief Enable cursor by client.
482 * @param[in] enabled Whether cursor is enabled or not
484 void EnableCursorByClient(bool enabled);
487 * @brief Get the selected text.
489 * @return the selected text
491 std::string GetSelectedText() const;
494 * @brief Send Touch Events.
496 bool SendTouchEvent(const TouchEvent& touch);
499 * @brief Send key Events.
501 bool SendKeyEvent(const KeyEvent& event);
505 * @param[in] focused True if web view is focused, false otherwise
507 void SetFocus(bool focused);
510 * @brief Enable/disable mouse events. The default is enabled.
512 * @param[in] enabled True if mouse events are enabled, false otherwise
514 void EnableMouseEvents(bool enabled);
517 * @brief Enable/disable key events. The default is enabled.
519 * @param[in] enabled True if key events are enabled, false otherwise
521 void EnableKeyEvents(bool enabled);
524 * @brief Set zoom factor of the current page.
525 * @param[in] zoomFactor a new factor to be set.
527 void SetPageZoomFactor(float zoomFactor);
530 * @brief Query the current zoom factor of the page。
531 * @return The current page zoom factor.
533 float GetPageZoomFactor() const;
536 * @brief Set the current text zoom level。.
537 * @param[in] zoomFactor a new factor to be set.
539 void SetTextZoomFactor(float zoomFactor);
542 * @brief Get the current text zoom level.
543 * @return The current text zoom factor.
545 float GetTextZoomFactor() const;
548 * @brief Get the current load progress of the page.
549 * @return The load progress of the page.
551 float GetLoadProgressPercentage() const;
554 * @brief Scale the current page, centered at the given point.
555 * @param[in] scaleFactor a new factor to be scaled.
556 * @param[in] point a center coordinate.
558 void SetScaleFactor(float scaleFactor, Dali::Vector2 point);
561 * @brief Get the current scale factor of the page.
562 * @return The current scale factor.
564 float GetScaleFactor() const;
567 * @brief Request to activate/deactivate the accessibility usage set by web app.
568 * @param[in] activated Activate accessibility or not.
570 void ActivateAccessibility(bool activated);
573 * @brief Get the accessibility address (bus and path) for embedding.
574 * @return Accessibility address of the root web content element.
576 Accessibility::Address GetAccessibilityAddress();
579 * @brief Request to set the current page's visibility.
580 * @param[in] visible Visible or not.
582 * @return true if changed successfully, false otherwise
584 bool SetVisibility(bool visible);
587 * @brief Search and highlights the given string in the document.
588 * @param[in] text The text to find
589 * @param[in] options The options to find
590 * @param[in] maxMatchCount The maximum match count to find
592 * @return true if found & highlighted, false otherwise
594 bool HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount);
597 * @brief Add dynamic certificate path.
598 * @param[in] host host that required client authentication
599 * @param[in] certPath the file path stored certificate
601 void AddDynamicCertificatePath(const std::string& host, const std::string& certPath);
604 * @brief Get snapshot of the specified viewArea of page.
606 * @param[in] viewArea The rectangle of screen shot
607 * @param[in] scaleFactor The scale factor
609 * @return pixel data of screen shot
611 Dali::PixelData GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor);
614 * @brief Request to get snapshot of the specified viewArea of page asynchronously.
616 * @param[in] viewArea The rectangle of screen shot
617 * @param[in] scaleFactor The scale factor
618 * @param[in] callback The callback for screen shot
620 * @return true if requested successfully, false otherwise
622 bool GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback);
625 * @brief Asynchronous request to check if there is a video playing in the given view.
627 * @param[in] callback The callback called after checking if video is playing or not
629 * @return true if requested successfully, false otherwise
631 bool CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback);
634 * @brief Set callback which alled upon geolocation permission request.
636 * @param[in] callback The callback for requesting geolocation permission
638 void RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback);
641 * @brief Update display area.
642 * @param[in] displayArea The area to display web page
644 void UpdateDisplayArea(Dali::Rect<int32_t> displayArea);
647 * @brief Enable video hole.
648 * @param[in] enabled True if video hole is enabled, false otherwise
650 void EnableVideoHole(bool enabled);
653 * @brief Send hover events.
654 * @param[in] event The hover event would be sent.
656 bool SendHoverEvent(const HoverEvent& event);
659 * @brief Send wheel events.
660 * @param[in] event The wheel event would be sent.
662 bool SendWheelEvent(const WheelEvent& event);
665 * @brief Callback to be called when frame would be rendered.
667 * @param[in] callback
669 void RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback);
672 * @brief Callback to be called when page loading is started.
674 * @param[in] callback
676 void RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
679 * @brief Callback to be called when page loading is in progress.
681 * @param[in] callback
683 void RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
686 * @brief Callback to be called when page loading is finished.
688 * @param[in] callback
690 void RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
693 * @brief Callback to be called when an error occurs in page loading.
695 * @param[in] callback
697 void RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback);
700 * @brief Callback to be called when scroll edge is reached.
702 * @param[in] callback
704 void RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback);
707 * @brief Callback to be called when url is changed.
709 * @param[in] callback
711 void RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback);
714 * @brief Callback to be called when form repost decision is requested.
716 * @param[in] callback
718 void RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback);
721 * @brief Callback to be called when console message will be logged.
723 * @param[in] callback
725 void RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback);
728 * @brief Callback to be called when response policy would be decided.
730 * @param[in] callback
732 void RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback);
735 * @brief Callback to be called when navigation policy would be decided.
737 * @param[in] callback
739 void RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback);
742 * @brief Callback to be called when a new window would be created.
744 * @param[in] callback
746 void RegisterNewWindowCreatedCallback(Dali::WebEnginePlugin::WebEngineNewWindowCreatedCallback callback);
749 * @brief Callback to be called when certificate need be confirmed.
751 * @param[in] callback
753 void RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
756 * @brief Callback to be called when ssl certificate is changed.
758 * @param[in] callback
760 void RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
763 * @brief Callback to be called when http authentication need be confirmed.
765 * @param[in] callback
767 void RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback);
770 * @brief Callback to be called when context menu would be shown.
772 * @param[in] callback
774 void RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback);
777 * @brief Callback to be called when context menu would be hidden.
779 * @param[in] callback
781 void RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback);
784 * @brief Get a plain text of current web page asynchronously.
786 * @param[in] callback The callback function called asynchronously.
788 void GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback);
790 private: // Not intended for application developers
792 * @brief Internal constructor
794 explicit DALI_INTERNAL WebEngine(Internal::Adaptor::WebEngine* internal);
799 #endif // DALI_WEB_ENGINE_H