From: leerang song Date: Wed, 27 Feb 2013 07:12:34 +0000 (+0900) Subject: Implement certificate confirm popup X-Git-Tag: 2.1b_release~22^2~27 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5abc0e625b2b2b598aa220b739eb17e52ddf967c;p=platform%2Fframework%2Fweb%2Fwrt.git Implement certificate confirm popup [Issue#] N/A [Problem] Can't storage certificate info [Cause] Not exist certificate db [Solution] Make certificate db [SCMRequest] N/A Change-Id: If2ff85fd8b14e980983aa81faa45cdb079145424 --- diff --git a/src/view/common/CMakeLists.txt b/src/view/common/CMakeLists.txt old mode 100644 new mode 100755 index 5b9bfc3..5eb7dcb --- a/src/view/common/CMakeLists.txt +++ b/src/view/common/CMakeLists.txt @@ -45,6 +45,7 @@ PKG_CHECK_MODULES(VIEW_COMMON_DEP dpl-wrt-dao-ro wrt-commons-auto-save-dao-rw wrt-commons-security-origin-dao + wrt-commons-certificate-dao wrt-popup-wrt-runner REQUIRED ) @@ -67,6 +68,7 @@ SET(VIEW_COMMON_SOURCES ${PROJECT_SOURCE_DIR}/src/view/common/view_logic_uri_support.cpp ${PROJECT_SOURCE_DIR}/src/view/common/view_logic_user_agent_support.cpp ${PROJECT_SOURCE_DIR}/src/view/common/view_logic_vibration_support.cpp + ${PROJECT_SOURCE_DIR}/src/view/common/view_logic_certificate_support.cpp ) SET(VIEW_COMMON_INCLUDES diff --git a/src/view/common/view_logic_certificate_support.cpp b/src/view/common/view_logic_certificate_support.cpp new file mode 100755 index 0000000..308157c --- /dev/null +++ b/src/view/common/view_logic_certificate_support.cpp @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ +/** + * @file view_logic_certificate_origin_support.cpp + * @author Leerang Song (leerang.song@samsung.com) + * @version 1.0 + * @brief Support certificate dao + */ + +#include "view_logic_certificate_support.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace ViewModule { +namespace { +const char* const DAEMON_EDJ_PATH = "/usr/share/edje/wrt/Daemon.edj"; +} + +class CertificateSupportImplementation +{ + private: + WidgetModel* m_model; + CertificateDB::CertificateDAOPtr m_certificateDAO; + + public: + CertificateSupportImplementation(WidgetModel* widgetModel) : + m_model(NULL) + { + Assert(widgetModel); + m_model = widgetModel; + } + + ~CertificateSupportImplementation() + {} + + CertificateDB::CertificateDAO* getCertificateDAO(void) + { + Assert(m_model); + if (!m_certificateDAO) { + LogDebug("initialize CertificateDAO"); + m_certificateDAO = + CertificateDB::CertificateDAOPtr( + new CertificateDB::CertificateDAO(m_model->TzPkgId. + Get())); + // initialize certificate result data. Remove allow, deny for + m_certificateDAO->removeCertificateData( + CertificateDB::RESULT_ALLOW_ONCE); + m_certificateDAO->removeCertificateData( + CertificateDB::RESULT_DENY_ONCE); + } + return m_certificateDAO.get(); + } +}; + +CertificateSupport::CertificateSupport(WidgetModel* widgetModel) : + m_impl(new CertificateSupportImplementation(widgetModel)) +{} + +CertificateSupport::~CertificateSupport() +{} + +CertificateDB::CertificateDAO* CertificateSupport:: + getCertificateDAO(void) +{ + return m_impl->getCertificateDAO(); +} + +Evas_Object* CertificateSupportUtil::createPopup( + Evas_Object* window, + const char* bodyText, + const char* checkText, + Evas_Smart_Cb + buttonCallback, + void* data) +{ + LogDebug("createPopup"); + Evas_Object* popup = elm_popup_add(window); + + Evas_Object* label = elm_label_add(popup); + elm_object_style_set(label, "popup/default"); + elm_label_line_wrap_set(label, ELM_WRAP_MIXED); + elm_object_text_set(label, bodyText); + evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(label); + + Evas_Object* layout = elm_layout_add(popup); + elm_layout_file_set(layout, DAEMON_EDJ_PATH, "popupWithCheck"); + evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + + Evas_Object* check = elm_check_add(popup); + evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_show(check); + + elm_object_part_text_set(layout, "elm.text", checkText); + elm_object_part_content_set(layout, "elm.swallow.content", label); + elm_object_part_content_set(layout, "elm.swallow.end", check); + + evas_object_show(layout); + elm_object_content_set(popup, layout); + Evas_Object* btn1 = elm_button_add(popup); + elm_object_text_set(btn1, "YES"); + elm_object_part_content_set(popup, "button1", btn1); + evas_object_smart_callback_add(btn1, "clicked", buttonCallback, data); + Evas_Object* btn2 = elm_button_add(popup); + elm_object_text_set(btn2, "NO"); + elm_object_part_content_set(popup, "button2", btn2); + evas_object_smart_callback_add(btn2, "clicked", buttonCallback, data); + return popup; +} + +Evas_Object* CertificateSupportUtil::getPopup(Evas_Object* button) +{ + Assert(button); + + Evas_Object* popup = button; + while (strcmp(elm_object_widget_type_get(popup), "elm_popup")) { + popup = elm_object_parent_widget_get(popup); + if (!popup) { + return NULL; + } + } + return popup; +} + +Evas_Object* CertificateSupportUtil::getCheck(Evas_Object* popup) +{ + Assert(popup); + if (strcmp(elm_object_widget_type_get(popup), "elm_popup")) { + return NULL; + } + Evas_Object* check = elm_object_part_content_get( + elm_object_content_get(popup), + "elm.swallow.end"); + return check; +} + +CertificateDB::Result CertificateSupportUtil::getResult( + Evas_Object* button) +{ + using namespace CertificateDB; + + Assert(button); + // get popup evas_object + Evas_Object* popup = getPopup(button); + if (popup == NULL) { + return RESULT_UNKNOWN; + } + bool allow = !strcmp("YES", elm_object_text_get(button)); + + // get check evas_object + Evas_Object* check = getCheck(popup); + if (check == NULL) { + return RESULT_UNKNOWN; + } + if (allow) { + return elm_check_state_get(check) ? RESULT_ALLOW_ALWAYS : + RESULT_ALLOW_ONCE; + } else { + return elm_check_state_get(check) ? RESULT_DENY_ALWAYS : + RESULT_DENY_ONCE; + } +} +} // namespace ViewModule diff --git a/src/view/common/view_logic_certificate_support.h b/src/view/common/view_logic_certificate_support.h new file mode 100755 index 0000000..8216c9b --- /dev/null +++ b/src/view/common/view_logic_certificate_support.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ +/** + * @file view_logic_certificate_origin_support.h + * @author Leerang Song (leerang.song@samsung.com) + * @version 1.0 + * @brief Header file for certificate + */ + +#ifndef VIEW_LOGIC_CERTIFICATE_SUPPORT_H_ +#define VIEW_LOGIC_CERTIFICATE_SUPPORT_H_ + +#include +#include +#include +#include +#include + +class WidgetModel; +namespace CertificateDB { +class CertificateDAO; +} + +namespace ViewModule { +class CertificateSupportImplementation; + +class CertificateSupport +{ + public: + CertificateSupport(WidgetModel* widgetModel); + virtual ~CertificateSupport(); + CertificateDB::CertificateDAO* getCertificateDAO(); + + private: + std::unique_ptr m_impl; +}; + +namespace CertificateSupportUtil { +class PermissionData +{ + public: + CertificateDB::CertificateDAO* m_certiDao; + CertificateDB::CertificateData m_certiData; + void* m_data; + + PermissionData( + CertificateDB::CertificateDAO* certiDao, + CertificateDB::CertificateData certiData, + void* data) : + m_certiDao(certiDao), + m_certiData(certiData), + m_data(data) + {} +}; + +Evas_Object* createPopup(Evas_Object* window, + const char* bodyText, + const char* checkText, + Evas_Smart_Cb buttonCallback, + void* data); +Evas_Object* getPopup(Evas_Object* button); +Evas_Object* getCheck(Evas_Object* popup); +CertificateDB::Result getResult(Evas_Object* button); +}; +} // namespace ViewModule + +#endif // VIEW_LOGIC_CERTIFICATE_SUPPORT_H_ \ No newline at end of file diff --git a/src/view/webkit/CMakeLists.txt b/src/view/webkit/CMakeLists.txt index bfb5047..811c49e 100644 --- a/src/view/webkit/CMakeLists.txt +++ b/src/view/webkit/CMakeLists.txt @@ -50,6 +50,7 @@ SET(VIEW_MODULE_SOURCES ${PROJECT_SOURCE_DIR}/src/view/webkit/view_logic_usermedia_support.cpp ${PROJECT_SOURCE_DIR}/src/view/webkit/view_logic_web_notification_support.cpp ${PROJECT_SOURCE_DIR}/src/view/webkit/bundles/plugin_module_support.cpp + ${PROJECT_SOURCE_DIR}/src/view/webkit/view_logic_certificate_confirm_support.cpp ${VIEW_MODULE_SOURCES} ) diff --git a/src/view/webkit/view_logic.cpp b/src/view/webkit/view_logic.cpp old mode 100644 new mode 100755 index a2f3f4b..e568efc --- a/src/view/webkit/view_logic.cpp +++ b/src/view/webkit/view_logic.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -56,6 +57,8 @@ #include #include #include + +#include #include "bundles/plugin_module_support.h" #include @@ -506,6 +509,7 @@ void ViewLogic::initializeSupport() ViewModule::StorageSupport::initializeStorage(m_model); m_appsSupport->initialize(m_model); m_securityOriginSupport.reset(new ViewModule::SecurityOriginSupport(m_model)); + m_certificateSupport.reset(new ViewModule::CertificateSupport(m_model)); m_vibrationSupport->initialize(); } @@ -1830,26 +1834,10 @@ void ViewLogic::certificateConfirmRequestCallback( Assert(data); ViewLogic* This = static_cast(data); Assert(eventInfo); - Ewk_Certificate_Policy_Decision* certificatePolicyDecision = - static_cast(eventInfo); - - bool status = This->askUserForCertificateConfirm(); - if (!status) { - ewk_certificate_policy_decision_allowed_set( - certificatePolicyDecision, - EINA_FALSE); - } else { - ewk_certificate_policy_decision_allowed_set( - certificatePolicyDecision, - EINA_TRUE); - } -} - -bool ViewLogic::askUserForCertificateConfirm() -{ - return Wrt::Popup::PopupInvoker().askYesNo( - CERTIFICATE_CONFIRM_REQUEST_ASK_TITLE, - CERTIFICATE_CONFIRM_REQUEST_ASK_BODY); + ViewModule::CertificateConfirmSupport::certificatePermissionRequest( + This->m_window, + This->m_certificateSupport->getCertificateDAO(), + eventInfo); } void ViewLogic::authenticationChallengeRequestCallback( diff --git a/src/view/webkit/view_logic.h b/src/view/webkit/view_logic.h old mode 100644 new mode 100755 index bcab546..3a2c289 --- a/src/view/webkit/view_logic.h +++ b/src/view/webkit/view_logic.h @@ -39,6 +39,7 @@ class SchemeSupport; namespace ViewModule { class SecurityOriginSupport; +class CertificateSupport; } class ViewLogic : public ViewModule::IViewModule @@ -278,7 +279,8 @@ class ViewLogic : public ViewModule::IViewModule std::unique_ptr m_appsSupport; std::unique_ptr m_vibrationSupport; std::unique_ptr m_securityOriginSupport; - + std::unique_ptr m_certificateSupport; + static std::map m_ewkCallbacksMap; }; diff --git a/src/view/webkit/view_logic_certificate_confirm_support.cpp b/src/view/webkit/view_logic_certificate_confirm_support.cpp new file mode 100755 index 0000000..34d2d21 --- /dev/null +++ b/src/view/webkit/view_logic_certificate_confirm_support.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ +/** + * @file view_logic_certificate_confirm_support.cpp + * @author Leerang Song (leerang.song@samsung.com) + */ + +#include "view_logic_certificate_confirm_support.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace ViewModule { +namespace CertificateConfirmSupport { +using namespace CertificateDB; +using namespace ViewModule::CertificateSupportUtil; + +namespace { +const char* const CERTIFICATION_ASK_BODY = + "This site's security certificate is not trusted! Do you acess this site?"; +const char* const CERTIFICATION_ASK_CHECK = "Don't ask again"; + +// function declare +void askUserForCertificatePermission( + Evas_Object* window, + PermissionData* data); +static void popupCallback(void* data, Evas_Object* obj, void* eventInfo); + +void askUserForCertificatePermission( + Evas_Object* window, + PermissionData* data) +{ + LogDebug("askUserForCertificatePermission called"); + Evas_Object* popup = createPopup(window, + CERTIFICATION_ASK_BODY, + CERTIFICATION_ASK_CHECK, + popupCallback, + data); + + if (popup == NULL) { + LogError("Fail to create popup object"); + delete data; + return; + } else { + evas_object_show(popup); + } +} + +void popupCallback(void* data, Evas_Object* obj, void* /*eventInfo*/) +{ + LogDebug("popupCallback"); + Assert(data); + PermissionData* permData = static_cast(data); + Ewk_Certificate_Policy_Decision* certificatePolicyDecision = + static_cast(permData->m_data); + + Evas_Object* popup = getPopup(obj); + Result result = getResult(obj); + + if (result != RESULT_UNKNOWN) { + permData->m_certiDao->setCertificateData(permData->m_certiData, + result); + } + Eina_Bool ret = + (result == RESULT_ALLOW_ALWAYS || result == RESULT_ALLOW_ONCE) ? + EINA_TRUE : EINA_FALSE; + + ewk_certificate_policy_decision_allowed_set( + certificatePolicyDecision, + ret); + delete permData; + evas_object_hide(popup); + evas_object_del(popup); +} +} // namespace + +void certificatePermissionRequest( + Evas_Object* window, + CertificateDB::CertificateDAO* certificateDAO, + void* data) +{ + LogDebug("certificationPermissionRequest called"); + Assert(certificateDAO); + Assert(data); + + Ewk_Certificate_Policy_Decision* certificatePolicyDecision = + static_cast(data); + ewk_certificate_policy_decision_suspend(certificatePolicyDecision); + Assert(certificatePolicyDecision); + + CertificateData certificateData( + DPL::FromUTF8String( + ewk_certificate_policy_decision_certificate_pem_get( + certificatePolicyDecision))); + + // check cache database + Result result = certificateDAO->getResult(certificateData); + + if (RESULT_ALLOW_ONCE == result || RESULT_ALLOW_ALWAYS == result) { + LogDebug("allow"); + ewk_certificate_policy_decision_allowed_set( + certificatePolicyDecision, + EINA_TRUE); + return; + } else if (RESULT_DENY_ONCE == result || RESULT_DENY_ALWAYS == result) { + LogDebug("Deny"); + ewk_certificate_policy_decision_allowed_set( + certificatePolicyDecision, + EINA_FALSE); + return; + } + // ask to user + PermissionData* permissionData = + new PermissionData(certificateDAO, + certificateData, + certificatePolicyDecision); + askUserForCertificatePermission(window, permissionData); + return; +} +} +} // namespace ViewModule diff --git a/src/view/webkit/view_logic_certificate_confirm_support.h b/src/view/webkit/view_logic_certificate_confirm_support.h new file mode 100755 index 0000000..8bd42ba --- /dev/null +++ b/src/view/webkit/view_logic_certificate_confirm_support.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ +/** + * @file view_logic_certificate_confirm_support.h + * @author Leerang Song (leerang.song@samsung.com) + */ + +#ifndef VIEW_LOGIC_CERTIFICATE_CONFIRM_SUPPORT_H_ +#define VIEW_LOGIC_CERTIFICATE_CONFIRM_SUPPORT_H_ + +#include +#include + +namespace CertificateDB { +class CertificateDAO; +} + +namespace ViewModule { +namespace CertificateConfirmSupport { +void certificatePermissionRequest( + Evas_Object* window, + CertificateDB::CertificateDAO* certificateDAO, + void* data); +} +} // namespace ViewModule + +#endif