|
1 /* |
|
2 * Copyright (c) 2002-2004 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: BrowserLauncherExtension |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "BrowserLauncher.h" |
|
22 #include "BrowserLauncherExtension.h" |
|
23 #include "logger.h" |
|
24 #include "DownloadedContentHandler.h" |
|
25 #include <FavouritesLimits.h> // Context Id:s |
|
26 |
|
27 #include <eikenv.h> |
|
28 #include <AiwGenericParam.h> |
|
29 #include <s32mem.h> |
|
30 #include <coecntrl.h> |
|
31 #include <eikappui.h> |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 NONSHARABLE_CLASS( CLauncherCommandAbsorbingControl ) : public CCoeControl |
|
37 { |
|
38 public: |
|
39 /** |
|
40 * Two-phased constructor. |
|
41 */ |
|
42 static CLauncherCommandAbsorbingControl* NewL( CActiveSchedulerWait& aWaiter, TInt& aExitCode ); |
|
43 |
|
44 /** |
|
45 * Destructor. |
|
46 */ |
|
47 ~CLauncherCommandAbsorbingControl(); |
|
48 |
|
49 /** |
|
50 * Set enabled/disabled status |
|
51 */ |
|
52 inline void SetEnabled( TBool aEnabled ) { iEnabled = aEnabled; } |
|
53 |
|
54 private: |
|
55 /** |
|
56 * From CCoeControl |
|
57 */ |
|
58 virtual TKeyResponse OfferKeyEventL( const TKeyEvent& /*aKeyEvent*/,TEventCode /*aType*/ ); |
|
59 |
|
60 private: |
|
61 /** |
|
62 * C++ default constructor. |
|
63 */ |
|
64 CLauncherCommandAbsorbingControl( CActiveSchedulerWait& aWaiter, TInt& aExitCode ); |
|
65 |
|
66 /** |
|
67 * Symbian OS constructor. |
|
68 */ |
|
69 void ConstructL(); |
|
70 |
|
71 private: // Data |
|
72 CEikAppUi* iAppUi; |
|
73 CActiveSchedulerWait& iWaiter; |
|
74 TBool iEnabled; |
|
75 TInt& iExitCode; |
|
76 }; |
|
77 |
|
78 |
|
79 // ============================ MEMBER FUNCTIONS =============================== |
|
80 |
|
81 |
|
82 // --------------------------------------------------------- |
|
83 // CLauncherCommandAbsorbingControl::CLauncherCommandAbsorbingControl |
|
84 // |
|
85 // --------------------------------------------------------- |
|
86 // |
|
87 CLauncherCommandAbsorbingControl::CLauncherCommandAbsorbingControl( CActiveSchedulerWait& aWaiter, TInt& aExitCode ) |
|
88 : iWaiter( aWaiter ), iExitCode( aExitCode ) |
|
89 { |
|
90 } |
|
91 |
|
92 |
|
93 // --------------------------------------------------------- |
|
94 // CLauncherCommandAbsorbingControl::~CLauncherCommandAbsorbingControl |
|
95 // |
|
96 // --------------------------------------------------------- |
|
97 // |
|
98 CLauncherCommandAbsorbingControl::~CLauncherCommandAbsorbingControl() |
|
99 { |
|
100 if ( iCoeEnv && iAppUi ) |
|
101 { |
|
102 iAppUi->RemoveFromStack( this ); |
|
103 } |
|
104 } |
|
105 |
|
106 |
|
107 // --------------------------------------------------------- |
|
108 // CLauncherCommandAbsorbingControl::NewLC |
|
109 // |
|
110 // --------------------------------------------------------- |
|
111 // |
|
112 CLauncherCommandAbsorbingControl* CLauncherCommandAbsorbingControl::NewL( CActiveSchedulerWait& aWaiter, TInt& aExitCode ) |
|
113 { |
|
114 CLauncherCommandAbsorbingControl* self = new( ELeave ) CLauncherCommandAbsorbingControl( aWaiter, aExitCode ); |
|
115 CleanupStack::PushL( self ); |
|
116 self->ConstructL(); |
|
117 CleanupStack::Pop( self ); |
|
118 return self; |
|
119 } |
|
120 |
|
121 |
|
122 |
|
123 // --------------------------------------------------------- |
|
124 // CLauncherCommandAbsorbingControl::ConstructL |
|
125 // |
|
126 // --------------------------------------------------------- |
|
127 // |
|
128 void CLauncherCommandAbsorbingControl::ConstructL() |
|
129 { |
|
130 iAppUi = iEikonEnv->EikAppUi(); |
|
131 // |
|
132 CreateWindowL(); |
|
133 SetExtent( TPoint( 0,0 ), TSize( 0,0 ) ); |
|
134 ActivateL(); |
|
135 SetPointerCapture( ETrue ); |
|
136 ClaimPointerGrab( ETrue ); |
|
137 // |
|
138 iAppUi->AddToStackL( this, ECoeStackPriorityDialog ); |
|
139 } |
|
140 |
|
141 |
|
142 // --------------------------------------------------------- |
|
143 // CLauncherCommandAbsorbingControl::OfferKeyEventL |
|
144 // |
|
145 // --------------------------------------------------------- |
|
146 // |
|
147 TKeyResponse CLauncherCommandAbsorbingControl::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
148 { |
|
149 TKeyResponse response = EKeyWasNotConsumed; |
|
150 // |
|
151 if ( iEnabled ) |
|
152 { |
|
153 if ( aKeyEvent.iCode == EKeyEscape && aType == EEventKey ) |
|
154 { |
|
155 if ( iWaiter.IsStarted() ) |
|
156 { |
|
157 iExitCode = KErrCancel; |
|
158 iWaiter.AsyncStop(); |
|
159 } |
|
160 } |
|
161 |
|
162 response = EKeyWasConsumed; |
|
163 } |
|
164 // |
|
165 return response; |
|
166 } |
|
167 |
|
168 // ============================ MEMBER FUNCTIONS =============================== |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CBrowserLauncherExtension::CBrowserLauncherExtension |
|
172 // C++ default constructor can NOT contain any code, that |
|
173 // might leave. |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 CBrowserLauncherExtension::CBrowserLauncherExtension |
|
177 ( CBrowserLauncher& aLauncher ) |
|
178 : CActive( CActive::EPriorityStandard ), iLauncher( aLauncher ), iBufferSizeP( iBufferSize ) |
|
179 { |
|
180 CActiveScheduler::Add( this ); |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CBrowserLauncherExtension::ConstructL |
|
185 // Symbian 2nd phase constructor can leave. |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 void CBrowserLauncherExtension::ConstructL() |
|
189 { |
|
190 |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CBrowserLauncherExtension::NewL |
|
195 // Two-phased constructor. |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 CBrowserLauncherExtension* CBrowserLauncherExtension::NewL( CBrowserLauncher& aLauncher ) |
|
199 { |
|
200 LOG_ENTERFN( "CBrowserLauncherExtension::NewL" ); |
|
201 CBrowserLauncherExtension* self = new (ELeave) CBrowserLauncherExtension( aLauncher ); |
|
202 CleanupStack::PushL(self); |
|
203 self->ConstructL(); |
|
204 CleanupStack::Pop(self); |
|
205 return self; |
|
206 } |
|
207 |
|
208 // Destructor |
|
209 CBrowserLauncherExtension::~CBrowserLauncherExtension() |
|
210 { |
|
211 LOG_ENTERFN( "CBrowserLauncherExtension::~CBrowserLauncherExtension" ); |
|
212 Cancel(); |
|
213 iLauncherClientService.Close(); |
|
214 delete iReceiveBuffer; |
|
215 delete iPackedLauncherData; |
|
216 delete iCommandAbsorber; |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CBrowserLauncherExtension::WaitBrowserToFinish |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 TInt CBrowserLauncherExtension::WaitBrowserToFinish() |
|
224 { |
|
225 LOG_ENTERFN( "CBrowserLauncherExtension::WaitBrowserToFinish" ); |
|
226 if( !iCommandAbsorber ) |
|
227 { |
|
228 iCommandAbsorber = CLauncherCommandAbsorbingControl::NewL( iWait, iExitCode ); |
|
229 } |
|
230 iCommandAbsorber->SetEnabled( ETrue ); |
|
231 iWait.Start(); |
|
232 iCommandAbsorber->SetEnabled( EFalse ); |
|
233 |
|
234 // This class will complete us as an MAknServerAppExitObserver. |
|
235 return iExitCode; |
|
236 } |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // CBrowserLauncherExtension::SetPackedLauncherData |
|
240 // ----------------------------------------------------------------------------- |
|
241 // |
|
242 void CBrowserLauncherExtension::SetPackedLauncherData( HBufC8* aBuf ) |
|
243 { |
|
244 delete iPackedLauncherData; |
|
245 iPackedLauncherData = aBuf; |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CBrowserLauncherExtension::DoCancel |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 void CBrowserLauncherExtension::DoCancel() |
|
253 { |
|
254 } |
|
255 |
|
256 // ----------------------------------------------------------------------------- |
|
257 // CBrowserLauncherExtension::RunL |
|
258 // ----------------------------------------------------------------------------- |
|
259 // |
|
260 void CBrowserLauncherExtension::RunL() |
|
261 { |
|
262 } |
|
263 |
|
264 // ----------------------------------------------------------------------------- |
|
265 // CBrowserLauncherExtension::RunError |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 TInt CBrowserLauncherExtension::RunError( TInt aError ) |
|
269 { |
|
270 return aError; |
|
271 } |
|
272 |
|
273 // ----------------------------------------------------------------------------- |
|
274 // CBrowserLauncherExtension::HandleServerAppExit |
|
275 // ----------------------------------------------------------------------------- |
|
276 // |
|
277 void CBrowserLauncherExtension::HandleServerAppExit( TInt aReason ) |
|
278 { |
|
279 LOG_ENTERFN( "CBrowserLauncherExtension::HandleServerAppExit" ); |
|
280 if ( iWait.IsStarted() ) |
|
281 { |
|
282 /* If the Launcher was started synchronously, then |
|
283 iBrowserLauncherClientExitObserver cannot be set => |
|
284 no need to call iBrowserLauncherClientExitObserver->HandleServerAppExit() */ |
|
285 |
|
286 // Note down the exit reason |
|
287 iExitCode = aReason; |
|
288 iWait.AsyncStop(); |
|
289 iCommandAbsorber->SetEnabled( EFalse ); |
|
290 } |
|
291 else if ( iBrowserLauncherClientExitObserver ) |
|
292 { |
|
293 // Forward the exit event |
|
294 iBrowserLauncherClientExitObserver->HandleServerAppExit( aReason ); |
|
295 } |
|
296 } |
|
297 |
|
298 // ----------------------------------------------------------------------------- |
|
299 // CBrowserLauncherExtension::HandleReceivedDataL |
|
300 // ----------------------------------------------------------------------------- |
|
301 // |
|
302 void CBrowserLauncherExtension::HandleReceivedDataL( TRequestStatus aStatus ) |
|
303 { |
|
304 LOG_ENTERFN( "CBrowserLauncherExtension::HandleReceivedDataL" ); |
|
305 |
|
306 LOG_WRITE_FORMAT(" aStatus.Int(): %d", aStatus.Int()); |
|
307 User::LeaveIfError( aStatus.Int() ); |
|
308 |
|
309 //--------------------create buffer for server----- |
|
310 // Create buffer to hold data, sent by Browser application. |
|
311 // iBufferSize was defined by the server by now... |
|
312 delete iReceiveBuffer; |
|
313 iReceiveBuffer = 0; |
|
314 iReceiveBuffer = HBufC8::NewL( iBufferSize ); |
|
315 TPtr8 tempRecBuf ( iReceiveBuffer->Des() ); |
|
316 // Send the allocated descriptor to server, who fills it. |
|
317 User::LeaveIfError( iLauncherClientService.SendSyncBuffer( tempRecBuf ) ); |
|
318 // OK, buffer has been filled. |
|
319 |
|
320 //--------------------internalize stream----------- |
|
321 // Create Stream object. |
|
322 RDesReadStream readStream( tempRecBuf ); |
|
323 CleanupClosePushL( readStream ); |
|
324 // Create param list object |
|
325 CAiwGenericParamList* paramList = CAiwGenericParamList::NewL( readStream ); |
|
326 LOG_WRITE(" paramList OK"); |
|
327 CleanupStack::PopAndDestroy( &readStream ); |
|
328 CleanupStack::PushL( paramList ); |
|
329 //--------------------eof internalize stream------- |
|
330 |
|
331 TBool clientWantsToContinue( EFalse ); |
|
332 TBool wasContentHandled = EFalse; |
|
333 |
|
334 // If the embedding application handles the downloaded content. |
|
335 if ( iDownloadedContentHandler ) |
|
336 { |
|
337 LOG_WRITE_FORMAT(" iDownloadedContentHandler: 0x%x", iDownloadedContentHandler); |
|
338 // Extract the file name from the generic paam list |
|
339 TInt index(0); |
|
340 const TAiwGenericParam* paramFileName = |
|
341 paramList->FindFirst( index, EGenericParamFile, EVariantTypeDesC ); |
|
342 TPtrC fileName; |
|
343 if ( index == KErrNotFound ) |
|
344 { |
|
345 fileName.Set( KNullDesC ); |
|
346 } |
|
347 else |
|
348 { |
|
349 fileName.Set( paramFileName->Value().AsDes() ); |
|
350 } |
|
351 |
|
352 // Call the embedding app with these parameters, to handle the downloaded |
|
353 // content |
|
354 TRAPD( handlerLeave, wasContentHandled = |
|
355 iDownloadedContentHandler->HandleContentL( |
|
356 fileName, |
|
357 *paramList, |
|
358 clientWantsToContinue ) ); |
|
359 ++handlerLeave; // To avoid warnings. Used for logging. |
|
360 LOG_WRITE_FORMAT(" handlerLeave: %d", handlerLeave); |
|
361 } |
|
362 |
|
363 // Tell the server app the output parameters |
|
364 User::LeaveIfError( iLauncherClientService.SendSyncBools |
|
365 ( clientWantsToContinue, wasContentHandled ) ); |
|
366 |
|
367 // This async request completed, reinitialize it |
|
368 iLauncherClientService.SendAsync(iBufferSizeP); |
|
369 |
|
370 CleanupStack::PopAndDestroy( paramList ); // paramList |
|
371 } |
|
372 |
|
373 // End of file |