widgets/widgetapp/src/WidgetUiWindowManager.cpp
changeset 0 dd21522fd290
child 16 a359256acfc6
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2006, 2008 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:  Manages widget windows, each window display one widget
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "WidgetUiWindowManager.h"
       
    20 #include "WidgetUiWindowView.h"
       
    21 #include "WidgetUiWindowContainer.h"
       
    22 #include "WidgetUiWindow.h"
       
    23 #include "WidgetUiAppUi.h"
       
    24 #include "WidgetInstallerInternalCRKeys.h"
       
    25 #include "SWInstWidgetUid.h"
       
    26 #include "widgetappdefs.rh"
       
    27 #include "Browser_platform_variant.hrh"
       
    28 #ifdef BRDO_WRT_HS_FF
       
    29 #include "cpspublisher.h"
       
    30 #endif
       
    31 
       
    32 #include <WidgetUi.rsg>
       
    33 #include <BrCtlInterface.h>
       
    34 #include <WidgetRegistryConstants.h>
       
    35 #include <centralrepository.h>
       
    36 #include <StringLoader.h>
       
    37 #include <AknNoteDialog.h>
       
    38 #include <BrowserDialogsProvider.h>
       
    39 #include <S32FILE.H>
       
    40 #include <aknnotewrappers.h>
       
    41 #include "cpglobals.h" // CPS string definitions.
       
    42 
       
    43 #include <InternetConnectionManager.h>
       
    44 #include <ActiveApDb.h>
       
    45 
       
    46 
       
    47 /**
       
    48 * Utility class to show the prompt for platform security access.
       
    49 *
       
    50 * The class exists only to provide platform security access prompt
       
    51 * for the widgets which are launched in minview 
       
    52 */
       
    53 class CGlobalQueryHandlerAO : public CActive
       
    54     {
       
    55 public:
       
    56     /**
       
    57     * Startup.
       
    58     *
       
    59     * @param aManager Window Manager.
       
    60     * @param aWindow Window.
       
    61     * @param aMessage Message to be prompted.
       
    62     * @param aSoftkeys for prompt.
       
    63     */
       
    64     static CGlobalQueryHandlerAO* StartLD (
       
    65                             CWidgetUiWindowManager& aManager,
       
    66                             CWidgetUiWindow& aWindow,
       
    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
       
    79     /**
       
    80     * Execute asynchronous operation.
       
    81     */
       
    82     void RunL();
       
    83     
       
    84     /**
       
    85     * Provide cancellation methods.
       
    86     */
       
    87     void DoCancel();
       
    88     
       
    89 private:
       
    90 
       
    91     /**
       
    92     * Constructor.
       
    93     *
       
    94     * @param aManager Manager.
       
    95     * @param aWindow Window.
       
    96     * @param aMessage Message for prompt.
       
    97     * @param aSoftkeys for prompt.
       
    98     */
       
    99     CGlobalQueryHandlerAO (
       
   100             CWidgetUiWindowManager& aManager,
       
   101             CWidgetUiWindow& aWindow,
       
   102             const TDesC& aMessage, 
       
   103             TInt aSoftkeys);
       
   104         
       
   105     /**
       
   106     * Destructor. 
       
   107     *
       
   108     * Private on purpose.
       
   109     */
       
   110     ~CGlobalQueryHandlerAO();
       
   111     
       
   112 private:
       
   113 
       
   114     CWidgetUiWindowManager& iManager;
       
   115     CWidgetUiWindow& iWindow;
       
   116     CAknGlobalConfirmationQuery* iGlobalConfirmationQuery ;
       
   117     CActiveSchedulerWait iScheduler;
       
   118     HBufC* iConfirmationText;
       
   119 
       
   120     };
       
   121 
       
   122 // =============================================================================
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CWidgetUiWindowManager::CWidgetUiWindowManager()
       
   126 // Default constructor
       
   127 //
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 CWidgetUiWindowManager::CWidgetUiWindowManager(CWidgetUiAppUi& aAppUi):
       
   131     iAppUi(aAppUi),
       
   132     iStrictMode(ETrue)
       
   133     {
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CWidgetUiWindowManager::ConstructL()
       
   138 // Symbian constructor
       
   139 //
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 void CWidgetUiWindowManager::ConstructL()
       
   143     {
       
   144     CRepository* cenRep(NULL);
       
   145     
       
   146     CCoeEnv::Static()->FsSession().CreatePrivatePath( EDriveC );
       
   147     // Create the client-side session
       
   148     User::LeaveIfError( iClientSession.Connect() );
       
   149     iServerConnected = ETrue;
       
   150 
       
   151 
       
   152     TRAPD(error,cenRep = CRepository::NewL( TUid::Uid( KSWInstWidgetUIUid ) ));
       
   153     if (!error)
       
   154         {
       
   155         TInt strictMode;
       
   156         if (cenRep->Get( KWidgetInstallerStrictMode, strictMode ) == KErrNone)
       
   157             {
       
   158             iStrictMode = strictMode;
       
   159             }
       
   160         delete cenRep;
       
   161         }
       
   162         
       
   163     iDialogsProvider = CBrowserDialogsProvider::NewL( NULL );
       
   164     iHandler = CDocumentHandler::NewL(CEikonEnv::Static()->Process());
       
   165 
       
   166     iDb = CActiveApDb::NewL( EDatabaseTypeIAP );
       
   167     iConnection = CInternetConnectionManager::NewL( iDb->Database(), EFalse );
       
   168 #ifdef BRDO_WRT_HS_FF    
       
   169     iCpsPublisher = CCpsPublisher::NewL();
       
   170 #endif
       
   171     }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CWidgetUiWindowManager::NewL
       
   175 // Two-phased constructor
       
   176 //
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 CWidgetUiWindowManager* CWidgetUiWindowManager::NewL( CWidgetUiAppUi& aAppUi )
       
   180     {
       
   181     CWidgetUiWindowManager* self = new ( ELeave ) CWidgetUiWindowManager( aAppUi );
       
   182 
       
   183     CleanupStack::PushL( self );
       
   184     self->ConstructL();
       
   185     CleanupStack::Pop( self );
       
   186 
       
   187     return self;
       
   188     }
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CWidgetUiWindowManager::~CWidgetUiWindowManager()
       
   192 // Destructor
       
   193 //
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 CWidgetUiWindowManager::~CWidgetUiWindowManager()
       
   197     {
       
   198     iWindowList.ResetAndDestroy();
       
   199 
       
   200     // TODO Why there is a "Disconnect" method in the first place...
       
   201     // RHandleBase::Close() should be enough?
       
   202     if ( iServerConnected )
       
   203         {
       
   204         iClientSession.Disconnect();
       
   205         }
       
   206         
       
   207     iClientSession.Close();
       
   208     
       
   209     delete iHandler;
       
   210     delete iDialogsProvider;
       
   211 
       
   212     if ( iConnection )
       
   213         {
       
   214         TRAP_IGNORE( iConnection->StopConnectionL() );
       
   215         }
       
   216 
       
   217     delete iConnection;
       
   218 #ifdef BRDO_WRT_HS_FF  
       
   219     delete iCpsPublisher;
       
   220 #endif
       
   221     delete iDb;
       
   222     }
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CWidgetUiWindowManager::DeactivateMiniViewL()
       
   226 // Stop MiniView. Stops publishing and exits widget
       
   227 //
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 void CWidgetUiWindowManager::DeactivateMiniViewL( const TUid& aUid )
       
   231     {
       
   232     CWidgetUiWindow* wdgt_window = GetWindow(aUid);
       
   233     
       
   234     if(!wdgt_window)
       
   235         return ;
       
   236     wdgt_window->SetWindowStateMiniViewL( EMiniViewEnabled );
       
   237     SuspendWidget( aUid );
       
   238 
       
   239     // TODO also other states are possible when we should react?
       
   240 
       
   241     // Removing . Miniview, shall remove full view as well. For blanket permissions
       
   242     // will be revoked for miniview
       
   243 
       
   244     iClientSession.SetBlanketPermissionL( aUid, EFalse );
       
   245     iClientSession.SetMiniViewL( aUid, EFalse );
       
   246     CloseWindow( wdgt_window );
       
   247     }
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CWidgetUiWindowManager::ActivateMiniView()
       
   251 // Start publishing offscreenbitmap  to HS.
       
   252 //
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 TBool CWidgetUiWindowManager::ActivateMiniViewL( 
       
   256     const TUid& aUid, 
       
   257     const TRect& aRect )
       
   258     {
       
   259     TBool res( EFalse );
       
   260     CWidgetUiWindow* wdgt_window( GetWindow( aUid ) );
       
   261     
       
   262     __ASSERT_DEBUG( wdgt_window, User::Invariant() );
       
   263     
       
   264     if ( wdgt_window->WidgetMiniViewState() != EMiniViewNotEnabled )
       
   265         {
       
   266         // We could throw User::Invariant() if state == EPublishStart, but that would be nasty...
       
   267         if ( wdgt_window->WidgetMiniViewState() != EPublishStart )
       
   268             {            
       
   269             iClientSession.SetMiniViewL( aUid, ETrue );
       
   270 
       
   271             HideWindow( iActiveFsWindow );
       
   272             //This is done to prevent offscreen bit map overlap 
       
   273             //when widget selected from FSW
       
   274             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             }
       
   286         
       
   287         res = ETrue;
       
   288         }
       
   289         
       
   290     return res;
       
   291     }
       
   292 
       
   293 // ------------------------------------------------------------------------
       
   294 // CWidgetUiWindowManager::HandleWidgetCommandL()
       
   295 // Open or close widget window
       
   296 //
       
   297 // ------------------------------------------------------------------------
       
   298 //
       
   299 void CWidgetUiWindowManager::HandleWidgetCommandL( 
       
   300     const TUid& aUid,
       
   301     TUint32 aOperation )
       
   302     {
       
   303     switch ( aOperation )
       
   304         {
       
   305         case LaunchFullscreen:
       
   306         case LaunchMiniview:
       
   307             {
       
   308             OpenOrCreateWindowL( aUid, aOperation );
       
   309             }
       
   310             break;
       
   311         case Deactivate:
       
   312             {
       
   313             DeactivateMiniViewL( aUid );
       
   314             }
       
   315             break;
       
   316         case WidgetResume:
       
   317             {
       
   318             ResumeWidgetL( aUid );
       
   319             }
       
   320             break;
       
   321         case WidgetSuspend:
       
   322             {
       
   323             SuspendWidget( aUid );
       
   324             }
       
   325             break;
       
   326         case WidgetSelect:
       
   327             {
       
   328             // If we don't have window we know that WidgetUI has died
       
   329             // We must enable miniview state
       
   330             if( !GetWindow( aUid ))
       
   331                 {
       
   332                 OpenOrCreateWindowL( aUid, LaunchMiniview );
       
   333                 }
       
   334             //WidgetLauncher modified to bring app to foreground
       
   335             OpenOrCreateWindowL( aUid, LaunchFullscreen );
       
   336             }
       
   337             break;
       
   338         }
       
   339     }
       
   340     
       
   341 void CWidgetUiWindowManager::OpenOrCreateWindowL( 
       
   342     const TUid& aUid,
       
   343     TUint32 aOperation )
       
   344     {
       
   345     CWidgetUiWindow* wdgt_window( GetWindow( aUid ) );
       
   346     TBool setFullViewState(EFalse);
       
   347 
       
   348 #ifdef BRDO_WRT_HS_FF
       
   349     TSize miniviewSize( iCpsPublisher->BitmapSize());
       
   350 #else
       
   351     TSize miniviewSize( 0,0 );
       
   352 #endif
       
   353          
       
   354     if( wdgt_window ) 
       
   355         {
       
   356         // This might come from app shell as well where appshell window needs to be resized
       
   357         // then active window should be set
       
   358         //  if active window is there hide it
       
   359         // set the new window as current and active. Chcek if window needs resizing and set the registry as fullView and active
       
   360         // can be checked , we can launch in full view if Rect size is same as view size
       
   361 
       
   362 
       
   363         if ( aOperation == LaunchMiniview )
       
   364             {
       
   365             if ( !ActivateMiniViewL( aUid, miniviewSize ) )
       
   366                 {
       
   367                 wdgt_window = NULL;
       
   368                 }
       
   369             }
       
   370 
       
   371         // If the existing widget is in miniview state, we need to make it full-screen.
       
   372         // Sanity check that we don't have to do anything extra.
       
   373         else 
       
   374             {
       
   375 #ifdef BRDO_WRT_HS_FF
       
   376             //Make sure that all the mini widgets are already suspended
       
   377             SuspendAllWidget();
       
   378 #endif
       
   379             // TODO Combine these methods somewhere in WidgetUiWindow, so it knows
       
   380             // how to tamper its own internal state. For example MakeFullScreen().
       
   381            
       
   382             setFullViewState = ETrue;
       
   383             iClientSession.SetFullViewL( aUid, ETrue );
       
   384             }
       
   385         }
       
   386     else
       
   387         {
       
   388         // Create a new window.
       
   389         if ( !IsWidgetAllowedL( aUid ) )
       
   390             {
       
   391             ShowNoteDialogL( R_WIDGETUI_STRICT_MODE_ACCESS );
       
   392             
       
   393             iAppUi.SendAppToBackground();
       
   394             }
       
   395         else 
       
   396             {
       
   397             // Does the widget support miniviews, in case that is desired?
       
   398             if ( aOperation == LaunchFullscreen || DoesWidgetSupportMiniviewL( aUid ) )
       
   399                 {
       
   400                 if ( aOperation == LaunchFullscreen )
       
   401                     iClientSession.SetFullViewL( aUid, ETrue );
       
   402                 // Create window.
       
   403                 wdgt_window = CreateNewWidgetWindowL( aUid );
       
   404             
       
   405                 if ( aOperation )
       
   406                     {
       
   407                     // Don't care if this returns, we know miniviews are supported.
       
   408                     TRAPD( err, ActivateMiniViewL( aUid, miniviewSize ) );
       
   409                     if ( err )
       
   410                         {
       
   411                         CloseWindow( wdgt_window );
       
   412                         wdgt_window = NULL;
       
   413                         }
       
   414                     }
       
   415                 else
       
   416                     {
       
   417 #ifdef BRDO_WRT_HS_FF
       
   418                     SuspendAllWidget();
       
   419 #endif
       
   420                     setFullViewState = ETrue;
       
   421                    
       
   422                     }
       
   423                 }
       
   424             }
       
   425         }
       
   426         
       
   427     // Windows are up & running. Hopefully.
       
   428     if ( wdgt_window  )
       
   429         {
       
   430         if ( iActiveFsWindow != wdgt_window )
       
   431             {
       
   432             HideWindow( iActiveFsWindow );
       
   433             }
       
   434         
       
   435         if( setFullViewState )
       
   436             {
       
   437             iActiveFsWindow = wdgt_window;
       
   438             iActiveFsWindow->SetWindowStateFullView(ETrue);
       
   439             iActiveFsWindow->SetCurrentWindow( ETrue );
       
   440             if ( iActiveFsWindow->Engine()->Rect() != View()->ClientRect())
       
   441                 {
       
   442                 iActiveFsWindow->Engine()->SetRect( View()->ClientRect() );
       
   443                 }
       
   444             //iActiveFsWindow->Engine()->MakeVisible( ETrue );
       
   445             
       
   446             }
       
   447         }
       
   448     iClientSession.SetActive( aUid, ETrue );
       
   449     }
       
   450 
       
   451 // =============================================================================
       
   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()
       
   472 // return the window of a widget with a particular url
       
   473 //
       
   474 // =============================================================================
       
   475 //
       
   476 CWidgetUiWindow* CWidgetUiWindowManager::GetWindow( const TDesC& aUrl )
       
   477     {
       
   478     for ( TInt i = 0; i < iWindowList.Count(); i++ )
       
   479         {
       
   480         CWidgetUiWindow* window = iWindowList[i];
       
   481         if ( window->Url()->Des() == aUrl )
       
   482             {
       
   483             return window;
       
   484             }
       
   485         }
       
   486     return NULL;
       
   487     }
       
   488 
       
   489 // =============================================================================
       
   490 // CWidgetUiWindowManager::GetWindow()
       
   491 // return the window of a widget with a particular Uid
       
   492 //
       
   493 // =============================================================================
       
   494 //
       
   495 CWidgetUiWindow* CWidgetUiWindowManager::GetWindow( const TUid& aUid )
       
   496     {
       
   497     for ( TInt i = 0; i < iWindowList.Count(); i++ )
       
   498         {
       
   499         CWidgetUiWindow* window = iWindowList[i];
       
   500         if ( window->Uid() == aUid )
       
   501             {
       
   502             return window;
       
   503             }
       
   504         }
       
   505     return NULL;
       
   506     }
       
   507 
       
   508 // =============================================================================
       
   509 // CWidgetUiWindowManager::CloseWindow()
       
   510 // close window of widget
       
   511 //
       
   512 // =============================================================================
       
   513 //
       
   514 void CWidgetUiWindowManager::CloseWindow( CWidgetUiWindow* aWidgetWindow )
       
   515     {
       
   516 
       
   517     TBool lastOne( iWindowList.Count() == 1 );
       
   518     
       
   519     RemoveFromWindowList( aWidgetWindow );
       
   520      
       
   521     if ( !lastOne )
       
   522         {
       
   523         // Starting JS timer, since we stopped it for deactivating miniview widget
       
   524         CWidgetUiWindow* window = iWindowList[iWindowList.Count() - 1];
       
   525         if ( window)
       
   526                TRAP_IGNORE ( window->Engine()->HandleCommandL( 
       
   527                               (TInt)TBrCtlDefs::ECommandAppForeground + 
       
   528                               (TInt)TBrCtlDefs::ECommandIdBase));
       
   529 
       
   530         for ( TInt i = 0; i < iWindowList.Count(); ++i )// Fix needed. Do we need onShow here.
       
   531             {
       
   532             CWidgetUiWindow* window( iWindowList[i] );
       
   533             if ( window->WidgetMiniViewState() == EPublishStart )
       
   534                 {
       
   535 				TRAP_IGNORE (window->WidgetExtension()->HandleCommandL(
       
   536 				                (TInt)TBrCtlDefs::ECommandAppForeground +   
       
   537 								(TInt)TBrCtlDefs::ECommandIdBase));  
       
   538 
       
   539                     break;
       
   540                 }
       
   541             }
       
   542 
       
   543         }
       
   544     }
       
   545 
       
   546 // =============================================================================
       
   547 // CWidgetUiWindowManager::RemoveFromWindowList()
       
   548 // remove widget window from window list
       
   549 //
       
   550 // =============================================================================
       
   551 //
       
   552 void CWidgetUiWindowManager::RemoveFromWindowList( CWidgetUiWindow* aWidgetWindow )
       
   553     {
       
   554     __ASSERT_DEBUG( aWidgetWindow, User::Invariant() );
       
   555     if ( iDialogsProvider->IsDialogLaunched() )
       
   556         {
       
   557         return;
       
   558         }
       
   559 
       
   560     if ( iClientSession.IsWidgetInFullView ( aWidgetWindow->Uid()))
       
   561         {
       
   562         HideWindow( aWidgetWindow );
       
   563         if (aWidgetWindow == iActiveFsWindow)
       
   564             iActiveFsWindow = NULL;
       
   565         // make widgets act like separate applications by pushing to background
       
   566         // when widget is in fullview , this way user is sent back to app shell or idle 
       
   567         // to run another widget
       
   568         iAppUi.SendAppToBackground();
       
   569         }
       
   570 
       
   571     // update the status of the widget to not active.
       
   572     TRAP_IGNORE(iClientSession.SetFullViewL( aWidgetWindow->Uid(), EFalse ));
       
   573     iClientSession.SetActive( aWidgetWindow->Uid(), EFalse );
       
   574 
       
   575     iWindowList.Remove( iWindowList.Find( aWidgetWindow ) );
       
   576     TBool lastOne( iWindowList.Count() == 0 );
       
   577     if ( lastOne )
       
   578         {
       
   579         TRAP_IGNORE( aWidgetWindow->Engine()->HandleCommandL( 
       
   580                 (TInt)TBrCtlDefs::ECommandIdBase +
       
   581                 (TInt)TBrCtlDefs::ECommandDisconnect ) );
       
   582 
       
   583         delete aWidgetWindow;
       
   584         iAppUi.Exit();
       
   585         }
       
   586     else
       
   587         {
       
   588         delete aWidgetWindow;
       
   589         }
       
   590     }
       
   591 
       
   592 // =============================================================================
       
   593 // CWidgetUiWindowManager::CloseWindow()
       
   594 // close window of widget with a particular Uid
       
   595 //
       
   596 // =============================================================================
       
   597 //
       
   598 void CWidgetUiWindowManager::CloseWindow( const TUid& aUid )
       
   599     {
       
   600     CWidgetUiWindow* widgetWindow = GetWindow( aUid );
       
   601     CloseWindow( widgetWindow );
       
   602     }
       
   603 
       
   604 // =============================================================================
       
   605 // CWidgetUiWindowManager::CloseAllWindowsExceptCurrent()
       
   606 // close all window except the current widget
       
   607 //
       
   608 // =============================================================================
       
   609 //
       
   610 void CWidgetUiWindowManager::CloseAllWindowsExceptCurrent()
       
   611     {
       
   612     TInt idx(0);
       
   613     SuspendAllWidget();
       
   614     while (iWindowList.Count() > 1)
       
   615         {
       
   616         CWidgetUiWindow* window = iWindowList[idx];
       
   617         TRAP_IGNORE(iClientSession.SetMiniViewL( window->Uid(), EFalse ));
       
   618         if(CheckIfWindowNeedsToBeClosed(window))
       
   619             {
       
   620             RemoveFromWindowList( window );
       
   621             }
       
   622         else
       
   623             {
       
   624             idx++;// skip ActiveWindow
       
   625             }
       
   626         }
       
   627     }
       
   628 
       
   629 // =============================================================================
       
   630 // CWidgetUiWindowManager::CheckIfWindowNeedsToBeClosed()
       
   631 // return true for the widgets that needs to be closed
       
   632 //
       
   633 // =============================================================================
       
   634 //
       
   635 TBool CWidgetUiWindowManager::CheckIfWindowNeedsToBeClosed(CWidgetUiWindow* aWindow) const
       
   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 // =============================================================================
       
   654 // CWidgetUiWindowManager::Exit()
       
   655 // Exit from widget and close widget window
       
   656 //
       
   657 // =============================================================================
       
   658 //
       
   659 void CWidgetUiWindowManager::Exit( TInt aCommand, const TUid& aUid )
       
   660     {
       
   661     CWidgetUiWindow* window( GetWindow( aUid ) );
       
   662     if( !window )
       
   663         return;
       
   664     if( ( window->WidgetMiniViewState() == EMiniViewEnabled ) ||
       
   665         ( window->WidgetMiniViewState() == EMiniViewNotEnabled ) ) 
       
   666         {
       
   667         // The widget is not publishing.
       
   668         if ( window->WidgetExtension() )
       
   669             {
       
   670             if ( window->WidgetExtension()->HandleCommandL( aCommand ) )
       
   671                 return;
       
   672             }
       
   673 
       
   674         CloseWindow( window );
       
   675         if( window == iActiveFsWindow)
       
   676             iActiveFsWindow = NULL;
       
   677         }
       
   678     else
       
   679         {
       
   680         ExitPublishingWidget( aUid );
       
   681         }
       
   682     }
       
   683 
       
   684 // =============================================================================
       
   685 // CWidgetUiWindowManager::ExitPublishingWidget()
       
   686 // Exit from widget in full view when it is publishing
       
   687 //
       
   688 // =============================================================================
       
   689 //
       
   690 void CWidgetUiWindowManager::ExitPublishingWidget( const TUid& aUid )
       
   691     {
       
   692     CWidgetUiWindow* window( GetWindow( aUid ) );
       
   693     if( !window )
       
   694         return;
       
   695 
       
   696     // 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
       
   698     iAppUi.SendAppToBackground();
       
   699 
       
   700     if ( iWindowList.Count() == 0 )
       
   701         {
       
   702         iAppUi.Exit(); //TODO Check if it is required for publishin widget
       
   703         }
       
   704     window->Engine()->MakeVisible( EFalse );
       
   705     window->SetWindowStateFullView( EFalse );
       
   706     //  Add registry info
       
   707     TRAP_IGNORE(iClientSession.SetFullViewL( window->Uid(), EFalse ));
       
   708     }
       
   709 
       
   710 // =============================================================================
       
   711 // CWidgetUiWindowManager::SetActiveWidgetAtExit()
       
   712 // Set active widget to widget in full view which is not added to homescreen 
       
   713 // incase no such widget is there set it to null
       
   714 //
       
   715 // =============================================================================
       
   716 //
       
   717 void CWidgetUiWindowManager::SetActiveWidgetAtExit()
       
   718     {
       
   719     //Get widget in Fullview that is not publishing and not same as active window
       
   720     for ( TInt i = 0; i < iWindowList.Count(); ++i )
       
   721         {
       
   722         CWidgetUiWindow* window( iWindowList[i] );
       
   723         if ( ( window != iActiveFsWindow ) &&   
       
   724              ( window->WidgetFullViewState() ) )
       
   725             {
       
   726             iActiveFsWindow = window;
       
   727             //ShowWindow( window );
       
   728             return;
       
   729             }
       
   730         }
       
   731         
       
   732     iActiveFsWindow = NULL;
       
   733     }
       
   734 
       
   735 // =============================================================================
       
   736 // CWidgetUiWindowManager::HandleLSKcommandL()
       
   737 // Execute LSK Handler if present
       
   738 //
       
   739 // =============================================================================
       
   740 //
       
   741 TBool CWidgetUiWindowManager::HandleLSKCommandL( TInt aCommand )
       
   742     {
       
   743     if ( iActiveFsWindow && iActiveFsWindow->WidgetExtension() )
       
   744 
       
   745         {
       
   746          return iActiveFsWindow->WidgetExtension()->HandleCommandL( aCommand );
       
   747        }
       
   748     return EFalse;
       
   749 
       
   750     }
       
   751 
       
   752 // =============================================================================
       
   753 // CWidgetUiWindowManager::GetWidgetEntryForUrl()
       
   754 // return Uid of widget with a particular Url
       
   755 //
       
   756 // =============================================================================
       
   757 //
       
   758 TInt CWidgetUiWindowManager::GetWidgetEntryForUrl( const TDesC& aUrl ) //const
       
   759     {
       
   760     return iClientSession.GetWidgetUidForUrl( aUrl );
       
   761     }
       
   762 
       
   763 // -----------------------------------------------------------------------------
       
   764 // CWidgetUiWindowManager::SetDisplayLandscape()
       
   765 // switch the display orientation to landscape
       
   766 //
       
   767 // -----------------------------------------------------------------------------
       
   768 //
       
   769 void CWidgetUiWindowManager::SetDisplayLandscape( )
       
   770     {
       
   771     TRAP_IGNORE(iAppUi.SetDisplayLandscapeL());
       
   772     }
       
   773 
       
   774 // -----------------------------------------------------------------------------
       
   775 // CWidgetUiWindowManager::SetDisplayPortrait()
       
   776 // switch the display orientation to portrait
       
   777 //
       
   778 // -----------------------------------------------------------------------------
       
   779 //
       
   780 void CWidgetUiWindowManager::SetDisplayPortrait( )
       
   781     {
       
   782     TRAP_IGNORE(iAppUi.SetDisplayPortraitL());
       
   783     }
       
   784 
       
   785 // -----------------------------------------------------------------------------
       
   786 // CWidgetUiWindowManager::SetDisplayAuto()
       
   787 // switch the display orientation to device defined
       
   788 //
       
   789 // -----------------------------------------------------------------------------
       
   790 //
       
   791 void CWidgetUiWindowManager::SetDisplayAuto( )
       
   792     {
       
   793     iAppUi.SetDisplayAuto();
       
   794     }
       
   795 
       
   796 // -----------------------------------------------------------------------------
       
   797 // CWidgetUiWindowManager::HandleForegroundEvent
       
   798 // called when application goes to background or comes back to foreground
       
   799 //
       
   800 // This method is called only for "Go to background" events. "Come to foreground"
       
   801 // is filtered away by CWidgetUiAppUi::HandleForegroundEventL .
       
   802 // But we need to check the aForeground value anyway since flipping back and
       
   803 // forth from powersave mode doesn't involve OpenOrCreateWindowL.
       
   804 // -----------------------------------------------------------------------------
       
   805 //
       
   806 void CWidgetUiWindowManager::HandleForegroundEvent( TBool aForeground )
       
   807     {
       
   808     if ( aForeground )
       
   809         {
       
   810         ShowWindow( iActiveFsWindow );
       
   811         }
       
   812     else
       
   813         {
       
   814         HideWindow( iActiveFsWindow );
       
   815         }
       
   816     }
       
   817 
       
   818 // -----------------------------------------------------------------------------
       
   819 // CWidgetUiWindowManager::HandleOOMEventL
       
   820 // called when out of memory message is received by app ui
       
   821 //
       
   822 // -----------------------------------------------------------------------------
       
   823 //
       
   824 void CWidgetUiWindowManager::HandleOOMEventL( TBool /*aForeground*/ )
       
   825     {
       
   826     HBufC* message = StringLoader::LoadLC( R_WIDGETUI_OOM_EVENT );
       
   827     CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote( ETrue );
       
   828     note->ExecuteLD(*message );
       
   829     CleanupStack::PopAndDestroy( message );// message
       
   830     
       
   831     CloseWindowsAsync( ETrue );// close all widgets
       
   832     }
       
   833 
       
   834 // -----------------------------------------------------------------------------
       
   835 // CWidgetUiWindowManager::CloseWindowsAsync
       
   836 // close all windows or current window async
       
   837 //
       
   838 // -----------------------------------------------------------------------------
       
   839 //
       
   840 void CWidgetUiWindowManager::CloseWindowsAsync( TBool aAllWindows )
       
   841     {
       
   842     iAppUi.AsyncExit(aAllWindows);
       
   843     }
       
   844 
       
   845 // -----------------------------------------------------------------------------
       
   846 // CWidgetUiWindowManager::SuspendWidget
       
   847 // Suspend currently publishing widget (if so).
       
   848 //
       
   849 // -----------------------------------------------------------------------------
       
   850 //
       
   851 void CWidgetUiWindowManager::SuspendWidget( const TUid& aUid )
       
   852     {
       
   853     CWidgetUiWindow* wdgt_window = GetWindow(aUid);
       
   854 
       
   855     if(!wdgt_window)
       
   856         return;
       
   857 
       
   858     if( (wdgt_window->WidgetMiniViewState() == EPublishStart) &&
       
   859         (wdgt_window->WidgetMiniViewState() != EPublishSuspend))
       
   860         {
       
   861         TRAP_IGNORE(
       
   862         wdgt_window->SetWindowStateMiniViewL(EPublishSuspend);
       
   863 
       
   864         wdgt_window->WidgetExtension()->HandleCommandL( 
       
   865             (TInt)TBrCtlDefs::ECommandAppBackground + 
       
   866             (TInt)TBrCtlDefs::ECommandIdBase);
       
   867 
       
   868         wdgt_window->Engine()->HandleCommandL( 
       
   869             (TInt)TBrCtlDefs::ECommandAppBackground + 
       
   870             (TInt)TBrCtlDefs::ECommandIdBase);
       
   871             );
       
   872 
       
   873         }
       
   874 
       
   875     }
       
   876 
       
   877 // -----------------------------------------------------------------------------
       
   878 // CWidgetUiWindowManager::ResumeWidget
       
   879 // Resume publishing stuff, in case it is valid for the widget.
       
   880 //
       
   881 // -----------------------------------------------------------------------------
       
   882 //
       
   883 void CWidgetUiWindowManager::ResumeWidgetL( const TUid& aUid )
       
   884     {
       
   885     CWidgetUiWindow* wdgt_window( GetWindow( aUid ) );
       
   886     
       
   887     // Window can be null if WidgetUI has been killed due to low memory situation
       
   888     //__ASSERT_DEBUG( wdgt_window, User::Invariant() );
       
   889     if(!wdgt_window || !wdgt_window->GetBlanketPromptDisplayed())
       
   890         return;
       
   891     
       
   892     if( (wdgt_window ->WidgetMiniViewState() == EMiniViewEnabled) ||
       
   893         (wdgt_window->WidgetMiniViewState() == EPublishSuspend) )
       
   894         {
       
   895         //HideWindow( iActiveFsWindow );
       
   896         //iActiveFsWindow = NULL;
       
   897         // Publish should start only after widget is resumed.
       
   898         wdgt_window->SetWindowStateMiniViewL(EPublishStart);
       
   899 
       
   900         wdgt_window->Engine()->HandleCommandL( 
       
   901             (TInt)TBrCtlDefs::ECommandAppForeground + 
       
   902             (TInt)TBrCtlDefs::ECommandIdBase);
       
   903 
       
   904         wdgt_window->WidgetExtension()->HandleCommandL(
       
   905             (TInt)TBrCtlDefs::ECommandAppForeground + 
       
   906             (TInt)TBrCtlDefs::ECommandIdBase);
       
   907 #ifdef BRDO_WRT_HS_FF  
       
   908         wdgt_window->Engine()->SetRect( iCpsPublisher->BitmapSize());
       
   909 #endif
       
   910         }
       
   911     }
       
   912 
       
   913 // -----------------------------------------------------------------------------
       
   914 // CWidgetUiWindowManager::SuspendAllWidget
       
   915 // SUspend all publishing widgets, if not already done.
       
   916 //
       
   917 // -----------------------------------------------------------------------------
       
   918 //
       
   919 void CWidgetUiWindowManager::SuspendAllWidget()
       
   920     {
       
   921     for ( TInt i = 0; i < iWindowList.Count(); i++ )
       
   922         {
       
   923         CWidgetUiWindow* window = iWindowList[i];
       
   924         if ( window->WidgetMiniViewState() == EPublishStart)
       
   925             {
       
   926             SuspendWidget(window->Uid());
       
   927             }
       
   928         }
       
   929 
       
   930     }
       
   931 
       
   932 // ------------------------------------------------------------------------
       
   933 // CWidgetUiWindowManager::HideWindow
       
   934 //
       
   935 // Hide currently active window.
       
   936 // ------------------------------------------------------------------------
       
   937 void CWidgetUiWindowManager::HideWindow( CWidgetUiWindow* aWindow )
       
   938     {
       
   939     if ( aWindow )
       
   940         {
       
   941         // Hide the previously active widget.
       
   942         aWindow->SetCurrentWindow(EFalse);
       
   943         /*        
       
   944             if( iActiveFsWindow->WidgetMiniViewState() == EPublishSuspend ) 
       
   945                 {
       
   946                 iClientSession.SetFullView( aWindow->Uid(), EFalse );
       
   947                 aWindow->SetWindowStateFullView( EFalse );   
       
   948                 }
       
   949            */     
       
   950         }
       
   951     }
       
   952  
       
   953 // ------------------------------------------------------------------------
       
   954 // CWidgetUiWindowManager::IsWidgetAllowedL
       
   955 // 
       
   956 // Check widget's compatibility for running.
       
   957 // ------------------------------------------------------------------------
       
   958 TBool CWidgetUiWindowManager::IsWidgetAllowedL( 
       
   959     const TUid& aUid ) //const
       
   960     {
       
   961     __UHEAP_MARK;
       
   962     
       
   963     TBool res( EFalse );
       
   964     CWidgetPropertyValue* value( iClientSession.GetWidgetPropertyValueL(
       
   965         aUid, 
       
   966         ENokiaWidget ) );
       
   967     
       
   968     if ( iStrictMode )
       
   969         {
       
   970         if ( *value )
       
   971             {
       
   972             res = ETrue;
       
   973             }
       
   974         }
       
   975     else
       
   976         {
       
   977         res = *value;
       
   978         }
       
   979     
       
   980     delete value;
       
   981     
       
   982     __UHEAP_MARKEND;
       
   983     return res;
       
   984     }
       
   985  
       
   986 // ------------------------------------------------------------------------
       
   987 // CWidgetUiWindowManager::ShowNoteDialogL
       
   988 // 
       
   989 // Show a note to user.
       
   990 // ------------------------------------------------------------------------
       
   991 void CWidgetUiWindowManager::ShowNoteDialogL( TInt aResourceID ) const
       
   992     {
       
   993     CEikDialog* dialog( NULL );
       
   994     HBufC* message( StringLoader::LoadLC( aResourceID ) );
       
   995     
       
   996     dialog = new (ELeave) CAknNoteDialog( 
       
   997             &dialog,
       
   998             CAknNoteDialog::ENoTone, 
       
   999             CAknNoteDialog::ELongTimeout );
       
  1000     
       
  1001     CleanupStack::PushL( dialog );
       
  1002     static_cast< CAknNoteDialog* >( dialog )->SetTextL( *message );
       
  1003     CleanupStack::Pop( dialog );
       
  1004     
       
  1005     CleanupStack::PopAndDestroy( message );
       
  1006     dialog->ExecuteLD(R_WIDGETUI_OK_NOTE);
       
  1007     delete dialog;
       
  1008     dialog = NULL;
       
  1009     }
       
  1010 
       
  1011 // ------------------------------------------------------------------------
       
  1012 // CWidgetUiWindowManager::CreateNewWidgetWindowL
       
  1013 //
       
  1014 // New widget, new window.
       
  1015 // ------------------------------------------------------------------------
       
  1016 CWidgetUiWindow* CWidgetUiWindowManager::CreateNewWidgetWindowL( 
       
  1017     const TUid& aUid )
       
  1018     {
       
  1019 #ifdef BRDO_WRT_HS_FF  
       
  1020     CWidgetUiWindow* window(
       
  1021         CWidgetUiWindow::OpenWindowL( *this, aUid, iCpsPublisher ) );
       
  1022 #else
       
  1023     CWidgetUiWindow* window(
       
  1024         CWidgetUiWindow::OpenWindowL( *this, aUid, NULL ) );
       
  1025 #endif
       
  1026     
       
  1027     CleanupStack::PushL( window );
       
  1028 
       
  1029     // Add it to the queue
       
  1030     iWindowList.AppendL( window );
       
  1031     
       
  1032     CleanupStack::Pop( window );
       
  1033     
       
  1034     // reset the display orientation when the widget is launched
       
  1035     iAppUi.SetDisplayAuto();
       
  1036 
       
  1037     window->ReloadWidget();
       
  1038     
       
  1039     return window;
       
  1040     }
       
  1041     
       
  1042 // ------------------------------------------------------------------------
       
  1043 // CWidgetUiWindowManager::DoesWidgetSupportMiniviewL
       
  1044 //
       
  1045 // Register widget to CPS listener.
       
  1046 // ------------------------------------------------------------------------
       
  1047 TBool CWidgetUiWindowManager::DoesWidgetSupportMiniviewL( const TUid& aUid )
       
  1048     {
       
  1049     __UHEAP_MARK;
       
  1050     CWidgetPropertyValue* val( iClientSession.GetWidgetPropertyValueL( aUid, EMiniViewEnable ) );
       
  1051     TBool res( *val );
       
  1052     
       
  1053     delete val;
       
  1054     
       
  1055     __UHEAP_MARKEND;
       
  1056     
       
  1057     return res;
       
  1058     }
       
  1059 
       
  1060 void CWidgetUiWindowManager::ShowWindow( CWidgetUiWindow* aWindow )
       
  1061     {
       
  1062     if ( !aWindow )
       
  1063         return;
       
  1064     if ( aWindow != iActiveFsWindow )
       
  1065         {
       
  1066         HideWindow( iActiveFsWindow );
       
  1067         }
       
  1068         
       
  1069     iActiveFsWindow = aWindow;
       
  1070     iActiveFsWindow->SetCurrentWindow( ETrue );
       
  1071     iActiveFsWindow->Engine()->MakeVisible( ETrue );
       
  1072     }
       
  1073 
       
  1074 // ------------------------------------------------------------------------
       
  1075 // CGlobalQueryHandlerAO::StartLD
       
  1076 //
       
  1077 // Initialize AO.
       
  1078 // ------------------------------------------------------------------------
       
  1079 CGlobalQueryHandlerAO* CGlobalQueryHandlerAO::StartLD(
       
  1080     CWidgetUiWindowManager& aManager,
       
  1081     CWidgetUiWindow& aWindow,
       
  1082     const TDesC& aMessage, 
       
  1083     TInt aSoftkeys)
       
  1084     {
       
  1085     CGlobalQueryHandlerAO* self( new( ELeave ) CGlobalQueryHandlerAO( aManager, aWindow, aMessage, aSoftkeys) );
       
  1086     TRAPD(error, self->ShowGlobalQueryDialogL ( aMessage, aSoftkeys ));
       
  1087     if ( error )
       
  1088         {
       
  1089         delete self;
       
  1090         User::Leave(error);
       
  1091         }
       
  1092     self->SetActive();
       
  1093     self->iScheduler.Start();
       
  1094     return self;
       
  1095     }
       
  1096 
       
  1097 // ------------------------------------------------------------------------
       
  1098 // CGlobalQueryHandlerAO::CGlobalQueryHandlerAO
       
  1099 //
       
  1100 // Constructor.
       
  1101 // ------------------------------------------------------------------------
       
  1102 CGlobalQueryHandlerAO::CGlobalQueryHandlerAO(
       
  1103     CWidgetUiWindowManager& aManager,
       
  1104     CWidgetUiWindow& aWindow,
       
  1105     const TDesC& aMessage, 
       
  1106     TInt aSoftkeys):CActive( EPriorityHigh ),
       
  1107     iWindow ( aWindow ), 
       
  1108     iManager(aManager),
       
  1109     iConfirmationText(aMessage.AllocL())
       
  1110     {
       
  1111     CActiveScheduler::Add( this );
       
  1112     }
       
  1113 
       
  1114 // ------------------------------------------------------------------------
       
  1115 // CGlobalQueryHandlerAO::CGlobalQueryHandlerAO
       
  1116 //
       
  1117 // ISet network and platofrom access permission based on user response.
       
  1118 // ------------------------------------------------------------------------
       
  1119 void CGlobalQueryHandlerAO::RunL()
       
  1120     {
       
  1121     if (iScheduler.IsStarted())
       
  1122         {
       
  1123         iScheduler.AsyncStop();
       
  1124         }
       
  1125     
       
  1126     RWidgetRegistryClientSession clientSession = iManager.WidgetUIClientSession();	
       
  1127     if (iStatus == EAknSoftkeyOk)
       
  1128         {
       
  1129         clientSession.SetBlanketPermissionL( iWindow.Uid(), ETrue );
       
  1130         }
       
  1131     else if ( iStatus == EAknSoftkeyCancel)
       
  1132         {
       
  1133         //iWindow.SetNetworkAccessGrant(EDeny);
       
  1134         clientSession.SetBlanketPermissionL( iWindow.Uid(), EFalse );
       
  1135         //User::Leave( KErrAccessDenied );
       
  1136         }
       
  1137     iWindow.SetBlanketPromptDisplayed(ETrue); 
       
  1138 	iManager.ResumeWidgetL(iWindow.Uid());        
       
  1139     delete this;
       
  1140     }
       
  1141 
       
  1142 // ------------------------------------------------------------------------
       
  1143 // CGlobalQueryHandlerAO::DoCancel
       
  1144 //
       
  1145 // Do nothing.
       
  1146 // ------------------------------------------------------------------------
       
  1147 void CGlobalQueryHandlerAO::DoCancel()
       
  1148     {
       
  1149     if ( iGlobalConfirmationQuery )
       
  1150         {
       
  1151         iGlobalConfirmationQuery->CancelConfirmationQuery();
       
  1152         }
       
  1153     iScheduler.AsyncStop();
       
  1154     }
       
  1155 
       
  1156 // ------------------------------------------------------------------------
       
  1157 // CGlobalQueryHandlerAO::~CGlobalQueryHandlerAO
       
  1158 //
       
  1159 // Destructor.
       
  1160 // ------------------------------------------------------------------------
       
  1161 CGlobalQueryHandlerAO::~CGlobalQueryHandlerAO()
       
  1162     {
       
  1163     Cancel();
       
  1164     delete iGlobalConfirmationQuery;
       
  1165     delete iConfirmationText;
       
  1166     }
       
  1167 
       
  1168 // ---------------------------------------------------------
       
  1169 // CGlobalQueryHandlerAO::ShowGlobalQueryDialogL()
       
  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 
       
  1181 // End of file
       
  1182 
       
  1183 
       
  1184 
       
  1185 
       
  1186