1 #ifndef DALI_WEB_ENGINE_PLUGIN_H
2 #define DALI_WEB_ENGINE_PLUGIN_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/devel-api/common/bitwise-enum.h>
23 #include <dali/public-api/images/native-image-interface.h>
24 #include <dali/public-api/math/rect.h>
25 #include <dali/public-api/signals/dali-signal.h>
34 class WebEngineBackForwardList;
35 class WebEngineContext;
36 class WebEngineCookieManager;
37 class WebEngineFormRepostDecision;
38 class WebEngineSettings;
43 * @brief WebEnginePlugin is an abstract interface, used by dali-adaptor to access WebEngine plugin.
44 * A concrete implementation must be created for each platform and provided as dynamic library.
50 * @brief WebEngine signal type related with page loading.
52 using WebEnginePageLoadSignalType = Signal<void(const std::string&)>;
55 * @brief WebView signal type related with page loading error.
57 using WebEnginePageLoadErrorSignalType = Signal<void(const std::string&, int)>;
59 // forward declaration.
60 enum class ScrollEdge;
63 * @brief WebView signal type related with scroll edge reached.
65 using WebEngineScrollEdgeReachedSignalType = Signal<void(const ScrollEdge)>;
68 * @brief WebView signal type related with page url changed.
70 using WebEngineUrlChangedSignalType = Signal<void(const std::string&)>;
73 * @brief WebView signal type related with screen captured.
75 using ScreenshotCapturedCallback = std::function<void(Dali::PixelData)>;
78 * @brief WebView signal type related with geolocation permission.
79 * Host and protocol of security origin will be provided when requesting
80 * geolocation permission.
81 * It returns true if a pop-up is created successfully, false otherwise.
83 using GeolocationPermissionCallback = std::function<bool(const std::string&, const std::string&)>;
86 * @brief WebView signal type related with video playing.
88 using VideoPlayingCallback = std::function<void(bool)>;
91 * @brief Alert callback when JavaScript alert is called with a message.
92 * It returns true if a pop-up is created successfully, false otherwise.
94 using JavaScriptAlertCallback = std::function<bool(const std::string&)>;
97 * @brief Confirm callback when JavaScript confirm is called with a message.
98 * It returns true if a pop-up is created successfully, false otherwise.
100 using JavaScriptConfirmCallback = std::function<bool(const std::string&)>;
103 * @brief Prompt callback when JavaScript prompt is called with a message
104 * and an optional value that is the default value for the input field.
105 * It returns true if a pop-up is created successfully, false otherwise.
107 using JavaScriptPromptCallback = std::function<bool(const std::string&, const std::string&)>;
110 * @brief WebView signal type related with form repost decision.
112 using WebEngineFormRepostDecisionSignalType = Signal<void(std::shared_ptr<Dali::WebEngineFormRepostDecision>)>;
115 * @brief WebView signal type related with frame rendered.
117 using WebEngineFrameRenderedSignalType = Signal<void(void)>;
120 * @brief Enumeration for the scroll edge.
122 enum class ScrollEdge
124 LEFT, ///< Left edge reached.
125 RIGHT, ///< Right edge reached.
126 TOP, ///< Top edge reached.
127 BOTTOM, ///< Bottom edge reached.
131 * @brief Enumeration that provides the option to find text.
133 enum class FindOption
135 NONE = 0, ///< No search flags, this means a case sensitive, no wrap, forward only search
136 CASE_INSENSITIVE = 1 << 0, ///< Case insensitive search
137 AT_WORD_STARTS = 1 << 1, ///< Search text only at the beginning of the words
138 TREAT_MEDIAL_CAPITAL_AS_WORD_START = 1 << 2, ///< Treat capital letters in the middle of words as word start
139 BACKWARDS = 1 << 3, ///< Search backwards
140 WRAP_AROUND = 1 << 4, ///< If not present the search stops at the end of the document
141 SHOW_OVERLAY = 1 << 5, ///< Show overlay
142 SHOW_FIND_INDICATOR = 1 << 6, ///< Show indicator
143 SHOW_HIGHLIGHT = 1 << 7, ///< Show highlight
147 * @brief Constructor.
149 WebEnginePlugin() = default;
154 virtual ~WebEnginePlugin() = default;
157 * @brief Creates WebEngine instance.
159 * @param [in] width The width of Web
160 * @param [in] height The height of Web
161 * @param [in] locale The locale of Web
162 * @param [in] timezoneId The timezoneID of Web
164 virtual void Create(int width, int height, const std::string& locale, const std::string& timezoneId) = 0;
167 * @brief Creates WebEngine instance.
169 * @param [in] width The width of Web
170 * @param [in] height The height of Web
171 * @param [in] argc The count of application arguments
172 * @param [in] argv The string array of application arguments
174 virtual void Create(int width, int height, int argc, char** argv) = 0;
177 * @brief Destroys WebEngine instance.
179 virtual void Destroy() = 0;
182 * @brief Get settings of WebEngine.
184 virtual WebEngineSettings& GetSettings() const = 0;
187 * @brief Get context of WebEngine.
189 virtual WebEngineContext& GetContext() const = 0;
192 * @brief Get cookie manager of WebEngine.
194 virtual WebEngineCookieManager& GetCookieManager() const = 0;
197 * @brief Get back-forward list of WebEngine.
199 virtual WebEngineBackForwardList& GetBackForwardList() const = 0;
202 * @brief Loads a web page based on a given URL.
204 * @param [in] url The URL of the resource to load
206 virtual void LoadUrl(const std::string& url) = 0;
209 * @brief Returns the title of the Web.
211 * @return The title of web page
213 virtual std::string GetTitle() const = 0;
216 * @brief Returns the Favicon of the Web.
218 * @return Favicon of Dali::PixelData& type
220 virtual Dali::PixelData GetFavicon() const = 0;
223 * @brief Gets image to render.
225 virtual NativeImageInterfacePtr GetNativeImageSource() = 0;
228 * @brief Returns the URL of the Web.
230 * @return Url of string type
232 virtual const std::string& GetUrl() = 0;
235 * @brief Loads a given string as web contents.
237 * @param [in] htmlString The string to use as the contents of the web page
239 virtual void LoadHtmlString(const std::string& htmlString) = 0;
242 * @brief Load the specified html string as the content of the view overriding current history entry
244 * @param[in] html HTML data to load
245 * @param[in] basicUri Base URL used for relative paths to external objects
246 * @param[in] unreachableUrl URL that could not be reached
248 * @return true if successfully loaded, false otherwise
250 virtual bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl) = 0;
253 * @brief Requests loading the given contents by MIME type into the view object
255 * @param[in] contents The content to load
256 * @param[in] contentSize The size of contents (in bytes)
257 * @param[in] mimeType The type of contents, if 0 is given "text/html" is assumed
258 * @param[in] encoding The encoding for contents, if 0 is given "UTF-8" is assumed
259 * @param[in] baseUri The base URI to use for relative resources
261 * @return true if successfully request, false otherwise
263 virtual bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri) = 0;
266 * @brief Reloads the Web.
268 virtual void Reload() = 0;
271 * @brief Reloads the current page's document without cache
273 virtual bool ReloadWithoutCache() = 0;
276 * @brief Stops loading web contents on the current page.
278 virtual void StopLoading() = 0;
281 * @brief Suspends the operation associated with the view.
283 virtual void Suspend() = 0;
286 * @brief Resumes the operation associated with the view object after calling Suspend().
288 virtual void Resume() = 0;
291 * @brief To suspend all url loading
293 virtual void SuspendNetworkLoading() = 0;
296 * @brief To resume new url network loading
298 virtual void ResumeNetworkLoading() = 0;
301 * @brief Add custom header
303 * @param[in] name custom header name to add the custom header
304 * @param[in] value custom header value to add the custom header
306 * @return true if succeeded, false otherwise
308 virtual bool AddCustomHeader(const std::string& name, const std::string& value) = 0;
311 * @brief Remove custom header
313 * @param[in] name custom header name to remove the custom header
315 * @return true if succeeded, false otherwise
317 virtual bool RemoveCustomHeader(const std::string& name) = 0;
320 * @brief Start the inspector server
322 * @param[in] port port number
324 * @return the port number
326 virtual uint32_t StartInspectorServer(uint32_t port) = 0;
329 * @brief Stop the inspector server
331 * @return true if succeeded, false otherwise
333 virtual bool StopInspectorServer() = 0;
336 * @brief Scrolls web page of view by deltaX and deltaY.
338 * @param[in] deltaX horizontal offset to scroll
339 * @param[in] deltaY vertical offset to scroll
341 virtual void ScrollBy(int deltaX, int deltaY) = 0;
344 * @brief Scrolls edge of view by deltaX and deltaY.
346 * @param[in] deltaX horizontal offset to scroll
347 * @param[in] deltaY vertical offset to scroll
349 * @return true if succeeded, false otherwise
351 virtual bool ScrollEdgeBy(int deltaX, int deltaY) = 0;
354 * @brief Scroll to the specified position of the given view.
356 virtual void SetScrollPosition(int x, int y) = 0;
359 * @brief Gets the current scroll position of the given view.
361 virtual Dali::Vector2 GetScrollPosition() const = 0;
364 * @brief Gets the possible scroll size of the given view.
366 virtual Dali::Vector2 GetScrollSize() const = 0;
369 * @brief Gets the last known content's size.
371 virtual Dali::Vector2 GetContentSize() const = 0;
374 * @brief Returns whether forward is possible.
376 * @return True if forward is possible, false otherwise
378 virtual bool CanGoForward() = 0;
381 * @brief Goes to forward.
383 virtual void GoForward() = 0;
386 * @brief Returns whether backward is possible.
388 * @return True if backward is possible, false otherwise
390 virtual bool CanGoBack() = 0;
393 * @brief Goes to back.
395 virtual void GoBack() = 0;
398 * @brief Evaluates JavaScript code represented as a string.
400 * @param[in] script The JavaScript code
401 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
403 virtual void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler) = 0;
406 * @brief Add a message handler into JavaScript.
408 * @param[in] exposedObjectName The name of exposed object
409 * @param[in] handler The callback function
411 virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler) = 0;
414 * @brief Register a callback for JavaScript alert.
416 * @param[in] callback The callback function
418 virtual void RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback) = 0;
421 * @brief Reply for JavaScript alert.
423 virtual void JavaScriptAlertReply() = 0;
426 * @brief Register a callback for JavaScript confirm.
428 * @param[in] callback The callback function
430 virtual void RegisterJavaScriptConfirmCallback(JavaScriptConfirmCallback callback) = 0;
433 * @brief Reply for JavaScript confirm.
435 virtual void JavaScriptConfirmReply(bool confirmed) = 0;
438 * @brief Register a callback for JavaScript prompt.
440 * @param[in] callback The callback function
442 virtual void RegisterJavaScriptPromptCallback(JavaScriptPromptCallback callback) = 0;
445 * @brief Reply for JavaScript prompt.
447 virtual void JavaScriptPromptReply(const std::string& result) = 0;
450 * @brief Clears the history of Web.
452 virtual void ClearHistory() = 0;
455 * @brief Clears all tiles resources of Web.
457 virtual void ClearAllTilesResources() = 0;
460 * @brief Get user agent string.
462 * @return The string value of user agent
464 virtual const std::string& GetUserAgent() const = 0;
467 * @brief Set user agent string.
469 * @param[in] userAgent The string value of user agent
471 virtual void SetUserAgent(const std::string& userAgent) = 0;
474 * @brief Sets size of Web Page.
476 virtual void SetSize(int width, int height) = 0;
479 * @brief Sets background color of web page.
481 * @param[in] color Background color
483 virtual void SetDocumentBackgroundColor(Dali::Vector4 color) = 0;
486 * @brief Clears tiles when hidden.
488 * @param[in] cleared Whether tiles are cleared or not
490 virtual void ClearTilesWhenHidden(bool cleared) = 0;
493 * @brief Sets multiplier of cover area of tile.
495 * @param[in] multiplier The multiplier of cover area
497 virtual void SetTileCoverAreaMultiplier(float multiplier) = 0;
500 * @brief Enables cursor by client.
502 * @param[in] enabled Whether cursor is enabled or not
504 virtual void EnableCursorByClient(bool enabled) = 0;
507 * @brief Gets the selected text.
509 * @return the selected text
511 virtual std::string GetSelectedText() const = 0;
514 * @brief Sends Touch Events.
516 virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
519 * @brief Sends Key Events.
521 virtual bool SendKeyEvent(const KeyEvent& event) = 0;
524 * @brief Support mouse events or not.
525 * @param[in] enabled True if enabled, false othewise.
527 virtual void EnableMouseEvents( bool enabled ) = 0;
530 * @brief Support key events or not.
531 * @param[in] enabled True if enabled, false othewise.
533 virtual void EnableKeyEvents( bool enabled ) = 0;
537 * @param[in] focused True if focus is gained, false lost.
539 virtual void SetFocus(bool focused) = 0;
542 * @brief Sets zoom factor of the current page.
543 * @param[in] zoomFactor a new factor to be set.
545 virtual void SetPageZoomFactor(float zoomFactor) = 0;
548 * @brief Queries the current zoom factor of the page。
549 * @return The current page zoom factor.
551 virtual float GetPageZoomFactor() const = 0;
554 * @brief Sets the current text zoom level。.
555 * @param[in] zoomFactor a new factor to be set.
557 virtual void SetTextZoomFactor(float zoomFactor) = 0;
560 * @brief Gets the current text zoom level.
561 * @return The current text zoom factor.
563 virtual float GetTextZoomFactor() const = 0;
566 * @brief Gets the current load progress of the page.
567 * @return The load progress of the page.
569 virtual float GetLoadProgressPercentage() const = 0;
572 * @brief Scales the current page, centered at the given point.
573 * @param[in] scaleFactor a new factor to be scaled.
574 * @param[in] point a center coordinate.
576 virtual void SetScaleFactor(float scaleFactor, Dali::Vector2 point) = 0;
579 * @brief Gets the current scale factor of the page.
580 * @return The current scale factor.
582 virtual float GetScaleFactor() const = 0;
585 * @brief Request to activate/deactivate the accessibility usage set by web app.
586 * @param[in] activated Activate accessibility or not.
588 virtual void ActivateAccessibility(bool activated) = 0;
591 * @brief Request to set the current page's visibility.
592 * @param[in] visible Visible or not.
594 * @return true if succeeded, false otherwise
596 virtual bool SetVisibility(bool visible) = 0;
599 * @brief Searches and highlights the given string in the document.
600 * @param[in] text The text to find
601 * @param[in] options The options to find
602 * @param[in] maxMatchCount The maximum match count to find
604 * @return true if found & highlighted, false otherwise
606 virtual bool HighlightText(const std::string& text, FindOption options, uint32_t maxMatchCount) = 0;
609 * @brief Add dynamic certificate path.
610 * @param[in] host host that required client authentication
611 * @param[in] certPath the file path stored certificate
613 virtual void AddDynamicCertificatePath(const std::string& host, const std::string& certPath) = 0;
616 * @brief Get snapshot of the specified viewArea of page.
618 * @param[in] viewArea The rectangle of screen shot
619 * @param[in] scaleFactor The scale factor
621 * @return pixel data of screen shot
623 virtual Dali::PixelData GetScreenshot(Dali::Rect<int> viewArea, float scaleFactor) = 0;
626 * @brief Request to get snapshot of the specified viewArea of page asynchronously.
628 * @param[in] viewArea The rectangle of screen shot
629 * @param[in] scaleFactor The scale factor
630 * @param[in] callback The callback for screen shot
632 * @return true if requested successfully, false otherwise
634 virtual bool GetScreenshotAsynchronously(Dali::Rect<int> viewArea, float scaleFactor, ScreenshotCapturedCallback callback) = 0;
637 * @brief Asynchronously request to check if there is a video playing in the given view.
639 * @param[in] callback The callback called after checking if video is playing or not
641 * @return true if requested successfully, false otherwise
643 virtual bool CheckVideoPlayingAsynchronously(VideoPlayingCallback callback) = 0;
646 * @brief Sets callback which will be called upon geolocation permission request.
648 * @param[in] callback The callback for requesting geolocation permission
650 virtual void RegisterGeolocationPermissionCallback(GeolocationPermissionCallback callback) = 0;
653 * @brief Update display area.
654 * @param[in] displayArea The display area need be updated.
656 virtual void UpdateDisplayArea(Dali::Rect<int> displayArea) = 0;
659 * @brief Enable video hole.
660 * @param[in] enabled True if enabled, false othewise.
662 virtual void EnableVideoHole(bool enabled) = 0;
665 * @brief Sends Hover Events.
666 * @param[in] event The hover event would be sent.
668 virtual bool SendHoverEvent( const HoverEvent& event ) = 0;
671 * @brief Sends Wheel Events.
672 * @param[in] event The wheel event would be sent.
674 virtual bool SendWheelEvent( const WheelEvent& event ) = 0;
677 * @brief Connects to this signal to be notified when page loading is started.
679 * @return A signal object to connect with.
681 virtual WebEnginePageLoadSignalType& PageLoadStartedSignal() = 0;
684 * @brief Connects to this signal to be notified when page loading is in progress.
686 * @return A signal object to connect with.
688 virtual WebEnginePageLoadSignalType& PageLoadInProgressSignal() = 0;
691 * @brief Connects to this signal to be notified when page loading is finished.
693 * @return A signal object to connect with.
695 virtual WebEnginePageLoadSignalType& PageLoadFinishedSignal() = 0;
698 * @brief Connects to this signal to be notified when an error occurs in page loading.
700 * @return A signal object to connect with.
702 virtual WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() = 0;
705 * @brief Connects to this signal to be notified when scroll edge is reached.
707 * @return A signal object to connect with.
709 virtual WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal() = 0;
712 * @brief Connects to this signal to be notified when url is changed.
714 * @return A signal object to connect with.
716 virtual WebEngineUrlChangedSignalType& UrlChangedSignal() = 0;
719 * @brief Connects to this signal to be notified when form repost decision is requested.
721 * @return A signal object to connect with.
723 virtual WebEngineFormRepostDecisionSignalType& FormRepostDecisionSignal() = 0;
726 * @brief Connects to this signal to be notified when frame is rendered.
728 * @return A signal object to connect with.
730 virtual WebEngineFrameRenderedSignalType& FrameRenderedSignal() = 0;
733 // specialization has to be done in the same namespace
735 struct EnableBitMaskOperators<WebEnginePlugin::FindOption>
737 static const bool ENABLE = true;