c773acaf5aa63733449d7b8c3721c741927f1bfe
[platform/framework/web/crosswalk-tizen.git] / atom / app / ui_runtime.cc
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <app.h>
18 #include <string>
19 #include <vector>
20
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"
31
32 namespace runtime {
33
34 UiRuntime::UiRuntime(content::ContentMainParams *params) {
35   _params = params;
36 }
37
38 UiRuntime::~UiRuntime() {
39 }
40
41
42 bool UiRuntime::OnCreate() {
43   return true;
44 }
45
46 void UiRuntime::OnTerminate() {
47   atom::Browser *browser_model = atom::Browser::Get();
48 }
49
50 void UiRuntime::OnPause() {
51   LOG(ERROR) << "OnPause()";
52   atom::Browser *browser_model = atom::Browser::Get();
53   browser_model->Hide();
54 }
55
56 void UiRuntime::OnResume() {
57   LOG(ERROR) << "OnResume()";
58   atom::Browser *browser_model = atom::Browser::Get();
59   browser_model->Show();
60 }
61
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));
72   } else {
73    browser_model->Initialize();
74    browser_model->Launch(std::move(appcontrol));
75   }
76 }
77
78 void UiRuntime::OnLanguageChanged(const std::string& language) {
79   LOG(ERROR) << "OnLanguageChanged()";
80 }
81
82 void UiRuntime::OnLowMemory() {
83   LOG(ERROR) << "OnLowMemory()";
84 }
85
86 int UiRuntime::Exec() {
87   ui_app_lifecycle_callback_s ops = {NULL, NULL, NULL, NULL, NULL};
88
89   // onCreate
90   ops.create = [](void* data) -> bool {
91
92     LOG(ERROR) << "Create Tizen App.";
93     UiRuntime *runtime = (UiRuntime*)data;
94     content::ContentMain(*runtime->_params);
95     return true;
96   };
97
98   // onTerminate
99   ops.terminate = [](void* data) -> void {
100     LOG(ERROR) << "Terminate Tizen App.";
101     UiRuntime *runtime = (UiRuntime*)data;
102     runtime->OnTerminate();
103   };
104
105   // onPause
106   ops.pause = [](void* data) -> void {
107     LOG(ERROR) << "Pause Tizen App.";
108     UiRuntime *runtime = (UiRuntime*)data;
109     runtime->OnPause();
110   };
111
112   // onResume
113   ops.resume = [](void* data) -> void {
114     LOG(ERROR) << "Resume Tizen App.";
115     UiRuntime *runtime = (UiRuntime*)data;
116     runtime->OnResume();
117   };
118
119   // onAppControl
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);
124   };
125
126   return ui_app_main(_params->argc, const_cast<char**>(_params->argv), &ops, this);
127 }
128 } //namespace