Defer main loop until window is completely closed 26/107126/9
authorYoungsoo Choi <kenshin.choi@samsung.com>
Mon, 26 Dec 2016 15:23:50 +0000 (00:23 +0900)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 27 Dec 2016 13:40:04 +0000 (05:40 -0800)
When uninstalling a webapp is performed while running the webapp,
there's no enough time for termination of render thread by |OnTerminate|.
In that case, the life-cycle of main loop needs to be guaranteed
until closing window callback is called.

So, this CL defers main loop until window is completely closed
and removes previously implemented timer for the termination.

Bug: TSAM-12072
Url: http://suprem.sec.samsung.net/jira/browse/TSAM-12072

Change-Id: I095d522f70d1c1759d07f697a179986fea7ebab5
Signed-off-by: Youngsoo Choi <kenshin.choi@samsung.com>
runtime/browser/ime_runtime.cc
runtime/browser/runtime.cc [changed mode: 0755->0644]
runtime/browser/runtime.h [changed mode: 0644->0755]
runtime/browser/runtime_process.cc
runtime/browser/ui_runtime.cc
runtime/browser/watch_runtime.cc
runtime/browser/watch_runtime.h
runtime/browser/web_application.cc

index 9cdc3db157c4c81b7be00e3f2c08575a1f026aff..0527c838744b0b34cc37008831baf00936e9daf8 100644 (file)
@@ -164,6 +164,7 @@ void ImeRuntime::OnCreate() {
 
 void ImeRuntime::OnTerminate() {
   LOGGER(DEBUG) << "ime_app_terminate";
+  ClosePageFromOnTerminate(application_);
 }
 
 void ImeRuntime::OnShow(int context_id, ime_context_h context) {
old mode 100755 (executable)
new mode 100644 (file)
index 051ffe0..a2e0c03
@@ -32,6 +32,8 @@
 
 namespace runtime {
 
+bool Runtime::is_on_terminate_called = false;
+
 Runtime::~Runtime() {
 }
 
@@ -55,5 +57,18 @@ std::unique_ptr<Runtime> Runtime::MakeRuntime(
   }
 }
 
+void Runtime::ClosePageFromOnTerminate(WebApplication* app) {
+  if (app) {
+    std::list<WebView*> vstack = app->view_stack();
+    auto it = vstack.begin();
+    if (it != vstack.end()) {
+      Runtime::is_on_terminate_called = true;
+      for (; it != vstack.end(); ++it) {
+        vstack.front()->SetVisibility(false);
+        ewk_view_page_close((*it)->evas_object());
+      }
+    }
+  }
+}
 
 }  // namespace runtime
old mode 100644 (file)
new mode 100755 (executable)
index db4ef00..b4f1029
@@ -22,6 +22,7 @@
 #include <string>
 
 #include "common/application_data.h"
+#include "runtime/browser/web_application.h"
 
 namespace runtime {
 
@@ -31,8 +32,12 @@ class Runtime {
 
   virtual int Exec(int argc, char* argv[]) = 0;
 
+  static bool is_on_terminate_called;
   static std::unique_ptr<Runtime> MakeRuntime(
     common::ApplicationData* app_data);
+
+ protected:
+  void ClosePageFromOnTerminate(WebApplication* app);
 };
 
 }  // namespace runtime
index 0f015fe0257da8cd5a80f7c38366761e890fb98c..1d01b999a8af07e724b3b63d90d39d95b8abc34a 100755 (executable)
 #include "runtime/browser/prelauncher.h"
 #include "runtime/browser/preload_manager.h"
 
-bool g_prelaunch = false;
+#include "runtime/browser/ui_runtime.h"
 
-#ifdef IME_FEATURE_SUPPORT
-static Ecore_Timer* timeout = NULL;
+bool g_prelaunch = false;
 
-static Eina_Bool terminateDelayCallback(void* data) {
-  timeout = NULL;
-  ecore_main_loop_quit();
-  return ECORE_CALLBACK_CANCEL;
-}
-#endif
 #ifdef WATCH_FACE_FEATURE_SUPPORT
 static int setWatchEnv(int argc, char **argv) {
   bundle *kb = NULL;
@@ -139,20 +132,11 @@ int real_main(int argc, char* argv[]) {
     std::unique_ptr<runtime::Runtime> runtime =
         runtime::Runtime::MakeRuntime(appdata);
     ret = runtime->Exec(argc, argv);
+    if (runtime->is_on_terminate_called) {
+      ecore_main_loop_begin();
+    }
     runtime.reset();
   }
-#ifdef IME_FEATURE_SUPPORT
-  if (appdata->app_type() == common::ApplicationData::IME) {
-    timeout = ecore_timer_add(0.5, terminateDelayCallback, NULL);
-    // This timer is added because of deadlock issue.
-    // If default keyboard is switched from webapp keyboard to tizen keyboard
-    // before webapp keyboard is completely loaded, main loop waits
-    // until webview is closed where webview is waiting to finish load.
-    // This timer delays main loop shutdown until webview load is finished.
-    // FIXME: http://suprem.sec.samsung.net/jira/browse/TSAM-11361
-    ecore_main_loop_begin();
-  }
-#endif
   ewk_shutdown();
   elm_shutdown();
   elm_exit();
index 20dddc6be5b266d47586277e24d27442fafea334..4e20943b78cfd24c84f939dea3ece55d71ca5164 100755 (executable)
@@ -142,8 +142,7 @@ bool UiRuntime::OnCreate() {
 }
 
 void UiRuntime::OnTerminate() {
-  application_.reset();
-  native_window_.reset();
+  ClosePageFromOnTerminate(application_.get());
 }
 
 void UiRuntime::OnPause() {
index afc3dbd4ea4a9240721d5370df86a4399035b26e..657a7f125be0e5b74aa037438a4c70117493a5d4 100644 (file)
@@ -99,14 +99,7 @@ bool WatchRuntime::OnCreate() {
 }
 
 void WatchRuntime::OnTerminate() {
-  if (application_) {
-    delete application_;
-    application_ = nullptr;
-  }
-  if (native_window_) {
-    delete native_window_;
-    native_window_ = nullptr;
-  }
+  ClosePageFromOnTerminate(application_);
 }
 
 void WatchRuntime::OnPause() {
index 8838c0d44191ff8a6e25a8e5f4f78ae2ba699c73..94c23d2c1b4e999be098c7cdd8e0064bd306acf1 100644 (file)
@@ -24,7 +24,6 @@
 #include "common/application_data.h"
 #include "runtime/browser/runtime.h"
 #include "runtime/browser/native_window.h"
-#include "runtime/browser/web_application.h"
 
 namespace runtime {
 
index d1462656a850415beb9f00dd4bb168b1ef89cff0..30be5300e173eee047aa89f67815cdc50c8fad88 100755 (executable)
@@ -44,6 +44,7 @@
 #include "runtime/browser/vibration_manager.h"
 #include "runtime/browser/web_view.h"
 #include "runtime/browser/splash_screen.h"
+#include "runtime/browser/ui_runtime.h"
 #include "extensions/common/xwalk_extension_server.h"
 
 #ifndef INJECTED_BUNDLE_PATH
@@ -709,8 +710,12 @@ void WebApplication::RemoveWebViewFromStack(WebView* view) {
 }
 
 void WebApplication::OnClosedWebView(WebView* view) {
-    is_terminated_by_callback_ = true;
-    RemoveWebViewFromStack(view);
+  is_terminated_by_callback_ = true;
+  RemoveWebViewFromStack(view);
+
+  if (runtime::Runtime::is_on_terminate_called) {
+    ecore_main_loop_quit();
+  }
 }
 
 void WebApplication::OnReceivedWrtMessage(WebView* /*view*/,