1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Browser App Entry point |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #include "BrowserApplication.h" |
|
22 #include <e32std.h> |
|
23 #include <u32std.h> |
|
24 #include <eikapp.h> |
|
25 #include <eikstart.h> |
|
26 #include <MemoryManager.h> |
|
27 #include <avkon.rsg> |
|
28 #include <BrowserNG.rsg> |
|
29 #include <bautils.h> |
|
30 #include <f32file.h> |
|
31 #include <data_caging_path_literals.hrh> |
|
32 #include <hal.h> |
|
33 #include <barsc.h> |
|
34 |
|
35 _LIT(KBrowserResourceFile, "BrowserNG.rsc"); |
|
36 |
|
37 |
|
38 const int KFreeMemoryTarget = 6000000; |
|
39 |
|
40 |
|
41 LOCAL_C CApaApplication* NewApplication( ) |
|
42 { |
|
43 return new CBrowserApplication; |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // SetupThreadHeap - Called for heap creation of thread in this process. |
|
48 // This approach used to keep correct heap for pointers held in static data objects |
|
49 // when they are destructed after E32Main() by OS. |
|
50 // ----------------------------------------------------------------------------- |
|
51 EXPORT_C TInt UserHeap::SetupThreadHeap(TBool aSubThread, SStdEpocThreadCreateInfo& aInfo) |
|
52 { |
|
53 TInt r = KErrNone; |
|
54 if (!aInfo.iAllocator && aInfo.iHeapInitialSize>0) |
|
55 { |
|
56 // new heap required |
|
57 RHeap* pH = NULL; |
|
58 r = CreateThreadHeap(aInfo, pH); |
|
59 if (r == KErrNone && !aSubThread) |
|
60 { |
|
61 // main thread - new allocator created and set as default heap |
|
62 MemoryManager::CreateFastAllocator(); |
|
63 } |
|
64 } |
|
65 else if (aInfo.iAllocator) |
|
66 { |
|
67 // sharing a heap |
|
68 RAllocator* pA = aInfo.iAllocator; |
|
69 pA->Open(); |
|
70 User::SwitchAllocator(pA); |
|
71 } |
|
72 |
|
73 return r; |
|
74 } |
|
75 |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // GetUiUtilitiesResourceFilenameL |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 TInt GetCorrectResourceFilenameL(TFileName& aResourceFileName) |
|
82 { |
|
83 |
|
84 TParse parse; |
|
85 parse.Set(KBrowserResourceFile, &KDC_APP_RESOURCE_DIR, NULL); |
|
86 aResourceFileName.Copy(parse.FullName()); |
|
87 |
|
88 RFs fs; |
|
89 User::LeaveIfError(fs.Connect()); |
|
90 CleanupClosePushL( fs ); |
|
91 |
|
92 // Resource File Name on C: |
|
93 aResourceFileName.Insert( 0, TDriveUnit( EDriveC).Name() ); |
|
94 // try to locate the localised resource |
|
95 BaflUtils::NearestLanguageFile( fs, aResourceFileName ); |
|
96 |
|
97 // if the localised resource is found, the file name is changed to the localised name (z:\resources\webkit.r001) |
|
98 if( !BaflUtils::FileExists( fs, aResourceFileName ) ) { |
|
99 |
|
100 aResourceFileName.Replace( 0, KMaxDriveName, TDriveUnit( EDriveZ ).Name() ); |
|
101 // not found on c drive, try z try to locate the localised resource again |
|
102 BaflUtils::NearestLanguageFile( fs, aResourceFileName ); |
|
103 |
|
104 // if file was not found this time, there is no localised resource with the name |
|
105 if (!BaflUtils::FileExists( fs, aResourceFileName ) ) { |
|
106 User::Leave(KErrNotFound); |
|
107 } |
|
108 } |
|
109 CleanupStack::PopAndDestroy( &fs ); |
|
110 return KErrNone; |
|
111 } |
|
112 |
|
113 void ShowOOMDialogWithNotifierL() |
|
114 { |
|
115 |
|
116 TFileName resourceFileName; |
|
117 User::LeaveIfError(GetCorrectResourceFilenameL(resourceFileName)); |
|
118 |
|
119 RFs fsSession; |
|
120 User::LeaveIfError(fsSession.Connect()); |
|
121 CleanupClosePushL(fsSession); |
|
122 |
|
123 RResourceFile resFile; |
|
124 resFile.OpenL(fsSession,resourceFileName ); |
|
125 resFile.ConfirmSignatureL(0); |
|
126 |
|
127 HBufC8* dataOkButtonBuffer = resFile.AllocReadLC(R_QTN_OK_BUTTON); |
|
128 HBufC8* dataOOMMessageBuffer = resFile.AllocReadLC(R_QTN_BROWSER_DIALOG_OOM); |
|
129 |
|
130 TPtrC16 OkButtonBuffer( ( TUint16* ) dataOkButtonBuffer->Ptr(),dataOkButtonBuffer->Length() / 2 ); |
|
131 TPtrC16 OOMMessageBuffer( ( TUint16* ) dataOOMMessageBuffer->Ptr(),dataOOMMessageBuffer->Length() / 2 ); |
|
132 |
|
133 _LIT(KTxtEmptyLine," "); |
|
134 _LIT(KTxtEmptyButton,""); |
|
135 |
|
136 RNotifier notifier; |
|
137 TInt err = notifier.Connect(); |
|
138 if(err == KErrNone) { |
|
139 TInt whichbutton(-1); |
|
140 TRequestStatus stat; |
|
141 notifier.Notify(OOMMessageBuffer,KTxtEmptyLine,OkButtonBuffer,KTxtEmptyButton,whichbutton,stat); |
|
142 User::WaitForRequest(stat); |
|
143 } |
|
144 |
|
145 notifier.Close(); |
|
146 |
|
147 //this will clear OkButtonBuffer and OOMMessageBuffer |
|
148 CleanupStack::PopAndDestroy(2); |
|
149 resFile.Close(); |
|
150 CleanupStack::PopAndDestroy(&fsSession); |
|
151 |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // E32Main |
|
156 // ----------------------------------------------------------------------------- |
|
157 GLDEF_C TInt E32Main() |
|
158 { |
|
159 //Initilize memory manager... |
|
160 MemoryManager::InitFastAllocator(); |
|
161 |
|
162 TInt freeRAM = 0; |
|
163 TInt r = HAL::Get(HAL::EMemoryRAMFree, freeRAM); |
|
164 |
|
165 if ((r != KErrNone) || freeRAM < KFreeMemoryTarget) |
|
166 { |
|
167 // create clean-up stack as none is created |
|
168 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
169 |
|
170 // Show OOM message through RNotifier ... |
|
171 TRAP_IGNORE(ShowOOMDialogWithNotifierL()); |
|
172 |
|
173 // destroy clean-up stack |
|
174 delete cleanup; |
|
175 return KErrNoMemory; |
|
176 } |
|
177 |
|
178 // Run application event loop |
|
179 return EikStart::RunApplication(NewApplication); |
|
180 } |
|
181 |
|
182 // End of File |
|