This patch is to add policy decision feature in web view.
Change-Id: Iddf70088cd663a3362a995b317edda04cdf05817
#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-frame.h>
+#include <dali/devel-api/adaptor-framework/web-engine-policy-decision.h>
#include <dali/devel-api/adaptor-framework/web-engine-request-interceptor.h>
#include <dali/devel-api/adaptor-framework/web-engine-load-error.h>
#include <dali/devel-api/adaptor-framework/web-engine-settings.h>
void Reply(bool allowed) override {}
};
+class MockWebEngineFrame : public Dali::WebEngineFrame
+{
+public:
+ MockWebEngineFrame()
+ {
+ }
+
+ bool IsMainFrame() const override
+ {
+ return true;
+ }
+};
+
+class MockWebEnginePolicyDecision : public Dali::WebEnginePolicyDecision
+{
+public:
+ MockWebEnginePolicyDecision()
+ {
+ }
+
+ std::string GetUrl() const override
+ {
+ return "http://test.html";
+ }
+
+ std::string GetCookie() const override
+ {
+ return "test:abc";
+ }
+
+ Dali::WebEnginePolicyDecision::DecisionType GetDecisionType() const
+ {
+ return Dali::WebEnginePolicyDecision::DecisionType::USE;
+ }
+
+ std::string GetResponseMime() const
+ {
+ return "txt/xml";
+ }
+
+ int32_t GetResponseStatusCode() const
+ {
+ return 500;
+ }
+
+ Dali::WebEnginePolicyDecision::NavigationType GetNavigationType() const
+ {
+ return Dali::WebEnginePolicyDecision::NavigationType::LINK_CLICKED;
+ }
+
+ Dali::WebEngineFrame& GetFrame() const
+ {
+ return *(Dali::WebEngineFrame*)(&mockWebFrame);
+ }
+
+ std::string GetScheme() const
+ {
+ return "test";
+ }
+
+ bool Use()
+ {
+ return true;
+ }
+
+ bool Ignore()
+ {
+ return true;
+ }
+
+ bool Suspend()
+ {
+ return true;
+ }
+
+private:
+ MockWebEngineFrame mockWebFrame;
+};
+
class MockWebEngineRequestInterceptor : public WebEngineRequestInterceptor
{
public:
return mConsoleMessageSignal;
}
+ Dali::WebEnginePlugin::WebEnginePolicyDecisionSignalType& PolicyDecisionSignal()
+ {
+ return mPolicyDecisionSignal;
+ }
+
std::string mUrl;
std::vector<std::string> mHistory;
size_t mCurrentPlusOnePos;
Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType mFrameRenderedSignal;
Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType mRequestInterceptorSignal;
Dali::WebEnginePlugin::WebEngineConsoleMessageSignalType mConsoleMessageSignal;
+ Dali::WebEnginePlugin::WebEnginePolicyDecisionSignalType mPolicyDecisionSignal;
bool mEvaluating;
float mPageZoomFactor;
gInstance->mPageLoadFinishedSignal.Emit( gInstance->mUrl );
gInstance->mUrlChangedSignal.Emit( "http://new-test" );
- std::shared_ptr<Dali::WebEngineFormRepostDecision> decision(new MockWebEngineFormRepostDecision());
- gInstance->mFormRepostDecisionSignal.Emit(std::move(decision));
+ std::shared_ptr<Dali::WebEngineFormRepostDecision> repostDecision(new MockWebEngineFormRepostDecision());
+ gInstance->mFormRepostDecisionSignal.Emit(std::move(repostDecision));
gInstance->mFrameRenderedSignal.Emit();
std::shared_ptr<Dali::WebEngineRequestInterceptor> interceptor(new MockWebEngineRequestInterceptor());
gInstance->mRequestInterceptorSignal.Emit(std::move(interceptor));
gInstance->mPageLoadErrorSignal.Emit(std::move(error));
std::shared_ptr<Dali::WebEngineConsoleMessage> message(new MockWebEngineConsoleMessage());
gInstance->mConsoleMessageSignal.Emit(std::move(message));
+ std::shared_ptr<Dali::WebEnginePolicyDecision> policyDecision(new MockWebEnginePolicyDecision());
+ gInstance->mPolicyDecisionSignal.Emit(std::move(policyDecision));
}
return false;
}
Dali::WebEnginePlugin::WebEngineFormRepostDecisionSignalType& WebEngine::FormRepostDecisionSignal()
{
- return Internal::Adaptor::GetImplementation( *this ).FormRepostDecisionSignal();
+ return Internal::Adaptor::GetImplementation(*this).FormRepostDecisionSignal();
}
Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& WebEngine::FrameRenderedSignal()
return Internal::Adaptor::GetImplementation(*this).ConsoleMessageSignal();
}
+Dali::WebEnginePlugin::WebEnginePolicyDecisionSignalType& WebEngine::PolicyDecisionSignal()
+{
+ return Internal::Adaptor::GetImplementation(*this).PolicyDecisionSignal();
+}
+
} // namespace Dali;
#include "dali-toolkit-test-utils/toolkit-timer.h"
#include <dali.h>
+#include <dali/devel-api/adaptor-framework/web-engine-frame.h>
+#include <dali/devel-api/adaptor-framework/web-engine-policy-decision.h>
#include <dali/devel-api/adaptor-framework/web-engine-request-interceptor.h>
#include <dali/devel-api/adaptor-framework/web-engine-console-message.h>
#include <dali/devel-api/adaptor-framework/web-engine-load-error.h>
static bool gHovered = false;
static bool gWheelEventHandled = false;
static int gFormRepostDecisionCallbackCalled = 0;
-static std::shared_ptr<Dali::Toolkit::WebFormRepostDecision> gFormRepostDecisionInstance;
+static std::shared_ptr<Dali::Toolkit::WebFormRepostDecision> gFormRepostDecisionInstance = nullptr;
static int gFrameRenderedCallbackCalled = 0;
static int gRequestInterceptorCallbackCalled = 0;
static std::shared_ptr<Dali::WebEngineRequestInterceptor> gRequestInterceptorInstance = nullptr;
static int gConsoleMessageCallbackCalled = 0;
static std::shared_ptr<Dali::WebEngineConsoleMessage> gConsoleMessageInstance = nullptr;
+static int gPolicyDecisionCallbackCalled = 0;
+static std::shared_ptr<Dali::WebEnginePolicyDecision> gPolicyDecisionInstance = nullptr;
struct CallbackFunctor
{
gScrollEdgeReachedCallbackCalled++;
}
+static void OnPolicyDecisionRequest(WebView view, std::shared_ptr<Dali::WebEnginePolicyDecision> decision)
+{
+ gPolicyDecisionCallbackCalled++;
+ gPolicyDecisionInstance = std::move(decision);
+}
+
static void OnUrlChanged( WebView view, const std::string& url )
{
gUrlChangedCallbackCalled++;
static void OnFormRepostDecision(WebView, std::shared_ptr<Dali::Toolkit::WebFormRepostDecision> decision)
{
gFormRepostDecisionCallbackCalled++;
- gFormRepostDecisionInstance = decision;
+ gFormRepostDecisionInstance = std::move(decision);
}
static void OnFrameRendered(WebView)
assign = copy;
DALI_TEST_CHECK( assign == view );
-
// DownCast Test
tet_infoline( "UtcDaliWebViewBasic DownCast Test" );
BaseHandle handle(view);
DALI_TEST_CHECK( view2 );
DALI_TEST_CHECK( view == view2 );
-
// TypeRegistry Test
tet_infoline( "UtcDaliWebViewBasic TypeRegistry Test" );
TypeRegistry typeRegistry = TypeRegistry::Get();
END_TEST;
}
+int UtcDaliWebViewPolicyDecisionRequest(void)
+{
+ ToolkitTestApplication application;
+
+ WebView view = WebView::New();
+ DALI_TEST_CHECK( view );
+
+ // load url.
+ ConnectionTracker* testTracker = new ConnectionTracker();
+ view.PolicyDecisionSignal().Connect( &OnPolicyDecisionRequest );
+ bool signal1 = false;
+ view.ConnectSignal( testTracker, "policyDecision", CallbackFunctor(&signal1) );
+ DALI_TEST_EQUALS( gPolicyDecisionCallbackCalled, 0, TEST_LOCATION );
+ DALI_TEST_CHECK(gPolicyDecisionInstance == 0);
+
+ view.LoadUrl( TEST_URL1 );
+ Test::EmitGlobalTimerSignal();
+ DALI_TEST_EQUALS( gPolicyDecisionCallbackCalled, 1, TEST_LOCATION );
+ DALI_TEST_CHECK( signal1 );
+
+ // check policy decision & its frame.
+ DALI_TEST_CHECK(gPolicyDecisionInstance != 0);
+ std::string testUrl("http://test.html");
+ DALI_TEST_EQUALS(gPolicyDecisionInstance->GetUrl(), testUrl, TEST_LOCATION);
+ std::string testCookie("test:abc");
+ DALI_TEST_EQUALS(gPolicyDecisionInstance->GetCookie(), testCookie, TEST_LOCATION);
+ Dali::WebEnginePolicyDecision::DecisionType testDecisionType = Dali::WebEnginePolicyDecision::DecisionType::USE;
+ DALI_TEST_EQUALS(gPolicyDecisionInstance->GetDecisionType(), testDecisionType, TEST_LOCATION);
+ std::string testResponseMime("txt/xml");
+ DALI_TEST_EQUALS(gPolicyDecisionInstance->GetResponseMime(), testResponseMime, TEST_LOCATION);
+ int32_t ResponseStatusCode = 500;
+ DALI_TEST_EQUALS(gPolicyDecisionInstance->GetResponseStatusCode(), ResponseStatusCode, TEST_LOCATION);
+ Dali::WebEnginePolicyDecision::NavigationType testNavigationType = Dali::WebEnginePolicyDecision::NavigationType::LINK_CLICKED;
+ DALI_TEST_EQUALS(gPolicyDecisionInstance->GetNavigationType(), testNavigationType, TEST_LOCATION);
+ std::string testScheme("test");
+ DALI_TEST_EQUALS(gPolicyDecisionInstance->GetScheme(), testScheme, TEST_LOCATION);
+ DALI_TEST_CHECK(gPolicyDecisionInstance->Use());
+ DALI_TEST_CHECK(gPolicyDecisionInstance->Ignore());
+ DALI_TEST_CHECK(gPolicyDecisionInstance->Suspend());
+
+ Dali::WebEngineFrame* webFrame = &(gPolicyDecisionInstance->GetFrame());
+ DALI_TEST_CHECK(webFrame);
+ DALI_TEST_CHECK(webFrame->IsMainFrame());
+
+ gPolicyDecisionInstance = nullptr;
+
+ END_TEST;
+}
+
int UtcDaliWebViewEvaluteJavaScript(void)
{
ToolkitTestApplication application;
return Dali::Toolkit::GetImpl(*this).ConsoleMessageSignal();
}
+WebView::WebViewPolicyDecisionSignalType& WebView::PolicyDecisionSignal()
+{
+ return Dali::Toolkit::GetImpl(*this).PolicyDecisionSignal();
+}
+
WebView::WebView(Internal::WebView& implementation)
: Control(implementation)
{
*/
using WebViewConsoleMessageSignalType = Signal<void(WebView, std::shared_ptr<Dali::WebEngineConsoleMessage>)>;
+ /**
+ * @brief WebView signal type related with policy decision.
+ */
+ using WebViewPolicyDecisionSignalType = Signal<void(WebView, std::shared_ptr<Dali::WebEnginePolicyDecision>)>;
+
public:
/**
* @brief Creates an initialized WebView.
*/
WebViewConsoleMessageSignalType& ConsoleMessageSignal();
+ /**
+ * @brief Connects to this signal to be notified when new policy would be decided.
+ *
+ * @return A signal object to connect with.
+ */
+ WebViewPolicyDecisionSignalType& PolicyDecisionSignal();
+
public: // Not intended for application developers
/// @cond internal
/**
#include <dali/devel-api/adaptor-framework/web-engine-form-repost-decision.h>
#include <dali/devel-api/adaptor-framework/web-engine-request-interceptor.h>
#include <dali/devel-api/adaptor-framework/web-engine-load-error.h>
+#include <dali/devel-api/adaptor-framework/web-engine-policy-decision.h>
#include <dali/devel-api/adaptor-framework/web-engine-settings.h>
#include <dali/devel-api/common/stage.h>
#include <dali/devel-api/scripting/enum-helper.h>
DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "frameRendered", FRAME_RENDERED_SIGNAL )
DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "requestInterceptor", REQUEST_INTERCEPTOR_SIGNAL )
DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "consoleMessage", CONSOLE_MESSAGE_SIGNAL )
+DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "policyDecision", POLICY_DECISION )
DALI_TYPE_REGISTRATION_END()
// clang-format on
mPageLoadFinishedSignal(),
mPageLoadErrorSignal(),
mUrlChangedSignal(),
- mVideoHoleEnabled(true),
mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
+ mVideoHoleEnabled(true),
mMouseEventsEnabled(true),
mKeyEventsEnabled(true)
{
mPageLoadFinishedSignal(),
mPageLoadErrorSignal(),
mUrlChangedSignal(),
- mVideoHoleEnabled(true),
mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
+ mVideoHoleEnabled(true),
mMouseEventsEnabled(true),
mKeyEventsEnabled(true)
{
mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnFrameRendered);
mWebEngine.RequestInterceptorSignal().Connect(this, &WebView::OnInterceptRequest);
mWebEngine.ConsoleMessageSignal().Connect(this, &WebView::OnConsoleMessage);
+ mWebEngine.PolicyDecisionSignal().Connect(this, &WebView::OnPolicyDecisionRequest);
mWebContext = std::unique_ptr<Dali::Toolkit::WebContext>(new WebContext(mWebEngine.GetContext()));
mWebCookieManager = std::unique_ptr<Dali::Toolkit::WebCookieManager>(new WebCookieManager(mWebEngine.GetCookieManager()));
return mConsoleMessageSignal;
}
+Dali::Toolkit::WebView::WebViewPolicyDecisionSignalType& WebView::PolicyDecisionSignal()
+{
+ return mPolicyDecisionSignal;
+}
+
void WebView::OnPageLoadStarted(const std::string& url)
{
if(!mPageLoadStartedSignal.Empty())
}
}
+void WebView::OnPolicyDecisionRequest(std::shared_ptr<Dali::WebEnginePolicyDecision> decision)
+{
+ if(!mPolicyDecisionSignal.Empty())
+ {
+ Dali::Toolkit::WebView handle(GetOwner());
+ mPolicyDecisionSignal.Emit(handle, std::move(decision));
+ }
+}
+
bool WebView::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
{
Dali::BaseHandle handle(object);
webView.ConsoleMessageSignal().Connect(tracker, functor);
connected = true;
}
+ else if(0 == strcmp(signalName.c_str(), POLICY_DECISION))
+ {
+ webView.PolicyDecisionSignal().Connect(tracker, functor);
+ connected = true;
+ }
return connected;
}
*/
Dali::Toolkit::WebView::WebViewConsoleMessageSignalType& ConsoleMessageSignal();
+ /**
+ * @copydoc Dali::Toolkit::WebView::PolicyDecisionSignal()
+ */
+ Dali::Toolkit::WebView::WebViewPolicyDecisionSignalType& PolicyDecisionSignal();
+
public: // Properties
/**
* @brief Called when a property of an object of this type is set.
/**
* @brief Callback function to be called when scroll edge is reached.
- * @param[in] e The scroll edge reached.
+ * @param[in] edge The scroll edge reached.
*/
void OnScrollEdgeReached(Dali::WebEnginePlugin::ScrollEdge edge);
*/
void OnConsoleMessage(std::shared_ptr<Dali::WebEngineConsoleMessage> message);
+ /**
+ * @brief Callback function to be called when policy need be decided.
+ * @param[in] decision The policy decided.
+ */
+ void OnPolicyDecisionRequest(std::shared_ptr<Dali::WebEnginePolicyDecision> decision);
+
private:
std::string mUrl;
Dali::Toolkit::Visual::Base mVisual;
Dali::Toolkit::WebView::WebViewFrameRenderedSignalType mFrameRenderedSignal;
Dali::Toolkit::WebView::WebViewRequestInterceptorSignalType mRequestInterceptorSignal;
Dali::Toolkit::WebView::WebViewConsoleMessageSignalType mConsoleMessageSignal;
+ Dali::Toolkit::WebView::WebViewPolicyDecisionSignalType mPolicyDecisionSignal;
std::unique_ptr<Dali::Toolkit::WebContext> mWebContext;
std::unique_ptr<Dali::Toolkit::WebCookieManager> mWebCookieManager;
Dali::PropertyNotification mPositionUpdateNotification;
Dali::PropertyNotification mSizeUpdateNotification;
Dali::PropertyNotification mScaleUpdateNotification;
- bool mVideoHoleEnabled;
Dali::Rect<int> mWebViewArea;
+ bool mVideoHoleEnabled;
bool mMouseEventsEnabled;
bool mKeyEventsEnabled;