| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 SDK.CookieModel = class extends SDK.SDKModel { | 5 SDK.CookieModel = class extends SDK.SDKModel { |
| 6 /** | 6 /** |
| 7 * @param {!SDK.Target} target | 7 * @param {!SDK.Target} target |
| 8 */ | 8 */ |
| 9 constructor(target) { | 9 constructor(target) { |
| 10 super(target); | 10 super(target); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 cookie.addAttribute('httpOnly'); | 25 cookie.addAttribute('httpOnly'); |
| 26 if (protocolCookie['secure']) | 26 if (protocolCookie['secure']) |
| 27 cookie.addAttribute('secure'); | 27 cookie.addAttribute('secure'); |
| 28 if (protocolCookie['sameSite']) | 28 if (protocolCookie['sameSite']) |
| 29 cookie.addAttribute('sameSite', protocolCookie['sameSite']); | 29 cookie.addAttribute('sameSite', protocolCookie['sameSite']); |
| 30 cookie.setSize(protocolCookie['size']); | 30 cookie.setSize(protocolCookie['size']); |
| 31 return cookie; | 31 return cookie; |
| 32 } | 32 } |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * @param {!SDK.Target} target | |
| 36 * @return {!SDK.CookieModel} | |
| 37 */ | |
| 38 static fromTarget(target) { | |
| 39 return /** @type {!SDK.CookieModel} */ (target.model(SDK.CookieModel)); | |
| 40 } | |
| 41 | |
| 42 /** | |
| 43 * @param {!SDK.Cookie} cookie | 35 * @param {!SDK.Cookie} cookie |
| 44 * @param {string} resourceURL | 36 * @param {string} resourceURL |
| 45 * @return {boolean} | 37 * @return {boolean} |
| 46 */ | 38 */ |
| 47 static cookieMatchesResourceURL(cookie, resourceURL) { | 39 static cookieMatchesResourceURL(cookie, resourceURL) { |
| 48 var url = resourceURL.asParsedURL(); | 40 var url = resourceURL.asParsedURL(); |
| 49 if (!url || !SDK.CookieModel.cookieDomainMatchesResourceDomain(cookie.domain
(), url.host)) | 41 if (!url || !SDK.CookieModel.cookieDomainMatchesResourceDomain(cookie.domain
(), url.host)) |
| 50 return false; | 42 return false; |
| 51 return ( | 43 return ( |
| 52 url.path.startsWith(cookie.path()) && (!cookie.port() || url.port === co
okie.port()) && | 44 url.path.startsWith(cookie.path()) && (!cookie.port() || url.port === co
okie.port()) && |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 getCookiesForDomain(domain, callback) { | 111 getCookiesForDomain(domain, callback) { |
| 120 var resourceURLs = []; | 112 var resourceURLs = []; |
| 121 /** | 113 /** |
| 122 * @param {!SDK.Resource} resource | 114 * @param {!SDK.Resource} resource |
| 123 */ | 115 */ |
| 124 function populateResourceURLs(resource) { | 116 function populateResourceURLs(resource) { |
| 125 var url = resource.documentURL.asParsedURL(); | 117 var url = resource.documentURL.asParsedURL(); |
| 126 if (url && (!domain || url.securityOrigin() === domain)) | 118 if (url && (!domain || url.securityOrigin() === domain)) |
| 127 resourceURLs.push(resource.url); | 119 resourceURLs.push(resource.url); |
| 128 } | 120 } |
| 129 SDK.ResourceTreeModel.fromTarget(this.target()).forAllResources(populateReso
urceURLs); | 121 var resourceTreeModel = this.target().model(SDK.ResourceTreeModel); |
| 122 if (resourceTreeModel) |
| 123 resourceTreeModel.forAllResources(populateResourceURLs); |
| 130 this.getCookiesAsync(resourceURLs, callback); | 124 this.getCookiesAsync(resourceURLs, callback); |
| 131 } | 125 } |
| 132 | 126 |
| 133 /** | 127 /** |
| 134 * @param {!Array<!SDK.Cookie>} cookies | 128 * @param {!Array<!SDK.Cookie>} cookies |
| 135 * @param {function()=} callback | 129 * @param {function()=} callback |
| 136 */ | 130 */ |
| 137 _deleteAll(cookies, callback) { | 131 _deleteAll(cookies, callback) { |
| 138 var networkAgent = this.target().networkAgent(); | 132 var networkAgent = this.target().networkAgent(); |
| 139 function deleteCookie(cookie) { | 133 function deleteCookie(cookie) { |
| 140 return new Promise(resolve => networkAgent.deleteCookie(cookie.name(), coo
kie.url(), resolve)); | 134 return new Promise(resolve => networkAgent.deleteCookie(cookie.name(), coo
kie.url(), resolve)); |
| 141 } | 135 } |
| 142 Promise.all(cookies.map(deleteCookie)).then(callback || function() {}); | 136 Promise.all(cookies.map(deleteCookie)).then(callback || function() {}); |
| 143 } | 137 } |
| 144 }; | 138 }; |
| 145 | 139 |
| 146 SDK.SDKModel.register(SDK.CookieModel, SDK.Target.Capability.Network, false); | 140 SDK.SDKModel.register(SDK.CookieModel, SDK.Target.Capability.Network, false); |
| OLD | NEW |