webengine/osswebengine/WebKit/s60/plugins/PluginSkin.cpp
branchRCL_3
changeset 94 919f36ff910f
parent 93 79859ed3eea9
child 99 ca6d8a014f4b
equal deleted inserted replaced
93:79859ed3eea9 94:919f36ff910f
    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"
    47 
    49 
    48 #include <ApEngineConsts.h>
    50 #include <ApEngineConsts.h>
    49 #include <uri8.h>
    51 #include <Uri8.h>
    50 #include <InternetConnectionManager.h>
    52 #include <internetconnectionmanager.h>
    51 #include <es_enum.h>
    53 #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 
    56 
    57 
    57 // CONSTANTS
    58 // CONSTANTS
    58 using namespace WebCore;
    59 using namespace WebCore;
    59 // scheme for RTSP url
    60 // scheme for RTSP url
    60 _LIT8(KRtsp, "rtsp");
    61 _LIT8(KRtsp, "rtsp");
    82 _LIT(KUnknownMode, "UnKnownMode");
    83 _LIT(KUnknownMode, "UnKnownMode");
    83 _LIT(KApplicationId,"ApplicationId");
    84 _LIT(KApplicationId,"ApplicationId");
    84 _LIT(KSecMgrScriptSession,"SecMgrScriptSession");
    85 _LIT(KSecMgrScriptSession,"SecMgrScriptSession");
    85 _LIT(KAllowNetworkAccess,"AllowNetworkAccess");
    86 _LIT(KAllowNetworkAccess,"AllowNetworkAccess");
    86 
    87 
    87 
    88 #if defined(__PLATFORM_VERSION_32__)
       
    89 #define KArraySize 1
       
    90 #else
    88 #define KArraySize 3
    91 #define KArraySize 3
       
    92 #endif
    89 
    93 
    90 const TInt32 KWidgetApplicationId =  0x10282822;
    94 const TInt32 KWidgetApplicationId =  0x10282822;
    91 const TInt32 KBrowserApplicationId = 0x10008D39;
    95 const TInt32 KBrowserApplicationId = 0x10008D39;
    92 
    96 
    93 //MACROS
    97 //MACROS
    98 // ----------------------------------------------------------------------------
   102 // ----------------------------------------------------------------------------
    99 // makeAbsoluteUrlL()
   103 // makeAbsoluteUrlL()
   100 // return an absolute url that results from refUrl being resolved against 
   104 // return an absolute url that results from refUrl being resolved against 
   101 // baseUrl.
   105 // baseUrl.
   102 // ----------------------------------------------------------------------------
   106 // ----------------------------------------------------------------------------
   103 HBufC8* makeAbsoluteUrlL(const TDesC8& baseUrl, const TDesC8& refUrl)
   107 HBufC8* makeAbsoluteUrlL(const TDesC8* baseUrl,const TDesC8* docUrl, const TDesC8& refUrl)
   104 {
   108 {
   105     TUriParser8 baseUrlparser;
   109     TUriParser8 baseUrlparser;
   106     baseUrlparser.Parse(baseUrl); 
   110     if(baseUrl == NULL)
       
   111         baseUrlparser.Parse(*docUrl); 
       
   112     else
       
   113         baseUrlparser.Parse(*baseUrl);
   107     TUriParser8 refUrlparser;
   114     TUriParser8 refUrlparser;
   108     refUrlparser.Parse(refUrl); 
   115     refUrlparser.Parse(refUrl); 
   109 
   116 
   110     CUri8* absoluteUrl = CUri8::ResolveL(baseUrlparser, refUrlparser);
   117     CUri8* absoluteUrl = CUri8::ResolveL(baseUrlparser, refUrlparser);
   111     CleanupStack::PushL(absoluteUrl);
   118     CleanupStack::PushL(absoluteUrl);
   153       m_pluginSupported( EFalse ),
   160       m_pluginSupported( EFalse ),
   154       m_pluginClosed(false),
   161       m_pluginClosed(false),
   155       m_canInteract( EFalse ),
   162       m_canInteract( EFalse ),
   156       m_rect(TRect(0,0,0,0)),
   163       m_rect(TRect(0,0,0,0)),
   157       m_ref(1),
   164       m_ref(1),
       
   165       m_oldRect(TRect(0,0,0,0)),
       
   166       m_oldViewport(TRect(0,0,0,0)),
       
   167       m_NPObject(0),
   158       m_handle(-1),
   168       m_handle(-1),
   159       m_instance(0),    
   169       m_instance(0),    
   160       m_pluginfuncs(0),
   170       m_pluginfuncs(0),
   161       m_resized(false),
   171       m_resized(false)
   162       m_oldRect(TRect(0,0,0,0)),
       
   163       m_oldViewport(TRect(0,0,0,0))
       
   164   {
   172   {
   165   }
   173   }
   166 
   174 
   167 
   175 
   168 void PluginSkin::addWidgetAttributesL()
   176 void PluginSkin::addWidgetAttributesL()
   192         NPN_GenericElement ScriptSession(SecMgrScriptSession,scriptSession);
   200         NPN_GenericElement ScriptSession(SecMgrScriptSession,scriptSession);
   193         iGenericElementArray->AppendL(ScriptSession);           
   201         iGenericElementArray->AppendL(ScriptSession);           
   194 #endif
   202 #endif
   195 
   203 
   196         TInt uid = wdgtExt->GetWidgetId();         
   204         TInt uid = wdgtExt->GetWidgetId();         
       
   205         
   197         CWidgetPropertyValue* AccessValue = widgetregistry.GetWidgetPropertyValueL(TUid::Uid(uid), EAllowNetworkAccess ); 
   206         CWidgetPropertyValue* AccessValue = widgetregistry.GetWidgetPropertyValueL(TUid::Uid(uid), EAllowNetworkAccess ); 
   198         TInt networkAccess = *AccessValue;
   207         TInt networkAccess = AccessValue && *AccessValue;
       
   208         delete AccessValue;
       
   209         
   199         const TDesC& allowNetworkAccess = KAllowNetworkAccess();
   210         const TDesC& allowNetworkAccess = KAllowNetworkAccess();
   200         NPN_GenericElement NetworkAccess(allowNetworkAccess,networkAccess);
   211         NPN_GenericElement NetworkAccess(allowNetworkAccess,networkAccess);
   201         iGenericElementArray->AppendL(NetworkAccess);
   212         iGenericElementArray->AppendL(NetworkAccess);
   202     }
   213     }
   203     User::LeaveIfError(widgetregistry.Disconnect());
   214     User::LeaveIfError(widgetregistry.Disconnect());
   395     User::Free(m_instance); m_instance = 0;
   406     User::Free(m_instance); m_instance = 0;
   396     delete m_pluginwin; m_pluginwin = 0;
   407     delete m_pluginwin; m_pluginwin = 0;
   397     delete m_attributeNames; m_attributeNames = 0;
   408     delete m_attributeNames; m_attributeNames = 0;
   398     delete m_attributeValues; m_attributeValues = 0;
   409     delete m_attributeValues; m_attributeValues = 0;
   399     delete m_url; m_url = 0;
   410     delete m_url; m_url = 0;
   400     delete iJavascriptTimer; iJavascriptTimer = 0;
   411     if(iJavascriptTimer)
       
   412         { 
       
   413         iJavascriptTimer->Cancel();
       
   414         delete iJavascriptTimer; 
       
   415         iJavascriptTimer = 0;
       
   416         }
   401     m_pluginfuncs = 0;
   417     m_pluginfuncs = 0;
   402     m_pluginSupported = EFalse;
   418     m_pluginSupported = EFalse;
   403     m_pluginClosed = true;
   419     m_pluginClosed = true;
       
   420     
   404  }
   421  }
   405 
   422 
       
   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 }
   406 
   442 
   407 // ----------------------------------------------------------------------------
   443 // ----------------------------------------------------------------------------
   408 // PluginSkin::pluginFocusChanged()
   444 // PluginSkin::pluginFocusChanged()
   409 // PluginSkin function to show/hide fullscreen sprite
   445 // PluginSkin function to show/hide fullscreen sprite
   410 // ----------------------------------------------------------------------------
   446 // ----------------------------------------------------------------------------
   460     gc->SetPenStyle( CGraphicsContext::ENullPen );
   496     gc->SetPenStyle( CGraphicsContext::ENullPen );
   461     gc->SetBrushStyle( CGraphicsContext::ENullBrush );
   497     gc->SetBrushStyle( CGraphicsContext::ENullBrush );
   462 
   498 
   463     CFbsBitmap* bitmap = m_cannedimg.m_img;
   499     CFbsBitmap* bitmap = m_cannedimg.m_img;
   464     TSize bmpSize( bitmap->SizeInPixels() );
   500     TSize bmpSize( bitmap->SizeInPixels() );
   465     if ( !m_pluginwin && newRect.Height() >= bmpSize.iHeight && newRect.Width() >= bmpSize.iWidth )
   501     CWidgetExtension* wdgtExt = control(this->frame()) ? control(this->frame())->getWidgetExt(): NULL;
       
   502     
       
   503     if ( !wdgtExt && !m_pluginwin && newRect.Height() >= bmpSize.iHeight && newRect.Width() >= bmpSize.iWidth )
   466         {
   504         {
   467         // The inner rect is big enough, draw the placeholder image
   505         // The inner rect is big enough, draw the placeholder image
   468         TPoint bitmapStartPoint( newRect.Center() );
   506         TPoint bitmapStartPoint( newRect.Center() );
   469         bitmapStartPoint -= TPoint(bmpSize.iWidth/2,bmpSize.iHeight/2);
   507         bitmapStartPoint -= TPoint(bmpSize.iWidth/2,bmpSize.iHeight/2);
   470         gc->BitBltMasked( bitmapStartPoint, m_cannedimg.m_img,
   508         gc->BitBltMasked( bitmapStartPoint, m_cannedimg.m_img,
   471                         bmpSize, m_cannedimg.m_msk, ETrue );
   509                         bmpSize, m_cannedimg.m_msk, ETrue );
   472         }
   510         }
   473     if(m_pluginwin)
   511     if(m_pluginwin)
   474         {
   512         {
   475         positionChanged();
   513         //if bitmap is shared from plugins then draw the shared bitmap
   476         // Force the control to be redrawn.
   514         if(m_pluginwin->IsPluginBitMapSet())
   477         m_pluginwin->refreshPlugin(*gc,newRect);
   515             {
       
   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             }
   478         }
   542         }
   479     }
   543     }
   480 
   544 
   481 // ----------------------------------------------------------------------------
   545 // ----------------------------------------------------------------------------
   482 // PluginSkin::IsVisible
   546 // PluginSkin::IsVisible
   500 // PluginSkin::MakeVisible
   564 // PluginSkin::MakeVisible
   501 // From MWebCoreObjectWidget
   565 // From MWebCoreObjectWidget
   502 // ----------------------------------------------------------------------------
   566 // ----------------------------------------------------------------------------
   503 void PluginSkin::makeVisible( TBool visible )
   567 void PluginSkin::makeVisible( TBool visible )
   504     {
   568     {
       
   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     }
   505     if ( m_pluginwin )
   593     if ( m_pluginwin )
   506         {
   594         {
       
   595         if (visible && !visibility)
       
   596             visible = EFalse;
       
   597         
   507         m_visible = visible;
   598         m_visible = visible;
   508         if(m_active)
   599         if(m_active && !visible)
   509             deActivate();
   600             deActivate();
   510         m_pluginwin->makeVisible(visible);
   601         m_pluginwin->makeVisible(visible);
   511         }
   602         }
   512     }
   603     }
   513 
   604 
   563             TRAP_IGNORE( m_pluginwin->processEventL(EEventActivate, consumed));
   654             TRAP_IGNORE( m_pluginwin->processEventL(EEventActivate, consumed));
   564             if (consumed)
   655             if (consumed)
   565                 {
   656                 {
   566                 m_active = ETrue;
   657                 m_active = ETrue;
   567                 m_frame->frameView()->topView()->setFocusedElementType(TBrCtlDefs::EElementActivatedObjectBox);
   658                 m_frame->frameView()->topView()->setFocusedElementType(TBrCtlDefs::EElementActivatedObjectBox);
       
   659                 control(m_frame)->webView()->page()->focusController()->setFocusedNode(getElement(), control(m_frame)->webView()->page()->focusController()->focusedOrMainFrame());                        
   568                 pluginHandler->setActivePlugin(this);
   660                 pluginHandler->setActivePlugin(this);
   569                 pluginHandler->setPluginToActivate(NULL);
   661                 pluginHandler->setPluginToActivate(NULL);
   570                 }
   662                 }
   571             // Set right soft key
   663             // Set right soft key
   572             m_frame->frameView()->topView()->brCtl()->updateDefaultSoftkeys();
   664             m_frame->frameView()->topView()->brCtl()->updateDefaultSoftkeys();
   648     if (!m_instance) {
   740     if (!m_instance) {
   649         
   741         
   650         NPError error( NPERR_NO_ERROR );
   742         NPError error( NPERR_NO_ERROR );
   651         
   743         
   652         m_instance = (NPP) User::AllocL(sizeof(NPP_t));
   744         m_instance = (NPP) User::AllocL(sizeof(NPP_t));
   653         m_instance->ndata = pluginWin();
       
   654         m_instance->pdata = NULL;
       
   655 
       
   656         if (m_instance) {
   745         if (m_instance) {
   657             
   746             m_instance->ndata = pluginWin();
       
   747             m_instance->pdata = NULL;            
   658             PluginHandler* pluginhandler = WebCore::StaticObjectsContainer::instance()->pluginHandler();
   748             PluginHandler* pluginhandler = WebCore::StaticObjectsContainer::instance()->pluginHandler();
   659             if ( pluginhandler ) {
   749             if ( pluginhandler ) {
   660                 pluginhandler->loadPluginL( m_handle, &m_pluginfuncs );
   750                 pluginhandler->loadPluginL( m_handle, &m_pluginfuncs );
   661         
   751         
   662                 if (m_pluginfuncs && m_pluginfuncs->newp) {        
   752                 if (m_pluginfuncs && m_pluginfuncs->newp) {        
   669                                                     NULL );
   759                                                     NULL );
   670                                                                       
   760                                                                       
   671                 }
   761                 }
   672                 if (m_pluginwin) {
   762                 if (m_pluginwin) {
   673                     m_pluginwin->ConstructL(*(control(m_frame)->webView()));
   763                     m_pluginwin->ConstructL(*(control(m_frame)->webView()));
       
   764                 }
   674             }
   765             }
   675         }
       
   676         }
   766         }
   677 
   767 
   678         switch ( error ) {
   768         switch ( error ) {
   679             case NPERR_OUT_OF_MEMORY_ERROR: {
   769             case NPERR_OUT_OF_MEMORY_ERROR: {
   680                 User::Leave( KErrNoMemory );
   770                 User::Leave( KErrNoMemory );
   682             }
   772             }
   683             case NPERR_GENERIC_ERROR: {
   773             case NPERR_GENERIC_ERROR: {
   684                 User::Leave( KErrNotSupported );
   774                 User::Leave( KErrNotSupported );
   685                 break;
   775                 break;
   686             }
   776             }
   687         }    
   777         }
   688         
   778         
   689         if (m_pluginwin)
   779         if (m_pluginwin)
   690         m_pluginwin->SetExtent( TPoint(0,0), TSize(0,0) );
   780             m_pluginwin->SetExtent( TPoint(0,0), TSize(0,0) );
   691             
   781     }
   692     }
       
   693 
       
   694 }
   782 }
   695 
   783 
   696 // -----------------------------------------------------------------------------
   784 // -----------------------------------------------------------------------------
   697 // PluginSkin::CreatePluginWinL
   785 // PluginSkin::CreatePluginWinL
   698 //
   786 //
   798 
   886 
   799 //callbacks from NpnImplementation  
   887 //callbacks from NpnImplementation  
   800 int PluginSkin::getRequestL(const TDesC8& url, bool notify, void* notifydata,const TDesC* aWindowType)
   888 int PluginSkin::getRequestL(const TDesC8& url, bool notify, void* notifydata,const TDesC* aWindowType)
   801 {
   889 {
   802     TPluginLoadMode loadmode = GetLoadMode(aWindowType);
   890     TPluginLoadMode loadmode = GetLoadMode(aWindowType);
   803 
   891     
   804     if (url.Ptr() == NULL ) {                        
   892     if (url.Ptr() == NULL ) {                        
   805         return KErrArgument;
   893         return KErrArgument;
   806     }
   894     }
   807 
   895     
   808     _LIT8(KJs, "javascript:");
   896     _LIT8(KJs, "javascript:");
   809     if ((url.Length() > KJs().Length() ) &&(url.Left(KJs().Length()).FindF(KJs) == 0)) {
   897     if ((url.Length() > KJs().Length() ) &&(url.Left(KJs().Length()).FindF(KJs) == 0)) {
   810         HBufC* pBuffer = HBufC::NewL(url.Length());
   898         HBufC* pBuffer = HBufC::NewL(url.Length());
   811 	    TPtr16 temp = pBuffer->Des(); 
   899 	    TPtr16 temp = pBuffer->Des(); 
   812 	    temp.Copy(url);
   900 	    temp.Copy(url);
   819          }
   907          }
   820         return KErrNone;
   908         return KErrNone;
   821      }
   909      }
   822 
   910 
   823     // make sure it is an absolute URL
   911     // make sure it is an absolute URL
   824     HBufC8* absoluteUrl = makeAbsoluteUrlL(*m_url, url); 
   912     HBufC8* docUrl = HBufC8::NewLC(core(m_frame)->document()->baseURI().length());
       
   913     docUrl->Des().Copy(core(m_frame)->document()->baseURI());
       
   914     HBufC8* absoluteUrl = makeAbsoluteUrlL(m_url, docUrl, url); 
   825     CleanupStack::PushL(absoluteUrl);
   915     CleanupStack::PushL(absoluteUrl);
   826 
   916 
   827     if (loadmode == ELoadModePlugin ) {    
   917     PluginHandler* pluginHandler = StaticObjectsContainer::instance()->pluginHandler();
   828         
   918     if( (loadmode == ELoadModePlugin ) || (loadmode == ELoadModeTop && (pluginHandler->pluginMimeByExtention(url) != NULL)) ){        
   829         if (m_instance && m_pluginfuncs) {
   919         if (m_instance && m_pluginfuncs) {
   830         
   920         
   831             NetscapePlugInStreamLoaderClient* pluginloader = NetscapePlugInStreamLoaderClient::NewL(url, this, core(m_frame), notifydata);
   921             NetscapePlugInStreamLoaderClient* pluginloader = NetscapePlugInStreamLoaderClient::NewL(url, this, core(m_frame), notifydata, notify);
   832             if (pluginloader) {
   922             if (pluginloader) {
   833                 pluginloader->start();                            
   923                 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                 
       
   842             }                
   924             }                
   843         }                 
   925         }                 
   844     }
   926     }
   845     else {    
   927     else {    
   846         HBufC* windowType = HBufC::NewLC(aWindowType->Length());
   928         HBufC* windowType = HBufC::NewLC(aWindowType->Length());
   847         windowType->Des().Copy(*aWindowType);
   929         windowType->Des().Copy(*aWindowType);
   848         frame()->loadURL(*absoluteUrl,TBrCtlDefs::ECacheModeNormal,String(),&String(*windowType));
   930         frame()->loadURL(*absoluteUrl,TBrCtlDefs::ECacheModeNormal,String(),&String(*windowType));
   849         CleanupStack::PopAndDestroy(windowType);
   931         CleanupStack::PopAndDestroy(windowType);
   850     }
   932     }
   851 
   933 
   852     CleanupStack::PopAndDestroy(absoluteUrl);
   934     CleanupStack::PopAndDestroy(2);
   853 
   935 
   854     return KErrNone;
   936     return KErrNone;
   855 }
   937 }
   856 
   938 
   857 int PluginSkin::postRequestL(const TDesC8& url,const TDesC& buffer, bool fromfile, bool notify, void* notifydata,const TDesC* aWindowType)
   939 int PluginSkin::postRequestL(const TDesC8& url,const TDesC& buffer, bool fromfile, bool notify, void* notifydata,const TDesC* aWindowType)
   858 {
   940 {
   859     // make sure it is an absolute URL
   941     // make sure it is an absolute URL
   860     HBufC8* absoluteUrl = makeAbsoluteUrlL(*m_url, url);     
   942     HBufC8* docUrl = HBufC8::NewLC(core(m_frame)->document()->baseURI().length());
       
   943     docUrl->Des().Copy(core(m_frame)->document()->baseURI());
       
   944     HBufC8* absoluteUrl = makeAbsoluteUrlL(m_url, docUrl, url);     
   861     CleanupStack::PushL(absoluteUrl);
   945     CleanupStack::PushL(absoluteUrl);
   862     TPluginLoadMode loadmode = GetLoadMode(aWindowType);
   946     TPluginLoadMode loadmode = GetLoadMode(aWindowType);
   863  
   947  
   864     ResourceRequest request = (KURL(*absoluteUrl));
   948     ResourceRequest request = (KURL(*absoluteUrl));
   865 
   949 
   905     else{        
   989     else{        
   906         
   990         
   907         int start_content = buffer.Find(KRequestEOH());    
   991         int start_content = buffer.Find(KRequestEOH());    
   908         start_content =  (start_content != KErrNotFound) ? start_content+ KRequestEOH().Length() : 0;                
   992         start_content =  (start_content != KErrNotFound) ? start_content+ KRequestEOH().Length() : 0;                
   909         
   993         
   910         HBufC* body = HBufC::NewLC(buffer.Mid(start_content).Length()+1);                
   994         HBufC8* body = HBufC8::NewLC(buffer.Mid(start_content).Length());                
   911         body->Des().Copy(buffer.Mid(start_content));
   995         body->Des().Copy(buffer.Mid(start_content));        
   912         TextEncoding *ecoder = new TextEncoding(core(mainFrame(m_frame))->loader()->encoding());
   996         FormData* fd = new (ELeave) FormData(body->Ptr(),body->Length());                                          
   913         CString decoded_body = ecoder->encode(body->Des().PtrZ(),body->Length());
       
   914         FormData* fd = new (ELeave) FormData(decoded_body.data(),decoded_body.length());                                               
       
   915         request.setHTTPBody(fd);                                              
   997         request.setHTTPBody(fd);                                              
   916         CleanupStack::PopAndDestroy(); // body
   998         CleanupStack::PopAndDestroy(); // body
   917     }
   999     }
   918                 
  1000                 
   919         
  1001         
   920     if (loadmode == ELoadModePlugin ) {    
  1002     if (loadmode == ELoadModePlugin ) {    
   921                         
  1003                         
   922         if (m_instance && m_pluginfuncs) {
  1004         if (m_instance && m_pluginfuncs) {
   923             NetscapePlugInStreamLoaderClient* pluginloader = NetscapePlugInStreamLoaderClient::NewL(request, this, core(m_frame), notifydata);
  1005             NetscapePlugInStreamLoaderClient* pluginloader = NetscapePlugInStreamLoaderClient::NewL(request, this, core(m_frame), notifydata, notify);
   924             if (pluginloader) {
  1006             if (pluginloader) {
   925                 pluginloader->start();                            
  1007                 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                 
       
   934             }                
  1008             }                
   935         }                 
  1009         }                 
   936     }
  1010     }
   937     else {
  1011     else {
   938         HBufC* windowType = HBufC::NewLC(aWindowType->Length());
  1012         HBufC* windowType = HBufC::NewLC(aWindowType->Length());
   940         frame()->loadRequest(request,&String(*windowType));
  1014         frame()->loadRequest(request,&String(*windowType));
   941         CleanupStack::PopAndDestroy(windowType);                   
  1015         CleanupStack::PopAndDestroy(windowType);                   
   942     }
  1016     }
   943     
  1017     
   944 
  1018 
   945     CleanupStack::PopAndDestroy(absoluteUrl);
  1019     CleanupStack::PopAndDestroy(2);
   946 
  1020 
   947     return KErrNone;
  1021     return KErrNone;
   948 }
  1022 }
   949 
  1023 
   950 
  1024 
   991 
  1065 
   992 */
  1066 */
   993 
  1067 
   994 void* PluginSkin::pluginScriptableObject()
  1068 void* PluginSkin::pluginScriptableObject()
   995 {
  1069 {
   996     //
  1070     if (!m_NPObject && m_pluginfuncs && m_pluginfuncs->getvalue) {
   997     if (m_pluginfuncs && m_pluginfuncs->getvalue) {
  1071         NPError npErr = m_pluginfuncs->getvalue( m_instance, NPPVpluginScriptableNPObject, &m_NPObject);
   998         void *value = 0;
  1072         if (npErr != NPERR_NO_ERROR) {
   999         NPError npErr = m_pluginfuncs->getvalue( m_instance, NPPVpluginScriptableNPObject, (void *)&value);
  1073             m_NPObject = 0;
  1000         if (npErr == NPERR_NO_ERROR) {
  1074         }
  1001             return value;
  1075     }
  1002         }
  1076     return m_NPObject;
  1003     }
  1077 }
  1004     return (void *)0;
  1078 
       
  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;
  1005 }
  1096 }
  1006 
  1097 
  1007 TBool PluginSkin::isBrowserScheme(const TPtrC8& url)
  1098 TBool PluginSkin::isBrowserScheme(const TPtrC8& url)
  1008 {
  1099 {
  1009     TBool supported(EFalse);
  1100     TBool supported(EFalse);
  1010     TUriParser8 parser;
  1101     TUriParser8 parser;
  1011     if( parser.Parse( url ) == KErrNone ) {
  1102     if( parser.Parse( url ) == KErrNone ) {
  1012         TPtrC8 scheme = parser.Extract( EUriScheme );
  1103         TPtrC8 scheme = parser.Extract( EUriScheme );
  1013         if (scheme.CompareF( _L8("http" ) ) == 0 || scheme.CompareF( _L8("https" ) ) == 0 
  1104         if (scheme.CompareF( _L8("http" ) ) == 0 || scheme.CompareF( _L8("https" ) ) == 0 
  1014             || scheme.Length() == 1 || scheme.CompareF( _L8("file") ) == 0 || scheme.CompareF( _L8("data") ) == 0) {
  1105             || scheme.Length() == 1 || scheme.CompareF( _L8("file") ) == 0) {
  1015             supported = ETrue;
  1106             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);
  1016         }
  1111         }
  1017     }
  1112     }
  1018     return supported;
  1113     return supported;
  1019 }
  1114 }
  1020 
  1115 
  1048     TBool isPluginVisible = frameRectInViewCoord.Intersects(fullRect); 
  1143     TBool isPluginVisible = frameRectInViewCoord.Intersects(fullRect); 
  1049     TBool isFrameVisible = m_frame->frameView()->isVisible() && 
  1144     TBool isFrameVisible = m_frame->frameView()->isVisible() && 
  1050                            frameRectInViewCoord.Intersects(viewRect);
  1145                            frameRectInViewCoord.Intersects(viewRect);
  1051       
  1146       
  1052     if (m_pluginwin) {
  1147     if (m_pluginwin) {
  1053         m_pluginwin->makeVisible( isFrameVisible && !isPageViewMode && isPluginVisible);
  1148         TBool visibility = isFrameVisible && !isPageViewMode && isPluginVisible;
  1054         if (!m_pluginwin->isPluginInFullscreen()) {
  1149         if(fullRect.Size() != TSize(0,0)) {
       
  1150             m_pluginwin->makeVisible(visibility);
       
  1151         }
       
  1152         if (!m_pluginwin->isPluginInFullscreen() && visibility) {
  1055             clipRect.Intersection(fullRect);
  1153             clipRect.Intersection(fullRect);
  1056             m_pluginwin->SetRect(clipRect);
  1154             m_pluginwin->SetRect(clipRect);
  1057         }
  1155         }
  1058     }
  1156     }
  1059 }
  1157 }
  1185         return EWindowTypeTop;
  1283         return EWindowTypeTop;
  1186     }
  1284     }
  1187 
  1285 
  1188     return EWindowTypeUnknown;
  1286     return EWindowTypeUnknown;
  1189 }
  1287 }
       
  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     }