|
1 /* |
|
2 * Copyright (c) 2006 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: Implementation of CSynchRequest |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <../bidi.h> |
|
21 #include <e32std.h> |
|
22 #include <eikenv.h> |
|
23 |
|
24 #include "config.h" |
|
25 |
|
26 #include "BrCtl.h" |
|
27 #include "ResourceHandleInternal.h" |
|
28 #include "ResourceHandleManagerSymbian.h" |
|
29 #include "ResourceLoaderDelegate.h" |
|
30 #include "StaticObjectsContainer.h" |
|
31 |
|
32 #include "SynchRequest.h" |
|
33 |
|
34 namespace WebCore |
|
35 { |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS =============================== |
|
38 |
|
39 // ---------------------------------------------------------------------------- |
|
40 // CSynchRequest::NewL() |
|
41 // Two-phased constructor. |
|
42 // ---------------------------------------------------------------------------- |
|
43 // |
|
44 CSynchRequest* CSynchRequest::NewL() |
|
45 { |
|
46 CSynchRequest* self = NewLC(); |
|
47 CleanupStack::Pop(self); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // ---------------------------------------------------------------------------- |
|
52 // CSynchRequest::NewLC() |
|
53 // Two-phased constructor. |
|
54 // ---------------------------------------------------------------------------- |
|
55 // |
|
56 CSynchRequest* CSynchRequest::NewLC() |
|
57 { |
|
58 CSynchRequest* self = new ( ELeave ) CSynchRequest(); |
|
59 CleanupStack::PushL(self); |
|
60 self->ConstructL(); |
|
61 return self; |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------------------------------- |
|
65 // CSynchRequest::~CSynchRequest() |
|
66 // Destructor. |
|
67 // ---------------------------------------------------------------------------- |
|
68 // |
|
69 CSynchRequest::~CSynchRequest() |
|
70 { |
|
71 if (IsActive()) { |
|
72 Cancel(); |
|
73 } |
|
74 |
|
75 if (iActiveSchedulerWait) { |
|
76 delete iActiveSchedulerWait; |
|
77 iActiveSchedulerWait = NULL; |
|
78 } |
|
79 } |
|
80 |
|
81 // ---------------------------------------------------------------------------- |
|
82 // CSynchRequest::CSynchRequest() |
|
83 // Constructor. |
|
84 // ---------------------------------------------------------------------------- |
|
85 // |
|
86 CSynchRequest::CSynchRequest() |
|
87 : CActive(CActive::EPriorityStandard) |
|
88 , m_synchLoader(0) |
|
89 , m_error(String(), KErrNone, String(), String()) |
|
90 { |
|
91 CActiveScheduler::Add( this); |
|
92 } |
|
93 |
|
94 // ---------------------------------------------------------------------------- |
|
95 // CSynchRequest::ConstructL() |
|
96 // Perform second phase construction of this object. |
|
97 // ---------------------------------------------------------------------------- |
|
98 // |
|
99 void CSynchRequest::ConstructL() |
|
100 { |
|
101 // Initializing the ActiveShedulerWait. |
|
102 iActiveSchedulerWait = new (ELeave) CActiveSchedulerWait(); |
|
103 } |
|
104 |
|
105 // ---------------------------------------------------------------------------- |
|
106 // CSynchRequest::RunL() |
|
107 // Respond to an event. |
|
108 // ---------------------------------------------------------------------------- |
|
109 // |
|
110 void CSynchRequest::RunL() |
|
111 { |
|
112 if (KErrNone == iStatus.Int()) { |
|
113 m_error = ResourceError(); |
|
114 } else { |
|
115 m_error = ResourceError(String(), iStatus.Int(), String(), String()); |
|
116 } |
|
117 |
|
118 if (iActiveSchedulerWait->IsStarted()) { |
|
119 iActiveSchedulerWait->AsyncStop(); |
|
120 } |
|
121 } |
|
122 |
|
123 // ---------------------------------------------------------------------------- |
|
124 // CSynchRequest::DoCancel() |
|
125 // Cancel any outstanding requests. |
|
126 // ---------------------------------------------------------------------------- |
|
127 // |
|
128 void CSynchRequest::DoCancel() |
|
129 { |
|
130 if (m_synchLoader) { |
|
131 m_synchLoader->cancel(); |
|
132 } else { |
|
133 // Complete pending request |
|
134 if (KRequestPending == iStatus.Int()) { |
|
135 TRequestStatus* status = &iStatus; |
|
136 User::RequestComplete(status, KErrAbort); |
|
137 } |
|
138 } |
|
139 } |
|
140 |
|
141 // ---------------------------------------------------------------------------- |
|
142 // CSynchRequest::RunError(TInt aError) |
|
143 // Handles a leave occurring in the request completion event handler RunL(). |
|
144 // ---------------------------------------------------------------------------- |
|
145 // |
|
146 TInt CSynchRequest::RunError(TInt /*aError*/) |
|
147 { |
|
148 return KErrNone; |
|
149 } |
|
150 |
|
151 // ---------------------------------------------------------------------------- |
|
152 // CSynchRequest::CreateResource() |
|
153 // |
|
154 // ---------------------------------------------------------------------------- |
|
155 // |
|
156 |
|
157 void CSynchRequest::CreateResource(const ResourceRequest& request, |
|
158 ResourceError& error, |
|
159 ResourceResponse& response, |
|
160 Vector<char>& data, |
|
161 Frame* frame) |
|
162 { |
|
163 if (IsActive()) { |
|
164 Cancel(); |
|
165 } |
|
166 iStatus = KRequestPending; |
|
167 |
|
168 SetActive(); |
|
169 |
|
170 // Initialize loader for processing responses |
|
171 m_synchLoader = SynchResourceHandleClient::create(iStatus, request, frame); |
|
172 if (!m_synchLoader) { |
|
173 if (IsActive()) { |
|
174 Cancel(); |
|
175 } |
|
176 error = m_error; |
|
177 return; |
|
178 } |
|
179 |
|
180 // Wait for request finished or other failure/cancel events |
|
181 iActiveSchedulerWait->Start(); |
|
182 |
|
183 if (m_error.errorCode() != KErrNone) { |
|
184 // Prefer local override of error (e.g., to signal user cancel) |
|
185 error = m_error; |
|
186 } |
|
187 else { |
|
188 error = m_synchLoader->resourceError(); |
|
189 } |
|
190 data = m_synchLoader->data(); |
|
191 response = m_synchLoader->resourceResponse(); |
|
192 |
|
193 m_synchLoader = 0; |
|
194 } |
|
195 |
|
196 } // end namespace WebCore |
|
197 |
|
198 // End of File |