From: huayong.xu Date: Thu, 10 Dec 2020 10:33:27 +0000 (+0800) Subject: Implement some new ewk apis in web view. X-Git-Tag: dali_2.0.11~7^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=d30d320c158f38d9c1ff49e01627467d3950698d Implement some new ewk apis in web view. Support some new APIs, e.g. BackForwardList, Context, CookieManager, Settings. Change-Id: I84a9a60ed80c6da0c3c063af5ddfec8a19c3da2b --- diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-web-engine.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-web-engine.cpp index 9d7a582..e5077fe 100755 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-web-engine.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-web-engine.cpp @@ -18,6 +18,11 @@ #include "toolkit-timer.h" #include +#include +#include +#include +#include +#include #include #include #include @@ -58,6 +63,228 @@ static void DisconnectFromGlobalSignal( bool (*func)() ) } } +class MockWebEngineContext : public Dali::WebEngineContext +{ +public: + MockWebEngineContext() + : mockModel( Dali::WebEngineContext::CacheModel::DOCUMENT_VIEWER ) + { + } + + Dali::WebEngineContext::CacheModel GetCacheModel() const override + { + return mockModel; + } + + void SetCacheModel( Dali::WebEngineContext::CacheModel cacheModel ) override + { + mockModel = cacheModel; + } + + void SetProxyUri( const std::string& uri ) override + { + } + + void SetDefaultProxyAuth( const std::string& username, const std::string& password ) override + { + } + + void SetCertificateFilePath( const std::string& certificatePath ) override + { + } + + void DeleteWebDatabase() override + { + } + + void DeleteWebStorage() override + { + } + + void DeleteLocalFileSystem() override + { + } + + void DisableCache( bool cacheDisabled ) override + { + } + + void ClearCache() override + { + } + +private: + Dali::WebEngineContext::CacheModel mockModel; +}; + +class MockWebEngineCookieManager : public Dali::WebEngineCookieManager +{ +public: + MockWebEngineCookieManager() + : mockCookieAcceptPolicy( Dali::WebEngineCookieManager::CookieAcceptPolicy::NO_THIRD_PARTY ) + { + } + + void SetCookieAcceptPolicy( Dali::WebEngineCookieManager::CookieAcceptPolicy policy ) override + { + mockCookieAcceptPolicy = policy; + } + + Dali::WebEngineCookieManager::CookieAcceptPolicy GetCookieAcceptPolicy() const override + { + return mockCookieAcceptPolicy; + } + + void ClearCookies() override + { + } + + void SetPersistentStorage( const std::string& path, Dali::WebEngineCookieManager::CookiePersistentStorage storage ) override + { + } + +private: + Dali::WebEngineCookieManager::CookieAcceptPolicy mockCookieAcceptPolicy; +}; + +class MockWebEngineBackForwardListItem : public Dali::WebEngineBackForwardListItem +{ +public: + MockWebEngineBackForwardListItem() + : mockUrl( "http://url" ), + mockTitle( "title" ), + mockOriginalUrl( "http://originalurl" ) + { + } + + std::string GetUrl() const override + { + return mockUrl; + } + + std::string GetTitle() const override + { + return mockTitle; + } + + std::string GetOriginalUrl() const override + { + return mockOriginalUrl; + } + +private: + std::string mockUrl; + std::string mockTitle; + std::string mockOriginalUrl; +}; + +class MockWebEngineBackForwardList : public Dali::WebEngineBackForwardList +{ +public: + MockWebEngineBackForwardList( ) + : mockItem(), + pMockItem( &mockItem ) + { + } + + Dali::WebEngineBackForwardListItem& GetCurrentItem() const override + { + return *pMockItem; + } + + Dali::WebEngineBackForwardListItem& GetItemAtIndex( uint32_t index ) const override + { + return *pMockItem; + } + + uint32_t GetItemCount() const override + { + return 1; + } + +private: + MockWebEngineBackForwardListItem mockItem; + WebEngineBackForwardListItem* pMockItem; +}; + +class MockWebEngineSettings : public WebEngineSettings +{ +public: + MockWebEngineSettings() + : mockDefaultFontSize( 16 ), + mockJavaScriptEnabled( true ), + mockImageLoadedAutomatically( true ), + mockDefaultTextEncodingName() + { + } + + uint32_t GetDefaultFontSize() const override + { + return mockDefaultFontSize; + } + + void SetDefaultFontSize( uint32_t size ) override + { + mockDefaultFontSize = size; + } + + bool IsJavaScriptEnabled() const override + { + return mockJavaScriptEnabled; + } + + void EnableJavaScript( bool enabled ) override + { + mockJavaScriptEnabled = enabled; + } + + bool AreImagesLoadedAutomatically() const override + { + return mockImageLoadedAutomatically; + } + + void AllowImagesLoadAutomatically( bool automatic ) override + { + mockImageLoadedAutomatically = automatic; + } + + std::string GetDefaultTextEncodingName() const override + { + return mockDefaultTextEncodingName; + } + + void SetDefaultTextEncodingName( const std::string& defaultTextEncodingName ) override + { + mockDefaultTextEncodingName = defaultTextEncodingName; + } + + void AllowMixedContents( bool allowed ) override + { + } + + void EnableSpatialNavigation( bool enabled ) override + { + } + + void EnableWebSecurity( bool enabled ) override + { + } + + void AllowFileAccessFromExternalUrl( bool allowed ) override + { + } + + void AllowScriptsOpenWindows( bool allowed ) override + { + } + +private: + int mockDefaultFontSize; + bool mockJavaScriptEnabled; + bool mockImageLoadedAutomatically; + std::string mockDefaultTextEncodingName; +}; + class WebEngine: public Dali::BaseObject { public: @@ -65,13 +292,7 @@ public: WebEngine() : mUrl() , mCurrentPlusOnePos( 0 ) - , mCacheModel( Dali::WebEnginePlugin::CacheModel::DOCUMENT_VIEWER ) - , mCookieAcceptPolicy( Dali::WebEnginePlugin::CookieAcceptPolicy::NO_THIRD_PARTY ) , mUserAgent() - , mEnableJavaScript( true ) - , mLoadImagesAutomatically( true ) - , mDefaultTextEncodingName() - , mDefaultFontSize( 16 ) , mEvaluating( false ) , mScrollPosition( 0, 0 ) , mScrollSize( 500, 500 ) @@ -79,6 +300,11 @@ public: { gInstanceCount++; gInstance = this; + + mockWebEngineSettings = new MockWebEngineSettings(); + mockWebEngineContext = new MockWebEngineContext(); + mockWebEngineCookieManager = new MockWebEngineCookieManager(); + mockWebEngineBackForwardList = new MockWebEngineBackForwardList(); } virtual ~WebEngine() @@ -88,6 +314,31 @@ public: { gInstance = NULL; } + + delete mockWebEngineSettings; + delete mockWebEngineContext; + delete mockWebEngineCookieManager; + delete mockWebEngineBackForwardList; + } + + Dali::WebEngineSettings& GetSettings() const + { + return *mockWebEngineSettings; + } + + Dali::WebEngineContext& GetContext() const + { + return *mockWebEngineContext; + } + + Dali::WebEngineCookieManager& GetCookieManager() const + { + return *mockWebEngineCookieManager; + } + + Dali::WebEngineBackForwardList& GetBackForwardList() const + { + return *mockWebEngineBackForwardList; } void LoadUrl( const std::string& url ) @@ -138,26 +389,6 @@ public: ConnectToGlobalSignal( &OnClearHistory ); } - Dali::WebEnginePlugin::CacheModel GetCacheModel() const - { - return mCacheModel; - } - - void SetCacheModel( Dali::WebEnginePlugin::CacheModel cacheModel ) - { - mCacheModel = cacheModel; - } - - Dali::WebEnginePlugin::CookieAcceptPolicy GetCookieAcceptPolicy() const - { - return mCookieAcceptPolicy; - } - - void SetCookieAcceptPolicy( Dali::WebEnginePlugin::CookieAcceptPolicy policy ) - { - mCookieAcceptPolicy = policy; - } - const std::string& GetUserAgent() const { return mUserAgent; @@ -168,46 +399,6 @@ public: mUserAgent = userAgent; } - bool IsJavaScriptEnabled() const - { - return mEnableJavaScript; - } - - void EnableJavaScript( bool enabled ) - { - mEnableJavaScript = enabled; - } - - bool AreImagesAutomaticallyLoaded() const - { - return mLoadImagesAutomatically; - } - - void LoadImagesAutomatically( bool automatic ) - { - mLoadImagesAutomatically = automatic; - } - - const std::string& GetDefaultTextEncodingName() const - { - return mDefaultTextEncodingName; - } - - void SetDefaultTextEncodingName( const std::string& defaultTextEncodingName ) - { - mDefaultTextEncodingName = defaultTextEncodingName; - } - - int GetDefaultFontSize() const - { - return mDefaultFontSize; - } - - void SetDefaultFontSize( int defaultFontSize ) - { - mDefaultFontSize = defaultFontSize; - } - void ScrollBy( int dx, int dy ) { mScrollPosition += Dali::Vector2( dx, dy ); @@ -264,13 +455,7 @@ public: std::string mUrl; std::vector< std::string > mHistory; size_t mCurrentPlusOnePos; - Dali::WebEnginePlugin::CacheModel mCacheModel; - Dali::WebEnginePlugin::CookieAcceptPolicy mCookieAcceptPolicy; std::string mUserAgent; - bool mEnableJavaScript; - bool mLoadImagesAutomatically; - std::string mDefaultTextEncodingName; - int mDefaultFontSize; Dali::WebEnginePlugin::WebEnginePageLoadSignalType mPageLoadStartedSignal; Dali::WebEnginePlugin::WebEnginePageLoadSignalType mPageLoadFinishedSignal; Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType mPageLoadErrorSignal; @@ -281,6 +466,10 @@ public: Dali::Vector2 mScrollPosition; Dali::Vector2 mScrollSize; Dali::Vector2 mContentSize; + WebEngineBackForwardList* mockWebEngineBackForwardList; + WebEngineContext* mockWebEngineContext; + WebEngineCookieManager* mockWebEngineCookieManager; + WebEngineSettings* mockWebEngineSettings; }; inline WebEngine& GetImplementation( Dali::WebEngine& webEngine ) @@ -419,6 +608,26 @@ void WebEngine::Destroy() { } +WebEngineSettings& WebEngine::GetSettings() const +{ + return Internal::Adaptor::GetImplementation( *this ).GetSettings(); +} + +WebEngineContext& WebEngine::GetContext() const +{ + return Internal::Adaptor::GetImplementation( *this ).GetContext(); +} + +WebEngineCookieManager& WebEngine::GetCookieManager() const +{ + return Internal::Adaptor::GetImplementation( *this ).GetCookieManager(); +} + +WebEngineBackForwardList& WebEngine::GetBackForwardList() const +{ + return Internal::Adaptor::GetImplementation( *this ).GetBackForwardList(); +} + void WebEngine::LoadUrl( const std::string& url ) { return Internal::Adaptor::GetImplementation( *this ).LoadUrl( url ); @@ -436,7 +645,7 @@ NativeImageInterfacePtr WebEngine::GetNativeImageSource() return sourcePtr; } -void WebEngine::LoadHTMLString( const std::string& htmlString ) +void WebEngine::LoadHtmlString( const std::string& htmlString ) { } @@ -490,34 +699,6 @@ void WebEngine::ClearHistory() Internal::Adaptor::GetImplementation( *this ).ClearHistory(); } -void WebEngine::ClearCache() -{ -} - -void WebEngine::ClearCookies() -{ -} - -Dali::WebEnginePlugin::CacheModel WebEngine::GetCacheModel() const -{ - return Internal::Adaptor::GetImplementation( *this ).GetCacheModel(); -} - -void WebEngine::SetCacheModel( Dali::WebEnginePlugin::CacheModel cacheModel ) -{ - Internal::Adaptor::GetImplementation( *this ).SetCacheModel( cacheModel ); -} - -Dali::WebEnginePlugin::CookieAcceptPolicy WebEngine::GetCookieAcceptPolicy() const -{ - return Internal::Adaptor::GetImplementation( *this ).GetCookieAcceptPolicy(); -} - -void WebEngine::SetCookieAcceptPolicy( Dali::WebEnginePlugin::CookieAcceptPolicy policy ) -{ - Internal::Adaptor::GetImplementation( *this ).SetCookieAcceptPolicy( policy ); -} - const std::string& WebEngine::GetUserAgent() const { return Internal::Adaptor::GetImplementation( *this ).GetUserAgent(); @@ -528,46 +709,6 @@ void WebEngine::SetUserAgent( const std::string& userAgent ) Internal::Adaptor::GetImplementation( *this ).SetUserAgent( userAgent ); } -bool WebEngine::IsJavaScriptEnabled() const -{ - return Internal::Adaptor::GetImplementation( *this ).IsJavaScriptEnabled(); -} - -void WebEngine::EnableJavaScript( bool enabled ) -{ - Internal::Adaptor::GetImplementation( *this ).EnableJavaScript( enabled ); -} - -bool WebEngine::AreImagesAutomaticallyLoaded() const -{ - return Internal::Adaptor::GetImplementation( *this ).AreImagesAutomaticallyLoaded(); -} - -void WebEngine::LoadImagesAutomatically( bool automatic ) -{ - Internal::Adaptor::GetImplementation( *this ).LoadImagesAutomatically( automatic ); -} - -const std::string& WebEngine::GetDefaultTextEncodingName() const -{ - return Internal::Adaptor::GetImplementation( *this ).GetDefaultTextEncodingName(); -} - -void WebEngine::SetDefaultTextEncodingName( const std::string& defaultTextEncodingName ) -{ - Internal::Adaptor::GetImplementation( *this ).SetDefaultTextEncodingName( defaultTextEncodingName ); -} - -int WebEngine::GetDefaultFontSize() const -{ - return Internal::Adaptor::GetImplementation( *this ).GetDefaultFontSize(); -} - -void WebEngine::SetDefaultFontSize( int defaultFontSize ) -{ - Internal::Adaptor::GetImplementation( *this ).SetDefaultFontSize( defaultFontSize ); -} - void WebEngine::ScrollBy( int dx, int dy ) { Internal::Adaptor::GetImplementation( *this ).ScrollBy( dx, dy ); diff --git a/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp index 0ca47b6..2088d90 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp @@ -25,6 +25,11 @@ #include #include #include +#include +#include +#include +#include +#include #include @@ -207,8 +212,6 @@ int UtcDaliWebViewPageNavigation(void) view.Reload(); view.StopLoading(); view.ClearHistory(); - view.ClearCache(); - view.ClearCookies(); Test::EmitGlobalTimerSignal(); DALI_TEST_CHECK( !view.CanGoBack() ); DALI_TEST_CHECK( !view.CanGoForward() ); @@ -286,211 +289,95 @@ int UtcDaliWebViewFocusGainedAndLost(void) END_TEST; } -int UtcDaliWebViewProperty1(void) +int UtcDaliWebViewGetWebBackForwardList(void) { - // URL ToolkitTestApplication application; WebView view = WebView::New(); DALI_TEST_CHECK( view ); - std::string local; - view.SetProperty( WebView::Property::URL, TEST_URL1 ); - Property::Value val = view.GetProperty( WebView::Property::URL ); - DALI_TEST_CHECK( val.Get( local ) ); - DALI_TEST_EQUALS( local, TEST_URL1, TEST_LOCATION ); + Dali::Toolkit::WebBackForwardList* bfList = view.GetBackForwardList(); + DALI_TEST_CHECK( bfList != 0 ); END_TEST; } -int UtcDaliWebViewProperty2(void) +int UtcDaliWebViewGetWebContext(void) { - // CACHE_MODEL ToolkitTestApplication application; WebView view = WebView::New(); DALI_TEST_CHECK( view ); - const std::string kDefaultValue = "DOCUMENT_VIEWER"; - const WebView::CacheModel::Type kTestEnum = WebView::CacheModel::PRIMARY_WEB_BROWSER; - const std::string kTestValue = "PRIMARY_WEB_BROWSER"; - - // Check default value - std::string output; - Property::Value value = view.GetProperty( WebView::Property::CACHE_MODEL ); - DALI_TEST_CHECK( value.Get( output ) ); - DALI_TEST_EQUALS( output, kDefaultValue, TEST_LOCATION ); - - // Check Set/GetProperty - view.SetProperty( WebView::Property::CACHE_MODEL, kTestEnum ); - value = view.GetProperty( WebView::Property::CACHE_MODEL ); - DALI_TEST_CHECK( value.Get( output ) ); - DALI_TEST_EQUALS( output, kTestValue, TEST_LOCATION ); - - view.SetProperty( WebView::Property::CACHE_MODEL, kTestValue ); - value = view.GetProperty( WebView::Property::CACHE_MODEL ); - DALI_TEST_CHECK( value.Get( output ) ); - DALI_TEST_EQUALS( output, kTestValue, TEST_LOCATION ); + Dali::Toolkit::WebContext* context = view.GetContext(); + DALI_TEST_CHECK( context != 0 ); END_TEST; } -int UtcDaliWebViewProperty3(void) +int UtcDaliWebViewGetWebCookieManager(void) { - // COOKIE_ACCEPT_POLICY ToolkitTestApplication application; WebView view = WebView::New(); DALI_TEST_CHECK( view ); - const std::string kDefaultValue = "NO_THIRD_PARTY"; - const WebView::CookieAcceptPolicy::Type kTestEnum = WebView::CookieAcceptPolicy::NEVER; - const std::string kTestValue = "NEVER"; - - // Check default value - std::string output; - Property::Value value = view.GetProperty( WebView::Property::COOKIE_ACCEPT_POLICY ); - DALI_TEST_CHECK( value.Get( output ) ); - DALI_TEST_EQUALS( output, kDefaultValue, TEST_LOCATION ); - - // Check Set/GetProperty - view.SetProperty( WebView::Property::COOKIE_ACCEPT_POLICY, kTestEnum ); - value = view.GetProperty( WebView::Property::COOKIE_ACCEPT_POLICY ); - DALI_TEST_CHECK( value.Get( output ) ); - DALI_TEST_EQUALS( output, kTestValue, TEST_LOCATION ); - - view.SetProperty( WebView::Property::COOKIE_ACCEPT_POLICY, kTestValue ); - value = view.GetProperty( WebView::Property::COOKIE_ACCEPT_POLICY ); - DALI_TEST_CHECK( value.Get( output ) ); - DALI_TEST_EQUALS( output, kTestValue, TEST_LOCATION ); + Dali::Toolkit::WebCookieManager* cookieManager = view.GetCookieManager(); + DALI_TEST_CHECK( cookieManager != 0 ); END_TEST; } -int UtcDaliWebViewProperty4(void) +int UtcDaliWebViewGetWebSettings(void) { - // USER_AGENT ToolkitTestApplication application; WebView view = WebView::New(); DALI_TEST_CHECK( view ); - const std::string kDefaultValue; - const std::string kTestValue = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"; - - // Check default value - std::string output; - Property::Value value = view.GetProperty( WebView::Property::USER_AGENT ); - DALI_TEST_CHECK( value.Get( output ) ); - DALI_TEST_EQUALS( output, kDefaultValue, TEST_LOCATION ); - - // Check Set/GetProperty - view.SetProperty( WebView::Property::USER_AGENT, kTestValue ); - value = view.GetProperty( WebView::Property::USER_AGENT ); - DALI_TEST_CHECK( value.Get( output ) ); - DALI_TEST_EQUALS( output, kTestValue, TEST_LOCATION ); + Dali::Toolkit::WebSettings* settings = view.GetSettings(); + DALI_TEST_CHECK( settings != 0 ); END_TEST; } -int UtcDaliWebViewProperty5(void) -{ - // ENABLE_JAVASCRIPT - ToolkitTestApplication application; - - WebView view = WebView::New(); - DALI_TEST_CHECK( view ); - - const bool kDefaultValue = true; - const bool kTestValue = false; - - // Check default value - bool output; - Property::Value value = view.GetProperty( WebView::Property::ENABLE_JAVASCRIPT ); - DALI_TEST_CHECK( value.Get( output ) ); - DALI_TEST_EQUALS( output, kDefaultValue, TEST_LOCATION ); - - // Check Set/GetProperty - view.SetProperty( WebView::Property::ENABLE_JAVASCRIPT, kTestValue ); - value = view.GetProperty( WebView::Property::ENABLE_JAVASCRIPT ); - DALI_TEST_CHECK( value.Get( output ) ); - DALI_TEST_EQUALS( output, kTestValue, TEST_LOCATION ); - - END_TEST; -} - -int UtcDaliWebViewProperty6(void) +int UtcDaliWebViewProperty1(void) { - // LOAD_IMAGES_AUTOMATICALLY + // URL ToolkitTestApplication application; WebView view = WebView::New(); DALI_TEST_CHECK( view ); - const bool kDefaultValue = true; - const bool kTestValue = false; - - // Check default value - bool output; - Property::Value value = view.GetProperty( WebView::Property::LOAD_IMAGES_AUTOMATICALLY ); - DALI_TEST_CHECK( value.Get( output ) ); - DALI_TEST_EQUALS( output, kDefaultValue, TEST_LOCATION ); - - // Check Set/GetProperty - view.SetProperty( WebView::Property::LOAD_IMAGES_AUTOMATICALLY, kTestValue ); - value = view.GetProperty( WebView::Property::LOAD_IMAGES_AUTOMATICALLY ); - DALI_TEST_CHECK( value.Get( output ) ); - DALI_TEST_EQUALS( output, kTestValue, TEST_LOCATION ); + std::string local; + view.SetProperty( WebView::Property::URL, TEST_URL1 ); + Property::Value val = view.GetProperty( WebView::Property::URL ); + DALI_TEST_CHECK( val.Get( local ) ); + DALI_TEST_EQUALS( local, TEST_URL1, TEST_LOCATION ); END_TEST; } -int UtcDaliWebViewProperty7(void) +int UtcDaliWebViewProperty4(void) { - // DEFAULT_TEXT_ENCODING_NAME + // USER_AGENT ToolkitTestApplication application; WebView view = WebView::New(); DALI_TEST_CHECK( view ); const std::string kDefaultValue; - const std::string kTestValue = "UTF-8"; + const std::string kTestValue = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"; // Check default value std::string output; - Property::Value value = view.GetProperty( WebView::Property::DEFAULT_TEXT_ENCODING_NAME ); - DALI_TEST_CHECK( value.Get( output ) ); - DALI_TEST_EQUALS( output, kDefaultValue, TEST_LOCATION ); - - // Check Set/GetProperty - view.SetProperty( WebView::Property::DEFAULT_TEXT_ENCODING_NAME, kTestValue ); - value = view.GetProperty( WebView::Property::DEFAULT_TEXT_ENCODING_NAME ); - DALI_TEST_CHECK( value.Get( output ) ); - DALI_TEST_EQUALS( output, kTestValue, TEST_LOCATION ); - - END_TEST; -} - -int UtcDaliWebViewProperty8(void) -{ - // DEFAULT_FONT_SIZE - ToolkitTestApplication application; - - WebView view = WebView::New(); - DALI_TEST_CHECK( view ); - - const int kDefaultValue = 16; - const int kTestValue = 26; - - // Check default value - int output; - Property::Value value = view.GetProperty( WebView::Property::DEFAULT_FONT_SIZE ); + Property::Value value = view.GetProperty( WebView::Property::USER_AGENT ); DALI_TEST_CHECK( value.Get( output ) ); DALI_TEST_EQUALS( output, kDefaultValue, TEST_LOCATION ); // Check Set/GetProperty - view.SetProperty( WebView::Property::DEFAULT_FONT_SIZE, kTestValue ); - value = view.GetProperty( WebView::Property::DEFAULT_FONT_SIZE ); + view.SetProperty( WebView::Property::USER_AGENT, kTestValue ); + value = view.GetProperty( WebView::Property::USER_AGENT ); DALI_TEST_CHECK( value.Get( output ) ); DALI_TEST_EQUALS( output, kTestValue, TEST_LOCATION ); @@ -569,7 +456,7 @@ int UtcDaliWebViewEvaluteJavaScript(void) WebView view = WebView::New( "ko-KR", "Asia/Seoul" ); - view.LoadHTMLString( "Hello World!" ); + view.LoadHtmlString( "Hello World!" ); view.EvaluateJavaScript( "jsObject.postMessage('Hello')" ); view.EvaluateJavaScript( "jsObject.postMessage('World')", OnEvaluateJavaScript ); Test::EmitGlobalTimerSignal(); @@ -579,14 +466,13 @@ int UtcDaliWebViewEvaluteJavaScript(void) END_TEST; } - int UtcDaliWebViewMethodsForCoverage(void) { ToolkitTestApplication application; WebView view = WebView::New( "ko-KR", "Asia/Seoul" ); - view.LoadHTMLString( "Hello World!" ); + view.LoadHtmlString( "Hello World!" ); view.AddJavaScriptMessageHandler( "jsObject", []( const std::string& arg ) { } @@ -596,3 +482,227 @@ int UtcDaliWebViewMethodsForCoverage(void) END_TEST; } + +// test cases for web backforward list. + +int UtcDaliWebBackForwardListCheckItem(void) +{ + ToolkitTestApplication application; + + WebView view = WebView::New(); + DALI_TEST_CHECK( view ); + + Dali::Toolkit::WebBackForwardList* bfList = view.GetBackForwardList(); + DALI_TEST_CHECK( bfList != 0 ) + + unsigned int itemCount = bfList->GetItemCount(); + DALI_TEST_CHECK( itemCount == 1 ) + + Dali::Toolkit::WebBackForwardListItem* citem = bfList->GetCurrentItem(); + DALI_TEST_CHECK( citem != 0 ); + + const std::string kDefaultUrl( "http://url" ); + std::string testValue = citem->GetUrl(); + DALI_TEST_EQUALS( testValue, kDefaultUrl, TEST_LOCATION ); + + const std::string kDefaultTitle( "title" ); + testValue = citem->GetTitle(); + DALI_TEST_EQUALS( testValue, kDefaultTitle, TEST_LOCATION ); + + const std::string kDefaultOriginalUrl( "http://originalurl" ); + testValue = citem->GetOriginalUrl(); + DALI_TEST_EQUALS( testValue, kDefaultOriginalUrl, TEST_LOCATION ); + + Dali::Toolkit::WebBackForwardListItem* item = bfList->GetItemAtIndex( 0 ); + DALI_TEST_CHECK( item != 0 ); + + END_TEST; +} + +// test cases for web context. + +int UtcDaliWebContextGetSetCacheModel(void) +{ + ToolkitTestApplication application; + + WebView view = WebView::New(); + DALI_TEST_CHECK( view ); + + Dali::Toolkit::WebContext* context = view.GetContext(); + DALI_TEST_CHECK( context != 0 ) + + std::string kDefaultValue; + + // Reset something + context->SetProxyUri( kDefaultValue ); + context->SetCertificateFilePath( kDefaultValue ); + context->DisableCache( false ); + context->SetDefaultProxyAuth( kDefaultValue, kDefaultValue ); + context->DeleteWebDatabase(); + context->DeleteWebStorage(); + context->DeleteLocalFileSystem(); + context->ClearCache(); + + // Check default value + Dali::WebEngineContext::CacheModel value = context->GetCacheModel(); + DALI_TEST_CHECK( value == Dali::WebEngineContext::CacheModel::DOCUMENT_VIEWER ); + + // Check Set/GetProperty + context->SetCacheModel( Dali::WebEngineContext::CacheModel::DOCUMENT_BROWSER ); + value = context->GetCacheModel(); + DALI_TEST_CHECK( value == Dali::WebEngineContext::CacheModel::DOCUMENT_BROWSER ); + + END_TEST; +} + +// test cases for web cookie manager. + +int UtcDaliWebCookieManagerGetSetCookieAcceptPolicy(void) +{ + ToolkitTestApplication application; + + WebView view = WebView::New(); + DALI_TEST_CHECK( view ); + + Dali::Toolkit::WebCookieManager* cookieManager = view.GetCookieManager(); + DALI_TEST_CHECK( cookieManager != 0 ) + + const std::string kDefaultValue; + + // Reset something + cookieManager->SetPersistentStorage( kDefaultValue, Dali::WebEngineCookieManager::CookiePersistentStorage::SQLITE ); + cookieManager->ClearCookies(); + + // Check default value + Dali::WebEngineCookieManager::CookieAcceptPolicy value = cookieManager->GetCookieAcceptPolicy(); + DALI_TEST_CHECK( value == Dali::WebEngineCookieManager::CookieAcceptPolicy::NO_THIRD_PARTY ); + + // Check Set/GetProperty + cookieManager->SetCookieAcceptPolicy( Dali::WebEngineCookieManager::CookieAcceptPolicy::ALWAYS ); + value = cookieManager->GetCookieAcceptPolicy(); + DALI_TEST_CHECK( value == Dali::WebEngineCookieManager::CookieAcceptPolicy::ALWAYS ); + + END_TEST; +} + +// test cases for web settings. + +int UtcDaliWebSettingsGetSetDefaultFontSize(void) +{ + ToolkitTestApplication application; + + WebView view = WebView::New(); + DALI_TEST_CHECK( view ); + + Dali::Toolkit::WebSettings* settings = view.GetSettings(); + DALI_TEST_CHECK( settings != 0 ) + + // Reset something + settings->AllowMixedContents( false ); + settings->EnableSpatialNavigation( false ); + settings->EnableWebSecurity( false ); + settings->AllowFileAccessFromExternalUrl( false ); + settings->AllowScriptsOpenWindows( false ); + + // Check default value + int value = settings->GetDefaultFontSize(); + DALI_TEST_CHECK( value == 16 ); + + // Check Set/GetProperty + settings->SetDefaultFontSize( 20 ); + value = settings->GetDefaultFontSize(); + DALI_TEST_CHECK( value == 20 ); + + END_TEST; +} + +int UtcDaliWebSettingsCheckEnableJavaScript(void) +{ + ToolkitTestApplication application; + + WebView view = WebView::New(); + DALI_TEST_CHECK( view ); + + Dali::Toolkit::WebSettings* settings = view.GetSettings(); + DALI_TEST_CHECK( settings != 0 ) + + // Reset something + settings->AllowMixedContents( false ); + settings->EnableSpatialNavigation( false ); + settings->EnableWebSecurity( false ); + settings->AllowFileAccessFromExternalUrl( false ); + settings->AllowScriptsOpenWindows( false ); + + // Check default value is true or not + bool value = settings->IsJavaScriptEnabled(); + DALI_TEST_CHECK( value ); + + // Check Set/GetProperty + settings->EnableJavaScript( false ); + value = settings->IsJavaScriptEnabled(); + DALI_TEST_CHECK( !value ); + + END_TEST; +} + +int UtcDaliWebSettingsCheckAllowImagesLoadAutomatically(void) +{ + ToolkitTestApplication application; + + WebView view = WebView::New(); + DALI_TEST_CHECK( view ); + + Dali::Toolkit::WebSettings* settings = view.GetSettings(); + DALI_TEST_CHECK( settings != 0 ) + + // Reset something + settings->AllowMixedContents( false ); + settings->EnableSpatialNavigation( false ); + settings->EnableWebSecurity( false ); + settings->AllowFileAccessFromExternalUrl( false ); + settings->AllowScriptsOpenWindows( false ); + + // Check default value is true or not + bool value = settings->AreImagesLoadedAutomatically(); + DALI_TEST_CHECK( value ); + + // Check Set/GetProperty + settings->AllowImagesLoadAutomatically( false ); + value = settings->AreImagesLoadedAutomatically(); + DALI_TEST_CHECK( !value ); + + END_TEST; +} + +int UtcDaliWebSettingsGetSetDefaultTextEncodingName(void) +{ + ToolkitTestApplication application; + + WebView view = WebView::New(); + DALI_TEST_CHECK( view ); + + Dali::Toolkit::WebSettings* settings = view.GetSettings(); + DALI_TEST_CHECK( settings != 0 ) + + const std::string kDefaultValue; + const std::string kTestValue = "UTF-8"; + + // Reset something + settings->AllowMixedContents( false ); + settings->EnableSpatialNavigation( false ); + settings->EnableWebSecurity( false ); + settings->AllowFileAccessFromExternalUrl( false ); + settings->AllowScriptsOpenWindows( false ); + + // Check default value + std::string value = settings->GetDefaultTextEncodingName(); + DALI_TEST_EQUALS( value, kDefaultValue, TEST_LOCATION ); + + // Check Set/GetProperty + settings->SetDefaultTextEncodingName( kTestValue ); + value = settings->GetDefaultTextEncodingName(); + DALI_TEST_EQUALS( value, kTestValue, TEST_LOCATION ); + + END_TEST; +} + diff --git a/dali-toolkit/devel-api/controls/web-view/web-back-forward-list-item.cpp b/dali-toolkit/devel-api/controls/web-view/web-back-forward-list-item.cpp new file mode 100755 index 0000000..c8f9aeb --- /dev/null +++ b/dali-toolkit/devel-api/controls/web-view/web-back-forward-list-item.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include + +// EXTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Toolkit +{ + +const std::string EMPTY_STRING; + +WebBackForwardListItem::WebBackForwardListItem( const Dali::WebEngineBackForwardListItem* item ) +: mWebEngineBackForwardListItem( item ) +{ +} + +WebBackForwardListItem::~WebBackForwardListItem() +{ +} + +std::string WebBackForwardListItem::GetUrl() const +{ + return mWebEngineBackForwardListItem ? mWebEngineBackForwardListItem->GetUrl() : EMPTY_STRING; +} + +std::string WebBackForwardListItem::GetTitle() const +{ + return mWebEngineBackForwardListItem ? mWebEngineBackForwardListItem->GetTitle() : EMPTY_STRING; +} + +std::string WebBackForwardListItem::GetOriginalUrl() const +{ + return mWebEngineBackForwardListItem ? mWebEngineBackForwardListItem->GetOriginalUrl() : EMPTY_STRING; +} + +} // namespace Toolkit + +} // namespace Dali diff --git a/dali-toolkit/devel-api/controls/web-view/web-back-forward-list-item.h b/dali-toolkit/devel-api/controls/web-view/web-back-forward-list-item.h new file mode 100755 index 0000000..44a3bc1 --- /dev/null +++ b/dali-toolkit/devel-api/controls/web-view/web-back-forward-list-item.h @@ -0,0 +1,97 @@ +#ifndef DALI_TOOLKIT_WEB_BACK_FORWARD_LIST_ITEM_H +#define DALI_TOOLKIT_WEB_BACK_FORWARD_LIST_ITEM_H + +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include + +// INTERNAL INCLUDES +#include + +namespace Dali +{ + +class WebEngineBackForwardListItem; + +namespace Toolkit +{ + +/** + * @addtogroup dali_toolkit_controls_web_view + * @{ + */ + +/** + * @brief WebBackForwardListItem is a class for back-forward list item of WebView. + * + * + * For working WebBackForwardListItem, a Dali::WebBackForwardListItem should be provided. + * + */ +class DALI_TOOLKIT_API WebBackForwardListItem +{ +public: + /** + * @brief Creates a WebBackForwardListItem. + */ + WebBackForwardListItem( const Dali::WebEngineBackForwardListItem* item ); + + /** + * @brief Destructor. + */ + virtual ~WebBackForwardListItem() final; + + /** + * @brief Returns the URL of the item. + * + * @details The returned URL may differ from the original URL (For example, + * if the page is redirected). + * + * @return The URL of the @a item, otherwise "" in case of an error + */ + std::string GetUrl() const; + + /** + * @brief Returns the title of the item. + * + * @return The title of the @a item, otherwise "" in case of an error + */ + std::string GetTitle() const; + + /** + * @brief Returns the original URL of the item. + * + * @return The original URL of the @a item, otherwise "" in case of an error + */ + std::string GetOriginalUrl() const; + +private: + + const Dali::WebEngineBackForwardListItem* mWebEngineBackForwardListItem; +}; + +/** + * @} + */ + +} // namespace Toolkit + +} // namespace Dali + +#endif // DALI_TOOLKIT_WEB_BACK_FORWARD_LIST_ITEM_H diff --git a/dali-toolkit/devel-api/controls/web-view/web-back-forward-list.cpp b/dali-toolkit/devel-api/controls/web-view/web-back-forward-list.cpp new file mode 100755 index 0000000..fe4e33b --- /dev/null +++ b/dali-toolkit/devel-api/controls/web-view/web-back-forward-list.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include + +// EXTERNAL INCLUDES +#include +#include + +namespace Dali +{ +namespace Toolkit +{ + +WebBackForwardList::WebBackForwardList( const Dali::WebEngineBackForwardList& list ) +: mWebEngineBackForwardList( list ) +, mWebBackForwardListItem( 0 ) +{ +} + +WebBackForwardList::~WebBackForwardList() +{ +} + +WebBackForwardListItem* WebBackForwardList::GetCurrentItem() +{ + mWebBackForwardListItem = WebBackForwardListItem( &mWebEngineBackForwardList.GetCurrentItem() ); + return &mWebBackForwardListItem; +} + +WebBackForwardListItem* WebBackForwardList::GetItemAtIndex( uint32_t index ) +{ + mWebBackForwardListItem = WebBackForwardListItem( &mWebEngineBackForwardList.GetItemAtIndex( index ) ); + return &mWebBackForwardListItem; +} + +uint32_t WebBackForwardList::GetItemCount() const +{ + return mWebEngineBackForwardList.GetItemCount(); +} + +} // namespace Toolkit + +} // namespace Dali diff --git a/dali-toolkit/devel-api/controls/web-view/web-back-forward-list.h b/dali-toolkit/devel-api/controls/web-view/web-back-forward-list.h new file mode 100755 index 0000000..144c02b --- /dev/null +++ b/dali-toolkit/devel-api/controls/web-view/web-back-forward-list.h @@ -0,0 +1,94 @@ +#ifndef DALI_TOOLKIT_WEB_BACK_FORWARD_LIST_H +#define DALI_TOOLKIT_WEB_BACK_FORWARD_LIST_H + +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// INTERNAL INCLUDES +#include +#include + +namespace Dali +{ + +class WebEngineBackForwardList; + +namespace Toolkit +{ +class WebBackForwardListItem; + +/** + * @addtogroup dali_toolkit_controls_web_view + * @{ + */ + +/** + * @brief WebBackForwardList is a class for back-forward list item of WebView. + * + * + * For working WebBackForwardList, a Dali::WebBackForwardList should be provided. + * + */ +class DALI_TOOLKIT_API WebBackForwardList +{ +public: + /** + * @brief Creates a WebBackForwardList. + */ + WebBackForwardList( const Dali::WebEngineBackForwardList& list ); + + /** + * @brief Destructor. + */ + virtual ~WebBackForwardList() final; + + /** + * @brief Returns the current item in the @a list. + * @return The current item in list. + */ + WebBackForwardListItem* GetCurrentItem(); + + /** + * @brief Returns the item at a given @a index relative to the current item. + * @param[in] index The index of the item + * @return The current item in list. + */ + WebBackForwardListItem* GetItemAtIndex(uint32_t index); + + /** + * @brief Returns the length of the back-forward list including the current + * item. + * @return The length of the back-forward list including the current item, + * otherwise 0 in case of an error + */ + uint32_t GetItemCount() const; + +private: + const Dali::WebEngineBackForwardList& mWebEngineBackForwardList; + Dali::Toolkit::WebBackForwardListItem mWebBackForwardListItem; + +}; + +/** + * @} + */ + +} // namespace Toolkit + +} // namespace Dali + +#endif // DALI_TOOLKIT_WEB_BACK_FORWARD_LIST_H diff --git a/dali-toolkit/devel-api/controls/web-view/web-context.cpp b/dali-toolkit/devel-api/controls/web-view/web-context.cpp new file mode 100755 index 0000000..1e0cbbd --- /dev/null +++ b/dali-toolkit/devel-api/controls/web-view/web-context.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include + +namespace Dali +{ +namespace Toolkit +{ + +WebContext::WebContext( Dali::WebEngineContext& context) +: mWebEngineContext( context ) +{ +} + +WebContext::~WebContext() +{ +} + +Dali::WebEngineContext::CacheModel WebContext::GetCacheModel() const +{ + return mWebEngineContext.GetCacheModel(); +} + +void WebContext::SetCacheModel(Dali::WebEngineContext::CacheModel cacheModel ) +{ + mWebEngineContext.SetCacheModel( cacheModel ); +} + +void WebContext::SetProxyUri( const std::string& uri ) +{ + mWebEngineContext.SetProxyUri( uri ); +} + +void WebContext::SetCertificateFilePath( const std::string& certificatePath ) +{ + mWebEngineContext.SetCertificateFilePath( certificatePath ); +} + +void WebContext::DisableCache( bool cacheDisabled ) +{ + mWebEngineContext.DisableCache( cacheDisabled ); +} + +void WebContext::SetDefaultProxyAuth( const std::string& username, const std::string& password ) +{ + mWebEngineContext.SetDefaultProxyAuth( username, password ); +} + +void WebContext::DeleteWebDatabase() +{ + mWebEngineContext.DeleteWebDatabase(); +} + +void WebContext::DeleteWebStorage() +{ + mWebEngineContext.DeleteWebStorage(); +} + +void WebContext::DeleteLocalFileSystem() +{ + mWebEngineContext.DeleteLocalFileSystem(); +} + +void WebContext::ClearCache() +{ + mWebEngineContext.ClearCache(); +} + +} // namespace Toolkit + +} // namespace Dali diff --git a/dali-toolkit/devel-api/controls/web-view/web-context.h b/dali-toolkit/devel-api/controls/web-view/web-context.h new file mode 100755 index 0000000..1640c70 --- /dev/null +++ b/dali-toolkit/devel-api/controls/web-view/web-context.h @@ -0,0 +1,148 @@ +#ifndef DALI_TOOLKIT_WEB_CONTEXT_H +#define DALI_TOOLKIT_WEB_CONTEXT_H + +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include +#include + +// INTERNAL INCLUDES +#include + +namespace Dali +{ + +namespace Toolkit +{ + +/** + * @addtogroup dali_toolkit_controls_web_view + * @{ + */ + +/** + * @brief WebContext is a control for settings of WebView. + * + * For working WebContext, a WebView should be provided. + * + */ +class DALI_TOOLKIT_API WebContext +{ +public: + + /** + * @brief Creates a WebContext. + * + * @param[in] context The context of web engine. + */ + WebContext( Dali::WebEngineContext& context ); + + /** + * @brief Destructor. + */ + virtual ~WebContext() final; + + /** + * @brief Returns the cache model type. + * + * @return #Dali::WebEngineContext::CacheModel + */ + Dali::WebEngineContext::CacheModel GetCacheModel() const; + + /** + * @brief Requests to set the cache model. + * + * @param[in] cacheModel The cache model + */ + void SetCacheModel(Dali::WebEngineContext::CacheModel cacheModel ); + + /** + * @brief Sets the given proxy URI to network backend of specific context. + * + * @param[in] uri The proxy URI to set + */ + void SetProxyUri( const std::string& uri ); + + /** + * Adds CA certificates to persistent NSS certificate database + * + * Function accepts a path to a CA certificate file, a path to a directory + * containing CA certificate files, or a colon-seprarated list of those. + * Certificate files should have *.crt extension. + * Directories are traversed recursively. + * + * @param[in] certificatePath path to a CA certificate file(s), see above for details + */ + void SetCertificateFilePath( const std::string& certificatePath ); + + /** + * Toggles the cache to be enabled or disabled + * + * Function works asynchronously. + * By default the cache is disabled resulting in not storing network data on disk. + * + * @param[in] cacheDisabled enable or disable cache + */ + void DisableCache( bool cacheDisabled ); + + /** + * @brief Sets a proxy auth credential to network backend of specific context. + * + * @param[in] username username to set + * @param[in] password password to set + */ + void SetDefaultProxyAuth( const std::string& username, const std::string& password ); + + /** + * Requests for deleting all web databases. + */ + void DeleteWebDatabase(); + + /** + * @brief Deletes web storage. + * + * @details This function does not ensure that all data will be removed. + * Should be used to extend free physical memory. + */ + void DeleteWebStorage(); + + /** + * @brief Requests for deleting all local file systems. + */ + void DeleteLocalFileSystem(); + + /** + * @brief Requests to clear cache + */ + void ClearCache(); + +private: + + Dali::WebEngineContext& mWebEngineContext; +}; + +/** + * @} + */ + +} // namespace Toolkit + +} // namespace Dali + +#endif // DALI_TOOLKIT_WEB_CONTEXT_H diff --git a/dali-toolkit/devel-api/controls/web-view/web-cookie-manager.cpp b/dali-toolkit/devel-api/controls/web-view/web-cookie-manager.cpp new file mode 100755 index 0000000..ef6bd64 --- /dev/null +++ b/dali-toolkit/devel-api/controls/web-view/web-cookie-manager.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include + +namespace Dali +{ +namespace Toolkit +{ + +WebCookieManager::WebCookieManager( Dali::WebEngineCookieManager& manager ) +: mWebEngineCookieManager( manager ) +{ +} + +WebCookieManager::~WebCookieManager() +{ +} + +void WebCookieManager::SetCookieAcceptPolicy( Dali::WebEngineCookieManager::CookieAcceptPolicy cookieAcceptPolicy ) +{ + mWebEngineCookieManager.SetCookieAcceptPolicy( cookieAcceptPolicy ); +} + +Dali::WebEngineCookieManager::CookieAcceptPolicy WebCookieManager::GetCookieAcceptPolicy() const +{ + return mWebEngineCookieManager.GetCookieAcceptPolicy(); +} + +void WebCookieManager::ClearCookies() +{ + mWebEngineCookieManager.ClearCookies(); +} + +void WebCookieManager::SetPersistentStorage( const std::string& path, Dali::WebEngineCookieManager::CookiePersistentStorage storage ) +{ + mWebEngineCookieManager.SetPersistentStorage( path, storage ); +} + +} // namespace Toolkit + +} // namespace Dali diff --git a/dali-toolkit/devel-api/controls/web-view/web-cookie-manager.h b/dali-toolkit/devel-api/controls/web-view/web-cookie-manager.h new file mode 100755 index 0000000..adb8481 --- /dev/null +++ b/dali-toolkit/devel-api/controls/web-view/web-cookie-manager.h @@ -0,0 +1,111 @@ +#ifndef DALI_TOOLKIT_WEB_COOKIE_MANAGER_H +#define DALI_TOOLKIT_WEB_COOKIE_MANAGER_H + +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include +#include + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +class WebEngineCookieManager; + +namespace Toolkit +{ + +/** + * @addtogroup dali_toolkit_controls_web_view + * @{ + */ + +/** + * @brief WebCookieManager is a control for settings of WebView. + * + * + * For working WebCookieManager, a WebView should be provided. + * + */ +class DALI_TOOLKIT_API WebCookieManager +{ +public: + + /** + * @brief Creates a WebCookieManager. + * @param[in] manager A #Dali::WebEngineCookieManager + */ + WebCookieManager( Dali::WebEngineCookieManager& manager ); + + /** + * @brief Destructor. + */ + virtual ~WebCookieManager() final; + + /** + * @brief Sets @a policy as the cookie acceptance policy for @a manager. + * + * @details By default, only cookies set by the main document loaded are + * accepted. + * + * @param[in] policy A #Dali::WebEngineCookieManager::CookieAcceptPolicy + */ + void SetCookieAcceptPolicy(Dali::WebEngineCookieManager::CookieAcceptPolicy policy ); + + /** + * @brief Gets the cookie acceptance policy. The default is Toolkit::WebCookieManager::CookieAcceptPolicy::NO_THIRD_PARTY. + * @see Dali::WebEngineCookieManager::CookieAcceptPolicy + */ + Dali::WebEngineCookieManager::CookieAcceptPolicy GetCookieAcceptPolicy() const; + + /** + * @brief Deletes all the cookies of @a manager. + */ + void ClearCookies(); + + /** + * @brief Sets the @a path where non-session cookies are stored persistently using + * @a storage as the format to read/write the cookies. + * + * @details Cookies are initially read from @a path/Cookies to create an initial + * set of cookies. Then, non-session cookies will be written to @a path/Cookies. + * By default, @a manager doesn't store the cookies persistently, so you need to + * call this method to keep cookies saved across sessions. + * If @a path does not exist it will be created. + * + * @param[in] path The path where to read/write Cookies + * @param[in] storage The type of storage + */ + void SetPersistentStorage( const std::string& path, Dali::WebEngineCookieManager::CookiePersistentStorage storage ); + +private: + + Dali::WebEngineCookieManager& mWebEngineCookieManager; +}; + +/** + * @} + */ + +} // namespace Toolkit + +} // namespace Dali + +#endif // DALI_TOOLKIT_WEB_COOKIE_MANAGER_H diff --git a/dali-toolkit/devel-api/controls/web-view/web-settings.cpp b/dali-toolkit/devel-api/controls/web-view/web-settings.cpp new file mode 100755 index 0000000..7b6dc13 --- /dev/null +++ b/dali-toolkit/devel-api/controls/web-view/web-settings.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include + +// EXTERNAL INCLUDES +#include + +namespace Dali +{ +namespace Toolkit +{ + +WebSettings::WebSettings( Dali::WebEngineSettings& settings ) +: mWebEngineSettings( settings ) +{ +} + +WebSettings::~WebSettings() +{ +} + +void WebSettings::AllowMixedContents( bool allowed ) +{ + mWebEngineSettings.AllowMixedContents( allowed ); +} + +void WebSettings::EnableSpatialNavigation( bool enabled ) +{ + mWebEngineSettings.AllowMixedContents( enabled ); +} + +int WebSettings::GetDefaultFontSize() const +{ + return mWebEngineSettings.GetDefaultFontSize(); +} + +void WebSettings::SetDefaultFontSize( int defaultFontSize ) +{ + mWebEngineSettings.SetDefaultFontSize( defaultFontSize ); +} + +void WebSettings::EnableWebSecurity( bool enabled ) +{ + mWebEngineSettings.EnableWebSecurity( enabled ); +} + +void WebSettings::AllowFileAccessFromExternalUrl( bool allowed ) +{ + mWebEngineSettings.AllowFileAccessFromExternalUrl( allowed ); +} + +bool WebSettings::IsJavaScriptEnabled() const +{ + return mWebEngineSettings.IsJavaScriptEnabled(); +} + +void WebSettings::EnableJavaScript( bool enabled ) +{ + mWebEngineSettings.EnableJavaScript( enabled ); +} + +void WebSettings::AllowScriptsOpenWindows( bool allowed ) +{ + mWebEngineSettings.AllowScriptsOpenWindows( allowed ); +} + +bool WebSettings::AreImagesLoadedAutomatically() const +{ + return mWebEngineSettings.AreImagesLoadedAutomatically(); +} + +void WebSettings::AllowImagesLoadAutomatically( bool automatic ) +{ + mWebEngineSettings.AllowImagesLoadAutomatically( automatic ); +} + +std::string WebSettings::GetDefaultTextEncodingName() const +{ + return mWebEngineSettings.GetDefaultTextEncodingName(); +} + +void WebSettings::SetDefaultTextEncodingName( const std::string& defaultTextEncodingName ) +{ + mWebEngineSettings.SetDefaultTextEncodingName( defaultTextEncodingName ); +} + +} // namespace Toolkit + +} // namespace Dali diff --git a/dali-toolkit/devel-api/controls/web-view/web-settings.h b/dali-toolkit/devel-api/controls/web-view/web-settings.h new file mode 100755 index 0000000..dc46e7c --- /dev/null +++ b/dali-toolkit/devel-api/controls/web-view/web-settings.h @@ -0,0 +1,169 @@ +#ifndef DALI_TOOLKIT_WEB_SETTINGS_H +#define DALI_TOOLKIT_WEB_SETTINGS_H + +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include + +// INTERNAL INCLUDES +#include + +namespace Dali +{ +class WebEngineSettings; + +namespace Toolkit +{ + +/** + * @addtogroup dali_toolkit_controls_web_view + * @{ + */ + +/** + * @brief WebEngineSettings is a control for settings of WebView. + * + * + * For working WebEngineSettings, a WebView should be provided. + * + */ +class DALI_TOOLKIT_API WebSettings +{ +public: + /** + * @brief Creates a WebEngineSettings. + * + * @param[in] settings A settings of web engine. + */ + WebSettings( Dali::WebEngineSettings& settings ); + + /** + * @brief Destructor. + */ + virtual ~WebSettings() final; + + /** + *@brief Allow running mixed contents or not. + * + * @param[in] allowed if true, allow to run mixed contents, + * otherwise not allow + */ + void AllowMixedContents( bool allowed ); + + /** + * @brief Enable the spatial navigation or not. + * + * @param[in] enabled if true, use spatial navigation, + * otherwise to disable + */ + void EnableSpatialNavigation( bool enabled ); + + /** + * @brief Returns the default font size in pixel. The default value is 16. + * + * @return The default font size + */ + int GetDefaultFontSize() const; + + /** + * @brief Sets the default font size in pixel. The default value is 16. + * + * @param[in] defaultFontSize A new default font size to set + */ + void SetDefaultFontSize( int defaultFontSize ); + + /** + * @brief Enables/disables web security. + * + * @param[in] enabled if true, to enable the web security + * otherwise to disable + */ + void EnableWebSecurity( bool enabled ); + + /** + * @brief Allow/Disallow file access from external url + * + * @param[in] allowed if true, to allow file access from external url + * otherwise to disallow + */ + void AllowFileAccessFromExternalUrl( bool allowed ); + + /** + * @brief Returns whether JavaScript can be executable. The default is true. + * + * @return true if JavaScript executing is enabled, false otherwise + */ + bool IsJavaScriptEnabled() const; + + /** + * @brief Enables/disables JavaScript executing. The default is enabled. + * + * @param[in] enabled True if JavaScript executing is enabled, false otherwise + */ + void EnableJavaScript( bool enabled ); + + /** + * @brief Allow if the scripts can open new windows. + * + * @param[in] allowed if true, the scripts can open new windows, + * otherwise not + */ + void AllowScriptsOpenWindows( bool allowed ); + + /** + * @brief Returns whether images can be loaded automatically. The default is true. + * + * @return true if images are loaded automatically, false otherwise + */ + bool AreImagesLoadedAutomatically() const; + + /** + * @brief Enables/disables auto loading of images. The default is enabled. + * + * @param[in] automatic True if images are loaded automatically, false otherwise + */ + void AllowImagesLoadAutomatically( bool automatic ); + + /** + * @brief Gets the default text encoding name (e.g. UTF-8). + * + * @return The default text encoding name + */ + std::string GetDefaultTextEncodingName() const; + + /** + * @brief Sets the default text encoding name (e.g. UTF-8). + * + * @param[in] defaultTextEncodingName The default text encoding name + */ + void SetDefaultTextEncodingName( const std::string& defaultTextEncodingName ); + +private: + Dali::WebEngineSettings& mWebEngineSettings; +}; + +/** + * @} + */ + +} // namespace Toolkit + +} // namespace Dali + +#endif // DALI_TOOLKIT_WEB_SETTINGS_H diff --git a/dali-toolkit/devel-api/controls/web-view/web-view.cpp b/dali-toolkit/devel-api/controls/web-view/web-view.cpp index 338f8b9..4c9de03 100755 --- a/dali-toolkit/devel-api/controls/web-view/web-view.cpp +++ b/dali-toolkit/devel-api/controls/web-view/web-view.cpp @@ -63,14 +63,34 @@ WebView WebView::DownCast(BaseHandle handle) return Control::DownCast(handle); } +Dali::Toolkit::WebSettings* WebView::GetSettings() const +{ + return Dali::Toolkit::GetImpl( *this ).GetSettings(); +} + +Dali::Toolkit::WebContext* WebView::GetContext() const +{ + return Dali::Toolkit::GetImpl( *this ).GetContext(); +} + +Dali::Toolkit::WebCookieManager* WebView::GetCookieManager() const +{ + return Dali::Toolkit::GetImpl( *this ).GetCookieManager(); +} + +Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const +{ + return Dali::Toolkit::GetImpl( *this ).GetBackForwardList(); +} + void WebView::LoadUrl(const std::string& url) { Dali::Toolkit::GetImpl(*this).LoadUrl(url); } -void WebView::LoadHTMLString(const std::string& htmlString) +void WebView::LoadHtmlString(const std::string& htmlString) { - Dali::Toolkit::GetImpl(*this).LoadHTMLString(htmlString); + Dali::Toolkit::GetImpl(*this).LoadHtmlString(htmlString); } void WebView::Reload() @@ -138,16 +158,6 @@ void WebView::ClearHistory() Dali::Toolkit::GetImpl(*this).ClearHistory(); } -void WebView::ClearCache() -{ - Dali::Toolkit::GetImpl(*this).ClearCache(); -} - -void WebView::ClearCookies() -{ - Dali::Toolkit::GetImpl(*this).ClearCookies(); -} - WebView::WebViewPageLoadSignalType& WebView::PageLoadStartedSignal() { return Dali::Toolkit::GetImpl(*this).PageLoadStartedSignal(); diff --git a/dali-toolkit/devel-api/controls/web-view/web-view.h b/dali-toolkit/devel-api/controls/web-view/web-view.h index f447eda..2fa6433 100755 --- a/dali-toolkit/devel-api/controls/web-view/web-view.h +++ b/dali-toolkit/devel-api/controls/web-view/web-view.h @@ -29,6 +29,11 @@ namespace Dali { namespace Toolkit { +class WebBackForwardList; +class WebContext; +class WebCookieManager; +class WebSettings; + namespace Internal DALI_INTERNAL { class WebView; @@ -50,59 +55,6 @@ class WebView; class DALI_TOOLKIT_API WebView : public Control { public: - /** - * @brief A structure used to contain the cache model enumeration. - */ - struct CacheModel - { - /** - * @brief Enumeration for cache model options. - */ - enum Type - { - /** - * @brief Use the smallest cache capacity. - */ - DOCUMENT_VIEWER, - - /** - * @brief Use the bigger cache capacity than DocumentBrowser. - */ - DOCUMENT_BROWSER, - - /** - * @brief Use the biggest cache capacity. - */ - PRIMARY_WEB_BROWSER - }; - }; - - /** - * @brief A structure used to contain the cookie acceptance policy enumeration. - */ - struct CookieAcceptPolicy - { - /** - * @brief Enumeration for the cookies accept policies. - */ - enum Type - { - /** - * @brief Accepts every cookie sent from any page. - */ - ALWAYS, - - /** - * @brief Rejects all the cookies. - */ - NEVER, - - /** - * @brief Accepts only cookies set by the main document that is loaded. - */ - NO_THIRD_PARTY - }; - }; /** * @brief Enumeration for the start and end property ranges for this control. @@ -127,56 +79,12 @@ public: URL = PROPERTY_START_INDEX, /** - * @brief The cache model. - * @details Name "cacheModel", type WebView::CacheModel::Type (Property::INTEGER) or Property::STRING. - * @note Default is WebView::CacheModel::DOCUMENT_VIEWER. - * @see WebView::CacheModel::Type - */ - CACHE_MODEL, - - /** - * @brief The cookie acceptance policy. - * @details Name "cookieAcceptPolicy", type WebView::CookieAcceptPolicy::Type (Property::INTEGER) or Property::STRING. - * @note Default is WebView::CookieAcceptPolicy::NO_THIRD_PARTY. - * @see WebView::CookieAcceptPolicy::Type - */ - COOKIE_ACCEPT_POLICY, - - /** * @brief The user agent string. * @details Name "userAgent", type Property::STRING. */ USER_AGENT, /** - * @brief Whether JavaScript is enabled. - * @details Name "enableJavaScript", type Property::BOOLEAN. - * @note Default is true. - */ - ENABLE_JAVASCRIPT, - - /** - * @brief Whether images can be loaded automatically. - * @details Name "loadImagesAutomatically", type Property::BOOLEAN. - * @note Default is true. - */ - LOAD_IMAGES_AUTOMATICALLY, - - /** - * @brief The default text encoding name. - * @details Name "defaultTextEncodingName", type Property::STRING. - * @note If the value is not set, the web engine detects web page's text encoding. - */ - DEFAULT_TEXT_ENCODING_NAME, - - /** - * @brief The default font size in pixel. - * @details Name "defaultFontSize", type Property::INT. - * @note Default is 16. - */ - DEFAULT_FONT_SIZE, - - /** * @brief The current position of scroll. * @details Name "scrollPosition", type Property::VECTOR2. */ @@ -348,6 +256,26 @@ public: static WebView DownCast(BaseHandle handle); /** + * @brief Get WebSettings of WebEngine. + */ + Dali::Toolkit::WebSettings* GetSettings() const; + + /** + * @brief Get WebContext of WebEngine. + */ + Dali::Toolkit::WebContext* GetContext() const; + + /** + * @brief Get CookieManager of WebEngine. + */ + Dali::Toolkit::WebCookieManager* GetCookieManager() const; + + /** + * @brief Get WebBackForwardList of WebEngine. + */ + Dali::Toolkit::WebBackForwardList* GetBackForwardList() const; + + /** * @brief Loads a web page based on a given URL. * * @param [in] url The URL of the resource to load @@ -359,7 +287,7 @@ public: * * @param [in] htmlString The string to use as the contents of the web page */ - void LoadHTMLString(const std::string& htmlString); + void LoadHtmlString(const std::string& htmlString); /** * @brief Reloads the Web. @@ -459,16 +387,6 @@ public: void ClearHistory(); /** - * @brief Clears the cache of Web. - */ - void ClearCache(); - - /** - * @brief Clears all the cookies of Web. - */ - void ClearCookies(); - - /** * @brief Connects to this signal to be notified when page loading is started. * * @return A signal object to connect with diff --git a/dali-toolkit/devel-api/file.list b/dali-toolkit/devel-api/file.list index c8445cf..f43ca09 100755 --- a/dali-toolkit/devel-api/file.list +++ b/dali-toolkit/devel-api/file.list @@ -36,6 +36,11 @@ SET( devel_api_src_files ${devel_api_src_dir}/controls/text-controls/text-selection-toolbar.cpp ${devel_api_src_dir}/controls/tool-bar/tool-bar.cpp ${devel_api_src_dir}/controls/video-view/video-view-devel.cpp + ${devel_api_src_dir}/controls/web-view/web-back-forward-list.cpp + ${devel_api_src_dir}/controls/web-view/web-back-forward-list-item.cpp + ${devel_api_src_dir}/controls/web-view/web-context.cpp + ${devel_api_src_dir}/controls/web-view/web-cookie-manager.cpp + ${devel_api_src_dir}/controls/web-view/web-settings.cpp ${devel_api_src_dir}/controls/web-view/web-view.cpp ${devel_api_src_dir}/focus-manager/keyinput-focus-manager.cpp ${devel_api_src_dir}/focus-manager/keyboard-focus-manager-devel.cpp @@ -245,6 +250,11 @@ SET( devel_api_video_view_header_files ) SET( devel_api_web_view_header_files + ${devel_api_src_dir}/controls/web-view/web-back-forward-list.h + ${devel_api_src_dir}/controls/web-view/web-back-forward-list-item.h + ${devel_api_src_dir}/controls/web-view/web-context.h + ${devel_api_src_dir}/controls/web-view/web-cookie-manager.h + ${devel_api_src_dir}/controls/web-view/web-settings.h ${devel_api_src_dir}/controls/web-view/web-view.h ) diff --git a/dali-toolkit/internal/controls/web-view/web-view-impl.cpp b/dali-toolkit/internal/controls/web-view/web-view-impl.cpp index db14c27..2369acf 100755 --- a/dali-toolkit/internal/controls/web-view/web-view-impl.cpp +++ b/dali-toolkit/internal/controls/web-view/web-view-impl.cpp @@ -20,6 +20,10 @@ // EXTERNAL INCLUDES #include +#include +#include +#include +#include #include #include #include @@ -29,6 +33,10 @@ // INTERNAL INCLUDES #include +#include +#include +#include +#include #include #include #include @@ -50,28 +58,10 @@ BaseHandle Create() return Toolkit::WebView::New(); } -DALI_ENUM_TO_STRING_TABLE_BEGIN( CacheModel ) -DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::WebView::CacheModel, DOCUMENT_VIEWER ) -DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::WebView::CacheModel, DOCUMENT_BROWSER ) -DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::WebView::CacheModel, PRIMARY_WEB_BROWSER ) -DALI_ENUM_TO_STRING_TABLE_END( CacheModel ) - -DALI_ENUM_TO_STRING_TABLE_BEGIN( CookieAcceptPolicy ) -DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::WebView::CookieAcceptPolicy, ALWAYS ) -DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::WebView::CookieAcceptPolicy, NEVER ) -DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::WebView::CookieAcceptPolicy, NO_THIRD_PARTY ) -DALI_ENUM_TO_STRING_TABLE_END( CookieAcceptPolicy ) - DALI_TYPE_REGISTRATION_BEGIN( Toolkit::WebView, Toolkit::Control, Create ) DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "url", STRING, URL ) -DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "cacheModel", STRING, CACHE_MODEL ) -DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "cookieAcceptPolicy", STRING, COOKIE_ACCEPT_POLICY ) DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "userAgent", STRING, USER_AGENT ) -DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "enableJavaScript", BOOLEAN, ENABLE_JAVASCRIPT ) -DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "loadImagesAutomatically", BOOLEAN, LOAD_IMAGES_AUTOMATICALLY ) -DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "defaultTextEncodingName", STRING, DEFAULT_TEXT_ENCODING_NAME ) -DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "defaultFontSize", INTEGER, DEFAULT_FONT_SIZE ) DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "scrollPosition", VECTOR2, SCROLL_POSITION ) DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "scrollSize", VECTOR2, SCROLL_SIZE ) DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "contentSize", VECTOR2, CONTENT_SIZE ) @@ -150,9 +140,34 @@ void WebView::OnInitialize() mWebEngine.PageLoadFinishedSignal().Connect( this, &WebView::OnPageLoadFinished ); mWebEngine.PageLoadErrorSignal().Connect( this, &WebView::OnPageLoadError ); mWebEngine.ScrollEdgeReachedSignal().Connect( this, &WebView::OnScrollEdgeReached ); + + mWebContext = std::unique_ptr( new WebContext( mWebEngine.GetContext() ) ); + mWebCookieManager = std::unique_ptr( new WebCookieManager( mWebEngine.GetCookieManager() ) ); + mWebSettings = std::unique_ptr( new WebSettings( mWebEngine.GetSettings() ) ); + mWebBackForwardList = std::unique_ptr( new WebBackForwardList( mWebEngine.GetBackForwardList() ) ); } } +Dali::Toolkit::WebSettings* WebView::GetSettings() const +{ + return mWebSettings.get(); +} + +Dali::Toolkit::WebContext* WebView::GetContext() const +{ + return mWebContext.get(); +} + +Dali::Toolkit::WebCookieManager* WebView::GetCookieManager() const +{ + return mWebCookieManager.get(); +} + +Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const +{ + return mWebBackForwardList.get(); +} + void WebView::LoadUrl( const std::string& url ) { mUrl = url; @@ -173,7 +188,7 @@ void WebView::LoadUrl( const std::string& url ) } } -void WebView::LoadHTMLString( const std::string& htmlString ) +void WebView::LoadHtmlString( const std::string& htmlString ) { if( mWebEngine ) { @@ -186,7 +201,7 @@ void WebView::LoadHTMLString( const std::string& htmlString ) if( mVisual ) { DevelControl::RegisterVisual( *this, Toolkit::WebView::Property::URL, mVisual ); - mWebEngine.LoadHTMLString( htmlString ); + mWebEngine.LoadHtmlString( htmlString ); } } } @@ -281,22 +296,6 @@ void WebView::ClearHistory() } } -void WebView::ClearCache() -{ - if( mWebEngine ) - { - mWebEngine.ClearCache(); - } -} - -void WebView::ClearCookies() -{ - if( mWebEngine ) - { - mWebEngine.ClearCookies(); - } -} - Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadStartedSignal() { return mPageLoadStartedSignal; @@ -429,20 +428,6 @@ void WebView::SetProperty( BaseObject* object, Property::Index index, const Prop } break; } - case Toolkit::WebView::Property::CACHE_MODEL: - { - Toolkit::WebView::CacheModel::Type output = impl.GetCacheModel(); - GET_ENUM_VALUE( CacheModel, value, output ); - impl.SetCacheModel( output ); - break; - } - case Toolkit::WebView::Property::COOKIE_ACCEPT_POLICY: - { - Toolkit::WebView::CookieAcceptPolicy::Type output = impl.GetCookieAcceptPolicy(); - GET_ENUM_VALUE( CookieAcceptPolicy, value, output ); - impl.SetCookieAcceptPolicy( output ); - break; - } case Toolkit::WebView::Property::USER_AGENT: { std::string input; @@ -452,42 +437,6 @@ void WebView::SetProperty( BaseObject* object, Property::Index index, const Prop } break; } - case Toolkit::WebView::Property::ENABLE_JAVASCRIPT: - { - bool input; - if( value.Get( input ) ) - { - impl.EnableJavaScript( input ); - } - break; - } - case Toolkit::WebView::Property::LOAD_IMAGES_AUTOMATICALLY: - { - bool input; - if( value.Get( input ) ) - { - impl.LoadImagesAutomatically( input ); - } - break; - } - case Toolkit::WebView::Property::DEFAULT_TEXT_ENCODING_NAME: - { - std::string input; - if( value.Get( input ) ) - { - impl.SetDefaultTextEncodingName( input ); - } - break; - } - case Toolkit::WebView::Property::DEFAULT_FONT_SIZE: - { - int input; - if( value.Get( input ) ) - { - impl.SetDefaultFontSize( input ); - } - break; - } case Toolkit::WebView::Property::SCROLL_POSITION: { Vector2 input; @@ -517,41 +466,11 @@ Property::Value WebView::GetProperty( BaseObject* object, Property::Index proper value = impl.mUrl; break; } - case Toolkit::WebView::Property::CACHE_MODEL: - { - value = GET_ENUM_STRING( CacheModel, impl.GetCacheModel() ); - break; - } - case Toolkit::WebView::Property::COOKIE_ACCEPT_POLICY: - { - value = GET_ENUM_STRING( CookieAcceptPolicy, impl.GetCookieAcceptPolicy() ); - break; - } case Toolkit::WebView::Property::USER_AGENT: { value = impl.GetUserAgent(); break; } - case Toolkit::WebView::Property::ENABLE_JAVASCRIPT: - { - value = impl.IsJavaScriptEnabled(); - break; - } - case Toolkit::WebView::Property::LOAD_IMAGES_AUTOMATICALLY: - { - value = impl.AreImagesAutomaticallyLoaded(); - break; - } - case Toolkit::WebView::Property::DEFAULT_TEXT_ENCODING_NAME: - { - value = impl.GetDefaultTextEncodingName(); - break; - } - case Toolkit::WebView::Property::DEFAULT_FONT_SIZE: - { - value = impl.GetDefaultFontSize(); - break; - } case Toolkit::WebView::Property::SCROLL_POSITION: { int x, y; @@ -655,32 +574,6 @@ void WebView::GetContentSize( int& width, int& height ) const } } -Toolkit::WebView::CacheModel::Type WebView::GetCacheModel() const -{ - return mWebEngine ? static_cast< Toolkit::WebView::CacheModel::Type >( mWebEngine.GetCacheModel() ) : Toolkit::WebView::CacheModel::DOCUMENT_VIEWER; -} - -void WebView::SetCacheModel( Toolkit::WebView::CacheModel::Type cacheModel ) -{ - if( mWebEngine ) - { - mWebEngine.SetCacheModel( static_cast< WebEnginePlugin::CacheModel >( cacheModel ) ); - } -} - -Toolkit::WebView::CookieAcceptPolicy::Type WebView::GetCookieAcceptPolicy() const -{ - return mWebEngine ? static_cast< Toolkit::WebView::CookieAcceptPolicy::Type >( mWebEngine.GetCookieAcceptPolicy() ) : Toolkit::WebView::CookieAcceptPolicy::NO_THIRD_PARTY; -} - -void WebView::SetCookieAcceptPolicy( Toolkit::WebView::CookieAcceptPolicy::Type policy ) -{ - if( mWebEngine ) - { - mWebEngine.SetCookieAcceptPolicy( static_cast< WebEnginePlugin::CookieAcceptPolicy >( policy ) ); - } -} - const std::string& WebView::GetUserAgent() const { return mWebEngine ? mWebEngine.GetUserAgent() : kEmptyString; @@ -694,58 +587,6 @@ void WebView::SetUserAgent( const std::string& userAgent ) } } -bool WebView::IsJavaScriptEnabled() const -{ - return mWebEngine ? mWebEngine.IsJavaScriptEnabled() : true; -} - -void WebView::EnableJavaScript( bool enabled ) -{ - if( mWebEngine ) - { - mWebEngine.EnableJavaScript( enabled ); - } -} - -bool WebView::AreImagesAutomaticallyLoaded() const -{ - return mWebEngine ? mWebEngine.AreImagesAutomaticallyLoaded() : true; -} - -void WebView::LoadImagesAutomatically( bool automatic ) -{ - if( mWebEngine ) - { - mWebEngine.LoadImagesAutomatically( automatic ); - } -} - -const std::string& WebView::GetDefaultTextEncodingName() const -{ - return mWebEngine ? mWebEngine.GetDefaultTextEncodingName() : kEmptyString; -} - -void WebView::SetDefaultTextEncodingName( const std::string& defaultTextEncodingName ) -{ - if( mWebEngine ) - { - mWebEngine.SetDefaultTextEncodingName( defaultTextEncodingName ); - } -} - -int WebView::GetDefaultFontSize() const -{ - return mWebEngine ? mWebEngine.GetDefaultFontSize() : 0; -} - -void WebView::SetDefaultFontSize( int defaultFontSize ) -{ - if( mWebEngine ) - { - mWebEngine.SetDefaultFontSize( defaultFontSize ); - } -} - #undef GET_ENUM_STRING #undef GET_ENUM_VALUE diff --git a/dali-toolkit/internal/controls/web-view/web-view-impl.h b/dali-toolkit/internal/controls/web-view/web-view-impl.h index 0769bad..4769110 100755 --- a/dali-toolkit/internal/controls/web-view/web-view-impl.h +++ b/dali-toolkit/internal/controls/web-view/web-view-impl.h @@ -19,13 +19,14 @@ */ // EXTERNAL INCLUDES +#include #include #include // INTERNAL INCLUDES +#include #include #include -#include namespace Dali { @@ -35,6 +36,10 @@ namespace Toolkit class KeyEvent; class TouchEvent; +class WebBackForwardList; +class WebContext; +class WebCookieManager; +class WebSettings; class WebView; namespace Internal @@ -63,6 +68,26 @@ public: static Toolkit::WebView New( const std::string& locale, const std::string& timezoneId ); /** + * @brief Get settings of WebEngine. + */ + Dali::Toolkit::WebSettings* GetSettings() const; + + /** + * @brief Get context of WebEngine. + */ + Dali::Toolkit::WebContext* GetContext() const; + + /** + * @brief Get cookie manager of WebEngine. + */ + Dali::Toolkit::WebCookieManager* GetCookieManager() const; + + /** + * @brief Get WebBackForwardList of WebEngine. + */ + Dali::Toolkit::WebBackForwardList* GetBackForwardList() const; + + /** * @copydoc Dali::Toolkit::WebView::LoadUrl() */ void LoadUrl( const std::string& url ); @@ -70,7 +95,7 @@ public: /** * @copydoc Dali::WebEngine::LoadHTMLString() */ - void LoadHTMLString( const std::string& htmlString ); + void LoadHtmlString( const std::string& htmlString ); /** * @copydoc Dali::Toolkit::WebView::Reload() @@ -133,16 +158,6 @@ public: void ClearHistory(); /** - * @copydoc Dali::Toolkit::WebView::ClearCache() - */ - void ClearCache(); - - /** - * @copydoc Dali::Toolkit::WebView::ClearCookies() - */ - void ClearCookies(); - - /** * @copydoc Dali::Toolkit::WebView::PageLoadStartedSignal() */ Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadStartedSignal(); @@ -269,32 +284,6 @@ private: void GetContentSize( int& width, int& height ) const; /** - * @brief Get cache model option. The default isToolkit::WebView::CacheModel::DOCUMENT_VIEWER. - * @see Toolkit::WebView::CacheModel::Type - */ - Toolkit::WebView::CacheModel::Type GetCacheModel() const; - - /** - * @brief Set cache model option. The default isToolkit::WebView::CacheModel::DOCUMENT_VIEWER. - * @param[in] cacheModel The cache model option - * @see Toolkit::WebView::CacheModel::Type - */ - void SetCacheModel( Toolkit::WebView::CacheModel::Type cacheModel ); - - /** - * @brief Gets the cookie acceptance policy. The default is Toolkit::WebView::CookieAcceptPolicy::NO_THIRD_PARTY. - * @see Toolkit::WebView::CookieAcceptPolicy::Type - */ - Toolkit::WebView::CookieAcceptPolicy::Type GetCookieAcceptPolicy() const; - - /** - * @brief Sets the cookie acceptance policy. The default is Toolkit::WebView::CookieAcceptPolicy::NO_THIRD_PARTY. - * @param[in] policy The cookie acceptance policy - * @see Toolkit::WebView::CookieAcceptPolicy::Type - */ - void SetCookieAcceptPolicy( Toolkit::WebView::CookieAcceptPolicy::Type policy ); - - /** * @brief Get user agent string. * @return The string value of user agent */ @@ -307,62 +296,6 @@ private: void SetUserAgent( const std::string& userAgent ); /** - * @brief Returns whether JavaScript can be executable. The default is true. - * - * @return true if JavaScript executing is enabled, false otherwise - */ - bool IsJavaScriptEnabled() const; - - /** - * @brief Enables/disables JavaScript executing. The default is enabled. - * - * @param[in] enabled True if JavaScript executing is enabled, false otherwise - */ - void EnableJavaScript( bool enabled ); - - /** - * @brief Returns whether images can be loaded automatically. The default is true. - * - * @return true if images are loaded automatically, false otherwise - */ - bool AreImagesAutomaticallyLoaded() const; - - /** - * @brief Enables/disables auto loading of images. The default is enabled. - * - * @param[in] automatic True if images are loaded automatically, false otherwise - */ - void LoadImagesAutomatically( bool automatic ); - - /** - * @brief Gets the default text encoding name (e.g. UTF-8). - * - * @return The default text encoding name - */ - const std::string& GetDefaultTextEncodingName() const; - - /** - * @brief Sets the default text encoding name (e.g. UTF-8). - * - * @param[in] defaultTextEncodingName The default text encoding name - */ - void SetDefaultTextEncodingName( const std::string& defaultTextEncodingName ); - - /** - * @brief Returns the default font size in pixel. The default value is 16. - * - * @return The default font size - */ - int GetDefaultFontSize() const; - - /** - * @brief Sets the default font size in pixel. The default value is 16. - * - * @param[in] defaultFontSize A new default font size to set - */ - void SetDefaultFontSize( int defaultFontSize ); - - /** * @brief Callback function to be called when page load started. * @param[in] url The url currently being loaded */ @@ -398,6 +331,11 @@ private: Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadFinishedSignal; Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType mPageLoadErrorSignal; Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType mScrollEdgeReachedSignal; + + std::unique_ptr mWebContext; + std::unique_ptr mWebCookieManager; + std::unique_ptr mWebSettings; + std::unique_ptr mWebBackForwardList; }; } // namespace Internal