webengine/osswebengine/WebKit/s60/webview/WebDataLoadConsumer.cpp
changeset 0 dd21522fd290
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:  Handles the viewing of a single frame. If the page is not frame
       
    15 *                enabled, this class is used as the single view.  If frame
       
    16 *                enabled, there is one instance of this class for each frame.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #include "WebDataLoadConsumer.h"
       
    22 
       
    23 WebDataLoadConsumer* WebDataLoadConsumer::initWithMetaData(CBrCtl* brctl, const TDesC& url, const TDataType& dataType,
       
    24     TUid charsetUid, TUint contentLength, MBrCtlDataLoadSupplier* brCtlDataLoadSupplier)
       
    25 {
       
    26     WebDataLoadConsumer* self = new WebDataLoadConsumer(brctl, dataType, charsetUid, contentLength, brCtlDataLoadSupplier);
       
    27     if (self) {
       
    28         self->m_url = url.Alloc();
       
    29         self->m_data = HBufC8::New(contentLength);
       
    30         if (self->m_url == NULL || self->m_data == NULL) {
       
    31             delete self;
       
    32             self = NULL;
       
    33         }
       
    34     }
       
    35     return self;
       
    36 }
       
    37 
       
    38 WebDataLoadConsumer::WebDataLoadConsumer(CBrCtl* brctl, const TDataType& dataType,
       
    39     TUid charsetUid, TUint contentLength, MBrCtlDataLoadSupplier* brCtlDataLoadSupplier) :
       
    40 m_brctl(brctl),
       
    41 m_dataType(dataType),
       
    42 m_charsetUid(charsetUid),
       
    43 m_contentLength(contentLength),
       
    44 m_brCtlDataLoadSupplier(brCtlDataLoadSupplier)
       
    45 {
       
    46 }
       
    47 	
       
    48 WebDataLoadConsumer::~WebDataLoadConsumer()
       
    49 {
       
    50     delete m_url;
       
    51     delete m_data;
       
    52 }
       
    53 	    
       
    54 void WebDataLoadConsumer::stopDataLoad()
       
    55 {
       
    56     m_brCtlDataLoadSupplier->CancelLoad();
       
    57 }
       
    58 
       
    59 void WebDataLoadConsumer::HandleNextDataChunk(const TDesC8& aData)
       
    60 {
       
    61     if (m_data->Length() + aData.Length() > m_contentLength) {
       
    62         m_brCtlDataLoadSupplier->CancelLoad();
       
    63         m_brctl->endLoadData();
       
    64     }
       
    65     else {
       
    66         m_data->Des().Append(aData);
       
    67     }
       
    68 }
       
    69 
       
    70 void WebDataLoadConsumer::HandleLoadComplete()
       
    71 {
       
    72     TRAP_IGNORE(m_brctl->LoadDataL(m_url->Des(), m_data->Des(), m_dataType, m_charsetUid));
       
    73     m_brctl->endLoadData();
       
    74 }
       
    75 
       
    76 void WebDataLoadConsumer::HandleError(TInt aError)
       
    77 {
       
    78     m_brctl->endLoadData();
       
    79 }