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 WebEngineConsoleMessage;
36 class WebEngineContext;
37 class WebEngineCookieManager;
38 class WebEngineFormRepostDecision;
39 class WebEngineRequestInterceptor;
40 class WebEngineLoadError;
41 class WebEngineSettings;
46 * @brief WebEnginePlugin is an abstract interface, used by dali-adaptor to access WebEngine plugin.
47 * A concrete implementation must be created for each platform and provided as dynamic library.
53 * @brief WebEngine signal type related with page loading.
55 using WebEnginePageLoadSignalType = Signal<void(const std::string&)>;
58 * @brief WebView signal type related with page loading error.
60 using WebEnginePageLoadErrorSignalType = Signal<void(std::shared_ptr<Dali::WebEngineLoadError>)>;
62 // forward declaration.
63 enum class ScrollEdge;
66 * @brief WebView signal type related with scroll edge reached.
68 using WebEngineScrollEdgeReachedSignalType = Signal<void(const ScrollEdge)>;
71 * @brief WebView signal type related with page url changed.
73 using WebEngineUrlChangedSignalType = Signal<void(const std::string&)>;
76 * @brief WebView signal type related with screen captured.
78 using ScreenshotCapturedCallback = std::function<void(Dali::PixelData)>;
81 * @brief WebView signal type related with geolocation permission.
82 * Host and protocol of security origin will be provided when requesting
83 * geolocation permission.
84 * It returns true if a pop-up is created successfully, false otherwise.
86 using GeolocationPermissionCallback = std::function<bool(const std::string&, const std::string&)>;
89 * @brief WebView signal type related with video playing.
91 using VideoPlayingCallback = std::function<void(bool)>;
94 * @brief WebView signal type related with http request interceptor.
96 using WebEngineRequestInterceptorSignalType = Signal<void(std::shared_ptr<Dali::WebEngineRequestInterceptor>)>;
99 * @brief WebView signal type related with console message will be logged.
101 using WebEngineConsoleMessageSignalType = Signal<void(std::shared_ptr<Dali::WebEngineConsoleMessage>)>;
104 * @brief Alert callback when JavaScript alert is called with a message.
105 * It returns true if a pop-up is created successfully, false otherwise.
107 using JavaScriptAlertCallback = std::function<bool(const std::string&)>;
110 * @brief Confirm callback when JavaScript confirm is called with a message.
111 * It returns true if a pop-up is created successfully, false otherwise.
113 using JavaScriptConfirmCallback = std::function<bool(const std::string&)>;
116 * @brief Prompt callback when JavaScript prompt is called with a message
117 * and an optional value that is the default value for the input field.
118 * It returns true if a pop-up is created successfully, false otherwise.
120 using JavaScriptPromptCallback = std::function<bool(const std::string&, const std::string&)>;
123 * @brief WebView signal type related with form repost decision.
125 using WebEngineFormRepostDecisionSignalType = Signal<void(std::shared_ptr<Dali::WebEngineFormRepostDecision>)>;
128 * @brief WebView signal type related with frame rendered.
130 using WebEngineFrameRenderedSignalType = Signal<void(void)>;
133 * @brief Enumeration for the scroll edge.
135 enum class ScrollEdge
137 LEFT, ///< Left edge reached.
138 RIGHT, ///< Right edge reached.
139 TOP, ///< Top edge reached.
140 BOTTOM, ///< Bottom edge reached.
144 * @brief Enumeration that provides the option to find text.
146 enum class FindOption
148 NONE = 0, ///< No search flags, this means a case sensitive, no wrap, forward only search
149 CASE_INSENSITIVE = 1 << 0, ///< Case insensitive search
150 AT_WORD_STARTS = 1 << 1, ///< Search text only at the beginning of the words
151 TREAT_MEDIAL_CAPITAL_AS_WORD_START = 1 << 2, ///< Treat capital letters in the middle of words as word start
152 BACKWARDS = 1 << 3, ///< Search backwards
153 WRAP_AROUND = 1 << 4, ///< If not present the search stops at the end of the document
154 SHOW_OVERLAY = 1 << 5, ///< Show overlay
155 SHOW_FIND_INDICATOR = 1 << 6, ///< Show indicator
156 SHOW_HIGHLIGHT = 1 << 7, ///< Show highlight
160 * @brief Constructor.
162 WebEnginePlugin() = default;
167 virtual ~WebEnginePlugin() = default;
170 * @brief Create WebEngine instance.
172 * @param [in] width The width of Web
173 * @param [in] height The height of Web
174 * @param [in] locale The locale of Web
175 * @param [in] timezoneId The timezoneID of Web
177 virtual void Create(int width, int height, const std::string& locale, const std::string& timezoneId) = 0;
180 * @brief Create WebEngine instance.
182 * @param [in] width The width of Web
183 * @param [in] height The height of Web
184 * @param [in] argc The count of application arguments
185 * @param [in] argv The string array of application arguments
187 virtual void Create(int width, int height, int argc, char** argv) = 0;
190 * @brief Destroy WebEngine instance.
192 virtual void Destroy() = 0;
195 * @brief Get settings of WebEngine.
197 virtual WebEngineSettings& GetSettings() const = 0;
200 * @brief Get context of WebEngine.
202 virtual WebEngineContext& GetContext() const = 0;
205 * @brief Get cookie manager of WebEngine.
207 virtual WebEngineCookieManager& GetCookieManager() const = 0;
210 * @brief Get back-forward list of WebEngine.
212 virtual WebEngineBackForwardList& GetBackForwardList() const = 0;
215 * @brief Load a web page based on a given URL.
217 * @param [in] url The URL of the resource to load
219 virtual void LoadUrl(const std::string& url) = 0;
222 * @brief Return the title of the Web.
224 * @return The title of web page
226 virtual std::string GetTitle() const = 0;
229 * @brief Return the Favicon of the Web.
231 * @return Favicon of Dali::PixelData& type
233 virtual Dali::PixelData GetFavicon() const = 0;
236 * @brief Get image to render.
238 virtual NativeImageInterfacePtr GetNativeImageSource() = 0;
241 * @brief Returns the URL of the Web.
243 * @return Url of string type
245 virtual const std::string& GetUrl() = 0;
248 * @brief Load a given string as web contents.
250 * @param [in] htmlString The string to use as the contents of the web page
252 virtual void LoadHtmlString(const std::string& htmlString) = 0;
255 * @brief Load the specified html string as the content of the view overriding current history entry
257 * @param[in] html HTML data to load
258 * @param[in] basicUri Base URL used for relative paths to external objects
259 * @param[in] unreachableUrl URL that could not be reached
261 * @return true if successfully loaded, false otherwise
263 virtual bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl) = 0;
266 * @brief Request loading the given contents by MIME type into the view object
268 * @param[in] contents The content to load
269 * @param[in] contentSize The size of contents (in bytes)
270 * @param[in] mimeType The type of contents, if 0 is given "text/html" is assumed
271 * @param[in] encoding The encoding for contents, if 0 is given "UTF-8" is assumed
272 * @param[in] baseUri The base URI to use for relative resources
274 * @return true if successfully request, false otherwise
276 virtual bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri) = 0;
279 * @brief Reload the Web.
281 virtual void Reload() = 0;
284 * @brief Reload the current page's document without cache
286 virtual bool ReloadWithoutCache() = 0;
289 * @brief Stop loading web contents on the current page.
291 virtual void StopLoading() = 0;
294 * @brief Suspend the operation associated with the view.
296 virtual void Suspend() = 0;
299 * @brief Resume the operation associated with the view object after calling Suspend().
301 virtual void Resume() = 0;
304 * @brief To suspend all url loading
306 virtual void SuspendNetworkLoading() = 0;
309 * @brief To resume new url network loading
311 virtual void ResumeNetworkLoading() = 0;
314 * @brief Add custom header
316 * @param[in] name custom header name to add the custom header
317 * @param[in] value custom header value to add the custom header
319 * @return true if succeeded, false otherwise
321 virtual bool AddCustomHeader(const std::string& name, const std::string& value) = 0;
324 * @brief Remove custom header
326 * @param[in] name custom header name to remove the custom header
328 * @return true if succeeded, false otherwise
330 virtual bool RemoveCustomHeader(const std::string& name) = 0;
333 * @brief Start the inspector server
335 * @param[in] port port number
337 * @return the port number
339 virtual uint32_t StartInspectorServer(uint32_t port) = 0;
342 * @brief Stop the inspector server
344 * @return true if succeeded, false otherwise
346 virtual bool StopInspectorServer() = 0;
349 * @brief Scroll web page of view by deltaX and deltaY.
351 * @param[in] deltaX horizontal offset to scroll
352 * @param[in] deltaY vertical offset to scroll
354 virtual void ScrollBy(int deltaX, int deltaY) = 0;
357 * @brief Scroll edge of view by deltaX and deltaY.
359 * @param[in] deltaX horizontal offset to scroll
360 * @param[in] deltaY vertical offset to scroll
362 * @return true if succeeded, false otherwise
364 virtual bool ScrollEdgeBy(int deltaX, int deltaY) = 0;
367 * @brief Scroll to the specified position of the given view.
369 virtual void SetScrollPosition(int x, int y) = 0;
372 * @brief Get the current scroll position of the given view.
374 virtual Dali::Vector2 GetScrollPosition() const = 0;
377 * @brief Get the possible scroll size of the given view.
379 virtual Dali::Vector2 GetScrollSize() const = 0;
382 * @brief Get the last known content's size.
384 virtual Dali::Vector2 GetContentSize() const = 0;
387 * @brief Return whether forward is possible.
389 * @return True if forward is possible, false otherwise
391 virtual bool CanGoForward() = 0;
394 * @brief Go to forward.
396 virtual void GoForward() = 0;
399 * @brief Return whether backward is possible.
401 * @return True if backward is possible, false otherwise
403 virtual bool CanGoBack() = 0;
408 virtual void GoBack() = 0;
411 * @brief Evaluates JavaScript code represented as a string.
413 * @param[in] script The JavaScript code
414 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
416 virtual void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler) = 0;
419 * @brief Add a message handler into JavaScript.
421 * @param[in] exposedObjectName The name of exposed object
422 * @param[in] handler The callback function
424 virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler) = 0;
427 * @brief Register a callback for JavaScript alert.
429 * @param[in] callback The callback function
431 virtual void RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback) = 0;
434 * @brief Reply for JavaScript alert.
436 virtual void JavaScriptAlertReply() = 0;
439 * @brief Register a callback for JavaScript confirm.
441 * @param[in] callback The callback function
443 virtual void RegisterJavaScriptConfirmCallback(JavaScriptConfirmCallback callback) = 0;
446 * @brief Reply for JavaScript confirm.
448 virtual void JavaScriptConfirmReply(bool confirmed) = 0;
451 * @brief Register a callback for JavaScript prompt.
453 * @param[in] callback The callback function
455 virtual void RegisterJavaScriptPromptCallback(JavaScriptPromptCallback callback) = 0;
458 * @brief Reply for JavaScript prompt.
460 virtual void JavaScriptPromptReply(const std::string& result) = 0;
463 * @brief Clear the history of Web.
465 virtual void ClearHistory() = 0;
468 * @brief Clear all tiles resources of Web.
470 virtual void ClearAllTilesResources() = 0;
473 * @brief Get user agent string.
475 * @return The string value of user agent
477 virtual const std::string& GetUserAgent() const = 0;
480 * @brief Set user agent string.
482 * @param[in] userAgent The string value of user agent
484 virtual void SetUserAgent(const std::string& userAgent) = 0;
487 * @brief Sets size of Web Page.
489 virtual void SetSize(int width, int height) = 0;
492 * @brief Set background color of web page.
494 * @param[in] color Background color
496 virtual void SetDocumentBackgroundColor(Dali::Vector4 color) = 0;
499 * @brief Clear tiles when hidden.
501 * @param[in] cleared Whether tiles are cleared or not
503 virtual void ClearTilesWhenHidden(bool cleared) = 0;
506 * @brief Set multiplier of cover area of tile.
508 * @param[in] multiplier The multiplier of cover area
510 virtual void SetTileCoverAreaMultiplier(float multiplier) = 0;
513 * @brief Enable cursor by client.
515 * @param[in] enabled Whether cursor is enabled or not
517 virtual void EnableCursorByClient(bool enabled) = 0;
520 * @brief Get the selected text.
522 * @return the selected text
524 virtual std::string GetSelectedText() const = 0;
527 * @brief Send Touch Events.
529 virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
532 * @brief Send Key Events.
534 virtual bool SendKeyEvent(const KeyEvent& event) = 0;
537 * @brief Support mouse events or not.
538 * @param[in] enabled True if enabled, false othewise.
540 virtual void EnableMouseEvents(bool enabled) = 0;
543 * @brief Support key events or not.
544 * @param[in] enabled True if enabled, false othewise.
546 virtual void EnableKeyEvents(bool enabled) = 0;
550 * @param[in] focused True if focus is gained, false lost.
552 virtual void SetFocus(bool focused) = 0;
555 * @brief Set zoom factor of the current page.
556 * @param[in] zoomFactor a new factor to be set.
558 virtual void SetPageZoomFactor(float zoomFactor) = 0;
561 * @brief Query the current zoom factor of the page。
562 * @return The current page zoom factor.
564 virtual float GetPageZoomFactor() const = 0;
567 * @brief Set the current text zoom level。.
568 * @param[in] zoomFactor a new factor to be set.
570 virtual void SetTextZoomFactor(float zoomFactor) = 0;
573 * @brief Get the current text zoom level.
574 * @return The current text zoom factor.
576 virtual float GetTextZoomFactor() const = 0;
579 * @brief Get the current load progress of the page.
580 * @return The load progress of the page.
582 virtual float GetLoadProgressPercentage() const = 0;
585 * @brief Scale the current page, centered at the given point.
586 * @param[in] scaleFactor a new factor to be scaled.
587 * @param[in] point a center coordinate.
589 virtual void SetScaleFactor(float scaleFactor, Dali::Vector2 point) = 0;
592 * @brief Get the current scale factor of the page.
593 * @return The current scale factor.
595 virtual float GetScaleFactor() const = 0;
598 * @brief Request to activate/deactivate the accessibility usage set by web app.
599 * @param[in] activated Activate accessibility or not.
601 virtual void ActivateAccessibility(bool activated) = 0;
604 * @brief Request to set the current page's visibility.
605 * @param[in] visible Visible or not.
607 * @return true if succeeded, false otherwise
609 virtual bool SetVisibility(bool visible) = 0;
612 * @brief Search and highlight the given string in the document.
613 * @param[in] text The text to find
614 * @param[in] options The options to find
615 * @param[in] maxMatchCount The maximum match count to find
617 * @return true if found & highlighted, false otherwise
619 virtual bool HighlightText(const std::string& text, FindOption options, uint32_t maxMatchCount) = 0;
622 * @brief Add dynamic certificate path.
623 * @param[in] host host that required client authentication
624 * @param[in] certPath the file path stored certificate
626 virtual void AddDynamicCertificatePath(const std::string& host, const std::string& certPath) = 0;
629 * @brief Get snapshot of the specified viewArea of page.
631 * @param[in] viewArea The rectangle of screen shot
632 * @param[in] scaleFactor The scale factor
634 * @return pixel data of screen shot
636 virtual Dali::PixelData GetScreenshot(Dali::Rect<int> viewArea, float scaleFactor) = 0;
639 * @brief Request to get snapshot of the specified viewArea of page asynchronously.
641 * @param[in] viewArea The rectangle of screen shot
642 * @param[in] scaleFactor The scale factor
643 * @param[in] callback The callback for screen shot
645 * @return true if requested successfully, false otherwise
647 virtual bool GetScreenshotAsynchronously(Dali::Rect<int> viewArea, float scaleFactor, ScreenshotCapturedCallback callback) = 0;
650 * @brief Asynchronously request to check if there is a video playing in the given view.
652 * @param[in] callback The callback called after checking if video is playing or not
654 * @return true if requested successfully, false otherwise
656 virtual bool CheckVideoPlayingAsynchronously(VideoPlayingCallback callback) = 0;
659 * @brief Set callback which will be called upon geolocation permission request.
661 * @param[in] callback The callback for requesting geolocation permission
663 virtual void RegisterGeolocationPermissionCallback(GeolocationPermissionCallback callback) = 0;
666 * @brief Update display area.
667 * @param[in] displayArea The display area need be updated.
669 virtual void UpdateDisplayArea(Dali::Rect<int> displayArea) = 0;
672 * @brief Enable video hole.
673 * @param[in] enabled True if enabled, false othewise.
675 virtual void EnableVideoHole(bool enabled) = 0;
678 * @brief Send Hover Events.
679 * @param[in] event The hover event would be sent.
681 virtual bool SendHoverEvent(const HoverEvent& event) = 0;
684 * @brief Send Wheel Events.
685 * @param[in] event The wheel event would be sent.
687 virtual bool SendWheelEvent(const WheelEvent& event) = 0;
690 * @brief Connect to this signal to be notified when page loading is started.
692 * @return A signal object to connect with.
694 virtual WebEnginePageLoadSignalType& PageLoadStartedSignal() = 0;
697 * @brief Connect to this signal to be notified when page loading is in progress.
699 * @return A signal object to connect with.
701 virtual WebEnginePageLoadSignalType& PageLoadInProgressSignal() = 0;
704 * @brief Connect to this signal to be notified when page loading is finished.
706 * @return A signal object to connect with.
708 virtual WebEnginePageLoadSignalType& PageLoadFinishedSignal() = 0;
711 * @brief Connect to this signal to be notified when an error occurs in page loading.
713 * @return A signal object to connect with.
715 virtual WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() = 0;
718 * @brief Connect to this signal to be notified when scroll edge is reached.
720 * @return A signal object to connect with.
722 virtual WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal() = 0;
725 * @brief Connect to this signal to be notified when url is changed.
727 * @return A signal object to connect with.
729 virtual WebEngineUrlChangedSignalType& UrlChangedSignal() = 0;
732 * @brief Connect to this signal to be notified when form repost decision is requested.
734 * @return A signal object to connect with.
736 virtual WebEngineFormRepostDecisionSignalType& FormRepostDecisionSignal() = 0;
739 * @brief Connect to this signal to be notified when frame is rendered.
741 * @return A signal object to connect with.
743 virtual WebEngineFrameRenderedSignalType& FrameRenderedSignal() = 0;
746 * @brief Connects to this signal to be notified when http request need be intercepted.
748 * @return A signal object to connect with.
750 virtual WebEngineRequestInterceptorSignalType& RequestInterceptorSignal() = 0;
753 * @brief Connect to this signal to be notified when console message will be logged.
755 * @return A signal object to connect with.
757 virtual WebEngineConsoleMessageSignalType& ConsoleMessageSignal() = 0;
760 // specialization has to be done in the same namespace
762 struct EnableBitMaskOperators<WebEnginePlugin::FindOption>
764 static const bool ENABLE = true;