|
1 /* |
|
2 * Copyright (c) 2007 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "ResourceHandle.h" |
|
19 #include "ResourceHandleManagerSymbian.h" |
|
20 #include "ResolvedConnection.h" |
|
21 #include "ResourceRequest.h" |
|
22 |
|
23 #include "Brctl.h" |
|
24 #include "WebFrame.h" |
|
25 |
|
26 // EXTERNAL DATA STRUCTURES |
|
27 |
|
28 // EXTERNAL FUNCTION PROTOTYPES |
|
29 |
|
30 // CONSTANTS |
|
31 |
|
32 // MACROS |
|
33 |
|
34 // LOCAL CONSTANTS AND MACROS |
|
35 |
|
36 // MODULE DATA STRUCTURES |
|
37 |
|
38 // LOCAL FUNCTION PROTOTYPES |
|
39 |
|
40 // FORWARD DECLARATIONS |
|
41 |
|
42 using namespace WebCore; |
|
43 |
|
44 TInt processResponseCb(TAny* ptr) |
|
45 { |
|
46 ResolvedConnection* rc = static_cast<ResolvedConnection*>(ptr); |
|
47 rc->processResponse(); |
|
48 return KErrNone; |
|
49 } |
|
50 |
|
51 ResolvedConnection::ResolvedConnection(ResourceHandle* _handle, Frame* frame) : MUrlConnection(_handle) |
|
52 { |
|
53 m_frame = frame; |
|
54 m_didSubmit = false; |
|
55 m_scheduler = NULL; |
|
56 m_contentType = NULL; |
|
57 m_charset = NULL; |
|
58 m_contentBuf = NULL; |
|
59 m_maxSize = 0; |
|
60 } |
|
61 |
|
62 ResolvedConnection::~ResolvedConnection() |
|
63 { |
|
64 if (m_scheduler) { |
|
65 m_scheduler->Cancel(); |
|
66 delete m_scheduler; |
|
67 } |
|
68 delete m_contentType; |
|
69 delete m_charset; |
|
70 delete m_contentBuf; |
|
71 } |
|
72 |
|
73 int ResolvedConnection::submit() |
|
74 { |
|
75 m_didSubmit = true; |
|
76 if (m_contentBuf) { |
|
77 m_scheduler = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
78 m_scheduler->Start( 0, 0, TCallBack( &processResponseCb, this ) ); |
|
79 } |
|
80 return KErrNone; |
|
81 } |
|
82 |
|
83 void ResolvedConnection::cancel() |
|
84 { |
|
85 control(m_frame)->brCtlLinkResolver()->CancelAll(); |
|
86 } |
|
87 |
|
88 void ResolvedConnection::download(ResourceHandle* handle, |
|
89 const ResourceRequest& request, |
|
90 const ResourceResponse& response) |
|
91 { |
|
92 __ASSERT_ALWAYS(EFalse, User::Panic(_L("Resource Loader"), KErrArgument)); |
|
93 } |
|
94 |
|
95 void ResolvedConnection::HandleResolveComplete(const TDesC& aContentType, |
|
96 const TDesC& aCharset, |
|
97 const HBufC8* aContentBuf) |
|
98 { |
|
99 if (aContentType.Length() == 0 || aContentBuf == NULL) { |
|
100 complete(KErrArgument); |
|
101 } |
|
102 else { |
|
103 m_contentType = aContentType.Alloc(); |
|
104 m_charset = aCharset.Alloc(); |
|
105 m_contentBuf = aContentBuf->Alloc(); |
|
106 if (!(m_contentType && m_charset && m_contentBuf)) { |
|
107 complete(KErrNoMemory); |
|
108 } |
|
109 else { |
|
110 m_maxSize = aContentBuf->Length(); |
|
111 if (m_didSubmit) { |
|
112 m_scheduler = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
113 m_scheduler->Start( 0, 0, TCallBack( &processResponseCb, this ) ); |
|
114 } |
|
115 } |
|
116 } |
|
117 } |
|
118 |
|
119 void ResolvedConnection::processResponse() |
|
120 { |
|
121 if (m_scheduler) { |
|
122 m_scheduler->Cancel(); |
|
123 delete m_scheduler; |
|
124 m_scheduler = NULL; |
|
125 } |
|
126 __ASSERT_DEBUG(m_didSubmit && m_contentBuf, User::Panic(_L(""), KErrGeneral)); |
|
127 ResourceResponse response(m_handle->request().url().des(), m_contentType->Des(), m_contentBuf->Length(), m_charset->Des(), String() ); |
|
128 response.setHTTPStatusCode(200); |
|
129 CResourceHandleManager::self()->receivedResponse(m_handle, response, this); |
|
130 CResourceHandleManager::self()->receivedData(m_handle, m_contentBuf->Des(), m_contentBuf->Length(), this); |
|
131 CResourceHandleManager::self()->receivedFinished(m_handle, KErrNone, this); |
|
132 derefHandle(); |
|
133 } |
|
134 |
|
135 void ResolvedConnection::HandleResolveError(TInt aError) |
|
136 { |
|
137 complete(aError); |
|
138 } |
|
139 |
|
140 void ResolvedConnection::complete(int error) |
|
141 { |
|
142 CResourceHandleManager::self()->receivedFinished(m_handle, error, this); |
|
143 derefHandle(); |
|
144 } |
|
145 |
|
146 // end of file |