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/proxy-accessible.h>
24 #include <dali/devel-api/adaptor-framework/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;
44 class WebCookieManager;
50 class WebView : public Control
55 WebView(const std::string& locale, const std::string& timezoneId);
57 WebView(uint32_t argc, char** argv);
63 * @copydoc Dali::Toolkit::WebView::New()
65 static Toolkit::WebView New();
68 * @copydoc Dali::Toolkit::WebView::New( const std::string&, const std::string& )
70 static Toolkit::WebView New(const std::string& locale, const std::string& timezoneId);
73 * @copydoc Dali::Toolkit::WebView::New( uint32_t, char** )
75 static Toolkit::WebView New(uint32_t argc, char** argv);
78 * @copydoc Dali::Toolkit::WebView::GetSettings()
80 Dali::Toolkit::WebSettings* GetSettings() const;
83 * @copydoc Dali::Toolkit::WebView::GetContext()
85 Dali::Toolkit::WebContext* GetContext() const;
88 * @copydoc Dali::Toolkit::WebView::GetCookieManager()
90 Dali::Toolkit::WebCookieManager* GetCookieManager() const;
93 * @copydoc Dali::Toolkit::WebView::GetBackForwardList()
95 Dali::Toolkit::WebBackForwardList* GetBackForwardList() const;
98 * @copydoc Dali::Toolkit::WebView::GetFavicon()
100 Dali::Toolkit::ImageView GetFavicon() const;
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(int32_t deltaX, int32_t deltaY);
183 * @copydoc Dali::WebEngine::ScrollEdgeBy()
185 bool ScrollEdgeBy(int32_t deltaX, int32_t 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, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback resultHandler);
213 * @copydoc Dali::Toolkit::WebView::AddJavaScriptMessageHandler()
215 void AddJavaScriptMessageHandler(const std::string& exposedObjectName, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback 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::CreateHitTest()
250 std::unique_ptr<Dali::WebEngineHitTest> CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode);
253 * @copydoc Dali::Toolkit::WebView::CreateHitTestAsynchronously()
255 bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback);
258 * @copydoc Dali::Toolkit::WebView::ClearHistory()
263 * @copydoc Dali::Toolkit::WebView::ClearAllTilesResources()
265 void ClearAllTilesResources();
268 * @copydoc Dali::Toolkit::WebView::SetScaleFactor()
270 void SetScaleFactor(float scaleFactor, Dali::Vector2 point);
273 * @copydoc Dali::Toolkit::WebView::GetScaleFactor()
275 float GetScaleFactor() const;
278 * @copydoc Dali::Toolkit::WebView::ActivateAccessibility()
280 void ActivateAccessibility(bool activated);
283 * @copydoc Dali::Toolkit::WebView::HighlightText()
285 bool HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount);
288 * @copydoc Dali::Toolkit::WebView::AddDynamicCertificatePath()
290 void AddDynamicCertificatePath(const std::string& host, const std::string& certPath);
293 * @copydoc Dali::Toolkit::WebView::GetScreenshot()
295 Dali::Toolkit::ImageView GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor);
298 * @copydoc Dali::Toolkit::WebView::GetScreenshotAsynchronously()
300 bool GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback);
303 * @copydoc Dali::Toolkit::WebView::CheckVideoPlayingAsynchronously()
305 bool CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback);
308 * @copydoc Dali::Toolkit::WebView::RegisterGeolocationPermissionCallback()
310 void RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback);
313 * @copydoc Dali::Toolkit::WebView::SetTtsFocus()
315 void SetTtsFocus(bool focused);
318 * @copydoc Dali::Toolkit::WebView::RegisterPageLoadStartedCallback()
320 void RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
323 * @copydoc Dali::Toolkit::WebView::RegisterPageLoadInProgressCallback()
325 void RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
328 * @copydoc Dali::Toolkit::WebView::RegisterPageLoadFinishedCallback()
330 void RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
333 * @copydoc Dali::Toolkit::WebView::RegisterPageLoadErrorCallback()
335 void RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback);
338 * @copydoc Dali::Toolkit::WebView::RegisterScrollEdgeReachedCallback()
340 void RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback);
343 * @copydoc Dali::Toolkit::WebView::RegisterUrlChangedCallback()
345 void RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback);
348 * @copydoc Dali::Toolkit::WebView::RegisterFormRepostDecidedCallback()
350 void RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback);
353 * @copydoc Dali::Toolkit::WebView::RegisterFrameRenderedCallback()
355 void RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback);
358 * @copydoc Dali::Toolkit::WebView::RegisterConsoleMessageReceivedCallback()
360 void RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback);
363 * @copydoc Dali::Toolkit::WebView::RegisterResponsePolicyDecidedCallback()
365 void RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback);
368 * @copydoc Dali::Toolkit::WebView::RegisterNavigationPolicyDecidedCallback()
370 void RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback);
373 * @copydoc Dali::Toolkit::WebView::RegisterCertificateConfirmedCallback()
375 void RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
378 * @copydoc Dali::Toolkit::WebView::RegisterSslCertificateChangedCallback()
380 void RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
383 * @copydoc Dali::Toolkit::WebView::RegisterHttpAuthHandlerCallback()
385 void RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback);
388 * @copydoc Dali::Toolkit::WebView::RegisterContextMenuShownCallback()
390 void RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback);
393 * @copydoc Dali::Toolkit::WebView::RegisterContextMenuHiddenCallback()
395 void RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback);
398 * @copydoc Dali::Toolkit::WebView::GetPlainTextAsynchronously()
400 void GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback);
402 public: // Properties
404 * @brief Called when a property of an object of this type is set.
406 * @param[in] object The object whose property is set.
407 * @param[in] index The property index.
408 * @param[in] value The new property value.
410 static void SetProperty(Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value);
413 * @brief Called to retrieve a property of an object of this type.
415 * @param[in] object The object whose property is to be retrieved.
416 * @param[in] index The property index.
417 * @return The current value of the property.
419 static Dali::Property::Value GetProperty(Dali::BaseObject* object, Dali::Property::Index propertyIndex);
421 private: // From Control
423 * @copydoc Toolkit::Control::OnInitialize()
425 void OnInitialize() override;
428 * @copydoc Toolkit::Internal::Control::CreateAccessibleObject()
430 DevelControl::ControlAccessible* CreateAccessibleObject() override;
433 * @copydoc Toolkit::Control::GetNaturalSize
435 Vector3 GetNaturalSize() override;
438 * @copydoc Toolkit::Control::OnKeyEvent()
440 bool OnKeyEvent(const Dali::KeyEvent& event) override;
443 * @copydoc Toolkit::Control::OnKeyInputFocusGained()
445 void OnKeyInputFocusGained() override;
448 * @copydoc Toolkit::Control::OnKeyInputFocusLost()
450 void OnKeyInputFocusLost() override;
453 * @copydoc Toolkit::Control::OnSceneConnection()
455 void OnSceneConnection(int depth) override;
459 WebView(const WebView& webView);
461 WebView& operator=(const WebView& webView);
464 * @brief Set an absolute scroll of the given view.
465 * @param[in] x The coordinate x of scroll
466 * @param[in] y The coordinate y of scroll
468 void SetScrollPosition(int32_t x, int32_t y);
471 * @brief Get the current scroll position of the given view.
472 * @param[out] x The coordinate x of scroll
473 * @param[out] y The coordinate y of scroll
475 Dali::Vector2 GetScrollPosition() const;
478 * @brief Get the possible scroll size of the given view.
479 * @param[out] width The width of scroll size
480 * @param[out] height The height of scroll size
482 Dali::Vector2 GetScrollSize() const;
485 * @brief Get the last known content's size.
486 * @param[out] width The width of content's size
487 * @param[out] height The height of content's size
489 Dali::Vector2 GetContentSize() const;
492 * @brief Return the title of the Web.
494 * @return The title of web page
496 std::string GetTitle() const;
499 * @brief Set the background color of web page.
500 * @param[in] color The value of background color.
502 void SetDocumentBackgroundColor(Dali::Vector4 color);
505 * @brief Clear tiles when hidden.
507 * @param[in] cleared Whether tiles are cleared or not
509 void ClearTilesWhenHidden(bool cleared);
512 * @brief Set multiplier of cover area of tile.
514 * @param[in] multiplier The multiplier of cover area
516 void SetTileCoverAreaMultiplier(float multiplier);
519 * @brief Enable cursor by client.
520 * @param[in] enabled Whether cursor is enabled or not.
522 void EnableCursorByClient(bool enabled);
525 * @brief Get the selected text.
526 * @return The selected text
528 std::string GetSelectedText() const;
531 * @brief Get url of web page.
532 * @return The string of url
534 std::string GetUrl() const;
537 * @brief Get user agent string.
538 * @return The string value of user agent
540 std::string GetUserAgent() const;
543 * @brief Set user agent string.
544 * @param[in] userAgent The string value of user agent
546 void SetUserAgent(const std::string& userAgent);
549 * @brief Set zoom factor of the current page.
550 * @param[in] zoomFactor a new factor to be set.
552 void SetPageZoomFactor(float zoomFactor);
555 * @brief Query the current zoom factor of the page。
556 * @return The current page zoom factor.
558 float GetPageZoomFactor() const;
561 * @brief Set the current text zoom level。.
562 * @param[in] zoomFactor a new factor to be set.
564 void SetTextZoomFactor(float zoomFactor);
567 * @brief Get the current text zoom level.
568 * @return The current text zoom factor.
570 float GetTextZoomFactor() const;
573 * @brief Get the current load progress of the page.
574 * @return The load progress of the page.
576 float GetLoadProgressPercentage() const;
579 * @brief Request to set the current page's visibility.
580 * @param[in] visible Visible or not.
582 * @return true if succeeded, false otherwise
584 bool SetVisibility(bool visible);
587 * @brief Update display area of web view.
588 * @param[in] source The soource triggers Notification.
590 void UpdateDisplayArea(Dali::PropertyNotification& source);
593 * @brief Enable/Disable video hole for video playing.
594 * @param[in] enabled True if video hole is enabled, false otherwise.
596 void EnableVideoHole(bool enabled);
599 * @brief Enable blend mode.
600 * @param[in] blendEnabled True if turn on blend mode, false otherwise.
602 void EnableBlendMode(bool blendEnabled);
605 * @brief Enable/disable mouse events. The default is enabled.
607 * @param[in] enabled True if mouse events are enabled, false otherwise
609 void EnableMouseEvents(bool enabled);
612 * @brief Enable/disable key events. The default is enabled.
614 * @param[in] enabled True if key events enabled, false otherwise
616 void EnableKeyEvents(bool enabled);
619 * @brief Create image view by pixel data.
620 * @param[in] pixel Pixel data
621 * @return The new image view
623 Dali::Toolkit::ImageView CreateImageView(Dali::PixelData pixel) const;
626 * @brief Signal occurs when the Web View has been touched.
627 * @param[in] actor The Actor Touched
628 * @param[in] touch The Touch Data.
629 * @return Whether to consume event or not.
631 bool OnTouchEvent(Actor actor, const Dali::TouchEvent& touch);
634 * @brief Signal occurs when the Web View has been hovered.
635 * @param[in] actor The Actor Hovered
636 * @param[in] hover The Hover Data.
637 * @return Whether to consume event or not.
639 bool OnHoverEvent(Actor actor, const Dali::HoverEvent& hover);
642 * @brief Signal occurs when the Web View receives wheel event.
643 * @param[in] actor The Actor that receives Wheel event.
644 * @param[in] wheel The Wheel Data.
645 * @return Whether to consume event or not.
647 bool OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel);
650 * @brief Callback function to be called when frame is rendered.
652 void OnFrameRendered();
655 * @brief Callback function to be called when frame is rendered. This is to check initial buffer is ready.
657 void OnInitialFrameRendered();
660 * @brief Callback function to be called when visibility is changed.
661 * @param[in] actor The actor, or child of actor, whose visibility has changed
662 * @param[in] isVisible Whether the actor is now visible or not
663 * @param[in] type, Whether the actor's visible property has changed or a parent's
665 void OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type);
668 * @brief callback for screen shot captured.
669 * @param[in] pixel Pixel data of screen shot.
671 void OnScreenshotCaptured(Dali::PixelData pixel);
674 class WebViewAccessible : public DevelControl::ControlAccessible
677 WebViewAccessible() = delete;
679 WebViewAccessible(Dali::Actor self, Dali::WebEngine& webEngine);
683 * @copydoc Dali::Accessibility::ActorAccessible::DoGetChildren()
685 void DoGetChildren(std::vector<Dali::Accessibility::Accessible*>& children) override;
688 void OnAccessibilityEnabled();
689 void OnAccessibilityDisabled();
690 void SetRemoteChildAddress(Dali::Accessibility::Address address);
692 Dali::Accessibility::ProxyAccessible mRemoteChild;
693 Dali::WebEngine& mWebEngine;
697 Dali::Toolkit::Visual::Base mVisual;
698 Dali::Size mWebViewSize;
699 Dali::WebEngine mWebEngine;
701 std::unique_ptr<Dali::Toolkit::WebContext> mWebContext;
702 std::unique_ptr<Dali::Toolkit::WebCookieManager> mWebCookieManager;
703 std::unique_ptr<Dali::Toolkit::WebSettings> mWebSettings;
704 std::unique_ptr<Dali::Toolkit::WebBackForwardList> mWebBackForwardList;
706 Dali::PropertyNotification mPositionUpdateNotification;
707 Dali::PropertyNotification mSizeUpdateNotification;
708 Dali::PropertyNotification mScaleUpdateNotification;
709 Dali::Rect<int32_t> mWebViewArea;
710 bool mVideoHoleEnabled;
711 bool mMouseEventsEnabled;
712 bool mKeyEventsEnabled;
714 Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback mScreenshotCapturedCallback;
715 Dali::WebEnginePlugin::WebEngineFrameRenderedCallback mFrameRenderedCallback;
718 } // namespace Internal
720 inline Toolkit::Internal::WebView& GetImpl(Toolkit::WebView& handle)
722 DALI_ASSERT_ALWAYS(handle);
723 Dali::RefObject& impl = handle.GetImplementation();
724 return static_cast<Toolkit::Internal::WebView&>(impl);
727 inline const Toolkit::Internal::WebView& GetImpl(const Toolkit::WebView& handle)
729 DALI_ASSERT_ALWAYS(handle);
730 const Dali::RefObject& impl = handle.GetImplementation();
731 return static_cast<const Toolkit::Internal::WebView&>(impl);
734 } // namespace Toolkit
738 #endif // DALI_TOOLKIT_INTERNAL_WEB_VIEW_H