widgets/widgetapp/src/WidgetUiWindow.cpp
changeset 10 a359256acfc6
parent 5 10e98eab6f85
child 11 c8a366e56285
equal deleted inserted replaced
5:10e98eab6f85 10:a359256acfc6
    49 // CONSTANTS
    49 // CONSTANTS
    50 static const TUint32 KDummyCommand = 0;
    50 static const TUint32 KDummyCommand = 0;
    51 
    51 
    52 const TUint KWmlNoDefaultAccessPoint = KMaxTUint; // see cenrep setting default -1 as int, here as uint
    52 const TUint KWmlNoDefaultAccessPoint = KMaxTUint; // see cenrep setting default -1 as int, here as uint
    53 const TUint KWmlNoDefaultSnapId = KMaxTUint; // see cenrep setting default -1 as int, here as uint
    53 const TUint KWmlNoDefaultSnapId = KMaxTUint; // see cenrep setting default -1 as int, here as uint
    54 _LIT( KSeparator, ":" );
    54 
    55 // MACROS
    55 // MACROS
    56 
    56 
    57 // LOCAL CONSTANTS AND MACROS
    57 // LOCAL CONSTANTS AND MACROS
    58 
    58 
    59 // MODULE DATA STRUCTURES
    59 // MODULE DATA STRUCTURES
    90 //
    90 //
    91 CWidgetUiWindow::CWidgetUiWindow( CWidgetUiWindowManager& aWindowManager, CCpsPublisher* aCpsPublisher )
    91 CWidgetUiWindow::CWidgetUiWindow( CWidgetUiWindowManager& aWindowManager, CCpsPublisher* aCpsPublisher )
    92     : iWindowManager( aWindowManager ), iCpsPublisher( aCpsPublisher ), iNetworkAccessGrant(EInvalid),
    92     : iWindowManager( aWindowManager ), iCpsPublisher( aCpsPublisher ), iNetworkAccessGrant(EInvalid),
    93       iPreferredOrientation(TBrCtlDefs::EOrientationUndefined),
    93       iPreferredOrientation(TBrCtlDefs::EOrientationUndefined),
    94       iIsCurrent(EFalse), iShowSoftkeys(EFalse), iWidgetLoaded(EFalse),
    94       iIsCurrent(EFalse), iShowSoftkeys(EFalse), iWidgetLoaded(EFalse),
    95       iSchemeProcessing (EFalse),
    95       iSchemeProcessing (EFalse),iClickCount(0), iWidgetLoadStarted(EFalse),
    96       iBlanketPromptDisplayed (EFalse) 
    96       iNetworkState(ENetworkNotAllowed), iUserPermission(ETrue)
    97     {
    97     {
    98     }
    98     }
    99 
    99 
   100 // -----------------------------------------------------------------------------
   100 // -----------------------------------------------------------------------------
   101 // CWidgetUiWindow::ConstructL()
   101 // CWidgetUiWindow::ConstructL()
   169         {
   169         {
   170         SetWindowStateMiniViewL( EMiniViewNotEnabled );
   170         SetWindowStateMiniViewL( EMiniViewNotEnabled );
   171         }
   171         }
   172      
   172      
   173     iDlId = 0;
   173     iDlId = 0;
       
   174     
       
   175     // determine initial widget online/offline network state
       
   176     DetermineNetworkState();
   174     }
   177     }
   175 
   178 
   176 // -----------------------------------------------------------------------------
   179 // -----------------------------------------------------------------------------
   177 // CWidgetUiWindow::~CWidgetUiWindow()
   180 // CWidgetUiWindow::~CWidgetUiWindow()
   178 // Destructor
   181 // Destructor
   193     delete iWidgetBundleId;
   196     delete iWidgetBundleId;
   194     delete iRightSoftKeyLabel;
   197     delete iRightSoftKeyLabel;
   195     delete iLeftSoftKeyLabel;
   198     delete iLeftSoftKeyLabel;
   196     delete iWidgetUiDialogsProviderProxy;
   199     delete iWidgetUiDialogsProviderProxy;
   197     delete iSchemeHandler;
   200     delete iSchemeHandler;
       
   201     delete iMiniviewBitmap;
   198     }
   202     }
   199 
   203 
   200 // -----------------------------------------------------------------------------
   204 // -----------------------------------------------------------------------------
   201 // CWidgetUiWindow::CbaGroup()
   205 // CWidgetUiWindow::CbaGroup()
   202 // returns cba group
   206 // returns cba group
   316     iShowSoftkeys = (aVisible);
   320     iShowSoftkeys = (aVisible);
   317 
   321 
   318     if (CbaGroup())
   322     if (CbaGroup())
   319         {
   323         {
   320         CbaGroup()->MakeVisible( iShowSoftkeys );
   324         CbaGroup()->MakeVisible( iShowSoftkeys );
   321         iWindowManager.View()->UpdateStatusPane();
   325         iWindowManager.View()->UpdateStatusPane( aVisible );
       
   326         //in case CBA keys are disbaled by javascript ,SetToolbarVisibility EFalse,
       
   327         //Since it would take entire screen.Else SetToolbarVisibility to ETrue in Landscape mode
       
   328         iShowSoftkeys?iWindowManager.View()->UpdateToolbar(ETrue):iWindowManager.View()->UpdateToolbar(EFalse);
   322         CbaGroup()->DrawNow();
   329         CbaGroup()->DrawNow();
   323         TRect clientRect = iWindowManager.View()->ClientRect();
   330         TRect clientRect = iWindowManager.View()->ClientRect();
   324         // resize the container to take into account the size of the softkey labels
   331         // resize the container to take into account the size of the softkey labels
   325         // reduction is only needed for portrait mode (softkey on bottom) since landscape
   332         // reduction is only needed for portrait mode (softkey on bottom) since landscape
   326         // mode softkeys don't take up screen real estate
   333         // mode softkeys don't take up screen real estate
   402             }
   409             }
   403         }
   410         }
   404 
   411 
   405     // make sure softkeys are visible before setting the text
   412     // make sure softkeys are visible before setting the text
   406     // CEikButtonGroupContainer::Current() returns NULL if softkeys are not visible
   413     // CEikButtonGroupContainer::Current() returns NULL if softkeys are not visible
   407     SetSoftkeysVisible(ETrue);
   414     SetSoftkeysVisible(iShowSoftkeys);
   408 
   415 
   409     TInt err(KErrNotFound);
   416     TInt err(KErrNotFound);
   410     // check to see if aText is a filename
   417     // check to see if aText is a filename
   411     if (aText.Find(_L(".")) != KErrNotFound)
   418     if (aText.Find(_L(".")) != KErrNotFound)
   412         {
   419         {
   493 //
   500 //
   494 // -----------------------------------------------------------------------------
   501 // -----------------------------------------------------------------------------
   495 //
   502 //
   496 void CWidgetUiWindow::SetCurrentWindow( TBool aCurrent )
   503 void CWidgetUiWindow::SetCurrentWindow( TBool aCurrent )
   497     {
   504     {
   498     if (iIsCurrent != aCurrent && iWindowManager.View())
   505     if (iIsCurrent != aCurrent && iWindowManager.View() && Engine())
   499         {
   506         {
   500         iIsCurrent = aCurrent;
   507         iIsCurrent = aCurrent;
   501 
   508 
   502         iWindowManager.View()->ShowActivatedObject(EFalse); // deactivates any open edit boxes
   509         iWindowManager.View()->UpdateStatusPane(EFalse); // deactivates any open edit boxes
   503 
   510 
   504         if (aCurrent)
   511         if (aCurrent)
   505             {
   512             {
   506             UpdateCba();
   513             UpdateCba();
   507             Engine()->MakeVisible( iWidgetLoaded );
   514             Engine()->MakeVisible( iWidgetLoaded );
   514             iWindowManager.View()->StopDisplayingMenuBar();
   521             iWindowManager.View()->StopDisplayingMenuBar();
   515             //deactivate optionsmenu flag
   522             //deactivate optionsmenu flag
   516             iWindowManager.View()->DeActivateOptionsMenu();
   523             iWindowManager.View()->DeActivateOptionsMenu();
   517             Engine()->MakeVisible(EFalse);// hide the active widget
   524             Engine()->MakeVisible(EFalse);// hide the active widget
   518             }
   525             }
   519         if ( !aCurrent )
   526         if ( !aCurrent &&  (EPublishStart != WidgetMiniViewState()))
       
   527             {
   520             iWidgetExtension->HandleCommandL ( (TInt)TBrCtlDefs::ECommandAppBackground + (TInt)TBrCtlDefs::ECommandIdBase );
   528             iWidgetExtension->HandleCommandL ( (TInt)TBrCtlDefs::ECommandAppBackground + (TInt)TBrCtlDefs::ECommandIdBase );
   521 
   529             Engine()->HandleCommandL( (TInt)TBrCtlDefs::ECommandAppBackground + (TInt)TBrCtlDefs::ECommandIdBase);
       
   530             }
   522         if ( aCurrent )
   531         if ( aCurrent )
   523             {
   532             {
   524             Engine()->HandleCommandL( (TInt)TBrCtlDefs::ECommandAppForeground + (TInt)TBrCtlDefs::ECommandIdBase);
   533             Engine()->HandleCommandL( (TInt)TBrCtlDefs::ECommandAppForeground + (TInt)TBrCtlDefs::ECommandIdBase);
   525             iWidgetExtension->HandleCommandL( (TInt)TBrCtlDefs::ECommandAppForeground + (TInt)TBrCtlDefs::ECommandIdBase );
   534             iWidgetExtension->HandleCommandL( (TInt)TBrCtlDefs::ECommandAppForeground + (TInt)TBrCtlDefs::ECommandIdBase );
   526            }
   535            }
   566 // -----------------------------------------------------------------------------
   575 // -----------------------------------------------------------------------------
   567 //
   576 //
   568 void CWidgetUiWindow::ReloadWidget( )
   577 void CWidgetUiWindow::ReloadWidget( )
   569     {
   578     {
   570     SetWidgetLoaded(EFalse);
   579     SetWidgetLoaded(EFalse);
       
   580     iWidgetLoadStarted = ETrue;
   571     TRAPD(err,iEngine->LoadFileL( iUrl->Des() ));
   581     TRAPD(err,iEngine->LoadFileL( iUrl->Des() ));
   572     if (err != KErrNone)
   582     if (err != KErrNone)
   573         {
   583         {
   574         SetWidgetLoaded(ETrue);
   584         SetWidgetLoaded(ETrue);
       
   585         iWidgetLoadStarted = EFalse;
   575         }
   586         }
   576     }
   587     }
   577 
   588 
   578 // -----------------------------------------------------------------------------
   589 // -----------------------------------------------------------------------------
   579 // CWidgetUiWindow::SetWidgetLoaded()
   590 // CWidgetUiWindow::SetWidgetLoaded()
   599 //
   610 //
   600 // -----------------------------------------------------------------------------
   611 // -----------------------------------------------------------------------------
   601 //
   612 //
   602 void CWidgetUiWindow::PublishSnapShot()
   613 void CWidgetUiWindow::PublishSnapShot()
   603     {
   614     {
   604     if( iWidgetLoaded )
   615     if( iWidgetLoaded && (WidgetMiniViewState() == EPublishStart ) )
   605         {
   616         {
   606 #ifdef BRDO_WRT_HS_FF
   617 #ifdef BRDO_WRT_HS_FF
   607         CFbsBitmap* bitmap( new CFbsBitmap() );
   618 
   608 
   619         if ( !iMiniviewBitmap )
   609         if ( bitmap && iCpsPublisher)
   620             {
   610             {
   621             iMiniviewBitmap = new CFbsBitmap();
   611 
   622             }
       
   623             
       
   624         if ( iMiniviewBitmap && iCpsPublisher)
       
   625             {
   612             TRAP_IGNORE(
   626             TRAP_IGNORE(
   613                (iEngine->TakeSnapshotL( *bitmap ));
   627                (iEngine->TakeSnapshotL( *iMiniviewBitmap ));
   614                 HBufC* publisherName = WidgetIdAndNameLC();
   628                 iCpsPublisher->PublishBitmapL( *iMiniviewBitmap, *iWidgetBundleId );
   615                 RDebug::Printf( "CWidgetUiWindow::PublishSnapShot" );
       
   616                 iCpsPublisher->PublishBitmapL( *bitmap, *publisherName );
       
   617                 CleanupStack::PopAndDestroy( publisherName );
       
   618                 );
   629                 );
   619 
       
   620 
       
   621             delete bitmap;
       
   622             }
   630             }
   623 #endif
   631 #endif
   624         }
   632         }
   625     }
   633     }
   626 
   634 
   627 // -----------------------------------------------------------------------------
   635 
   628 // CWidgetUiWindow::WidgetIdAndNameLC()
       
   629 // Constructs the publisher identifier
       
   630 //
       
   631 // -----------------------------------------------------------------------------
       
   632 //
       
   633 HBufC* CWidgetUiWindow::WidgetIdAndNameLC()
       
   634     {
       
   635 
       
   636     HBufC* widgetBundleName = HBufC::NewLC( KWidgetRegistryVal );
       
   637     TPtr bundleName( widgetBundleName->Des() );
       
   638     GetBundleName( bundleName );
       
   639 
       
   640     HBufC* name = HBufC::NewL( bundleName.Length() + KSeparator().Length() +  iWidgetBundleId->Length() );
       
   641     TPtr namePtr( name->Des());
       
   642     namePtr.Append( *iWidgetBundleId );
       
   643     namePtr.Append( KSeparator );
       
   644     namePtr.Append( bundleName );
       
   645     CleanupStack::PopAndDestroy( widgetBundleName );
       
   646     CleanupStack::PushL( name );
       
   647     return name;
       
   648     }
       
   649 
       
   650 // -----------------------------------------------------------------------------
       
   651 // CWidgetUiWindow::GetBundleName()
       
   652 // Get Bundle name for the current widget Uid
       
   653 //
       
   654 // -----------------------------------------------------------------------------
       
   655 //
       
   656 void CWidgetUiWindow::GetBundleName( TPtr& aBundleName )
       
   657     {
       
   658     RWidgetRegistryClientSession clientSession = iWindowManager.WidgetUIClientSession();
       
   659 
       
   660     clientSession.GetWidgetBundleName( iUid, aBundleName );
       
   661     }
       
   662 
   636 
   663 // -----------------------------------------------------------------------------
   637 // -----------------------------------------------------------------------------
   664 // CWidgetUiWindow::HasMiniviewL()
   638 // CWidgetUiWindow::HasMiniviewL()
   665 // Check whether widget has miniview or not
   639 // Check whether widget has miniview or not
   666 //
   640 //
   681 //
   655 //
   682 // -----------------------------------------------------------------------------
   656 // -----------------------------------------------------------------------------
   683 //
   657 //
   684 TBool CWidgetUiWindow::CheckNetworkAccessL()
   658 TBool CWidgetUiWindow::CheckNetworkAccessL()
   685     {
   659     {
       
   660     // if widgets in offline mode, deny network access
       
   661     if (iWindowManager.GetNetworkMode() == EOfflineMode)
       
   662         {
       
   663         // if widget is in full view, offer user the option to go to online mode
       
   664 #ifdef BRDO_WRT_HS_FF
       
   665         if ( WidgetFullViewState() && WidgetMiniViewState() != EPublishStart )
       
   666             {
       
   667             iCpsPublisher->NetworkConnectionAllowedL();
       
   668             }
       
   669 #endif
       
   670         SetNetworkAccessGrant( EDeny );
       
   671         User::Leave( KErrAccessDenied );
       
   672         }
       
   673     
   686     // begin info.plist (declare EAllowNetworkAccess or EAllowFullAccess ?)
   674     // begin info.plist (declare EAllowNetworkAccess or EAllowFullAccess ?)
   687     RWidgetRegistryClientSession& widgetRegistry
   675     RWidgetRegistryClientSession& widgetRegistry
   688                 = iWindowManager.WidgetUIClientSession();
   676                 = iWindowManager.WidgetUIClientSession();
   689 
   677 
   690     CWidgetPropertyValue* propValue = widgetRegistry.GetWidgetPropertyValueL( iUid, EAllowNetworkAccess );
   678     CWidgetPropertyValue* propValue = widgetRegistry.GetWidgetPropertyValueL(iUid, EAllowNetworkAccess ); 
   691     TInt networkAccess = *propValue;
   679     TInt networkAccess = *propValue;
   692     delete propValue;
   680     delete propValue;
   693     propValue = widgetRegistry.GetWidgetPropertyValueL( iUid, EAllowFullAccess );
   681     propValue = widgetRegistry.GetWidgetPropertyValueL(iUid, EAllowFullAccess );
   694     TInt fullAccess = *propValue;
   682     TInt fullAccess = *propValue;
   695     delete propValue;
   683     delete propValue;
   696     propValue = widgetRegistry.GetWidgetPropertyValueL( iUid, EBlanketPermGranted );
   684  
   697     TInt blanketPermission = *propValue;
   685     if ( !( networkAccess || fullAccess ) )
   698     delete propValue;
       
   699     TInt inMiniView = widgetRegistry.IsWidgetInMiniView( iUid);
       
   700     if ( !( networkAccess || fullAccess )  ||
       
   701         ( inMiniView && !blanketPermission  ))
       
   702         {
   686         {
   703         SetNetworkAccessGrant( EDeny );
   687         SetNetworkAccessGrant( EDeny );
   704         User::Leave( KErrAccessDenied );
   688         User::Leave( KErrAccessDenied );
   705         }
   689         }
   706     SetNetworkAccessGrant( EAllow );
   690     SetNetworkAccessGrant( EAllow );
   732              if ( rep->Get( KWidgetPomptForNetworkAccess, prompt ) )
   716              if ( rep->Get( KWidgetPomptForNetworkAccess, prompt ) )
   733                 {
   717                 {
   734                     prompt = 1; // got error, force prompt
   718                     prompt = 1; // got error, force prompt
   735                 }
   719                 }
   736                 delete rep;
   720                 delete rep;
   737            }
   721             }
   738 
   722         
   739             if ( prompt )
   723             if ( prompt )
   740                 {
   724                 {
   741                 CBrowserDialogsProvider* dialogProvider
   725                 CBrowserDialogsProvider* dialogProvider
   742                             = iWindowManager.DialogsProvider();
   726                             = iWindowManager.DialogsProvider();
   743                 TBool grant = EFalse;
   727                 TBool grant = EFalse;
   746                 HBufC* no = StringLoader::LoadLC( R_WIDGETUI_SOFTKEY_NO );
   730                 HBufC* no = StringLoader::LoadLC( R_WIDGETUI_SOFTKEY_NO );
   747                 grant = dialogProvider->DialogConfirmL( _L(""), *message, *yes, *no );
   731                 grant = dialogProvider->DialogConfirmL( _L(""), *message, *yes, *no );
   748                 CleanupStack::PopAndDestroy( 3 );
   732                 CleanupStack::PopAndDestroy( 3 );
   749                 // save prompt result for session
   733                 // save prompt result for session
   750                 SetNetworkAccessGrant( grant? EAllow : EDeny );
   734                 SetNetworkAccessGrant( grant? EAllow : EDeny );
       
   735                 
       
   736                 CheckUserPermissionChanged( grant );
   751                 }
   737                 }
   752             else
   738             else
   753                 {
   739                 {
   754                 // cenrep setting is no prompt for session
   740                 // cenrep setting is no prompt for session
   755                 SetNetworkAccessGrant( EAllow );
   741                 SetNetworkAccessGrant( EAllow );
   824         {
   810         {
   825         // 2.2. make a connection
   811         // 2.2. make a connection
   826         TInt connFailure = iWindowManager.GetConnection()->StartConnectionL( ETrue );
   812         TInt connFailure = iWindowManager.GetConnection()->StartConnectionL( ETrue );
   827         if (KErrCancel == connFailure)
   813         if (KErrCancel == connFailure)
   828             {
   814             {
   829             // Only if user cancelled, do we treat this as
   815 #ifdef BRDO_WRT_HS_FF
   830             // session deny permission to prevent repeated attempts
   816             iCpsPublisher->NetworkConnectionCancelledL();
   831             SetNetworkAccessGrant( EDeny );
   817 #endif
   832             User::Leave( connFailure );
   818             User::Leave( connFailure );
   833             }
   819             }
   834         else if ( KErrNone != connFailure )
   820         else if ( KErrNone != connFailure )
   835             {
   821             {
   836             // Note: In case of no network signal, user may be prompted
   822             // Note: In case of no network signal, user may be prompted
  1096         }
  1082         }
  1097     CleanupStack::Pop( genericParamList ); // genericParamList
  1083     CleanupStack::Pop( genericParamList ); // genericParamList
  1098     return genericParamList;
  1084     return genericParamList;
  1099     }
  1085     }
  1100 
  1086 
       
  1087 // ---------------------------------------------------------
       
  1088 // CWidgetUiWindow::CheckUserPermissionChanged()
       
  1089 // ---------------------------------------------------------
       
  1090 //
       
  1091 void CWidgetUiWindow::CheckUserPermissionChanged(TBool iCurrUserPerm)
       
  1092     {
       
  1093     if ( iUserPermission != iCurrUserPerm )
       
  1094         {
       
  1095         iUserPermission = iCurrUserPerm;
       
  1096         DetermineNetworkState();
       
  1097         }
       
  1098     }
       
  1099 
       
  1100 // ---------------------------------------------------------
       
  1101 // CWidgetUiWindow::DetermineNetworkState()
       
  1102 // ---------------------------------------------------------
       
  1103 //
       
  1104 void CWidgetUiWindow::DetermineNetworkState()
       
  1105     {
       
  1106     TNetworkState currNetState;
       
  1107     RWidgetRegistryClientSession& widgetRegistry = iWindowManager.WidgetUIClientSession();
       
  1108     TInt inMiniView = widgetRegistry.IsWidgetInMiniView( iUid);
       
  1109     CWidgetPropertyValue* propValue = widgetRegistry.GetWidgetPropertyValueL( iUid, EAllowNetworkAccess ); 
       
  1110     TInt netAccessWdgtProp = *propValue;    // AllowNetworkAccess in the info.plist file
       
  1111     
       
  1112     if ( netAccessWdgtProp && ((inMiniView && (iWindowManager.GetNetworkMode() == (TInt)EOnlineMode)) 
       
  1113                                     || (!inMiniView && iUserPermission)) )
       
  1114         {
       
  1115         if ( iWindowManager.GetNetworkConn() )
       
  1116             {
       
  1117             currNetState = ENetworkAccessible;
       
  1118             }
       
  1119         else
       
  1120             {
       
  1121             currNetState = ENetworkAccessAllowed;
       
  1122             }
       
  1123         }
       
  1124     else
       
  1125         {
       
  1126         currNetState = ENetworkNotAllowed;
       
  1127         }
       
  1128     
       
  1129     if ( iNetworkState != currNetState )
       
  1130         {
       
  1131         iNetworkState = currNetState;
       
  1132         // send the new widget network state to widget engine
       
  1133         iWidgetExtension->SetParamL( TBrCtlDefs::EWidgetNetworkState, (TInt)iNetworkState );
       
  1134         }
       
  1135     }
       
  1136 
  1101 // End of file
  1137 // End of file