browserui/browser/BrowserAppSrc/BrowserSpecialLoadObserver.cpp
changeset 0 84ad3b177aa3
child 11 16a119033e3e
equal deleted inserted replaced
-1:000000000000 0:84ad3b177aa3
       
     1 /*
       
     2 * Copyright (c) 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:  Handle special load events such as network connection,
       
    15 *                deal with non-http or non-html requests
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "BrowserContentView.h"  // not used, to be removed
       
    22 #include "BrowserSpecialLoadObserver.h"
       
    23 #include "BrowserLoadObserver.h"
       
    24 #include "logger.h"
       
    25 #include "BrowserAppDocument.h"
       
    26 #include "ApiProvider.h"
       
    27 #include "Preferences.h"
       
    28 #include "BrowserUIVariant.hrh"
       
    29 #include "Display.h"
       
    30 #include "BrowserAppUi.h"
       
    31 #include "BrowserWindow.h"
       
    32 #include "BrowserWindowManager.h"
       
    33 #include "CommonConstants.h"
       
    34 #ifdef __WINS__
       
    35     #include <commdb.h>
       
    36     #include <aknselectionlist.h>
       
    37     #include <AknLists.h>
       
    38 #endif // __WINS__
       
    39 #include <DocumentHandler.h>
       
    40 #include <MConnection.h>  // for MConnection
       
    41 #include <schemehandler.h>
       
    42 #include <BrowserNG.rsg>
       
    43 #include <FeatMgr.h>
       
    44 #include <AiwGenericParam.h>
       
    45 
       
    46 //CONSTANTS
       
    47 const TInt KMaxDocHandlerUrlLen = 255;
       
    48 //DestNetChange
       
    49 #include <CmApplicationSettingsUi.h>
       
    50 
       
    51 
       
    52 // ---------------------------------------------------------
       
    53 // CBrowserSpecialLoadObserver::NewL()
       
    54 // ---------------------------------------------------------
       
    55 //
       
    56 CBrowserSpecialLoadObserver* CBrowserSpecialLoadObserver::NewL(
       
    57         MApiProvider& aApiProvider,
       
    58         CBrowserWindow* aWindow,
       
    59         CEikDocument* aDocument,
       
    60         CBrowserContentView* aContentView )
       
    61     {
       
    62     CBrowserSpecialLoadObserver* self = 
       
    63         new (ELeave) CBrowserSpecialLoadObserver(
       
    64             aApiProvider, aWindow, aDocument, aContentView );
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL( );
       
    67     CleanupStack::Pop();  // self
       
    68     return self;
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------
       
    72 // CBrowserSpecialLoadObserver::~CBrowserSpecialLoadObserver()
       
    73 // ---------------------------------------------------------
       
    74 //
       
    75 CBrowserSpecialLoadObserver::~CBrowserSpecialLoadObserver()
       
    76     {
       
    77     delete iSchemeHandler;
       
    78     delete iDocHandler;
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------
       
    82 // CBrowserSpecialLoadObserver::CBrowserSpecialLoadObserver()
       
    83 // ---------------------------------------------------------
       
    84 //
       
    85 CBrowserSpecialLoadObserver::CBrowserSpecialLoadObserver(
       
    86         MApiProvider& aApiProvider,
       
    87         CBrowserWindow* aWindow,
       
    88         CEikDocument* aDocument,
       
    89         CBrowserContentView* aContentView ) : 
       
    90     iApiProvider( &aApiProvider ),
       
    91     iWindow( aWindow ),
       
    92     iDocument( aDocument ),
       
    93     iSchemeHandler( NULL ),
       
    94     iContentView( aContentView ),
       
    95     iSchemeProcessing( EFalse ),
       
    96     iLongZeroStartup( EFalse ),
       
    97     iConnectionStarted( EFalse )
       
    98     {
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------
       
   102 // CBrowserSpecialLoadObserver::ConstructL()
       
   103 // ---------------------------------------------------------
       
   104 //
       
   105 void CBrowserSpecialLoadObserver::ConstructL()
       
   106     {
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------
       
   110 // CBrowserSpecialLoadObserver::NetworkConnectionNeededL()
       
   111 // ---------------------------------------------------------
       
   112 //
       
   113 void CBrowserSpecialLoadObserver::NetworkConnectionNeededL(
       
   114         TInt* aConnectionPtr,
       
   115         TInt* aSockSvrHandle,
       
   116         TBool* aNewConn,
       
   117         TApBearerType* aBearerType )
       
   118     {
       
   119 LOG_ENTERFN("CBrowserSpecialLoadObserver::NetworkConnectionNeededL");
       
   120 	
       
   121 	__ASSERT_DEBUG( (aConnectionPtr != NULL), Util::Panic( Util::EUninitializedData ) );
       
   122 	__ASSERT_DEBUG( (aSockSvrHandle != NULL), Util::Panic( Util::EUninitializedData ) );
       
   123 	__ASSERT_DEBUG( (aNewConn != NULL), Util::Panic( Util::EUninitializedData ) );
       
   124 	__ASSERT_DEBUG( (aBearerType != NULL), Util::Panic( Util::EUninitializedData ) );
       
   125 	
       
   126     iApiProvider->SetProgressShown( ETrue );
       
   127     TBool query( EFalse );
       
   128     if( iApiProvider->Connection().Connected() )
       
   129         {
       
   130         TInt a( iWindow->WindowId() );
       
   131 		BROWSER_LOG( ( _L( "already connected, WindowId: %d" ), a ) );
       
   132         *aConnectionPtr = (TInt) &iApiProvider->Connection().Connection();
       
   133         *aSockSvrHandle = iApiProvider->Connection().SocketServer().Handle();
       
   134         *aNewConn = EFalse;
       
   135         *aBearerType = iApiProvider->Connection().CurrentBearerTypeL();
       
   136         }
       
   137     else
       
   138         {
       
   139 		BROWSER_LOG((_L("not connected.")));
       
   140         *aNewConn = ETrue;
       
   141         TBool isValid( EFalse );
       
   142         TUint32 ap( 0 );
       
   143         TInt err( KErrNone );
       
   144 
       
   145 		BROWSER_LOG((_L("AP selectionMode: %d."),
       
   146     	iApiProvider->Preferences().AccessPointSelectionMode() ));
       
   147 
       
   148        //determine the type of connection
       
   149         switch (iApiProvider->Preferences().AccessPointSelectionMode() )
       
   150         	{
       
   151         	case EAlwaysAsk:
       
   152         		{
       
   153 	            BROWSER_LOG((_L("always ask.")));
       
   154 	            // Always ask
       
   155 	            isValid = ETrue;
       
   156 	        	break;	
       
   157         		}
       
   158         		
       
   159         	case EDestination:
       
   160         		{
       
   161                 isValid = ETrue;  // force to show LAN connection dialog
       
   162 
       
   163 #ifdef __WINS__
       
   164                 query = ETrue;  // disable connection query dialog
       
   165 #endif  // __WINS__
       
   166                    
       
   167                 // for bug fix MLAN-7EKFV4, if bookmark has defined its AP, use it
       
   168                 if ( iApiProvider->RequestedAp() != KWmlNoDefaultAccessPoint )
       
   169                     {
       
   170                     #ifndef __WINS__
       
   171                                         ap = Util::IapIdFromWapIdL(
       
   172                                             *iApiProvider, iApiProvider->RequestedAp() );
       
   173 				                        BROWSER_LOG((_L("ap: %d"), ap));
       
   174                     #else  // __WINS__
       
   175                                         // On WINS no need to convert the AP ID
       
   176                                         ap = iApiProvider->RequestedAp();
       
   177                     #endif // __WINS__
       
   178 
       
   179                     iApiProvider->Connection().SetRequestedAP( ap );
       
   180                     iApiProvider->Connection().SetConnectionType( EConnectionMethod );
       
   181                     }
       
   182                 else
       
   183                     {
       
   184                     TUint32 snapId = iApiProvider->Preferences().DefaultSnapId();
       
   185                     //connection type is destination nw 
       
   186                     iApiProvider->Connection().SetConnectionType( EDestination );
       
   187                     //set snap id
       
   188                     iApiProvider->Connection().SetRequestedSnap( snapId );        		        		
       
   189                     }
       
   190                 break;	
       
   191         		}
       
   192         		
       
   193         	case EConnectionMethod:
       
   194         		{
       
   195         		BROWSER_LOG((_L("user defined.")));
       
   196                 // User defined
       
   197 
       
   198                 TRAP( err, isValid = Util::CheckApValidityL( *iApiProvider, 
       
   199                     iApiProvider->RequestedAp() ));
       
   200 			    BROWSER_LOG((_L("isValid 1: %d"), isValid));
       
   201 			    BROWSER_LOG((_L("err: %d"), err));
       
   202                 if( isValid )
       
   203                     {  // valid AP, get it
       
   204 #ifndef __WINS__
       
   205                     ap = Util::IapIdFromWapIdL(
       
   206                         *iApiProvider, iApiProvider->RequestedAp() );
       
   207 				    BROWSER_LOG((_L("ap: %d"), ap));
       
   208 #else  // __WINS__
       
   209                     // On WINS no need to convert the AP ID
       
   210                     ap = iApiProvider->RequestedAp();
       
   211 #endif // __WINS__
       
   212                     }
       
   213                 else if( err == KErrNone )
       
   214                     {  // still try to get AP
       
   215                     TUint apUid = iApiProvider->Preferences().DefaultAccessPoint();
       
   216     				
       
   217 				    BROWSER_LOG((_L("apUid: %d"), apUid));
       
   218                     
       
   219                     if ( apUid == KWmlNoDefaultAccessPoint )
       
   220                         {
       
   221 #ifdef __WINS__
       
   222                         query = ETrue;  // disable connection query dialog
       
   223                         isValid = ETrue;  // force to show LAN connection dialog
       
   224 #else  // __WINS__
       
   225 						BROWSER_LOG((_L("StartPrefView.")));
       
   226                         //  there are no AP, show preferences view without always ask
       
   227                         isValid  = iApiProvider->StartPreferencesViewL( EShowDestinations | EShowConnectionMethods );
       
   228                         if( isValid )
       
   229                             {
       
   230                             if( iApiProvider->Preferences().AccessPointSelectionMode() == EConnectionMethod )
       
   231                                 {
       
   232                        		    ap = iApiProvider->Preferences().DefaultAccessPoint();
       
   233                                 }
       
   234                             // else if EDestination, user choosed SNAP in preference view
       
   235                             }
       
   236 #endif  // __WINS__
       
   237                         }
       
   238                     }
       
   239 
       
   240                 //set connection type and AP or SNAP Id                     
       
   241                 if( iApiProvider->Preferences().AccessPointSelectionMode() == EDestination )
       
   242                     {
       
   243                     TUint32 snapId = iApiProvider->Preferences().DefaultSnapId();
       
   244                     iApiProvider->Connection().SetConnectionType( EDestination );
       
   245                     iApiProvider->Connection().SetRequestedSnap( snapId );        		        		
       
   246                     }
       
   247                 else // EConnectionMethod
       
   248                     {
       
   249                     iApiProvider->Connection().SetRequestedAP( ap );
       
   250                     iApiProvider->Connection().SetConnectionType( EConnectionMethod );
       
   251                     }
       
   252         		break;	
       
   253         		}
       
   254  
       
   255         	default:
       
   256         		{
       
   257         		BROWSER_LOG((_L("wrong type of connection")));	
       
   258         		}
       
   259         	} //switch	
       
   260  		
       
   261 		BROWSER_LOG((_L("isValid 2: %d"), isValid));
       
   262         if( isValid )
       
   263             {
       
   264             iConnectionCancelled = EFalse;
       
   265             if( !iApiProvider->Connection().Connected() )
       
   266                 {
       
   267                 iApiProvider->Connection().SetRequestedAP( ap );
       
   268 
       
   269                 TBool startPage = iWindow->LoadObserver().LoadUrlType() == 
       
   270                                     CBrowserLoadObserver::ELoadUrlTypeStartPage;
       
   271                 TBool noConnDlgs = !iApiProvider->Preferences().ShowConnectionDialogs();
       
   272 
       
   273                 // Disable connection dialogs if...
       
   274                 TBool disableConnDlgs = 
       
   275                         query ||
       
   276                         startPage ||    // ...the load type is StartPage
       
   277                         noConnDlgs ||   // ...connection dialogs setting = OFF
       
   278                         LongZeroStartup();  // ...Browser started with long zero keypress
       
   279                 SetLongZeroStartup( EFalse );
       
   280 
       
   281 				BROWSER_LOG((_L("StartConnection params, query: %d, temp: %d"), query, disableConnDlgs));
       
   282                 iConnectionStarted = ETrue; // is true when connection request submited.
       
   283                 // might leave, don't TRAP. OK.
       
   284                 err = iApiProvider->Connection().StartConnectionL( disableConnDlgs );
       
   285                 iConnectionStarted = EFalse; // is false when connection response completed.
       
   286                 }
       
   287                 
       
   288             // during StartConnectionL user pressing "Stop" can cancel
       
   289             if (iConnectionCancelled)
       
   290                 {
       
   291                 err = KErrCancel;
       
   292                 }
       
   293             BROWSER_LOG((_L("err after StartConnection: %d"), err));
       
   294             
       
   295             if( err == KErrNone )
       
   296                 {
       
   297                 *aConnectionPtr = (TInt) &iApiProvider->Connection().Connection();
       
   298                 *aSockSvrHandle = iApiProvider->Connection().SocketServer().Handle();
       
   299                 *aBearerType = iApiProvider->Connection().CurrentBearerTypeL();
       
   300                 }
       
   301             
       
   302             CBrowserAppUi::Static()->ConnNeededStatusL( err );
       
   303             if (( err == KErrCancel ) && !iApiProvider->IsPageLoaded())
       
   304                 {                
       
   305 	          	// Close Browser's Content View window if connection setup is cancelled to avoid a blank white screen
       
   306                 //  ** Don't do this is page was previously loaded and is visible to user.
       
   307 				// ALSO, if feeds are enabled, don't close the window if coming from feeds folder view
       
   308 				// or in topic or feed views
       
   309 
       
   310 				// *** Changing back to CloseContentView as a part of the new Browser exit functionality				   
       
   311 #ifdef __RSS_FEEDS
       
   312  				TUid previousViewID = iApiProvider->LastActiveViewId();
       
   313                 if( (previousViewID != KUidBrowserFeedsFolderViewId) &&
       
   314                 	(previousViewID != KUidBrowserFeedsTopicViewId) &&
       
   315                 	(previousViewID != KUidBrowserFeedsFeedViewId) )
       
   316                 	{
       
   317         	        CBrowserAppUi::Static()->CloseContentViewL();
       
   318                 	}
       
   319 #else //__RSS_FEEDS           
       
   320                 CBrowserAppUi::Static()->CloseContentViewL();
       
   321 #endif //__RSS_FEEDS
       
   322                 }
       
   323             else if( err == KErrGeneral )
       
   324                 {
       
   325                 if( !iApiProvider->Preferences().HttpSecurityWarningsStatSupressed() )
       
   326                     {
       
   327                     iWindow->Display().UpdateSecureIndicatorL(
       
   328                         EAknIndicatorStateOff );
       
   329                     }
       
   330                 }
       
   331             // user might cancel, pass result to BrowserEngine
       
   332             User::LeaveIfError( err );
       
   333             iApiProvider->Display().StartProgressAnimationL();
       
   334             }
       
   335         else
       
   336             {
       
   337             User::LeaveIfError( err );
       
   338             }
       
   339         }
       
   340     }
       
   341 
       
   342 // ---------------------------------------------------------
       
   343 // CBrowserSpecialLoadObserver::DoHandleRequestL()
       
   344 // ---------------------------------------------------------
       
   345 //
       
   346 TBool CBrowserSpecialLoadObserver::DoHandleRequestL
       
   347     ( RArray<TUint>* aTypeArray, CDesCArrayFlat* aDesArray )
       
   348     {
       
   349     LOG_ENTERFN("CBrowserSpecialLoadObserver::HandleRequestL");
       
   350 
       
   351     if( !iSchemeProcessing )
       
   352         {
       
   353         iSchemeProcessing = ETrue;
       
   354         TBool paramFound( EFalse );
       
   355         TPtrC requestUrl = ExtractBrCtlParam( 
       
   356             EParamRequestUrl, 
       
   357             aTypeArray,
       
   358             aDesArray, 
       
   359             paramFound );
       
   360         __ASSERT_DEBUG( paramFound, Util::Panic( Util::EUninitializedData ) );
       
   361         BROWSER_LOG( ( _L( " EParamRequestUrl: %S" ), &requestUrl ) );
       
   362 
       
   363         // pass to the CSchemaHandler             
       
   364         CSchemeHandler* newSH = CSchemeHandler::NewL( requestUrl );
       
   365         delete iSchemeHandler;
       
   366         iSchemeHandler = newSH;
       
   367         BROWSER_LOG( ( _L( " iSchemeHandler OK" ) ) );
       
   368 
       
   369         // construct the current accesspoint
       
   370         // if it's connected, always add it 
       
   371         if ( iApiProvider->Connection().Connected() )
       
   372             {
       
   373             CAiwGenericParamList* paramsList = CAiwGenericParamList::NewL();
       
   374             CleanupStack::PushL(paramsList);
       
   375         	TInt32 ap = iApiProvider->Connection().CurrentAPId(); 
       
   376         	TAiwVariant paramVariant (ap);
       
   377         	TAiwGenericParam genericParam( EGenericParamAccessPoint, paramVariant );
       
   378         	paramsList->AppendL (genericParam );
       
   379             
       
   380         	
       
   381 		    // set the parameter
       
   382      	    iSchemeHandler->SetParameterList( paramsList );
       
   383      	
       
   384          	CleanupStack::Pop();
       
   385             }
       
   386 
       
   387         iSchemeHandler->Observer( this );
       
   388         iSchemeHandler->HandleUrlEmbeddedL();
       
   389         }
       
   390     return ETrue;
       
   391     }
       
   392 
       
   393 // ---------------------------------------------------------
       
   394 // CBrowserSpecialLoadObserver::HandleRequestL()
       
   395 // ---------------------------------------------------------
       
   396 //
       
   397 TBool CBrowserSpecialLoadObserver::HandleRequestL
       
   398     ( RArray<TUint>* aTypeArray, CDesCArrayFlat* aDesArray )
       
   399     {
       
   400     TBool ret( ETrue );
       
   401     TRAPD( err, DoHandleRequestL( aTypeArray, aDesArray ) );
       
   402     if( KErrNone != err )
       
   403         {
       
   404         iSchemeProcessing = EFalse;
       
   405         User::Leave( err );
       
   406         }
       
   407     return ret;
       
   408     }
       
   409 
       
   410 // ---------------------------------------------------------
       
   411 // CBrowserSpecialLoadObserver::HandleDownloadL()
       
   412 // ---------------------------------------------------------
       
   413 //
       
   414 TBool CBrowserSpecialLoadObserver::HandleDownloadL
       
   415     ( RArray<TUint>* aTypeArray, CDesCArrayFlat* aDesArray )
       
   416     {
       
   417     LOG_ENTERFN("CBrowserSpecialLoadObserver::HandleDownloadL");
       
   418 
       
   419     TBool downloadHandled = EFalse;
       
   420 
       
   421 #ifdef __RSS_FEEDS
       
   422 	// Check to see if this is content to be handled by UI (rss or opml)
       
   423 	//
       
   424     if (HandleUiContentL(aTypeArray, aDesArray))
       
   425     	{
       
   426     	return ETrue;
       
   427     	}
       
   428 #endif  // __RSS_FEEDS
       
   429 
       
   430     CBrowserAppDocument* appDoc = STATIC_CAST( CBrowserAppDocument*, iDocument );
       
   431     
       
   432     __ASSERT_DEBUG( (appDoc != NULL), Util::Panic( Util::EUninitializedData ) );
       
   433     
       
   434     if ( appDoc->IsContentHandlerRegistered() )
       
   435         {
       
   436         BROWSER_LOG( ( _L( "Calling file handler." ) ) );
       
   437 
       
   438         TBool paramFound( EFalse );
       
   439         TPtrC fileName = ExtractBrCtlParam( 
       
   440                             EParamLocalFileName, 
       
   441                             aTypeArray,
       
   442                             aDesArray, 
       
   443                             paramFound );
       
   444         __ASSERT_DEBUG( paramFound, Util::Panic( Util::EUninitializedData ) );
       
   445 
       
   446         if ( fileName.Length() == 0 )
       
   447             {
       
   448             // May be a Rights Object download - 
       
   449             // no downloaded file, nothing to open/handle/pass to BrowserLauncher client.
       
   450             BROWSER_LOG( ( _L( " Empty fileName" ) ) );
       
   451             }
       
   452         else
       
   453             {
       
   454             CAiwGenericParamList* genericParamList = 
       
   455                 BrCtlParamList2GenericParamListL( aTypeArray, aDesArray );
       
   456             CleanupStack::PushL( genericParamList );
       
   457 
       
   458             // Forward the file to the registered handler.
       
   459             TBool continueBrowsing( EFalse );
       
   460             downloadHandled = CBrowserAppUi::Static()->HandleContentL
       
   461                              ( fileName, *genericParamList, continueBrowsing );
       
   462             BROWSER_LOG( ( _L( " downloadHandled: %d, continueBrowsing: %d" ),
       
   463                 downloadHandled, continueBrowsing ) );
       
   464 
       
   465             CleanupStack::PopAndDestroy( genericParamList ); // genericParamList
       
   466 
       
   467             if ( downloadHandled )
       
   468                 {
       
   469                 // We can delete the file now.
       
   470                 RFs fs;
       
   471                 User::LeaveIfError( fs.Connect() );
       
   472                 CleanupClosePushL( fs );
       
   473                 fs.Delete( fileName ); // Return value is ignored.
       
   474                 CleanupStack::PopAndDestroy( &fs ); // fs
       
   475                 }
       
   476 
       
   477             if ( !continueBrowsing )
       
   478                 {
       
   479                 iApiProvider->SetExitFromEmbeddedMode( ETrue );
       
   480                 }
       
   481             }
       
   482         }
       
   483     else
       
   484         {
       
   485         // No handler registered.
       
   486         BROWSER_LOG( ( _L( " No handler registered." ) ) );
       
   487         }
       
   488 
       
   489     // If the download (file) was not handled, 
       
   490     //   the BrowserUI handles it with Document Handler.
       
   491     if ( !downloadHandled )
       
   492         {
       
   493         // This content must be handled by BrowserUI - Browser Control cannot handle it.
       
   494         OpenFileEmbeddedL( aTypeArray, aDesArray );
       
   495         downloadHandled = ETrue;
       
   496         }
       
   497         
       
   498     BROWSER_LOG( ( _L( " downloadHandled: [%d]" ), (TInt)downloadHandled ) );
       
   499     return downloadHandled;
       
   500     }
       
   501 
       
   502 #ifdef __RSS_FEEDS
       
   503 // ---------------------------------------------------------
       
   504 // CBrowserSpecialLoadObserver::HandleUiContentL()
       
   505 // ---------------------------------------------------------
       
   506 //
       
   507 TBool CBrowserSpecialLoadObserver::HandleUiContentL( 
       
   508                          RArray<TUint>* aTypeArray, 
       
   509                          CDesCArrayFlat* aDesArray ) const
       
   510     {
       
   511     TDataType dataType;
       
   512 
       
   513     TBool contentTypeFound( EFalse );
       
   514     TBool urlFound( EFalse );
       
   515     TBool fileFound( EFalse );
       
   516     TBool result( EFalse );
       
   517     
       
   518     TPtrC receivedContentType = ExtractBrCtlParam( 
       
   519         EParamReceivedContentType, 
       
   520         aTypeArray,
       
   521         aDesArray, 
       
   522         contentTypeFound );
       
   523         
       
   524     TPtrC url = ExtractBrCtlParam( 
       
   525         EParamRequestUrl, 
       
   526         aTypeArray,
       
   527         aDesArray, 
       
   528         urlFound );
       
   529       
       
   530         
       
   531     TPtrC fileName = ExtractBrCtlParam( 
       
   532     	EParamLocalFileName, 
       
   533         aTypeArray,
       
   534         aDesArray, 
       
   535         fileFound );
       
   536     
       
   537     // Compare returns 0 if the strings are the same
       
   538     if ((receivedContentType.Compare(KMimeTypeAppXML) == 0) || 
       
   539           (receivedContentType.Compare(KMimeTypeTextXML) == 0) ||
       
   540           (receivedContentType.Compare(KMimeTypeRSS) == 0) ||
       
   541           (receivedContentType.Compare(KMimeTypeAtom) == 0) ||
       
   542           (receivedContentType.Compare(KMimeTypeRDF) == 0) ||
       
   543           (receivedContentType.Compare(KOPMLMimeType) == 0) ||
       
   544           //++PK added check for Text/xml content-type, only T is in caps, should make string check case insensitive
       
   545           (receivedContentType.Compare(KMimeTypeCapsTextXML) == 0)
       
   546           //++PK
       
   547           )
       
   548     	{
       
   549     	if (fileFound)
       
   550     		{
       
   551     		RFs             rfs;
       
   552     		RFile           rfile;
       
   553     	
       
   554     		// Open the file.
       
   555     		User::LeaveIfError(rfs.Connect());
       
   556     		CleanupClosePushL(rfs);
       
   557 
       
   558 			TInt fileResult( rfile.Open( rfs, fileName, EFileRead ) );
       
   559     		// file open doesn't succeeded
       
   560     		User::LeaveIfError( fileResult );
       
   561     		if( fileResult == KErrNone )
       
   562         		{
       
   563         		CleanupClosePushL( rfile );
       
   564     		
       
   565     			TBuf<KMaxDataTypeLength> dataTypeDes;
       
   566                 TBool   deleteOpml = EFalse;
       
   567     		
       
   568     			if(CBrowserAppUi::Static()->RecognizeUiFileL(rfile, dataTypeDes))
       
   569     				{
       
   570 					TFileName fileNameBuf = TFileName(fileName);
       
   571 					TFileName truncFileName;
       
   572 					User::LeaveIfError( rfile.Name(truncFileName) );    				
       
   573     				    				
       
   574     				// Confirm with user that we want to handle it
       
   575     				if(CBrowserAppUi::Static()->ConfirmUiHandlingL(truncFileName, dataTypeDes))
       
   576     					{  					
       
   577 						// Have AppUI decide what to do with it, what view, etc.
       
   578     					CBrowserAppUi::Static()->HandleUiDownloadL(fileNameBuf, dataTypeDes);
       
   579     					}
       
   580                     else
       
   581                         {
       
   582                         deleteOpml = ETrue;
       
   583                         }
       
   584     				result = ETrue;
       
   585        				}
       
   586        			CleanupStack::PopAndDestroy(); //rfile
       
   587        			
       
   588                 // delete the downloaded file if it is not handled
       
   589                 if(deleteOpml && (dataTypeDes.Compare(KOPMLMimeType) == 0 ))
       
   590                     {
       
   591                     rfs.Delete(fileName);
       
   592                     }       			
       
   593         		}
       
   594         	CleanupStack::PopAndDestroy(); //rfs        	
       
   595     		}
       
   596     		
       
   597     	// If open file was handled, skip sending to feeds engine
       
   598     	// otherwise, pass it on
       
   599     	if(!result)
       
   600     		{
       
   601     		// Launch the Feeds Engine
       
   602 			iContentView->HandleSubscribeToWithUrlL(url);
       
   603 			result = ETrue;	
       
   604     		}
       
   605     	}
       
   606     
       
   607     return result;
       
   608     }
       
   609      
       
   610 #endif  // __RSS_FEEDS
       
   611 
       
   612 
       
   613 // ---------------------------------------------------------
       
   614 // CBrowserSpecialLoadObserver::BrCtlParamList2GenericParamListL()
       
   615 // ---------------------------------------------------------
       
   616 //
       
   617 CAiwGenericParamList* CBrowserSpecialLoadObserver::BrCtlParamList2GenericParamListL( 
       
   618                          RArray<TUint>* aTypeArray, 
       
   619                          CDesCArrayFlat* aDesArray ) const
       
   620     {
       
   621     LOG_ENTERFN("CBrowserSpecialLoadObserver::BrCtlParamList2GenericParamListL");
       
   622 
       
   623 	__ASSERT_DEBUG( (aTypeArray != NULL), Util::Panic( Util::EUninitializedData ) );
       
   624 	__ASSERT_DEBUG( (aDesArray != NULL), Util::Panic( Util::EUninitializedData ) );
       
   625 
       
   626 
       
   627     //Creating generic param list
       
   628     CAiwGenericParamList* genericParamList = CAiwGenericParamList::NewLC();
       
   629 
       
   630     for( TInt j = 0; j < aTypeArray->Count(); j++ )
       
   631         {
       
   632         BROWSER_LOG( ( _L( " iter: %d" ), j ) );
       
   633         TBool paramFound( EFalse );
       
   634         const TUint paramType = (*aTypeArray)[j];
       
   635         TPtrC param = ExtractBrCtlParam( 
       
   636                                  paramType, 
       
   637                                  aTypeArray,
       
   638                                  aDesArray, 
       
   639                                  paramFound );
       
   640         __ASSERT_DEBUG( paramFound, Util::Panic( Util::EUninitializedData ) );
       
   641 
       
   642         BROWSER_LOG( ( _L( " Type:  %d, Value: %S" ), paramType, &param ) );
       
   643 
       
   644         switch( paramType )
       
   645             {
       
   646             case EParamRequestUrl:
       
   647                 {
       
   648                 BROWSER_LOG( ( _L( " EParamRequestUrl" ) ) );
       
   649                 // limit url to 255 char's or DocHandler panics!
       
   650                 TAiwVariant paramVariant( param.Left( KMaxDocHandlerUrlLen ) );
       
   651                 TAiwGenericParam genericParam( EGenericParamURL, 
       
   652                                                paramVariant );
       
   653                 genericParamList->AppendL( genericParam );
       
   654                 break;
       
   655                 }
       
   656             case EParamRealm:
       
   657                 {
       
   658                 BROWSER_LOG( ( _L( " EParamRealm" ) ) );
       
   659                 // No corresponding generic param!
       
   660                 break;
       
   661                 }
       
   662             case EParamUsername:
       
   663                 {
       
   664                 BROWSER_LOG( ( _L( " EParamUsername" ) ) );
       
   665                 // No corresponding generic param!
       
   666                 break;
       
   667                 }
       
   668             case EParamPassword:
       
   669                 {
       
   670                 BROWSER_LOG( ( _L( " EParamPassword" ) ) );
       
   671                 // No corresponding generic param!
       
   672                 break;
       
   673                 }
       
   674             case EParamProxyUsername:
       
   675                 {
       
   676                 BROWSER_LOG( ( _L( " EParamProxyUsername" ) ) );
       
   677                 // No corresponding generic param!
       
   678                 break;
       
   679                 }
       
   680             case EParamProxyPassword:
       
   681                 {
       
   682                 BROWSER_LOG( ( _L( " EParamProxyPassword" ) ) );
       
   683                 // No corresponding generic param!
       
   684                 break;
       
   685                 }
       
   686             case EParamRawRequestHeader:
       
   687                 {
       
   688                 BROWSER_LOG( ( _L( " EParamRawRequestHeader" ) ) );
       
   689                 // No corresponding generic param!
       
   690                 break;
       
   691                 }
       
   692             case EParamReceivedContentType:
       
   693                 {
       
   694                 BROWSER_LOG( ( _L( " EParamReceivedContentType" ) ) );
       
   695                 // The expected content type should override the response header's
       
   696                 // content type => don't use EParamReceivedContentType if 
       
   697                 // EParamExpectedContentType is set!
       
   698                 TBool expectedContentTypeFound( EFalse );
       
   699                 ExtractBrCtlParam( 
       
   700                                                  EParamExpectedContentType, 
       
   701                                                  aTypeArray,
       
   702                                                  aDesArray, 
       
   703                                                  expectedContentTypeFound );
       
   704                 if ( !expectedContentTypeFound )
       
   705                     {
       
   706                     // Using EParamReceivedContentType
       
   707                     BROWSER_LOG( ( _L( " EParamExpectedContentType not found" ) ) );
       
   708                     TAiwVariant paramVariant( param );
       
   709                     TAiwGenericParam genericParam( EGenericParamMIMEType, 
       
   710                                                    paramVariant );
       
   711                     genericParamList->AppendL( genericParam );
       
   712                     }
       
   713                 break;
       
   714                 }
       
   715             case EParamExpectedContentType:
       
   716                 {
       
   717                 // Overrides EParamReceivedContentType!
       
   718                 BROWSER_LOG( ( _L( " EParamExpectedContentType" ) ) );
       
   719                 TAiwVariant paramVariant( param );
       
   720                 TAiwGenericParam genericParam( EGenericParamMIMEType, 
       
   721                                                paramVariant );
       
   722                 genericParamList->AppendL( genericParam );
       
   723                 break;
       
   724                 }
       
   725             case EParamTotalContentLength:
       
   726                 {
       
   727                 BROWSER_LOG( ( _L( " EParamTotalContentLength" ) ) );
       
   728                 // No corresponding generic param!
       
   729                 break;
       
   730                 }
       
   731             case EParamReceivedContent:
       
   732                 {
       
   733                 BROWSER_LOG( ( _L( " EParamReceivedContent" ) ) );
       
   734                 // No corresponding generic param!
       
   735                 break;
       
   736                 }
       
   737             case EParamRawResponseHeader:
       
   738                 {
       
   739                 BROWSER_LOG( ( _L( " EParamRawResponseHeader" ) ) );
       
   740                 // No corresponding generic param!
       
   741                 break;
       
   742                 }
       
   743             case EParamLocalFileName:
       
   744                 {
       
   745                 BROWSER_LOG( ( _L( " EParamLocalFileName" ) ) );
       
   746                 TAiwVariant paramVariant( param );
       
   747                 TAiwGenericParam genericParam( EGenericParamFile, 
       
   748                                                paramVariant );
       
   749                 genericParamList->AppendL( genericParam );
       
   750                 break;
       
   751                 }
       
   752             case EParamCharset:
       
   753                 {
       
   754                 BROWSER_LOG( ( _L( " EParamCharset" ) ) );
       
   755                 TAiwVariant paramVariant( param );
       
   756                 TAiwGenericParam genericParam( EGenericParamCharSet, 
       
   757                                                paramVariant );
       
   758                 genericParamList->AppendL( genericParam );
       
   759                 break;
       
   760                 }
       
   761             case EParamRefererHeader:
       
   762                 {
       
   763                 BROWSER_LOG( ( _L( " EParamRefererHeader" ) ) );
       
   764                 TAiwVariant paramVariant( param );
       
   765                 TAiwGenericParam genericParam( EGenericParamReferringURI, 
       
   766                                                paramVariant );
       
   767                 genericParamList->AppendL( genericParam );
       
   768                 break;
       
   769                 }
       
   770             default:
       
   771                 {
       
   772                 BROWSER_LOG( ( _L( " Unexpected argument" ) ) );
       
   773                 break;
       
   774                 }
       
   775             }
       
   776         }
       
   777 
       
   778     // Always add the access point, if currently connected
       
   779     if( iApiProvider->Connection().Connected() )
       
   780         {
       
   781         TInt32 ap = iApiProvider->Connection().CurrentAPId();
       
   782         BROWSER_LOG( ( _L( " IAP: %d" ), ap ) );
       
   783         TAiwVariant paramVariant( ap );
       
   784         TAiwGenericParam genericParam( EGenericParamAccessPoint, 
       
   785                                        paramVariant );
       
   786         genericParamList->AppendL( genericParam );
       
   787         }
       
   788 
       
   789     CleanupStack::Pop( genericParamList ); // genericParamList
       
   790     return genericParamList;
       
   791     }
       
   792 
       
   793 // ---------------------------------------------------------
       
   794 // CBrowserSpecialLoadObserver::ExtractBrCtlParam()
       
   795 // ---------------------------------------------------------
       
   796 //
       
   797 TPtrC CBrowserSpecialLoadObserver::ExtractBrCtlParam
       
   798     ( TUint aParamTypeToFind,
       
   799       RArray<TUint>* aTypeArray, 
       
   800       CDesCArrayFlat* aDesArray, 
       
   801       TBool& aParamFound ) const
       
   802     {
       
   803     LOG_ENTERFN("CBrowserSpecialLoadObserver::ExtractBrCtlParam");
       
   804 
       
   805 	__ASSERT_DEBUG( (aTypeArray != NULL), Util::Panic( Util::EUninitializedData ) );
       
   806 	__ASSERT_DEBUG( (aDesArray != NULL), Util::Panic( Util::EUninitializedData ) );
       
   807 
       
   808     // initialize output parameter
       
   809     aParamFound = EFalse;
       
   810     TPtrC16 retParamValue;
       
   811 
       
   812     for( TInt j = 0; j < aTypeArray->Count(); j++ )
       
   813         {
       
   814         BROWSER_LOG( ( _L( " iter: %d" ), j ) );
       
   815         const TUint paramType = (*aTypeArray)[j];
       
   816         if ( aParamTypeToFind == paramType )
       
   817             {
       
   818             // That's we need
       
   819             retParamValue.Set( aDesArray->MdcaPoint(j) );
       
   820             aParamFound = ETrue; // Indicate it in the out param
       
   821             BROWSER_LOG( ( _L( " Type:  %d, Value: %S" ), paramType, &retParamValue ) );
       
   822             break; // break the loop - we found it
       
   823             }
       
   824         }
       
   825 
       
   826     return retParamValue;
       
   827     }
       
   828 
       
   829 // ---------------------------------------------------------
       
   830 // CBrowserSpecialLoadObserver::IsSelfDownloadContentTypeL()
       
   831 // ---------------------------------------------------------
       
   832 //
       
   833 TBool CBrowserSpecialLoadObserver::IsSelfDownloadContentTypeL
       
   834     ( RArray<TUint>* aTypeArray, 
       
   835       CDesCArrayFlat* aDesArray ) const
       
   836     {
       
   837     LOG_ENTERFN("CBrowserSpecialLoadObserver::IsSelfDownloadContentTypeL");
       
   838 
       
   839     TBool isSelfDownloadContentType = EFalse;
       
   840     
       
   841     // First get the download's content type (mime type)
       
   842     TBool paramFound( EFalse );
       
   843     TPtrC contentType = ExtractBrCtlParam( 
       
   844                         EParamReceivedContentType, 
       
   845                         aTypeArray,
       
   846                         aDesArray, 
       
   847                         paramFound );
       
   848                         
       
   849     if ( !paramFound )
       
   850         {
       
   851         isSelfDownloadContentType = EFalse;
       
   852         }
       
   853     else
       
   854         {
       
   855         BROWSER_LOG( ( _L( " contentType: [%S]" ), &contentType ) );
       
   856         // Then check, if it is in SelfDownloadContentTypes
       
   857         TInt cTLength = contentType.Length();
       
   858         TPtrC selfDownloadCTs = iApiProvider->Preferences().SelfDownloadContentTypesL();
       
   859         TInt idx = KErrNotFound;
       
   860         idx = selfDownloadCTs.FindF( contentType );
       
   861         const TChar KBrowserSpecLoadObsSemicolon = ';';
       
   862         while( idx != KErrNotFound )
       
   863             {
       
   864             // check for ';' on the left KSemicolon
       
   865             if ( idx == 0 || selfDownloadCTs[ idx - 1 ] == KBrowserSpecLoadObsSemicolon )
       
   866                 {
       
   867                 // check for ';' on the right
       
   868                 idx += cTLength;
       
   869                 if ( idx == selfDownloadCTs.Length() || selfDownloadCTs[ idx ] == KBrowserSpecLoadObsSemicolon )
       
   870                     {
       
   871                     isSelfDownloadContentType = ETrue;
       
   872                     break;
       
   873                     }
       
   874                 }
       
   875             selfDownloadCTs.Set( selfDownloadCTs.Mid( idx ) );
       
   876             idx = selfDownloadCTs.FindF( contentType );
       
   877             }
       
   878         }
       
   879         
       
   880     BROWSER_LOG( ( _L( " isSelfDownloadContentType: %d" ), isSelfDownloadContentType ) );
       
   881     return isSelfDownloadContentType;
       
   882     }
       
   883 
       
   884 // ---------------------------------------------------------
       
   885 // CBrowserSpecialLoadObserver::OpenFileEmbeddedL()
       
   886 // ---------------------------------------------------------
       
   887 //
       
   888 void CBrowserSpecialLoadObserver::OpenFileEmbeddedL
       
   889     ( RArray<TUint>* aTypeArray, 
       
   890       CDesCArrayFlat* aDesArray )
       
   891     {
       
   892     LOG_ENTERFN("CBrowserSpecialLoadObserver::OpenFileEmbeddedL");
       
   893 
       
   894     CDocumentHandler* newDocHandler = CDocumentHandler::NewL();
       
   895     delete iDocHandler;
       
   896     iDocHandler = newDocHandler;
       
   897     iDocHandler->SetExitObserver( this );
       
   898 
       
   899     TBool paramFound( EFalse );
       
   900     TPtrC fileName = ExtractBrCtlParam( 
       
   901                         EParamLocalFileName, 
       
   902                         aTypeArray,
       
   903                         aDesArray, 
       
   904                         paramFound );
       
   905     __ASSERT_DEBUG( paramFound, Util::Panic( Util::EUninitializedData ) );
       
   906 
       
   907     TPtrC contentType = ExtractBrCtlParam( 
       
   908                         EParamReceivedContentType, 
       
   909                         aTypeArray,
       
   910                         aDesArray, 
       
   911                         paramFound );
       
   912     HBufC8* contentType8 = 0;
       
   913     if ( !paramFound )
       
   914         {
       
   915         contentType8 = KNullDesC8().AllocLC();
       
   916         }
       
   917     else
       
   918         {
       
   919         BROWSER_LOG( ( _L( " contentType: [%S]" ), &contentType ) );
       
   920         contentType8 = HBufC8::NewLC( contentType.Length() );
       
   921         // 16 bit buffer copied into 8 bit buffer.
       
   922         contentType8->Des().Copy( contentType );
       
   923         }
       
   924     TDataType dataType( *contentType8 );
       
   925 
       
   926     CAiwGenericParamList* genericParamList = 
       
   927         BrCtlParamList2GenericParamListL( aTypeArray, aDesArray );
       
   928     CleanupStack::PushL( genericParamList );
       
   929 
       
   930     // File is not yet saved to target folder.
       
   931     TBool allowSave( ETrue );
       
   932     TAiwVariant allowSaveVariant( allowSave );
       
   933     TAiwGenericParam genericParamAllowSave
       
   934                      ( EGenericParamAllowSave, allowSaveVariant );
       
   935     genericParamList->AppendL( genericParamAllowSave );
       
   936     
       
   937     // Set EGenericParamAllowMove - we encourage handlers to apply 
       
   938     // move instead of copy for the file.
       
   939     TBool allowMove( ETrue );
       
   940     TAiwVariant allowMoveVariant( allowMove );
       
   941     TAiwGenericParam genericParamAllowMove
       
   942                      ( EGenericParamAllowMove, allowMoveVariant );
       
   943     genericParamList->AppendL( genericParamAllowMove );
       
   944 
       
   945     RFile tempFile; 
       
   946     iDocHandler->OpenTempFileL( fileName, tempFile );
       
   947     CleanupClosePushL( tempFile );
       
   948     /*TInt err = */iDocHandler->OpenFileEmbeddedL( tempFile, 
       
   949                                           dataType, 
       
   950                                           *genericParamList );
       
   951     //BROWSER_LOG( ( _L( " err: %d" ), err ) );
       
   952     CleanupStack::PopAndDestroy( &tempFile ); // tempFile
       
   953     
       
   954     CleanupStack::PopAndDestroy( genericParamList ); // genericParamList
       
   955     CleanupStack::PopAndDestroy( contentType8 ); // contentType8
       
   956     }
       
   957 
       
   958 // ---------------------------------------------------------
       
   959 // CBrowserSpecialLoadObserver::HandleServerAppExit()
       
   960 // ---------------------------------------------------------
       
   961 //
       
   962 void CBrowserSpecialLoadObserver::HandleServerAppExit( TInt /*aReason*/ )
       
   963     {
       
   964     iSchemeProcessing = EFalse;
       
   965     }
       
   966 
       
   967 #ifdef __WINS__
       
   968 // ----------------------------------------------------------------------------
       
   969 // CBrowserSpecialLoadObserver::AskIapIdL(TUint32& aId)
       
   970 // Ask IAP id from the user
       
   971 // ----------------------------------------------------------------------------
       
   972 //
       
   973 TInt CBrowserSpecialLoadObserver::AskIapIdL( TUint32& aId )
       
   974     {
       
   975     CCommsDatabase* TheDb;
       
   976     TInt res;
       
   977     TBuf<40> name;
       
   978     TUint32 id;
       
   979     RArray<TUint32> idArray; 
       
   980     CDesCArrayFlat* items = new (ELeave) CDesCArrayFlat(16);
       
   981     CleanupStack::PushL( items );  // 1
       
   982 
       
   983     // Get IAP names and ids from the database
       
   984     TheDb = CCommsDatabase::NewL( EDatabaseTypeIAP );
       
   985     CleanupStack::PushL( TheDb );  // 2
       
   986 
       
   987     TheDb->ShowHiddenRecords();
       
   988 
       
   989     CCommsDbTableView* view = TheDb->OpenTableLC( TPtrC( IAP ) );  // 3
       
   990     res = view->GotoFirstRecord();
       
   991 
       
   992     while( !res )
       
   993         {
       
   994         view->ReadTextL( TPtrC( COMMDB_NAME ), name );
       
   995         view->ReadUintL( TPtrC( COMMDB_ID ), id );
       
   996 
       
   997         idArray.Insert( id, 0 );
       
   998         items->InsertL( 0, name );
       
   999 
       
  1000         res = view->GotoNextRecord();
       
  1001         RDebug::Print(_L("IAP name, id: %S, %d"), &name, id );
       
  1002         }
       
  1003 
       
  1004     // Create listbox and PUSH it.
       
  1005     CEikTextListBox* list = new (ELeave) CAknSinglePopupMenuStyleListBox;
       
  1006     CleanupStack::PushL( list );  // 4
       
  1007 
       
  1008     // Create popup list and PUSH it.
       
  1009     CAknPopupList* popupList = CAknPopupList::NewL(
       
  1010         list, R_AVKON_SOFTKEYS_OK_EMPTY__OK,
       
  1011         AknPopupLayouts::EMenuWindow);
       
  1012     CleanupStack::PushL( popupList );  // 5
       
  1013 
       
  1014     // initialize listbox.
       
  1015     list->ConstructL(popupList, CEikListBox::ELeftDownInViewRect);
       
  1016     list->CreateScrollBarFrameL(ETrue);
       
  1017     list->ScrollBarFrame()->SetScrollBarVisibilityL(
       
  1018         CEikScrollBarFrame::EOff,
       
  1019         CEikScrollBarFrame::EAuto);
       
  1020 
       
  1021     // Set listitems.
       
  1022     CTextListBoxModel* model = list->Model();
       
  1023     model->SetItemTextArray( items );
       
  1024     model->SetOwnershipType( ELbmOwnsItemArray );
       
  1025 
       
  1026     // Set title
       
  1027     popupList->SetTitleL( _L( "Select IAP:" ) );
       
  1028 
       
  1029     // Show popup list.
       
  1030     TInt popupOk = popupList->ExecuteLD();
       
  1031     if( popupOk )
       
  1032         {
       
  1033         TInt index = list->CurrentItemIndex();
       
  1034         aId = idArray[index];
       
  1035         }
       
  1036 
       
  1037     CleanupStack::Pop( popupList );       // popuplist
       
  1038     CleanupStack::PopAndDestroy( list );  // list
       
  1039     CleanupStack::PopAndDestroy( view );  // view
       
  1040     CleanupStack::PopAndDestroy( TheDb ); // TheDb
       
  1041     CleanupStack::Pop( items );           // items CTextListBoxModel* model owns it
       
  1042 
       
  1043     idArray.Close();
       
  1044     items = NULL;
       
  1045     return popupOk;
       
  1046     }
       
  1047 
       
  1048 #endif // __WINS__
       
  1049 
       
  1050 // End of file