2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include "atom/app/atom_main_delegate.h"
22 #include "atom/app/ui_runtime.h"
23 #include "atom/browser/browser.h"
24 #include "atom/browser/atom_browser_client.h"
25 #include "atom/common/atom_command_line.h"
26 #include "base/logging.h"
27 #include "content/public/app/content_main.h"
28 #include "tizen/common/app_db.h"
29 #include "tizen/common/app_control.h"
30 #include "tizen/common/constants.h"
34 UiRuntime::UiRuntime(content::ContentMainParams *params) {
38 UiRuntime::~UiRuntime() {
42 bool UiRuntime::OnCreate() {
46 void UiRuntime::OnTerminate() {
47 atom::Browser *browser_model = atom::Browser::Get();
50 void UiRuntime::OnPause() {
51 LOG(ERROR) << "OnPause()";
52 atom::Browser *browser_model = atom::Browser::Get();
53 browser_model->Hide();
56 void UiRuntime::OnResume() {
57 LOG(ERROR) << "OnResume()";
58 atom::Browser *browser_model = atom::Browser::Get();
59 browser_model->Show();
62 void UiRuntime::OnAppControl(app_control_h app_control) {
63 LOG(ERROR) << "OnAppControl()";
64 std::unique_ptr<common::AppControl>
65 appcontrol(new common::AppControl(app_control));
66 common::AppDB* appdb = common::AppDB::GetInstance();
67 appdb->Set(kAppDBRuntimeSection, kAppDBRuntimeBundle,
68 appcontrol->encoded_bundle());
69 atom::Browser *browser_model = atom::Browser::Get();
70 if (browser_model->launched()) {
71 browser_model->AppControl(std::move(appcontrol));
73 browser_model->Initialize();
74 browser_model->Launch(std::move(appcontrol));
78 void UiRuntime::OnLanguageChanged(const std::string& language) {
79 LOG(ERROR) << "OnLanguageChanged()";
82 void UiRuntime::OnLowMemory() {
83 LOG(ERROR) << "OnLowMemory()";
86 int UiRuntime::Exec() {
87 ui_app_lifecycle_callback_s ops = {NULL, NULL, NULL, NULL, NULL};
90 ops.create = [](void* data) -> bool {
92 LOG(ERROR) << "Create Tizen App.";
93 UiRuntime *runtime = (UiRuntime*)data;
94 content::ContentMain(*runtime->_params);
99 ops.terminate = [](void* data) -> void {
100 LOG(ERROR) << "Terminate Tizen App.";
101 UiRuntime *runtime = (UiRuntime*)data;
102 runtime->OnTerminate();
106 ops.pause = [](void* data) -> void {
107 LOG(ERROR) << "Pause Tizen App.";
108 UiRuntime *runtime = (UiRuntime*)data;
113 ops.resume = [](void* data) -> void {
114 LOG(ERROR) << "Resume Tizen App.";
115 UiRuntime *runtime = (UiRuntime*)data;
120 ops.app_control = [](app_control_h app_control, void* data) -> void {
121 LOG(ERROR) << "app_control Tizen App.";
122 UiRuntime *runtime = (UiRuntime*)data;
123 runtime->OnAppControl(app_control);
126 return ui_app_main(_params->argc, const_cast<char**>(_params->argv), &ops, this);