1 #ifndef DALI_TOOLKIT_INTERNAL_WEB_VIEW_H
2 #define DALI_TOOLKIT_INTERNAL_WEB_VIEW_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/actors/actor-devel.h>
23 #include <dali/devel-api/adaptor-framework/web-engine.h>
24 #include <dali/public-api/images/image-operations.h>
25 #include <dali/public-api/object/property-notification.h>
29 #include <dali-toolkit/devel-api/controls/web-view/web-view.h>
30 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
31 #include <dali-toolkit/public-api/controls/control-impl.h>
32 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
40 class WebBackForwardList;
42 class WebCookieManager;
48 class WebView : public Control
53 WebView(const std::string& locale, const std::string& timezoneId);
55 WebView(int argc, char** argv);
61 * @copydoc Dali::Toolkit::WebView::New()
63 static Toolkit::WebView New();
66 * @copydoc Dali::Toolkit::WebView::New( const std::string&, const std::string& )
68 static Toolkit::WebView New(const std::string& locale, const std::string& timezoneId);
71 * @copydoc Dali::Toolkit::WebView::New( int, char** )
73 static Toolkit::WebView New(int argc, char** argv);
76 * @brief Get settings of WebEngine.
78 Dali::Toolkit::WebSettings* GetSettings() const;
81 * @brief Get context of WebEngine.
83 Dali::Toolkit::WebContext* GetContext() const;
86 * @brief Get cookie manager of WebEngine.
88 Dali::Toolkit::WebCookieManager* GetCookieManager() const;
91 * @brief Get WebBackForwardList of WebEngine.
93 Dali::Toolkit::WebBackForwardList* GetBackForwardList() const;
96 * @brief Get Favicon of web page.
98 * @return Handle to a fav icon
100 Dali::Toolkit::ImageView& GetFavicon();
103 * @copydoc Dali::Toolkit::WebView::LoadUrl()
105 void LoadUrl(const std::string& url);
108 * @copydoc Dali::WebEngine::LoadHTMLString()
110 void LoadHtmlString(const std::string& htmlString);
113 * @copydoc Dali::WebEngine::LoadHtmlStringOverrideCurrentEntry()
115 bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl);
118 * @copydoc Dali::WebEngine::LoadContents()
120 bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri);
123 * @copydoc Dali::Toolkit::WebView::Reload()
128 * @copydoc Dali::WebEngine::ReloadWithoutCache()
130 bool ReloadWithoutCache();
133 * @copydoc Dali::Toolkit::WebView::StopLoading()
138 * @copydoc Dali::Toolkit::WebView::StopLoading()
143 * @copydoc Dali::Toolkit::WebView::Resume()
148 * @copydoc Dali::WebEngine::SuspendNetworkLoading()
150 void SuspendNetworkLoading();
153 * @copydoc Dali::WebEngine::ResumeNetworkLoading()
155 void ResumeNetworkLoading();
158 * @copydoc Dali::WebEngine::AddCustomHeader()
160 bool AddCustomHeader(const std::string& name, const std::string& value);
163 * @copydoc Dali::WebEngine::RemoveCustomHeader()
165 bool RemoveCustomHeader(const std::string& name);
168 * @copydoc Dali::WebEngine::StartInspectorServer()
170 uint32_t StartInspectorServer(uint32_t port);
173 * @copydoc Dali::WebEngine::StopInspectorServer()
175 bool StopInspectorServer();
178 * @copydoc Dali::Toolkit::WebView::ScrollBy()
180 void ScrollBy(int deltaX, int deltaY);
183 * @copydoc Dali::WebEngine::ScrollEdgeBy()
185 bool ScrollEdgeBy(int deltaX, int deltaY);
188 * @copydoc Dali::Toolkit::WebView::CanGoForward()
193 * @copydoc Dali::Toolkit::WebView::GoForward()
198 * @copydoc Dali::Toolkit::WebView::CanGoBack()
203 * @copydoc Dali::Toolkit::WebView::GoBack()
208 * @copydoc Dali::Toolkit::WebView::EvaluateJavaScript()
210 void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler);
213 * @copydoc Dali::Toolkit::WebView::AddJavaScriptMessageHandler()
215 void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
218 * @copydoc Dali::Toolkit::WebView::RegisterJavaScriptAlertCallback()
220 void RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback);
223 * @copydoc Dali::Toolkit::WebView::JavaScriptAlertReply()
225 void JavaScriptAlertReply();
228 * @copydoc Dali::Toolkit::WebView::RegisterJavaScriptConfirmCallback()
230 void RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback);
233 * @copydoc Dali::Toolkit::WebView::JavaScriptConfirmReply()
235 void JavaScriptConfirmReply(bool confirmed);
238 * @copydoc Dali::Toolkit::WebView::RegisterJavaScriptPromptCallback()
240 void RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback);
243 * @copydoc Dali::Toolkit::WebView::JavaScriptPromptReply()
245 void JavaScriptPromptReply(const std::string& result);
248 * @copydoc Dali::Toolkit::WebView::ClearHistory()
253 * @copydoc Dali::Toolkit::WebView::ClearAllTilesResources()
255 void ClearAllTilesResources();
258 * @copydoc Dali::Toolkit::WebView::SetScaleFactor()
260 void SetScaleFactor(float scaleFactor, Dali::Vector2 point);
263 * @copydoc Dali::Toolkit::WebView::GetScaleFactor()
265 float GetScaleFactor() const;
268 * @copydoc Dali::Toolkit::WebView::ActivateAccessibility()
270 void ActivateAccessibility(bool activated);
273 * @copydoc Dali::Toolkit::WebView::HighlightText()
275 bool HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount);
278 * @copydoc Dali::Toolkit::WebView::AddDynamicCertificatePath()
280 void AddDynamicCertificatePath(const std::string& host, const std::string& certPath);
283 * @copydoc Dali::Toolkit::WebView::GetScreenshot()
285 Dali::Toolkit::ImageView GetScreenshot(Dali::Rect<int> viewArea, float scaleFactor);
288 * @copydoc Dali::Toolkit::WebView::GetScreenshotAsynchronously()
290 bool GetScreenshotAsynchronously(Dali::Rect<int> viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback);
293 * @copydoc Dali::Toolkit::WebView::CheckVideoPlayingAsynchronously()
295 bool CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback);
298 * @copydoc Dali::Toolkit::WebView::RegisterGeolocationPermissionCallback()
300 void RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback);
303 * @copydoc Dali::Toolkit::WebView::PageLoadStartedSignal()
305 Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadStartedSignal();
308 * @copydoc Dali::Toolkit::WebView::PageLoadInProgressSignal()
310 Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadInProgressSignal();
313 * @copydoc Dali::Toolkit::WebView::PageLoadFinishedSignal()
315 Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadFinishedSignal();
318 * @copydoc Dali::Toolkit::WebView::PageLoadErrorSignal()
320 Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType& PageLoadErrorSignal();
323 * @copydoc Dali::Toolkit::WebView::ScrollEdgeReachedSignal()
325 Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
328 * @copydoc Dali::Toolkit::WebView::UrlChangedSignal()
330 Dali::Toolkit::WebView::WebViewUrlChangedSignalType& UrlChangedSignal();
333 * @copydoc Dali::Toolkit::WebView::FormRepostDecisionSignal()
335 Dali::Toolkit::WebView::WebViewFormRepostDecisionSignalType& FormRepostDecisionSignal();
338 * @copydoc Dali::Toolkit::WebView::FrameRenderedSignal()
340 Dali::Toolkit::WebView::WebViewFrameRenderedSignalType& FrameRenderedSignal();
343 * @copydoc Dali::Toolkit::WebView::RequestInterceptorSignal()
345 Dali::Toolkit::WebView::WebViewRequestInterceptorSignalType& RequestInterceptorSignal();
347 public: // Properties
349 * @brief Called when a property of an object of this type is set.
351 * @param[in] object The object whose property is set.
352 * @param[in] index The property index.
353 * @param[in] value The new property value.
355 static void SetProperty(Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value);
358 * @brief Called to retrieve a property of an object of this type.
360 * @param[in] object The object whose property is to be retrieved.
361 * @param[in] index The property index.
362 * @return The current value of the property.
364 static Dali::Property::Value GetProperty(Dali::BaseObject* object, Dali::Property::Index propertyIndex);
367 * Connects a callback function with the object's signals.
368 * @param[in] object The object providing the signal.
369 * @param[in] tracker Used to disconnect the signal.
370 * @param[in] signalName The signal to connect to.
371 * @param[in] functor A newly allocated FunctorDelegate.
372 * @return True if the signal was connected.
373 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the c
375 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
377 private: // From Control
379 * @copydoc Toolkit::Control::OnInitialize()
381 void OnInitialize() override;
384 * @copydoc Toolkit::Control::GetNaturalSize
386 Vector3 GetNaturalSize() override;
389 * @copydoc Toolkit::Control::OnKeyEvent()
391 bool OnKeyEvent(const Dali::KeyEvent& event) override;
394 * @copydoc Toolkit::Control::OnKeyInputFocusGained()
396 void OnKeyInputFocusGained() override;
399 * @copydoc Toolkit::Control::OnKeyInputFocusLost()
401 void OnKeyInputFocusLost() override;
404 * @copydoc Toolkit::Control::OnSceneConnection()
406 void OnSceneConnection(int depth) override;
410 WebView(const WebView& webView);
412 WebView& operator=(const WebView& webView);
415 * @brief Sets an absolute scroll of the given view.
416 * @param[in] x The coordinate x of scroll
417 * @param[in] y The coordinate y of scroll
419 void SetScrollPosition(int x, int y);
422 * @brief Gets the current scroll position of the given view.
423 * @param[out] x The coordinate x of scroll
424 * @param[out] y The coordinate y of scroll
426 Dali::Vector2 GetScrollPosition() const;
429 * @brief Gets the possible scroll size of the given view.
430 * @param[out] width The width of scroll size
431 * @param[out] height The height of scroll size
433 Dali::Vector2 GetScrollSize() const;
436 * @brief Gets the last known content's size.
437 * @param[out] width The width of content's size
438 * @param[out] height The height of content's size
440 Dali::Vector2 GetContentSize() const;
443 * @brief Returns the title of the Web.
445 * @return The title of web page
447 std::string GetTitle() const;
450 * @brief Sets the background color of web page.
451 * @param[in] color The value of background color.
453 void SetDocumentBackgroundColor(Dali::Vector4 color);
456 * @brief Clears tiles when hidden.
458 * @param[in] cleared Whether tiles are cleared or not
460 void ClearTilesWhenHidden(bool cleared);
463 * @brief Sets multiplier of cover area of tile.
465 * @param[in] multiplier The multiplier of cover area
467 void SetTileCoverAreaMultiplier(float multiplier);
470 * @brief Enables cursor by client.
471 * @param[in] enabled Whether cursor is enabled or not.
473 void EnableCursorByClient(bool enabled);
476 * @brief Gets the selected text.
477 * @return The selected text
479 std::string GetSelectedText() const;
482 * @brief Get user agent string.
483 * @return The string value of user agent
485 const std::string& GetUserAgent() const;
488 * @brief Set user agent string.
489 * @param[in] userAgent The string value of user agent
491 void SetUserAgent(const std::string& userAgent);
494 * @brief Sets zoom factor of the current page.
495 * @param[in] zoomFactor a new factor to be set.
497 void SetPageZoomFactor(float zoomFactor);
500 * @brief Queries the current zoom factor of the page。
501 * @return The current page zoom factor.
503 float GetPageZoomFactor() const;
506 * @brief Sets the current text zoom level。.
507 * @param[in] zoomFactor a new factor to be set.
509 void SetTextZoomFactor(float zoomFactor);
512 * @brief Gets the current text zoom level.
513 * @return The current text zoom factor.
515 float GetTextZoomFactor() const;
518 * @brief Gets the current load progress of the page.
519 * @return The load progress of the page.
521 float GetLoadProgressPercentage() const;
524 * @brief Request to set the current page's visibility.
525 * @param[in] visible Visible or not.
527 * @return true if succeeded, false otherwise
529 bool SetVisibility(bool visible);
532 * @brief Updates display area of web view.
533 * @param[in] source The soource triggers Notification.
535 void UpdateDisplayArea(Dali::PropertyNotification& source);
538 * @brief Enable/Disable video hole for video playing.
539 * @param[in] enabled True if video hole is enabled, false otherwise.
541 void EnableVideoHole(bool enabled);
544 * @brief Enable blend mode.
545 * @param[in] blendEnabled True if turn on blend mode, false otherwise.
547 void EnableBlendMode(bool blendEnabled);
550 * @brief Enables/disables mouse events. The default is enabled.
552 * @param[in] enabled True if mouse events are enabled, false otherwise
554 void EnableMouseEvents(bool enabled);
557 * @brief Enables/disables key events. The default is enabled.
559 * @param[in] enabled True if key events enabled, false otherwise
561 void EnableKeyEvents(bool enabled);
564 * @brief Create image view by pixel data.
565 * @param[in] pixel Pixel data
566 * @return The new image view
568 Dali::Toolkit::ImageView CreateImageView(Dali::PixelData pixel);
571 * @brief Callback function to be called when page load started.
572 * @param[in] url The url currently being loaded
574 void OnPageLoadStarted(const std::string& url);
577 * @brief Callback function to be called when page is loading in progress.
578 * @param[in] url The url currently being loaded
580 void OnPageLoadInProgress(const std::string& url);
583 * @brief Callback function to be called when page load finished.
584 * @param[in] url The url currently being loaded
586 void OnPageLoadFinished(const std::string& url);
589 * @brief Callback function to be called when there is an error in page loading.
590 * @param[in] url The url currently being loaded
591 * @param[in] errorCode The error code
593 void OnPageLoadError(const std::string& url, int errorCode);
596 * @brief Callback function to be called when scroll edge is reached.
597 * @param[in] e The scroll edge reached.
599 void OnScrollEdgeReached(Dali::WebEnginePlugin::ScrollEdge edge);
602 * @brief Callback function to be called when url is changed.
603 * @param[in] url The url currently being loaded
605 void OnUrlChanged(const std::string& url);
608 * Signal occurs when the Web View has been touched.
609 * @param[in] actor The Actor Touched
610 * @param[in] touch The Touch Data.
611 * @return Whether to consume event or not.
613 bool OnTouchEvent(Actor actor, const Dali::TouchEvent& touch);
616 * Signal occurs when the Web View has been hovered.
617 * @param[in] actor The Actor Hovered
618 * @param[in] hover The Hover Data.
619 * @return Whether to consume event or not.
621 bool OnHoverEvent(Actor actor, const Dali::HoverEvent& hover);
624 * Signal occurs when the Web View receives wheel event.
625 * @param[in] actor The Actor that receives Wheel event.
626 * @param[in] wheel The Wheel Data.
627 * @return Whether to consume event or not.
629 bool OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel);
632 * @brief Callback function to be called when form repost decision need be checked.
633 * @param[in] decision The new decision for form repost
635 void OnFormRepostDecision(std::shared_ptr<Dali::WebEngineFormRepostDecision> decision);
638 * @brief Callback function to be called when frame is rendered.
640 void OnFrameRendered();
643 * @brief Callback function to be called when visibility is changed.
644 * @param[in] actor The actor, or child of actor, whose visibility has changed
645 * @param[in] isVisible Whether the actor is now visible or not
646 * @param[in] type, Whether the actor's visible property has changed or a parent's
648 void OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type);
651 * @brief callback for screen shot captured.
652 * @param[in] pixel Pixel data of screen shot.
654 void OnScreenshotCaptured(Dali::PixelData pixel);
657 * @brief Callback function to be called when http request need be intercepted.
658 * @param [in] request The http request interceptor.
660 void OnInterceptRequest(std::shared_ptr<Dali::WebEngineRequestInterceptor> interceptor);
664 Dali::Toolkit::Visual::Base mVisual;
665 Dali::Size mWebViewSize;
666 Dali::WebEngine mWebEngine;
668 Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadStartedSignal;
669 Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadInProgressSignal;
670 Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadFinishedSignal;
671 Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType mPageLoadErrorSignal;
672 Dali::Toolkit::WebView::WebViewUrlChangedSignalType mUrlChangedSignal;
673 Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType mScrollEdgeReachedSignal;
674 Dali::Toolkit::WebView::WebViewFormRepostDecisionSignalType mFormRepostDecisionSignal;
675 Dali::Toolkit::WebView::WebViewFrameRenderedSignalType mFrameRenderedSignal;
676 Dali::Toolkit::WebView::WebViewRequestInterceptorSignalType mRequestInterceptorSignal;
678 std::unique_ptr<Dali::Toolkit::WebContext> mWebContext;
679 std::unique_ptr<Dali::Toolkit::WebCookieManager> mWebCookieManager;
680 std::unique_ptr<Dali::Toolkit::WebSettings> mWebSettings;
681 std::unique_ptr<Dali::Toolkit::WebBackForwardList> mWebBackForwardList;
683 Dali::Toolkit::ImageView mFaviconView;
685 Dali::PropertyNotification mPositionUpdateNotification;
686 Dali::PropertyNotification mSizeUpdateNotification;
687 Dali::PropertyNotification mScaleUpdateNotification;
688 bool mVideoHoleEnabled;
689 Dali::Rect<int> mWebViewArea;
690 bool mMouseEventsEnabled;
691 bool mKeyEventsEnabled;
693 Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback mScreenshotCapturedCallback;
696 } // namespace Internal
698 inline Toolkit::Internal::WebView& GetImpl(Toolkit::WebView& handle)
700 DALI_ASSERT_ALWAYS(handle);
701 Dali::RefObject& impl = handle.GetImplementation();
702 return static_cast<Toolkit::Internal::WebView&>(impl);
705 inline const Toolkit::Internal::WebView& GetImpl(const Toolkit::WebView& handle)
707 DALI_ASSERT_ALWAYS(handle);
708 const Dali::RefObject& impl = handle.GetImplementation();
709 return static_cast<const Toolkit::Internal::WebView&>(impl);
712 } // namespace Toolkit
716 #endif // DALI_TOOLKIT_INTERNAL_WEB_VIEW_H