webengine/wmlengine/src/urlloader/include/urlloader_murlschemehandler.inl
changeset 74 91031d3aab7d
parent 68 92a765b5b3e7
child 85 e358f2276d3f
equal deleted inserted replaced
68:92a765b5b3e7 74:91031d3aab7d
     1 /*
       
     2 * Copyright (c) 2003 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:  Handling of general url loading
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "BrsrStatusCodes.h"
       
    21 #include "nwx_http_defs.h"
       
    22 
       
    23 // EXTERNAL DATA STRUCTURES
       
    24 
       
    25 // EXTERNAL FUNCTION PROTOTYPES
       
    26 
       
    27 // CONSTANTS
       
    28 
       
    29 // MACROS
       
    30 
       
    31 // LOCAL CONSTANTS AND MACROS
       
    32 
       
    33 // MODULE DATA STRUCTURES
       
    34 
       
    35 // LOCAL FUNCTION PROTOTYPES
       
    36 
       
    37 // FORWARD DECLARATIONS
       
    38 
       
    39 // ============================= LOCAL FUNCTIONS ===============================
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // MUrlSchemeHandler::PartialResponse
       
    45 // Call the partial response callback with a chunk.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 inline TBrowserStatusCode MUrlSchemeHandler::PartialResponse(const TUint16* aUri,
       
    49                                         TPtr8& aBody,
       
    50                                         void* aHeaders,
       
    51                                         TUint8* aContentTypeString,
       
    52                                         TUint8* aContentLocationString,
       
    53                                         NW_Bool aNoStore,
       
    54                                         TUint8* aBoundaryString,
       
    55                                         TUint16* aLastModified,
       
    56                                         TUint16 aCharset,
       
    57                                         NW_Uint8 *aCharsetString,
       
    58                                         TUint aHttpStatus,
       
    59                                         TUint8 aMethod,
       
    60                                         TUint16 aTransId,
       
    61                                         TInt aChunkIndex,
       
    62                                         void* aCertInfo,
       
    63                                         TUint aContentLength,
       
    64                                         TInt aErr,
       
    65                                         void* aLoadContext,
       
    66                                         NW_Url_RespCallback_t* aPartialCallback )
       
    67   {
       
    68     TUint convertedHttpStatus = aHttpStatus;
       
    69 
       
    70   __ASSERT_DEBUG(aUri != NULL, LoaderUtils::PanicLoader());
       
    71   __ASSERT_DEBUG(aPartialCallback != NULL, LoaderUtils::PanicLoader());
       
    72 
       
    73   LoaderUtils::LogLoaderEvents(ELogTypeResponse, aTransId, aUri);
       
    74 
       
    75   TUint8* body = (TUint8*)aBody.Ptr();
       
    76 
       
    77     if (aBody.Length() && aHttpStatus > Success && aHttpStatus < MultipleChoices)
       
    78     {
       
    79         /* Http status of 2xx is success, we map to OK (200) if there is a body. */
       
    80         convertedHttpStatus = Success;
       
    81     }
       
    82 
       
    83     if (aBody.Length() && aHttpStatus >= MultipleChoices && aHttpStatus < BadRequest)
       
    84     {
       
    85         /* Display the content, not a generic error, if there is a body. */
       
    86         convertedHttpStatus = Success;
       
    87     }
       
    88 
       
    89     if (aBody.Length() && aHttpStatus >= ServerError && aHttpStatus < 600)
       
    90     {
       
    91         /* Display the content, not a generic error, if there is a body. */
       
    92         convertedHttpStatus = Success;
       
    93     }
       
    94 
       
    95     // when dealing with http status 300 and 500 check to see if body is present
       
    96     // if so we want to treat this as a standard content load and force the
       
    97     // http status to be 200 (success)
       
    98 
       
    99     if ((body) && (((aHttpStatus >= MultipleChoices) && (aHttpStatus < 400)) || ((aHttpStatus >= ServerError) && (aHttpStatus < 600))))
       
   100         {
       
   101         aHttpStatus = Success;
       
   102         convertedHttpStatus = Success;
       
   103         iIsBodyPresent = ETrue;
       
   104         }
       
   105 
       
   106     if ((iIsBodyPresent && (aChunkIndex == -1)) && (((aHttpStatus >= MultipleChoices) && (aHttpStatus < 400)) || ((aHttpStatus >= ServerError) && (aHttpStatus < 600))))
       
   107         {
       
   108         aHttpStatus = Success;
       
   109         convertedHttpStatus = Success;
       
   110         iIsBodyPresent = EFalse;
       
   111         }
       
   112 
       
   113     TBrowserStatusCode status = (aErr == KErrNone && convertedHttpStatus != Success) ?
       
   114                        KBrsrHttpStatus : LoaderUtils::MapErrors(aErr);
       
   115 
       
   116   NW_Url_Resp_t* urlResp = UrlLoader_UrlResponseNew(aUri, (TUint8*)aBody.Ptr(),
       
   117                                                    aBody.Length(), aHeaders,
       
   118                                                    aContentTypeString,
       
   119                                                    aContentLocationString,
       
   120                                                    aNoStore,
       
   121                                                    aBoundaryString, 
       
   122                                                    aLastModified,
       
   123                                                    aCharset,
       
   124                                                    aCharsetString,
       
   125                                                    aHttpStatus, 
       
   126                                                    aMethod,
       
   127                                                    aTransId,
       
   128                                                    aContentLength);
       
   129   if (aCertInfo != NULL)
       
   130     {
       
   131     urlResp->certInfo = aCertInfo;
       
   132     }
       
   133   
       
   134   CleanupStack::PushL(aContentTypeString);
       
   135   CleanupStack::PushL(aContentLocationString);
       
   136   CleanupStack::PushL(aBoundaryString);
       
   137   CleanupStack::PushL(aLastModified);
       
   138   CleanupStack::PushL(body);
       
   139   if (urlResp == NULL)
       
   140     {
       
   141     status = (aPartialCallback)(KBrsrOutOfMemory, aTransId, aChunkIndex, aLoadContext, NULL);
       
   142     CleanupStack::PopAndDestroy(5); // body, aContentTypeString, aContentLocationString
       
   143                                     // aBoundaryString, aLastModified
       
   144     }
       
   145   else
       
   146     {
       
   147     status = (aPartialCallback)(status, aTransId, aChunkIndex, aLoadContext, urlResp);
       
   148     CleanupStack::Pop(5); // body, aContentTypeString, aContentLocationString, aBoundaryString, aLastModified
       
   149     }
       
   150   return status;
       
   151   }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // MUrlSchemeHandler::Response
       
   155 // Call the response callback with an error code.
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 inline TBrowserStatusCode MUrlSchemeHandler::PartialResponse(TUint16 aTransId,
       
   159                                                TInt aErr,
       
   160                                                void* aLoadContext,
       
   161                                                NW_Url_RespCallback_t* aPartialCallback)
       
   162 {
       
   163     __ASSERT_DEBUG(aPartialCallback != NULL, LoaderUtils::PanicLoader());
       
   164 
       
   165     LoaderUtils::LogLoaderEvents(ELogTypeFailedResponse, aTransId,
       
   166 				LoaderUtils::MapErrors(aErr));
       
   167     return (aPartialCallback)(LoaderUtils::MapErrors(aErr), aTransId, -1, aLoadContext, NULL);
       
   168 }
       
   169 
       
   170 //  End of File