From: huayong.xu Date: Thu, 25 Feb 2021 11:59:54 +0000 (+0800) Subject: Add APIs for ssl certificate and http authentication. X-Git-Tag: dali_2.0.21~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f15407e1710844219f3e418e83e689b5ff7341c2;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git Add APIs for ssl certificate and http authentication. This patch is to add some APIs for ssl certificate and http authentication in web view. Change-Id: Ic1e3790d2ec5e9754f613cdcc969132440c48241 --- 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 00c08c0..14f2c1f 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 @@ -20,14 +20,16 @@ #include #include #include +#include #include #include #include #include #include +#include +#include #include #include -#include #include #include #include @@ -223,7 +225,59 @@ public: private: MockWebEngineBackForwardListItem mockItem; - WebEngineBackForwardListItem* pMockItem; + WebEngineBackForwardListItem* pMockItem; +}; + +class MockWebEngineCertificate : public Dali::WebEngineCertificate +{ +public: + MockWebEngineCertificate() + { + } + + void Allow(bool allowed) override + { + } + + bool IsFromMainFrame() const override + { + return true; + } + + std::string GetPem() const override + { + return "abc"; + } + + bool IsContextSecure() const override + { + return true; + } +}; + +class MockWebEngineHttpAuthHandler : public Dali::WebEngineHttpAuthHandler +{ +public: + MockWebEngineHttpAuthHandler() + { + } + + std::string GetRealm() const override + { + return "test"; + } + + void Suspend() override + { + } + + void UseCredential(const std::string& user, const std::string& password) override + { + } + + void CancelCredential() override + { + } }; class MockWebEngineFormRepostDecision : public WebEngineFormRepostDecision @@ -988,6 +1042,21 @@ public: return mPolicyDecisionSignal; } + Dali::WebEnginePlugin::WebEngineCertificateSignalType& CertificateConfirmSignal() + { + return mCertificateConfirmSignal; + } + + Dali::WebEnginePlugin::WebEngineCertificateSignalType& SslCertificateChangedSignal() + { + return mSslCertificateChangedSignal; + } + + Dali::WebEnginePlugin::WebEngineHttpAuthHandlerSignalType& HttpAuthHandlerSignal() + { + return mHttpAuthHandlerSignal; + } + std::string mUrl; std::vector mHistory; size_t mCurrentPlusOnePos; @@ -1004,6 +1073,9 @@ public: Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType mRequestInterceptorSignal; Dali::WebEnginePlugin::WebEngineConsoleMessageSignalType mConsoleMessageSignal; Dali::WebEnginePlugin::WebEnginePolicyDecisionSignalType mPolicyDecisionSignal; + Dali::WebEnginePlugin::WebEngineCertificateSignalType mCertificateConfirmSignal; + Dali::WebEnginePlugin::WebEngineCertificateSignalType mSslCertificateChangedSignal; + Dali::WebEnginePlugin::WebEngineHttpAuthHandlerSignalType mHttpAuthHandlerSignal; bool mEvaluating; float mPageZoomFactor; @@ -1082,6 +1154,13 @@ bool OnLoadUrl() gInstance->mConsoleMessageSignal.Emit(std::move(message)); std::shared_ptr policyDecision(new MockWebEnginePolicyDecision()); gInstance->mPolicyDecisionSignal.Emit(std::move(policyDecision)); + + std::shared_ptr certificate(new MockWebEngineCertificate()); + gInstance->mCertificateConfirmSignal.Emit(std::move(certificate)); + std::shared_ptr sslCertificate(new MockWebEngineCertificate()); + gInstance->mSslCertificateChangedSignal.Emit(std::move(sslCertificate)); + std::shared_ptr handler(new MockWebEngineHttpAuthHandler()); + gInstance->mHttpAuthHandlerSignal.Emit(std::move(handler)); } return false; } @@ -1664,5 +1743,20 @@ Dali::WebEnginePlugin::WebEnginePolicyDecisionSignalType& WebEngine::PolicyDecis return Internal::Adaptor::GetImplementation(*this).PolicyDecisionSignal(); } +Dali::WebEnginePlugin::WebEngineCertificateSignalType& WebEngine::CertificateConfirmSignal() +{ + return Internal::Adaptor::GetImplementation(*this).CertificateConfirmSignal(); +} + +Dali::WebEnginePlugin::WebEngineCertificateSignalType& WebEngine::SslCertificateChangedSignal() +{ + return Internal::Adaptor::GetImplementation(*this).SslCertificateChangedSignal(); +} + +Dali::WebEnginePlugin::WebEngineHttpAuthHandlerSignalType& WebEngine::HttpAuthHandlerSignal() +{ + return Internal::Adaptor::GetImplementation(*this).HttpAuthHandlerSignal(); +} + } // 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 75f6977..034e377 100755 --- a/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp @@ -22,11 +22,13 @@ #include "dali-toolkit-test-utils/toolkit-timer.h" #include +#include +#include #include +#include +#include #include #include -#include -#include #include #include #include @@ -77,6 +79,12 @@ static int gConsoleMessageCallbackCalled = 0; static std::shared_ptr gConsoleMessageInstance = nullptr; static int gPolicyDecisionCallbackCalled = 0; static std::shared_ptr gPolicyDecisionInstance = nullptr; +static int gCertificateConfirmCallbackCalled = 0; +static std::shared_ptr gCertificateConfirmInstance = nullptr; +static int gSslCertificateChangedCallbackCalled = 0; +static std::shared_ptr gSslCertificateInstance = nullptr; +static int gHttpAuthHandlerCallbackCalled = 0; +static std::shared_ptr gHttpAuthInstance = nullptr; struct CallbackFunctor { @@ -209,6 +217,24 @@ static void OnConsoleMessage(WebView view, std::shared_ptr certificate ) +{ + gCertificateConfirmCallbackCalled++; + gCertificateConfirmInstance = std::move(certificate); +} + +static void OnSslCertificateChanged(WebView view, std::shared_ptr certificate ) +{ + gSslCertificateChangedCallbackCalled++; + gSslCertificateInstance = std::move(certificate); +} + +static void OnHttpAuthHandler( WebView view, std::shared_ptr hander ) +{ + gHttpAuthHandlerCallbackCalled++; + gHttpAuthInstance = std::move(hander); +} + } // namespace void web_view_startup(void) @@ -738,6 +764,65 @@ int UtcDaliWebViewFormRepostDecisionFrameRendering(void) END_TEST; } +int UtcDaliWebViewSslCertificateHttpAuthentication(void) +{ + ToolkitTestApplication application; + + WebView view = WebView::New(); + view.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + view.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + view.SetProperty( Actor::Property::POSITION, Vector2( 0, 0 )); + view.SetProperty( Actor::Property::SIZE, Vector2( 800, 600 ) ); + application.GetScene().Add( view ); + application.SendNotification(); + application.Render(); + DALI_TEST_CHECK( view ); + + ConnectionTracker* testTracker = new ConnectionTracker(); + view.CertificateConfirmSignal().Connect(&OnCertificateConfirm); + view.SslCertificateChangedSignal().Connect(&OnSslCertificateChanged); + view.HttpAuthHandlerSignal().Connect(&OnHttpAuthHandler); + bool signal1 = false; + bool signal2 = false; + bool signal3 = false; + view.ConnectSignal( testTracker, "certificateConfirm", CallbackFunctor(&signal1) ); + view.ConnectSignal( testTracker, "sslCertificateChanged", CallbackFunctor(&signal2) ); + view.ConnectSignal( testTracker, "httpAuthRequest", CallbackFunctor(&signal3) ); + DALI_TEST_EQUALS( gCertificateConfirmCallbackCalled, 0, TEST_LOCATION ); + DALI_TEST_EQUALS( gSslCertificateChangedCallbackCalled, 0, TEST_LOCATION ); + DALI_TEST_EQUALS( gHttpAuthHandlerCallbackCalled, 0, TEST_LOCATION ); + + view.LoadUrl( TEST_URL1 ); + Test::EmitGlobalTimerSignal(); + DALI_TEST_EQUALS( gCertificateConfirmCallbackCalled, 1, TEST_LOCATION ); + DALI_TEST_EQUALS( gSslCertificateChangedCallbackCalled, 1, TEST_LOCATION ); + DALI_TEST_EQUALS( gHttpAuthHandlerCallbackCalled, 1, TEST_LOCATION ); + DALI_TEST_CHECK( signal1 & signal2 & signal3); + + // certificate. + DALI_TEST_CHECK(gCertificateConfirmInstance); + gCertificateConfirmInstance->Allow(true); + DALI_TEST_CHECK(gCertificateConfirmInstance->IsFromMainFrame()); + + DALI_TEST_CHECK(gSslCertificateInstance); + DALI_TEST_EQUALS(gSslCertificateInstance->GetPem(), "abc", TEST_LOCATION); + DALI_TEST_CHECK(gSslCertificateInstance->IsContextSecure()); + + // http authentication. + DALI_TEST_CHECK(gHttpAuthInstance); + gHttpAuthInstance->Suspend(); + gHttpAuthInstance->UseCredential("", ""); + gHttpAuthInstance->CancelCredential(); + DALI_TEST_EQUALS(gHttpAuthInstance->GetRealm(), "test", TEST_LOCATION); + + // reset + gCertificateConfirmInstance = nullptr; + gSslCertificateInstance = nullptr; + gHttpAuthInstance = nullptr; + + END_TEST; +} + int UtcDaliWebViewGetWebBackForwardList(void) { ToolkitTestApplication application; 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 ebdb218..06c4ee9 100755 --- a/dali-toolkit/devel-api/controls/web-view/web-view.cpp +++ b/dali-toolkit/devel-api/controls/web-view/web-view.cpp @@ -354,6 +354,21 @@ WebView::WebViewPolicyDecisionSignalType& WebView::PolicyDecisionSignal() return Dali::Toolkit::GetImpl(*this).PolicyDecisionSignal(); } +WebView::WebViewCertificateSignalType& WebView::CertificateConfirmSignal() +{ + return Dali::Toolkit::GetImpl(*this).CertificateConfirmSignal(); +} + +WebView::WebViewCertificateSignalType& WebView::SslCertificateChangedSignal() +{ + return Dali::Toolkit::GetImpl(*this).SslCertificateChangedSignal(); +} + +WebView::WebViewHttpAuthHandlerSignalType& WebView::HttpAuthHandlerSignal() +{ + return Dali::Toolkit::GetImpl(*this).HttpAuthHandlerSignal(); +} + 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 d307d76..df73d0e 100755 --- a/dali-toolkit/devel-api/controls/web-view/web-view.h +++ b/dali-toolkit/devel-api/controls/web-view/web-view.h @@ -236,6 +236,16 @@ public: */ using WebViewPolicyDecisionSignalType = Signal)>; + /** + * @brief WebView signal type related with certificate changed. + */ + using WebViewCertificateSignalType = Signal)>; + + /** + * @brief WebView signal type related with http authentication. + */ + using WebViewHttpAuthHandlerSignalType = Signal)>; + public: /** * @brief Creates an initialized WebView. @@ -714,6 +724,27 @@ public: */ WebViewPolicyDecisionSignalType& PolicyDecisionSignal(); + /** + * @brief Connects to this signal to be notified when certificate need be confirmed. + * + * @return A signal object to connect with. + */ + WebViewCertificateSignalType& CertificateConfirmSignal(); + + /** + * @brief Connects to this signal to be notified when ssl certificate is changed. + * + * @return A signal object to connect with. + */ + WebViewCertificateSignalType& SslCertificateChangedSignal(); + + /** + * @brief Connects to this signal to be notified when http authentication need be confirmed. + * + * @return A signal object to connect with. + */ + WebViewHttpAuthHandlerSignalType& HttpAuthHandlerSignal(); + public: // Not intended for application developers /// @cond internal /** diff --git a/dali-toolkit/internal/controls/web-view/web-view-impl.cpp b/dali-toolkit/internal/controls/web-view/web-view-impl.cpp old mode 100644 new mode 100755 index 7db2689..2eeabeb --- a/dali-toolkit/internal/controls/web-view/web-view-impl.cpp +++ b/dali-toolkit/internal/controls/web-view/web-view-impl.cpp @@ -20,13 +20,15 @@ // EXTERNAL INCLUDES #include +#include #include #include #include #include -#include +#include #include #include +#include #include #include #include @@ -83,17 +85,20 @@ DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "pageZoomFactor", FLOAT, DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "textZoomFactor", FLOAT, TEXT_ZOOM_FACTOR ) DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "loadProgressPercentage", FLOAT, LOAD_PROGRESS_PERCENTAGE ) -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_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_SIGNAL_REGISTRATION(Toolkit, WebView, "consoleMessage", CONSOLE_MESSAGE_SIGNAL ) -DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "policyDecision", POLICY_DECISION ) +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_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_SIGNAL_REGISTRATION(Toolkit, WebView, "consoleMessage", CONSOLE_MESSAGE_SIGNAL ) +DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "policyDecision", POLICY_DECISION ) +DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "certificateConfirm", CERTIFICATE_CONFIRM_SIGNAL ) +DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "sslCertificateChanged", SSL_CERTIFICATE_CHANGED_SIGNAL) +DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "httpAuthRequest", HTTP_AUTH_REQUEST_SIGNAL ) DALI_TYPE_REGISTRATION_END() // clang-format on @@ -226,6 +231,9 @@ void WebView::OnInitialize() mWebEngine.RequestInterceptorSignal().Connect(this, &WebView::OnInterceptRequest); mWebEngine.ConsoleMessageSignal().Connect(this, &WebView::OnConsoleMessage); mWebEngine.PolicyDecisionSignal().Connect(this, &WebView::OnPolicyDecisionRequest); + mWebEngine.CertificateConfirmSignal().Connect(this, &WebView::OnCertificateConfirm); + mWebEngine.SslCertificateChangedSignal().Connect(this, &WebView::OnSslCertificateChanged); + mWebEngine.HttpAuthHandlerSignal().Connect(this, &WebView::OnHttpAuthenticationRequest); mWebContext = std::unique_ptr(new WebContext(mWebEngine.GetContext())); mWebCookieManager = std::unique_ptr(new WebCookieManager(mWebEngine.GetCookieManager())); @@ -734,6 +742,21 @@ Dali::Toolkit::WebView::WebViewPolicyDecisionSignalType& WebView::PolicyDecision return mPolicyDecisionSignal; } +Dali::Toolkit::WebView::WebViewCertificateSignalType& WebView::CertificateConfirmSignal() +{ + return mCertificateConfirmSignal; +} + +Dali::Toolkit::WebView::WebViewCertificateSignalType& WebView::SslCertificateChangedSignal() +{ + return mSslCertificateChangedSignal; +} + +Dali::Toolkit::WebView::WebViewHttpAuthHandlerSignalType& WebView::HttpAuthHandlerSignal() +{ + return mHttpAuthHandlerSignal; +} + void WebView::OnPageLoadStarted(const std::string& url) { if(!mPageLoadStartedSignal.Empty()) @@ -851,6 +874,33 @@ void WebView::OnPolicyDecisionRequest(std::shared_ptr certificate) +{ + if(!mCertificateConfirmSignal.Empty()) + { + Dali::Toolkit::WebView handle(GetOwner()); + mCertificateConfirmSignal.Emit(handle, std::move(certificate)); + } +} + +void WebView::OnSslCertificateChanged(std::shared_ptr certificate) +{ + if(!mSslCertificateChangedSignal.Empty()) + { + Dali::Toolkit::WebView handle(GetOwner()); + mSslCertificateChangedSignal.Emit(handle, std::move(certificate)); + } +} + +void WebView::OnHttpAuthenticationRequest(std::shared_ptr handler) +{ + if(!mHttpAuthHandlerSignal.Empty()) + { + Dali::Toolkit::WebView handle(GetOwner()); + mHttpAuthHandlerSignal.Emit(handle, std::move(handler)); + } +} + bool WebView::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor) { Dali::BaseHandle handle(object); @@ -913,6 +963,21 @@ bool WebView::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tr webView.PolicyDecisionSignal().Connect(tracker, functor); connected = true; } + else if(0 == strcmp(signalName.c_str(), CERTIFICATE_CONFIRM_SIGNAL)) + { + webView.CertificateConfirmSignal().Connect(tracker, functor); + connected = true; + } + else if(0 == strcmp(signalName.c_str(), SSL_CERTIFICATE_CHANGED_SIGNAL)) + { + webView.SslCertificateChangedSignal().Connect(tracker, functor); + connected = true; + } + else if(0 == strcmp(signalName.c_str(), HTTP_AUTH_REQUEST_SIGNAL)) + { + webView.HttpAuthHandlerSignal().Connect(tracker, functor); + connected = true; + } return connected; } 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 5a2751a..532fec6 100755 --- a/dali-toolkit/internal/controls/web-view/web-view-impl.h +++ b/dali-toolkit/internal/controls/web-view/web-view-impl.h @@ -354,6 +354,21 @@ public: */ Dali::Toolkit::WebView::WebViewPolicyDecisionSignalType& PolicyDecisionSignal(); + /** + * @copydoc Dali::Toolkit::WebView::CertificateConfirmSignal() + */ + Dali::Toolkit::WebView::WebViewCertificateSignalType& CertificateConfirmSignal(); + + /** + * @copydoc Dali::Toolkit::WebView::SslCertificateChangedSignal() + */ + Dali::Toolkit::WebView::WebViewCertificateSignalType& SslCertificateChangedSignal(); + + /** + * @copydoc Dali::Toolkit::WebView::HttpAuthHandlerSignal() + */ + Dali::Toolkit::WebView::WebViewHttpAuthHandlerSignalType& HttpAuthHandlerSignal(); + public: // Properties /** * @brief Called when a property of an object of this type is set. @@ -681,6 +696,24 @@ private: */ void OnPolicyDecisionRequest(std::shared_ptr decision); + /** + * @brief Callback function to be called when certificate need be confirmed. + * @param[in] certificate The certificate policy decision. + */ + void OnCertificateConfirm(std::shared_ptr certificate); + + /** + * @brief Callback function to be called when ssl certificate is changed. + * @param[in] certificate The certificate information received. + */ + void OnSslCertificateChanged(std::shared_ptr certificate); + + /** + * @brief Callback function to be called when http authentication need be confirmed. + * @param[in] handler The handler for http authentication + */ + void OnHttpAuthenticationRequest(std::shared_ptr handler); + private: std::string mUrl; Dali::Toolkit::Visual::Base mVisual; @@ -698,6 +731,9 @@ private: Dali::Toolkit::WebView::WebViewRequestInterceptorSignalType mRequestInterceptorSignal; Dali::Toolkit::WebView::WebViewConsoleMessageSignalType mConsoleMessageSignal; Dali::Toolkit::WebView::WebViewPolicyDecisionSignalType mPolicyDecisionSignal; + Dali::Toolkit::WebView::WebViewCertificateSignalType mCertificateConfirmSignal; + Dali::Toolkit::WebView::WebViewCertificateSignalType mSslCertificateChangedSignal; + Dali::Toolkit::WebView::WebViewHttpAuthHandlerSignalType mHttpAuthHandlerSignal; std::unique_ptr mWebContext; std::unique_ptr mWebCookieManager;