browserui/browser/BrowserAppSrc/BrowserAppUi.cpp
changeset 0 84ad3b177aa3
child 1 57d5b8e231c4
equal deleted inserted replaced
-1:000000000000 0:84ad3b177aa3
       
     1 /*
       
     2 * Copyright (c) 2002 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: 
       
    15 *      Implementation of CBrowserAppUi
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDES
       
    22 #include <BrowserNG.rsg>
       
    23 #include <uri16.h>
       
    24 #include <uri8.h>
       
    25 #include <uriutils.h>
       
    26 #include <ApUtils.h>
       
    27 #include <StringLoader.h>
       
    28 #include <e32def.h>
       
    29 #include <aplistitemlist.h>
       
    30 #include <aplistitem.h>
       
    31 #include <apparc.h>
       
    32 #include "FavouritesFile.h"
       
    33 #include <aknmessagequerydialog.h>
       
    34 #include <FeatMgr.h>
       
    35 #include <InternetConnectionManager.h>
       
    36 #include <APSettingsHandlerUi.h>
       
    37 #include <UriUtilsCommon.h>
       
    38 #include <aknnavi.h>
       
    39 #include <AiwGenericParam.h>
       
    40 #include <AknDef.h>
       
    41 #include <DocumentHandler.h>
       
    42 #include <MGXFileManagerFactory.h>
       
    43 #include <CMGXFileManager.h>
       
    44 #include <BrowserPluginInterface.h>
       
    45 #include <oommonitorplugin.h>
       
    46 
       
    47 #include "BrowserOverriddenSettings.h"
       
    48 #include "BrowserLauncherService.h"
       
    49 
       
    50 #include "CookieManagerClient.h"
       
    51 
       
    52 #ifdef __SERIES60_HELP
       
    53 #include <hlplch.h>
       
    54 #endif //__SERIES60_HELP
       
    55 
       
    56 #include "BrowserAppDocument.h"
       
    57 #include "DownloadedContentHandler.h"
       
    58 #include "BrowserBmOTABinSender.h"
       
    59 #include "BrowserCommandLineParser.h"
       
    60 #include "BrowserApplication.h"
       
    61 #include "BrowserContentView.h"
       
    62 #include "BrowserContentViewContainer.h"
       
    63 #include "BrowserContentViewToolbar.h"
       
    64 #include "BrowserBookmarksView.h"
       
    65 #include "SettingsView.h"
       
    66 #include "BrowserWindowSelectionView.h"
       
    67 #include "BrowserInitialView.h"
       
    68 #include "CommonConstants.h"
       
    69 #include "BrowserDialogs.h"
       
    70 #include "BrowserDisplay.h"
       
    71 #include "BrowserCommsModel.h"
       
    72 #include "BrowserUtil.h"
       
    73 #include "BrowserPreferences.h"
       
    74 #include "SessionAndSecurity.h"
       
    75 #include "BrowserUIVariant.hrh"
       
    76 #include "Logger.h"
       
    77 #include <data_caging_path_literals.hrh>
       
    78 
       
    79 #include <BrCtlDefs.h>
       
    80 #include "BrowserDialogsProvider.h"
       
    81 #include "BrowserSoftkeysObserver.h"
       
    82 #include "BrowserLoadObserver.h"
       
    83 #include "BrowserSpecialLoadObserver.h"
       
    84 #include "BrowserAsyncExit.h"
       
    85 #include "CommonConstants.h"
       
    86 
       
    87 
       
    88 // Dialogs Provider
       
    89 #include <BrowserDialogsProviderObserver.h>
       
    90 #include <BrCtlInterface.h>
       
    91 #include <BrowserDialogsProvider.h>
       
    92 
       
    93 // Multiple Windows
       
    94 #include "BrowserPopupEngine.h"
       
    95 #include "BrowserDialogsProviderProxy.h"
       
    96 #include "BrowserWindow.h"
       
    97 #include "BrowserWindowManager.h"
       
    98 #include "AknInfoPopupNoteController.h"
       
    99 
       
   100 #include "BrowserAppUi.h"
       
   101 
       
   102 #include "BrowserPushMtmObserver.h"
       
   103 
       
   104 //CONSTANTS
       
   105 const TUint KBookmarkId = 1;
       
   106 const TUint KUrlId = 4;
       
   107 _LIT8 ( KLongZeroIdString, "5" );
       
   108 const TUint KFolderId = 6;
       
   109 const TUint KLaunchFeeds = 7;
       
   110 
       
   111 const TInt KMaxNumOfOpenedWindows = 5;
       
   112 const TInt KMinNumOfOpenedWindows = 2; // must allow at least 2 windows for most use cases
       
   113 
       
   114 const TUint KDot('.');
       
   115 const TUint KSlash('/');
       
   116 _LIT( KDefaultSchema, "http://" );
       
   117 const TInt KDefaultSchemaLength = 7;
       
   118 
       
   119 // ================= MEMBER FUNCTIONS =======================
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CBrowserAppUi::CBrowserAppUi()
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 CBrowserAppUi::CBrowserAppUi():
       
   126 iCalledFromAnotherApp( EFalse ),
       
   127 iIsForeground( EFalse ),
       
   128 iLastViewId( KUidBrowserNullViewId ),
       
   129 iExitInProgress( EFalse ),
       
   130 iShutdownRequested( EFalse ),
       
   131 iParametrizedLaunchInProgress( 0 ),
       
   132 iExitFromEmbeddedMode( EFalse ),
       
   133 iLongZeroPressed( EFalse ),
       
   134 iStartedUp( EFalse ),
       
   135 iFeatureManager( EFalse ),
       
   136 iUserExit( EFalse ),
       
   137 iPgNotFound( EFalse ),
       
   138 iOverriddenLaunchContextId( EBrowserContextIdNormal ),
       
   139 iBrowserAlreadyRunning (EFalse)
       
   140     {
       
   141     iViewToBeActivatedIfNeeded.iUid = 0;
       
   142     iViewToReturnOnClose.iUid = 0;
       
   143 	}
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CBrowserAppUi::~CBrowserAppUi()
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 CBrowserAppUi::~CBrowserAppUi()
       
   150     {
       
   151     LOG_ENTERFN("CBrowserAppUi::~CBrowserAppUi");
       
   152 
       
   153     SetExitInProgress( ETrue );
       
   154     if(iBrowserAsyncExit)
       
   155     	{
       
   156     	iBrowserAsyncExit->Cancel();
       
   157     	}
       
   158     if(iIdle)
       
   159     	{
       
   160     	iIdle->Cancel();
       
   161     	}
       
   162 
       
   163 
       
   164     if( iFeatureManager )
       
   165         {
       
   166         FeatureManager::UnInitializeLib();
       
   167         iFeatureManager = EFalse;
       
   168         }
       
   169 
       
   170     //
       
   171     delete iPushMtmObserver;
       
   172 
       
   173 #ifdef __RSS_FEEDS
       
   174     delete iFeedsClientUtilities;
       
   175     LOG_WRITE( "iFeedsClientUtilities deleted" );
       
   176 #endif //__RSS_FEEDS
       
   177 
       
   178     delete iPopupEngine;
       
   179     LOG_WRITE(" iPopupEngine deleted.");
       
   180 
       
   181     // set user exit for 'save launch param' command handling
       
   182     if ( iWindowManager )
       
   183         {
       
   184         iWindowManager->SetUserExit( iUserExit );
       
   185         }
       
   186     delete iWindowManager;
       
   187     LOG_WRITE( " iWindowManager deleted" );
       
   188 
       
   189     // Delete the inetconman after deleting window manager
       
   190     CInternetConnectionManager* inetconman = (CInternetConnectionManager*)iConnection;
       
   191     delete inetconman;
       
   192     LOG_WRITE( " inetconman deleted" );
       
   193     delete iConnStageNotifier;
       
   194     LOG_WRITE( " iConnStageNotifier deleted" );
       
   195 
       
   196     delete iPreferences;
       
   197     LOG_WRITE( " iPreferences deleted" );
       
   198     delete iCommsModel;
       
   199     LOG_WRITE( " iCommsModel deleted" );
       
   200 
       
   201     delete iLateSendUi;
       
   202 	LOG_WRITE( " iLateSendUi deleted" );
       
   203 
       
   204     delete iSender;
       
   205     LOG_WRITE( " iSender deleted" );
       
   206 
       
   207     delete iIdle;
       
   208     LOG_WRITE( " iIdle deleted" );
       
   209 
       
   210 	delete iRecentUrlStore;
       
   211 	LOG_WRITE( " iRecentUrlStore deleted" );
       
   212 
       
   213     if ( iDoorObserver )
       
   214       {
       
   215         iDoorObserver->NotifyExit(MApaEmbeddedDocObserver::ENoChanges);
       
   216         LOG_WRITE( " NotifyExit deleted" );
       
   217       }
       
   218     delete iDialogsProvider;
       
   219     LOG_WRITE( " iDialogsProvider deleted" );
       
   220 
       
   221 	TBool isStandAlone = !IsEmbeddedModeOn();
       
   222 	LOG_WRITE_FORMAT( " isStandAlone: %d", isStandAlone );
       
   223 
       
   224     delete iBrowserAsyncExit;
       
   225     LOG_WRITE( " iBrowserAsyncExit deleted" );
       
   226 
       
   227     iFavouritesSess.Close();
       
   228     LOG_WRITE( " iFavouritesSess.Close() deleted" );
       
   229     }
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CBrowserAppUi::ConstructL()
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 void CBrowserAppUi::ConstructL()
       
   236     {
       
   237     LOG_CREATE;
       
   238     LOG_ENTERFN( "CBrowserAppUi::ConstructL" );
       
   239 PERFLOG_CREATE;
       
   240 PERFLOG_LOCAL_INIT;
       
   241 PERFLOG_STOPWATCH_START;
       
   242 
       
   243 
       
   244     BaseConstructL( EAknEnableSkin | EAknEnableMSK );
       
   245 
       
   246     if ( !IsEmbeddedModeOn( ) )
       
   247     	{
       
   248     	InitBrowserL();
       
   249     	LOG_WRITE( "Browser started standalone" );
       
   250     	}
       
   251 	else
       
   252 		{
       
   253 		iStartedUp = EFalse;
       
   254 		LOG_WRITE( "Browser started embedded" );
       
   255 		}
       
   256 
       
   257 PERFLOG_STOP_WRITE("BrowserUI::ConstructL");
       
   258 
       
   259     }
       
   260 
       
   261 // -----------------------------------------------------------------------------
       
   262 // CBrowserAppUi::InitBrowser()
       
   263 // -----------------------------------------------------------------------------
       
   264 //
       
   265 void CBrowserAppUi::InitBrowserL()
       
   266     {
       
   267     if (!iStartedUp)
       
   268         {
       
   269         LOG_ENTERFN( "CBrowserAppUi::InitBrowser" );
       
   270 
       
   271         User::LeaveIfError( iFavouritesSess.Connect() );
       
   272 
       
   273         PERFLOG_LOCAL_INIT;
       
   274 
       
   275         PERFLOG_STOPWATCH_START;
       
   276 
       
   277         // Replace the original synchronous creation with this async
       
   278         // creation. A new method was added to the interface stub that was
       
   279         // not added to the MAHLEClientAPI (it is owned by another group).
       
   280         //  // Init AHLE Interface
       
   281         //  TAHLEScore adaptationSpeed;
       
   282         //  TUint      primarySize;
       
   283         //  TUint      secondarySize;
       
   284         //  iAHLEClient=CAHLEInterface::NewL();
       
   285         //  iAHLEClient->GetConfigurationL( primarySize, secondarySize, adaptationSpeed  );
       
   286         //  iAHLEClient->ReconfigureL( KAhlePrimaryStorage, secondarySize, adaptationSpeed  );
       
   287 /*
       
   288     // Write to the file only if we are not below critical disk level
       
   289     if (SysUtil::DiskSpaceBelowCriticalLevelL (&rfs, aData.Length(), EDriveC))
       
   290         {
       
   291         User::Leave(KErrDiskFull);
       
   292         }
       
   293 
       
   294     TMemoryInfoV1Buf info;
       
   295     UserHal::MemoryInfo( info );
       
   296     TInt freeRamInBytes = 10*1024*1024;
       
   297     TInt dataSize = iContext->iDataPtr.Length();
       
   298     if( UserHal::MemoryInfo( info ) == KErrNone )
       
   299         freeRamInBytes = info().iFreeRamInBytes;
       
   300 
       
   301 */
       
   302         //New constructor that just replaces the default primary storage size with this one.
       
   303         iRecentUrlStore = CRecentUrlStore::NewL();
       
   304 
       
   305         iFlashPresent = CheckFlashPresent();
       
   306         PERFLOG_STOP_WRITE("\t AhleInterface Creation + Configuration");
       
   307         BROWSER_LOG( ( _L( "AHLE Interface inited" ) ) );
       
   308 
       
   309         // Init FeatureManager
       
   310         FeatureManager::InitializeLibL();
       
   311         iFeatureManager = ETrue;
       
   312 
       
   313         // Init CommsModel
       
   314 
       
   315         PERFLOG_STOPWATCH_START;
       
   316         iCommsModel = CBrowserCommsModel::NewL();
       
   317         PERFLOG_STOP_WRITE("\t CommsModel NewL");
       
   318         BROWSER_LOG( ( _L( "CommsModel up" ) ) );
       
   319 
       
   320         CBrowserAppDocument* doc = STATIC_CAST(CBrowserAppDocument*, Document());
       
   321 
       
   322         // Creating object to hold application settings
       
   323         PERFLOG_STOPWATCH_START;
       
   324         iPreferences = CBrowserPreferences::NewL( *iCommsModel, *this, doc->GetOverriddenSettings());
       
   325         PERFLOG_STOP_WRITE("\t Preferences NewL");
       
   326         BROWSER_LOG( ( _L( "Preferences up" ) ) );
       
   327 
       
   328         PERFLOG_STOPWATCH_START;
       
   329         iConnection = CInternetConnectionManager::NewL( &iCommsModel->CommsDb(), EFalse );
       
   330         PERFLOG_STOP_WRITE("\t ConnMan NewL");
       
   331         BROWSER_LOG( ( _L( "ConnectionManager up" ) ) );
       
   332 
       
   333 
       
   334         PERFLOG_STOPWATCH_START;
       
   335         iConnStageNotifier = CConnectionStageNotifierWCB::NewL();
       
   336         PERFLOG_STOP_WRITE("\t StageNotif NewL");
       
   337         BROWSER_LOG( ( _L( "StageNofier up" ) ) );
       
   338 
       
   339         // Starts a background processing, so it must be started early, to get
       
   340         // finished before the first send operation! Or it must be synchronized!
       
   341         PERFLOG_STOPWATCH_START;
       
   342         iLateSendUi  = CIdle::NewL( CActive::EPriorityIdle );
       
   343         iLateSendUi ->Start( TCallBack( DelayedSendUiConstructL, this ) );
       
   344         PERFLOG_STOP_WRITE("\t OtaSender NewL");
       
   345 
       
   346         iHTTPSecurityIndicatorSupressed = iPreferences->HttpSecurityWarningsStatSupressed();
       
   347 
       
   348         // set AP to be a default one (for Push messages)
       
   349         SetRequestedAP( Preferences().DefaultAccessPoint() );
       
   350         // get client rect before hiding CBAs
       
   351         TRect rect = ClientRect();
       
   352         Cba()->MakeVisible( EFalse );
       
   353 
       
   354         //-------------------------------------------------------------------------
       
   355         // Create ContentView
       
   356 
       
   357         PERFLOG_STOPWATCH_START;
       
   358         CBrowserContentView* contentView =
       
   359             CBrowserContentView::NewLC( *this, rect );
       
   360         AddViewL( contentView ); // transfer ownership to CAknViewAppUi
       
   361         CleanupStack::Pop(); // contentView
       
   362         PERFLOG_STOP_WRITE("\t ContentView NewL");
       
   363         BROWSER_LOG( ( _L( "ContentView up" ) ) );
       
   364 
       
   365         //-------------------------------------------------------------------------
       
   366         // Create the Plugin Browser Engine
       
   367 
       
   368         // proxy will handle dialog events through load observer
       
   369         iDialogsProvider = CBrowserDialogsProvider::NewL( NULL);
       
   370         BROWSER_LOG( ( _L( "CBrowserDialogsProvider UP" ) ) );
       
   371 
       
   372 #ifdef __RSS_FEEDS
       
   373         iFeedsClientUtilities = CFeedsClientUtilities::NewL( *this, *this );
       
   374 
       
   375         BROWSER_LOG( ( _L("Feeds up.") ) );
       
   376 #endif //__RSS_FEEDS
       
   377 
       
   378         PERFLOG_STOPWATCH_START;
       
   379         // Is Multiple Window feature suported?
       
   380         if ( Preferences().UiLocalFeatureSupported( KBrowserMultipleWindows ) )
       
   381             {
       
   382             if (Preferences().UiLocalFeatureSupported( KBrowserMinimalMultipleWindows ))//midrange
       
   383                 {
       
   384                 iWindowManager = CBrowserWindowManager::NewL( *this, *contentView,
       
   385                     KMinNumOfOpenedWindows );
       
   386                 }
       
   387             else
       
   388                 {
       
   389                 iWindowManager = CBrowserWindowManager::NewL( *this, *contentView,
       
   390                     KMaxNumOfOpenedWindows );
       
   391                 }
       
   392             LOG_WRITE_FORMAT("WindowManager Up. Max windows number. %d",
       
   393                 KMaxNumOfOpenedWindows );
       
   394 
       
   395             // bug fix for: EMBI-6NBAYM
       
   396             // Be very careful of the location to initialize the iPopupEngine before
       
   397             // PopupEngine is improved.
       
   398             iPopupEngine = CBrowserPopupEngine::NewL();
       
   399             BROWSER_LOG( ( _L( "PopupEngine up" ) ) );
       
   400             }
       
   401         else
       
   402             {
       
   403             iWindowManager = CBrowserWindowManager::NewL( *this, *contentView,
       
   404                 KMinNumOfOpenedWindows );
       
   405             BROWSER_LOG( ( _L( "WindowManager Up. MWs not supported." ) ) );
       
   406             }
       
   407 
       
   408         PERFLOG_STOP_WRITE("\t WindowMgr + PopUp Engine");
       
   409         contentView->SetZoomLevelL();
       
   410         contentView->Container()->FindKeywordPane()->SetOrdinalPosition( 0 );
       
   411         contentView->Container()->GotoPane()->SetOrdinalPosition( 0 );
       
   412 
       
   413         //-------------------------------------------------------------------------
       
   414 
       
   415         PERFLOG_STOPWATCH_START;
       
   416         CBrowserBookmarksView* bookmarksView = NULL;
       
   417         TInt folderUid = doc->GetFolderToOpen();
       
   418         if ( IsEmbeddedModeOn() && folderUid!= KFavouritesRootUid)
       
   419             {
       
   420             bookmarksView = CBrowserBookmarksView::NewLC( *this, *iRecentUrlStore, folderUid );
       
   421             }
       
   422         else
       
   423             {
       
   424             bookmarksView = CBrowserBookmarksView::NewLC( *this, *iRecentUrlStore );
       
   425             }
       
   426         PERFLOG_STOP_WRITE("\t BMView NewL")
       
   427 
       
   428         iBookmarksView = bookmarksView;
       
   429 
       
   430         AddViewL( bookmarksView );  // transfer ownership to CAknViewAppUi
       
   431         CleanupStack::Pop(); // bookmarksView
       
   432         BROWSER_LOG( ( _L( "Bookmarksview up" ) ) );
       
   433 
       
   434         CBrowserSettingsView* settingsView = CBrowserSettingsView::NewLC( *this );
       
   435         AddViewL( settingsView );   // transfer ownership to CAknViewAppUi
       
   436         CleanupStack::Pop(); // settingsView
       
   437         BROWSER_LOG( ( _L( "SettingsView up" ) ) );
       
   438 
       
   439         CBrowserWindowSelectionView* windowSelectionView = CBrowserWindowSelectionView::NewLC( *this );
       
   440         AddViewL( windowSelectionView );   // transfer ownership to CAknViewAppUi
       
   441         CleanupStack::Pop(); // windowSelectionView
       
   442         BROWSER_LOG( ( _L( "windowSelectionView up" ) ) );
       
   443 
       
   444         CBrowserInitialView* initialView = CBrowserInitialView::NewLC( *this );
       
   445         AddViewL( initialView );   // transfer ownership to CAknViewAppUi
       
   446         CleanupStack::Pop(); // initialView
       
   447         BROWSER_LOG( ( _L( "initialView up" ) ) );
       
   448 
       
   449         //-------------------------------------------------------------------------
       
   450 
       
   451         iIdle = CIdle::NewL( CActive::EPriorityIdle );
       
   452 
       
   453         // Create asyncronous object to call when exit requires it.
       
   454         iBrowserAsyncExit = CBrowserAsyncExit::NewL( this );
       
   455         iStartedUp = ETrue;
       
   456         iSecureSiteVisited = EFalse;
       
   457 
       
   458 	    iPushMtmObserver = CBrowserPushMtmObserver::NewL( this );
       
   459 	    iPushMtmObserver->StartObserver();
       
   460         } //if (iStartedUp)
       
   461     }
       
   462 
       
   463 // -----------------------------------------------------------------------------
       
   464 // CBrowserAppUi::ProcessCommandL(TInt aCommand)
       
   465 // -----------------------------------------------------------------------------
       
   466 //
       
   467 void CBrowserAppUi::ProcessCommandL(TInt aCommand)
       
   468     {
       
   469     MEikAppUiFactory* appUiFactory = (iEikonEnv)->AppUiFactory();
       
   470     if (appUiFactory->MenuBar())
       
   471         {
       
   472         StopDisplayingMenuBar();
       
   473         }
       
   474     CAknViewAppUi::ProcessCommandL(aCommand);
       
   475     }
       
   476 
       
   477 // -----------------------------------------------------------------------------
       
   478 // CBrowserAppUi::HandleCommandL()
       
   479 // -----------------------------------------------------------------------------
       
   480 //
       
   481 void CBrowserAppUi::HandleCommandL(TInt aCommand)
       
   482     {
       
   483     // Default handling for all the thingies.
       
   484     switch (aCommand)
       
   485         {
       
   486         case EEikCmdExit:
       
   487 			{
       
   488 			ExitBrowser ( IsAppShutterActive() );
       
   489 			break;
       
   490 			}
       
   491     case EAknSoftkeyExit://  closes the whole application chain if embedded browser
       
   492     case EAknCmdExit:
       
   493 			{
       
   494 			if ( IsEmbeddedModeOn() )
       
   495 				{
       
   496 				CAknEnv::RunAppShutter();
       
   497 				break;
       
   498 				}
       
   499 			else
       
   500 				{
       
   501 				ExitBrowser ( ETrue ) ;
       
   502 				break;
       
   503 				}
       
   504 			}
       
   505 		//Fix for TSW error ICHV-75UFKZ	
       
   506 		case EWmlCmdUserExit://closes the current browser instance only
       
   507 		case EWmlCmdCloseBrowser: 
       
   508 			{
       
   509 			ExitBrowser ( ETrue );
       
   510 			break;
       
   511 			}
       
   512         case EWmlCmdChangeConnection :
       
   513             {
       
   514             ChangeConnectionL();
       
   515             break;
       
   516             }
       
   517         case EWmlCmdPreferences:
       
   518             {
       
   519             SetViewToBeActivatedIfNeededL( KUidBrowserSettingsViewId );
       
   520             break;
       
   521             }
       
   522         case EWmlCmdPreferencesToolbar:
       
   523             {
       
   524             SetViewToBeActivatedIfNeededL( KUidBrowserSettingsViewId, KUidSettingsGotoToolbarGroup.iUid );
       
   525             break;
       
   526             }            
       
   527         case EWmlCmdFavourites:
       
   528             {
       
   529             SetViewToBeActivatedIfNeededL( KUidBrowserBookmarksViewId );
       
   530             break;
       
   531             }
       
   532         case EWmlCmdSearchWeb:
       
   533             {
       
   534             LoadSearchPageL();
       
   535             break;
       
   536             }
       
   537         case EWmlCmdReload:
       
   538             {
       
   539 			BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandReload +
       
   540 												(TInt)TBrCtlDefs::ECommandIdBase );
       
   541             break;
       
   542             }
       
   543         case EAknSoftkeyBack:
       
   544         case EWmlCmdBack:
       
   545             {
       
   546             HistoryLoadPrevious();
       
   547             break;
       
   548             }
       
   549         case EWmlCmdBackToFeedsView:
       
   550             {
       
   551    			//Note: iPreviousView in this case will always be one of the Feeds view.
       
   552    			//In general iPreviousView holds the UID of the previous view.
       
   553    			SetViewToBeActivatedIfNeededL( iPreviousView );
       
   554             break;
       
   555             }
       
   556         case EWmlCmdClearTheCache:
       
   557             {
       
   558             ClearTheCacheL(ETrue, ETrue);
       
   559             break;
       
   560             }
       
   561         case EWmlCmdDeleteCookies:
       
   562             {
       
   563             DeleteCookiesL();
       
   564             TBrowserDialogs::InfoNoteL(
       
   565                 R_BROWSER_OK_NOTE, R_QTN_BROWSER_NOTE_COOKIES_DELETED );
       
   566             break;
       
   567             }
       
   568 
       
   569         case EWmlCmdClearAllPrivacy:
       
   570             {
       
   571             ClearAllPrivacyL();
       
   572             break;
       
   573             }
       
   574 
       
   575         case EWmlCmdClearHistory:
       
   576             {
       
   577             ClearHistoryWithPromptL();
       
   578             break;
       
   579             }
       
   580 
       
   581         case EWmlCmdClearFormAndPasswd:
       
   582             {
       
   583             ClearFormAndPasswdDataL(ETrue);
       
   584             break;
       
   585             }
       
   586 
       
   587         case EWmlCmdLaunchHomePage:
       
   588             {
       
   589             if (!IsLaunchHomePageDimmedL())
       
   590                 {
       
   591                 LaunchHomePageL( /* EFalse */ );
       
   592                 }
       
   593             break;
       
   594             }
       
   595         case EWmlCmdDisconnect :
       
   596             {
       
   597             DisconnectL();
       
   598             TBrowserDialogs::InfoNoteL(
       
   599 									R_BROWSER_INFO_NOTE, R_WML_DISCONNECT );
       
   600             break;
       
   601             }
       
   602         case EWmlCmdCancelFetch:
       
   603             {
       
   604             if (SpecialLoadObserver().IsConnectionStarted()) // If Connection request is in processing 
       
   605             {                                                // try to Cancel.
       
   606                 SpecialLoadObserver().CancelConnection();
       
   607                 Connection().Disconnect();
       
   608             }
       
   609             else
       
   610             {
       
   611                 CancelFetch( ETrue );
       
   612             }
       
   613             break;
       
   614             }
       
   615         case EWmlCmdPageInfo:
       
   616             {
       
   617             CSessionAndSecurity* security = CSessionAndSecurity::NewLC(*this);
       
   618             security->ShowPageInfoL();
       
   619             CleanupStack::PopAndDestroy(); // security
       
   620             break;
       
   621             }
       
   622         case EWmlCmdInfoSession:
       
   623             {
       
   624             CSessionAndSecurity* session = CSessionAndSecurity::NewLC(*this);
       
   625             session->ShowSessionInfoL();
       
   626             CleanupStack::PopAndDestroy();  // session
       
   627             break;
       
   628             }
       
   629         case EWmlCmdInfoSecurity:
       
   630             {
       
   631             CSessionAndSecurity* security = CSessionAndSecurity::NewLC(*this);
       
   632             security->ShowSecurityInfoL();
       
   633             CleanupStack::PopAndDestroy();  // security
       
   634             break;
       
   635             }
       
   636         // browser engine specific command
       
   637 #ifdef __SERIES60_HELP
       
   638 
       
   639         case EAknCmdHelp:
       
   640             {
       
   641             HlpLauncher::LaunchHelpApplicationL
       
   642                 ( iEikonEnv->WsSession(), AppHelpContextL() );
       
   643             break;
       
   644             }
       
   645 
       
   646 #endif //__SERIES60_HELP
       
   647 
       
   648 		case EWmlCmdForward:
       
   649 			{
       
   650             HistoryLoadNext();
       
   651 			break;
       
   652 			}
       
   653 
       
   654         case EWmlCmdRotateDisplay:
       
   655             {
       
   656             if ( Orientation() == EAppUiOrientationPortrait )
       
   657                 {
       
   658                 SetOrientationL(EAppUiOrientationLandscape);
       
   659                 }
       
   660             else if (Orientation() == EAppUiOrientationLandscape)
       
   661                 {
       
   662                 SetOrientationL(EAppUiOrientationPortrait);
       
   663                 }
       
   664             else // EAppUiOrientationUnspecified
       
   665                 {
       
   666                 TRect rect = ApplicationRect();
       
   667                 TInt width = rect.Width();
       
   668                 TInt height = rect.Height();
       
   669 
       
   670                 if (width > height)
       
   671                     {
       
   672                     SetOrientationL(EAppUiOrientationPortrait);
       
   673                     }
       
   674                 else
       
   675                     {
       
   676                     SetOrientationL(EAppUiOrientationLandscape);
       
   677                     }
       
   678                 }
       
   679              if(ContentView()->KeymapIsUp())
       
   680              	{             	          
       
   681              	ContentView()->RedrawKeymap();
       
   682              	}
       
   683             break;
       
   684             }
       
   685 
       
   686         case EWmlCmdAboutProduct:
       
   687             {
       
   688             // get version info from browser control and display it
       
   689             ShowNameAndVersionL();
       
   690             break;
       
   691             }
       
   692 		case EWmlCmdProductUpdate:
       
   693             {
       
   694     			/*if(!iAppUpdate)
       
   695 				    {
       
   696 				    iAppUpdate = CBrowserAppUpdate::NewL();
       
   697 				    }
       
   698 			    iAppUpdate->CheckUpdates();*/            
       
   699             break;
       
   700             }
       
   701 
       
   702         //=====================================================================
       
   703         // Multiple Windows Support
       
   704         //
       
   705     	case EWmlCmdSwitchWindow:
       
   706             {
       
   707             if(WindowMgr().WindowCount() > 1)
       
   708 	            {
       
   709 	            // use switch window tab view if pageoverview bitmaps are available
       
   710 	            if (Preferences().UiLocalFeatureSupported( KBrowserGraphicalPage ))
       
   711 	            	{
       
   712 	            	SetViewToBeActivatedIfNeededL( KUidBrowserWindowSelectionViewId );
       
   713 	            	}
       
   714 	            else
       
   715 	            	{
       
   716 	            	SwitchWindowL();
       
   717 		            }            	
       
   718             	}
       
   719             break;
       
   720             }
       
   721     	case EWmlCmdCloseWindow:
       
   722     		{
       
   723     		if ( IsEmbeddedInOperatorMenu() )
       
   724     			{
       
   725     			ExitBrowser( ETrue );
       
   726     			}
       
   727     		else
       
   728 				{
       
   729     			CloseWindowL();
       
   730 				}
       
   731     		break;
       
   732     		}
       
   733     	case EWmlCmdAllowPopups:
       
   734         	{
       
   735         	// Add url to whitelist
       
   736         	HBufC* url( WindowMgr().CurrentWindow()->BrCtlInterface().
       
   737                 PageInfoLC( TBrCtlDefs::EPageInfoUrl ) );
       
   738             PopupEngine().AddUrlToWhiteListL( *url );
       
   739             CleanupStack::PopAndDestroy( url );
       
   740     		break;
       
   741 	    	}
       
   742     	case EWmlCmdBlockPopups:
       
   743         	{
       
   744         	// Remove from whitelist
       
   745         	HBufC* url( WindowMgr().CurrentWindow()->BrCtlInterface().
       
   746                 PageInfoLC( TBrCtlDefs::EPageInfoUrl ) );
       
   747         	PopupEngine().RemoveUrlFromWhiteListL( *url );
       
   748             CleanupStack::PopAndDestroy( url );
       
   749         	break;
       
   750         	}
       
   751         case EWmlCmdShowAnchorHref:
       
   752             {
       
   753 			BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandIdBase + (TInt)TBrCtlDefs::ECommandShowAnchorHref );
       
   754             break;
       
   755             }
       
   756         case EWmlCmdSaveToGallery:
       
   757             {
       
   758             SaveFocusedImageToGalleryL();
       
   759             break;
       
   760             }
       
   761         case EWmlCmdOpenToViewer:
       
   762             {
       
   763             TBrCtlImageCarrier* imageCarrier = BrCtlInterface().FocusedImageLC();
       
   764             if (imageCarrier)
       
   765                 {
       
   766                 CArrayFixFlat<TBrCtlImageCarrier>* imageArray = new( ELeave ) CArrayFixFlat<TBrCtlImageCarrier>(1);
       
   767                 CleanupStack::PushL(imageArray);
       
   768                 imageArray->AppendL(*imageCarrier);
       
   769                 iDialogsProvider->DialogDisplayPageImagesL( *imageArray );
       
   770                 CleanupStack::PopAndDestroy(2); // imageArray, imageCarrier
       
   771                 }
       
   772             break;
       
   773             }
       
   774         case EWmlCmdSaveUrlAsBookmark:
       
   775             {
       
   776             HBufC* url = BrCtlInterface().PageInfoLC(TBrCtlDefs::EPageInfoFocusedNodeUrl);
       
   777             ContentView()->AddNewBookmarkL(EFalse, url);
       
   778             CleanupStack::PopAndDestroy(); // url
       
   779             break;
       
   780             }
       
   781         case EWmlCmdSmartLinkMakeCall:
       
   782             {
       
   783 			BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandIdBase + (TInt)TBrCtlDefs::ECommandSmartLinkMakeCall );
       
   784             break;
       
   785             }
       
   786         case EWmlCmdSmartLinkSendEmail:
       
   787             {
       
   788 			BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandIdBase + (TInt)TBrCtlDefs::ECommandSmartLinkSendEmail );
       
   789             break;
       
   790             }
       
   791         case EWmlCmdSmartLinkSendSms:
       
   792             {
       
   793 			BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandIdBase + (TInt)TBrCtlDefs::ECommandSmartLinkSendMessage );
       
   794             break;
       
   795             }
       
   796         case EWmlCmdSmartLinkAddToContacts:
       
   797             {
       
   798 			BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandIdBase + (TInt)TBrCtlDefs::ECommandSmartLinkAddToPhoneBook );
       
   799             break;
       
   800             }
       
   801         case EWmlCmdLoadFocusedImage:
       
   802             {
       
   803 			BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandIdBase + (TInt)TBrCtlDefs::ECommandLoadFocusedImage );
       
   804             break;
       
   805             }
       
   806         case EWmlCmdLoadImagesOnly:
       
   807             {
       
   808             iPreferences->SetAutoLoadContentL(EWmlSettingsAutoloadImagesNoFlash);
       
   809             break;
       
   810             }
       
   811         case EWmlCmdLoadImagesAndFlash:
       
   812             {
       
   813             iPreferences->SetAutoLoadContentL(EWmlSettingsAutoloadAll);
       
   814             break;
       
   815             }
       
   816         case EWmlCmdOneStepBack:
       
   817             {
       
   818 			BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandIdBase + (TInt)TBrCtlDefs::ECommandOneStepBack );
       
   819             break;
       
   820             }
       
   821 	    //=====================================================================
       
   822         default:
       
   823             {
       
   824             if( iStartedUp )
       
   825                 {
       
   826                 // pass to Browser Control
       
   827                 BrCtlInterface().HandleCommandL( aCommand );
       
   828                 }
       
   829             break;
       
   830             }
       
   831         }
       
   832     }
       
   833 
       
   834 // -----------------------------------------------------------------------------
       
   835 // CBrowserAppUi::ActiveView()
       
   836 // -----------------------------------------------------------------------------
       
   837 //
       
   838 CBrowserViewBase* CBrowserAppUi::ActiveView()
       
   839     {
       
   840     TVwsViewId activeViewId;
       
   841     TInt err = GetActiveViewId( activeViewId );
       
   842 
       
   843     if ( !err )
       
   844         {
       
   845         return STATIC_CAST( CBrowserViewBase*, View(activeViewId.iViewUid) );
       
   846         }
       
   847     else
       
   848         {
       
   849         //We should not panic
       
   850         //On 3.0 wk40 it was observed that GetActiveViewId returned with KErrNotFound
       
   851         //in case Browser was in the background
       
   852         //Symbian error?
       
   853         return NULL;
       
   854         }
       
   855     }
       
   856 
       
   857 // -----------------------------------------------------------------------------
       
   858 // CBrowserAppUi::SetRequestedAP()
       
   859 // -----------------------------------------------------------------------------
       
   860 //
       
   861 void CBrowserAppUi::SetRequestedAP( TInt aAp )
       
   862     {
       
   863     iRequestedAp = aAp;
       
   864     }
       
   865 
       
   866 // -----------------------------------------------------------------------------
       
   867 // CBrowserAppUi::IsPageLoaded()
       
   868 // -----------------------------------------------------------------------------
       
   869 //
       
   870 TBool CBrowserAppUi::IsPageLoaded()
       
   871     {
       
   872     TBool ret( EFalse );
       
   873     TInt winCount( WindowMgr().WindowCount() );
       
   874 
       
   875     // at least 2 window -> there is a page loaded
       
   876     if( winCount > 1 )
       
   877         {
       
   878         ret = ETrue;
       
   879         }
       
   880     // 1 window with a loaded content
       
   881     else if( winCount == 1 )
       
   882         {
       
   883         // This checks to see if a dialog is launched and if that is the case, then
       
   884         // the current window is being used, hence returning true.
       
   885         if( iDialogsProvider->IsDialogLaunched() )
       
   886             {
       
   887             ret = ETrue;
       
   888             }
       
   889         else
       
   890             {
       
   891             ret = WindowMgr().IsContentExist();
       
   892             }
       
   893         }
       
   894     // else (winCount == 0), no content view -> no page loaded
       
   895     return ret;
       
   896     }
       
   897 
       
   898 // -----------------------------------------------------------------------------
       
   899 // CBrowserAppUi::Fetching()
       
   900 // -----------------------------------------------------------------------------
       
   901 //
       
   902 TBool CBrowserAppUi::Fetching() const
       
   903     {
       
   904 	// TO DO:
       
   905 	// use load obs., remove ifetchstate from this class and use from loadobs.
       
   906 	// iLoadState
       
   907     //return ( iFetchState == MFetchObserver::ELoadStart );
       
   908 	return ( LoadObserver().LoadState() != CBrowserLoadObserver::ELoadStateIdle );
       
   909     }
       
   910 // -----------------------------------------------------------------------------
       
   911 // CBrowserAppUi::ContentDisplayed()
       
   912 // -----------------------------------------------------------------------------
       
   913 //
       
   914 TBool CBrowserAppUi::ContentDisplayed() const
       
   915     {
       
   916     return ( LoadObserver().ContentDisplayed() );
       
   917     }
       
   918 
       
   919 // -----------------------------------------------------------------------------
       
   920 // CBrowserAppUi::SetContentDisplayed()
       
   921 // -----------------------------------------------------------------------------
       
   922 //
       
   923 void CBrowserAppUi::SetContentDisplayed(TBool aValue) 
       
   924     {
       
   925         LoadObserver().SetContentDisplayed( aValue );
       
   926     }
       
   927 // -----------------------------------------------------------------------------
       
   928 // CBrowserAppUi::FetchBookmarkL
       
   929 // -----------------------------------------------------------------------------
       
   930 //
       
   931 void CBrowserAppUi::FetchBookmarkL( TInt aBookmarkUid )
       
   932     {
       
   933     SetViewToReturnOnClose( KUidBrowserBookmarksViewId );
       
   934     if ( aBookmarkUid == KFavouritesStartPageUid )
       
   935         {
       
   936         TUint defaultAp = Preferences().DefaultAccessPoint();
       
   937         if ( defaultAp != KWmlNoDefaultAccessPoint ) // There is no access point defined
       
   938             {
       
   939             CApAccessPointItem* apItem = Preferences().AllPreferencesL().iDefaultAPDetails;
       
   940             if ( apItem )
       
   941                 {
       
   942                 const HBufC* currentHP = apItem->ReadConstLongTextL( EApWapStartPage );
       
   943                 //TPtrC currentHP(apItem->StartPage()); // Get the start page of the access point.
       
   944                 TFavouritesWapAp accessPoint;
       
   945 
       
   946                 FetchL( *currentHP, KNullDesC, KNullDesC, accessPoint,
       
   947                     CBrowserLoadObserver::ELoadUrlTypeStartPage ); // Fetch the start page.
       
   948 				}
       
   949             }
       
   950         }
       
   951     else
       
   952         {
       
   953         RFavouritesDb db;
       
   954         User::LeaveIfError( db.Open( iFavouritesSess, KBrowserBookmarks ) );
       
   955         CleanupClosePushL<RFavouritesDb>( db );
       
   956 
       
   957         CFavouritesItem* item = CFavouritesItem::NewLC();
       
   958         User::LeaveIfError( db.Get( aBookmarkUid, *item ) );
       
   959 
       
   960         FetchBookmarkL( *item );
       
   961         CleanupStack::PopAndDestroy( 2 );  // item, db
       
   962         }
       
   963     }
       
   964 
       
   965 // -----------------------------------------------------------------------------
       
   966 // CBrowserAppUi::FetchBookmarkL
       
   967 // -----------------------------------------------------------------------------
       
   968 //
       
   969 void CBrowserAppUi::FetchBookmarkL( const CFavouritesItem& aBookmarkItem )
       
   970     {
       
   971     SetViewToReturnOnClose( KUidBrowserBookmarksViewId );
       
   972     if ( Util::CheckBookmarkApL( *this, aBookmarkItem.WapAp()) )
       
   973         FetchL
       
   974             (
       
   975             aBookmarkItem.Url() ,
       
   976             aBookmarkItem.UserName(),
       
   977             aBookmarkItem.Password(),
       
   978             aBookmarkItem.WapAp(),
       
   979             CBrowserLoadObserver::ELoadUrlTypeOther
       
   980             );
       
   981     else
       
   982         TBrowserDialogs::ErrorNoteL( R_WML_INVALID_AP );
       
   983     }
       
   984 
       
   985 // -----------------------------------------------------------------------------
       
   986 // CBrowserAppUi::SetViewToBeActivatedIfNeededL
       
   987 // -----------------------------------------------------------------------------
       
   988 //
       
   989 void CBrowserAppUi::SetViewToBeActivatedIfNeededL( TUid aUid, TInt aMessageId )
       
   990     {
       
   991 	CBrowserAppDocument* doc = STATIC_CAST(CBrowserAppDocument*, Document());
       
   992 
       
   993 	if((iCurrentView != aUid) && (aUid != KUidBrowserSettingsViewId))
       
   994 	{
       
   995 		iPreviousView = iCurrentView;
       
   996 		iCurrentView = aUid;
       
   997 	}
       
   998 
       
   999 	//Check view id validity first
       
  1000 	if ( aUid == KUidBrowserNullViewId )
       
  1001 		{
       
  1002 		SetLastActiveViewId( KUidBrowserBookmarksViewId );
       
  1003 		SetViewToBeActivatedIfNeededL( LastActiveViewId() );
       
  1004            return;
       
  1005 		}
       
  1006 
       
  1007 	if ( ( aUid != KUidBrowserContentViewId ) && 
       
  1008 	   ( LastActiveViewId() == KUidBrowserContentViewId ) )
       
  1009 		{
       
  1010 		ContentView()->SetFullScreenOffL();
       
  1011 		}
       
  1012 	
       
  1013 	if ( iWindowManager->ContentView()->FullScreenMode() )
       
  1014 	    {
       
  1015     	if ( aUid == KUidBrowserFeedsFeedViewId )
       
  1016     	    {
       
  1017     	    BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandIdBase + 
       
  1018     	        (TInt)TBrCtlDefs::ECommandLeaveFullscreenBrowsing );
       
  1019     	    }
       
  1020     	
       
  1021     	else  if ( aUid != KUidBrowserFeedsTopicViewId && 
       
  1022             aUid != KUidBrowserFeedsFolderViewId && 
       
  1023             aUid != KUidBrowserBookmarksViewId )
       
  1024             {
       
  1025             BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandIdBase + 
       
  1026                 (TInt)TBrCtlDefs::ECommandEnterFullscreenBrowsing );
       
  1027             }
       
  1028     	}
       
  1029 
       
  1030 
       
  1031 	if ( iIsForeground )
       
  1032 		{
       
  1033         if ( aUid == KUidBrowserSettingsViewId )
       
  1034 	        {
       
  1035             CEikStatusPane* sp = STATIC_CAST( CAknAppUi*,
       
  1036 						  CEikonEnv::Static()->EikAppUi() )
       
  1037 			                ->StatusPane();
       
  1038             sp->DrawNow();
       
  1039             }
       
  1040 
       
  1041 		ActivateLocalViewL(  aUid, TUid::Uid( aMessageId ), KNullDesC8 );
       
  1042 		}
       
  1043 	else
       
  1044 		{
       
  1045 		iViewToBeActivatedIfNeeded = aUid;
       
  1046 		}
       
  1047     }
       
  1048 
       
  1049 // -----------------------------------------------------------------------------
       
  1050 // CBrowserAppUi::LastActiveViewId
       
  1051 // -----------------------------------------------------------------------------
       
  1052 //
       
  1053 TUid CBrowserAppUi::LastActiveViewId() const
       
  1054     {
       
  1055     return iLastViewId;
       
  1056     }
       
  1057 
       
  1058 // -----------------------------------------------------------------------------
       
  1059 // CBrowserAppUi::SetLastActiveViewId
       
  1060 // -----------------------------------------------------------------------------
       
  1061 //
       
  1062 void CBrowserAppUi::SetLastActiveViewId( TUid aUid )
       
  1063     {
       
  1064 LOG_ENTERFN("CBrowserAppUi::SetLastActiveViewId");
       
  1065     LOG_WRITE_FORMAT(" SetLastActiveViewId: %d", aUid);
       
  1066     iLastViewId = aUid;
       
  1067     }
       
  1068 
       
  1069 // -----------------------------------------------------------------------------
       
  1070 // CBrowserAppUi::ExitInProgress
       
  1071 // -----------------------------------------------------------------------------
       
  1072 //
       
  1073 TBool CBrowserAppUi::ExitInProgress() const
       
  1074     {
       
  1075     return iExitInProgress;
       
  1076     }
       
  1077 
       
  1078 // -----------------------------------------------------------------------------
       
  1079 // CBrowserAppUi::ExitInProgress
       
  1080 // -----------------------------------------------------------------------------
       
  1081 //
       
  1082 void CBrowserAppUi::SetExitInProgress( TBool aValue )
       
  1083     {
       
  1084     iExitInProgress = aValue;
       
  1085     }
       
  1086 
       
  1087 // -----------------------------------------------------------------------------
       
  1088 // CBrowserAppUi::IsConnecting
       
  1089 // -----------------------------------------------------------------------------
       
  1090 //
       
  1091 TBool CBrowserAppUi::IsConnecting() const
       
  1092     {
       
  1093     return ( LoadObserver().LoadState() != CBrowserLoadObserver::ELoadStateIdle );
       
  1094     }
       
  1095 
       
  1096 // -----------------------------------------------------------------------------
       
  1097 // CBrowserAppUi::HandleForegroundEventL
       
  1098 // -----------------------------------------------------------------------------
       
  1099 //
       
  1100 void CBrowserAppUi::HandleForegroundEventL( TBool aForeground )
       
  1101     {
       
  1102     // Handle this event only if the browser is started up
       
  1103     if ( !StartedUp() )
       
  1104     	{
       
  1105     	return;
       
  1106     	}
       
  1107     iIsForeground = IsForeground();
       
  1108     if( iIsForeground )
       
  1109     	{
       
  1110  	    if (iViewToBeActivatedIfNeeded.iUid)
       
  1111 	        {
       
  1112 	        ActivateLocalViewL( iViewToBeActivatedIfNeeded );
       
  1113 	        }
       
  1114 	    else
       
  1115 	        {
       
  1116 	        // LastActiveViewId() might return with 0!
       
  1117 	        TRAP_IGNORE( ActivateLocalViewL( LastActiveViewId() ) );
       
  1118 	        }    	
       
  1119     	}
       
  1120 	iViewToBeActivatedIfNeeded.iUid = 0;    
       
  1121     CAknViewAppUi::HandleForegroundEventL( aForeground );
       
  1122             
       
  1123     if( iIsForeground )
       
  1124         {	               
       
  1125         // We need to refresh the softkeys
       
  1126         UpdateCbaL();
       
  1127         if ( Preferences().FullScreen() == EWmlSettingsFullScreenFullScreen )
       
  1128             {
       
  1129             ContentView()->UpdateFullScreenL();
       
  1130             }
       
  1131 
       
  1132         if( !Fetching() )
       
  1133             {
       
  1134             Display().StopProgressAnimationL();
       
  1135             }
       
  1136         }
       
  1137     else if (ContentView()->FullScreenMode())
       
  1138 	    {
       
  1139 	    //Disable content view full screen mode if it goes to background
       
  1140     	ContentView()->EnableFullScreenModeL( EFalse);
       
  1141 	    }
       
  1142 
       
  1143 
       
  1144     if (iWindowManager)
       
  1145         {
       
  1146         iWindowManager->SendCommandToAllWindowsL( iIsForeground
       
  1147             ? (TInt)TBrCtlDefs::ECommandAppForeground + (TInt)TBrCtlDefs::ECommandIdBase
       
  1148             : (TInt)TBrCtlDefs::ECommandAppBackground + (TInt)TBrCtlDefs::ECommandIdBase);
       
  1149         }
       
  1150 
       
  1151     // if browser comes to foreground and exit is requested,
       
  1152     // asyncronous exit is started
       
  1153     if( iIsForeground && iExitFromEmbeddedMode && !IsEmbeddedInOperatorMenu() )
       
  1154         {
       
  1155         iBrowserAsyncExit->Start();
       
  1156         } 
       
  1157     }
       
  1158 
       
  1159 // -----------------------------------------------------------------------------
       
  1160 // CBrowserAppUi::FetchL
       
  1161 // -----------------------------------------------------------------------------
       
  1162 //
       
  1163 void CBrowserAppUi::FetchL(
       
  1164 						   const TDesC& aUrl,
       
  1165                            const TDesC& aUsername,
       
  1166                            const TDesC& aPassword,
       
  1167                            const TFavouritesWapAp& aAccessPoint,
       
  1168                            CBrowserLoadObserver::TBrowserLoadUrlType aUrlType )
       
  1169     {
       
  1170 LOG_ENTERFN("CBrowserAppUi::FetchL");
       
  1171     // Let's cancel the previous fetch if any
       
  1172     if ( Fetching() )
       
  1173 		{
       
  1174         CancelFetch();
       
  1175 		}
       
  1176 
       
  1177     // iDoNotRestoreContentFlag = EFalse;
       
  1178 
       
  1179     TInt toPop = 0;
       
  1180     TUriParser uriParser;
       
  1181     TInt err = uriParser.Parse(aUrl);
       
  1182     if ( !err && aUrl.Length() )
       
  1183         {
       
  1184         // check url for missing scheme and add default scheme if needed
       
  1185         HBufC* url = NULL;
       
  1186         HBufC* resultUrlBuf = NULL;
       
  1187         //find ://
       
  1188         TPtrC scheme = uriParser.Extract( EUriScheme );
       
  1189         // add http:// scheme as default if it is missing
       
  1190         if( scheme.Length() == 0 )
       
  1191             { 
       
  1192             //put the "http://" schema before the string
       
  1193             url = HBufC::NewLC( aUrl.Length() + KDefaultSchemaLength );
       
  1194             url->Des().Copy( KDefaultSchema );
       
  1195             url->Des().Append( aUrl );
       
  1196             ++toPop;  // url
       
  1197             resultUrlBuf = CreateFullUrlLC( url->Des(), aUsername, aPassword );
       
  1198 		    LogRequestedPageToRecentUrlL(  url->Des() );
       
  1199             }
       
  1200         else
       
  1201             {
       
  1202             resultUrlBuf = CreateFullUrlLC( aUrl, aUsername, aPassword );
       
  1203 		    LogRequestedPageToRecentUrlL(  aUrl );
       
  1204             }
       
  1205         ++toPop;  // resultUrlBuf
       
  1206     
       
  1207     
       
  1208         if ( aAccessPoint.IsNull() || aAccessPoint.IsDefault() || (!Util::IsValidAPFromParamL( *this, aAccessPoint.ApId() )) )
       
  1209 			{
       
  1210             if ( (Preferences().AccessPointSelectionMode() == EConnectionMethod) || 
       
  1211                  (Preferences().AccessPointSelectionMode() == EAlwaysAsk) )
       
  1212                 {
       
  1213     			iRequestedAp = Preferences().DefaultAccessPoint();
       
  1214                 }
       
  1215             else if ( Preferences().AccessPointSelectionMode() == EDestination ) 
       
  1216                 {
       
  1217                 // for bug fix MLAN-7EKFV4
       
  1218     			iRequestedAp = KWmlNoDefaultAccessPoint;
       
  1219                 }
       
  1220             }
       
  1221 		else
       
  1222 			{
       
  1223 			iRequestedAp = aAccessPoint.ApId();
       
  1224 			}
       
  1225 #ifndef __WINSCW__ //On WINS we don't want this dlg to come up
       
  1226 					//as the ConnMan will present us with a selection
       
  1227         BROWSER_LOG( ( _L( "requestedAp: %d" ), iRequestedAp ) );
       
  1228         // it's ok to assign in the case of EDest, since CBrCtl doesn't use the apId passed in LoadUrlL()
       
  1229         TUint32 IAPid = iRequestedAp;
       
  1230         TUint32 defaultSnap =  iPreferences->DefaultSnapId();
       
  1231         // if no AP or SNAP is defined, define it
       
  1232         if( (iRequestedAp == KWmlNoDefaultAccessPoint && iPreferences->AccessPointSelectionMode() == EConnectionMethod) || 
       
  1233             (defaultSnap == KWmlNoDefaultSnapId && iPreferences->AccessPointSelectionMode() == EDestination) )
       
  1234             {
       
  1235             StartPreferencesViewL( EShowAlwaysAsk | EShowDestinations | EShowConnectionMethods );
       
  1236             }
       
  1237         //Check AP and snap if it is still not defined, set always ask mode this case
       
  1238         if ( (iRequestedAp == KWmlNoDefaultAccessPoint && iPreferences->AccessPointSelectionMode() == EConnectionMethod) ||
       
  1239              (defaultSnap == KWmlNoDefaultSnapId && iPreferences->AccessPointSelectionMode() == EDestination) )
       
  1240             {
       
  1241             BROWSER_LOG( ( _L( "AP or SNAP was not added set to Always ask mode" ) ) );
       
  1242             iPreferences->SetAccessPointSelectionModeL(EAlwaysAsk );
       
  1243             }
       
  1244         if ( iRequestedAp == KWmlNoDefaultAccessPoint )
       
  1245             {
       
  1246             // For all cases just set dummy id to IAPid not to let Ap engine or Ap util to leave
       
  1247             // In the cases of EDest, EAA, since ap will not be used, it's ok to do so as well
       
  1248             // In the case of EDest, need to preserve KWmlNoDefaultAccessPoint as the value
       
  1249             // it'll be used in BrowserSpecialLoadObserver.cpp for for bug fix MLAN-7EKFV4
       
  1250             if ( Preferences().AccessPointSelectionMode() != EDestination )
       
  1251                 {
       
  1252     		    iRequestedAp = 2;
       
  1253                 }
       
  1254             IAPid = 2;
       
  1255             }
       
  1256         else
       
  1257             {
       
  1258     		BROWSER_LOG( ( _L( "AP added" ) ) );
       
  1259     		IAPid = Util::IapIdFromWapIdL( *this, iRequestedAp );  // Get currently active ap
       
  1260     		BROWSER_LOG( ( _L( "No AP 2" ) ) );
       
  1261             }
       
  1262 
       
  1263 #else	//we can use any numbers here
       
  1264         // alr: snap on emulator should not exist; use cm mode instead?
       
  1265 		iRequestedAp = 2;
       
  1266 		TUint32 IAPid = 2;
       
  1267 #endif //__WINSCW__
       
  1268 
       
  1269 		err = KErrNone;
       
  1270 		BROWSER_LOG( ( _L( "Load the URL" ) ) );
       
  1271         LoadObserver().DoStartLoad( aUrlType );
       
  1272         
       
  1273         TRAP( err, BrCtlInterface().LoadUrlL( resultUrlBuf->Des(), IAPid ) );
       
  1274 
       
  1275 		CleanupStack::PopAndDestroy(toPop); //resultUrlBuf and url if needed
       
  1276 		BROWSER_LOG( ( _L( "No AP 4 %d" ), err  ) );
       
  1277 		if ( err != KErrNone )
       
  1278     		{
       
  1279 		    CancelFetch();
       
  1280 	    	}
       
  1281         }
       
  1282 
       
  1283     BROWSER_LOG( ( _L( "Check the result" ) ) );
       
  1284 	switch ( err )
       
  1285 		{
       
  1286 		case KErrNotFound:
       
  1287 			{
       
  1288 			(*(CBrowserBookmarksView*)View( KUidBrowserBookmarksViewId )).UpdateGotoPaneL();
       
  1289 			iCoeEnv->HandleError( KBrsrMalformedUrl );
       
  1290 			BROWSER_LOG( ( _L( "KErrNotFound" ) ) );
       
  1291 			break;
       
  1292 			}
       
  1293 		case KUriUtilsErrInvalidUri: // return value of TUriParser::Parse
       
  1294 			{
       
  1295 			(*(CBrowserBookmarksView*)View( KUidBrowserBookmarksViewId )).UpdateGotoPaneL();
       
  1296 			iCoeEnv->HandleError( KBrsrUnknownScheme );
       
  1297 			BROWSER_LOG( ( _L( "KUriUtilsErrInvalidUri" ) ) );
       
  1298 			break;
       
  1299 			}
       
  1300 		case KErrNone:
       
  1301 		    {
       
  1302 		    BROWSER_LOG( ( _L( "KErrNone" ) ) );
       
  1303             ContentView()->ResetPreviousViewFlag();
       
  1304 		    break;
       
  1305 		    }
       
  1306         case KErrCancel:
       
  1307             {
       
  1308             BROWSER_LOG( ( _L( "KErrCancel" ) ) );
       
  1309             // do nothing, it is already cancelled by CancelFetch().
       
  1310             break;
       
  1311             }
       
  1312         default:
       
  1313 			{
       
  1314 			BROWSER_LOG( ( _L( "default" ) ) );
       
  1315 			User::Leave( err );  // pass error code to caller
       
  1316 			break;
       
  1317 			}
       
  1318 		}
       
  1319 	}
       
  1320 
       
  1321 // -----------------------------------------------------------------------------
       
  1322 // CBrowserAppUi::ExitBrowser()
       
  1323 // -----------------------------------------------------------------------------
       
  1324 //
       
  1325 void CBrowserAppUi::ExitBrowser( TBool aUserInitiated )
       
  1326     {
       
  1327     LOG_ENTERFN("CBrowserAppUi::ExitBrowser");
       
  1328 
       
  1329     TInt err( KErrNone );
       
  1330 	TBool isStandAlone = !IsEmbeddedModeOn();
       
  1331 	BROWSER_LOG( ( _L( " isStandAlone: %d" ), isStandAlone ) );
       
  1332 
       
  1333 	if( isStandAlone && aUserInitiated )
       
  1334 	    {
       
  1335 		if( !BrCtlInterface().OkToExit() )
       
  1336 		    {
       
  1337 		    return;
       
  1338 		    }
       
  1339 	    }
       
  1340 
       
  1341 	//If launch with parameters is in progress, do not exit now
       
  1342 	//as it can lead to synchronisation problems in embedded mode
       
  1343 	if ( iParametrizedLaunchInProgress == 1 )
       
  1344 		{
       
  1345 		BROWSER_LOG( ( _L( " iParametrizedLaunchInProgress" ) ) );
       
  1346 		return;
       
  1347 		}
       
  1348 
       
  1349     // Operator feature - Display confirmation note on exit only if exit is initiated by user.
       
  1350     // Skip displaying exit confirmation if exit is initiated from fast swap window.
       
  1351     BROWSER_LOG(  ( _L( " iPreferences:  %d" ), iPreferences ) );
       
  1352     if ( iPreferences->QueryOnExit() && aUserInitiated )
       
  1353         {
       
  1354         BROWSER_LOG( ( _L( " iPreferences->QueryOnExit()" ) ) );
       
  1355         TBool confirmdialog( EFalse );
       
  1356         TRAP( err, confirmdialog = TBrowserDialogs::ConfirmQueryYesNoL( R_TEXT_WML_EXIT_CONFIRM ) );
       
  1357         if ( !confirmdialog )
       
  1358         	{
       
  1359             return;
       
  1360         	}
       
  1361 		}
       
  1362 
       
  1363     //delete attacment from mailer if existing
       
  1364 	CCoeEnv::Static()->FsSession().Delete( KAttachment() );
       
  1365 	
       
  1366     BROWSER_LOG( ( _L(" iConnection:  %d"), iConnection ) );
       
  1367     BROWSER_LOG( ( _L(" iExitFromEmbeddedMode:  %d"), iExitFromEmbeddedMode ) );
       
  1368     // if browser is embedded, should not call Exit(),
       
  1369     // just delete the object, otherwise leave occurs.
       
  1370     if( ( IsEmbeddedInOperatorMenu() || IsEmbeddedModeOn() ) &&
       
  1371             !ExitInProgress() &&
       
  1372              ((LoadObserver().LoadUrlType() == CBrowserLoadObserver::ELoadUrlTypeEmbeddedBrowserWithUrl) ||
       
  1373               (LoadObserver().LoadUrlType() == CBrowserLoadObserver::ELoadUrlTypeOther)   ) )
       
  1374                // ELoadUrlTypeEmbeddedBrowserWithUrl is typical for load via Phonebook, MMS, OperatorMenu
       
  1375                // ELoadUrlTypeOther is typical via Media download since those are via GotoPane entered urls
       
  1376         {
       
  1377         // Simulate an escape key event in order to close any open resources (for example an open dialog)
       
  1378         TKeyEvent keyEvent;
       
  1379         keyEvent.iModifiers = 0;
       
  1380         keyEvent.iRepeats = 0;
       
  1381         keyEvent.iCode = EKeyEscape;
       
  1382         keyEvent.iScanCode = EStdKeyEscape;
       
  1383         TRAP_IGNORE(iCoeEnv->SimulateKeyEventL( keyEvent, EEventKey ));
       
  1384 
       
  1385         // force not to load Exit() when next time call this function,
       
  1386         // just delete the object
       
  1387         SetExitFromEmbeddedMode( ETrue );
       
  1388         SetExitInProgress( ETrue );
       
  1389         BROWSER_LOG( ( _L( " iBrowserAsyncExit->Start()" ) ) );
       
  1390         iBrowserAsyncExit->Start();
       
  1391         }
       
  1392     else if( iExitFromEmbeddedMode )
       
  1393     	{
       
  1394     	BROWSER_LOG( ( _L( " delete this;" ) ) );
       
  1395     	if ( iConnection )
       
  1396     		{
       
  1397             TRAP_IGNORE( SendDisconnectEventL() );
       
  1398     		iConnection->Disconnect();
       
  1399 #ifdef __RSS_FEEDS
       
  1400             BROWSER_LOG( ( _L( " iFeedsClientUtilities->DisconnectFeedsViewL()" ) ) );
       
  1401             TRAP_IGNORE( iFeedsClientUtilities->DisconnectFeedsViewL() );
       
  1402             //notify feeds engine to close the connection
       
  1403             TRAP_IGNORE( iFeedsClientUtilities->DisconnectManualUpdateConnectionL() );
       
  1404 #endif
       
  1405     		}
       
  1406         PrepareToExit();
       
  1407         Exit();
       
  1408     	}
       
  1409     else
       
  1410     	{
       
  1411     	BROWSER_LOG( ( _L( " Exit()" ) ) );
       
  1412     	if ( iConnection )
       
  1413     		{
       
  1414             TRAP_IGNORE( SendDisconnectEventL() );
       
  1415     		iConnection->Disconnect();
       
  1416 #ifdef __RSS_FEEDS
       
  1417     		BROWSER_LOG( ( _L( " iFeedsClientUtilities->DisconnectFeedsViewL()" ) ) );
       
  1418     		TRAP_IGNORE( iFeedsClientUtilities->DisconnectFeedsViewL() );
       
  1419     		//notify feeds engine to close the connection
       
  1420 			TRAP_IGNORE( iFeedsClientUtilities->DisconnectManualUpdateConnectionL() );
       
  1421 #endif
       
  1422     		}
       
  1423         Exit();
       
  1424     	}
       
  1425     }
       
  1426 
       
  1427 // -----------------------------------------------------------------------------
       
  1428 // CBrowserAppUi::Display
       
  1429 // -----------------------------------------------------------------------------
       
  1430 //
       
  1431 MDisplay& CBrowserAppUi::Display() const
       
  1432     {
       
  1433     CBrowserWindow *window = iWindowManager->CurrentWindow();
       
  1434     __ASSERT_DEBUG( window, Util::Panic( Util::EUninitializedData ) );
       
  1435     return window->Display();
       
  1436     }
       
  1437 
       
  1438 // -----------------------------------------------------------------------------
       
  1439 // CBrowserAppUi::SoftkeysObserver()
       
  1440 // -----------------------------------------------------------------------------
       
  1441 //
       
  1442 CBrowserSoftkeysObserver& CBrowserAppUi::SoftkeysObserver() const
       
  1443     {
       
  1444     CBrowserWindow *window = iWindowManager->CurrentWindow();
       
  1445     __ASSERT_DEBUG( window, Util::Panic( Util::EUninitializedData ) );
       
  1446     return window->SoftkeysObserver();
       
  1447     }
       
  1448 
       
  1449 // -----------------------------------------------------------------------------
       
  1450 // CBrowserAppUi::CommsModel
       
  1451 // -----------------------------------------------------------------------------
       
  1452 //
       
  1453 MCommsModel& CBrowserAppUi::CommsModel() const
       
  1454     {
       
  1455     __ASSERT_DEBUG( iCommsModel,
       
  1456         Util::Panic( Util::EUninitializedData ) );
       
  1457     return *iCommsModel;
       
  1458     }
       
  1459 
       
  1460 // -----------------------------------------------------------------------------
       
  1461 // CBrowserAppUi::Preferences
       
  1462 // -----------------------------------------------------------------------------
       
  1463 //
       
  1464 MPreferences& CBrowserAppUi::Preferences() const
       
  1465     {
       
  1466     __ASSERT_DEBUG( iPreferences,
       
  1467         Util::Panic( Util::EUninitializedData ) );
       
  1468     return *iPreferences;
       
  1469     }
       
  1470 
       
  1471 // -----------------------------------------------------------------------------
       
  1472 // CBrowserAppUi::Connection
       
  1473 // -----------------------------------------------------------------------------
       
  1474 //
       
  1475 MConnection& CBrowserAppUi::Connection() const
       
  1476     {
       
  1477     __ASSERT_DEBUG( iConnection,
       
  1478         Util::Panic( Util::EUninitializedData ) );
       
  1479     return *iConnection;
       
  1480     }
       
  1481 
       
  1482 // -----------------------------------------------------------------------------
       
  1483 // CBrowserAppUi::BrCtlInterface
       
  1484 // -----------------------------------------------------------------------------
       
  1485 CBrCtlInterface& CBrowserAppUi::BrCtlInterface() const
       
  1486     {
       
  1487     CBrowserWindow *window = iWindowManager->CurrentWindow();
       
  1488     __ASSERT_DEBUG( window, Util::Panic( Util::EUninitializedData ) );
       
  1489     return window->BrCtlInterface();
       
  1490     }
       
  1491 
       
  1492 // -----------------------------------------------------------------------------
       
  1493 // CBrowserAppUi::LoadObserver
       
  1494 // -----------------------------------------------------------------------------
       
  1495 //
       
  1496 CBrowserLoadObserver& CBrowserAppUi::LoadObserver() const
       
  1497     {
       
  1498     CBrowserWindow *window = iWindowManager->CurrentWindow();
       
  1499     __ASSERT_DEBUG( window, Util::Panic( Util::EUninitializedData ) );
       
  1500     return window->LoadObserver();
       
  1501     }
       
  1502 
       
  1503 // -----------------------------------------------------------------------------
       
  1504 // CBrowserAppUi::SpecialLoadObserver
       
  1505 // -----------------------------------------------------------------------------
       
  1506 //
       
  1507 CBrowserSpecialLoadObserver& CBrowserAppUi::SpecialLoadObserver() const
       
  1508     {
       
  1509     CBrowserWindow *window = iWindowManager->CurrentWindow();
       
  1510     __ASSERT_DEBUG( window, Util::Panic( Util::EUninitializedData ) );
       
  1511     return window->SpecialLoadObserver();
       
  1512     }
       
  1513 
       
  1514 // -----------------------------------------------------------------------------
       
  1515 // CBrowserAppUi::DialogsProvider
       
  1516 // -----------------------------------------------------------------------------
       
  1517 //
       
  1518 CBrowserDialogsProvider& CBrowserAppUi::DialogsProvider() const
       
  1519 	{
       
  1520 	return *iDialogsProvider;
       
  1521 	}
       
  1522 
       
  1523 // -----------------------------------------------------------------------------
       
  1524 // CBrowserAppUi::PopupEngine
       
  1525 // -----------------------------------------------------------------------------
       
  1526 //
       
  1527 CBrowserPopupEngine& CBrowserAppUi::PopupEngine() const
       
  1528     {
       
  1529     return *iPopupEngine;
       
  1530     }
       
  1531 
       
  1532 // -----------------------------------------------------------------------------
       
  1533 // CBrowserAppUi::WindowMgr()
       
  1534 // -----------------------------------------------------------------------------
       
  1535 //
       
  1536 CBrowserWindowManager& CBrowserAppUi::WindowMgr() const
       
  1537     {
       
  1538     return *iWindowManager;
       
  1539     }
       
  1540 
       
  1541 // -----------------------------------------------------------------------------
       
  1542 // CBrowserAppUi::IsCancelFetchAllowed
       
  1543 // -----------------------------------------------------------------------------
       
  1544 //
       
  1545 TBool CBrowserAppUi::IsCancelFetchAllowed() const
       
  1546     {
       
  1547     return ETrue;
       
  1548     }
       
  1549 
       
  1550 // -----------------------------------------------------------------------------
       
  1551 // CBrowserAppUi::UpdateCbaL()
       
  1552 // -----------------------------------------------------------------------------
       
  1553 //
       
  1554 void CBrowserAppUi::UpdateCbaL()
       
  1555     {
       
  1556     if( ActiveView() )
       
  1557         {
       
  1558         ActiveView()->UpdateCbaL();
       
  1559         }
       
  1560     }
       
  1561 
       
  1562 void CBrowserAppUi::LogAccessToRecentUrlL( CBrCtlInterface& aBrCtlInterface )
       
  1563     {
       
  1564     if ((ADAPTIVEBOOKMARKS)&&(!(Preferences().AdaptiveBookmarks()==EWmlSettingsAdaptiveBookmarksOff )))
       
  1565         {
       
  1566         HBufC* url = aBrCtlInterface.PageInfoLC( TBrCtlDefs::EPageInfoUrl );
       
  1567         HBufC* name = aBrCtlInterface.PageInfoLC( TBrCtlDefs::EPageInfoTitle );
       
  1568         if( url && url->Length() )
       
  1569             {
       
  1570             // If url is same as the one in the store delete it because the url will be rewritten 
       
  1571             // along with the name 
       
  1572             iRecentUrlStore->DeleteData(*url);
       
  1573             
       
  1574             TInt index;
       
  1575             index = url->Des().LocateReverse(KSlash);
       
  1576             // If the only difference between the url in the store and the one we are writing is a "/" 
       
  1577             // at the end of the url, delete the one in the store because it will be rewritten along 
       
  1578             // with the name
       
  1579             if (index == url->Length()-1)
       
  1580             	{
       
  1581 	            HBufC* urlwoslash = HBufC::NewLC( url->Length() );
       
  1582 				urlwoslash->Des().Copy( *url );
       
  1583 				urlwoslash->Des().Delete(url->Length() -1, 2);         
       
  1584 	            
       
  1585 	            iRecentUrlStore->DeleteData(*urlwoslash);
       
  1586 
       
  1587 	            CleanupStack::PopAndDestroy(); //urlwoslash            	
       
  1588             	}
       
  1589                         
       
  1590             if (name && name->Length())
       
  1591             	{
       
  1592             	iRecentUrlStore->SaveData(*url,*name);
       
  1593             	}
       
  1594             else
       
  1595             	{
       
  1596             	if (url->Length() > KFavouritesMaxName)
       
  1597                 	{
       
  1598                 	// name will be the url but it needs to be compressed to fit max name length
       
  1599                 	HBufC* cname = HBufC::NewLC(KFavouritesMaxName);
       
  1600                 	TInt edgeStringLen = ((KFavouritesMaxName / 2) - 3);
       
  1601                 	TPtrC cnameRight( url->Right( edgeStringLen ) );
       
  1602                 	TPtrC cnameLeft( url->Left( edgeStringLen ));
       
  1603                 	TPtr cnameDes = cname->Des();
       
  1604 
       
  1605                   	cnameDes.Append( cnameLeft );
       
  1606                    	cnameDes.AppendFill( TChar(KDot),5 );   // '.....'
       
  1607                    	cnameDes.Append( cnameRight );
       
  1608                 	iRecentUrlStore->SaveData(*url,*cname);
       
  1609                     CleanupStack::PopAndDestroy();//cname
       
  1610                 	}
       
  1611                 else
       
  1612             	    {
       
  1613             	    iRecentUrlStore->SaveData(*url,*url);
       
  1614             	    }
       
  1615             	}
       
  1616             }
       
  1617         CleanupStack().PopAndDestroy(2); // url, name
       
  1618         }
       
  1619     }
       
  1620 
       
  1621 void CBrowserAppUi::LogRequestedPageToRecentUrlL( const TDesC& aUrl )
       
  1622     {
       
  1623     if ((ADAPTIVEBOOKMARKS)&&(!(Preferences().AdaptiveBookmarks()==EWmlSettingsAdaptiveBookmarksOff )))
       
  1624         {
       
  1625         HBufC *url = HBufC::NewLC( aUrl.Length() );
       
  1626 		url->Des().Copy( aUrl );
       
  1627 
       
  1628         if( url && url->Length() )
       
  1629             {
       
  1630            	if (url->Length() > KFavouritesMaxName)
       
  1631             	{
       
  1632             	// name will be the url but it needs to be compressed to fit max name length
       
  1633             	HBufC* cname = HBufC::NewLC(KFavouritesMaxName);
       
  1634             	TInt edgeStringLen = ((KFavouritesMaxName / 2) - 3);
       
  1635             	TPtrC cnameRight( url->Right( edgeStringLen ) );
       
  1636             	TPtrC cnameLeft( url->Left( edgeStringLen ));
       
  1637             	TPtr cnameDes = cname->Des();
       
  1638 
       
  1639               	cnameDes.Append( cnameLeft );
       
  1640                	cnameDes.AppendFill( TChar(KDot),5 );   // '.....'
       
  1641                	cnameDes.Append( cnameRight );
       
  1642             	iRecentUrlStore->SaveData(*url,*cname);
       
  1643                 CleanupStack::PopAndDestroy();//cname
       
  1644             	}
       
  1645             else
       
  1646         	    {
       
  1647         	    iRecentUrlStore->SaveData(*url,*url);
       
  1648         	    }
       
  1649             }
       
  1650         CleanupStack().PopAndDestroy(); // url
       
  1651         }
       
  1652     }
       
  1653 
       
  1654 // -----------------------------------------------------------------------------
       
  1655 // CBrowserAppUi::SwitchWindowL()
       
  1656 // -----------------------------------------------------------------------------
       
  1657 //
       
  1658 void CBrowserAppUi::SwitchWindowL()
       
  1659     {
       
  1660 LOG_ENTERFN("CBrowserAppUi::SwitchWindowL");
       
  1661     CArrayFixFlat<CWindowInfo*>* windowBuf = iWindowManager->GetWindowInfoL( this );
       
  1662     CleanupStack::PushL( windowBuf );
       
  1663 
       
  1664     // Open 'Switch Window' selection dialog
       
  1665     HBufC* title = StringLoader::LoadLC( R_BROWSER_SWITCH_WINDOW_HEADER );
       
  1666 
       
  1667     CArrayFixFlat<TBrCtlSelectOptionData>* optDataArray = new ( ELeave )
       
  1668         CArrayFixFlat<TBrCtlSelectOptionData>( KGranularityMedium );
       
  1669     CleanupStack::PushL( optDataArray );
       
  1670 
       
  1671     TInt i( 0 );
       
  1672     TInt numWindows = windowBuf->Count();
       
  1673 
       
  1674 LOG_WRITE_FORMAT("Window's count: %d", numWindows );
       
  1675     for ( i = 0; i < numWindows; ++i )
       
  1676         {
       
  1677         TBrCtlSelectOptionData optData( *((*windowBuf)[i]->iWindowText),
       
  1678                                         (*windowBuf)[i]->iCurrent,
       
  1679                                         EFalse,
       
  1680                                         EFalse );
       
  1681         optDataArray->AppendL( optData );
       
  1682         }
       
  1683 
       
  1684     TBool ret = DialogsProvider().DialogSelectOptionL( *title,
       
  1685                                                         ESelectTypeSingle,
       
  1686                                                         *optDataArray );
       
  1687     if ( ret )
       
  1688         {
       
  1689         for( i = 0; i < numWindows; ++i)
       
  1690             {
       
  1691             if( (*optDataArray)[i].IsSelected() )
       
  1692                 {
       
  1693                 LOG_WRITE_FORMAT("Selected window: %d", (*windowBuf)[i]->iWindowId );
       
  1694                 iWindowManager->SwitchWindowL( (*windowBuf)[i]->iWindowId );
       
  1695                 break;
       
  1696                 }
       
  1697             }
       
  1698         }
       
  1699     CleanupStack::PopAndDestroy( 3 );           // optDataArray, title, windowBuf
       
  1700     }
       
  1701 
       
  1702 // -----------------------------------------------------------------------------
       
  1703 // CBrowserAppUi::SetCalledFromAnotherApp
       
  1704 // -----------------------------------------------------------------------------
       
  1705 //
       
  1706 void CBrowserAppUi::SetCalledFromAnotherApp( TBool aValue )
       
  1707     {
       
  1708     iCalledFromAnotherApp = aValue;
       
  1709     }
       
  1710 
       
  1711 // -----------------------------------------------------------------------------
       
  1712 // CBrowserAppUi::CalledFromAnotherApp
       
  1713 // -----------------------------------------------------------------------------
       
  1714 //
       
  1715 TBool CBrowserAppUi::CalledFromAnotherApp()
       
  1716     {
       
  1717     return iCalledFromAnotherApp;
       
  1718     }
       
  1719     
       
  1720 // -----------------------------------------------------------------------------
       
  1721 // CBrowserAppUi::NoHomePageToBeLaunchedL
       
  1722 // -----------------------------------------------------------------------------
       
  1723 //
       
  1724 TBool CBrowserAppUi::NoHomePageToBeLaunchedL()
       
  1725     {
       
  1726     LOG_ENTERFN("CBrowserAppUi::NoHomePageToBeLaunchedL");
       
  1727     TWmlSettingsHomePage pgtype = iPreferences->HomePageType();
       
  1728     TBool alwaysAskCase = (( Preferences().AccessPointSelectionMode() == EAlwaysAsk ) &&
       
  1729                            ( EWmlSettingsHomePageAccessPoint == pgtype ));
       
  1730     BROWSER_LOG( ( _L( "pgtype: %d, alwaysAsk: %d" ), pgtype, alwaysAskCase ) );
       
  1731 
       
  1732     if( ( pgtype == EWmlSettingsHomePageBookmarks ) || alwaysAskCase )
       
  1733         {   // Can't load home page since set to Bookmarks or (AlwaysAsk AP and homepage set to AP homepage)
       
  1734         return ETrue;
       
  1735         }
       
  1736     else
       
  1737         {
       
  1738         // now check for other cases where homepage string might be defined and will be used    
       
  1739         HBufC* buf = HBufC::NewLC( KMaxHomePgUrlLength );  // cleanupstack
       
  1740         TPtr ptr( buf->Des() );
       
  1741         TInt pgFound = Preferences().HomePageUrlL( ptr );
       
  1742         CleanupStack::PopAndDestroy( buf );
       
  1743         if (pgFound != KErrNone)
       
  1744             {   // no homepage string found
       
  1745             return ETrue;
       
  1746             }
       
  1747         else
       
  1748             {   // homepage string was found 
       
  1749             return EFalse;
       
  1750             }
       
  1751         }        
       
  1752     }
       
  1753 
       
  1754 // CBrowserAppUi::ProcessCommandParametersL()
       
  1755 // -----------------------------------------------------------------------------
       
  1756 //
       
  1757 TBool CBrowserAppUi::ProcessCommandParametersL( TApaCommand aCommand,
       
  1758                                                TFileName& /*aDocumentName*/ ,
       
  1759                                                const TDesC8& /*aTail*/ )
       
  1760     {
       
  1761     LOG_ENTERFN("CBrowserAppUi::ProcessCommandParametersL");
       
  1762     LOG_WRITE_FORMAT(" aCommand: %d", aCommand);
       
  1763 
       
  1764     // The browser is in embedded mode and it is not initialized yet
       
  1765     if ( !StartedUp() )
       
  1766     	{
       
  1767     	return EFalse;
       
  1768     	}
       
  1769 
       
  1770     if ( aCommand == EApaCommandOpen )
       
  1771         {
       
  1772 		//Startup parameters are given to browser at CBrowserAppDocument::OpenFileL().
       
  1773 		//- a part of shell starting (ConstructAppFromCommandLineL calls OpenFileL)
       
  1774         }
       
  1775 
       
  1776     else if ( aCommand == EApaCommandRun )
       
  1777         {
       
  1778 
       
  1779    	    if ( LastActiveViewId() == KUidBrowserNullViewId )
       
  1780 	        {
       
  1781 	        if (NoHomePageToBeLaunchedL())
       
  1782 	            {
       
  1783 	            // No homepage to be launched so start browser in bookmarks view
       
  1784     	        SetLastActiveViewId(KUidBrowserBookmarksViewId);
       
  1785 	            }
       
  1786     	    else
       
  1787     	        {
       
  1788     	        // There's a homepage to be launched so start in content view
       
  1789     	        SetLastActiveViewId(KUidBrowserContentViewId);  
       
  1790     	          
       
  1791                	//wait for contentview to initialize itself
       
  1792         	    WaitCVInit();
       
  1793 
       
  1794                 TInt error( KErrNone );
       
  1795                 TRAP( error, FetchHomePageL() );
       
  1796                 if( error != KErrNone )
       
  1797                     {
       
  1798                     CloseContentViewL();
       
  1799                     }
       
  1800                 }
       
  1801             ActivateLocalViewL( LastActiveViewId() );
       
  1802         	}
       
  1803 
       
  1804         }
       
  1805     else if ( aCommand == EApaCommandViewActivate )
       
  1806     // Get when activated from soft notification (Downloads List).
       
  1807     // Must behave as in case of EApaCommandOpen, but no OpenFileL() is called.
       
  1808         {
       
  1809         ParseAndProcessParametersL( KNullDesC8 );
       
  1810         }
       
  1811     return EFalse;
       
  1812     }
       
  1813 
       
  1814 // -----------------------------------------------------------------------------
       
  1815 // CBrowserAppUi::Static()
       
  1816 // -----------------------------------------------------------------------------
       
  1817 //
       
  1818 CBrowserAppUi* CBrowserAppUi::Static()
       
  1819     {
       
  1820     return REINTERPRET_CAST( CBrowserAppUi*, CEikonEnv::Static()->EikAppUi() );
       
  1821     }
       
  1822 
       
  1823 // -----------------------------------------------------------------------------
       
  1824 // CBrowserAppUi::ParseAndProcessParametersL
       
  1825 // -----------------------------------------------------------------------------
       
  1826 //
       
  1827 void CBrowserAppUi::ParseAndProcessParametersL( const TDesC8& aDocumentName, TBool aDoFetch )
       
  1828     {
       
  1829     LOG_ENTERFN("CBrowserAppUi::ParseAndProcessParametersL");
       
  1830     TInt err = KErrNone;
       
  1831 
       
  1832     TUid ViewToActivate = { 0 };
       
  1833 
       
  1834     HBufC8* params = NULL;
       
  1835     TLex8 parameter(aDocumentName);
       
  1836 
       
  1837     // Here we check if the url contains control characters.
       
  1838     TBool urlError( EFalse );  // If there is a Control caracter in the url.
       
  1839     parameter.Mark(); // Save the start position in the string.
       
  1840     while ( !parameter.Eos() && !urlError )
       
  1841         {
       
  1842         if ( parameter.Get().IsControl() )
       
  1843             {
       
  1844             urlError = ETrue;
       
  1845             }
       
  1846         }
       
  1847     parameter.UnGetToMark(); // Now go back to the beginning of the string.
       
  1848 
       
  1849     //Check for parameter validity
       
  1850     if(	!parameter.Peek().IsDigit() || urlError )    //First char of aDocumentName is NOT a digit
       
  1851         {
       
  1852         if( ( aDocumentName.Locate( ':' ) > 0) && (!urlError) )    //There is a ":" character in aDocumentName (->probably a valid url)
       
  1853             {
       
  1854             //Add "4" + <space> before the given parameter to make the parameter legal for url launch
       
  1855             _LIT8(KUrlId, "4 ");
       
  1856             params = HBufC8::NewL(aDocumentName.Length() + 2 + 1);
       
  1857             params->Des().Copy( KUrlId );
       
  1858             params->Des().Append(aDocumentName);
       
  1859             params->Des().ZeroTerminate();
       
  1860             ViewToActivate = KUidBrowserContentViewId;
       
  1861             }
       
  1862         else
       
  1863             {
       
  1864             //Activate bookmarks view if parameters are invalid and browser is not embedded.
       
  1865             // In embedded mode bookmarks are not shown, so if there is an
       
  1866             // error in the url, we make the browser to pop up a
       
  1867             // "Page not found" note, by defining a not existing url.
       
  1868             if ( IsEmbeddedModeOn() )
       
  1869                 {
       
  1870                 params = HBufC8::NewL( 10 );
       
  1871                 params->Des().Copy(_L8("4 http://") );
       
  1872                 }
       
  1873             else
       
  1874                 {
       
  1875                 params = HBufC8::NewL(aDocumentName.Length() + 1 );
       
  1876                 params->Des().Copy(aDocumentName);
       
  1877                 }
       
  1878             params->Des().ZeroTerminate();
       
  1879             ViewToActivate = KUidBrowserBookmarksViewId;
       
  1880             }
       
  1881         }
       
  1882     else
       
  1883         {
       
  1884         params = HBufC8::NewL(aDocumentName.Length() + 1);
       
  1885         params->Des().Copy(aDocumentName);
       
  1886         params->Des().ZeroTerminate();
       
  1887         ViewToActivate = KUidBrowserContentViewId;
       
  1888         }
       
  1889     CleanupStack::PushL( params );
       
  1890 
       
  1891     //Set view to activate if no view yet activated
       
  1892     if ( LastActiveViewId() == KUidBrowserNullViewId )
       
  1893         {
       
  1894         SetLastActiveViewId(ViewToActivate);
       
  1895         }
       
  1896 
       
  1897     CBrowserCommandLineParser8* command = CBrowserCommandLineParser8::NewL( *params );
       
  1898     CleanupStack::PopAndDestroy( params );
       
  1899     CleanupStack::PushL( command );
       
  1900 
       
  1901 	//wait a while, contentview initializing itself
       
  1902     WaitCVInit();
       
  1903     switch ( command->Count() )
       
  1904         {
       
  1905         case 0:
       
  1906             {
       
  1907             SetViewToBeActivatedIfNeededL( LastActiveViewId() );
       
  1908             break;
       
  1909             }
       
  1910         case 1:
       
  1911             {
       
  1912             if ( !aDocumentName.Compare( KLongZeroIdString ) )
       
  1913                 {
       
  1914                 // Long 0 is pressed and Browser is started up for the first time...
       
  1915                 // if no AP or SNAP is defined, define it
       
  1916                 TUint32 defaultAp = iPreferences->DefaultAccessPoint();
       
  1917                 TUint32 defaultSnap =  iPreferences->DefaultSnapId();
       
  1918                 // AP or SNAP is not defined
       
  1919                 if( (defaultAp == KWmlNoDefaultAccessPoint && iPreferences->AccessPointSelectionMode() == EConnectionMethod) || 
       
  1920                     (defaultSnap == KWmlNoDefaultSnapId && iPreferences->AccessPointSelectionMode() == EDestination) )
       
  1921                     {
       
  1922                     StartPreferencesViewL( EShowAlwaysAsk | EShowDestinations | EShowConnectionMethods );
       
  1923                     }
       
  1924                 // If there is a homepage url then try to fetch it
       
  1925                 if ( !NoHomePageToBeLaunchedL() )
       
  1926                     {
       
  1927                     iLongZeroPressed = ETrue;
       
  1928                     FetchHomePageL();
       
  1929                     }
       
  1930                 else  
       
  1931                     {
       
  1932                     ContentView()->SetFullScreenOffL();
       
  1933                     if ( !IsEmbeddedModeOn() )
       
  1934                         {
       
  1935                         SetLastActiveViewId( KUidBrowserBookmarksViewId );
       
  1936                         }
       
  1937                     }
       
  1938                 }
       
  1939             SetViewToBeActivatedIfNeededL( LastActiveViewId() );
       
  1940             break;
       
  1941             }
       
  1942         case 2:
       
  1943         case 3:
       
  1944             {
       
  1945             // UID and wml adress and optional access point UID
       
  1946 
       
  1947             TUint typeId;
       
  1948             TInt dataId;
       
  1949             TLex8 param0( command->Param( 0 ) );
       
  1950             TLex8 param1( command->Param( 1 ) );
       
  1951             err = param0.Val( typeId );
       
  1952             if ( !err )
       
  1953                 {
       
  1954                 BROWSER_LOG( ( _L( " typeId: %d" ), typeId ) );
       
  1955 
       
  1956                 if ( typeId == KUrlId )
       
  1957                     {  // FIX THIS!
       
  1958                     TUriParser8 uri8;
       
  1959                     err = uri8.Parse(command->Param(1));      // what if parsing fails?
       
  1960                     User::LeaveIfError(err);
       
  1961                     // Url decoding section was removed from here.
       
  1962                     HBufC* url = HBufC::NewL(command->Param(1).Length()+1);
       
  1963                     url->Des().Copy( command->Param(1) );
       
  1964                     CleanupStack::PushL(url);
       
  1965                     BROWSER_LOG( ( _L( " url: %S" ), url ) );
       
  1966 
       
  1967                     TFavouritesWapAp accessPoint;   // Initially "default".
       
  1968                     BROWSER_LOG( ( _L( " Count: %d" ), command->Count() ) );
       
  1969                     if ( command->Count() == 3 )
       
  1970                         {
       
  1971                         // URL Typeid, url, ap
       
  1972                         TUint ap;
       
  1973                         TLex8 param2( command->Param( 2 ) );
       
  1974                         err = param2.Val( ap );
       
  1975                         if ( !err )
       
  1976                             {
       
  1977                             BROWSER_LOG( ( _L( " ap: %d" ), ap ) );
       
  1978                             if (iSuppressAlwaysAsk)
       
  1979                                 {
       
  1980                                 // Always ask was temporarily disabled, enable it again
       
  1981                                 iPreferences->SetAccessPointSelectionModeL(EAlwaysAsk);
       
  1982                                 
       
  1983                                 iSuppressAlwaysAsk = EFalse;
       
  1984                                 }
       
  1985 
       
  1986                             // Note: OTA Provisioning application requires the 
       
  1987                             // KBrowserAccessPointSelectionMode key value to be
       
  1988                             // read directly from cenrep, rather than use the
       
  1989                             // cached cenrep value taken at browser initialization 
       
  1990                             // time. 
       
  1991                             TInt selectionMode;
       
  1992 
       
  1993                             CRepository* repository = CRepository::NewLC( KCRUidBrowser );
       
  1994                             User::LeaveIfError( repository->Get( KBrowserAccessPointSelectionMode, selectionMode ) );
       
  1995                             CleanupStack::PopAndDestroy( repository );
       
  1996 
       
  1997                             // If selectionMode cenrep value is always ask, then 
       
  1998                             // temporarily change selection mode
       
  1999                             if ( EBrowserCenRepApSelModeAlwaysAsk == selectionMode )
       
  2000                                 {
       
  2001                                 iSuppressAlwaysAsk = ETrue;
       
  2002                                 iPreferences->SetAccessPointSelectionModeL(EConnectionMethod);
       
  2003                                 }
       
  2004                             accessPoint.SetApId( ap );
       
  2005                             SetCalledFromAnotherApp( ETrue );
       
  2006                             CBrowserLoadObserver::TBrowserLoadUrlType urlType =
       
  2007                                 IsEmbeddedModeOn() ?
       
  2008                                     CBrowserLoadObserver::ELoadUrlTypeEmbeddedBrowserWithUrl :
       
  2009                                     CBrowserLoadObserver::ELoadUrlTypeOther;
       
  2010                             if( IsPageLoaded() &&
       
  2011                             	!(WindowMgr().CurrentWindow()->HasWMLContent(EFalse)) &&
       
  2012             		            Preferences().UiLocalFeatureSupported( KBrowserMultipleWindows ) &&
       
  2013             	                !Preferences().UiLocalFeatureSupported( KBrowserMinimalMultipleWindows ))
       
  2014                                 {
       
  2015                                 // Cancel history view, mini map, toolbar or any other active control on the current window 
       
  2016                                 BrCtlInterface().HandleCommandL( TBrCtlDefs::ECommandCancel + TBrCtlDefs::ECommandIdBase );
       
  2017                                 // there is already a window, so create a new one
       
  2018                                 CBrowserWindow *win = WindowMgr().CreateWindowL( 0, &KNullDesC );
       
  2019                                 if (win != NULL)
       
  2020                                     {
       
  2021                                         
       
  2022                                     CleanupStack::PushL( win );
       
  2023                                     WindowMgr().SwitchWindowL( win->WindowId() );
       
  2024                                     TRAP( err, FetchL(  *url,
       
  2025                                                                 KNullDesC,
       
  2026                                                                 KNullDesC,
       
  2027                                                                 accessPoint,
       
  2028                                                                 urlType ) );
       
  2029                                     CleanupStack::Pop();  // win
       
  2030                                     SetLastActiveViewId( KUidBrowserContentViewId );
       
  2031                                     }
       
  2032                                 }                          
       
  2033                             else
       
  2034                                 {
       
  2035                                 // Cancel history view, mini map, toolbar or any other active control on the current window 
       
  2036                                 BrCtlInterface().HandleCommandL( TBrCtlDefs::ECommandCancel + TBrCtlDefs::ECommandIdBase );
       
  2037                                 TRAP( err, FetchL(  *url,
       
  2038                                                             KNullDesC,
       
  2039                                                             KNullDesC,
       
  2040                                                             accessPoint,
       
  2041                                                             urlType ) );                                
       
  2042                                 SetLastActiveViewId( KUidBrowserContentViewId );                                
       
  2043                                 }                        
       
  2044                             }
       
  2045                         }
       
  2046                     else
       
  2047                         {
       
  2048                         // URL Typeid, url
       
  2049                         SetCalledFromAnotherApp( ETrue );
       
  2050 
       
  2051                         if ( aDoFetch )
       
  2052                             {
       
  2053                             CBrowserLoadObserver::TBrowserLoadUrlType urlType =
       
  2054                                 IsEmbeddedModeOn() ?
       
  2055                                     CBrowserLoadObserver::ELoadUrlTypeEmbeddedBrowserWithUrl :
       
  2056                                     CBrowserLoadObserver::ELoadUrlTypeOther;
       
  2057                             if( IsPageLoaded() &&
       
  2058                             	!(WindowMgr().CurrentWindow()->HasWMLContent(EFalse)) &&                            
       
  2059                         		Preferences().UiLocalFeatureSupported( KBrowserMultipleWindows ) &&
       
  2060                             	!Preferences().UiLocalFeatureSupported( KBrowserMinimalMultipleWindows ))
       
  2061                                 {
       
  2062                                 // Cancel history view, mini map, toolbar or any other active control on the current window 
       
  2063                                 BrCtlInterface().HandleCommandL( TBrCtlDefs::ECommandCancel + TBrCtlDefs::ECommandIdBase );
       
  2064                                 // there is already a window, so create a new one
       
  2065                                 CBrowserWindow *win = WindowMgr().CreateWindowL( 0, &KNullDesC );
       
  2066                                 if (win != NULL)
       
  2067                                     {
       
  2068                                         
       
  2069                                     CleanupStack::PushL( win );
       
  2070                                     WindowMgr().SwitchWindowL( win->WindowId() );
       
  2071                                     TRAP( err, FetchL(  *url,
       
  2072                                                                 KNullDesC,
       
  2073                                                                 KNullDesC,
       
  2074                                                                 accessPoint,
       
  2075                                                                 urlType ) );
       
  2076                                     CleanupStack::Pop();  // win
       
  2077                                     }
       
  2078                             }
       
  2079                             else
       
  2080                                 {
       
  2081                                 // Cancel history view, mini map, toolbar or any other active control on the current window 
       
  2082                                 BrCtlInterface().HandleCommandL( TBrCtlDefs::ECommandCancel + TBrCtlDefs::ECommandIdBase );
       
  2083                                 TRAP( err, FetchL(  *url,
       
  2084                                                             KNullDesC,
       
  2085                                                             KNullDesC,
       
  2086                                                             accessPoint,
       
  2087                                                             urlType ) );
       
  2088                                 }
       
  2089                             }          
       
  2090                     if (err==KErrNone)
       
  2091                         {
       
  2092                         SetLastActiveViewId(ViewToActivate);
       
  2093                         }
       
  2094                         }
       
  2095                     CleanupStack::PopAndDestroy();  // url
       
  2096                     }
       
  2097                 else if( typeId == KLaunchFeeds )
       
  2098                     {
       
  2099                     // Special facility to launch non-embedded into the feeds view
       
  2100                     if( !iBrowserAlreadyRunning )
       
  2101                     	{
       
  2102                     	SetOverriddenLaunchContextId(EBrowserContextIdFeeds);
       
  2103                     	SetLastActiveViewId( KUidBrowserFeedsFolderViewId );                    	
       
  2104                     	}	
       
  2105                     LaunchIntoFeedsL();          	
       
  2106                     }         
       
  2107                 else
       
  2108                     {
       
  2109                     err = param1.Val( dataId );
       
  2110                     if ( !err )
       
  2111                         {
       
  2112                         switch ( typeId )
       
  2113                             {
       
  2114                             case KBookmarkId:
       
  2115                                 {
       
  2116                                 // Bookmark typeid, uid
       
  2117                                 SetCalledFromAnotherApp( ETrue );
       
  2118 								
       
  2119 	                            if( IsPageLoaded() &&
       
  2120                                	!(WindowMgr().CurrentWindow()->HasWMLContent(EFalse)) &&
       
  2121                         		Preferences().UiLocalFeatureSupported( KBrowserMultipleWindows ) &&
       
  2122                             	!Preferences().UiLocalFeatureSupported( KBrowserMinimalMultipleWindows ))
       
  2123 	                                {
       
  2124 	   	                            // Cancel history view, mini map, toolbar or any other active control on the current window 
       
  2125 	                                BrCtlInterface().HandleCommandL( TBrCtlDefs::ECommandCancel + TBrCtlDefs::ECommandIdBase );
       
  2126 	                                // there is already a window, so create a new one
       
  2127 	                                CBrowserWindow *win = WindowMgr().CreateWindowL( 0, &KNullDesC );
       
  2128 	                                if (win != NULL)
       
  2129     	                                {
       
  2130     	                                CleanupStack::PushL( win );
       
  2131     	                                WindowMgr().SwitchWindowL( win->WindowId() );
       
  2132     	                            	TRAP( err, FetchBookmarkL( dataId ) );
       
  2133     	                                CleanupStack::Pop();  // win                                
       
  2134     	                                }
       
  2135 	                                }
       
  2136 	                            else
       
  2137 	                            	{
       
  2138     	                            // Cancel history view, mini map, toolbar or any other active control on the current window 
       
  2139 	                                BrCtlInterface().HandleCommandL( TBrCtlDefs::ECommandCancel + TBrCtlDefs::ECommandIdBase );
       
  2140 	                            	TRAP( err, FetchBookmarkL( dataId ) );
       
  2141 	                            	}    
       
  2142 
       
  2143                                 if ( err )
       
  2144                                     {
       
  2145                                     // Unable to fetch bookmark
       
  2146                                     TBrowserDialogs::InfoNoteL(
       
  2147                                         R_BROWSER_INFO_NOTE, R_WML_UNABLE_TO_FETCH_BOOKMARK );
       
  2148                                     }
       
  2149 	                            if (err==KErrNone)
       
  2150     			                    {
       
  2151                 			        SetLastActiveViewId(ViewToActivate);
       
  2152                         			}
       
  2153 
       
  2154                                 break;
       
  2155                                 }
       
  2156                             case KFolderId:
       
  2157                                 {
       
  2158                                 CloseContentViewL();
       
  2159                                 SetLastActiveViewId( KUidBrowserBookmarksViewId );
       
  2160                                 break;
       
  2161                                 }
       
  2162                             default:
       
  2163                                 {
       
  2164                                 // Typeid was not readable
       
  2165                                 // TBD: error message!
       
  2166                                 break;
       
  2167                                 }
       
  2168                             }
       
  2169                         }
       
  2170                     else
       
  2171                         {
       
  2172                         // Dataid was not readable
       
  2173                         User::Leave( err );
       
  2174                         }
       
  2175                     }
       
  2176                 }
       
  2177             else
       
  2178                 {
       
  2179                 // Sender Uid was not readable
       
  2180                 User::Leave( err );
       
  2181                 }
       
  2182             SetViewToBeActivatedIfNeededL( LastActiveViewId() );
       
  2183             break;
       
  2184             }
       
  2185 
       
  2186         default:
       
  2187             {
       
  2188             SendBrowserToBackground();
       
  2189             break;
       
  2190             }
       
  2191         }
       
  2192         CleanupStack::PopAndDestroy();  // command
       
  2193     }
       
  2194 
       
  2195 // -----------------------------------------------------------------------------
       
  2196 // CBrowserAppUi::WaitCVInit
       
  2197 // -----------------------------------------------------------------------------
       
  2198 //
       
  2199 void CBrowserAppUi::WaitCVInit()
       
  2200     {
       
  2201     if( iParametrizedLaunchInProgress == 0 )
       
  2202         {
       
  2203         iParametrizedLaunchInProgress = 1;
       
  2204         iIdle->Cancel();
       
  2205         iIdle->Start( TCallBack( StopDelay, this ) );
       
  2206         iWait.Start();
       
  2207         iParametrizedLaunchInProgress = 2;
       
  2208         }
       
  2209     }
       
  2210 
       
  2211 // -----------------------------------------------------------------------------
       
  2212 // CBrowserAppUi::ConnNeededStatusL
       
  2213 // -----------------------------------------------------------------------------
       
  2214 //
       
  2215 void CBrowserAppUi::ConnNeededStatusL( TInt aErr )
       
  2216     {
       
  2217     UpdateSoftKeys();
       
  2218     if (iSuppressAlwaysAsk)
       
  2219         {
       
  2220         // Always ask was temporarily disabled, after creating the network connection, enable it again
       
  2221         iPreferences->SetAccessPointSelectionModeL(EAlwaysAsk);
       
  2222         iSuppressAlwaysAsk = EFalse;
       
  2223         }
       
  2224     if ( aErr != KErrNone )
       
  2225         {
       
  2226         if( iCalledFromAnotherApp )
       
  2227             {
       
  2228             // This function call should be replaced by ExitBrowser(ETrue)
       
  2229             // so that the blank content view is not displayed.
       
  2230             // SendBrowserToBackground();
       
  2231             }
       
  2232         // if any error, return Cancel to Kimono.
       
  2233         return;
       
  2234         }
       
  2235 
       
  2236 
       
  2237 
       
  2238     if ( !iConnStageNotifier->IsActive() )
       
  2239         {
       
  2240         TName* connectionName = Connection().ConnectionNameL();
       
  2241         CleanupStack::PushL( connectionName );
       
  2242         iConnStageNotifier->StartNotificationL(
       
  2243             connectionName, KConnectionUninitialised, this);
       
  2244         CleanupStack::PopAndDestroy();  //connectionName
       
  2245         }
       
  2246     }
       
  2247 
       
  2248 
       
  2249 // -----------------------------------------------------------------------------
       
  2250 // CBrowserAppUi::SendBrowserToBackground
       
  2251 // -----------------------------------------------------------------------------
       
  2252 //
       
  2253 void CBrowserAppUi::SendBrowserToBackground()
       
  2254     {
       
  2255     TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
       
  2256 
       
  2257     // Browser might be embedded. 
       
  2258     TUid appUid;
       
  2259     if ( iEmbeddingApplicationUid != KNullUid )
       
  2260         {
       
  2261         appUid = iEmbeddingApplicationUid;
       
  2262         }
       
  2263     else 
       
  2264         {
       
  2265         appUid = KUidBrowserApplication;
       
  2266         }
       
  2267     TApaTask task = taskList.FindApp( appUid );
       
  2268     task.SendToBackground();
       
  2269     }
       
  2270 
       
  2271 
       
  2272 // -----------------------------------------------------------------------------
       
  2273 // CBrowserAppUi::CreateWindowInfoLC()
       
  2274 // -----------------------------------------------------------------------------
       
  2275 //
       
  2276 HBufC* CBrowserAppUi::CreateWindowInfoLC( const CBrowserWindow& aWindow )
       
  2277     {
       
  2278     HBufC* buf = aWindow.BrCtlInterface().PageInfoLC( TBrCtlDefs::EPageInfoTitle );
       
  2279     if( !buf || !buf->Length() )
       
  2280         {
       
  2281         CleanupStack::PopAndDestroy( buf );
       
  2282         buf = aWindow.BrCtlInterface().PageInfoLC( TBrCtlDefs::EPageInfoUrl );
       
  2283         if( !buf )
       
  2284             {
       
  2285 
       
  2286             CleanupStack::PopAndDestroy( buf );
       
  2287             buf = KNullDesC().AllocLC();
       
  2288             }
       
  2289         }
       
  2290     return buf;
       
  2291     }
       
  2292 
       
  2293 
       
  2294 // -----------------------------------------------------------------------------
       
  2295 // CBrowserAppUi::ConnectionStageAchievedL()
       
  2296 // -----------------------------------------------------------------------------
       
  2297 //
       
  2298 void CBrowserAppUi::ConnectionStageAchievedL()
       
  2299     {
       
  2300     // this function is called only when network is lost
       
  2301     // because we set notifier for KAgentUnconnected only
       
  2302     Display().StopProgressAnimationL();
       
  2303 	if ( Fetching() )
       
  2304 		{
       
  2305                  CancelFetch();
       
  2306 		}
       
  2307 
       
  2308     // SendDisconnectEventL();
       
  2309     // not needed as by that point HTTPSession was already shutdown by executing disconnect menu option
       
  2310     // will cause a crash when user tries to quickly reconnect right after disconnecting, as HTTP session
       
  2311     // is starting to initialize, while this call is trying to close it.
       
  2312     }
       
  2313 
       
  2314 
       
  2315 // -----------------------------------------------------------------------------
       
  2316 // CBrowserAppUi::UpdateSoftKeys
       
  2317 // -----------------------------------------------------------------------------
       
  2318 //
       
  2319 void CBrowserAppUi::UpdateSoftKeys()
       
  2320     {
       
  2321 	TRAP_IGNORE( UpdateCbaL() );
       
  2322     }
       
  2323 
       
  2324 // -----------------------------------------------------------------------------
       
  2325 // CBrowserAppUi::DeleteCookiesL
       
  2326 // -----------------------------------------------------------------------------
       
  2327 //
       
  2328 void CBrowserAppUi::DeleteCookiesL()
       
  2329     {
       
  2330     // stringPool is not needed to initialize
       
  2331     RStringPool stringPool;
       
  2332     RCookieManager cookieManager( stringPool );
       
  2333     TInt num(0);
       
  2334 
       
  2335     User::LeaveIfError( cookieManager.Connect() );
       
  2336     CleanupClosePushL( cookieManager );
       
  2337     User::LeaveIfError( cookieManager.ClearCookies( num ) );
       
  2338     CleanupStack::PopAndDestroy( &cookieManager );
       
  2339 
       
  2340     stringPool.Close();
       
  2341     }
       
  2342 
       
  2343 // -----------------------------------------------------------------------------
       
  2344 // CBrowserAppUi::LaunchHomePageL
       
  2345 // -----------------------------------------------------------------------------
       
  2346 //
       
  2347 void CBrowserAppUi::LaunchHomePageL()
       
  2348     {
       
  2349     LOG_ENTERFN( "CBrowserAppUi::LaunchHomePageL" );
       
  2350     TWmlSettingsHomePage pgtype = iPreferences->HomePageType();
       
  2351     TBool alwaysAskCase = (( Preferences().AccessPointSelectionMode() == EAlwaysAsk ) &&
       
  2352                            ( EWmlSettingsHomePageAccessPoint == pgtype ));
       
  2353     BROWSER_LOG( ( _L( "pgtype: %d, alwaysAsk: %d" ), pgtype, alwaysAskCase ) );
       
  2354 
       
  2355     if( ( pgtype == EWmlSettingsHomePageBookmarks ) || alwaysAskCase )
       
  2356         // Bookmarks is selected as HomePage
       
  2357         // has effect only for startup, otherwise 'Home' command is not shown
       
  2358         {
       
  2359         ContentView()->SetFullScreenOffL();
       
  2360         // view change will be done somewhere else
       
  2361         SetLastActiveViewId( KUidBrowserBookmarksViewId );
       
  2362         SetViewToBeActivatedIfNeededL( LastActiveViewId() );
       
  2363         return;
       
  2364         }
       
  2365 
       
  2366     HBufC* buf = HBufC::NewLC( KMaxHomePgUrlLength );  // cleanupstack
       
  2367     TPtr ptr( buf->Des() );
       
  2368     TInt pgFound( KErrNotFound );
       
  2369 
       
  2370     pgFound = Preferences().HomePageUrlL( ptr );
       
  2371     BROWSER_LOG( ( _L( "pgFound 1: %d" ), pgFound ) );
       
  2372 
       
  2373 
       
  2374     if( pgFound == KErrNone )     // Home page url found, fetch the url
       
  2375         {
       
  2376         SetLastActiveViewId( KUidBrowserContentViewId );
       
  2377         FetchL( ptr );
       
  2378         }
       
  2379     else  // Home page not found, or not defined, go to BookMarksView
       
  2380         {
       
  2381         TVwsViewId activeViewId;
       
  2382         if( ( GetActiveViewId( activeViewId ) != KErrNone ) ||
       
  2383             ( activeViewId.iViewUid == KUidBrowserContentViewId ) )
       
  2384             {
       
  2385             ContentView()->SetFullScreenOffL();
       
  2386             }
       
  2387         SetLastActiveViewId( KUidBrowserBookmarksViewId );
       
  2388         SetViewToBeActivatedIfNeededL( LastActiveViewId() );
       
  2389         }
       
  2390     CleanupStack::PopAndDestroy( buf );
       
  2391     }
       
  2392 
       
  2393 // -----------------------------------------------------------------------------
       
  2394 // CBrowserAppUi::ClearTheCacheL
       
  2395 // -----------------------------------------------------------------------------
       
  2396 //
       
  2397 void CBrowserAppUi::ClearTheCacheL(TBool afterQuery, TBool aShowDoneNote)
       
  2398     {
       
  2399     TUint32 totalBytesFlushed = BrCtlInterface().ClearCache();
       
  2400         if(afterQuery || totalBytesFlushed)
       
  2401     	{
       
  2402 
       
  2403     	HBufC* resultText = NULL;
       
  2404     	HBufC* tempText = NULL;
       
  2405     	TBuf<12> totalText;
       
  2406 
       
  2407     	totalText.Num ((TInt)totalBytesFlushed);
       
  2408 
       
  2409     	resultText = StringLoader::LoadLC( R_TEXT_WML_CACHE_EMPTIED_NOTE);
       
  2410     	//CleanupStack::PushL(resultText);
       
  2411     	tempText = HBufC::NewLC( resultText->Length() + totalText.Length() );
       
  2412     	//CleanupStack::PushL(tempText);
       
  2413 
       
  2414     	tempText->Des().AppendFormat( resultText->Des(), totalBytesFlushed );
       
  2415 
       
  2416 
       
  2417 
       
  2418     	if(aShowDoneNote)
       
  2419     	    {
       
  2420     	    TBrowserDialogs::InfoNoteL ( R_BROWSER_OK_NOTE, tempText->Des() );
       
  2421     	    }
       
  2422      	CleanupStack::PopAndDestroy(2); //resultText, tempText
       
  2423     	}
       
  2424     }
       
  2425 
       
  2426 // ---------------------------------------------------------
       
  2427 // CBrowserAppUi::ClearFormAndPasswdDataL
       
  2428 // ---------------------------------------------------------
       
  2429 //
       
  2430 void CBrowserAppUi::ClearFormAndPasswdDataL(TBool aShowPromptAndComplete)
       
  2431     {
       
  2432     if (aShowPromptAndComplete)
       
  2433         {
       
  2434         CAknQueryDialog* query = CAknQueryDialog::NewL();
       
  2435 	    if ( query->ExecuteLD( R_BROWSER_CLEARFORMPASSWDDATA_QUERY ) )
       
  2436             {
       
  2437             // call brctl to clear form and password data
       
  2438             BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandClearAutoFormFillData +
       
  2439     		       						     (TInt)TBrCtlDefs::ECommandIdBase );
       
  2440 
       
  2441             BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandClearAutoFormFillPasswordData +
       
  2442      		 								 (TInt)TBrCtlDefs::ECommandIdBase );
       
  2443 
       
  2444             TBrowserDialogs::InfoNoteL(
       
  2445                 R_BROWSER_OK_NOTE, R_QTN_BROWSER_NOTE_FORM_AND_PASSWD_DATA_CLEARED );
       
  2446             }
       
  2447 
       
  2448         }
       
  2449     else
       
  2450         {
       
  2451             // call brctl to clear form and password data
       
  2452             BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandClearAutoFormFillData +
       
  2453     		       						     (TInt)TBrCtlDefs::ECommandIdBase );
       
  2454 
       
  2455             BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandClearAutoFormFillPasswordData +
       
  2456      		 								 (TInt)TBrCtlDefs::ECommandIdBase );
       
  2457 
       
  2458         }
       
  2459     }
       
  2460 
       
  2461 
       
  2462 // ---------------------------------------------------------
       
  2463 // CBrowserAppUi::ClearHistoryWithPromptL
       
  2464 // ---------------------------------------------------------
       
  2465 //
       
  2466 void CBrowserAppUi::ClearHistoryWithPromptL()
       
  2467     {
       
  2468     CAknQueryDialog* query = CAknQueryDialog::NewL();
       
  2469 
       
  2470     if ( query->ExecuteLD( R_BROWSER_CLEARHISTORYDATA_QUERY ) )
       
  2471         {
       
  2472         ClearHistoryL();
       
  2473         TBrowserDialogs::InfoNoteL( R_BROWSER_OK_NOTE,
       
  2474                     R_QTN_BROWSER_NOTE_HISTORY_CLEARED );
       
  2475         }
       
  2476     }
       
  2477 
       
  2478 // ---------------------------------------------------------
       
  2479 // CBrowserAppUi::ClearHistoryL
       
  2480 // ---------------------------------------------------------
       
  2481 //
       
  2482 void CBrowserAppUi::ClearHistoryL()
       
  2483     {
       
  2484 	if (iWindowManager)
       
  2485         {
       
  2486         iWindowManager->SendCommandToAllWindowsL(
       
  2487         (TInt)TBrCtlDefs::ECommandClearHistory + (TInt)TBrCtlDefs::ECommandIdBase);
       
  2488         }
       
  2489     else
       
  2490         {
       
  2491         BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandClearHistory +
       
  2492                                          (TInt)TBrCtlDefs::ECommandIdBase );
       
  2493 
       
  2494         }
       
  2495 
       
  2496     if (!(Preferences().AdaptiveBookmarks()==EWmlSettingsAdaptiveBookmarksOff ))
       
  2497         {
       
  2498         // This call will ensure that the bookmarks are cleared when we are
       
  2499         // outside the bookmarksview since the next call doesn't do anything in
       
  2500         // that case due to the unset Container pointer.
       
  2501 		iRecentUrlStore->ClearData();
       
  2502 
       
  2503         // Below will serve for when we are called from BookmarksView to ensure
       
  2504         // thorough clearing and view refresh after clearing adapt bookmarks
       
  2505         iBookmarksView->HandleCommandL(EWmlCmdClearAdaptiveBookmarksNoPrompt);
       
  2506         }
       
  2507 
       
  2508     UpdateCbaL();
       
  2509 
       
  2510     }
       
  2511 
       
  2512 // ---------------------------------------------------------
       
  2513 // CBrowserAppUi::ClearAllPrivacyL
       
  2514 // ---------------------------------------------------------
       
  2515 //
       
  2516 void CBrowserAppUi::ClearAllPrivacyL()
       
  2517     {
       
  2518 
       
  2519     CAknQueryDialog* query = CAknQueryDialog::NewL();
       
  2520 	if ( query->ExecuteLD( R_BROWSER_CLEARPRIVACYDATA_QUERY ) )
       
  2521         {
       
  2522         ClearTheCacheL(EFalse, EFalse);     // false -> no prompt or info note after op
       
  2523         DeleteCookiesL();
       
  2524         ClearHistoryL();
       
  2525         ClearFormAndPasswdDataL(EFalse);    // no prompt or completed info note
       
  2526 
       
  2527         TBrowserDialogs::InfoNoteL(
       
  2528             R_BROWSER_OK_NOTE, R_QTN_BROWSER_NOTE_CLEAR_ALL_PRIVACY_DONE );
       
  2529         }
       
  2530     }
       
  2531 
       
  2532 
       
  2533 // -----------------------------------------------------------------------------
       
  2534 // CBrowserAppUi::DisconnectL
       
  2535 // -----------------------------------------------------------------------------
       
  2536 //
       
  2537 void CBrowserAppUi::DisconnectL()
       
  2538     {
       
  2539 //#pragma message("TODO: inform LoadObserver?")
       
  2540     SendDisconnectEventL();
       
  2541     Connection().Disconnect();
       
  2542 
       
  2543 #ifdef __RSS_FEEDS
       
  2544     iFeedsClientUtilities->DisconnectFeedsViewL();
       
  2545     //notify feeds engine to close the connection
       
  2546 	iFeedsClientUtilities->DisconnectManualUpdateConnectionL();
       
  2547 #endif
       
  2548     }
       
  2549 
       
  2550 
       
  2551 // -----------------------------------------------------------------------------
       
  2552 // CBrowserAppUi::BmOTABinSenderL()
       
  2553 // -----------------------------------------------------------------------------
       
  2554 //
       
  2555 MBmOTABinSender& CBrowserAppUi::BmOTABinSenderL()
       
  2556     {
       
  2557     if (!iSender)
       
  2558     	{
       
  2559 		iLateSendUi->Cancel();
       
  2560     	DoConstructSendUiL();
       
  2561     	}
       
  2562     return *iSender;
       
  2563     }
       
  2564 
       
  2565 
       
  2566 // -----------------------------------------------------------------------------
       
  2567 // CBrowserAppUi::ContentView()
       
  2568 // -----------------------------------------------------------------------------
       
  2569 //
       
  2570 CBrowserContentView* CBrowserAppUi::ContentView() const
       
  2571     {
       
  2572     return (CBrowserContentView*)View( KUidBrowserContentViewId );
       
  2573     }
       
  2574 
       
  2575 
       
  2576 // -----------------------------------------------------------------------------
       
  2577 // CBrowserAppUi::FetchL
       
  2578 // -----------------------------------------------------------------------------
       
  2579 //
       
  2580 void CBrowserAppUi::FetchL( const TDesC& aUrl, CBrowserLoadObserver::TBrowserLoadUrlType aUrlType )
       
  2581     {
       
  2582     TFavouritesWapAp ap;
       
  2583     ap.SetDefault();
       
  2584     FetchL( aUrl, KNullDesC, KNullDesC, ap, aUrlType );
       
  2585     }
       
  2586 
       
  2587 // TO DO: done by BaP
       
  2588 // -----------------------------------------------------------------------------
       
  2589 // CBrowserAppUi::CancelFetch
       
  2590 // -----------------------------------------------------------------------------
       
  2591 //
       
  2592 void CBrowserAppUi::CancelFetch( TBool aIsUserInitiated /*= EFalse*/ )
       
  2593     {
       
  2594     LoadObserver().DoEndLoad( aIsUserInitiated );
       
  2595     TRAP_IGNORE( BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandCancelFetch + (TInt)TBrCtlDefs::ECommandIdBase ) );
       
  2596     SetContentDisplayed(ETrue);
       
  2597     }
       
  2598 
       
  2599 
       
  2600 // ----------------------------------------------------------------------------------------
       
  2601 // CBrowserAppUi::HandleMessageL
       
  2602 //
       
  2603 // Changes the URL to another if WAP is running before Wap Url
       
  2604 // is started from Desk
       
  2605 // ----------------------------------------------------------------------------------------
       
  2606 //
       
  2607 MCoeMessageObserver::TMessageResponse CBrowserAppUi::HandleMessageL(
       
  2608 																	TUint32 aClientHandleOfTargetWindowGroup,
       
  2609 																	TUid aMessageUid,
       
  2610 																	const TDesC8& aMessageParameters )
       
  2611     {
       
  2612     iBrowserAlreadyRunning = ETrue;
       
  2613     TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
       
  2614     TUid wapUid = KUidBrowserApplication;
       
  2615     TApaTask task = taskList.FindApp( wapUid );
       
  2616     task.BringToForeground();
       
  2617     if ( aMessageParameters.Compare( KLongZeroIdString ) )
       
  2618         {
       
  2619         ParseAndProcessParametersL( aMessageParameters );
       
  2620         }
       
  2621     return CAknViewAppUi::HandleMessageL(
       
  2622 		aClientHandleOfTargetWindowGroup,
       
  2623         aMessageUid,
       
  2624 		aMessageParameters);
       
  2625     }
       
  2626 
       
  2627 // ----------------------------------------------------------------------------------
       
  2628 // CBrowserAppUi::UpdateNaviPaneL
       
  2629 // ----------------------------------------------------------------------------------
       
  2630 //
       
  2631 void CBrowserAppUi::UpdateNaviPaneL( TDesC& aStatusMsg )
       
  2632     {
       
  2633     ContentView()->UpdateNaviPaneL( aStatusMsg );
       
  2634     }
       
  2635 
       
  2636 // ----------------------------------------------------------------------------------
       
  2637 // CBrowserAppUi::StopDelay
       
  2638 // ----------------------------------------------------------------------------------
       
  2639 //
       
  2640 TInt CBrowserAppUi::StopDelay( TAny* aCBrowserAppUi )
       
  2641     {
       
  2642 	__ASSERT_DEBUG(aCBrowserAppUi, Util::Panic( Util::EUninitializedData ));
       
  2643 
       
  2644     ((CBrowserAppUi*)aCBrowserAppUi)->DoStopDelay();
       
  2645     return 0;
       
  2646     }
       
  2647 
       
  2648 
       
  2649 // ----------------------------------------------------------------------------------
       
  2650 // CBrowserAppUi::DoStopDelay
       
  2651 // ----------------------------------------------------------------------------------
       
  2652 //
       
  2653 void CBrowserAppUi::DoStopDelay()
       
  2654     {
       
  2655     iWait.AsyncStop();
       
  2656     }
       
  2657 
       
  2658 // ----------------------------------------------------------------------------------
       
  2659 // CBrowserAppUi::DelayedSendUiConstructL
       
  2660 // ----------------------------------------------------------------------------------
       
  2661 //
       
  2662 /*static*/ TInt CBrowserAppUi::DelayedSendUiConstructL( TAny* aCBrowserAppUi )
       
  2663 	{
       
  2664 	__ASSERT_DEBUG(aCBrowserAppUi, Util::Panic( Util::EUninitializedData ));
       
  2665 	TRAP_IGNORE(
       
  2666 				((CBrowserAppUi*)aCBrowserAppUi)->DoConstructSendUiL();
       
  2667 				);
       
  2668 	return KErrNone;
       
  2669 	}
       
  2670 
       
  2671 
       
  2672 // ----------------------------------------------------------------------------------
       
  2673 // CBrowserAppUi::DoConstructSendUiL
       
  2674 // ----------------------------------------------------------------------------------
       
  2675 //
       
  2676 void CBrowserAppUi::DoConstructSendUiL()
       
  2677 	{
       
  2678 	__ASSERT_DEBUG(!iSender, Util::Panic( Util::EUnExpected ));
       
  2679 	iSender = CWmlBrowserBmOTABinSender::NewL();
       
  2680 	}
       
  2681 
       
  2682 // -----------------------------------------------------------------------------------
       
  2683 // CBrowserAppUi::SetViewToReturnOnClose
       
  2684 // -----------------------------------------------------------------------------------
       
  2685 //
       
  2686 void CBrowserAppUi::SetViewToReturnOnClose( TUid const &aUid )
       
  2687     {
       
  2688     iViewToReturnOnClose.iUid = aUid.iUid;
       
  2689     }
       
  2690 
       
  2691 // -----------------------------------------------------------------------------------
       
  2692 // CBrowserAppUi::CloseContentViewL
       
  2693 // -----------------------------------------------------------------------------------
       
  2694 //
       
  2695 void CBrowserAppUi::CloseContentViewL()
       
  2696     {
       
  2697 LOG_ENTERFN("CBrowserAppUi::CloseContentViewL");
       
  2698 	CBrowserAppDocument* doc = STATIC_CAST(CBrowserAppDocument*, Document());
       
  2699 
       
  2700     // Close should Exit asynchronously if called from another application 
       
  2701     // & if not in feeds view
       
  2702 #ifdef __RSS_FEEDS
       
  2703 	if(CalledFromAnotherApp() && (!IsEmbeddedModeOn()) 
       
  2704     	&& (GetPreviousViewFromViewHistory() != KUidBrowserFeedsFolderViewId)
       
  2705     	&& (GetPreviousViewFromViewHistory() != KUidBrowserFeedsTopicViewId)
       
  2706     	&& (GetPreviousViewFromViewHistory() != KUidBrowserFeedsFeedViewId ))
       
  2707 	    {
       
  2708         SetExitInProgress( ETrue );
       
  2709         BROWSER_LOG( ( _L( " iBrowserAsyncExit->Start()" ) ) );
       
  2710         iBrowserAsyncExit->Start();
       
  2711 	    }
       
  2712 #else
       
  2713 	if(CalledFromAnotherApp() && !IsEmbeddedModeOn()) 
       
  2714 	    {
       
  2715         SetExitInProgress( ETrue );
       
  2716         BROWSER_LOG( ( _L( " iBrowserAsyncExit->Start()" ) ) );
       
  2717         iBrowserAsyncExit->Start();
       
  2718 	    }
       
  2719 #endif // __RSS_FEEDS
       
  2720    	    
       
  2721 	else
       
  2722 	    {	    
       
  2723 	if ( IsEmbeddedModeOn() &&
       
  2724         doc->GetFolderToOpen() == KFavouritesRootUid )
       
  2725 		{
       
  2726 		ExitBrowser(ETrue);
       
  2727 		}
       
  2728 	else
       
  2729 		{
       
  2730         if ( ContentView()->GetPreviousViewID() == KUidBrowserBookmarksViewId )
       
  2731             {
       
  2732             if ( GetBookmarksView()->GetAdaptiveBookmarksFolderWasActive() )
       
  2733                 {
       
  2734                 GetBookmarksView()->OpenAdaptiveBookmarksWhenActivated();
       
  2735                 }
       
  2736             SetViewToBeActivatedIfNeededL( KUidBrowserBookmarksViewId );
       
  2737             }
       
  2738         else
       
  2739             {
       
  2740                	if(CalledFromAnotherApp() && (!IsEmbeddedModeOn()))
       
  2741                	    {
       
  2742                     SetViewToBeActivatedIfNeededL( GetPreviousViewFromViewHistory());
       
  2743   	       	        SetCalledFromAnotherApp(EFalse);
       
  2744                	    SendBrowserToBackground();
       
  2745                	    }                	
       
  2746                 else
       
  2747                     {                  
       
  2748                     SetViewToBeActivatedIfNeededL( iViewToReturnOnClose );
       
  2749                     }
       
  2750                 }
       
  2751             }
       
  2752 		}
       
  2753 	}
       
  2754 
       
  2755 // -----------------------------------------------------------------------------------
       
  2756 // CBrowserAppUi::IsEmbeddedModeOn
       
  2757 // -----------------------------------------------------------------------------------
       
  2758 //
       
  2759 TBool CBrowserAppUi::IsEmbeddedModeOn() const
       
  2760 	{
       
  2761 	return iEikonEnv->StartedAsServerApp();
       
  2762 	}
       
  2763 
       
  2764 // -----------------------------------------------------------------------------------
       
  2765 // CBrowserAppUi::HistoryLoadPrevious
       
  2766 // -----------------------------------------------------------------------------------
       
  2767 //
       
  2768 void CBrowserAppUi::HistoryLoadPrevious()
       
  2769     {
       
  2770     if( BrCtlInterface().NavigationAvailable( TBrCtlDefs::ENavigationBack ) )
       
  2771         {
       
  2772 	    TRAP_IGNORE( BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandBack +
       
  2773 										    (TInt)TBrCtlDefs::ECommandIdBase ) );
       
  2774         }
       
  2775     }
       
  2776 
       
  2777 // -----------------------------------------------------------------------------------
       
  2778 // CBrowserAppUi::HistoryLoadNext
       
  2779 // -----------------------------------------------------------------------------------
       
  2780 //
       
  2781 void CBrowserAppUi::HistoryLoadNext()
       
  2782     {
       
  2783     if( BrCtlInterface().NavigationAvailable( TBrCtlDefs::ENavigationForward ) )
       
  2784         {
       
  2785         LoadObserver().DoStartLoad( CBrowserLoadObserver::ELoadUrlTypeOther );
       
  2786         BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandForward +
       
  2787                                                 (TInt)TBrCtlDefs::ECommandIdBase );
       
  2788         }
       
  2789     }
       
  2790 
       
  2791 
       
  2792 // ---------------------------------------------------------------------------
       
  2793 // CBrowserAppUi::IsShutdownRequested
       
  2794 // ---------------------------------------------------------------------------
       
  2795 //
       
  2796 TBool CBrowserAppUi::IsShutdownRequested() const
       
  2797 	{
       
  2798     return iShutdownRequested;
       
  2799 	}
       
  2800 
       
  2801 // ---------------------------------------------------------------------------
       
  2802 // CBrowserAppUi::IsEmbeddedInOperatorMenu
       
  2803 // ---------------------------------------------------------------------------
       
  2804 //
       
  2805 TBool CBrowserAppUi::IsEmbeddedInOperatorMenu() const
       
  2806 	{
       
  2807 	const TUid KUidOperatorMenuApp = { 0x10008D5E };
       
  2808 	const TUid KUidVideoServicesApp = { 0x10281893 }; 
       
  2809 
       
  2810 	// If the embedding application is the Operator Menu or Video Services
       
  2811 	if ( iEmbeddingApplicationUid == KUidOperatorMenuApp || iEmbeddingApplicationUid == KUidVideoServicesApp )
       
  2812 		{
       
  2813 		return ETrue;
       
  2814 		}
       
  2815 	else
       
  2816 		{
       
  2817 		return EFalse;
       
  2818 		}
       
  2819 	}
       
  2820 
       
  2821 // ---------------------------------------------------------------------------
       
  2822 // CBrowserAppUi::IsAppShutterActive
       
  2823 // ---------------------------------------------------------------------------
       
  2824 //
       
  2825 TBool CBrowserAppUi::IsAppShutterActive() const
       
  2826 	{
       
  2827 	CAknAppUi* shuttingApp = CAknEnv::AppWithShutterRunning();
       
  2828 
       
  2829 	if ( shuttingApp )
       
  2830 		{
       
  2831 		return ETrue;
       
  2832 		}
       
  2833 	else
       
  2834 		{
       
  2835 		return EFalse;
       
  2836 		}
       
  2837 	}
       
  2838 
       
  2839 // ---------------------------------------------------------------------------
       
  2840 // CBrowserAppUi::FetchHomePage
       
  2841 // --------------------------------------------------------------------------
       
  2842 //
       
  2843 void CBrowserAppUi::FetchHomePageL()
       
  2844     {
       
  2845 LOG_ENTERFN( "CBrowserAppUi::FetchHomePageL" );
       
  2846     if ( !Fetching() )
       
  2847         {
       
  2848         UpdateSoftKeys();
       
  2849 
       
  2850         // If the last active view is content view, return to the bookmark view on close.
       
  2851         // Otherwise if the last active view is bookmark view and we return to the appropriate view on close.
       
  2852         TUid lastViewId = LastActiveViewId();
       
  2853         if( lastViewId == KUidBrowserContentViewId ||
       
  2854             lastViewId == KUidBrowserNullViewId )
       
  2855             {
       
  2856             lastViewId = KUidBrowserBookmarksViewId;
       
  2857             }
       
  2858         SetViewToReturnOnClose( lastViewId );
       
  2859 
       
  2860         if( iLongZeroPressed )
       
  2861             {
       
  2862 			BROWSER_LOG( ( _L( " LongZeroPressed." ) ) );
       
  2863 
       
  2864             // There should only be one special load observer at startup
       
  2865             SpecialLoadObserver().SetLongZeroStartup( iLongZeroPressed );
       
  2866             iLongZeroPressed = EFalse;
       
  2867             HBufC* buf = HBufC::NewLC( KMaxHomePgUrlLength );
       
  2868             TPtr ptr( buf->Des() );
       
  2869             TBool homePgFound( KErrNotFound );
       
  2870 
       
  2871             // try to read Access Points homepage
       
  2872             TUint defaultAp( KWmlNoDefaultAccessPoint );
       
  2873             // 'always ask' feature doesn't let to read the AP
       
  2874             if( Preferences().AccessPointSelectionMode() == EConnectionMethod )
       
  2875                 {
       
  2876                 defaultAp = Preferences().DefaultAccessPoint();
       
  2877                 }
       
  2878             if ( defaultAp != KWmlNoDefaultAccessPoint ) // There is an access point defined
       
  2879                 {
       
  2880                 CApAccessPointItem* apItem = Preferences().AllPreferencesL().iDefaultAPDetails;
       
  2881                 if ( apItem )
       
  2882                     {
       
  2883                     const HBufC* defaultHP = apItem->ReadConstLongTextL( EApWapStartPage );
       
  2884                     if ( defaultHP->Length() )
       
  2885                         {
       
  2886                         ptr.Zero();
       
  2887                         ptr.Append( *defaultHP );
       
  2888                         homePgFound = KErrNone;
       
  2889                         }
       
  2890                     }
       
  2891                 }
       
  2892             // in case of error, read user defined home page from SD
       
  2893             TInt err( KErrNone );
       
  2894             if( homePgFound == KErrNotFound ) 
       
  2895                 {
       
  2896                 // do not let leaving
       
  2897                 if ((Preferences().HomePageType() == EWmlSettingsHomePageAddress)
       
  2898                    ||(Preferences().HomePageType() == EWmlSettingsHomePageUseCurrent))
       
  2899                 	{                         
       
  2900                 	TRAP( err, homePgFound = Preferences().HomePageUrlL( ptr, ETrue ) );
       
  2901                 	}
       
  2902                 }
       
  2903             // we have a url to load
       
  2904             if( err == KErrNone &&
       
  2905                 homePgFound == KErrNone &&
       
  2906                 ptr.Length() > 0 )
       
  2907                 {
       
  2908                 TRAP( err, FetchL( ptr, CBrowserLoadObserver::ELoadUrlTypeOther ) );
       
  2909                 // in case of any error switch back to BookmarksView
       
  2910                 if( err != KErrNone )
       
  2911                     {
       
  2912                     ContentView()->SetFullScreenOffL();
       
  2913                     SetLastActiveViewId( KUidBrowserBookmarksViewId );
       
  2914                     }
       
  2915                 }
       
  2916             else
       
  2917                 {
       
  2918                 // we already switched to ContentView, so change the layout back
       
  2919                 ContentView()->SetFullScreenOffL();
       
  2920                 SetLastActiveViewId( KUidBrowserBookmarksViewId );
       
  2921                 }
       
  2922             CleanupStack::PopAndDestroy( buf );
       
  2923             }
       
  2924         else
       
  2925             {
       
  2926             // it checks HomePageSettings
       
  2927             LaunchHomePageL( /* EFalse */ );
       
  2928             }
       
  2929         }
       
  2930     }
       
  2931 
       
  2932 // ---------------------------------------------------------------------------
       
  2933 // CBrowserAppUi::StartPreferencesViewL
       
  2934 // ---------------------------------------------------------------------------
       
  2935 //
       
  2936 TBool CBrowserAppUi::StartPreferencesViewL( TUint aListItems )
       
  2937     {
       
  2938     TBool retVal( EFalse );
       
  2939 	TInt retUi( KErrNone );
       
  2940     TInt err(KErrNone);
       
  2941 
       
  2942 	//start the connection  dialog
       
  2943 	CCmApplicationSettingsUi* settings = CCmApplicationSettingsUi::NewL();
       
  2944 	CleanupStack::PushL( settings );
       
  2945 	TCmSettingSelection selection;
       
  2946     // empty filter array because no filtering is wanted
       
  2947     TBearerFilterArray filterArray;
       
  2948 	TRAP ( err, retUi = settings->RunApplicationSettingsL( selection, aListItems, filterArray ) );
       
  2949 	CleanupStack::PopAndDestroy(); // settings
       
  2950     
       
  2951 	//if something has been selected
       
  2952 	if (retUi)	
       
  2953 	    {
       
  2954 	    //set the selection mode
       
  2955         iPreferences->SetAccessPointSelectionModeL( 
       
  2956                 STATIC_CAST( TCmSettingSelectionMode, selection.iResult ) );
       
  2957 
       
  2958 	    //based on the chosen connection type, store the connection identifier(iapid, snap id, always ask)
       
  2959 	    //in the preferences list
       
  2960 	    switch ( iPreferences->AccessPointSelectionMode() )
       
  2961 		    {			
       
  2962 		    case EConnectionMethod:
       
  2963 			    {
       
  2964 			    TUint32 id = iPreferences->DefaultAccessPoint();
       
  2965                 // CMManager gives us IAPid, need to translate to WAPid
       
  2966 			    if (selection.iId != 0)
       
  2967 			        {                   		
       
  2968 			        id = Util::WapIdFromIapIdL( *this, selection.iId ); 
       
  2969 			        }			    			    
       
  2970 			    iPreferences->SetDefaultAccessPointL( id );
       
  2971                 // Requested AP is preset for PushMtm
       
  2972 			    id = iPreferences->DefaultAccessPoint();
       
  2973                 if( id != KWmlNoDefaultAccessPoint )
       
  2974                     {
       
  2975     			    SetRequestedAP( id );
       
  2976                     retVal = ETrue;
       
  2977                     }
       
  2978 			    break;	
       
  2979 			    }
       
  2980 
       
  2981 		    case EDestination:
       
  2982 			    {
       
  2983 			    TUint32 snapId = iPreferences->DefaultSnapId();
       
  2984 			    if (selection.iId != 0)
       
  2985 			        {                   		
       
  2986 			        snapId = selection.iId;
       
  2987 			        }			        
       
  2988 			    iPreferences->SetDefaultSnapId( snapId );
       
  2989                 if( snapId != KWmlNoDefaultSnapId )
       
  2990                     {
       
  2991                     retVal = ETrue;
       
  2992                     }
       
  2993 			    break;	
       
  2994 			    }
       
  2995 
       
  2996 		    case EAlwaysAsk:
       
  2997 		    default:
       
  2998 			    {
       
  2999 			    break;	
       
  3000 			    }
       
  3001 		    }			
       
  3002 	    }
       
  3003 
       
  3004     // alr: is return val needed?  should it be true or false in EAA and default?  check how it's used
       
  3005     return retVal;
       
  3006     }
       
  3007 // ---------------------------------------------------------------------------
       
  3008 // CBrowserAppUi::AhleConnection
       
  3009 // ---------------------------------------------------------------------------
       
  3010 //
       
  3011 CRecentUrlStore* CBrowserAppUi::RecentUrlStore()
       
  3012     {
       
  3013     return iRecentUrlStore;
       
  3014     }
       
  3015 
       
  3016 // ---------------------------------------------------------------------------
       
  3017 // CBrowserAppUi::SomeItemsNotSecure
       
  3018 // ---------------------------------------------------------------------------
       
  3019 //
       
  3020 TBool CBrowserAppUi::SomeItemsNotSecure() const
       
  3021     {
       
  3022     return !( LoadObserver().LoadStatus( CBrowserLoadObserver::ELoadStatusAllItemIsSecure ) );
       
  3023     }
       
  3024 
       
  3025 // ----------------------------------------------------
       
  3026 // CBrowserAppUi::IsProgressShown
       
  3027 // ----------------------------------------------------
       
  3028 //
       
  3029 TBool CBrowserAppUi::IsProgressShown() const
       
  3030     {
       
  3031     return iShowProgress;
       
  3032     }
       
  3033 
       
  3034 // ----------------------------------------------------
       
  3035 // CBrowserAppUi::SetProgressShown
       
  3036 // ----------------------------------------------------
       
  3037 //
       
  3038 void CBrowserAppUi::SetProgressShown( TBool aProgressShown )
       
  3039     {
       
  3040     iShowProgress = aProgressShown;
       
  3041     }
       
  3042 
       
  3043 // ----------------------------------------------------
       
  3044 // CBrowserAppUi::RecognizeUiFileL
       
  3045 // ----------------------------------------------------
       
  3046 //
       
  3047 TBool CBrowserAppUi::RecognizeUiFileL( RFile& aFile, TBuf<KMaxDataTypeLength>& aDataTypeDes  )
       
  3048 	{
       
  3049 	TBool recognized = EFalse;
       
  3050 	HBufC8* buffer = NULL;
       
  3051 
       
  3052 	TFileName fileName;
       
  3053 	User::LeaveIfError(aFile.FullName(fileName));
       
  3054 
       
  3055     TInt fileSize;
       
  3056 
       
  3057 	// Read the file from the beginning into a buffer
       
  3058 	User::LeaveIfError(aFile.Size(fileSize));
       
  3059 	buffer = HBufC8::NewLC(fileSize);
       
  3060     TPtr8 bufferPtr(buffer->Des());
       
  3061     TInt startPos = 0;
       
  3062     User::LeaveIfError(aFile.Read(startPos, bufferPtr, fileSize));
       
  3063     // move the seek position back to start
       
  3064     User::LeaveIfError(aFile.Seek(ESeekStart, startPos));
       
  3065 
       
  3066     _LIT( KDotOPML, ".opml");
       
  3067     _LIT( KDotXML, ".xml");
       
  3068 
       
  3069     // First try the name extension
       
  3070     if ( fileName.Length() >= 3 )
       
  3071         {
       
  3072         TInt dotPos = fileName.LocateReverse( '.' );
       
  3073         if ( dotPos != KErrNotFound )
       
  3074             {
       
  3075             TInt extLength = fileName.Length() - dotPos;
       
  3076             HBufC* ext = fileName.Right( extLength ).AllocL();
       
  3077             CleanupStack::PushL( ext );
       
  3078 
       
  3079             // if .opml return true
       
  3080             if ( ext->CompareF( KDotOPML )  == 0)
       
  3081             	{
       
  3082 				aDataTypeDes = KOPMLMimeType;
       
  3083             	recognized = ETrue;
       
  3084             	}
       
  3085             else if (ext->CompareF( KDotXML ) == 0 )
       
  3086                 {
       
  3087                 _LIT8( dtd, "<opml" );
       
  3088 				if( bufferPtr.FindF( dtd ) != KErrNotFound )
       
  3089 					{
       
  3090 					aDataTypeDes =  KOPMLMimeType;
       
  3091 					recognized = ETrue;
       
  3092 					}
       
  3093                	}
       
  3094             CleanupStack::PopAndDestroy();	// ext
       
  3095             }
       
  3096         }
       
  3097 
       
  3098 		if (!recognized)
       
  3099 			{
       
  3100 			// just check content of buffer
       
  3101         	_LIT8( dtd, "<opml" );
       
  3102 			if( (bufferPtr.Length() > 5) &&
       
  3103 			    (bufferPtr.FindF( dtd ) != KErrNotFound ))
       
  3104 				{
       
  3105 				aDataTypeDes = KOPMLMimeType;
       
  3106 				recognized = ETrue;
       
  3107 				}
       
  3108         	}
       
  3109 
       
  3110 	CleanupStack::PopAndDestroy(); //buffer
       
  3111 
       
  3112 	return recognized;
       
  3113 	}
       
  3114 
       
  3115 
       
  3116 // ---------------------------------------------------------
       
  3117 // CBrowserAppUi::ConfirmUiHandlingL
       
  3118 // ---------------------------------------------------------
       
  3119 //
       
  3120 TBool CBrowserAppUi::ConfirmUiHandlingL( TFileName& aFilename, TBuf<KMaxDataTypeLength>& aDataTypeDes  )
       
  3121 	{
       
  3122 	// switch on data type desc and handle file accordingly
       
  3123 	if(aDataTypeDes.Compare( KOPMLMimeType ) == 0)
       
  3124 		{
       
  3125 		// Display confirmation dialog before activating feeds view
       
  3126 		HBufC* message = StringLoader::LoadLC(R_FEEDS_QUERY_IMPORT_NOW, aFilename);
       
  3127 		HBufC* lsc_yes = StringLoader::LoadLC(R_FEEDS_IMPORT_NOW_YES);
       
  3128 		HBufC* rsc_no = StringLoader::LoadLC(R_FEEDS_IMPORT_NOW_NO);
       
  3129 
       
  3130 		TBool ret(iDialogsProvider->DialogConfirmL( _L(""), *message, *lsc_yes, *rsc_no ));
       
  3131 
       
  3132 		CleanupStack::PopAndDestroy(3); //message, lsc_yes, rsc_no
       
  3133 
       
  3134 		if(ret)
       
  3135 			{
       
  3136 			return ETrue;
       
  3137 			}
       
  3138 		}
       
  3139 
       
  3140 	return EFalse;
       
  3141 	}
       
  3142 
       
  3143 // ---------------------------------------------------------
       
  3144 // CBrowserAppUi::CopyUiRFileToFileL
       
  3145 // ---------------------------------------------------------
       
  3146 //
       
  3147 
       
  3148 void CBrowserAppUi::CopyUiRFileToFileL( RFile& aFile, const TDesC& aFilepath )
       
  3149 	{
       
  3150 	//
       
  3151 	// copy r-file to a temporary file
       
  3152 	//
       
  3153 	RFs tempRFs;
       
  3154 	RFile tempRFile;
       
  3155 	TInt fileSize;
       
  3156 	HBufC8* buffer = NULL;
       
  3157 
       
  3158 	// Connect to file server
       
  3159 	User::LeaveIfError(tempRFs.Connect());
       
  3160     CleanupClosePushL(tempRFs);
       
  3161 
       
  3162 	// Create the filepath to copy to
       
  3163 	// Replace the file if it already exists
       
  3164 	User::LeaveIfError(tempRFile.Replace(tempRFs, aFilepath, EFileWrite));
       
  3165 	CleanupClosePushL(tempRFile);
       
  3166 
       
  3167 	// Copy the file
       
  3168 	User::LeaveIfError(aFile.Size(fileSize));
       
  3169 	buffer = HBufC8::NewLC(fileSize);
       
  3170     TPtr8 bufferPtr(buffer->Des());
       
  3171 
       
  3172 	// Read from the start of the file
       
  3173     User::LeaveIfError(aFile.Read(0, bufferPtr, fileSize));
       
  3174 	User::LeaveIfError(tempRFile.Write(bufferPtr, fileSize));
       
  3175 
       
  3176 	tempRFile.Close();
       
  3177 	tempRFs.Close();
       
  3178 
       
  3179 	// Cleanup Buffer and file copy stuff
       
  3180 	CleanupStack::PopAndDestroy(3); //buffer, tempRFile, tempRFs
       
  3181 	}
       
  3182 
       
  3183 // ---------------------------------------------------------
       
  3184 // CBrowserAppUi::HandleUiFileL
       
  3185 // ---------------------------------------------------------
       
  3186 //
       
  3187 void CBrowserAppUi::HandleUiFileL( TFileName& aFilepath, TBuf<KMaxDataTypeLength>& aDataTypeDes )
       
  3188 	{
       
  3189 	// switch on data type desc and handle file accordingly
       
  3190 	if(aDataTypeDes.Compare(KOPMLMimeType) == 0)
       
  3191 		{
       
  3192 		// Activate Content view first in order to
       
  3193 		// get it's BrowserControl instance ready to go
       
  3194 		// (as opposed to Feeds' BC instance) to be used to render
       
  3195 		// feeds content in case the user wants to read
       
  3196 		// the feed in-page.
       
  3197 		SetLastActiveViewId( KUidBrowserContentViewId );
       
  3198 		SetViewToBeActivatedIfNeededL( LastActiveViewId() );
       
  3199 		ActivateLocalViewL( LastActiveViewId() );
       
  3200 
       
  3201 		// Now activate bookmarks view
       
  3202 		SetLastActiveViewId( KUidBrowserBookmarksViewId );
       
  3203 		SetViewToBeActivatedIfNeededL( LastActiveViewId() );
       
  3204 		ActivateLocalViewL( LastActiveViewId() );
       
  3205 		HandleForegroundEventL( ETrue );
       
  3206 
       
  3207 		// wait until the content view is completely ready
       
  3208 		WaitCVInit();
       
  3209 
       
  3210 		// begin import, pass to feeds view
       
  3211 		iFeedsClientUtilities->BeginImportOPMLFeedsFileL(aFilepath);
       
  3212 		}
       
  3213 	}
       
  3214 
       
  3215 // ---------------------------------------------------------
       
  3216 // CBrowserAppUi::HandleUiDownloadL
       
  3217 // ---------------------------------------------------------
       
  3218 //
       
  3219 void CBrowserAppUi::HandleUiDownloadL( TFileName& aFilepath, TBuf<KMaxDataTypeLength>& aDataTypeDes )
       
  3220 	{
       
  3221 	// switch on data type desc and handle file accordingly
       
  3222 	if(aDataTypeDes.Compare(KOPMLMimeType) == 0)
       
  3223 		{
       
  3224 		SetLastActiveViewId( KUidBrowserFeedsFolderViewId );
       
  3225 		// begin import
       
  3226 		iFeedsClientUtilities->BeginImportOPMLFeedsFileL(aFilepath);
       
  3227         // switch back to FeedsView, so change layout
       
  3228         ContentView()->SetFullScreenOffL();
       
  3229 		}
       
  3230 	}
       
  3231 	
       
  3232 // ---------------------------------------------------------
       
  3233 // CBrowserAppUi::LaunchIntoFeedsL
       
  3234 // ---------------------------------------------------------
       
  3235 //
       
  3236 void CBrowserAppUi::LaunchIntoFeedsL()
       
  3237 {
       
  3238     if(iBrowserAlreadyRunning && (LastActiveViewId() == KUidBrowserContentViewId))
       
  3239 		{
       
  3240 		iFeedsClientUtilities->ShowFolderViewL(KUidBrowserContentViewId);         	
       
  3241 		}
       
  3242 	else
       
  3243 		{
       
  3244 		iFeedsClientUtilities->ShowFolderViewL();
       
  3245 		}
       
  3246 }
       
  3247 	
       
  3248 // ----------------------------------------------------
       
  3249 // CBrowserAppUi::CreateFullUrlLC
       
  3250 // ----------------------------------------------------
       
  3251 //
       
  3252 HBufC* CBrowserAppUi::CreateFullUrlLC(
       
  3253         const TDesC& aUrl,
       
  3254         const TDesC& aUsername,
       
  3255         const TDesC& aPassword )
       
  3256     {
       
  3257     // username[:password]@server/document
       
  3258     TInt lPw = aPassword.Length();
       
  3259     TInt lUn = aUsername.Length();
       
  3260     _LIT( KBrowserScheme, "://" );
       
  3261     TInt index = aUrl.Find( KBrowserScheme );
       
  3262     if( index == KErrNotFound )
       
  3263     	{
       
  3264         index = 0;  // insert at first position
       
  3265     	}
       
  3266     else
       
  3267     	{
       
  3268     	index += 3;  // insert after scheme
       
  3269     	}
       
  3270 
       
  3271     HBufC *fullUrl = HBufC::NewLC( aUrl.Length() + lUn + lPw + 3 );
       
  3272     fullUrl->Des().Copy( aUrl );
       
  3273     if( lPw + lUn )
       
  3274         {
       
  3275         fullUrl->Des().Insert( index, _L( "@" ) );
       
  3276         }
       
  3277     if( lPw )
       
  3278         {
       
  3279         fullUrl->Des().Insert( index, aPassword );
       
  3280         fullUrl->Des().Insert( index, _L( ":" ) );
       
  3281         }
       
  3282     if( lUn )
       
  3283         {
       
  3284         fullUrl->Des().Insert( index, aUsername );
       
  3285         }
       
  3286     // insert scheme???
       
  3287     fullUrl->Des().ZeroTerminate();
       
  3288 
       
  3289     return fullUrl;
       
  3290     }
       
  3291 
       
  3292 // ---------------------------------------------------------
       
  3293 // CBrowserAppUi::HandleResourceChangeL( TInt aType )
       
  3294 // ---------------------------------------------------------
       
  3295 //
       
  3296 void CBrowserAppUi::HandleResourceChangeL( TInt aType )
       
  3297     {
       
  3298     LOG_ENTERFN("CBrowserAppUi::HandleResourceChangeL");
       
  3299     LOG_WRITE_FORMAT(" aType: %d", aType);
       
  3300     if( iExitInProgress )
       
  3301         {
       
  3302         BROWSER_LOG( ( _L(" iExitInProgress ETrue ") ) );
       
  3303         return;
       
  3304         }
       
  3305 
       
  3306     CAknViewAppUi::HandleResourceChangeL( aType );
       
  3307     if ( aType == KEikDynamicLayoutVariantSwitch )
       
  3308         {
       
  3309         CBrowserViewBase* activeView = ActiveView( );
       
  3310         if( activeView != NULL )
       
  3311             {
       
  3312             activeView->HandleClientRectChange();
       
  3313             if (activeView != ContentView())
       
  3314                 {
       
  3315                 ContentView()->HandleClientRectChange();
       
  3316                 }
       
  3317             }
       
  3318         }
       
  3319     if (aType == KEikMessageFadeAllWindows)
       
  3320         {
       
  3321         if (ContentView() && ContentView()->PenEnabled())
       
  3322             {
       
  3323             if (iCurrentView == KUidBrowserContentViewId)
       
  3324                 {
       
  3325                 ContentView()->Toolbar()->DisableToolbarL(ETrue);
       
  3326                 }
       
  3327             }
       
  3328         }
       
  3329 
       
  3330     if (aType == KEikMessageUnfadeWindows)
       
  3331         {
       
  3332         if (ContentView()&& ContentView()->PenEnabled() && !ExitInProgress())
       
  3333             {
       
  3334             if (iCurrentView == KUidBrowserContentViewId)
       
  3335                 {
       
  3336                 ContentView()->MakeZoomSliderVisibleL(EFalse);
       
  3337                 ContentView()->Toolbar()->DisableToolbarL(EFalse);
       
  3338                 }
       
  3339             }
       
  3340         }
       
  3341     }
       
  3342 
       
  3343 // ---------------------------------------------------------
       
  3344 // CBrowserAppUi::ChangeConnectionL()
       
  3345 // ---------------------------------------------------------
       
  3346 //
       
  3347 void CBrowserAppUi::ChangeConnectionL()
       
  3348     {
       
  3349     TConManChangeConn change;
       
  3350     // This will contain the new IAP as well, but it needs to pass the old one
       
  3351     TUint32 newAp = Util::IapIdFromWapIdL( *this, RequestedAp() );
       
  3352     iConnection->ChangeIapL( change, newAp );
       
  3353     if( EConManDoNothing == change )
       
  3354         {
       
  3355         // Do nothing
       
  3356         }
       
  3357     else
       
  3358         {
       
  3359         //cancel transaction
       
  3360         SendDisconnectEventL();
       
  3361         /* start all */
       
  3362         if( EConManCloseAndStart == change )
       
  3363             {
       
  3364             //close connection
       
  3365             iConnection->Disconnect();
       
  3366 
       
  3367 #ifdef __RSS_FEEDS
       
  3368             //notify feeds engine to close the connection
       
  3369         	iFeedsClientUtilities->DisconnectManualUpdateConnectionL();
       
  3370 #endif
       
  3371             }
       
  3372         iConnection->SetRequestedAP( newAp );
       
  3373         TInt err = iConnection->StartConnectionL( ETrue );
       
  3374         if( err == KErrNone )
       
  3375             {
       
  3376             iConnection->ShowConnectionChangedDlg();
       
  3377             }
       
  3378         }
       
  3379     }
       
  3380 
       
  3381 // ---------------------------------------------------------
       
  3382 // CBrowserAppUi::HandleContentL()
       
  3383 // ---------------------------------------------------------
       
  3384 //
       
  3385 TBool CBrowserAppUi::HandleContentL( const TDesC& aFileName,
       
  3386                                       const CAiwGenericParamList& aParamList,
       
  3387                                       TBool& aContinue )
       
  3388     {
       
  3389     // Put the file name to the generic parameter list, if it is not there yet
       
  3390     TInt index(0);
       
  3391     aParamList.FindFirst( index, EGenericParamFile, EVariantTypeDesC );
       
  3392     if ( index == KErrNotFound )
       
  3393     	{
       
  3394         TAiwVariant paramVariant( aFileName );
       
  3395         TAiwGenericParam genericParam( EGenericParamFile, paramVariant );
       
  3396         CAiwGenericParamList* paramList = (CAiwGenericParamList*)&aParamList;
       
  3397         paramList->AppendL( genericParam );
       
  3398     	}
       
  3399 
       
  3400 	// Set EGenericParamAllowMove - we allow handlers to apply move instead
       
  3401 	// of copy for the file.
       
  3402     aParamList.FindFirst( index, EGenericParamAllowMove, EVariantTypeAny );
       
  3403     if ( index == KErrNotFound )
       
  3404     	{
       
  3405     	TBool allowMove( ETrue );
       
  3406         TAiwVariant allowMoveVariant( allowMove );
       
  3407         TAiwGenericParam genericParamAllowMove( EGenericParamAllowMove, allowMoveVariant );
       
  3408         CAiwGenericParamList* paramList = (CAiwGenericParamList*)&aParamList;
       
  3409         paramList->AppendL( genericParamAllowMove );
       
  3410     	}
       
  3411 
       
  3412     BrowserLauncherService()->DownloadFinishedL( KErrNone, aParamList );
       
  3413 
       
  3414     // Wait until the client sends two TBools (contentHandled & continueBrowsing).
       
  3415     iClientWantsToContinue = EFalse;
       
  3416     iWasContentHandled = EFalse;
       
  3417 
       
  3418     iLauncherServiceWait.Start();
       
  3419 
       
  3420     // iClientWantsToContinue and iWasContentHandled contains the results
       
  3421     aContinue = iClientWantsToContinue;
       
  3422     return iWasContentHandled;
       
  3423     }
       
  3424 
       
  3425 // ---------------------------------------------------------
       
  3426 // CBrowserAppUi::DownloadedContentHandlerReserved1()
       
  3427 // ---------------------------------------------------------
       
  3428 //
       
  3429 TAny* CBrowserAppUi::DownloadedContentHandlerReserved1( TAny* /*aAnyParam*/ )
       
  3430     {
       
  3431     return 0;
       
  3432     }
       
  3433 
       
  3434 // ---------------------------------------------------------
       
  3435 // CBrowserAppUi::SetContentHandlingResult()
       
  3436 // ---------------------------------------------------------
       
  3437 //
       
  3438 void CBrowserAppUi::SetContentHandlingResult
       
  3439     ( TBool aClientWantsToContinue, TBool aWasContentHandled )
       
  3440     {
       
  3441     iClientWantsToContinue = aClientWantsToContinue;
       
  3442     iWasContentHandled = aWasContentHandled;
       
  3443 
       
  3444     // continue handling the content
       
  3445     iLauncherServiceWait.AsyncStop();
       
  3446     }
       
  3447 
       
  3448 // ---------------------------------------------------------
       
  3449 // CBrowserAppUi::LoadSearchPageL()
       
  3450 // ---------------------------------------------------------
       
  3451 //
       
  3452 void CBrowserAppUi::LoadSearchPageL()
       
  3453 	{
       
  3454     TPtrC url = iPreferences->SearchPageUrlL();
       
  3455 
       
  3456     // url undefined
       
  3457     if ( !url.Length() )
       
  3458         {
       
  3459         HBufC* query = StringLoader::LoadLC(
       
  3460                                     R_BROWSER_QUERY_DEF_SEARCHPAGE );
       
  3461         // Ask if user want to define the search web setting now
       
  3462         if (
       
  3463             TBrowserDialogs::DialogQueryReqL( query->Des(),
       
  3464                                                 KNullDesC,
       
  3465                                                 KNullDesC )
       
  3466             )
       
  3467             {
       
  3468             HBufC* prompt = StringLoader::LoadLC(
       
  3469                                         R_BROWSER_PROMPT_SEARCH_URL );
       
  3470             HBufC* retBuf = HBufC::NewLC( KMaxSearchPgUrlLength );
       
  3471             TPtr retString = retBuf->Des();
       
  3472             retString.Copy( KNullDesC );
       
  3473 
       
  3474             TInt result = TBrowserDialogs::DialogPromptReqL(
       
  3475                                              prompt->Des(),
       
  3476                                              &retString,
       
  3477                                              ETrue,
       
  3478                                              KMaxSearchPgUrlLength
       
  3479                                              );
       
  3480 
       
  3481             if( result )  // URL was accepted
       
  3482                 {
       
  3483                 Preferences().SetSearchPageUrlL( retString );
       
  3484                 url.Set( iPreferences->SearchPageUrlL() );
       
  3485                 }
       
  3486             CleanupStack::PopAndDestroy( 2 ); // retBuf, prompt
       
  3487             }
       
  3488         CleanupStack::PopAndDestroy( query );
       
  3489         }
       
  3490 
       
  3491     FetchL( url );
       
  3492 	}
       
  3493 
       
  3494 // ---------------------------------------------------------
       
  3495 // CBrowserAppUi::CloseWindowL()
       
  3496 // ---------------------------------------------------------
       
  3497 //
       
  3498 void CBrowserAppUi::CloseWindowL( TInt aWindowId )
       
  3499     {
       
  3500 LOG_ENTERFN("AppUi::CloseWindowL");
       
  3501 
       
  3502 	//There are only two cases for closing window. One is user initialized and the
       
  3503 	//other is script initialized. For both cases, the window should be deleted.
       
  3504     TBool forceDelete( ETrue );
       
  3505     // delete the current window by default
       
  3506     if( aWindowId == 0 )
       
  3507         {
       
  3508         aWindowId = WindowMgr().CurrentWindow()->WindowId();
       
  3509         // scripts directly pass a real windowId,
       
  3510         // so if user initiated the process, we really delete the window
       
  3511         forceDelete = ETrue;
       
  3512         }
       
  3513 
       
  3514 #ifdef __RSS_FEEDS
       
  3515 	// If we are closing a Feeds Full Story then go back to feeds
       
  3516 	TBool feedsWindow(EFalse);
       
  3517 	CBrowserWindow* win;
       
  3518 	TInt err = WindowMgr().Window(aWindowId, win);
       
  3519 	if (err == KErrNone)
       
  3520 		{
       
  3521 		feedsWindow = win->HasFeedsContent();
       
  3522 		win->SetHasFeedsContent(EFalse);
       
  3523 		}
       
  3524 #endif
       
  3525 
       
  3526 	TInt winId = WindowMgr().DeleteWindowL( aWindowId, forceDelete );
       
  3527 
       
  3528 #ifdef __RSS_FEEDS
       
  3529 	if (feedsWindow)
       
  3530 		{
       
  3531 		SetViewToBeActivatedIfNeededL( KUidBrowserFeedsFeedViewId );
       
  3532 		return;
       
  3533 		}
       
  3534 #endif
       
  3535 
       
  3536     if( winId > 0 )  // still remain a window to be activated
       
  3537         {
       
  3538    	    WindowMgr().SwitchWindowL( winId );
       
  3539             if(CalledFromAnotherApp() && (!IsEmbeddedModeOn()))
       
  3540    	        {
       
  3541    	        SetCalledFromAnotherApp(EFalse);
       
  3542    	        SendBrowserToBackground();
       
  3543    	        }
       
  3544    	    }
       
  3545    	else  if( winId == 0) // last window was closed
       
  3546 	    {
       
  3547         if(CalledFromAnotherApp() && (!IsEmbeddedModeOn()))
       
  3548    	        {
       
  3549 #ifdef __RSS_FEEDS
       
  3550    	        if ((GetPreviousViewFromViewHistory() == KUidBrowserFeedsFolderViewId) || 
       
  3551    	            (GetPreviousViewFromViewHistory() == KUidBrowserFeedsTopicViewId) ||
       
  3552    	            (GetPreviousViewFromViewHistory() == KUidBrowserFeedsFeedViewId))
       
  3553    	            {
       
  3554    	            SetViewToBeActivatedIfNeededL( GetPreviousViewFromViewHistory() );
       
  3555    	            SetCalledFromAnotherApp(EFalse);
       
  3556    	            SendBrowserToBackground();
       
  3557    	            }
       
  3558    	        else
       
  3559                 {
       
  3560                	ExitBrowser(ETrue);
       
  3561                 }
       
  3562 #else
       
  3563             ExitBrowser(ETrue);
       
  3564 #endif // __RSS_FEEDS
       
  3565    	        }
       
  3566         else
       
  3567             {
       
  3568         	ExitBrowser(ETrue);        
       
  3569             }
       
  3570     	}
       
  3571     // else a background window was closed
       
  3572 
       
  3573     }
       
  3574 
       
  3575 // ---------------------------------------------------------
       
  3576 // CBrowserAppUi::StartProgressAnimationL
       
  3577 // ---------------------------------------------------------
       
  3578 //
       
  3579 void CBrowserAppUi::StartProgressAnimationL()
       
  3580     {
       
  3581 LOG_ENTERFN("AppUi::StartProgressAnimationL");
       
  3582     }
       
  3583 
       
  3584 // ---------------------------------------------------------
       
  3585 // CBrowserAppUi::StopProgressAnimationL
       
  3586 // ---------------------------------------------------------
       
  3587 //
       
  3588 void CBrowserAppUi::StopProgressAnimationL()
       
  3589     {
       
  3590 LOG_ENTERFN("AppUi::StopProgressAnimationL");
       
  3591     }
       
  3592 
       
  3593 #ifdef __RSS_FEEDS
       
  3594 // ---------------------------------------------------------
       
  3595 // CBrowserAppUi::FeedsClientUtilities
       
  3596 // ---------------------------------------------------------
       
  3597 //
       
  3598 CFeedsClientUtilities& CBrowserAppUi::FeedsClientUtilities() const
       
  3599 	{
       
  3600 	return *iFeedsClientUtilities;
       
  3601 	}
       
  3602 #endif  // __RSS_FEEDS
       
  3603 
       
  3604 // ---------------------------------------------------------
       
  3605 // CBrowserAppUi::OpenLinkInNewWindowL()
       
  3606 // ---------------------------------------------------------
       
  3607 //
       
  3608 void CBrowserAppUi::OpenLinkInNewWindowL( const CFavouritesItem& aBookmarkItem )
       
  3609     {
       
  3610     if( ( aBookmarkItem.IsItem() ) &&
       
  3611         ( aBookmarkItem.Uid() != KFavouritesRSSItemUid ) )
       
  3612         {
       
  3613         // Check if we should/can create a new window
       
  3614         // In most cases when the feature is not allowed option menu items have been dimmed.
       
  3615         // In the case where a long key press on a bookmark happens we fall through to this function
       
  3616         // and check the feature here.  If a new window is not allowed we can open in the current window
       
  3617         if( IsPageLoaded() &&
       
  3618         		Preferences().UiLocalFeatureSupported( KBrowserMultipleWindows ) &&
       
  3619             	!Preferences().UiLocalFeatureSupported( KBrowserMinimalMultipleWindows ))
       
  3620             {
       
  3621             // there is already a window, so create a new one
       
  3622             CBrowserWindow *win = WindowMgr().CreateWindowL( 0, &KNullDesC );
       
  3623             if (win != NULL)
       
  3624                 {
       
  3625                 CleanupStack::PushL( win );
       
  3626                 WindowMgr().SwitchWindowL( win->WindowId() );
       
  3627                 FetchBookmarkL( aBookmarkItem );
       
  3628                 CleanupStack::Pop();  // win
       
  3629                 }
       
  3630             }
       
  3631         else
       
  3632             {
       
  3633             // no page is loaded yet, so do not create new window
       
  3634             FetchBookmarkL( aBookmarkItem );
       
  3635             }
       
  3636         }
       
  3637     }
       
  3638 
       
  3639 // ---------------------------------------------------------
       
  3640 // CBrowserAppUi::SendDisconnectEventL
       
  3641 // ---------------------------------------------------------
       
  3642 //
       
  3643 void CBrowserAppUi::SendDisconnectEventL()
       
  3644     {
       
  3645     LOG_ENTERFN("CBrowserAppUi::SendDisconnectEventL");
       
  3646     SpecialLoadObserver().CancelConnection();
       
  3647     CArrayFixFlat<CWindowInfo*>* windows = iWindowManager->GetWindowInfoL( this );
       
  3648     if( windows )
       
  3649         {
       
  3650         TInt i;
       
  3651 
       
  3652         for ( i = 0; i < windows->Count(); i++ )
       
  3653             {
       
  3654             CBrowserWindow* window = NULL;
       
  3655             iWindowManager->Window( windows->At( i )->iWindowId, window );
       
  3656             if( window )
       
  3657                 {
       
  3658                 TInt err;
       
  3659            //     BROWSER_LOG( ( _L( " iConnection Connected" ) ) );
       
  3660                 TRAP( err, window->BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandCancelFetch + (TInt)TBrCtlDefs::ECommandIdBase ) );
       
  3661            //     BROWSER_LOG( ( _L( " HandleCommandL:  %d"), err ) );
       
  3662                 }
       
  3663             }
       
  3664         
       
  3665         CBrowserWindow* window = NULL;
       
  3666         iWindowManager->Window( windows->At( 0 )->iWindowId, window );
       
  3667         
       
  3668         // Close session only once
       
  3669         if (window)
       
  3670             {
       
  3671             window->BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandDisconnect + (TInt)TBrCtlDefs::ECommandIdBase );
       
  3672             }
       
  3673         
       
  3674         // delete the window items before deleting the array
       
  3675         for( i=0; i<windows->Count(); ++i )
       
  3676             delete windows->At( i );
       
  3677 
       
  3678         delete windows;
       
  3679         }
       
  3680     }
       
  3681     /*
       
  3682 
       
  3683 // ----------------------------------------------------
       
  3684 // CBrowserAppUi::IsPgNotFound
       
  3685 // ----------------------------------------------------
       
  3686 //
       
  3687 TBool CBrowserAppUi::IsPgNotFound() const
       
  3688     {
       
  3689     return iPgNotFound;
       
  3690     }
       
  3691 */
       
  3692 // ----------------------------------------------------
       
  3693 // CBrowserAppUi::HandleApplicationSpecificEventL
       
  3694 // ----------------------------------------------------
       
  3695 //
       
  3696 void CBrowserAppUi::HandleApplicationSpecificEventL(TInt aEventType, const TWsEvent& aWsEvent)
       
  3697     {
       
  3698     CAknAppUi::HandleApplicationSpecificEventL(aEventType, aWsEvent);
       
  3699 
       
  3700 	if(aEventType == KAppOomMonitor_FreeRam )
       
  3701 		{
       
  3702 		iWindowManager->CloseAllWindowsExceptCurrent();
       
  3703 		if(!iIsForeground)
       
  3704 		    {
       
  3705             BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandFreeMemory + (TInt)TBrCtlDefs::ECommandIdBase);
       
  3706 		    }
       
  3707 		}
       
  3708 	else if(aEventType == KAppOomMonitor_MemoryGood)
       
  3709 		{
       
  3710         BrCtlInterface().HandleCommandL( (TInt)TBrCtlDefs::ECommandMemoryGood + (TInt)TBrCtlDefs::ECommandIdBase);
       
  3711 		}
       
  3712     else if ( KAknFullOrPartialForegroundGained == aEventType )
       
  3713         {
       
  3714         if ( iViewToBeActivatedIfNeeded.iUid )
       
  3715             {
       
  3716             ActivateLocalViewL( iViewToBeActivatedIfNeeded );
       
  3717             }
       
  3718         else
       
  3719             {
       
  3720             // LastActiveViewId() might return with 0!
       
  3721             TRAP_IGNORE( ActivateLocalViewL( LastActiveViewId() ) );
       
  3722             }
       
  3723         iViewToBeActivatedIfNeeded.iUid = 0;
       
  3724         }
       
  3725     }
       
  3726 
       
  3727 // ----------------------------------------------------
       
  3728 // CBrowserAppUi::OfferApplicationSpecificKeyEventL
       
  3729 //
       
  3730 // Use this function to handle key events that are application wide and not specific to any view
       
  3731 // All views (containers) call this first and should return if key was consumed
       
  3732 // As a note for future reference the red end key shows up as iCode = EKeyNo...though you would
       
  3733 // think it would be EKeyEnd...
       
  3734 // ----------------------------------------------------
       
  3735 //
       
  3736 TKeyResponse CBrowserAppUi::OfferApplicationSpecificKeyEventL(const TKeyEvent& /*aKeyEvent*/,
       
  3737 															  TEventCode /*aType*/)
       
  3738     {
       
  3739     TKeyResponse result( EKeyWasNotConsumed );
       
  3740 
       
  3741     return result;
       
  3742     }
       
  3743 
       
  3744 // -----------------------------------------------------------------------------
       
  3745 // CBrowserAppUi::GetPreviousViewFromViewHistory
       
  3746 // -----------------------------------------------------------------------------
       
  3747 //
       
  3748 TUid CBrowserAppUi::GetPreviousViewFromViewHistory()
       
  3749 {
       
  3750 	return iPreviousView;
       
  3751 }
       
  3752 
       
  3753 // -----------------------------------------------------------------------------
       
  3754 // CBrowserAppUi::SaveFocusedImageToGalleryL
       
  3755 // -----------------------------------------------------------------------------
       
  3756 //
       
  3757 void CBrowserAppUi::SaveFocusedImageToGalleryL()
       
  3758     {
       
  3759     TBrCtlImageCarrier* imageCarrier = BrCtlInterface().FocusedImageLC();
       
  3760     CDocumentHandler* docHandler = CDocumentHandler::NewLC();
       
  3761     TUriParser uriParser;
       
  3762     User::LeaveIfError(uriParser.Parse(imageCarrier->Url()));
       
  3763     TPtrC path;
       
  3764     path.Set( uriParser.Extract( EUriPath ) );
       
  3765     HBufC* fileName = NULL;
       
  3766     if( path.Length() )
       
  3767         {
       
  3768         TInt slash = path.LocateReverse( '/' );
       
  3769         if( slash != KErrNotFound && slash != path.Length() )
       
  3770             {
       
  3771             TPtrC temp( path.Right( path.Length() - slash - 1 ) );
       
  3772             if( temp.Length() )
       
  3773                 {
       
  3774                 fileName = HBufC::NewLC(temp.Length() + 4); // leave room for edding extenstion if needed
       
  3775                 fileName->Des().Copy(temp);
       
  3776                 }
       
  3777             }
       
  3778         }
       
  3779     HBufC8* dataType8 = NULL;
       
  3780     dataType8 = HBufC8::NewLC(imageCarrier->ContentType().Length());
       
  3781     dataType8->Des().Copy(imageCarrier->ContentType());
       
  3782     TDataType dataType(*dataType8);
       
  3783     if (fileName)
       
  3784         {
       
  3785         TPtr fileNamePtr(fileName->Des());
       
  3786         docHandler->CheckFileNameExtension(fileNamePtr, dataType);
       
  3787         docHandler->SaveL(imageCarrier->RawData(), dataType, *fileName, KEntryAttNormal);
       
  3788         }
       
  3789     else
       
  3790         {
       
  3791         docHandler->SaveL(imageCarrier->RawData(), dataType, KEntryAttNormal);
       
  3792         }
       
  3793     if (fileName)
       
  3794         {
       
  3795         CleanupStack::PopAndDestroy(2); // fileName, dataType8
       
  3796         }
       
  3797     else
       
  3798         {
       
  3799         CleanupStack::PopAndDestroy(dataType8); // dataType8
       
  3800         }
       
  3801 
       
  3802     TFileName fName;
       
  3803     User::LeaveIfError(docHandler->GetPath(fName));
       
  3804     CMGXFileManager* mgFileManager = MGXFileManagerFactory::NewFileManagerL(CEikonEnv::Static()->FsSession());
       
  3805     CleanupStack::PushL(mgFileManager);
       
  3806     if( fName.Length() > 0 )
       
  3807         {
       
  3808         TRAP_IGNORE( mgFileManager->UpdateL( fName ) );
       
  3809         }
       
  3810     else
       
  3811         {
       
  3812         TRAP_IGNORE( mgFileManager->UpdateL() );
       
  3813         }
       
  3814     CleanupStack::PopAndDestroy(2); // imageCarrier, mgFileManager
       
  3815     }
       
  3816 
       
  3817 // ---------------------------------------------------------
       
  3818 // CBrowserAppUi::CheckFlashPresent
       
  3819 // ---------------------------------------------------------
       
  3820 //
       
  3821 TBool CBrowserAppUi::CheckFlashPresent()
       
  3822     {
       
  3823     RImplInfoPtrArray animPluginList;
       
  3824 
       
  3825     TRAP_IGNORE( REComSession::ListImplementationsL( KBrowserPluginInterfaceUid,
       
  3826                                         animPluginList ) );
       
  3827 
       
  3828 
       
  3829 	_LIT8(KFlashMimeType,     "application/x-shockwave-flash");
       
  3830 
       
  3831     const TInt count = animPluginList.Count();
       
  3832     TBool found = EFalse;
       
  3833     for ( TInt i = 0; i < count; i++ )
       
  3834         {
       
  3835         CImplementationInformation* implInfo = animPluginList[i];
       
  3836         if (( implInfo->DataType( ) ).Find( KFlashMimeType) != KErrNotFound)
       
  3837             {
       
  3838             found = ETrue;  //flash plugin is present
       
  3839             break;
       
  3840             }
       
  3841         }
       
  3842     animPluginList.ResetAndDestroy();
       
  3843 
       
  3844     return found;
       
  3845 
       
  3846     }
       
  3847 
       
  3848 // ---------------------------------------------------------
       
  3849 // CBrowserAppUi::FlashPresent
       
  3850 // ---------------------------------------------------------
       
  3851 //
       
  3852 TBool CBrowserAppUi::FlashPresent()
       
  3853     {
       
  3854     return iFlashPresent;
       
  3855     }
       
  3856 
       
  3857 // ---------------------------------------------------------
       
  3858 // CBrowserAppUi::ShowNameAndVersionL
       
  3859 // ---------------------------------------------------------
       
  3860 //
       
  3861 void CBrowserAppUi::ShowNameAndVersionL()
       
  3862 {
       
  3863     HBufC* header = StringLoader::LoadLC( R_BROWSER_QUERY_BROWSER_VERSION );
       
  3864     HBufC* browserVersion = BrCtlInterface().VersionInfoLC(TBrCtlDefs::EBrowserVersion);
       
  3865 
       
  3866     // output browser version to dialog
       
  3867     CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL( *browserVersion );
       
  3868     CleanupStack::PushL(dlg);
       
  3869     dlg->PrepareLC( R_BROWSER_PAGE_VERSION );
       
  3870     CleanupStack::Pop(dlg);
       
  3871     CAknPopupHeadingPane* hPane = dlg->QueryHeading();
       
  3872     if ( hPane )
       
  3873         {
       
  3874         CleanupStack::PushL(hPane);
       
  3875         hPane->SetTextL( *header );
       
  3876 	    CleanupStack::Pop(hPane);
       
  3877         }
       
  3878     dlg->RunLD();
       
  3879 	CleanupStack::PopAndDestroy(2); // browserVersion, header
       
  3880 }
       
  3881 
       
  3882 
       
  3883 // ---------------------------------------------------------
       
  3884 // CBrowserAppUi::IsLaunchHomePageDimmedL
       
  3885 // ---------------------------------------------------------
       
  3886 //
       
  3887 TBool CBrowserAppUi::IsLaunchHomePageDimmedL()
       
  3888 {
       
  3889     
       
  3890     // Set dimmed flag if shortcut key for launch home page is dimmed and was selected
       
  3891     TBool dimmed = EFalse;
       
  3892     TBool homepage = Preferences().UiLocalFeatureSupported( KBrowserUiHomePageSetting );
       
  3893     if( homepage )
       
  3894         {
       
  3895         TWmlSettingsHomePage pgtype = Preferences().HomePageType();
       
  3896         TBool alwaysAskCase = ((Preferences().AccessPointSelectionMode() == EAlwaysAsk ) &&
       
  3897             ( EWmlSettingsHomePageAccessPoint == pgtype ));
       
  3898         
       
  3899         if (alwaysAskCase || (pgtype == EWmlSettingsHomePageBookmarks))
       
  3900             {
       
  3901             dimmed = ETrue;
       
  3902             }
       
  3903         else if (pgtype == EWmlSettingsHomePageAccessPoint)
       
  3904         	{
       
  3905         	// check to see if no home page defined on the access point
       
  3906         	HBufC* buf = HBufC::NewLC( KMaxHomePgUrlLength );  // cleanupstack
       
  3907     		TPtr ptr( buf->Des() );
       
  3908     		TInt pgFound = Preferences().HomePageUrlL( ptr );
       
  3909     		if( pgFound != KErrNone )
       
  3910     			{
       
  3911     			dimmed = ETrue;
       
  3912     			}
       
  3913     		CleanupStack::PopAndDestroy( buf );
       
  3914         	}
       
  3915         }
       
  3916     else
       
  3917         {
       
  3918         dimmed = ETrue;
       
  3919         }
       
  3920         
       
  3921     return(dimmed);
       
  3922 }
       
  3923 
       
  3924 // ---------------------------------------------------------
       
  3925 // CBrowserAppUi::IsDisplayingMenuOrDialog
       
  3926 // ---------------------------------------------------------
       
  3927 //
       
  3928 TBool CBrowserAppUi::IsDisplayingMenuOrDialog()
       
  3929 {
       
  3930 	return CCoeAppUi::IsDisplayingMenuOrDialog();
       
  3931 }
       
  3932 // ---------------------------------------------------------
       
  3933 // CBrowserAppUi::HandleWsEventL
       
  3934 // ---------------------------------------------------------
       
  3935 void CBrowserAppUi::HandleWsEventL(const TWsEvent& aEvent, 
       
  3936                                    CCoeControl* aDestination)
       
  3937 {
       
  3938   /**
       
  3939    * We need a special handling for pointer events to handle the situation 
       
  3940    * when the pointer is crossing the boundaries of plugin window. Browser
       
  3941    * scrolling id done using PointerMove events not a Drag. 
       
  3942    * When PointerMoveBuffer is ready HandlePointerBufferReadyL() is called by
       
  3943    * Symbian framework. By default if Pointer Down event wasn't issued on the 
       
  3944    * current CoeControl Pointer Move events are not sent to this control.
       
  3945    * The code below makes sure that when we entering the Content View window 
       
  3946    * from pluging window we are still getting move events.
       
  3947    * When we are leaving Content window we are generating fake Pointer Up 
       
  3948    * event in order to on-demand scrollbars disapear properly. The later is a
       
  3949    * hack and needs to be re-designed in such way that pluging will pass 
       
  3950    * pointer event back to the browser.
       
  3951    */
       
  3952    if (aDestination != NULL)
       
  3953        {
       
  3954        TInt type=aEvent.Type();
       
  3955        
       
  3956        switch (type)
       
  3957            {
       
  3958            case EEventPointerExit:
       
  3959                {
       
  3960                CCoeControl* ctrl = &(BrCtlInterface());
       
  3961                CCoeControl* parent = ctrl->Parent();
       
  3962 
       
  3963                if (aDestination == parent) 
       
  3964                    {
       
  3965                    TPointerEvent  event;
       
  3966                    event.iType = TPointerEvent::EButton1Up;
       
  3967                    event.iModifiers = 0;
       
  3968                    event.iPosition = TPoint(0, 0);
       
  3969                    parent->HandlePointerEventL(event);
       
  3970                    }
       
  3971                break;
       
  3972                }
       
  3973                
       
  3974            case EEventPointerEnter:
       
  3975                {
       
  3976                if (iCurrentView == KUidBrowserContentViewId)
       
  3977                    {
       
  3978                    CCoeControl* ctrl = &(BrCtlInterface());
       
  3979                    ctrl->DrawableWindow()->DiscardPointerMoveBuffer(); 
       
  3980                    const TInt count = ctrl->CountComponentControls();
       
  3981                    for (TInt i = 0; i < count; i++) 
       
  3982                        {
       
  3983                        CCoeControl* c = ctrl->ComponentControl(i);
       
  3984                        if (c) 
       
  3985                           {
       
  3986                           c->ClaimPointerGrab(EFalse);
       
  3987                           }
       
  3988                        }
       
  3989                    ctrl->ClaimPointerGrab(EFalse);
       
  3990                    }
       
  3991                break;
       
  3992                }
       
  3993            
       
  3994            }
       
  3995        }
       
  3996    CAknViewAppUi::HandleWsEventL(aEvent, aDestination);
       
  3997 }
       
  3998 // End of File