Fixed Nabi issue N_SE-40542,N_SE-39949,N_SE-40229
[apps/osp/Internet.git] / src / IntInternetApp.cpp
1 //
2
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.1 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 //!Internet
19 /*@file:        Internet.cpp
20  *@brief:       provides basic features necessary to define an UiApp.
21  */
22
23 #include "IntBookmarkData.h"
24 #include "IntBookmarkPresentationModel.h"
25 #include "IntCommonLib.h"
26 #include "IntFaviconManager.h"
27 #include "IntHistoryPresentationModel.h"
28 #include "IntInternetApp.h"
29 #include "IntMainFrame.h"
30 #include "IntMainForm.h"
31 #include "IntMultipleWindowPresentationModel.h"
32 #include "IntSceneRegister.h"
33 #include "IntSettingPresentationModel.h"
34
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::System;
39 using namespace Tizen::Ui;
40 using namespace Tizen::Ui::Controls;
41 using namespace Tizen::Ui::Scenes;
42
43 InternetApp::InternetApp(void)
44 : __pMultiWindowManager(NULL),__pNewWindowInfo(null)
45 {
46
47 }
48
49 InternetApp::~InternetApp(void)
50 {
51         if (__pNewWindowInfo != NULL)
52         {
53                 delete __pNewWindowInfo;
54                 __pNewWindowInfo = NULL;
55         }
56 }
57
58 UiApp*
59 InternetApp::CreateInstance(void)
60 {
61         // Create the instance through the constructor.
62         return new(std::nothrow) InternetApp();
63 }
64
65 void
66 InternetApp::ShowPopup(String& pTitle, String& pText)
67 {
68         MessageBox messageBox;
69         messageBox.Construct(pTitle, pText,MSGBOX_STYLE_OK,3000);
70         int modalResult = 0;
71
72         messageBox.ShowAndWait(modalResult);
73         switch (modalResult)
74         {
75         case MSGBOX_RESULT_OK:
76         {
77
78         }
79         break;
80         default:
81                 break;
82         }
83 }
84
85 bool
86 InternetApp::OnAppInitializing(AppRegistry& appRegistry)
87 {
88         AppLog("ABC::Internet::OnAppInitializing entered");
89         AppControlProviderManager* pAppMgr = AppControlProviderManager::GetInstance();
90         if (pAppMgr != null)
91         {
92                 result r = pAppMgr->SetAppControlProviderEventListener(this);
93                 AppLogDebug("SetAppControlProviderEventListener result %s",GetErrorMessage(r));
94         }
95         return true;
96 }
97
98 bool
99 InternetApp::OnAppInitialized(void)
100 {
101         result r = E_SUCCESS;
102
103         String title1 = L"URL1";
104         String title2 = L"URL2";
105         String folder1 = L"Folder 1";
106         String strSite1 = "Site 1";
107
108         BookmarkPresentationModel::GetInstance();
109         HistoryPresentationModel::GetInstance();
110         FaviconManager::GetInstance();
111         SettingPresentationModel::GetInstance();
112
113 //      MultipleWindowPresentationModel::GetInstance();
114
115         SettingInfo::AddSettingEventListener(*this);
116         __pMultiWindowManager = MultipleWindowPresentationModel::GetInstance();
117         AppLogDebug("window count %d",__pMultiWindowManager->GetAllWindowArrayList()->GetCount());
118
119         // Goto the first scene.
120         SceneManager* pSceneManager = SceneManager::GetInstance();
121         if (pSceneManager == null)
122         {
123                 AppLogDebug("pSceneManager is null returning");
124                 return false;
125         }
126         // Create a Frame
127         MainFrame* pSceneManagementFrame = new(std::nothrow) MainFrame();
128         pSceneManagementFrame->Construct();
129         pSceneManagementFrame->SetName(L"SceneManagement");
130         AddFrame(*pSceneManagementFrame);
131
132         String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
133         if (homePage == (L"IDS_BR_BODY_MOST_VISITED_SITES") || homePage == (L"IDS_BR_BODY_BLANK_PAGE"))
134         {
135                 homePage = L"";
136         }
137         else if (homePage == CommonUtil::GetString(L"IDS_BR_BODY_USER_HOMEPAGE"))
138         {
139                 AppLog("InternetApp::OnAppInitialized homaepage = userhomepage");
140                 homePage = SettingPresentationModel::GetInstance()->GetFavoriteUrl();
141                 AppLog("InternetApp::OnAppInitialized fav URL = %ls ",homePage.GetPointer());
142         }
143
144         if (__pNewWindowInfo == null)//if the application is launched normally
145         {
146                 __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene(homePage);
147         }
148
149         if (__pNewWindowInfo == null)
150         {
151                 return false;
152         }
153
154         ArrayList* pArgList = new(std::nothrow) ArrayList();
155         pArgList->Construct();
156         pArgList->Add(*__pNewWindowInfo);
157         /*
158          * The GoForward call cannot be moved into the MainFrame::OnInitializing
159          * because when the application is launched from the appcontol, the data(URL)
160          * is not available for Mainframe, and we cannot pass the url information to
161          * the Mainframe because logically MainFrame should not know the URL information.
162          */
163         if (E_SUCCESS != pSceneManager->GoForward(ForwardSceneTransition(__pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList))
164         {
165                 AppLogDebug("CustomAppControl::OnAppInitializing Result = %s", GetLastResult());
166                 delete pArgList;
167                 __pNewWindowInfo = null;
168                 return false;
169         }
170
171         delete pArgList;
172         pArgList = null;
173         __pNewWindowInfo = null;
174
175         return true;
176 }
177
178 bool
179 InternetApp::OnAppWillTerminate(void)
180 {
181         return true;
182 }
183
184
185 bool
186 InternetApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
187 {
188         AppLogDebug("Internet::OnAppTerminating");
189
190         SettingInfo::RemoveSettingEventListener(*this);
191
192         return true;
193 }
194
195 void
196 InternetApp::OnForeground(void)
197 {
198         Form* pCurrentForm = (SceneManager::GetInstance()->GetCurrentScene()->GetForm());
199         if (pCurrentForm)
200         {
201                 pCurrentForm->SendUserEvent(FORE_GROUND_APP_EVENT, NULL);
202         }
203 }
204
205 void
206 InternetApp::OnBackground(void)
207 {
208         Form* pCurrentForm = (SceneManager::GetInstance()->GetCurrentScene()->GetForm());
209         if(pCurrentForm)
210         {
211                 pCurrentForm->SendUserEvent(BACK_GROUND_APP_EVENT, NULL);
212         }
213 }
214
215 void
216 InternetApp::OnLowMemory(void)
217 {
218
219 }
220
221 void
222 InternetApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
223 {
224
225 }
226
227 void
228 InternetApp::OnScreenOn(void)
229 {
230
231 }
232
233 void
234 InternetApp::OnScreenOff(void)
235 {
236         // TODO:
237         // Unless there is a strong reason to do otherwise, release resources (such as 3D, media, and sensors) to allow the device
238         // to enter the sleep mode to save the battery.
239         // Invoking a lengthy asynchronous method within this listener method can be risky, because it is not guaranteed to invoke a
240         // callback before the device enters the sleep mode.
241         // Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.
242 }
243
244 void
245 InternetApp::OnSettingChanged(Tizen::Base::String& key)
246 {
247         AppLog("InternetApp::OnSettingChanged: %ls", key.GetPointer());
248         if (key == L"http://tizen.org/setting/locale.language")
249         {
250                 Terminate();
251         }
252 }
253
254 void
255 InternetApp::OnAppControlRequestReceived(RequestId reqId, const String &operationId, const String* pUriScheme, const String *pDataType, const IMap *pArgs)
256 {
257         AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN entered %ls",operationId.GetPointer());
258
259         if (operationId.CompareTo(L"http://tizen.org/appcontrol/operation/view") == 0)
260         {
261                 String urlData;
262                 if (pUriScheme)
263                 {
264                         urlData = *pUriScheme;
265                 }
266                 else
267                 {
268                         int argCount = pArgs->GetCount();
269                         AppLog("argCount == %d", argCount);
270
271                         IList *pValues = pArgs->GetValuesN();
272                         if(pValues == null)
273                         {
274                                 AppLog("pValues == null");
275                                 return;
276                         }
277
278                         String url = L"url";
279                         String* pUrl = dynamic_cast<String*>(const_cast<Object*>(pArgs->GetValue(url)));
280                         if(pUrl == null)
281                         {
282                                 delete pValues;
283                                 AppLog("pUrl == null");
284                                 return;
285                         }
286                         urlData = *pUrl;
287                 }
288                 AppLog("URL received %ls", urlData.GetPointer());
289
290                 if (__pNewWindowInfo == null)
291                 {
292                         __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene(urlData, true);
293                 }
294                 if (__pNewWindowInfo == null)
295                 {
296                         if (MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
297                         {
298                                 String strTitle = CommonUtil::GetString(L"IDS_COM_SK_MAX_LIMIT_REACHED");
299                                 String strText = CommonUtil::GetString(L"IDS_COM_SK_CREATE_WINDOWS_BNO");
300                                 ShowPopup(strTitle, strText);
301                         }
302                         return;
303                 }
304                 if (__pMultiWindowManager != null && __pMultiWindowManager->GetAllWindowArrayList()->GetCount() != 0)
305                 {
306                         //if the application is running in background and it receives an appcontrol request it will launch a new(std::nothrow) window here,
307                         //otherwise appcontrol request will be handled by OnAppInitialized method
308                         SceneManager* pSceneManager = SceneManager::GetInstance();
309                         if (pSceneManager == null)
310                         {
311                                 return;
312                         }
313
314                         ArrayList* pArgList = new(std::nothrow) ArrayList();
315                         pArgList->Construct();
316                         pArgList->Add(*__pNewWindowInfo);
317
318                         if (E_SUCCESS != pSceneManager->GoForward(ForwardSceneTransition(__pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList))
319                         {
320                                 AppLogDebug("CustomAppControl::OnAppInitializing Result = %s", GetLastResult());
321                                                 delete pArgList;
322                                 __pNewWindowInfo = null;
323                                 return;
324                         }
325
326                         delete pArgList;
327
328                         __pNewWindowInfo = null;
329                 }
330         }
331         AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN Exit");
332         return;
333 }
334