#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-request-interceptor.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>
class MockWebEngineBackForwardList : public Dali::WebEngineBackForwardList
{
public:
- MockWebEngineBackForwardList( )
+ MockWebEngineBackForwardList()
: mockItem(),
pMockItem( &mockItem )
{
void Reply(bool allowed) override {}
};
+class MockWebEngineRequestInterceptor : public WebEngineRequestInterceptor
+{
+public:
+ MockWebEngineRequestInterceptor()
+ {
+ }
+
+ std::string GetUrl() const override
+ {
+ return "http://test.html";
+ }
+
+ bool Ignore() override
+ {
+ return true;
+ }
+
+ bool SetResponseStatus(int statusCode, const std::string &customedStatusText) override
+ {
+ return true;
+ }
+
+ bool AddResponseHeader(const std::string &fieldName, const std::string &fieldValue) override
+ {
+ return true;
+ }
+
+ bool AddResponseBody(const std::string &body, uint32_t length) override
+ {
+ return true;
+ }
+};
+
class MockWebEngineSettings : public WebEngineSettings
{
public:
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<JavaScriptEvaluatedResultCallback> mResultCallbacks;
- bool mEvaluating;
- float mPageZoomFactor;
- float mTextZoomFactor;
- float mScaleFactor;
+ Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& RequestInterceptorSignal()
+ {
+ return mRequestInterceptorSignal;
+ }
+
+ 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;
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;
-
+ Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType mRequestInterceptorSignal;
+
+ bool mEvaluating;
+ float mPageZoomFactor;
+ float mTextZoomFactor;
+ float mScaleFactor;
+
+ Dali::Vector2 mScrollPosition;
+ Dali::Vector2 mScrollSize;
+ Dali::Vector2 mContentSize;
+ WebEngineBackForwardList* mockWebEngineBackForwardList;
+ WebEngineContext* mockWebEngineContext;
+ WebEngineCookieManager* mockWebEngineCookieManager;
+ WebEngineSettings* mockWebEngineSettings;
+
+ std::vector<JavaScriptEvaluatedResultCallback> mResultCallbacks;
Dali::WebEnginePlugin::JavaScriptAlertCallback mJavaScriptAlertCallback;
Dali::WebEnginePlugin::JavaScriptConfirmCallback mJavaScriptConfirmCallback;
Dali::WebEnginePlugin::JavaScriptPromptCallback mJavaScriptPromptCallback;
gInstance->mUrlChangedSignal.Emit( "http://new-test" );
std::shared_ptr<Dali::WebEngineFormRepostDecision> decision(new MockWebEngineFormRepostDecision());
- gInstance->mFormRepostDecisionSignal.Emit(decision);
+ gInstance->mFormRepostDecisionSignal.Emit(std::move(decision));
gInstance->mFrameRenderedSignal.Emit();
+ std::shared_ptr<Dali::WebEngineRequestInterceptor> interceptor(new MockWebEngineRequestInterceptor());
+ gInstance->mRequestInterceptorSignal.Emit(std::move(interceptor));
}
return false;
}
Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& WebEngine::FrameRenderedSignal()
{
- return Internal::Adaptor::GetImplementation( *this ).FrameRenderedSignal();
+ return Internal::Adaptor::GetImplementation(*this).FrameRenderedSignal();
+}
+
+Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& WebEngine::RequestInterceptorSignal()
+{
+ return Internal::Adaptor::GetImplementation(*this).RequestInterceptorSignal();
}
} // namespace Dali;
#include "dali-toolkit-test-utils/toolkit-timer.h"
#include <dali.h>
+#include <dali/devel-api/adaptor-framework/web-engine-request-interceptor.h>
#include <dali/integration-api/events/hover-event-integ.h>
#include <dali/integration-api/events/key-event-integ.h>
#include <dali/integration-api/events/touch-event-integ.h>
static int gFormRepostDecisionCallbackCalled = 0;
static std::shared_ptr<Dali::Toolkit::WebFormRepostDecision> gFormRepostDecisionInstance;
static int gFrameRenderedCallbackCalled = 0;
+static int gRequestInterceptorCallbackCalled = 0;
+static std::shared_ptr<Dali::WebEngineRequestInterceptor> gRequestInterceptorInstance = nullptr;
struct CallbackFunctor
{
gFrameRenderedCallbackCalled++;
}
+static void OnRequestInterceptor(WebView view, std::shared_ptr<Dali::WebEngineRequestInterceptor> interceptor)
+{
+ gRequestInterceptorCallbackCalled++;
+ gRequestInterceptorInstance = std::move(interceptor);
+}
+
} // namespace
void web_view_startup(void)
END_TEST;
}
+int UtcDaliWebViewHttpRequestInterceptor(void)
+{
+ ToolkitTestApplication application;
+
+ WebView view = WebView::New();
+ DALI_TEST_CHECK( view );
+
+ // load url.
+ ConnectionTracker* testTracker = new ConnectionTracker();
+ view.RequestInterceptorSignal().Connect( &OnRequestInterceptor );
+ bool signal1 = false;
+ view.ConnectSignal( testTracker, "requestInterceptor", CallbackFunctor(&signal1) );
+ DALI_TEST_EQUALS( gRequestInterceptorCallbackCalled, 0, TEST_LOCATION );
+ DALI_TEST_CHECK(gRequestInterceptorInstance == 0);
+
+ view.LoadUrl( TEST_URL1 );
+ Test::EmitGlobalTimerSignal();
+ DALI_TEST_EQUALS( gRequestInterceptorCallbackCalled, 1, TEST_LOCATION );
+ DALI_TEST_CHECK( signal1 );
+
+ // check request interceptor.
+ DALI_TEST_CHECK(gRequestInterceptorInstance != 0);
+ DALI_TEST_CHECK(gRequestInterceptorInstance->Ignore());
+ DALI_TEST_CHECK(gRequestInterceptorInstance->SetResponseStatus(400, "error"));
+ DALI_TEST_CHECK(gRequestInterceptorInstance->AddResponseHeader("key", "value"));
+ DALI_TEST_CHECK(gRequestInterceptorInstance->AddResponseBody("test", 4));
+ std::string testUrl("http://test.html");
+ DALI_TEST_EQUALS(gRequestInterceptorInstance->GetUrl(), testUrl, TEST_LOCATION);
+
+ gRequestInterceptorInstance = nullptr;
+
+ END_TEST;
+}
+
int UtcDaliWebViewEvaluteJavaScript(void)
{
ToolkitTestApplication application;
return Dali::Toolkit::GetImpl(*this).FrameRenderedSignal();
}
+WebView::WebViewRequestInterceptorSignalType& WebView::RequestInterceptorSignal()
+{
+ return Dali::Toolkit::GetImpl(*this).RequestInterceptorSignal();
+}
+
WebView::WebView(Internal::WebView& implementation)
: Control(implementation)
{
*/
using WebViewFrameRenderedSignalType = Signal<void(WebView)>;
+ /**
+ * @brief WebView signal type related with http request interceptor.
+ */
+ using WebViewRequestInterceptorSignalType = Signal<void(WebView, std::shared_ptr<Dali::WebEngineRequestInterceptor>)>;
+
public:
/**
* @brief Creates an initialized WebView.
*/
WebViewFrameRenderedSignalType& FrameRenderedSignal();
+ /**
+ * @brief Connects to this signal to be notified when http request need be intercepted.
+ *
+ * @return A signal object to connect with.
+ */
+ WebViewRequestInterceptorSignalType& RequestInterceptorSignal();
+
public: // Not intended for application developers
/// @cond internal
/**
#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-request-interceptor.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, "urlChanged", URL_CHANGED_SIGNAL )
DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "formRepostDecision", FORM_REPOST_DECISION_SIGNAL )
DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "frameRendered", FRAME_RENDERED_SIGNAL )
+DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "requestInterceptor", REQUEST_INTERCEPTOR_SIGNAL )
DALI_TYPE_REGISTRATION_END()
// clang-format on
mWebEngine.UrlChangedSignal().Connect(this, &WebView::OnUrlChanged);
mWebEngine.FormRepostDecisionSignal().Connect(this, &WebView::OnFormRepostDecision);
mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnFrameRendered);
+ mWebEngine.RequestInterceptorSignal().Connect(this, &WebView::OnInterceptRequest);
mWebContext = std::unique_ptr<Dali::Toolkit::WebContext>(new WebContext(mWebEngine.GetContext()));
mWebCookieManager = std::unique_ptr<Dali::Toolkit::WebCookieManager>(new WebCookieManager(mWebEngine.GetCookieManager()));
return mFrameRenderedSignal;
}
+Dali::Toolkit::WebView::WebViewRequestInterceptorSignalType& WebView::RequestInterceptorSignal()
+{
+ return mRequestInterceptorSignal;
+}
+
void WebView::OnPageLoadStarted(const std::string& url)
{
if(!mPageLoadStartedSignal.Empty())
}
}
+void WebView::OnInterceptRequest(std::shared_ptr<Dali::WebEngineRequestInterceptor> interceptor)
+{
+ if(!mRequestInterceptorSignal.Empty())
+ {
+ Dali::Toolkit::WebView handle(GetOwner());
+ mRequestInterceptorSignal.Emit(handle, std::move(interceptor));
+ }
+}
+
bool WebView::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
{
Dali::BaseHandle handle(object);
webView.FrameRenderedSignal().Connect(tracker, functor);
connected = true;
}
+ else if(0 == strcmp(signalName.c_str(), REQUEST_INTERCEPTOR_SIGNAL))
+ {
+ webView.RequestInterceptorSignal().Connect(tracker, functor);
+ connected = true;
+ }
return connected;
}
*/
Dali::Toolkit::WebView::WebViewFrameRenderedSignalType& FrameRenderedSignal();
+ /**
+ * @copydoc Dali::Toolkit::WebView::RequestInterceptorSignal()
+ */
+ Dali::Toolkit::WebView::WebViewRequestInterceptorSignalType& RequestInterceptorSignal();
+
public: // Properties
/**
* @brief Called when a property of an object of this type is set.
*/
void OnScreenshotCaptured(Dali::PixelData pixel);
+ /**
+ * @brief Callback function to be called when http request need be intercepted.
+ * @param [in] request The http request interceptor.
+ */
+ void OnInterceptRequest(std::shared_ptr<Dali::WebEngineRequestInterceptor> interceptor);
+
private:
std::string mUrl;
Dali::Toolkit::Visual::Base mVisual;
Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType mScrollEdgeReachedSignal;
Dali::Toolkit::WebView::WebViewFormRepostDecisionSignalType mFormRepostDecisionSignal;
Dali::Toolkit::WebView::WebViewFrameRenderedSignalType mFrameRenderedSignal;
+ Dali::Toolkit::WebView::WebViewRequestInterceptorSignalType mRequestInterceptorSignal;
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::Toolkit::ImageView mFaviconView;
Dali::PropertyNotification mPositionUpdateNotification;
Dali::PropertyNotification mSizeUpdateNotification;