1 #ifndef DALI_TOOLKIT_INTERNAL_WEB_VIEW_H
2 #define DALI_TOOLKIT_INTERNAL_WEB_VIEW_H
5 * Copyright (c) 2023 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/proxy-accessible.h>
24 #include <dali/devel-api/adaptor-framework/web-engine/web-engine.h>
25 #include <dali/public-api/images/image-operations.h>
26 #include <dali/public-api/object/property-notification.h>
30 #include <dali-toolkit/devel-api/controls/control-accessible.h>
31 #include <dali-toolkit/devel-api/controls/web-view/web-view.h>
32 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
33 #include <dali-toolkit/public-api/controls/control-impl.h>
34 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
42 class WebBackForwardList;
48 class WebView : public Control
53 WebView(const std::string& locale, const std::string& timezoneId);
55 WebView(uint32_t 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( uint32_t, char** )
73 static Toolkit::WebView New(uint32_t argc, char** argv);
76 * @copydoc Dali::Toolkit::WebView::FindWebView()
78 static Toolkit::WebView FindWebView(Dali::WebEnginePlugin* plugin);
81 * @copydoc Dali::Toolkit::WebView::GetContext()
83 static Dali::WebEngineContext* GetContext();
86 * @copydoc Dali::Toolkit::WebView::GetCookieManager()
88 static Dali::WebEngineCookieManager* GetCookieManager();
91 * @copydoc Dali::Toolkit::WebView::GetSettings()
93 Dali::Toolkit::WebSettings* GetSettings() const;
96 * @copydoc Dali::Toolkit::WebView::GetBackForwardList()
98 Dali::Toolkit::WebBackForwardList* GetBackForwardList() const;
101 * @copydoc Dali::Toolkit::WebView::GetPlugin()
103 Dali::WebEnginePlugin* GetPlugin() const;
106 * @copydoc Dali::Toolkit::WebView::GetFavicon()
108 Dali::Toolkit::ImageView GetFavicon() const;
111 * @copydoc Dali::Toolkit::WebView::LoadUrl()
113 void LoadUrl(const std::string& url);
116 * @copydoc Dali::WebEngine::LoadHTMLString()
118 void LoadHtmlString(const std::string& htmlString);
121 * @copydoc Dali::WebEngine::LoadHtmlStringOverrideCurrentEntry()
123 bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl);
126 * @copydoc Dali::WebEngine::LoadContents()
128 bool LoadContents(const int8_t* contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri);
131 * @copydoc Dali::Toolkit::WebView::Reload()
136 * @copydoc Dali::WebEngine::ReloadWithoutCache()
138 bool ReloadWithoutCache();
141 * @copydoc Dali::Toolkit::WebView::StopLoading()
146 * @copydoc Dali::Toolkit::WebView::StopLoading()
151 * @copydoc Dali::Toolkit::WebView::Resume()
156 * @copydoc Dali::WebEngine::SuspendNetworkLoading()
158 void SuspendNetworkLoading();
161 * @copydoc Dali::WebEngine::ResumeNetworkLoading()
163 void ResumeNetworkLoading();
166 * @copydoc Dali::WebEngine::AddCustomHeader()
168 bool AddCustomHeader(const std::string& name, const std::string& value);
171 * @copydoc Dali::WebEngine::RemoveCustomHeader()
173 bool RemoveCustomHeader(const std::string& name);
176 * @copydoc Dali::WebEngine::StartInspectorServer()
178 uint32_t StartInspectorServer(uint32_t port);
181 * @copydoc Dali::WebEngine::StopInspectorServer()
183 bool StopInspectorServer();
186 * @copydoc Dali::Toolkit::WebView::ScrollBy()
188 void ScrollBy(int32_t deltaX, int32_t deltaY);
191 * @copydoc Dali::WebEngine::ScrollEdgeBy()
193 bool ScrollEdgeBy(int32_t deltaX, int32_t deltaY);
196 * @copydoc Dali::Toolkit::WebView::CanGoForward()
201 * @copydoc Dali::Toolkit::WebView::GoForward()
206 * @copydoc Dali::Toolkit::WebView::CanGoBack()
211 * @copydoc Dali::Toolkit::WebView::GoBack()
216 * @copydoc Dali::Toolkit::WebView::EvaluateJavaScript()
218 void EvaluateJavaScript(const std::string& script, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback resultHandler);
221 * @copydoc Dali::Toolkit::WebView::AddJavaScriptMessageHandler()
223 void AddJavaScriptMessageHandler(const std::string& exposedObjectName, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback handler);
226 * @copydoc Dali::Toolkit::WebView::RegisterJavaScriptAlertCallback()
228 void RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback);
231 * @copydoc Dali::Toolkit::WebView::JavaScriptAlertReply()
233 void JavaScriptAlertReply();
236 * @copydoc Dali::Toolkit::WebView::RegisterJavaScriptConfirmCallback()
238 void RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback);
241 * @copydoc Dali::Toolkit::WebView::JavaScriptConfirmReply()
243 void JavaScriptConfirmReply(bool confirmed);
246 * @copydoc Dali::Toolkit::WebView::RegisterJavaScriptPromptCallback()
248 void RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback);
251 * @copydoc Dali::Toolkit::WebView::JavaScriptPromptReply()
253 void JavaScriptPromptReply(const std::string& result);
256 * @copydoc Dali::Toolkit::WebView::CreateHitTest()
258 std::unique_ptr<Dali::WebEngineHitTest> CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode);
261 * @copydoc Dali::Toolkit::WebView::CreateHitTestAsynchronously()
263 bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback);
266 * @copydoc Dali::Toolkit::WebView::ClearHistory()
271 * @copydoc Dali::Toolkit::WebView::ClearAllTilesResources()
273 void ClearAllTilesResources();
276 * @copydoc Dali::Toolkit::WebView::SetScaleFactor()
278 void SetScaleFactor(float scaleFactor, Dali::Vector2 point);
281 * @copydoc Dali::Toolkit::WebView::GetScaleFactor()
283 float GetScaleFactor() const;
286 * @copydoc Dali::Toolkit::WebView::ActivateAccessibility()
288 void ActivateAccessibility(bool activated);
291 * @copydoc Dali::Toolkit::WebView::HighlightText()
293 bool HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount);
296 * @copydoc Dali::Toolkit::WebView::AddDynamicCertificatePath()
298 void AddDynamicCertificatePath(const std::string& host, const std::string& certPath);
301 * @copydoc Dali::Toolkit::WebView::GetScreenshot()
303 Dali::Toolkit::ImageView GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor);
306 * @copydoc Dali::Toolkit::WebView::GetScreenshotAsynchronously()
308 bool GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback);
311 * @copydoc Dali::Toolkit::WebView::CheckVideoPlayingAsynchronously()
313 bool CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback);
316 * @copydoc Dali::Toolkit::WebView::RegisterGeolocationPermissionCallback()
318 void RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback);
321 * @copydoc Dali::Toolkit::WebView::SetTtsFocus()
323 void SetTtsFocus(bool focused);
326 * @copydoc Dali::Toolkit::WebView::RegisterPageLoadStartedCallback()
328 void RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
331 * @copydoc Dali::Toolkit::WebView::RegisterPageLoadInProgressCallback()
333 void RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
336 * @copydoc Dali::Toolkit::WebView::RegisterPageLoadFinishedCallback()
338 void RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
341 * @copydoc Dali::Toolkit::WebView::RegisterPageLoadErrorCallback()
343 void RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback);
346 * @copydoc Dali::Toolkit::WebView::RegisterScrollEdgeReachedCallback()
348 void RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback);
351 * @copydoc Dali::Toolkit::WebView::RegisterUrlChangedCallback()
353 void RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback);
356 * @copydoc Dali::Toolkit::WebView::RegisterFormRepostDecidedCallback()
358 void RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback);
361 * @copydoc Dali::Toolkit::WebView::RegisterFrameRenderedCallback()
363 void RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback);
366 * @copydoc Dali::Toolkit::WebView::RegisterConsoleMessageReceivedCallback()
368 void RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback);
371 * @copydoc Dali::Toolkit::WebView::RegisterResponsePolicyDecidedCallback()
373 void RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback);
376 * @copydoc Dali::Toolkit::WebView::RegisterNavigationPolicyDecidedCallback()
378 void RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback);
381 * @copydoc Dali::Toolkit::WebView::RegisterNewWindowCreatedCallback()
383 void RegisterNewWindowCreatedCallback(Dali::WebEnginePlugin::WebEngineNewWindowCreatedCallback callback);
386 * @copydoc Dali::Toolkit::WebView::RegisterCertificateConfirmedCallback()
388 void RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
391 * @copydoc Dali::Toolkit::WebView::RegisterSslCertificateChangedCallback()
393 void RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
396 * @copydoc Dali::Toolkit::WebView::RegisterHttpAuthHandlerCallback()
398 void RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback);
401 * @copydoc Dali::Toolkit::WebView::RegisterContextMenuShownCallback()
403 void RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback);
406 * @copydoc Dali::Toolkit::WebView::RegisterContextMenuHiddenCallback()
408 void RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback);
411 * @copydoc Dali::Toolkit::WebView::GetPlainTextAsynchronously()
413 void GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback);
415 public: // Properties
417 * @brief Called when a property of an object of this type is set.
419 * @param[in] object The object whose property is set.
420 * @param[in] index The property index.
421 * @param[in] value The new property value.
423 static void SetProperty(Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value);
426 * @brief Called to retrieve a property of an object of this type.
428 * @param[in] object The object whose property is to be retrieved.
429 * @param[in] index The property index.
430 * @return The current value of the property.
432 static Dali::Property::Value GetProperty(Dali::BaseObject* object, Dali::Property::Index propertyIndex);
434 private: // From Control
436 * @copydoc Toolkit::Control::OnInitialize()
438 void OnInitialize() override;
441 * @copydoc Toolkit::Internal::Control::CreateAccessibleObject()
443 DevelControl::ControlAccessible* CreateAccessibleObject() override;
446 * @copydoc Toolkit::Internal::Control::OnRelayout()
448 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
451 * @copydoc Toolkit::Control::GetNaturalSize
453 Vector3 GetNaturalSize() override;
456 * @copydoc Toolkit::Control::OnKeyEvent()
458 bool OnKeyEvent(const Dali::KeyEvent& event) override;
461 * @copydoc Toolkit::Control::OnKeyInputFocusGained()
463 void OnKeyInputFocusGained() override;
466 * @copydoc Toolkit::Control::OnKeyInputFocusLost()
468 void OnKeyInputFocusLost() override;
471 * @copydoc Toolkit::Control::OnSceneConnection()
473 void OnSceneConnection(int depth) override;
477 WebView(const WebView& webView);
479 WebView& operator=(const WebView& webView);
482 * @brief Set an absolute scroll of the given view.
483 * @param[in] x The coordinate x of scroll
484 * @param[in] y The coordinate y of scroll
486 void SetScrollPosition(int32_t x, int32_t y);
489 * @brief Get the current scroll position of the given view.
490 * @param[out] x The coordinate x of scroll
491 * @param[out] y The coordinate y of scroll
493 Dali::Vector2 GetScrollPosition() const;
496 * @brief Get the possible scroll size of the given view.
497 * @param[out] width The width of scroll size
498 * @param[out] height The height of scroll size
500 Dali::Vector2 GetScrollSize() const;
503 * @brief Get the last known content's size.
504 * @param[out] width The width of content's size
505 * @param[out] height The height of content's size
507 Dali::Vector2 GetContentSize() const;
510 * @brief Return the title of the Web.
512 * @return The title of web page
514 std::string GetTitle() const;
517 * @brief Set the background color of web page.
518 * @param[in] color The value of background color.
520 void SetDocumentBackgroundColor(Dali::Vector4 color);
523 * @brief Clear tiles when hidden.
525 * @param[in] cleared Whether tiles are cleared or not
527 void ClearTilesWhenHidden(bool cleared);
530 * @brief Set multiplier of cover area of tile.
532 * @param[in] multiplier The multiplier of cover area
534 void SetTileCoverAreaMultiplier(float multiplier);
537 * @brief Enable cursor by client.
538 * @param[in] enabled Whether cursor is enabled or not.
540 void EnableCursorByClient(bool enabled);
543 * @brief Get the selected text.
544 * @return The selected text
546 std::string GetSelectedText() const;
549 * @brief Get url of web page.
550 * @return The string of url
552 std::string GetUrl() const;
555 * @brief Get user agent string.
556 * @return The string value of user agent
558 std::string GetUserAgent() const;
561 * @brief Set user agent string.
562 * @param[in] userAgent The string value of user agent
564 void SetUserAgent(const std::string& userAgent);
567 * @brief Set zoom factor of the current page.
568 * @param[in] zoomFactor a new factor to be set.
570 void SetPageZoomFactor(float zoomFactor);
573 * @brief Query the current zoom factor of the page。
574 * @return The current page zoom factor.
576 float GetPageZoomFactor() const;
579 * @brief Set the current text zoom level。.
580 * @param[in] zoomFactor a new factor to be set.
582 void SetTextZoomFactor(float zoomFactor);
585 * @brief Get the current text zoom level.
586 * @return The current text zoom factor.
588 float GetTextZoomFactor() const;
591 * @brief Get the current load progress of the page.
592 * @return The load progress of the page.
594 float GetLoadProgressPercentage() const;
597 * @brief Request to set the current page's visibility.
598 * @param[in] visible Visible or not.
600 * @return true if succeeded, false otherwise
602 bool SetVisibility(bool visible);
605 * @brief Enable/Disable video hole for video playing.
606 * @param[in] enabled True if video hole is enabled, false otherwise.
608 void EnableVideoHole(bool enabled);
611 * @brief Enable blend mode.
612 * @param[in] blendEnabled True if turn on blend mode, false otherwise.
614 void EnableBlendMode(bool blendEnabled);
617 * @brief Enable/disable mouse events. The default is enabled.
619 * @param[in] enabled True if mouse events are enabled, false otherwise
621 void EnableMouseEvents(bool enabled);
624 * @brief Enable/disable key events. The default is enabled.
626 * @param[in] enabled True if key events enabled, false otherwise
628 void EnableKeyEvents(bool enabled);
631 * @brief Create image view by pixel data.
632 * @param[in] pixel Pixel data
633 * @return The new image view
635 Dali::Toolkit::ImageView CreateImageView(Dali::PixelData pixel) const;
638 * @brief Signal occurs when the Web View has been touched.
639 * @param[in] actor The Actor Touched
640 * @param[in] touch The Touch Data.
641 * @return Whether to consume event or not.
643 bool OnTouchEvent(Actor actor, const Dali::TouchEvent& touch);
646 * @brief Signal occurs when the Web View has been hovered.
647 * @param[in] actor The Actor Hovered
648 * @param[in] hover The Hover Data.
649 * @return Whether to consume event or not.
651 bool OnHoverEvent(Actor actor, const Dali::HoverEvent& hover);
654 * @brief Signal occurs when the Web View receives wheel event.
655 * @param[in] actor The Actor that receives Wheel event.
656 * @param[in] wheel The Wheel Data.
657 * @return Whether to consume event or not.
659 bool OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel);
662 * @brief Callback function to be called when frame is rendered.
664 void OnFrameRendered();
667 * @brief Callback for updating display area of web view.
668 * @param[in] source The soource triggers Notification.
670 void OnDisplayAreaUpdated(Dali::PropertyNotification& source);
673 * @brief Callback function to be called when visibility is changed.
674 * @param[in] actor The actor, or child of actor, whose visibility has changed
675 * @param[in] isVisible Whether the actor is now visible or not
676 * @param[in] type, Whether the actor's visible property has changed or a parent's
678 void OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type);
681 * @brief callback for screen shot captured.
682 * @param[in] pixel Pixel data of screen shot.
684 void OnScreenshotCaptured(Dali::PixelData pixel);
687 * @brief Set DisplayArea by input value.
688 * It will send changes area infomations to webengine internally.
690 * @param[in] displayArea The display area for current webview want to show.
692 void SetDisplayArea(const Dali::Rect<int32_t>& displayArea);
695 class WebViewAccessible : public DevelControl::ControlAccessible
698 WebViewAccessible() = delete;
700 WebViewAccessible(Dali::Actor self, Dali::WebEngine& webEngine);
704 * @copydoc Dali::Accessibility::Accessible::GetAttributes()
706 Dali::Accessibility::Attributes GetAttributes() const override;
709 * @copydoc Dali::Accessibility::ActorAccessible::DoGetChildren()
711 void DoGetChildren(std::vector<Dali::Accessibility::Accessible*>& children) override;
714 void OnAccessibilityEnabled();
715 void OnAccessibilityDisabled();
716 void SetRemoteChildAddress(Dali::Accessibility::Address address);
718 Dali::Accessibility::ProxyAccessible mRemoteChild;
719 Dali::WebEngine& mWebEngine;
723 Dali::Toolkit::Visual::Base mVisual;
724 Dali::Size mWebViewSize;
725 Dali::WebEngine mWebEngine;
727 uint32_t mLastRenderedNativeImageWidth;
728 uint32_t mLastRenderedNativeImageHeight;
730 std::unique_ptr<Dali::Toolkit::WebSettings> mWebSettings;
731 std::unique_ptr<Dali::Toolkit::WebBackForwardList> mWebBackForwardList;
733 Dali::PropertyNotification mPositionUpdateNotification;
734 Dali::PropertyNotification mSizeUpdateNotification;
735 Dali::PropertyNotification mScaleUpdateNotification;
736 Dali::Rect<int32_t> mWebViewArea;
737 bool mVideoHoleEnabled;
738 bool mMouseEventsEnabled;
739 bool mKeyEventsEnabled;
741 bool mVisualChangeRequired;
743 Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback mScreenshotCapturedCallback;
744 Dali::WebEnginePlugin::WebEngineFrameRenderedCallback mFrameRenderedCallback;
747 } // namespace Internal
749 inline Toolkit::Internal::WebView& GetImpl(Toolkit::WebView& handle)
751 DALI_ASSERT_ALWAYS(handle);
752 Dali::RefObject& impl = handle.GetImplementation();
753 return static_cast<Toolkit::Internal::WebView&>(impl);
756 inline const Toolkit::Internal::WebView& GetImpl(const Toolkit::WebView& handle)
758 DALI_ASSERT_ALWAYS(handle);
759 const Dali::RefObject& impl = handle.GetImplementation();
760 return static_cast<const Toolkit::Internal::WebView&>(impl);
763 } // namespace Toolkit
767 #endif // DALI_TOOLKIT_INTERNAL_WEB_VIEW_H