From: prathmeshm Date: Fri, 23 Feb 2018 11:09:44 +0000 (+0530) Subject: Implement Tizen application loop. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0142abc136202966e3bdcbc6de593fa5fea82a9f;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git Implement Tizen application loop. Change-Id: I4c9487ca7bf3125d7614bb1de0d84c60acb2dd36 Signed-off-by: prathmeshm --- diff --git a/atom/app/atom_main.cc b/atom/app/atom_main.cc index cd51296aa..c67500fa7 100644 --- a/atom/app/atom_main.cc +++ b/atom/app/atom_main.cc @@ -37,11 +37,13 @@ #include "base/i18n/icu_util.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" -#include "base/logging.h" #endif namespace { @@ -136,6 +138,17 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) { #elif defined(OS_LINUX) // defined(OS_WIN) #if defined(OS_TIZEN) +// For debug purpose only. +// 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; + } + } + return false; +} + int real_main(int argc, char* argv[]) { #else int main(int argc, char* argv[]) { @@ -177,6 +190,13 @@ int main(int argc, char* argv[]) { 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); + std::unique_ptr runtime = runtime::Runtime::MakeRuntime(¶ms); + return runtime->Exec(); + } +#endif return content::ContentMain(params); } diff --git a/atom/app/runtime.cc b/atom/app/runtime.cc new file mode 100644 index 000000000..a14e84248 --- /dev/null +++ b/atom/app/runtime.cc @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "atom/app/runtime.h" +#include "atom/app/ui_runtime.h" +#include "base/logging.h" + +namespace runtime { + +Runtime::~Runtime() { +} + +std::unique_ptr Runtime::MakeRuntime(content::ContentMainParams *params) { +/* if (app_data->app_type() == common::ApplicationData::UI) { + return std::unique_ptr(new UiRuntime()); + } +#ifdef IME_FEATURE_SUPPORT + else if (app_data->app_type() == common::ApplicationData::IME) { + return std::unique_ptr(new ImeRuntime(app_data)); + } +#endif // IME_FEATURE_SUPPORT +#ifdef WATCH_FACE_FEATURE_SUPPORT + else if (app_data->app_type() == common::ApplicationData::WATCH) { + return std::unique_ptr(new WatchRuntime(app_data)); + } +#endif // WATCH_FACE_FEATURE_SUPPORT + else { */ + return std::unique_ptr(new UiRuntime(params)); + //} +} + +} // namespace runtime \ No newline at end of file diff --git a/atom/app/runtime.h b/atom/app/runtime.h new file mode 100644 index 000000000..baf9001b0 --- /dev/null +++ b/atom/app/runtime.h @@ -0,0 +1,39 @@ + +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef RUNTIME_H_ +#define RUNTIME_H_ + +#include +#include + +#include "content/public/app/content_main.h" + +namespace runtime { + +class Runtime { + public: + virtual ~Runtime() = 0; + + virtual int Exec() = 0; + + static std::unique_ptr MakeRuntime(content::ContentMainParams *params); +}; + +} // namespace runtime + +#endif // RUNTIME_H_ \ No newline at end of file diff --git a/atom/app/ui_runtime.cc b/atom/app/ui_runtime.cc new file mode 100644 index 000000000..97ef0a9ee --- /dev/null +++ b/atom/app/ui_runtime.cc @@ -0,0 +1,115 @@ +/* + * 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 +#include +#include + +#include "atom/app/atom_main_delegate.h" +#include "atom/app/ui_runtime.h" +#include "atom/browser/browser.h" +#include "atom/browser/atom_browser_client.h" +#include "atom/common/atom_command_line.h" +#include "base/logging.h" +#include "content/public/app/content_main.h" + +namespace runtime { + +UiRuntime::UiRuntime(content::ContentMainParams *params) { + _params = params; +} + +UiRuntime::~UiRuntime() { +} + + +bool UiRuntime::OnCreate() { + return true; +} + +void UiRuntime::OnTerminate() { + atom::Browser *browser_model = atom::Browser::Get(); + browser_model->Shutdown(); +} + +void UiRuntime::OnPause() { + LOG(ERROR) << "OnPause()"; + atom::Browser *browser_model = atom::Browser::Get(); + browser_model->Hide(); +} + +void UiRuntime::OnResume() { + LOG(ERROR) << "OnResume()"; + atom::Browser *browser_model = atom::Browser::Get(); + browser_model->Show(); +} + +void UiRuntime::OnAppControl(app_control_h app_control) { + LOG(ERROR) << "OnAppControl()"; +} + +void UiRuntime::OnLanguageChanged(const std::string& language) { + LOG(ERROR) << "OnLanguageChanged()"; +} + +void UiRuntime::OnLowMemory() { + LOG(ERROR) << "OnLowMemory()"; +} + +int UiRuntime::Exec() { + ui_app_lifecycle_callback_s ops = {NULL, NULL, NULL, NULL, NULL}; + + // onCreate + ops.create = [](void* data) -> bool { + + LOG(ERROR) << "Create Tizen App."; + UiRuntime *runtime = (UiRuntime*)data; + content::ContentMain(*runtime->_params); + return true; + }; + + // onTerminate + ops.terminate = [](void* data) -> void { + LOG(ERROR) << "Terminate Tizen App."; + UiRuntime *runtime = (UiRuntime*)data; + runtime->OnTerminate(); + }; + + // onPause + ops.pause = [](void* data) -> void { + LOG(ERROR) << "Pause Tizen App."; + UiRuntime *runtime = (UiRuntime*)data; + runtime->OnPause(); + }; + + // onResume + ops.resume = [](void* data) -> void { + LOG(ERROR) << "Resume Tizen App."; + UiRuntime *runtime = (UiRuntime*)data; + runtime->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); + }; + + return ui_app_main(_params->argc, const_cast(_params->argv), &ops, this); +} + +} //namespace \ No newline at end of file diff --git a/atom/app/ui_runtime.h b/atom/app/ui_runtime.h new file mode 100644 index 000000000..1c8ec225b --- /dev/null +++ b/atom/app/ui_runtime.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UI_RUNTIME_H_ +#define UI_RUNTIME_H_ + +#include +#include +#include "atom/app/runtime.h" +#include "content/public/app/content_main.h" + +namespace runtime { + +class UiRuntime : public Runtime { + public: + UiRuntime(content::ContentMainParams *params); + virtual ~UiRuntime(); + + virtual int Exec(); + + 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; +}; + +} // namespace runtime + +#endif // XWALK_RUNTIME_BROWSER_UI_RUNTIME_H_ diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 72b8e33ef..f19fbda29 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -310,6 +310,16 @@ void Window::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) { } #endif +#if defined(USE_EFL) +void Window::OnSuspend() { + Emit("app-on-suspend"); +} + +void Window::OnResume() { + Emit("app-on-resume"); +} +#endif + // static mate::WrappableBase* Window::New(mate::Arguments* args) { if (!Browser::Get()->is_ready()) { diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 75f0328ba..91b563319 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -96,6 +96,11 @@ class Window : public mate::TrackableObject, void OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) override; #endif +#if defined(USE_EFL) + void OnSuspend(); + void OnResume(); +#endif + private: void Init(v8::Isolate* isolate, v8::Local wrapper, diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index b2900a326..42cc787ee 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -213,4 +213,14 @@ void Browser::OnWindowAllClosed() { } } +void Browser::Hide() { + for (BrowserObserver& observer : observers_) + observer.OnSuspend(); +} + +void Browser::Show() { + for (BrowserObserver& observer : observers_) + observer.OnResume(); +} + } // namespace atom diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 78cac65f7..fc674dd92 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -104,6 +104,8 @@ class Browser : public WindowListObserver { void SetLoginItemSettings(LoginItemSettings settings); LoginItemSettings GetLoginItemSettings(const LoginItemSettings& options); + void Hide(); + void Show(); #if defined(OS_MACOSX) // Hide the application. void Hide(); diff --git a/atom/browser/browser_observer.h b/atom/browser/browser_observer.h index 88a50a93a..b5760ecd9 100644 --- a/atom/browser/browser_observer.h +++ b/atom/browser/browser_observer.h @@ -55,6 +55,8 @@ class BrowserObserver { // The browser's accessibility suppport has changed. virtual void OnAccessibilitySupportChanged() {} + virtual void OnSuspend() {} + virtual void OnResume() {} #if defined(OS_MACOSX) // The browser wants to resume a user activity via handoff. (macOS only) virtual void OnContinueUserActivity( diff --git a/efl/build/system.gyp b/efl/build/system.gyp index 893423782..3e0f94f5f 100644 --- a/efl/build/system.gyp +++ b/efl/build/system.gyp @@ -197,5 +197,26 @@ }], # tizen_product_tv==1 ], }, # vd-win-util + { + 'target_name': 'capi-appfw-application', + 'type': 'none', + 'conditions': [ + ['is_tizen==1', { + 'direct_dependent_settings': { + 'cflags': [ + ' { + events.on(WAS_EVENT.WEBAPPLICATION.RESUME, (sender, id) => { runtime_debug('handleWasMessages: focus ' + id); return _this.onResume(id); }); - events.on(WAS_EVENT.RUNTIME.UNFOCUS, (sender, id) => { + events.on(WAS_EVENT.WEBAPPLICATION.SUSPEND, (sender, id) => { return _this.onPause(id); }); } diff --git a/wrt/src/web_window.js b/wrt/src/web_window.js index 64233007b..1baa83a2c 100644 --- a/wrt/src/web_window.js +++ b/wrt/src/web_window.js @@ -131,6 +131,14 @@ class WebWindow { this.mainWindow.on('language-changed', function(event, locale) { webwindow_debug('WebWindow : language-changed event = ' + (JSON.stringify(locale))); }); + this.mainWindow.on('app-on-suspend', function() { + webwindow_debug('WebWindow : app-on-suspend'); + events.emit(WAS_EVENT.WEBAPPLICATION.SUSPEND, 'web_window', self.mainWindow.id); + }); + this.mainWindow.on('app-on-resume', function() { + webwindow_debug('WebWindow : app-on-resume'); + events.emit(WAS_EVENT.WEBAPPLICATION.RESUME, 'web_window', self.mainWindow.id); + }); this.mainWindow.webContents.on('crashed', function() { webwindow_debug('WebWindow : webContents crashed'); global.webApplication.exit(100); diff --git a/wrt/src/web_window_tag.js b/wrt/src/web_window_tag.js index ae60995e7..ec77a47a4 100644 --- a/wrt/src/web_window_tag.js +++ b/wrt/src/web_window_tag.js @@ -154,6 +154,14 @@ class WebWindowTag { this.mainWindow.on('language-changed', function(event, locale) { webwindow_debug('WebWindow : language-changed event = ' + (JSON.stringify(locale))); }); + this.mainWindow.on('app-on-suspend', function() { + webwindow_debug('WebWindow : app-on-suspend'); + events.emit(WAS_EVENT.WEBAPPLICATION.SUSPEND, 'web_window', self.mainWindow.id); + }); + this.mainWindow.on('app-on-resume', function() { + webwindow_debug('WebWindow : app-on-resume'); + events.emit(WAS_EVENT.WEBAPPLICATION.RESUME, 'web_window', self.mainWindow.id); + }); this.mainWindow.webContents.on('crashed', function() { webwindow_debug('WebWindow : webContents crashed'); global.webApplication.exit(100);