From a989130f765c3686fa5ec07a49831a3f47a709bc Mon Sep 17 00:00:00 2001 From: "huayong.xu" Date: Thu, 25 Feb 2021 19:57:59 +0800 Subject: [PATCH] Add APIs for ssl certificate and http authentication. This patch is to add some APIs for ssl certificate and http authentication in web engine. Change-Id: I1f72530682234fede563f593654d7908396cc8f5 --- .../adaptor-framework/web-engine-certificate.h | 73 ++++++++++++++++++++++ .../web-engine-http-auth-handler.h | 70 +++++++++++++++++++++ .../adaptor-framework/web-engine-plugin.h | 33 ++++++++++ dali/devel-api/adaptor-framework/web-engine.cpp | 17 +++++ dali/devel-api/adaptor-framework/web-engine.h | 21 +++++++ dali/devel-api/file.list | 2 + .../internal/web-engine/common/web-engine-impl.cpp | 21 ++++++- dali/internal/web-engine/common/web-engine-impl.h | 15 +++++ 8 files changed, 250 insertions(+), 2 deletions(-) create mode 100755 dali/devel-api/adaptor-framework/web-engine-certificate.h create mode 100755 dali/devel-api/adaptor-framework/web-engine-http-auth-handler.h diff --git a/dali/devel-api/adaptor-framework/web-engine-certificate.h b/dali/devel-api/adaptor-framework/web-engine-certificate.h new file mode 100755 index 0000000..cd0b055 --- /dev/null +++ b/dali/devel-api/adaptor-framework/web-engine-certificate.h @@ -0,0 +1,73 @@ +#ifndef DALI_WEB_ENGINE_CERTIFICATE_H +#define DALI_WEB_ENGINE_CERTIFICATE_H + +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include + +namespace Dali +{ +/** + * @brief A class WebEngineCertificate for certificate of web engine. + */ +class WebEngineCertificate +{ +public: + /** + * @brief Constructor. + */ + WebEngineCertificate() = default; + + /** + * @brief Destructor. + */ + virtual ~WebEngineCertificate() = default; + + /** + * @brief Allow the site access about certificate error. + * + * @param[in] allowed A value to decide policy + */ + virtual void Allow(bool allowed) = 0; + + /** + * @brief Returns information whether the certificate comes from main frame. + * + * @return true if the certificate comes from main frame, false otherwise + */ + virtual bool IsFromMainFrame() const = 0; + + /** + * @brief Query certificate's PEM data. + * + * @return A certificate itself in the PEM format. + */ + virtual std::string GetPem() const = 0; + + /** + * @brief Query if the context loaded with a given certificate is secure. + * + * @return true if the context is secure, false otherwise + */ + virtual bool IsContextSecure() const = 0; +}; + +} // namespace Dali + +#endif // DALI_WEB_ENGINE_CERTIFICATE_H diff --git a/dali/devel-api/adaptor-framework/web-engine-http-auth-handler.h b/dali/devel-api/adaptor-framework/web-engine-http-auth-handler.h new file mode 100755 index 0000000..6fcc132 --- /dev/null +++ b/dali/devel-api/adaptor-framework/web-engine-http-auth-handler.h @@ -0,0 +1,70 @@ +#ifndef DALI_WEB_ENGINE_HTTP_AUTH_HANDLER_H +#define DALI_WEB_ENGINE_HTTP_AUTH_HANDLER_H + +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include + +namespace Dali +{ +/** + * @brief A class WebEngineHttpAuthHandler for HTTP authentication handler of web engine. + */ +class WebEngineHttpAuthHandler +{ +public: + /** + * @brief Constructor. + */ + WebEngineHttpAuthHandler() = default; + + /** + * @brief Destructor. + */ + virtual ~WebEngineHttpAuthHandler() = default; + + /** + * @brief Gets the realm string of authentication challenge received. + * + * @return the realm of authentication challenge + */ + virtual std::string GetRealm() const = 0; + + /** + * @brief Suspend the operation for authentication challenge. + */ + virtual void Suspend() = 0; + + /** + * @brief Send credential for authentication challenge. + * + * @param[in] user user id from user input. + * @param[in] password user password from user input. + */ + virtual void UseCredential(const std::string& user, const std::string& password) = 0; + + /** + * @brief Send cancellation notification for authentication challenge. + */ + virtual void CancelCredential() = 0; +}; + +} // namespace Dali + +#endif // DALI_WEB_ENGINE_HTTP_AUTH_HANDLER_H diff --git a/dali/devel-api/adaptor-framework/web-engine-plugin.h b/dali/devel-api/adaptor-framework/web-engine-plugin.h index bbfa6f6..c87fbe4 100644 --- a/dali/devel-api/adaptor-framework/web-engine-plugin.h +++ b/dali/devel-api/adaptor-framework/web-engine-plugin.h @@ -32,10 +32,12 @@ class KeyEvent; class PixelData; class TouchEvent; class WebEngineBackForwardList; +class WebEngineCertificate; class WebEngineConsoleMessage; class WebEngineContext; class WebEngineCookieManager; class WebEngineFormRepostDecision; +class WebEngineHttpAuthHandler; class WebEngineLoadError; class WebEnginePolicyDecision; class WebEngineRequestInterceptor; @@ -102,6 +104,16 @@ public: using WebEngineConsoleMessageSignalType = Signal)>; /** + * @brief WebView signal type related with certificate changed. + */ + using WebEngineCertificateSignalType = Signal)>; + + /** + * @brief WebView signal type related with http authentication. + */ + using WebEngineHttpAuthHandlerSignalType = Signal)>; + + /** * @brief Alert callback when JavaScript alert is called with a message. * It returns true if a pop-up is created successfully, false otherwise. */ @@ -768,6 +780,27 @@ public: * @return A signal object to connect with. */ virtual WebEnginePolicyDecisionSignalType& PolicyDecisionSignal() = 0; + + /** + * @brief Connects to this signal to be notified when certificate need be confirmed. + * + * @return A signal object to connect with. + */ + virtual WebEngineCertificateSignalType& CertificateConfirmSignal() = 0; + + /** + * @brief Connects to this signal to be notified when ssl certificate is changed. + * + * @return A signal object to connect with. + */ + virtual WebEngineCertificateSignalType& SslCertificateChangedSignal() = 0; + + /** + * @brief Connects to this signal to be notified when http authentication need be confirmed. + * + * @return A signal object to connect with. + */ + virtual WebEngineHttpAuthHandlerSignalType& HttpAuthHandlerSignal() = 0; }; // specialization has to be done in the same namespace diff --git a/dali/devel-api/adaptor-framework/web-engine.cpp b/dali/devel-api/adaptor-framework/web-engine.cpp index b1d9fa0..c7edd4c 100755 --- a/dali/devel-api/adaptor-framework/web-engine.cpp +++ b/dali/devel-api/adaptor-framework/web-engine.cpp @@ -20,9 +20,11 @@ // INTERNAL INCLUDES #include +#include #include #include #include +#include #include #include #include @@ -518,4 +520,19 @@ Dali::WebEnginePlugin::WebEnginePolicyDecisionSignalType& WebEngine::PolicyDecis return GetImplementation(*this).PolicyDecisionSignal(); } +Dali::WebEnginePlugin::WebEngineCertificateSignalType& WebEngine::CertificateConfirmSignal() +{ + return GetImplementation(*this).CertificateConfirmSignal(); +} + +Dali::WebEnginePlugin::WebEngineCertificateSignalType& WebEngine::SslCertificateChangedSignal() +{ + return GetImplementation(*this).SslCertificateChangedSignal(); +} + +Dali::WebEnginePlugin::WebEngineHttpAuthHandlerSignalType& WebEngine::HttpAuthHandlerSignal() +{ + return GetImplementation(*this).HttpAuthHandlerSignal(); +} + } // namespace Dali diff --git a/dali/devel-api/adaptor-framework/web-engine.h b/dali/devel-api/adaptor-framework/web-engine.h index 9b479e4..ca3ea6f 100755 --- a/dali/devel-api/adaptor-framework/web-engine.h +++ b/dali/devel-api/adaptor-framework/web-engine.h @@ -685,6 +685,27 @@ public: */ Dali::WebEnginePlugin::WebEnginePolicyDecisionSignalType& PolicyDecisionSignal(); + /** + * @brief Connects to this signal to be notified when certificate need be confirmed. + * + * @return A signal object to connect with. + */ + Dali::WebEnginePlugin::WebEngineCertificateSignalType& CertificateConfirmSignal(); + + /** + * @brief Connects to this signal to be notified when ssl certificate is changed. + * + * @return A signal object to connect with. + */ + Dali::WebEnginePlugin::WebEngineCertificateSignalType& SslCertificateChangedSignal(); + + /** + * @brief Connects to this signal to be notified when http authentication need be confirmed. + * + * @return A signal object to connect with. + */ + Dali::WebEnginePlugin::WebEngineHttpAuthHandlerSignalType& HttpAuthHandlerSignal(); + private: // Not intended for application developers /** * @brief Internal constructor diff --git a/dali/devel-api/file.list b/dali/devel-api/file.list index b5664dc..8e3ed5f 100755 --- a/dali/devel-api/file.list +++ b/dali/devel-api/file.list @@ -91,11 +91,13 @@ SET( devel_api_adaptor_framework_header_files ${adaptor_devel_api_dir}/adaptor-framework/web-engine.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-back-forward-list-item.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-back-forward-list.h + ${adaptor_devel_api_dir}/adaptor-framework/web-engine-certificate.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-console-message.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-context.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-cookie-manager.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-form-repost-decision.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-frame.h + ${adaptor_devel_api_dir}/adaptor-framework/web-engine-http-auth-handler.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-load-error.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-plugin.h ${adaptor_devel_api_dir}/adaptor-framework/web-engine-policy-decision.h diff --git a/dali/internal/web-engine/common/web-engine-impl.cpp b/dali/internal/web-engine/common/web-engine-impl.cpp index 4c3b7d8..be477de 100755 --- a/dali/internal/web-engine/common/web-engine-impl.cpp +++ b/dali/internal/web-engine/common/web-engine-impl.cpp @@ -27,12 +27,14 @@ // INTERNAL INCLUDES #include #include +#include #include #include #include -#include +#include #include #include +#include #include #include #include @@ -350,7 +352,7 @@ void WebEngine::JavaScriptAlertReply() void WebEngine::RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback) { - mPlugin->RegisterJavaScriptAlertCallback(callback); + mPlugin->RegisterJavaScriptConfirmCallback(callback); } void WebEngine::JavaScriptConfirmReply(bool confirmed) @@ -613,6 +615,21 @@ Dali::WebEnginePlugin::WebEnginePolicyDecisionSignalType& WebEngine::PolicyDecis return mPlugin->PolicyDecisionSignal(); } +Dali::WebEnginePlugin::WebEngineCertificateSignalType& WebEngine::CertificateConfirmSignal() +{ + return mPlugin->CertificateConfirmSignal(); +} + +Dali::WebEnginePlugin::WebEngineCertificateSignalType& WebEngine::SslCertificateChangedSignal() +{ + return mPlugin->SslCertificateChangedSignal(); +} + +Dali::WebEnginePlugin::WebEngineHttpAuthHandlerSignalType& WebEngine::HttpAuthHandlerSignal() +{ + return mPlugin->HttpAuthHandlerSignal(); +} + } // namespace Adaptor } // namespace Internal } // namespace Dali diff --git a/dali/internal/web-engine/common/web-engine-impl.h b/dali/internal/web-engine/common/web-engine-impl.h index 0500628..b572c76 100755 --- a/dali/internal/web-engine/common/web-engine-impl.h +++ b/dali/internal/web-engine/common/web-engine-impl.h @@ -499,6 +499,21 @@ public: */ Dali::WebEnginePlugin::WebEnginePolicyDecisionSignalType& PolicyDecisionSignal(); + /** + * @copydoc Dali::WebEngine::CertificateConfirmSignal() + */ + Dali::WebEnginePlugin::WebEngineCertificateSignalType& CertificateConfirmSignal(); + + /** + * @copydoc Dali::WebEngine::SslCertificateChangedSignal() + */ + Dali::WebEnginePlugin::WebEngineCertificateSignalType& SslCertificateChangedSignal(); + + /** + * @copydoc Dali::WebEngine::HttpAuthHandlerSignal() + */ + Dali::WebEnginePlugin::WebEngineHttpAuthHandlerSignalType& HttpAuthHandlerSignal(); + private: /** * @brief Constructor. -- 2.7.4