#include "common/audit/logger.h"
#include "common/exception.h"
#include "ui/common.h"
+
#include "popup.h"
#include <csr-content-screening-types.h>
namespace Csr {
namespace Ui {
-namespace {
-
-std::unordered_map<int, std::function<void()>> g_callbackRegistry;
-
-void evasCbWrapper(void *data, Evas_Object *, void *)
-{
- auto response = reinterpret_cast<int *>(data);
- g_callbackRegistry[*response]();
- g_callbackRegistry.clear();
-}
-
-void registerCb(Evas_Object *button, int *rp, std::function<void()> &&func)
-{
- evas_object_smart_callback_add(button, "clicked", evasCbWrapper, rp);
- g_callbackRegistry[*rp] = std::move(func);
-}
-
-void addButton(int response, int *rp, const std::string &buttonPart,
- const std::string &buttonText, Popup &popup, RawBuffer &result)
-{
- *rp = response;
-
- auto button = popup.addButton(buttonPart);
- elm_object_text_set(button, buttonText.c_str());
-
- registerCb(button, rp, [rp, &result, &popup]() {
- DEBUG("Button for response[" << *rp << "] clicked!");
- result = BinaryQueue::Serialize(rp).pop();
- popup.stop();
- });
-}
-
-} // namespace anonymous
-
-Logic::Logic()
-{
-}
-
-Logic::~Logic()
-{
-}
-
-RawBuffer Logic::csPromptData(const std::string &message,
- const CsDetected &d) const
+RawBuffer Logic::csPromptData(const std::string &message, const CsDetected &d) const
{
- Popup popup;
+ std::string risk(d.severity == CSR_CS_SEVERITY_LOW ? "Low" : "Medium");
+ Popup p(1);
- popup.fillText("Virus detected on data", FORMAT(
- "Malware: " << d.malwareName << "<br>" <<
- "Severity: " << static_cast<int>(d.severity) << "<br>" <<
- "Do you want to stop processing?" <<
- message.c_str()));
+ p.setMessage(message);
+ p.setTitle("Malware detected");
+ p.setHeader("Malware which is harm your phone is detected.");
+ p.setBody(FORMAT(
+ "- Risk : " << risk << " (" << d.malwareName << ")" <<
+ "<br><br>" << "More information"));
+ p.setFooter("Processing is prohibited to protect your phone.");
- RawBuffer result;
+ p.setText(p.m_buttons[0], "OK");
- std::unique_ptr<int[]> resps(new int[2]);
+ p.m_types.emplace_back(
+ static_cast<int>(CSR_CS_USER_RESPONSE_PROCESSING_DISALLOWED));
- addButton(static_cast<int>(CSR_CS_USER_RESPONSE_PROCESSING_ALLOWED), &resps[0], "button1", "yes",
- popup, result);
- addButton(static_cast<int>(CSR_CS_USER_RESPONSE_PROCESSING_DISALLOWED), &resps[1], "button2", "no",
- popup, result);
+ p.callbackRegister(p.m_buttons[0], "clicked", &p.m_types[0]);
- popup.start();
-
- return result;
+ p.run();
+ return p.getResult();
}
RawBuffer Logic::csPromptFile(const std::string &message, const CsDetected &d) const
{
- Popup popup;
-
- popup.fillText("Virus detected", FORMAT(
- "File: " << d.targetName << "<br>" <<
- "Malware: " << d.malwareName << "<br>" <<
- message.c_str()));
-
- RawBuffer result;
-
- std::unique_ptr<int[]> resps(new int[3]);
-
- addButton(static_cast<int>(CSR_CS_USER_RESPONSE_REMOVE), &resps[0], "button1", "remove", popup,
- result);
- addButton(static_cast<int>(CSR_CS_USER_RESPONSE_PROCESSING_ALLOWED), &resps[1], "button2", "allow",
- popup, result);
- addButton(static_cast<int>(CSR_CS_USER_RESPONSE_PROCESSING_DISALLOWED), &resps[2], "button3", "deny",
- popup, result);
-
- popup.start();
-
- return result;
+ std::string risk(d.severity == CSR_CS_SEVERITY_LOW ? "Low" : "Medium");
+
+ Popup p(3);
+
+ p.setMessage(message);
+ p.setTitle("Malware detected");
+ p.setHeader("Malware which is harm your phone is detected.");
+ p.setBody(FORMAT(
+ "- File name : " << d.targetName << "<br>" <<
+ "- Path : " << "path" << "<br>" <<
+ "- Risk : " << risk << " (" << d.malwareName << ")" <<
+ "<br><br>" << "More information"));
+ p.setFooter("Tap Delete to delete infected files and"
+ "protect your phone. If you really want to"
+ "process anyway, tap Ignore.");
+
+ p.setText(p.m_buttons[0], "OK");
+ p.setText(p.m_buttons[1], "Ignore");
+ p.setText(p.m_buttons[2], "Delete");
+
+ p.m_types.emplace_back(
+ static_cast<int>(CSR_CS_USER_RESPONSE_PROCESSING_DISALLOWED));
+ p.m_types.emplace_back(
+ static_cast<int>(CSR_CS_USER_RESPONSE_PROCESSING_ALLOWED));
+ p.m_types.emplace_back(
+ static_cast<int>(CSR_CS_USER_RESPONSE_REMOVE));
+
+ p.callbackRegister(p.m_buttons[0], "clicked", &p.m_types[0]);
+ p.callbackRegister(p.m_buttons[1], "clicked", &p.m_types[1]);
+ p.callbackRegister(p.m_buttons[2], "clicked", &p.m_types[2]);
+
+ p.run();
+ return p.getResult();
}
RawBuffer Logic::csPromptApp(const std::string &message, const CsDetected &d) const
{
- Popup popup;
-
- popup.fillText("Virus detected", FORMAT(
- "App: " << d.targetName << "<br>" <<
- "Malware: " << d.malwareName << "<br>" <<
- message.c_str()));
-
- RawBuffer result;
-
- std::unique_ptr<int[]> resps(new int[3]);
-
- addButton(static_cast<int>(CSR_CS_USER_RESPONSE_REMOVE), &resps[0], "button1", "remove", popup,
- result);
- addButton(static_cast<int>(CSR_CS_USER_RESPONSE_PROCESSING_ALLOWED), &resps[1], "button2", "allow",
- popup, result);
- addButton(static_cast<int>(CSR_CS_USER_RESPONSE_PROCESSING_DISALLOWED), &resps[2], "button3", "deny",
- popup, result);
-
- popup.start();
-
- return result;
+ std::string risk(d.severity == CSR_CS_SEVERITY_LOW ? "Low" : "Medium");
+
+ Popup p(3);
+
+ p.setMessage(message);
+ p.setTitle("Malware detected");
+ p.setHeader("Malware which is harm your phone is detected.");
+ p.setBody(FORMAT(
+ "App name : " << d.targetName << "<br>" <<
+ "Version : " << "1.0" << "<br>" <<
+ "Risk : " << risk << " (" << d.malwareName << ")" <<
+ "<br><br>" << "More information"));
+ p.setFooter("Tap Uninstall to uninstall infected"
+ "application and protect your phone."
+ "If you really want to process anyway, tap Ignore.");
+
+ p.setText(p.m_buttons[0], "OK");
+ p.setText(p.m_buttons[1], "Ignore");
+ p.setText(p.m_buttons[2], "Uninstall");
+
+ p.m_types.emplace_back(
+ static_cast<int>(CSR_CS_USER_RESPONSE_PROCESSING_DISALLOWED));
+ p.m_types.emplace_back(
+ static_cast<int>(CSR_CS_USER_RESPONSE_PROCESSING_ALLOWED));
+ p.m_types.emplace_back(
+ static_cast<int>(CSR_CS_USER_RESPONSE_REMOVE));
+
+ p.callbackRegister(p.m_buttons[0], "clicked", &p.m_types[0]);
+ p.callbackRegister(p.m_buttons[1], "clicked", &p.m_types[1]);
+ p.callbackRegister(p.m_buttons[2], "clicked", &p.m_types[2]);
+
+ p.run();
+ return p.getResult();
}
RawBuffer Logic::csNotifyData(const std::string &message, const CsDetected &d) const
{
- Popup popup;
-
- popup.fillText("Virus detected on data", FORMAT(
- "Malware: " << d.malwareName << "<br>" <<
- "Severity: " << static_cast<int>(d.severity) << "<br>" <<
- "Do you want to stop processing?" <<
- message.c_str()));
+ Popup p(1);
- RawBuffer result;
+ p.setMessage(message);
+ p.setTitle("Malware detected");
+ p.setHeader("Malware which is harm your phone is detected.");
+ p.setBody(FORMAT(
+ "- Risk : " << "High" << " (" << d.malwareName << ")" <<
+ "<br><br>" << "More information"));
+ p.setFooter("Processing is prohibited to protect your phone.");
- std::unique_ptr<int[]> resps(new int[2]);
+ p.setText(p.m_buttons[0], "OK");
- addButton(static_cast<int>(CSR_CS_USER_RESPONSE_PROCESSING_ALLOWED), &resps[0], "button1", "yes",
- popup, result);
- addButton(static_cast<int>(CSR_CS_USER_RESPONSE_PROCESSING_DISALLOWED), &resps[1], "button2", "no",
- popup, result);
+ p.m_types.emplace_back(
+ static_cast<int>(CSR_CS_USER_RESPONSE_PROCESSING_DISALLOWED));
- popup.start();
+ p.callbackRegister(p.m_buttons[0], "clicked", &p.m_types[0]);
- return result;
+ p.run();
+ return p.getResult();
}
RawBuffer Logic::csNotifyFile(const std::string &message, const CsDetected &d) const
{
- Popup popup;
-
- popup.fillText("Virus detected", FORMAT(
- "File: " << d.targetName << "<br>" <<
- "Malware: " << d.malwareName << "<br>" <<
- message.c_str()));
-
- RawBuffer result;
-
- std::unique_ptr<int[]> resps(new int[2]);
-
- addButton(static_cast<int>(CSR_CS_USER_RESPONSE_REMOVE), &resps[0], "button1", "remove", popup,
- result);
- addButton(static_cast<int>(CSR_CS_USER_RESPONSE_PROCESSING_DISALLOWED), &resps[1], "button2", "deny",
- popup, result);
-
- popup.start();
-
- return result;
+ Popup p(2);
+
+ p.setMessage(message);
+ p.setTitle("Malware detected");
+ p.setHeader("Malware which is harm your phone is detected.");
+ p.setBody(FORMAT(
+ "- File name : " << d.targetName << "<br>" <<
+ "- Path : " << "path" << "<br>" <<
+ "- Risk : " << "High" << " (" << d.malwareName << ")" <<
+ "<br><br>" << "More information"));
+ p.setFooter("Tap Delete to delete infected files and"
+ "protect your phone.");
+
+ p.setText(p.m_buttons[0], "OK");
+ p.setText(p.m_buttons[1], "Delete");
+
+ p.m_types.emplace_back(
+ static_cast<int>(CSR_CS_USER_RESPONSE_PROCESSING_DISALLOWED));
+ p.m_types.emplace_back(
+ static_cast<int>(CSR_CS_USER_RESPONSE_REMOVE));
+
+ p.callbackRegister(p.m_buttons[0], "clicked", &p.m_types[0]);
+ p.callbackRegister(p.m_buttons[1], "clicked", &p.m_types[1]);
+
+ p.run();
+ return p.getResult();
}
RawBuffer Logic::csNotifyApp(const std::string &message, const CsDetected &d) const
{
- Popup popup;
-
- popup.fillText("Virus detected", FORMAT(
- "App: " << d.targetName << "<br>" <<
- "Malware: " << d.malwareName << "<br>" <<
- message.c_str()));
-
- RawBuffer result;
-
- std::unique_ptr<int[]> resps(new int[2]);
-
- addButton(static_cast<int>(CSR_CS_USER_RESPONSE_REMOVE), &resps[0], "button1", "remove", popup,
- result);
- addButton(static_cast<int>(CSR_CS_USER_RESPONSE_PROCESSING_DISALLOWED), &resps[1], "button2", "deny",
- popup, result);
-
- popup.start();
-
- return result;
+ Popup p(2);
+
+ p.setMessage(message);
+ p.setTitle("Malware detected");
+ p.setHeader("Malware which is harm your phone is detected.");
+ p.setBody(FORMAT(
+ "App name : " << d.targetName << "<br>" <<
+ "Version : " << "1.0" << "<br>" <<
+ "Risk : " << "High" << " (" << d.malwareName << ")" <<
+ "<br><br>" << "More information"));
+ p.setFooter("Tap Uninstall to uninstall infected"
+ "application and protect your phone.");
+
+ p.setText(p.m_buttons[0], "OK");
+ p.setText(p.m_buttons[1], "Uninstall");
+
+ p.m_types.emplace_back(
+ static_cast<int>(CSR_CS_USER_RESPONSE_PROCESSING_DISALLOWED));
+ p.m_types.emplace_back(
+ static_cast<int>(CSR_CS_USER_RESPONSE_PROCESSING_ALLOWED));
+
+ p.callbackRegister(p.m_buttons[0], "clicked", &p.m_types[0]);
+ p.callbackRegister(p.m_buttons[1], "clicked", &p.m_types[1]);
+
+ p.run();
+ return p.getResult();
}
RawBuffer Logic::wpPrompt(const std::string &message, const UrlItem &item) const
{
- Popup popup;
+ std::string risk(item.risk == CSR_WP_RISK_LOW ? "Low" : "Medium");
- popup.fillText("Danger URL", FORMAT(
- "URL: " << item.url << "<br>" <<
- "Risky: " << (item.risk == CSR_WP_RISK_HIGH
- ? "High" : "Medium") << "<br>" <<
- message.c_str()));
+ Popup p(1);
- RawBuffer result;
+ p.setMessage(message);
+ p.setTitle("Block malicious URL");
+ p.setHeader("This website may harm your phone.");
+ p.setBody(FORMAT(
+ "- URL : " << item.url << "<br>" <<
+ "- Risk : " << risk << "<br><br>" <<
+ "More information"));
+ p.setFooter("Accessing to this URL is prohibited to protect your phone.");
- std::unique_ptr<int[]> resps(new int[2]);
+ p.setText(p.m_buttons[0], "OK");
- addButton(static_cast<int>(CSR_WP_USER_RESPONSE_PROCESSING_ALLOWED), &resps[0], "button1", "allow",
- popup, result);
- addButton(static_cast<int>(CSR_WP_USER_RESPONSE_PROCESSING_DISALLOWED), &resps[1], "button2", "deny",
- popup, result);
+ p.m_types.emplace_back(static_cast<int>(CSR_WP_USER_RESPONSE_PROCESSING_DISALLOWED));
- popup.start();
+ p.callbackRegister(p.m_buttons[0], "clicked", &p.m_types[0]);
- return result;
+ p.run();
+ return p.getResult();
}
RawBuffer Logic::wpNotify(const std::string &message, const UrlItem &item) const
{
- Popup popup;
-
- popup.fillText("Danger URL", FORMAT(
- "URL: " << item.url << "<br>" <<
- "Risky: " << (item.risk == CSR_WP_RISK_HIGH
- ? "High" : "Medium") << "<br>" <<
- message.c_str()));
-
- RawBuffer result;
-
- std::unique_ptr<int> resp(new int);
-
- addButton(static_cast<int>(CSR_WP_USER_RESPONSE_PROCESSING_DISALLOWED), resp.get(), "button1",
- "confirm", popup, result);
-
- popup.start();
-
- return result;
-}
-
-}
+ Popup p(2);
+
+ p.setMessage(message);
+ p.setTitle("Block malicious URL");
+ p.setHeader("This website may harm your phone.");
+ p.setBody(FORMAT(
+ "- URL : " << item.url << "<br>" <<
+ "- Risk : " << "High" << "<br><br>" <<
+ "More information"));
+ p.setFooter("If you really want to process anyway, tap View");
+
+ p.setText(p.m_buttons[0], "OK");
+ p.setText(p.m_buttons[1], "View");
+
+ p.m_types.emplace_back(
+ static_cast<int>(CSR_WP_USER_RESPONSE_PROCESSING_DISALLOWED));
+ p.m_types.emplace_back(
+ static_cast<int>(CSR_WP_USER_RESPONSE_PROCESSING_ALLOWED));
+
+ p.callbackRegister(p.m_buttons[0], "clicked", &p.m_types[0]);
+ p.callbackRegister(p.m_buttons[1], "clicked", &p.m_types[1]);
+
+ p.run();
+ return p.getResult();
}
+} // namespace Ui
+} // namespace Csr
/*
* @file popup.cpp
* @author Kyungwook Tak (k.tak@samsung.com)
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
* @version 1.0
* @brief
*/
#include "popup.h"
-#include <stdexcept>
-
-#include "common/audit/logger.h"
-
namespace Csr {
namespace Ui {
-Popup::Popup()
+Popup::Popup(int buttonN)
{
- Evas_Object *win = elm_win_add(nullptr, "CSR popup", ELM_WIN_NOTIFICATION);
- elm_win_indicator_opacity_set(win, ELM_WIN_INDICATOR_TRANSLUCENT);
- elm_win_borderless_set(win, EINA_TRUE);
- elm_win_alpha_set(win, EINA_TRUE);
-
- Evas_Object *popup = elm_popup_add(win);
- evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-
- m_win = win;
- m_popup = popup;
+ m_win = elm_win_add(nullptr, "CSR popup", ELM_WIN_NOTIFICATION);
+ elm_win_indicator_opacity_set(m_win, ELM_WIN_INDICATOR_TRANSLUCENT);
+ elm_win_borderless_set(m_win, EINA_TRUE);
+ elm_win_alpha_set(m_win, EINA_TRUE);
+
+ m_popup = elm_popup_add(m_win);
+ evas_object_size_hint_weight_set(m_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ for(int i=1 ; i <= buttonN; i++) {
+ std::string id("button" + std::to_string(i));
+ Evas_Object *button = elm_button_add(m_popup);
+ elm_object_style_set(button, "bottom");
+ elm_object_part_content_set(m_popup, id.c_str(), button);
+ elm_object_text_set(button, "default");
+
+ m_buttons.emplace_back(button);
+ }
}
Popup::~Popup()
{
+ for (auto &obj : m_objects)
+ evas_object_del(obj);
}
-void Popup::stop()
+void Popup::setHeader(const std::string &header) noexcept
{
- if (m_popup)
- evas_object_del(m_popup);
+ m_header = header;
+}
- if (m_win)
- evas_object_del(m_win);
+void Popup::setBody(const std::string &body) noexcept
+{
+ m_body = body;
+}
- elm_exit();
+void Popup::setFooter(const std::string &footer) noexcept
+{
+ m_footer = footer;
+}
+
+void Popup::setMessage(const std::string &msg) noexcept
+{
+ m_message = msg;
}
-void Popup::start()
+void Popup::run(void)
{
- evas_object_show(m_win);
- evas_object_show(m_popup);
+ setText(m_popup, (m_header + "<br>" +
+ m_body + "<br><br>" + m_footer).c_str());
+
+ m_objects.emplace_back(m_popup);
+ m_objects.emplace_back(m_win);
- DEBUG("Popup UI event loop start!");
+ for (auto &obj : m_objects)
+ evas_object_show(obj);
elm_run();
}
-void Popup::fillText(const std::string &title, const std::string &content)
+int Popup::response = -1;
+
+RawBuffer Popup::getResult(void)
{
- elm_object_part_text_set(m_popup, "title,text", title.c_str());
- elm_object_text_set(m_popup, content.c_str());
+ return BinaryQueue::Serialize(response).pop();
}
-Evas_Object *Popup::addButton(const std::string &part)
+void Popup::setTitle(const std::string &title) noexcept
{
- Evas_Object *button = elm_button_add(m_popup);
- elm_object_style_set(button, "bottom");
- elm_object_part_content_set(m_popup, part.c_str(), button);
- evas_object_show(button);
+ elm_object_part_text_set(m_popup, "title,text", title.c_str());
+}
- return button;
+void Popup::setText(Evas_Object *obj, const std::string &text) noexcept
+{
+ elm_object_text_set(obj, text.c_str());
}
+void Popup::callbackRegister(Evas_Object *obj, const char *event, int *type)
+{
+ evas_object_smart_callback_add(obj, event, btnClickedCb, type);
}
+
+void Popup::btnClickedCb(void *data, Evas_Object *, void *)
+{
+ response = *(reinterpret_cast<int *>(data));
+ elm_exit();
}
+} // namespace Ui
+} // namespace Csr