S60 3rd Edition SDK for Symbian OS
Example Applications Guide

CBrCtlSampleAppLinkResolver Class Reference

#include <BrCtlSampleAppLinkResolver.h>

List of all members.

Public Member Functions

 ~CBrCtlSampleAppLinkResolver ()
TBool ResolveEmbeddedLinkL (const TDesC &aEmbeddedUrl, const TDesC &aCurrentUrl, TBrCtlLoadContentType aLoadContentType, MBrCtlLinkContent &aEmbeddedLinkContent)
TBool ResolveLinkL (const TDesC &aUrl, const TDesC &aCurrentUrl, MBrCtlLinkContent &aBrCtlLinkContent)
void CancelAll ()

Static Public Member Functions

static CBrCtlSampleAppLinkResolver * NewL ()

Private Member Functions

void ConstructL ()
TBool IsFileScheme (const TDesC &aFileName)
HBufC8 * ReadFileLC (const TDesC &aFileName)
HBufC * RecognizeLC (const TDesC &aFileName, const TDesC8 &aData)
TBool GetFileNameL (const TDesC &aFileName)

Private Attributes

HBufC * iFileName


Detailed Description

CBrCtlSampleAppLinkResolver class. This class inherits from the MBrCtlLinkResolver interface. This class is used to provide a callback mechanism for receiving the content of an embedded link or the content of a user-initiated load request.

Definition at line 32 of file BrCtlSampleAppLinkResolver.h.


Constructor & Destructor Documentation

CBrCtlSampleAppLinkResolver::~CBrCtlSampleAppLinkResolver (   ) 
 

Destructor.

Definition at line 95 of file BrCtlSampleAppLinkResolver.cpp.

References iFileName.

00096     {
00097     delete iFileName;
00098     }


Member Function Documentation

CBrCtlSampleAppLinkResolver * CBrCtlSampleAppLinkResolver::NewL (   )  [static]
 

Two-phased constructor.

Definition at line 106 of file BrCtlSampleAppLinkResolver.cpp.

References ConstructL().

00107     {
00108     CBrCtlSampleAppLinkResolver* self = new(ELeave)CBrCtlSampleAppLinkResolver;
00109     CleanupStack::PushL(self);
00110     self->ConstructL();
00111     CleanupStack::Pop();
00112     return self;
00113     }

TBool CBrCtlSampleAppLinkResolver::ResolveEmbeddedLinkL (  const TDesC &  aEmbeddedUrl,
const TDesC &  aCurrentUrl,
TBrCtlLoadContentType  aLoadContentType,
MBrCtlLinkContent &  aEmbeddedLinkContent
) 
 

Browser plug-in calls this method when embedded link is found. Used with ECapabilityClientResolveEmbeddedURL

Since:
2.8
Parameters:
aEmbeddedUrl The url of the embedded content
aCurrentUrl The url of the current page
aLoadContentType The expected type of the embedded content
aEmbeddedLinkContent A callback interface to return the embedded content
Returns:
EFalse, if the browser will resolve the link

Definition at line 30 of file BrCtlSampleAppLinkResolver.cpp.

References GetFileNameL(), iFileName, IsFileScheme(), ReadFileLC(), and RecognizeLC().

00034     {        
00035     if (IsFileScheme(aEmbeddedUrl))
00036         {
00037         GetFileNameL(aEmbeddedUrl);
00038         HBufC8* buf = ReadFileLC(*iFileName);
00039         HBufC* contentType = NULL;
00040         TPtrC p(NULL, 0);
00041         contentType = RecognizeLC(*iFileName, *buf);
00042         aEmbeddedLinkContent.HandleResolveComplete(*contentType, p, buf);        
00043         CleanupStack::PopAndDestroy(2); // contentType, buf
00044         return ETrue;
00045         }
00046     return EFalse;
00047     }

TBool CBrCtlSampleAppLinkResolver::ResolveLinkL (  const TDesC &  aUrl,
const TDesC &  aCurrentUrl,
MBrCtlLinkContent &  aBrCtlLinkContent
) 
 

Browser plug-in calls this method when the user requests to load content via selecting a link, or any other way. Used with ECapabilityClientNotifyURL

Since:
2.8
Parameters:
aUrl The requested url
aCurrentUrl The url of the current page
aBrCtlLinkContent A callback interface to return the embedded content
Returns:
EFalse, if the browser will resolve the link

Definition at line 54 of file BrCtlSampleAppLinkResolver.cpp.

References GetFileNameL(), iFileName, IsFileScheme(), ReadFileLC(), and RecognizeLC().

00057     {        
00058     if (IsFileScheme(aUrl))
00059         {
00060         GetFileNameL(aUrl);
00061         HBufC8* buf = ReadFileLC(*iFileName);
00062         HBufC* contentType = NULL;
00063         TPtrC p(NULL, 0);
00064         contentType = RecognizeLC(*iFileName, *buf);
00065         aBrCtlLinkContent.HandleResolveComplete(*contentType, p, buf);        
00066         CleanupStack::PopAndDestroy(2); // contentType, buf
00067         return ETrue;
00068         }
00069     return EFalse;
00070     }

void CBrCtlSampleAppLinkResolver::CancelAll (   ) 
 

Cancel all outstanding resolving operations

Since:
2.8
Returns:
void

Definition at line 77 of file BrCtlSampleAppLinkResolver.cpp.

00078     {        
00079     }

void CBrCtlSampleAppLinkResolver::ConstructL (   )  [private]
 

By default Symbian 2nd phase constructor is private.

Definition at line 87 of file BrCtlSampleAppLinkResolver.cpp.

00088     {
00089     }

TBool CBrCtlSampleAppLinkResolver::IsFileScheme (  const TDesC &  aFileName  )  [private]
 

Find if the scheme if file://

Definition at line 120 of file BrCtlSampleAppLinkResolver.cpp.

00121     {
00122     _LIT(KFileScheme, "file://");
00123     if (aFileName.Length() > 0 && aFileName.Ptr() != NULL)
00124         {
00125         if (aFileName.FindF(KFileScheme) == 0)
00126             {
00127             return ETrue;
00128             }
00129         }
00130     return EFalse;
00131     }

HBufC8 * CBrCtlSampleAppLinkResolver::ReadFileLC (  const TDesC &  aFileName  )  [private]
 

Read the file.

Definition at line 138 of file BrCtlSampleAppLinkResolver.cpp.

00139     {
00140     RFs rfs;
00141     RFile file;
00142     User::LeaveIfError(rfs.Connect());
00143     CleanupClosePushL(rfs);
00144     User::LeaveIfError(file.Open(rfs, aFileName, EFileRead));
00145     CleanupClosePushL(file);
00146     TInt size;
00147     User::LeaveIfError(file.Size(size));
00148     HBufC8* buf = HBufC8::NewLC(size);
00149     TPtr8 bufPtr(buf->Des());
00150     User::LeaveIfError(file.Read(bufPtr));
00151     CleanupStack::Pop(); // buf
00152     CleanupStack::PopAndDestroy(2); // file, rfs
00153     CleanupStack::PushL(buf);
00154     return buf;
00155     }

HBufC * CBrCtlSampleAppLinkResolver::RecognizeLC (  const TDesC &  aFileName,
const TDesC8 &  aData
)  [private]
 

Rcognize the mime type.

Definition at line 162 of file BrCtlSampleAppLinkResolver.cpp.

00163     {
00164     TDataRecognitionResult dataType;
00165     RApaLsSession apaSession;
00166     TInt ret;
00167     HBufC* contentTypeString = NULL;
00168 
00169     User::LeaveIfError(apaSession.Connect());
00170     // Ask the application architecture to find the file type
00171     ret = apaSession.RecognizeData(aFileName, aData, dataType);
00172     apaSession.Close();
00173 
00174     if (ret == KErrNone &&
00175         (dataType.iConfidence == CApaDataRecognizerType::ECertain) ||
00176         (dataType.iConfidence == CApaDataRecognizerType::EProbable))
00177         {
00178         // If the file type was found, try to match it to a known file type
00179         TPtrC8 mimeTypePtr = dataType.iDataType.Des8();
00180         TInt len = mimeTypePtr.Length() + 1;
00181         contentTypeString = HBufC::NewL(len); 
00182         contentTypeString->Des().Copy(mimeTypePtr);
00183         contentTypeString->Des().ZeroTerminate();
00184         }
00185     CleanupStack::PushL(contentTypeString);
00186     return contentTypeString;
00187     }

TBool CBrCtlSampleAppLinkResolver::GetFileNameL (  const TDesC &  aFileName  )  [private]
 

Translate the file name from a URL to a valid file name in the system..

Definition at line 195 of file BrCtlSampleAppLinkResolver.cpp.

00196     {
00197     // This function accepts URLs in the following format:
00198     // file://filename.xxx
00199     // file:///filename.xxx
00200     // file://c:/filename.xxx
00201     // file:///c:/filename.xxx
00202     //
00203     _LIT(KFileScheme, "file://");
00204     _LIT(KDefaultDrivePath, "C:\\");
00205     _LIT(KPathChar, "\\");
00206     
00207     TInt count;
00208     TInt index = 0;
00209     TBool drvLetter = EFalse;
00210     TUint16 c;
00211     
00212     // Verify the file scheme
00213     TPtrC urlPtr(aFileName);
00214     if (urlPtr.FindF(KFileScheme) != 0)
00215         {
00216         return EFalse;
00217         }
00218     urlPtr.Set(urlPtr.Mid(KFileScheme().Length()));
00219     
00220     // make sure there are enough characters in the filename before
00221     // trying to check them
00222     count = urlPtr.Length();
00223     if(count == 0)
00224         {
00225         return EFalse;            // no filename, so can't look at urlPtr[0]
00226         }
00227     
00228     // Skip the first '/' if there is one
00229     if (urlPtr[0] == '/')
00230         {
00231         urlPtr.Set(urlPtr.Mid(1));
00232         }
00233     count = urlPtr.Length();
00234     
00235     // Is there a drive letter?
00236     if(count > 1)
00237         {
00238         // can check for drive letter
00239         if (urlPtr[1 + index] == ':')
00240             {
00241             drvLetter = ETrue;
00242             }
00243         }
00244     if(drvLetter == EFalse)
00245         {
00246         // 3 additional characters for the string "c:\"
00247         count = urlPtr.Length() + 3;
00248         }
00249     iFileName = HBufC::NewL(count);
00250     if (!drvLetter)
00251         {
00252         iFileName->Des().Append(KDefaultDrivePath);
00253         }
00254     
00255     TBool fragment(EFalse);
00256     // Convert relative path containing /./ and /../ to absolute path
00257     for (; index < urlPtr.Length() && !fragment; index ++)
00258         {
00259         switch(urlPtr[index])
00260             {
00261             case '#':    //Check if there is a fragment '#'
00262                 {
00263                 fragment = ETrue;
00264                 continue; // Just stop there
00265                 }
00266                 
00267             case '/':
00268                 {
00269                 iFileName->Des().Append(KPathChar);
00270                 break;
00271                 }
00272             case '.':
00273                 {
00274                 if (index > 1 && urlPtr[index - 1] == '/')
00275                     {
00276                     if (index < count - 1 && urlPtr[index + 1] == '/')
00277                         {
00278                         index ++; // skip  ./
00279                         break;
00280                         }
00281                     if (index > 2 && index < count - 3 &&
00282                         urlPtr[index + 1] == '.' && urlPtr[index + 2] == '/')
00283                         {
00284                         TInt i = index - 2;
00285                         
00286                         for (; i > 0 && urlPtr[i] != '/'; i--) {} // skip  /../
00287                         
00288                         iFileName->Des().SetLength(iFileName->Des().Length() - (index - i));
00289                         index += 2;
00290                         break;
00291                         }
00292                     }
00293                 }
00294                 // no break
00295                 //lint -fallthrough
00296                 
00297             default:
00298                 {
00299                 c = urlPtr[index];
00300                 iFileName->Des().Append(&c, 1);
00301                 break;
00302                 }
00303             }   // end of switch
00304         }
00305     return ETrue;
00306 }


© Nokia 2006

Back to top