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 Downcast a handle to WebEngine handle.
92 * If handle points to a WebEngine the downcast produces valid
93 * handle. If not the returned handle is left uninitialized.
95 * @param[in] handle Handle to an object
96 * @return Handle to a WebEngine or an uninitialized handle
98 static WebEngine DownCast(BaseHandle handle);
101 * @brief Create WebEngine instance.
103 * @param [in] width The width of Web
104 * @param [in] height The height of Web
105 * @param [in] locale The locale of Web
106 * @param [in] timezoneId The timezoneID of Web
108 void Create(uint32_t width, uint32_t height, const std::string& locale, const std::string& timezoneId);
111 * @brief Create WebEngine instance.
113 * @param [in] width The width of Web
114 * @param [in] height The height of Web
115 * @param [in] argc The count of application arguments
116 * @param [in] argv The string array of application arguments
118 void Create(uint32_t width, uint32_t height, uint32_t argc, char** argv);
121 * @brief Destroy WebEngine instance.
126 * @brief Gets web engine plugin.
128 Dali::WebEnginePlugin* GetPlugin() const;
131 * @brief Get native image source to render.
133 NativeImageSourcePtr GetNativeImageSource();
136 * @brief Get settings of WebEngine.
138 Dali::WebEngineSettings& GetSettings() const;
141 * @brief Get back-forward list of WebEngine.
143 Dali::WebEngineBackForwardList& GetBackForwardList() const;
146 * @brief Load a web page based on a given URL.
148 * @param [in] url The URL of the resource to load
150 void LoadUrl(const std::string& url);
153 * @brief Return the title of the Web.
155 * @return The title of web page
157 std::string GetTitle() const;
160 * @brief Return the Favicon of the Web.
162 * @return FavIcon of Dali::PixelData& type
164 Dali::PixelData GetFavicon() const;
167 * @brief Get the url.
169 std::string GetUrl() const;
172 * @brief Load a given string as web contents.
174 * @param [in] htmlString The string to use as the contents of the web page
176 void LoadHtmlString(const std::string& htmlString);
179 * @brief Load the specified html string as the content of the view overriding current history entry
181 * @param[in] html HTML data to load
182 * @param[in] basicUri Base URL used for relative paths to external objects
183 * @param[in] unreachableUrl URL that could not be reached
185 * @return true if successfully loaded, false otherwise
187 bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl);
190 * @brief Request loading the given contents by MIME type into the view object
192 * @param[in] contents The content to load
193 * @param[in] contentSize The size of contents (in bytes)
194 * @param[in] mimeType The type of contents, if 0 is given "text/html" is assumed
195 * @param[in] encoding The encoding for contents, if 0 is given "UTF-8" is assumed
196 * @param[in] baseUri The base URI to use for relative resources
198 * @return true if successfully request, false otherwise
200 bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri);
203 * @brief Reload the Web.
208 * @brief Reload the current page's document without cache
210 bool ReloadWithoutCache();
213 * @brief Stop loading web contents on the current page.
218 * @brief Suspend the operation associated with the view.
223 * @brief Resume the operation associated with the view object after calling Suspend().
228 * @brief To suspend all url loading
230 void SuspendNetworkLoading();
233 * @brief To resume new url network loading
235 void ResumeNetworkLoading();
238 * @brief Add custom header
240 * @param[in] name custom header name to add the custom header
241 * @param[in] value custom header value to add the custom header
243 * @return true if succeeded, false otherwise
245 bool AddCustomHeader(const std::string& name, const std::string& value);
248 * @brief Remove custom header
250 * @param[in] name custom header name to remove the custom header
252 * @return true if succeeded, false otherwise
254 bool RemoveCustomHeader(const std::string& name);
257 * @brief Start the inspector server
259 * @param[in] port port number
261 * @return the port number
263 uint32_t StartInspectorServer(uint32_t port);
266 * @brief Stop the inspector server
268 * @return true if succeeded, false otherwise
270 bool StopInspectorServer();
273 * @brief Scroll web page of view by deltaX and deltaY.
275 * @param[in] deltaX horizontal offset to scroll
276 * @param[in] deltaY vertical offset to scroll
278 void ScrollBy(int32_t deltaX, int32_t deltaY);
281 * @brief Scroll edge of view by deltaX and deltaY.
283 * @param[in] deltaX horizontal offset to scroll
284 * @param[in] deltaY vertical offset to scroll
286 * @return true if succeeded, false otherwise
288 bool ScrollEdgeBy(int32_t deltaX, int32_t deltaY);
291 * @brief Set an absolute scroll of the given view.
293 void SetScrollPosition(int32_t x, int32_t y);
296 * @brief Get the current scroll position of the given view.
298 Dali::Vector2 GetScrollPosition() const;
301 * @brief Get the possible scroll size of the given view.
303 Dali::Vector2 GetScrollSize() const;
306 * @brief Get the last known content's size.
308 Dali::Vector2 GetContentSize() const;
311 * @brief Return whether forward is possible.
313 * @return True if forward is possible, false otherwise
318 * @brief Go to forward.
323 * @brief Return whether backward is possible.
325 * @return True if backward is possible, false otherwise
335 * @brief Evaluate JavaScript code represented as a string.
337 * @param[in] script The JavaScript code
338 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
340 void EvaluateJavaScript(const std::string& script, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback resultHandler);
343 * @brief Add a message handler into JavaScript.
345 * @param[in] exposedObjectName The name of exposed object
346 * @param[in] handler The callback function
348 void AddJavaScriptMessageHandler(const std::string& exposedObjectName, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback handler);
351 * @brief Register a callback for JavaScript alert.
353 * @param[in] callback The callback function
355 void RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback);
358 * @brief Reply for JavaScript alert.
360 void JavaScriptAlertReply();
363 * @brief Register a callback for JavaScript confirm.
365 * @param[in] callback The callback function
367 void RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback);
370 * @brief Reply for JavaScript confirm.
371 * @param[in] confirmed True if confirmed, false otherwise.
373 void JavaScriptConfirmReply(bool confirmed);
376 * @brief Register a callback for JavaScript prompt.
378 * @param[in] callback The callback function
380 void RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback);
383 * @brief Reply for JavaScript prompt.
384 * @param[in] result The result returned from input-field in prompt popup.
386 void JavaScriptPromptReply(const std::string& result);
389 * @brief Create a new hit test.
391 * @param[in] x the horizontal position to query
392 * @param[in] y the vertical position to query
393 * @param[in] mode the mode of hit test
395 * @return a new hit test object
397 std::unique_ptr<Dali::WebEngineHitTest> CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode);
400 * @brief create a hit test asynchronously.
402 * @param[in] x the horizontal position to query
403 * @param[in] y the vertical position to query
404 * @param[in] mode the mode of hit test
405 * @param[in] callback the callback function
407 * @return true if succeeded, false otherwise
409 bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback);
412 * @brief Clear the history of Web.
417 * @brief Clear all tiles resources of Web.
419 void ClearAllTilesResources();
422 * @brief Get user agent string.
424 * @return The string value of user agent
426 std::string GetUserAgent() const;
429 * @brief Set user agent string.
431 * @param[in] userAgent The string value of user agent
433 void SetUserAgent(const std::string& userAgent);
436 * @brief Set the size of Web Pages.
438 void SetSize(uint32_t width, uint32_t height);
441 * @brief Set background color of web page.
443 * @param[in] color Background color
445 void SetDocumentBackgroundColor(Dali::Vector4 color);
448 * @brief Clear tiles when hidden.
450 * @param[in] cleared Whether tiles are cleared or not
452 void ClearTilesWhenHidden(bool cleared);
455 * @brief Set multiplier of cover area of tile.
457 * @param[in] multiplier The multiplier of cover area
459 void SetTileCoverAreaMultiplier(float multiplier);
462 * @brief Enable cursor by client.
464 * @param[in] enabled Whether cursor is enabled or not
466 void EnableCursorByClient(bool enabled);
469 * @brief Get the selected text.
471 * @return the selected text
473 std::string GetSelectedText() const;
476 * @brief Send Touch Events.
478 bool SendTouchEvent(const TouchEvent& touch);
481 * @brief Send key Events.
483 bool SendKeyEvent(const KeyEvent& event);
487 * @param[in] focused True if web view is focused, false otherwise
489 void SetFocus(bool focused);
492 * @brief Enable/disable mouse events. The default is enabled.
494 * @param[in] enabled True if mouse events are enabled, false otherwise
496 void EnableMouseEvents(bool enabled);
499 * @brief Enable/disable key events. The default is enabled.
501 * @param[in] enabled True if key events are enabled, false otherwise
503 void EnableKeyEvents(bool enabled);
506 * @brief Set zoom factor of the current page.
507 * @param[in] zoomFactor a new factor to be set.
509 void SetPageZoomFactor(float zoomFactor);
512 * @brief Query the current zoom factor of the page。
513 * @return The current page zoom factor.
515 float GetPageZoomFactor() const;
518 * @brief Set the current text zoom level。.
519 * @param[in] zoomFactor a new factor to be set.
521 void SetTextZoomFactor(float zoomFactor);
524 * @brief Get the current text zoom level.
525 * @return The current text zoom factor.
527 float GetTextZoomFactor() const;
530 * @brief Get the current load progress of the page.
531 * @return The load progress of the page.
533 float GetLoadProgressPercentage() const;
536 * @brief Scale the current page, centered at the given point.
537 * @param[in] scaleFactor a new factor to be scaled.
538 * @param[in] point a center coordinate.
540 void SetScaleFactor(float scaleFactor, Dali::Vector2 point);
543 * @brief Get the current scale factor of the page.
544 * @return The current scale factor.
546 float GetScaleFactor() const;
549 * @brief Request to activate/deactivate the accessibility usage set by web app.
550 * @param[in] activated Activate accessibility or not.
552 void ActivateAccessibility(bool activated);
555 * @brief Get the accessibility address (bus and path) for embedding.
556 * @return Accessibility address of the root web content element.
558 Accessibility::Address GetAccessibilityAddress();
561 * @brief Request to set the current page's visibility.
562 * @param[in] visible Visible or not.
564 * @return true if changed successfully, false otherwise
566 bool SetVisibility(bool visible);
569 * @brief Search and highlights the given string in the document.
570 * @param[in] text The text to find
571 * @param[in] options The options to find
572 * @param[in] maxMatchCount The maximum match count to find
574 * @return true if found & highlighted, false otherwise
576 bool HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount);
579 * @brief Add dynamic certificate path.
580 * @param[in] host host that required client authentication
581 * @param[in] certPath the file path stored certificate
583 void AddDynamicCertificatePath(const std::string& host, const std::string& certPath);
586 * @brief Get snapshot of the specified viewArea of page.
588 * @param[in] viewArea The rectangle of screen shot
589 * @param[in] scaleFactor The scale factor
591 * @return pixel data of screen shot
593 Dali::PixelData GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor);
596 * @brief Request to get snapshot of the specified viewArea of page asynchronously.
598 * @param[in] viewArea The rectangle of screen shot
599 * @param[in] scaleFactor The scale factor
600 * @param[in] callback The callback for screen shot
602 * @return true if requested successfully, false otherwise
604 bool GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback);
607 * @brief Asynchronous request to check if there is a video playing in the given view.
609 * @param[in] callback The callback called after checking if video is playing or not
611 * @return true if requested successfully, false otherwise
613 bool CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback);
616 * @brief Set callback which alled upon geolocation permission request.
618 * @param[in] callback The callback for requesting geolocation permission
620 void RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback);
623 * @brief Update display area.
624 * @param[in] displayArea The area to display web page
626 void UpdateDisplayArea(Dali::Rect<int32_t> displayArea);
629 * @brief Enable video hole.
630 * @param[in] enabled True if video hole is enabled, false otherwise
632 void EnableVideoHole(bool enabled);
635 * @brief Send hover events.
636 * @param[in] event The hover event would be sent.
638 bool SendHoverEvent(const HoverEvent& event);
641 * @brief Send wheel events.
642 * @param[in] event The wheel event would be sent.
644 bool SendWheelEvent(const WheelEvent& event);
647 * @brief Connect to this signal to be notified when frame is rendered.
649 * @return A signal object to connect with.
651 Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& FrameRenderedSignal();
654 * @brief Callback to be called when page loading is started.
656 * @param[in] callback
658 void RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
661 * @brief Callback to be called when page loading is in progress.
663 * @param[in] callback
665 void RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
668 * @brief Callback to be called when page loading is finished.
670 * @param[in] callback
672 void RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
675 * @brief Callback to be called when an error occurs in page loading.
677 * @param[in] callback
679 void RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback);
682 * @brief Callback to be called when scroll edge is reached.
684 * @param[in] callback
686 void RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback);
689 * @brief Callback to be called when url is changed.
691 * @param[in] callback
693 void RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback);
696 * @brief Callback to be called when form repost decision is requested.
698 * @param[in] callback
700 void RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback);
703 * @brief Callback to be called when console message will be logged.
705 * @param[in] callback
707 void RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback);
710 * @brief Callback to be called when response policy would be decided.
712 * @param[in] callback
714 void RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback);
717 * @brief Callback to be called when navigation policy would be decided.
719 * @param[in] callback
721 void RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback);
724 * @brief Callback to be called when certificate need be confirmed.
726 * @param[in] callback
728 void RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
731 * @brief Callback to be called when ssl certificate is changed.
733 * @param[in] callback
735 void RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
738 * @brief Callback to be called when http authentication need be confirmed.
740 * @param[in] callback
742 void RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback);
745 * @brief Callback to be called when context menu would be shown.
747 * @param[in] callback
749 void RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback);
752 * @brief Callback to be called when context menu would be hidden.
754 * @param[in] callback
756 void RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback);
759 * @brief Get a plain text of current web page asynchronously.
761 * @param[in] callback The callback function called asynchronously.
763 void GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback);
765 private: // Not intended for application developers
767 * @brief Internal constructor
769 explicit DALI_INTERNAL WebEngine(Internal::Adaptor::WebEngine* internal);
774 #endif // DALI_WEB_ENGINE_H