From: SangYong Park Date: Wed, 25 Jul 2018 09:44:31 +0000 (+0900) Subject: Initialize chromium binding during preload X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=991b30c36bfbb645fd37ae118b622486a0fec206;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git Initialize chromium binding during preload 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 --- diff --git a/atom/app/atom_main_delegate.cc b/atom/app/atom_main_delegate.cc index b88049f2b..0358e7d7a 100644 --- a/atom/app/atom_main_delegate.cc +++ b/atom/app/atom_main_delegate.cc @@ -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"); diff --git a/atom/app/runtime.cc b/atom/app/runtime.cc index 6e27d1a27..157755a65 100644 --- a/atom/app/runtime.cc +++ b/atom/app/runtime.cc @@ -15,26 +15,24 @@ */ #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::MakeRuntime(content::ContentMainParams *params) { +// static +std::unique_ptr Runtime::MakeRuntime() { /* if (app_data->app_type() == common::ApplicationData::UI) { return std::unique_ptr(new UiRuntime()); } @@ -47,10 +45,10 @@ std::unique_ptr 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(new WatchRuntime(params)); + return std::unique_ptr(new WatchRuntime()); else #endif - return std::unique_ptr(new UiRuntime(params)); + return std::unique_ptr(new UiRuntime()); } } // namespace runtime diff --git a/atom/app/runtime.h b/atom/app/runtime.h index b5f956a09..d07c56e57 100644 --- a/atom/app/runtime.h +++ b/atom/app/runtime.h @@ -19,20 +19,19 @@ #define RUNTIME_H_ #include -#include - -#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 MakeRuntime(content::ContentMainParams *params); + static std::unique_ptr MakeRuntime(); + + protected: + Runtime(); }; } // namespace runtime diff --git a/atom/app/ui_runtime.cc b/atom/app/ui_runtime.cc index 0b5c77ea9..186b76503 100644 --- a/atom/app/ui_runtime.cc +++ b/atom/app/ui_runtime.cc @@ -14,123 +14,90 @@ * limitations under the License. */ +#include "atom/app/ui_runtime.h" + #include #include -#include -#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 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(data)->OnCreate(); }; - - // onTerminate ops.terminate = [](void* data) -> void { - LOG(ERROR) << "Terminate Tizen App."; - UiRuntime *runtime = (UiRuntime*)data; - runtime->OnTerminate(); + reinterpret_cast(data)->OnTerminate(); }; - - // onPause ops.pause = [](void* data) -> void { - LOG(ERROR) << "Pause Tizen App."; - UiRuntime *runtime = (UiRuntime*)data; - runtime->OnPause(); + reinterpret_cast(data)->OnPause(); }; - - // onResume ops.resume = [](void* data) -> void { - LOG(ERROR) << "Resume Tizen App."; - UiRuntime *runtime = (UiRuntime*)data; - runtime->OnResume(); + reinterpret_cast(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(data)->OnAppControl(app_control); }; - - return ui_app_main(_params->argc, const_cast(_params->argv), &ops, this); + return ui_app_main(argc, argv, &ops, this); } -} //namespace + +} // namespace runtime diff --git a/atom/app/ui_runtime.h b/atom/app/ui_runtime.h index f39dc4e9e..d86818b1b 100644 --- a/atom/app/ui_runtime.h +++ b/atom/app/ui_runtime.h @@ -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 diff --git a/atom/app/watch_runtime.cc b/atom/app/watch_runtime.cc index 793356c0d..d32b51fd4 100644 --- a/atom/app/watch_runtime.cc +++ b/atom/app/watch_runtime.cc @@ -14,126 +14,94 @@ * limitations under the License. */ +#include "atom/app/watch_runtime.h" + #include #include -#include #include -#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 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(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(data)->OnAppControl(app_control); }; - - // onPause ops.pause = [](void* data) -> void { - LOG(ERROR) << "Pause Tizen App."; - WatchRuntime *runtime = (WatchRuntime*)data; - runtime->OnPause(); + reinterpret_cast(data)->OnPause(); }; - - // onResume ops.resume = [](void* data) -> void { - LOG(ERROR) << "Resume Tizen App."; - WatchRuntime *runtime = (WatchRuntime*)data; - runtime->OnResume(); + reinterpret_cast(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(data)->OnTerminate(); }; - - return watch_app_main(_params->argc, const_cast(_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 diff --git a/atom/app/watch_runtime.h b/atom/app/watch_runtime.h index 23cdfbd45..4fbfe5619 100644 --- a/atom/app/watch_runtime.h +++ b/atom/app/watch_runtime.h @@ -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 diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index 24c6c1f0c..808e9136c 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -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 #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 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() { diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 358bcb982..6c73a24d6 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -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 observers_; @@ -266,7 +259,6 @@ class Browser : public WindowListObserver, std::unique_ptr splash_screen_; std::string start_url_; bool launched_; - bool is_electron_launch_; #endif // Whether `app.exit()` has been called diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 4320eb810..0964d4e73 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -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 NativeWindow::DraggableRegionsToSkRegion( diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 0e07787cc..f5237ecd5 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -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); diff --git a/atom/browser/native_window_observer.h b/atom/browser/native_window_observer.h index 96ac37593..76bf7dcf4 100644 --- a/atom/browser/native_window_observer.h +++ b/atom/browser/native_window_observer.h @@ -97,7 +97,6 @@ class NativeWindowObserver { // Tizen virtual void OnSuspend() {} virtual void OnResume() {} - virtual void OnAppControl() {} #endif }; diff --git a/tizen/common/application_data.cc b/tizen/common/application_data.cc index 13ecf5c88..987d3fd52 100644 --- a/tizen/common/application_data.cc +++ b/tizen/common/application_data.cc @@ -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 res_path(app_get_resource_path()); if (res_path) { diff --git a/tizen/common/application_data.h b/tizen/common/application_data.h index 0429eb063..8fecc8509 100644 --- a/tizen/common/application_data.h +++ b/tizen/common/application_data.h @@ -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 index 000000000..55eff6514 --- /dev/null +++ b/tizen/src/app/wrt_main_delegate.cc @@ -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 index 000000000..b79c09578 --- /dev/null +++ b/tizen/src/app/wrt_main_delegate.h @@ -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_ diff --git a/tizen/src/browser/api/wrt_api_core.cc b/tizen/src/browser/api/wrt_api_core.cc index c171f642a..5c8759371 100644 --- a/tizen/src/browser/api/wrt_api_core.cc +++ b/tizen/src/browser/api/wrt_api_core.cc @@ -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) { diff --git a/tizen/src/browser/api/wrt_api_core.h b/tizen/src/browser/api/wrt_api_core.h index 99eb3c0e4..c3940f5a8 100644 --- a/tizen/src/browser/api/wrt_api_core.h +++ b/tizen/src/browser/api/wrt_api_core.h @@ -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 { +class WebRuntime : public mate::EventEmitter, + public NativeWebRuntimeObserver { public: static mate::Handle Create(v8::Isolate* isolate); @@ -21,6 +23,9 @@ class WebRuntime : public mate::EventEmitter { 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 index 000000000..20c5413c4 --- /dev/null +++ b/tizen/src/browser/native_web_runtime.cc @@ -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::Create()); + browser_main_runner_ = std::unique_ptr( + 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 index 000000000..c77259356 --- /dev/null +++ b/tizen/src/browser/native_web_runtime.h @@ -0,0 +1,40 @@ +#ifndef BROWSER_NATIVE_WEB_RUNTIME_H_ +#define BROWSER_NATIVE_WEB_RUNTIME_H_ + +#include + +#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_main_runner_; + std::unique_ptr browser_main_runner_; + + base::ObserverList 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 index 000000000..8423b4fda --- /dev/null +++ b/tizen/src/browser/native_web_runtime_observer.h @@ -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_ diff --git a/tizen/src/wrt_main.cc b/tizen/src/wrt_main.cc index 32de2425a..38ccdfab8 100644 --- a/tizen/src/wrt_main.cc +++ b/tizen/src/wrt_main.cc @@ -3,24 +3,22 @@ // found in the LICENSE file. #include "wrt_main.h" -#include "tizen/common/env_variables.h" #include -#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 - #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" @@ -29,39 +27,8 @@ 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_; 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(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 flags; - for (int i = 0; i < args_count; ++i) - command_line->AppendSwitch(const_cast(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(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(¶ms); - 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(¶ms); + } + + std::unique_ptr 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(argv))) + const auto& argv = atom::AtomCommandLine::argv(); + std::vector 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(argv); - atom::AtomCommandLine::Init(argc, argv); - atom::AtomBrowserMainParts::SetNodeEnvironment(); + content::ContentMainParams params(&g_delegate); + tizen::NativeWebRuntime::GetInstance().InitializeMain(¶ms); 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(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(argv)); } } -#endif diff --git a/wrt.gyp b/wrt.gyp index 83132cac6..e0a24b37b 100644 --- a/wrt.gyp +++ b/wrt.gyp @@ -125,8 +125,13 @@ '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', diff --git a/wrt/src/runtime.js b/wrt/src/runtime.js index ae01bb358..1c13e826b 100755 --- a/wrt/src/runtime.js +++ b/wrt/src/runtime.js @@ -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) { diff --git a/wrt/src/web_application.js b/wrt/src/web_application.js index 101897f47..7505bc1ac 100644 --- a/wrt/src/web_application.js +++ b/wrt/src/web_application.js @@ -59,6 +59,7 @@ class WebApplication { setupWebWindow() {} addWebWindow(webwindow) { this.webwindows.push(webwindow); + this.focusedWebWindow = webwindow; } removeWebWindow(webwindow) { var _ref; diff --git a/wrt/src/web_window.js b/wrt/src/web_window.js index cb1f8eec2..d6d581e8a 100644 --- a/wrt/src/web_window.js +++ b/wrt/src/web_window.js @@ -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);