|
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 "HttpUiCallbacks.h" |
|
19 #include "Page.h" |
|
20 #include <../bidi.h> |
|
21 #include <StringLoader.h> |
|
22 #include <Uri16.h> |
|
23 #include <es_enum.h> |
|
24 #include <Webkit.rsg> |
|
25 #include "WebFrame.h" |
|
26 #include "WebFrameView.h" |
|
27 #include "WebView.h" |
|
28 #include "BrCtl.h" |
|
29 #include "SettingsContainer.h" |
|
30 #include "BrCtlSpecialLoadObserver.h" |
|
31 #include "StaticObjectsContainer.h" |
|
32 #include "ResourceLoaderDelegate.h" |
|
33 #include "HttpDefs.h" |
|
34 #include "HttpConnection.h" |
|
35 #include "CDBCols.h" |
|
36 |
|
37 using namespace WebCore; |
|
38 |
|
39 // CONSTANTS |
|
40 _LIT (KEmptyTitle, ""); |
|
41 |
|
42 static CBrCtl* brctl() |
|
43 { |
|
44 return StaticObjectsContainer::instance()->brctl(); |
|
45 } |
|
46 |
|
47 HttpUiCallbacks::HttpUiCallbacks() |
|
48 { |
|
49 m_error = KErrNone; |
|
50 m_scheduler = NULL; |
|
51 } |
|
52 |
|
53 HttpUiCallbacks::~HttpUiCallbacks() |
|
54 { |
|
55 if (m_scheduler) { |
|
56 m_scheduler->Cancel(); |
|
57 delete m_scheduler; |
|
58 } |
|
59 } |
|
60 |
|
61 TInt HttpUiCallbacks::handleErrorCb(TAny* aPtr) |
|
62 { |
|
63 HttpUiCallbacks* self = static_cast<HttpUiCallbacks*>(aPtr); |
|
64 self->handleError(); |
|
65 return KErrNone; |
|
66 } |
|
67 |
|
68 void HttpUiCallbacks::handleError() |
|
69 { |
|
70 m_scheduler->Cancel(); |
|
71 delete m_scheduler; |
|
72 m_scheduler = NULL; |
|
73 StaticObjectsContainer::instance()->resourceLoaderDelegate()->httpSessionManager()->handleError(m_error); |
|
74 } |
|
75 |
|
76 |
|
77 TInt HttpUiCallbacks::CreateConnection(TInt* aConnectionPtr, TInt* aSockSvrHandle, |
|
78 TBool* aNewConn, TApBearerType* aBearerType) |
|
79 { |
|
80 TInt error = KErrNone; |
|
81 if( aConnectionPtr && aSockSvrHandle && aNewConn ){ |
|
82 TRAP(error, brctl()->brCtlSpecialLoadObserver()->NetworkConnectionNeededL(aConnectionPtr, aSockSvrHandle, aNewConn, aBearerType)); |
|
83 if( error == KErrNone && *aConnectionPtr ) { |
|
84 RConnection* connPtr = REINTERPRET_CAST( RConnection*, *aConnectionPtr ); |
|
85 TConnectionInfoBuf connInfoBuf; |
|
86 TUint conns( 0 ); |
|
87 connPtr->EnumerateConnections( conns ); |
|
88 if (conns > 0 && connPtr->GetConnectionInfo(1, connInfoBuf) == KErrNone ) |
|
89 { |
|
90 TUint32 iapId; |
|
91 TBuf<20> query; |
|
92 |
|
93 //Get the IAP id used by browser from the RConnection object. |
|
94 query.Format( _L("%s\\%s"), IAP, COMMDB_ID ); |
|
95 if( connPtr->GetIntSetting( query, iapId ) == KErrNone) |
|
96 { |
|
97 // Set the access point Id to BrCrl |
|
98 brctl()->webView()->setAccessPointId( iapId ); |
|
99 |
|
100 } |
|
101 //If IAP is not avilable from connection Object then use the first connection. |
|
102 else |
|
103 { |
|
104 brctl()->webView()->setAccessPointId( connInfoBuf().iIapId ); |
|
105 } |
|
106 } |
|
107 //pass the connection to download manager |
|
108 // let the dm know about the connection |
|
109 HttpDownload* httpDownload = StaticObjectsContainer::instance()->resourceLoaderDelegate()->httpSessionManager()->httpDownload(); |
|
110 if(httpDownload) |
|
111 { |
|
112 TName name; |
|
113 connPtr->Name( name ); |
|
114 httpDownload->connect( name ); |
|
115 } |
|
116 } |
|
117 } |
|
118 // no connection, cancel transactions asynchronously |
|
119 if( error != KErrNone ) { |
|
120 m_error = error; |
|
121 if (m_scheduler == NULL) { |
|
122 m_scheduler = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
123 m_scheduler->Start( 0, 0, TCallBack( &handleErrorCb, this ) ); |
|
124 } |
|
125 } |
|
126 return error; |
|
127 } |
|
128 |
|
129 void HttpUiCallbacks::CoverageEvent( TInt aError ) |
|
130 { |
|
131 TInt error = (aError == EErrNetUnreach) ? KErrNetUnreach : |
|
132 ((aError == EErrWaitTimeout ) ? KBrowserWaitTimeout : KErrNone); |
|
133 TRAP_IGNORE(brctl()->brCtlDialogsProvider()->DialogNotifyErrorL(error)); |
|
134 StaticObjectsContainer::instance()->resourceLoaderDelegate()->httpSessionManager()->handleError(error); |
|
135 // the download manager handles coverage event in the Dl Mgr Server (KShutDownTimer = 30 sec). |
|
136 } |
|
137 |
|
138 int HttpUiCallbacks::aboutToLoadPage(CBrCtl* brctl, int stateType) |
|
139 { |
|
140 int ret = KErrNone; |
|
141 TRAPD(err, ret = aboutToLoadPageL(brctl, stateType)); |
|
142 return (err == KErrNone) ? ret : err; |
|
143 } |
|
144 |
|
145 int HttpUiCallbacks::aboutToLoadPageL(CBrCtl* brctl, int stateType) |
|
146 { |
|
147 TBool result ( ETrue ); |
|
148 TEnterStatus enterStatus ( (TEnterStatus)stateType ); |
|
149 TInt resId ( 0 ); // don't display a dialog, |
|
150 // event = 0 means, don't send an event. NOTE: TBrCtlDefs::EEventNone = 0 |
|
151 TBrCtlDefs::TBrCtlLoadEvent event ( TBrCtlDefs::EEventNone ) ; |
|
152 // Map TEnterStatus to a corresponding dialog string |
|
153 // resource IDs and browser load event |
|
154 switch (enterStatus) |
|
155 { |
|
156 case EExitingSecurePage: |
|
157 { |
|
158 resId = R_HTTPSEC_LEAVE_SECURE_SITE; |
|
159 event = TBrCtlDefs::EEventExitingSecurePage; |
|
160 break; |
|
161 } |
|
162 case EEnteringSecurePage: |
|
163 { |
|
164 resId = R_HTTPSEC_ENTER_SECURE_SITE; |
|
165 event = TBrCtlDefs::EEventEnteringSecurePage; |
|
166 break; |
|
167 } |
|
168 case ESomeItemsNotSecure: |
|
169 { |
|
170 resId = R_HTTPSEC_SOME_ITEMS_NOT_SECURE; |
|
171 event = TBrCtlDefs::EEventSomeItemsNotSecure; |
|
172 break; |
|
173 } |
|
174 case ESubmittingToNonSecurePage: |
|
175 { |
|
176 resId = R_HTTPSEC_SUBMITTING_TO_NON_SECURE_PAGE; |
|
177 event = TBrCtlDefs::EEventExitingSecurePage; |
|
178 break; |
|
179 } |
|
180 case ERedirectConfirmation: |
|
181 { |
|
182 resId = R_HTTP_REDIRECT_POST_CONFIRMATION; |
|
183 event = TBrCtlDefs::EEventRedirectConfirmation; |
|
184 break; |
|
185 } |
|
186 case ERepostConfirmation: |
|
187 { |
|
188 resId = R_HTTP_REPOST_CONFIRMATION; |
|
189 event = TBrCtlDefs::EEventRepostConfirmation; |
|
190 break; |
|
191 } |
|
192 case ESecureItemInNonSecurePage: |
|
193 { |
|
194 resId = 0; |
|
195 event = TBrCtlDefs::EEventSecureItemInNonSecurePage; |
|
196 break; |
|
197 } |
|
198 |
|
199 default: |
|
200 { |
|
201 resId = 0; |
|
202 event = TBrCtlDefs::EEventNone; |
|
203 break; |
|
204 } |
|
205 } // end of switch |
|
206 TUint retVal = brctl->settings()->brctlSetting(TBrCtlDefs::ESettingsSecurityWarnings); |
|
207 // Show dialogs only if warning dialogs are enabled in the preferences, and |
|
208 if (retVal && resId) |
|
209 { |
|
210 HBufC* message = StringLoader::LoadLC(resId); |
|
211 HBufC* leftMessage = NULL; |
|
212 HBufC* rightMessage = NULL; |
|
213 leftMessage = StringLoader::LoadLC(R_TEXT_SOFTKEY_YES); |
|
214 rightMessage = StringLoader::LoadLC(R_TEXT_SOFTKEY_NO); |
|
215 MBrCtlDialogsProvider* dialogsProvider = brctl->brCtlDialogsProvider(); |
|
216 TRAPD(err, result = dialogsProvider->DialogConfirmL(KEmptyTitle, |
|
217 *message, |
|
218 *leftMessage, |
|
219 *rightMessage)); |
|
220 // Clean up the memory we allocated, before returning |
|
221 CleanupStack::PopAndDestroy(3); // message, leftMessage, rightMessage |
|
222 // Check to see if DialogConfirmL leaves |
|
223 if (err != KErrNone) |
|
224 { |
|
225 return KErrNoMemory; |
|
226 } |
|
227 // If the user selected "No" or "Cancel", we are cancelling the load |
|
228 if ( !result ) |
|
229 { |
|
230 return KErrCancel; |
|
231 } |
|
232 } // end of if |
|
233 if(result && event != TBrCtlDefs::EEventNone) |
|
234 // Send the BrowserLoadEvent to the registered listeners |
|
235 { |
|
236 brctl->HandleBrowserLoadEventL(event, 0, 0); |
|
237 } |
|
238 |
|
239 // The user selected "Yes" or "Continue" or we aren't displaying a dialog |
|
240 return KErrNone; |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // HttpUiCallbacks::AuthenticationNeeded |
|
245 // Public Class Method |
|
246 // UI Call back to inform authentication is required |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 void HttpUiCallbacks::AuthenticationRequest( |
|
250 HttpConnection* aHttpConn, |
|
251 TPtr& aUri, |
|
252 TPtr& aUsername, |
|
253 TPtr& aRealm, |
|
254 bool aProxy, |
|
255 bool aDataExists, |
|
256 TPtr& aPassword, |
|
257 bool aBasicAuthentication ) |
|
258 { |
|
259 TPtr usernamePtr(NULL, 0); |
|
260 TPtr passwordPtr(NULL, 0); |
|
261 TUint16* retUsername = NULL; |
|
262 TUint16* retPassword = NULL; |
|
263 int status( KErrNone ); |
|
264 int error( KErrNone ); |
|
265 // Check if authentication data exists |
|
266 // If Yes: |
|
267 if( !aDataExists ) |
|
268 { |
|
269 //Get user authentication data |
|
270 TRAP(status, GetUserAuthenticationDataL(aHttpConn, aUri.Ptr(), |
|
271 aUsername.Ptr(), aRealm.Ptr(), &retUsername, |
|
272 &retPassword, aBasicAuthentication)); |
|
273 switch (status) |
|
274 { |
|
275 case KErrNone: |
|
276 { |
|
277 if (retUsername ) |
|
278 { |
|
279 usernamePtr.Set(retUsername, User::StringLength(retUsername), |
|
280 User::StringLength(retUsername)); |
|
281 } |
|
282 if (retPassword != NULL) |
|
283 { |
|
284 passwordPtr.Set(retPassword, User::StringLength(retPassword), |
|
285 User::StringLength(retPassword)); |
|
286 } |
|
287 break; |
|
288 } |
|
289 case KErrCancel: |
|
290 { |
|
291 error = KErrCancel; |
|
292 break; |
|
293 } |
|
294 case KErrNoMemory: |
|
295 { |
|
296 error = KErrNoMemory; |
|
297 break; |
|
298 } |
|
299 default: |
|
300 { |
|
301 error = KErrGeneral; |
|
302 break; |
|
303 } |
|
304 } |
|
305 } |
|
306 else |
|
307 // if aDataExists take the existing uname/pwd again, because |
|
308 // they were ok, but nonce was expired. |
|
309 // Make a copy of the original uname/pwd. |
|
310 { |
|
311 retPassword = new TUint16 [aPassword.Length() + 1]; |
|
312 if ( retPassword ) |
|
313 { |
|
314 passwordPtr.Set(retPassword, aPassword.Length() + 1, aPassword.Length() + 1); |
|
315 passwordPtr.Copy(aPassword); |
|
316 passwordPtr.ZeroTerminate(); |
|
317 retUsername = new TUint16 [aUsername.Length() + 1]; |
|
318 if ( retUsername ) |
|
319 { |
|
320 usernamePtr.Set(retUsername, aUsername.Length() + 1, aUsername.Length() + 1); |
|
321 usernamePtr.Copy(aUsername); |
|
322 usernamePtr.ZeroTerminate(); |
|
323 } |
|
324 else |
|
325 { |
|
326 passwordPtr.Set( NULL, 0, 0 ); |
|
327 delete [] retPassword; |
|
328 retPassword = NULL; |
|
329 error = KErrNoMemory; |
|
330 } |
|
331 } |
|
332 else |
|
333 { |
|
334 error = KErrNoMemory; |
|
335 } |
|
336 } |
|
337 // send the credentials |
|
338 aHttpConn->AuthenticationResponse( usernamePtr, passwordPtr, aProxy, error); |
|
339 } |
|
340 |
|
341 // ----------------------------------------------------------------------------- |
|
342 // HttpUiCallbacks::NextUriL |
|
343 // Private Class Method |
|
344 // ----------------------------------------------------------------------------- |
|
345 void HttpUiCallbacks::NextUriL(const TDesC8& aUri, CBrCtl* brCtl) |
|
346 { |
|
347 HBufC16* urlDes = HBufC16::NewLC(aUri.Length()); |
|
348 urlDes->Des().Copy(aUri); |
|
349 if (brCtl) |
|
350 brCtl->LoadUrlL (*urlDes, -1, TBrCtlDefs::ECacheModeNormal); |
|
351 CleanupStack::Pop(urlDes); |
|
352 } |
|
353 |
|
354 // ----------------------------------------------------------------------------- |
|
355 // HttpUiCallbacks::GetUserAuthenticationDataL |
|
356 // Private Class Method |
|
357 // ----------------------------------------------------------------------------- |
|
358 void HttpUiCallbacks::GetUserAuthenticationDataL( |
|
359 HttpConnection* aHttpConn, |
|
360 const TUint16* aUri, |
|
361 const TUint16* aUsername, |
|
362 const TUint16* aRealm, |
|
363 TUint16** aRetUsername, |
|
364 TUint16** aRetPassword, |
|
365 bool aBasicAuthentication) |
|
366 { |
|
367 TBool bRet( EFalse ); |
|
368 HBufC* returnedUserName = NULL; |
|
369 HBufC* returnedPasswd = NULL; |
|
370 // Initialize our return values |
|
371 *aRetUsername = NULL; |
|
372 *aRetPassword = NULL; |
|
373 TInt needPop ( 0 ); |
|
374 |
|
375 CBrCtl* brCtl = control(aHttpConn->frame()); |
|
376 MBrCtlDialogsProvider* dialogsProvider = brCtl->brCtlDialogsProvider(); |
|
377 |
|
378 // Display the User Authentication Dialog |
|
379 bRet = dialogsProvider->DialogUserAuthenticationLC(TPtrC(aUri), |
|
380 TPtrC(aRealm), |
|
381 TPtrC(aUsername), |
|
382 returnedUserName, |
|
383 returnedPasswd, |
|
384 aBasicAuthentication); |
|
385 |
|
386 TUint retVal ( 0 ); |
|
387 TRAP_IGNORE( retVal = brCtl->BrowserSettingL(TBrCtlDefs::ESettingsSecurityWarnings)); |
|
388 |
|
389 TUriParser uriParser; |
|
390 TBool secureScheme(EFalse); |
|
391 if(uriParser.Parse( TPtrC(aUri) ) == KErrNone) |
|
392 { |
|
393 if( uriParser.Extract( EUriScheme ).FindF( _L("https") ) == 0 ) |
|
394 { |
|
395 secureScheme = ETrue; |
|
396 } |
|
397 } |
|
398 |
|
399 // Display the Basic Authentication dialog, if needed. |
|
400 if (bRet && aBasicAuthentication && retVal && !secureScheme) |
|
401 { |
|
402 // Our memory pointers for the basic authentication dialog |
|
403 HBufC* message = NULL; |
|
404 HBufC* okMsg = NULL; |
|
405 HBufC* cancelMsg = NULL; |
|
406 // Set up the message text |
|
407 message = StringLoader::LoadLC(R_BROWSER_QUERY_BASIC_AUTHENTICATION); |
|
408 // Set up the OK button text |
|
409 okMsg = StringLoader::LoadLC(R_WML_OK_BUTTON); |
|
410 // Set up the CANCEL button text |
|
411 cancelMsg = StringLoader::LoadLC(R_WML_CANCEL_BUTTON); |
|
412 // Display the basic authentication dialog |
|
413 if (message && okMsg && cancelMsg) |
|
414 { |
|
415 bRet = dialogsProvider->DialogConfirmL(KEmptyTitle, *message, *okMsg, *cancelMsg); |
|
416 } |
|
417 // Clean up the basic authentication dialog memory |
|
418 CleanupStack::PopAndDestroy(3); // message, okMsg, cancelMsg |
|
419 } // end of if (bRet && basic authentication && display security warnings) |
|
420 // The user selected "yes" or "continue", from the dialog(s). |
|
421 // Return the username and password. |
|
422 if (bRet) |
|
423 { |
|
424 // Set up the returned user name |
|
425 if (!returnedUserName) |
|
426 { |
|
427 *aRetUsername = NULL; |
|
428 } |
|
429 else |
|
430 { |
|
431 *aRetUsername = new(ELeave) TUint16[returnedUserName->Length() + 1]; |
|
432 CleanupStack::PushL(*aRetUsername); |
|
433 needPop ++; |
|
434 |
|
435 TPtr usernamePtr(*aRetUsername, returnedUserName->Length() + 1); |
|
436 usernamePtr.Copy(*returnedUserName); |
|
437 usernamePtr.ZeroTerminate(); |
|
438 } |
|
439 |
|
440 // Set up the returned password |
|
441 if (!returnedPasswd) |
|
442 { |
|
443 *aRetPassword = NULL; |
|
444 } |
|
445 else |
|
446 { |
|
447 *aRetPassword = new(ELeave) TUint16[returnedPasswd->Length() + 1]; |
|
448 TPtr passwordPtr(*aRetPassword, returnedPasswd->Length() + 1); |
|
449 passwordPtr.Copy(*returnedPasswd); |
|
450 passwordPtr.ZeroTerminate(); |
|
451 } |
|
452 } |
|
453 else |
|
454 { |
|
455 TRAP_IGNORE(brCtl->HandleBrowserLoadEventL(TBrCtlDefs::EEventAuthenticationFailed, 0, 0)); |
|
456 } |
|
457 CleanupStack::Pop(needPop); // *aRetUsername |
|
458 |
|
459 // Clean up the memory from User Authentication dialog |
|
460 if (returnedUserName) |
|
461 { |
|
462 CleanupStack::PopAndDestroy(); // returnedUserName |
|
463 } |
|
464 if (returnedPasswd) |
|
465 { |
|
466 CleanupStack::PopAndDestroy(); // returnedPasswd |
|
467 } |
|
468 if (!bRet) |
|
469 { |
|
470 User::Leave(KErrCancel); |
|
471 } |
|
472 } |
|
473 |
|
474 // ----------------------------------------------------------------------------- |
|
475 // HttpUiCallbacks::reportError |
|
476 // ----------------------------------------------------------------------------- |
|
477 void HttpUiCallbacks::reportError(int error) |
|
478 { |
|
479 MBrCtlDialogsProvider* dialogsProvider = brctl()->brCtlDialogsProvider(); |
|
480 if ( dialogsProvider ) |
|
481 { |
|
482 TRAP_IGNORE(dialogsProvider->DialogNotifyErrorL(error)); |
|
483 } |
|
484 } |
|
485 |
|
486 void HttpUiCallbacks::reportHttpError(int error, const TDesC& aText ) |
|
487 { |
|
488 MBrCtlDialogsProvider* dialogsProvider = brctl()->brCtlDialogsProvider(); |
|
489 if ( dialogsProvider ) |
|
490 { |
|
491 TRAP_IGNORE(dialogsProvider->DialogNotifyHttpErrorL( error, aText ) ); |
|
492 } |
|
493 } |
|
494 |
|
495 // end of file |