From f4ff83391bb81102199f11c2ef65e580bb0af682 Mon Sep 17 00:00:00 2001 From: "ws29.jung" Date: Wed, 25 Jul 2018 17:34:23 +0900 Subject: [PATCH 01/16] fixup! Separate Watch app implementation from TV build ttrace was accidently removed from spec file. Change-Id: I9fe7e74009128bcef8767d610ac5ac3ce820b4bf Signed-off-by: ws29.jung --- packaging/electron-efl.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/electron-efl.spec b/packaging/electron-efl.spec index 3a9137f..ba61619 100755 --- a/packaging/electron-efl.spec +++ b/packaging/electron-efl.spec @@ -48,6 +48,7 @@ BuildRequires: pkgconfig(nss) BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(uuid) +BuildRequires: pkgconfig(ttrace) BuildRequires: pkgconfig(tts) BuildRequires: pkgconfig(wgt-manifest-handlers) BuildRequires: pkgconfig(jsoncpp) -- 2.7.4 From 6ea597120e61db2be35b578241a3b9bbc2d0a321 Mon Sep 17 00:00:00 2001 From: "surya.kumar7" Date: Thu, 19 Jul 2018 13:50:00 +0530 Subject: [PATCH 02/16] Add runtime configuration to dynamically modify single process mode Single process mode can be easily altered with the help of a platform level environment flag Change-Id: Ie5b56e0b786f3221b37522ff921a495e17a9347f Signed-off-by: surya.kumar7 --- atom/app/node_main.cc | 8 ++++---- atom/browser/browser.cc | 2 ++ atom/browser/node_debugger.h | 2 +- packaging/electron-efl.spec | 5 +++++ tizen/pwrt_env.sh | 1 + tizen/src/wrt_main.cc | 5 ++--- vendor/node/src/node.cc | 6 +++--- vendor/node/src/node.h | 4 ++-- wrt.gyp | 8 ++++++++ 9 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 tizen/pwrt_env.sh diff --git a/atom/app/node_main.cc b/atom/app/node_main.cc index dbfbfae..9e80ef2 100644 --- a/atom/app/node_main.cc +++ b/atom/app/node_main.cc @@ -44,7 +44,7 @@ int NodeMain(int argc, char *argv[]) { int exec_argc; const char** exec_argv; - // node::Init(&argc, const_cast(argv), &exec_argc, &exec_argv); not called + node::Init(&argc, const_cast(argv), &exec_argc, &exec_argv); node::IsolateData isolate_data(gin_env.isolate(), loop); node::Environment* env = node::CreateEnvironment( @@ -52,9 +52,9 @@ int NodeMain(int argc, char *argv[]) { exec_argc, exec_argv); // Start our custom debugger implementation. - // NodeDebugger node_debugger(gin_env.isolate()); not called - // if (node_debugger.IsRunning()) - // env->AssignToContext(v8::Debug::GetDebugContext(gin_env.isolate())); + NodeDebugger node_debugger(gin_env.isolate()); + if (node_debugger.IsRunning()) + env->AssignToContext(v8::Debug::GetDebugContext(gin_env.isolate())); mate::Dictionary process(gin_env.isolate(), env->process_object()); #if defined(OS_WIN) diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index dcbe344..24c6c1f 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -121,6 +121,8 @@ void Browser::Shutdown() { if (base::ThreadTaskRunnerHandle::IsSet()) { if (::tizen::is_single_process) { + // TODO: If delay is not produced, child thread closure is not happening; + // engine has to be checked base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), base::TimeDelta::FromSeconds(1)); } else { diff --git a/atom/browser/node_debugger.h b/atom/browser/node_debugger.h index 4889fb2..04a4f62 100644 --- a/atom/browser/node_debugger.h +++ b/atom/browser/node_debugger.h @@ -19,7 +19,7 @@ namespace atom { // Add support for node's "--debug" switch. class NodeDebugger : public net::test_server::StreamListenSocket::Delegate { public: - explicit NodeDebugger(v8::Isolate* isolate, uv_loop_t* loop_); + explicit NodeDebugger(v8::Isolate* isolate, uv_loop_t* loop_ = uv_default_loop()); virtual ~NodeDebugger(); bool IsRunning() const; diff --git a/packaging/electron-efl.spec b/packaging/electron-efl.spec index ba61619..0e1a392 100755 --- a/packaging/electron-efl.spec +++ b/packaging/electron-efl.spec @@ -160,6 +160,10 @@ install -p -m 644 %{_out}/gen/widget.json %{buildroot}%{extension_path} # Need to remove the below line later install -p -m 644 %{_out}/lib/libwidget_plugin.so %{buildroot}%{_libdir} +# pwrt_env file +mkdir -p %{buildroot}%{_sysconfdir}/profile.d/ +install -p -m 755 %{_out}/gen/pwrt_env.sh %{buildroot}%{_sysconfdir}/profile.d/pwrt_env.sh + # screen_plugin install -p -m 644 %{_out}/lib/libsplash_screen_plugin.so %{buildroot}%{extension_path} install -p -m 644 %{_out}/gen/splash_screen.json %{buildroot}%{extension_path} @@ -200,3 +204,4 @@ rm -fr %{buildroot} # Need to remove these below lines later %attr(644,root,root) %{_libdir}/libwidget_plugin.so %attr(644,root,root) %{_libdir}/libsplash_screen_plugin.so +%attr(755,root,root) %{_sysconfdir}/profile.d/pwrt_env.sh diff --git a/tizen/pwrt_env.sh b/tizen/pwrt_env.sh new file mode 100644 index 0000000..96cb594 --- /dev/null +++ b/tizen/pwrt_env.sh @@ -0,0 +1 @@ +export PWRT_BLOCK_SINGLE_PROCESS=ON \ No newline at end of file diff --git a/tizen/src/wrt_main.cc b/tizen/src/wrt_main.cc index c32c287..f449862 100644 --- a/tizen/src/wrt_main.cc +++ b/tizen/src/wrt_main.cc @@ -9,7 +9,6 @@ #include "atom/app/atom_main_delegate.h" // NOLINT #include "content/public/app/content_main.h" -#include "atom/app/node_main.h" #include "atom/browser/atom_browser_main_parts.h" #include "atom/common/atom_command_line.h" #include "base/at_exit.h" @@ -30,7 +29,7 @@ namespace { -bool block_single_process = false; // set to true to disable single process mode altogether +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[] = { @@ -124,7 +123,7 @@ int main(int argc, char* argv[]) { int args_count = kElectronArgsCount; if (IsBrowserProcess()) { - if (!block_single_process && !isElectronWebApp()) { + if (!getenv(kBlockSingleProcess) && !isElectronWebApp()) { LOG(ERROR) << "will run in single process mode"; tizen::is_single_process = true; args_count = kTizenWebappArgsCount; diff --git a/vendor/node/src/node.cc b/vendor/node/src/node.cc index 4b54bf8..9fb3463 100644 --- a/vendor/node/src/node.cc +++ b/vendor/node/src/node.cc @@ -4440,7 +4440,7 @@ void FreeEnvironment(Environment* env) { } -inline int Start(Isolate* isolate, IsolateData* isolate_data, // not called +inline int Start(Isolate* isolate, IsolateData* isolate_data, int argc, const char* const* argv, int exec_argc, const char* const* exec_argv) { HandleScope handle_scope(isolate); @@ -4501,7 +4501,7 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data, // not called return exit_code; } -inline int Start(uv_loop_t* event_loop, // not called +inline int Start(uv_loop_t* event_loop, int argc, const char* const* argv, int exec_argc, const char* const* exec_argv) { Isolate::CreateParams params; @@ -4563,7 +4563,7 @@ int Start(int argc, char** argv) { // optional, in case you're wondering. int exec_argc; const char** exec_argv; - // Init(&argc, const_cast(argv), &exec_argc, &exec_argv); + Init(&argc, const_cast(argv), &exec_argc, &exec_argv); #if HAVE_OPENSSL if (const char* extra = secure_getenv("NODE_EXTRA_CA_CERTS")) diff --git a/vendor/node/src/node.h b/vendor/node/src/node.h index bac44b0..5890706 100644 --- a/vendor/node/src/node.h +++ b/vendor/node/src/node.h @@ -189,11 +189,11 @@ NODE_EXTERN extern bool g_standalone_mode; NODE_EXTERN extern bool g_upstream_node_mode; NODE_EXTERN int Start(int argc, char *argv[]); -NODE_EXTERN void Init(int* argc, // apart from NodeBindings::Initialize(), no one seems to call +NODE_EXTERN void Init(int* argc, const char** argv, int* exec_argc, const char*** exec_argv, - uv_loop_t* uv_loop_); + uv_loop_t* uv_loop_ = uv_default_loop()); class IsolateData; class Environment; diff --git a/wrt.gyp b/wrt.gyp index 272eb50..7fadfec 100644 --- a/wrt.gyp +++ b/wrt.gyp @@ -42,6 +42,14 @@ ], 'cflags': [ '-fPIC' ], 'cflags_cc': [ '-fPIC' ], + 'copies': [ + { + 'destination': '<(SHARED_INTERMEDIATE_DIR)', + 'files': [ + 'tizen/pwrt_env.sh', + ], + }, + ], }, # target wrt { 'target_name': 'wrt-service', -- 2.7.4 From a85e8595738a1970de7f93c048f81ed2382ee212 Mon Sep 17 00:00:00 2001 From: "surya.kumar7" Date: Thu, 26 Jul 2018 12:42:13 +0530 Subject: [PATCH 03/16] Refactor runtime object Since runtime object is not created during prelaunch, removed functions which handled such scenarios Change-Id: I3ab42b4b5b7299c8a700ee670c7c0ca3a6ab68be Signed-off-by: surya.kumar7 --- atom/app/runtime.h | 2 -- atom/app/ui_runtime.cc | 8 -------- atom/app/ui_runtime.h | 3 +-- atom/app/watch_runtime.cc | 7 ------- atom/app/watch_runtime.h | 3 +-- tizen/src/wrt_main.cc | 3 --- 6 files changed, 2 insertions(+), 24 deletions(-) diff --git a/atom/app/runtime.h b/atom/app/runtime.h index c5552fb..b5f956a 100644 --- a/atom/app/runtime.h +++ b/atom/app/runtime.h @@ -32,8 +32,6 @@ class Runtime { virtual int Exec() = 0; - virtual void SetParam(content::ContentMainParams *params) = 0; - static std::unique_ptr MakeRuntime(content::ContentMainParams *params); }; diff --git a/atom/app/ui_runtime.cc b/atom/app/ui_runtime.cc index c078f65..0b5c77e 100644 --- a/atom/app/ui_runtime.cc +++ b/atom/app/ui_runtime.cc @@ -26,7 +26,6 @@ #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" @@ -42,13 +41,6 @@ UiRuntime::UiRuntime(content::ContentMainParams *params) UiRuntime::~UiRuntime() { } -void UiRuntime::SetParam(content::ContentMainParams *params) { - if (_params) - LOG(ERROR) << "Use SetParam only when params is null"; - else - _params = params; -} - bool UiRuntime::OnCreate() { auto appdata = common::ApplicationDataManager::GetCurrentAppData(); atom::Browser::Get()->Initialize(); diff --git a/atom/app/ui_runtime.h b/atom/app/ui_runtime.h index f32086b..f39dc4e 100644 --- a/atom/app/ui_runtime.h +++ b/atom/app/ui_runtime.h @@ -29,8 +29,7 @@ class UiRuntime : public Runtime { UiRuntime(content::ContentMainParams *params); virtual ~UiRuntime(); - virtual int Exec(); - virtual void SetParam(content::ContentMainParams *params); + virtual int Exec() override; protected: virtual bool OnCreate(); diff --git a/atom/app/watch_runtime.cc b/atom/app/watch_runtime.cc index 58b4204..793356c 100644 --- a/atom/app/watch_runtime.cc +++ b/atom/app/watch_runtime.cc @@ -43,13 +43,6 @@ WatchRuntime::WatchRuntime(content::ContentMainParams *params) WatchRuntime::~WatchRuntime() { } -void WatchRuntime::SetParam(content::ContentMainParams *params) { - if (_params) - LOG(ERROR) << "Use SetParam only when params is null"; - else - _params = params; -} - bool WatchRuntime::OnCreate() { auto appdata = common::ApplicationDataManager::GetCurrentAppData(); if (appdata->splash_screen_info()) { diff --git a/atom/app/watch_runtime.h b/atom/app/watch_runtime.h index 43636bc..23cdfbd 100644 --- a/atom/app/watch_runtime.h +++ b/atom/app/watch_runtime.h @@ -30,8 +30,7 @@ class WatchRuntime : public Runtime { WatchRuntime(content::ContentMainParams *params); virtual ~WatchRuntime(); - virtual int Exec(); - virtual void SetParam(content::ContentMainParams *params); + virtual int Exec() override; protected: virtual bool OnCreate(); diff --git a/tizen/src/wrt_main.cc b/tizen/src/wrt_main.cc index f449862..32de242 100644 --- a/tizen/src/wrt_main.cc +++ b/tizen/src/wrt_main.cc @@ -145,9 +145,6 @@ int main(int argc, char* argv[]) { if (hasTizenPackageID(argc,argv)) { // TODO: Check to be removed later elm_init(argc, argv); runtime_ = runtime::Runtime::MakeRuntime(¶ms); - if (g_initialized_) { - runtime_->SetParam(¶ms); - } return runtime_->Exec(); } #endif -- 2.7.4 From 3e58f27649209936f44aa63a83d855587f95be11 Mon Sep 17 00:00:00 2001 From: Prathmesh Date: Tue, 24 Jul 2018 15:56:44 +0530 Subject: [PATCH 04/16] Make wrt target separate from the main target Make main target as none, so that libs can be generated separately if required, else all the .so needs to be statically linked with wrt target Change-Id: I149b467e1ba4c2b152f73388fb44d830a29ae246 Signed-off-by: Prathmesh --- packaging/electron-efl.spec | 9 +-------- script/update.py | 2 +- wrt.gyp | 2 -- wrt_all.gyp | 13 +++++++++++++ 4 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 wrt_all.gyp diff --git a/packaging/electron-efl.spec b/packaging/electron-efl.spec index 0e1a392..ea9690e 100755 --- a/packaging/electron-efl.spec +++ b/packaging/electron-efl.spec @@ -103,7 +103,7 @@ DEFINE_ARGS+=" -v %endif -./script/build.py -c D -t wrt +./script/build.py -c D -t wrt_all %install install -d %{_out}/packaging @@ -157,8 +157,6 @@ install -p -m 755 %{_out}/lib/libxwalk_injected_bundle.so %{buildroot}%{_libdir} # widget plugin install -p -m 644 %{_out}/lib/libwidget_plugin.so %{buildroot}%{extension_path} install -p -m 644 %{_out}/gen/widget.json %{buildroot}%{extension_path} -# Need to remove the below line later -install -p -m 644 %{_out}/lib/libwidget_plugin.so %{buildroot}%{_libdir} # pwrt_env file mkdir -p %{buildroot}%{_sysconfdir}/profile.d/ @@ -167,8 +165,6 @@ install -p -m 755 %{_out}/gen/pwrt_env.sh %{buildroot}%{_sysconfdir}/profile.d/p # screen_plugin install -p -m 644 %{_out}/lib/libsplash_screen_plugin.so %{buildroot}%{extension_path} install -p -m 644 %{_out}/gen/splash_screen.json %{buildroot}%{extension_path} -# Need to remove the below line later -install -p -m 644 %{_out}/lib/libsplash_screen_plugin.so %{buildroot}%{_libdir} %post # FIXME: Until electron-efl is released to platform, @@ -201,7 +197,4 @@ rm -fr %{buildroot} %attr(644,root,root) %{extension_path}/widget.json %attr(644,root,root) %{extension_path}/libsplash_screen_plugin.so %attr(644,root,root) %{extension_path}/splash_screen.json -# Need to remove these below lines later -%attr(644,root,root) %{_libdir}/libwidget_plugin.so -%attr(644,root,root) %{_libdir}/libsplash_screen_plugin.so %attr(755,root,root) %{_sysconfdir}/profile.d/pwrt_env.sh diff --git a/script/update.py b/script/update.py index 5c9c957..08bdf58 100755 --- a/script/update.py +++ b/script/update.py @@ -98,7 +98,7 @@ def run_gyp(target_arch, component): if 'use_efl=1' in [d.strip() for d in args.defines.split(' ')]: return subprocess.call([python, gyp, '-f', generator, '--depth', '.', - 'wrt.gyp', '-I' + os.path.join('tizen', 'common.gypi')] + defines, env=env) + 'wrt_all.gyp', '-I' + os.path.join('tizen', 'common.gypi')] + defines, env=env) return subprocess.call([python, gyp, '-f', generator, '--depth', '.', 'electron.gyp', '-Icommon.gypi'] + defines, env=env) diff --git a/wrt.gyp b/wrt.gyp index 7fadfec..83132ca 100644 --- a/wrt.gyp +++ b/wrt.gyp @@ -14,8 +14,6 @@ 'wrt-service', '<(DEPTH)/tizen/common/common.gyp:wrt_common', '<(DEPTH)/tizen/loader/loader.gyp:wrt-loader', - '<(DEPTH)/tizen/extensions/extensions.gyp:widget_plugin', - '<(DEPTH)/tizen/extensions/extensions.gyp:splash_screen_plugin', '<(DEPTH)/tizen/renderer/injected_bundle.gyp:xwalk_injected_bundle', '<(DEPTH)/efl/build/system.gyp:ecore', '<(DEPTH)/efl/build/system.gyp:launchpad', diff --git a/wrt_all.gyp b/wrt_all.gyp new file mode 100644 index 0000000..31b6291 --- /dev/null +++ b/wrt_all.gyp @@ -0,0 +1,13 @@ +{ + 'targets': [ + { + 'target_name': 'wrt_all', + 'type': 'none', + 'dependencies': [ + '<(DEPTH)/tizen/extensions/extensions.gyp:widget_plugin', + '<(DEPTH)/tizen/extensions/extensions.gyp:splash_screen_plugin', + '<(DEPTH)/wrt.gyp:wrt', + ], + }, # end of target 'wrt_all' + ], # end of targets +} \ No newline at end of file -- 2.7.4 From 991b30c36bfbb645fd37ae118b622486a0fec206 Mon Sep 17 00:00:00 2001 From: SangYong Park Date: Wed, 25 Jul 2018 18:44:31 +0900 Subject: [PATCH 05/16] 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 --- atom/app/atom_main_delegate.cc | 9 -- atom/app/runtime.cc | 24 ++-- atom/app/runtime.h | 13 +- atom/app/ui_runtime.cc | 95 +++++--------- atom/app/ui_runtime.h | 21 ++- atom/app/watch_runtime.cc | 104 +++++---------- atom/app/watch_runtime.h | 21 ++- atom/browser/browser.cc | 22 +--- atom/browser/browser.h | 8 -- atom/browser/native_window.cc | 6 - atom/browser/native_window.h | 1 - atom/browser/native_window_observer.h | 1 - tizen/common/application_data.cc | 10 ++ tizen/common/application_data.h | 2 + tizen/src/app/wrt_main_delegate.cc | 62 +++++++++ tizen/src/app/wrt_main_delegate.h | 26 ++++ tizen/src/browser/api/wrt_api_core.cc | 10 +- tizen/src/browser/api/wrt_api_core.h | 7 +- tizen/src/browser/native_web_runtime.cc | 56 ++++++++ tizen/src/browser/native_web_runtime.h | 40 ++++++ tizen/src/browser/native_web_runtime_observer.h | 15 +++ tizen/src/wrt_main.cc | 167 ++++++++---------------- wrt.gyp | 5 + wrt/src/runtime.js | 29 ++-- wrt/src/web_application.js | 1 + wrt/src/web_window.js | 4 - 26 files changed, 409 insertions(+), 350 deletions(-) create mode 100644 tizen/src/app/wrt_main_delegate.cc create mode 100644 tizen/src/app/wrt_main_delegate.h create mode 100644 tizen/src/browser/native_web_runtime.cc create mode 100644 tizen/src/browser/native_web_runtime.h create mode 100644 tizen/src/browser/native_web_runtime_observer.h diff --git a/atom/app/atom_main_delegate.cc b/atom/app/atom_main_delegate.cc index b88049f..0358e7d 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 6e27d1a..157755a 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 b5f956a..d07c56e 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 0b5c77e..186b765 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 f39dc4e..d86818b 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 793356c..d32b51f 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 23cdfbd..4fbfe56 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 24c6c1f..808e913 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 358bcb9..6c73a24 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 4320eb8..0964d4e 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 0e07787..f5237ec 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 96ac375..76bf7dc 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 13ecf5c..987d3fd 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 0429eb0..8fecc85 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 0000000..55eff65 --- /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 0000000..b79c095 --- /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 c171f64..5c87593 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 99eb3c0..c3940f5 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 0000000..20c5413 --- /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 0000000..c772593 --- /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 0000000..8423b4f --- /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 32de242..38ccdfa 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 83132ca..e0a24b3 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 ae01bb3..1c13e82 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 101897f..7505bc1 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 cb1f8ee..d6d581e 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); -- 2.7.4 From 2e83697aff70fde91e30670e02fe3247ad631d35 Mon Sep 17 00:00:00 2001 From: SangYong Park Date: Tue, 7 Aug 2018 13:30:40 +0900 Subject: [PATCH 06/16] Make build directory depending on profile . make build directory depending on profile . change build dependency (dbus-glib-1 -> dbus-1) . fix build warning Change-Id: I829394b076f187b51b9246ad7b47a3f631febf54 Signed-off-by: SangYong Park --- packaging/electron-efl.spec | 11 +++++++++-- script/build.py | 4 ++-- script/update.py | 2 -- tizen/extensions/renderer/xwalk_module_system.cc | 2 +- tizen/extensions/renderer/xwalk_v8tools_module.cc | 5 ++++- tizen/script/build | 12 ++++++++++-- 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/packaging/electron-efl.spec b/packaging/electron-efl.spec index ea9690e..54ecad2 100755 --- a/packaging/electron-efl.spec +++ b/packaging/electron-efl.spec @@ -27,7 +27,7 @@ BuildRequires: pkgconfig(capi-system-system-settings) BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(chromium-efl) BuildRequires: pkgconfig(cynara-client) -BuildRequires: pkgconfig(dbus-glib-1) +BuildRequires: pkgconfig(dbus-1) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(ecore) BuildRequires: pkgconfig(ecore-evas) @@ -74,10 +74,17 @@ cp %{SOURCE1001} . %define _icondir %TZ_SYS_RO_APP/%{_pkgid}/shared/res %define _pkgid org.tizen.%{name} %define _xmldir %TZ_SYS_RO_PACKAGES -%define _out out.tizen/out/D %define _resourcedir /opt/usr/home/owner/data/wrt %define extension_path %{_libdir}/tizen-extensions-crosswalk +%define _build_config D +%if "%{?outputdir}" != "" +%define _out %outputdir/out/%_build_config +export GYP_GENERATOR_OUTPUT=%outputdir +%else +%define _out out.tizen/out/%_build_config +%endif + DEFINE_ARGS=" libchromiumcontent_component=1 use_efl=1 diff --git a/script/build.py b/script/build.py index 80f266d..05dff2f 100755 --- a/script/build.py +++ b/script/build.py @@ -27,8 +27,8 @@ def main(): args = parse_args() for config in args.configuration: - if PLATFORM == 'tizen': - build_path = os.path.join('out.tizen', 'out', config[0]) + if PLATFORM == 'tizen' and os.environ.has_key('GYP_GENERATOR_OUTPUT'): + build_path = os.path.join(os.environ.get('GYP_GENERATOR_OUTPUT'), 'out', config[0]) else: build_path = os.path.join('out', config[0]) ret = subprocess.call([ninja, '-C', build_path, args.target]) diff --git a/script/update.py b/script/update.py index 08bdf58..a82822a 100755 --- a/script/update.py +++ b/script/update.py @@ -61,8 +61,6 @@ def run_gyp(target_arch, component): env['GYP_CROSSCOMPILE'] = '1' elif PLATFORM == 'win32': env['GYP_MSVS_VERSION'] = '2015' - elif PLATFORM == 'tizen': - env['GYP_GENERATOR_OUTPUT'] = os.path.join(SOURCE_ROOT, 'out.tizen') python = sys.executable if sys.platform == 'cygwin': # Force using win32 python on cygwin. diff --git a/tizen/extensions/renderer/xwalk_module_system.cc b/tizen/extensions/renderer/xwalk_module_system.cc index 2218188..0cba12f 100644 --- a/tizen/extensions/renderer/xwalk_module_system.cc +++ b/tizen/extensions/renderer/xwalk_module_system.cc @@ -517,7 +517,7 @@ void XWalkModuleSystem::EnsureExtensionNamespaceIsReadOnly( v8::Handle v8_extension_name( v8::String::NewFromUtf8(context->GetIsolate(), basename.c_str())); value.As()->ForceSet( - v8_extension_name, value.As()->Get(v8_extension_name), + context, v8_extension_name, value.As()->Get(v8_extension_name), v8::ReadOnly); } diff --git a/tizen/extensions/renderer/xwalk_v8tools_module.cc b/tizen/extensions/renderer/xwalk_v8tools_module.cc index 4fcad37..1d8ce93 100644 --- a/tizen/extensions/renderer/xwalk_v8tools_module.cc +++ b/tizen/extensions/renderer/xwalk_v8tools_module.cc @@ -18,7 +18,10 @@ void ForceSetPropertyCallback( if (info.Length() != 3 || !info[0]->IsObject() || !info[1]->IsString()) { return; } - info[0].As()->ForceSet(info[1], info[2]); + v8::Isolate* isolate = info.GetIsolate(); + v8::HandleScope handle_scope(isolate); + v8::Local context = isolate->GetCurrentContext(); + info[0].As()->ForceSet(context, info[1], info[2]); } // ================ diff --git a/tizen/script/build b/tizen/script/build index 22091bd..8ea059c 100755 --- a/tizen/script/build +++ b/tizen/script/build @@ -122,6 +122,7 @@ def build_gbs(profile, force_bootstrap, verbose): print 'Build : profile=' + profile + ' architecture=' + arch command = ['gbs', '--conf', os.path.join(SCRIPT_PATH, 'gbs.conf'), 'build', '-P', profile, '--include-all', '-A', arch, '--incremental'] + command.extend(['--define=outputdir ' + get_output_dir(profile)]) if not force_bootstrap and not need_bootstrap(profile): command.extend(['--define=skipbootstrap 1']) return True if subprocess.call(command) == 0 else False @@ -131,15 +132,22 @@ def find_architecture(profile): return 'armv7l' values = profile.split('_') arch = values[-1] if values[-1] != 'mirror' else values[-2] - arch = arch if arch != 'ia32' else 'i586' + if arch == 'standard': + return 'armv7l' + elif arch == 'ia32': + return 'i586' return arch +def get_output_dir(profile): + values = profile.split('_') + return 'out.' + '_'.join(values if values[-1] != 'mirror' else values[:-1]) + def need_bootstrap(profile): # TODO: condition improvement is necessary if profile == 'desktop': if os.path.isdir(os.path.join(ROOT_PATH, 'out')): return False - elif os.path.isdir(os.path.join(ROOT_PATH, 'out.tizen', 'out')): + elif os.path.isdir(os.path.join(ROOT_PATH, get_output_dir(profile), 'out')): return False return True -- 2.7.4 From 5d9055982a0083772db28c96fc147f5d38c99e53 Mon Sep 17 00:00:00 2001 From: "jaekuk, lee" Date: Tue, 7 Aug 2018 14:04:24 +0900 Subject: [PATCH 07/16] Change the default value of block_sing_process to OFF Change-Id: I886ae28eaa5cb651e8ab601397f5bc3ae6a52e46 Signed-off-by: jaekuk, lee --- tizen/pwrt_env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 tizen/pwrt_env.sh diff --git a/tizen/pwrt_env.sh b/tizen/pwrt_env.sh old mode 100644 new mode 100755 index 96cb594..ebf59d6 --- a/tizen/pwrt_env.sh +++ b/tizen/pwrt_env.sh @@ -1 +1 @@ -export PWRT_BLOCK_SINGLE_PROCESS=ON \ No newline at end of file +export PWRT_BLOCK_SINGLE_PROCESS=OFF \ No newline at end of file -- 2.7.4 From 89ba8e6e857e26ab3eddf3ae7adfaf8c0c7bd21b Mon Sep 17 00:00:00 2001 From: SangYong Park Date: Thu, 9 Aug 2018 10:59:46 +0900 Subject: [PATCH 08/16] Fix build break Fix build break when outputdir is not defined. Change-Id: I5beec25729a81fee527542c92c9a9bf54a13ff4e Signed-off-by: SangYong Park --- packaging/electron-efl.spec | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packaging/electron-efl.spec b/packaging/electron-efl.spec index 54ecad2..137348e 100755 --- a/packaging/electron-efl.spec +++ b/packaging/electron-efl.spec @@ -77,13 +77,12 @@ cp %{SOURCE1001} . %define _resourcedir /opt/usr/home/owner/data/wrt %define extension_path %{_libdir}/tizen-extensions-crosswalk +%if "%{?outputdir}" == "" +%define outputdir out.tizen +%endif %define _build_config D -%if "%{?outputdir}" != "" %define _out %outputdir/out/%_build_config export GYP_GENERATOR_OUTPUT=%outputdir -%else -%define _out out.tizen/out/%_build_config -%endif DEFINE_ARGS=" libchromiumcontent_component=1 -- 2.7.4 From 3f6318228ce38383928be2bc5bad36f478e09765 Mon Sep 17 00:00:00 2001 From: guneet khosla Date: Thu, 16 Aug 2018 17:48:15 +0530 Subject: [PATCH 09/16] Generate |UserAgent| without "demo/0.1.0" Earlier, "demo/0.1.0" was appended in |UserAgent|. This caused failures in tct-workers-w3c-tests. Change-Id: I017556e0d0d8f1da2b89b2c589b06438522c0038 Signed-off-by: guneet khosla --- atom/browser/atom_browser_context.cc | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/atom/browser/atom_browser_context.cc b/atom/browser/atom_browser_context.cc index 76a23cd..a2ad39f 100644 --- a/atom/browser/atom_browser_context.cc +++ b/atom/browser/atom_browser_context.cc @@ -79,16 +79,8 @@ AtomBrowserContext::AtomBrowserContext(const std::string& partition, Browser* browser = Browser::Get(); std::string name = RemoveWhitespace(browser->GetName()); std::string user_agent; - if (name == ATOM_PRODUCT_NAME) { - user_agent = "Chrome/" CHROME_VERSION_STRING " " - ATOM_PRODUCT_NAME "/" ATOM_VERSION_STRING; - } else { - user_agent = base::StringPrintf( - "%s/%s Chrome/%s " ATOM_PRODUCT_NAME "/" ATOM_VERSION_STRING, - name.c_str(), - browser->GetVersion().c_str(), - CHROME_VERSION_STRING); - } + user_agent = "Chrome/" CHROME_VERSION_STRING " " + ATOM_PRODUCT_NAME "/" ATOM_VERSION_STRING; user_agent_ = content::BuildUserAgentFromProduct(user_agent); // Read options. -- 2.7.4 From 6fed38c7b1903f3e3e6fbed5dc257fbde1d99052 Mon Sep 17 00:00:00 2001 From: "prathmesh.m" Date: Thu, 16 Aug 2018 18:21:49 +0530 Subject: [PATCH 10/16] Send terminate event to engine - Pass the onTerminate to engine Change-Id: Ic62b385182fc65e5fd54ae7ca1ec227565e9e16b Signed-off-by: prathmesh.m --- atom/app/ui_runtime.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/atom/app/ui_runtime.cc b/atom/app/ui_runtime.cc index 186b765..7f76282 100644 --- a/atom/app/ui_runtime.cc +++ b/atom/app/ui_runtime.cc @@ -45,6 +45,7 @@ bool UiRuntime::OnCreate() { void UiRuntime::OnTerminate() { LOG(INFO) << "OnTerminate()"; + atom::Browser::Get()->Quit(); } void UiRuntime::OnPause() { -- 2.7.4 From 2bcaa52c70a4af64761831276de95b9fa111a506 Mon Sep 17 00:00:00 2001 From: "jaekuk, lee" Date: Fri, 17 Aug 2018 17:31:15 +0900 Subject: [PATCH 11/16] Fix the issue that add-on doesn't work - Define noExtensions of options - Don't create WebApplication class when launching Electron app Change-Id: I0dfb8b1d33c66c3da956e8da307499ee980badac Signed-off-by: jaekuk, lee --- tizen/src/browser/api/wrt_api_core.cc | 2 ++ wrt/src/main.js | 4 +++- wrt/src/runtime.js | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) mode change 100644 => 100755 tizen/src/browser/api/wrt_api_core.cc mode change 100644 => 100755 wrt/src/main.js diff --git a/tizen/src/browser/api/wrt_api_core.cc b/tizen/src/browser/api/wrt_api_core.cc old mode 100644 new mode 100755 index 5c87593..e58d525 --- a/tizen/src/browser/api/wrt_api_core.cc +++ b/tizen/src/browser/api/wrt_api_core.cc @@ -90,6 +90,8 @@ bool WebRuntime::isTizenWebApp() const { bool WebRuntime::isElectronLaunch() const { auto app_data = common::ApplicationDataManager::GetCurrentAppData(); + if (!app_data) + return false; return app_data->IsElectronApp(); } diff --git a/wrt/src/main.js b/wrt/src/main.js old mode 100644 new mode 100755 index b84ef59..d00a8c4 --- a/wrt/src/main.js +++ b/wrt/src/main.js @@ -29,6 +29,7 @@ let parseCommandLine = function() { options.alias('h', 'help').boolean('h').describe('h', 'Print this usage message.'); options.alias('p', 'path').string('p').describe('p', 'Set contents path to load'); options.alias('s', 'window-size').string('s').describe('s', 'Set the window size'); + options.alias('E', 'no-extensions').boolean('E').describe('E', 'Do not load extensions'); let args = options.argv; if (args.help) { process.stdout.write(options.help()); @@ -39,7 +40,8 @@ let parseCommandLine = function() { appID: args.a, devMode: args.d, path: args.p, - windowSize: args.s + windowSize: args.s, + noExtensions: args.E }; }; diff --git a/wrt/src/runtime.js b/wrt/src/runtime.js index 1c13e82..c4813c9 100755 --- a/wrt/src/runtime.js +++ b/wrt/src/runtime.js @@ -60,9 +60,12 @@ class Runtime { app.once('ready', function(event) { runtime_debug('ready'); _this.extensionManager = new ExtensionManager(EXTENSIONS_PATH); - if (!options.noExtensions) { + if (!options.noExtensions) { _this.extensionManager.build(); } + if (wrt.isElectronLaunch()) { + return; + } _this.webApplication = new WebApplication(options); }); wrt.on('start-app', function() { -- 2.7.4 From 9e3af881c5133a126c01c95d95f97421ee63f84e Mon Sep 17 00:00:00 2001 From: "k2.nagaraju" Date: Mon, 20 Aug 2018 12:52:17 +0530 Subject: [PATCH 12/16] Enable encrypted app support. Use |WrtFileProtocolHandler| for handling the file schemas. Change-Id: Ia39034af94d7ebd332e7b9e1d38924499f5cafd9 Signed-off-by: k2.nagaraju --- atom/browser/atom_browser_context.cc | 25 ++++++++++++++++++---- .../wrt/wrt_file_protocol_handler.h | 13 ++++------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/atom/browser/atom_browser_context.cc b/atom/browser/atom_browser_context.cc index a2ad39f..0d56c5f 100644 --- a/atom/browser/atom_browser_context.cc +++ b/atom/browser/atom_browser_context.cc @@ -44,6 +44,10 @@ #include "net/url_request/url_request_intercepting_job_factory.h" #include "url/url_constants.h" +#if defined(OS_TIZEN) +#include "tizen_src/ewk/efl_integration/wrt/wrt_file_protocol_handler.h" +#endif + using content::BrowserThread; namespace atom { @@ -126,10 +130,23 @@ AtomBrowserContext::CreateURLRequestJobFactory( base::WrapUnique(new AboutProtocolHandler)); job_factory->SetProtocolHandler( url::kDataScheme, base::WrapUnique(new net::DataProtocolHandler)); - job_factory->SetProtocolHandler( - url::kFileScheme, base::WrapUnique(new asar::AsarProtocolHandler( - BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( - base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)))); +#if defined(OS_TIZEN) + auto app_data = common::ApplicationDataManager::GetCurrentAppData(); + if (app_data && app_data->IsElectronApp()) { +#endif + job_factory->SetProtocolHandler( + url::kFileScheme, base::WrapUnique(new asar::AsarProtocolHandler( + BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( + base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)))); +#if defined(OS_TIZEN) + } else { + job_factory->SetProtocolHandler( + url::kFileScheme, base::WrapUnique(new net::WrtFileProtocolHandler( + BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( + base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)))); + } +#endif + job_factory->SetProtocolHandler( url::kHttpScheme, base::WrapUnique(new HttpProtocolHandler(url::kHttpScheme))); diff --git a/vendor/brightray/vendor/libchromiumcontent/src/tizen_src/ewk/efl_integration/wrt/wrt_file_protocol_handler.h b/vendor/brightray/vendor/libchromiumcontent/src/tizen_src/ewk/efl_integration/wrt/wrt_file_protocol_handler.h index 6fab49f..2fd9a90 100644 --- a/vendor/brightray/vendor/libchromiumcontent/src/tizen_src/ewk/efl_integration/wrt/wrt_file_protocol_handler.h +++ b/vendor/brightray/vendor/libchromiumcontent/src/tizen_src/ewk/efl_integration/wrt/wrt_file_protocol_handler.h @@ -19,21 +19,16 @@ namespace net { class NetworkDelegate; class URLRequestJob; -class WrtFileProtocolHandler +class __attribute__((visibility("default"))) WrtFileProtocolHandler : public URLRequestJobFactory::ProtocolHandler { public: explicit WrtFileProtocolHandler( - const scoped_refptr& file_task_runner) - : file_task_runner_(file_task_runner) {} - ~WrtFileProtocolHandler() override {} + const scoped_refptr& file_task_runner); + ~WrtFileProtocolHandler() override; URLRequestJob* MaybeCreateJob( URLRequest* request, NetworkDelegate* network_delegate) const override; - /* LCOV_EXCL_START */ - bool IsSafeRedirectTarget(const GURL& location) const override { - return false; - } - /* LCOV_EXCL_STOP */ + bool IsSafeRedirectTarget(const GURL& location) const override; private: bool GetWrtParsedUrl(const GURL& url, GURL& parsed_url) const; -- 2.7.4 From e27feba669b2cd9d5985d90179c0f4d3bd279480 Mon Sep 17 00:00:00 2001 From: "k2.nagaraju" Date: Fri, 31 Aug 2018 15:34:49 +0530 Subject: [PATCH 13/16] Send |WrtViewMsg_ResumeScheduledTasks| IPC only if webview is suspended. With this patch approximately 100 to 150ms time is reducing. Change-Id: I77404f90de3784b262fd3d9bc7239fe0d1b28bb9 Signed-off-by: k2.nagaraju --- tizen/browser/tizen_browser_parts.cc | 9 ++++++--- tizen/browser/tizen_browser_parts.h | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tizen/browser/tizen_browser_parts.cc b/tizen/browser/tizen_browser_parts.cc index 41bf8d5..d7c882a 100644 --- a/tizen/browser/tizen_browser_parts.cc +++ b/tizen/browser/tizen_browser_parts.cc @@ -57,7 +57,8 @@ static bool ProcessWellKnownScheme(const std::string& url) { } // namespace TizenBrowserParts::TizenBrowserParts() - : locale_manager_(new common::LocaleManager()) { + : locale_manager_(new common::LocaleManager()), + is_suspended_(false) { } void TizenBrowserParts::Initialize() { @@ -123,16 +124,18 @@ void TizenBrowserParts::RenderViewCreated(content::RenderViewHost* render_view_h } void TizenBrowserParts::Suspend(content::RenderViewHost* rvh) { - if(!rvh) + if (is_suspended_ || !rvh) return; + is_suspended_ = true; rvh->Send(new WrtViewMsg_SuspendScheduledTask(rvh->GetRoutingID())); } void TizenBrowserParts::Resume(content::RenderViewHost* rvh) { - if(!rvh) + if (!is_suspended_ || !rvh) return; + is_suspended_ = false; rvh->Send(new WrtViewMsg_ResumeScheduledTasks(rvh->GetRoutingID())); } diff --git a/tizen/browser/tizen_browser_parts.h b/tizen/browser/tizen_browser_parts.h index 3ef4c97..19b7072 100644 --- a/tizen/browser/tizen_browser_parts.h +++ b/tizen/browser/tizen_browser_parts.h @@ -52,6 +52,7 @@ class TizenBrowserParts { common::ApplicationData* app_data_; int security_model_version_; + bool is_suspended_; std::string csp_rule_; std::string csp_report_rule_; }; -- 2.7.4 From 020a05f255f2af697b2e858f181153315eee1dd1 Mon Sep 17 00:00:00 2001 From: Suneel Kota Date: Thu, 20 Sep 2018 18:18:41 +0530 Subject: [PATCH 14/16] Add popup support for runtime and impl to allow cert erros this patch adds the popup support, it also adds the required implementation for providing option to ALLOW or DENY when certificate error occurs and remember the old option selected. Change-Id: Ie479998172322434ad2d948bbacfe91bf00675ac Signed-off-by: Suneel Kota --- atom/browser/api/atom_api_app.cc | 71 ++++++- atom/browser/api/atom_api_app.h | 5 + tizen/common/constants.cc | 1 + tizen/common/constants.h | 1 + tizen/src/browser/popup.cc | 381 ++++++++++++++++++++++++++++++++++++++ tizen/src/browser/popup.h | 106 +++++++++++ tizen/src/browser/popup_string.cc | 67 +++++++ tizen/src/browser/popup_string.h | 58 ++++++ wrt.gyp | 4 + 9 files changed, 693 insertions(+), 1 deletion(-) create mode 100644 tizen/src/browser/popup.cc create mode 100644 tizen/src/browser/popup.h create mode 100644 tizen/src/browser/popup_string.cc create mode 100644 tizen/src/browser/popup_string.h diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 1471c86..e5e0571 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -51,7 +51,21 @@ #include "base/strings/utf_string_conversions.h" #endif +#include "tizen/src/browser/popup.h" +#include "tizen/src/browser/popup_string.h" +#include "atom/browser/native_window_efl.h" + +#include "common/app_db.h" + using atom::Browser; +namespace { + const char* kCertificateAllowPrefix = "__WRT_CERTIPERM_"; + const char* kDbInitedCheckKey = "__WRT_DB_INITED__"; + const char* kDBPublicSection = "public"; + const char* kDBPrivateSection = "private"; + const char* kReadOnlyPrefix = "_READONLY_KEY_"; +} // namespace + namespace mate { @@ -620,6 +634,7 @@ void App::AllowCertificateError( bool expired_previous_decision, const base::Callback& callback) { + LOG(ERROR)<<__FUNCTION__; if (!::tizen::is_single_process) v8::Locker locker(isolate()); v8::HandleScope handle_scope(isolate()); @@ -630,9 +645,63 @@ void App::AllowCertificateError( ssl_info.cert, callback); + std::string pem_certificate; + if (!net::X509Certificate::GetPEMEncoded(ssl_info.cert->os_cert_handle(), &pem_certificate)) { + LOG(INFO) << "Certificate for URL: " << request_url.spec() << " could not be opened"; + callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL); + return; + } + // Deny the certificate by default. - if (!prevent_default) + /* if (!prevent_default) callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); + else*/ + //callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CONTINUE); + + + AllowCertificateDialog(web_contents, request_url.spec(), pem_certificate, callback); +} +void App::AllowCertificateDialog(content::WebContents* web_contents, + const std::string& url, + const std::string& pem, + const base::Callback& + callback) { + auto db = common::AppDB::GetInstance(); + std::string reminder = + db->Get(kDBPrivateSection, kCertificateAllowPrefix + pem); + if (reminder == "allowed") { + callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CONTINUE); + return; + } else if (reminder == "denied") { + callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); + return; + } + + + Evas_Object* window = static_cast(atom::NativeWindow::FromWebContents(web_contents))->evas_object(); + runtime::Popup* popup = runtime::Popup::CreatePopup(window); + popup->SetButtonType(runtime::Popup::ButtonType::AllowDenyButton); + popup->SetTitle(runtime::popup_string::kPopupTitleCert); + popup->SetBody(runtime::popup_string::GetText(runtime::popup_string::kPopupBodyCert) + "\n\n" + url); + popup->SetCheckBox(runtime::popup_string::kPopupCheckRememberPreference); + popup->SetResultHandler( + [db, callback, pem](runtime::Popup* popup, void* /*user_data*/) { + //[db, result_handler, pem](Popup* popup, void* /*user_data*/) { + bool result = popup->GetButtonResult(); + bool remember = popup->GetCheckBoxResult(); + if (remember) { + LOG(ERROR)<<"pem: "<Set(kDBPrivateSection, kCertificateAllowPrefix + pem, + result ? "allowed" : "denied"); + + } + if(result) + callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CONTINUE); + else + callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); + }, + this); + popup->Show(); } void App::SelectClientCertificate( diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index a87b88b..b8ecc6f 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -108,6 +108,11 @@ class App : public AtomBrowserClient::Delegate, bool expired_previous_decision, const base::Callback& callback) override; +void AllowCertificateDialog(content::WebContents* web_contents, + const std::string& url, + const std::string& pem, + const base::Callback& + callback); void SelectClientCertificate( content::WebContents* web_contents, net::SSLCertRequestInfo* cert_request_info, diff --git a/tizen/common/constants.cc b/tizen/common/constants.cc index 59f9b7a..660058e 100644 --- a/tizen/common/constants.cc +++ b/tizen/common/constants.cc @@ -21,5 +21,6 @@ namespace runtime { const char kAppDBRuntimeSection[] = "Runtime"; const char kAppDBRuntimeBundle[] = "encoded_bundle"; +const char kTextDomainRuntime[] = "xwalk"; } // namespace runtime diff --git a/tizen/common/constants.h b/tizen/common/constants.h index bada698..0c6aa96 100644 --- a/tizen/common/constants.h +++ b/tizen/common/constants.h @@ -19,6 +19,7 @@ namespace runtime { extern const char kAppDBRuntimeSection[]; extern const char kAppDBRuntimeBundle[]; +extern const char kTextDomainRuntime[]; } // namespace runtime diff --git a/tizen/src/browser/popup.cc b/tizen/src/browser/popup.cc new file mode 100644 index 0000000..198cf49 --- /dev/null +++ b/tizen/src/browser/popup.cc @@ -0,0 +1,381 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "tizen/src/browser/popup.h" + +//#include "common/logger.h" +#include "atom/browser/native_window.h" +#include "tizen/src/browser/popup_string.h" +#include "tizen/common/constants.h" + +namespace runtime { + +namespace { + +const char* kWRTEdjePath = "/usr/share/edje/xwalk/xwalk_tizen.edj"; + +#ifdef MODEL_FORMFACTOR_CIRCLE +const char* kWRTIconDeletePath = "/usr/share/icons/xwalk/tw_ic_popup_btn_delete.png"; +const char* kWRTIconCheckPath = "/usr/share/icons/xwalk/tw_ic_popup_btn_check.png"; + +const char* kLayoutTheme = "content/circle/buttons2"; +const char* kContentTitle = "elm.text.title"; +const char* kContentText = "elm.text"; + +const char* kStylePopup = "circle"; +const char* kStyleCheck = "small"; +const char* kStyleButtonLeft = "popup/circle/left"; +const char* kStyleButtonRight = "popup/circle/right"; +#else +const char* kContentTitle = "title,text"; +const char* kContentText = NULL; + +const char* kStylePopup = "default"; +const char* kStyleCheck = "default"; +const char* kStyleButtonLeft = "popup"; +const char* kStyleButtonRight = "popup"; +#endif // MODEL_FORMFACTOR_CIRCLE + +const char* kContentButton1 = "button1"; +const char* kContentButton2 = "button2"; + +const char* kStyleLabel = "popup/default"; +const char* kStyleButton = "popup"; +const char* kStyleEditPw = "editfield/password/popup"; + +const char* kSignalEdit = "elm,action,hide,search_icon"; + +const char* kStateActivated = "activated"; +const char* kStateClicked = "clicked"; + +static void ButtonClickedCallback(void* data, + Evas_Object* obj, void* /*eventInfo*/) { + Popup* popup = static_cast(data); + if (!popup) { + LOG(ERROR) << "Fail to get Popup instance"; + return; + } + popup->Result(popup->IsPositiveButton(obj)); + popup->Hide(); +} + +// caution: not Evas_Object* but Popup* +static Evas_Object* AddButton(Popup* popup, const char* str_id, + const char* content, + const char* style_button) { + Evas_Object* btn = elm_button_add(popup->popup()); + elm_object_style_set(btn, style_button); + elm_object_domain_translatable_part_text_set(btn, 0, + kTextDomainRuntime, + str_id); + elm_object_part_content_set(popup->popup(), content, btn); + evas_object_smart_callback_add(btn, kStateClicked, + ButtonClickedCallback, popup); +#ifdef MODEL_FORMFACTOR_CIRCLE + Evas_Object* icon = elm_image_add(btn); + if (!strcmp(content, kContentButton1)) { + elm_image_file_set(icon, kWRTIconDeletePath, NULL); + } else { + elm_image_file_set(icon, kWRTIconCheckPath, NULL); + } + evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_object_part_content_set(btn, "elm.swallow.content", icon); + evas_object_show(icon); +#endif // MODEL_FORMFACTOR_CIRCLE + return btn; +} + +static Evas_Object* AddEntry(Evas_Object* parent, Popup::EntryType type) { + Evas_Object* entry = elm_entry_add(parent); + elm_object_style_set(entry, kStyleEditPw); + elm_entry_single_line_set(entry, EINA_TRUE); + elm_entry_scrollable_set(entry, EINA_TRUE); + evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_entry_prediction_allow_set(entry, EINA_FALSE); + elm_object_signal_emit(entry, kSignalEdit, ""); + elm_entry_autocapital_type_set(entry, ELM_AUTOCAPITAL_TYPE_NONE); + + if (type == Popup::EntryType::Edit) { + evas_object_smart_callback_add(entry, kStateActivated, + [](void*, Evas_Object* obj, void*) { + elm_object_focus_set(obj, EINA_TRUE); + }, NULL); + } else { + elm_entry_password_set(entry, EINA_TRUE); + elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_PASSWORD); + } + + return entry; +} + +static Evas_Object* AddEntrySet(Evas_Object* parent, + const char* str_id, Popup::EntryType type) { + Evas_Object* entry = AddEntry(parent, type); + evas_object_show(entry); + + Evas_Object* layout = elm_layout_add(parent); + elm_layout_file_set(layout, kWRTEdjePath, "PopupTextEntrySet"); + + Evas_Object* rectangle = evas_object_rectangle_add( + evas_object_evas_get(layout)); + evas_object_color_set(rectangle, 0, 0, 0, 0); + evas_object_resize(rectangle, 100, 100); + evas_object_size_hint_min_set(rectangle, 100, 100); + evas_object_show(rectangle); + elm_object_part_content_set(layout, "entry.rectangle", rectangle); + evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_object_domain_translatable_part_text_set(layout, "entry.text", + kTextDomainRuntime, + str_id); + elm_layout_content_set(layout, "entry.swallow", entry); + + evas_object_show(layout); + elm_box_pack_end(parent, layout); + + return entry; +} + +static Evas_Object* AddCheckBox(Evas_Object* parent) { + Evas_Object* check = elm_check_add(parent); + elm_object_style_set(check, kStyleCheck); + evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL); +#ifndef MODEL_FORMFACTOR_CIRCLE + elm_object_style_set(check, "multiline"); +#endif // MODEL_FORMFACTOR_CIRCLE + elm_check_state_set(check, EINA_TRUE); + return check; +} + +} // namespace + +// static variable initialize +std::set Popup::opened_popups_; + +Popup* Popup::CreatePopup(Evas_Object* window) { + Evas_Object* popup = elm_popup_add(window); + evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_object_style_set(popup, kStylePopup); + + Evas_Object* layout = elm_layout_add(popup); +#ifdef MODEL_FORMFACTOR_CIRCLE + elm_layout_theme_set(layout, "layout", "popup", kLayoutTheme); + elm_object_content_set(popup, layout); + + Evas_Object* box = elm_box_add(layout); +#else + Evas_Object* box = elm_box_add(popup); +#endif // MODEL_FORMFACTOR_CIRCLE + + elm_box_padding_set(box, 0, 10); + evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL); + +#ifdef MODEL_FORMFACTOR_CIRCLE + elm_object_part_content_set(layout, "elm.swallow.content", box); +#else + elm_object_part_content_set(popup, "default", box); +#endif // MODEL_FORMFACTOR_CIRCLE + evas_object_show(box); + + evas_object_event_callback_add(popup, EVAS_CALLBACK_RESIZE, NULL, NULL); + + return new Popup(popup, layout, box); + +} + +void Popup::ForceCloseAllPopup() { + auto backup = opened_popups_; + for (auto& popup : backup) { + // will cause modification of opened_popups_ + popup->Hide(); + } +} + +void Popup::SetButtonType(ButtonType type) { + enable_button_ = true; + LOG(ERROR)<<"SetButtonType"; + switch (type) { + case ButtonType::OkButton: + button1_ = AddButton(this, popup_string::kPopupButtonOk, + kContentButton1, kStyleButton); + break; + case ButtonType::OkCancelButton: + button1_ = AddButton(this, popup_string::kPopupButtonCancel, + kContentButton1, kStyleButtonLeft); + button2_ = AddButton(this, popup_string::kPopupButtonOk, + kContentButton2, kStyleButtonRight); + break; + case ButtonType::LoginCancelButton: + button1_ = AddButton(this, popup_string::kPopupButtonCancel, + kContentButton1, kStyleButtonLeft); + button2_ = AddButton(this, popup_string::kPopupButtonLogin, + kContentButton2, kStyleButtonRight); + break; + case ButtonType::AllowDenyButton: + LOG(ERROR)<<"ALLOW DENY"; + button1_ = AddButton(this, popup_string::kPopupButtonDeny, + kContentButton1, kStyleButtonLeft); + button2_ = AddButton(this, popup_string::kPopupButtonAllow, + kContentButton2, kStyleButtonRight); + break; + } +} + +bool Popup::IsPositiveButton(Evas_Object* button) { + if (button == NULL || button1_ == NULL) + return false; + else + return button == button2_; +} + +bool Popup::GetButtonResult() const { + return result_button_; +} + +void Popup::SetFirstEntry(const std::string& str_id, EntryType type) { + enable_entry_ = true; + entry1_ = AddEntrySet(box_, str_id.c_str(), type); +} + +// suppose that it is called after SetFirstEntry() +void Popup::SetSecondEntry(const std::string& str_id, EntryType type) { + if (!enable_entry_ || !entry1_) { + LOG(ERROR) << "SetFirstEntry() is not called yet"; + return; + } + entry2_ = AddEntrySet(box_, str_id.c_str(), type); +} + +std::string Popup::GetFirstEntryResult() const { + return result_entry1_; +} + +std::string Popup::GetSecondEntryResult() const { + return result_entry2_; +} + +void Popup::SetCheckBox(const std::string& str_id) { + enable_check_box_ = true; + check_box_ = AddCheckBox(box_); + if (!str_id.empty()) { + elm_object_domain_translatable_part_text_set( + check_box_, kContentText, + kTextDomainRuntime, + str_id.c_str()); + } +#ifdef MODEL_FORMFACTOR_CIRCLE + elm_object_part_content_set(box_, "elm.swallow.checkbox", check_box_); + evas_object_size_hint_min_set(check_box_, 0, 80); +#endif // MODEL_FORMFACTOR_CIRCLE + elm_box_pack_end(box_, check_box_); + evas_object_show(check_box_); +} + +bool Popup::GetCheckBoxResult() const { + return result_check_box_; +} + +void Popup::SetTitle(const std::string& str_id) { + elm_object_domain_translatable_part_text_set( +#ifdef MODEL_FORMFACTOR_CIRCLE + layout_, +#else + popup_, +#endif // MODEL_FORMFACTOR_CIRCLE + kContentTitle, + kTextDomainRuntime, + str_id.c_str()); +} + +void Popup::SetBody(const std::string& str_id) { + Evas_Object* label = elm_label_add(box_); + elm_object_style_set(label, kStyleLabel); + elm_label_line_wrap_set(label, ELM_WRAP_MIXED); + elm_object_domain_translatable_part_text_set( + label, kContentText, kTextDomainRuntime, + elm_entry_utf8_to_markup(str_id.c_str())); + evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL); +#ifdef MODEL_FORMFACTOR_CIRCLE + evas_object_color_set(label, 255, 255, 255, 255); + elm_object_part_content_set(box_, "elm.swallow.label", label); +#else + evas_object_color_set(label, 0, 0, 0, 255); +#endif // MODEL_FORMFACTOR_CIRCLE + elm_box_pack_end(box_, label); + evas_object_show(label); +} + +void Popup::SetResultHandler(std::function handler, void* user_data) { + handler_ = handler; + user_data_ = user_data; +} + +void Popup::Show() { + evas_object_show(popup_); + opened_popups_.insert(this); +} + +void Popup::Hide() { + evas_object_hide(popup_); + ecore_idler_add([](void* popup) { + Popup* obj = static_cast(popup); + delete obj; + return EINA_FALSE; + }, this); + auto found = opened_popups_.find(this); + if (found != opened_popups_.end()) { + opened_popups_.erase(found); + } +} + +void Popup::Result(bool is_positive) { + if (enable_button_) { + result_button_ = is_positive; + } + if (enable_entry_ && !!entry1_) { + const char* text = elm_entry_entry_get(entry1_); + if (text) + result_entry1_ = text; + if (!!entry2_) { + text = elm_entry_entry_get(entry2_); + if (text) + result_entry2_ = text; + } + } + if (enable_check_box_) { + result_check_box_ = elm_check_state_get(check_box_); + } + + handler_(this, user_data_); +} + +Popup::Popup(Evas_Object* popup, Evas_Object* layout, Evas_Object* box) + : popup_(popup), layout_(layout), box_(box), button1_(NULL), button2_(NULL), + entry1_(NULL), entry2_(NULL), check_box_(NULL), user_data_(NULL), + enable_button_(false), result_button_(false), enable_entry_(false), + enable_check_box_(false), result_check_box_(false) {} + +Popup::~Popup() { + if (popup_) + evas_object_del(popup_); + popup_ = NULL; +} + +} // namespace runtime diff --git a/tizen/src/browser/popup.h b/tizen/src/browser/popup.h new file mode 100644 index 0000000..9938d48 --- /dev/null +++ b/tizen/src/browser/popup.h @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef XWALK_RUNTIME_BROWSER_POPUP_H_ +#define XWALK_RUNTIME_BROWSER_POPUP_H_ + +#include +#include + +#include +#include +#include +#include + + +namespace runtime { + + +class Popup { + public: + enum class ButtonType { + OkButton, + OkCancelButton, + LoginCancelButton, + AllowDenyButton + }; + + enum class EntryType { + Edit, + PwEdit + }; + + static Popup* CreatePopup(Evas_Object* window); + static void ForceCloseAllPopup(); + + // button + void SetButtonType(ButtonType type); + bool IsPositiveButton(Evas_Object* button); + bool GetButtonResult() const; // yes/allow/ok: true, the others: false + + void SetFirstEntry(const std::string& str_id, EntryType type); + void SetSecondEntry(const std::string& str_id, EntryType type); + std::string GetFirstEntryResult() const; + std::string GetSecondEntryResult() const; + + // check box + void SetCheckBox(const std::string& str_id = std::string()); + bool GetCheckBoxResult() const; + + // etc. + void SetTitle(const std::string& str_id); + void SetBody(const std::string& str_id); + void SetResultHandler(std::function + handler, void* user_data); + + // Popup's actions + void Show(); + void Hide(); + void Result(bool is_positive); + + // getter + Evas_Object* popup() { return popup_; } + + private: + Popup(Evas_Object* popup, Evas_Object* layout, Evas_Object* box); + ~Popup(); + + Evas_Object* popup_; + Evas_Object* layout_; + Evas_Object* box_; + Evas_Object* button1_; + Evas_Object* button2_; + Evas_Object* entry1_; + Evas_Object* entry2_; + Evas_Object* check_box_; + + std::function handler_; + void* user_data_; + + bool enable_button_; + bool result_button_; + bool enable_entry_; + std::string result_entry1_; + std::string result_entry2_; + bool enable_check_box_; + bool result_check_box_; + static std::set opened_popups_; +}; + +} // namespace runtime + +#endif // XWALK_RUNTIME_BROWSER_POPUP_H_ diff --git a/tizen/src/browser/popup_string.cc b/tizen/src/browser/popup_string.cc new file mode 100644 index 0000000..edee085 --- /dev/null +++ b/tizen/src/browser/popup_string.cc @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "tizen/src/browser/popup_string.h" + +#include + +#include "tizen/common/constants.h" + +namespace runtime { + +namespace popup_string { + + +const char kPopupTitleAuthRequest[] = "IDS_SA_BODY_USER_AUTHENTICATION"; +const char kPopupTitleCert[] = "IDS_BR_HEADER_CERTIFICATE_INFO"; +const char kPopupTitleGeoLocation[] = "IDS_WRT_OPT_ACCESS_USER_LOCATION"; +const char kPopupTitleUserMedia[] = "IDS_WRT_OPT_USE_USER_MEDIA"; +const char kPopupTitleWebNotification[] = + "IDS_BR_HEADER_WEB_NOTIFICATION"; +const char kPopupTitleWebStorage[] = "IDS_WRT_OPT_USE_STORE_WEB_DATA"; + +const char kPopupBodyAuthRequest[] = + "IDS_BR_BODY_DESTINATIONS_AUTHENTICATION_REQUIRED"; +const char kPopupBodyCert[] = + "IDS_BR_BODY_SECURITY_CERTIFICATE_PROBLEM_MSG"; +const char kPopupBodyGeoLocation[] = + "IDS_WRT_BODY_ALLOWS_THIS_SITE_TO_ACCESS_YOUR_LOCATION_INFORMATION"; +const char kPopupBodyUserMedia[] = + "IDS_BR_POP_P1SS_HP2SS_IS_REQUESTING_PERMISSION_TO_USE_YOUR_CAMERA"; +const char kPopupBodyWebNotification[] = + "IDS_WRT_BODY_ALLOWS_THIS_SITE_TO_DISPLAY_NOTIFICATIONS"; +const char kPopupBodyWebStorage[] = + "IDS_WRT_BODY_ALLOWS_THIS_SITE_TO_SAVE_A_LARGE_AMOUNT_OF_DATA_ON_YOUR_DEVICE"; + +const char kPopupCheckRememberPreference[] = + "IDS_BR_BODY_REMEMBER_PREFERENCE"; + +const char kPopupLabelAuthusername[] = "IDS_BR_BODY_AUTHUSERNAME"; +const char kPopupLabelPassword[] = "IDS_BR_BODY_AUTHPASSWORD"; + +const char kPopupButtonOk[] = "IDS_BR_SK_OK"; +const char kPopupButtonLogin[] = "IDS_BR_BODY_LOGIN"; +const char kPopupButtonCancel[] = "IDS_BR_SK_CANCEL"; +const char kPopupButtonAllow[] = "IDS_BR_OPT_ALLOW"; +const char kPopupButtonDeny[] = "IDS_COM_BODY_DENY"; + +std::string GetText(const std::string& msg_id) { + return dgettext(kTextDomainRuntime, msg_id.c_str()); +} + +} // namespace popup_string + +} // namespace runtime diff --git a/tizen/src/browser/popup_string.h b/tizen/src/browser/popup_string.h new file mode 100644 index 0000000..09a6c9a --- /dev/null +++ b/tizen/src/browser/popup_string.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef XWALK_RUNTIME_BROWSER_POPUP_STRING_H_ +#define XWALK_RUNTIME_BROWSER_POPUP_STRING_H_ + +#include + +namespace runtime { + +namespace popup_string { + +extern const char kPopupTitleAuthRequest[]; +extern const char kPopupTitleCert[]; +extern const char kPopupTitleGeoLocation[]; +extern const char kPopupTitleUserMedia[]; +extern const char kPopupTitleWebNotification[]; +extern const char kPopupTitleWebStorage[]; + +extern const char kPopupBodyAuthRequest[]; +extern const char kPopupBodyCert[]; +extern const char kPopupBodyGeoLocation[]; +extern const char kPopupBodyUserMedia[]; +extern const char kPopupBodyWebNotification[]; +extern const char kPopupBodyWebStorage[]; + +extern const char kPopupCheckRememberPreference[]; + +extern const char kPopupLabelAuthusername[]; +extern const char kPopupLabelPassword[]; + +extern const char kPopupButtonOk[]; +extern const char kPopupButtonLogin[]; +extern const char kPopupButtonCancel[]; +extern const char kPopupButtonAllow[]; +extern const char kPopupButtonDeny[]; + +std::string GetText(const std::string& msg_id); + +} // namespace popup_string + +} // namespace runtime + +#endif // XWALK_RUNTIME_BROWSER_POPUP_STRING_H_ diff --git a/wrt.gyp b/wrt.gyp index e0a24b3..1ca7046 100644 --- a/wrt.gyp +++ b/wrt.gyp @@ -129,6 +129,10 @@ '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/popup.cc', + 'tizen/src/browser/popup.h', + 'tizen/src/browser/popup_string.cc', + 'tizen/src/browser/popup_string.h', 'tizen/src/browser/native_web_runtime.cc', 'tizen/src/browser/native_web_runtime.h', 'tizen/src/browser/native_web_runtime_observer.h', -- 2.7.4 From 37b8b649de1af305354621931218a37b8b381d50 Mon Sep 17 00:00:00 2001 From: "ws29.jung" Date: Wed, 19 Sep 2018 19:59:44 +0900 Subject: [PATCH 15/16] Remove redundant CommandLine class Electron-efl had 3 different CommandLine classes which do the job not very different and they weren't a inherited class of any other. From this patch, common::CommandLine class is removed and only AtomCommandLine and base::CommandLine are left. Change-Id: Ic6a85e29a153461771f2441fc3321141f0ce3624 Signed-off-by: ws29.jung --- atom/common/atom_command_line.cc | 19 ++++++++++++++++++- atom/common/atom_command_line.h | 3 ++- tizen/common/common.gyp | 2 -- tizen/src/browser/api/wrt_api_core.cc | 7 ++----- tizen/src/wrt_main.cc | 11 +++-------- 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/atom/common/atom_command_line.cc b/atom/common/atom_command_line.cc index 08880ff..4a5bfe9 100644 --- a/atom/common/atom_command_line.cc +++ b/atom/common/atom_command_line.cc @@ -11,7 +11,7 @@ namespace atom { // static std::vector AtomCommandLine::argv_; - +int AtomCommandLine::argc_; #if defined(OS_WIN) // static std::vector AtomCommandLine::wargv_; @@ -20,6 +20,7 @@ std::vector AtomCommandLine::wargv_; // static void AtomCommandLine::Init(int argc, const char* const* argv) { // Hack around with the argv pointer. Used for process.title = "blah" + argc_ = argc; char** new_argv = uv_setup_args(argc, const_cast(argv)); for (int i = 0; i < argc; ++i) { argv_.push_back(new_argv[i]); @@ -42,4 +43,20 @@ void AtomCommandLine::InitializeFromCommandLine() { } #endif +std::string AtomCommandLine::GetAppIdFromCommandLine(const std::string& program) { + if (argc_ > 0) { + std::string tmp = argv_[0]; + if (tmp == program) { + if (argv_.size() > 0) { + // Suppose that appid is at the first of arguments_ + return argv_[0]; + } + } else { + return tmp; + } + } + return std::string(); +} + + } // namespace atom diff --git a/atom/common/atom_command_line.h b/atom/common/atom_command_line.h index a834ce9..3b6d689 100644 --- a/atom/common/atom_command_line.h +++ b/atom/common/atom_command_line.h @@ -29,9 +29,10 @@ class AtomCommandLine { // it is using zygote. static void InitializeFromCommandLine(); #endif - + static std::string GetAppIdFromCommandLine(const std::string& program); private: static std::vector argv_; + static int argc_; #if defined(OS_WIN) static std::vector wargv_; diff --git a/tizen/common/common.gyp b/tizen/common/common.gyp index 637f5c4..7dbb07d 100644 --- a/tizen/common/common.gyp +++ b/tizen/common/common.gyp @@ -7,8 +7,6 @@ 'target_name': 'wrt_common', 'type': 'shared_library', 'sources': [ - 'command_line.h', - 'command_line.cc', 'constants.h', 'constants.cc', 'file_utils.h', diff --git a/tizen/src/browser/api/wrt_api_core.cc b/tizen/src/browser/api/wrt_api_core.cc index e58d525..c63f6b8 100755 --- a/tizen/src/browser/api/wrt_api_core.cc +++ b/tizen/src/browser/api/wrt_api_core.cc @@ -3,12 +3,12 @@ #include #include "atom/browser/browser.h" +#include "atom/common/atom_command_line.h" #include "atom/common/node_includes.h" #include "base/files/file_path.h" #include "base/logging.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" @@ -77,10 +77,7 @@ std::string WebRuntime::GetPath() const { } bool WebRuntime::isTizenWebApp() const { - common::CommandLine* runtime_cmd = common::CommandLine::ForCurrentProcess(); - if (!runtime_cmd) - return false; - std::string appid = runtime_cmd->GetAppIdFromCommandLine("/usr/bin/electron"); + std::string appid = atom::AtomCommandLine::GetAppIdFromCommandLine("/usr/bin/electron"); if (appid != "electron") { // TODO: Any better distinguishing feature? return true; } else { diff --git a/tizen/src/wrt_main.cc b/tizen/src/wrt_main.cc index 38ccdfa..87fd3e8 100644 --- a/tizen/src/wrt_main.cc +++ b/tizen/src/wrt_main.cc @@ -20,7 +20,6 @@ #if defined(OS_TIZEN) #include "atom/app/runtime.h" #include "tizen/common/application_data.h" -#include "tizen/common/command_line.h" #include "tizen/loader/prelauncher.h" #include "tizen/browser/preload_manager.h" #endif @@ -42,19 +41,14 @@ int real_main(int argc, char* argv[]) { for (int i = 0; i < argc; ++i) LOG(INFO) << "argv[" << i << "] : " << argv[i]; - if (!common::CommandLine::Init(argc, argv)) { - common::CommandLine::Reset(); - common::CommandLine::Init(argc, argv); - } - if (base::CommandLine::InitializedForCurrentProcess()) { base::CommandLine::ForCurrentProcess()->SetProgram(base::FilePath(argv[0])); } else { base::CommandLine::Init(argc, argv); } - common::CommandLine* runtime_cmd = common::CommandLine::ForCurrentProcess(); - std::string appid = runtime_cmd->GetAppIdFromCommandLine("/usr/bin/wrt"); + atom::AtomCommandLine::Init(argc, argv); + std::string appid = atom::AtomCommandLine::GetAppIdFromCommandLine("/usr/bin/wrt"); base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); bool is_browser_process = @@ -100,6 +94,7 @@ int main(int argc, const char* argv[]) { 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); -- 2.7.4 From 52d96c8715a5fb5903b6fbddd9fdc3b774c97902 Mon Sep 17 00:00:00 2001 From: Suneel Kota Date: Mon, 17 Sep 2018 20:03:46 +0530 Subject: [PATCH 16/16] Add command line flag to enable touch events touchstart, touchend and other touch events will be enabled and the respective event handlers will only work when touch events are enabled in command line. Change-Id: I8527d5b098cb9427a567c2f0fb57ba65fd234271 Signed-off-by: Suneel Kota --- tizen/src/app/wrt_main_delegate.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tizen/src/app/wrt_main_delegate.cc b/tizen/src/app/wrt_main_delegate.cc index 55eff65..6d4afe5 100644 --- a/tizen/src/app/wrt_main_delegate.cc +++ b/tizen/src/app/wrt_main_delegate.cc @@ -5,6 +5,7 @@ #include "efl/init.h" #include "tizen/common/env_variables.h" #include "tizen/common/application_data.h" +#include "tizen/common/platform_info.h" namespace { @@ -46,6 +47,8 @@ bool WRTMainDelegate::BasicStartupComplete(int* exit_code) { command_line->AppendSwitch("enable-tizen-app-container"); command_line->AppendSwitchASCII( "injected-bundle-path", "/usr/lib/libxwalk_injected_bundle.so"); + if ( common::getProfile() != common::kPROFILE_TV) + command_line->AppendSwitchASCII("touch-events", "enabled"); return AtomMainDelegate::BasicStartupComplete(exit_code); } -- 2.7.4