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 9cdc3db..0527c83 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 0f015fe..1d01b99 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 20dddc6..4e20943 100755 (executable)
@@ -142,8 +142,7 @@ bool UiRuntime::OnCreate() {
 }
 
 void UiRuntime::OnTerminate() {
-  application_.reset();
-  native_window_.reset();
+  ClosePageFromOnTerminate(application_.get());
 }
 
 void UiRuntime::OnPause() {
index afc3dbd..657a7f1 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 8838c0d..94c23d2 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 d146265..30be530 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*/,