2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "toolkit-timer.h"
20 #include <dali/devel-api/adaptor-framework/web-engine.h>
21 #include <dali/devel-api/adaptor-framework/web-engine-back-forward-list.h>
22 #include <dali/devel-api/adaptor-framework/web-engine-back-forward-list-item.h>
23 #include <dali/devel-api/adaptor-framework/web-engine-certificate.h>
24 #include <dali/devel-api/adaptor-framework/web-engine-console-message.h>
25 #include <dali/devel-api/adaptor-framework/web-engine-context.h>
26 #include <dali/devel-api/adaptor-framework/web-engine-cookie-manager.h>
27 #include <dali/devel-api/adaptor-framework/web-engine-form-repost-decision.h>
28 #include <dali/devel-api/adaptor-framework/web-engine-frame.h>
29 #include <dali/devel-api/adaptor-framework/web-engine-http-auth-handler.h>
30 #include <dali/devel-api/adaptor-framework/web-engine-load-error.h>
31 #include <dali/devel-api/adaptor-framework/web-engine-policy-decision.h>
32 #include <dali/devel-api/adaptor-framework/web-engine-request-interceptor.h>
33 #include <dali/devel-api/adaptor-framework/web-engine-settings.h>
34 #include <dali/public-api/adaptor-framework/native-image-source.h>
35 #include <dali/public-api/images/pixel-data.h>
36 #include <dali/public-api/object/any.h>
37 #include <dali/public-api/object/base-object.h>
40 #include <toolkit-application.h>
56 // Generally only one WebEngine instance exists.
57 // If > 1, a new web engine has been created by CreateWindowSignal.
58 static WebEngine* gInstance = 0;
59 static int gInstanceCount = 0;
64 bool OnEvaluteJavaScript();
65 bool OnJavaScriptAlert();
66 bool OnJavaScriptConfirm();
67 bool OnJavaScriptPrompt();
69 bool OnScreenshotCaptured();
70 bool OnVideoPlaying();
71 bool OnGeolocationPermission();
72 bool OnClearHistory();
74 static void ConnectToGlobalSignal( bool ( *func )() )
76 Dali::Timer timer = Dali::Timer::New( 0 );
77 timer.TickSignal().Connect( func );
80 static void DisconnectFromGlobalSignal( bool ( *func )() )
82 Dali::Timer timer = Dali::Timer::New( 0 );
83 timer.TickSignal().Disconnect( func );
85 } // namespace anonymous
87 class MockWebEngineContext : public Dali::WebEngineContext
90 MockWebEngineContext()
91 : mockModel( Dali::WebEngineContext::CacheModel::DOCUMENT_VIEWER )
95 Dali::WebEngineContext::CacheModel GetCacheModel() const override
100 void SetCacheModel( Dali::WebEngineContext::CacheModel cacheModel ) override
102 mockModel = cacheModel;
105 void SetProxyUri( const std::string& uri ) override
109 void SetDefaultProxyAuth( const std::string& username, const std::string& password ) override
113 void SetCertificateFilePath( const std::string& certificatePath ) override
117 void DeleteWebDatabase() override
121 void DeleteWebStorage() override
125 void DeleteLocalFileSystem() override
129 void DisableCache( bool cacheDisabled ) override
133 void ClearCache() override
138 Dali::WebEngineContext::CacheModel mockModel;
141 class MockWebEngineCookieManager : public Dali::WebEngineCookieManager
144 MockWebEngineCookieManager()
145 : mockCookieAcceptPolicy( Dali::WebEngineCookieManager::CookieAcceptPolicy::NO_THIRD_PARTY )
149 void SetCookieAcceptPolicy( Dali::WebEngineCookieManager::CookieAcceptPolicy policy ) override
151 mockCookieAcceptPolicy = policy;
154 Dali::WebEngineCookieManager::CookieAcceptPolicy GetCookieAcceptPolicy() const override
156 return mockCookieAcceptPolicy;
159 void ClearCookies() override
163 void SetPersistentStorage( const std::string& path, Dali::WebEngineCookieManager::CookiePersistentStorage storage ) override
168 Dali::WebEngineCookieManager::CookieAcceptPolicy mockCookieAcceptPolicy;
171 class MockWebEngineBackForwardListItem : public Dali::WebEngineBackForwardListItem
174 MockWebEngineBackForwardListItem()
175 : mockUrl( "http://url" ),
176 mockTitle( "title" ),
177 mockOriginalUrl( "http://originalurl" )
181 std::string GetUrl() const override
186 std::string GetTitle() const override
191 std::string GetOriginalUrl() const override
193 return mockOriginalUrl;
198 std::string mockTitle;
199 std::string mockOriginalUrl;
202 class MockWebEngineBackForwardList : public Dali::WebEngineBackForwardList
205 MockWebEngineBackForwardList()
209 std::unique_ptr<Dali::WebEngineBackForwardListItem> GetCurrentItem() const override
211 std::unique_ptr<Dali::WebEngineBackForwardListItem> ret(new MockWebEngineBackForwardListItem());
215 std::unique_ptr<Dali::WebEngineBackForwardListItem> GetPreviousItem() const override
217 std::unique_ptr<Dali::WebEngineBackForwardListItem> ret(new MockWebEngineBackForwardListItem());
221 std::unique_ptr<Dali::WebEngineBackForwardListItem> GetNextItem() const override
223 std::unique_ptr<Dali::WebEngineBackForwardListItem> ret(new MockWebEngineBackForwardListItem());
227 std::unique_ptr<Dali::WebEngineBackForwardListItem> GetItemAtIndex( uint32_t index ) const override
229 std::unique_ptr<Dali::WebEngineBackForwardListItem> ret(new MockWebEngineBackForwardListItem());
233 uint32_t GetItemCount() const override
238 std::vector<std::unique_ptr<Dali::WebEngineBackForwardListItem>> GetBackwardItems(int limit) override
240 std::vector<std::unique_ptr<Dali::WebEngineBackForwardListItem>> ret;
241 std::unique_ptr<Dali::WebEngineBackForwardListItem> item(new MockWebEngineBackForwardListItem());
242 ret.push_back(std::move(item));
246 std::vector<std::unique_ptr<Dali::WebEngineBackForwardListItem>> GetForwardItems(int limit) override
248 std::vector<std::unique_ptr<Dali::WebEngineBackForwardListItem>> ret;
249 std::unique_ptr<Dali::WebEngineBackForwardListItem> item(new MockWebEngineBackForwardListItem());
250 ret.push_back(std::move(item));
256 class MockWebEngineCertificate : public Dali::WebEngineCertificate
259 MockWebEngineCertificate()
263 void Allow(bool allowed) override
267 bool IsFromMainFrame() const override
272 std::string GetPem() const override
277 bool IsContextSecure() const override
283 class MockWebEngineHttpAuthHandler : public Dali::WebEngineHttpAuthHandler
286 MockWebEngineHttpAuthHandler()
290 std::string GetRealm() const override
295 void Suspend() override
299 void UseCredential(const std::string& user, const std::string& password) override
303 void CancelCredential() override
308 class MockWebEngineFormRepostDecision : public WebEngineFormRepostDecision
311 MockWebEngineFormRepostDecision()
315 void Reply(bool allowed) override {}
318 class MockWebEngineFrame : public Dali::WebEngineFrame
325 bool IsMainFrame() const override
331 class MockWebEnginePolicyDecision : public Dali::WebEnginePolicyDecision
334 MockWebEnginePolicyDecision()
338 std::string GetUrl() const override
340 return "http://test.html";
343 std::string GetCookie() const override
348 Dali::WebEnginePolicyDecision::DecisionType GetDecisionType() const
350 return Dali::WebEnginePolicyDecision::DecisionType::USE;
353 std::string GetResponseMime() const
358 int32_t GetResponseStatusCode() const
363 Dali::WebEnginePolicyDecision::NavigationType GetNavigationType() const
365 return Dali::WebEnginePolicyDecision::NavigationType::LINK_CLICKED;
368 Dali::WebEngineFrame& GetFrame() const
370 return *(Dali::WebEngineFrame*)(&mockWebFrame);
373 std::string GetScheme() const
394 MockWebEngineFrame mockWebFrame;
397 class MockWebEngineRequestInterceptor : public WebEngineRequestInterceptor
400 MockWebEngineRequestInterceptor()
404 std::string GetUrl() const override
406 return "http://test.html";
409 bool Ignore() override
414 bool SetResponseStatus(int statusCode, const std::string &customedStatusText) override
419 bool AddResponseHeader(const std::string &fieldName, const std::string &fieldValue) override
424 bool AddResponseBody(const std::string &body, uint32_t length) override
430 class MockWebEngineConsoleMessage : public Dali::WebEngineConsoleMessage
433 MockWebEngineConsoleMessage()
437 std::string GetSource() const override
442 uint32_t GetLine() const override
447 SeverityLevel GetSeverityLevel() const override
449 return SeverityLevel::EMPTY;
452 std::string GetText() const override
454 return "This is a text.";
458 class MockWebEngineLoadError : public Dali::WebEngineLoadError
461 MockWebEngineLoadError(const std::string& url)
466 std::string GetUrl() const override
471 ErrorCode GetCode() const override
473 return ErrorCode::UNKNOWN;
476 std::string GetDescription() const override
478 return "This is an error.";
481 ErrorType GetType() const override
483 return ErrorType::NONE;
490 class MockWebEngineSettings : public WebEngineSettings
493 MockWebEngineSettings()
494 : mockDefaultFontSize( 16 ),
495 mockJavaScriptEnabled( true ),
496 mockAutoFittingEnabled ( true ),
497 mockPluginsEnabled ( true ),
498 mockPrivateBrowsingEnabled( true ),
499 mockLinkMagnifierEnabled( true ),
500 mockKeypadWithoutUserActionUsed( true ),
501 mockAutofillPasswordFormEnabled( true ),
502 mockFormCandidateDataEnabled( true ),
503 mockTextSelectionEnabled( true ),
504 mockTextAutosizingEnable( true ),
505 mockArrowScrollEnable( true ),
506 mockClipboardEnabled( true ),
507 mockImePanelEnabled( true ),
508 mockImageLoadedAutomatically( true ),
509 mockDefaultTextEncodingName()
513 uint32_t GetDefaultFontSize() const override
515 return mockDefaultFontSize;
518 void SetDefaultFontSize( uint32_t size ) override
520 mockDefaultFontSize = size;
523 bool IsJavaScriptEnabled() const override
525 return mockJavaScriptEnabled;
528 void EnableJavaScript( bool enabled ) override
530 mockJavaScriptEnabled = enabled;
533 bool IsAutoFittingEnabled() const override
535 return mockAutoFittingEnabled;
538 void EnableAutoFitting( bool enabled ) override
540 mockAutoFittingEnabled = enabled;
543 bool ArePluginsEnabled() const override
545 return mockPluginsEnabled;
548 void EnablePlugins( bool enabled ) override
550 mockPluginsEnabled = enabled;
553 bool IsPrivateBrowsingEnabled() const override
555 return mockPrivateBrowsingEnabled;
558 void EnablePrivateBrowsing( bool enabled ) override
560 mockPrivateBrowsingEnabled = enabled;
563 bool IsLinkMagnifierEnabled() const override
565 return mockLinkMagnifierEnabled;
568 void EnableLinkMagnifier( bool enabled ) override
570 mockLinkMagnifierEnabled = enabled;
573 bool IsKeypadWithoutUserActionUsed() const override
575 return mockKeypadWithoutUserActionUsed;
578 void UseKeypadWithoutUserAction( bool used ) override
580 mockKeypadWithoutUserActionUsed = used;
583 bool IsAutofillPasswordFormEnabled() const override
585 return mockAutofillPasswordFormEnabled;
588 void EnableAutofillPasswordForm( bool enabled ) override
590 mockAutofillPasswordFormEnabled = enabled;
593 bool IsFormCandidateDataEnabled() const override
595 return mockFormCandidateDataEnabled;
598 void EnableFormCandidateData( bool enabled ) override
600 mockFormCandidateDataEnabled = enabled;
603 bool IsTextSelectionEnabled() const override
605 return mockTextSelectionEnabled;
608 void EnableTextSelection( bool enabled ) override
610 mockTextSelectionEnabled = enabled;
613 bool IsTextAutosizingEnabled() const override
615 return mockTextAutosizingEnable;
618 void EnableTextAutosizing( bool enabled ) override
620 mockTextAutosizingEnable = enabled;
623 bool IsArrowScrollEnabled() const override
625 return mockArrowScrollEnable;
628 void EnableArrowScroll( bool enabled ) override
630 mockArrowScrollEnable = enabled;
633 bool IsClipboardEnabled() const override
635 return mockClipboardEnabled;
638 void EnableClipboard( bool enabled ) override
640 mockClipboardEnabled = enabled;
643 bool IsImePanelEnabled() const override
645 return mockImePanelEnabled;
648 void EnableImePanel( bool enabled ) override
650 mockImePanelEnabled = enabled;
653 bool AreImagesLoadedAutomatically() const override
655 return mockImageLoadedAutomatically;
658 void AllowImagesLoadAutomatically( bool automatic ) override
660 mockImageLoadedAutomatically = automatic;
663 std::string GetDefaultTextEncodingName() const override
665 return mockDefaultTextEncodingName;
668 void SetDefaultTextEncodingName( const std::string& defaultTextEncodingName ) override
670 mockDefaultTextEncodingName = defaultTextEncodingName;
673 void AllowMixedContents( bool allowed ) override
677 void EnableSpatialNavigation( bool enabled ) override
681 void EnableWebSecurity( bool enabled ) override
685 void EnableCacheBuilder( bool enabled ) override
689 void UseScrollbarThumbFocusNotifications( bool used ) override
693 void EnableDoNotTrack( bool enabled ) override
697 void AllowFileAccessFromExternalUrl( bool allowed ) override
701 void AllowScriptsOpenWindows( bool allowed ) override
706 int mockDefaultFontSize;
707 bool mockJavaScriptEnabled;
708 bool mockAutoFittingEnabled;
709 bool mockPluginsEnabled;
710 bool mockPrivateBrowsingEnabled;
711 bool mockLinkMagnifierEnabled;
712 bool mockKeypadWithoutUserActionUsed;
713 bool mockAutofillPasswordFormEnabled;
714 bool mockFormCandidateDataEnabled;
715 bool mockTextSelectionEnabled;
716 bool mockTextAutosizingEnable;
717 bool mockArrowScrollEnable;
718 bool mockClipboardEnabled;
719 bool mockImePanelEnabled;
720 bool mockImageLoadedAutomatically;
721 std::string mockDefaultTextEncodingName;
724 class WebEngine: public Dali::BaseObject
728 using JavaScriptEvaluatedResultCallback = std::function<void(const std::string&)>;
732 , mCurrentPlusOnePos( 0 )
734 , mEvaluating( false )
735 , mScrollPosition( 0, 0 )
736 , mScrollSize( 500, 500 )
737 , mContentSize( 500, 500 )
740 if ( gInstanceCount == 1 ) // only first web engine need be saved.
745 mockWebEngineSettings = new MockWebEngineSettings();
746 mockWebEngineContext = new MockWebEngineContext();
747 mockWebEngineCookieManager = new MockWebEngineCookieManager();
748 mockWebEngineBackForwardList = new MockWebEngineBackForwardList();
754 if( !gInstanceCount )
759 delete mockWebEngineSettings;
760 delete mockWebEngineContext;
761 delete mockWebEngineCookieManager;
762 delete mockWebEngineBackForwardList;
765 Dali::WebEngineSettings& GetSettings() const
767 return *mockWebEngineSettings;
770 Dali::WebEngineContext& GetContext() const
772 return *mockWebEngineContext;
775 Dali::WebEngineCookieManager& GetCookieManager() const
777 return *mockWebEngineCookieManager;
780 Dali::WebEngineBackForwardList& GetBackForwardList() const
782 return *mockWebEngineBackForwardList;
785 void LoadUrl( const std::string& url )
788 ConnectToGlobalSignal( &OnLoadUrl );
791 const std::string& GetUrl() const
796 std::string GetTitle() const
798 return std::string("title");
801 Dali::PixelData GetFavicon() const
803 uint8_t* faviconData = new uint8_t[ 16 ];
805 faviconData[ 0 ] = 0xff;
806 faviconData[ 1 ] = 0x00;
807 faviconData[ 2 ] = 0x00;
808 faviconData[ 3 ] = 0xff;
809 faviconData[ 4 ] = 0xff;
810 faviconData[ 5 ] = 0x00;
811 faviconData[ 6 ] = 0x00;
812 faviconData[ 7 ] = 0xff;
813 faviconData[ 8 ] = 0xff;
814 faviconData[ 9 ] = 0x00;
815 faviconData[ 10 ] = 0x00;
816 faviconData[ 11 ] = 0xff;
817 faviconData[ 12 ] = 0xff;
818 faviconData[ 13 ] = 0x00;
819 faviconData[ 14 ] = 0x00;
820 faviconData[ 15 ] = 0xff;
822 return Dali::PixelData::New( faviconData, 16, 2, 2,
823 Dali::Pixel::Format::RGBA8888,
824 Dali::PixelData::ReleaseFunction::DELETE_ARRAY );
827 bool CanGoForward() const
829 return mHistory.size() > mCurrentPlusOnePos;
834 ConnectToGlobalSignal( &OnGoForward );
837 bool CanGoBack() const
839 return mCurrentPlusOnePos > 1;
844 ConnectToGlobalSignal( &OnGoBack );
847 void EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler )
853 ConnectToGlobalSignal( &OnEvaluteJavaScript );
855 mResultCallbacks.push_back( resultHandler );
859 void RegisterJavaScriptAlertCallback( Dali::WebEnginePlugin::JavaScriptAlertCallback callback )
863 ConnectToGlobalSignal( &OnJavaScriptAlert );
864 mJavaScriptAlertCallback = callback;
868 void RegisterJavaScriptConfirmCallback( Dali::WebEnginePlugin::JavaScriptConfirmCallback callback )
872 ConnectToGlobalSignal( &OnJavaScriptConfirm );
873 mJavaScriptConfirmCallback = callback;
877 void RegisterJavaScriptPromptCallback( Dali::WebEnginePlugin::JavaScriptPromptCallback callback )
881 ConnectToGlobalSignal( &OnJavaScriptPrompt );
882 mJavaScriptPromptCallback = callback;
888 ConnectToGlobalSignal( &OnClearHistory );
891 const std::string& GetUserAgent() const
896 void SetUserAgent( const std::string& userAgent )
898 mUserAgent = userAgent;
901 void ScrollBy( int dx, int dy )
903 mScrollPosition += Dali::Vector2( dx, dy );
904 if ( mScrollPosition.y + mScrollSize.height > mContentSize.height )
906 ConnectToGlobalSignal( &OnScrollEdge );
910 bool ScrollEdgeBy( int dx, int dy )
912 mScrollPosition += Dali::Vector2( dx, dy );
913 if ( mScrollPosition.y + mScrollSize.height > mContentSize.height )
915 ConnectToGlobalSignal( &OnScrollEdge );
920 void SetScrollPosition( int x, int y )
922 mScrollPosition.x = x;
923 mScrollPosition.y = y;
926 Dali::Vector2 GetScrollPosition() const
928 return mScrollPosition;
931 Dali::Vector2 GetScrollSize() const
936 Dali::Vector2 GetContentSize() const
941 void SetPageZoomFactor(float zoomFactor)
943 mPageZoomFactor = zoomFactor;
946 float GetPageZoomFactor() const
948 return mPageZoomFactor;
951 void SetTextZoomFactor(float zoomFactor)
953 mTextZoomFactor = zoomFactor;
956 float GetTextZoomFactor() const
958 return mTextZoomFactor;
961 float GetLoadProgressPercentage() const
966 void SetScaleFactor(float scaleFactor, Dali::Vector2 point)
968 mScaleFactor = scaleFactor;
971 float GetScaleFactor() const
976 Dali::PixelData GetScreenshot(Dali::Rect<int> viewArea, float scaleFactor)
978 uint32_t bufferSize = viewArea.width * viewArea.height * 4 ;
979 uint8_t* pixel = new uint8_t[ bufferSize ];
980 memset(pixel, 0xff, bufferSize);
981 return Dali::PixelData::New( pixel, bufferSize, viewArea.width, viewArea.height,
982 Dali::Pixel::Format::RGBA8888,
983 Dali::PixelData::ReleaseFunction::DELETE_ARRAY );
986 bool GetScreenshotAsynchronously(Dali::Rect<int> viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback)
990 ConnectToGlobalSignal( &OnScreenshotCaptured );
991 mScreenshotCapturedCallback = callback;
996 bool CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback)
1000 ConnectToGlobalSignal( &OnVideoPlaying );
1001 mVideoPlayingCallback = callback;
1006 void RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback)
1010 ConnectToGlobalSignal( &OnGeolocationPermission );
1011 mGeolocationPermissionCallback = callback;
1015 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal()
1017 return mPageLoadStartedSignal;
1020 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadInProgressSignal()
1022 return mPageLoadInProgressSignal;
1025 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal()
1027 return mPageLoadFinishedSignal;
1030 Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal()
1032 return mPageLoadErrorSignal;
1035 Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal()
1037 return mScrollEdgeReachedSignal;
1040 Dali::WebEnginePlugin::WebEngineUrlChangedSignalType& UrlChangedSignal()
1042 return mUrlChangedSignal;
1045 Dali::WebEnginePlugin::WebEngineFormRepostDecisionSignalType& FormRepostDecisionSignal()
1047 return mFormRepostDecisionSignal;
1050 Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& FrameRenderedSignal()
1052 return mFrameRenderedSignal;
1055 Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& RequestInterceptorSignal()
1057 return mRequestInterceptorSignal;
1060 Dali::WebEnginePlugin::WebEngineConsoleMessageSignalType& ConsoleMessageSignal()
1062 return mConsoleMessageSignal;
1065 Dali::WebEnginePlugin::WebEnginePolicyDecisionSignalType& PolicyDecisionSignal()
1067 return mPolicyDecisionSignal;
1070 Dali::WebEnginePlugin::WebEngineCertificateSignalType& CertificateConfirmSignal()
1072 return mCertificateConfirmSignal;
1075 Dali::WebEnginePlugin::WebEngineCertificateSignalType& SslCertificateChangedSignal()
1077 return mSslCertificateChangedSignal;
1080 Dali::WebEnginePlugin::WebEngineHttpAuthHandlerSignalType& HttpAuthHandlerSignal()
1082 return mHttpAuthHandlerSignal;
1086 std::vector<std::string> mHistory;
1087 size_t mCurrentPlusOnePos;
1088 std::string mUserAgent;
1090 Dali::WebEnginePlugin::WebEnginePageLoadSignalType mPageLoadStartedSignal;
1091 Dali::WebEnginePlugin::WebEnginePageLoadSignalType mPageLoadInProgressSignal;
1092 Dali::WebEnginePlugin::WebEnginePageLoadSignalType mPageLoadFinishedSignal;
1093 Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType mPageLoadErrorSignal;
1094 Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType mScrollEdgeReachedSignal;
1095 Dali::WebEnginePlugin::WebEngineUrlChangedSignalType mUrlChangedSignal;
1096 Dali::WebEnginePlugin::WebEngineFormRepostDecisionSignalType mFormRepostDecisionSignal;
1097 Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType mFrameRenderedSignal;
1098 Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType mRequestInterceptorSignal;
1099 Dali::WebEnginePlugin::WebEngineConsoleMessageSignalType mConsoleMessageSignal;
1100 Dali::WebEnginePlugin::WebEnginePolicyDecisionSignalType mPolicyDecisionSignal;
1101 Dali::WebEnginePlugin::WebEngineCertificateSignalType mCertificateConfirmSignal;
1102 Dali::WebEnginePlugin::WebEngineCertificateSignalType mSslCertificateChangedSignal;
1103 Dali::WebEnginePlugin::WebEngineHttpAuthHandlerSignalType mHttpAuthHandlerSignal;
1106 float mPageZoomFactor;
1107 float mTextZoomFactor;
1110 Dali::Vector2 mScrollPosition;
1111 Dali::Vector2 mScrollSize;
1112 Dali::Vector2 mContentSize;
1113 WebEngineBackForwardList* mockWebEngineBackForwardList;
1114 WebEngineContext* mockWebEngineContext;
1115 WebEngineCookieManager* mockWebEngineCookieManager;
1116 WebEngineSettings* mockWebEngineSettings;
1118 std::vector<JavaScriptEvaluatedResultCallback> mResultCallbacks;
1119 Dali::WebEnginePlugin::JavaScriptAlertCallback mJavaScriptAlertCallback;
1120 Dali::WebEnginePlugin::JavaScriptConfirmCallback mJavaScriptConfirmCallback;
1121 Dali::WebEnginePlugin::JavaScriptPromptCallback mJavaScriptPromptCallback;
1122 Dali::WebEnginePlugin::ScreenshotCapturedCallback mScreenshotCapturedCallback;
1123 Dali::WebEnginePlugin::VideoPlayingCallback mVideoPlayingCallback;
1124 Dali::WebEnginePlugin::GeolocationPermissionCallback mGeolocationPermissionCallback;
1133 DisconnectFromGlobalSignal( &OnGoBack );
1135 if( gInstance && gInstance->CanGoBack() )
1137 gInstance->mCurrentPlusOnePos--;
1144 DisconnectFromGlobalSignal( &OnGoForward );
1146 if( gInstance && gInstance->CanGoForward() )
1148 gInstance->mCurrentPlusOnePos++;
1155 DisconnectFromGlobalSignal( &OnLoadUrl );
1159 if( gInstance->mHistory.size() > gInstance->mCurrentPlusOnePos )
1161 gInstance->mHistory.erase( gInstance->mHistory.begin() + gInstance->mCurrentPlusOnePos, gInstance->mHistory.end() );
1163 gInstance->mHistory.push_back( gInstance->mUrl );
1164 gInstance->mCurrentPlusOnePos++;
1165 gInstance->mPageLoadStartedSignal.Emit( gInstance->mUrl );
1166 gInstance->mPageLoadInProgressSignal.Emit( gInstance->mUrl );
1167 gInstance->mPageLoadFinishedSignal.Emit( gInstance->mUrl );
1168 gInstance->mUrlChangedSignal.Emit( "http://new-test" );
1170 std::shared_ptr<Dali::WebEngineFormRepostDecision> repostDecision(new MockWebEngineFormRepostDecision());
1171 gInstance->mFormRepostDecisionSignal.Emit(std::move(repostDecision));
1172 gInstance->mFrameRenderedSignal.Emit();
1173 std::shared_ptr<Dali::WebEngineRequestInterceptor> interceptor(new MockWebEngineRequestInterceptor());
1174 gInstance->mRequestInterceptorSignal.Emit(std::move(interceptor));
1176 std::shared_ptr<Dali::WebEngineLoadError> error(new MockWebEngineLoadError(gInstance->mUrl));
1177 gInstance->mPageLoadErrorSignal.Emit(std::move(error));
1178 std::shared_ptr<Dali::WebEngineConsoleMessage> message(new MockWebEngineConsoleMessage());
1179 gInstance->mConsoleMessageSignal.Emit(std::move(message));
1180 std::shared_ptr<Dali::WebEnginePolicyDecision> policyDecision(new MockWebEnginePolicyDecision());
1181 gInstance->mPolicyDecisionSignal.Emit(std::move(policyDecision));
1183 std::shared_ptr<Dali::WebEngineCertificate> certificate(new MockWebEngineCertificate());
1184 gInstance->mCertificateConfirmSignal.Emit(std::move(certificate));
1185 std::shared_ptr<Dali::WebEngineCertificate> sslCertificate(new MockWebEngineCertificate());
1186 gInstance->mSslCertificateChangedSignal.Emit(std::move(sslCertificate));
1187 std::shared_ptr<Dali::WebEngineHttpAuthHandler> handler(new MockWebEngineHttpAuthHandler());
1188 gInstance->mHttpAuthHandlerSignal.Emit(std::move(handler));
1195 DisconnectFromGlobalSignal( &OnScrollEdge );
1199 gInstance->mScrollEdgeReachedSignal.Emit( Dali::WebEnginePlugin::ScrollEdge::BOTTOM );
1205 bool OnEvaluteJavaScript()
1207 DisconnectFromGlobalSignal( &OnEvaluteJavaScript );
1211 for( auto& func : gInstance->mResultCallbacks )
1215 gInstance->mResultCallbacks.clear();
1220 bool OnJavaScriptAlert()
1222 DisconnectFromGlobalSignal( &OnJavaScriptAlert );
1225 gInstance->mJavaScriptAlertCallback( "this is an alert popup." );
1230 bool OnJavaScriptConfirm()
1232 DisconnectFromGlobalSignal( &OnJavaScriptConfirm );
1235 gInstance->mJavaScriptConfirmCallback( "this is a confirm popup." );
1240 bool OnJavaScriptPrompt()
1242 DisconnectFromGlobalSignal( &OnJavaScriptPrompt );
1245 gInstance->mJavaScriptPromptCallback( "this is a prompt pompt.", "" );
1250 bool OnScreenshotCaptured()
1252 DisconnectFromGlobalSignal( &OnScreenshotCaptured );
1255 uint8_t* pixel = new uint8_t[ 2 * 2 * 4 ];
1256 memset(pixel, 0xff, 2 * 2 * 4);
1257 Dali::PixelData data = Dali::PixelData::New( pixel, 2 * 2 * 4, 2, 2,
1258 Dali::Pixel::Format::RGBA8888,
1259 Dali::PixelData::ReleaseFunction::DELETE_ARRAY );
1260 gInstance->mScreenshotCapturedCallback( data );
1265 bool OnVideoPlaying()
1267 DisconnectFromGlobalSignal( &OnVideoPlaying );
1270 gInstance->mVideoPlayingCallback( true );
1275 bool OnGeolocationPermission()
1277 DisconnectFromGlobalSignal( &OnGeolocationPermission );
1280 gInstance->mGeolocationPermissionCallback( "", "" );
1285 bool OnClearHistory()
1287 DisconnectFromGlobalSignal( &OnClearHistory );
1289 if( gInstance && gInstance->mCurrentPlusOnePos )
1291 std::string url = gInstance->mHistory[ gInstance->mCurrentPlusOnePos - 1 ];
1292 std::vector< std::string >().swap( gInstance->mHistory );
1293 gInstance->mHistory.push_back( url );
1294 gInstance->mCurrentPlusOnePos = 1;
1301 inline WebEngine& GetImplementation( Dali::WebEngine& webEngine )
1303 DALI_ASSERT_ALWAYS( webEngine && "WebEngine handle is empty." );
1304 BaseObject& handle = webEngine.GetBaseObject();
1305 return static_cast< Internal::Adaptor::WebEngine& >( handle );
1308 inline const WebEngine& GetImplementation( const Dali::WebEngine& webEngine )
1310 DALI_ASSERT_ALWAYS( webEngine && "WebEngine handle is empty." );
1311 const BaseObject& handle = webEngine.GetBaseObject();
1312 return static_cast< const Internal::Adaptor::WebEngine& >( handle );
1315 } // namespace Adaptor
1317 } // namespace Internal
1319 // Dali::WebEngine Implementation
1320 WebEngine::WebEngine()
1324 WebEngine::WebEngine( Internal::Adaptor::WebEngine* internal )
1325 : BaseHandle( internal )
1329 WebEngine::~WebEngine()
1333 WebEngine WebEngine::New()
1335 Internal::Adaptor::WebEngine* baseObject = new Internal::Adaptor::WebEngine();
1337 return WebEngine( baseObject );
1340 WebEngine::WebEngine( const WebEngine& WebEngine )
1341 : BaseHandle( WebEngine )
1345 WebEngine& WebEngine::operator=( const WebEngine& webEngine )
1347 BaseHandle::operator=( webEngine );
1351 WebEngine WebEngine::DownCast( BaseHandle handle )
1353 return WebEngine( dynamic_cast< Internal::Adaptor::WebEngine* >( handle.GetObjectPtr() ) );
1356 void WebEngine::Create( int width, int height, const std::string& locale, const std::string& timezoneId )
1360 void WebEngine::Create( int width, int height, int argc, char** argv )
1364 void WebEngine::Destroy()
1368 WebEngineSettings& WebEngine::GetSettings() const
1370 return Internal::Adaptor::GetImplementation( *this ).GetSettings();
1373 WebEngineContext& WebEngine::GetContext() const
1375 return Internal::Adaptor::GetImplementation( *this ).GetContext();
1378 WebEngineCookieManager& WebEngine::GetCookieManager() const
1380 return Internal::Adaptor::GetImplementation( *this ).GetCookieManager();
1383 WebEngineBackForwardList& WebEngine::GetBackForwardList() const
1385 return Internal::Adaptor::GetImplementation( *this ).GetBackForwardList();
1388 void WebEngine::LoadUrl( const std::string& url )
1390 return Internal::Adaptor::GetImplementation( *this ).LoadUrl( url );
1393 std::string WebEngine::GetTitle() const
1395 return Internal::Adaptor::GetImplementation( *this ).GetTitle();
1398 Dali::PixelData WebEngine::GetFavicon() const
1400 return Internal::Adaptor::GetImplementation( *this ).GetFavicon();
1403 const std::string& WebEngine::GetUrl()
1405 return Internal::Adaptor::GetImplementation( *this ).GetUrl();
1408 NativeImageInterfacePtr WebEngine::GetNativeImageSource()
1411 Dali::NativeImageSourcePtr sourcePtr = Dali::NativeImageSource::New( source );
1415 void WebEngine::LoadHtmlString( const std::string& htmlString )
1419 bool WebEngine::LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl)
1424 bool WebEngine::LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri)
1429 void WebEngine::Reload()
1433 bool WebEngine::ReloadWithoutCache()
1438 void WebEngine::StopLoading()
1442 void WebEngine::Suspend()
1446 void WebEngine::Resume()
1450 void WebEngine::SuspendNetworkLoading()
1454 void WebEngine::ResumeNetworkLoading()
1458 bool WebEngine::AddCustomHeader(const std::string& name, const std::string& value)
1463 bool WebEngine::RemoveCustomHeader(const std::string& name)
1468 uint32_t WebEngine::StartInspectorServer(uint32_t port)
1473 bool WebEngine::StopInspectorServer()
1478 bool WebEngine::CanGoForward()
1480 return Internal::Adaptor::GetImplementation( *this ).CanGoForward();
1483 void WebEngine::GoForward()
1485 Internal::Adaptor::GetImplementation( *this ).GoForward();
1488 bool WebEngine::CanGoBack()
1490 return Internal::Adaptor::GetImplementation( *this ).CanGoBack();
1493 void WebEngine::GoBack()
1495 Internal::Adaptor::GetImplementation( *this ).GoBack();
1498 void WebEngine::EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler )
1500 Internal::Adaptor::GetImplementation( *this ).EvaluateJavaScript( script, resultHandler );
1503 void WebEngine::AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void(const std::string&) > handler )
1507 void WebEngine::RegisterJavaScriptAlertCallback( Dali::WebEnginePlugin::JavaScriptAlertCallback callback )
1509 Internal::Adaptor::GetImplementation( *this ).RegisterJavaScriptAlertCallback( callback );
1512 void WebEngine::JavaScriptAlertReply()
1516 void WebEngine::RegisterJavaScriptConfirmCallback( Dali::WebEnginePlugin::JavaScriptConfirmCallback callback )
1518 Internal::Adaptor::GetImplementation( *this ).RegisterJavaScriptConfirmCallback( callback );
1521 void WebEngine::JavaScriptConfirmReply( bool confirmed )
1525 void WebEngine::RegisterJavaScriptPromptCallback( Dali::WebEnginePlugin::JavaScriptPromptCallback callback )
1527 Internal::Adaptor::GetImplementation( *this ).RegisterJavaScriptPromptCallback( callback );
1530 void WebEngine::JavaScriptPromptReply( const std::string& result )
1534 void WebEngine::ClearAllTilesResources()
1538 void WebEngine::ClearHistory()
1540 Internal::Adaptor::GetImplementation( *this ).ClearHistory();
1543 void WebEngine::SetScaleFactor(float scaleFactor, Dali::Vector2 point)
1545 Internal::Adaptor::GetImplementation( *this ).SetScaleFactor(scaleFactor, point);
1548 float WebEngine::GetScaleFactor() const
1550 return Internal::Adaptor::GetImplementation( *this ).GetScaleFactor();
1553 void WebEngine::ActivateAccessibility(bool activated)
1557 bool WebEngine::HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount)
1562 void WebEngine::AddDynamicCertificatePath(const std::string& host, const std::string& certPath)
1566 Dali::PixelData WebEngine::GetScreenshot(Dali::Rect<int> viewArea, float scaleFactor)
1568 return Internal::Adaptor::GetImplementation( *this ).GetScreenshot(viewArea, scaleFactor);
1571 bool WebEngine::GetScreenshotAsynchronously(Dali::Rect<int> viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback)
1573 return Internal::Adaptor::GetImplementation( *this ).GetScreenshotAsynchronously(viewArea, scaleFactor, callback);
1576 bool WebEngine::CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback)
1578 return Internal::Adaptor::GetImplementation( *this ).CheckVideoPlayingAsynchronously(callback);
1581 void WebEngine::RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback)
1583 Internal::Adaptor::GetImplementation( *this ).RegisterGeolocationPermissionCallback(callback);
1586 const std::string& WebEngine::GetUserAgent() const
1588 return Internal::Adaptor::GetImplementation( *this ).GetUserAgent();
1591 void WebEngine::SetUserAgent( const std::string& userAgent )
1593 Internal::Adaptor::GetImplementation( *this ).SetUserAgent( userAgent );
1596 void WebEngine::ScrollBy( int dx, int dy )
1598 Internal::Adaptor::GetImplementation( *this ).ScrollBy( dx, dy );
1601 bool WebEngine::ScrollEdgeBy( int dx, int dy )
1603 return Internal::Adaptor::GetImplementation( *this ).ScrollEdgeBy( dx, dy );
1606 void WebEngine::SetScrollPosition( int x, int y )
1608 Internal::Adaptor::GetImplementation( *this ).SetScrollPosition( x, y );
1611 Dali::Vector2 WebEngine::GetScrollPosition() const
1613 return Internal::Adaptor::GetImplementation( *this ).GetScrollPosition();
1616 Dali::Vector2 WebEngine::GetScrollSize() const
1618 return Internal::Adaptor::GetImplementation( *this ).GetScrollSize();
1621 Dali::Vector2 WebEngine::GetContentSize() const
1623 return Internal::Adaptor::GetImplementation( *this ).GetContentSize();
1626 void WebEngine::SetSize( int width, int height )
1630 void WebEngine::SetDocumentBackgroundColor(Dali::Vector4 color)
1634 void WebEngine::ClearTilesWhenHidden(bool cleared)
1638 void WebEngine::SetTileCoverAreaMultiplier(float multiplier)
1642 void WebEngine::EnableCursorByClient(bool enabled)
1646 std::string WebEngine::GetSelectedText() const
1651 bool WebEngine::SendTouchEvent( const TouchEvent& touch )
1656 bool WebEngine::SendKeyEvent( const KeyEvent& event )
1661 bool WebEngine::SendHoverEvent( const HoverEvent& event )
1666 bool WebEngine::SendWheelEvent( const WheelEvent& event )
1671 void WebEngine::SetFocus( bool focused )
1675 void WebEngine::SetPageZoomFactor(float zoomFactor)
1677 Internal::Adaptor::GetImplementation( *this ).SetPageZoomFactor(zoomFactor);
1680 float WebEngine::GetPageZoomFactor() const
1682 return Internal::Adaptor::GetImplementation( *this ).GetPageZoomFactor();
1685 void WebEngine::SetTextZoomFactor(float zoomFactor)
1687 Internal::Adaptor::GetImplementation( *this ).SetTextZoomFactor(zoomFactor);
1690 float WebEngine::GetTextZoomFactor() const
1692 return Internal::Adaptor::GetImplementation( *this ).GetTextZoomFactor();
1695 float WebEngine::GetLoadProgressPercentage() const
1697 return Internal::Adaptor::GetImplementation( *this ).GetLoadProgressPercentage();
1700 void WebEngine::UpdateDisplayArea( Dali::Rect< int > displayArea )
1704 void WebEngine::EnableVideoHole( bool enabled )
1708 void WebEngine::EnableMouseEvents( bool enabled )
1712 void WebEngine::EnableKeyEvents( bool enabled )
1716 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadStartedSignal()
1718 return Internal::Adaptor::GetImplementation( *this ).PageLoadStartedSignal();
1721 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadInProgressSignal()
1723 return Internal::Adaptor::GetImplementation( *this ).PageLoadInProgressSignal();
1726 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadFinishedSignal()
1728 return Internal::Adaptor::GetImplementation( *this ).PageLoadFinishedSignal();
1731 Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& WebEngine::PageLoadErrorSignal()
1733 return Internal::Adaptor::GetImplementation( *this ).PageLoadErrorSignal();
1736 Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& WebEngine::ScrollEdgeReachedSignal()
1738 return Internal::Adaptor::GetImplementation( *this ).ScrollEdgeReachedSignal();
1741 Dali::WebEnginePlugin::WebEngineUrlChangedSignalType& WebEngine::UrlChangedSignal()
1743 return Internal::Adaptor::GetImplementation( *this ).UrlChangedSignal();
1746 Dali::WebEnginePlugin::WebEngineFormRepostDecisionSignalType& WebEngine::FormRepostDecisionSignal()
1748 return Internal::Adaptor::GetImplementation(*this).FormRepostDecisionSignal();
1751 Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& WebEngine::FrameRenderedSignal()
1753 return Internal::Adaptor::GetImplementation(*this).FrameRenderedSignal();
1756 Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& WebEngine::RequestInterceptorSignal()
1758 return Internal::Adaptor::GetImplementation(*this).RequestInterceptorSignal();
1761 Dali::WebEnginePlugin::WebEngineConsoleMessageSignalType& WebEngine::ConsoleMessageSignal()
1763 return Internal::Adaptor::GetImplementation(*this).ConsoleMessageSignal();
1766 Dali::WebEnginePlugin::WebEnginePolicyDecisionSignalType& WebEngine::PolicyDecisionSignal()
1768 return Internal::Adaptor::GetImplementation(*this).PolicyDecisionSignal();
1771 Dali::WebEnginePlugin::WebEngineCertificateSignalType& WebEngine::CertificateConfirmSignal()
1773 return Internal::Adaptor::GetImplementation(*this).CertificateConfirmSignal();
1776 Dali::WebEnginePlugin::WebEngineCertificateSignalType& WebEngine::SslCertificateChangedSignal()
1778 return Internal::Adaptor::GetImplementation(*this).SslCertificateChangedSignal();
1781 Dali::WebEnginePlugin::WebEngineHttpAuthHandlerSignalType& WebEngine::HttpAuthHandlerSignal()
1783 return Internal::Adaptor::GetImplementation(*this).HttpAuthHandlerSignal();
1786 } // namespace Dali;