Ticket #13894: 0001-WebPositive-Improve-CookieWindow-cookie-deletion.patch

File 0001-WebPositive-Improve-CookieWindow-cookie-deletion.patch, 2.6 KB (added by ohnx56, 7 years ago)
  • src/apps/webpositive/CookieWindow.cpp

    From 215357c1bcb7f2be1475d2b09ffe3e28c40df873 Mon Sep 17 00:00:00 2001
    From: ohnx <me@masonx.ca>
    Date: Thu, 21 Dec 2017 04:36:08 +0000
    Subject: [PATCH] WebPositive: Improve CookieWindow cookie deletion
    
    Fixes Coverity issue CID 1340122.
    Also resolves two TODO items in the code: allowing the deletion
    of a selection of cookies, and deleting all cookies from a site
    when there are no specific cookies selected.
    ---
     src/apps/webpositive/CookieWindow.cpp | 47 +++++++++++++++++++++++++----------
     1 file changed, 34 insertions(+), 13 deletions(-)
    
    diff --git a/src/apps/webpositive/CookieWindow.cpp b/src/apps/webpositive/CookieWindow.cpp
    index a8b7ec228f..abb21c3518 100644
    a b CookieWindow::CookieWindow(BRect frame, BNetworkCookieJar& jar)  
    144144        .Add(fCookies)
    145145        .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING)
    146146            .SetInsets(5, 5, 5, 5)
    147 #if 0
     147#if DEBUG
    148148            .Add(new BButton("import", B_TRANSLATE("Import" B_UTF8_ELLIPSIS),
    149149                NULL))
    150150            .Add(new BButton("export", B_TRANSLATE("Export" B_UTF8_ELLIPSIS),
    CookieWindow::_AddDomain(BString domain, bool fake)  
    303303        }
    304304    }
    305305
    306 #if 0
     306#if DEBUG
    307307    puts("==============================");
    308308    for (i = 0; i < fDomains->FullListCountItems(); i++) {
    309309        BStringItem* t = (BStringItem*)fDomains->FullListItemAt(i);
    CookieWindow::_ShowCookiesForDomain(BString domain)  
    373373void
    374374CookieWindow::_DeleteCookies()
    375375{
    376     // TODO shall we handle multiple selection here?
    377     CookieRow* row = (CookieRow*)fCookies->CurrentSelection();
    378     if (row == NULL) {
    379         // TODO see if a domain is selected in the domain list, and delete all
    380         // cookies for that domain
    381         return;
     376    CookieRow* row;
     377    CookieRow* prevRow;
     378
     379    for (prevRow = NULL; ; prevRow = row) {
     380        row = (CookieRow*)fCookies->CurrentSelection(prevRow);
     381
     382        if (prevRow != NULL) {
     383            fCookies->RemoveRow(prevRow);
     384            delete prevRow;
     385        }
     386
     387        if (row == NULL)
     388            break;
     389
     390        // delete this cookie
     391        BNetworkCookie& cookie = row->Cookie();
     392        cookie.SetExpirationDate(0);
     393        fCookieJar.AddCookie(cookie);
    382394    }
    383395
    384     fCookies->RemoveRow(row);
     396    // A domain was selected in the domain list
     397    if (prevRow == NULL) {
     398        while (true) {
     399            // Clear the first cookie continuously
     400            row = (CookieRow*)fCookies->RowAt(0);
    385401
    386     BNetworkCookie& cookie = row->Cookie();
    387     cookie.SetExpirationDate(0);
    388     fCookieJar.AddCookie(cookie);
     402            if (row == NULL)
     403                break;
    389404
    390     delete row;
     405            BNetworkCookie& cookie = row->Cookie();
     406            cookie.SetExpirationDate(0);
     407            fCookieJar.AddCookie(cookie);
     408            fCookies->RemoveRow(row);
     409            delete row;
     410        }
     411    }
    391412}