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>
28 #include <unordered_map>
31 #include <dali-toolkit/devel-api/controls/control-accessible.h>
32 #include <dali-toolkit/devel-api/controls/web-view/web-view.h>
33 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
34 #include <dali-toolkit/public-api/controls/control-impl.h>
35 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
43 class WebBackForwardList;
49 class WebView : public Control
54 WebView(const std::string& locale, const std::string& timezoneId);
56 WebView(uint32_t argc, char** argv);
62 * @copydoc Dali::Toolkit::WebView::New()
64 static Toolkit::WebView New();
67 * @copydoc Dali::Toolkit::WebView::New( const std::string&, const std::string& )
69 static Toolkit::WebView New(const std::string& locale, const std::string& timezoneId);
72 * @copydoc Dali::Toolkit::WebView::New( uint32_t, char** )
74 static Toolkit::WebView New(uint32_t argc, char** argv);
77 * @copydoc Dali::Toolkit::WebView::FindWebView()
79 static Toolkit::WebView FindWebView(Dali::WebEnginePlugin* plugin);
82 * @copydoc Dali::Toolkit::WebView::GetContext()
84 static Dali::WebEngineContext* GetContext();
87 * @copydoc Dali::Toolkit::WebView::GetCookieManager()
89 static Dali::WebEngineCookieManager* GetCookieManager();
92 * @copydoc Dali::Toolkit::WebView::GetSettings()
94 Dali::Toolkit::WebSettings* GetSettings() const;
97 * @copydoc Dali::Toolkit::WebView::GetBackForwardList()
99 Dali::Toolkit::WebBackForwardList* GetBackForwardList() const;
102 * @copydoc Dali::Toolkit::WebView::GetFavicon()
104 Dali::Toolkit::ImageView GetFavicon() const;
107 * @copydoc Dali::Toolkit::WebView::LoadUrl()
109 void LoadUrl(const std::string& url);
112 * @copydoc Dali::WebEngine::LoadHTMLString()
114 void LoadHtmlString(const std::string& htmlString);
117 * @copydoc Dali::WebEngine::LoadHtmlStringOverrideCurrentEntry()
119 bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl);
122 * @copydoc Dali::WebEngine::LoadContents()
124 bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri);
127 * @copydoc Dali::Toolkit::WebView::Reload()
132 * @copydoc Dali::WebEngine::ReloadWithoutCache()
134 bool ReloadWithoutCache();
137 * @copydoc Dali::Toolkit::WebView::StopLoading()
142 * @copydoc Dali::Toolkit::WebView::StopLoading()
147 * @copydoc Dali::Toolkit::WebView::Resume()
152 * @copydoc Dali::WebEngine::SuspendNetworkLoading()
154 void SuspendNetworkLoading();
157 * @copydoc Dali::WebEngine::ResumeNetworkLoading()
159 void ResumeNetworkLoading();
162 * @copydoc Dali::WebEngine::AddCustomHeader()
164 bool AddCustomHeader(const std::string& name, const std::string& value);
167 * @copydoc Dali::WebEngine::RemoveCustomHeader()
169 bool RemoveCustomHeader(const std::string& name);
172 * @copydoc Dali::WebEngine::StartInspectorServer()
174 uint32_t StartInspectorServer(uint32_t port);
177 * @copydoc Dali::WebEngine::StopInspectorServer()
179 bool StopInspectorServer();
182 * @copydoc Dali::Toolkit::WebView::ScrollBy()
184 void ScrollBy(int32_t deltaX, int32_t deltaY);
187 * @copydoc Dali::WebEngine::ScrollEdgeBy()
189 bool ScrollEdgeBy(int32_t deltaX, int32_t deltaY);
192 * @copydoc Dali::Toolkit::WebView::CanGoForward()
197 * @copydoc Dali::Toolkit::WebView::GoForward()
202 * @copydoc Dali::Toolkit::WebView::CanGoBack()
207 * @copydoc Dali::Toolkit::WebView::GoBack()
212 * @copydoc Dali::Toolkit::WebView::EvaluateJavaScript()
214 void EvaluateJavaScript(const std::string& script, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback resultHandler);
217 * @copydoc Dali::Toolkit::WebView::AddJavaScriptMessageHandler()
219 void AddJavaScriptMessageHandler(const std::string& exposedObjectName, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback handler);
222 * @copydoc Dali::Toolkit::WebView::RegisterJavaScriptAlertCallback()
224 void RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback);
227 * @copydoc Dali::Toolkit::WebView::JavaScriptAlertReply()
229 void JavaScriptAlertReply();
232 * @copydoc Dali::Toolkit::WebView::RegisterJavaScriptConfirmCallback()
234 void RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback);
237 * @copydoc Dali::Toolkit::WebView::JavaScriptConfirmReply()
239 void JavaScriptConfirmReply(bool confirmed);
242 * @copydoc Dali::Toolkit::WebView::RegisterJavaScriptPromptCallback()
244 void RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback);
247 * @copydoc Dali::Toolkit::WebView::JavaScriptPromptReply()
249 void JavaScriptPromptReply(const std::string& result);
252 * @copydoc Dali::Toolkit::WebView::CreateHitTest()
254 std::unique_ptr<Dali::WebEngineHitTest> CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode);
257 * @copydoc Dali::Toolkit::WebView::CreateHitTestAsynchronously()
259 bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback);
262 * @copydoc Dali::Toolkit::WebView::ClearHistory()
267 * @copydoc Dali::Toolkit::WebView::ClearAllTilesResources()
269 void ClearAllTilesResources();
272 * @copydoc Dali::Toolkit::WebView::SetScaleFactor()
274 void SetScaleFactor(float scaleFactor, Dali::Vector2 point);
277 * @copydoc Dali::Toolkit::WebView::GetScaleFactor()
279 float GetScaleFactor() const;
282 * @copydoc Dali::Toolkit::WebView::ActivateAccessibility()
284 void ActivateAccessibility(bool activated);
287 * @copydoc Dali::Toolkit::WebView::HighlightText()
289 bool HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount);
292 * @copydoc Dali::Toolkit::WebView::AddDynamicCertificatePath()
294 void AddDynamicCertificatePath(const std::string& host, const std::string& certPath);
297 * @copydoc Dali::Toolkit::WebView::GetScreenshot()
299 Dali::Toolkit::ImageView GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor);
302 * @copydoc Dali::Toolkit::WebView::GetScreenshotAsynchronously()
304 bool GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback);
307 * @copydoc Dali::Toolkit::WebView::CheckVideoPlayingAsynchronously()
309 bool CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback);
312 * @copydoc Dali::Toolkit::WebView::RegisterGeolocationPermissionCallback()
314 void RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback);
317 * @copydoc Dali::Toolkit::WebView::SetTtsFocus()
319 void SetTtsFocus(bool focused);
322 * @copydoc Dali::Toolkit::WebView::RegisterPageLoadStartedCallback()
324 void RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
327 * @copydoc Dali::Toolkit::WebView::RegisterPageLoadInProgressCallback()
329 void RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
332 * @copydoc Dali::Toolkit::WebView::RegisterPageLoadFinishedCallback()
334 void RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
337 * @copydoc Dali::Toolkit::WebView::RegisterPageLoadErrorCallback()
339 void RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback);
342 * @copydoc Dali::Toolkit::WebView::RegisterScrollEdgeReachedCallback()
344 void RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback);
347 * @copydoc Dali::Toolkit::WebView::RegisterUrlChangedCallback()
349 void RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback);
352 * @copydoc Dali::Toolkit::WebView::RegisterFormRepostDecidedCallback()
354 void RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback);
357 * @copydoc Dali::Toolkit::WebView::RegisterFrameRenderedCallback()
359 void RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback);
362 * @copydoc Dali::Toolkit::WebView::RegisterConsoleMessageReceivedCallback()
364 void RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback);
367 * @copydoc Dali::Toolkit::WebView::RegisterResponsePolicyDecidedCallback()
369 void RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback);
372 * @copydoc Dali::Toolkit::WebView::RegisterNavigationPolicyDecidedCallback()
374 void RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback);
377 * @copydoc Dali::Toolkit::WebView::RegisterCertificateConfirmedCallback()
379 void RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
382 * @copydoc Dali::Toolkit::WebView::RegisterSslCertificateChangedCallback()
384 void RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);
387 * @copydoc Dali::Toolkit::WebView::RegisterHttpAuthHandlerCallback()
389 void RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback);
392 * @copydoc Dali::Toolkit::WebView::RegisterContextMenuShownCallback()
394 void RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback);
397 * @copydoc Dali::Toolkit::WebView::RegisterContextMenuHiddenCallback()
399 void RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback);
402 * @copydoc Dali::Toolkit::WebView::GetPlainTextAsynchronously()
404 void GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback);
406 public: // Properties
408 * @brief Called when a property of an object of this type is set.
410 * @param[in] object The object whose property is set.
411 * @param[in] index The property index.
412 * @param[in] value The new property value.
414 static void SetProperty(Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value);
417 * @brief Called to retrieve a property of an object of this type.
419 * @param[in] object The object whose property is to be retrieved.
420 * @param[in] index The property index.
421 * @return The current value of the property.
423 static Dali::Property::Value GetProperty(Dali::BaseObject* object, Dali::Property::Index propertyIndex);
425 private: // From Control
427 * @copydoc Toolkit::Control::OnInitialize()
429 void OnInitialize() override;
432 * @copydoc Toolkit::Internal::Control::CreateAccessibleObject()
434 DevelControl::ControlAccessible* CreateAccessibleObject() override;
437 * @copydoc Toolkit::Control::GetNaturalSize
439 Vector3 GetNaturalSize() override;
442 * @copydoc Toolkit::Control::OnKeyEvent()
444 bool OnKeyEvent(const Dali::KeyEvent& event) override;
447 * @copydoc Toolkit::Control::OnKeyInputFocusGained()
449 void OnKeyInputFocusGained() override;
452 * @copydoc Toolkit::Control::OnKeyInputFocusLost()
454 void OnKeyInputFocusLost() override;
457 * @copydoc Toolkit::Control::OnSceneConnection()
459 void OnSceneConnection(int depth) override;
463 WebView(const WebView& webView);
465 WebView& operator=(const WebView& webView);
468 * @brief Gets web engine plugin.
470 Dali::WebEnginePlugin* GetPlugin() const;
473 * @brief Set an absolute scroll of the given view.
474 * @param[in] x The coordinate x of scroll
475 * @param[in] y The coordinate y of scroll
477 void SetScrollPosition(int32_t x, int32_t y);
480 * @brief Get the current scroll position of the given view.
481 * @param[out] x The coordinate x of scroll
482 * @param[out] y The coordinate y of scroll
484 Dali::Vector2 GetScrollPosition() const;
487 * @brief Get the possible scroll size of the given view.
488 * @param[out] width The width of scroll size
489 * @param[out] height The height of scroll size
491 Dali::Vector2 GetScrollSize() const;
494 * @brief Get the last known content's size.
495 * @param[out] width The width of content's size
496 * @param[out] height The height of content's size
498 Dali::Vector2 GetContentSize() const;
501 * @brief Return the title of the Web.
503 * @return The title of web page
505 std::string GetTitle() const;
508 * @brief Set the background color of web page.
509 * @param[in] color The value of background color.
511 void SetDocumentBackgroundColor(Dali::Vector4 color);
514 * @brief Clear tiles when hidden.
516 * @param[in] cleared Whether tiles are cleared or not
518 void ClearTilesWhenHidden(bool cleared);
521 * @brief Set multiplier of cover area of tile.
523 * @param[in] multiplier The multiplier of cover area
525 void SetTileCoverAreaMultiplier(float multiplier);
528 * @brief Enable cursor by client.
529 * @param[in] enabled Whether cursor is enabled or not.
531 void EnableCursorByClient(bool enabled);
534 * @brief Get the selected text.
535 * @return The selected text
537 std::string GetSelectedText() const;
540 * @brief Get url of web page.
541 * @return The string of url
543 std::string GetUrl() const;
546 * @brief Get user agent string.
547 * @return The string value of user agent
549 std::string GetUserAgent() const;
552 * @brief Set user agent string.
553 * @param[in] userAgent The string value of user agent
555 void SetUserAgent(const std::string& userAgent);
558 * @brief Set zoom factor of the current page.
559 * @param[in] zoomFactor a new factor to be set.
561 void SetPageZoomFactor(float zoomFactor);
564 * @brief Query the current zoom factor of the page。
565 * @return The current page zoom factor.
567 float GetPageZoomFactor() const;
570 * @brief Set the current text zoom level。.
571 * @param[in] zoomFactor a new factor to be set.
573 void SetTextZoomFactor(float zoomFactor);
576 * @brief Get the current text zoom level.
577 * @return The current text zoom factor.
579 float GetTextZoomFactor() const;
582 * @brief Get the current load progress of the page.
583 * @return The load progress of the page.
585 float GetLoadProgressPercentage() const;
588 * @brief Request to set the current page's visibility.
589 * @param[in] visible Visible or not.
591 * @return true if succeeded, false otherwise
593 bool SetVisibility(bool visible);
596 * @brief Update display area of web view.
597 * @param[in] source The soource triggers Notification.
599 void UpdateDisplayArea(Dali::PropertyNotification& source);
602 * @brief Enable/Disable video hole for video playing.
603 * @param[in] enabled True if video hole is enabled, false otherwise.
605 void EnableVideoHole(bool enabled);
608 * @brief Enable blend mode.
609 * @param[in] blendEnabled True if turn on blend mode, false otherwise.
611 void EnableBlendMode(bool blendEnabled);
614 * @brief Enable/disable mouse events. The default is enabled.
616 * @param[in] enabled True if mouse events are enabled, false otherwise
618 void EnableMouseEvents(bool enabled);
621 * @brief Enable/disable key events. The default is enabled.
623 * @param[in] enabled True if key events enabled, false otherwise
625 void EnableKeyEvents(bool enabled);
628 * @brief Create image view by pixel data.
629 * @param[in] pixel Pixel data
630 * @return The new image view
632 Dali::Toolkit::ImageView CreateImageView(Dali::PixelData pixel) const;
635 * @brief Signal occurs when the Web View has been touched.
636 * @param[in] actor The Actor Touched
637 * @param[in] touch The Touch Data.
638 * @return Whether to consume event or not.
640 bool OnTouchEvent(Actor actor, const Dali::TouchEvent& touch);
643 * @brief Signal occurs when the Web View has been hovered.
644 * @param[in] actor The Actor Hovered
645 * @param[in] hover The Hover Data.
646 * @return Whether to consume event or not.
648 bool OnHoverEvent(Actor actor, const Dali::HoverEvent& hover);
651 * @brief Signal occurs when the Web View receives wheel event.
652 * @param[in] actor The Actor that receives Wheel event.
653 * @param[in] wheel The Wheel Data.
654 * @return Whether to consume event or not.
656 bool OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel);
659 * @brief Callback function to be called when frame is rendered.
661 void OnFrameRendered();
664 * @brief Callback function to be called when frame is rendered. This is to check initial buffer is ready.
666 void OnInitialFrameRendered();
669 * @brief Callback function to be called when visibility is changed.
670 * @param[in] actor The actor, or child of actor, whose visibility has changed
671 * @param[in] isVisible Whether the actor is now visible or not
672 * @param[in] type, Whether the actor's visible property has changed or a parent's
674 void OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type);
677 * @brief callback for screen shot captured.
678 * @param[in] pixel Pixel data of screen shot.
680 void OnScreenshotCaptured(Dali::PixelData pixel);
683 class WebViewAccessible : public DevelControl::ControlAccessible
686 WebViewAccessible() = delete;
688 WebViewAccessible(Dali::Actor self, Dali::WebEngine& webEngine);
692 * @copydoc Dali::Accessibility::ActorAccessible::DoGetChildren()
694 void DoGetChildren(std::vector<Dali::Accessibility::Accessible*>& children) override;
697 void OnAccessibilityEnabled();
698 void OnAccessibilityDisabled();
699 void SetRemoteChildAddress(Dali::Accessibility::Address address);
701 Dali::Accessibility::ProxyAccessible mRemoteChild;
702 Dali::WebEngine& mWebEngine;
706 Dali::Toolkit::Visual::Base mVisual;
707 Dali::Size mWebViewSize;
708 Dali::WebEngine mWebEngine;
710 std::unique_ptr<Dali::Toolkit::WebSettings> mWebSettings;
711 std::unique_ptr<Dali::Toolkit::WebBackForwardList> mWebBackForwardList;
713 Dali::PropertyNotification mPositionUpdateNotification;
714 Dali::PropertyNotification mSizeUpdateNotification;
715 Dali::PropertyNotification mScaleUpdateNotification;
716 Dali::Rect<int32_t> mWebViewArea;
717 bool mVideoHoleEnabled;
718 bool mMouseEventsEnabled;
719 bool mKeyEventsEnabled;
721 Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback mScreenshotCapturedCallback;
722 Dali::WebEnginePlugin::WebEngineFrameRenderedCallback mFrameRenderedCallback;
724 static std::unordered_map<Dali::WebEnginePlugin*, Dali::WeakHandle<Toolkit::WebView>> mPluginWebViewMap;
727 } // namespace Internal
729 inline Toolkit::Internal::WebView& GetImpl(Toolkit::WebView& handle)
731 DALI_ASSERT_ALWAYS(handle);
732 Dali::RefObject& impl = handle.GetImplementation();
733 return static_cast<Toolkit::Internal::WebView&>(impl);
736 inline const Toolkit::Internal::WebView& GetImpl(const Toolkit::WebView& handle)
738 DALI_ASSERT_ALWAYS(handle);
739 const Dali::RefObject& impl = handle.GetImplementation();
740 return static_cast<const Toolkit::Internal::WebView&>(impl);
743 } // namespace Toolkit
747 #endif // DALI_TOOLKIT_INTERNAL_WEB_VIEW_H