1 #ifndef DALI_TOOLKIT_INTERNAL_WEB_VIEW_H
2 #define DALI_TOOLKIT_INTERNAL_WEB_VIEW_H
5 * Copyright (c) 2022 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::GetContext()
78 static Dali::WebEngineContext* GetContext();
81 * @copydoc Dali::Toolkit::WebView::GetCookieManager()
83 static Dali::WebEngineCookieManager* GetCookieManager();
86 * @copydoc Dali::Toolkit::WebView::GetSettings()
88 Dali::Toolkit::WebSettings* GetSettings() const;
91 * @copydoc Dali::Toolkit::WebView::GetBackForwardList()
93 Dali::Toolkit::WebBackForwardList* GetBackForwardList() const;
96 * @copydoc Dali::Toolkit::WebView::GetFavicon()
98 Dali::Toolkit::ImageView GetFavicon() const;
101 * @copydoc Dali::Toolkit::WebView::LoadUrl()
103 void LoadUrl(const std::string& url);
106 * @copydoc Dali::WebEngine::LoadHTMLString()
108 void LoadHtmlString(const std::string& htmlString);
111 * @copydoc Dali::WebEngine::LoadHtmlStringOverrideCurrentEntry()
113 bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl);
116 * @copydoc Dali::WebEngine::LoadContents()
118 bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri);
121 * @copydoc Dali::Toolkit::WebView::Reload()
126 * @copydoc Dali::WebEngine::ReloadWithoutCache()
128 bool ReloadWithoutCache();
131 * @copydoc Dali::Toolkit::WebView::StopLoading()
136 * @copydoc Dali::Toolkit::WebView::StopLoading()
141 * @copydoc Dali::Toolkit::WebView::Resume()
146 * @copydoc Dali::WebEngine::SuspendNetworkLoading()
148 void SuspendNetworkLoading();
151 * @copydoc Dali::WebEngine::ResumeNetworkLoading()
153 void ResumeNetworkLoading();
156 * @copydoc Dali::WebEngine::AddCustomHeader()
158 bool AddCustomHeader(const std::string& name, const std::string& value);
161 * @copydoc Dali::WebEngine::RemoveCustomHeader()
163 bool RemoveCustomHeader(const std::string& name);
166 * @copydoc Dali::WebEngine::StartInspectorServer()
168 uint32_t StartInspectorServer(uint32_t port);
171 * @copydoc Dali::WebEngine::StopInspectorServer()
173 bool StopInspectorServer();
176 * @copydoc Dali::Toolkit::WebView::ScrollBy()
178 void ScrollBy(int32_t deltaX, int32_t deltaY);
181 * @copydoc Dali::WebEngine::ScrollEdgeBy()
183 bool ScrollEdgeBy(int32_t deltaX, int32_t deltaY);
186 * @copydoc Dali::Toolkit::WebView::CanGoForward()
191 * @copydoc Dali::Toolkit::WebView::GoForward()
196 * @copydoc Dali::Toolkit::WebView::CanGoBack()
201 * @copydoc Dali::Toolkit::WebView::GoBack()
206 * @copydoc Dali::Toolkit::WebView::EvaluateJavaScript()
208 void EvaluateJavaScript(const std::string& script, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback resultHandler);
211 * @copydoc Dali::Toolkit::WebView::AddJavaScriptMessageHandler()
213 void AddJavaScriptMessageHandler(const std::string& exposedObjectName, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback handler);
216 * @copydoc Dali::Toolkit::WebView::RegisterJavaScriptAlertCallback()
218 void RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback);
221 * @copydoc Dali::Toolkit::WebView::JavaScriptAlertReply()
223 void JavaScriptAlertReply();
226 * @copydoc Dali::Toolkit::WebView::RegisterJavaScriptConfirmCallback()
228 void RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback);
231 * @copydoc Dali::Toolkit::WebView::JavaScriptConfirmReply()
233 void JavaScriptConfirmReply(bool confirmed);
236 * @copydoc Dali::Toolkit::WebView::RegisterJavaScriptPromptCallback()
238 void RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback);
241 * @copydoc Dali::Toolkit::WebView::JavaScriptPromptReply()
243 void JavaScriptPromptReply(const std::string& result);
246 * @copydoc Dali::Toolkit::WebView::CreateHitTest()
248 std::unique_ptr<Dali::WebEngineHitTest> CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode);
251 * @copydoc Dali::Toolkit::WebView::CreateHitTestAsynchronously()
253 bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback);
256 * @copydoc Dali::Toolkit::WebView::ClearHistory()
261 * @copydoc Dali::Toolkit::WebView::ClearAllTilesResources()
263 void ClearAllTilesResources();
266 * @copydoc Dali::Toolkit::WebView::SetScaleFactor()
268 void SetScaleFactor(float scaleFactor, Dali::Vector2 point);
271 * @copydoc Dali::Toolkit::WebView::GetScaleFactor()
273 float GetScaleFactor() const;
276 * @copydoc Dali::Toolkit::WebView::ActivateAccessibility()
278 void ActivateAccessibility(bool activated);
281 * @copydoc Dali::Toolkit::WebView::HighlightText()
283 bool HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount);
286 * @copydoc Dali::Toolkit::WebView::AddDynamicCertificatePath()
288 void AddDynamicCertificatePath(const std::string& host, const std::string& certPath);
291 * @copydoc Dali::Toolkit::WebView::GetScreenshot()
293 Dali::Toolkit::ImageView GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor);
296 * @copydoc Dali::Toolkit::WebView::GetScreenshotAsynchronously()
298 bool GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback);
301 * @copydoc Dali::Toolkit::WebView::CheckVideoPlayingAsynchronously()
303 bool CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback);
306 * @copydoc Dali::Toolkit::WebView::RegisterGeolocationPermissionCallback()
308 void RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback);
311 * @copydoc Dali::Toolkit::WebView::SetTtsFocus()
313 void SetTtsFocus(bool focused);
316 * @copydoc Dali::Toolkit::WebView::RegisterPageLoadStartedCallback()
318 void RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
321 * @copydoc Dali::Toolkit::WebView::RegisterPageLoadInProgressCallback()
323 void RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
326 * @copydoc Dali::Toolkit::WebView::RegisterPageLoadFinishedCallback()
328 void RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
331 * @copydoc Dali::Toolkit::WebView::RegisterPageLoadErrorCallback()
333 void RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback);
336 * @copydoc Dali::Toolkit::WebView::RegisterScrollEdgeReachedCallback()
338 void RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback);
341 * @copydoc Dali::Toolkit::WebView::RegisterUrlChangedCallback()
343 void RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback);
346 * @copydoc Dali::Toolkit::WebView::RegisterFormRepostDecidedCallback()
348 void RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback);
351 * @copydoc Dali::Toolkit::WebView::RegisterFrameRenderedCallback()
353 void RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback);
356 * @copydoc Dali::Toolkit::WebView::RegisterConsoleMessageReceivedCallback()
358 void RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback);
361 * @copydoc Dali::Toolkit::WebView::RegisterResponsePolicyDecidedCallback()
363 void RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback);
366 * @copydoc Dali::Toolkit::WebView::RegisterNavigationPolicyDecidedCallback()
368 void RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback);
371 * @copydoc Dali::Toolkit::WebView::RegisterCertificateConfirmedCallback()
373 void RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
376 * @copydoc Dali::Toolkit::WebView::RegisterSslCertificateChangedCallback()
378 void RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
381 * @copydoc Dali::Toolkit::WebView::RegisterHttpAuthHandlerCallback()
383 void RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback);
386 * @copydoc Dali::Toolkit::WebView::RegisterContextMenuShownCallback()
388 void RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback);
391 * @copydoc Dali::Toolkit::WebView::RegisterContextMenuHiddenCallback()
393 void RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback);
396 * @copydoc Dali::Toolkit::WebView::GetPlainTextAsynchronously()
398 void GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback);
400 public: // Properties
402 * @brief Called when a property of an object of this type is set.
404 * @param[in] object The object whose property is set.
405 * @param[in] index The property index.
406 * @param[in] value The new property value.
408 static void SetProperty(Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value);
411 * @brief Called to retrieve a property of an object of this type.
413 * @param[in] object The object whose property is to be retrieved.
414 * @param[in] index The property index.
415 * @return The current value of the property.
417 static Dali::Property::Value GetProperty(Dali::BaseObject* object, Dali::Property::Index propertyIndex);
419 private: // From Control
421 * @copydoc Toolkit::Control::OnInitialize()
423 void OnInitialize() override;
426 * @copydoc Toolkit::Internal::Control::CreateAccessibleObject()
428 DevelControl::ControlAccessible* CreateAccessibleObject() override;
431 * @copydoc Toolkit::Control::GetNaturalSize
433 Vector3 GetNaturalSize() override;
436 * @copydoc Toolkit::Control::OnKeyEvent()
438 bool OnKeyEvent(const Dali::KeyEvent& event) override;
441 * @copydoc Toolkit::Control::OnKeyInputFocusGained()
443 void OnKeyInputFocusGained() override;
446 * @copydoc Toolkit::Control::OnKeyInputFocusLost()
448 void OnKeyInputFocusLost() override;
451 * @copydoc Toolkit::Control::OnSceneConnection()
453 void OnSceneConnection(int depth) override;
457 WebView(const WebView& webView);
459 WebView& operator=(const WebView& webView);
462 * @brief Set an absolute scroll of the given view.
463 * @param[in] x The coordinate x of scroll
464 * @param[in] y The coordinate y of scroll
466 void SetScrollPosition(int32_t x, int32_t y);
469 * @brief Get the current scroll position of the given view.
470 * @param[out] x The coordinate x of scroll
471 * @param[out] y The coordinate y of scroll
473 Dali::Vector2 GetScrollPosition() const;
476 * @brief Get the possible scroll size of the given view.
477 * @param[out] width The width of scroll size
478 * @param[out] height The height of scroll size
480 Dali::Vector2 GetScrollSize() const;
483 * @brief Get the last known content's size.
484 * @param[out] width The width of content's size
485 * @param[out] height The height of content's size
487 Dali::Vector2 GetContentSize() const;
490 * @brief Return the title of the Web.
492 * @return The title of web page
494 std::string GetTitle() const;
497 * @brief Set the background color of web page.
498 * @param[in] color The value of background color.
500 void SetDocumentBackgroundColor(Dali::Vector4 color);
503 * @brief Clear tiles when hidden.
505 * @param[in] cleared Whether tiles are cleared or not
507 void ClearTilesWhenHidden(bool cleared);
510 * @brief Set multiplier of cover area of tile.
512 * @param[in] multiplier The multiplier of cover area
514 void SetTileCoverAreaMultiplier(float multiplier);
517 * @brief Enable cursor by client.
518 * @param[in] enabled Whether cursor is enabled or not.
520 void EnableCursorByClient(bool enabled);
523 * @brief Get the selected text.
524 * @return The selected text
526 std::string GetSelectedText() const;
529 * @brief Get url of web page.
530 * @return The string of url
532 std::string GetUrl() const;
535 * @brief Get user agent string.
536 * @return The string value of user agent
538 std::string GetUserAgent() const;
541 * @brief Set user agent string.
542 * @param[in] userAgent The string value of user agent
544 void SetUserAgent(const std::string& userAgent);
547 * @brief Set zoom factor of the current page.
548 * @param[in] zoomFactor a new factor to be set.
550 void SetPageZoomFactor(float zoomFactor);
553 * @brief Query the current zoom factor of the page。
554 * @return The current page zoom factor.
556 float GetPageZoomFactor() const;
559 * @brief Set the current text zoom level。.
560 * @param[in] zoomFactor a new factor to be set.
562 void SetTextZoomFactor(float zoomFactor);
565 * @brief Get the current text zoom level.
566 * @return The current text zoom factor.
568 float GetTextZoomFactor() const;
571 * @brief Get the current load progress of the page.
572 * @return The load progress of the page.
574 float GetLoadProgressPercentage() const;
577 * @brief Request to set the current page's visibility.
578 * @param[in] visible Visible or not.
580 * @return true if succeeded, false otherwise
582 bool SetVisibility(bool visible);
585 * @brief Update display area of web view.
586 * @param[in] source The soource triggers Notification.
588 void UpdateDisplayArea(Dali::PropertyNotification& source);
591 * @brief Enable/Disable video hole for video playing.
592 * @param[in] enabled True if video hole is enabled, false otherwise.
594 void EnableVideoHole(bool enabled);
597 * @brief Enable blend mode.
598 * @param[in] blendEnabled True if turn on blend mode, false otherwise.
600 void EnableBlendMode(bool blendEnabled);
603 * @brief Enable/disable mouse events. The default is enabled.
605 * @param[in] enabled True if mouse events are enabled, false otherwise
607 void EnableMouseEvents(bool enabled);
610 * @brief Enable/disable key events. The default is enabled.
612 * @param[in] enabled True if key events enabled, false otherwise
614 void EnableKeyEvents(bool enabled);
617 * @brief Create image view by pixel data.
618 * @param[in] pixel Pixel data
619 * @return The new image view
621 Dali::Toolkit::ImageView CreateImageView(Dali::PixelData pixel) const;
624 * @brief Signal occurs when the Web View has been touched.
625 * @param[in] actor The Actor Touched
626 * @param[in] touch The Touch Data.
627 * @return Whether to consume event or not.
629 bool OnTouchEvent(Actor actor, const Dali::TouchEvent& touch);
632 * @brief Signal occurs when the Web View has been hovered.
633 * @param[in] actor The Actor Hovered
634 * @param[in] hover The Hover Data.
635 * @return Whether to consume event or not.
637 bool OnHoverEvent(Actor actor, const Dali::HoverEvent& hover);
640 * @brief Signal occurs when the Web View receives wheel event.
641 * @param[in] actor The Actor that receives Wheel event.
642 * @param[in] wheel The Wheel Data.
643 * @return Whether to consume event or not.
645 bool OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel);
648 * @brief Callback function to be called when frame is rendered.
650 void OnFrameRendered();
653 * @brief Callback function to be called when frame is rendered. This is to check initial buffer is ready.
655 void OnInitialFrameRendered();
658 * @brief Callback function to be called when visibility is changed.
659 * @param[in] actor The actor, or child of actor, whose visibility has changed
660 * @param[in] isVisible Whether the actor is now visible or not
661 * @param[in] type, Whether the actor's visible property has changed or a parent's
663 void OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type);
666 * @brief callback for screen shot captured.
667 * @param[in] pixel Pixel data of screen shot.
669 void OnScreenshotCaptured(Dali::PixelData pixel);
672 class WebViewAccessible : public DevelControl::ControlAccessible
675 WebViewAccessible() = delete;
677 WebViewAccessible(Dali::Actor self, Dali::WebEngine& webEngine);
681 * @copydoc Dali::Accessibility::ActorAccessible::DoGetChildren()
683 void DoGetChildren(std::vector<Dali::Accessibility::Accessible*>& children) override;
686 void OnAccessibilityEnabled();
687 void OnAccessibilityDisabled();
688 void SetRemoteChildAddress(Dali::Accessibility::Address address);
690 Dali::Accessibility::ProxyAccessible mRemoteChild;
691 Dali::WebEngine& mWebEngine;
695 Dali::Toolkit::Visual::Base mVisual;
696 Dali::Size mWebViewSize;
697 Dali::WebEngine mWebEngine;
699 std::unique_ptr<Dali::Toolkit::WebSettings> mWebSettings;
700 std::unique_ptr<Dali::Toolkit::WebBackForwardList> mWebBackForwardList;
702 Dali::PropertyNotification mPositionUpdateNotification;
703 Dali::PropertyNotification mSizeUpdateNotification;
704 Dali::PropertyNotification mScaleUpdateNotification;
705 Dali::Rect<int32_t> mWebViewArea;
706 bool mVideoHoleEnabled;
707 bool mMouseEventsEnabled;
708 bool mKeyEventsEnabled;
710 Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback mScreenshotCapturedCallback;
711 Dali::WebEnginePlugin::WebEngineFrameRenderedCallback mFrameRenderedCallback;
714 } // namespace Internal
716 inline Toolkit::Internal::WebView& GetImpl(Toolkit::WebView& handle)
718 DALI_ASSERT_ALWAYS(handle);
719 Dali::RefObject& impl = handle.GetImplementation();
720 return static_cast<Toolkit::Internal::WebView&>(impl);
723 inline const Toolkit::Internal::WebView& GetImpl(const Toolkit::WebView& handle)
725 DALI_ASSERT_ALWAYS(handle);
726 const Dali::RefObject& impl = handle.GetImplementation();
727 return static_cast<const Toolkit::Internal::WebView&>(impl);
730 } // namespace Toolkit
734 #endif // DALI_TOOLKIT_INTERNAL_WEB_VIEW_H