Initial implementation of app loop 48/170948/4
authorprathmeshm <prathmesh.m@samsung.com>
Fri, 23 Feb 2018 11:09:44 +0000 (16:39 +0530)
committerprathmeshm <prathmesh.m@samsung.com>
Wed, 28 Feb 2018 11:10:59 +0000 (16:40 +0530)
Change-Id: Id704b08ce2df00648de0e7b1718f5c994894df40
Signed-off-by: prathmeshm <prathmesh.m@samsung.com>
17 files changed:
atom/app/atom_main.cc
atom/app/runtime.cc [new file with mode: 0644]
atom/app/runtime.h [new file with mode: 0644]
atom/app/ui_runtime.cc [new file with mode: 0644]
atom/app/ui_runtime.h [new file with mode: 0644]
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/browser.cc
atom/browser/browser.h
atom/browser/browser_observer.h
efl/build/system.gyp
electron.gyp
filenames.gypi
wrt/src/runtime.js
wrt/src/web_window.js
wrt/src/web_window_tag.js

index 49625a66fab15f8a15ee0c9b7afa162dca8c9a97..c71f3dd4c509bad2d072efe902686236df43a4f8 100644 (file)
@@ -44,6 +44,8 @@
 #include "base/logging.h"
 #endif
 
+#include "atom/app/runtime.h"
+
 namespace {
 
 const char* kRunAsNode = "ELECTRON_RUN_AS_NODE";
@@ -135,6 +137,18 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
 
 #elif defined(OS_LINUX)  // defined(OS_WIN)
 
+#if defined(OS_TIZEN)
+// For debug purpose only
+bool hasTizenPackageID(int argc, const char* const* argv) {
+  if (argc > 3) {
+    if (0 == strncmp(argv[0], "/opt/usr/globalapps/", strlen("/opt/usr/globalapps/"))) {
+      return true;
+    }
+  }
+  return false;
+}
+#endif
+
 #if defined(OS_TIZEN)
 int real_main(int argc, char* argv[]) {
 #else
@@ -175,7 +189,15 @@ int main(int argc, char* argv[]) {
   params.argc = argc;
   params.argv = const_cast<const char**>(argv);
   atom::AtomCommandLine::Init(argc, argv);
+#if defined(OS_TIZEN)
+  if (hasTizenPackageID(argc,argv)) {
+    std::unique_ptr<runtime::Runtime> runtime = runtime::Runtime::MakeRuntime();
+    runtime->Exec(params);
+    return 1;
+  }
+#endif
   return content::ContentMain(params);
+
 }
 
 #if defined(OS_TIZEN)
diff --git a/atom/app/runtime.cc b/atom/app/runtime.cc
new file mode 100644 (file)
index 0000000..95a9b16
--- /dev/null
@@ -0,0 +1,29 @@
+#include "atom/app/runtime.h"
+#include "atom/app/ui_runtime.h"
+#include "base/logging.h"
+
+namespace runtime {
+
+Runtime::~Runtime() {
+}
+
+std::unique_ptr<Runtime> Runtime::MakeRuntime() {
+/*  if (app_data->app_type() == common::ApplicationData::UI) {
+    return std::unique_ptr<Runtime>(new UiRuntime());
+  }
+#ifdef IME_FEATURE_SUPPORT
+  else if (app_data->app_type() == common::ApplicationData::IME) {
+    return std::unique_ptr<Runtime>(new ImeRuntime(app_data));
+  }
+#endif  // IME_FEATURE_SUPPORT
+#ifdef WATCH_FACE_FEATURE_SUPPORT
+  else if (app_data->app_type() == common::ApplicationData::WATCH) {
+    return std::unique_ptr<Runtime>(new WatchRuntime(app_data));
+  }
+#endif  // WATCH_FACE_FEATURE_SUPPORT
+  else { */
+    return std::unique_ptr<Runtime>(new UiRuntime());
+  //}
+}
+
+}  // namespace runtime
\ No newline at end of file
diff --git a/atom/app/runtime.h b/atom/app/runtime.h
new file mode 100644 (file)
index 0000000..a893875
--- /dev/null
@@ -0,0 +1,23 @@
+
+#ifndef RUNTIME_H_
+#define RUNTIME_H_
+
+#include <memory>
+#include <string>
+
+#include "content/public/app/content_main.h"
+
+namespace runtime {
+
+class Runtime {
+ public:
+  virtual ~Runtime() = 0;
+
+  virtual int Exec(content::ContentMainParams params) = 0;
+
+  static std::unique_ptr<Runtime> MakeRuntime();
+};
+
+}  // namespace runtime
+
+#endif  // RUNTIME_H_
\ No newline at end of file
diff --git a/atom/app/ui_runtime.cc b/atom/app/ui_runtime.cc
new file mode 100644 (file)
index 0000000..b732652
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include "atom/app/ui_runtime.h"
+#include "atom/app/atom_main_delegate.h"
+#include "content/public/app/content_main.h"
+#include "atom/common/atom_command_line.h"
+#include "atom/browser/atom_browser_client.h"
+#include "base/logging.h"
+#include "atom/browser/browser.h"
+
+#include <app.h>
+#include <string>
+#include <vector>
+
+namespace runtime {
+
+UiRuntime::UiRuntime() {
+}
+
+UiRuntime::~UiRuntime() {
+}
+
+
+bool UiRuntime::OnCreate() {
+  
+}
+
+void UiRuntime::OnTerminate() {
+}
+
+void UiRuntime::Terminate() {
+  
+}
+
+void UiRuntime::OnPause() {
+  LOG(ERROR) << "OnPause()";
+}
+
+void UiRuntime::OnResume() {
+  LOG(ERROR) << "OnResume()";
+}
+
+void UiRuntime::OnAppControl(app_control_h app_control) {
+    LOG(ERROR) << "OnAppControl()";
+}
+
+void UiRuntime::OnLanguageChanged(const std::string& language) {
+  LOG(ERROR) << "OnLanguageChanged()";
+}
+
+void UiRuntime::OnLowMemory() {
+  LOG(ERROR) << "OnLowMemory()";
+}
+
+int UiRuntime::Exec(content::ContentMainParams params) {
+  ui_app_lifecycle_callback_s ops = {NULL, NULL, NULL, NULL, NULL};
+
+    // onCreate
+    ops.create = [](void* data) -> bool {
+
+      LOG(ERROR) << "Create Tizen App.";
+      content::ContentMainParams *params = (content::ContentMainParams*)data;
+      content::ContentMain(*params);
+      return true;
+    };
+
+    // onTerminate
+    ops.terminate = [](void* data) -> void {
+      LOG(ERROR) << "Terminate Tizen App.";
+      atom::Browser *browser_model = atom::Browser::Get();
+      browser_model->Shutdown();
+    };
+
+    // onPause
+    ops.pause = [](void* data) -> void {
+      LOG(ERROR) << "Pause Tizen App.";
+      atom::Browser *browser_model = atom::Browser::Get();
+      browser_model->Hide();
+    };
+
+    // onResume
+    ops.resume = [](void* data) -> void {
+      LOG(ERROR) << "Resume Tizen App.";
+      atom::Browser *browser_model = atom::Browser::Get();
+      browser_model->Show();
+    };
+
+    // onAppControl
+    ops.app_control = [](app_control_h app_control, void* data) -> void {
+      LOG(ERROR) << "app_control Tizen App.";
+    };
+
+    std::vector<std::string> cmdAgrs =  atom::AtomCommandLine::argv();
+    int argc = cmdAgrs.size();
+    //std::string argv;
+    char **argvs = (char**)malloc(sizeof(char)*100);
+    for (int i=0;i<argc;i++) {
+      argvs[i] = (char*)malloc(sizeof(char)*200);
+      strcpy(argvs[i] , cmdAgrs[i].c_str());
+    }
+    LOG(ERROR) << "Start app";
+    ui_app_main(argc, (char **)argvs, &ops, &params);
+    return 1;
+}
+
+void UiRuntime::ResetWebApplication() {
+
+}
+
+} //namespace
\ No newline at end of file
diff --git a/atom/app/ui_runtime.h b/atom/app/ui_runtime.h
new file mode 100644 (file)
index 0000000..4f4dd36
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#ifndef UI_RUNTIME_H_
+#define UI_RUNTIME_H_
+
+#include <app.h>
+#include <string>
+#include "atom/app/runtime.h"
+#include "content/public/app/content_main.h"
+
+namespace runtime {
+
+class UiRuntime : public Runtime {
+ public:
+  UiRuntime();
+  virtual ~UiRuntime();
+
+  virtual int Exec(content::ContentMainParams params);
+
+ protected:
+  virtual bool OnCreate();
+  virtual void OnTerminate();
+  virtual void OnPause();
+  virtual void OnResume();
+  virtual void OnAppControl(app_control_h app_control);
+  virtual void OnLanguageChanged(const std::string& language);
+  virtual void OnLowMemory();
+  virtual void Terminate();
+
+ private:
+  void ResetWebApplication();
+};
+
+}  // namespace runtime
+
+#endif  // XWALK_RUNTIME_BROWSER_UI_RUNTIME_H_
index 8c473c5a0942d395374d3d457221c172bdb40582..66c456490667e463bc9c35c9ab5c819fe9e78a43 100644 (file)
@@ -434,7 +434,12 @@ bool WebContents::DidAddMessageToConsole(content::WebContents* source,
                                          int32_t line_no,
                                          const base::string16& source_id) {
   if (type_ == BROWSER_WINDOW || type_ == OFF_SCREEN) {
+#if defined(USE_EFL)
+    LOG(ERROR) << "ConsoleMessage : " << message << "\", source: " << source_id << " (" << line_no << ")";
+    return true;
+#else
     return false;
+#endif
   } else {
     Emit("console-message", level, message, line_no, source_id);
     return true;
index 72b8e33ef7b57dde0ce8a78f37c83e20ec50dba5..f19fbda29ce86de083febf0d4c18d4d5b6b2f6c6 100644 (file)
@@ -310,6 +310,16 @@ void Window::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {
 }
 #endif
 
+#if defined(USE_EFL)
+void Window::OnSuspend() {
+  Emit("app-on-suspend");
+}
+
+void Window::OnResume() {
+  Emit("app-on-resume");
+}
+#endif
+
 // static
 mate::WrappableBase* Window::New(mate::Arguments* args) {
   if (!Browser::Get()->is_ready()) {
index 75f0328ba64fdd103e02ad30ff4c6ffe9e838f92..daa56c7f1b7dec22db0251ec7f822addf5a4a9b5 100644 (file)
@@ -96,6 +96,11 @@ class Window : public mate::TrackableObject<Window>,
   void OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) override;
   #endif
 
+  #if defined(USE_EFL)
+  void OnSuspend();
+  void OnResume();
+  #endif
+
  private:
   void Init(v8::Isolate* isolate,
             v8::Local<v8::Object> wrapper,
index b2900a326ff344cf1f9d8d783f994b913cf830df..6f2a3c7294f02842cbb9b81d4d42189b4d3b4072 100644 (file)
@@ -213,4 +213,14 @@ void Browser::OnWindowAllClosed() {
   }
 }
 
+void Browser::Hide() {
+  for (BrowserObserver& observer : observers_)
+      observer.OnSuspend();
+}
+
+void Browser::Show() {
+  for (BrowserObserver& observer : observers_)
+      observer.OnResume();
+}
+
 }  // namespace atom
index 78cac65f7e40185bfdcf006e6e79bc22f8f96fe1..fc674dd929ee272df6805c53f363b54b9be3eae4 100644 (file)
@@ -104,6 +104,8 @@ class Browser : public WindowListObserver {
   void SetLoginItemSettings(LoginItemSettings settings);
   LoginItemSettings GetLoginItemSettings(const LoginItemSettings& options);
 
+  void Hide();
+  void Show();
 #if defined(OS_MACOSX)
   // Hide the application.
   void Hide();
index 88a50a93a7ee8547eee805f750584989abc8e0e9..b5760ecd9c95b64aa95a3809768130e638759ba7 100644 (file)
@@ -55,6 +55,8 @@ class BrowserObserver {
   // The browser's accessibility suppport has changed.
   virtual void OnAccessibilitySupportChanged() {}
 
+  virtual void OnSuspend() {}
+  virtual void OnResume() {}
 #if defined(OS_MACOSX)
   // The browser wants to resume a user activity via handoff. (macOS only)
   virtual void OnContinueUserActivity(
index 893423782e1d7aab1e7cc1617ab60ee4123eb19f..3e0f94f5f493002ca6e518da4d85484a752afa67 100644 (file)
         }], # tizen_product_tv==1
       ],
     }, # vd-win-util
+    {
+      'target_name': 'capi-appfw-application',
+      'type': 'none',
+      'conditions': [
+        ['is_tizen==1', {
+          'direct_dependent_settings': {
+            'cflags': [
+              '<!@(<(pkg-config) --cflags capi-appfw-application)',
+            ],
+          },
+          'link_settings': {
+            'ldflags': [
+              '<!@(<(pkg-config) --libs-only-L --libs-only-other capi-appfw-application)',
+            ],
+            'libraries': [
+              '<!@(<(pkg-config) --libs-only-l capi-appfw-application)',
+            ],
+          },
+        }],
+      ],
+    }, # capi-appfw-application
   ],
 }
index a7f036f470631aa6d7eefb91322522e7e8774771..99d35459558772f4e7fc4a87bcf3bfed82747ffb 100644 (file)
             'tizen/loader/loader.gyp:wrt-loader',
             '<(DEPTH)/efl/build/system.gyp:ecore',
             '<(DEPTH)/efl/build/system.gyp:launchpad',
+            '<(DEPTH)/efl/build/system.gyp:capi-appfw-application',
           ],
           'sources': [
             'tizen/loader/prelauncher.h',
                 '<(DEPTH)/efl/build/system.gyp:efl-extension',
                 '<(DEPTH)/efl/build/system.gyp:evas',
                 '<(DEPTH)/efl/build/system.gyp:icu',
+                '<(DEPTH)/efl/build/system.gyp:capi-appfw-application',
                 'electron_shell_copy',
               ],
             }, {
index 16fd220540e011a6640d0bc068cec39a3b4206e0..79dfbeb84af32f495942ac0391d8c06b4d9e8bcc 100644 (file)
@@ -99,6 +99,8 @@
       'atom/app/atom_main_delegate.h',
       'atom/app/atom_main_delegate_mac.mm',
       'atom/app/node_main.cc',
+      'atom/app/runtime.cc',
+      'atom/app/ui_runtime.cc',
       'atom/app/node_main.h',
       'atom/app/uv_task_runner.cc',
       'atom/app/uv_task_runner.h',
index b156ca3b90f7a7ee55fdc3720701ebbc365f46bc..ca2fc62c218df4349524e037f09e925fb00ffa22 100644 (file)
@@ -115,11 +115,11 @@ class Runtime {
     killAllProcesses() {}
     handleWasEvents() {
         var _this = this;
-        events.on(WAS_EVENT.RUNTIME.FOCUS, (sender, id) => {
+        events.on(WAS_EVENT.RUNTIME.RESUME, (sender, id) => {
             runtime_debug('handleWasMessages: focus ' + id);
             return _this.onResume(id);
         });
-        events.on(WAS_EVENT.RUNTIME.UNFOCUS, (sender, id) => {
+        events.on(WAS_EVENT.RUNTIME.SUSPEND, (sender, id) => {
             return _this.onPause(id);
         });
     }
index 559c61baa1fa6fc480355fc65e26aee74c20a78c..5720c8254b9ec4547effd21b16d8ab1c937aa599 100644 (file)
@@ -131,6 +131,14 @@ class WebWindow {
         this.mainWindow.on('language-changed', function(event, locale) {
             webwindow_debug('WebWindow : language-changed event  = ' + (JSON.stringify(locale)));
         });
+        this.mainWindow.on('app-on-suspend', function() {
+            webwindow_debug('WebWindow : app-on-suspend');
+            events.emit(WAS_EVENT.RUNTIME.SUSPEND, 'web_window', self.mainWindow.id);
+        });
+        this.mainWindow.on('app-on-resume', function() {
+            webwindow_debug('WebWindow : app-on-resume');
+            events.emit(WAS_EVENT.RUNTIME.RESUME, 'web_window', self.mainWindow.id);
+        });
         this.mainWindow.webContents.on('crashed', function() {
             webwindow_debug('WebWindow : webContents crashed');
             global.webApplication.exit(100);
index ae60995e7a11cd19ddcad0cb7e2d698efdb30e89..ac024054b97d4e138efb489328bcc6ed7058df1c 100644 (file)
@@ -154,6 +154,14 @@ class WebWindowTag {
         this.mainWindow.on('language-changed', function(event, locale) {
             webwindow_debug('WebWindow : language-changed event  = ' + (JSON.stringify(locale)));
         });
+        this.mainWindow.on('app-on-suspend', function() {
+            webwindow_debug('WebWindow : app-on-suspend');
+            events.emit(WAS_EVENT.RUNTIME.SUSPEND, 'web_window', self.mainWindow.id);
+        });
+        this.mainWindow.on('app-on-resume', function() {
+            webwindow_debug('WebWindow : app-on-resume');
+            events.emit(WAS_EVENT.RUNTIME.RESUME, 'web_window', self.mainWindow.id);
+        });
         this.mainWindow.webContents.on('crashed', function() {
             webwindow_debug('WebWindow : webContents crashed');
             global.webApplication.exit(100);