Assure proper termination using context session
[platform/framework/web/crosswalk-tizen.git] / runtime / browser / runtime_process.cc
index b115546..83d7645 100755 (executable)
 #include "common/command_line.h"
 #include "common/logger.h"
 #include "common/profiler.h"
+#include "extensions/renderer/xwalk_extension_renderer_controller.h"
 #include "runtime/browser/runtime.h"
 #include "runtime/common/constants.h"
 #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;
+using namespace extensions;
+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,23 +134,22 @@ int real_main(int argc, char* argv[]) {
     std::unique_ptr<runtime::Runtime> runtime =
         runtime::Runtime::MakeRuntime(appdata);
     ret = runtime->Exec(argc, argv);
+    if (ret)
+      LOGGER(ERROR) << "Exec returns non zero.";
+    LOGGER(DEBUG) << "plugin_session_count : " <<
+        XWalkExtensionRendererController::plugin_session_count;
+    if (XWalkExtensionRendererController::plugin_session_count > 0) {
+      LOGGER(DEBUG) << "Defer termination of main loop";
+      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
+  LOGGER(DEBUG) << "ewk_shutdown";
   ewk_shutdown();
+  elm_shutdown();
   elm_exit();
 
+  LOGGER(DEBUG) << "EXIT_SUCCESS";
   return EXIT_SUCCESS;
 }