Run Tizen Webapps in single process mode
[platform/framework/web/crosswalk-tizen.git] / atom / browser / api / atom_api_window.cc
index 6748c9c..d4a975b 100644 (file)
@@ -5,6 +5,7 @@
 #include "atom/browser/api/atom_api_window.h"
 #include "atom/common/native_mate_converters/value_converter.h"
 
+#include "atom/browser/api/atom_api_browser_view.h"
 #include "atom/browser/api/atom_api_menu.h"
 #include "atom/browser/api/atom_api_web_contents.h"
 #include "atom/browser/browser.h"
@@ -22,6 +23,7 @@
 #include "content/public/common/content_switches.h"
 #include "native_mate/constructor.h"
 #include "native_mate/dictionary.h"
+#include "tizen/common/env_variables.h"
 #include "ui/gfx/geometry/rect.h"
 
 #if defined(TOOLKIT_VIEWS)
@@ -162,7 +164,8 @@ void Window::WillCloseWindow(bool* prevent_default) {
 
 void Window::WillDestroyNativeObject() {
   // Close all child windows before closing current window.
-  v8::Locker locker(isolate());
+  if (!::tizen::is_single_process)
+    v8::Locker locker(isolate());
   v8::HandleScope handle_scope(isolate());
   for (v8::Local<v8::Value> value : child_windows_.Values(isolate())) {
     mate::Handle<Window> child;
@@ -190,6 +193,10 @@ void Window::OnWindowClosed() {
       FROM_HERE, GetDestroyClosure());
 }
 
+void Window::OnWindowEndSession() {
+  Emit("session-end");
+}
+
 void Window::OnWindowBlur() {
   Emit("blur");
 }
@@ -262,6 +269,14 @@ void Window::OnWindowSwipe(const std::string& direction) {
   Emit("swipe", direction);
 }
 
+void Window::OnWindowSheetBegin() {
+  Emit("sheet-begin");
+}
+
+void Window::OnWindowSheetEnd() {
+  Emit("sheet-end");
+}
+
 void Window::OnWindowEnterHtmlFullScreen() {
   Emit("enter-html-full-screen");
 }
@@ -297,6 +312,20 @@ void Window::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {
 }
 #endif
 
+#if defined(OS_TIZEN)
+void Window::OnSuspend() {
+  Emit("app-on-suspend");
+}
+
+void Window::OnResume() {
+  Emit("app-on-resume");
+}
+
+void Window::OnAppControl() {
+  Emit("app-on-appcontrol");
+}
+#endif
+
 // static
 mate::WrappableBase* Window::New(mate::Arguments* args) {
   if (!Browser::Get()->is_ready()) {
@@ -816,6 +845,25 @@ std::vector<v8::Local<v8::Object>> Window::GetChildWindows() const {
   return child_windows_.Values(isolate());
 }
 
+v8::Local<v8::Value> Window::GetBrowserView() const {
+  if (browser_view_.IsEmpty()) {
+    return v8::Null(isolate());
+  }
+
+  return v8::Local<v8::Value>::New(isolate(), browser_view_);
+}
+
+void Window::SetBrowserView(v8::Local<v8::Value> value) {
+  mate::Handle<BrowserView> browser_view;
+  if (value->IsNull()) {
+    window_->SetBrowserView(nullptr);
+    browser_view_.Reset();
+  } else if (mate::ConvertFromV8(isolate(), value, &browser_view)) {
+    window_->SetBrowserView(browser_view->view());
+    browser_view_.Reset(isolate(), value);
+  }
+}
+
 bool Window::IsModal() const {
   return window_->is_modal();
 }
@@ -853,15 +901,20 @@ void Window::RefreshTouchBarItem(const std::string& item_id) {
   window_->RefreshTouchBarItem(item_id);
 }
 
+void Window::SetEscapeTouchBarItem(const mate::PersistentDictionary& item) {
+  window_->SetEscapeTouchBarItem(item);
+}
+
 int32_t Window::ID() const {
   return weak_map_id();
 }
 
 v8::Local<v8::Value> Window::WebContents(v8::Isolate* isolate) {
-  if (web_contents_.IsEmpty())
+  if (web_contents_.IsEmpty()) {
     return v8::Null(isolate);
-  else
-    return v8::Local<v8::Value>::New(isolate, web_contents_);
+  }
+
+  return v8::Local<v8::Value>::New(isolate, web_contents_);
 }
 
 void Window::RemoveFromParentChildWindows() {
@@ -906,6 +959,8 @@ void Window::BuildPrototype(v8::Isolate* isolate,
 #endif
       .SetMethod("getParentWindow", &Window::GetParentWindow)
       .SetMethod("getChildWindows", &Window::GetChildWindows)
+      .SetMethod("getBrowserView", &Window::GetBrowserView)
+      .SetMethod("setBrowserView", &Window::SetBrowserView)
       .SetMethod("isModal", &Window::IsModal)
       .SetMethod("getNativeWindowHandle", &Window::GetNativeWindowHandle)
       .SetMethod("getBounds", &Window::GetBounds)
@@ -975,6 +1030,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
       .SetMethod("setVibrancy", &Window::SetVibrancy)
       .SetMethod("_setTouchBarItems", &Window::SetTouchBar)
       .SetMethod("_refreshTouchBarItem", &Window::RefreshTouchBarItem)
+      .SetMethod("_setEscapeTouchBarItem", &Window::SetEscapeTouchBarItem)
 #if defined(OS_WIN)
       .SetMethod("hookWindowMessage", &Window::HookWindowMessage)
       .SetMethod("isWindowMessageHooked", &Window::IsWindowMessageHooked)