Changeset 153882 in webkit
- Timestamp:
- Aug 9, 2013 3:48:49 AM (11 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 6 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r153879 r153882 1 2013-08-09 Brian Holt <brian.holt@samsung.com> 2 3 [GTK] [WebKit2] Add an 'authenticate' signal to WebKitWebView 4 https://bugs.webkit.org/show_bug.cgi?id=99352 5 6 Reviewed by Carlos Garcia Campos. 7 8 Add a new public class to the API, WebKitAuthenticationRequest, to be 9 emitted along with a new WebKitWebView::authenticate signal to 10 let client applications to provide their own authentication 11 when the user is challenged with HTTP authentication. The 12 credential is exposed through a new class WebKitCredential. 13 14 * GNUmakefile.list.am: 15 * UIProcess/API/gtk/WebKitAuthenticationDialog.cpp: 16 (okButtonClicked): Use new API for authentication. 17 (cancelButtonClicked): Ditto. 18 (webkitAuthenticationDialogInitialize):Get 19 authenticationChallenge from request object. 20 (webkitAuthenticationDialogNew): Ditto. 21 * UIProcess/API/gtk/WebKitAuthenticationDialog.h: 22 * UIProcess/API/gtk/WebKitAuthenticationRequest.cpp: Added new 23 class representing a HTTP authentication request. 24 (webkitAuthenticationRequestDispose): 25 (webkit_authentication_request_class_init): 26 (webkitAuthenticationRequestCreate): 27 (webkitAuthenticationRequestGetAuthenticationChallenge): 28 (webkit_authentication_request_can_save_credentials): 29 (webkit_authentication_request_get_proposed_credential): 30 (webkit_authentication_request_get_host): 31 (webkit_authentication_request_get_port): 32 (webkit_authentication_request_get_realm): 33 (webkit_authentication_request_get_scheme): 34 (webkit_authentication_request_is_for_proxy): 35 (webkit_authentication_request_is_retry): 36 (webkit_authentication_request_authenticate): 37 (webkit_authentication_request_cancel): 38 * UIProcess/API/gtk/WebKitAuthenticationRequest.h: Added. 39 * UIProcess/API/gtk/WebKitAuthenticationRequestPrivate.h: Added. 40 * UIProcess/API/gtk/WebKitCredential.cpp: Added new class to 41 support credentials for HTTP authentication. 42 (_WebKitCredential::_WebKitCredential): 43 (webkitCredentialCreate): 44 (webkitCredentialGetCredential): 45 (webkit_credential_new): 46 (webkit_credential_copy): 47 (webkit_credential_free): 48 (webkit_credential_get_username): 49 (webkit_credential_get_password): 50 (webkit_credential_has_password): 51 (webkit_credential_get_persistence): 52 * UIProcess/API/gtk/WebKitCredential.h: Added. 53 * UIProcess/API/gtk/WebKitCredentialPrivate.h: Added. 54 * UIProcess/API/gtk/WebKitWebView.cpp: Added authenticate signal. 55 (webkitWebViewAuthenticate): Default signal handler for authenticate. 56 (webkit_web_view_class_init): Ditto. 57 (webkitWebViewHandleAuthenticationChallenge): Create an 58 authentication request and emit it with authenticate signal. 59 * UIProcess/API/gtk/WebKitWebView.h: Replaced reserved function 60 pointer slot with for WebViewClass with function pointer to 61 authenticate signal handler. 62 * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Added new section for 63 the authentication request. 64 * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Ditto. 65 * UIProcess/API/gtk/docs/webkit2gtk.types: Added authentication 66 request and credential types. 67 * UIProcess/API/gtk/tests/TestWebKitWebView.cpp: Created a new 68 unit test for HTTP authentication. A libsoup server callback 69 handler is installed that creates soup messages with appropriate 70 headers and body to test HTTP authentication. 71 (testWebViewAuthenticationRequest): Test the authentication 72 request and credential API. 73 (testWebViewAuthenticationCancel): Test cancelled authentication. 74 (testWebViewAuthenticationFailure): Test repeated authentication failures. 75 (testWebViewAuthenticationNoCredential): Test continue without 76 credentials. 77 (testWebViewAuthenticationStorage): Test credential storage. 78 (testWebViewAuthenticationSuccess): Test successful authentication. 79 (beforeAll): Added tests. 80 * UIProcess/API/gtk/webkit2.h: Added WebKitAuthenticationRequest and 81 WebKitCredential headers. 82 1 83 2013-08-09 Tim Horton <timothy_horton@apple.com> 2 84 -
trunk/Source/WebKit2/GNUmakefile.list.am
r153460 r153882 95 95 96 96 webkit2gtk_h_api += \ 97 $(WebKit2)/UIProcess/API/gtk/WebKitAuthenticationRequest.h \ 97 98 $(WebKit2)/UIProcess/API/gtk/WebKitBackForwardList.h \ 98 99 $(WebKit2)/UIProcess/API/gtk/WebKitBackForwardListItem.h \ … … 101 102 $(WebKit2)/UIProcess/API/gtk/WebKitContextMenuItem.h \ 102 103 $(WebKit2)/UIProcess/API/gtk/WebKitCookieManager.h \ 104 $(WebKit2)/UIProcess/API/gtk/WebKitCredential.h \ 103 105 $(WebKit2)/UIProcess/API/gtk/WebKitDefines.h \ 104 106 $(WebKit2)/UIProcess/API/gtk/WebKitDownload.h \ … … 654 656 Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationDialog.cpp \ 655 657 Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationDialog.h \ 658 Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationRequest.cpp \ 659 Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationRequest.h \ 660 Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationRequestPrivate.h \ 656 661 Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardList.h \ 657 662 Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardList.cpp \ … … 673 678 Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.cpp \ 674 679 Source/WebKit2/UIProcess/API/gtk/WebKitCookieManagerPrivate.h \ 680 Source/WebKit2/UIProcess/API/gtk/WebKitCredential.cpp \ 681 Source/WebKit2/UIProcess/API/gtk/WebKitCredential.h \ 682 Source/WebKit2/UIProcess/API/gtk/WebKitCredentialPrivate.h \ 675 683 Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h \ 676 684 Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp \ -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationDialog.cpp
r148294 r153882 22 22 23 23 #include "AuthenticationDecisionListener.h" 24 #include "WebCredential.h" 24 #include "WebKitAuthenticationRequestPrivate.h" 25 #include "WebKitCredentialPrivate.h" 25 26 #include "WebKitPrivate.h" 26 27 … … 28 29 29 30 struct _WebKitAuthenticationDialogPrivate { 30 RefPtr<AuthenticationChallengeProxy> authenticationChallenge; 31 31 GRefPtr<WebKitAuthenticationRequest> request; 32 32 GtkWidget* authWidget; 33 33 GtkWidget* defaultButton; … … 37 37 WEBKIT_DEFINE_TYPE(WebKitAuthenticationDialog, webkit_authentication_dialog, GTK_TYPE_EVENT_BOX) 38 38 39 static void webkitAuthenticationDialogAuthenticate(WebKitAuthenticationDialog* authDialog, WebCredential* credential)40 {41 WebKitAuthenticationDialogPrivate* priv = authDialog->priv;42 priv->authenticationChallenge->listener()->useCredential(credential);43 gtk_widget_destroy(GTK_WIDGET(authDialog));44 }45 46 39 static void okButtonClicked(GtkButton*, WebKitAuthenticationDialog* authDialog) 47 40 { 48 41 WebKitAuthenticationDialogPrivate* priv = authDialog->priv; 49 RefPtr<WebCredential> webCredential = WebCredential::create(webkitAuthenticationWidgetCreateCredential(WEBKIT_AUTHENTICATION_WIDGET(priv->authWidget))); 50 webkitAuthenticationDialogAuthenticate(authDialog, webCredential.get()); 42 WebKitCredential* credential = webkitCredentialCreate(webkitAuthenticationWidgetCreateCredential(WEBKIT_AUTHENTICATION_WIDGET(priv->authWidget))); 43 webkit_authentication_request_authenticate(priv->request.get(), credential); 44 webkit_credential_free(credential); 45 gtk_widget_destroy(GTK_WIDGET(authDialog)); 51 46 } 52 47 53 48 static void cancelButtonClicked(GtkButton*, WebKitAuthenticationDialog* authDialog) 54 49 { 55 webkitAuthenticationDialogAuthenticate(authDialog, 0); 50 webkit_authentication_request_authenticate(authDialog->priv->request.get(), 0); 51 gtk_widget_destroy(GTK_WIDGET(authDialog)); 56 52 } 57 53 … … 81 77 gtk_widget_show(button); 82 78 83 authDialog->priv->authWidget = webkitAuthenticationWidgetNew( authDialog->priv->authenticationChallenge->core(), credentialStorageMode);79 authDialog->priv->authWidget = webkitAuthenticationWidgetNew(webkitAuthenticationRequestGetAuthenticationChallenge(authDialog->priv->request.get())->core(), credentialStorageMode); 84 80 gtk_box_pack_start(GTK_BOX(vBox), authDialog->priv->authWidget, TRUE, TRUE, 0); 85 81 gtk_widget_show(authDialog->priv->authWidget); … … 139 135 } 140 136 141 GtkWidget* webkitAuthenticationDialogNew( AuthenticationChallengeProxy* authenticationChallenge, CredentialStorageMode mode)137 GtkWidget* webkitAuthenticationDialogNew(WebKitAuthenticationRequest* request, CredentialStorageMode mode) 142 138 { 143 139 WebKitAuthenticationDialog* authDialog = WEBKIT_AUTHENTICATION_DIALOG(g_object_new(WEBKIT_TYPE_AUTHENTICATION_DIALOG, NULL)); 144 authDialog->priv-> authenticationChallenge = authenticationChallenge;140 authDialog->priv->request = request; 145 141 webkitAuthenticationDialogInitialize(authDialog, mode); 146 142 return GTK_WIDGET(authDialog); -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationDialog.h
r148294 r153882 21 21 #define WebKitAuthenticationDialog_h 22 22 23 #include " AuthenticationChallengeProxy.h"23 #include "WebKitAuthenticationRequest.h" 24 24 #include "WebKitAuthenticationWidget.h" 25 25 #include <gtk/gtk.h> … … 49 49 50 50 GType webkit_authentication_dialog_get_type(); 51 GtkWidget* webkitAuthenticationDialogNew(WebKit ::AuthenticationChallengeProxy*, CredentialStorageMode);51 GtkWidget* webkitAuthenticationDialogNew(WebKitAuthenticationRequest*, CredentialStorageMode); 52 52 53 53 G_END_DECLS -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp
r152354 r153882 29 29 #include "WebData.h" 30 30 #include "WebKitAuthenticationDialog.h" 31 #include "WebKitAuthenticationRequestPrivate.h" 31 32 #include "WebKitBackForwardListPrivate.h" 32 33 #include "WebKitContextMenuClient.h" … … 120 121 WEB_PROCESS_CRASHED, 121 122 123 AUTHENTICATE, 124 122 125 LAST_SIGNAL 123 126 }; … … 428 431 g_signal_handler_disconnect(webkit_web_context_get_favicon_database(priv->context), priv->faviconChangedHandlerID); 429 432 priv->faviconChangedHandlerID = 0; 433 } 434 435 static gboolean webkitWebViewAuthenticate(WebKitWebView* webView, WebKitAuthenticationRequest* request) 436 { 437 CredentialStorageMode credentialStorageMode = webkit_authentication_request_can_save_credentials(request) ? AllowPersistentStorage : DisallowPersistentStorage; 438 webkitWebViewBaseAddAuthenticationDialog(WEBKIT_WEB_VIEW_BASE(webView), webkitAuthenticationDialogNew(request, credentialStorageMode)); 439 440 return TRUE; 430 441 } 431 442 … … 606 617 webViewClass->permission_request = webkitWebViewPermissionRequest; 607 618 webViewClass->run_file_chooser = webkitWebViewRunFileChooser; 619 webViewClass->authenticate = webkitWebViewAuthenticate; 608 620 609 621 /** … … 1367 1379 webkit_marshal_BOOLEAN__VOID, 1368 1380 G_TYPE_BOOLEAN, 0); 1381 1382 /** 1383 * WebKitWebView::authenticate: 1384 * @web_view: the #WebKitWebView on which the signal is emitted 1385 * @request: a #WebKitAuthenticationRequest 1386 * 1387 * This signal is emitted when the user is challenged with HTTP 1388 * authentication. To let the application access or supply 1389 * the credentials as well as to allow the client application 1390 * to either cancel the request or perform the authentication, 1391 * the signal will pass an instance of the 1392 * #WebKitAuthenticationRequest in the @request argument. 1393 * To handle this signal asynchronously you should keep a ref 1394 * of the request and return %TRUE. To disable HTTP authentication 1395 * entirely, connect to this signal and simply return %TRUE. 1396 * 1397 * The default signal handler will run a default authentication 1398 * dialog asynchronously for the user to interact with. 1399 * 1400 * Returns: %TRUE to stop other handlers from being invoked for the event. 1401 * %FALSE to propagate the event further. 1402 * 1403 * Since: 2.2 1404 */ 1405 signals[AUTHENTICATE] = 1406 g_signal_new("authenticate", 1407 G_TYPE_FROM_CLASS(webViewClass), 1408 G_SIGNAL_RUN_LAST, 1409 G_STRUCT_OFFSET(WebKitWebViewClass, authenticate), 1410 g_signal_accumulator_true_handled, 0 /* accumulator data */, 1411 webkit_marshal_BOOLEAN__OBJECT, 1412 G_TYPE_BOOLEAN, 1, /* number of parameters */ 1413 WEBKIT_TYPE_AUTHENTICATION_REQUEST); 1369 1414 } 1370 1415 … … 1739 1784 void webkitWebViewHandleAuthenticationChallenge(WebKitWebView* webView, AuthenticationChallengeProxy* authenticationChallenge) 1740 1785 { 1741 CredentialStorageMode credentialStorageMode; 1742 if (webkit_settings_get_enable_private_browsing(webkit_web_view_get_settings(webView))) 1743 credentialStorageMode = DisallowPersistentStorage; 1744 else 1745 credentialStorageMode = AllowPersistentStorage; 1746 1747 webkitWebViewBaseAddAuthenticationDialog(WEBKIT_WEB_VIEW_BASE(webView), webkitAuthenticationDialogNew(authenticationChallenge, credentialStorageMode)); 1786 gboolean privateBrowsingEnabled = webkit_settings_get_enable_private_browsing(webkit_web_view_get_settings(webView)); 1787 GRefPtr<WebKitAuthenticationRequest> request = adoptGRef(webkitAuthenticationRequestCreate(authenticationChallenge, privateBrowsingEnabled)); 1788 gboolean returnValue; 1789 g_signal_emit(webView, signals[AUTHENTICATE], 0, request.get(), &returnValue); 1748 1790 } 1749 1791 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h
r150130 r153882 30 30 31 31 #include <JavaScriptCore/JSBase.h> 32 #include <webkit2/WebKitAuthenticationRequest.h> 32 33 #include <webkit2/WebKitBackForwardList.h> 33 34 #include <webkit2/WebKitDefines.h> … … 243 244 gboolean (* web_process_crashed) (WebKitWebView *web_view); 244 245 246 gboolean (* authenticate) (WebKitWebView *web_view, 247 WebKitAuthenticationRequest *request); 245 248 void (*_webkit_reserved0) (void); 246 249 void (*_webkit_reserved1) (void); … … 250 253 void (*_webkit_reserved5) (void); 251 254 void (*_webkit_reserved6) (void); 252 void (*_webkit_reserved7) (void);253 255 }; 254 256 -
trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml
r149117 r153882 14 14 <xi:include href="xml/WebKitWebContext.xml"/> 15 15 <xi:include href="xml/WebKitWebView.xml"/> 16 <xi:include href="xml/WebKitAuthenticationRequest.xml"/> 16 17 <xi:include href="xml/WebKitBackForwardList.xml"/> 17 18 <xi:include href="xml/WebKitBackForwardListItem.xml"/> … … 54 55 <title>Index</title> 55 56 </index> 57 58 <index id="api-index-2-2" role="2.2"> 59 <title>Index of new symbols in 2.2</title> 60 <xi:include href="xml/api-index-2.2.xml"><xi:fallback /></xi:include> 61 </index> 62 56 63 <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include> 57 64 </book> -
trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt
r150158 r153882 176 176 webkit_script_dialog_get_type 177 177 WebKitWebViewPrivate 178 </SECTION> 179 180 <SECTION> 181 <FILE>WebKitAuthenticationRequest</FILE> 182 WebKitAuthenticationRequest 183 WebKitAuthenticationScheme 184 webkit_authentication_request_authenticate 185 webkit_authentication_request_cancel 186 webkit_authentication_request_can_save_credentials 187 webkit_authentication_request_get_host 188 webkit_authentication_request_get_port 189 webkit_authentication_request_is_retry 190 webkit_authentication_request_get_proposed_credential 191 webkit_authentication_request_get_realm 192 webkit_authentication_request_get_scheme 193 webkit_authentication_request_is_for_proxy 194 195 <SUBSECTION Standard> 196 WebKitAuthenticationRequestClass 197 WEBKIT_TYPE_AUTHENTICATION_REQUEST 198 WEBKIT_AUTHENTICATION_REQUEST 199 WEBKIT_AUTHENTICATION_REQUEST_CLASS 200 WEBKIT_AUTHENTICATION_REQUEST_GET_CLASS 201 WEBKIT_IS_AUTHENTICATION_REQUEST 202 WEBKIT_IS_AUTHENTICATION_REQUEST_CLASS 203 WEBKIT_TYPE_CREDENTIAL 204 205 <SUBSECTION Private> 206 WebKitAuthenticationRequestPrivate 207 webkit_authentication_request_get_type 208 webkit_credential_get_type 209 210 <SUBSECTION> 211 WebKitCredential 212 WebKitCredentialPersistence 213 webkit_credential_new 214 webkit_credential_copy 215 webkit_credential_free 216 webkit_credential_get_password 217 webkit_credential_get_persistence 218 webkit_credential_get_username 219 webkit_credential_has_password 178 220 </SECTION> 179 221 -
trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types
r149117 r153882 25 25 webkit_web_extension_get_type 26 26 webkit_web_page_get_type 27 webkit_authentication_request_get_type 28 webkit_credential_get_type -
trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp
r151833 r153882 19 19 20 20 #include "config.h" 21 #include "LoadTrackingTest.h" 22 #include "WebKitTestServer.h" 21 23 #include "WebViewTest.h" 22 24 #include <JavaScriptCore/JSStringRef.h> … … 26 28 #include <wtf/gobject/GRefPtr.h> 27 29 #include <wtf/text/StringHash.h> 30 31 static WebKitTestServer* kServer; 28 32 29 33 static void testWebViewDefaultContext(WebViewTest* test, gconstpointer) … … 1230 1234 } 1231 1235 1236 class AuthenticationTest: public LoadTrackingTest { 1237 public: 1238 MAKE_GLIB_TEST_FIXTURE(AuthenticationTest); 1239 1240 AuthenticationTest() 1241 { 1242 g_signal_connect(m_webView, "authenticate", G_CALLBACK(runAuthenticationCallback), this); 1243 } 1244 1245 ~AuthenticationTest() 1246 { 1247 g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); 1248 } 1249 1250 static int authenticationRetries; 1251 1252 void loadURI(const char* uri) 1253 { 1254 // Reset the retry count of the fake server when a page is loaded. 1255 authenticationRetries = 0; 1256 LoadTrackingTest::loadURI(uri); 1257 } 1258 1259 static gboolean runAuthenticationCallback(WebKitWebView*, WebKitAuthenticationRequest* request, AuthenticationTest* test) 1260 { 1261 test->runAuthentication(request); 1262 return TRUE; 1263 } 1264 1265 void runAuthentication(WebKitAuthenticationRequest* request) 1266 { 1267 assertObjectIsDeletedWhenTestFinishes(G_OBJECT(request)); 1268 m_authenticationRequest = request; 1269 g_main_loop_quit(m_mainLoop); 1270 } 1271 1272 WebKitAuthenticationRequest* waitForAuthenticationRequest() 1273 { 1274 g_main_loop_run(m_mainLoop); 1275 return m_authenticationRequest.get(); 1276 } 1277 1278 private: 1279 GRefPtr<WebKitAuthenticationRequest> m_authenticationRequest; 1280 }; 1281 1282 int AuthenticationTest::authenticationRetries = 0; 1283 1284 static const char authTestUsername[] = "username"; 1285 static const char authTestPassword[] = "password"; 1286 static const char authExpectedSuccessTitle[] = "WebKit2Gtk+ Authentication test"; 1287 static const char authExpectedFailureTitle[] = "401 Authorization Required"; 1288 static const char authExpectedAuthorization[] = "Basic dXNlcm5hbWU6cGFzc3dvcmQ="; // Base64 encoding of "username:password". 1289 static const char authSuccessHTMLString[] = 1290 "<html>" 1291 "<head><title>WebKit2Gtk+ Authentication test</title></head>" 1292 "<body></body></html>"; 1293 static const char authFailureHTMLString[] = 1294 "<html>" 1295 "<head><title>401 Authorization Required</title></head>" 1296 "<body></body></html>"; 1297 1298 static void testWebViewAuthenticationRequest(AuthenticationTest* test, gconstpointer) 1299 { 1300 // Test authentication request getters match soup authentication header. 1301 test->loadURI(kServer->getURIForPath("/auth-test.html").data()); 1302 WebKitAuthenticationRequest* request = test->waitForAuthenticationRequest(); 1303 g_assert_cmpstr(webkit_authentication_request_get_host(request), ==, soup_uri_get_host(kServer->baseURI())); 1304 g_assert_cmpuint(webkit_authentication_request_get_port(request), ==, soup_uri_get_port(kServer->baseURI())); 1305 g_assert_cmpstr(webkit_authentication_request_get_realm(request), ==, "my realm"); 1306 g_assert(webkit_authentication_request_get_scheme(request) == WEBKIT_AUTHENTICATION_SCHEME_HTTP_BASIC); 1307 g_assert(!webkit_authentication_request_is_for_proxy(request)); 1308 g_assert(!webkit_authentication_request_is_retry(request)); 1309 } 1310 1311 static void testWebViewAuthenticationCancel(AuthenticationTest* test, gconstpointer) 1312 { 1313 // Test cancel. 1314 test->loadURI(kServer->getURIForPath("/auth-test.html").data()); 1315 WebKitAuthenticationRequest* request = test->waitForAuthenticationRequest(); 1316 webkit_authentication_request_cancel(request); 1317 // Server doesn't ask for new credentials. 1318 test->waitUntilLoadFinished(); 1319 1320 g_assert_cmpint(test->m_loadEvents.size(), ==, 3); 1321 g_assert_cmpint(test->m_loadEvents[0], ==, LoadTrackingTest::ProvisionalLoadStarted); 1322 g_assert_cmpint(test->m_loadEvents[1], ==, LoadTrackingTest::ProvisionalLoadFailed); 1323 g_assert_cmpint(test->m_loadEvents[2], ==, LoadTrackingTest::LoadFinished); 1324 1325 g_assert_error(test->m_error.get(), WEBKIT_NETWORK_ERROR, WEBKIT_NETWORK_ERROR_CANCELLED); 1326 } 1327 1328 static void testWebViewAuthenticationFailure(AuthenticationTest* test, gconstpointer) 1329 { 1330 // Test authentication failures. 1331 test->loadURI(kServer->getURIForPath("/auth-test.html").data()); 1332 WebKitAuthenticationRequest* request = test->waitForAuthenticationRequest(); 1333 g_assert(!webkit_authentication_request_is_retry(request)); 1334 WebKitCredential* credential = webkit_credential_new(authTestUsername, "wrongpassword", WEBKIT_CREDENTIAL_PERSISTENCE_NONE); 1335 webkit_authentication_request_authenticate(request, credential); 1336 webkit_credential_free(credential); 1337 // Expect a second authentication request. 1338 request = test->waitForAuthenticationRequest(); 1339 g_assert(webkit_authentication_request_is_retry(request)); 1340 // Test second failure. 1341 credential = webkit_credential_new(authTestUsername, "wrongpassword2", WEBKIT_CREDENTIAL_PERSISTENCE_NONE); 1342 webkit_authentication_request_authenticate(request, credential); 1343 webkit_credential_free(credential); 1344 // Expect authentication failed page. 1345 test->waitUntilLoadFinished(); 1346 1347 g_assert_cmpint(test->m_loadEvents.size(), ==, 3); 1348 g_assert_cmpint(test->m_loadEvents[0], ==, LoadTrackingTest::ProvisionalLoadStarted); 1349 g_assert_cmpint(test->m_loadEvents[1], ==, LoadTrackingTest::LoadCommitted); 1350 g_assert_cmpint(test->m_loadEvents[2], ==, LoadTrackingTest::LoadFinished); 1351 g_assert_cmpstr(webkit_web_view_get_title(test->m_webView), ==, authExpectedFailureTitle); 1352 } 1353 1354 static void testWebViewAuthenticationNoCredential(AuthenticationTest* test, gconstpointer) 1355 { 1356 // Test continue without credentials. 1357 test->loadURI(kServer->getURIForPath("/auth-test.html").data()); 1358 WebKitAuthenticationRequest* request = test->waitForAuthenticationRequest(); 1359 webkit_authentication_request_authenticate(request, 0); 1360 // Server doesn't ask for new credentials. 1361 test->waitUntilLoadFinished(); 1362 1363 g_assert_cmpint(test->m_loadEvents.size(), ==, 3); 1364 g_assert_cmpint(test->m_loadEvents[0], ==, LoadTrackingTest::ProvisionalLoadStarted); 1365 g_assert_cmpint(test->m_loadEvents[1], ==, LoadTrackingTest::LoadCommitted); 1366 g_assert_cmpint(test->m_loadEvents[2], ==, LoadTrackingTest::LoadFinished); 1367 g_assert_cmpstr(webkit_web_view_get_title(test->m_webView), ==, authExpectedFailureTitle); 1368 } 1369 1370 static void testWebViewAuthenticationStorage(AuthenticationTest* test, gconstpointer) 1371 { 1372 // Enable private browsing before authentication request to test that credentials can't be saved. 1373 webkit_settings_set_enable_private_browsing(webkit_web_view_get_settings(test->m_webView), TRUE); 1374 test->loadURI(kServer->getURIForPath("/auth-test.html").data()); 1375 WebKitAuthenticationRequest* request = test->waitForAuthenticationRequest(); 1376 g_assert(!webkit_authentication_request_get_proposed_credential(request)); 1377 g_assert(!webkit_authentication_request_can_save_credentials(request)); 1378 1379 // If WebKit has been compiled with libsecret, and private browsing is disabled 1380 // then check that credentials can be saved. 1381 #if ENABLE(CREDENTIAL_STORAGE) 1382 webkit_settings_set_enable_private_browsing(webkit_web_view_get_settings(test->m_webView), FALSE); 1383 test->loadURI(kServer->getURIForPath("/auth-test.html").data()); 1384 request = test->waitForAuthenticationRequest(); 1385 g_assert(!webkit_authentication_request_get_proposed_credential(request)); 1386 g_assert(webkit_authentication_request_can_save_credentials(request)); 1387 #endif 1388 } 1389 1390 static void testWebViewAuthenticationSuccess(AuthenticationTest* test, gconstpointer) 1391 { 1392 // Test correct authentication. 1393 test->loadURI(kServer->getURIForPath("/auth-test.html").data()); 1394 WebKitAuthenticationRequest* request = test->waitForAuthenticationRequest(); 1395 WebKitCredential* credential = webkit_credential_new(authTestUsername, authTestPassword, WEBKIT_CREDENTIAL_PERSISTENCE_FOR_SESSION); 1396 webkit_authentication_request_authenticate(request, credential); 1397 webkit_credential_free(credential); 1398 test->waitUntilLoadFinished(); 1399 1400 g_assert_cmpint(test->m_loadEvents.size(), ==, 3); 1401 g_assert_cmpint(test->m_loadEvents[0], ==, LoadTrackingTest::ProvisionalLoadStarted); 1402 g_assert_cmpint(test->m_loadEvents[1], ==, LoadTrackingTest::LoadCommitted); 1403 g_assert_cmpint(test->m_loadEvents[2], ==, LoadTrackingTest::LoadFinished); 1404 g_assert_cmpstr(webkit_web_view_get_title(test->m_webView), ==, authExpectedSuccessTitle); 1405 1406 // Test loading the same (authorized) page again. 1407 test->loadURI(kServer->getURIForPath("/auth-test.html").data()); 1408 // There is no authentication challenge. 1409 test->waitUntilLoadFinished(); 1410 1411 g_assert_cmpint(test->m_loadEvents.size(), ==, 3); 1412 g_assert_cmpint(test->m_loadEvents[0], ==, LoadTrackingTest::ProvisionalLoadStarted); 1413 g_assert_cmpint(test->m_loadEvents[1], ==, LoadTrackingTest::LoadCommitted); 1414 g_assert_cmpint(test->m_loadEvents[2], ==, LoadTrackingTest::LoadFinished); 1415 g_assert_cmpstr(webkit_web_view_get_title(test->m_webView), ==, authExpectedSuccessTitle); 1416 } 1417 1418 static void serverCallback(SoupServer*, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, void*) 1419 { 1420 if (message->method != SOUP_METHOD_GET) { 1421 soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED); 1422 return; 1423 } 1424 1425 if (!strcmp(path, "/auth-test.html")) { 1426 const char* authorization = soup_message_headers_get_one(message->request_headers, "Authorization"); 1427 // Require authentication. 1428 if (!g_strcmp0(authorization, authExpectedAuthorization)) { 1429 // Successful authentication. 1430 soup_message_set_status(message, SOUP_STATUS_OK); 1431 soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, authSuccessHTMLString, strlen(authSuccessHTMLString)); 1432 AuthenticationTest::authenticationRetries = 0; 1433 } else if (++AuthenticationTest::authenticationRetries < 3) { 1434 // No or invalid authorization header provided by the client, request authentication twice then fail. 1435 soup_message_set_status(message, SOUP_STATUS_UNAUTHORIZED); 1436 soup_message_headers_append(message->response_headers, "WWW-Authenticate", "Basic realm=\"my realm\""); 1437 // Include a failure message in case the user attempts to proceed without authentication. 1438 soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, authFailureHTMLString, strlen(authFailureHTMLString)); 1439 } else { 1440 // Authentication not successful, display a "401 Authorization Required" page. 1441 soup_message_set_status(message, SOUP_STATUS_OK); 1442 soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, authFailureHTMLString, strlen(authFailureHTMLString)); 1443 } 1444 } else 1445 soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); 1446 1447 soup_message_body_complete(message->response_body); 1448 } 1449 1232 1450 void beforeAll() 1233 1451 { 1452 kServer = new WebKitTestServer(); 1453 kServer->run(serverCallback); 1454 1234 1455 WebViewTest::add("WebKitWebView", "default-context", testWebViewDefaultContext); 1235 1456 WebViewTest::add("WebKitWebView", "custom-charset", testWebViewCustomCharset); … … 1252 1473 SnapshotWebViewTest::add("WebKitWebView", "snapshot", testWebViewSnapshot); 1253 1474 WebViewTest::add("WebKitWebView", "page-visibility", testWebViewPageVisibility); 1475 AuthenticationTest::add("WebKitWebView", "authentication-request", testWebViewAuthenticationRequest); 1476 AuthenticationTest::add("WebKitWebView", "authentication-cancel", testWebViewAuthenticationCancel); 1477 AuthenticationTest::add("WebKitWebView", "authentication-failure", testWebViewAuthenticationFailure); 1478 AuthenticationTest::add("WebKitWebView", "authentication-no-credential", testWebViewAuthenticationNoCredential); 1479 AuthenticationTest::add("WebKitWebView", "authentication-storage", testWebViewAuthenticationStorage); 1480 // Testing authentication success must be done last because libsoup will never fire 1481 // the authenticate signal again once authentication is successful. 1482 AuthenticationTest::add("WebKitWebView", "authentication-success", testWebViewAuthenticationSuccess); 1254 1483 } 1255 1484 1256 1485 void afterAll() 1257 1486 { 1258 } 1487 delete kServer; 1488 } -
trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h
r149117 r153882 24 24 #define __WEBKIT2_H_INSIDE__ 25 25 26 #include <webkit2/WebKitAuthenticationRequest.h> 26 27 #include <webkit2/WebKitBackForwardList.h> 27 28 #include <webkit2/WebKitBackForwardListItem.h> … … 30 31 #include <webkit2/WebKitContextMenuItem.h> 31 32 #include <webkit2/WebKitCookieManager.h> 33 #include <webkit2/WebKitCredential.h> 32 34 #include <webkit2/WebKitDefines.h> 33 35 #include <webkit2/WebKitDownload.h>
Note: See TracChangeset
for help on using the changeset viewer.