widgets/widgetapp/src/WidgetUiWindowManager.cpp
changeset 10 a359256acfc6
parent 0 dd21522fd290
child 11 c8a366e56285
equal deleted inserted replaced
5:10e98eab6f85 10:a359256acfc6
    19 #include "WidgetUiWindowManager.h"
    19 #include "WidgetUiWindowManager.h"
    20 #include "WidgetUiWindowView.h"
    20 #include "WidgetUiWindowView.h"
    21 #include "WidgetUiWindowContainer.h"
    21 #include "WidgetUiWindowContainer.h"
    22 #include "WidgetUiWindow.h"
    22 #include "WidgetUiWindow.h"
    23 #include "WidgetUiAppUi.h"
    23 #include "WidgetUiAppUi.h"
       
    24 #include "WidgetUiNetworkListener.h"
    24 #include "WidgetInstallerInternalCRKeys.h"
    25 #include "WidgetInstallerInternalCRKeys.h"
    25 #include "SWInstWidgetUid.h"
    26 #include "SWInstWidgetUid.h"
    26 #include "widgetappdefs.rh"
    27 #include "widgetappdefs.rh"
    27 #include "Browser_platform_variant.hrh"
    28 #include "Browser_platform_variant.hrh"
    28 #ifdef BRDO_WRT_HS_FF
    29 #ifdef BRDO_WRT_HS_FF
    40 #include <aknnotewrappers.h>
    41 #include <aknnotewrappers.h>
    41 #include "cpglobals.h" // CPS string definitions.
    42 #include "cpglobals.h" // CPS string definitions.
    42 
    43 
    43 #include <InternetConnectionManager.h>
    44 #include <InternetConnectionManager.h>
    44 #include <ActiveApDb.h>
    45 #include <ActiveApDb.h>
    45 
    46 #include <oommonitorsession.h>
    46 
    47 #include <aknglobalnote.h>
    47 /**
    48 
    48 * Utility class to show the prompt for platform security access.
    49 // LOCAL FUNCTION PROTOTYPES
    49 *
    50 TInt doDestructOOMNotifyTimer( TAny* ptr );
    50 * The class exists only to provide platform security access prompt
    51 TInt doNotifyHarvester( TAny* ptr );
    51 * for the widgets which are launched in minview 
    52 
    52 */
    53 // CONSTANTS
    53 class CGlobalQueryHandlerAO : public CActive
    54 #define KUidWidgetOOMPlugin 0x10282855
    54     {
    55 const TUint32 KCRUidActiveIdleLV = 0x10275102;
    55 public:
    56 const TUint32 KAIWebStatus = 0x0000300F;
    56     /**
    57 const TInt KMemoryToCreateWidgetWindow = 10*1024*1024;
    57     * Startup.
    58 const TInt KOOMNotificationDialogIntervalTimeOut = 60000000;
    58     *
    59 const TInt KOOMNotificationDialogTimeOut = 2000000;
    59     * @param aManager Window Manager.
    60 const TInt KOOMHarvesterNotificationTimeOut = 5000000;
    60     * @param aWindow Window.
    61 const TInt KOOMWidgetCloseTimeOut = 15;//Do not close the widget that was started after OOM within 15 sec
    61     * @param aMessage Message to be prompted.
    62 
    62     * @param aSoftkeys for prompt.
    63 class CRequestRAM : public CActive
    63     */
    64     {
    64     static CGlobalQueryHandlerAO* StartLD (
    65 public: 
    65                             CWidgetUiWindowManager& aManager,
    66 
    66                             CWidgetUiWindow& aWindow,
    67     static CRequestRAM* StartLD(CWidgetUiWindowManager* aWidgetUiWindowManager, const TUid& aUid, TUint32 aOperation);
    67                             const TDesC& aMessage, 
       
    68                             TInt aSoftkeys);
       
    69     /**
       
    70     * ShowGlobalQueryDialogL.
       
    71     *
       
    72     * @param aMessage Message to be prompted.
       
    73     * @param aSoftkeys for prompt.
       
    74     */
       
    75     void ShowGlobalQueryDialogL ( 
       
    76                             const TDesC& aMessage, 
       
    77                             TInt aSoftkeys );
       
    78 protected: // From CActive
    68 protected: // From CActive
    79     /**
    69     /**
    80     * Execute asynchronous operation.
    70     * Execute asynchronous operation.
    81     */
    71     */
    82     void RunL();
    72     void RunL();
    83     
    73     
    84     /**
    74     /**
    85     * Provide cancellation methods.
    75     * Provide cancellation methods.
    86     */
    76     */
    87     void DoCancel();
    77     void DoCancel();
       
    78     void ConstructL();
    88     
    79     
    89 private:
    80 private:
    90 
    81 
    91     /**
    82     /**
    92     * Constructor.
    83     * Constructor.
    93     *
       
    94     * @param aManager Manager.
       
    95     * @param aWindow Window.
       
    96     * @param aMessage Message for prompt.
       
    97     * @param aSoftkeys for prompt.
       
    98     */
    84     */
    99     CGlobalQueryHandlerAO (
    85     CRequestRAM (CWidgetUiWindowManager* aWidgetUiWindowManager, const TUid& aUid, TUint32 aOperation);
   100             CWidgetUiWindowManager& aManager,
       
   101             CWidgetUiWindow& aWindow,
       
   102             const TDesC& aMessage, 
       
   103             TInt aSoftkeys);
       
   104         
    86         
   105     /**
    87     /**
   106     * Destructor. 
    88     * Destructor. 
   107     *
    89     *
   108     * Private on purpose.
    90     * Private on purpose.
   109     */
    91     */
   110     ~CGlobalQueryHandlerAO();
    92     ~CRequestRAM();
   111     
    93     
   112 private:
    94 private:
   113 
    95     ROomMonitorSession iOomSession;
   114     CWidgetUiWindowManager& iManager;
    96     CWidgetUiWindowManager* iWidgetUiWindowManager;
   115     CWidgetUiWindow& iWindow;
    97     TUid iUid;
   116     CAknGlobalConfirmationQuery* iGlobalConfirmationQuery ;
    98     TUint32 iOperation;
   117     CActiveSchedulerWait iScheduler;
       
   118     HBufC* iConfirmationText;
       
   119 
       
   120     };
    99     };
       
   100 
       
   101 // ============================= LOCAL FUNCTIONS ================================
       
   102 
       
   103 static void NotifyCommandHandled()
       
   104     {
       
   105     const TUid KMyPropertyCat = { 0x10282E5A };
       
   106     enum TMyPropertyKeys { EMyPropertyState = 109 };
       
   107     TInt state( 1 );
       
   108     RProperty::Set( KMyPropertyCat, EMyPropertyState , state );
       
   109     }
   121 
   110 
   122 // =============================================================================
   111 // =============================================================================
   123 
   112 
   124 // -----------------------------------------------------------------------------
   113 // -----------------------------------------------------------------------------
   125 // CWidgetUiWindowManager::CWidgetUiWindowManager()
   114 // CWidgetUiWindowManager::CWidgetUiWindowManager()
   127 //
   116 //
   128 // -----------------------------------------------------------------------------
   117 // -----------------------------------------------------------------------------
   129 //
   118 //
   130 CWidgetUiWindowManager::CWidgetUiWindowManager(CWidgetUiAppUi& aAppUi):
   119 CWidgetUiWindowManager::CWidgetUiWindowManager(CWidgetUiAppUi& aAppUi):
   131     iAppUi(aAppUi),
   120     iAppUi(aAppUi),
   132     iStrictMode(ETrue)
   121     iStrictMode(ETrue),
       
   122     iNetworkMode(EUnknownMode),
       
   123     iNetworkConnected(EFalse)
   133     {
   124     {
   134     }
   125     }
   135 
   126 
   136 // -----------------------------------------------------------------------------
   127 // -----------------------------------------------------------------------------
   137 // CWidgetUiWindowManager::ConstructL()
   128 // CWidgetUiWindowManager::ConstructL()
   166     iDb = CActiveApDb::NewL( EDatabaseTypeIAP );
   157     iDb = CActiveApDb::NewL( EDatabaseTypeIAP );
   167     iConnection = CInternetConnectionManager::NewL( iDb->Database(), EFalse );
   158     iConnection = CInternetConnectionManager::NewL( iDb->Database(), EFalse );
   168 #ifdef BRDO_WRT_HS_FF    
   159 #ifdef BRDO_WRT_HS_FF    
   169     iCpsPublisher = CCpsPublisher::NewL();
   160     iCpsPublisher = CCpsPublisher::NewL();
   170 #endif
   161 #endif
       
   162     
       
   163     iNetworkListener = CWidgetUiNetworkListener::NewL( *this );
   171     }
   164     }
   172 
   165 
   173 // -----------------------------------------------------------------------------
   166 // -----------------------------------------------------------------------------
   174 // CWidgetUiWindowManager::NewL
   167 // CWidgetUiWindowManager::NewL
   175 // Two-phased constructor
   168 // Two-phased constructor
   194 // -----------------------------------------------------------------------------
   187 // -----------------------------------------------------------------------------
   195 //
   188 //
   196 CWidgetUiWindowManager::~CWidgetUiWindowManager()
   189 CWidgetUiWindowManager::~CWidgetUiWindowManager()
   197     {
   190     {
   198     iWindowList.ResetAndDestroy();
   191     iWindowList.ResetAndDestroy();
       
   192     
       
   193     delete iNetworkListener;
   199 
   194 
   200     // TODO Why there is a "Disconnect" method in the first place...
   195     // TODO Why there is a "Disconnect" method in the first place...
   201     // RHandleBase::Close() should be enough?
   196     // RHandleBase::Close() should be enough?
   202     if ( iServerConnected )
   197     if ( iServerConnected )
   203         {
   198         {
   225 // CWidgetUiWindowManager::DeactivateMiniViewL()
   220 // CWidgetUiWindowManager::DeactivateMiniViewL()
   226 // Stop MiniView. Stops publishing and exits widget
   221 // Stop MiniView. Stops publishing and exits widget
   227 //
   222 //
   228 // -----------------------------------------------------------------------------
   223 // -----------------------------------------------------------------------------
   229 //
   224 //
   230 void CWidgetUiWindowManager::DeactivateMiniViewL( const TUid& aUid )
   225 TBool CWidgetUiWindowManager::DeactivateMiniViewL( const TUid& aUid )
   231     {
   226     {
   232     CWidgetUiWindow* wdgt_window = GetWindow(aUid);
   227     CWidgetUiWindow* wdgt_window = GetWindow(aUid);
   233     
   228     
   234     if(!wdgt_window)
   229     if(!wdgt_window)
   235         return ;
   230         return EFalse;
   236     wdgt_window->SetWindowStateMiniViewL( EMiniViewEnabled );
   231     wdgt_window->SetWindowStateMiniViewL( EMiniViewEnabled );
   237     SuspendWidget( aUid );
       
   238 
   232 
   239     // TODO also other states are possible when we should react?
   233     // TODO also other states are possible when we should react?
   240 
   234 
   241     // Removing . Miniview, shall remove full view as well. For blanket permissions
   235     // Removing . Miniview, shall remove full view as well. For blanket permissions
   242     // will be revoked for miniview
   236     // will be revoked for miniview
   243 
   237 
   244     iClientSession.SetBlanketPermissionL( aUid, EFalse );
   238     iClientSession.SetBlanketPermissionL( aUid, EBlanketUnknown );
   245     iClientSession.SetMiniViewL( aUid, EFalse );
   239     iClientSession.SetMiniViewL( aUid, EFalse );
   246     CloseWindow( wdgt_window );
   240     return CloseWindow( wdgt_window );
   247     }
   241     }
   248 
   242 
   249 // -----------------------------------------------------------------------------
   243 // -----------------------------------------------------------------------------
   250 // CWidgetUiWindowManager::ActivateMiniView()
   244 // CWidgetUiWindowManager::ActivateMiniView()
   251 // Start publishing offscreenbitmap  to HS.
   245 // Start publishing offscreenbitmap  to HS.
   269             iClientSession.SetMiniViewL( aUid, ETrue );
   263             iClientSession.SetMiniViewL( aUid, ETrue );
   270 
   264 
   271             HideWindow( iActiveFsWindow );
   265             HideWindow( iActiveFsWindow );
   272             //This is done to prevent offscreen bit map overlap 
   266             //This is done to prevent offscreen bit map overlap 
   273             //when widget selected from FSW
   267             //when widget selected from FSW
   274             wdgt_window->Engine()->MakeVisible( EFalse );       
   268             wdgt_window->Engine()->MakeVisible( EFalse );                    
   275                      
       
   276             if ( !iClientSession.IsBlanketPermGranted ( aUid) )
       
   277                 {
       
   278                 AllowPlatformAccessL(aUid);
       
   279                 }
       
   280             else 
       
   281                 { 
       
   282                 wdgt_window->SetBlanketPromptDisplayed(ETrue); 
       
   283                 ResumeWidgetL(aUid); 
       
   284  		        }                 
       
   285             }
   269             }
   286         
   270         
   287         res = ETrue;
   271         res = ETrue;
   288         }
   272         }
   289         
   273         
   298 //
   282 //
   299 void CWidgetUiWindowManager::HandleWidgetCommandL( 
   283 void CWidgetUiWindowManager::HandleWidgetCommandL( 
   300     const TUid& aUid,
   284     const TUid& aUid,
   301     TUint32 aOperation )
   285     TUint32 aOperation )
   302     {
   286     {
       
   287     TBool exit( EFalse );
       
   288     TBool needToNotify (ETrue) ;
   303     switch ( aOperation )
   289     switch ( aOperation )
   304         {
   290         {
   305         case LaunchFullscreen:
   291         case LaunchFullscreen:
   306         case LaunchMiniview:
   292         case LaunchMiniview:
   307             {
   293             {
   308             OpenOrCreateWindowL( aUid, aOperation );
   294             OpenOrCreateWindowL( aUid, aOperation );
   309             }
   295             }
   310             break;
   296             break;
   311         case Deactivate:
   297         case Deactivate:
   312             {
   298             {
   313             DeactivateMiniViewL( aUid );
   299             exit = DeactivateMiniViewL( aUid );
   314             }
   300             }
   315             break;
   301             break;
   316         case WidgetResume:
   302         case WidgetResume:
   317             {
   303             {
       
   304             needToNotify = GetWindow(aUid) ? ETrue: EFalse;
   318             ResumeWidgetL( aUid );
   305             ResumeWidgetL( aUid );
   319             }
   306             }
   320             break;
   307             break;
   321         case WidgetSuspend:
   308         case WidgetSuspend:
   322             {
   309             {
   323             SuspendWidget( aUid );
   310             SuspendWidget( aUid );
   324             }
   311             }
   325             break;
   312             break;
   326         case WidgetSelect:
   313         case WidgetSelect:
   327             {
   314             {            	
   328             // If we don't have window we know that WidgetUI has died
   315             // If we don't have window we know that WidgetUI has died
   329             // We must enable miniview state
   316             // We must enable miniview state
   330             if( !GetWindow( aUid ))
   317             if( !GetWindow(aUid))
   331                 {
   318                 {        
   332                 OpenOrCreateWindowL( aUid, LaunchMiniview );
   319                 needToNotify = EFalse;
       
   320                 CanWindowBeCreated( aUid, aOperation );
       
   321                 break;
   333                 }
   322                 }
   334             //WidgetLauncher modified to bring app to foreground
   323             //WidgetLauncher modified to bring app to foreground
   335             OpenOrCreateWindowL( aUid, LaunchFullscreen );
   324             GetWindow( aUid)->IncrementClickCount();
       
   325             OpenOrCreateWindowL( aUid, LaunchFullscreen );            
   336             }
   326             }
   337             break;
   327             break;
   338         }
   328         case WidgetOnline:
   339     }
   329             {
   340     
   330             iNetworkMode = EOnlineMode;
       
   331             GetWindow( aUid )->DetermineNetworkState();
       
   332             }
       
   333             break;
       
   334        case WidgetOffline:
       
   335             {
       
   336             iNetworkMode = EOfflineMode;
       
   337             // if no full view widgets open, then close the network connection
       
   338             if ( ( !FullViewWidgetsOpen() ) && ( iConnection->Connected() ) )
       
   339                 {
       
   340                 CWidgetUiWindow* wdgt_window( GetWindow( aUid ) );
       
   341                 wdgt_window->Engine()->HandleCommandL( 
       
   342                         (TInt)TBrCtlDefs::ECommandIdBase +
       
   343                         (TInt)TBrCtlDefs::ECommandDisconnect );
       
   344                 iConnection->StopConnectionL();
       
   345                 }
       
   346             GetWindow( aUid )->DetermineNetworkState();
       
   347             }
       
   348             break;
       
   349        case WidgetRestart:
       
   350            {
       
   351            OpenOrCreateWindowL( aUid, LaunchMiniview );
       
   352            ResumeWidgetL( aUid );
       
   353            }
       
   354            break;
       
   355         }
       
   356     if(needToNotify)
       
   357     // Widget is up and running, notify that next one can be launched    
       
   358     	NotifyCommandHandled();
       
   359     
       
   360     if( exit )
       
   361         {
       
   362         iAppUi.Exit();
       
   363         }
       
   364     }
       
   365 
       
   366 // ------------------------------------------------------------------------
       
   367 // CWidgetUiWindowManager::CanWindowBeCreated()
       
   368 // Check for availaibilty for window creation
       
   369 //
       
   370 // ------------------------------------------------------------------------
       
   371 //
       
   372 void CWidgetUiWindowManager::CanWindowBeCreated(const TUid& aUid, TUint32 aOperation)
       
   373     {
       
   374     CRequestRAM* requestRam = CRequestRAM::StartLD(this, aUid, aOperation);
       
   375     }
       
   376 
       
   377 // ------------------------------------------------------------------------
       
   378 // CWidgetUiWindowManager::OpenOrCreateWindowL()
       
   379 // Open or create widget window
       
   380 //
       
   381 // ------------------------------------------------------------------------
       
   382 //
   341 void CWidgetUiWindowManager::OpenOrCreateWindowL( 
   383 void CWidgetUiWindowManager::OpenOrCreateWindowL( 
   342     const TUid& aUid,
   384     const TUid& aUid,
   343     TUint32 aOperation )
   385     TUint32 aOperation )
   344     {
   386     {
   345     CWidgetUiWindow* wdgt_window( GetWindow( aUid ) );
   387     CWidgetUiWindow* wdgt_window( GetWindow( aUid ) );
   434         
   476         
   435         if( setFullViewState )
   477         if( setFullViewState )
   436             {
   478             {
   437             iActiveFsWindow = wdgt_window;
   479             iActiveFsWindow = wdgt_window;
   438             iActiveFsWindow->SetWindowStateFullView(ETrue);
   480             iActiveFsWindow->SetWindowStateFullView(ETrue);
   439             iActiveFsWindow->SetCurrentWindow( ETrue );
   481             
   440             if ( iActiveFsWindow->Engine()->Rect() != View()->ClientRect())
   482             if ( iActiveFsWindow->Engine()->Rect() != View()->ClientRect())
   441                 {
   483                 {
   442                 iActiveFsWindow->Engine()->SetRect( View()->ClientRect() );
   484                 iActiveFsWindow->Engine()->SetRect( View()->ClientRect() );
   443                 }
   485                 }
       
   486             iActiveFsWindow->SetCurrentWindow( ETrue ); 
       
   487             iActiveFsWindow->Engine()->SetFocus(ETrue);
   444             //iActiveFsWindow->Engine()->MakeVisible( ETrue );
   488             //iActiveFsWindow->Engine()->MakeVisible( ETrue );
   445             
   489             
   446             }
   490             }
   447         }
   491         }
   448     iClientSession.SetActive( aUid, ETrue );
   492     iClientSession.SetActive( aUid, ETrue );
   449     }
   493     }
   450 
   494 
   451 // =============================================================================
   495 // =============================================================================
   452 // CWidgetUiWindowManager::AllowPlatformAccessL()
       
   453 // Prompt for network access allow
       
   454 //
       
   455 // =============================================================================
       
   456 //
       
   457 void CWidgetUiWindowManager::AllowPlatformAccessL( const TUid& aUid )
       
   458     {
       
   459     CWidgetUiWindow* wdgt_window( GetWindow( aUid ) );
       
   460     if( !wdgt_window)
       
   461         return ;
       
   462      
       
   463     HBufC* confirmationText = StringLoader::LoadLC(R_WIDGETUI_PLEASE_WORK);
       
   464     TInt softKey = R_AVKON_SOFTKEYS_OK_CANCEL;
       
   465     CGlobalQueryHandlerAO* tmp = NULL;
       
   466     TRAP_IGNORE(  tmp = CGlobalQueryHandlerAO::StartLD( *this, *wdgt_window , confirmationText->Des(), softKey ) );
       
   467     CleanupStack::PopAndDestroy(confirmationText);  
       
   468     }
       
   469 
       
   470 // =============================================================================
       
   471 // CWidgetUiWindowManager::GetWindow()
   496 // CWidgetUiWindowManager::GetWindow()
   472 // return the window of a widget with a particular url
   497 // return the window of a widget with a particular url
   473 //
   498 //
   474 // =============================================================================
   499 // =============================================================================
   475 //
   500 //
   509 // CWidgetUiWindowManager::CloseWindow()
   534 // CWidgetUiWindowManager::CloseWindow()
   510 // close window of widget
   535 // close window of widget
   511 //
   536 //
   512 // =============================================================================
   537 // =============================================================================
   513 //
   538 //
   514 void CWidgetUiWindowManager::CloseWindow( CWidgetUiWindow* aWidgetWindow )
   539 TBool CWidgetUiWindowManager::CloseWindow( CWidgetUiWindow* aWidgetWindow )
   515     {
   540     {
   516 
   541 
   517     TBool lastOne( iWindowList.Count() == 1 );
   542     TBool lastOne( iWindowList.Count() == 1 );
   518     
   543     TBool ret( EFalse );
   519     RemoveFromWindowList( aWidgetWindow );
   544     ret = RemoveFromWindowList( aWidgetWindow );
   520      
   545      
   521     if ( !lastOne )
   546     if ( !lastOne )
   522         {
   547         {
   523         // Starting JS timer, since we stopped it for deactivating miniview widget
   548         // Starting JS timer, since we stopped it for deactivating miniview widget
   524         CWidgetUiWindow* window = iWindowList[iWindowList.Count() - 1];
   549         CWidgetUiWindow* window = iWindowList[iWindowList.Count() - 1];
   530         for ( TInt i = 0; i < iWindowList.Count(); ++i )// Fix needed. Do we need onShow here.
   555         for ( TInt i = 0; i < iWindowList.Count(); ++i )// Fix needed. Do we need onShow here.
   531             {
   556             {
   532             CWidgetUiWindow* window( iWindowList[i] );
   557             CWidgetUiWindow* window( iWindowList[i] );
   533             if ( window->WidgetMiniViewState() == EPublishStart )
   558             if ( window->WidgetMiniViewState() == EPublishStart )
   534                 {
   559                 {
   535 				TRAP_IGNORE (window->WidgetExtension()->HandleCommandL(
   560                     TRAP_IGNORE (window->WidgetExtension()->HandleCommandL(
   536 				                (TInt)TBrCtlDefs::ECommandAppForeground +   
   561                                    (TInt)TBrCtlDefs::ECommandAppForeground + 
   537 								(TInt)TBrCtlDefs::ECommandIdBase));  
   562                                    (TInt)TBrCtlDefs::ECommandIdBase));
   538 
   563 
   539                     break;
   564                     break;
   540                 }
   565                 }
   541             }
   566             }
   542 
   567 
   543         }
   568         }
       
   569     return ret;
   544     }
   570     }
   545 
   571 
   546 // =============================================================================
   572 // =============================================================================
   547 // CWidgetUiWindowManager::RemoveFromWindowList()
   573 // CWidgetUiWindowManager::RemoveFromWindowList()
   548 // remove widget window from window list
   574 // remove widget window from window list
   549 //
   575 //
   550 // =============================================================================
   576 // =============================================================================
   551 //
   577 //
   552 void CWidgetUiWindowManager::RemoveFromWindowList( CWidgetUiWindow* aWidgetWindow )
   578 TBool CWidgetUiWindowManager::RemoveFromWindowList( CWidgetUiWindow* aWidgetWindow )
   553     {
   579     {
   554     __ASSERT_DEBUG( aWidgetWindow, User::Invariant() );
   580     __ASSERT_DEBUG( aWidgetWindow, User::Invariant() );
   555     if ( iDialogsProvider->IsDialogLaunched() )
   581     if ( iDialogsProvider->IsDialogLaunched() )
   556         {
   582         {
   557         return;
   583         return EFalse;
   558         }
   584         }
   559 
   585 
   560     if ( iClientSession.IsWidgetInFullView ( aWidgetWindow->Uid()))
   586     if ( iClientSession.IsWidgetInFullView ( aWidgetWindow->Uid()))
   561         {
   587         {
   562         HideWindow( aWidgetWindow );
   588         HideWindow( aWidgetWindow );
   572     TRAP_IGNORE(iClientSession.SetFullViewL( aWidgetWindow->Uid(), EFalse ));
   598     TRAP_IGNORE(iClientSession.SetFullViewL( aWidgetWindow->Uid(), EFalse ));
   573     iClientSession.SetActive( aWidgetWindow->Uid(), EFalse );
   599     iClientSession.SetActive( aWidgetWindow->Uid(), EFalse );
   574 
   600 
   575     iWindowList.Remove( iWindowList.Find( aWidgetWindow ) );
   601     iWindowList.Remove( iWindowList.Find( aWidgetWindow ) );
   576     TBool lastOne( iWindowList.Count() == 0 );
   602     TBool lastOne( iWindowList.Count() == 0 );
       
   603     TRAP_IGNORE( aWidgetWindow->Engine()->HandleCommandL( 
       
   604             (TInt)TBrCtlDefs::ECommandIdBase +
       
   605             (TInt)TBrCtlDefs::ECommandCancelFetch ) );   
   577     if ( lastOne )
   606     if ( lastOne )
   578         {
   607         {
   579         TRAP_IGNORE( aWidgetWindow->Engine()->HandleCommandL( 
   608         TRAP_IGNORE( aWidgetWindow->Engine()->HandleCommandL( 
   580                 (TInt)TBrCtlDefs::ECommandIdBase +
   609                 (TInt)TBrCtlDefs::ECommandIdBase +
   581                 (TInt)TBrCtlDefs::ECommandDisconnect ) );
   610                 (TInt)TBrCtlDefs::ECommandDisconnect ) );
   582 
   611 
   583         delete aWidgetWindow;
   612         delete aWidgetWindow;
   584         iAppUi.Exit();
   613         return ETrue;
   585         }
   614         }
   586     else
   615     else
   587         {
   616         {
   588         delete aWidgetWindow;
   617         delete aWidgetWindow;
   589         }
   618         }
   590     }
   619     return EFalse;
   591 
   620     }
   592 // =============================================================================
   621 
   593 // CWidgetUiWindowManager::CloseWindow()
   622 // =============================================================================
   594 // close window of widget with a particular Uid
   623 // CWidgetUiWindowManager::CloseWindowWithLeastClick()
   595 //
   624 // return true for the last widgets  to be closed
   596 // =============================================================================
   625 //
   597 //
   626 // =============================================================================
   598 void CWidgetUiWindowManager::CloseWindow( const TUid& aUid )
   627 //
   599     {
   628 TBool CWidgetUiWindowManager::CloseWindowWithLeastClick()
   600     CWidgetUiWindow* widgetWindow = GetWindow( aUid );
   629     {
   601     CloseWindow( widgetWindow );
   630    
   602     }
   631     TInt temp(iWindowList[0]->GetClickCount());
   603 
   632     TInt err(KErrNone);
   604 // =============================================================================
   633     CWidgetUiWindow* windowToBeClosed(NULL);
   605 // CWidgetUiWindowManager::CloseAllWindowsExceptCurrent()
   634     TTime currentTime;
   606 // close all window except the current widget
   635     currentTime.HomeTime();    
   607 //
   636     TTimeIntervalSeconds  seconds;
   608 // =============================================================================
   637     for ( TInt i = 0; i < iWindowList.Count(); i++ )
   609 //
   638         {
   610 void CWidgetUiWindowManager::CloseAllWindowsExceptCurrent()
   639         CWidgetUiWindow* window = iWindowList[i];        
   611     {
   640         err = currentTime.SecondsFrom(window->GetTime(),seconds);
   612     TInt idx(0);
   641         if ( window->GetClickCount() <= temp && window != iActiveFsWindow &&  
   613     SuspendAllWidget();
   642              (err == KErrOverflow || seconds.Int() > KOOMWidgetCloseTimeOut))
   614     while (iWindowList.Count() > 1)
   643             {
   615         {
   644             temp  = window->GetClickCount();
   616         CWidgetUiWindow* window = iWindowList[idx];
   645             windowToBeClosed = window;
   617         TRAP_IGNORE(iClientSession.SetMiniViewL( window->Uid(), EFalse ));
   646             }
   618         if(CheckIfWindowNeedsToBeClosed(window))
   647         else if( window == iActiveFsWindow )
   619             {
   648             {
   620             RemoveFromWindowList( window );
   649             if ( window->WidgetMiniViewState() == EPublishStart ||
   621             }
   650                  window->WidgetMiniViewState() == EPublishSuspend )
   622         else
   651                 {
   623             {
   652                 // Incase when the widget is active and as in full as well as miniview. 
   624             idx++;// skip ActiveWindow
   653                 // it will stop publishing
   625             }
   654                 TRAP_IGNORE(window->SetWindowStateMiniViewL( EMiniViewEnabled ));
   626         }
   655                 }
   627     }
   656             }
   628 
   657         }
   629 // =============================================================================
   658         if ( windowToBeClosed)
   630 // CWidgetUiWindowManager::CheckIfWindowNeedsToBeClosed()
   659             {
   631 // return true for the widgets that needs to be closed
   660             return RemoveFromWindowList(windowToBeClosed);
   632 //
   661             }
   633 // =============================================================================
   662 
   634 //
   663     return EFalse;
   635 TBool CWidgetUiWindowManager::CheckIfWindowNeedsToBeClosed(CWidgetUiWindow* aWindow) const
   664     }
   636     {
       
   637     __ASSERT_DEBUG( aWindow, User::Invariant() );
       
   638 
       
   639     if( aWindow == iActiveFsWindow )
       
   640         {
       
   641         if ( aWindow->WidgetMiniViewState() == EPublishStart ||
       
   642              aWindow->WidgetMiniViewState() == EPublishSuspend )
       
   643             {
       
   644             // Incase when the widget is active and as in full as well as miniview. 
       
   645             // it will stop publishing
       
   646             TRAP_IGNORE(aWindow->SetWindowStateMiniViewL( EMiniViewEnabled ));
       
   647             }
       
   648         return EFalse;
       
   649         }
       
   650     return ETrue;
       
   651     }
       
   652 
       
   653 // =============================================================================
   665 // =============================================================================
   654 // CWidgetUiWindowManager::Exit()
   666 // CWidgetUiWindowManager::Exit()
   655 // Exit from widget and close widget window
   667 // Exit from widget and close widget window
   656 //
   668 //
   657 // =============================================================================
   669 // =============================================================================
   659 void CWidgetUiWindowManager::Exit( TInt aCommand, const TUid& aUid )
   671 void CWidgetUiWindowManager::Exit( TInt aCommand, const TUid& aUid )
   660     {
   672     {
   661     CWidgetUiWindow* window( GetWindow( aUid ) );
   673     CWidgetUiWindow* window( GetWindow( aUid ) );
   662     if( !window )
   674     if( !window )
   663         return;
   675         return;
       
   676         
       
   677     if ( window->WidgetExtension() )
       
   678         {
       
   679         if ( window->WidgetExtension()->HandleCommandL( aCommand ) )
       
   680             return;    
       
   681         }
       
   682     
   664     if( ( window->WidgetMiniViewState() == EMiniViewEnabled ) ||
   683     if( ( window->WidgetMiniViewState() == EMiniViewEnabled ) ||
   665         ( window->WidgetMiniViewState() == EMiniViewNotEnabled ) ) 
   684         ( window->WidgetMiniViewState() == EMiniViewNotEnabled ) ) 
   666         {
   685         {
   667         // The widget is not publishing.
   686         // The widget is not publishing.
   668         if ( window->WidgetExtension() )
   687         TBool isOkToExit = CloseWindow( window );
   669             {
   688         if ( isOkToExit)
   670             if ( window->WidgetExtension()->HandleCommandL( aCommand ) )
   689             iAppUi.Exit();
   671                 return;
       
   672             }
       
   673 
       
   674         CloseWindow( window );
       
   675         if( window == iActiveFsWindow)
       
   676             iActiveFsWindow = NULL;
       
   677         }
   690         }
   678     else
   691     else
   679         {
   692         {
   680         ExitPublishingWidget( aUid );
   693         // Since widget is in miniview we just push the widget app to background and
   681         }
   694         // set the window status
   682     }
   695         SendWidgetToBackground( aUid );
   683 
   696         }
   684 // =============================================================================
   697     }
   685 // CWidgetUiWindowManager::ExitPublishingWidget()
   698 
   686 // Exit from widget in full view when it is publishing
   699 // =============================================================================
   687 //
   700 // CWidgetUiWindowManager::SendWidgetToBackground()
   688 // =============================================================================
   701 // Push the widget to background and set the window status
   689 //
   702 //
   690 void CWidgetUiWindowManager::ExitPublishingWidget( const TUid& aUid )
   703 // =============================================================================
       
   704 //
       
   705 void CWidgetUiWindowManager::SendWidgetToBackground( const TUid& aUid )
   691     {
   706     {
   692     CWidgetUiWindow* window( GetWindow( aUid ) );
   707     CWidgetUiWindow* window( GetWindow( aUid ) );
   693     if( !window )
   708     if( !window )
   694         return;
   709         return;
   695 
   710 
   696     // make widgets act like separate applications by pushing to background
   711     // make widgets act like separate applications by pushing to background
   697     // this way user is sent back to app shell or idle to run another widget
   712     // this way user is sent back to app shell or idle to run another widget
   698     iAppUi.SendAppToBackground();
   713     iAppUi.SendAppToBackground();
   699 
   714     if ( window == iActiveFsWindow )
   700     if ( iWindowList.Count() == 0 )
   715         {
   701         {
   716         //make the active window NULL and also CurrentWindow as False
   702         iAppUi.Exit(); //TODO Check if it is required for publishin widget
   717         iActiveFsWindow->SetIsCurrentWindow(EFalse);
   703         }
   718         iActiveFsWindow = NULL;        
       
   719         }        
       
   720 
   704     window->Engine()->MakeVisible( EFalse );
   721     window->Engine()->MakeVisible( EFalse );
   705     window->SetWindowStateFullView( EFalse );
   722     window->SetWindowStateFullView( EFalse );
   706     //  Add registry info
   723     //  Add registry info
   707     TRAP_IGNORE(iClientSession.SetFullViewL( window->Uid(), EFalse ));
   724     TRAP_IGNORE(iClientSession.SetFullViewL( window->Uid(), EFalse ));
   708     }
   725     }
   815         }
   832         }
   816     }
   833     }
   817 
   834 
   818 // -----------------------------------------------------------------------------
   835 // -----------------------------------------------------------------------------
   819 // CWidgetUiWindowManager::HandleOOMEventL
   836 // CWidgetUiWindowManager::HandleOOMEventL
   820 // called when out of memory message is received by app ui
   837 // called to display  notification for out of memory when message is received 
       
   838 // by app ui
   821 //
   839 //
   822 // -----------------------------------------------------------------------------
   840 // -----------------------------------------------------------------------------
   823 //
   841 //
   824 void CWidgetUiWindowManager::HandleOOMEventL( TBool /*aForeground*/ )
   842 void CWidgetUiWindowManager::HandleOOMEventL( TBool /*aForeground*/ )
   825     {
   843     {
       
   844     if ( iNotifyOOMFlagTimer)
       
   845         return;
       
   846     
   826     HBufC* message = StringLoader::LoadLC( R_WIDGETUI_OOM_EVENT );
   847     HBufC* message = StringLoader::LoadLC( R_WIDGETUI_OOM_EVENT );
   827     CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote( ETrue );
   848     
   828     note->ExecuteLD(*message );
   849     TInt NoteId (-1);
       
   850     CAknGlobalNote* dialog = CAknGlobalNote::NewLC();
       
   851     NoteId = dialog->ShowNoteL( EAknGlobalInformationNote, *message);
       
   852     User::After(KOOMNotificationDialogTimeOut);
       
   853     dialog->CancelNoteL(NoteId);
       
   854 
       
   855     CleanupStack::PopAndDestroy(dialog);
   829     CleanupStack::PopAndDestroy( message );// message
   856     CleanupStack::PopAndDestroy( message );// message
   830     
   857     
   831     CloseWindowsAsync( ETrue );// close all widgets
   858     iNotifyOOMFlagTimer = CPeriodic::NewL(CActive::EPriorityLow);
       
   859     iNotifyOOMFlagTimer->Start(KOOMNotificationDialogIntervalTimeOut,0,TCallBack(&doDestructOOMNotifyTimer,this));
       
   860     }
       
   861  
       
   862 TInt doDestructOOMNotifyTimer( TAny* ptr )
       
   863     {
       
   864     CWidgetUiWindowManager* temp = static_cast<CWidgetUiWindowManager*>(ptr);
       
   865     if(temp)
       
   866         {
       
   867         temp->DeleteOOMNotifyTimer();                         
       
   868         }
       
   869     return EFalse;
   832     }
   870     }
   833 
   871 
   834 // -----------------------------------------------------------------------------
   872 // -----------------------------------------------------------------------------
   835 // CWidgetUiWindowManager::CloseWindowsAsync
   873 // CWidgetUiWindowManager::CloseWindowsAsync
   836 // close all windows or current window async
   874 // close all windows or current window async
   882 //
   920 //
   883 void CWidgetUiWindowManager::ResumeWidgetL( const TUid& aUid )
   921 void CWidgetUiWindowManager::ResumeWidgetL( const TUid& aUid )
   884     {
   922     {
   885     CWidgetUiWindow* wdgt_window( GetWindow( aUid ) );
   923     CWidgetUiWindow* wdgt_window( GetWindow( aUid ) );
   886     
   924     
       
   925     if ( iNetworkMode == EUnknownMode )
       
   926         {
       
   927         TInt HSOnlineMode = GetCenrepHSModeL();
       
   928         if (HSOnlineMode)
       
   929             {
       
   930             iNetworkMode = EOnlineMode;
       
   931             }
       
   932         else
       
   933             {
       
   934             iNetworkMode = EOfflineMode;
       
   935             }
       
   936         }
       
   937     
   887     // Window can be null if WidgetUI has been killed due to low memory situation
   938     // Window can be null if WidgetUI has been killed due to low memory situation
   888     //__ASSERT_DEBUG( wdgt_window, User::Invariant() );
   939     //__ASSERT_DEBUG( wdgt_window, User::Invariant() );
   889     if(!wdgt_window || !wdgt_window->GetBlanketPromptDisplayed())
   940     if(!wdgt_window)
   890         return;
   941         {
   891     
   942         //LAUNCH WIDGET Window
       
   943         CanWindowBeCreated(aUid,WidgetResume);		
       
   944 		return;
       
   945     	}
       
   946     
       
   947     // reload widget now moved to resume for miniview widgets, to be called 
       
   948     // after determining online/offline mode
       
   949     if ( !(wdgt_window->IsWidgetLoaded() || wdgt_window->IsWidgetLoadStarted()) )
       
   950         {
       
   951         wdgt_window->ReloadWidget();
       
   952         }
       
   953 		
   892     if( (wdgt_window ->WidgetMiniViewState() == EMiniViewEnabled) ||
   954     if( (wdgt_window ->WidgetMiniViewState() == EMiniViewEnabled) ||
   893         (wdgt_window->WidgetMiniViewState() == EPublishSuspend) )
   955         (wdgt_window->WidgetMiniViewState() == EPublishSuspend) )
   894         {
   956         {
   895         //HideWindow( iActiveFsWindow );
   957         //Widgets on HS cannnot be active
   896         //iActiveFsWindow = NULL;
   958         iActiveFsWindow = NULL;
   897         // Publish should start only after widget is resumed.
   959         // Publish should start only after widget is resumed.
   898         wdgt_window->SetWindowStateMiniViewL(EPublishStart);
   960         wdgt_window->SetWindowStateMiniViewL(EPublishStart);
   899 
   961 
   900         wdgt_window->Engine()->HandleCommandL( 
   962         wdgt_window->Engine()->HandleCommandL( 
   901             (TInt)TBrCtlDefs::ECommandAppForeground + 
   963             (TInt)TBrCtlDefs::ECommandAppForeground + 
   902             (TInt)TBrCtlDefs::ECommandIdBase);
   964             (TInt)TBrCtlDefs::ECommandIdBase);
   903 
   965 
   904         wdgt_window->WidgetExtension()->HandleCommandL(
   966         wdgt_window->WidgetExtension()->HandleCommandL(
   905             (TInt)TBrCtlDefs::ECommandAppForeground + 
   967             (TInt)TBrCtlDefs::ECommandAppForeground + 
   906             (TInt)TBrCtlDefs::ECommandIdBase);
   968             (TInt)TBrCtlDefs::ECommandIdBase);
   907 #ifdef BRDO_WRT_HS_FF  
   969 #ifdef BRDO_WRT_HS_FF 
       
   970         wdgt_window->Engine()->MakeVisible( EFalse );
   908         wdgt_window->Engine()->SetRect( iCpsPublisher->BitmapSize());
   971         wdgt_window->Engine()->SetRect( iCpsPublisher->BitmapSize());
   909 #endif
   972 #endif
   910         }
   973         }
   911     }
   974     }
   912 
   975 
   937 void CWidgetUiWindowManager::HideWindow( CWidgetUiWindow* aWindow )
  1000 void CWidgetUiWindowManager::HideWindow( CWidgetUiWindow* aWindow )
   938     {
  1001     {
   939     if ( aWindow )
  1002     if ( aWindow )
   940         {
  1003         {
   941         // Hide the previously active widget.
  1004         // Hide the previously active widget.
   942         aWindow->SetCurrentWindow(EFalse);
  1005         aWindow->SetCurrentWindow(EFalse);        
   943         /*        
       
   944             if( iActiveFsWindow->WidgetMiniViewState() == EPublishSuspend ) 
       
   945                 {
       
   946                 iClientSession.SetFullView( aWindow->Uid(), EFalse );
       
   947                 aWindow->SetWindowStateFullView( EFalse );   
       
   948                 }
       
   949            */     
       
   950         }
  1006         }
   951     }
  1007     }
   952  
  1008  
   953 // ------------------------------------------------------------------------
  1009 // ------------------------------------------------------------------------
   954 // CWidgetUiWindowManager::IsWidgetAllowedL
  1010 // CWidgetUiWindowManager::IsWidgetAllowedL
  1032     CleanupStack::Pop( window );
  1088     CleanupStack::Pop( window );
  1033     
  1089     
  1034     // reset the display orientation when the widget is launched
  1090     // reset the display orientation when the widget is launched
  1035     iAppUi.SetDisplayAuto();
  1091     iAppUi.SetDisplayAuto();
  1036 
  1092 
  1037     window->ReloadWidget();
  1093     // reload widget only for full view widgets
       
  1094     if ( iClientSession.IsWidgetInFullView(aUid) )
       
  1095         {
       
  1096         window->ReloadWidget();
       
  1097         }
  1038     
  1098     
  1039     return window;
  1099     return window;
  1040     }
  1100     }
  1041     
  1101     
  1042 // ------------------------------------------------------------------------
  1102 // ------------------------------------------------------------------------
  1058     }
  1118     }
  1059 
  1119 
  1060 void CWidgetUiWindowManager::ShowWindow( CWidgetUiWindow* aWindow )
  1120 void CWidgetUiWindowManager::ShowWindow( CWidgetUiWindow* aWindow )
  1061     {
  1121     {
  1062     if ( !aWindow )
  1122     if ( !aWindow )
       
  1123         {
       
  1124         iAppUi.SendAppToBackground();
  1063         return;
  1125         return;
       
  1126         }
  1064     if ( aWindow != iActiveFsWindow )
  1127     if ( aWindow != iActiveFsWindow )
  1065         {
  1128         {
  1066         HideWindow( iActiveFsWindow );
  1129         HideWindow( iActiveFsWindow );
  1067         }
  1130         }
  1068         
  1131         
  1069     iActiveFsWindow = aWindow;
  1132     iActiveFsWindow = aWindow;
  1070     iActiveFsWindow->SetCurrentWindow( ETrue );
  1133     iActiveFsWindow->SetCurrentWindow( ETrue );
  1071     iActiveFsWindow->Engine()->MakeVisible( ETrue );
  1134     iActiveFsWindow->Engine()->MakeVisible( ETrue );
  1072     }
  1135     }
  1073 
  1136 // ------------------------------------------------------------------------
  1074 // ------------------------------------------------------------------------
  1137 // CWidgetUiWindowManager::DeleteOOMNotifyTimer
  1075 // CGlobalQueryHandlerAO::StartLD
  1138 //
  1076 //
  1139 // ------------------------------------------------------------------------
  1077 // Initialize AO.
  1140     
  1078 // ------------------------------------------------------------------------
  1141 void CWidgetUiWindowManager::DeleteOOMNotifyTimer()
  1079 CGlobalQueryHandlerAO* CGlobalQueryHandlerAO::StartLD(
  1142     {
  1080     CWidgetUiWindowManager& aManager,
  1143     iNotifyOOMFlagTimer->Cancel();
  1081     CWidgetUiWindow& aWindow,
  1144     delete iNotifyOOMFlagTimer;
  1082     const TDesC& aMessage, 
  1145     iNotifyOOMFlagTimer = NULL;
  1083     TInt aSoftkeys)
  1146     }
  1084     {
  1147     
  1085     CGlobalQueryHandlerAO* self( new( ELeave ) CGlobalQueryHandlerAO( aManager, aWindow, aMessage, aSoftkeys) );
  1148 void CWidgetUiWindowManager::StartHarvesterNotifyTimer()
  1086     TRAPD(error, self->ShowGlobalQueryDialogL ( aMessage, aSoftkeys ));
  1149 {
  1087     if ( error )
  1150     if(iNotifyHarvester)
  1088         {
  1151         DeleteHarvesterNotifyTimer();
  1089         delete self;
  1152     iNotifyHarvester = CPeriodic::NewL(CActive::EPriorityLow);
  1090         User::Leave(error);
  1153     iNotifyHarvester->Start(KOOMHarvesterNotificationTimeOut,0,TCallBack(&doNotifyHarvester,this));
  1091         }
  1154 }
  1092     self->SetActive();
  1155 
  1093     self->iScheduler.Start();
  1156 TInt doNotifyHarvester( TAny* ptr )
  1094     return self;
  1157 {
  1095     }
  1158     NotifyCommandHandled();
  1096 
  1159     CWidgetUiWindowManager* temp = static_cast<CWidgetUiWindowManager*>(ptr);
  1097 // ------------------------------------------------------------------------
  1160     if(temp)
  1098 // CGlobalQueryHandlerAO::CGlobalQueryHandlerAO
  1161         temp->DeleteHarvesterNotifyTimer();
  1099 //
  1162     return EFalse;    
  1100 // Constructor.
  1163 }
  1101 // ------------------------------------------------------------------------
  1164 
  1102 CGlobalQueryHandlerAO::CGlobalQueryHandlerAO(
  1165 void CWidgetUiWindowManager::DeleteHarvesterNotifyTimer()
  1103     CWidgetUiWindowManager& aManager,
  1166 {
  1104     CWidgetUiWindow& aWindow,
  1167     iNotifyHarvester->Cancel();
  1105     const TDesC& aMessage, 
  1168     delete iNotifyHarvester;
  1106     TInt aSoftkeys):CActive( EPriorityHigh ),
  1169     iNotifyHarvester = NULL;    
  1107     iWindow ( aWindow ), 
  1170 }
  1108     iManager(aManager),
  1171 
  1109     iConfirmationText(aMessage.AllocL())
  1172 // ------------------------------------------------------------------------
  1110     {
  1173 // CWidgetUiWindowManager::GetCenrepHSModeL
       
  1174 //
       
  1175 // Determine the homescreen network mode (online/offline) from the cenrep
       
  1176 // ------------------------------------------------------------------------
       
  1177 TInt CWidgetUiWindowManager::GetCenrepHSModeL()
       
  1178     {
       
  1179     TInt value( 0 );
       
  1180     CRepository* rep( NULL );
       
  1181     TRAPD( cenrepError, rep = CRepository::NewL( TUid::Uid( KCRUidActiveIdleLV ) ) );
       
  1182     if ( KErrNone == cenrepError )
       
  1183         {
       
  1184         (void)rep->Get( KAIWebStatus, value );
       
  1185         }
       
  1186     delete rep;
       
  1187     
       
  1188     return value;
       
  1189     }
       
  1190 
       
  1191 // ------------------------------------------------------------------------
       
  1192 // CWidgetUiWindowManager::FullViewWidgetsOpen
       
  1193 //
       
  1194 // Checks if any full view widgets are open 
       
  1195 // ------------------------------------------------------------------------
       
  1196 TBool CWidgetUiWindowManager::FullViewWidgetsOpen()
       
  1197     {
       
  1198     for ( TInt i = 0; i < iWindowList.Count(); ++i )
       
  1199         {
       
  1200         CWidgetUiWindow* window( iWindowList[i] );
       
  1201         if ( ( window->WidgetFullViewState() ) && ( !iClientSession.IsWidgetInMiniView( window->Uid() ) ) )
       
  1202             {
       
  1203             return ETrue;
       
  1204             }
       
  1205         }
       
  1206     
       
  1207     return EFalse;
       
  1208     }
       
  1209 
       
  1210 // ------------------------------------------------------------------------
       
  1211 // CWidgetUiWindowManager::NotifyConnecionChange
       
  1212 //
       
  1213 // Notify widgets of a network connection change 
       
  1214 // ------------------------------------------------------------------------
       
  1215 void CWidgetUiWindowManager::NotifyConnecionChange( TBool aConn )
       
  1216     {
       
  1217     iNetworkConnected = aConn;
       
  1218     for ( TInt i = 0; i < iWindowList.Count(); ++i )
       
  1219         {
       
  1220         CWidgetUiWindow* window( iWindowList[i] );
       
  1221         window->DetermineNetworkState();
       
  1222         }
       
  1223     }
       
  1224 
       
  1225 #ifdef OOM_WIDGET_CLOSEALL
       
  1226 // ------------------------------------------------------------------------
       
  1227 // CWidgetUiWindowManager::CloseAllWidgetsUnderOOM
       
  1228 //
       
  1229 // In case of OOM closes all widgets. 
       
  1230 // ------------------------------------------------------------------------
       
  1231 TBool  CWidgetUiWindowManager::CloseAllWidgetsUnderOOM()
       
  1232     {
       
  1233     TInt temp(0);
       
  1234     TInt err(KErrNone);
       
  1235     CWidgetUiWindow* windowToBeClosed(NULL);
       
  1236     TTime currentTime;
       
  1237     currentTime.HomeTime();    
       
  1238     TTimeIntervalSeconds  seconds;
       
  1239     TInt nCountWidgetClosed = 0;
       
  1240     TBool bAllWindowsClosed = ETrue;
       
  1241       
       
  1242     TInt nWidgetsCount = iWindowList.Count();
       
  1243     for ( TInt i = (nWidgetsCount-1); i >= 0; i-- )
       
  1244         {
       
  1245         CWidgetUiWindow* window = iWindowList[i];        
       
  1246         err = currentTime.SecondsFrom(iTimeLastWidgetOpen,seconds);
       
  1247         if ( err == KErrOverflow || seconds.Int() > KOOMWidgetCloseTimeOut)
       
  1248            {
       
  1249            windowToBeClosed = window;
       
  1250            if ( windowToBeClosed)
       
  1251                {
       
  1252                RemoveFromWindowList(windowToBeClosed);
       
  1253                nCountWidgetClosed++;
       
  1254                }
       
  1255            }
       
  1256         }
       
  1257     if(nWidgetsCount == nCountWidgetClosed)
       
  1258         {
       
  1259         bAllWindowsClosed = ETrue;
       
  1260         }
       
  1261     else
       
  1262         {
       
  1263         bAllWindowsClosed = EFalse;
       
  1264         }
       
  1265     return bAllWindowsClosed;
       
  1266     }
       
  1267  
       
  1268 #endif  //OOM_WIDGET_CLOSEALL    
       
  1269 
       
  1270 void CWidgetUiWindowManager::SendAppToBackground()
       
  1271     {
       
  1272     iAppUi.SendAppToBackground();    
       
  1273     }
       
  1274     
       
  1275 CRequestRAM::CRequestRAM(CWidgetUiWindowManager* aWidgetUiWindowManager, const TUid& aUid, TUint32 aOperation):
       
  1276     CActive( EPriorityStandard ),
       
  1277     iOperation(aOperation),
       
  1278     iUid(aUid),
       
  1279     iWidgetUiWindowManager(aWidgetUiWindowManager)
       
  1280     {
       
  1281 	}
       
  1282 	
       
  1283 CRequestRAM* CRequestRAM::StartLD(CWidgetUiWindowManager* aWidgetUiWindowManager, const TUid& aUid, TUint32 aOperation)
       
  1284     {
       
  1285      CRequestRAM* self = new ( ELeave ) CRequestRAM(aWidgetUiWindowManager, aUid, aOperation); 
       
  1286      CleanupStack::PushL( self );
       
  1287      self->ConstructL();
       
  1288      CleanupStack::Pop();
       
  1289      return self;
       
  1290     }
       
  1291     
       
  1292 void CRequestRAM::ConstructL()
       
  1293     {
       
  1294     User::LeaveIfError(iOomSession.Connect());
  1111     CActiveScheduler::Add( this );
  1295     CActiveScheduler::Add( this );
  1112     }
  1296 #ifdef FF_OOM_MONITOR2_COMPONENT
  1113 
  1297     iOomSession.RequestOptionalRam(KMemoryToCreateWidgetWindow, KMemoryToCreateWidgetWindow, KUidWidgetOOMPlugin, iStatus);
  1114 // ------------------------------------------------------------------------
  1298     SetActive();
  1115 // CGlobalQueryHandlerAO::CGlobalQueryHandlerAO
  1299 #else
  1116 //
  1300     TMemoryInfoV1Buf  info;
  1117 // ISet network and platofrom access permission based on user response.
  1301     UserHal::MemoryInfo (info);                
  1118 // ------------------------------------------------------------------------
  1302     TInt err = info().iFreeRamInBytes > KMemoryToCreateWidgetWindow ? KErrNone : KErrNoMemory;   
  1119 void CGlobalQueryHandlerAO::RunL()
  1303     SetActive();
  1120     {
  1304     TRequestStatus* status = &iStatus;
  1121     if (iScheduler.IsStarted())
  1305     User::RequestComplete(status, err); 
  1122         {
  1306 #endif
  1123         iScheduler.AsyncStop();
  1307     }
  1124         }
  1308 
  1125     
  1309 void CRequestRAM::RunL()
  1126     RWidgetRegistryClientSession clientSession = iManager.WidgetUIClientSession();	
  1310     {    
  1127     if (iStatus == EAknSoftkeyOk)
  1311     if(iStatus >= 0)
  1128         {
  1312         {        
  1129         clientSession.SetBlanketPermissionL( iWindow.Uid(), ETrue );
  1313         iWidgetUiWindowManager->OpenOrCreateWindowL( iUid, LaunchMiniview );
  1130         }
  1314         iWidgetUiWindowManager->ResumeWidgetL( iUid );
  1131     else if ( iStatus == EAknSoftkeyCancel)
  1315         iWidgetUiWindowManager->GetWindow(iUid)->SetTime();
  1132         {
  1316 #ifdef OOM_WIDGET_CLOSEALL        
  1133         //iWindow.SetNetworkAccessGrant(EDeny);
  1317         iWidgetUiWindowManager->SetLastWidgetRestartTime( iWidgetUiWindowManager->GetWindow(iUid)->GetTime());
  1134         clientSession.SetBlanketPermissionL( iWindow.Uid(), EFalse );
  1318 #endif //OOM_WIDGET_CLOSEALL
  1135         //User::Leave( KErrAccessDenied );
  1319         
  1136         }
  1320         switch ( iOperation )
  1137     iWindow.SetBlanketPromptDisplayed(ETrue); 
  1321             {
  1138 	iManager.ResumeWidgetL(iWindow.Uid());        
  1322             case WidgetSelect:
  1139     delete this;
  1323                 {
  1140     }
  1324                 iWidgetUiWindowManager->GetWindow(iUid)->IncrementClickCount();                
  1141 
  1325                 iWidgetUiWindowManager->OpenOrCreateWindowL( iUid, LaunchFullscreen );
  1142 // ------------------------------------------------------------------------
  1326                 iWidgetUiWindowManager->GetWindow(iUid)->SetWindowStateMiniViewL(EPublishSuspend); 
  1143 // CGlobalQueryHandlerAO::DoCancel
  1327                 }
  1144 //
  1328                 break;
  1145 // Do nothing.
  1329             case WidgetResume:
  1146 // ------------------------------------------------------------------------
  1330                 {                
  1147 void CGlobalQueryHandlerAO::DoCancel()
  1331 
  1148     {
  1332                 }
  1149     if ( iGlobalConfirmationQuery )
  1333                 break;                
  1150         {
  1334             } 
  1151         iGlobalConfirmationQuery->CancelConfirmationQuery();
  1335         iWidgetUiWindowManager->StartHarvesterNotifyTimer();            
  1152         }
  1336         }
  1153     iScheduler.AsyncStop();
  1337     else
  1154     }
  1338         {
  1155 
  1339         NotifyCommandHandled();
  1156 // ------------------------------------------------------------------------
  1340         iWidgetUiWindowManager->SendAppToBackground();  
  1157 // CGlobalQueryHandlerAO::~CGlobalQueryHandlerAO
  1341         iWidgetUiWindowManager->WidgetUIClientSession().SetActive( iUid, EFalse );
  1158 //
  1342         }        
  1159 // Destructor.
  1343     delete this;    
  1160 // ------------------------------------------------------------------------
  1344     }
  1161 CGlobalQueryHandlerAO::~CGlobalQueryHandlerAO()
  1345 
       
  1346 
       
  1347 CRequestRAM::~CRequestRAM()
  1162     {
  1348     {
  1163     Cancel();
  1349     Cancel();
  1164     delete iGlobalConfirmationQuery;
  1350     iOomSession.Close();
  1165     delete iConfirmationText;
  1351     }
  1166     }
  1352 void CRequestRAM::DoCancel()
  1167 
  1353     {
  1168 // ---------------------------------------------------------
  1354     iOomSession.CancelRequestFreeMemory();
  1169 // CGlobalQueryHandlerAO::ShowGlobalQueryDialogL()
  1355     }    
  1170 // ---------------------------------------------------------
       
  1171 // 
       
  1172 void CGlobalQueryHandlerAO::ShowGlobalQueryDialogL(const TDesC& aMessage, TInt aSoftkeys)
       
  1173     {
       
  1174     iGlobalConfirmationQuery = CAknGlobalConfirmationQuery::NewL();
       
  1175     iGlobalConfirmationQuery->ShowConfirmationQueryL
       
  1176                                 (iStatus,
       
  1177                                 aMessage,
       
  1178                                 aSoftkeys);
       
  1179     }
       
  1180 
  1356 
  1181 // End of file
  1357 // End of file
  1182 
       
  1183 
       
  1184 
       
  1185 
       
  1186