1 #ifndef DALI_WEB_ENGINE_H
2 #define DALI_WEB_ENGINE_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/public-api/object/base-handle.h>
25 #include <dali/devel-api/adaptor-framework/web-engine-plugin.h>
26 #include <dali/public-api/dali-adaptor-common.h>
35 } // namespace Adaptor
37 } // namespace Internal
40 * @brief Proxy class to dynamically load, use and unload web engine plugin.
42 * The purpose of this class is to dynamically load the web engine plugin if and when its needed.
43 * So we don't slow down every application startup if they never need web engine.
45 class DALI_ADAPTOR_API WebEngine : public BaseHandle
59 * @brief Create a new instance of a WebEngine.
61 static WebEngine New();
64 * @brief Copy constructor.
66 * @param[in] WebEngine WebEngine to copy. The copied WebEngine will point at the same implementation
68 WebEngine(const WebEngine& WebEngine);
71 * @brief Assignment operator.
73 * @param[in] WebEngine The WebEngine to assign from.
74 * @return The updated WebEngine.
76 WebEngine& operator=(const WebEngine& WebEngine);
79 * @brief Downcast a handle to WebEngine handle.
81 * If handle points to a WebEngine the downcast produces valid
82 * handle. If not the returned handle is left uninitialized.
84 * @param[in] handle Handle to an object
85 * @return Handle to a WebEngine or an uninitialized handle
87 static WebEngine DownCast(BaseHandle handle);
90 * @brief Create WebEngine instance.
92 * @param [in] width The width of Web
93 * @param [in] height The height of Web
94 * @param [in] locale The locale of Web
95 * @param [in] timezoneId The timezoneID of Web
97 void Create(uint32_t width, uint32_t height, const std::string& locale, const std::string& timezoneId);
100 * @brief Create WebEngine instance.
102 * @param [in] width The width of Web
103 * @param [in] height The height of Web
104 * @param [in] argc The count of application arguments
105 * @param [in] argv The string array of application arguments
107 void Create(uint32_t width, uint32_t height, uint32_t argc, char** argv);
110 * @brief Destroy WebEngine instance.
115 * @brief Get native image source to render.
117 NativeImageInterfacePtr GetNativeImageSource();
120 * @brief Get settings of WebEngine.
122 Dali::WebEngineSettings& GetSettings() const;
125 * @brief Get context of WebEngine.
127 Dali::WebEngineContext& GetContext() const;
130 * @brief Get cookie manager of WebEngine.
132 Dali::WebEngineCookieManager& GetCookieManager() const;
135 * @brief Get back-forward list of WebEngine.
137 Dali::WebEngineBackForwardList& GetBackForwardList() const;
140 * @brief Load a web page based on a given URL.
142 * @param [in] url The URL of the resource to load
144 void LoadUrl(const std::string& url);
147 * @brief Return the title of the Web.
149 * @return The title of web page
151 std::string GetTitle() const;
154 * @brief Return the Favicon of the Web.
156 * @return FavIcon of Dali::PixelData& type
158 Dali::PixelData GetFavicon() const;
161 * @brief Get the url.
163 const std::string& GetUrl();
166 * @brief Load a given string as web contents.
168 * @param [in] htmlString The string to use as the contents of the web page
170 void LoadHtmlString(const std::string& htmlString);
173 * @brief Load the specified html string as the content of the view overriding current history entry
175 * @param[in] html HTML data to load
176 * @param[in] basicUri Base URL used for relative paths to external objects
177 * @param[in] unreachableUrl URL that could not be reached
179 * @return true if successfully loaded, false otherwise
181 bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl);
184 * @brief Request loading the given contents by MIME type into the view object
186 * @param[in] contents The content to load
187 * @param[in] contentSize The size of contents (in bytes)
188 * @param[in] mimeType The type of contents, if 0 is given "text/html" is assumed
189 * @param[in] encoding The encoding for contents, if 0 is given "UTF-8" is assumed
190 * @param[in] baseUri The base URI to use for relative resources
192 * @return true if successfully request, false otherwise
194 bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri);
197 * @brief Reload the Web.
202 * @brief Reload the current page's document without cache
204 bool ReloadWithoutCache();
207 * @brief Stop loading web contents on the current page.
212 * @brief Suspend the operation associated with the view.
217 * @brief Resume the operation associated with the view object after calling Suspend().
222 * @brief To suspend all url loading
224 void SuspendNetworkLoading();
227 * @brief To resume new url network loading
229 void ResumeNetworkLoading();
232 * @brief Add custom header
234 * @param[in] name custom header name to add the custom header
235 * @param[in] value custom header value to add the custom header
237 * @return true if succeeded, false otherwise
239 bool AddCustomHeader(const std::string& name, const std::string& value);
242 * @brief Remove custom header
244 * @param[in] name custom header name to remove the custom header
246 * @return true if succeeded, false otherwise
248 bool RemoveCustomHeader(const std::string& name);
251 * @brief Start the inspector server
253 * @param[in] port port number
255 * @return the port number
257 uint32_t StartInspectorServer(uint32_t port);
260 * @brief Stop the inspector server
262 * @return true if succeeded, false otherwise
264 bool StopInspectorServer();
267 * @brief Scroll web page of view by deltaX and deltaY.
269 * @param[in] deltaX horizontal offset to scroll
270 * @param[in] deltaY vertical offset to scroll
272 void ScrollBy(int32_t deltaX, int32_t deltaY);
275 * @brief Scroll edge of view by deltaX and deltaY.
277 * @param[in] deltaX horizontal offset to scroll
278 * @param[in] deltaY vertical offset to scroll
280 * @return true if succeeded, false otherwise
282 bool ScrollEdgeBy(int32_t deltaX, int32_t deltaY);
285 * @brief Set an absolute scroll of the given view.
287 void SetScrollPosition(int32_t x, int32_t y);
290 * @brief Get the current scroll position of the given view.
292 Dali::Vector2 GetScrollPosition() const;
295 * @brief Get the possible scroll size of the given view.
297 Dali::Vector2 GetScrollSize() const;
300 * @brief Get the last known content's size.
302 Dali::Vector2 GetContentSize() const;
305 * @brief Return whether forward is possible.
307 * @return True if forward is possible, false otherwise
312 * @brief Go to forward.
317 * @brief Return whether backward is possible.
319 * @return True if backward is possible, false otherwise
329 * @brief Evaluate JavaScript code represented as a string.
331 * @param[in] script The JavaScript code
332 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
334 void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler);
337 * @brief Add a message handler into JavaScript.
339 * @param[in] exposedObjectName The name of exposed object
340 * @param[in] handler The callback function
342 void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
345 * @brief Register a callback for JavaScript alert.
347 * @param[in] callback The callback function
349 void RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback);
352 * @brief Reply for JavaScript alert.
354 void JavaScriptAlertReply();
357 * @brief Register a callback for JavaScript confirm.
359 * @param[in] callback The callback function
361 void RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback);
364 * @brief Reply for JavaScript confirm.
365 * @param[in] confirmed True if confirmed, false otherwise.
367 void JavaScriptConfirmReply(bool confirmed);
370 * @brief Register a callback for JavaScript prompt.
372 * @param[in] callback The callback function
374 void RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback);
377 * @brief Reply for JavaScript prompt.
378 * @param[in] result The result returned from input-field in prompt popup.
380 void JavaScriptPromptReply(const std::string& result);
383 * @brief Create a new hit test.
385 * @param[in] x the horizontal position to query
386 * @param[in] y the vertical position to query
387 * @param[in] mode the mode of hit test
389 * @return a new hit test object
391 std::unique_ptr<Dali::WebEngineHitTest> CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode);
394 * @brief create a hit test asynchronously.
396 * @param[in] x the horizontal position to query
397 * @param[in] y the vertical position to query
398 * @param[in] mode the mode of hit test
399 * @param[in] callback the callback function
401 * @return true if succeeded, false otherwise
403 bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback);
406 * @brief Clear the history of Web.
411 * @brief Clear all tiles resources of Web.
413 void ClearAllTilesResources();
416 * @brief Get user agent string.
418 * @return The string value of user agent
420 const std::string& GetUserAgent() const;
423 * @brief Set user agent string.
425 * @param[in] userAgent The string value of user agent
427 void SetUserAgent(const std::string& userAgent);
430 * @brief Set the size of Web Pages.
432 void SetSize(uint32_t width, uint32_t height);
435 * @brief Set background color of web page.
437 * @param[in] color Background color
439 void SetDocumentBackgroundColor(Dali::Vector4 color);
442 * @brief Clear tiles when hidden.
444 * @param[in] cleared Whether tiles are cleared or not
446 void ClearTilesWhenHidden(bool cleared);
449 * @brief Set multiplier of cover area of tile.
451 * @param[in] multiplier The multiplier of cover area
453 void SetTileCoverAreaMultiplier(float multiplier);
456 * @brief Enable cursor by client.
458 * @param[in] enabled Whether cursor is enabled or not
460 void EnableCursorByClient(bool enabled);
463 * @brief Get the selected text.
465 * @return the selected text
467 std::string GetSelectedText() const;
470 * @brief Send Touch Events.
472 bool SendTouchEvent(const TouchEvent& touch);
475 * @brief Send key Events.
477 bool SendKeyEvent(const KeyEvent& event);
481 * @param[in] focused True if web view is focused, false otherwise
483 void SetFocus(bool focused);
486 * @brief Enable/disable mouse events. The default is enabled.
488 * @param[in] enabled True if mouse events are enabled, false otherwise
490 void EnableMouseEvents(bool enabled);
493 * @brief Enable/disable key events. The default is enabled.
495 * @param[in] enabled True if key events are enabled, false otherwise
497 void EnableKeyEvents(bool enabled);
500 * @brief Set zoom factor of the current page.
501 * @param[in] zoomFactor a new factor to be set.
503 void SetPageZoomFactor(float zoomFactor);
506 * @brief Query the current zoom factor of the page。
507 * @return The current page zoom factor.
509 float GetPageZoomFactor() const;
512 * @brief Set the current text zoom level。.
513 * @param[in] zoomFactor a new factor to be set.
515 void SetTextZoomFactor(float zoomFactor);
518 * @brief Get the current text zoom level.
519 * @return The current text zoom factor.
521 float GetTextZoomFactor() const;
524 * @brief Get the current load progress of the page.
525 * @return The load progress of the page.
527 float GetLoadProgressPercentage() const;
530 * @brief Scale the current page, centered at the given point.
531 * @param[in] scaleFactor a new factor to be scaled.
532 * @param[in] point a center coordinate.
534 void SetScaleFactor(float scaleFactor, Dali::Vector2 point);
537 * @brief Get the current scale factor of the page.
538 * @return The current scale factor.
540 float GetScaleFactor() const;
543 * @brief Request to activate/deactivate the accessibility usage set by web app.
544 * @param[in] activated Activate accessibility or not.
546 void ActivateAccessibility(bool activated);
549 * @brief Request to set the current page's visibility.
550 * @param[in] visible Visible or not.
552 * @return true if changed successfully, false otherwise
554 bool SetVisibility(bool visible);
557 * @brief Search and highlights the given string in the document.
558 * @param[in] text The text to find
559 * @param[in] options The options to find
560 * @param[in] maxMatchCount The maximum match count to find
562 * @return true if found & highlighted, false otherwise
564 bool HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount);
567 * @brief Add dynamic certificate path.
568 * @param[in] host host that required client authentication
569 * @param[in] certPath the file path stored certificate
571 void AddDynamicCertificatePath(const std::string& host, const std::string& certPath);
574 * @brief Get snapshot of the specified viewArea of page.
576 * @param[in] viewArea The rectangle of screen shot
577 * @param[in] scaleFactor The scale factor
579 * @return pixel data of screen shot
581 Dali::PixelData GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor);
584 * @brief Request to get snapshot of the specified viewArea of page asynchronously.
586 * @param[in] viewArea The rectangle of screen shot
587 * @param[in] scaleFactor The scale factor
588 * @param[in] callback The callback for screen shot
590 * @return true if requested successfully, false otherwise
592 bool GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback);
595 * @brief Asynchronous request to check if there is a video playing in the given view.
597 * @param[in] callback The callback called after checking if video is playing or not
599 * @return true if requested successfully, false otherwise
601 bool CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback);
604 * @brief Set callback which alled upon geolocation permission request.
606 * @param[in] callback The callback for requesting geolocation permission
608 void RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback);
611 * @brief Update display area.
612 * @param[in] displayArea The area to display web page
614 void UpdateDisplayArea(Dali::Rect<int32_t> displayArea);
617 * @brief Enable video hole.
618 * @param[in] enabled True if video hole is enabled, false otherwise
620 void EnableVideoHole(bool enabled);
623 * @brief Send hover events.
624 * @param[in] event The hover event would be sent.
626 bool SendHoverEvent(const HoverEvent& event);
629 * @brief Send wheel events.
630 * @param[in] event The wheel event would be sent.
632 bool SendWheelEvent(const WheelEvent& event);
635 * @brief Connect to this signal to be notified when page loading is started.
637 * @return A signal object to connect with
639 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal();
642 * @brief Connect to this signal to be notified when page loading is in progress.
644 * @return A signal object to connect with
646 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadInProgressSignal();
649 * @brief Connect to this signal to be notified when page loading is finished.
651 * @return A signal object to connect with
653 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal();
656 * @brief Connect to this signal to be notified when an error occurs in page loading.
658 * @return A signal object to connect with
660 Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal();
663 * @brief Connect to this signal to be notified when scroll edge is reached.
665 * @return A signal object to connect with
667 Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
670 * @brief Connect to this signal to be notified when url is changed.
672 * @return A signal object to connect with
674 Dali::WebEnginePlugin::WebEngineUrlChangedSignalType& UrlChangedSignal();
677 * @brief Connect to this signal to be notified when form repost decision is requested.
679 * @return A signal object to connect with.
681 Dali::WebEnginePlugin::WebEngineFormRepostDecisionSignalType& FormRepostDecisionSignal();
684 * @brief Connect to this signal to be notified when frame is rendered.
686 * @return A signal object to connect with.
688 Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& FrameRenderedSignal();
691 * @brief Connect to this signal to be notified when http request need be intercepted.
693 * @return A signal object to connect with.
695 Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& RequestInterceptorSignal();
698 * @brief Connect to this signal to be notified when console message will be logged.
700 * @return A signal object to connect with.
702 Dali::WebEnginePlugin::WebEngineConsoleMessageSignalType& ConsoleMessageSignal();
705 * @brief Connect to this signal to be notified when new policy would be decided.
707 * @return A signal object to connect with.
709 Dali::WebEnginePlugin::WebEnginePolicyDecisionSignalType& PolicyDecisionSignal();
712 * @brief Connect to this signal to be notified when certificate need be confirmed.
714 * @return A signal object to connect with.
716 Dali::WebEnginePlugin::WebEngineCertificateSignalType& CertificateConfirmSignal();
719 * @brief Connect to this signal to be notified when ssl certificate is changed.
721 * @return A signal object to connect with.
723 Dali::WebEnginePlugin::WebEngineCertificateSignalType& SslCertificateChangedSignal();
726 * @brief Connect to this signal to be notified when http authentication need be confirmed.
728 * @return A signal object to connect with.
730 Dali::WebEnginePlugin::WebEngineHttpAuthHandlerSignalType& HttpAuthHandlerSignal();
733 * @brief Connect to this signal to be notified when context menu would be customized.
735 * @return A signal object to connect with.
737 Dali::WebEnginePlugin::WebEngineContextMenuCustomizedSignalType& ContextMenuCustomizedSignal();
740 * @brief Connect to this signal to be notified when context menu item is selected.
742 * @return A signal object to connect with.
744 Dali::WebEnginePlugin::WebEngineContextMenuItemSelectedSignalType& ContextMenuItemSelectedSignal();
746 private: // Not intended for application developers
748 * @brief Internal constructor
750 explicit DALI_INTERNAL WebEngine(Internal::Adaptor::WebEngine* internal);
755 #endif // DALI_WEB_ENGINE_H