From 062ef0db7c55ed393186fd3829f3da437cca1ca9 Mon Sep 17 00:00:00 2001 From: Jihoon Chung Date: Fri, 23 Nov 2012 13:12:29 +0900 Subject: [PATCH] Support check popup for security origin permission [Issue#] N/A [Problem] Permission for security origin is changed Popup needs check button for "Don't ask again" [Cause] N/A [Solution] Implement check popup for security origin in the security origin support. This popup isn't flexible for using other case. [SCMRequest] N/A Change-Id: I0424a15b30152a49d2a81243c8c308261af45fed --- .../common/view_logic_security_origin_support.cpp | 98 +++++++++ .../common/view_logic_security_origin_support.h | 31 +++ src/view/webkit/view_logic_filesystem_support.cpp | 218 +++------------------ 3 files changed, 159 insertions(+), 188 deletions(-) diff --git a/src/view/common/view_logic_security_origin_support.cpp b/src/view/common/view_logic_security_origin_support.cpp index b37f0c7..dcd1c94 100644 --- a/src/view/common/view_logic_security_origin_support.cpp +++ b/src/view/common/view_logic_security_origin_support.cpp @@ -23,12 +23,17 @@ #include "view_logic_security_origin_support.h" #include +#include +#include #include #include #include #include namespace ViewModule { +namespace { +const char* const DAEMON_EDJ_PATH = "/usr/share/edje/wrt/Daemon.edj"; +} class SecurityOriginSupportImplementation { @@ -80,4 +85,97 @@ SecurityOriginDB::SecurityOriginDAO* SecurityOriginSupport::getSecurityOriginDAO { return m_impl->getSecurityOriginDAO(); } + +Evas_Object* SecurityOriginSupportUtil::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* SecurityOriginSupportUtil::getPopup(Evas_Object* button) +{ + Assert(button); + + Evas_Object* popup = button; + while (strcmp(elm_object_widget_type_get(popup), "popup")) { + popup = elm_object_parent_widget_get(popup); + if (!popup) { + return NULL; + } + } + return popup; +} + +Evas_Object* SecurityOriginSupportUtil::getCheck(Evas_Object* popup) +{ + Assert(popup); + if (strcmp(elm_object_widget_type_get(popup), "popup")) { + return NULL; + } + Evas_Object* check = elm_object_part_content_get( + elm_object_content_get(popup), + "elm.swallow.end"); + return check; +} + +SecurityOriginDB::Result SecurityOriginSupportUtil::getResult(Evas_Object* button) +{ + using namespace SecurityOriginDB; + + 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_security_origin_support.h b/src/view/common/view_logic_security_origin_support.h index 4eab3d7..98ab404 100644 --- a/src/view/common/view_logic_security_origin_support.h +++ b/src/view/common/view_logic_security_origin_support.h @@ -24,6 +24,8 @@ #define VIEW_LOGIC_SECURITY_ORIGIN_SUPPORT_H_ #include +#include +#include #include class WidgetModel; @@ -45,6 +47,35 @@ class SecurityOriginSupport private: std::unique_ptr m_impl; }; + +namespace SecurityOriginSupportUtil { +class PermissionData +{ + public: + SecurityOriginDB::SecurityOriginDAO* m_originDao; + SecurityOriginDB::SecurityOriginData m_originData; + void* m_data; + + PermissionData( + SecurityOriginDB::SecurityOriginDAO* originDao, + SecurityOriginDB::SecurityOriginData originData, + void* data) : + m_originDao(originDao), + m_originData(originData), + 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); +SecurityOriginDB::Result getResult(Evas_Object* button); +}; } // namespace ViewModule diff --git a/src/view/webkit/view_logic_filesystem_support.cpp b/src/view/webkit/view_logic_filesystem_support.cpp index 4be37bb..ee1dc32 100644 --- a/src/view/webkit/view_logic_filesystem_support.cpp +++ b/src/view/webkit/view_logic_filesystem_support.cpp @@ -28,59 +28,25 @@ #include #include #include -#include #include namespace ViewModule { using namespace SecurityOriginDB; - -// class declare -class PermissionData -{ - public: - SecurityOriginDB::SecurityOriginDAO* m_originDao; - SecurityOriginDB::SecurityOriginData m_originData; - void* m_data; - - PermissionData( - SecurityOriginDB::SecurityOriginDAO* originDao, - SecurityOriginDB::SecurityOriginData originData, - void* data) : - m_originDao(originDao), - m_originData(originData), - m_data(data) - { - }; -}; +using namespace ViewModule::SecurityOriginSupportUtil; namespace { -const char* const DAEMON_EDJ_PATH = "/usr/share/edje/wrt/Daemon.edj"; const char* const FILESYSTEM_USE_ASK_TITLE = "Use FileSystem?"; const char* const FILESYSTEM_USE_ASK_BODY_PREFIX = "Do you want to allow "; const char* const FILESYSTEM_USE_ASK_BODY_POSTFIX = " to use persistent filesystem?"; +const char* const FILESYSTEM_USE_ASK_CHECK = "Don't ask again"; // function declare void askUserForFileSystemPermission( Evas_Object* window, - const SecurityOriginData& originData); -Evas_Object* createPopup(Evas_Object* window, - const char* bodyText, - const char* checkText, - Evas_Smart_Cb lButtonCallback, - Evas_Smart_Cb rButtonCallback, - void* data); -static void allowCallback(void* data, Evas_Object* obj, void* eventInfo); -static void denyCallback(void* data, Evas_Object* obj, void* eventInfo); - -Result searchDatabase( - SecurityOriginDAO* dao, - const SecurityOriginData& originData); -void saveResult( - SecurityOriginDAO* dao, - const SecurityOriginData &securityOriginData, - const Result result); + PermissionData* data); +static void popupCallback(void* data, Evas_Object* obj, void* eventInfo); void askUserForFileSystemPermission(Evas_Object* window, PermissionData* data) { @@ -91,169 +57,41 @@ void askUserForFileSystemPermission(Evas_Object* window, PermissionData* data) FILESYSTEM_USE_ASK_BODY_POSTFIX; Evas_Object* popup = createPopup(window, body.c_str(), - "Don't ask again", - allowCallback, - denyCallback, + FILESYSTEM_USE_ASK_CHECK, + popupCallback, data); if (popup == NULL) { - LogError("Fail to find popup object"); + LogError("Fail to create popup object"); delete data; return; + } else { + evas_object_show(popup); } - evas_object_show(popup); -} - -Evas_Object* createPopup(Evas_Object* window, - const char* bodyText, - const char* checkText, - Evas_Smart_Cb lButtonCallback, - Evas_Smart_Cb rButtonCallback, - 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", lButtonCallback, 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", rButtonCallback, data); - return popup; -} - -void allowCallback(void* data, Evas_Object* obj, void* /*eventInfo*/) -{ - LogDebug("allow"); - Assert(data); - PermissionData* permData = static_cast(data); - Ewk_Context_File_System_Permission* fileSystemPermission = - static_cast(permData->m_data); - - // get popup evas_object - Evas_Object* popup = obj; - const char* type = elm_object_widget_type_get(popup); - while (type != NULL && strcmp(type, "popup")) { - popup = elm_object_parent_widget_get(popup); - type = elm_object_widget_type_get(popup); - } - if (type == NULL) { - LogError("Fail to find popup object"); - ewk_context_file_system_permission_allow_set(fileSystemPermission, - EINA_FALSE); - delete permData; - evas_object_del(popup); - return; - } - - // get check evas_object - Evas_Object* check = elm_object_part_content_get( - elm_object_content_get(popup), - "elm.swallow.end"); - if (check == NULL) { - LogError("Fail to find check object"); - ewk_context_file_system_permission_allow_set(fileSystemPermission, - EINA_FALSE); - delete permData; - evas_object_del(popup); - return; - } - - Result result = elm_check_state_get(check) ? RESULT_ALLOW_ALWAYS : RESULT_ALLOW_ONCE; - LogDebug("permit"); - saveResult(permData->m_originDao, permData->m_originData, result); - ewk_context_file_system_permission_allow_set(fileSystemPermission, - EINA_TRUE); - delete permData; - evas_object_del(popup); } -void denyCallback(void* data, Evas_Object* obj, void* /*eventInfo*/) +void popupCallback(void* data, Evas_Object* obj, void* /*eventInfo*/) { - LogDebug("deny"); + LogDebug("popupCallback"); Assert(data); PermissionData* permData = static_cast(data); Ewk_Context_File_System_Permission* fileSystemPermission = static_cast(permData->m_data); - // get popup evas_object - Evas_Object* popup = obj; - const char* type = elm_object_widget_type_get(popup); - while (type != NULL && strcmp(type, "popup")) { - popup = elm_object_parent_widget_get(popup); - type = elm_object_widget_type_get(popup); - } - if (type == NULL) { - LogError("Fail to find popup object"); - ewk_context_file_system_permission_allow_set(fileSystemPermission, - EINA_FALSE); - delete permData; - evas_object_del(popup); - return; - } + Evas_Object* popup = getPopup(obj); + Result result = getResult(obj); - // get check evas_object - Evas_Object* check = elm_object_part_content_get( - elm_object_content_get(popup), - "elm.swallow.end"); - if (check == NULL) { - LogError("Fail to find check object"); - ewk_context_file_system_permission_allow_set(fileSystemPermission, - EINA_FALSE); - delete permData; - evas_object_del(popup); - return; + if (result != RESULT_UNKNOWN) { + permData->m_originDao->setSecurityOriginData(permData->m_originData, result); } - - Result result = elm_check_state_get(check) ? RESULT_DENY_ALWAYS : RESULT_DENY_ONCE; - LogDebug("permit"); - saveResult(permData->m_originDao, permData->m_originData, result); + Eina_Bool ret = + (result == RESULT_ALLOW_ALWAYS || result == RESULT_ALLOW_ONCE) ? + EINA_TRUE : EINA_FALSE; ewk_context_file_system_permission_allow_set(fileSystemPermission, - EINA_FALSE); + ret); delete permData; + evas_object_hide(popup); evas_object_del(popup); } - -Result searchDatabase(SecurityOriginDAO* dao, - const SecurityOriginData& originData) -{ - LogDebug("searchDatabase called"); - return dao->getResult(originData); -} - -void saveResult(SecurityOriginDAO* dao, - const SecurityOriginData &securityOriginData, - const Result result) -{ - LogDebug("searchDatabase called"); - dao->setSecurityOriginData(securityOriginData, result); - return; -} } // namespace void FileSystemSupport::fileSystemPermissionRequest( @@ -273,12 +111,13 @@ void FileSystemSupport::fileSystemPermissionRequest( SecurityOriginData securityOriginData( FEATURE_FILE_SYSTEM_ACCESS, - Origin(DPL::FromUTF8String(ewk_security_origin_protocol_get(ewkOrigin)), - DPL::FromUTF8String(ewk_security_origin_host_get(ewkOrigin)), - ewk_security_origin_port_get(ewkOrigin))); + Origin( + DPL::FromUTF8String(ewk_security_origin_protocol_get(ewkOrigin)), + DPL::FromUTF8String(ewk_security_origin_host_get(ewkOrigin)), + ewk_security_origin_port_get(ewkOrigin))); // check cache database - Result result = searchDatabase(securityOriginDAO, securityOriginData); + Result result = securityOriginDAO->getResult(securityOriginData); if (RESULT_ALLOW_ONCE == result || RESULT_ALLOW_ALWAYS == result) { LogDebug("permit"); ewk_context_file_system_permission_allow_set(fileSystemPermission, @@ -291,8 +130,11 @@ void FileSystemSupport::fileSystemPermissionRequest( return; } - // case of no stored data in the cache database, ask user - PermissionData* permissionData = new PermissionData(securityOriginDAO, securityOriginData, fileSystemPermission); + // ask to user + PermissionData* permissionData = + new PermissionData(securityOriginDAO, + securityOriginData, + fileSystemPermission); askUserForFileSystemPermission(window, permissionData); return; } -- 2.7.4