S60 3rd Edition SDK for Symbian OS
Example Applications Guide

BrCtlSampleAppSpecialLoadObserver.cpp

00001 /*
00002 * ============================================================================
00003 *  Name        : BrCtlSampleAppSpecialLoadObserver.cpp
00004 *  Part of     : BrCtlSampleApp
00005 *  Interface   : Browser Control API
00006 *  Description : Handle special load requests like Non-HTTP(S) load requests,
00007 *                and Non-HTML content. Control over network connections
00008 *  Version     : 
00009 *
00010 *  Copyright (c) 2005-2006 Nokia Corporation.
00011 *  This material, including documentation and any related 
00012 *  computer programs, is protected by copyright controlled by 
00013 *  Nokia Corporation.
00014 * ============================================================================
00015 */
00016 
00017 // INCLUDE FILES
00018 #include <apmrec.h>
00019 #include <apgcli.h>
00020 #include <eikappui.h>
00021 #include <eikenv.h>
00022 #include "BrCtlSampleAppSpecialLoadObserver.h"
00023 #include <avkon.hrh>
00024 #include <aknmessagequerydialog.h>
00025 
00026 
00027 // ================= MEMBER FUNCTIONS =======================
00028 
00029 // ---------------------------------------------------------
00030 // CBrCtlSampleAppSpecialLoadObserver::NetworkConnectionNeededL
00031 // ---------------------------------------------------------
00032 //
00033 void CBrCtlSampleAppSpecialLoadObserver::NetworkConnectionNeededL(TInt* /*aConnectionPtr*/,
00034                                       TInt* /*aSockSvrHandle*/,
00035                                       TBool* /*aNewConn*/,
00036                                       TApBearerType* /*aBearerType*/) 
00037     {
00038     }
00039 
00040 // ---------------------------------------------------------
00041 // CBrCtlSampleAppSpecialLoadObserver::HandleRequestL
00042 // ---------------------------------------------------------
00043 //
00044 TBool CBrCtlSampleAppSpecialLoadObserver::HandleRequestL(RArray<TUint>* aTypeArray, CDesCArrayFlat* aDesArray) 
00045     {   
00046     TInt i;
00047     // The 2 arrays must be in sync. Each element in iTypeArray 
00048     // identifies the type of the corresponding element in iDesArray.
00049     if( aTypeArray->Count() != aDesArray->Count() )
00050         {
00051         User::Leave( KErrArgument );
00052         }
00053 
00054         // Get url
00055     HBufC* url = NULL;
00056     // Search url in the param list
00057     for( i = 0; i < aTypeArray->Count(); i++ )
00058         {
00059         if( (*aTypeArray)[i] == EParamRequestUrl )
00060             {
00061             // the url is found
00062             url = HBufC::NewLC( (*aDesArray)[i].Length() );
00063             url->Des().Copy( (*aDesArray)[i] );
00064             break;
00065             }
00066         }
00067     if( !url )
00068         {
00069         // The url wasn't found. 
00070         User::Leave( KErrArgument );
00071         }
00072 
00073         // Get referrer header
00074     HBufC* refererHeader = NULL;
00075     // Search url in the param list
00076     for( i = 0; i < aTypeArray->Count(); i++ )
00077         {
00078         if( (*aTypeArray)[i] == EParamRefererHeader )
00079             {
00080             // the referer Header is found
00081             refererHeader = HBufC::NewLC( (*aDesArray)[i].Length() );
00082             refererHeader->Des().Copy( (*aDesArray)[i] );
00083             break;
00084             }
00085         }
00086 
00087         // This is where you would place your scheme handling code
00088         // For example a scheme could be "rtsp://" or "sms:"
00089         // The scheme handler is then responsible for dispatching the request to 
00090         // the correct component.
00091 
00092     if( refererHeader )
00093                 {
00094                         CleanupStack::PopAndDestroy( 1 ); // refererHeader
00095                 }
00096 
00097     CleanupStack::PopAndDestroy( 1 ); // url
00098     return ETrue;
00099     }
00100 
00101 // ---------------------------------------------------------
00102 // CBrCtlSampleAppSpecialLoadObserver::HandleDownloadL
00103 // ---------------------------------------------------------
00104 //
00105 TBool CBrCtlSampleAppSpecialLoadObserver::HandleDownloadL(RArray<TUint>* aTypeArray, CDesCArrayFlat* aDesArray)
00106     {
00107     TInt i = 0;
00108     TInt count = aTypeArray->Count();
00109     for (i = 0; i < count; i++)
00110         {
00111         if ((*aTypeArray)[i] == EParamLocalFileName && aDesArray[i].Length() > 0)
00112             {
00113             TInt j = 0;
00114             for (j = 0; j < count; j++)
00115                 {
00116                 if ((*aTypeArray)[j] == EParamReceivedContentType)
00117                     {
00118                     HBufC8* dataType8 = HBufC8::NewLC((*aDesArray)[j].Length());
00119                     dataType8->Des().Copy((*aDesArray)[j]);
00120                     TDataType dataType(*dataType8);
00121                     iHandler->OpenFileEmbeddedL((*aDesArray)[i], dataType);
00122                     CleanupStack::PopAndDestroy();
00123                     break;
00124                     }
00125                 }
00126             break;
00127             }
00128         }
00129     return EFalse;
00130     }
00131 
00132 // ---------------------------------------------------------
00133 // CBrCtlSampleAppSpecialLoadObserver::ConstructL
00134 // ---------------------------------------------------------
00135 //
00136 void CBrCtlSampleAppSpecialLoadObserver::ConstructL()
00137     {
00138     iHandler = CDocumentHandler::NewL() ;
00139     }
00140 
00141 // ---------------------------------------------------------
00142 // CBrCtlSampleAppSpecialLoadObserver::~CBrCtlSampleAppSpecialLoadObserver
00143 // ---------------------------------------------------------
00144 //
00145 CBrCtlSampleAppSpecialLoadObserver::~CBrCtlSampleAppSpecialLoadObserver()
00146     {
00147     delete iHandler;
00148     }
00149 
00150 
00151 // ---------------------------------------------------------
00152 // CBrCtlSampleAppSpecialLoadObserver::NewL
00153 // ---------------------------------------------------------
00154 //
00155 CBrCtlSampleAppSpecialLoadObserver* CBrCtlSampleAppSpecialLoadObserver::NewL()
00156     {
00157     CBrCtlSampleAppSpecialLoadObserver* self = new(ELeave)CBrCtlSampleAppSpecialLoadObserver;
00158     CleanupStack::PushL(self);
00159     self->ConstructL();
00160     CleanupStack::Pop();
00161     return self;
00162     }
00163 
00164 // End of File  
00165 

© Nokia 2006

Back to top