Add main loop exit method in WebApplication
authorSeungkeun Lee <sngn.lee@samsung.com>
Tue, 21 Apr 2015 10:51:00 +0000 (19:51 +0900)
committerSeungkeun Lee <sngn.lee@samsung.com>
Tue, 21 Apr 2015 10:51:00 +0000 (19:51 +0900)
Change-Id: I7d77f0daa8dfcf326b69d91788181dd2a805fe5f

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

index 72bb987..e17dfa0 100755 (executable)
@@ -44,6 +44,7 @@ bool Runtime::OnCreate() {
     LoggerE("WebApplication couldn't be created.");
     return false;
   }
+  application_->set_terminator([](){ ui_app_exit(); });
 
   // Process First Launch
   native_window_ = CreateNativeWindow();
index d224622..cb87a3b 100755 (executable)
@@ -62,7 +62,8 @@ WebApplication::WebApplication(const std::string& appid)
       ewk_context_(ewk_context_new()),
       locale_manager_(new LocaleManager()),
       app_data_(new ApplicationData(appid)),
-      debug_mode_(false) {
+      debug_mode_(false),
+      terminator_(NULL) {
   // app_data_path
   std::unique_ptr<char, decltype(std::free)*>
     path {app_get_data_path(), std::free};
@@ -78,7 +79,8 @@ WebApplication::WebApplication(std::unique_ptr<ApplicationData> app_data)
       ewk_context_(ewk_context_new()),
       locale_manager_(new LocaleManager()),
       app_data_(std::move(app_data)),
-      debug_mode_(false) {
+      debug_mode_(false),
+      terminator_(NULL) {
   // app_data_path
   std::unique_ptr<char, decltype(std::free)*>
     path {app_get_data_path(), std::free};
@@ -267,7 +269,9 @@ void WebApplication::OnClosedWebView(WebView * view) {
   }
 
   if (view_stack_.size() == 0) {
-    // TODO(sngn.lee): terminate the webapp
+    if (terminator_ != NULL) {
+      terminator_();
+    }
   } else if (current != view_stack_.front()) {
     view_stack_.front()->SetVisibility(true);
     window_->SetContent(view_stack_.front()->evas_object());
index 2b8873a..a3837eb 100755 (executable)
@@ -8,6 +8,7 @@
 #include <string>
 #include <list>
 #include <memory>
+#include <functional>
 
 #include "runtime/web_view.h"
 #include "extension/extension_server.h"
@@ -34,6 +35,8 @@ class WebApplication : public WebView::EventListener {
   bool Initialize(NativeWindow* window);
   std::string data_path() const { return app_data_path_; }
   bool initialized() const { return initialized_; }
+  void set_terminator(std::function<void(void)> terminator)
+      { terminator_ = terminator; }
 
   virtual void OnCreatedNewWebView(WebView* view, WebView* new_view);
   virtual void OnClosedWebView(WebView * view);
@@ -67,6 +70,7 @@ class WebApplication : public WebView::EventListener {
   std::unique_ptr<LocaleManager> locale_manager_;
   std::unique_ptr<ApplicationData> app_data_;
   bool debug_mode_;
+  std::function<void(void)> terminator_;
 };
 
 }  // namespace wrt