/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * 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.
namespace
{
-static WebEngine* gInstance = NULL;
+
+// Generally only one WebEngine instance exists.
+// If > 1, a new web engine has been created by CreateWindowSignal.
+static WebEngine* gInstance = 0;
static int gInstanceCount = 0;
bool OnGoBack();
bool OnGoForward();
bool OnLoadUrl();
bool OnEvaluteJavaScript();
+bool OnJavaScriptAlert();
+bool OnJavaScriptConfirm();
+bool OnJavaScriptPrompt();
+bool OnScrollEdge();
bool OnClearHistory();
-static void ConnectToGlobalSignal( bool (*func)() )
+static void ConnectToGlobalSignal( bool ( *func )() )
{
Dali::Timer timer = Dali::Timer::New( 0 );
timer.TickSignal().Connect( func );
}
-static void DisconnectFromGlobalSignal( bool (*func)() )
+static void DisconnectFromGlobalSignal( bool ( *func )() )
{
Dali::Timer timer = Dali::Timer::New( 0 );
timer.TickSignal().Disconnect( func );
}
-}
+} // namespace anonymous
class MockWebEngineContext : public Dali::WebEngineContext
{
{
public:
+ using JavaScriptEvaluatedResultCallback = std::function<void(const std::string&)>;
+ using JavaScriptAlertCallback = std::function<bool(const std::string&)>;
+ using JavaScriptConfirmCallback = std::function<bool(const std::string&)>;
+ using JavaScriptPromptCallback = std::function<bool(const std::string&, const std::string&)>;
+
WebEngine()
: mUrl()
, mCurrentPlusOnePos( 0 )
, mContentSize( 500, 500 )
{
gInstanceCount++;
- gInstance = this;
+ if ( gInstanceCount == 1 ) // only first web engine need be saved.
+ {
+ gInstance = this;
+ }
mockWebEngineSettings = new MockWebEngineSettings();
mockWebEngineContext = new MockWebEngineContext();
gInstanceCount--;
if( !gInstanceCount )
{
- gInstance = NULL;
+ gInstance = 0;
}
delete mockWebEngineSettings;
}
}
+ void RegisterJavaScriptAlertCallback( Dali::WebEnginePlugin::JavaScriptAlertCallback callback )
+ {
+ if ( callback )
+ {
+ ConnectToGlobalSignal( &OnJavaScriptAlert );
+ mJavaScriptAlertCallback = callback;
+ }
+ }
+
+ void RegisterJavaScriptConfirmCallback( Dali::WebEnginePlugin::JavaScriptConfirmCallback callback )
+ {
+ if ( callback )
+ {
+ ConnectToGlobalSignal( &OnJavaScriptConfirm );
+ mJavaScriptConfirmCallback = callback;
+ }
+ }
+
+ void RegisterJavaScriptPromptCallback( Dali::WebEnginePlugin::JavaScriptPromptCallback callback )
+ {
+ if ( callback )
+ {
+ ConnectToGlobalSignal( &OnJavaScriptPrompt );
+ mJavaScriptPromptCallback = callback;
+ }
+ }
+
void ClearHistory()
{
ConnectToGlobalSignal( &OnClearHistory );
mScrollPosition += Dali::Vector2( dx, dy );
if ( mScrollPosition.y + mScrollSize.height > mContentSize.height )
{
- gInstance->mScrollEdgeReachedSignal.Emit( Dali::WebEnginePlugin::ScrollEdge::BOTTOM );
+ ConnectToGlobalSignal( &OnScrollEdge );
}
}
return mPageLoadStartedSignal;
}
+ Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadInProgressSignal()
+ {
+ return mPageLoadInProgressSignal;
+ }
+
Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal()
{
return mPageLoadFinishedSignal;
return mScrollEdgeReachedSignal;
}
+ Dali::WebEnginePlugin::WebEngineUrlChangedSignalType& UrlChangedSignal()
+ {
+ return mUrlChangedSignal;
+ }
+
std::string mUrl;
std::vector< std::string > mHistory;
size_t mCurrentPlusOnePos;
std::string mUserAgent;
Dali::WebEnginePlugin::WebEnginePageLoadSignalType mPageLoadStartedSignal;
+ Dali::WebEnginePlugin::WebEnginePageLoadSignalType mPageLoadInProgressSignal;
Dali::WebEnginePlugin::WebEnginePageLoadSignalType mPageLoadFinishedSignal;
Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType mPageLoadErrorSignal;
- std::vector< std::function< void( const std::string& ) > > mResultCallbacks;
+ std::vector<JavaScriptEvaluatedResultCallback> mResultCallbacks;
bool mEvaluating;
Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType mScrollEdgeReachedSignal;
WebEngineContext* mockWebEngineContext;
WebEngineCookieManager* mockWebEngineCookieManager;
WebEngineSettings* mockWebEngineSettings;
-};
+ Dali::WebEnginePlugin::WebEngineUrlChangedSignalType mUrlChangedSignal;
-inline WebEngine& GetImplementation( Dali::WebEngine& webEngine )
-{
- DALI_ASSERT_ALWAYS( webEngine && "WebEngine handle is empty." );
- BaseObject& handle = webEngine.GetBaseObject();
- return static_cast< Internal::Adaptor::WebEngine& >( handle );
-}
+ JavaScriptAlertCallback mJavaScriptAlertCallback;
+ JavaScriptConfirmCallback mJavaScriptConfirmCallback;
+ JavaScriptPromptCallback mJavaScriptPromptCallback;
+};
-inline const WebEngine& GetImplementation( const Dali::WebEngine& webEngine )
-{
- DALI_ASSERT_ALWAYS( webEngine && "WebEngine handle is empty." );
- const BaseObject& handle = webEngine.GetBaseObject();
- return static_cast< const Internal::Adaptor::WebEngine& >( handle );
-}
namespace
{
gInstance->mHistory.push_back( gInstance->mUrl );
gInstance->mCurrentPlusOnePos++;
gInstance->mPageLoadStartedSignal.Emit( gInstance->mUrl );
+ gInstance->mPageLoadInProgressSignal.Emit( gInstance->mUrl );
gInstance->mPageLoadFinishedSignal.Emit( gInstance->mUrl );
+ gInstance->mUrlChangedSignal.Emit( "http://new-test" );
}
return false;
}
+bool OnScrollEdge()
+{
+ DisconnectFromGlobalSignal( &OnScrollEdge );
+
+ if( gInstance )
+ {
+ gInstance->mScrollEdgeReachedSignal.Emit( Dali::WebEnginePlugin::ScrollEdge::BOTTOM );
+ }
+
+ return false;
+}
+
bool OnEvaluteJavaScript()
{
DisconnectFromGlobalSignal( &OnEvaluteJavaScript );
return false;
}
+bool OnJavaScriptAlert()
+{
+ DisconnectFromGlobalSignal( &OnJavaScriptAlert );
+ if ( gInstance )
+ {
+ gInstance->mJavaScriptAlertCallback( "this is an alert popup." );
+ }
+ return false;
+}
+
+bool OnJavaScriptConfirm()
+{
+ DisconnectFromGlobalSignal( &OnJavaScriptConfirm );
+ if ( gInstance )
+ {
+ gInstance->mJavaScriptConfirmCallback( "this is a confirm popup." );
+ }
+ return false;
+}
+
+bool OnJavaScriptPrompt()
+{
+ DisconnectFromGlobalSignal( &OnJavaScriptPrompt );
+ if ( gInstance )
+ {
+ gInstance->mJavaScriptPromptCallback( "this is a prompt pompt.", "" );
+ }
+ return false;
+}
+
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 );
}
return false;
}
+
} // namespace
+inline WebEngine& GetImplementation( Dali::WebEngine& webEngine )
+{
+ DALI_ASSERT_ALWAYS( webEngine && "WebEngine handle is empty." );
+ BaseObject& handle = webEngine.GetBaseObject();
+ return static_cast< Internal::Adaptor::WebEngine& >( handle );
+}
+
+inline const WebEngine& GetImplementation( const Dali::WebEngine& webEngine )
+{
+ DALI_ASSERT_ALWAYS( webEngine && "WebEngine handle is empty." );
+ const BaseObject& handle = webEngine.GetBaseObject();
+ return static_cast< const Internal::Adaptor::WebEngine& >( handle );
+}
+
} // namespace Adaptor
} // namespace Internal
-
// Dali::WebEngine Implementation
WebEngine::WebEngine()
{
{
}
+void WebEngine::RegisterJavaScriptAlertCallback( Dali::WebEnginePlugin::JavaScriptAlertCallback callback )
+{
+ Internal::Adaptor::GetImplementation( *this ).RegisterJavaScriptAlertCallback( callback );
+}
+
+void WebEngine::JavaScriptAlertReply()
+{
+}
+
+void WebEngine::RegisterJavaScriptConfirmCallback( Dali::WebEnginePlugin::JavaScriptConfirmCallback callback )
+{
+ Internal::Adaptor::GetImplementation( *this ).RegisterJavaScriptConfirmCallback( callback );
+}
+
+void WebEngine::JavaScriptConfirmReply( bool confirmed )
+{
+}
+
+void WebEngine::RegisterJavaScriptPromptCallback( Dali::WebEnginePlugin::JavaScriptPromptCallback callback )
+{
+ Internal::Adaptor::GetImplementation( *this ).RegisterJavaScriptPromptCallback( callback );
+}
+
+void WebEngine::JavaScriptPromptReply( const std::string& result )
+{
+}
+
void WebEngine::ClearAllTilesResources()
{
}
return Internal::Adaptor::GetImplementation( *this ).PageLoadStartedSignal();
}
+Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadInProgressSignal()
+{
+ return Internal::Adaptor::GetImplementation( *this ).PageLoadInProgressSignal();
+}
+
Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadFinishedSignal()
{
return Internal::Adaptor::GetImplementation( *this ).PageLoadFinishedSignal();
return Internal::Adaptor::GetImplementation( *this ).ScrollEdgeReachedSignal();
}
+Dali::WebEnginePlugin::WebEngineUrlChangedSignalType& WebEngine::UrlChangedSignal()
+{
+ return Internal::Adaptor::GetImplementation( *this ).UrlChangedSignal();
+}
+
} // namespace Dali;
const char* const TEST_URL2( "http://www.somewhere.valid2.com" );
static int gPageLoadStartedCallbackCalled = 0;
+static int gPageLoadInProgressCallbackCalled = 0;
static int gPageLoadFinishedCallbackCalled = 0;
static int gScrollEdgeReachedCallbackCalled = 0;
+static int gUrlChangedCallbackCalled = 0;
static int gEvaluateJavaScriptCallbackCalled = 0;
+static int gJavaScriptAlertCallbackCalled = 0;
+static int gJavaScriptConfirmCallbackCalled = 0;
+static int gJavaScriptPromptCallbackCalled = 0;
static bool gTouched = false;
struct CallbackFunctor
gPageLoadStartedCallbackCalled++;
}
+static void OnPageLoadInProgress( WebView view, const std::string& url )
+{
+ gPageLoadInProgressCallbackCalled++;
+}
+
static void OnPageLoadFinished( WebView view, const std::string& url )
{
gPageLoadFinishedCallbackCalled++;
gScrollEdgeReachedCallbackCalled++;
}
+static void OnUrlChanged( WebView view, const std::string& url )
+{
+ gUrlChangedCallbackCalled++;
+}
+
static void OnPageLoadError( WebView view, const std::string& url, WebView::LoadErrorCode errorCode )
{
}
gEvaluateJavaScriptCallbackCalled++;
}
+static bool OnJavaScriptAlert( const std::string& result )
+{
+ gJavaScriptAlertCallbackCalled++;
+ return true;
+}
+
+static bool OnJavaScriptConfirm( const std::string& result )
+{
+ gJavaScriptConfirmCallbackCalled++;
+ return true;
+}
+
+static bool OnJavaScriptPrompt( const std::string& meesage1, const std::string& message2 )
+{
+ gJavaScriptPromptCallbackCalled++;
+ return true;
+}
+
static bool OnTouched( Actor actor, const Dali::TouchEvent& touch )
{
gTouched = true;
ConnectionTracker* testTracker = new ConnectionTracker();
view.PageLoadStartedSignal().Connect( &OnPageLoadStarted );
+ view.PageLoadInProgressSignal().Connect( &OnPageLoadInProgress );
view.PageLoadFinishedSignal().Connect( &OnPageLoadFinished );
view.PageLoadErrorSignal().Connect( &OnPageLoadError );
+ view.UrlChangedSignal().Connect( &OnUrlChanged );
bool signal1 = false;
bool signal2 = false;
bool signal3 = false;
+ bool signal4 = false;
+ bool signal5 = false;
view.ConnectSignal( testTracker, "pageLoadStarted", CallbackFunctor(&signal1) );
- view.ConnectSignal( testTracker, "pageLoadFinished", CallbackFunctor(&signal2) );
- view.ConnectSignal( testTracker, "invalidname", CallbackFunctor(&signal3) );
+ view.ConnectSignal( testTracker, "pageLoadInProgress", CallbackFunctor(&signal2) );
+ view.ConnectSignal( testTracker, "pageLoadFinished", CallbackFunctor(&signal3) );
+ view.ConnectSignal( testTracker, "urlChanged", CallbackFunctor(&signal4) );
+ view.ConnectSignal( testTracker, "invalidname", CallbackFunctor(&signal5) );
DALI_TEST_EQUALS( gPageLoadStartedCallbackCalled, 0, TEST_LOCATION );
+ DALI_TEST_EQUALS( gPageLoadInProgressCallbackCalled, 0, TEST_LOCATION );
DALI_TEST_EQUALS( gPageLoadFinishedCallbackCalled, 0, TEST_LOCATION );
-
+ DALI_TEST_EQUALS( gUrlChangedCallbackCalled, 0, TEST_LOCATION );
view.LoadUrl( TEST_URL1 );
view.GetNaturalSize();
Test::EmitGlobalTimerSignal();
DALI_TEST_EQUALS( view.CanGoBack(), false, TEST_LOCATION );
DALI_TEST_EQUALS( gPageLoadStartedCallbackCalled, 1, TEST_LOCATION );
+ DALI_TEST_EQUALS( gPageLoadInProgressCallbackCalled, 1, TEST_LOCATION );
DALI_TEST_EQUALS( gPageLoadFinishedCallbackCalled, 1, TEST_LOCATION );
- DALI_TEST_CHECK( signal1 & signal2 );
- DALI_TEST_CHECK( !signal3 );
+ DALI_TEST_EQUALS( gUrlChangedCallbackCalled, 1, TEST_LOCATION );
+ DALI_TEST_CHECK( signal1 & signal2 & signal3 & signal4 );
+ DALI_TEST_CHECK( !signal5 );
view.LoadUrl( TEST_URL2 );
view.Suspend();
DALI_TEST_EQUALS( view.CanGoBack(), true, TEST_LOCATION );
DALI_TEST_EQUALS( view.CanGoForward(), false, TEST_LOCATION );
DALI_TEST_EQUALS( gPageLoadStartedCallbackCalled, 2, TEST_LOCATION );
+ DALI_TEST_EQUALS( gPageLoadInProgressCallbackCalled, 2, TEST_LOCATION );
DALI_TEST_EQUALS( gPageLoadFinishedCallbackCalled, 2, TEST_LOCATION );
+ DALI_TEST_EQUALS( gUrlChangedCallbackCalled, 2, TEST_LOCATION );
view.GoBack();
Test::EmitGlobalTimerSignal();
// scroll by and trigger scrollEdgeReached event.
view.ScrollBy( 50, 50 );
+ Test::EmitGlobalTimerSignal();
+
view.GetProperty( WebView::Property::SCROLL_POSITION ).Get( output );
DALI_TEST_CHECK( output.x == 150 && output.y == 150 );
DALI_TEST_EQUALS( gScrollEdgeReachedCallbackCalled, 1, TEST_LOCATION );
END_TEST;
}
+int UtcDaliWebViewJavaScriptAlertConfirmPrompt(void)
+{
+ ToolkitTestApplication application;
+
+ WebView view = WebView::New( "ko-KR", "Asia/Seoul" );
+
+ view.RegisterJavaScriptAlertCallback( &OnJavaScriptAlert );
+ view.LoadHtmlString( "<head><script type='text/javascript'>alert('this is an alert popup.');</script></head><body>Hello World!</body>" );
+ view.JavaScriptAlertReply();
+ Test::EmitGlobalTimerSignal();
+ DALI_TEST_EQUALS( gJavaScriptAlertCallbackCalled, 1, TEST_LOCATION );
+
+ view.RegisterJavaScriptConfirmCallback( &OnJavaScriptConfirm );
+ view.LoadHtmlString( "<head><script type='text/javascript'>confirm('this is a confirm popup.');</script></head><body>Hello World!</body>" );
+ view.JavaScriptConfirmReply( true );
+ Test::EmitGlobalTimerSignal();
+ DALI_TEST_EQUALS( gJavaScriptConfirmCallbackCalled, 1, TEST_LOCATION );
+
+ view.RegisterJavaScriptPromptCallback( &OnJavaScriptPrompt );
+ view.LoadHtmlString( "<head><script type='text/javascript'>prompt('this is a prompt popup.');</script></head><body>Hello World!</body>" );
+ view.JavaScriptPromptReply( "it is a prompt." );
+ Test::EmitGlobalTimerSignal();
+ DALI_TEST_EQUALS( gJavaScriptPromptCallbackCalled, 1, TEST_LOCATION );
+
+ END_TEST;
+}
+
int UtcDaliWebViewMethodsForCoverage(void)
{
ToolkitTestApplication application;
Dali::Toolkit::GetImpl(*this).AddJavaScriptMessageHandler(exposedObjectName, handler);
}
-void WebView::ClearAllTilesResources()
+void WebView::RegisterJavaScriptAlertCallback( Dali::WebEnginePlugin::JavaScriptAlertCallback callback )
+{
+ Dali::Toolkit::GetImpl( *this ).RegisterJavaScriptAlertCallback( callback );
+}
+
+void WebView::JavaScriptAlertReply()
+{
+ Dali::Toolkit::GetImpl( *this ).JavaScriptAlertReply();
+}
+
+void WebView::RegisterJavaScriptConfirmCallback( Dali::WebEnginePlugin::JavaScriptConfirmCallback callback )
+{
+ Dali::Toolkit::GetImpl( *this ).RegisterJavaScriptConfirmCallback( callback );
+}
+
+void WebView::JavaScriptConfirmReply( bool confirmed )
+{
+ Dali::Toolkit::GetImpl( *this ).JavaScriptConfirmReply( confirmed );
+}
+
+void WebView::RegisterJavaScriptPromptCallback( Dali::WebEnginePlugin::JavaScriptPromptCallback callback )
{
- Dali::Toolkit::GetImpl(*this).ClearAllTilesResources();
+ Dali::Toolkit::GetImpl( *this ).RegisterJavaScriptPromptCallback( callback );
+}
+
+void WebView::JavaScriptPromptReply( const std::string& result )
+{
+ Dali::Toolkit::GetImpl( *this ).JavaScriptPromptReply( result );
}
void WebView::ClearHistory()
Dali::Toolkit::GetImpl(*this).ClearHistory();
}
+void WebView::ClearAllTilesResources()
+{
+ Dali::Toolkit::GetImpl( *this ).ClearAllTilesResources();
+}
+
WebView::WebViewPageLoadSignalType& WebView::PageLoadStartedSignal()
{
return Dali::Toolkit::GetImpl(*this).PageLoadStartedSignal();
}
+WebView::WebViewPageLoadSignalType& WebView::PageLoadInProgressSignal()
+{
+ return Dali::Toolkit::GetImpl( *this ).PageLoadInProgressSignal();
+}
+
WebView::WebViewPageLoadSignalType& WebView::PageLoadFinishedSignal()
{
return Dali::Toolkit::GetImpl(*this).PageLoadFinishedSignal();
return Dali::Toolkit::GetImpl(*this).ScrollEdgeReachedSignal();
}
+WebView::WebViewUrlChangedSignalType& WebView::UrlChangedSignal()
+{
+ return Dali::Toolkit::GetImpl( *this ).UrlChangedSignal();
+}
+
WebView::WebView(Internal::WebView& implementation)
: Control(implementation)
{
*/
using WebViewScrollEdgeReachedSignalType = Signal<void(WebView, Dali::WebEnginePlugin::ScrollEdge)>;
+ /**
+ * @brief WebView signal type related with url changed.
+ */
+ using WebViewUrlChangedSignalType = Signal<void(WebView, const std::string&)>;
+
public:
/**
* @brief Creates an initialized WebView.
void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
/**
- * @brief Clears all tiles resources of Web.
+ * @brief Register alert callback for javascript.
+ *
+ * @param[in] callback The callback function to be called by the JavaScript runtime.
*/
- void ClearAllTilesResources();
+ void RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback);
+
+ /**
+ * @brief Reply for JavaScript alert.
+ */
+ void JavaScriptAlertReply();
+
+ /**
+ * @brief Register confirm callback for javascript.
+ *
+ * @param[in] callback The callback function to be called by the JavaScript runtime.
+ */
+ void RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback);
+
+ /**
+ * @brief Reply for JavaScript confirm.
+ * @param[in] confirmed True if confirmed, false otherwise
+ */
+ void JavaScriptConfirmReply(bool confirmed);
+
+ /**
+ * @brief Register prompt callback for javascript.
+ *
+ * @param[in] callback The callback function to be called by the JavaScript runtime.
+ */
+ void RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback);
+
+ /**
+ * @brief Reply for JavaScript prompt.
+ * @param[in] result The result from input-field of prompt popup.
+ */
+ void JavaScriptPromptReply(const std::string& result);
/**
* @brief Clears the history of Web.
void ClearHistory();
/**
+ * @brief Clears all tiles resources of Web.
+ */
+ void ClearAllTilesResources();
+
+ /**
* @brief Connects to this signal to be notified when page loading is started.
*
* @return A signal object to connect with
WebViewPageLoadSignalType& PageLoadStartedSignal();
/**
+ * @brief Connects to this signal to be notified when page loading is in progress.
+ *
+ * @return A signal object to connect with.
+ */
+ WebViewPageLoadSignalType& PageLoadInProgressSignal();
+
+ /**
* @brief Connects to this signal to be notified when page loading is finished.
*
* @return A signal object to connect with
*/
WebViewScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
+ /**
+ * @brief Connects to this signal to be notified when url is changed.
+ *
+ * @return A signal object to connect with.
+ */
+ WebViewUrlChangedSignalType& UrlChangedSignal();
+
public: // Not intended for application developers
/// @cond internal
/**
DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "title", STRING, TITLE )
DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "videoHoleEnabled", BOOLEAN, VIDEO_HOLE_ENABLED)
-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_SIGNAL_REGISTRATION(Toolkit, WebView, "scrollEdgeReached", SCROLL_EDGE_REACHED_SIGNAL)
+DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadStarted", PAGE_LOAD_STARTED_SIGNAL )
+DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadInProgress", PAGE_LOAD_IN_PROGRESS_SIGNAL)
+DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadFinished", PAGE_LOAD_FINISHED_SIGNAL )
+DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadError", PAGE_LOAD_ERROR_SIGNAL )
+DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "scrollEdgeReached", SCROLL_EDGE_REACHED_SIGNAL )
+DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "urlChanged", URL_CHANGED_SIGNAL )
DALI_TYPE_REGISTRATION_END()
// clang-format on
mPageLoadFinishedSignal(),
mPageLoadErrorSignal(),
mVideoHoleEnabled(true),
- mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height)
+ mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
+ mUrlChangedSignal()
{
mWebEngine = Dali::WebEngine::New();
mPageLoadFinishedSignal(),
mPageLoadErrorSignal(),
mVideoHoleEnabled(true),
- mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height)
+ mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
+ mUrlChangedSignal()
{
mWebEngine = Dali::WebEngine::New();
if(mWebEngine)
{
- mWebEngine.PageLoadStartedSignal().Connect(this, &WebView::OnPageLoadStarted);
- mWebEngine.PageLoadFinishedSignal().Connect(this, &WebView::OnPageLoadFinished);
- mWebEngine.PageLoadErrorSignal().Connect(this, &WebView::OnPageLoadError);
- mWebEngine.ScrollEdgeReachedSignal().Connect(this, &WebView::OnScrollEdgeReached);
+ mWebEngine.PageLoadStartedSignal().Connect( this, &WebView::OnPageLoadStarted );
+ mWebEngine.PageLoadInProgressSignal().Connect(this, &WebView::OnPageLoadInProgress);
+ mWebEngine.PageLoadFinishedSignal().Connect( this, &WebView::OnPageLoadFinished );
+ mWebEngine.PageLoadErrorSignal().Connect( this, &WebView::OnPageLoadError );
+ mWebEngine.ScrollEdgeReachedSignal().Connect( this, &WebView::OnScrollEdgeReached );
+ mWebEngine.UrlChangedSignal().Connect(this, &WebView::OnUrlChanged);
mWebContext = std::unique_ptr<Dali::Toolkit::WebContext>(new WebContext(mWebEngine.GetContext()));
mWebCookieManager = std::unique_ptr<Dali::Toolkit::WebCookieManager>(new WebCookieManager(mWebEngine.GetCookieManager()));
}
}
-void WebView::ClearAllTilesResources()
+void WebView::RegisterJavaScriptAlertCallback( Dali::WebEnginePlugin::JavaScriptAlertCallback callback )
{
if(mWebEngine)
{
- mWebEngine.ClearAllTilesResources();
+ mWebEngine.RegisterJavaScriptAlertCallback( callback );
+ }
+}
+
+void WebView::JavaScriptAlertReply()
+{
+ if ( mWebEngine )
+ {
+ mWebEngine.JavaScriptAlertReply();
+ }
+}
+
+void WebView::RegisterJavaScriptConfirmCallback( Dali::WebEnginePlugin::JavaScriptConfirmCallback callback )
+{
+ if ( mWebEngine )
+ {
+ mWebEngine.RegisterJavaScriptConfirmCallback( callback );
+ }
+}
+
+void WebView::JavaScriptConfirmReply( bool confirmed )
+{
+ if ( mWebEngine )
+ {
+ mWebEngine.JavaScriptConfirmReply( confirmed );
+ }
+}
+
+void WebView::RegisterJavaScriptPromptCallback( Dali::WebEnginePlugin::JavaScriptPromptCallback callback )
+{
+ if ( mWebEngine )
+ {
+ mWebEngine.RegisterJavaScriptPromptCallback( callback );
+ }
+}
+
+void WebView::JavaScriptPromptReply( const std::string& result )
+{
+ if ( mWebEngine )
+ {
+ mWebEngine.JavaScriptPromptReply( result );
}
}
}
}
+void WebView::ClearAllTilesResources()
+{
+ if( mWebEngine )
+ {
+ mWebEngine.ClearAllTilesResources();
+ }
+}
+
Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadStartedSignal()
{
return mPageLoadStartedSignal;
}
+Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadInProgressSignal()
+{
+ return mPageLoadInProgressSignal;
+}
+
Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadFinishedSignal()
{
return mPageLoadFinishedSignal;
return mScrollEdgeReachedSignal;
}
-void WebView::OnPageLoadStarted(const std::string& url)
+Dali::Toolkit::WebView::WebViewUrlChangedSignalType& WebView::UrlChangedSignal()
+{
+ return mUrlChangedSignal;
+}
+
+void WebView::OnPageLoadStarted( const std::string& url )
{
if(!mPageLoadStartedSignal.Empty())
{
}
}
-void WebView::OnPageLoadFinished(const std::string& url)
+void WebView::OnPageLoadInProgress( const std::string& url )
+{
+ if ( !mPageLoadInProgressSignal.Empty() )
+ {
+ Dali::Toolkit::WebView handle( GetOwner() );
+ mPageLoadInProgressSignal.Emit( handle, url );
+ }
+}
+
+void WebView::OnPageLoadFinished( const std::string& url )
{
if(!mPageLoadFinishedSignal.Empty())
{
}
}
-bool WebView::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
+void WebView::OnUrlChanged(const std::string& url)
+{
+ if (!mUrlChangedSignal.Empty())
+ {
+ Dali::Toolkit::WebView handle(GetOwner());
+ mUrlChangedSignal.Emit(handle, url);
+ }
+}
+
+bool WebView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
{
Dali::BaseHandle handle(object);
webView.PageLoadStartedSignal().Connect(tracker, functor);
connected = true;
}
+ else if (0 == strcmp(signalName.c_str(), PAGE_LOAD_IN_PROGRESS_SIGNAL))
+ {
+ webView.PageLoadInProgressSignal().Connect(tracker, functor);
+ connected = true;
+ }
else if(0 == strcmp(signalName.c_str(), PAGE_LOAD_FINISHED_SIGNAL))
{
webView.PageLoadFinishedSignal().Connect(tracker, functor);
webView.ScrollEdgeReachedSignal().Connect(tracker, functor);
connected = true;
}
+ else if (0 == strcmp(signalName.c_str(), URL_CHANGED_SIGNAL))
+ {
+ webView.UrlChangedSignal().Connect( tracker, functor );
+ connected = true;
+ }
return connected;
}
void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
/**
- * @brief Clears all tiles resources of Web.
+ * @copydoc Dali::Toolkit::WebView::RegisterJavaScriptAlertCallback()
*/
- void ClearAllTilesResources();
+ void RegisterJavaScriptAlertCallback( Dali::WebEnginePlugin::JavaScriptAlertCallback callback );
+
+ /**
+ * @copydoc Dali::Toolkit::WebView::JavaScriptAlertReply()
+ */
+ void JavaScriptAlertReply();
+
+ /**
+ * @copydoc Dali::Toolkit::WebView::RegisterJavaScriptConfirmCallback()
+ */
+ void RegisterJavaScriptConfirmCallback( Dali::WebEnginePlugin::JavaScriptConfirmCallback callback );
+
+ /**
+ * @copydoc Dali::Toolkit::WebView::JavaScriptConfirmReply()
+ */
+ void JavaScriptConfirmReply( bool confirmed );
+
+ /**
+ * @copydoc Dali::Toolkit::WebView::RegisterJavaScriptPromptCallback()
+ */
+ void RegisterJavaScriptPromptCallback( Dali::WebEnginePlugin::JavaScriptPromptCallback callback);
+
+ /**
+ * @copydoc Dali::Toolkit::WebView::JavaScriptPromptReply()
+ */
+ void JavaScriptPromptReply( const std::string& result );
/**
* @copydoc Dali::Toolkit::WebView::ClearHistory()
void ClearHistory();
/**
+ * @brief Clears all tiles resources of Web.
+ */
+ void ClearAllTilesResources();
+
+ /**
* @copydoc Dali::Toolkit::WebView::PageLoadStartedSignal()
*/
Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadStartedSignal();
/**
+ * @copydoc Dali::Toolkit::WebView::PageLoadInProgressSignal()
+ */
+ Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadInProgressSignal();
+
+ /**
* @copydoc Dali::Toolkit::WebView::PageLoadFinishedSignal()
*/
Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadFinishedSignal();
*/
Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
+ /**
+ * @copydoc Dali::Toolkit::WebView::UrlChangedSignal()
+ */
+ Dali::Toolkit::WebView::WebViewUrlChangedSignalType& UrlChangedSignal();
+
public: // Properties
/**
* @brief Called when a property of an object of this type is set.
void OnPageLoadStarted(const std::string& url);
/**
+ * @brief Callback function to be called when page is loading in progress.
+ * @param[in] url The url currently being loaded
+ */
+ void OnPageLoadInProgress( const std::string& url );
+
+ /**
* @brief Callback function to be called when page load finished.
* @param[in] url The url currently being loaded
*/
*/
void OnScrollEdgeReached(Dali::WebEnginePlugin::ScrollEdge edge);
+ /**
+ * @brief Callback function to be called when url is changed.
+ * @param[in] url The url currently being loaded
+ */
+ void OnUrlChanged( const std::string& url );
+
private:
- 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;
+ std::string mUrl;
+ Dali::Toolkit::Visual::Base mVisual;
+ Dali::Size mWebViewSize;
+ Dali::WebEngine mWebEngine;
+
+ Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadStartedSignal;
+ Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadInProgressSignal;
+ Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadFinishedSignal;
+ Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType mPageLoadErrorSignal;
Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType mScrollEdgeReachedSignal;
- std::unique_ptr<Dali::Toolkit::WebContext> mWebContext;
- std::unique_ptr<Dali::Toolkit::WebCookieManager> mWebCookieManager;
- std::unique_ptr<Dali::Toolkit::WebSettings> mWebSettings;
- std::unique_ptr<Dali::Toolkit::WebBackForwardList> mWebBackForwardList;
- Dali::Toolkit::ImageView mFaviconView;
-
- Dali::PropertyNotification mPositionUpdateNotification;
- Dali::PropertyNotification mSizeUpdateNotification;
- Dali::PropertyNotification mScaleUpdateNotification;
- bool mVideoHoleEnabled;
- Dali::Rect<int> mWebViewArea;
+ std::unique_ptr<Dali::Toolkit::WebContext> mWebContext;
+ std::unique_ptr<Dali::Toolkit::WebCookieManager> mWebCookieManager;
+ std::unique_ptr<Dali::Toolkit::WebSettings> mWebSettings;
+ std::unique_ptr<Dali::Toolkit::WebBackForwardList> mWebBackForwardList;
+ Dali::Toolkit::ImageView mFaviconView;
+
+ Dali::PropertyNotification mPositionUpdateNotification;
+ Dali::PropertyNotification mSizeUpdateNotification;
+ Dali::PropertyNotification mScaleUpdateNotification;
+ bool mVideoHoleEnabled;
+ Dali::Rect< int > mWebViewArea;
+ Dali::Toolkit::WebView::WebViewUrlChangedSignalType mUrlChangedSignal;
};
} // namespace Internal