sdkcreationmw/sdkruntimes/FileLoader/src/W32FileConnection.cpp
author Shabe Razvi <shaber@symbian.org>
Thu, 04 Nov 2010 17:22:05 +0000
changeset 4 b3b823debf08
parent 0 b26acd06ea60
permissions -rw-r--r--
Workaround for Bug 3917 - CWinsockInterface::DataSent calls NotifyDataSent which is not implemented.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     1
/*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     3
* All rights reserved.
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     4
* This component and the accompanying materials are made available
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     6
* which accompanies this distribution, and is available
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     8
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     9
* Initial Contributors:
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    11
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    12
* Contributors:
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    13
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    14
* Description:
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    15
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    16
*/
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    17
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    18
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    19
#include <emulator.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    20
#include <uri16.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    21
#include <apmrec.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    22
#include <apgcli.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    23
#include "ResourceHandle.h"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    24
#include "W32FileConnection.h"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    25
#include "W32FileReader.h"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    26
#include "ResourceHandleManagerSymbian.h"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    27
#include "StaticObjectsContainer.h"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    28
#include "ResourceRequest.h"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    29
#include <BrCtlSpecialLoadObserver.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    30
#include "brctl.h"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    31
#include "DeprecatedString.h"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    32
HANDLE   iFh;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    33
const TInt KFileReadChunkSize = 23920; // bytes
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    34
_LIT8( KResLoaderLatin1, "iso-8859-1" );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    35
_LIT8( KResLoaderUCS2, "iso-10646-ucs-2" );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    36
_LIT8( KResLoaderWapWmlc, "application/vnd.wap.wmlc" );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    37
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    38
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    39
static int s_fileTransactionsCount = 0;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    40
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    41
using namespace WebCore;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    42
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    43
CW32FileConnection::CW32FileConnection(ResourceHandle* _handle) : MUrlConnection(_handle)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    44
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    45
    m_fileName = 0;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    46
    m_fileReader = 0;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    47
    s_fileTransactionsCount++;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    48
    m_chunkIndex = 0;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    49
    m_charset = 0;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    50
    m_contentType = 0;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    51
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    52
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    53
CW32FileConnection::~CW32FileConnection()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    54
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    55
    ::CloseHandle(iFh);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    56
    s_fileTransactionsCount--;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    57
    delete m_fileName;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    58
    delete m_fileReader;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    59
    delete m_charset;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    60
    delete m_contentType;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    61
//    m_file.Close();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    62
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    63
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    64
TInt CW32FileConnection::submit()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    65
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    66
    TRAPD(error, submitL());
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    67
    return error;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    68
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    69
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    70
//========================================================================
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    71
//  CW32FileConnection::submitL
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    72
//========================================================================
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    73
TInt CW32FileConnection::submitL()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    74
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    75
    TInt error(KErrNone);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    76
    TPtrC8 urlPtr( m_handle->request().url().des() );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    77
    m_fileName = parseFileNameL( urlPtr );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    78
    if (m_fileName) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    79
    iFh = Emulator::CreateFile(m_fileName->Des().PtrZ(), GENERIC_READ,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    80
                           FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    81
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    82
    if (iFh == INVALID_HANDLE_VALUE) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    83
      error = Emulator::LastError();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    84
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    85
    else {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    86
        TUint32  fileSize = ::GetFileSize(iFh, NULL); //W32 call
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    87
        m_maxSize = fileSize;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    88
    if (m_fileReader == NULL) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    89
        m_fileReader = CW32FileReader::NewL(iFh, KFileReadChunkSize, this);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    90
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    91
    m_fileReader->StartReading();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    92
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    93
  }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    94
  else {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    95
    error = KErrArgument;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    96
  }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    97
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    98
    User::LeaveIfError(error);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    99
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   100
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   101
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   102
// -----------------------------------------------------------------------------
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   103
// CW32FileConnection::parseFileNameL
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   104
// Translate the file name from a URL to a valid file name in the system.
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   105
// -----------------------------------------------------------------------------
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   106
//
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   107
HBufC* CW32FileConnection::parseFileNameL(const TDesC8& aUrl )
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   108
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   109
    //To convert TPtrC8 to Tptr16
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   110
	TBufC8<200> Urlbuf(aUrl);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   111
    HBufC16* buf16 = HBufC16::NewL(256);//delete buf16 dont forget.
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   112
    TPtr16 bufptr16(buf16->Des());
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   113
    bufptr16.Copy(Urlbuf.Des());
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   114
    TInt status;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   115
    TUriParser parser;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   116
    HBufC* fileName = NULL;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   117
    status = parser.Parse( bufptr16 );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   118
    if( status == KErrNone ) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   119
        // this must be the drive letter
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   120
        TPtrC host = parser.Extract( EUriHost );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   121
        TPtrC path = parser.Extract( EUriPath );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   122
        // add missing ":"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   123
        fileName = HBufC::NewL( (host.Length()?host.Length()+1:0) + path.Length()+ 1/*0 terminated*/ );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   124
        TPtr fileNamePtr( fileName->Des() );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   125
        if( host.Length() == 1 ) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   126
            // fix c to c:
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   127
            fileNamePtr.Copy( host );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   128
            fileNamePtr.Append( _L(":") );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   129
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   130
        else {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   131
            // according to symbian uri parser in case of
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   132
            // file:///c:\foo.html
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   133
            // host: /c:\foo.html
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   134
            // path: /c:\foo.html
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   135
            // remove: / from the begenning of the path
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   136
            if( path.Length() > 2 && path[0] == '/' && path[2] == ':' ) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   137
                // move pointer from "/c:\" to "c:\"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   138
                path.Set( path.Mid( 1 ) );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   139
         
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   140
            }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   141
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   142
        fileNamePtr.Append( path );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   143
        // fix slashes
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   144
        for( TInt i = 0; i < fileNamePtr.Length(); i++ ) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   145
            if( fileNamePtr[ i ] == '/' ) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   146
                fileNamePtr[ i ] = '\\';
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   147
            }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   148
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   149
    // then replace possible %20-sequences with blank
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   150
    TInt pos = 0;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   151
    _LIT(KWinSP, "%20");
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   152
    _LIT(KSpace, " ");
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   153
    TInt len = (&KWinSP)->Length();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   154
    while ((pos = fileNamePtr.FindC(KWinSP)) != KErrNotFound) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   155
        fileNamePtr.Replace(pos, (&KWinSP)->Length(), KSpace);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   156
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   157
//    return fileName16;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   158
//    CleanupStack::PushL( fileName16 );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   159
      delete buf16;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   160
      return fileName;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   161
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   162
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   163
void CW32FileConnection::cancel()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   164
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   165
    if( m_fileReader ) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   166
        m_fileReader->StopReading();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   167
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   168
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   169
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   170
void CW32FileConnection::download(WebCore::ResourceHandle* handle,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   171
                              const WebCore::ResourceRequest& request,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   172
                              const WebCore::ResourceResponse& response)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   173
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   174
    // stop reading and close the file
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   175
    m_fileReader->StopReading();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   176
    m_cancelled = true;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   177
    ::CloseHandle(iFh); //windows call
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   178
    // send data to the host application
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   179
    MBrCtlSpecialLoadObserver* loadObserver = StaticObjectsContainer::instance()->brctl()->brCtlSpecialLoadObserver();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   180
    if(loadObserver) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   181
        RArray<TUint> typeArray;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   182
        CDesCArrayFlat* desArray = new (ELeave) CDesCArrayFlat(4);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   183
        CleanupStack::PushL(desArray);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   184
        //
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   185
        HBufC* url = HBufC::NewLC(handle->request().url().url().length());
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   186
        url->Des().Copy(handle->request().url().des());
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   187
        typeArray.Append(EParamRequestUrl);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   188
        desArray->AppendL(*url);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   189
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   190
        typeArray.Append(EParamCharset);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   191
        desArray->AppendL(*m_charset);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   192
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   193
        typeArray.Append(EParamReceivedContentType);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   194
        desArray->AppendL(*m_contentType);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   195
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   196
        typeArray.Append(EParamLocalFileName);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   197
        desArray->AppendL(*m_fileName);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   198
        //
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   199
        loadObserver->HandleDownloadL(&typeArray, desArray);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   200
        //
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   201
        typeArray.Close();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   202
        desArray->Reset();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   203
        CleanupStack::PopAndDestroy(2); // desArray, url 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   204
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   205
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   206
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   207
// -----------------------------------------------------------------------------
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   208
// CW32FileConnection::contentTypeL
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   209
// Determine the content type of the file.
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   210
// -----------------------------------------------------------------------------
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   211
HBufC8* CW32FileConnection::contentTypeL()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   212
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   213
    TPtrC8 contentTypePtr;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   214
    HBufC8* contentType = NULL;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   215
    TDataRecognitionResult dataType;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   216
    RApaLsSession apaSession;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   217
    TInt ret;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   218
    
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   219
    User::LeaveIfError( apaSession.Connect() );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   220
    // Ask the application architecture to find the file type
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   221
    TPtrC8 chunkPtr;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   222
    
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   223
    m_fileReader->GetChunkBuffer( chunkPtr );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   224
    ret = apaSession.RecognizeData( m_fileName->Des(), chunkPtr, dataType );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   225
    apaSession.Close();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   226
    
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   227
    if( ret == KErrNone &&
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   228
        ( dataType.iConfidence == CApaDataRecognizerType::ECertain ) ||
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   229
        ( dataType.iConfidence == CApaDataRecognizerType::EProbable ) ) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   230
        // If the file type was found, try to match it to a known file type
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   231
        contentTypePtr.Set( dataType.iDataType.Des8() );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   232
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   233
    else {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   234
        // extensions
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   235
        _LIT( KCssExt, ".css" );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   236
        _LIT(KWbmpExt, ".wbmp");
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   237
        _LIT(KEcmaScriptExt, ".es");
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   238
        _LIT(KJavaScriptExt, ".js");
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   239
        
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   240
        TPtrC extPtr( m_fileName->Right( m_fileName->Length() -  m_fileName->LocateReverse('.') ) );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   241
        
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   242
        if( extPtr.CompareF( KCssExt() ) == 0 ) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   243
            contentTypePtr.Set( _L8( "text/css" ) );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   244
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   245
        else if( extPtr.CompareF( KWbmpExt() ) == 0 ) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   246
            contentTypePtr.Set( _L8( "image/vnd.wap.wbmp" ) );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   247
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   248
        else if( extPtr.CompareF( KEcmaScriptExt() ) == 0 ||
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   249
            extPtr.CompareF( KJavaScriptExt() ) == 0 ) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   250
            contentTypePtr.Set( _L8( "text/ecmascript" ) );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   251
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   252
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   253
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   254
    if( contentTypePtr.Length() ) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   255
        contentType = HBufC8::NewL( contentTypePtr.Length() );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   256
        contentType->Des().Copy( contentTypePtr );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   257
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   258
    return contentType;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   259
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   260
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   261
// -----------------------------------------------------------------------------
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   262
// CW32FileConnection::contentEncoding
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   263
// Determine the content encoding of the file.
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   264
// -----------------------------------------------------------------------------
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   265
//
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   266
TPtrC8 CW32FileConnection::contentEncoding(const TDesC8& aContentTypeString ) const
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   267
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   268
    // Assume Latin-1 for xhtml and html. ucs2 for any other
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   269
    TPtrC8 charset( KResLoaderLatin1 );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   270
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   271
    TPtrC8 httpAppString( KResLoaderWapWmlc );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   272
    TPtrC8 contentString( aContentTypeString );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   273
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   274
    // Is the contentType a HTTP_application_vnd_wap_wmlc_string
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   275
    TUint index = contentString.FindF( httpAppString );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   276
    if( index == 0 ) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   277
        // This is a HTTP_application_vnd_wap_wmlc_string
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   278
        charset.Set( KResLoaderUCS2 );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   279
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   280
    return charset;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   281
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   282
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   283
void CW32FileConnection::response()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   284
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   285
    TRAPD(error, responseL());
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   286
    if (error) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   287
        complete(error);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   288
    }        
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   289
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   290
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   291
void CW32FileConnection::responseL()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   292
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   293
    if (m_chunkIndex == 0 ) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   294
        HBufC8* contentType = contentTypeL();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   295
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   296
        if( contentType ) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   297
            m_contentType = HBufC::NewL(contentType->Length());
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   298
            m_contentType->Des().Copy(*contentType);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   299
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   300
            TPtrC8 contentEncodingPtr( contentEncoding( contentType->Des() ) );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   301
            ResourceResponse response(m_handle->request().url().des(), contentType->Des(), m_maxSize, contentEncodingPtr, String() );
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   302
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   303
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   304
            const TDesC& charset = response.textEncodingName().des();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   305
            m_charset = charset.AllocL();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   306
            response.setHTTPStatusCode(200);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   307
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   308
            CResourceHandleManager::self()->receivedResponse(m_handle, response, this);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   309
        }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   310
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   311
    // If it is not Browser content, reading the file is canceled in CW32FileConnection::download().
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   312
    if (!m_cancelled) {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   313
        TPtrC8 chunkPtr;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   314
        m_fileReader->GetChunkBuffer( chunkPtr );    
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   315
        m_chunkIndex++;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   316
        CResourceHandleManager::self()->receivedData(m_handle, chunkPtr, m_maxSize, this);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   317
    }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   318
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   319
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   320
void CW32FileConnection::complete(int error)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   321
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   322
    CResourceHandleManager::self()->receivedFinished(m_handle, error, this);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   323
    derefHandle();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   324
}
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   325
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   326
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   327
// end of file