// ---------------------------------------------------------
// CBrCtlApiTestObserver::ResolveLinkL
// ---------------------------------------------------------
//
TBool CBrCtlApiTestObserver::ResolveLinkL(const TDesC& aUrl, const TDesC& /* aCurrentUrl */,
                   MBrCtlLinkContent& aBrCtlLinkContent) 
    {
    if (IsFileScheme(aUrl))
        {
        GetFileNameL(aUrl);
        HBufC8* buf = ReadFileLC(*iFileName);
        HBufC* contentType = NULL;
        TPtrC p(NULL, 0);
        contentType = RecognizeLC(*iFileName, *buf);
        aBrCtlLinkContent.HandleResolveComplete(*contentType, p, buf);        
        CleanupStack::PopAndDestroy(2); // contentType, buf
        return ETrue;
        }
    return EFalse;
    }
TBool
CContentWindowContainer::GetFileL(
      class MBrCtlLinkContent *aLinkContent, const TDesC& aUrl)
{
   RFs myFs;
   RFile myFile;

   myFs.Connect();

   HBufC8* data = HBufC8::NewLC(1024*100);
   TPtr8 ptr = data->Des();
   
   TBool foo = ETrue;

   _LIT(KJpg, ".jpg");
   if (KErrNotFound != aUrl.Find(KJpg)) {
      foo = EFalse;
   }

   if (foo) {
      myFile.Open(myFs, Kfilename, EFileShareReadersOnly|EFileRead);
   } else {
      myFile.Open(myFs, Kimagename, EFileShareReadersOnly|EFileRead);
   }

   myFile.Read(ptr, 1024*100);
   myFile.Close();

   HBufC* contentType = NULL;
   contentType = RecognizeLC(aUrl, ptr);

   aLinkContent->HandleResolveComplete(*contentType, KCharSet, data);

   CleanupStack::PopAndDestroy(contentType);
   CleanupStack::PopAndDestroy(data);

   myFs.Close();

   return ETrue;
}
// -----------------------------------------------------------------------------
// CWidgetUiObserver::ResolveEmbeddedLinkL
// -----------------------------------------------------------------------------
//
TBool CWidgetUiObserver::ResolveEmbeddedLinkL(const TDesC& aEmbeddedUrl,
                                              const TDesC& aCurrentUrl,
                                              TBrCtlLoadContentType aLoadContentType,
                                              MBrCtlLinkContent& aEmbeddedLinkContent)
    {
    (void)aCurrentUrl;
    (void)aLoadContentType;
#ifdef _DEBUG
    _LIT(KResolveEmbeddedLink, "Resolve embedded link  aEmbeddedUrl = :%s:, aCurrentUrl = :%s:, aLoadContentType = %d");

    if ( iCanLog )
        {
        iFileLogger.WriteFormat( KResolveEmbeddedLink, aEmbeddedUrl, aCurrentUrl, aLoadContentType );
        }
#endif
    if ( IsFileScheme( aEmbeddedUrl ) )
        {

        // DENY if accessing anything inside WidgetUI's private dir AND that file is not inside 
        // the widget's own "sandbox". We define an installed widget's "sandbox" to be anything
        // under e:/private/10282822/<widget ID>/

        // Convert URL form to a more friendly path form, with locale-specific subdirectory
        TFileName lprojName;
        iWindow->WindowManager().WidgetUIClientSession().GetLprojName( lprojName );
        TranslateURLToFilenameL( aEmbeddedUrl, lprojName ); 
        
		iFs.PrivatePath(iAppPrivatePath);        
        // TRUE if e:/private/10282822/*/* was requested. It may or may not be inside a widget's sandbox.
        TBool isInsidePrivateDir = ( iFileName && ( (*iFileName).FindF(iAppPrivatePath) == KMaxDriveName ) ) ? ETrue : EFalse; 

        HBufC* widgetPath = iWindow->WidgetPath();          // The widget's sandbox. Object not ours.
        // TRUE if e:/private/10282822/<widgetID>/foo.js was requested. This is INSIDE widget's sandbox
        TBool isSandboxed = ( iFileName && widgetPath && (*iFileName).FindF( *widgetPath ) == 0 ) ? ETrue : EFalse;
        
        if ( isInsidePrivateDir && !isSandboxed )
            {   //Acess denied!
            User::Leave(KErrAccessDenied);
            }
        
        if ( !isSandboxed )
            { // For files in Public areas, don't use localized subdirectory
            TranslateURLToFilenameL( aEmbeddedUrl, KNullDesC); 
            } 
        
        HBufC8* buf = ReadFileL( *iFileName);
        
        if ( !buf && isSandboxed )
            { // In case of failure, fall-back to generic/non-localized content
            TranslateURLToFilenameL( aEmbeddedUrl, KNullDesC );
            buf = ReadFileL( *iFileName);
            }
        
        if ( !buf )
            {
            User::Leave(KErrGeneral);  
            }
        
        CleanupStack::PushL( buf );
        HBufC* contentType = NULL;
        TPtrC p( NULL, 0 );
        contentType = RecognizeLC( *iFileName, *buf );
        aEmbeddedLinkContent.HandleResolveComplete( *contentType, p, buf );
        CleanupStack::PopAndDestroy( 2, buf ); // contentType, buf
        return ETrue;
        }

    return EFalse;
    }