webengine/osswebengine/WebKit/s60/plugins/PluginSkin.cpp
branchRCL_3
changeset 93 79859ed3eea9
parent 92 e1bea15f9a39
child 94 919f36ff910f
equal deleted inserted replaced
92:e1bea15f9a39 93:79859ed3eea9
    14 * Description:  
    14 * Description:  
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 //INCLUDES
    18 //INCLUDES
    19 #include <Browser_Platform_Variant.hrh>
    19 #include <Browser_platform_variant.hrh>
    20 #include "../../bidi.h"
    20 #include "../../bidi.h"
    21 #include "PlatformString.h"
    21 #include "PlatformString.h"
    22 #include <centralrepository.h>
    22 #include <centralrepository.h>
    23 #include <browseruisdkcrkeys.h>
    23 #include <BrowserUiSDKCRKeys.h>
    24 #include "PluginSkin.h"
    24 #include "PluginSkin.h"
    25 #include "PluginWin.h"
    25 #include "PluginWin.h"
    26 #include "PluginHandler.h"
    26 #include "PluginHandler.h"
    27 #include "PluginStreamLoaderClient.h"
    27 #include "PluginStreamLoaderClient.h"
    28 #include "PluginStream.h"
    28 #include "PluginStream.h"
    31 #include "WebView.h"
    31 #include "WebView.h"
    32 #include "WebPageFullScreenHandler.h"
    32 #include "WebPageFullScreenHandler.h"
    33 #include "BrCtl.h"
    33 #include "BrCtl.h"
    34 #include "WebCoreGraphicsContext.h"
    34 #include "WebCoreGraphicsContext.h"
    35 #include "StaticObjectsContainer.h"
    35 #include "StaticObjectsContainer.h"
    36 #include <brctldefs.h>
    36 #include "BrCtlDefs.h"
    37 #include "SettingsContainer.h"
    37 #include "SettingsContainer.h"
    38 #include <Uri8.h>
    38 #include <uri8.h>
    39 #include <StringLoader.h>
    39 #include <StringLoader.h>
    40 #include <Webkit.rsg>
    40 #include <Webkit.rsg>
    41 #include "Frame.h"
    41 #include "Frame.h"
    42 #include "FrameLoader.h"
    42 #include "FrameLoader.h"
    43 #include "DocumentLoader.h"
    43 #include "DocumentLoader.h"
    44 #include "ResourceRequest.h"
    44 #include "ResourceRequest.h"
    45 #include "Widget.h"
    45 #include "Widget.h"
    46 #include "PlatformScrollBar.h"
    46 #include "PlatformScrollbar.h"
    47 #include "Page.h"
       
    48 #include "FocusController.h"
       
    49 
    47 
    50 #include <ApEngineConsts.h>
    48 #include <ApEngineConsts.h>
    51 #include <Uri8.h>
    49 #include <uri8.h>
    52 #include <internetconnectionmanager.h>
    50 #include <InternetConnectionManager.h>
    53 #include <es_enum.h>
    51 #include <es_enum.h>
       
    52 #include <TextEncoding.h>
       
    53 #include "CString.h"
    54 #include "WidgetExtension.h"
    54 #include "WidgetExtension.h"
    55 #include <widgetregistryclient.h>
    55 #include <WidgetRegistryClient.h>
    56 
       
    57 
    56 
    58 // CONSTANTS
    57 // CONSTANTS
    59 using namespace WebCore;
    58 using namespace WebCore;
    60 // scheme for RTSP url
    59 // scheme for RTSP url
    61 _LIT8(KRtsp, "rtsp");
    60 _LIT8(KRtsp, "rtsp");
    83 _LIT(KUnknownMode, "UnKnownMode");
    82 _LIT(KUnknownMode, "UnKnownMode");
    84 _LIT(KApplicationId,"ApplicationId");
    83 _LIT(KApplicationId,"ApplicationId");
    85 _LIT(KSecMgrScriptSession,"SecMgrScriptSession");
    84 _LIT(KSecMgrScriptSession,"SecMgrScriptSession");
    86 _LIT(KAllowNetworkAccess,"AllowNetworkAccess");
    85 _LIT(KAllowNetworkAccess,"AllowNetworkAccess");
    87 
    86 
    88 #if defined(__PLATFORM_VERSION_32__)
    87 
    89 #define KArraySize 1
       
    90 #else
       
    91 #define KArraySize 3
    88 #define KArraySize 3
    92 #endif
       
    93 
    89 
    94 const TInt32 KWidgetApplicationId =  0x10282822;
    90 const TInt32 KWidgetApplicationId =  0x10282822;
    95 const TInt32 KBrowserApplicationId = 0x10008D39;
    91 const TInt32 KBrowserApplicationId = 0x10008D39;
    96 
    92 
    97 //MACROS
    93 //MACROS
   102 // ----------------------------------------------------------------------------
    98 // ----------------------------------------------------------------------------
   103 // makeAbsoluteUrlL()
    99 // makeAbsoluteUrlL()
   104 // return an absolute url that results from refUrl being resolved against 
   100 // return an absolute url that results from refUrl being resolved against 
   105 // baseUrl.
   101 // baseUrl.
   106 // ----------------------------------------------------------------------------
   102 // ----------------------------------------------------------------------------
   107 HBufC8* makeAbsoluteUrlL(const TDesC8* baseUrl,const TDesC8* docUrl, const TDesC8& refUrl)
   103 HBufC8* makeAbsoluteUrlL(const TDesC8& baseUrl, const TDesC8& refUrl)
   108 {
   104 {
   109     TUriParser8 baseUrlparser;
   105     TUriParser8 baseUrlparser;
   110     if(baseUrl == NULL)
   106     baseUrlparser.Parse(baseUrl); 
   111         baseUrlparser.Parse(*docUrl); 
       
   112     else
       
   113         baseUrlparser.Parse(*baseUrl);
       
   114     TUriParser8 refUrlparser;
   107     TUriParser8 refUrlparser;
   115     refUrlparser.Parse(refUrl); 
   108     refUrlparser.Parse(refUrl); 
   116 
   109 
   117     CUri8* absoluteUrl = CUri8::ResolveL(baseUrlparser, refUrlparser);
   110     CUri8* absoluteUrl = CUri8::ResolveL(baseUrlparser, refUrlparser);
   118     CleanupStack::PushL(absoluteUrl);
   111     CleanupStack::PushL(absoluteUrl);
   160       m_pluginSupported( EFalse ),
   153       m_pluginSupported( EFalse ),
   161       m_pluginClosed(false),
   154       m_pluginClosed(false),
   162       m_canInteract( EFalse ),
   155       m_canInteract( EFalse ),
   163       m_rect(TRect(0,0,0,0)),
   156       m_rect(TRect(0,0,0,0)),
   164       m_ref(1),
   157       m_ref(1),
   165       m_oldRect(TRect(0,0,0,0)),
       
   166       m_oldViewport(TRect(0,0,0,0)),
       
   167       m_NPObject(0),
       
   168       m_handle(-1),
   158       m_handle(-1),
   169       m_instance(0),    
   159       m_instance(0),    
   170       m_pluginfuncs(0),
   160       m_pluginfuncs(0),
   171       m_resized(false)
   161       m_resized(false),
       
   162       m_oldRect(TRect(0,0,0,0)),
       
   163       m_oldViewport(TRect(0,0,0,0))
   172   {
   164   {
   173   }
   165   }
   174 
   166 
   175 
   167 
   176 void PluginSkin::addWidgetAttributesL()
   168 void PluginSkin::addWidgetAttributesL()
   200         NPN_GenericElement ScriptSession(SecMgrScriptSession,scriptSession);
   192         NPN_GenericElement ScriptSession(SecMgrScriptSession,scriptSession);
   201         iGenericElementArray->AppendL(ScriptSession);           
   193         iGenericElementArray->AppendL(ScriptSession);           
   202 #endif
   194 #endif
   203 
   195 
   204         TInt uid = wdgtExt->GetWidgetId();         
   196         TInt uid = wdgtExt->GetWidgetId();         
   205         
       
   206         CWidgetPropertyValue* AccessValue = widgetregistry.GetWidgetPropertyValueL(TUid::Uid(uid), EAllowNetworkAccess ); 
   197         CWidgetPropertyValue* AccessValue = widgetregistry.GetWidgetPropertyValueL(TUid::Uid(uid), EAllowNetworkAccess ); 
   207         TInt networkAccess = AccessValue && *AccessValue;
   198         TInt networkAccess = *AccessValue;
   208         delete AccessValue;
       
   209         
       
   210         const TDesC& allowNetworkAccess = KAllowNetworkAccess();
   199         const TDesC& allowNetworkAccess = KAllowNetworkAccess();
   211         NPN_GenericElement NetworkAccess(allowNetworkAccess,networkAccess);
   200         NPN_GenericElement NetworkAccess(allowNetworkAccess,networkAccess);
   212         iGenericElementArray->AppendL(NetworkAccess);
   201         iGenericElementArray->AppendL(NetworkAccess);
   213     }
   202     }
   214     User::LeaveIfError(widgetregistry.Disconnect());
   203     User::LeaveIfError(widgetregistry.Disconnect());
   406     User::Free(m_instance); m_instance = 0;
   395     User::Free(m_instance); m_instance = 0;
   407     delete m_pluginwin; m_pluginwin = 0;
   396     delete m_pluginwin; m_pluginwin = 0;
   408     delete m_attributeNames; m_attributeNames = 0;
   397     delete m_attributeNames; m_attributeNames = 0;
   409     delete m_attributeValues; m_attributeValues = 0;
   398     delete m_attributeValues; m_attributeValues = 0;
   410     delete m_url; m_url = 0;
   399     delete m_url; m_url = 0;
   411     if(iJavascriptTimer)
   400     delete iJavascriptTimer; iJavascriptTimer = 0;
   412         { 
       
   413         iJavascriptTimer->Cancel();
       
   414         delete iJavascriptTimer; 
       
   415         iJavascriptTimer = 0;
       
   416         }
       
   417     m_pluginfuncs = 0;
   401     m_pluginfuncs = 0;
   418     m_pluginSupported = EFalse;
   402     m_pluginSupported = EFalse;
   419     m_pluginClosed = true;
   403     m_pluginClosed = true;
   420     
       
   421  }
   404  }
   422 
   405 
   423 // ----------------------------------------------------------------------------
       
   424 // PluginSkin::HandleLosingForeground()
       
   425 // PluginSkin function to handle Losing foreground event
       
   426 // ----------------------------------------------------------------------------
       
   427 void PluginSkin::HandleLosingForeground()
       
   428 {
       
   429     if(m_pluginwin) 
       
   430         m_pluginwin->HandleLosingForeground();
       
   431 }
       
   432  
       
   433 // ----------------------------------------------------------------------------
       
   434 // PluginSkin::HandleGainingForeground()
       
   435 // PluginSkin function to handle Gaining foreground event
       
   436 // ----------------------------------------------------------------------------
       
   437 void PluginSkin::HandleGainingForeground()
       
   438 {
       
   439     if(m_pluginwin)
       
   440         m_pluginwin->HandleGainingForeground();
       
   441 }
       
   442 
   406 
   443 // ----------------------------------------------------------------------------
   407 // ----------------------------------------------------------------------------
   444 // PluginSkin::pluginFocusChanged()
   408 // PluginSkin::pluginFocusChanged()
   445 // PluginSkin function to show/hide fullscreen sprite
   409 // PluginSkin function to show/hide fullscreen sprite
   446 // ----------------------------------------------------------------------------
   410 // ----------------------------------------------------------------------------
   496     gc->SetPenStyle( CGraphicsContext::ENullPen );
   460     gc->SetPenStyle( CGraphicsContext::ENullPen );
   497     gc->SetBrushStyle( CGraphicsContext::ENullBrush );
   461     gc->SetBrushStyle( CGraphicsContext::ENullBrush );
   498 
   462 
   499     CFbsBitmap* bitmap = m_cannedimg.m_img;
   463     CFbsBitmap* bitmap = m_cannedimg.m_img;
   500     TSize bmpSize( bitmap->SizeInPixels() );
   464     TSize bmpSize( bitmap->SizeInPixels() );
   501     CWidgetExtension* wdgtExt = control(this->frame()) ? control(this->frame())->getWidgetExt(): NULL;
   465     if ( !m_pluginwin && newRect.Height() >= bmpSize.iHeight && newRect.Width() >= bmpSize.iWidth )
   502     
       
   503     if ( !wdgtExt && !m_pluginwin && newRect.Height() >= bmpSize.iHeight && newRect.Width() >= bmpSize.iWidth )
       
   504         {
   466         {
   505         // The inner rect is big enough, draw the placeholder image
   467         // The inner rect is big enough, draw the placeholder image
   506         TPoint bitmapStartPoint( newRect.Center() );
   468         TPoint bitmapStartPoint( newRect.Center() );
   507         bitmapStartPoint -= TPoint(bmpSize.iWidth/2,bmpSize.iHeight/2);
   469         bitmapStartPoint -= TPoint(bmpSize.iWidth/2,bmpSize.iHeight/2);
   508         gc->BitBltMasked( bitmapStartPoint, m_cannedimg.m_img,
   470         gc->BitBltMasked( bitmapStartPoint, m_cannedimg.m_img,
   509                         bmpSize, m_cannedimg.m_msk, ETrue );
   471                         bmpSize, m_cannedimg.m_msk, ETrue );
   510         }
   472         }
   511     if(m_pluginwin)
   473     if(m_pluginwin)
   512         {
   474         {
   513         //if bitmap is shared from plugins then draw the shared bitmap
   475         positionChanged();
   514         if(m_pluginwin->IsPluginBitMapSet())
   476         // Force the control to be redrawn.
   515             {
   477         m_pluginwin->refreshPlugin(*gc,newRect);
   516             CFbsBitmap* bitmap = m_pluginwin->PluginBitmap();
       
   517             if(bitmap)
       
   518                 {
       
   519                 TRect clippingRect = context.clippingRect();
       
   520                 TRect oldcontextrect = context.clippingRect();
       
   521 
       
   522                 if(newRect != clippingRect)
       
   523                     {
       
   524                     context.setClippingRect(newRect);
       
   525                     }
       
   526                  gc->DrawBitmap(newRect, bitmap);
       
   527                  context.setClippingRect(oldcontextrect);
       
   528                 }
       
   529             else
       
   530                 {
       
   531                 //if not a valid bitmap, then hide that plugin
       
   532                 m_pluginwin->MakeVisible(EFalse);
       
   533                 }
       
   534                 positionChanged();
       
   535             }
       
   536         else
       
   537             {
       
   538             positionChanged();
       
   539             // Force the control to be redrawn, for window less plugins
       
   540             m_pluginwin->refreshPlugin(*gc,newRect);
       
   541             }
       
   542         }
   478         }
   543     }
   479     }
   544 
   480 
   545 // ----------------------------------------------------------------------------
   481 // ----------------------------------------------------------------------------
   546 // PluginSkin::IsVisible
   482 // PluginSkin::IsVisible
   564 // PluginSkin::MakeVisible
   500 // PluginSkin::MakeVisible
   565 // From MWebCoreObjectWidget
   501 // From MWebCoreObjectWidget
   566 // ----------------------------------------------------------------------------
   502 // ----------------------------------------------------------------------------
   567 void PluginSkin::makeVisible( TBool visible )
   503 void PluginSkin::makeVisible( TBool visible )
   568     {
   504     {
   569     // if visible is true for a plugin, make sure that the plugin is actually visible in the window before proceeding 
       
   570     TBool visibility = EFalse;
       
   571     if (visible) {
       
   572         TRect fullRect(getPluginWinRect());
       
   573         TRect clipRect(getClipRect());
       
   574         TRect frameRect(m_frame->frameView()->rect());
       
   575         TRect viewRect = control(m_frame)->webView()->Rect();
       
   576         TBool isPageViewMode = control(m_frame)->webView()->inPageViewMode();
       
   577         WebFrame* pf = m_frame;
       
   578         TPoint p = frameRect.iTl;
       
   579 
       
   580         if (m_frame->parentFrame()) {
       
   581             pf = m_frame->parentFrame();
       
   582             p = pf->frameView()->frameCoordsInViewCoords(frameRect.iTl); 
       
   583         }
       
   584         TSize  sz = pf->frameView()->toViewCoords(frameRect.Size());
       
   585         TRect frameRectInViewCoord = TRect(p, sz);
       
   586         TBool isPluginVisible = frameRectInViewCoord.Intersects(fullRect); 
       
   587         TBool isFrameVisible = m_frame->frameView()->isVisible() && 
       
   588                                 frameRectInViewCoord.Intersects(viewRect);
       
   589         
       
   590         visibility = isFrameVisible && !isPageViewMode && isPluginVisible;
       
   591       
       
   592     }
       
   593     if ( m_pluginwin )
   505     if ( m_pluginwin )
   594         {
   506         {
   595         if (visible && !visibility)
       
   596             visible = EFalse;
       
   597         
       
   598         m_visible = visible;
   507         m_visible = visible;
   599         if(m_active && !visible)
   508         if(m_active)
   600             deActivate();
   509             deActivate();
   601         m_pluginwin->makeVisible(visible);
   510         m_pluginwin->makeVisible(visible);
   602         }
   511         }
   603     }
   512     }
   604 
   513 
   654             TRAP_IGNORE( m_pluginwin->processEventL(EEventActivate, consumed));
   563             TRAP_IGNORE( m_pluginwin->processEventL(EEventActivate, consumed));
   655             if (consumed)
   564             if (consumed)
   656                 {
   565                 {
   657                 m_active = ETrue;
   566                 m_active = ETrue;
   658                 m_frame->frameView()->topView()->setFocusedElementType(TBrCtlDefs::EElementActivatedObjectBox);
   567                 m_frame->frameView()->topView()->setFocusedElementType(TBrCtlDefs::EElementActivatedObjectBox);
   659                 control(m_frame)->webView()->page()->focusController()->setFocusedNode(getElement(), control(m_frame)->webView()->page()->focusController()->focusedOrMainFrame());                        
       
   660                 pluginHandler->setActivePlugin(this);
   568                 pluginHandler->setActivePlugin(this);
   661                 pluginHandler->setPluginToActivate(NULL);
   569                 pluginHandler->setPluginToActivate(NULL);
   662                 }
   570                 }
   663             // Set right soft key
   571             // Set right soft key
   664             m_frame->frameView()->topView()->brCtl()->updateDefaultSoftkeys();
   572             m_frame->frameView()->topView()->brCtl()->updateDefaultSoftkeys();
   740     if (!m_instance) {
   648     if (!m_instance) {
   741         
   649         
   742         NPError error( NPERR_NO_ERROR );
   650         NPError error( NPERR_NO_ERROR );
   743         
   651         
   744         m_instance = (NPP) User::AllocL(sizeof(NPP_t));
   652         m_instance = (NPP) User::AllocL(sizeof(NPP_t));
       
   653         m_instance->ndata = pluginWin();
       
   654         m_instance->pdata = NULL;
       
   655 
   745         if (m_instance) {
   656         if (m_instance) {
   746             m_instance->ndata = pluginWin();
   657             
   747             m_instance->pdata = NULL;            
       
   748             PluginHandler* pluginhandler = WebCore::StaticObjectsContainer::instance()->pluginHandler();
   658             PluginHandler* pluginhandler = WebCore::StaticObjectsContainer::instance()->pluginHandler();
   749             if ( pluginhandler ) {
   659             if ( pluginhandler ) {
   750                 pluginhandler->loadPluginL( m_handle, &m_pluginfuncs );
   660                 pluginhandler->loadPluginL( m_handle, &m_pluginfuncs );
   751         
   661         
   752                 if (m_pluginfuncs && m_pluginfuncs->newp) {        
   662                 if (m_pluginfuncs && m_pluginfuncs->newp) {        
   759                                                     NULL );
   669                                                     NULL );
   760                                                                       
   670                                                                       
   761                 }
   671                 }
   762                 if (m_pluginwin) {
   672                 if (m_pluginwin) {
   763                     m_pluginwin->ConstructL(*(control(m_frame)->webView()));
   673                     m_pluginwin->ConstructL(*(control(m_frame)->webView()));
   764                 }
       
   765             }
   674             }
       
   675         }
   766         }
   676         }
   767 
   677 
   768         switch ( error ) {
   678         switch ( error ) {
   769             case NPERR_OUT_OF_MEMORY_ERROR: {
   679             case NPERR_OUT_OF_MEMORY_ERROR: {
   770                 User::Leave( KErrNoMemory );
   680                 User::Leave( KErrNoMemory );
   772             }
   682             }
   773             case NPERR_GENERIC_ERROR: {
   683             case NPERR_GENERIC_ERROR: {
   774                 User::Leave( KErrNotSupported );
   684                 User::Leave( KErrNotSupported );
   775                 break;
   685                 break;
   776             }
   686             }
   777         }
   687         }    
   778         
   688         
   779         if (m_pluginwin)
   689         if (m_pluginwin)
   780             m_pluginwin->SetExtent( TPoint(0,0), TSize(0,0) );
   690         m_pluginwin->SetExtent( TPoint(0,0), TSize(0,0) );
   781     }
   691             
       
   692     }
       
   693 
   782 }
   694 }
   783 
   695 
   784 // -----------------------------------------------------------------------------
   696 // -----------------------------------------------------------------------------
   785 // PluginSkin::CreatePluginWinL
   697 // PluginSkin::CreatePluginWinL
   786 //
   698 //
   886 
   798 
   887 //callbacks from NpnImplementation  
   799 //callbacks from NpnImplementation  
   888 int PluginSkin::getRequestL(const TDesC8& url, bool notify, void* notifydata,const TDesC* aWindowType)
   800 int PluginSkin::getRequestL(const TDesC8& url, bool notify, void* notifydata,const TDesC* aWindowType)
   889 {
   801 {
   890     TPluginLoadMode loadmode = GetLoadMode(aWindowType);
   802     TPluginLoadMode loadmode = GetLoadMode(aWindowType);
   891     
   803 
   892     if (url.Ptr() == NULL ) {                        
   804     if (url.Ptr() == NULL ) {                        
   893         return KErrArgument;
   805         return KErrArgument;
   894     }
   806     }
   895     
   807 
   896     _LIT8(KJs, "javascript:");
   808     _LIT8(KJs, "javascript:");
   897     if ((url.Length() > KJs().Length() ) &&(url.Left(KJs().Length()).FindF(KJs) == 0)) {
   809     if ((url.Length() > KJs().Length() ) &&(url.Left(KJs().Length()).FindF(KJs) == 0)) {
   898         HBufC* pBuffer = HBufC::NewL(url.Length());
   810         HBufC* pBuffer = HBufC::NewL(url.Length());
   899 	    TPtr16 temp = pBuffer->Des(); 
   811 	    TPtr16 temp = pBuffer->Des(); 
   900 	    temp.Copy(url);
   812 	    temp.Copy(url);
   907          }
   819          }
   908         return KErrNone;
   820         return KErrNone;
   909      }
   821      }
   910 
   822 
   911     // make sure it is an absolute URL
   823     // make sure it is an absolute URL
   912     HBufC8* docUrl = HBufC8::NewLC(core(m_frame)->document()->baseURI().length());
   824     HBufC8* absoluteUrl = makeAbsoluteUrlL(*m_url, url); 
   913     docUrl->Des().Copy(core(m_frame)->document()->baseURI());
       
   914     HBufC8* absoluteUrl = makeAbsoluteUrlL(m_url, docUrl, url); 
       
   915     CleanupStack::PushL(absoluteUrl);
   825     CleanupStack::PushL(absoluteUrl);
   916 
   826 
   917     PluginHandler* pluginHandler = StaticObjectsContainer::instance()->pluginHandler();
   827     if (loadmode == ELoadModePlugin ) {    
   918     if( (loadmode == ELoadModePlugin ) || (loadmode == ELoadModeTop && (pluginHandler->pluginMimeByExtention(url) != NULL)) ){        
   828         
   919         if (m_instance && m_pluginfuncs) {
   829         if (m_instance && m_pluginfuncs) {
   920         
   830         
   921             NetscapePlugInStreamLoaderClient* pluginloader = NetscapePlugInStreamLoaderClient::NewL(url, this, core(m_frame), notifydata, notify);
   831             NetscapePlugInStreamLoaderClient* pluginloader = NetscapePlugInStreamLoaderClient::NewL(url, this, core(m_frame), notifydata);
   922             if (pluginloader) {
   832             if (pluginloader) {
   923                 pluginloader->start();                                          
   833                 pluginloader->start();                            
       
   834 
       
   835                 if ( notify ) {
       
   836                     HBufC* url16 = HBufC::NewLC( url.Length() );
       
   837                     url16->Des().Copy( url );
       
   838                     m_pluginfuncs->urlnotify( m_instance, *url16, NPRES_DONE, notifydata );        
       
   839                     CleanupStack::PopAndDestroy(url16);
       
   840                 }
       
   841                 
   924             }                
   842             }                
   925         }                 
   843         }                 
   926     }
   844     }
   927     else {    
   845     else {    
   928         HBufC* windowType = HBufC::NewLC(aWindowType->Length());
   846         HBufC* windowType = HBufC::NewLC(aWindowType->Length());
   929         windowType->Des().Copy(*aWindowType);
   847         windowType->Des().Copy(*aWindowType);
   930         frame()->loadURL(*absoluteUrl,TBrCtlDefs::ECacheModeNormal,String(),&String(*windowType));
   848         frame()->loadURL(*absoluteUrl,TBrCtlDefs::ECacheModeNormal,String(),&String(*windowType));
   931         CleanupStack::PopAndDestroy(windowType);
   849         CleanupStack::PopAndDestroy(windowType);
   932     }
   850     }
   933 
   851 
   934     CleanupStack::PopAndDestroy(2);
   852     CleanupStack::PopAndDestroy(absoluteUrl);
   935 
   853 
   936     return KErrNone;
   854     return KErrNone;
   937 }
   855 }
   938 
   856 
   939 int PluginSkin::postRequestL(const TDesC8& url,const TDesC& buffer, bool fromfile, bool notify, void* notifydata,const TDesC* aWindowType)
   857 int PluginSkin::postRequestL(const TDesC8& url,const TDesC& buffer, bool fromfile, bool notify, void* notifydata,const TDesC* aWindowType)
   940 {
   858 {
   941     // make sure it is an absolute URL
   859     // make sure it is an absolute URL
   942     HBufC8* docUrl = HBufC8::NewLC(core(m_frame)->document()->baseURI().length());
   860     HBufC8* absoluteUrl = makeAbsoluteUrlL(*m_url, url);     
   943     docUrl->Des().Copy(core(m_frame)->document()->baseURI());
       
   944     HBufC8* absoluteUrl = makeAbsoluteUrlL(m_url, docUrl, url);     
       
   945     CleanupStack::PushL(absoluteUrl);
   861     CleanupStack::PushL(absoluteUrl);
   946     TPluginLoadMode loadmode = GetLoadMode(aWindowType);
   862     TPluginLoadMode loadmode = GetLoadMode(aWindowType);
   947  
   863  
   948     ResourceRequest request = (KURL(*absoluteUrl));
   864     ResourceRequest request = (KURL(*absoluteUrl));
   949 
   865 
   989     else{        
   905     else{        
   990         
   906         
   991         int start_content = buffer.Find(KRequestEOH());    
   907         int start_content = buffer.Find(KRequestEOH());    
   992         start_content =  (start_content != KErrNotFound) ? start_content+ KRequestEOH().Length() : 0;                
   908         start_content =  (start_content != KErrNotFound) ? start_content+ KRequestEOH().Length() : 0;                
   993         
   909         
   994         HBufC8* body = HBufC8::NewLC(buffer.Mid(start_content).Length());                
   910         HBufC* body = HBufC::NewLC(buffer.Mid(start_content).Length()+1);                
   995         body->Des().Copy(buffer.Mid(start_content));        
   911         body->Des().Copy(buffer.Mid(start_content));
   996         FormData* fd = new (ELeave) FormData(body->Ptr(),body->Length());                                          
   912         TextEncoding *ecoder = new TextEncoding(core(mainFrame(m_frame))->loader()->encoding());
       
   913         CString decoded_body = ecoder->encode(body->Des().PtrZ(),body->Length());
       
   914         FormData* fd = new (ELeave) FormData(decoded_body.data(),decoded_body.length());                                               
   997         request.setHTTPBody(fd);                                              
   915         request.setHTTPBody(fd);                                              
   998         CleanupStack::PopAndDestroy(); // body
   916         CleanupStack::PopAndDestroy(); // body
   999     }
   917     }
  1000                 
   918                 
  1001         
   919         
  1002     if (loadmode == ELoadModePlugin ) {    
   920     if (loadmode == ELoadModePlugin ) {    
  1003                         
   921                         
  1004         if (m_instance && m_pluginfuncs) {
   922         if (m_instance && m_pluginfuncs) {
  1005             NetscapePlugInStreamLoaderClient* pluginloader = NetscapePlugInStreamLoaderClient::NewL(request, this, core(m_frame), notifydata, notify);
   923             NetscapePlugInStreamLoaderClient* pluginloader = NetscapePlugInStreamLoaderClient::NewL(request, this, core(m_frame), notifydata);
  1006             if (pluginloader) {
   924             if (pluginloader) {
  1007                 pluginloader->start();                                           
   925                 pluginloader->start();                            
       
   926 
       
   927                 if ( notify ) {
       
   928                     HBufC* url16 = HBufC::NewLC( url.Length() );
       
   929                     url16->Des().Copy( url );
       
   930                     m_pluginfuncs->urlnotify( m_instance, *url16, NPRES_DONE, notifydata );        
       
   931                     CleanupStack::PopAndDestroy(url16);
       
   932                 }
       
   933                 
  1008             }                
   934             }                
  1009         }                 
   935         }                 
  1010     }
   936     }
  1011     else {
   937     else {
  1012         HBufC* windowType = HBufC::NewLC(aWindowType->Length());
   938         HBufC* windowType = HBufC::NewLC(aWindowType->Length());
  1014         frame()->loadRequest(request,&String(*windowType));
   940         frame()->loadRequest(request,&String(*windowType));
  1015         CleanupStack::PopAndDestroy(windowType);                   
   941         CleanupStack::PopAndDestroy(windowType);                   
  1016     }
   942     }
  1017     
   943     
  1018 
   944 
  1019     CleanupStack::PopAndDestroy(2);
   945     CleanupStack::PopAndDestroy(absoluteUrl);
  1020 
   946 
  1021     return KErrNone;
   947     return KErrNone;
  1022 }
   948 }
  1023 
   949 
  1024 
   950 
  1065 
   991 
  1066 */
   992 */
  1067 
   993 
  1068 void* PluginSkin::pluginScriptableObject()
   994 void* PluginSkin::pluginScriptableObject()
  1069 {
   995 {
  1070     if (!m_NPObject && m_pluginfuncs && m_pluginfuncs->getvalue) {
   996     //
  1071         NPError npErr = m_pluginfuncs->getvalue( m_instance, NPPVpluginScriptableNPObject, &m_NPObject);
   997     if (m_pluginfuncs && m_pluginfuncs->getvalue) {
  1072         if (npErr != NPERR_NO_ERROR) {
   998         void *value = 0;
  1073             m_NPObject = 0;
   999         NPError npErr = m_pluginfuncs->getvalue( m_instance, NPPVpluginScriptableNPObject, (void *)&value);
  1074         }
  1000         if (npErr == NPERR_NO_ERROR) {
  1075     }
  1001             return value;
  1076     return m_NPObject;
  1002         }
  1077 }
  1003     }
  1078 
  1004     return (void *)0;
  1079 TBool validateDataScheme(const TPtrC8& url)
       
  1080 {
       
  1081     // Check if body part of "data:" exists = data:[<mediatype>][;base64],<body>. RFC-2397 : http://www.faqs.org/rfcs/rfc2397
       
  1082     TPtrC8 urlPtr8 = url;
       
  1083     
       
  1084     if(url.Length() <= 0 )
       
  1085            return EFalse;
       
  1086     
       
  1087     TInt commaPos( urlPtr8.Locate( ',' ) );
       
  1088     if (commaPos == KErrNotFound )
       
  1089         return EFalse;
       
  1090     
       
  1091     TPtrC8 datapart (urlPtr8.Mid(commaPos + 1)); 
       
  1092     if (datapart.Length() <= 0)
       
  1093         return EFalse;
       
  1094 
       
  1095     return ETrue;
       
  1096 }
  1005 }
  1097 
  1006 
  1098 TBool PluginSkin::isBrowserScheme(const TPtrC8& url)
  1007 TBool PluginSkin::isBrowserScheme(const TPtrC8& url)
  1099 {
  1008 {
  1100     TBool supported(EFalse);
  1009     TBool supported(EFalse);
  1101     TUriParser8 parser;
  1010     TUriParser8 parser;
  1102     if( parser.Parse( url ) == KErrNone ) {
  1011     if( parser.Parse( url ) == KErrNone ) {
  1103         TPtrC8 scheme = parser.Extract( EUriScheme );
  1012         TPtrC8 scheme = parser.Extract( EUriScheme );
  1104         if (scheme.CompareF( _L8("http" ) ) == 0 || scheme.CompareF( _L8("https" ) ) == 0 
  1013         if (scheme.CompareF( _L8("http" ) ) == 0 || scheme.CompareF( _L8("https" ) ) == 0 
  1105             || scheme.Length() == 1 || scheme.CompareF( _L8("file") ) == 0) {
  1014             || scheme.Length() == 1 || scheme.CompareF( _L8("file") ) == 0 || scheme.CompareF( _L8("data") ) == 0) {
  1106             supported = ETrue;
  1015             supported = ETrue;
  1107         }
       
  1108         else if(scheme.CompareF( _L8("data") ) == 0) {
       
  1109             // if the scheme is "data", check its validity according to RFC-2397 : http://www.faqs.org/rfcs/rfc2397
       
  1110             supported = validateDataScheme(url);
       
  1111         }
  1016         }
  1112     }
  1017     }
  1113     return supported;
  1018     return supported;
  1114 }
  1019 }
  1115 
  1020 
  1143     TBool isPluginVisible = frameRectInViewCoord.Intersects(fullRect); 
  1048     TBool isPluginVisible = frameRectInViewCoord.Intersects(fullRect); 
  1144     TBool isFrameVisible = m_frame->frameView()->isVisible() && 
  1049     TBool isFrameVisible = m_frame->frameView()->isVisible() && 
  1145                            frameRectInViewCoord.Intersects(viewRect);
  1050                            frameRectInViewCoord.Intersects(viewRect);
  1146       
  1051       
  1147     if (m_pluginwin) {
  1052     if (m_pluginwin) {
  1148         TBool visibility = isFrameVisible && !isPageViewMode && isPluginVisible;
  1053         m_pluginwin->makeVisible( isFrameVisible && !isPageViewMode && isPluginVisible);
  1149         if(fullRect.Size() != TSize(0,0)) {
  1054         if (!m_pluginwin->isPluginInFullscreen()) {
  1150             m_pluginwin->makeVisible(visibility);
       
  1151         }
       
  1152         if (!m_pluginwin->isPluginInFullscreen() && visibility) {
       
  1153             clipRect.Intersection(fullRect);
  1055             clipRect.Intersection(fullRect);
  1154             m_pluginwin->SetRect(clipRect);
  1056             m_pluginwin->SetRect(clipRect);
  1155         }
  1057         }
  1156     }
  1058     }
  1157 }
  1059 }
  1283         return EWindowTypeTop;
  1185         return EWindowTypeTop;
  1284     }
  1186     }
  1285 
  1187 
  1286     return EWindowTypeUnknown;
  1188     return EWindowTypeUnknown;
  1287 }
  1189 }
  1288 
       
  1289 void PluginSkin::reCreatePlugin()
       
  1290 {
       
  1291     TBuf16<4> apId;
       
  1292     apId.Format( _L("%d"), m_frame->frameView()->topView()->accessPointId() );
       
  1293     
       
  1294     if (m_pluginwin ) {
       
  1295         m_pluginwin->notifyAPChange((void*)&apId);
       
  1296     }
       
  1297     
       
  1298     if (m_streams.size() > 0) {
       
  1299         
       
  1300         //destroy the plugin
       
  1301     
       
  1302         Vector<PluginStream*> streams;
       
  1303         for (HashSet<PluginStream*>::iterator it = m_streams.begin(); it != m_streams.end(); ++it) {
       
  1304             streams.append(*it);
       
  1305         }    
       
  1306         for (int i=0; i<streams.size(); ++i) {
       
  1307             streams[i]->close();
       
  1308         }
       
  1309         m_streams.clear();
       
  1310     
       
  1311         if (m_instance && m_pluginfuncs && m_pluginfuncs->destroy) {        
       
  1312             m_pluginfuncs->destroy(m_instance, NULL);
       
  1313         }
       
  1314         User::Free(m_instance); m_instance = 0;
       
  1315         delete m_pluginwin; m_pluginwin = 0;
       
  1316         delete iJavascriptTimer; iJavascriptTimer = 0;
       
  1317         
       
  1318         RFs& rfs = StaticObjectsContainer::instance()->fsSession();
       
  1319         for(TInt i=0; i < m_tempFilesArray.Count(); i++) {
       
  1320             rfs.Delete(m_tempFilesArray[i]->Des());
       
  1321         }
       
  1322         m_tempFilesArray.ResetAndDestroy();
       
  1323            
       
  1324         //create/load the destroyed plugin again
       
  1325                     
       
  1326         NetscapePlugInStreamLoaderClient* pluginloader = NetscapePlugInStreamLoaderClient::NewL(m_url->Des(), this, core(m_frame));
       
  1327         if (pluginloader) {
       
  1328             pluginloader->start();                            
       
  1329         }                                                
       
  1330     }
       
  1331 }
       
  1332 
       
  1333 // -----------------------------------------------------------------------------
       
  1334 // PluginWin::NotifyPluginsForScrollOrPinch
       
  1335 // When ever there is Scroll or Pinch zoom is in progress, the webframe will
       
  1336 // Notify all the plugins "ETrue" for Start and "EFalse" for end
       
  1337 // -----------------------------------------------------------------------------
       
  1338 void PluginSkin::NotifyPluginsForScrollOrPinch(bool status)
       
  1339     {
       
  1340     if(m_pluginwin)
       
  1341        {
       
  1342         //while pinch zoom, deactivate and activate the plugins.
       
  1343     WebView* view = control(frame())->webView();
       
  1344     if(!view)
       
  1345         return;
       
  1346 
       
  1347        //check weather the collect bitmap is supported or not
       
  1348         TBool bitmapSupported  = m_pluginwin->IsCollectBitmapSupported();
       
  1349 
       
  1350         //if bitmap is not supported, check for pinch zoom and deactivate the plugins.
       
  1351         if((view->isPinchZoom()))
       
  1352             {
       
  1353             //if bitmap sharing is not supported then deactivate or activate the plugins
       
  1354             if(!bitmapSupported)
       
  1355                 {
       
  1356                 if(status)
       
  1357                     {
       
  1358                     if(m_pluginwin->IsVisible())
       
  1359                         {
       
  1360                         m_pluginwin->MakeVisible(false);
       
  1361                         m_pluginwin->setPluginFocusL(false);
       
  1362                         }
       
  1363                     }
       
  1364                 else
       
  1365                     {
       
  1366                     activate();
       
  1367                     }
       
  1368                 }
       
  1369 
       
  1370             }
       
  1371 
       
  1372         if(bitmapSupported)
       
  1373            {
       
  1374             m_pluginwin->GetBitmapFromPlugin(status);
       
  1375             if(!status)
       
  1376                 {
       
  1377                 m_pluginwin->ClearPluginBitmap();
       
  1378                 activateVisiblePlugins();
       
  1379                 }
       
  1380           }
       
  1381        }
       
  1382 }
       
  1383 
       
  1384 // -----------------------------------------------------------------------------
       
  1385 // PluginWin::IsCollectBitmapSupported
       
  1386 // Check Plugin are supported for Bitmap Sharing
       
  1387 // -----------------------------------------------------------------------------
       
  1388 TBool PluginSkin::IsCollectBitmapSupported()
       
  1389     {
       
  1390     if(m_pluginwin)
       
  1391         {
       
  1392         return  m_pluginwin->IsCollectBitmapSupported();
       
  1393         }
       
  1394     return false;
       
  1395     }
       
  1396 
       
  1397 void PluginSkin::activateVisiblePlugins()
       
  1398     {
       
  1399     TRect fullRect(getPluginWinRect());
       
  1400     TRect clipRect(getClipRect());
       
  1401     TRect frameRect(m_frame->frameView()->rect());
       
  1402     TRect viewRect = control(m_frame)->webView()->Rect();
       
  1403     TBool isPageViewMode = control(m_frame)->webView()->inPageViewMode();
       
  1404     WebFrame* pf = m_frame;
       
  1405     TPoint p = frameRect.iTl;
       
  1406 
       
  1407     if (m_frame->parentFrame())
       
  1408         {
       
  1409         pf = m_frame->parentFrame();
       
  1410         p = pf->frameView()->frameCoordsInViewCoords(frameRect.iTl);
       
  1411         }
       
  1412 
       
  1413     TSize  sz = pf->frameView()->toViewCoords(frameRect.Size());
       
  1414     TRect frameRectInViewCoord = TRect(p, sz);
       
  1415     TBool isPluginVisible = frameRectInViewCoord.Intersects(fullRect);
       
  1416     TBool isFrameVisible = m_frame->frameView()->isVisible() &&
       
  1417             frameRectInViewCoord.Intersects(viewRect);
       
  1418 
       
  1419     TBool visibility = isFrameVisible && !isPageViewMode && isPluginVisible;
       
  1420     if(fullRect.Size() != TSize(0,0))
       
  1421         {
       
  1422         if (visibility)
       
  1423             {
       
  1424             m_pluginwin->MakeVisible(true); //forcefully make the plugin visible, this is for pinch exit
       
  1425             m_pluginwin->makeVisible(true);
       
  1426             }
       
  1427         else
       
  1428             {
       
  1429             //this is required for flash plugin to clear the EGL surface
       
  1430             //when the plugin window is outside the view port
       
  1431             m_pluginwin->makeVisible(false);
       
  1432             }
       
  1433         }
       
  1434 
       
  1435     }