⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 155347 in webkit


Ignore:
Timestamp:
Sep 9, 2013, 6:49:33 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

[GTK] Cancel the current active WebKitAuthenticationRequest on load failed
https://bugs.webkit.org/show_bug.cgi?id=120350

Patch by Anton Obzhirov <Anton Obzhirov> on 2013-09-09
Reviewed by Carlos Garcia Campos.

The default dialog does not get closed and the authentication is not cancelled
if loading fails or is stopped on a page which requires HTTP authentication.

This patch cancels the authentication request on load failed
and adds new authentication cancelled signal in WebKitAuthenticationRequest
to allow the application handling of authentication UI.

  • UIProcess/API/gtk/WebKitAuthenticationDialog.cpp:

(authenticationCancelled):
(webkitAuthenticationDialogInitialize):
(webkitAuthenticationDialogDispose):
(webkitAuthenticationDialogNew):

  • UIProcess/API/gtk/WebKitAuthenticationDialog.h:
  • UIProcess/API/gtk/WebKitAuthenticationRequest.cpp:

(webkit_authentication_request_class_init):
(webkit_authentication_request_cancel):

  • UIProcess/API/gtk/WebKitWebView.cpp:

(webkitWebViewAuthenticate):
(webkitWebViewLoadFailed):
(webkitWebViewHandleAuthenticationChallenge):
(webkitWebViewCancelAuthenticationRequest):

  • UIProcess/API/gtk/tests/TestWebKitWebView.cpp:

(testWebViewAuthenticationLoadCancelled):
(beforeAll):

Location:
trunk/Source/WebKit2
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r155345 r155347  
     12013-09-09  Anton Obzhirov  <a.obzhirov@samsung.com>
     2
     3        [GTK] Cancel the current active WebKitAuthenticationRequest on load failed
     4        https://bugs.webkit.org/show_bug.cgi?id=120350
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        The default dialog does not get closed and the authentication is not cancelled
     9        if loading fails or is stopped on a page which requires HTTP authentication.
     10
     11        This patch cancels the authentication request on load failed
     12        and adds new authentication cancelled signal in WebKitAuthenticationRequest
     13        to allow the application handling of authentication UI.
     14
     15        * UIProcess/API/gtk/WebKitAuthenticationDialog.cpp:
     16        (authenticationCancelled):
     17        (webkitAuthenticationDialogInitialize):
     18        (webkitAuthenticationDialogDispose):
     19        (webkitAuthenticationDialogNew):
     20        * UIProcess/API/gtk/WebKitAuthenticationDialog.h:
     21        * UIProcess/API/gtk/WebKitAuthenticationRequest.cpp:
     22        (webkit_authentication_request_class_init):
     23        (webkit_authentication_request_cancel):
     24        * UIProcess/API/gtk/WebKitWebView.cpp:
     25        (webkitWebViewAuthenticate):
     26        (webkitWebViewLoadFailed):
     27        (webkitWebViewHandleAuthenticationChallenge):
     28        (webkitWebViewCancelAuthenticationRequest):
     29        * UIProcess/API/gtk/tests/TestWebKitWebView.cpp:
     30        (testWebViewAuthenticationLoadCancelled):
     31        (beforeAll):
     32
    1332013-09-09  Brian Holt  <brian.holt@samsung.com>
    234
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationDialog.cpp

    r154329 r155347  
    3333    GtkWidget* authWidget;
    3434    GtkWidget* defaultButton;
    35     unsigned long loadFailedEventID;
     35    unsigned long authenticationCancelledID;
    3636    GRefPtr<GtkStyleContext> styleContext;
    37     WebKitWebView* webView;
    3837};
    3938
     
    5554}
    5655
    57 static void pageLoadFailed(WebKitWebView*, WebKitLoadEvent, const char*, GError*, WebKitAuthenticationDialog* authDialog)
     56static void authenticationCancelled(WebKitAuthenticationRequest*, WebKitAuthenticationDialog* authDialog)
    5857{
    59     webkit_authentication_request_cancel(authDialog->priv->request.get());
    6058    gtk_widget_destroy(GTK_WIDGET(authDialog));
    6159}
    6260
    63 static void webkitAuthenticationDialogInitialize(WebKitAuthenticationDialog* authDialog, CredentialStorageMode credentialStorageMode, WebKitWebView* webView)
     61static void webkitAuthenticationDialogInitialize(WebKitAuthenticationDialog* authDialog, CredentialStorageMode credentialStorageMode)
    6462{
    6563    GtkWidget* frame = gtk_frame_new(0);
     
    9997    gtk_widget_show(frame);
    10098
    101     authDialog->priv->webView = webView;
    102     authDialog->priv->loadFailedEventID = g_signal_connect(webView, "load-failed", G_CALLBACK(pageLoadFailed), authDialog);
     99    authDialog->priv->authenticationCancelledID = g_signal_connect(authDialog->priv->request.get(), "cancelled", G_CALLBACK(authenticationCancelled), authDialog);
    103100}
    104101
     
    140137{
    141138    WebKitAuthenticationDialogPrivate* priv = WEBKIT_AUTHENTICATION_DIALOG(object)->priv;
    142     if (priv->loadFailedEventID) {
    143         g_signal_handler_disconnect(priv->webView, priv->loadFailedEventID);
    144         priv->loadFailedEventID = 0;
     139    if (priv->authenticationCancelledID) {
     140        g_signal_handler_disconnect(priv->request.get(), priv->authenticationCancelledID);
     141        priv->authenticationCancelledID = 0;
    145142    }
    146143
     
    159156}
    160157
    161 GtkWidget* webkitAuthenticationDialogNew(WebKitAuthenticationRequest* request, CredentialStorageMode mode, WebKitWebView* webView)
     158GtkWidget* webkitAuthenticationDialogNew(WebKitAuthenticationRequest* request, CredentialStorageMode mode)
    162159{
    163160    WebKitAuthenticationDialog* authDialog = WEBKIT_AUTHENTICATION_DIALOG(g_object_new(WEBKIT_TYPE_AUTHENTICATION_DIALOG, NULL));
    164161    authDialog->priv->request = request;
    165     webkitAuthenticationDialogInitialize(authDialog, mode, webView);
     162    webkitAuthenticationDialogInitialize(authDialog, mode);
    166163    return GTK_WIDGET(authDialog);
    167164}
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationDialog.h

    r154329 r155347  
    5050
    5151GType webkit_authentication_dialog_get_type();
    52 GtkWidget* webkitAuthenticationDialogNew(WebKitAuthenticationRequest*, CredentialStorageMode, WebKitWebView*);
     52GtkWidget* webkitAuthenticationDialogNew(WebKitAuthenticationRequest*, CredentialStorageMode);
    5353
    5454G_END_DECLS
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitAuthenticationRequest.cpp

    r153882 r155347  
    5252 */
    5353
     54enum {
     55    CANCELLED,
     56
     57    LAST_SIGNAL
     58};
     59
    5460struct _WebKitAuthenticationRequestPrivate {
    5561    RefPtr<AuthenticationChallengeProxy> authenticationChallenge;
     
    5965    CString realm;
    6066};
     67
     68static guint signals[LAST_SIGNAL] = { 0, };
    6169
    6270COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_AUTHENTICATION_SCHEME_DEFAULT, ProtectionSpaceAuthenticationSchemeDefault);
     
    8795    GObjectClass* objectClass = G_OBJECT_CLASS(requestClass);
    8896    objectClass->dispose = webkitAuthenticationRequestDispose;
     97
     98    /**
     99     * WebKitAuthenticationRequest::cancelled:
     100     * @request: the #WebKitAuthenticationRequest
     101     *
     102     * This signal is emitted when the user authentication request is
     103     * cancelled. It allows the application to dismiss its authentication
     104     * dialog in case of page load failure for example.
     105     *
     106     * Since: 2.2
     107     */
     108    signals[CANCELLED] =
     109        g_signal_new("cancelled",
     110            G_TYPE_FROM_CLASS(objectClass),
     111            G_SIGNAL_RUN_LAST,
     112            0, 0, 0,
     113            g_cclosure_marshal_VOID__VOID,
     114            G_TYPE_NONE, 0);
    89115}
    90116
     
    289315
    290316    request->priv->authenticationChallenge->listener()->cancel();
    291 }
     317
     318    g_signal_emit(request, signals[CANCELLED], 0);
     319}
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

    r155066 r155347  
    191191
    192192    SnapshotResultsMap snapshotResultsMap;
     193    GRefPtr<WebKitAuthenticationRequest> authenticationRequest;
    193194};
    194195
     
    438439{
    439440    CredentialStorageMode credentialStorageMode = webkit_authentication_request_can_save_credentials(request) ? AllowPersistentStorage : DisallowPersistentStorage;
    440     webkitWebViewBaseAddAuthenticationDialog(WEBKIT_WEB_VIEW_BASE(webView), webkitAuthenticationDialogNew(request, credentialStorageMode, webView));
     441    webkitWebViewBaseAddAuthenticationDialog(WEBKIT_WEB_VIEW_BASE(webView), webkitAuthenticationDialogNew(request, credentialStorageMode));
    441442
    442443    return TRUE;
     
    14311432}
    14321433
     1434static void webkitWebViewCancelAuthenticationRequest(WebKitWebView* webView)
     1435{
     1436    if (!webView->priv->authenticationRequest)
     1437        return;
     1438
     1439    webkit_authentication_request_cancel(webView->priv->authenticationRequest.get());
     1440    webView->priv->authenticationRequest.clear();
     1441}
     1442
    14331443static void webkitWebViewEmitLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent)
    14341444{
     
    14361446        webkitWebViewSetIsLoading(webView, true);
    14371447        webkitWebViewWatchForChangesInFavicon(webView);
    1438         webkitWebViewBaseCancelAuthenticationDialog(WEBKIT_WEB_VIEW_BASE(webView));
     1448        webkitWebViewCancelAuthenticationRequest(webView);
    14391449    } else if (loadEvent == WEBKIT_LOAD_FINISHED) {
    14401450        webkitWebViewSetIsLoading(webView, false);
    1441         webView->priv->waitingForMainResource = false;
     1451        webkitWebViewCancelAuthenticationRequest(webView);
    14421452        webkitWebViewDisconnectMainResourceResponseChangedSignalHandler(webView);
    14431453    } else
     
    14931503{
    14941504    webkitWebViewSetIsLoading(webView, false);
     1505    webkitWebViewCancelAuthenticationRequest(webView);
     1506
    14951507    gboolean returnValue;
    14961508    g_signal_emit(webView, signals[LOAD_FAILED], 0, loadEvent, failingURI, error, &returnValue);
     
    15011513{
    15021514    webkitWebViewSetIsLoading(webView, false);
     1515    webkitWebViewCancelAuthenticationRequest(webView);
    15031516
    15041517    WebKitTLSErrorsPolicy tlsErrorsPolicy = webkit_web_context_get_tls_errors_policy(webView->priv->context);
     
    17871800{
    17881801    gboolean privateBrowsingEnabled = webkit_settings_get_enable_private_browsing(webkit_web_view_get_settings(webView));
    1789     GRefPtr<WebKitAuthenticationRequest> request = adoptGRef(webkitAuthenticationRequestCreate(authenticationChallenge, privateBrowsingEnabled));
     1802    webView->priv->authenticationRequest = adoptGRef(webkitAuthenticationRequestCreate(authenticationChallenge, privateBrowsingEnabled));
    17901803    gboolean returnValue;
    1791     g_signal_emit(webView, signals[AUTHENTICATE], 0, request.get(), &returnValue);
     1804    g_signal_emit(webView, signals[AUTHENTICATE], 0, webView->priv->authenticationRequest.get(), &returnValue);
    17921805}
    17931806
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp

    r155125 r155347  
    299299}
    300300
    301 void webkitWebViewBaseCancelAuthenticationDialog(WebKitWebViewBase* webViewBase)
    302 {
    303     WebKitWebViewBasePrivate* priv = webViewBase->priv;
    304     if (priv->authenticationDialog)
    305         gtk_widget_destroy(priv->authenticationDialog);
    306 }
    307 
    308301void webkitWebViewBaseAddWebInspector(WebKitWebViewBase* webViewBase, GtkWidget* inspector)
    309302{
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp

    r154818 r155347  
    12491249
    12501250    static int authenticationRetries;
     1251    static bool authenticationCancelledReceived;
    12511252
    12521253    void loadURI(const char* uri)
     
    12541255        // Reset the retry count of the fake server when a page is loaded.
    12551256        authenticationRetries = 0;
     1257        authenticationCancelledReceived = false;
    12561258        LoadTrackingTest::loadURI(uri);
    12571259    }
     
    12591261    static gboolean runAuthenticationCallback(WebKitWebView*, WebKitAuthenticationRequest* request, AuthenticationTest* test)
    12601262    {
     1263        g_signal_connect(request, "cancelled", G_CALLBACK(authenticationCancelledCallback), test);
    12611264        test->runAuthentication(request);
    12621265        return TRUE;
     1266    }
     1267
     1268    static void authenticationCancelledCallback(WebKitAuthenticationRequest*, AuthenticationTest*)
     1269    {
     1270        authenticationCancelledReceived = true;
    12631271    }
    12641272
     
    12811289
    12821290int AuthenticationTest::authenticationRetries = 0;
     1291bool AuthenticationTest::authenticationCancelledReceived = false;
    12831292
    12841293static const char authTestUsername[] = "username";
     
    13171326    // Server doesn't ask for new credentials.
    13181327    test->waitUntilLoadFinished();
     1328
     1329    g_assert_cmpint(test->m_loadEvents.size(), ==, 3);
     1330    g_assert_cmpint(test->m_loadEvents[0], ==, LoadTrackingTest::ProvisionalLoadStarted);
     1331    g_assert_cmpint(test->m_loadEvents[1], ==, LoadTrackingTest::ProvisionalLoadFailed);
     1332    g_assert_cmpint(test->m_loadEvents[2], ==, LoadTrackingTest::LoadFinished);
     1333
     1334    g_assert_error(test->m_error.get(), WEBKIT_NETWORK_ERROR, WEBKIT_NETWORK_ERROR_CANCELLED);
     1335}
     1336
     1337static void testWebViewAuthenticationLoadCancelled(AuthenticationTest* test, gconstpointer)
     1338{
     1339    test->loadURI(kServer->getURIForPath("/auth-test.html").data());
     1340    test->waitForAuthenticationRequest();
     1341    webkit_web_view_stop_loading(test->m_webView);
     1342    // Expect empty page.
     1343    test->waitUntilLoadFinished();
     1344    g_assert(test->authenticationCancelledReceived);
    13191345
    13201346    g_assert_cmpint(test->m_loadEvents.size(), ==, 3);
     
    14751501    AuthenticationTest::add("WebKitWebView", "authentication-request", testWebViewAuthenticationRequest);
    14761502    AuthenticationTest::add("WebKitWebView", "authentication-cancel", testWebViewAuthenticationCancel);
     1503    AuthenticationTest::add("WebKitWebView", "authentication-load-cancelled", testWebViewAuthenticationLoadCancelled);
    14771504    AuthenticationTest::add("WebKitWebView", "authentication-failure", testWebViewAuthenticationFailure);
    14781505    AuthenticationTest::add("WebKitWebView", "authentication-no-credential", testWebViewAuthenticationNoCredential);
Note: See TracChangeset for help on using the changeset viewer.