From 36283f083ca4b9a8a6f4391e3bc67cca1c8ffdc5 Mon Sep 17 00:00:00 2001 From: "ayush.k123" Date: Fri, 27 Jan 2023 10:46:44 +0530 Subject: [PATCH] [M108 Migration][NativeControl] Refactor Permission Popup. This patch includes below changes: - Refactor Permission_popup. - Fix SetPopupTitle() hardcoding. - Permission popup is closed, When request is cancelled. - NULL checking while DeletePermissionRequest. Reference: https://review.tizen.org/gerrit/c/277643/ Change-Id: I87080ac0061bb9bdf42c8db6a09db6a51b2a6596 Signed-off-by: Ayush Kumar --- tizen_src/ewk/efl_integration/eweb_view.cc | 3 +- tizen_src/ewk/efl_integration/permission_popup.h | 9 +- .../efl_integration/permission_popup_manager.cc | 306 ++++++++------------- .../ewk/efl_integration/permission_popup_manager.h | 59 ++-- 4 files changed, 160 insertions(+), 217 deletions(-) mode change 100755 => 100644 tizen_src/ewk/efl_integration/permission_popup_manager.cc diff --git a/tizen_src/ewk/efl_integration/eweb_view.cc b/tizen_src/ewk/efl_integration/eweb_view.cc index ead962c..e28f0fe 100644 --- a/tizen_src/ewk/efl_integration/eweb_view.cc +++ b/tizen_src/ewk/efl_integration/eweb_view.cc @@ -1,4 +1,4 @@ -// Copyright 2014 Samsung Electronics. All rights reserved. +// Copyright 2014-2020 Samsung Electronics. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -289,7 +289,6 @@ EWebView::~EWebView() { old_context_ = nullptr; } - GetPermissionPopupManager()->DeleteAllPermissionRequest(); permission_popup_manager_.reset(); if (context_->GetImpl()->browser_context()->IsOffTheRecord()) diff --git a/tizen_src/ewk/efl_integration/permission_popup.h b/tizen_src/ewk/efl_integration/permission_popup.h index 32f07a0..a1b000b 100644 --- a/tizen_src/ewk/efl_integration/permission_popup.h +++ b/tizen_src/ewk/efl_integration/permission_popup.h @@ -1,4 +1,4 @@ -// Copyright 2015 Samsung Electronics. All rights reserved. +// Copyright 2015-2020 Samsung Electronics. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -19,12 +19,13 @@ class PermissionPopup { popup_message_ = message; } + PermissionPopup(const PermissionPopup&) = delete; + PermissionPopup& operator=(const PermissionPopup&) = delete; + virtual ~PermissionPopup() { } std::string GetMessage() const { return popup_message_; } - std::string GetOriginHost() const { - return std::string(ewk_security_origin_host_get(origin_)); - } + std::string GetOrigin() const { return origin_->GetURL().spec(); } virtual void SendDecidedPermission(Evas_Object*, bool decide) = 0; private: diff --git a/tizen_src/ewk/efl_integration/permission_popup_manager.cc b/tizen_src/ewk/efl_integration/permission_popup_manager.cc old mode 100755 new mode 100644 index 190f40b..2535b57 --- a/tizen_src/ewk/efl_integration/permission_popup_manager.cc +++ b/tizen_src/ewk/efl_integration/permission_popup_manager.cc @@ -1,254 +1,188 @@ -// Copyright 2015 Samsung Electronics. All rights reserved. +// Copyright 2015-2020 Samsung Electronics. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "permission_popup_manager.h" + #if BUILDFLAG(IS_TIZEN) #include #endif -#include -#include #include "base/strings/utf_string_conversions.h" -#include "eweb_view.h" #include "permission_popup.h" -#include "permission_popup_manager.h" -PermissionPopupManager::PermissionPopupManager(Evas_Object* eweb_view) - : is_decided_(false) - , permission_popups_(0) - , eweb_view_(eweb_view) - , popup_(0) - , widget_win_(0) - , top_widget_(0) { -} +PermissionPopupManager::PermissionPopupManager(Evas_Object* evas_object) + : evas_object_(evas_object) {} PermissionPopupManager::~PermissionPopupManager() { - ClosePopup(); - DeleteAllPermissionRequest(); + CancelPermissionRequest(); } -void PermissionPopupManager::AddPermissionRequest(PermissionPopup* popup) { - permission_popups_ = eina_list_append(permission_popups_, popup); +void PermissionPopupManager::AddPermissionRequest( + PermissionPopup* permission_popup) { + permission_popups_ = eina_list_append(permission_popups_, permission_popup); ShowPermissionPopup(static_cast( eina_list_data_get(permission_popups_))); } -void PermissionPopupManager::DeletePermissionRequest(PermissionPopup* popup) { - permission_popups_ = eina_list_remove(permission_popups_, popup); - delete popup; +void PermissionPopupManager::CancelPermissionRequest() { + DeletePopup(); + DeleteAllPermissionRequests(); +} - if (eina_list_count(permission_popups_) == 0) +void PermissionPopupManager::DeleteAllPermissionRequests() { + if (!permission_popups_) return; - ShowPermissionPopup(static_cast( - eina_list_data_get(permission_popups_))); + void* data; + EINA_LIST_FREE(permission_popups_, data) { + auto permission_popup = static_cast(data); + permission_popup->SendDecidedPermission(evas_object_, false); + delete permission_popup; + } } -void PermissionPopupManager::DeleteAllPermissionRequest() { - void* data; - EINA_LIST_FREE(permission_popups_, data) - delete static_cast(data); +void PermissionPopupManager::DeletePermissionRequest( + PermissionPopup* permission_popup) { + permission_popups_ = eina_list_remove(permission_popups_, permission_popup); + delete permission_popup; } -Evas_Object* PermissionPopupManager::CreatePopup() { - top_widget_ = elm_object_top_widget_get(elm_object_parent_widget_get(eweb_view_)); - if (!top_widget_) - return 0; +void PermissionPopupManager::ShowPermissionPopup( + PermissionPopup* permission_popup) { + if (popup_ || !CreatePopup()) + return; + if (!SetupPopup(permission_popup)) { + DeletePopup(); + return; + } - widget_win_ = elm_win_add(top_widget_, "WebKit Permission Popup", ELM_WIN_BASIC); - if (!widget_win_) - return 0; + evas_object_show(popup_); +} - elm_win_alpha_set(widget_win_, EINA_TRUE); -#if !defined(WAYLAND_BRINGUP) - ecore_x_icccm_name_class_set(elm_win_xwindow_get(widget_win_), - "APP_POPUP", "APP_POPUP"); -#endif +void PermissionPopupManager::Decide(bool decision) { + DeletePopup(); - if (elm_win_wm_rotation_supported_get(top_widget_)) { - int preferredRotation = - elm_win_wm_rotation_preferred_rotation_get(top_widget_); - if (preferredRotation == -1) { - int rots[4] = {0, 90, 180, 270}; - elm_win_wm_rotation_available_rotations_set(widget_win_, rots, 4); - } - else { - elm_win_wm_rotation_available_rotations_set(widget_win_, - &preferredRotation, 1); - } - } + auto permission_popup = + static_cast(eina_list_data_get(permission_popups_)); + permission_popup->SendDecidedPermission(evas_object_, decision); + DeletePermissionRequest(permission_popup); + permission_popup = + static_cast(eina_list_data_get(permission_popups_)); + if (permission_popup) + ShowPermissionPopup(permission_popup); +} - Eina_Rectangle windowRect; - Ecore_Evas* ee = ecore_evas_ecore_evas_get( - evas_object_evas_get(eweb_view_)); - ecore_evas_geometry_get(ee, &windowRect.x, &windowRect.y, - &windowRect.w, &windowRect.h); - evas_object_resize(widget_win_, windowRect.w, windowRect.h); +void PermissionPopupManager::PermissionOkCallback(void* data, + Evas_Object* obj, + void* event_info) { + PermissionPopupManager* manager = static_cast(data); + manager->Decide(true); +} + +void PermissionPopupManager::PermissionCancelCallback(void* data, + Evas_Object* obj, + void* event_info) { + PermissionPopupManager* manager = static_cast(data); + manager->Decide(false); +} - Evas_Object* conformant = elm_conformant_add(widget_win_); +bool PermissionPopupManager::CreatePopup() { + top_widget_ = + elm_object_top_widget_get(elm_object_parent_widget_get(evas_object_)); + if (!top_widget_) + return false; + + Evas_Object* conformant = elm_conformant_add(top_widget_); if (!conformant) - return 0; + return false; - evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - elm_win_resize_object_add(widget_win_, conformant); + evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, + EVAS_HINT_EXPAND); + elm_win_resize_object_add(top_widget_, conformant); evas_object_show(conformant); Evas_Object* layout = elm_layout_add(conformant); if (!layout) - return 0; + return false; elm_layout_theme_set(layout, "layout", "application", "default"); evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_show(layout); elm_object_content_set(conformant, layout); - elm_win_conformant_set(widget_win_, EINA_TRUE); - - evas_object_show(widget_win_); - - Evas_Object* popup = elm_popup_add(layout); - elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0); - - return popup; -} - -static void permissionPopupFocusInCallback( - void* data, Evas_Object* obj, void* event_info) { - evas_object_smart_callback_del(obj, "focus,in", permissionPopupFocusInCallback); - - PermissionPopupManager* manager = static_cast(data); - if (!manager) - return; - manager->ClosePopup(); - - PermissionPopup* popup = manager->GetPermissionPopup(); - if (!popup) - return; - popup->SendDecidedPermission(manager->GetEwebView(), manager->IsDecided()); - manager->DeletePermissionRequest(popup); + popup_ = elm_popup_add(layout); + return !!popup_; } -static void permissionOkCallback(void* data, Evas_Object* obj, void* event_info) { - PermissionPopupManager* manager = static_cast(data); - if (!manager) +void PermissionPopupManager::DeletePopup() { + if (!popup_) return; - - evas_object_smart_callback_add(manager->GetTopWidget(), - "focus,in", permissionPopupFocusInCallback, data); - manager->HidePopup(); - manager->Decide(true); + evas_object_del(popup_); + popup_ = nullptr; } -static void permissionCancelCallback( - void* data, Evas_Object* obj, void* event_info) { - PermissionPopupManager* manager = static_cast(data); - if (!manager) - return; +bool PermissionPopupManager::SetupPopup(PermissionPopup* permission_popup) { + elm_popup_align_set(popup_, ELM_NOTIFY_ALIGN_FILL, 1.0); - evas_object_smart_callback_add(manager->GetTopWidget(), "focus,in", - permissionPopupFocusInCallback, data); - manager->HidePopup(); - manager->Decide(false); -} + if (!SetPopupText(permission_popup->GetMessage()) || + !SetPopupTitle(permission_popup->GetOrigin())) { + return false; + } #if BUILDFLAG(IS_TIZEN) -static void permissionHwBackKeyCallback( - void* data, Evas_Object* obj, void* event_info) { - PermissionPopupManager* manager = static_cast(data); - if (!manager) - return; - - evas_object_smart_callback_add(manager->GetTopWidget(), - "focus,in", permissionPopupFocusInCallback, data); - manager->HidePopup(); -} + eext_object_event_callback_add( + popup_, EEXT_CALLBACK_BACK, + &PermissionPopupManager::PermissionCancelCallback, this); #endif -void PermissionPopupManager::ShowPermissionPopup(PermissionPopup* popup) { - if (popup_) - return; - - popup_ = CreatePopup(); - - if (!popup_) - return; - - if (!SetLabelText(popup->GetMessage())) - return; + AddButtonToPopup("button1", "IDS_WEBVIEW_BUTTON_CANCEL_ABB4", + &PermissionPopupManager::PermissionCancelCallback, false); + AddButtonToPopup("button2", "IDS_WEBVIEW_BUTTON_OK_ABB4", + &PermissionPopupManager::PermissionOkCallback, true); -#if BUILDFLAG(IS_TIZEN) - eext_object_event_callback_add(popup_, EEXT_CALLBACK_BACK, - permissionHwBackKeyCallback, this); -#endif - - Evas_Object* cancelButton = elm_button_add(popup_); - elm_object_style_set(cancelButton, "popup"); - elm_object_domain_translatable_part_text_set( - cancelButton, NULL, "WebKit", "Cancel"); - elm_object_part_content_set(popup_, "button1", cancelButton); - evas_object_smart_callback_add(cancelButton, "clicked", - permissionCancelCallback, this); - - Evas_Object* okButton = elm_button_add(popup_); - elm_object_style_set(okButton, "popup"); - elm_object_domain_translatable_part_text_set(okButton, NULL, "WebKit", "OK"); - elm_object_part_content_set(popup_, "button2", okButton); - evas_object_focus_set(okButton, true); - evas_object_smart_callback_add(okButton, "clicked", permissionOkCallback, this); - - elm_object_part_text_set(popup_, "title,text", GetTitle(popup).c_str()); - evas_object_show(popup_); + return true; } -std::string PermissionPopupManager::GetTitle(PermissionPopup* popup) { - std::string url = std::string(ewk_view_url_get(eweb_view_)); - - if (url.empty()) - url = std::string(ewk_view_title_get(eweb_view_)); +bool PermissionPopupManager::SetPopupTitle(const std::string& origin) { + // Empty origin is improper one. + if (origin.empty()) + return false; + std::string title = + dgettext("WebKit", "IDS_WEBVIEW_HEADER_MESSAGE_FROM_PS_M_WEBSITE"); - std::string popupTitle = std::string(dgettext( - "WebKit","IDS_WEBVIEW_HEADER_MESSAGE_FROM_PS_M_WEBSITE")); - std::string replaceStr = std::string("%s"); - size_t pos = popupTitle.find(replaceStr.c_str()); + const std::string replaceStr("%s"); + size_t pos = title.find(replaceStr); if (pos != std::string::npos) - popupTitle.replace(pos, replaceStr.length(), url.c_str()); - - return popupTitle; + title.replace(pos, replaceStr.length(), origin); + else + LOG(ERROR) << "Translation issue. " << title << " not found"; + elm_object_part_text_set(popup_, "title,text", title.c_str()); + return true; } -bool PermissionPopupManager::SetLabelText(const std::string& message) { +bool PermissionPopupManager::SetPopupText(const std::string& message) { if (message.empty()) return false; - - std::string labal_text = message; + std::string text = message; std::string replaceStr = std::string("\n"); - size_t pos = labal_text.find(replaceStr.c_str()); + size_t pos = text.find(replaceStr.c_str()); if (pos != std::string::npos) - labal_text.replace(pos, replaceStr.length(), "
"); - - elm_object_text_set(popup_, labal_text.c_str()); - + text.replace(pos, replaceStr.length(), "
"); + elm_object_text_set(popup_, text.c_str()); return true; } -void PermissionPopupManager::ClosePopup() { - if (!widget_win_) - return; - - evas_object_del(widget_win_); - popup_ = 0; - widget_win_ = 0; -} - -void PermissionPopupManager::HidePopup() { - if (popup_) - evas_object_hide(popup_); - - if (widget_win_) - evas_object_hide(widget_win_); -} - -PermissionPopup* PermissionPopupManager::GetPermissionPopup() { - return static_cast(eina_list_data_get(permission_popups_)); +void PermissionPopupManager::AddButtonToPopup(const char* name, + const char* text, + Evas_Smart_Cb callback, + bool focus) { + Evas_Object* button = elm_button_add(popup_); + elm_object_style_set(button, "popup"); + elm_object_domain_translatable_part_text_set(button, NULL, "WebKit", text); + elm_object_part_content_set(popup_, name, button); + evas_object_smart_callback_add(button, "clicked", callback, this); + if (focus) + evas_object_focus_set(button, true); } diff --git a/tizen_src/ewk/efl_integration/permission_popup_manager.h b/tizen_src/ewk/efl_integration/permission_popup_manager.h index 09fc2f5..83f9398 100644 --- a/tizen_src/ewk/efl_integration/permission_popup_manager.h +++ b/tizen_src/ewk/efl_integration/permission_popup_manager.h @@ -1,4 +1,4 @@ -// Copyright 2015 Samsung Electronics. All rights reserved. +// Copyright 2015-2020 Samsung Electronics. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,38 +6,47 @@ #define PermissionPopupManager_h #include -#include +#include -#include "permission_popup.h" +class PermissionPopup; class PermissionPopupManager { public: - PermissionPopupManager(Evas_Object* ); + PermissionPopupManager(Evas_Object* evas_object); ~PermissionPopupManager(); - bool IsDecided() const { return is_decided_; } - Evas_Object* GetEwebView() const { return eweb_view_; } - Evas_Object* GetTopWidget() const { return top_widget_; } - PermissionPopup* GetPermissionPopup(); - void AddPermissionRequest(PermissionPopup*); - void ClosePopup(); - void DeletePermissionRequest(PermissionPopup*); - void DeleteAllPermissionRequest(); - void HidePopup(); - void Decide(bool decided) { is_decided_ = decided; } + PermissionPopupManager(const PermissionPopupManager&) = delete; + PermissionPopupManager& operator=(const PermissionPopupManager&) = delete; + + void AddPermissionRequest(PermissionPopup* permission_popup); + void CancelPermissionRequest(); private: - bool SetLabelText(const std::string& message); - Evas_Object* CreatePopup(); - std::string GetTitle(PermissionPopup* popup); - void ShowPermissionPopup(PermissionPopup*); - - bool is_decided_; - Eina_List* permission_popups_; - Evas_Object* eweb_view_; - Evas_Object* popup_; - Evas_Object* widget_win_; - Evas_Object* top_widget_; + bool CreatePopup(); + bool SetupPopup(PermissionPopup* permission_popup); + void DeletePopup(); + bool SetPopupText(const std::string& message); + bool SetPopupTitle(const std::string& host); + void AddButtonToPopup(const char* name, + const char* text, + Evas_Smart_Cb callback, + bool focus); + void DeleteAllPermissionRequests(); + void DeletePermissionRequest(PermissionPopup* permission_popup); + void ShowPermissionPopup(PermissionPopup* permission_popup); + void Decide(bool decision); + + static void PermissionOkCallback(void* data, + Evas_Object* obj, + void* event_info); + static void PermissionCancelCallback(void* data, + Evas_Object* obj, + void* event_info); + + Eina_List* permission_popups_ = nullptr; + Evas_Object* popup_ = nullptr; + Evas_Object* top_widget_ = nullptr; + Evas_Object* evas_object_; }; #endif // PermissionPopupManager_h -- 2.7.4