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 Get native image source to render.
128 NativeImageSourcePtr GetNativeImageSource();
131 * @brief Get settings of WebEngine.
133 Dali::WebEngineSettings& GetSettings() const;
136 * @brief Get back-forward list of WebEngine.
138 Dali::WebEngineBackForwardList& GetBackForwardList() const;
141 * @brief Load a web page based on a given URL.
143 * @param [in] url The URL of the resource to load
145 void LoadUrl(const std::string& url);
148 * @brief Return the title of the Web.
150 * @return The title of web page
152 std::string GetTitle() const;
155 * @brief Return the Favicon of the Web.
157 * @return FavIcon of Dali::PixelData& type
159 Dali::PixelData GetFavicon() const;
162 * @brief Get the url.
164 std::string GetUrl() const;
167 * @brief Load a given string as web contents.
169 * @param [in] htmlString The string to use as the contents of the web page
171 void LoadHtmlString(const std::string& htmlString);
174 * @brief Load the specified html string as the content of the view overriding current history entry
176 * @param[in] html HTML data to load
177 * @param[in] basicUri Base URL used for relative paths to external objects
178 * @param[in] unreachableUrl URL that could not be reached
180 * @return true if successfully loaded, false otherwise
182 bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl);
185 * @brief Request loading the given contents by MIME type into the view object
187 * @param[in] contents The content to load
188 * @param[in] contentSize The size of contents (in bytes)
189 * @param[in] mimeType The type of contents, if 0 is given "text/html" is assumed
190 * @param[in] encoding The encoding for contents, if 0 is given "UTF-8" is assumed
191 * @param[in] baseUri The base URI to use for relative resources
193 * @return true if successfully request, false otherwise
195 bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri);
198 * @brief Reload the Web.
203 * @brief Reload the current page's document without cache
205 bool ReloadWithoutCache();
208 * @brief Stop loading web contents on the current page.
213 * @brief Suspend the operation associated with the view.
218 * @brief Resume the operation associated with the view object after calling Suspend().
223 * @brief To suspend all url loading
225 void SuspendNetworkLoading();
228 * @brief To resume new url network loading
230 void ResumeNetworkLoading();
233 * @brief Add custom header
235 * @param[in] name custom header name to add the custom header
236 * @param[in] value custom header value to add the custom header
238 * @return true if succeeded, false otherwise
240 bool AddCustomHeader(const std::string& name, const std::string& value);
243 * @brief Remove custom header
245 * @param[in] name custom header name to remove the custom header
247 * @return true if succeeded, false otherwise
249 bool RemoveCustomHeader(const std::string& name);
252 * @brief Start the inspector server
254 * @param[in] port port number
256 * @return the port number
258 uint32_t StartInspectorServer(uint32_t port);
261 * @brief Stop the inspector server
263 * @return true if succeeded, false otherwise
265 bool StopInspectorServer();
268 * @brief Scroll web page of view by deltaX and deltaY.
270 * @param[in] deltaX horizontal offset to scroll
271 * @param[in] deltaY vertical offset to scroll
273 void ScrollBy(int32_t deltaX, int32_t deltaY);
276 * @brief Scroll edge of view by deltaX and deltaY.
278 * @param[in] deltaX horizontal offset to scroll
279 * @param[in] deltaY vertical offset to scroll
281 * @return true if succeeded, false otherwise
283 bool ScrollEdgeBy(int32_t deltaX, int32_t deltaY);
286 * @brief Set an absolute scroll of the given view.
288 void SetScrollPosition(int32_t x, int32_t y);
291 * @brief Get the current scroll position of the given view.
293 Dali::Vector2 GetScrollPosition() const;
296 * @brief Get the possible scroll size of the given view.
298 Dali::Vector2 GetScrollSize() const;
301 * @brief Get the last known content's size.
303 Dali::Vector2 GetContentSize() const;
306 * @brief Return whether forward is possible.
308 * @return True if forward is possible, false otherwise
313 * @brief Go to forward.
318 * @brief Return whether backward is possible.
320 * @return True if backward is possible, false otherwise
330 * @brief Evaluate JavaScript code represented as a string.
332 * @param[in] script The JavaScript code
333 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
335 void EvaluateJavaScript(const std::string& script, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback resultHandler);
338 * @brief Add a message handler into JavaScript.
340 * @param[in] exposedObjectName The name of exposed object
341 * @param[in] handler The callback function
343 void AddJavaScriptMessageHandler(const std::string& exposedObjectName, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback handler);
346 * @brief Register a callback for JavaScript alert.
348 * @param[in] callback The callback function
350 void RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback);
353 * @brief Reply for JavaScript alert.
355 void JavaScriptAlertReply();
358 * @brief Register a callback for JavaScript confirm.
360 * @param[in] callback The callback function
362 void RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback);
365 * @brief Reply for JavaScript confirm.
366 * @param[in] confirmed True if confirmed, false otherwise.
368 void JavaScriptConfirmReply(bool confirmed);
371 * @brief Register a callback for JavaScript prompt.
373 * @param[in] callback The callback function
375 void RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback);
378 * @brief Reply for JavaScript prompt.
379 * @param[in] result The result returned from input-field in prompt popup.
381 void JavaScriptPromptReply(const std::string& result);
384 * @brief Create a new hit test.
386 * @param[in] x the horizontal position to query
387 * @param[in] y the vertical position to query
388 * @param[in] mode the mode of hit test
390 * @return a new hit test object
392 std::unique_ptr<Dali::WebEngineHitTest> CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode);
395 * @brief create a hit test asynchronously.
397 * @param[in] x the horizontal position to query
398 * @param[in] y the vertical position to query
399 * @param[in] mode the mode of hit test
400 * @param[in] callback the callback function
402 * @return true if succeeded, false otherwise
404 bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback);
407 * @brief Clear the history of Web.
412 * @brief Clear all tiles resources of Web.
414 void ClearAllTilesResources();
417 * @brief Get user agent string.
419 * @return The string value of user agent
421 std::string GetUserAgent() const;
424 * @brief Set user agent string.
426 * @param[in] userAgent The string value of user agent
428 void SetUserAgent(const std::string& userAgent);
431 * @brief Set the size of Web Pages.
433 void SetSize(uint32_t width, uint32_t height);
436 * @brief Set background color of web page.
438 * @param[in] color Background color
440 void SetDocumentBackgroundColor(Dali::Vector4 color);
443 * @brief Clear tiles when hidden.
445 * @param[in] cleared Whether tiles are cleared or not
447 void ClearTilesWhenHidden(bool cleared);
450 * @brief Set multiplier of cover area of tile.
452 * @param[in] multiplier The multiplier of cover area
454 void SetTileCoverAreaMultiplier(float multiplier);
457 * @brief Enable cursor by client.
459 * @param[in] enabled Whether cursor is enabled or not
461 void EnableCursorByClient(bool enabled);
464 * @brief Get the selected text.
466 * @return the selected text
468 std::string GetSelectedText() const;
471 * @brief Send Touch Events.
473 bool SendTouchEvent(const TouchEvent& touch);
476 * @brief Send key Events.
478 bool SendKeyEvent(const KeyEvent& event);
482 * @param[in] focused True if web view is focused, false otherwise
484 void SetFocus(bool focused);
487 * @brief Enable/disable mouse events. The default is enabled.
489 * @param[in] enabled True if mouse events are enabled, false otherwise
491 void EnableMouseEvents(bool enabled);
494 * @brief Enable/disable key events. The default is enabled.
496 * @param[in] enabled True if key events are enabled, false otherwise
498 void EnableKeyEvents(bool enabled);
501 * @brief Set zoom factor of the current page.
502 * @param[in] zoomFactor a new factor to be set.
504 void SetPageZoomFactor(float zoomFactor);
507 * @brief Query the current zoom factor of the page。
508 * @return The current page zoom factor.
510 float GetPageZoomFactor() const;
513 * @brief Set the current text zoom level。.
514 * @param[in] zoomFactor a new factor to be set.
516 void SetTextZoomFactor(float zoomFactor);
519 * @brief Get the current text zoom level.
520 * @return The current text zoom factor.
522 float GetTextZoomFactor() const;
525 * @brief Get the current load progress of the page.
526 * @return The load progress of the page.
528 float GetLoadProgressPercentage() const;
531 * @brief Scale the current page, centered at the given point.
532 * @param[in] scaleFactor a new factor to be scaled.
533 * @param[in] point a center coordinate.
535 void SetScaleFactor(float scaleFactor, Dali::Vector2 point);
538 * @brief Get the current scale factor of the page.
539 * @return The current scale factor.
541 float GetScaleFactor() const;
544 * @brief Request to activate/deactivate the accessibility usage set by web app.
545 * @param[in] activated Activate accessibility or not.
547 void ActivateAccessibility(bool activated);
550 * @brief Get the accessibility address (bus and path) for embedding.
551 * @return Accessibility address of the root web content element.
553 Accessibility::Address GetAccessibilityAddress();
556 * @brief Request to set the current page's visibility.
557 * @param[in] visible Visible or not.
559 * @return true if changed successfully, false otherwise
561 bool SetVisibility(bool visible);
564 * @brief Search and highlights the given string in the document.
565 * @param[in] text The text to find
566 * @param[in] options The options to find
567 * @param[in] maxMatchCount The maximum match count to find
569 * @return true if found & highlighted, false otherwise
571 bool HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount);
574 * @brief Add dynamic certificate path.
575 * @param[in] host host that required client authentication
576 * @param[in] certPath the file path stored certificate
578 void AddDynamicCertificatePath(const std::string& host, const std::string& certPath);
581 * @brief Get snapshot of the specified viewArea of page.
583 * @param[in] viewArea The rectangle of screen shot
584 * @param[in] scaleFactor The scale factor
586 * @return pixel data of screen shot
588 Dali::PixelData GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor);
591 * @brief Request to get snapshot of the specified viewArea of page asynchronously.
593 * @param[in] viewArea The rectangle of screen shot
594 * @param[in] scaleFactor The scale factor
595 * @param[in] callback The callback for screen shot
597 * @return true if requested successfully, false otherwise
599 bool GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback);
602 * @brief Asynchronous request to check if there is a video playing in the given view.
604 * @param[in] callback The callback called after checking if video is playing or not
606 * @return true if requested successfully, false otherwise
608 bool CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback);
611 * @brief Set callback which alled upon geolocation permission request.
613 * @param[in] callback The callback for requesting geolocation permission
615 void RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback);
618 * @brief Update display area.
619 * @param[in] displayArea The area to display web page
621 void UpdateDisplayArea(Dali::Rect<int32_t> displayArea);
624 * @brief Enable video hole.
625 * @param[in] enabled True if video hole is enabled, false otherwise
627 void EnableVideoHole(bool enabled);
630 * @brief Send hover events.
631 * @param[in] event The hover event would be sent.
633 bool SendHoverEvent(const HoverEvent& event);
636 * @brief Send wheel events.
637 * @param[in] event The wheel event would be sent.
639 bool SendWheelEvent(const WheelEvent& event);
642 * @brief Connect to this signal to be notified when frame is rendered.
644 * @return A signal object to connect with.
646 Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& FrameRenderedSignal();
649 * @brief Callback to be called when page loading is started.
651 * @param[in] callback
653 void RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
656 * @brief Callback to be called when page loading is in progress.
658 * @param[in] callback
660 void RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
663 * @brief Callback to be called when page loading is finished.
665 * @param[in] callback
667 void RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
670 * @brief Callback to be called when an error occurs in page loading.
672 * @param[in] callback
674 void RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback);
677 * @brief Callback to be called when scroll edge is reached.
679 * @param[in] callback
681 void RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback);
684 * @brief Callback to be called when url is changed.
686 * @param[in] callback
688 void RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback);
691 * @brief Callback to be called when form repost decision is requested.
693 * @param[in] callback
695 void RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback);
698 * @brief Callback to be called when console message will be logged.
700 * @param[in] callback
702 void RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback);
705 * @brief Callback to be called when response policy would be decided.
707 * @param[in] callback
709 void RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback);
712 * @brief Callback to be called when navigation policy would be decided.
714 * @param[in] callback
716 void RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback);
719 * @brief Callback to be called when certificate need be confirmed.
721 * @param[in] callback
723 void RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
726 * @brief Callback to be called when ssl certificate is changed.
728 * @param[in] callback
730 void RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
733 * @brief Callback to be called when http authentication need be confirmed.
735 * @param[in] callback
737 void RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback);
740 * @brief Callback to be called when context menu would be shown.
742 * @param[in] callback
744 void RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback);
747 * @brief Callback to be called when context menu would be hidden.
749 * @param[in] callback
751 void RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback);
754 * @brief Get a plain text of current web page asynchronously.
756 * @param[in] callback The callback function called asynchronously.
758 void GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback);
760 private: // Not intended for application developers
762 * @brief Internal constructor
764 explicit DALI_INTERNAL WebEngine(Internal::Adaptor::WebEngine* internal);
769 #endif // DALI_WEB_ENGINE_H