Initialize chromium binding during preload 80/185780/1
authorSangYong Park <sy302.park@samsung.com>
Wed, 25 Jul 2018 09:44:31 +0000 (18:44 +0900)
committerSangYong Park <sy302.park@samsung.com>
Thu, 2 Aug 2018 08:05:28 +0000 (17:05 +0900)
Initialize chroimium binding during preload for electron's launch sequence.
It will show better launch performance and minimal electron's code change.

Change-Id: I1e1441c2cc1762afc0ae6a46e946ca44a20b8885
Signed-off-by: SangYong Park <sy302.park@samsung.com>
26 files changed:
atom/app/atom_main_delegate.cc
atom/app/runtime.cc
atom/app/runtime.h
atom/app/ui_runtime.cc
atom/app/ui_runtime.h
atom/app/watch_runtime.cc
atom/app/watch_runtime.h
atom/browser/browser.cc
atom/browser/browser.h
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_observer.h
tizen/common/application_data.cc
tizen/common/application_data.h
tizen/src/app/wrt_main_delegate.cc [new file with mode: 0644]
tizen/src/app/wrt_main_delegate.h [new file with mode: 0644]
tizen/src/browser/api/wrt_api_core.cc
tizen/src/browser/api/wrt_api_core.h
tizen/src/browser/native_web_runtime.cc [new file with mode: 0644]
tizen/src/browser/native_web_runtime.h [new file with mode: 0644]
tizen/src/browser/native_web_runtime_observer.h [new file with mode: 0644]
tizen/src/wrt_main.cc
wrt.gyp
wrt/src/runtime.js
wrt/src/web_application.js
wrt/src/web_window.js

index b88049f2b82644de8730b0fe4caf9f949f45b767..0358e7d7aa67be50bb5329223158c83ac2b417d6 100644 (file)
@@ -151,15 +151,6 @@ void AtomMainDelegate::PreSandboxStartup() {
   // Allow file:// URIs to read other file:// URIs by default.
   command_line->AppendSwitch(::switches::kAllowFileAccessFromFiles);
 
-#if defined(OS_TIZEN)
-  LOG (ERROR) << "Set Injected bundle path to engine";
-  command_line->AppendSwitchASCII(
-      "injected-bundle-path","/usr/lib/libxwalk_injected_bundle.so");
-  std::string app_id = common::CommandLine::ForCurrentProcess()->
-      GetAppIdFromCommandLine("/usr/bin/wrt");
-  command_line->AppendSwitchASCII("widget-id",app_id);
-#endif
-
 #if defined(OS_MACOSX)
   // Enable AVFoundation.
   command_line->AppendSwitch("enable-avfoundation");
index 6e27d1a272cd94cafd9db03d5be6487a20f0e24f..157755a659e00d25d65eef704b394aab0430501d 100644 (file)
  */
 
 #include "atom/app/runtime.h"
+
 #include "atom/app/ui_runtime.h"
-#if !defined(OS_TIZEN_TV_PRODUCT)
-#include "atom/app/watch_runtime.h"
-#endif
-#include "atom/browser/atom_browser_main_parts.h"
 #include "atom/browser/native_window_efl.h"
-#include "base/logging.h"
 #include "efl/window_factory.h"
 #include "tizen/common/application_data.h"
 
+#if !defined(OS_TIZEN_TV_PRODUCT)
+#include "atom/app/watch_runtime.h"
+#endif
+
 namespace runtime {
 
-Runtime::Runtime() {
-  atom::AtomBrowserMainParts::SetNodeEnvironment();
-}
+Runtime::Runtime() {}
 
-Runtime::~Runtime() {
-}
+Runtime::~Runtime() {}
 
-std::unique_ptr<Runtime> Runtime::MakeRuntime(content::ContentMainParams *params) {
+// static
+std::unique_ptr<Runtime> Runtime::MakeRuntime() {
 /*  if (app_data->app_type() == common::ApplicationData::UI) {
     return std::unique_ptr<Runtime>(new UiRuntime());
   }
@@ -47,10 +45,10 @@ std::unique_ptr<Runtime> Runtime::MakeRuntime(content::ContentMainParams *params
   efl::WindowFactory::SetDelegate(&atom::NativeWindowEfl::GetHostWindowDelegate);
 #if !defined(OS_TIZEN_TV_PRODUCT)
   if (app_data->app_type() == common::ApplicationData::WATCH)
-    return std::unique_ptr<Runtime>(new WatchRuntime(params));
+    return std::unique_ptr<Runtime>(new WatchRuntime());
   else
 #endif
-    return std::unique_ptr<Runtime>(new UiRuntime(params));
+    return std::unique_ptr<Runtime>(new UiRuntime());
 }
 
 }  // namespace runtime
index b5f956a092cc6a64420c78a7b8adb6053b183999..d07c56e57ba2a9350b07c625ea670fcadfdb9b52 100644 (file)
 #define RUNTIME_H_
 
 #include <memory>
-#include <string>
-
-#include "content/public/app/content_main.h"
 
 namespace runtime {
 
 class Runtime {
  public:
-  Runtime();
-  virtual ~Runtime() = 0;
+  virtual ~Runtime();
 
-  virtual int Exec() = 0;
+  virtual int Exec(int argc, char** argv) = 0;
 
-  static std::unique_ptr<Runtime> MakeRuntime(content::ContentMainParams *params);
+  static std::unique_ptr<Runtime> MakeRuntime();
+
+ protected:
+  Runtime();
 };
 
 }  // namespace runtime
index 0b5c77ea90fec232b7f0a4199179ec3c9ef5be55..186b76503c41e75d22b2e1500f71c1e2639c85d9 100644 (file)
  *    limitations under the License.
  */
 
+#include "atom/app/ui_runtime.h"
+
 #include <app.h>
 #include <string>
-#include <vector>
 
-#include "atom/app/atom_main_delegate.h"
-#include "atom/app/ui_runtime.h"
-#include "atom/browser/atom_browser_client.h"
-#include "atom/browser/atom_browser_main_parts.h"
 #include "atom/browser/browser.h"
-#include "atom/common/atom_command_line.h"
 #include "base/logging.h"
-#include "content/public/app/content_main.h"
 #include "tizen/common/app_control.h"
 #include "tizen/common/app_db.h"
 #include "tizen/common/application_data.h"
-#include "tizen/common/command_line.h"
 #include "tizen/common/constants.h"
 
 namespace runtime {
 
-UiRuntime::UiRuntime(content::ContentMainParams *params)
-    : _params(params) {
-}
+UiRuntime::UiRuntime() {}
 
-UiRuntime::~UiRuntime() {
-}
+UiRuntime::~UiRuntime() {}
 
 bool UiRuntime::OnCreate() {
+  LOG(INFO) << "OnCreate()";
   auto appdata = common::ApplicationDataManager::GetCurrentAppData();
-  atom::Browser::Get()->Initialize();
-  if(appdata->splash_screen_info()){
-    atom::Browser* browser_model = atom::Browser::Get();
-    browser_model->SetSplashScreen();
+  auto browser = atom::Browser::Get();
+  browser->Initialize();
+  if (appdata->splash_screen_info()) {
+    browser->SetSplashScreen();
   }
-
   return true;
 }
 
 void UiRuntime::OnTerminate() {
-  LOG(ERROR) << "OnTerminate()";
+  LOG(INFO) << "OnTerminate()";
 }
 
 void UiRuntime::OnPause() {
-  LOG(ERROR) << "OnPause()";
-  atom::Browser *browser_model = atom::Browser::Get();
-  browser_model->Hide();
+  LOG(INFO) << "OnPause()";
+  atom::Browser::Get()->Hide();
 }
 
 void UiRuntime::OnResume() {
-  LOG(ERROR) << "OnResume()";
-  atom::Browser *browser_model = atom::Browser::Get();
-  browser_model->Show();
+  LOG(INFO) << "OnResume()";
+  atom::Browser::Get()->Show();
 }
 
 void UiRuntime::OnAppControl(app_control_h app_control) {
-  LOG(ERROR) << "OnAppControl()";
+  LOG(INFO) << "OnAppControl()";
   std::unique_ptr<common::AppControl>
       appcontrol(new common::AppControl(app_control));
   common::AppDB* appdb = common::AppDB::GetInstance();
   appdb->Set(kAppDBRuntimeSection, kAppDBRuntimeBundle,
              appcontrol->encoded_bundle());
-  atom::Browser *browser_model = atom::Browser::Get();
-  if (browser_model->launched()) {
-   browser_model->AppControl(std::move(appcontrol));
+  auto browser = atom::Browser::Get();
+  if (browser->launched()) {
+    browser->AppControl(std::move(appcontrol));
   } else {
-   browser_model->Launch(std::move(appcontrol));
+    browser->Launch(std::move(appcontrol));
   }
 }
 
 void UiRuntime::OnLanguageChanged(const std::string& language) {
-  LOG(ERROR) << "OnLanguageChanged()";
+  LOG(INFO) << "OnLanguageChanged()";
 }
 
 void UiRuntime::OnLowMemory() {
-  LOG(ERROR) << "OnLowMemory()";
+  LOG(INFO) << "OnLowMemory()";
 }
 
-int UiRuntime::Exec() {
-  ui_app_lifecycle_callback_s ops = {NULL, NULL, NULL, NULL, NULL};
-
-  // onCreate
+int UiRuntime::Exec(int argc, char** argv) {
+  ui_app_lifecycle_callback_s ops;
   ops.create = [](void* data) -> bool {
-    LOG(ERROR) << "Create Tizen App.";
-    UiRuntime *runtime = (UiRuntime*)data;
-    runtime->OnCreate();
-    content::ContentMain(*runtime->_params);
-    return true;
+    return reinterpret_cast<UiRuntime*>(data)->OnCreate();
   };
-
-  // onTerminate
   ops.terminate = [](void* data) -> void {
-    LOG(ERROR) << "Terminate Tizen App.";
-    UiRuntime *runtime = (UiRuntime*)data;
-    runtime->OnTerminate();
+    reinterpret_cast<UiRuntime*>(data)->OnTerminate();
   };
-
-  // onPause
   ops.pause = [](void* data) -> void {
-    LOG(ERROR) << "Pause Tizen App.";
-    UiRuntime *runtime = (UiRuntime*)data;
-    runtime->OnPause();
+    reinterpret_cast<UiRuntime*>(data)->OnPause();
   };
-
-  // onResume
   ops.resume = [](void* data) -> void {
-    LOG(ERROR) << "Resume Tizen App.";
-    UiRuntime *runtime = (UiRuntime*)data;
-    runtime->OnResume();
+    reinterpret_cast<UiRuntime*>(data)->OnResume();
   };
-
-  // onAppControl
   ops.app_control = [](app_control_h app_control, void* data) -> void {
-    LOG(ERROR) << "app_control Tizen App.";
-    UiRuntime *runtime = (UiRuntime*)data;
-    runtime->OnAppControl(app_control);
+    reinterpret_cast<UiRuntime*>(data)->OnAppControl(app_control);
   };
-
-  return ui_app_main(_params->argc, const_cast<char**>(_params->argv), &ops, this);
+  return ui_app_main(argc, argv, &ops, this);
 }
-} //namespace
+
+} // namespace runtime
index f39dc4e9e353d3447dddc3d06d40b12b5aa2e36e..d86818b1bf1096fd5a8dafbc232f0fd30f08c429 100644 (file)
@@ -26,22 +26,19 @@ namespace runtime {
 
 class UiRuntime : public Runtime {
  public:
-  UiRuntime(content::ContentMainParams *params);
+  UiRuntime();
   virtual ~UiRuntime();
 
-  virtual int Exec() override;
+  int Exec(int argc, char** argv) override;
 
  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();
-
- private:
-  content::ContentMainParams *_params;
+  bool OnCreate();
+  void OnTerminate();
+  void OnPause();
+  void OnResume();
+  void OnAppControl(app_control_h app_control);
+  void OnLanguageChanged(const std::string& language);
+  void OnLowMemory();
 };
 
 }  // namespace runtime
index 793356c0ddc24c0f3ee16db7aaa07926378aa0a6..d32b51fd4c6ddacb9ddfd021058b519940cb0a85 100644 (file)
  *    limitations under the License.
  */
 
+#include "atom/app/watch_runtime.h"
+
 #include <app.h>
 #include <string>
-#include <vector>
 #include <watch_app_efl.h>
 
-#include "atom/app/atom_main_delegate.h"
-#include "atom/app/watch_runtime.h"
-#include "atom/browser/atom_browser_client.h"
-#include "atom/browser/atom_browser_main_parts.h"
 #include "atom/browser/browser.h"
-#include "atom/common/atom_command_line.h"
 #include "base/logging.h"
-#include "content/public/app/content_main.h"
-#include "gin/v8_initializer.h"
 #include "tizen/common/app_control.h"
 #include "tizen/common/app_db.h"
 #include "tizen/common/application_data.h"
-#include "tizen/common/command_line.h"
 #include "tizen/common/constants.h"
 
 namespace runtime {
 
-WatchRuntime::WatchRuntime(content::ContentMainParams *params)
-    : _params(params) {
-}
+WatchRuntime::WatchRuntime() {}
 
-WatchRuntime::~WatchRuntime() {
-}
+WatchRuntime::~WatchRuntime() {}
 
 bool WatchRuntime::OnCreate() {
+  LOG(INFO) << "OnCreate()";
   auto appdata = common::ApplicationDataManager::GetCurrentAppData();
+  auto browser = atom::Browser::Get();
   if (appdata->splash_screen_info()) {
-    atom::Browser* browser_model = atom::Browser::Get();
-    browser_model->SetSplashScreen();
+    browser->SetSplashScreen();
   }
-
   return true;
 }
 
 void WatchRuntime::OnTerminate() {
-  LOG(ERROR) << "OnTerminate()";
-  atom::Browser *browser_model = atom::Browser::Get();
+  LOG(INFO) << "OnTerminate()";
 }
 
 void WatchRuntime::OnPause() {
-  LOG(ERROR) << "OnPause()";
-  atom::Browser *browser_model = atom::Browser::Get();
-  browser_model->Hide();
+  LOG(INFO) << "OnPause()";
+  atom::Browser::Get()->Hide();
 }
 
 void WatchRuntime::OnResume() {
-  LOG(ERROR) << "OnResume()";
-  atom::Browser *browser_model = atom::Browser::Get();
-  browser_model->Show();
+  LOG(INFO) << "OnResume()";
+  atom::Browser::Get()->Show();
 }
 
 void WatchRuntime::OnAppControl(app_control_h app_control) {
-  LOG(ERROR) << "OnAppControl()";
+  LOG(INFO) << "OnAppControl()";
   std::unique_ptr<common::AppControl>
       appcontrol(new common::AppControl(app_control));
   common::AppDB* appdb = common::AppDB::GetInstance();
   appdb->Set(kAppDBRuntimeSection, kAppDBRuntimeBundle,
              appcontrol->encoded_bundle());
-  atom::Browser *browser_model = atom::Browser::Get();
-  if (browser_model->launched()) {
-   browser_model->AppControl(std::move(appcontrol));
+  auto browser = atom::Browser::Get();
+  if (browser->launched()) {
+    browser->AppControl(std::move(appcontrol));
   } else {
-   browser_model->Initialize();
-   browser_model->Launch(std::move(appcontrol));
+    browser->Initialize();
+    browser->Launch(std::move(appcontrol));
   }
 }
 
 void WatchRuntime::OnLanguageChanged(const std::string& language) {
-  LOG(ERROR) << "OnLanguageChanged()";
+  LOG(INFO) << "OnLanguageChanged()";
 }
 
 void WatchRuntime::OnLowMemory() {
-  LOG(ERROR) << "OnLowMemory()";
+  LOG(INFO) << "OnLowMemory()";
 }
 
-int WatchRuntime::Exec() {
-  watch_app_lifecycle_callback_s ops = {NULL, NULL, NULL, NULL, NULL};
-
-  // onCreate
-  ops.create = [](int width, int height, void *data) -> bool {
-    LOG(ERROR) << "Create Tizen App.";
-    WatchRuntime *runtime = (WatchRuntime*)data;
-    runtime->OnCreate();
-    content::ContentMain(*runtime->_params);
-    return true;
+int WatchRuntime::Exec(int argc, char** argv) {
+  watch_app_lifecycle_callback_s ops;
+  ops.create = [](int width, int height, void* data) -> bool {
+    return reinterpret_cast<WatchRuntime*>(data)->OnCreate();
   };
-
-  // onTerminate
-  ops.terminate = [](void* data) -> void {
-    LOG(ERROR) << "Terminate Tizen App.";
-    WatchRuntime *runtime = (WatchRuntime*)data;
-    runtime->OnTerminate();
+  ops.app_control = [](app_control_h app_control, void* data) -> void {
+    reinterpret_cast<WatchRuntime*>(data)->OnAppControl(app_control);
   };
-
-  // onPause
   ops.pause = [](void* data) -> void {
-    LOG(ERROR) << "Pause Tizen App.";
-    WatchRuntime *runtime = (WatchRuntime*)data;
-    runtime->OnPause();
+    reinterpret_cast<WatchRuntime*>(data)->OnPause();
   };
-
-  // onResume
   ops.resume = [](void* data) -> void {
-    LOG(ERROR) << "Resume Tizen App.";
-    WatchRuntime *runtime = (WatchRuntime*)data;
-    runtime->OnResume();
+    reinterpret_cast<WatchRuntime*>(data)->OnResume();
   };
-
-  // onAppControl
-  ops.app_control = [](app_control_h app_control, void* data) -> void {
-    LOG(ERROR) << "app_control Tizen App.";
-    WatchRuntime *runtime = (WatchRuntime*)data;
-    runtime->OnAppControl(app_control);
+  ops.terminate = [](void* data) -> void {
+    reinterpret_cast<WatchRuntime*>(data)->OnTerminate();
   };
-
-  return watch_app_main(_params->argc, const_cast<char**>(_params->argv), &ops, this);
+  ops.time_tick = nullptr;
+  ops.ambient_tick = nullptr;
+  ops.ambient_changed = nullptr;
+  return watch_app_main(argc, argv, &ops, this);
 }
-} //namespace
+
+} // namespace runtime
index 23cdfbd45a76716f7236fd46775cdefb1211c5a6..4fbfe561952f34d0ef70e01ec771faa1e71aed8c 100644 (file)
@@ -27,22 +27,19 @@ namespace runtime {
 
 class WatchRuntime : public Runtime {
  public:
-  WatchRuntime(content::ContentMainParams *params);
+  WatchRuntime();
   virtual ~WatchRuntime();
 
-  virtual int Exec() override;
+  int Exec(int argc, char** argv) override;
 
  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();
-
- private:
-  content::ContentMainParams *_params;
+  bool OnCreate();
+  void OnTerminate();
+  void OnPause();
+  void OnResume();
+  void OnAppControl(app_control_h app_control);
+  void OnLanguageChanged(const std::string& language);
+  void OnLowMemory();
 };
 
 }  // namespace runtime
index 24c6c1f0c5924bd9bd6a0ac68c5620dda2a49a57..808e9136c3542861bd86fe2279328367d2677ef1 100644 (file)
@@ -23,6 +23,7 @@
 #if defined(OS_TIZEN)
 #include "tizen/common/command_line.h"
 #include "tizen/common/application_data.h"
+#include "tizen/src/browser/native_web_runtime.h"
 #include <Elementary.h>
 #include "wgt_manifest_handlers/launch_screen_handler.h"
 #endif  // defined(OS_TIZEN)
@@ -35,7 +36,6 @@ Browser::Browser()
     : is_quiting_(false),
 #if defined(OS_TIZEN)
       launched_(false),
-      is_electron_launch_(false),
 #endif
       is_exiting_(false),
       is_ready_(false),
@@ -136,19 +136,6 @@ void Browser::Shutdown() {
   }
 }
 
-#if defined(OS_TIZEN)
-void Browser::SetElectronAppLaunch() {
-  if (!is_electron_launch_) {
-    auto app_data = common::ApplicationDataManager::GetCurrentAppData();
-    if (app_data->content_info() && !strcmp(app_data->content_info()->src().c_str(), "package.json")) {
-      is_electron_launch_ = true;
-    }
-  } else {
-    is_electron_launch_ = false;
-  }
-}
-#endif
-
 std::string Browser::GetVersion() const {
   if (version_override_.empty()) {
     std::string version = GetExecutableFileVersion();
@@ -200,9 +187,6 @@ void Browser::Activate(bool has_visible_windows) {
 }
 
 void Browser::WillFinishLaunching() {
-#if defined(OS_TIZEN)
-  SetElectronAppLaunch();
-#endif
   for (BrowserObserver& observer : observers_)
     observer.OnWillFinishLaunching();
 }
@@ -335,9 +319,7 @@ void Browser::Launch(std::unique_ptr<common::AppControl> appcontrol) {
   if (res)
     start_url_ = resource_manager_->GetLocalizedPath(res->uri());
 
-  NativeWindow *last_window = WindowList::GetLastWindow();
-  if (last_window)
-    last_window->NotifyAppControl();
+  tizen::NativeWebRuntime::GetInstance().StartApplication();
 }
 
 void Browser::SetSplashScreen() {
index 358bcb982da27a45a4848ddc75aec3475c82ed6e..6c73a24d60118b24908bb2918f631595fdefb524 100644 (file)
@@ -231,9 +231,6 @@ class Browser : public WindowListObserver,
   bool is_shutting_down() const { return is_shutdown_; }
   bool is_quiting() const { return is_quiting_; }
   bool is_ready() const { return is_ready_; }
-#if defined(OS_TIZEN)
-  bool is_electron_launch() const { return is_electron_launch_; }
-#endif
 
  protected:
   // Returns the version of application bundle or executable file.
@@ -255,10 +252,6 @@ class Browser : public WindowListObserver,
   void OnWindowCloseCancelled(NativeWindow* window) override;
   void OnWindowAllClosed() override;
 
-#if defined(OS_TIZEN)
-  void SetElectronAppLaunch();
-#endif
-
   // Observers of the browser.
   base::ObserverList<BrowserObserver> observers_;
 
@@ -266,7 +259,6 @@ class Browser : public WindowListObserver,
   std::unique_ptr<SplashScreen> splash_screen_;
   std::string start_url_;
   bool launched_;
-  bool is_electron_launch_;
 #endif
 
   // Whether `app.exit()` has been called
index 4320eb810a7b483ed46f653c51bac275984f3e77..0964d4e73791fd9b1461d724695710b161465b0c 100644 (file)
@@ -617,12 +617,6 @@ void NativeWindow::NotifyResume()
   for (NativeWindowObserver& observer : observers_)
     observer.OnResume();
 }
-
-void NativeWindow::NotifyAppControl()
-{
-  for (NativeWindowObserver& observer : observers_)
-    observer.OnAppControl();
-}
 #endif
 
 std::unique_ptr<SkRegion> NativeWindow::DraggableRegionsToSkRegion(
index 0e07787cc0c539c3eb208f3a0e7a2152e2ceb96e..f5237ecd5b5086a2812bf865991dcb7c372fcc4f 100644 (file)
@@ -251,7 +251,6 @@ class NativeWindow : public base::SupportsUserData,
 #if defined(OS_TIZEN)
   void NotifySuspend();
   void NotifyResume();
-  void NotifyAppControl();
 #endif
   void AddObserver(NativeWindowObserver* obs) {
     observers_.AddObserver(obs);
index 96ac37593786d3e34d8cce8a6db0753551920287..76bf7dcf449609e39bbb379b0dd183da105d6ab5 100644 (file)
@@ -97,7 +97,6 @@ class NativeWindowObserver {
   // Tizen
   virtual void OnSuspend() {}
   virtual void OnResume() {}
-  virtual void OnAppControl() {}
 #endif
 };
 
index 13ecf5c886239bbed56c39df67626d1516f580b4..987d3fd52f2402eb71aa1831acdf43766399322d 100644 (file)
@@ -162,6 +162,16 @@ ApplicationData::AppType ApplicationData::GetAppType() {
   return UI;
 }
 
+bool ApplicationData::IsElectronApp() {
+  if (!content_info_) {
+    return false;
+  }
+  std::string startUrl = content_info_->src();
+  std::string suffix(".json");
+  return (startUrl.size() > suffix.size() &&
+          std::equal(suffix.rbegin(), suffix.rend(), startUrl.rbegin()));
+}
+
 bool ApplicationData::init() {
   std::unique_ptr<char> res_path(app_get_resource_path());
   if (res_path) {
index 0429eb0634f6cfcf5ee2fc32fd362a9b8d25670c..8fecc850964bb0c7b4e2c07353df6461351fa04a 100644 (file)
@@ -71,6 +71,8 @@ class ApplicationData {
   const std::string app_id() const { return app_id_; }
   ApplicationData::AppType app_type() { return app_type_; }
 
+  bool IsElectronApp();
+
  private:
   bool init();
   ApplicationData::AppType GetAppType();
diff --git a/tizen/src/app/wrt_main_delegate.cc b/tizen/src/app/wrt_main_delegate.cc
new file mode 100644 (file)
index 0000000..55eff65
--- /dev/null
@@ -0,0 +1,62 @@
+#include "tizen/src/app/wrt_main_delegate.h"
+
+#include "base/command_line.h"
+#include "content/public/common/content_switches.h"
+#include "efl/init.h"
+#include "tizen/common/env_variables.h"
+#include "tizen/common/application_data.h"
+
+namespace {
+
+const char* kBlockSingleProcess = "PWRT_BLOCK_SINGLE_PROCESS"; // set to ON to disable single process mode altogether
+
+}  // namespace
+
+namespace tizen {
+
+WRTMainDelegate::WRTMainDelegate() {}
+
+WRTMainDelegate::~WRTMainDelegate() {}
+
+bool WRTMainDelegate::BasicStartupComplete(int* exit_code) {
+  auto command_line = base::CommandLine::ForCurrentProcess();
+  auto process_type(command_line->GetSwitchValueASCII(switches::kProcessType));
+  bool is_browser_process = process_type.empty();
+
+  if (is_browser_process) {
+    efl::AppendPortParams(*command_line);
+    command_line->AppendSwitch(switches::kEnableLogging);
+
+    std::string block_single_process(getenv(kBlockSingleProcess));
+    auto app_data = common::ApplicationDataManager::GetCurrentAppData();
+    if (app_data && app_data->IsElectronApp()) {
+      block_single_process = "ON";
+    }
+    if (block_single_process != "ON") {
+      LOG(INFO) << "will run in single process mode";
+      tizen::is_single_process = true;
+      command_line->AppendSwitch(switches::kAllowUniversalAccessFromFiles);
+      command_line->AppendSwitch(switches::kNoZygote);
+      command_line->AppendSwitch(switches::kSingleProcess);
+    } else {
+      LOG(INFO) << "will run in non-single process mode";
+    }
+  }
+
+  command_line->AppendSwitch("enable-tizen-app-container");
+  command_line->AppendSwitchASCII(
+      "injected-bundle-path", "/usr/lib/libxwalk_injected_bundle.so");
+
+  return AtomMainDelegate::BasicStartupComplete(exit_code);
+}
+
+int WRTMainDelegate::RunProcess(
+    const std::string& process_type,
+    const content::MainFunctionParams& main_function_params) {
+  if (process_type.empty())
+    return 0;
+  else
+    return AtomMainDelegate::RunProcess(process_type, main_function_params);
+}
+
+}  // namespace tizen
diff --git a/tizen/src/app/wrt_main_delegate.h b/tizen/src/app/wrt_main_delegate.h
new file mode 100644 (file)
index 0000000..b79c095
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef APP_WRT_MAIN_DELEGATE_H_
+#define APP_WRT_MAIN_DELEGATE_H_
+
+#include "atom/app/atom_main_delegate.h"
+
+namespace tizen {
+
+class WRTMainDelegate : public atom::AtomMainDelegate {
+ public:
+  WRTMainDelegate();
+  ~WRTMainDelegate();
+
+ protected:
+  // content::ContentMainDelegate:
+  bool BasicStartupComplete(int* exit_code) override;
+  int RunProcess(
+      const std::string& process_type,
+      const content::MainFunctionParams& main_function_params) override;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(WRTMainDelegate);
+};
+
+}  // namespace tizen
+
+#endif  // APP_WRT_MAIN_DELEGATE_H_
index c171f642a097967faf179a47ac993d96abcffbc7..5c8759371adedc636036f7fb4b494c5eb7342607 100644 (file)
@@ -9,6 +9,7 @@
 #include "native_mate/dictionary.h"
 #include "tizen/common/application_data.h"
 #include "tizen/common/command_line.h"
+#include "tizen/src/browser/native_web_runtime.h"
 #include "tizen/src/browser/wrt_service.h"
 
 namespace tizen {
@@ -20,10 +21,16 @@ WebRuntime* WebRuntime::instance_ = nullptr;
 WebRuntime::WebRuntime(v8::Isolate* isolate) {
   Init(isolate);
   instance_ = this;
+  NativeWebRuntime::GetInstance().AddObserver(this);
 }
 
 WebRuntime::~WebRuntime() {
   instance_ = nullptr;
+  NativeWebRuntime::GetInstance().RemoveObserver(this);
+}
+
+void WebRuntime::OnStartApplication() {
+  Emit("start-app");
 }
 
 std::string WebRuntime::AppID() const {
@@ -82,7 +89,8 @@ bool WebRuntime::isTizenWebApp() const {
 }
 
 bool WebRuntime::isElectronLaunch() const {
-  return atom::Browser::Get()->is_electron_launch();
+  auto app_data = common::ApplicationDataManager::GetCurrentAppData();
+  return app_data->IsElectronApp();
 }
 
 void WebRuntime::HideSplashScreen(int reason) {
index 99eb3c0e4718cd9e022f78ae4e0e0a00e502acb4..c3940f5a84362be265f804323ad859e39c1c2b0f 100644 (file)
@@ -3,12 +3,14 @@
 
 #include "atom/browser/api/event_emitter.h"
 #include "native_mate/handle.h"
+#include "tizen/src/browser/native_web_runtime_observer.h"
 
 namespace tizen {
 
 namespace api {
 
-class WebRuntime : public mate::EventEmitter<WebRuntime> {
+class WebRuntime : public mate::EventEmitter<WebRuntime>,
+                   public NativeWebRuntimeObserver {
  public:
   static mate::Handle<WebRuntime> Create(v8::Isolate* isolate);
 
@@ -21,6 +23,9 @@ class WebRuntime : public mate::EventEmitter<WebRuntime> {
   explicit WebRuntime(v8::Isolate* isolate);
   ~WebRuntime() override;
 
+  // NativeWebRuntimeObserver:
+  void OnStartApplication() override;
+
  private:
   std::string AppID() const;
   std::string GetMessage() const;
diff --git a/tizen/src/browser/native_web_runtime.cc b/tizen/src/browser/native_web_runtime.cc
new file mode 100644 (file)
index 0000000..20c5413
--- /dev/null
@@ -0,0 +1,56 @@
+#include "tizen/src/browser/native_web_runtime.h"
+
+#include "base/command_line.h"
+#include "content/public/common/main_function_params.h"
+
+namespace tizen {
+
+NativeWebRuntime::NativeWebRuntime() { }
+
+NativeWebRuntime::~NativeWebRuntime() {
+  if (browser_main_runner_) {
+    browser_main_runner_->Shutdown();
+  }
+  if (content_main_runner_) {
+    content_main_runner_->Shutdown();
+  }
+}
+
+// static
+NativeWebRuntime& NativeWebRuntime::GetInstance() {
+  static NativeWebRuntime runtime;
+  return runtime;
+}
+
+void NativeWebRuntime::InitializeMain(content::ContentMainParams* params) {
+  if (content_main_runner_) {
+    LOG(ERROR) << "Try to initialize multiple times.";
+    return;
+  }
+
+  content_main_runner_ = std::unique_ptr<content::ContentMainRunner>(
+      content::ContentMainRunner::Create());
+  browser_main_runner_ =  std::unique_ptr<content::BrowserMainRunner>(
+      content::BrowserMainRunner::Create());
+
+  int exit_code = content_main_runner_->Initialize(*params);
+  if (exit_code >= 0) {
+    LOG(FATAL) << "Fail to initialize content main runner";
+  }
+  content_main_runner_->Run();
+
+  const base::CommandLine& command_line =
+      *base::CommandLine::ForCurrentProcess();
+  content::MainFunctionParams main_params(command_line);
+  exit_code = browser_main_runner_->Initialize(main_params);
+  if (exit_code >= 0) {
+    LOG(FATAL) << "Fail to initialize browser main runner";
+  }
+}
+
+void NativeWebRuntime::StartApplication() {
+  for (auto& observer : observers_)
+    observer.OnStartApplication();
+}
+
+}  // namespace
diff --git a/tizen/src/browser/native_web_runtime.h b/tizen/src/browser/native_web_runtime.h
new file mode 100644 (file)
index 0000000..c772593
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef BROWSER_NATIVE_WEB_RUNTIME_H_
+#define BROWSER_NATIVE_WEB_RUNTIME_H_
+
+#include <memory>
+
+#include "base/observer_list.h"
+#include "content/public/app/content_main_runner.h"
+#include "content/public/browser/browser_main_runner.h"
+#include "tizen/src/browser/native_web_runtime_observer.h"
+
+namespace tizen {
+
+class NativeWebRuntime {
+ public:
+  ~NativeWebRuntime();
+
+  static NativeWebRuntime& GetInstance();
+
+  void InitializeMain(content::ContentMainParams* params);
+  void StartApplication();
+
+  void AddObserver(NativeWebRuntimeObserver* obs) {
+    observers_.AddObserver(obs);
+  }
+  void RemoveObserver(NativeWebRuntimeObserver* obs) {
+    observers_.RemoveObserver(obs);
+  }
+
+ private:
+  NativeWebRuntime();
+
+  std::unique_ptr<content::ContentMainRunner> content_main_runner_;
+  std::unique_ptr<content::BrowserMainRunner> browser_main_runner_;
+
+  base::ObserverList<NativeWebRuntimeObserver> observers_;
+};
+
+}  // namespace tizen
+
+#endif  // BROWSER_NATIVE_WEB_RUNTIME_H_
diff --git a/tizen/src/browser/native_web_runtime_observer.h b/tizen/src/browser/native_web_runtime_observer.h
new file mode 100644 (file)
index 0000000..8423b4f
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef BROWSER_NATIVE_WEB_RUNTIME_OBSERVER_H_
+#define BROWSER_NATIVE_WEB_RUNTIME_OBSERVER_H_
+
+namespace tizen {
+
+class NativeWebRuntimeObserver {
+ public:
+  virtual ~NativeWebRuntimeObserver() {}
+
+  virtual void OnStartApplication() = 0;
+};
+
+}  // namespace tizen
+
+#endif  // BROWSER_NATIVE_WEB_RUNTIME_OBSERVER_H_
index 32de2425a3b417c46822a7f43ba4366451f04764..38ccdfab8a504b3e7a51053e0e3c60ef81574d63 100644 (file)
@@ -3,24 +3,22 @@
 // found in the LICENSE file.
 
 #include "wrt_main.h"
-#include "tizen/common/env_variables.h"
 
 #include <stdlib.h>
-#include "atom/app/atom_main_delegate.h"  // NOLINT
-#include "content/public/app/content_main.h"
 
-#include "atom/browser/atom_browser_main_parts.h"
 #include "atom/common/atom_command_line.h"
-#include "base/at_exit.h"
-#include "base/i18n/icu_util.h"
-
+#include "base/command_line.h"
+#include "base/files/file_path.h"
+#include "base/logging.h"
+#include "content/public/app/content_main.h"
+#include "content/public/common/content_switches.h"
 #include "efl/init.h"
+#include "tizen/common/env_variables.h"
+#include "tizen/src/app/wrt_main_delegate.h"
+#include "tizen/src/browser/native_web_runtime.h"
 
 #if defined(OS_TIZEN)
-#include <Elementary.h>
-
 #include "atom/app/runtime.h"
-#include "base/logging.h"
 #include "tizen/common/application_data.h"
 #include "tizen/common/command_line.h"
 #include "tizen/loader/prelauncher.h"
 
 namespace {
 
-const char *kBlockSingleProcess = "PWRT_BLOCK_SINGLE_PROCESS"; // set to ON to disable single process mode altogether
-
-// Default command line flags for all profiles and platforms
-const char* kDefaultCommandLineFlags[] = {
-  "allow-file-access-from-files",
-  "enable-tizen-app-container",
-  "allow-universal-access-from-files",
-  "single-process",
-  "no-sandbox",
-  "no-zygote",
-};
-
-const int kElectronArgsCount = 2;
-const int kTizenWebappArgsCount = 6;
-
-bool isElectronWebApp() {
-  auto app_data = common::ApplicationDataManager::GetCurrentAppData();
-  if (app_data) {
-    if (app_data->content_info()) {
-      std::string startUrl = app_data->content_info()->src();
-      if (std::string::npos != startUrl.find(".json")) {
-        return true;
-      }
-    }
-  }
-  return false;
-}
-
-bool IsBrowserProcess() {
-  auto command_line = base::CommandLine::ForCurrentProcess();
-  std::string process_type = command_line->GetSwitchValueASCII("type");
-  return process_type.empty();
-}
+bool g_initialized_ = false;
+tizen::WRTMainDelegate g_delegate;
 
 }  // namespace
 
@@ -71,114 +38,90 @@ bool IsBrowserProcess() {
 REFERENCE_MODULE(wrt);
 #undef REFERENCE_MODULE
 
-#if defined(OS_TIZEN)
-bool g_initialized_ = false;
-
-// For debug purpose only.
-// TODO: To be removed later
-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;
-    }
-    if (0 == strncmp(argv[0], "/opt/usr/apps/", strlen("/opt/usr/apps/"))) {
-      return true;
-    }
-  }
-  return false;
-}
-
 int real_main(int argc, char* argv[]) {
-#else
-int main(int argc, char* argv[]) {
-#endif
   for (int i = 0; i < argc; ++i)
-    LOG(ERROR) << "argv[" << i << "] : " << argv[i];
+    LOG(INFO) << "argv[" << i << "] : " << argv[i];
 
   if (!common::CommandLine::Init(argc, argv)) {
     common::CommandLine::Reset();
     common::CommandLine::Init(argc, argv);
   }
 
-  if (!base::CommandLine::Init(argc, argv)) {
-    base::CommandLine::Reset();
+  if (base::CommandLine::InitializedForCurrentProcess()) {
+    base::CommandLine::ForCurrentProcess()->SetProgram(base::FilePath(argv[0]));
+  } else {
     base::CommandLine::Init(argc, argv);
   }
 
-  std::unique_ptr<runtime::Runtime> runtime_;
   common::CommandLine* runtime_cmd = common::CommandLine::ForCurrentProcess();
   std::string appid = runtime_cmd->GetAppIdFromCommandLine("/usr/bin/wrt");
 
-  // load manifest
-  if (appid != "wrt") { // TODO: Any better way to distinguish?
+  base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
+  bool is_browser_process =
+      command_line->GetSwitchValueASCII(switches::kProcessType).empty();
+
+  if (is_browser_process) {
     common::ApplicationDataManager::SetCurrentAppID(appid);
+    command_line->AppendSwitchASCII("widget-id", appid);
   }
+
   if (!g_initialized_) {
     if (efl::Initialize(argc, const_cast<const char**>(argv)))
       return 1;
   }
 
-  // Add params for EFL port
-  base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
-
-  int args_count = kElectronArgsCount;
-  if (IsBrowserProcess()) {
-    if (!getenv(kBlockSingleProcess) && !isElectronWebApp()) {
-      LOG(ERROR) << "will run in single process mode";
-      tizen::is_single_process = true;
-      args_count = kTizenWebappArgsCount;
-    } else LOG(ERROR) << "will run in non-single process mode";
-  } else LOG(ERROR) << "not a browser process";
-
-  static std::vector<char*> flags;
-  for (int i = 0; i < args_count; ++i)
-    command_line->AppendSwitch(const_cast<char*>(kDefaultCommandLineFlags[i]));
-
-  efl::AppendPortParams(*command_line);
-
-  atom::AtomMainDelegate delegate;
-  content::ContentMainParams params(&delegate);
+  content::ContentMainParams params(&g_delegate);
   params.argc = argc;
   params.argv = const_cast<const char**>(argv);
   atom::AtomCommandLine::Init(argc, argv);
-#if defined(OS_TIZEN)
-  if (hasTizenPackageID(argc,argv)) { // TODO: Check to be removed later
-    elm_init(argc, argv);
-    runtime_ = runtime::Runtime::MakeRuntime(&params);
-    return runtime_->Exec();
+
+  if (is_browser_process) {
+    auto app_data = common::ApplicationDataManager::GetCurrentAppData();
+    if (tizen::is_single_process && app_data->IsElectronApp()) {
+      // FIXME: Need to find better way for electron app.
+      LOG(INFO) << "Run electron app in single process. Try restarting.";
+      execv(argv[0], argv);
+      LOG(FATAL) << "Fail to restart electron app";
+    }
+
+    if (!g_initialized_) {
+      tizen::NativeWebRuntime::GetInstance().InitializeMain(&params);
+    }
+
+    std::unique_ptr<runtime::Runtime> runtime = runtime::Runtime::MakeRuntime();
+    return runtime->Exec(argc, argv);
   }
-#endif
   return content::ContentMain(params);
 }
 
-#if defined(OS_TIZEN)
 __attribute__((visibility("default")))
 int main(int argc, const char* argv[]) {
-  for (int i = 0; i < argc; ++i)
-    LOG(ERROR) << "argv[" << i << "] : " << argv[i];
   if (strcmp(argv[0], "/usr/bin/wrt-loader") == 0) {
-    LOG(ERROR) << "run with wrt-loader";
-    auto preload = [argc, argv](void) {
+    LOG(INFO) << "run with wrt-loader";
+    for (int i = 0; i < argc; ++i)
+      LOG(INFO) << "argv[" << i << "] : " << argv[i];
+    int no_argument_count = 1;
+    atom::AtomCommandLine::Init(no_argument_count, argv);
+
+    auto preload = []() {
       g_initialized_ = true;
-      if (efl::Initialize(argc, const_cast<const char**>(argv)))
+      const auto& argv = atom::AtomCommandLine::argv();
+      std::vector<const char*> arguments;
+      arguments.reserve(argv.size());
+      for (auto& s : argv)
+        arguments.push_back(&s[0]);
+      if (efl::Initialize(arguments.size(), arguments.data()))
         return 1;
-
-      atom::AtomMainDelegate delegate;
-      content::ContentMainParams params(&delegate);
-      params.argc = argc;
-      params.argv = const_cast<const char**>(argv);
-      atom::AtomCommandLine::Init(argc, argv);
-      atom::AtomBrowserMainParts::SetNodeEnvironment();
+      content::ContentMainParams params(&g_delegate);
+      tizen::NativeWebRuntime::GetInstance().InitializeMain(&params);
       tizen::PreloadManager::GetInstance()->CreateCacheComponent();
       return 0;
     };
-    auto did_launch = [](const std::string& app_path) {
-    };
+    auto did_launch = [](const std::string& app_path) {};
     auto prelaunch = runtime::PreLauncher::Prelaunch;
     return prelaunch(argc, const_cast<char**>(argv), preload, did_launch, real_main);
   } else {
-    LOG(ERROR) << "run without wrt-loader";
+    LOG(INFO) << "run without wrt-loader";
     return real_main(argc, const_cast<char**>(argv));
   }
 }
-#endif
diff --git a/wrt.gyp b/wrt.gyp
index 83132cac6d3048b1877c8ac57643f70d7e691056..e0a24b37b4f17a7ca7020f94575b5bd8a1b94ecb 100644 (file)
--- a/wrt.gyp
+++ b/wrt.gyp
         'chromium_src/chrome/browser/extensions/global_shortcut_listener_ozone.cc',
         'chromium_src/chrome/browser/extensions/global_shortcut_listener_ozone.h',
         'chromium_src/chrome/browser/icon_loader_efllinux.cc',
+        'tizen/src/app/wrt_main_delegate.cc',
+        'tizen/src/app/wrt_main_delegate.h',
         'tizen/src/browser/api/wrt_api_core.cc',
         'tizen/src/browser/api/wrt_api_core.h',
+        'tizen/src/browser/native_web_runtime.cc',
+        'tizen/src/browser/native_web_runtime.h',
+        'tizen/src/browser/native_web_runtime_observer.h',
         'tizen/src/browser/wrt_ipc.cc',
         'tizen/src/browser/wrt_ipc.h',
         'tizen/src/browser/wrt_service.cc',
index ae01bb3584e6b906665f6f86d9d9e58fd807838a..1c13e826b7e63f2748385fdaa238862129869564 100755 (executable)
@@ -56,8 +56,20 @@ class Runtime {
         });
         app.on('will-finish-launching', function(event) {
             runtime_debug('will-finish-launching');
+        });
+        app.once('ready', function(event) {
+            runtime_debug('ready');
+            _this.extensionManager = new ExtensionManager(EXTENSIONS_PATH);
+             if (!options.noExtensions) {
+                _this.extensionManager.build();
+            }
+            _this.webApplication = new WebApplication(options);
+        });
+        wrt.on('start-app', function() {
+            runtime_debug('start-app');
             if (wrt.isElectronLaunch()) {
                 console.log("Electron App launch");
+                _this.webApplication = null;
                 let filePath = wrt.getPath();
                 let pkgJson = require(filePath.substr(7, filePath.length - 12));
                 let mainJsPath = filePath.substr(7, filePath.length - 19) +
@@ -65,18 +77,13 @@ class Runtime {
 
                 const Module = require('module');
                 Module._load(mainJsPath, Module, true);
-             }
-        });
-        app.on('ready', function(event) {
-            runtime_debug('ready');
-            _this.extensionManager = new ExtensionManager(EXTENSIONS_PATH);
-            if (!options.noExtensions && wrt.appID !== 'NVPDzvckj9.RuntimeAddonSetting') {
-                _this.extensionManager.build();
+                app.emit('ready');
+             } else {
+                _this.webApplication.focusedWebWindow.setUrl('');
+                if (wrt.appID !== 'NVPDzvckj9.RuntimeAddonSetting') {
+                    _this.extensionManager.activateAll(app);
+                }
             }
-            if (wrt.isElectronLaunch()) {
-                return;
-            }
-            _this.webApplication = new WebApplication(options);
         });
     }
     onPause(web_window_id) {
index 101897f471331c6ff9ba66d75fb7bbe97bc03565..7505bc1ac56ce022e1b5769281eccb89dafa1408 100644 (file)
@@ -59,6 +59,7 @@ class WebApplication {
     setupWebWindow() {}
     addWebWindow(webwindow) {
         this.webwindows.push(webwindow);
+        this.focusedWebWindow = webwindow;
     }
     removeWebWindow(webwindow) {
         var _ref;
index cb1f8eec273097193adcc96a7e18e1d282787c70..d6d581e8a6f4eb57da8dd1f318eccab083840779 100644 (file)
@@ -119,10 +119,6 @@ class WebWindow {
             webwindow_debug('WebWindow : app-on-resume');
             events.emit(WAS_EVENT.WEBAPPLICATION.RESUME, 'web_window', self.mainWindow.id);
         });
-        this.mainWindow.on('app-on-appcontrol', function() {
-            webwindow_debug('WebWindow : app-on-appcontrol');
-            self.setUrl('');
-        });
         this.mainWindow.webContents.on('crashed', function() {
             webwindow_debug('WebWindow : webContents crashed');
             self.webApplication.exit(100);