From 997da212a0e45b9f94da2e66927a40ef5f3b1e97 Mon Sep 17 00:00:00 2001 From: Seongjun Yim Date: Sat, 25 May 2013 19:17:15 +0900 Subject: [PATCH] apply certificate DB Change-Id: I1772acff5fd9572fbf96230e803f6d06c09997ec Signed-off-by: Seongjun Yim --- src/controls/FWebCtrl_CertificateConfirmPopup.cpp | 47 ++++++++++++-- src/controls/FWebCtrl_CertificateConfirmPopup.h | 6 +- src/controls/FWebCtrl_EflWebkit.cpp | 16 ++++- src/controls/FWebCtrl_EflWebkit.h | 1 + src/controls/FWebCtrl_WebImpl.cpp | 74 ++++++++++++++++++++++- src/controls/FWebCtrl_WebImpl.h | 2 + 6 files changed, 137 insertions(+), 9 deletions(-) mode change 100644 => 100755 src/controls/FWebCtrl_CertificateConfirmPopup.h diff --git a/src/controls/FWebCtrl_CertificateConfirmPopup.cpp b/src/controls/FWebCtrl_CertificateConfirmPopup.cpp index a6b1e4b..8bfebb5 100755 --- a/src/controls/FWebCtrl_CertificateConfirmPopup.cpp +++ b/src/controls/FWebCtrl_CertificateConfirmPopup.cpp @@ -19,20 +19,25 @@ * @file FWebCtrl_CertificateConfirmPopup.cpp * @brief The file contains the definition of _CertificateConfirmPopup class. */ +#include #include #include #include #include #include +#include +#include #include #include #include #include #include #include +#include #include #include #include "FWebCtrl_CertificateConfirmPopup.h" +#include "FWebCtrl_EflWebkit.h" #include "FWebCtrl_Utility.h" @@ -192,8 +197,7 @@ _CertificateConfirmPopup::OnActionPerformed(const Control& source, int actionId) switch (actionId) { case ID_BUTTON_CERTIFICATE_ALLOW: - ewk_certificate_policy_decision_allowed_set(__pCertificatePolicyData, EINA_TRUE); - __confirm = static_cast< bool >(EINA_TRUE); + HandleUserAction(true); break; case ID_BUTTON_CERTIFICATE_VIEW: @@ -214,8 +218,7 @@ _CertificateConfirmPopup::OnActionPerformed(const Control& source, int actionId) } case ID_BUTTON_CERTIFICATE_CANCEL: - ewk_certificate_policy_decision_allowed_set(__pCertificatePolicyData, EINA_FALSE); - __confirm = static_cast< bool >(EINA_FALSE); + HandleUserAction(false); break; case ID_BUTTON_CERTIFICATE_CLOSE: @@ -245,6 +248,42 @@ _CertificateConfirmPopup::GetConfirmResult() const } +void +_CertificateConfirmPopup::HandleUserAction(bool allow) +{ + __confirm = allow; + + String pem(ewk_certificate_policy_decision_certificate_pem_get(__pCertificatePolicyData)); + ewk_certificate_policy_decision_allowed_set(__pCertificatePolicyData, static_cast< Eina_Bool >(allow)); + AddCertificateDb(pem, allow); +} + + +void +_CertificateConfirmPopup::AddCertificateDb(const String& pem, bool allow) +{ + _DatabaseImpl db; + String certificatePath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME); + String table(CERTIFICATE_TABLE_NAME); + + result r = db.Construct(certificatePath, "r+", null); + SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r)); + + std::unique_ptr pStmt(db.CreateStatementN(L"Insert Into " + table + L" (pem, allow) Values (?, ?)")); + SysTryReturnVoidResult(NID_WEB_CTRL, pStmt.get(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); + + SysLog(NID_WEB_CTRL, "The current value of pem is %ls, allow is %d", pem.GetPointer(), allow); + + pStmt->BindString(0, pem); + pStmt->BindInt(1, static_cast < int >(allow)); + + db.BeginTransaction(); + + std::unique_ptr pEnum(db.ExecuteStatementN(*pStmt)); + + db.CommitTransaction(); +} + result _CertificateConfirmPopup::GenerateCertifiate(String& certString) { diff --git a/src/controls/FWebCtrl_CertificateConfirmPopup.h b/src/controls/FWebCtrl_CertificateConfirmPopup.h old mode 100644 new mode 100755 index 8c5e985..76ace71 --- a/src/controls/FWebCtrl_CertificateConfirmPopup.h +++ b/src/controls/FWebCtrl_CertificateConfirmPopup.h @@ -63,10 +63,14 @@ public: result Construct(_CertificatePopupMode certPopupMode, Ewk_Certificate_Policy_Decision* pPolicy); - virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId); + void HandleUserAction(bool allow); bool GetConfirmResult() const; + void AddCertificateDb(const Tizen::Base::String& pem, bool allow); + + virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId); + private: _CertificateConfirmPopup(const _CertificateConfirmPopup&); diff --git a/src/controls/FWebCtrl_EflWebkit.cpp b/src/controls/FWebCtrl_EflWebkit.cpp index 2a2c6f6..7a8dabe 100755 --- a/src/controls/FWebCtrl_EflWebkit.cpp +++ b/src/controls/FWebCtrl_EflWebkit.cpp @@ -69,9 +69,10 @@ extern const wchar_t USER_CONFIRM_DB_NAME[] = L"userConfirm.db"; extern const wchar_t GEOLOCATION_TABLE_NAME[] = L"geolocationPermission"; extern const wchar_t CUSTOM_PROTOCOL_TABLE_NAME[] = L"customProtocol"; extern const wchar_t CUSTOM_CONTENT_TABLE_NAME[] = L"customContent"; +extern const wchar_t CERTIFICATE_TABLE_NAME[] = L"certificate"; -static const int CUSTOM_DB_TABLE_COUNT= 3; +static const int CUSTOM_DB_TABLE_COUNT= 4; _EflWebkit::_EflWebkit(void) @@ -204,11 +205,12 @@ _EflWebkit::InitializeCustomDb(void) const String geolocationTable(GEOLOCATION_TABLE_NAME); String protocolTable(CUSTOM_PROTOCOL_TABLE_NAME); String contentTable(CUSTOM_CONTENT_TABLE_NAME); + String certificateTable(CERTIFICATE_TABLE_NAME); r = db.Construct(path, "a+", null); SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r)); - std::unique_ptr pEnum(db.QueryN(L"Select count(name) from sqlite_master Where type='table' And name in ('" + geolocationTable + L"', '" + protocolTable + L"', '" + contentTable + L"')")); + std::unique_ptr pEnum(db.QueryN(L"Select count(name) from sqlite_master Where type='table' And name in ('" + geolocationTable + L"', '" + protocolTable + L"', '" + contentTable + L"', '" + certificateTable + L"')")); if (pEnum.get()) { int count = 0; @@ -255,6 +257,16 @@ _EflWebkit::InitializeCustomDb(void) const SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r)); } + pEnum.reset(); + pEnum = std::unique_ptr(db.QueryN(L"Select name from sqlite_master Where type='table' And name = '" + certificateTable + L"'")); + if (!pEnum.get()) + { + r = db.ExecuteSql( + L"CREATE TABLE IF NOT EXISTS " + certificateTable + L"(id INTEGER PRIMARY KEY AUTOINCREMENT, pem TEXT, allow INTEGER)", + true); + SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r)); + } + return E_SUCCESS; } diff --git a/src/controls/FWebCtrl_EflWebkit.h b/src/controls/FWebCtrl_EflWebkit.h index 79a28d9..69cec83 100755 --- a/src/controls/FWebCtrl_EflWebkit.h +++ b/src/controls/FWebCtrl_EflWebkit.h @@ -52,6 +52,7 @@ _OSP_EXPORT_ extern const wchar_t USER_CONFIRM_DB_NAME[]; _OSP_EXPORT_ extern const wchar_t GEOLOCATION_TABLE_NAME[]; _OSP_EXPORT_ extern const wchar_t CUSTOM_PROTOCOL_TABLE_NAME[]; _OSP_EXPORT_ extern const wchar_t CUSTOM_CONTENT_TABLE_NAME[]; +_OSP_EXPORT_ extern const wchar_t CERTIFICATE_TABLE_NAME[]; class _EflWebkit : public Tizen::Base::Object diff --git a/src/controls/FWebCtrl_WebImpl.cpp b/src/controls/FWebCtrl_WebImpl.cpp index 8311f63..3297364 100755 --- a/src/controls/FWebCtrl_WebImpl.cpp +++ b/src/controls/FWebCtrl_WebImpl.cpp @@ -436,14 +436,42 @@ OnCertificateRequested(void* pUserData, Evas_Object* pView, void* pEventInfo) result r = E_SUCCESS; - r = pImpl->ShowCertificateConfirmPopup(CERTIFICATE_POPUP_MODE_USER_CONFIRM, pPolicy); + std::unique_ptr pEnum; + + String certificatePath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME); + String table(CERTIFICATE_TABLE_NAME); + _DatabaseImpl db; + + String pem(ewk_certificate_policy_decision_certificate_pem_get(pPolicy)); + + r = db.Construct(certificatePath, "r", null); SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r)); + pEnum = std::unique_ptr(db.QueryN(L"Select allow From " + table + L" Where pem = '" + pem + L"'")); + if (pEnum.get()) + { + r = pEnum->MoveNext(); + SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r)); + + int allow = 0; + r = pEnum->GetIntAt(0, allow); + SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r)); + + SysLog(NID_WEB_CTRL, "The current value of allow is %d", allow); + + ewk_certificate_policy_decision_allowed_set(pPolicy, static_cast < Eina_Bool >(allow)); + pImpl->SetCertificateConfirmed(static_cast < bool >(allow)); + } + else + { + r = pImpl->ShowCertificateConfirmPopup(CERTIFICATE_POPUP_MODE_USER_CONFIRM, pPolicy); + SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r)); + } + pImpl->SetCertificateRequested(true); break; } case WEB_CERTIFICATE_ERROR_HANDLING_MODE_CANCEL: -CATCH: ewk_certificate_policy_decision_allowed_set(pPolicy, EINA_FALSE); break; case WEB_CERTIFICATE_ERROR_HANDLING_MODE_CONTINUE : @@ -452,6 +480,13 @@ CATCH: default: SysAssert(false); } + + return; + +CATCH: + ewk_certificate_policy_decision_allowed_set(pPolicy, EINA_FALSE); + pImpl->SetCertificateConfirmed(false); + pImpl->SetCertificateRequested(true); } @@ -2145,8 +2180,10 @@ _WebImpl::_WebImpl(Web* pWeb, Tizen::Ui::_Control* pCore) _WebImpl::~_WebImpl() { RemoveEventListenerCallback(); + ClearCertificateDb(); } + _WebImpl* _WebImpl::CreateWebImplN(Web* pControl, const Rectangle& bounds) { @@ -3611,6 +3648,32 @@ _WebImpl::RemoveEventListenerCallback(void) const } +void +_WebImpl::ClearCertificateDb(void) +{ + result r = E_SUCCESS; + + String certificatePath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME); + String table(CERTIFICATE_TABLE_NAME); + _DatabaseImpl db; + + r = db.Construct(certificatePath, "r+", null); + SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r)); + + db.BeginTransaction(); + + r = db.ExecuteSql(L"Delete From " + table, true); + SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r)); + + db.CommitTransaction(); + + return; + +CATCH: + db.RollbackTransaction(); +} + + result _WebImpl::SetBlockSelectionPosition(const Point& startPoint) { @@ -3836,6 +3899,13 @@ _WebImpl::IsCertificateRequested(void) const } +void +_WebImpl::SetCertificateConfirmed(bool arg) +{ + __isCertificateConfirmed = arg; +} + + bool _WebImpl::IsCertificateConfirmed(void) const { diff --git a/src/controls/FWebCtrl_WebImpl.h b/src/controls/FWebCtrl_WebImpl.h index 4fe886f..856606e 100755 --- a/src/controls/FWebCtrl_WebImpl.h +++ b/src/controls/FWebCtrl_WebImpl.h @@ -311,7 +311,9 @@ public: void SetCertificateRequested(bool arg); bool IsCertificateRequested(void) const; + void SetCertificateConfirmed(bool arg); bool IsCertificateConfirmed(void) const; + void ClearCertificateDb(void); void SetOrientationChanged(bool arg); bool IsOrientationChanged(void) const; -- 2.7.4