Changeset 51846 in webkit


Ignore:
Timestamp:
Dec 8, 2009 5:21:03 AM (14 years ago)
Author:
eric@webkit.org
Message:

2009-12-08 Alexander Pavlov <apavlov@chromium.org>

Reviewed by Pavel Feldman.

Change the way cookies are retrieved in the WebInspector frontend.

Moved the cookie filtering from the native code into the frontend so that
all cookies can be retrieved regardless of the associated domain
(required for certain audits to run.)
https://bugs.webkit.org/show_bug.cgi?id=32160

  • inspector/cookie-resource-match-expected.txt: Added.
  • inspector/cookie-resource-match.html: Added.

2009-12-08 Alexander Pavlov <apavlov@chromium.org>

Reviewed by Pavel Feldman.

Change the way cookies are retrieved in the WebInspector frontend.

Moved the cookie filtering from the native code into the frontend so that
all cookies can be retrieved regardless of the associated domain
(required for certain audits to run.)
https://bugs.webkit.org/show_bug.cgi?id=32160

Test: inspector/cookie-resource-match.html

  • inspector/InspectorBackend.cpp: (WebCore::InspectorBackend::getCookies):
  • inspector/InspectorBackend.h:
  • inspector/InspectorBackend.idl:
  • inspector/InspectorController.cpp: (WebCore::InspectorController::getCookies):
  • inspector/InspectorController.h:
  • inspector/front-end/CookieItemsView.js: (WebInspector.CookieItemsView.prototype.update.callback): (WebInspector.CookieItemsView.prototype.update): (WebInspector.CookieItemsView.prototype._cookiesForDomain):
  • inspector/front-end/DOMAgent.js: (WebInspector.Cookies.getCookiesAsync): (WebInspector.Cookies.cookieMatchesResourceURL): (WebInspector.Cookies.cookieDomainMatchesResourceDomain):
  • inspector/front-end/Resource.js: (WebInspector.Resource): (WebInspector.Resource.prototype.get documentURL): (WebInspector.Resource.prototype.set documentURL):
  • inspector/front-end/inspector.js: (WebInspector.addResource):
Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r51843 r51846  
     12009-12-08  Alexander Pavlov  <apavlov@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Change the way cookies are retrieved in the WebInspector frontend.
     6
     7        Moved the cookie filtering from the native code into the frontend so that
     8        all cookies can be retrieved regardless of the associated domain
     9        (required for certain audits to run.)
     10        https://bugs.webkit.org/show_bug.cgi?id=32160
     11
     12        * inspector/cookie-resource-match-expected.txt: Added.
     13        * inspector/cookie-resource-match.html: Added.
     14
    1152009-12-08  Nikolas Zimmermann  <nzimmermann@rim.com>
    216
  • trunk/WebCore/ChangeLog

    r51845 r51846  
     12009-12-08  Alexander Pavlov  <apavlov@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Change the way cookies are retrieved in the WebInspector frontend.
     6
     7        Moved the cookie filtering from the native code into the frontend so that
     8        all cookies can be retrieved regardless of the associated domain
     9        (required for certain audits to run.)
     10        https://bugs.webkit.org/show_bug.cgi?id=32160
     11
     12        Test: inspector/cookie-resource-match.html
     13
     14        * inspector/InspectorBackend.cpp:
     15        (WebCore::InspectorBackend::getCookies):
     16        * inspector/InspectorBackend.h:
     17        * inspector/InspectorBackend.idl:
     18        * inspector/InspectorController.cpp:
     19        (WebCore::InspectorController::getCookies):
     20        * inspector/InspectorController.h:
     21        * inspector/front-end/CookieItemsView.js:
     22        (WebInspector.CookieItemsView.prototype.update.callback):
     23        (WebInspector.CookieItemsView.prototype.update):
     24        (WebInspector.CookieItemsView.prototype._cookiesForDomain):
     25        * inspector/front-end/DOMAgent.js:
     26        (WebInspector.Cookies.getCookiesAsync):
     27        (WebInspector.Cookies.cookieMatchesResourceURL):
     28        (WebInspector.Cookies.cookieDomainMatchesResourceDomain):
     29        * inspector/front-end/Resource.js:
     30        (WebInspector.Resource):
     31        (WebInspector.Resource.prototype.get documentURL):
     32        (WebInspector.Resource.prototype.set documentURL):
     33        * inspector/front-end/inspector.js:
     34        (WebInspector.addResource):
     35
    1362009-12-08  Nikolas Zimmermann  <nzimmermann@rim.com>
    237
  • trunk/WebCore/inspector/InspectorBackend.cpp

    r51528 r51846  
    358358}
    359359
    360 void InspectorBackend::getCookies(long callId, const String& domain)
     360void InspectorBackend::getCookies(long callId)
    361361{
    362362    if (!m_inspectorController)
    363363        return;
    364     m_inspectorController->getCookies(callId, domain);
     364    m_inspectorController->getCookies(callId);
    365365}
    366366
  • trunk/WebCore/inspector/InspectorBackend.h

    r51528 r51846  
    115115    void hideDOMNodeHighlight();
    116116
    117     void getCookies(long callId, const String& domain);
     117    void getCookies(long callId);
    118118    void deleteCookie(const String& cookieName, const String& domain);
    119119
  • trunk/WebCore/inspector/InspectorBackend.idl

    r51528 r51846  
    8888        void hideDOMNodeHighlight();
    8989
    90         void getCookies(in long callId, in DOMString domain);
     90        void getCookies(in long callId);
    9191        void deleteCookie(in DOMString cookieName, in DOMString domain);
    9292
  • trunk/WebCore/inspector/InspectorController.cpp

    r51631 r51846  
    11501150#endif
    11511151
    1152 void InspectorController::getCookies(long callId, const String& host)
     1152void InspectorController::getCookies(long callId)
    11531153{
    11541154    if (!m_frontend)
    11551155        return;
    1156    
     1156
    11571157    // If we can get raw cookies.
    11581158    ListHashSet<Cookie> rawCookiesList;
    1159    
     1159
    11601160    // If we can't get raw cookies - fall back to String representation
    11611161    String stringCookiesList;
    1162    
     1162
    11631163    // Return value to getRawCookies should be the same for every call because
    11641164    // the return value is platform/network backend specific, and the call will
    11651165    // always return the same true/false value.
    11661166    bool rawCookiesImplemented = false;
    1167    
     1167
    11681168    ResourcesMap::iterator resourcesEnd = m_resources.end();
    11691169    for (ResourcesMap::iterator it = m_resources.begin(); it != resourcesEnd; ++it) {
    11701170        Document* document = it->second->frame()->document();
    1171         if (document->url().host() == host) {
    1172             Vector<Cookie> docCookiesList;
    1173             rawCookiesImplemented = getRawCookies(document, document->cookieURL(), docCookiesList);
    1174            
    1175             if (!rawCookiesImplemented) {
    1176                 // FIXME: We need duplication checking for the String representation of cookies.
    1177                 ExceptionCode ec = 0;
    1178                 stringCookiesList += document->cookie(ec);
    1179                 // Exceptions are thrown by cookie() in sandboxed frames. That won't happen here
    1180                 // because "document" is the document of the main frame of the page.
    1181                 ASSERT(!ec);
    1182             } else {
    1183                 int cookiesSize = docCookiesList.size();
    1184                 for (int i = 0; i < cookiesSize; i++) {
    1185                     if (!rawCookiesList.contains(docCookiesList[i]))
    1186                         rawCookiesList.add(docCookiesList[i]);
    1187                 }
     1171        Vector<Cookie> docCookiesList;
     1172        rawCookiesImplemented = getRawCookies(document, document->cookieURL(), docCookiesList);
     1173
     1174        if (!rawCookiesImplemented) {
     1175            // FIXME: We need duplication checking for the String representation of cookies.
     1176            ExceptionCode ec = 0;
     1177            stringCookiesList += document->cookie(ec);
     1178            // Exceptions are thrown by cookie() in sandboxed frames. That won't happen here
     1179            // because "document" is the document of the main frame of the page.
     1180            ASSERT(!ec);
     1181        } else {
     1182            int cookiesSize = docCookiesList.size();
     1183            for (int i = 0; i < cookiesSize; i++) {
     1184                if (!rawCookiesList.contains(docCookiesList[i]))
     1185                    rawCookiesList.add(docCookiesList[i]);
    11881186            }
    11891187        }
    11901188    }
    1191    
     1189
    11921190    if (!rawCookiesImplemented)
    11931191        m_frontend->didGetCookies(callId, m_frontend->newScriptArray(), stringCookiesList);
  • trunk/WebCore/inspector/InspectorController.h

    r51631 r51846  
    187187    void mainResourceFiredDOMContentEvent(DocumentLoader*, const KURL&);
    188188                                                       
    189     void getCookies(long callId, const String& url);
     189    void getCookies(long callId);
    190190
    191191#if ENABLE(DATABASE)
  • trunk/WebCore/inspector/front-end/CookieItemsView.js

    r51528 r51846  
    6868
    6969        var self = this;
    70         function callback(cookies, isAdvanced) {
     70        function callback(allCookies, isAdvanced) {
     71            var cookies = self._cookiesForDomain(allCookies);
    7172            var dataGrid = (isAdvanced ? self.dataGridForCookies(cookies) : self.simpleDataGridForCookies(cookies));
    7273            if (dataGrid) {
     
    8687        }
    8788
    88         WebInspector.Cookies.getCookiesAsync(callback, this._cookieDomain);
     89        WebInspector.Cookies.getCookiesAsync(callback);
     90    },
     91
     92    _cookiesForDomain: function(allCookies)
     93    {
     94        var cookiesForDomain = [];
     95        var resourceURLsForDocumentURL = [];
     96
     97        for (var id in WebInspector.resources) {
     98            var resource = WebInspector.resources[id];
     99            var match = resource.documentURL.match(WebInspector.URLRegExp);
     100            if (match && match[2] === this._cookieDomain)
     101                resourceURLsForDocumentURL.push(resource.url);
     102        }
     103
     104        for (var i = 0; i < allCookies.length; ++i) {
     105            for (var j = 0; j < resourceURLsForDocumentURL.length; ++j) {
     106                var resourceURL = resourceURLsForDocumentURL[j];
     107                if (WebInspector.Cookies.cookieMatchesResourceURL(allCookies[i], resourceURL)) {
     108                    cookiesForDomain.push(allCookies[i]);
     109                    break;
     110                }
     111            }
     112        }
     113        return cookiesForDomain;
    89114    },
    90115
  • trunk/WebCore/inspector/front-end/DOMAgent.js

    r51601 r51846  
    440440WebInspector.Cookies = {}
    441441
    442 WebInspector.Cookies.getCookiesAsync = function(callback, cookieDomain)
     442WebInspector.Cookies.getCookiesAsync = function(callback)
    443443{
    444444    function mycallback(cookies, cookiesString) {
     
    449449    }
    450450    var callId = WebInspector.Callback.wrap(mycallback);
    451     InspectorBackend.getCookies(callId, cookieDomain);
     451    InspectorBackend.getCookies(callId);
    452452}
    453453
     
    469469
    470470    return cookies;
     471}
     472
     473WebInspector.Cookies.cookieMatchesResourceURL = function(cookie, resourceURL)
     474{
     475    var match = resourceURL.match(WebInspector.URLRegExp);
     476    if (!match)
     477        return false;
     478    // See WebInspector.URLRegExp for definitions of the group index constants.
     479    if (!this.cookieDomainMatchesResourceDomain(cookie.domain, match[2]))
     480        return false;
     481    var resourcePort = match[3] ? match[3] : undefined;
     482    var resourcePath = match[4] ? match[4] : '/';
     483    return (resourcePath.indexOf(cookie.path) === 0
     484        && (!cookie.port || resourcePort == cookie.port)
     485        && (!cookie.secure || match[1].toLowerCase() === 'https'));
     486}
     487
     488WebInspector.Cookies.cookieDomainMatchesResourceDomain = function(cookieDomain, resourceDomain)
     489{
     490    if (cookieDomain.charAt(0) !== '.')
     491        return resourceDomain === cookieDomain;
     492    return !!resourceDomain.match(new RegExp("^([^\\.]+\\.)?" + cookieDomain.substring(1).escapeForRegExp() + "$"), "i");
    471493}
    472494
  • trunk/WebCore/inspector/front-end/Resource.js

    r51229 r51846  
    2727 */
    2828
    29 WebInspector.Resource = function(requestHeaders, url, domain, path, lastPathComponent, identifier, mainResource, cached, requestMethod, requestFormData)
     29WebInspector.Resource = function(requestHeaders, url, documentURL, domain, path, lastPathComponent, identifier, mainResource, cached, requestMethod, requestFormData)
    3030{
    3131    this.identifier = identifier;
     
    3636    this.requestHeaders = requestHeaders;
    3737    this.url = url;
     38    this.documentURL = documentURL;
    3839    this.domain = domain;
    3940    this.path = path;
     
    163164    },
    164165
     166    get documentURL()
     167    {
     168        return this._documentURL;
     169    },
     170
     171    set documentURL(x)
     172    {
     173        if (this._documentURL === x)
     174            return;
     175        this._documentURL = x;
     176    },
     177
    165178    get domain()
    166179    {
  • trunk/WebCore/inspector/front-end/inspector.js

    r51839 r51846  
    7575    pendingDispatches: 0,
    7676
     77    // RegExp groups:
     78    // 1 - scheme
     79    // 2 - hostname
     80    // 3 - ?port
     81    // 4 - ?path
     82    // 5 - ?fragment
     83    URLRegExp: /^(http[s]?|file):\/\/([^\/:]+)(?::([\d]+))?(?:(\/[^#]*)(?:#(.*))?)?$/i,
     84
    7785    get platform()
    7886    {
     
    10101018        payload.requestHeaders,
    10111019        payload.requestURL,
     1020        payload.documentURL,
    10121021        payload.host,
    10131022        payload.path,
Note: See TracChangeset for help on using the changeset viewer.