webengine/osswebengine/WebKit/s60/webview/WmlDispatcher.cpp
changeset 0 dd21522fd290
child 68 92a765b5b3e7
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDES
       
    20 #include <Browser_Platform_Variant.hrh>
       
    21 #include "WmlDispatcher.h"
       
    22 
       
    23 #ifndef BRDO_WML_DISABLED_FF
       
    24 #include "WmlEngineInterface.h"
       
    25 #endif 
       
    26 
       
    27 #include "WmlResourceLoaderClient.h"
       
    28 
       
    29 #include "StaticObjectsContainer.h"
       
    30 #include "WebCursor.h"
       
    31 
       
    32 #include "Frame.h"
       
    33 #include "FrameLoader.h"
       
    34 #include "DocumentLoader.h"
       
    35 #include "ProgressTracker.h"
       
    36 #include "ResourceRequest.h"
       
    37 #include "ResourceResponse.h"
       
    38 #include "WmlResourceLoader.h"
       
    39 
       
    40 #include "WebKitLogger.h"
       
    41 
       
    42 // CONSTANTS
       
    43 
       
    44 // MACROS
       
    45 
       
    46 // DATA TYPES
       
    47 
       
    48 // FUNCTION PROTOTYPES
       
    49 
       
    50 // FORWARD DECLARATIONS
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CWmlDispatcher::NewL
       
    54 // Public Class Method
       
    55 // Two-phased constructor.
       
    56 // -----------------------------------------------------------------------------
       
    57 CWmlDispatcher* CWmlDispatcher::NewL(CBrCtl* aBrCtl, WebCore::Frame* frame)
       
    58 {
       
    59   
       
    60   CWmlDispatcher* self = new (ELeave) CWmlDispatcher(aBrCtl, frame);
       
    61   CleanupStack::PushL( self );
       
    62   self->ConstructL();
       
    63   CleanupStack::Pop(); // self
       
    64   return self;
       
    65 }
       
    66   
       
    67 // -----------------------------------------------------------------------------
       
    68 // CWmlDispatcher::ConstructL
       
    69 // Private Class Method
       
    70 // Symbian 2nd phase constructor can leave.
       
    71 // -----------------------------------------------------------------------------
       
    72 void CWmlDispatcher::ConstructL()
       
    73 {
       
    74 }
       
    75     
       
    76 // -----------------------------------------------------------------------------
       
    77 //   C++ default constructor.
       
    78 // -----------------------------------------------------------------------------
       
    79 CWmlDispatcher::CWmlDispatcher(CBrCtl* aBrCtl, WebCore::Frame* frame): m_brCtl(aBrCtl), m_frame(frame)
       
    80 {
       
    81 }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 //   C++ destructor.
       
    85 // -----------------------------------------------------------------------------  
       
    86 CWmlDispatcher::~CWmlDispatcher( )
       
    87 {
       
    88     delete m_url;
       
    89     delete m_contentType;
       
    90     delete m_charset;
       
    91     delete m_contentFile;
       
    92 }
       
    93 
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CWmlDispatcher::HeadersL
       
    97 // -----------------------------------------------------------------------------
       
    98 TInt CWmlDispatcher::HeadersL(TInt aTransactionId, WebCore::ResourceResponse& aResponseInfo)
       
    99 {  	
       
   100    TInt status(KErrNone);
       
   101 
       
   102 #ifndef BRDO_WML_DISABLED_FF
       
   103     // cleanup content file, parameter list and data type from prior response (if any)
       
   104     delete m_contentFile;
       
   105     m_contentFile = NULL;
       
   106     delete m_contentType;
       
   107     m_contentType = NULL;
       
   108     delete m_charset;
       
   109     m_charset = NULL;
       
   110     delete m_url;
       
   111     m_url = NULL;
       
   112 
       
   113     m_error = 0;
       
   114     m_contentFile = CTempFile::NewL();
       
   115     m_loading = ETrue;
       
   116     
       
   117     // set response attributes
       
   118     m_contentType = aResponseInfo.mimeType().des().AllocL();
       
   119     m_charset = aResponseInfo.textEncodingName().des().AllocL();
       
   120 
       
   121     TPtrC myUrl = aResponseInfo.url().url().des();
       
   122     m_url = HBufC::NewL(myUrl.Length() + 1);
       
   123     m_url->Des().Copy(myUrl);
       
   124     m_url->Des().ZeroTerminate();
       
   125 
       
   126     //If wmlEngine.dll is not loaded then it is time to load the dll.
       
   127     if( !m_brCtl->wmlEngineInterface() ){
       
   128         m_brCtl->LoadDllWmlEngineL();
       
   129     }
       
   130 
       
   131     if (! m_brCtl->wmlMode()) {
       
   132         m_brCtl->MakeVisible(EFalse);  // turn off previous view if necessary
       
   133     }
       
   134     m_brCtl->setWmlMode(ETrue);
       
   135     
       
   136     //send the certificate info
       
   137     m_brCtl->wmlEngineInterface()->SetCertInfo(m_brCtl->CertInfo());
       
   138     
       
   139 #else
       
   140     status = EFalse; 
       
   141 #endif    
       
   142     return status;
       
   143 }
       
   144 
       
   145 //
       
   146 // -----------------------------------------------------------------------------
       
   147 // CWmlDispatcher::ProcessResponseL
       
   148 // 
       
   149 // 
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 void CWmlDispatcher::ResponseL( const char* data, int length )
       
   153 {
       
   154 #ifndef BRDO_WML_DISABLED_FF
       
   155     if(0 == m_error){
       
   156     // write incoming data to the content file
       
   157     const TPtrC8 response((unsigned char *)data, length);
       
   158     m_contentFile->WriteL( response );
       
   159     }
       
   160 #endif     
       
   161 }
       
   162 
       
   163 //
       
   164 // -----------------------------------------------------------------------------
       
   165 // CWmlDispatcher::ResponseCompleteL
       
   166 // 
       
   167 // 
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 void CWmlDispatcher::CompleteL(TInt /*aTransactionId*/, TInt /*aError*/  )
       
   171 {
       
   172 #ifndef BRDO_WML_DISABLED_FF
       
   173     if(0 == m_error && m_loading){
       
   174     m_contentFile->CloseL();
       
   175     LoadFileL(m_contentFile->Name() , *m_url, *m_contentType);
       
   176     MakeWmlVisible(ETrue);
       
   177     m_loading = EFalse;
       
   178     }
       
   179 #endif     
       
   180 }
       
   181 
       
   182 //
       
   183 // -----------------------------------------------------------------------------
       
   184 // CWmlDispatcher::HandleError
       
   185 // 
       
   186 // 
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 void CWmlDispatcher::HandleError( TInt /*aTransactionId*/, TInt aError )
       
   190 {
       
   191 #ifndef BRDO_WML_DISABLED_FF
       
   192     m_error = aError;
       
   193 #endif     
       
   194 }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // void CWmlDispatcher::LoadFileL
       
   198 // Loads the specified file
       
   199 // -----------------------------------------------------------------------------
       
   200 void CWmlDispatcher::LoadFileL(const TDesC& aFileName, const TDesC& aUrl, const TDesC& aContType)
       
   201 {
       
   202 #ifndef BRDO_WML_DISABLED_FF
       
   203     if (aFileName.Ptr() == NULL || aFileName.Length() == 0){
       
   204         User::Leave(KErrArgument);
       
   205     }
       
   206     AddUrlToFileL(aFileName, aUrl, aContType);
       
   207     HBufC* urlName = m_brCtl->fileNameToUrlLC(aFileName);
       
   208     LoadUrlL( *urlName);
       
   209     CleanupStack::PopAndDestroy(urlName);
       
   210 #endif     
       
   211 }
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // void CWmlDispatcher::LoadUrlL
       
   215 // Loads the specified url
       
   216 // -----------------------------------------------------------------------------
       
   217 void CWmlDispatcher::LoadUrlL( const TDesC& aUrl )
       
   218 {
       
   219 #ifndef BRDO_WML_DISABLED_FF
       
   220     m_brCtl->wmlEngineInterface()->WmlLoadUrlL( aUrl );
       
   221 #endif     
       
   222 }
       
   223    
       
   224         
       
   225 // -----------------------------------------------------------------------------
       
   226 // CWmlDispatcher::AddUrlToFile
       
   227 // Adds the url to the file
       
   228 // -----------------------------------------------------------------------------
       
   229 //    
       
   230 void CWmlDispatcher::AddUrlToFileL(const TDesC& aFileName, const TDesC& aUrl, const TDesC& aContType)
       
   231 {
       
   232 #ifndef BRDO_WML_DISABLED_FF
       
   233     RFs fsSession;
       
   234     RFile contentFile;
       
   235     TInt fileSize;
       
   236     User::LeaveIfError(fsSession.Connect());
       
   237     User::LeaveIfError(contentFile.Open(fsSession,aFileName,EFileShareExclusive|EFileWrite));
       
   238   
       
   239     contentFile.Size(fileSize);
       
   240     _LIT8(KSeparator,"*");
       
   241     contentFile.Write(fileSize, KSeparator);
       
   242     
       
   243     TInt urlPtrLen = aUrl.Length() + 1;
       
   244     TUint8 *urlPtr = new(ELeave)TUint8[urlPtrLen];
       
   245 	   CleanupStack::PushL( urlPtr );
       
   246     TPtr8 ptr(urlPtr, (urlPtrLen));
       
   247     ptr.Copy(aUrl);
       
   248     ptr.ZeroTerminate();
       
   249     TPtrC8 urlPtr8(ptr);
       
   250     
       
   251     contentFile.Size(fileSize);
       
   252     contentFile.Write(fileSize, urlPtr8);
       
   253   
       
   254     //add charset to the file if it has a charset
       
   255     if(m_charset != NULL){ 
       
   256         TDesC& aCharset = *m_charset;
       
   257         contentFile.Size(fileSize);
       
   258         _LIT8(KCharsetSeparator,"$");
       
   259         contentFile.Write(fileSize, KCharsetSeparator);
       
   260 
       
   261         TInt charsetPtrLen = aCharset.Length() + 1;
       
   262         TUint8 *charsetPtr = new(ELeave)TUint8[charsetPtrLen];  
       
   263         TPtr8 csptr(charsetPtr, (charsetPtrLen));
       
   264         csptr.Copy(aCharset);
       
   265         csptr.ZeroTerminate();
       
   266         TPtrC8 charsetPtr8(csptr);
       
   267         contentFile.Size(fileSize);
       
   268         contentFile.Write(fileSize, charsetPtr8);
       
   269 
       
   270         if(charsetPtr)
       
   271             delete charsetPtr;
       
   272     }
       
   273 
       
   274   //add content type
       
   275   _LIT(KContentTypeT,"text/vnd.wap.wml");
       
   276   _LIT(KContentTypeTC,"text/vnd.wap.wmlc");
       
   277   _LIT(KContentWMLSType,"application/vnd.wap.wmlscriptc");
       
   278   _LIT(KContentWMLACType,"application/vnd.wap.wmlc");
       
   279 
       
   280   contentFile.Size(fileSize);
       
   281   if( aContType.Compare(KContentTypeT) == 0 ){
       
   282     _LIT8(KContType,"0");
       
   283     contentFile.Write(fileSize, KContType); 
       
   284   }
       
   285   else if( aContType.Compare(KContentTypeTC) == 0 ){
       
   286     _LIT8(KContType,"1");
       
   287     contentFile.Write(fileSize, KContType); 
       
   288   }
       
   289   else if( aContType.Compare(KContentWMLSType) == 0 ){
       
   290     _LIT8(KContType,"2");
       
   291     contentFile.Write(fileSize, KContType); 
       
   292   }
       
   293   else if( aContType.Compare(KContentWMLACType) == 0 ){
       
   294     _LIT8(KContType,"3");
       
   295     contentFile.Write(fileSize, KContType); 
       
   296   }
       
   297 
       
   298   CleanupStack::PopAndDestroy(urlPtr);
       
   299 
       
   300   contentFile.Close();
       
   301   fsSession.Close();
       
   302 #endif // BRDO_WML_DISABLED_FF  
       
   303 }
       
   304 
       
   305     
       
   306 //-------------------------------------------------------------------------------
       
   307 // MakeWmlVisible
       
   308 //
       
   309 //-------------------------------------------------------------------------------    
       
   310 void CWmlDispatcher::MakeWmlVisible(bool visible)
       
   311 {
       
   312 #ifndef BRDO_WML_DISABLED_FF
       
   313     if (m_brCtl->wmlMode()){
       
   314         m_brCtl->MakeVisible(visible);
       
   315         m_brCtl->SetFocus(visible);
       
   316         m_brCtl->DrawNow();
       
   317         WebCursor* cursor = WebCore::StaticObjectsContainer::instance()->webCursor();
       
   318         cursor->setCursorVisible(!visible);
       
   319     }
       
   320 #endif   
       
   321 }    
       
   322 
       
   323 //-------------------------------------------------------------------------------
       
   324 // loadResource
       
   325 //
       
   326 //-------------------------------------------------------------------------------    
       
   327 void CWmlDispatcher::loadResource(TDesC8& url,  CWmlContentInterface* content )
       
   328 {
       
   329 #ifndef BRDO_WML_DISABLED_FF
       
   330     //this object get's deleted by the WmlStreamLoader. 
       
   331     WmlResourceLoaderClient* wmlclient = WmlResourceLoaderClient::CreateResourceLoaderClient(this);
       
   332     if (wmlclient){
       
   333         wmlclient->start(url,m_frame);        
       
   334     }        
       
   335 #endif     
       
   336 }
       
   337 
       
   338 //-------------------------------------------------------------------------------
       
   339 // WmlParameters
       
   340 //
       
   341 //-------------------------------------------------------------------------------    
       
   342 void CWmlDispatcher::WmlParameters( const char* data, int length, TDesC& contentType, TDesC& charset, TInt httpStatus, TInt chunkIndex, TDesC& url  )
       
   343 {
       
   344 #ifndef BRDO_WML_DISABLED_FF
       
   345     m_brCtl->wmlEngineInterface()->WmlParameters( data, length, contentType, charset, httpStatus, chunkIndex, url);    
       
   346 #endif     
       
   347 }
       
   348 
       
   349 
       
   350 // End of File
       
   351 
       
   352