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>
36 } // namespace Adaptor
38 } // namespace Internal
41 * @brief Proxy class to dynamically load, use and unload web engine plugin.
43 * The purpose of this class is to dynamically load the web engine plugin if and when its needed.
44 * So we don't slow down every application startup if they never need web engine.
46 class DALI_ADAPTOR_API WebEngine : public BaseHandle
60 * @brief Create a new instance of a WebEngine.
62 static WebEngine New();
65 * @brief Get context of WebEngine.
67 static Dali::WebEngineContext* GetContext();
70 * @brief Get cookie manager of WebEngine.
72 static Dali::WebEngineCookieManager* GetCookieManager();
75 * @brief Copy constructor.
77 * @param[in] WebEngine WebEngine to copy. The copied WebEngine will point at the same implementation
79 WebEngine(const WebEngine& WebEngine);
82 * @brief Assignment operator.
84 * @param[in] WebEngine The WebEngine to assign from.
85 * @return The updated WebEngine.
87 WebEngine& operator=(const WebEngine& WebEngine);
90 * @brief Move constructor.
92 * @param[in] WebEngine WebEngine to move. The moved WebEngine will point at the same implementation
94 WebEngine(WebEngine&& WebEngine);
97 * @brief Move assignment operator.
99 * @param[in] WebEngine The WebEngine to assign from.
100 * @return The updated WebEngine.
102 WebEngine& operator=(WebEngine&& WebEngine);
105 * @brief Downcast a handle to WebEngine handle.
107 * If handle points to a WebEngine the downcast produces valid
108 * handle. If not the returned handle is left uninitialized.
110 * @param[in] handle Handle to an object
111 * @return Handle to a WebEngine or an uninitialized handle
113 static WebEngine DownCast(BaseHandle handle);
116 * @brief Create WebEngine instance.
118 * @param [in] width The width of Web
119 * @param [in] height The height of Web
120 * @param [in] locale The locale of Web
121 * @param [in] timezoneId The timezoneID of Web
123 void Create(uint32_t width, uint32_t height, const std::string& locale, const std::string& timezoneId);
126 * @brief Create WebEngine instance.
128 * @param [in] width The width of Web
129 * @param [in] height The height of Web
130 * @param [in] argc The count of application arguments
131 * @param [in] argv The string array of application arguments
133 void Create(uint32_t width, uint32_t height, uint32_t argc, char** argv);
136 * @brief Destroy WebEngine instance.
141 * @brief Gets web engine plugin.
143 Dali::WebEnginePlugin* GetPlugin() const;
146 * @brief Get native image source to render.
148 NativeImageSourcePtr GetNativeImageSource();
151 * @brief Get settings of WebEngine.
153 Dali::WebEngineSettings& GetSettings() const;
156 * @brief Get back-forward list of WebEngine.
158 Dali::WebEngineBackForwardList& GetBackForwardList() const;
161 * @brief Load a web page based on a given URL.
163 * @param [in] url The URL of the resource to load
165 void LoadUrl(const std::string& url);
168 * @brief Return the title of the Web.
170 * @return The title of web page
172 std::string GetTitle() const;
175 * @brief Return the Favicon of the Web.
177 * @return FavIcon of Dali::PixelData& type
179 Dali::PixelData GetFavicon() const;
182 * @brief Get the url.
184 std::string GetUrl() const;
187 * @brief Load a given string as web contents.
189 * @param [in] htmlString The string to use as the contents of the web page
191 void LoadHtmlString(const std::string& htmlString);
194 * @brief Load the specified html string as the content of the view overriding current history entry
196 * @param[in] html HTML data to load
197 * @param[in] basicUri Base URL used for relative paths to external objects
198 * @param[in] unreachableUrl URL that could not be reached
200 * @return true if successfully loaded, false otherwise
202 bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl);
205 * @brief Request loading the given contents by MIME type into the view object
207 * @param[in] contents The content to load
208 * @param[in] contentSize The size of contents (in bytes)
209 * @param[in] mimeType The type of contents, if 0 is given "text/html" is assumed
210 * @param[in] encoding The encoding for contents, if 0 is given "UTF-8" is assumed
211 * @param[in] baseUri The base URI to use for relative resources
213 * @return true if successfully request, false otherwise
215 bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri);
218 * @brief Reload the Web.
223 * @brief Reload the current page's document without cache
225 bool ReloadWithoutCache();
228 * @brief Stop loading web contents on the current page.
233 * @brief Suspend the operation associated with the view.
238 * @brief Resume the operation associated with the view object after calling Suspend().
243 * @brief To suspend all url loading
245 void SuspendNetworkLoading();
248 * @brief To resume new url network loading
250 void ResumeNetworkLoading();
253 * @brief Add custom header
255 * @param[in] name custom header name to add the custom header
256 * @param[in] value custom header value to add the custom header
258 * @return true if succeeded, false otherwise
260 bool AddCustomHeader(const std::string& name, const std::string& value);
263 * @brief Remove custom header
265 * @param[in] name custom header name to remove the custom header
267 * @return true if succeeded, false otherwise
269 bool RemoveCustomHeader(const std::string& name);
272 * @brief Start the inspector server
274 * @param[in] port port number
276 * @return the port number
278 uint32_t StartInspectorServer(uint32_t port);
281 * @brief Stop the inspector server
283 * @return true if succeeded, false otherwise
285 bool StopInspectorServer();
288 * @brief Scroll web page of view by deltaX and deltaY.
290 * @param[in] deltaX horizontal offset to scroll
291 * @param[in] deltaY vertical offset to scroll
293 void ScrollBy(int32_t deltaX, int32_t deltaY);
296 * @brief Scroll edge of view by deltaX and deltaY.
298 * @param[in] deltaX horizontal offset to scroll
299 * @param[in] deltaY vertical offset to scroll
301 * @return true if succeeded, false otherwise
303 bool ScrollEdgeBy(int32_t deltaX, int32_t deltaY);
306 * @brief Set an absolute scroll of the given view.
308 void SetScrollPosition(int32_t x, int32_t y);
311 * @brief Get the current scroll position of the given view.
313 Dali::Vector2 GetScrollPosition() const;
316 * @brief Get the possible scroll size of the given view.
318 Dali::Vector2 GetScrollSize() const;
321 * @brief Get the last known content's size.
323 Dali::Vector2 GetContentSize() const;
326 * @brief Return whether forward is possible.
328 * @return True if forward is possible, false otherwise
333 * @brief Go to forward.
338 * @brief Return whether backward is possible.
340 * @return True if backward is possible, false otherwise
350 * @brief Evaluate JavaScript code represented as a string.
352 * @param[in] script The JavaScript code
353 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
355 void EvaluateJavaScript(const std::string& script, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback resultHandler);
358 * @brief Add a message handler into JavaScript.
360 * @param[in] exposedObjectName The name of exposed object
361 * @param[in] handler The callback function
363 void AddJavaScriptMessageHandler(const std::string& exposedObjectName, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback handler);
366 * @brief Register a callback for JavaScript alert.
368 * @param[in] callback The callback function
370 void RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback);
373 * @brief Reply for JavaScript alert.
375 void JavaScriptAlertReply();
378 * @brief Register a callback for JavaScript confirm.
380 * @param[in] callback The callback function
382 void RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback);
385 * @brief Reply for JavaScript confirm.
386 * @param[in] confirmed True if confirmed, false otherwise.
388 void JavaScriptConfirmReply(bool confirmed);
391 * @brief Register a callback for JavaScript prompt.
393 * @param[in] callback The callback function
395 void RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback);
398 * @brief Reply for JavaScript prompt.
399 * @param[in] result The result returned from input-field in prompt popup.
401 void JavaScriptPromptReply(const std::string& result);
404 * @brief Create a new hit test.
406 * @param[in] x the horizontal position to query
407 * @param[in] y the vertical position to query
408 * @param[in] mode the mode of hit test
410 * @return a new hit test object
412 std::unique_ptr<Dali::WebEngineHitTest> CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode);
415 * @brief create a hit test asynchronously.
417 * @param[in] x the horizontal position to query
418 * @param[in] y the vertical position to query
419 * @param[in] mode the mode of hit test
420 * @param[in] callback the callback function
422 * @return true if succeeded, false otherwise
424 bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback);
427 * @brief Clear the history of Web.
432 * @brief Clear all tiles resources of Web.
434 void ClearAllTilesResources();
437 * @brief Get user agent string.
439 * @return The string value of user agent
441 std::string GetUserAgent() const;
444 * @brief Set user agent string.
446 * @param[in] userAgent The string value of user agent
448 void SetUserAgent(const std::string& userAgent);
451 * @brief Set the size of Web Pages.
453 void SetSize(uint32_t width, uint32_t height);
456 * @brief Set background color of web page.
458 * @param[in] color Background color
460 void SetDocumentBackgroundColor(Dali::Vector4 color);
463 * @brief Clear tiles when hidden.
465 * @param[in] cleared Whether tiles are cleared or not
467 void ClearTilesWhenHidden(bool cleared);
470 * @brief Set multiplier of cover area of tile.
472 * @param[in] multiplier The multiplier of cover area
474 void SetTileCoverAreaMultiplier(float multiplier);
477 * @brief Enable cursor by client.
479 * @param[in] enabled Whether cursor is enabled or not
481 void EnableCursorByClient(bool enabled);
484 * @brief Get the selected text.
486 * @return the selected text
488 std::string GetSelectedText() const;
491 * @brief Send Touch Events.
493 bool SendTouchEvent(const TouchEvent& touch);
496 * @brief Send key Events.
498 bool SendKeyEvent(const KeyEvent& event);
502 * @param[in] focused True if web view is focused, false otherwise
504 void SetFocus(bool focused);
507 * @brief Enable/disable mouse events. The default is enabled.
509 * @param[in] enabled True if mouse events are enabled, false otherwise
511 void EnableMouseEvents(bool enabled);
514 * @brief Enable/disable key events. The default is enabled.
516 * @param[in] enabled True if key events are enabled, false otherwise
518 void EnableKeyEvents(bool enabled);
521 * @brief Set zoom factor of the current page.
522 * @param[in] zoomFactor a new factor to be set.
524 void SetPageZoomFactor(float zoomFactor);
527 * @brief Query the current zoom factor of the page。
528 * @return The current page zoom factor.
530 float GetPageZoomFactor() const;
533 * @brief Set the current text zoom level。.
534 * @param[in] zoomFactor a new factor to be set.
536 void SetTextZoomFactor(float zoomFactor);
539 * @brief Get the current text zoom level.
540 * @return The current text zoom factor.
542 float GetTextZoomFactor() const;
545 * @brief Get the current load progress of the page.
546 * @return The load progress of the page.
548 float GetLoadProgressPercentage() const;
551 * @brief Scale the current page, centered at the given point.
552 * @param[in] scaleFactor a new factor to be scaled.
553 * @param[in] point a center coordinate.
555 void SetScaleFactor(float scaleFactor, Dali::Vector2 point);
558 * @brief Get the current scale factor of the page.
559 * @return The current scale factor.
561 float GetScaleFactor() const;
564 * @brief Request to activate/deactivate the accessibility usage set by web app.
565 * @param[in] activated Activate accessibility or not.
567 void ActivateAccessibility(bool activated);
570 * @brief Get the accessibility address (bus and path) for embedding.
571 * @return Accessibility address of the root web content element.
573 Accessibility::Address GetAccessibilityAddress();
576 * @brief Request to set the current page's visibility.
577 * @param[in] visible Visible or not.
579 * @return true if changed successfully, false otherwise
581 bool SetVisibility(bool visible);
584 * @brief Search and highlights the given string in the document.
585 * @param[in] text The text to find
586 * @param[in] options The options to find
587 * @param[in] maxMatchCount The maximum match count to find
589 * @return true if found & highlighted, false otherwise
591 bool HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount);
594 * @brief Add dynamic certificate path.
595 * @param[in] host host that required client authentication
596 * @param[in] certPath the file path stored certificate
598 void AddDynamicCertificatePath(const std::string& host, const std::string& certPath);
601 * @brief Get snapshot of the specified viewArea of page.
603 * @param[in] viewArea The rectangle of screen shot
604 * @param[in] scaleFactor The scale factor
606 * @return pixel data of screen shot
608 Dali::PixelData GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor);
611 * @brief Request to get snapshot of the specified viewArea of page asynchronously.
613 * @param[in] viewArea The rectangle of screen shot
614 * @param[in] scaleFactor The scale factor
615 * @param[in] callback The callback for screen shot
617 * @return true if requested successfully, false otherwise
619 bool GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback);
622 * @brief Asynchronous request to check if there is a video playing in the given view.
624 * @param[in] callback The callback called after checking if video is playing or not
626 * @return true if requested successfully, false otherwise
628 bool CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback);
631 * @brief Set callback which alled upon geolocation permission request.
633 * @param[in] callback The callback for requesting geolocation permission
635 void RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback);
638 * @brief Update display area.
639 * @param[in] displayArea The area to display web page
641 void UpdateDisplayArea(Dali::Rect<int32_t> displayArea);
644 * @brief Enable video hole.
645 * @param[in] enabled True if video hole is enabled, false otherwise
647 void EnableVideoHole(bool enabled);
650 * @brief Send hover events.
651 * @param[in] event The hover event would be sent.
653 bool SendHoverEvent(const HoverEvent& event);
656 * @brief Send wheel events.
657 * @param[in] event The wheel event would be sent.
659 bool SendWheelEvent(const WheelEvent& event);
662 * @brief Connect to this signal to be notified when frame is rendered.
664 * @return A signal object to connect with.
666 Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& FrameRenderedSignal();
669 * @brief Callback to be called when page loading is started.
671 * @param[in] callback
673 void RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
676 * @brief Callback to be called when page loading is in progress.
678 * @param[in] callback
680 void RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
683 * @brief Callback to be called when page loading is finished.
685 * @param[in] callback
687 void RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
690 * @brief Callback to be called when an error occurs in page loading.
692 * @param[in] callback
694 void RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback);
697 * @brief Callback to be called when scroll edge is reached.
699 * @param[in] callback
701 void RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback);
704 * @brief Callback to be called when url is changed.
706 * @param[in] callback
708 void RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback);
711 * @brief Callback to be called when form repost decision is requested.
713 * @param[in] callback
715 void RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback);
718 * @brief Callback to be called when console message will be logged.
720 * @param[in] callback
722 void RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback);
725 * @brief Callback to be called when response policy would be decided.
727 * @param[in] callback
729 void RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback);
732 * @brief Callback to be called when navigation policy would be decided.
734 * @param[in] callback
736 void RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback);
739 * @brief Callback to be called when certificate need be confirmed.
741 * @param[in] callback
743 void RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
746 * @brief Callback to be called when ssl certificate is changed.
748 * @param[in] callback
750 void RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
753 * @brief Callback to be called when http authentication need be confirmed.
755 * @param[in] callback
757 void RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback);
760 * @brief Callback to be called when context menu would be shown.
762 * @param[in] callback
764 void RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback);
767 * @brief Callback to be called when context menu would be hidden.
769 * @param[in] callback
771 void RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback);
774 * @brief Get a plain text of current web page asynchronously.
776 * @param[in] callback The callback function called asynchronously.
778 void GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback);
780 private: // Not intended for application developers
782 * @brief Internal constructor
784 explicit DALI_INTERNAL WebEngine(Internal::Adaptor::WebEngine* internal);
789 #endif // DALI_WEB_ENGINE_H