From: Jiyun Yang Date: Wed, 8 May 2019 11:34:32 +0000 (+0900) Subject: Implement WebView APIs X-Git-Tag: dali_1.4.20~1 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=e5d379064ba0e9a68d1d2680906952dbde263f34;hp=d65d27692a440b8fb20b69668c32d365ee822320 Implement WebView APIs Add Properties * CACHE_MODEL * COOKIE_ACCEPT_POLICY * USER_AGENT * JAVASCRIPT_ENABLED * LOAD_IMAGE_AUTOMATICALLY * DEFAULT_TEXT_ENCODING_NAME * DEFAULT_FONT_SIZE Add Signals * PageLoadErrorSignal Add Methods * Suspend * Resume * ClearCookies Modify Methods * EvaluateJavaScript Change-Id: Ic4c7c74e23f9d63ba5078224e2ad84d1e77e72de Signed-off-by: Jiyun Yang --- 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 29f26b9..5316331 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 @@ -43,6 +43,7 @@ static int gInstanceCount = 0; bool OnGoBack(); bool OnGoForward(); bool OnLoadUrl(); +bool OnEvaluteJavaScript(); bool OnClearHistory(); static void ConnectToGlobalSignal( bool (*func)() ) @@ -65,6 +66,14 @@ 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 ) { gInstanceCount++; gInstance = this; @@ -73,7 +82,7 @@ public: virtual ~WebEngine() { gInstanceCount--; - if ( !gInstanceCount ) + if( !gInstanceCount ) { gInstance = NULL; } @@ -110,26 +119,123 @@ public: ConnectToGlobalSignal( &OnGoBack ); } + void EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler ) + { + if( resultHandler ) + { + if( !mEvaluating ) + { + ConnectToGlobalSignal( &OnEvaluteJavaScript ); + } + mResultCallbacks.push_back( resultHandler ); + } + } + void ClearHistory() { ConnectToGlobalSignal( &OnClearHistory ); } - Dali::WebEnginePlugin::WebEngineSignalType& PageLoadStartedSignal() + 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; + } + + void SetUserAgent( const std::string& userAgent ) + { + 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; + } + + Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal() { return mPageLoadStartedSignal; } - Dali::WebEnginePlugin::WebEngineSignalType& PageLoadFinishedSignal() + Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal() { return mPageLoadFinishedSignal; } - std::string mUrl; - std::vector< std::string > mHistory; - size_t mCurrentPlusOnePos; - Dali::WebEnginePlugin::WebEngineSignalType mPageLoadStartedSignal; - Dali::WebEnginePlugin::WebEngineSignalType mPageLoadFinishedSignal; + Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() + { + return mPageLoadErrorSignal; + } + + 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; + std::vector< std::function< void( const std::string& ) > > mResultCallbacks; + bool mEvaluating; }; inline WebEngine& GetImplementation( Dali::WebEngine& webEngine ) @@ -153,7 +259,7 @@ bool OnGoBack() { DisconnectFromGlobalSignal( &OnGoBack ); - if ( gInstance && gInstance->CanGoBack() ) + if( gInstance && gInstance->CanGoBack() ) { gInstance->mCurrentPlusOnePos--; } @@ -164,7 +270,7 @@ bool OnGoForward() { DisconnectFromGlobalSignal( &OnGoForward ); - if ( gInstance && gInstance->CanGoForward() ) + if( gInstance && gInstance->CanGoForward() ) { gInstance->mCurrentPlusOnePos++; } @@ -175,9 +281,9 @@ bool OnLoadUrl() { DisconnectFromGlobalSignal( &OnLoadUrl ); - if ( gInstance ) + if( gInstance ) { - if ( gInstance->mHistory.size() > gInstance->mCurrentPlusOnePos ) + if( gInstance->mHistory.size() > gInstance->mCurrentPlusOnePos ) { gInstance->mHistory.erase( gInstance->mHistory.begin() + gInstance->mCurrentPlusOnePos, gInstance->mHistory.end() ); } @@ -186,7 +292,21 @@ bool OnLoadUrl() gInstance->mPageLoadStartedSignal.Emit( gInstance->mUrl ); gInstance->mPageLoadFinishedSignal.Emit( gInstance->mUrl ); } + return false; +} +bool OnEvaluteJavaScript() +{ + DisconnectFromGlobalSignal( &OnEvaluteJavaScript ); + + if( gInstance ) + { + for( auto& func : gInstance->mResultCallbacks ) + { + func("undefined"); + } + gInstance->mResultCallbacks.clear(); + } return false; } @@ -194,7 +314,7 @@ bool OnClearHistory() { DisconnectFromGlobalSignal( &OnClearHistory ); - if ( gInstance && gInstance->mCurrentPlusOnePos ) { + if( gInstance && gInstance->mCurrentPlusOnePos ) { std::string url = gInstance->mHistory[ gInstance->mCurrentPlusOnePos - 1 ]; std::vector< std::string >().swap( gInstance->mHistory ); gInstance->mHistory.push_back( url ); @@ -283,6 +403,14 @@ void WebEngine::StopLoading() { } +void WebEngine::Suspend() +{ +} + +void WebEngine::Resume() +{ +} + bool WebEngine::CanGoForward() { return Internal::Adaptor::GetImplementation( *this ).CanGoForward(); @@ -303,8 +431,9 @@ void WebEngine::GoBack() Internal::Adaptor::GetImplementation( *this ).GoBack(); } -void WebEngine::EvaluateJavaScript( const std::string& script ) +void WebEngine::EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler ) { + Internal::Adaptor::GetImplementation( *this ).EvaluateJavaScript( script, resultHandler ); } void WebEngine::AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void(const std::string&) > handler ) @@ -320,6 +449,80 @@ 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(); +} + +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::SetSize( int width, int height ) { } @@ -334,15 +537,20 @@ bool WebEngine::SendKeyEvent( const KeyEvent& event ) return true; } -Dali::WebEnginePlugin::WebEngineSignalType& WebEngine::PageLoadStartedSignal() +Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadStartedSignal() { return Internal::Adaptor::GetImplementation( *this ).PageLoadStartedSignal(); } -Dali::WebEnginePlugin::WebEngineSignalType& WebEngine::PageLoadFinishedSignal() +Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadFinishedSignal() { return Internal::Adaptor::GetImplementation( *this ).PageLoadFinishedSignal(); } +Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& WebEngine::PageLoadErrorSignal() +{ + return Internal::Adaptor::GetImplementation( *this ).PageLoadErrorSignal(); +} + } // namespace Dali; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp index cd49363..bb9e279 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp @@ -39,6 +39,7 @@ const char* const TEST_URL2( "http://www.somewhere.valid2.com" ); static int gPageLoadStartedCallbackCalled = 0; static int gPageLoadFinishedCallbackCalled = 0; +static int gEvaluateJavaScriptCallbackCalled = 0; static bool gTouched = false; struct CallbackFunctor @@ -65,6 +66,15 @@ static void OnPageLoadFinished( WebView view, const std::string& url ) gPageLoadFinishedCallbackCalled++; } +static void OnPageLoadError( WebView view, const std::string& url, WebView::LoadErrorCode errorCode ) +{ +} + +static void OnEvaluateJavaScript( const std::string& result ) +{ + gEvaluateJavaScriptCallbackCalled++; +} + static bool OnTouched( Actor actor, const Dali::TouchData& touch ) { gTouched = true; @@ -146,6 +156,7 @@ int UtcDaliWebViewPageNavigation(void) ConnectionTracker* testTracker = new ConnectionTracker(); view.PageLoadStartedSignal().Connect( &OnPageLoadStarted ); view.PageLoadFinishedSignal().Connect( &OnPageLoadFinished ); + view.PageLoadErrorSignal().Connect( &OnPageLoadError ); bool signal1 = false; bool signal2 = false; bool signal3 = false; @@ -159,7 +170,6 @@ int UtcDaliWebViewPageNavigation(void) view.LoadUrl( TEST_URL1 ); view.GetNaturalSize(); Test::EmitGlobalTimerSignal(); - DALI_TEST_CHECK( view.GetUrl().find( TEST_URL1 ) != std::string::npos ); DALI_TEST_EQUALS( view.CanGoBack(), false, TEST_LOCATION ); DALI_TEST_EQUALS( gPageLoadStartedCallbackCalled, 1, TEST_LOCATION ); DALI_TEST_EQUALS( gPageLoadFinishedCallbackCalled, 1, TEST_LOCATION ); @@ -167,11 +177,12 @@ int UtcDaliWebViewPageNavigation(void) DALI_TEST_CHECK( !signal3 ); view.LoadUrl( TEST_URL2 ); + view.Suspend(); view.SetSize( 400, 300 ); application.SendNotification(); application.Render(); Test::EmitGlobalTimerSignal(); - DALI_TEST_CHECK( view.GetUrl().find( TEST_URL2 ) != std::string::npos ); + view.Resume(); DALI_TEST_EQUALS( view.CanGoBack(), true, TEST_LOCATION ); DALI_TEST_EQUALS( view.CanGoForward(), false, TEST_LOCATION ); DALI_TEST_EQUALS( gPageLoadStartedCallbackCalled, 2, TEST_LOCATION ); @@ -191,6 +202,7 @@ int UtcDaliWebViewPageNavigation(void) view.StopLoading(); view.ClearHistory(); view.ClearCache(); + view.ClearCookies(); Test::EmitGlobalTimerSignal(); DALI_TEST_CHECK( !view.CanGoBack() ); DALI_TEST_CHECK( !view.CanGoForward() ); @@ -244,6 +256,7 @@ int UtcDaliWebViewTouchAndKeys(void) int UtcDaliWebViewProperty1(void) { + // URL ToolkitTestApplication application; WebView view = WebView::New(); @@ -258,6 +271,217 @@ int UtcDaliWebViewProperty1(void) END_TEST; } +int UtcDaliWebViewProperty2(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 ); + + END_TEST; +} + +int UtcDaliWebViewProperty3(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 ); + + END_TEST; +} + +int UtcDaliWebViewProperty4(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 ); + + 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) +{ + // LOAD_IMAGES_AUTOMATICALLY + 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 ); + + END_TEST; +} + +int UtcDaliWebViewProperty7(void) +{ + // DEFAULT_TEXT_ENCODING_NAME + ToolkitTestApplication application; + + WebView view = WebView::New(); + DALI_TEST_CHECK( view ); + + const std::string kDefaultValue; + const std::string kTestValue = "UTF-8"; + + // 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 ); + 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 ); + DALI_TEST_CHECK( value.Get( output ) ); + DALI_TEST_EQUALS( output, kTestValue, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliWebViewEvaluteJavaScript(void) +{ + ToolkitTestApplication application; + + WebView view = WebView::New( "ko-KR", "Asia/Seoul" ); + + view.LoadHTMLString( "Hello World!" ); + view.EvaluateJavaScript( "jsObject.postMessage('Hello')" ); + view.EvaluateJavaScript( "jsObject.postMessage('World')", OnEvaluateJavaScript ); + Test::EmitGlobalTimerSignal(); + + DALI_TEST_EQUALS( gEvaluateJavaScriptCallbackCalled, 1, TEST_LOCATION ); + + END_TEST; +} + + int UtcDaliWebViewMethodsForCoverage(void) { ToolkitTestApplication application; @@ -269,7 +493,6 @@ int UtcDaliWebViewMethodsForCoverage(void) []( const std::string& arg ) { } ); - view.EvaluateJavaScript( "jsObject.postMessage('Hello')" ); DALI_TEST_CHECK( view ); 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 0d1c680..20ae948 100644 --- a/dali-toolkit/devel-api/controls/web-view/web-view.cpp +++ b/dali-toolkit/devel-api/controls/web-view/web-view.cpp @@ -70,11 +70,6 @@ void WebView::LoadUrl( const std::string& url ) Dali::Toolkit::GetImpl( *this ).LoadUrl( url ); } -const std::string& WebView::GetUrl() -{ - return Dali::Toolkit::GetImpl( *this ).GetUrl(); -} - void WebView::LoadHTMLString( const std::string& htmlString ) { Dali::Toolkit::GetImpl( *this ).LoadHTMLString( htmlString ); @@ -90,6 +85,16 @@ void WebView::StopLoading() Dali::Toolkit::GetImpl( *this ).StopLoading(); } +void WebView::Suspend() +{ + Dali::Toolkit::GetImpl( *this ).Suspend(); +} + +void WebView::Resume() +{ + Dali::Toolkit::GetImpl( *this ).Resume(); +} + bool WebView::CanGoForward() { return Dali::Toolkit::GetImpl( *this ).CanGoForward(); @@ -110,9 +115,14 @@ void WebView::GoBack() Dali::Toolkit::GetImpl( *this ).GoBack(); } +void WebView::EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler ) +{ + Dali::Toolkit::GetImpl( *this ).EvaluateJavaScript( script, resultHandler ); +} + void WebView::EvaluateJavaScript( const std::string& script ) { - Dali::Toolkit::GetImpl( *this ).EvaluateJavaScript( script ); + Dali::Toolkit::GetImpl( *this ).EvaluateJavaScript( script, nullptr ); } void WebView::AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler ) @@ -130,16 +140,26 @@ void WebView::ClearCache() Dali::Toolkit::GetImpl( *this ).ClearCache(); } -WebView::WebViewSignalType& WebView::PageLoadStartedSignal() +void WebView::ClearCookies() +{ + Dali::Toolkit::GetImpl( *this ).ClearCookies(); +} + +WebView::WebViewPageLoadSignalType& WebView::PageLoadStartedSignal() { return Dali::Toolkit::GetImpl( *this ).PageLoadStartedSignal(); } -WebView::WebViewSignalType& WebView::PageLoadFinishedSignal() +WebView::WebViewPageLoadSignalType& WebView::PageLoadFinishedSignal() { return Dali::Toolkit::GetImpl( *this ).PageLoadFinishedSignal(); } +WebView::WebViewPageLoadErrorSignalType& WebView::PageLoadErrorSignal() +{ + return Dali::Toolkit::GetImpl( *this ).PageLoadErrorSignal(); +} + WebView::WebView( Internal::WebView& implementation ) : Control( implementation ) { 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 8d33f3a..ad39718 100644 --- a/dali-toolkit/devel-api/controls/web-view/web-view.h +++ b/dali-toolkit/devel-api/controls/web-view/web-view.h @@ -53,6 +53,60 @@ 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. */ enum PropertyRange @@ -69,15 +123,153 @@ public: enum { /** - * @brief name "url", type string - * - * @details Sets the url to load + * @brief The url to load. + * @details name "url", type Property::STRING. + */ + 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. */ - URL = PROPERTY_START_INDEX + 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 }; }; - typedef Signal< void ( WebView, const std::string& ) > WebViewSignalType; + /** + * @brief Enumeration for indicating error code of page loading. + */ + enum class LoadErrorCode + { + /** + * @brief Unknown. + */ + UNKNOWN = 0, + + /** + * @brief User canceled. + */ + CANCELED, + + /** + * @brief Can't show the page for this MIME type. + */ + CANT_SUPPORT_MIMETYPE, + + /** + * @brief File IO error. + */ + FAILED_FILE_IO, + + /** + * @brief Cannot connect to the network. + */ + CANT_CONNECT, + + /** + * @brief Fail to look up host from the DNS. + */ + CANT_LOOKUP_HOST, + + /** + * @brief Fail to SSL/TLS handshake. + */ + FAILED_TLS_HANDSHAKE, + + /** + * @brief Received certificate is invalid. + */ + INVALID_CERTIFICATE, + + /** + * @brief Connection timeout. + */ + REQUEST_TIMEOUT, + + /** + * @brief Too many redirects. + */ + TOO_MANY_REDIRECTS, + + /** + * @brief Too many requests during this load. + */ + TOO_MANY_REQUESTS, + + /** + * @brief Malformed URL. + */ + BAD_URL, + + /** + * @brief Unsupported scheme. + */ + UNSUPPORTED_SCHEME, + + /** + * @brief User authentication failed on the server. + */ + AUTHENTICATION, + + /** + * @brief Web server has an internal server error. + */ + INTERNAL_SERVER + }; + + /** + * @brief WebView signal type related with page loading. + */ + typedef Signal< void ( WebView, const std::string& ) > WebViewPageLoadSignalType; + + /** + * @brief WebView signal type related with page loading error. + */ + typedef Signal< void ( WebView, const std::string&, LoadErrorCode ) > WebViewPageLoadErrorSignalType; public: @@ -143,13 +335,6 @@ public: void LoadUrl( const std::string& url ); /** - * @brief Returns the URL of the Web. - * - * @return Url of string type - */ - const std::string& GetUrl(); - - /** * @brief Loads a given string as web contents. * * @param [in] htmlString The string to use as the contents of the web page @@ -167,6 +352,16 @@ public: void StopLoading(); /** + * @brief Suspends the operation associated with the view. + */ + void Suspend(); + + /** + * @brief Resumes the operation associated with the view object after calling Suspend(). + */ + void Resume(); + + /** * @brief Returns whether forward is possible. * * @return True if forward is possible, false otherwise @@ -194,6 +389,14 @@ public: * @brief Evaluates JavaScript code represented as a string. * * @param[in] script The JavaScript code + * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result. + */ + void EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler ); + + /** + * @brief Evaluates JavaScript code represented as a string. + * + * @param[in] script The JavaScript code */ void EvaluateJavaScript( const std::string& script ); @@ -234,18 +437,30 @@ public: 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 */ - WebViewSignalType& PageLoadStartedSignal(); + WebViewPageLoadSignalType& PageLoadStartedSignal(); /** * @brief Connects to this signal to be notified when page loading is finished. * * @return A signal object to connect with */ - WebViewSignalType& PageLoadFinishedSignal(); + WebViewPageLoadSignalType& PageLoadFinishedSignal(); + + /** + * @brief Connects to this signal to be notified when an error occurs in page loading. + * + * @return A signal object to connect with. + */ + WebViewPageLoadErrorSignalType& PageLoadErrorSignal(); public: // Not intended for application developers 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 5836f42..b0d81de 100644 --- 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,8 @@ // EXTERNAL INCLUDES #include +#include +#include #include #include #include @@ -47,17 +49,45 @@ BaseHandle Create() return Toolkit::WebView::New(); } -DALI_TYPE_REGISTRATION_BEGIN( Toolkit::WebView, Toolkit::Control, Create ); - -DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "url", STRING, URL ); - -DALI_SIGNAL_REGISTRATION( Toolkit, WebView, "pageLoadStarted", PAGE_LOAD_STARTED_SIGNAL ); -DALI_SIGNAL_REGISTRATION( Toolkit, WebView, "pageLoadFinished", PAGE_LOAD_FINISHED_SIGNAL ); +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_SIGNAL_REGISTRATION( Toolkit, WebView, "pageLoadStarted", PAGE_LOAD_STARTED_SIGNAL ) +DALI_SIGNAL_REGISTRATION( Toolkit, WebView, "pageLoadFinished", PAGE_LOAD_FINISHED_SIGNAL ) +DALI_SIGNAL_REGISTRATION( Toolkit, WebView, "pageLoadError", PAGE_LOAD_ERROR_SIGNAL ) DALI_TYPE_REGISTRATION_END() +const std::string kEmptyString; + } // anonymous namepsace +#define GET_ENUM_STRING( structName, inputExp ) \ + Scripting::GetLinearEnumerationName< Toolkit::WebView::structName::Type >( static_cast< Toolkit::WebView::structName::Type >( inputExp ), structName##_TABLE, structName##_TABLE_COUNT ) + +#define GET_ENUM_VALUE( structName, inputExp, outputExp ) \ + Scripting::GetEnumerationProperty< Toolkit::WebView::structName::Type >( inputExp, structName##_TABLE, structName##_TABLE_COUNT, outputExp ) + WebView::WebView( const std::string& locale, const std::string& timezoneId ) : Control( ControlBehaviour( ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS ) ), mUrl(), @@ -65,10 +95,13 @@ WebView::WebView( const std::string& locale, const std::string& timezoneId ) mWebViewSize( Stage::GetCurrent().GetSize() ), mWebEngine(), mPageLoadStartedSignal(), - mPageLoadFinishedSignal() + mPageLoadFinishedSignal(), + mPageLoadErrorSignal() { mWebEngine = Dali::WebEngine::New(); - if ( mWebEngine ) + + // WebEngine is empty when it is not properly initialized. + if( mWebEngine ) { mWebEngine.Create( mWebViewSize.width, mWebViewSize.height, locale, timezoneId ); } @@ -106,22 +139,23 @@ void WebView::OnInitialize() Self().SetKeyboardFocusable( true ); Self().TouchSignal().Connect( this, &WebView::OnTouchEvent ); - if ( mWebEngine ) + if( mWebEngine ) { mWebEngine.PageLoadStartedSignal().Connect( this, &WebView::OnPageLoadStarted ); mWebEngine.PageLoadFinishedSignal().Connect( this, &WebView::OnPageLoadFinished ); + mWebEngine.PageLoadErrorSignal().Connect( this, &WebView::OnPageLoadError ); } } void WebView::LoadUrl( const std::string& url ) { mUrl = url; - if ( mWebEngine ) + if( mWebEngine ) { Dali::Image image = Dali::NativeImage::New( *mWebEngine.GetNativeImageSource() ); mVisual = Toolkit::VisualFactory::Get().CreateVisual( image ); - if ( mVisual ) + if( mVisual ) { // Clean up previously registered visual and add new one. DevelControl::RegisterVisual( *this, Toolkit::WebView::Property::URL, mVisual ); @@ -130,19 +164,14 @@ void WebView::LoadUrl( const std::string& url ) } } -const std::string& WebView::GetUrl() -{ - return mWebEngine ? mWebEngine.GetUrl() : mUrl; -} - void WebView::LoadHTMLString( const std::string& htmlString ) { - if ( mWebEngine ) + if( mWebEngine ) { Dali::Image image = Dali::NativeImage::New( *mWebEngine.GetNativeImageSource() ); mVisual = Toolkit::VisualFactory::Get().CreateVisual( image ); - if ( mVisual ) + if( mVisual ) { DevelControl::RegisterVisual( *this, Toolkit::WebView::Property::URL, mVisual ); mWebEngine.LoadHTMLString( htmlString ); @@ -152,7 +181,7 @@ void WebView::LoadHTMLString( const std::string& htmlString ) void WebView::Reload() { - if ( mWebEngine ) + if( mWebEngine ) { mWebEngine.Reload(); } @@ -160,12 +189,28 @@ void WebView::Reload() void WebView::StopLoading() { - if ( mWebEngine ) + if( mWebEngine ) { mWebEngine.StopLoading(); } } +void WebView::Suspend() +{ + if( mWebEngine ) + { + mWebEngine.Suspend(); + } +} + +void WebView::Resume() +{ + if( mWebEngine ) + { + mWebEngine.Resume(); + } +} + bool WebView::CanGoForward() { return mWebEngine ? mWebEngine.CanGoForward() : false; @@ -173,7 +218,7 @@ bool WebView::CanGoForward() void WebView::GoForward() { - if ( mWebEngine ) + if( mWebEngine ) { mWebEngine.GoForward(); } @@ -186,23 +231,23 @@ bool WebView::CanGoBack() void WebView::GoBack() { - if ( mWebEngine ) + if( mWebEngine ) { mWebEngine.GoBack(); } } -void WebView::EvaluateJavaScript( const std::string& script ) +void WebView::EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler ) { - if ( mWebEngine ) + if( mWebEngine ) { - mWebEngine.EvaluateJavaScript( script ); + mWebEngine.EvaluateJavaScript( script, resultHandler ); } } void WebView::AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler ) { - if ( mWebEngine ) + if( mWebEngine ) { mWebEngine.AddJavaScriptMessageHandler( exposedObjectName, handler ); } @@ -210,7 +255,7 @@ void WebView::AddJavaScriptMessageHandler( const std::string& exposedObjectName, void WebView::ClearHistory() { - if ( mWebEngine ) + if( mWebEngine ) { mWebEngine.ClearHistory(); } @@ -218,22 +263,35 @@ void WebView::ClearHistory() void WebView::ClearCache() { - if ( mWebEngine ) + if( mWebEngine ) { mWebEngine.ClearCache(); } } -Dali::Toolkit::WebView::WebViewSignalType& WebView::PageLoadStartedSignal() +void WebView::ClearCookies() +{ + if( mWebEngine ) + { + mWebEngine.ClearCookies(); + } +} + +Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadStartedSignal() { return mPageLoadStartedSignal; } -Dali::Toolkit::WebView::WebViewSignalType& WebView::PageLoadFinishedSignal() +Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadFinishedSignal() { return mPageLoadFinishedSignal; } +Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType& WebView::PageLoadErrorSignal() +{ + return mPageLoadErrorSignal; +} + void WebView::OnPageLoadStarted( const std::string& url ) { if( !mPageLoadStartedSignal.Empty() ) @@ -252,6 +310,15 @@ void WebView::OnPageLoadFinished( const std::string& url ) } } +void WebView::OnPageLoadError( const std::string& url, int errorCode ) +{ + if( !mPageLoadErrorSignal.Empty() ) + { + Dali::Toolkit::WebView handle( GetOwner() ); + mPageLoadErrorSignal.Emit( handle, url, static_cast< Toolkit::WebView::LoadErrorCode >( errorCode ) ); + } +} + bool WebView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) { Dali::BaseHandle handle( object ); @@ -269,6 +336,11 @@ bool WebView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* t webView.PageLoadFinishedSignal().Connect( tracker, functor ); connected = true; } + else if( 0 == strcmp( signalName.c_str(), PAGE_LOAD_ERROR_SIGNAL ) ) + { + webView.PageLoadErrorSignal().Connect( tracker, functor ); + connected = true; + } return connected; } @@ -318,6 +390,65 @@ 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; + if( value.Get( input ) ) + { + impl.SetUserAgent( input ); + } + 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; + } } } } @@ -335,9 +466,46 @@ Property::Value WebView::GetProperty( BaseObject* object, Property::Index proper { case Toolkit::WebView::Property::URL: { - value = impl.GetUrl(); + 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; + } + default: + break; } } @@ -348,7 +516,7 @@ bool WebView::OnTouchEvent( Actor actor, const Dali::TouchData& touch ) { bool result = false; - if ( mWebEngine ) + if( mWebEngine ) { result = mWebEngine.SendTouchEvent( touch ); } @@ -359,13 +527,107 @@ bool WebView::OnKeyEvent( const Dali::KeyEvent& event ) { bool result = false; - if ( mWebEngine ) + if( mWebEngine ) { result = mWebEngine.SendKeyEvent( event ); } return result; } +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; +} + +void WebView::SetUserAgent( const std::string& userAgent ) +{ + if( mWebEngine ) + { + mWebEngine.SetUserAgent( 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 + } // namespace Internal } // namespace Toolkit 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 2bc7ddf..bce288d 100644 --- a/dali-toolkit/internal/controls/web-view/web-view-impl.h +++ b/dali-toolkit/internal/controls/web-view/web-view-impl.h @@ -68,74 +68,89 @@ public: void LoadUrl( const std::string& url ); /** - * @copydoc Dali::Toolkit::WebView::GetUrl() - */ - const std::string& GetUrl(); - - /** * @copydoc Dali::WebEngine::LoadHTMLString() */ void LoadHTMLString( const std::string& htmlString ); /** - * @copydoc Dali::WebEngine::Reload() + * @copydoc Dali::Toolkit::WebView::Reload() */ void Reload(); /** - * @copydoc Dali::WebEngine::StopLoading() + * @copydoc Dali::Toolkit::WebView::StopLoading() */ void StopLoading(); /** - * @copydoc Dali::WebEngine::CanGoForward() + * @copydoc Dali::Toolkit::WebView::StopLoading() + */ + void Suspend(); + + /** + * @copydoc Dali::Toolkit::WebView::Resume() + */ + void Resume(); + + /** + * @copydoc Dali::Toolkit::WebView::CanGoForward() */ bool CanGoForward(); /** - * @copydoc Dali::WebEngine::GoForward() + * @copydoc Dali::Toolkit::WebView::GoForward() */ void GoForward(); /** - * @copydoc Dali::WebEngine::CanGoBack() + * @copydoc Dali::Toolkit::WebView::CanGoBack() */ bool CanGoBack(); /** - * @copydoc Dali::WebEngine::GoBack() + * @copydoc Dali::Toolkit::WebView::GoBack() */ void GoBack(); /** - * @copydoc Dali::WebEngine::EvaluateJavaScript() + * @copydoc Dali::Toolkit::WebView::EvaluateJavaScript() */ - void EvaluateJavaScript( const std::string& script ); + void EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler ); /** - * @copydoc Dali::WebEngine::AddJavaScriptMessageHandler() + * @copydoc Dali::Toolkit::WebView::AddJavaScriptMessageHandler() */ void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler ); /** - * @copydoc Dali::WebEngine::ClearHistory() + * @copydoc Dali::Toolkit::WebView::ClearHistory() */ void ClearHistory(); /** - * @copydoc Dali::WebEngine::ClearCache() + * @copydoc Dali::Toolkit::WebView::ClearCache() */ void ClearCache(); /** + * @copydoc Dali::Toolkit::WebView::ClearCookies() + */ + void ClearCookies(); + + /** * @copydoc Dali::Toolkit::WebView::PageLoadStartedSignal() */ - Dali::Toolkit::WebView::WebViewSignalType& PageLoadStartedSignal(); + Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadStartedSignal(); /** * @copydoc Dali::Toolkit::WebView::PageLoadFinishedSignal() */ - Dali::Toolkit::WebView::WebViewSignalType& PageLoadFinishedSignal(); + Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadFinishedSignal(); + + /** + * @copydoc Dali::Toolkit::WebView::PageLoadErrorSignal() + */ + Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType& PageLoadErrorSignal(); public: // Properties @@ -205,18 +220,129 @@ private: WebView& operator=( const WebView& webView ); + /** + * @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 + */ + const std::string& GetUserAgent() const; + + /** + * @brief Set user agent string. + * @param[in] userAgent The string value of user agent + */ + 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 + */ void OnPageLoadStarted( const std::string& url ); + /** + * @brief Callback function to be called when page load finished. + * @param[in] url The url currently being loaded + */ void OnPageLoadFinished( const std::string& url ); + /** + * @brief Callback function to be called when there is an error in page loading. + * @param[in] url The url currently being loaded + * @param[in] errorCode The error code + */ + void OnPageLoadError( const std::string& url, int errorCode ); + private: - std::string mUrl; - Dali::Toolkit::Visual::Base mVisual; - Dali::Size mWebViewSize; - Dali::WebEngine mWebEngine; - Dali::Toolkit::WebView::WebViewSignalType mPageLoadStartedSignal; - Dali::Toolkit::WebView::WebViewSignalType mPageLoadFinishedSignal; + std::string mUrl; + Dali::Toolkit::Visual::Base mVisual; + Dali::Size mWebViewSize; + Dali::WebEngine mWebEngine; + + Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadStartedSignal; + Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadFinishedSignal; + Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType mPageLoadErrorSignal; }; } // namespace Internal