webengine/osswebengine/WebKit/s60/webview/WmlResourceLoaderClient.cpp
changeset 0 dd21522fd290
child 17 c8a366e56285
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 "WmlResourceLoaderClient.h"
       
    21 #include "WmlResourceLoader.h"
       
    22 #include "WmlDispatcher.h"
       
    23 #include "Page.h"
       
    24 #include "Frame.h"
       
    25 #include "FrameLoader.h"
       
    26 #include "DocumentLoader.h"
       
    27 #include "ProgressTracker.h"
       
    28 #include "ResourceRequest.h"
       
    29 #include "ResourceResponse.h"
       
    30 #include "StaticObjectsContainer.h"
       
    31 
       
    32 
       
    33 #include "WebKitLogger.h"
       
    34 
       
    35 // CONSTANTS
       
    36 
       
    37 // MACROS
       
    38 
       
    39 // DATA TYPES
       
    40 
       
    41 // FUNCTION PROTOTYPES
       
    42 
       
    43 // FORWARD DECLARATIONS
       
    44 using namespace WebCore;
       
    45 
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // 
       
    49 // -----------------------------------------------------------------------------
       
    50 WmlResourceLoaderClient* WmlResourceLoaderClient::CreateResourceLoaderClient(CWmlDispatcher* wmldispatcher)
       
    51 {
       
    52     //this object get's deleted by the WmlStreamLoader. 
       
    53     return new WmlResourceLoaderClient(wmldispatcher);    
       
    54 }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 //   C++ default constructor.
       
    58 // -----------------------------------------------------------------------------
       
    59 WmlResourceLoaderClient::WmlResourceLoaderClient(CWmlDispatcher* wmldispatcher) : 
       
    60     m_wmldispatcher(wmldispatcher),    
       
    61     m_loader(0),
       
    62     m_contentType(0),
       
    63     m_charset(0),
       
    64     m_url(0),        
       
    65     m_error(0),
       
    66     m_contentLength(0),
       
    67     m_restLength(0),
       
    68     m_httpStatus (0)
       
    69 {
       
    70 }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 //   C++ destructor.
       
    74 // -----------------------------------------------------------------------------  
       
    75 WmlResourceLoaderClient::~WmlResourceLoaderClient( )
       
    76 {
       
    77     delete m_url;
       
    78     delete m_contentType;
       
    79     delete m_charset;   
       
    80 }
       
    81 
       
    82 void WmlResourceLoaderClient::start(TDesC8& url, Frame* frame)
       
    83 {
       
    84 
       
    85     WebCore::ResourceRequest* request = new WebCore::ResourceRequest(WebCore::String(url));    
       
    86     m_loader = WebCore::WmlResourceLoader::create(frame, this);
       
    87     
       
    88     if (m_loader) {
       
    89         m_loader->documentLoader()->addSubresourceLoader(m_loader);
       
    90         m_loader->load(*request);            
       
    91     }
       
    92 }
       
    93 
       
    94 void WmlResourceLoaderClient::stop()
       
    95 {
       
    96     if (m_loader && !m_loader->isDone())
       
    97         m_loader->cancel();
       
    98 }
       
    99 
       
   100 void WmlResourceLoaderClient::cancelWithError(const WebCore::ResourceError& error)
       
   101 {
       
   102     if (m_loader && !m_loader->isDone()) 
       
   103         m_loader->cancel(error); 
       
   104 }
       
   105 
       
   106 void WmlResourceLoaderClient::didReceiveResponse(const WebCore::ResourceResponse& response)
       
   107 { 
       
   108     int status  = 200;
       
   109     if(response.isHTTP()){
       
   110         status = response.httpStatusCode();
       
   111     }
       
   112     
       
   113     if (status < 200 || status >= 300) {          
       
   114         cancelWithError(WebCore::ResourceError(WebCore::String(response.url()), KErrGeneral, WebCore::String(response.url()), WebCore::String(response.httpStatusText())));        
       
   115         return;
       
   116     }
       
   117     
       
   118     delete m_contentType;
       
   119     m_contentType = NULL;
       
   120     
       
   121     delete m_charset;
       
   122     m_charset = NULL;
       
   123     
       
   124     delete m_url;
       
   125     m_url = NULL;
       
   126     
       
   127     m_contentType = response.mimeType().des().AllocL();
       
   128     m_charset = response.textEncodingName().des().AllocL();
       
   129     
       
   130     TPtrC myUrl = response.url().url().des();
       
   131     m_url = HBufC::New(myUrl.Length() + 1);
       
   132     m_url->Des().Copy(myUrl);
       
   133     m_url->Des().ZeroTerminate();
       
   134     
       
   135     m_contentLength = response.expectedContentLength();
       
   136     m_httpStatus = status; 
       
   137     m_restLength = 0;
       
   138 }
       
   139 
       
   140 void WmlResourceLoaderClient::didReceiveData(const char* data, int length, long long lengthReceived)
       
   141 {
       
   142 	   //send data to wmlcontrol
       
   143     TInt chunkIndex = 0;     
       
   144     if(m_contentLength > length && m_restLength){
       
   145         chunkIndex++;     
       
   146     }
       
   147 
       
   148     if (m_contentType && m_charset && m_url) {
       
   149         m_wmldispatcher->WmlParameters( data, length, *m_contentType, *m_charset, m_httpStatus, chunkIndex, *m_url);        
       
   150     }
       
   151     
       
   152     m_restLength = m_contentLength - length;   
       
   153 }
       
   154 
       
   155 void WmlResourceLoaderClient::didFinishLoading()
       
   156 {
       
   157     TInt chunkIndex = -1;      // last chunk
       
   158     if (m_contentType && m_charset && m_url) {
       
   159         m_wmldispatcher->WmlParameters( NULL, 0, *m_contentType, *m_charset, m_httpStatus, chunkIndex, *m_url );
       
   160     }
       
   161     m_wmldispatcher->HandleError(0,KErrCompletion);
       
   162 }
       
   163 
       
   164 void WmlResourceLoaderClient::didFail(const WebCore::ResourceError& error)
       
   165 {    
       
   166     m_wmldispatcher->HandleError(0,error.errorCode());
       
   167 }
       
   168 
       
   169 void WmlResourceLoaderClient::didCancel(const WebCore::ResourceError& error)
       
   170 {
       
   171     m_wmldispatcher->HandleError(0,error.errorCode());
       
   172 }
       
   173 
       
   174 // End of File
       
   175