Fix Popup related crash issue
authorSeungkeun Lee <sngn.lee@samsung.com>
Fri, 28 Aug 2015 06:23:40 +0000 (15:23 +0900)
committerSeungkeun Lee <sngn.lee@samsung.com>
Mon, 31 Aug 2015 03:33:21 +0000 (20:33 -0700)
 - If popup was not closed when WebView was deleted, it will cause crash
 - When ClearViewStack, all opened popup was force closing

Change-Id: I4affe379c2f39160908c19c6efdbbdb3caa43ce5

src/runtime/popup.cc
src/runtime/popup.h
src/runtime/web_application.cc

index f3bdd5c508bb213fa6c5bc5dd72ff186f0f33423..a15e9fd8ba2818edf013fa5b1fa1c906bceccbed 100755 (executable)
@@ -134,6 +134,9 @@ static Evas_Object* AddCheckBox(Evas_Object* parent) {
 
 }  // namespace
 
+// static variable initialize
+std::set<Popup*> Popup::opened_popups_;
+
 Popup* Popup::CreatePopup(NativeWindow* window) {
   Evas_Object* popup = elm_popup_add(window->evas_object());
   elm_object_style_set(popup, kStyleDefault);
@@ -156,6 +159,15 @@ Popup* Popup::CreatePopup(NativeWindow* window) {
   return new Popup(popup, grid, box);
 }
 
+void Popup::ForceCloseAllPopup() {
+  auto backup = opened_popups_;
+  for (auto& popup : backup) {
+    // will cause modification of opened_popups_
+    popup->Hide();
+  }
+}
+
+
 void Popup::SetButtonType(ButtonType type) {
   enable_button_ = true;
   switch (type) {
@@ -260,6 +272,7 @@ void Popup::SetResultHandler(std::function<void
 
 void Popup::Show() {
   evas_object_show(popup_);
+  opened_popups_.insert(this);
 }
 
 void Popup::Hide() {
@@ -269,6 +282,10 @@ void Popup::Hide() {
       delete obj;
       return EINA_FALSE;
     }, this);
+  auto found = opened_popups_.find(this);
+  if (found != opened_popups_.end()) {
+    opened_popups_.erase(found);
+  }
 }
 
 void Popup::Result(bool is_positive) {
index d2c253c160fb28594dddb749caac9787f6019b84..368d2e646df33a3382830e79504fa137f52080cf 100755 (executable)
@@ -24,6 +24,7 @@
 #include <string>
 #include <vector>
 #include <functional>
+#include <set>
 
 namespace wrt {
 
@@ -44,6 +45,7 @@ class Popup {
   };
 
   static Popup* CreatePopup(NativeWindow* window);
+  static void ForceCloseAllPopup();
 
   // button
   void SetButtonType(ButtonType type);
@@ -96,6 +98,7 @@ class Popup {
   std::string result_entry2_;
   bool enable_check_box_;
   bool result_check_box_;
+  static std::set<Popup*> opened_popups_;
 };
 
 }  // namespace wrt
index 5303dbfb9518c78ebc6c16026252e1e37b121ff9..5334c95b4f6119d0a0f587d7c4326022fea1d3de 100755 (executable)
@@ -461,6 +461,7 @@ void WebApplication::SendAppControlEvent() {
 
 void WebApplication::ClearViewStack() {
   window_->SetContent(NULL);
+  Popup::ForceCloseAllPopup();
   auto it = view_stack_.begin();
   for ( ; it != view_stack_.end(); ++it) {
     (*it)->Suspend();