3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (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://www.tizenopensource.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 InternetApp::InternetApp(void)
44 : __pMultiWindowManager(NULL),__pNewWindowInfo(null)
49 InternetApp::~InternetApp(void)
51 if (__pNewWindowInfo != NULL)
53 delete __pNewWindowInfo;
54 __pNewWindowInfo = NULL;
59 InternetApp::CreateInstance(void)
61 // Create the instance through the constructor.
62 return new(std::nothrow) InternetApp();
66 InternetApp::ShowPopup(String& pTitle, String& pText)
68 MessageBox messageBox;
69 messageBox.Construct(pTitle, pText,MSGBOX_STYLE_OK,3000);
72 messageBox.ShowAndWait(modalResult);
75 case MSGBOX_RESULT_OK:
86 InternetApp::OnAppInitializing(AppRegistry& appRegistry)
88 AppLog("ABC::Internet::OnAppInitializing entered");
89 AppControlProviderManager* pAppMgr = AppControlProviderManager::GetInstance();
92 result r = pAppMgr->SetAppControlProviderEventListener(this);
93 AppLogDebug("SetAppControlProviderEventListener result %s",GetErrorMessage(r));
99 InternetApp::OnAppInitialized(void)
101 result r = E_SUCCESS;
103 String title1 = L"URL1";
104 String title2 = L"URL2";
105 String folder1 = L"Folder 1";
106 String strSite1 = "Site 1";
108 BookmarkPresentationModel::GetInstance();
109 HistoryPresentationModel::GetInstance();
110 FaviconManager::GetInstance();
111 SettingPresentationModel::GetInstance();
113 // MultipleWindowPresentationModel::GetInstance();
115 __pMultiWindowManager = MultipleWindowPresentationModel::GetInstance();
116 AppLogDebug("window count %d",__pMultiWindowManager->GetAllWindowArrayList()->GetCount());
118 // Goto the first scene.
119 SceneManager* pSceneManager = SceneManager::GetInstance();
120 if (pSceneManager == null)
122 AppLogDebug("pSceneManager is null returning");
126 MainFrame* pSceneManagementFrame = new(std::nothrow) MainFrame();
127 pSceneManagementFrame->Construct();
128 pSceneManagementFrame->SetName(L"SceneManagement");
129 AddFrame(*pSceneManagementFrame);
131 String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
132 if (homePage == (L"IDS_BR_BODY_MOST_VISITED_SITES") || homePage == (L"IDS_BR_BODY_BLANK_PAGE"))
136 else if (homePage == CommonUtil::GetString(L"IDS_BR_BODY_USER_HOMEPAGE"))
138 AppLog("InternetApp::OnAppInitialized homaepage = userhomepage");
139 homePage = SettingPresentationModel::GetInstance()->GetFavoriteUrl();
140 AppLog("InternetApp::OnAppInitialized fav URL = %ls ",homePage.GetPointer());
143 if (__pNewWindowInfo == null)//if the application is launched normally
145 __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene(homePage);
148 if (__pNewWindowInfo == null)
153 ArrayList* pArgList = new(std::nothrow) ArrayList();
154 pArgList->Construct();
155 pArgList->Add(*__pNewWindowInfo);
157 * The GoForward call cannot be moved into the MainFrame::OnInitializing
158 * because when the application is launched from the appcontol, the data(URL)
159 * is not available for Mainframe, and we cannot pass the url information to
160 * the Mainframe because logically MainFrame should not know the URL information.
162 if (E_SUCCESS != pSceneManager->GoForward(ForwardSceneTransition(__pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList))
164 AppLogDebug("CustomAppControl::OnAppInitializing Result = %s", GetLastResult());
166 __pNewWindowInfo = null;
172 __pNewWindowInfo = null;
178 InternetApp::OnAppWillTerminate(void)
185 InternetApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
187 AppLogDebug("Internet::OnAppTerminating");
193 InternetApp::OnForeground(void)
199 InternetApp::OnBackground(void)
205 InternetApp::OnLowMemory(void)
211 InternetApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
217 InternetApp::OnScreenOn(void)
223 InternetApp::OnScreenOff(void)
226 // Unless there is a strong reason to do otherwise, release resources (such as 3D, media, and sensors) to allow the device
227 // to enter the sleep mode to save the battery.
228 // Invoking a lengthy asynchronous method within this listener method can be risky, because it is not guaranteed to invoke a
229 // callback before the device enters the sleep mode.
230 // Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.
233 InternetApp::OnAppControlRequestReceived(RequestId reqId, const String &operationId, const String* pUriScheme, const String *pDataType, const IMap *pArgs)
235 AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN entered %ls",operationId.GetPointer());
237 if (operationId.CompareTo(L"http://tizen.org/appcontrol/operation/view") == 0)
242 urlData = *pUriScheme;
246 int argCount = pArgs->GetCount();
247 AppLog("argCount == %d", argCount);
249 IList *pValues = pArgs->GetValuesN();
252 AppLog("pValues == null");
257 String* pUrl = dynamic_cast<String*>(const_cast<Object*>(pArgs->GetValue(url)));
261 AppLog("pUrl == null");
266 AppLog("URL received %ls", urlData.GetPointer());
268 if (__pNewWindowInfo == null)
270 __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene(urlData, true);
272 if (__pNewWindowInfo == null)
274 if (MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
276 String strTitle = L"Maximum Limit Reached";
277 String strText = L"cannot open more than 9 windows";
278 ShowPopup(strTitle, strText);
282 if (__pMultiWindowManager != null && __pMultiWindowManager->GetAllWindowArrayList()->GetCount() != 0)
284 //if the application is running in background and it receives an appcontrol request it will launch a new(std::nothrow) window here,
285 //otherwise appcontrol request will be handled by OnAppInitialized method
286 SceneManager* pSceneManager = SceneManager::GetInstance();
287 if (pSceneManager == null)
292 ArrayList* pArgList = new(std::nothrow) ArrayList();
293 pArgList->Construct();
294 pArgList->Add(*__pNewWindowInfo);
296 if (E_SUCCESS != pSceneManager->GoForward(ForwardSceneTransition(__pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList))
298 AppLogDebug("CustomAppControl::OnAppInitializing Result = %s", GetLastResult());
300 __pNewWindowInfo = null;
306 __pNewWindowInfo = null;
309 AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN Exit");