webengine/osswebengine/WebCore/platform/network/symbian/UnknownContentHandler.cpp
changeset 0 dd21522fd290
child 8 7c90e6132015
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2  * Copyright (C) 2008 Nokia, Inc.  All rights reserved.
       
     3  *
       
     4  * Redistribution and use in source and binary forms, with or without
       
     5  * modification, are permitted provided that the following conditions
       
     6  * are met:
       
     7  *
       
     8  * 1.  Redistributions of source code must retain the above copyright
       
     9  *     notice, this list of conditions and the following disclaimer. 
       
    10  * 2.  Redistributions in binary form must reproduce the above copyright
       
    11  *     notice, this list of conditions and the following disclaimer in the
       
    12  *     documentation and/or other materials provided with the distribution. 
       
    13  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
       
    14  *     its contributors may be used to endorse or promote products derived
       
    15  *     from this software without specific prior written permission. 
       
    16  *
       
    17  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
       
    18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
       
    20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
       
    21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
       
    22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
       
    23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
       
    24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
       
    26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    27  */
       
    28 
       
    29 
       
    30 #include "UnknownContentHandler.h"
       
    31 #include "HttpConnection.h"
       
    32 #include "PlatformString.h"
       
    33 #include <Uri8.h>
       
    34 #include <apgcli.h>
       
    35 using namespace WebCore;
       
    36 
       
    37 
       
    38 UnknownContentHandler::UnknownContentHandler(HttpConnection* connection)
       
    39 {
       
    40     m_connection = connection;
       
    41     m_response = NULL;
       
    42 }
       
    43 
       
    44 UnknownContentHandler::~UnknownContentHandler()
       
    45 {
       
    46     delete m_response;
       
    47 }
       
    48 
       
    49 UnknownContentHandler* UnknownContentHandler::NewL(HttpConnection* connection, WebCore::ResourceResponse& response)
       
    50 {
       
    51     UnknownContentHandler* self = NULL;
       
    52     self = new(ELeave) UnknownContentHandler(connection);
       
    53     CleanupStack::PushL(self);
       
    54     self->ConstructL(response);
       
    55     CleanupStack::Pop(self);
       
    56     return self;
       
    57 }
       
    58 
       
    59 bool UnknownContentHandler::isUnknownContent(ResourceResponse& response)
       
    60 {
       
    61     const String& mimeType = response.mimeType();
       
    62     const KURL& url = response.url();
       
    63 
       
    64     if( equalIgnoringCase(mimeType, "application/octet-stream")) {
       
    65         TUriParser8 parser;
       
    66         if( parser.Parse(url.des()) == KErrNone ) {
       
    67             TPtrC8 path = parser.Extract( EUriPath );
       
    68             int length = path.Length();
       
    69             if( length > 4 ) {
       
    70                 if (path.Find(_L8(".html")) != KErrNotFound || path.Find(_L8(".htm")) != KErrNotFound) {
       
    71                     response.setMimeType("text/html");
       
    72                     return false; // good chance of being html content
       
    73                 }
       
    74                 if (path.Find(_L8(".xhtml")) != KErrNotFound ) {
       
    75                     response.setMimeType("application/xhtml+xml");
       
    76                     return false; // good chance of being xhtml content
       
    77                 }
       
    78                 if (path.Find(_L8(".wml")) != KErrNotFound) {
       
    79                     response.setMimeType("text/vnd.wap.wml");
       
    80                     return false; // good chance of being wml content
       
    81                 }
       
    82             }
       
    83         }
       
    84         return true; // could be html
       
    85     }
       
    86     return false;
       
    87 }
       
    88 
       
    89 
       
    90 void UnknownContentHandler::updateContentTypeL(TPtrC8& chunkPtr)
       
    91 {
       
    92     RApaLsSession apaSession;
       
    93     TInt ret;
       
    94     User::LeaveIfError( apaSession.Connect() );
       
    95     TDataRecognitionResult dataType;
       
    96     ret = apaSession.RecognizeData( KNullDesC, chunkPtr, dataType );
       
    97     apaSession.Close();
       
    98     
       
    99     if( ret == KErrNone &&
       
   100       ( dataType.iConfidence == CApaDataRecognizerType::ECertain ) ||
       
   101       ( dataType.iConfidence == CApaDataRecognizerType::EProbable ) ) {       
       
   102         // "text/plain" shouldn't be treated as a strong type
       
   103         if (dataType.iDataType.Des8().FindF(_L8("text/plain")) == KErrNotFound) {
       
   104             m_response->setMimeType(dataType.iDataType.Des8());
       
   105         }
       
   106     }
       
   107 }
       
   108 
       
   109 ResourceResponse* UnknownContentHandler::handOffResponse()
       
   110 {
       
   111     ResourceResponse* response = m_response;
       
   112     m_response = NULL;
       
   113     return response;
       
   114 }
       
   115 
       
   116 void UnknownContentHandler::ConstructL(ResourceResponse& response)
       
   117 {
       
   118     m_response = new(ELeave) ResourceResponse(response.url(), response.mimeType(), response.expectedContentLength(), response.textEncodingName(), response.suggestedFilename());
       
   119 
       
   120 }
       
   121 
       
   122 
       
   123 // end of file