49
|
1 |
/*
|
|
2 |
* Copyright (c) 2005 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: Definition of CWmlContentInterface
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// INCLUDES
|
|
19 |
#include <e32base.h>
|
|
20 |
#include "BrsrStatusCodes.h"
|
|
21 |
#include "WmlContentInterface.h"
|
|
22 |
#include "nwx_http_defs.h"
|
|
23 |
#include "urlloader_urlresponse.h"
|
|
24 |
#include "urlloader_loaderutils.h"
|
|
25 |
|
|
26 |
// CONSTANTS
|
|
27 |
|
|
28 |
// MACROS
|
|
29 |
|
|
30 |
// DATA TYPES
|
|
31 |
|
|
32 |
// FUNCTION PROTOTYPES
|
|
33 |
|
|
34 |
// FORWARD DECLARATIONS
|
|
35 |
|
|
36 |
// -----------------------------------------------------------------------------
|
|
37 |
// CWmlContentInterface::NewL
|
|
38 |
// Public Class Method
|
|
39 |
// Two-phased constructor.
|
|
40 |
// -----------------------------------------------------------------------------
|
|
41 |
CWmlContentInterface* CWmlContentInterface::NewL()
|
|
42 |
{
|
|
43 |
CWmlContentInterface* self = new (ELeave) CWmlContentInterface();
|
|
44 |
CleanupStack::PushL( self );
|
|
45 |
self->ConstructL( );
|
|
46 |
CleanupStack::Pop(); // self
|
|
47 |
return self;
|
|
48 |
}
|
|
49 |
// -----------------------------------------------------------------------------
|
|
50 |
// CWmlContentInterface::CWmlContentInterface
|
|
51 |
// Public Class Method
|
|
52 |
// C++ default constructor.
|
|
53 |
// -----------------------------------------------------------------------------
|
|
54 |
CWmlContentInterface::CWmlContentInterface()
|
|
55 |
{
|
|
56 |
|
|
57 |
}
|
|
58 |
|
|
59 |
// -----------------------------------------------------------------------------
|
|
60 |
// CWmlContentInterface::ConstructL
|
|
61 |
// Public Class Method
|
|
62 |
// Symbian 2nd phase constructor
|
|
63 |
// -----------------------------------------------------------------------------
|
|
64 |
void CWmlContentInterface::ConstructL()
|
|
65 |
{
|
|
66 |
|
|
67 |
}
|
|
68 |
// -----------------------------------------------------------------------------
|
|
69 |
// CWmlContentInterface::PartialResponse
|
|
70 |
// Public Class Method
|
|
71 |
// sends the partial response.
|
|
72 |
// -----------------------------------------------------------------------------
|
|
73 |
TBrowserStatusCode CWmlContentInterface::WMLPartialResponse( const TUint16* aUri,
|
|
74 |
TPtr8& aBody,
|
|
75 |
void* aHeaders,
|
|
76 |
TUint8* aContentTypeString,
|
|
77 |
TUint8* aContentLocationString,
|
|
78 |
TBool aNoStore,
|
|
79 |
TUint8* aBoundaryString,
|
|
80 |
TUint16* aLastModified,
|
|
81 |
TUint16 aCharset,
|
|
82 |
TUint8* aCharsetString,
|
|
83 |
TUint aHttpStatus,
|
|
84 |
TUint8 aMethod,
|
|
85 |
TUint16 aTransId,
|
|
86 |
TInt aChunkIndex,
|
|
87 |
void* aCertInfo,
|
|
88 |
TUint aContentLength,
|
|
89 |
TInt aErr,
|
|
90 |
void* aLoadContext,
|
|
91 |
void* aPartialCallback )
|
|
92 |
{
|
|
93 |
TUint convertedHttpStatus = aHttpStatus;
|
|
94 |
|
|
95 |
__ASSERT_DEBUG(aUri != NULL, LoaderUtils::PanicLoader());
|
|
96 |
__ASSERT_DEBUG(aPartialCallback != NULL, LoaderUtils::PanicLoader());
|
|
97 |
|
|
98 |
LoaderUtils::LogLoaderEvents(ELogTypeResponse, aTransId, aUri);
|
|
99 |
|
|
100 |
TUint8* body = (TUint8*)aBody.Ptr();
|
|
101 |
|
|
102 |
if (aBody.Length() && aHttpStatus > Success && aHttpStatus < MultipleChoices)
|
|
103 |
{
|
|
104 |
/* Http status of 2xx is success, we map to OK (200) if there is a body. */
|
|
105 |
convertedHttpStatus = Success;
|
|
106 |
}
|
|
107 |
|
|
108 |
if (aBody.Length() && aHttpStatus >= MultipleChoices && aHttpStatus < BadRequest)
|
|
109 |
{
|
|
110 |
/* Display the content, not a generic error, if there is a body. */
|
|
111 |
convertedHttpStatus = Success;
|
|
112 |
}
|
|
113 |
|
|
114 |
if (aBody.Length() && aHttpStatus >= ServerError && aHttpStatus < 600)
|
|
115 |
{
|
|
116 |
/* Display the content, not a generic error, if there is a body. */
|
|
117 |
convertedHttpStatus = Success;
|
|
118 |
}
|
|
119 |
|
|
120 |
// when dealing with http status 300 and 500 check to see if body is present
|
|
121 |
// if so we want to treat this as a standard content load and force the
|
|
122 |
// http status to be 200 (success)
|
|
123 |
|
|
124 |
if ((body) && (((aHttpStatus >= MultipleChoices) && (aHttpStatus < 400)) || ((aHttpStatus >= ServerError) && (aHttpStatus < 600))))
|
|
125 |
{
|
|
126 |
aHttpStatus = Success;
|
|
127 |
convertedHttpStatus = Success;
|
|
128 |
iIsBodyPresent = ETrue;
|
|
129 |
}
|
|
130 |
|
|
131 |
if ((iIsBodyPresent && (aChunkIndex == -1)) && (((aHttpStatus >= MultipleChoices) && (aHttpStatus < 400)) || ((aHttpStatus >= ServerError) && (aHttpStatus < 600))))
|
|
132 |
{
|
|
133 |
aHttpStatus = Success;
|
|
134 |
convertedHttpStatus = Success;
|
|
135 |
iIsBodyPresent = EFalse;
|
|
136 |
}
|
|
137 |
|
|
138 |
TBrowserStatusCode status = (aErr == KErrNone && convertedHttpStatus != Success) ?
|
|
139 |
KBrsrHttpStatus : LoaderUtils::MapErrors(aErr);
|
|
140 |
|
|
141 |
NW_Url_Resp_t* urlResp = UrlLoader_UrlResponseNew(aUri, (TUint8*)aBody.Ptr(),
|
|
142 |
aBody.Length(), aHeaders,
|
|
143 |
aContentTypeString,
|
|
144 |
aContentLocationString,
|
|
145 |
aNoStore,
|
|
146 |
aBoundaryString,
|
|
147 |
aLastModified,
|
|
148 |
aCharset,
|
|
149 |
aCharsetString,
|
|
150 |
aHttpStatus,
|
|
151 |
aMethod,
|
|
152 |
aTransId,
|
|
153 |
aContentLength);
|
|
154 |
if (aCertInfo != NULL)
|
|
155 |
{
|
|
156 |
urlResp->certInfo = aCertInfo;
|
|
157 |
}
|
|
158 |
|
|
159 |
CleanupStack::PushL(aContentTypeString);
|
|
160 |
CleanupStack::PushL(aContentLocationString);
|
|
161 |
CleanupStack::PushL(aBoundaryString);
|
|
162 |
CleanupStack::PushL(aLastModified);
|
|
163 |
CleanupStack::PushL(body);
|
|
164 |
if (urlResp == NULL)
|
|
165 |
{
|
|
166 |
status = ((NW_Url_RespCallback_t*)aPartialCallback)(KBrsrOutOfMemory, aTransId, aChunkIndex, aLoadContext, NULL);
|
|
167 |
CleanupStack::PopAndDestroy(5); // body, aContentTypeString, aContentLocationString
|
|
168 |
// aBoundaryString, aLastModified
|
|
169 |
}
|
|
170 |
else
|
|
171 |
{
|
|
172 |
status = ((NW_Url_RespCallback_t*)aPartialCallback)(status, aTransId, aChunkIndex, aLoadContext, urlResp);
|
|
173 |
CleanupStack::Pop(5); // body, aContentTypeString, aContentLocationString, aBoundaryString, aLastModified
|
|
174 |
}
|
|
175 |
|
|
176 |
return status;
|
|
177 |
}
|
|
178 |
|
|
179 |
void CWmlContentInterface::setUrl(const TDesC& aUrl)
|
|
180 |
{
|
|
181 |
m_resourceUrl = HBufC::New(aUrl.Length() + 1);
|
|
182 |
m_resourceUrl->Des().Append((const TUint16*) aUrl.Ptr(), aUrl.Length());
|
|
183 |
m_resourceUrl->Des().ZeroTerminate();
|
|
184 |
}
|
|
185 |
|
|
186 |
// -----------------------------------------------------------------------------
|
|
187 |
// CWmlContentInterface::~CWmlContentInterface()
|
|
188 |
// Public Class Method
|
|
189 |
// Donstructor.
|
|
190 |
// -----------------------------------------------------------------------------
|
|
191 |
CWmlContentInterface::~CWmlContentInterface()
|
|
192 |
{
|
|
193 |
|
|
194 |
}
|
|
195 |
|
|
196 |
// End of File
|