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>
// 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");
*/
#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());
}
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
#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
* 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
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
* 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
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
#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)
: is_quiting_(false),
#if defined(OS_TIZEN)
launched_(false),
- is_electron_launch_(false),
#endif
is_exiting_(false),
is_ready_(false),
}
}
-#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();
}
void Browser::WillFinishLaunching() {
-#if defined(OS_TIZEN)
- SetElectronAppLaunch();
-#endif
for (BrowserObserver& observer : observers_)
observer.OnWillFinishLaunching();
}
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() {
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.
void OnWindowCloseCancelled(NativeWindow* window) override;
void OnWindowAllClosed() override;
-#if defined(OS_TIZEN)
- void SetElectronAppLaunch();
-#endif
-
// Observers of the browser.
base::ObserverList<BrowserObserver> observers_;
std::unique_ptr<SplashScreen> splash_screen_;
std::string start_url_;
bool launched_;
- bool is_electron_launch_;
#endif
// Whether `app.exit()` has been called
for (NativeWindowObserver& observer : observers_)
observer.OnResume();
}
-
-void NativeWindow::NotifyAppControl()
-{
- for (NativeWindowObserver& observer : observers_)
- observer.OnAppControl();
-}
#endif
std::unique_ptr<SkRegion> NativeWindow::DraggableRegionsToSkRegion(
#if defined(OS_TIZEN)
void NotifySuspend();
void NotifyResume();
- void NotifyAppControl();
#endif
void AddObserver(NativeWindowObserver* obs) {
observers_.AddObserver(obs);
// Tizen
virtual void OnSuspend() {}
virtual void OnResume() {}
- virtual void OnAppControl() {}
#endif
};
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) {
const std::string app_id() const { return app_id_; }
ApplicationData::AppType app_type() { return app_type_; }
+ bool IsElectronApp();
+
private:
bool init();
ApplicationData::AppType GetAppType();
--- /dev/null
+#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
--- /dev/null
+#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_
#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 {
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 {
}
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) {
#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);
explicit WebRuntime(v8::Isolate* isolate);
~WebRuntime() override;
+ // NativeWebRuntimeObserver:
+ void OnStartApplication() override;
+
private:
std::string AppID() const;
std::string GetMessage() const;
--- /dev/null
+#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
--- /dev/null
+#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_
--- /dev/null
+#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_
// 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
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(¶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 = 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(¶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<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
'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',
});
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) +
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) {
setupWebWindow() {}
addWebWindow(webwindow) {
this.webwindows.push(webwindow);
+ this.focusedWebWindow = webwindow;
}
removeWebWindow(webwindow) {
var _ref;
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);