23 #include <StringLoader.h> |
23 #include <StringLoader.h> |
24 #include <WidgetUi.rsg> |
24 #include <WidgetUi.rsg> |
25 #include <avkon.hrh> |
25 #include <avkon.hrh> |
26 #include <aknmessagequerydialog.h> |
26 #include <aknmessagequerydialog.h> |
27 #include <ActiveApDb.h> |
27 #include <ActiveApDb.h> |
28 #include <escapeutils.h> |
28 #include <EscapeUtils.h> |
29 #include <uri16.h> |
29 #include <Uri16.h> |
30 #include <BrCtlDefs.h> |
30 #include <brctldefs.h> |
31 #include "WidgetUiObserver.h" |
31 #include "WidgetUiObserver.h" |
32 #include "WidgetUiWindow.h" |
32 #include "WidgetUiWindow.h" |
33 #include "WidgetUiWindowView.h" |
33 #include "WidgetUiWindowView.h" |
34 #include "WidgetUiWindowManager.h" |
34 #include "WidgetUiWindowManager.h" |
35 #include "WidgetUiWindowContainer.h" |
35 #include "WidgetUiWindowContainer.h" |
49 // CONSTANTS |
49 // CONSTANTS |
50 _LIT( KFileScheme, "file://" ); |
50 _LIT( KFileScheme, "file://" ); |
51 _LIT( KDefaultDrivePath, "C:\\" ); |
51 _LIT( KDefaultDrivePath, "C:\\" ); |
52 _LIT( KPathChar, "\\" ); |
52 _LIT( KPathChar, "\\" ); |
53 _LIT( KLprojExt, ".lproj" ); |
53 _LIT( KLprojExt, ".lproj" ); |
|
54 |
|
55 |
|
56 _LIT( KJavaExtension, ".js"); |
|
57 _LIT( KJavaMimeType, "application/x-javascript"); |
|
58 _LIT( KCssExtension, ".css"); |
|
59 _LIT( KCssMimeType,"text/css"); |
|
60 _LIT( KPngExtension, ".png"); |
|
61 _LIT( KPngMimeType, "image/png"); |
|
62 _LIT( KGifExtension, ".gif"); |
|
63 _LIT( KGifMimeType,"image/gif"); |
54 |
64 |
55 // MACROS |
65 // MACROS |
56 |
66 |
57 // LOCAL CONSTANTS AND MACROS |
67 // LOCAL CONSTANTS AND MACROS |
58 |
68 |
247 |
257 |
248 if ( !isSandboxed ) |
258 if ( !isSandboxed ) |
249 { // For files in Public areas, don't use localized subdirectory |
259 { // For files in Public areas, don't use localized subdirectory |
250 TranslateURLToFilenameL( aEmbeddedUrl, KNullDesC); |
260 TranslateURLToFilenameL( aEmbeddedUrl, KNullDesC); |
251 } |
261 } |
252 |
262 |
253 HBufC8* buf = ReadFileL( *iFileName); |
263 HBufC8* buf = ReadFileL( *iFileName); |
254 |
264 |
255 if ( !buf && isSandboxed ) |
265 if ( !buf && isSandboxed ) |
256 { // In case of failure, fall-back to generic/non-localized content |
266 { // In case of failure, fall-back to generic/non-localized content |
257 TranslateURLToFilenameL( aEmbeddedUrl, KNullDesC ); |
267 TranslateURLToFilenameL( aEmbeddedUrl, KNullDesC ); |
264 } |
274 } |
265 |
275 |
266 CleanupStack::PushL( buf ); |
276 CleanupStack::PushL( buf ); |
267 HBufC* contentType = NULL; |
277 HBufC* contentType = NULL; |
268 TPtrC p( NULL, 0 ); |
278 TPtrC p( NULL, 0 ); |
269 contentType = RecognizeLC( *iFileName, *buf ); |
279 |
|
280 // file extension check for .js, .css, .png & .gif |
|
281 TInt err(0); |
|
282 //.js |
|
283 err = iFileName->FindF(KJavaExtension); |
|
284 if(err != KErrNotFound) |
|
285 { |
|
286 //.js |
|
287 contentType = HBufC::NewLC(KJavaMimeType().Length()); |
|
288 *contentType = KJavaMimeType; |
|
289 } |
|
290 else |
|
291 { |
|
292 //.css |
|
293 err = iFileName->FindF(KCssExtension) ; |
|
294 if(err != KErrNotFound) |
|
295 { |
|
296 contentType = HBufC::NewLC(KCssMimeType().Length()); |
|
297 *contentType = KCssMimeType; |
|
298 } |
|
299 else if (err == KErrNotFound) |
|
300 { |
|
301 //.png |
|
302 err = iFileName->FindF(KPngExtension); |
|
303 if(err != KErrNotFound) |
|
304 { |
|
305 //.png |
|
306 contentType = HBufC::NewLC(KPngMimeType().Length()); |
|
307 *contentType = KPngMimeType; |
|
308 } |
|
309 else |
|
310 { |
|
311 //.gif |
|
312 err = iFileName->FindF(KGifExtension) ; |
|
313 if(err!=KErrNotFound) |
|
314 { |
|
315 contentType = HBufC::NewLC(KGifMimeType().Length()); |
|
316 *contentType = KGifMimeType; |
|
317 } |
|
318 } |
|
319 } |
|
320 } |
|
321 if(err == KErrNotFound) |
|
322 { |
|
323 //Let's use existing iFile the handle to the opened file (no need to re-open it) |
|
324 contentType = RecognizeLC( *iFileName); |
|
325 |
|
326 } |
|
327 iFile.Close(); |
|
328 |
270 aEmbeddedLinkContent.HandleResolveComplete( *contentType, p, buf ); |
329 aEmbeddedLinkContent.HandleResolveComplete( *contentType, p, buf ); |
271 CleanupStack::PopAndDestroy( 2, buf ); // contentType, buf |
330 CleanupStack::PopAndDestroy( 2, buf ); // contentType, buf |
272 return ETrue; |
331 return ETrue; |
273 } |
332 } |
274 |
333 |
411 } |
470 } |
412 |
471 |
413 return EFalse; |
472 return EFalse; |
414 } |
473 } |
415 |
474 |
416 // ----------------------------------------------------------------------------- |
475 // |
417 // CWidgetUiObserver::ReadFile |
476 // ----------------------------------------------------------------------------- |
|
477 // CWidgetUiObserver::ReadFileL |
418 // ----------------------------------------------------------------------------- |
478 // ----------------------------------------------------------------------------- |
419 // |
479 // |
420 HBufC8* CWidgetUiObserver::ReadFileL( const TDesC& aFileName ) |
480 HBufC8* CWidgetUiObserver::ReadFileL( const TDesC& aFileName ) |
421 { |
481 { |
422 RFile file; |
482 if (KErrNone != iFile.Open(CCoeEnv::Static()->FsSession(), aFileName, EFileRead|EFileShareAny) ) |
423 |
|
424 if (KErrNone != file.Open( CCoeEnv::Static()->FsSession(), aFileName, EFileRead ) ) |
|
425 { |
483 { |
426 return NULL; |
484 return NULL; |
427 } |
485 } |
428 |
486 |
429 CleanupClosePushL( file ); |
|
430 |
|
431 TInt size; |
487 TInt size; |
432 User::LeaveIfError( file.Size( size ) ); |
488 User::LeaveIfError( iFile.Size( size ) ); |
433 HBufC8* buf = HBufC8::NewLC( size ); |
489 HBufC8* buf = HBufC8::NewLC( size ); |
434 TPtr8 bufPtr( buf->Des() ); |
490 TPtr8 bufPtr( buf->Des() ); |
435 User::LeaveIfError( file.Read( bufPtr ) ); |
491 User::LeaveIfError( iFile.Read( bufPtr ) ); |
436 CleanupStack::Pop( buf ); |
492 CleanupStack::Pop( buf ); |
437 CleanupStack::PopAndDestroy( &file ); |
|
438 return buf; |
493 return buf; |
439 } |
494 } |
440 |
495 // |
441 // ----------------------------------------------------------------------------- |
496 // ----------------------------------------------------------------------------- |
442 // CWidgetUiObserver::RecognizeL |
497 // CWidgetUiObserver::RecognizeLC |
443 // ----------------------------------------------------------------------------- |
498 // ----------------------------------------------------------------------------- |
444 // |
499 // |
445 HBufC* CWidgetUiObserver::RecognizeLC( const TDesC& aFileName, const TDesC8& aData ) |
500 HBufC* CWidgetUiObserver::RecognizeLC( const TDesC& aFileName) |
446 { |
501 { |
447 TDataRecognitionResult dataType; |
502 TDataRecognitionResult dataType; |
448 RApaLsSession apaSession; |
503 RApaLsSession apaSession; |
449 TInt ret; |
504 TInt ret; |
450 |
505 |
451 CleanupClosePushL(apaSession); |
506 CleanupClosePushL(apaSession); |
452 User::LeaveIfError( apaSession.Connect() ); |
507 User::LeaveIfError( apaSession.Connect() ); |
453 |
508 |
454 // Ask the application architecture to find the file type |
509 // Ask the application architecture to find the file type |
455 ret = apaSession.RecognizeData( aFileName, aData, dataType ); |
510 ret = apaSession.RecognizeData( iFile, dataType ); |
456 apaSession.Close(); |
511 apaSession.Close(); |
|
512 |
457 CleanupStack::PopAndDestroy(1, &apaSession); |
513 CleanupStack::PopAndDestroy(1, &apaSession); |
458 |
514 |
459 TPtrC8 mimeTypePtr = dataType.iDataType.Des8(); |
515 TPtrC8 mimeTypePtr = dataType.iDataType.Des8(); |
460 TInt len = mimeTypePtr.Length() + 1; |
516 TInt len = mimeTypePtr.Length() + 1; |
461 HBufC* contentTypeString = HBufC::NewLC( len );; |
517 HBufC* contentTypeString = HBufC::NewLC( len );; |
462 |
518 |
463 if ( ret == KErrNone && |
519 if ( ret == KErrNone && |
464 ( dataType.iConfidence == CApaDataRecognizerType::ECertain ) || |
520 ( dataType.iConfidence == CApaDataRecognizerType::ECertain ) || |
465 ( dataType.iConfidence == CApaDataRecognizerType::EProbable ) ) |
521 ( dataType.iConfidence == CApaDataRecognizerType::EProbable) || |
|
522 ( dataType.iConfidence == CApaDataRecognizerType::EPossible) ) |
466 { |
523 { |
467 // If the file type was found, try to match it to a known file type |
524 // If the file type was found, try to match it to a known file type |
468 contentTypeString->Des().Copy( mimeTypePtr ); |
525 contentTypeString->Des().Copy( mimeTypePtr ); |
469 contentTypeString->Des().ZeroTerminate(); |
526 contentTypeString->Des().ZeroTerminate(); |
470 } |
527 } |