Changeset 192614 in webkit
- Timestamp:
- Nov 18, 2015, 10:27:21 PM (10 years ago)
- Location:
- trunk/Source/WebInspectorUI
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebInspectorUI/ChangeLog
r192613 r192614 1 2015-11-18 Brian Burg <bburg@apple.com> 2 3 Web Inspector: move cookie url matching out of CookieStorageContentView and clean up some code 4 https://bugs.webkit.org/show_bug.cgi?id=151424 5 6 Reviewed by Timothy Hatcher. 7 8 Move the code that decides whether a cookie matches a resource URL to a model class. 9 This will make it possible to test this code easily without pulling Views into tests. 10 11 * UserInterface/Models/CookieStorageObject.js: 12 (WebInspector.CookieStorageObject.cookieMatchesResourceURL): 13 (WebInspector.CookieStorageObject.cookieDomainMatchesResourceDomain): 14 (WebInspector.CookieStorageObject.prototype.saveIdentityToCookie): 15 (WebInspector.CookieStorageObject): 16 * UserInterface/Views/CookieStorageContentView.js: 17 (WebInspector.CookieStorageContentView.prototype.update): use Promises. 18 (WebInspector.CookieStorageContentView.prototype._rebuildTable): 19 (WebInspector.CookieStorageContentView.prototype._filterCookies): 20 21 Use Array.filter() and Array.some() to express this logic more directly. 22 23 (WebInspector.CookieStorageContentView.cookieMatchesResourceURL): Deleted. 24 (WebInspector.CookieStorageContentView.cookieDomainMatchesResourceDomain): Deleted. 25 (WebInspector.CookieStorageContentView.prototype.update.callback): Deleted. 26 1 27 2015-11-18 Matt Baker <mattbaker@apple.com> 2 28 -
trunk/Source/WebInspectorUI/UserInterface/Models/CookieStorageObject.js
r181769 r192614 1 1 /* 2 * Copyright (C) 2013 Apple Inc. All rights reserved.2 * Copyright (C) 2013, 2015 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 31 31 } 32 32 33 // Static 34 35 static cookieMatchesResourceURL(cookie, resourceURL) 36 { 37 var parsedURL = parseURL(resourceURL); 38 if (!parsedURL || !WebInspector.CookieStorageObject.cookieDomainMatchesResourceDomain(cookie.domain, parsedURL.host)) 39 return false; 40 41 return (parsedURL.path.startsWith(cookie.path) 42 && (!cookie.port || parsedURL.port === cookie.port) 43 && (!cookie.secure || parsedURL.scheme === "https")); 44 } 45 46 static cookieDomainMatchesResourceDomain(cookieDomain, resourceDomain) 47 { 48 if (cookieDomain.charAt(0) !== ".") 49 return resourceDomain === cookieDomain; 50 return !!resourceDomain.match(new RegExp("^([^\\.]+\\.)?" + cookieDomain.substring(1).escapeForRegExp() + "$"), "i"); 51 } 52 33 53 // Public 34 54 … … 40 60 saveIdentityToCookie(cookie) 41 61 { 42 // FIXME : This class will need to look up cookies that are setfor this host.62 // FIXME <https://webkit.org/b/151413>: This class should actually store cookie data for this host. 43 63 cookie[WebInspector.CookieStorageObject.CookieHostCookieKey] = this.host; 44 64 } -
trunk/Source/WebInspectorUI/UserInterface/Views/CookieStorageContentView.js
r192086 r192614 38 38 } 39 39 40 // Static41 42 static cookieMatchesResourceURL(cookie, resourceURL)43 {44 var parsedURL = parseURL(resourceURL);45 if (!parsedURL || !WebInspector.CookieStorageContentView.cookieDomainMatchesResourceDomain(cookie.domain, parsedURL.host))46 return false;47 48 return (parsedURL.path.startsWith(cookie.path)49 && (!cookie.port || parsedURL.port === cookie.port)50 && (!cookie.secure || parsedURL.scheme === "https"));51 }52 53 static cookieDomainMatchesResourceDomain(cookieDomain, resourceDomain)54 {55 if (cookieDomain.charAt(0) !== ".")56 return resourceDomain === cookieDomain;57 return !!resourceDomain.match(new RegExp("^([^\\.]+\\.)?" + cookieDomain.substring(1).escapeForRegExp() + "$"), "i");58 }59 60 40 // Public 61 41 … … 67 47 update() 68 48 { 69 function callback(error, cookies) 70 { 71 if (error) 72 return; 73 74 this._cookies = this._filterCookies(cookies); 49 PageAgent.getCookies().then((payload) => { 50 this._cookies = this._filterCookies(payload.cookies); 75 51 this._rebuildTable(); 76 } 77 78 PageAgent.getCookies(callback.bind(this));52 }).catch((error) => { 53 console.error("Could not fetch cookies: ", error); 54 }); 79 55 } 80 56 … … 96 72 _rebuildTable() 97 73 { 98 // FIXME: If there are no cookies, do we want to show an empty datagrid, or do something like the old 99 // inspector and show some text saying there are no cookies? 74 // FIXME <https://webkit.org/b/151400>: If there are no cookies, add placeholder explanatory text. 100 75 if (!this._dataGrid) { 101 76 var columns = {name: {}, value: {}, domain: {}, path: {}, expires: {}, size: {}, http: {}, secure: {}}; … … 173 148 _filterCookies(cookies) 174 149 { 175 var filteredCookies = []; 176 var resourcesForDomain = []; 177 178 var frames = WebInspector.frameResourceManager.frames; 179 for (var i = 0; i < frames.length; ++i) { 180 var resources = frames[i].resources; 181 for (var j = 0; j < resources.length; ++j) { 182 var urlComponents = resources[j].urlComponents; 183 if (urlComponents && urlComponents.host && urlComponents.host === this.representedObject.host) 184 resourcesForDomain.push(resources[j].url); 185 } 186 187 // The main resource isn't always in the list of resources, make sure to add it to the list of resources 188 // we get the URLs from. 189 var mainResourceURLComponents = frames[i].mainResource.urlComponents; 190 if (mainResourceURLComponents && mainResourceURLComponents.host && mainResourceURLComponents.host === this.representedObject.host) 191 resourcesForDomain.push(frames[i].mainResource.url); 192 } 193 194 for (var i = 0; i < cookies.length; ++i) { 195 for (var j = 0; j < resourcesForDomain.length; ++j) { 196 if (WebInspector.CookieStorageContentView.cookieMatchesResourceURL(cookies[i], resourcesForDomain[j])) { 197 filteredCookies.push(cookies[i]); 198 break; 199 } 200 } 201 } 202 203 return filteredCookies; 150 let resourceMatchesStorageDomain = (resource) => { 151 let urlComponents = resource.urlComponents; 152 return urlComponents && urlComponents.host && urlComponents.host === this.representedObject.host; 153 } 154 155 let allResources = []; 156 for (let frame of WebInspector.frameResourceManager.frames) { 157 // The main resource isn't in the list of resources, so add it as a candidate. 158 allResources.push(frame.mainResource); 159 allResources = allResources.concat(frame.resources); 160 } 161 162 let resourcesForDomain = allResources.filter(resourceMatchesStorageDomain); 163 164 let cookiesForDomain = cookies.filter((cookie) => { 165 return resourcesForDomain.some((resource) => { 166 return WebInspector.CookieStorageObject.cookieMatchesResourceURL(cookie, resource.url); 167 }); 168 }); 169 return cookiesForDomain; 204 170 } 205 171
Note:
See TracChangeset
for help on using the changeset viewer.