3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license
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.
20 *@brief: provides basic features necessary to define an UiApp.
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"
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;
43 const int MIN_MEMORY_NEEDED = 1048576;
45 InternetApp::InternetApp(void)
46 : __pMultiWindowManager(NULL),__pNewWindowInfo(null)
48 __isHwBackButtonExists = false;
51 InternetApp::~InternetApp(void)
53 if (__pNewWindowInfo != NULL)
55 delete __pNewWindowInfo;
56 __pNewWindowInfo = NULL;
61 InternetApp::IsHwBackKeyExists(void)
63 return __isHwBackButtonExists;
67 InternetApp::CreateInstance(void)
69 // Create the instance through the constructor.
70 return new(std::nothrow) InternetApp();
74 InternetApp::ShowPopup(String& pTitle, String& pText)
76 MessageBox messageBox;
77 messageBox.Construct(pTitle, pText,MSGBOX_STYLE_OK,3000);
80 messageBox.ShowAndWait(modalResult);
83 case MSGBOX_RESULT_OK:
94 InternetApp::OnAppInitializing(AppRegistry& appRegistry)
96 AppLog("ABC::Internet::OnAppInitializing entered");
97 AppControlProviderManager* pAppMgr = AppControlProviderManager::GetInstance();
100 result r = pAppMgr->SetAppControlProviderEventListener(this);
101 AppLogDebug("SetAppControlProviderEventListener result %s",GetErrorMessage(r));
103 Tizen::System::SystemInfo::GetValue(L"http://tizen.org/feature/input.keys.back",__isHwBackButtonExists);
108 InternetApp::OnAppInitialized(void)
110 result r = E_SUCCESS;
112 long long mem = GetAvailableMemory();
113 AppLogDebug("%lld",mem);
114 if(mem < MIN_MEMORY_NEEDED)
116 MessageBox LowMemory;
118 LowMemory.Construct(CommonUtil::GetString(L"IDS_LOW_MEMORY_MSG_TITLE"), CommonUtil::GetString(L"IDS_LOW_MEMORY_MSG"), MSGBOX_STYLE_NONE,1000);
120 // Calls ShowAndWait() : Draws and Shows itself and processes events
121 LowMemory.ShowAndWait(modalResult);
126 String title1 = L"URL1";
127 String title2 = L"URL2";
128 String folder1 = L"Folder 1";
129 String strSite1 = "Site 1";
131 BookmarkPresentationModel::GetInstance();
132 HistoryPresentationModel::GetInstance();
133 FaviconManager::GetInstance();
134 SettingPresentationModel::GetInstance();
136 // MultipleWindowPresentationModel::GetInstance();
138 SettingInfo::AddSettingEventListener(*this);
139 __pMultiWindowManager = MultipleWindowPresentationModel::GetInstance();
140 AppLogDebug("window count %d",__pMultiWindowManager->GetAllWindowArrayList()->GetCount());
145 MainFrame* pSceneManagementFrame = new(std::nothrow) MainFrame();
146 pSceneManagementFrame->Construct();
147 pSceneManagementFrame->SetName(L"SceneManagement");
148 AddFrame(*pSceneManagementFrame);
149 // Goto the first scene.
151 SceneManager* pSceneManager = SceneManager::GetInstance();
152 if (pSceneManager == null)
154 AppLogDebug("pSceneManager is null returning");
158 String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
159 if (homePage == (L"IDS_BR_BODY_MOST_VISITED_SITES") || homePage == (L"IDS_BR_BODY_BLANK_PAGE"))
163 else if (homePage == CommonUtil::GetString(L"IDS_BR_BODY_USER_HOMEPAGE"))
165 AppLog("InternetApp::OnAppInitialized homaepage = userhomepage");
166 homePage = SettingPresentationModel::GetInstance()->GetFavoriteUrl();
167 AppLog("InternetApp::OnAppInitialized fav URL = %ls ",homePage.GetPointer());
170 if (__pNewWindowInfo == null)//if the application is launched normally
172 __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN(homePage);
175 if (__pNewWindowInfo == null)
180 ArrayList* pArgList = new(std::nothrow) ArrayList();
181 pArgList->Construct();
182 pArgList->Add(*__pNewWindowInfo);
184 * The GoForward call cannot be moved into the MainFrame::OnInitializing
185 * because when the application is launched from the appcontol, the data(URL)
186 * is not available for Mainframe, and we cannot pass the url information to
187 * the Mainframe because logically MainFrame should not know the URL information.
189 if (E_SUCCESS != pSceneManager->GoForward(ForwardSceneTransition(__pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList))
191 AppLogDebug("CustomAppControl::OnAppInitializing Result = %s", GetLastResult());
193 __pNewWindowInfo = null;
199 __pNewWindowInfo = null;
205 InternetApp::OnAppWillTerminate(void)
212 InternetApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
214 AppLogDebug("Internet::OnAppTerminating");
216 SettingInfo::RemoveSettingEventListener(*this);
222 InternetApp::OnForeground(void)
224 Form* pCurrentForm = (SceneManager::GetInstance()->GetCurrentScene()->GetForm());
227 pCurrentForm->SendUserEvent(FORE_GROUND_APP_EVENT, NULL);
232 InternetApp::OnBackground(void)
234 Form* pCurrentForm = (SceneManager::GetInstance()->GetCurrentScene()->GetForm());
237 pCurrentForm->SendUserEvent(BACK_GROUND_APP_EVENT, NULL);
242 InternetApp::OnLowMemory(void)
248 InternetApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
254 InternetApp::OnScreenOn(void)
260 InternetApp::OnScreenOff(void)
263 // Unless there is a strong reason to do otherwise, release resources (such as 3D, media, and sensors) to allow the device
264 // to enter the sleep mode to save the battery.
265 // Invoking a lengthy asynchronous method within this listener method can be risky, because it is not guaranteed to invoke a
266 // callback before the device enters the sleep mode.
267 // Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.
271 InternetApp::OnSettingChanged(Tizen::Base::String& key)
273 AppLog("InternetApp::OnSettingChanged: %ls", key.GetPointer());
274 if (key == L"http://tizen.org/setting/locale.language")
281 InternetApp::OnAppControlRequestReceived(RequestId reqId, const String &operationId, const String* pUriScheme, const String *pDataType, const IMap *pArgs)
283 AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN entered %ls",operationId.GetPointer());
285 if (operationId.CompareTo(L"http://tizen.org/appcontrol/operation/view") == 0)
290 urlData = *pUriScheme;
294 int argCount = pArgs->GetCount();
295 AppLog("argCount == %d", argCount);
297 IList *pValues = pArgs->GetValuesN();
300 AppLog("pValues == null");
305 String* pUrl = dynamic_cast<String*>(const_cast<Object*>(pArgs->GetValue(url)));
309 AppLog("pUrl == null");
314 AppLog("URL received %ls", urlData.GetPointer());
316 if (__pNewWindowInfo == null)
318 __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN(urlData, true);
320 if (__pNewWindowInfo == null)
322 if (MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
324 String strTitle = CommonUtil::GetString(L"IDS_COM_SK_MAX_LIMIT_REACHED");
325 String strText = CommonUtil::GetString(L"IDS_COM_SK_CREATE_WINDOWS_BNO");
326 ShowPopup(strTitle, strText);
330 if (__pMultiWindowManager != null && __pMultiWindowManager->GetAllWindowArrayList()->GetCount() != 0)
332 //if the application is running in background and it receives an appcontrol request it will launch a new(std::nothrow) window here,
333 //otherwise appcontrol request will be handled by OnAppInitialized method
334 SceneManager* pSceneManager = SceneManager::GetInstance();
335 if (pSceneManager == null)
340 ArrayList* pArgList = new(std::nothrow) ArrayList();
341 pArgList->Construct();
342 pArgList->Add(*__pNewWindowInfo);
344 if (E_SUCCESS != pSceneManager->GoForward(ForwardSceneTransition(__pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList))
346 AppLogDebug("CustomAppControl::OnAppInitializing Result = %s", GetLastResult());
348 __pNewWindowInfo = null;
354 __pNewWindowInfo = null;
357 AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN Exit");
363 InternetApp::GetAvailableMemory(void)
365 result r = E_SUCCESS;
367 String key(L"http://tizen.org/runtime/storage.available.internal");
368 long long allocatedMemory = 0;
370 r = RuntimeInfo::GetValue(key, allocatedMemory);
371 TryCatch(r == E_SUCCESS, , "MyRuntimeInfo: Failed to get value");
373 return allocatedMemory;