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 Creates 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 Creates 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(int width, int height, const std::string& locale, const std::string& timezoneId);
100 * @brief Creates 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(int width, int height, int argc, char** argv);
110 * @brief Destroys WebEngine instance.
115 * @brief Gets 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 Loads 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 Returns the title of the Web.
149 * @return The title of web page
151 std::string GetTitle() const;
154 * @brief Returns the Favicon of the Web.
156 * @return FavIcon of Dali::PixelData& type
158 Dali::PixelData GetFavicon() const;
161 * @brief Gets the url.
163 const std::string& GetUrl();
166 * @brief Loads 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 Requests 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 Reloads the Web.
202 * @brief Reloads the current page's document without cache
204 bool ReloadWithoutCache();
207 * @brief Stops loading web contents on the current page.
212 * @brief Suspends the operation associated with the view.
217 * @brief Resumes 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 Scrolls 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(int deltaX, int deltaY);
275 * @brief Scrolls 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(int deltaX, int deltaY);
285 * @brief Sets an absolute scroll of the given view.
287 void SetScrollPosition(int x, int y);
290 * @brief Gets the current scroll position of the given view.
292 Dali::Vector2 GetScrollPosition() const;
295 * @brief Gets the possible scroll size of the given view.
297 Dali::Vector2 GetScrollSize() const;
300 * @brief Gets the last known content's size.
302 Dali::Vector2 GetContentSize() const;
305 * @brief Returns whether forward is possible.
307 * @return True if forward is possible, false otherwise
312 * @brief Goes to forward.
317 * @brief Returns whether backward is possible.
319 * @return True if backward is possible, false otherwise
324 * @brief Goes to back.
329 * @brief Evaluates 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 Clears the history of Web.
388 * @brief Clears all tiles resources of Web.
390 void ClearAllTilesResources();
393 * @brief Get user agent string.
395 * @return The string value of user agent
397 const std::string& GetUserAgent() const;
400 * @brief Set user agent string.
402 * @param[in] userAgent The string value of user agent
404 void SetUserAgent(const std::string& userAgent);
407 * @brief Sets the size of Web Pages.
409 void SetSize(int width, int height);
412 * @brief Sets background color of web page.
414 * @param[in] color Background color
416 void SetDocumentBackgroundColor(Dali::Vector4 color);
419 * @brief Clears tiles when hidden.
421 * @param[in] cleared Whether tiles are cleared or not
423 void ClearTilesWhenHidden(bool cleared);
426 * @brief Sets multiplier of cover area of tile.
428 * @param[in] multiplier The multiplier of cover area
430 void SetTileCoverAreaMultiplier(float multiplier);
433 * @brief Enables cursor by client.
435 * @param[in] enabled Whether cursor is enabled or not
437 void EnableCursorByClient(bool enabled);
440 * @brief Gets the selected text.
442 * @return the selected text
444 std::string GetSelectedText() const;
447 * @brief Sends Touch Events.
449 bool SendTouchEvent(const TouchEvent& touch);
452 * @brief Sends key Events.
454 bool SendKeyEvent(const KeyEvent& event);
458 * @param[in] focused True if web view is focused, false otherwise
460 void SetFocus(bool focused);
463 * @brief Enables/disables mouse events. The default is enabled.
465 * @param[in] enabled True if mouse events are enabled, false otherwise
467 void EnableMouseEvents( bool enabled );
470 * @brief Enables/disables key events. The default is enabled.
472 * @param[in] enabled True if key events are enabled, false otherwise
474 void EnableKeyEvents( bool enabled );
477 * @brief Sets zoom factor of the current page.
478 * @param[in] zoomFactor a new factor to be set.
480 void SetPageZoomFactor(float zoomFactor);
483 * @brief Queries the current zoom factor of the page。
484 * @return The current page zoom factor.
486 float GetPageZoomFactor() const;
489 * @brief Sets the current text zoom level。.
490 * @param[in] zoomFactor a new factor to be set.
492 void SetTextZoomFactor(float zoomFactor);
495 * @brief Gets the current text zoom level.
496 * @return The current text zoom factor.
498 float GetTextZoomFactor() const;
501 * @brief Gets the current load progress of the page.
502 * @return The load progress of the page.
504 float GetLoadProgressPercentage() const;
507 * @brief Scales the current page, centered at the given point.
508 * @param[in] scaleFactor a new factor to be scaled.
509 * @param[in] point a center coordinate.
511 void SetScaleFactor(float scaleFactor, Dali::Vector2 point);
514 * @brief Gets the current scale factor of the page.
515 * @return The current scale factor.
517 float GetScaleFactor() const;
520 * @brief Request to activate/deactivate the accessibility usage set by web app.
521 * @param[in] activated Activate accessibility or not.
523 void ActivateAccessibility(bool activated);
526 * @brief Request to set the current page's visibility.
527 * @param[in] visible Visible or not.
529 * @return true if changed successfully, false otherwise
531 bool SetVisibility(bool visible);
534 * @brief Searches and highlights the given string in the document.
535 * @param[in] text The text to find
536 * @param[in] options The options to find
537 * @param[in] maxMatchCount The maximum match count to find
539 * @return true if found & highlighted, false otherwise
541 bool HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount);
544 * @brief Add dynamic certificate path.
545 * @param[in] host host that required client authentication
546 * @param[in] certPath the file path stored certificate
548 void AddDynamicCertificatePath(const std::string& host, const std::string& certPath);
551 * @brief Get snapshot of the specified viewArea of page.
553 * @param[in] viewArea The rectangle of screen shot
554 * @param[in] scaleFactor The scale factor
556 * @return pixel data of screen shot
558 Dali::PixelData GetScreenshot(Dali::Rect<int> viewArea, float scaleFactor);
561 * @brief Request to get snapshot of the specified viewArea of page asynchronously.
563 * @param[in] viewArea The rectangle of screen shot
564 * @param[in] scaleFactor The scale factor
565 * @param[in] callback The callback for screen shot
567 * @return true if requested successfully, false otherwise
569 bool GetScreenshotAsynchronously(Dali::Rect<int> viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback);
572 * @brief Asynchronous request to check if there is a video playing in the given view.
574 * @param[in] callback The callback called after checking if video is playing or not
576 * @return true if requested successfully, false otherwise
578 bool CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback);
581 * @brief Sets callback which alled upon geolocation permission request.
583 * @param[in] callback The callback for requesting geolocation permission
585 void RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback);
588 * @brief Update display area.
589 * @param[in] displayArea The area to display web page
591 void UpdateDisplayArea(Dali::Rect<int> displayArea);
594 * @brief Enable video hole.
595 * @param[in] enabled True if video hole is enabled, false otherwise
597 void EnableVideoHole(bool enabled);
600 * @brief Sends hover events.
601 * @param[in] event The hover event would be sent.
603 bool SendHoverEvent( const HoverEvent& event );
606 * @brief Sends wheel events.
607 * @param[in] event The wheel event would be sent.
609 bool SendWheelEvent( const WheelEvent& event );
612 * @brief Connects to this signal to be notified when page loading is started.
614 * @return A signal object to connect with
616 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal();
619 * @brief Connects to this signal to be notified when page loading is in progress.
621 * @return A signal object to connect with
623 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadInProgressSignal();
626 * @brief Connects to this signal to be notified when page loading is finished.
628 * @return A signal object to connect with
630 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal();
633 * @brief Connects to this signal to be notified when an error occurs in page loading.
635 * @return A signal object to connect with
637 Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal();
640 * @brief Connects to this signal to be notified when scroll edge is reached.
642 * @return A signal object to connect with
644 Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
647 * @brief Connects to this signal to be notified when url is changed.
649 * @return A signal object to connect with
651 Dali::WebEnginePlugin::WebEngineUrlChangedSignalType& UrlChangedSignal();
654 * @brief Connects to this signal to be notified when form repost decision is requested.
656 * @return A signal object to connect with.
658 Dali::WebEnginePlugin::WebEngineFormRepostDecisionSignalType& FormRepostDecisionSignal();
661 * @brief Connects to this signal to be notified when frame is rendered.
663 * @return A signal object to connect with.
665 Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& FrameRenderedSignal();
668 * @brief Connects to this signal to be notified when http request need be intercepted.
670 * @return A signal object to connect with.
672 Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& RequestInterceptorSignal();
674 private: // Not intended for application developers
676 * @brief Internal constructor
678 explicit DALI_INTERNAL WebEngine(Internal::Adaptor::WebEngine* internal);
683 #endif // DALI_WEB_ENGINE_H