webengine/osswebengine/WebKit/s60/plugins/PluginSkin.cpp
changeset 65 5bfc169077b2
parent 42 d39add9822e2
child 68 92a765b5b3e7
equal deleted inserted replaced
42:d39add9822e2 65:5bfc169077b2
    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"
    45 #include "Widget.h"
    45 #include "Widget.h"
    46 #include "PlatformScrollBar.h"
    46 #include "PlatformScrollBar.h"
    47 
    47 
    48 #include <ApEngineConsts.h>
    48 #include <ApEngineConsts.h>
    49 #include <Uri8.h>
    49 #include <Uri8.h>
    50 #include <internetconnectionmanager.h>
    50 #include <InternetConnectionManager.h>
    51 #include <es_enum.h>
    51 #include <es_enum.h>
       
    52 #include <TextEncoding.h>
       
    53 #include "CString.h"
    52 #include "WidgetExtension.h"
    54 #include "WidgetExtension.h"
    53 #include <widgetregistryclient.h>
    55 #include <WidgetRegistryClient.h>
    54 
    56 
    55 // CONSTANTS
    57 // CONSTANTS
    56 using namespace WebCore;
    58 using namespace WebCore;
    57 // scheme for RTSP url
    59 // scheme for RTSP url
    58 _LIT8(KRtsp, "rtsp");
    60 _LIT8(KRtsp, "rtsp");
    96 // ----------------------------------------------------------------------------
    98 // ----------------------------------------------------------------------------
    97 // makeAbsoluteUrlL()
    99 // makeAbsoluteUrlL()
    98 // return an absolute url that results from refUrl being resolved against 
   100 // return an absolute url that results from refUrl being resolved against 
    99 // baseUrl.
   101 // baseUrl.
   100 // ----------------------------------------------------------------------------
   102 // ----------------------------------------------------------------------------
   101 HBufC8* makeAbsoluteUrlL(const TDesC8* baseUrl,const TDesC8* docUrl, const TDesC8& refUrl)
   103 HBufC8* makeAbsoluteUrlL(const TDesC8& baseUrl, const TDesC8& refUrl)
   102 {
   104 {
   103     TUriParser8 baseUrlparser;
   105     TUriParser8 baseUrlparser;
   104     if(baseUrl == NULL)
   106     baseUrlparser.Parse(baseUrl); 
   105         baseUrlparser.Parse(*docUrl); 
       
   106     else
       
   107         baseUrlparser.Parse(*baseUrl);
       
   108     TUriParser8 refUrlparser;
   107     TUriParser8 refUrlparser;
   109     refUrlparser.Parse(refUrl); 
   108     refUrlparser.Parse(refUrl); 
   110 
   109 
   111     CUri8* absoluteUrl = CUri8::ResolveL(baseUrlparser, refUrlparser);
   110     CUri8* absoluteUrl = CUri8::ResolveL(baseUrlparser, refUrlparser);
   112     CleanupStack::PushL(absoluteUrl);
   111     CleanupStack::PushL(absoluteUrl);
   803     TPluginLoadMode loadmode = GetLoadMode(aWindowType);
   802     TPluginLoadMode loadmode = GetLoadMode(aWindowType);
   804 
   803 
   805     if (url.Ptr() == NULL ) {                        
   804     if (url.Ptr() == NULL ) {                        
   806         return KErrArgument;
   805         return KErrArgument;
   807     }
   806     }
   808     _LIT8(KSwfExtn, ".swf");
   807 
   809     _LIT8(KJs, "javascript:");
   808     _LIT8(KJs, "javascript:");
   810     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)) {
   811         HBufC* pBuffer = HBufC::NewL(url.Length());
   810         HBufC* pBuffer = HBufC::NewL(url.Length());
   812 	    TPtr16 temp = pBuffer->Des(); 
   811 	    TPtr16 temp = pBuffer->Des(); 
   813 	    temp.Copy(url);
   812 	    temp.Copy(url);
   820          }
   819          }
   821         return KErrNone;
   820         return KErrNone;
   822      }
   821      }
   823 
   822 
   824     // make sure it is an absolute URL
   823     // make sure it is an absolute URL
   825     HBufC8* docUrl = HBufC8::NewLC(core(m_frame)->document()->baseURI().length());
   824     HBufC8* absoluteUrl = makeAbsoluteUrlL(*m_url, url); 
   826     docUrl->Des().Copy(core(m_frame)->document()->baseURI());
       
   827     HBufC8* absoluteUrl = makeAbsoluteUrlL(m_url, docUrl, url); 
       
   828     CleanupStack::PushL(absoluteUrl);
   825     CleanupStack::PushL(absoluteUrl);
   829 
   826 
   830     if( (loadmode == ELoadModePlugin ) || (url.FindF(KSwfExtn)!= KErrNotFound) ){    
   827     if (loadmode == ELoadModePlugin ) {    
   831         
   828         
   832         if (m_instance && m_pluginfuncs) {
   829         if (m_instance && m_pluginfuncs) {
   833         
   830         
   834             NetscapePlugInStreamLoaderClient* pluginloader = NetscapePlugInStreamLoaderClient::NewL(url, this, core(m_frame), notifydata, notify);
   831             NetscapePlugInStreamLoaderClient* pluginloader = NetscapePlugInStreamLoaderClient::NewL(url, this, core(m_frame), notifydata);
   835             if (pluginloader) {
   832             if (pluginloader) {
   836                 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                 
   837             }                
   842             }                
   838         }                 
   843         }                 
   839     }
   844     }
   840     else {    
   845     else {    
   841         HBufC* windowType = HBufC::NewLC(aWindowType->Length());
   846         HBufC* windowType = HBufC::NewLC(aWindowType->Length());
   842         windowType->Des().Copy(*aWindowType);
   847         windowType->Des().Copy(*aWindowType);
   843         frame()->loadURL(*absoluteUrl,TBrCtlDefs::ECacheModeNormal,String(),&String(*windowType));
   848         frame()->loadURL(*absoluteUrl,TBrCtlDefs::ECacheModeNormal,String(),&String(*windowType));
   844         CleanupStack::PopAndDestroy(windowType);
   849         CleanupStack::PopAndDestroy(windowType);
   845     }
   850     }
   846 
   851 
   847     CleanupStack::PopAndDestroy(2);
   852     CleanupStack::PopAndDestroy(absoluteUrl);
   848 
   853 
   849     return KErrNone;
   854     return KErrNone;
   850 }
   855 }
   851 
   856 
   852 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)
   853 {
   858 {
   854     // make sure it is an absolute URL
   859     // make sure it is an absolute URL
   855     HBufC8* docUrl = HBufC8::NewLC(core(m_frame)->document()->baseURI().length());
   860     HBufC8* absoluteUrl = makeAbsoluteUrlL(*m_url, url);     
   856     docUrl->Des().Copy(core(m_frame)->document()->baseURI());
       
   857     HBufC8* absoluteUrl = makeAbsoluteUrlL(m_url, docUrl, url);     
       
   858     CleanupStack::PushL(absoluteUrl);
   861     CleanupStack::PushL(absoluteUrl);
   859     TPluginLoadMode loadmode = GetLoadMode(aWindowType);
   862     TPluginLoadMode loadmode = GetLoadMode(aWindowType);
   860  
   863  
   861     ResourceRequest request = (KURL(*absoluteUrl));
   864     ResourceRequest request = (KURL(*absoluteUrl));
   862 
   865 
   902     else{        
   905     else{        
   903         
   906         
   904         int start_content = buffer.Find(KRequestEOH());    
   907         int start_content = buffer.Find(KRequestEOH());    
   905         start_content =  (start_content != KErrNotFound) ? start_content+ KRequestEOH().Length() : 0;                
   908         start_content =  (start_content != KErrNotFound) ? start_content+ KRequestEOH().Length() : 0;                
   906         
   909         
   907         HBufC8* body = HBufC8::NewLC(buffer.Mid(start_content).Length());                
   910         HBufC* body = HBufC::NewLC(buffer.Mid(start_content).Length()+1);                
   908         body->Des().Copy(buffer.Mid(start_content));        
   911         body->Des().Copy(buffer.Mid(start_content));
   909         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());                                               
   910         request.setHTTPBody(fd);                                              
   915         request.setHTTPBody(fd);                                              
   911         CleanupStack::PopAndDestroy(); // body
   916         CleanupStack::PopAndDestroy(); // body
   912     }
   917     }
   913                 
   918                 
   914         
   919         
   915     if (loadmode == ELoadModePlugin ) {    
   920     if (loadmode == ELoadModePlugin ) {    
   916                         
   921                         
   917         if (m_instance && m_pluginfuncs) {
   922         if (m_instance && m_pluginfuncs) {
   918             NetscapePlugInStreamLoaderClient* pluginloader = NetscapePlugInStreamLoaderClient::NewL(request, this, core(m_frame), notifydata, notify);
   923             NetscapePlugInStreamLoaderClient* pluginloader = NetscapePlugInStreamLoaderClient::NewL(request, this, core(m_frame), notifydata);
   919             if (pluginloader) {
   924             if (pluginloader) {
   920                 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                 
   921             }                
   934             }                
   922         }                 
   935         }                 
   923     }
   936     }
   924     else {
   937     else {
   925         HBufC* windowType = HBufC::NewLC(aWindowType->Length());
   938         HBufC* windowType = HBufC::NewLC(aWindowType->Length());
   927         frame()->loadRequest(request,&String(*windowType));
   940         frame()->loadRequest(request,&String(*windowType));
   928         CleanupStack::PopAndDestroy(windowType);                   
   941         CleanupStack::PopAndDestroy(windowType);                   
   929     }
   942     }
   930     
   943     
   931 
   944 
   932     CleanupStack::PopAndDestroy(2);
   945     CleanupStack::PopAndDestroy(absoluteUrl);
   933 
   946 
   934     return KErrNone;
   947     return KErrNone;
   935 }
   948 }
   936 
   949 
   937 
   950 
   989         }
  1002         }
   990     }
  1003     }
   991     return (void *)0;
  1004     return (void *)0;
   992 }
  1005 }
   993 
  1006 
   994 TBool validateDataScheme(const TPtrC8& url)
       
   995 {
       
   996     // Check if body part of "data:" exists = data:[<mediatype>][;base64],<body>. RFC-2397 : http://www.faqs.org/rfcs/rfc2397
       
   997     TPtrC8 urlPtr8 = url;
       
   998     
       
   999     if(url.Length() <= 0 )
       
  1000            return EFalse;
       
  1001     
       
  1002     TInt commaPos( urlPtr8.Locate( ',' ) );
       
  1003     if (commaPos == KErrNotFound )
       
  1004         return EFalse;
       
  1005     
       
  1006     TPtrC8 datapart (urlPtr8.Mid(commaPos + 1)); 
       
  1007     if (datapart.Length() <= 0)
       
  1008         return EFalse;
       
  1009 
       
  1010     return ETrue;
       
  1011 }
       
  1012 
       
  1013 TBool PluginSkin::isBrowserScheme(const TPtrC8& url)
  1007 TBool PluginSkin::isBrowserScheme(const TPtrC8& url)
  1014 {
  1008 {
  1015     TBool supported(EFalse);
  1009     TBool supported(EFalse);
  1016     TUriParser8 parser;
  1010     TUriParser8 parser;
  1017     if( parser.Parse( url ) == KErrNone ) {
  1011     if( parser.Parse( url ) == KErrNone ) {
  1018         TPtrC8 scheme = parser.Extract( EUriScheme );
  1012         TPtrC8 scheme = parser.Extract( EUriScheme );
  1019         if (scheme.CompareF( _L8("http" ) ) == 0 || scheme.CompareF( _L8("https" ) ) == 0 
  1013         if (scheme.CompareF( _L8("http" ) ) == 0 || scheme.CompareF( _L8("https" ) ) == 0 
  1020             || scheme.Length() == 1 || scheme.CompareF( _L8("file") ) == 0) {
  1014             || scheme.Length() == 1 || scheme.CompareF( _L8("file") ) == 0 || scheme.CompareF( _L8("data") ) == 0) {
  1021             supported = ETrue;
  1015             supported = ETrue;
  1022         }
       
  1023         else if(scheme.CompareF( _L8("data") ) == 0) {
       
  1024             // if the scheme is "data", check its validity according to RFC-2397 : http://www.faqs.org/rfcs/rfc2397
       
  1025             supported = validateDataScheme(url);
       
  1026         }
  1016         }
  1027     }
  1017     }
  1028     return supported;
  1018     return supported;
  1029 }
  1019 }
  1030 
  1020 
  1058     TBool isPluginVisible = frameRectInViewCoord.Intersects(fullRect); 
  1048     TBool isPluginVisible = frameRectInViewCoord.Intersects(fullRect); 
  1059     TBool isFrameVisible = m_frame->frameView()->isVisible() && 
  1049     TBool isFrameVisible = m_frame->frameView()->isVisible() && 
  1060                            frameRectInViewCoord.Intersects(viewRect);
  1050                            frameRectInViewCoord.Intersects(viewRect);
  1061       
  1051       
  1062     if (m_pluginwin) {
  1052     if (m_pluginwin) {
  1063         TBool visibility = isFrameVisible && !isPageViewMode && isPluginVisible;
  1053         m_pluginwin->makeVisible( isFrameVisible && !isPageViewMode && isPluginVisible);
  1064         m_pluginwin->makeVisible(visibility);
  1054         if (!m_pluginwin->isPluginInFullscreen()) {
  1065         if (!m_pluginwin->isPluginInFullscreen() && visibility) {
       
  1066             clipRect.Intersection(fullRect);
  1055             clipRect.Intersection(fullRect);
  1067             m_pluginwin->SetRect(clipRect);
  1056             m_pluginwin->SetRect(clipRect);
  1068         }
  1057         }
  1069     }
  1058     }
  1070 }
  1059 }