/*
- * 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.
#include <dali/devel-api/adaptor-framework/web-engine-back-forward-list-item.h>
#include <dali/devel-api/adaptor-framework/web-engine-context.h>
#include <dali/devel-api/adaptor-framework/web-engine-cookie-manager.h>
+#include <dali/devel-api/adaptor-framework/web-engine-form-repost-decision.h>
#include <dali/devel-api/adaptor-framework/web-engine-settings.h>
+#include <dali/public-api/adaptor-framework/native-image-source.h>
+#include <dali/public-api/images/pixel-data.h>
#include <dali/public-api/object/any.h>
#include <dali/public-api/object/base-object.h>
-#include <dali/public-api/adaptor-framework/native-image-source.h>
+#include <memory>
#include <toolkit-application.h>
namespace Dali
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
{
WebEngineBackForwardListItem* pMockItem;
};
+class MockWebEngineFormRepostDecision : public WebEngineFormRepostDecision
+{
+public:
+ MockWebEngineFormRepostDecision()
+ {
+ }
+
+ void Reply(bool allowed) override {}
+};
+
class MockWebEngineSettings : public WebEngineSettings
{
public:
MockWebEngineSettings()
: mockDefaultFontSize( 16 ),
mockJavaScriptEnabled( true ),
+ mockAutoFittingEnabled ( true ),
+ mockPluginsEnabled ( true ),
+ mockPrivateBrowsingEnabled( true ),
+ mockLinkMagnifierEnabled( true ),
+ mockKeypadWithoutUserActionUsed( true ),
+ mockAutofillPasswordFormEnabled( true ),
+ mockFormCandidateDataEnabled( true ),
+ mockTextSelectionEnabled( true ),
+ mockTextAutosizingEnable( true ),
+ mockArrowScrollEnable( true ),
+ mockClipboardEnabled( true ),
+ mockImePanelEnabled( true ),
mockImageLoadedAutomatically( true ),
mockDefaultTextEncodingName()
{
mockJavaScriptEnabled = enabled;
}
+ bool IsAutoFittingEnabled() const override
+ {
+ return mockAutoFittingEnabled;
+ }
+
+ void EnableAutoFitting( bool enabled ) override
+ {
+ mockAutoFittingEnabled = enabled;
+ }
+
+ bool ArePluginsEnabled() const override
+ {
+ return mockPluginsEnabled;
+ }
+
+ void EnablePlugins( bool enabled ) override
+ {
+ mockPluginsEnabled = enabled;
+ }
+
+ bool IsPrivateBrowsingEnabled() const override
+ {
+ return mockPrivateBrowsingEnabled;
+ }
+
+ void EnablePrivateBrowsing( bool enabled ) override
+ {
+ mockPrivateBrowsingEnabled = enabled;
+ }
+
+ bool IsLinkMagnifierEnabled() const override
+ {
+ return mockLinkMagnifierEnabled;
+ }
+
+ void EnableLinkMagnifier( bool enabled ) override
+ {
+ mockLinkMagnifierEnabled = enabled;
+ }
+
+ bool IsKeypadWithoutUserActionUsed() const override
+ {
+ return mockKeypadWithoutUserActionUsed;
+ }
+
+ void UseKeypadWithoutUserAction( bool used ) override
+ {
+ mockKeypadWithoutUserActionUsed = used;
+ }
+
+ bool IsAutofillPasswordFormEnabled() const override
+ {
+ return mockAutofillPasswordFormEnabled;
+ }
+
+ void EnableAutofillPasswordForm( bool enabled ) override
+ {
+ mockAutofillPasswordFormEnabled = enabled;
+ }
+
+ bool IsFormCandidateDataEnabled() const override
+ {
+ return mockFormCandidateDataEnabled;
+ }
+
+ void EnableFormCandidateData( bool enabled ) override
+ {
+ mockFormCandidateDataEnabled = enabled;
+ }
+
+ bool IsTextSelectionEnabled() const override
+ {
+ return mockTextSelectionEnabled;
+ }
+
+ void EnableTextSelection( bool enabled ) override
+ {
+ mockTextSelectionEnabled = enabled;
+ }
+
+ bool IsTextAutosizingEnabled() const override
+ {
+ return mockTextAutosizingEnable;
+ }
+
+ void EnableTextAutosizing( bool enabled ) override
+ {
+ mockTextAutosizingEnable = enabled;
+ }
+
+ bool IsArrowScrollEnabled() const override
+ {
+ return mockArrowScrollEnable;
+ }
+
+ void EnableArrowScroll( bool enabled ) override
+ {
+ mockArrowScrollEnable = enabled;
+ }
+
+ bool IsClipboardEnabled() const override
+ {
+ return mockClipboardEnabled;
+ }
+
+ void EnableClipboard( bool enabled ) override
+ {
+ mockClipboardEnabled = enabled;
+ }
+
+ bool IsImePanelEnabled() const override
+ {
+ return mockImePanelEnabled;
+ }
+
+ void EnableImePanel( bool enabled ) override
+ {
+ mockImePanelEnabled = enabled;
+ }
+
bool AreImagesLoadedAutomatically() const override
{
return mockImageLoadedAutomatically;
{
}
+ void EnableCacheBuilder( bool enabled ) override
+ {
+ }
+
+ void UseScrollbarThumbFocusNotifications( bool used ) override
+ {
+ }
+
+ void EnableDoNotTrack( bool enabled ) override
+ {
+ }
+
void AllowFileAccessFromExternalUrl( bool allowed ) override
{
}
private:
int mockDefaultFontSize;
bool mockJavaScriptEnabled;
+ bool mockAutoFittingEnabled;
+ bool mockPluginsEnabled;
+ bool mockPrivateBrowsingEnabled;
+ bool mockLinkMagnifierEnabled;
+ bool mockKeypadWithoutUserActionUsed;
+ bool mockAutofillPasswordFormEnabled;
+ bool mockFormCandidateDataEnabled;
+ bool mockTextSelectionEnabled;
+ bool mockTextAutosizingEnable;
+ bool mockArrowScrollEnable;
+ bool mockClipboardEnabled;
+ bool mockImePanelEnabled;
bool mockImageLoadedAutomatically;
std::string mockDefaultTextEncodingName;
};
{
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;
return mUrl;
}
+ std::string GetTitle() const
+ {
+ return std::string("title");
+ }
+
+ Dali::PixelData GetFavicon() const
+ {
+ uint8_t* faviconData = new uint8_t[ 16 ];
+
+ faviconData[ 0 ] = 0xff;
+ faviconData[ 1 ] = 0x00;
+ faviconData[ 2 ] = 0x00;
+ faviconData[ 3 ] = 0xff;
+ faviconData[ 4 ] = 0xff;
+ faviconData[ 5 ] = 0x00;
+ faviconData[ 6 ] = 0x00;
+ faviconData[ 7 ] = 0xff;
+ faviconData[ 8 ] = 0xff;
+ faviconData[ 9 ] = 0x00;
+ faviconData[ 10 ] = 0x00;
+ faviconData[ 11 ] = 0xff;
+ faviconData[ 12 ] = 0xff;
+ faviconData[ 13 ] = 0x00;
+ faviconData[ 14 ] = 0x00;
+ faviconData[ 15 ] = 0xff;
+
+ return Dali::PixelData::New( faviconData, 16, 2, 2,
+ Dali::Pixel::Format::RGBA8888,
+ Dali::PixelData::ReleaseFunction::DELETE_ARRAY );
+ }
+
bool CanGoForward() const
{
return mHistory.size() > mCurrentPlusOnePos;
}
}
+ 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 );
}
}
mScrollPosition.y = y;
}
- void GetScrollPosition( int& x, int& y ) const
+ Dali::Vector2 GetScrollPosition() const
{
- x = mScrollPosition.x;
- y = mScrollPosition.y;
+ return mScrollPosition;
}
- void GetScrollSize( int& w, int& h ) const
+ Dali::Vector2 GetScrollSize() const
{
- w = mScrollSize.width;
- h = mScrollSize.height;
+ return mScrollSize;
}
- void GetContentSize( int& w, int& h ) const
+ Dali::Vector2 GetContentSize() const
{
- w = mContentSize.width;
- h = mContentSize.height;
+ return mContentSize;
}
Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal()
return mPageLoadStartedSignal;
}
+ Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadInProgressSignal()
+ {
+ return mPageLoadInProgressSignal;
+ }
+
Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal()
{
return mPageLoadFinishedSignal;
return mScrollEdgeReachedSignal;
}
+ Dali::WebEnginePlugin::WebEngineUrlChangedSignalType& UrlChangedSignal()
+ {
+ return mUrlChangedSignal;
+ }
+
+ Dali::WebEnginePlugin::WebEngineFormRepostDecisionSignalType& FormRepostDecisionSignal()
+ {
+ return mFormRepostDecisionSignal;
+ }
+
+ Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& FrameRenderedSignal()
+ {
+ return mFrameRenderedSignal;
+ }
+
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;
- Dali::Vector2 mScrollPosition;
- Dali::Vector2 mScrollSize;
- Dali::Vector2 mContentSize;
- WebEngineBackForwardList* mockWebEngineBackForwardList;
- WebEngineContext* mockWebEngineContext;
- WebEngineCookieManager* mockWebEngineCookieManager;
- WebEngineSettings* mockWebEngineSettings;
+ Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType mScrollEdgeReachedSignal;
+ Dali::Vector2 mScrollPosition;
+ Dali::Vector2 mScrollSize;
+ Dali::Vector2 mContentSize;
+ WebEngineBackForwardList* mockWebEngineBackForwardList;
+ WebEngineContext* mockWebEngineContext;
+ WebEngineCookieManager* mockWebEngineCookieManager;
+ WebEngineSettings* mockWebEngineSettings;
+ Dali::WebEnginePlugin::WebEngineUrlChangedSignalType mUrlChangedSignal;
+ Dali::WebEnginePlugin::WebEngineFormRepostDecisionSignalType mFormRepostDecisionSignal;
+ Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType mFrameRenderedSignal;
+
+ JavaScriptAlertCallback mJavaScriptAlertCallback;
+ JavaScriptConfirmCallback mJavaScriptConfirmCallback;
+ JavaScriptPromptCallback mJavaScriptPromptCallback;
};
-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
{
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" );
+
+ std::shared_ptr<Dali::WebEngineFormRepostDecision> decision(new MockWebEngineFormRepostDecision());
+ gInstance->mFormRepostDecisionSignal.Emit(decision);
+ gInstance->mFrameRenderedSignal.Emit();
}
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::Create( int width, int height, int argc, char** argv )
+{
+}
+
void WebEngine::Destroy()
{
}
return Internal::Adaptor::GetImplementation( *this ).LoadUrl( url );
}
+std::string WebEngine::GetTitle() const
+{
+ return Internal::Adaptor::GetImplementation( *this ).GetTitle();
+}
+
+Dali::PixelData WebEngine::GetFavicon() const
+{
+ return Internal::Adaptor::GetImplementation( *this ).GetFavicon();
+}
+
const std::string& WebEngine::GetUrl()
{
return Internal::Adaptor::GetImplementation( *this ).GetUrl();
{
}
+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()
+{
+}
+
void WebEngine::ClearHistory()
{
Internal::Adaptor::GetImplementation( *this ).ClearHistory();
Internal::Adaptor::GetImplementation( *this ).SetScrollPosition( x, y );
}
-void WebEngine::GetScrollPosition( int& x, int& y ) const
+Dali::Vector2 WebEngine::GetScrollPosition() const
{
- Internal::Adaptor::GetImplementation( *this ).GetScrollPosition( x, y );
+ return Internal::Adaptor::GetImplementation( *this ).GetScrollPosition();
}
-void WebEngine::GetScrollSize( int& w, int& h ) const
+Dali::Vector2 WebEngine::GetScrollSize() const
{
- Internal::Adaptor::GetImplementation( *this ).GetScrollSize( w, h );
+ return Internal::Adaptor::GetImplementation( *this ).GetScrollSize();
}
-void WebEngine::GetContentSize( int& w, int& h ) const
+Dali::Vector2 WebEngine::GetContentSize() const
{
- Internal::Adaptor::GetImplementation( *this ).GetContentSize( w, h );
+ return Internal::Adaptor::GetImplementation( *this ).GetContentSize();
}
void WebEngine::SetSize( int width, int height )
{
}
+void WebEngine::SetDocumentBackgroundColor(Dali::Vector4 color)
+{
+}
+
+void WebEngine::ClearTilesWhenHidden(bool cleared)
+{
+}
+
+void WebEngine::SetTileCoverAreaMultiplier(float multiplier)
+{
+}
+
+void WebEngine::EnableCursorByClient(bool enabled)
+{
+}
+
+std::string WebEngine::GetSelectedText() const
+{
+ return "test";
+}
+
bool WebEngine::SendTouchEvent( const TouchEvent& touch )
{
return true;
return true;
}
+bool WebEngine::SendHoverEvent( const HoverEvent& event )
+{
+ return true;
+}
+
+bool WebEngine::SendWheelEvent( const WheelEvent& event )
+{
+ return true;
+}
+
void WebEngine::SetFocus( bool focused )
{
}
+void WebEngine::UpdateDisplayArea( Dali::Rect< int > displayArea )
+{
+}
+
+void WebEngine::EnableVideoHole( bool enabled )
+{
+}
+
+void WebEngine::EnableMouseEvents( bool enabled )
+{
+}
+
+void WebEngine::EnableKeyEvents( bool enabled )
+{
+}
+
Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadStartedSignal()
{
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();
+}
+
+Dali::WebEnginePlugin::WebEngineFormRepostDecisionSignalType& WebEngine::FormRepostDecisionSignal()
+{
+ return Internal::Adaptor::GetImplementation( *this ).FormRepostDecisionSignal();
+}
+
+Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& WebEngine::FrameRenderedSignal()
+{
+ return Internal::Adaptor::GetImplementation( *this ).FrameRenderedSignal();
+}
+
} // namespace Dali;