Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 } | 243 } |
| 244 | 244 |
| 245 /** | 245 /** |
| 246 * @return {boolean} | 246 * @return {boolean} |
| 247 */ | 247 */ |
| 248 secure() { | 248 secure() { |
| 249 return 'secure' in this._attributes; | 249 return 'secure' in this._attributes; |
| 250 } | 250 } |
| 251 | 251 |
| 252 /** | 252 /** |
| 253 * @return {string} | 253 * TODO(allada) This should not rely on _attributes and instead store them ind ividually. |
|
allada
2016/12/23 00:37:11
nit: We try not to add any non-jsdoc stuff in /**
| |
| 254 * @return {!Protocol.Network.CookieSameSite} | |
| 254 */ | 255 */ |
| 255 sameSite() { | 256 sameSite() { |
| 256 return this._attributes['samesite']; | 257 return /** @type {!Protocol.Network.CookieSameSite} */ (this._attributes['sa mesite']); |
| 257 } | 258 } |
| 258 | 259 |
| 259 /** | 260 /** |
| 260 * @return {boolean} | 261 * @return {boolean} |
| 261 */ | 262 */ |
| 262 session() { | 263 session() { |
| 263 // RFC 2965 suggests using Discard attribute to mark session cookies, but th is does not seem to be widely used. | 264 // RFC 2965 suggests using Discard attribute to mark session cookies, but th is does not seem to be widely used. |
| 264 // Check for absence of explicitly max-age or expiry date instead. | 265 // Check for absence of explicitly max-age or expiry date instead. |
| 265 return !('expires' in this._attributes || 'max-age' in this._attributes); | 266 return !('expires' in this._attributes || 'max-age' in this._attributes); |
| 266 } | 267 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 return this._attributes['max-age']; | 301 return this._attributes['max-age']; |
| 301 } | 302 } |
| 302 | 303 |
| 303 /** | 304 /** |
| 304 * @return {number} | 305 * @return {number} |
| 305 */ | 306 */ |
| 306 size() { | 307 size() { |
| 307 return this._size; | 308 return this._size; |
| 308 } | 309 } |
| 309 | 310 |
| 311 url() { | |
| 312 return (this.secure() ? 'https://' : 'http://') + this.domain() + this.path( ); | |
| 313 } | |
| 314 | |
| 310 /** | 315 /** |
| 311 * @param {number} size | 316 * @param {number} size |
| 312 */ | 317 */ |
| 313 setSize(size) { | 318 setSize(size) { |
| 314 this._size = size; | 319 this._size = size; |
| 315 } | 320 } |
| 316 | 321 |
| 317 /** | 322 /** |
| 318 * @return {?Date} | 323 * @return {?Date} |
| 319 */ | 324 */ |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 342 * @param {string=} value | 347 * @param {string=} value |
| 343 */ | 348 */ |
| 344 addAttribute(key, value) { | 349 addAttribute(key, value) { |
| 345 this._attributes[key.toLowerCase()] = value; | 350 this._attributes[key.toLowerCase()] = value; |
| 346 } | 351 } |
| 347 | 352 |
| 348 /** | 353 /** |
| 349 * @param {function(?Protocol.Error)=} callback | 354 * @param {function(?Protocol.Error)=} callback |
| 350 */ | 355 */ |
| 351 remove(callback) { | 356 remove(callback) { |
| 352 this._target.networkAgent().deleteCookie( | 357 this._target.networkAgent().deleteCookie(this.name(), this.url(), callback); |
| 353 this.name(), (this.secure() ? 'https://' : 'http://') + this.domain() + this.path(), callback); | 358 } |
| 359 | |
| 360 /** | |
| 361 * @param {function(?Protocol.Error, boolean)=} callback | |
| 362 */ | |
| 363 save(callback) { | |
| 364 var domain = this.domain(); | |
| 365 if (!domain.startsWith('.')) | |
| 366 domain = ''; | |
| 367 var expires = undefined; | |
| 368 if (this.expires()) | |
| 369 expires = Math.floor(Date.parse(this.expires()) / 1000); | |
| 370 this._target.networkAgent().setCookie(this.url(), this.name(), this.value(), domain, this.path(), this.secure(), | |
| 371 this.httpOnly(), this.sameSite(), expires, callback); | |
| 354 } | 372 } |
| 355 }; | 373 }; |
| 356 | 374 |
| 357 /** | 375 /** |
| 358 * @enum {number} | 376 * @enum {number} |
| 359 */ | 377 */ |
| 360 SDK.Cookie.Type = { | 378 SDK.Cookie.Type = { |
| 361 Request: 0, | 379 Request: 0, |
| 362 Response: 1 | 380 Response: 1 |
| 363 }; | 381 }; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 393 * @param {!SDK.Target} target | 411 * @param {!SDK.Target} target |
| 394 * @param {!Protocol.Network.Cookie} protocolCookie | 412 * @param {!Protocol.Network.Cookie} protocolCookie |
| 395 * @return {!SDK.Cookie} | 413 * @return {!SDK.Cookie} |
| 396 */ | 414 */ |
| 397 SDK.Cookies._parseProtocolCookie = function(target, protocolCookie) { | 415 SDK.Cookies._parseProtocolCookie = function(target, protocolCookie) { |
| 398 var cookie = new SDK.Cookie(target, protocolCookie.name, protocolCookie.value, null); | 416 var cookie = new SDK.Cookie(target, protocolCookie.name, protocolCookie.value, null); |
| 399 cookie.addAttribute('domain', protocolCookie['domain']); | 417 cookie.addAttribute('domain', protocolCookie['domain']); |
| 400 cookie.addAttribute('path', protocolCookie['path']); | 418 cookie.addAttribute('path', protocolCookie['path']); |
| 401 cookie.addAttribute('port', protocolCookie['port']); | 419 cookie.addAttribute('port', protocolCookie['port']); |
| 402 if (protocolCookie['expires']) | 420 if (protocolCookie['expires']) |
| 403 cookie.addAttribute('expires', protocolCookie['expires']); | 421 cookie.addAttribute('expires', (new Date(protocolCookie['expires'])).toUTCSt ring()); |
| 404 if (protocolCookie['httpOnly']) | 422 if (protocolCookie['httpOnly']) |
| 405 cookie.addAttribute('httpOnly'); | 423 cookie.addAttribute('httpOnly'); |
| 406 if (protocolCookie['secure']) | 424 if (protocolCookie['secure']) |
| 407 cookie.addAttribute('secure'); | 425 cookie.addAttribute('secure'); |
| 408 if (protocolCookie['sameSite']) | 426 if (protocolCookie['sameSite']) |
| 409 cookie.addAttribute('sameSite', protocolCookie['sameSite']); | 427 cookie.addAttribute('sameSite', protocolCookie['sameSite']); |
| 410 cookie.setSize(protocolCookie['size']); | 428 cookie.setSize(protocolCookie['size']); |
| 411 return cookie; | 429 return cookie; |
| 412 }; | 430 }; |
| 413 | 431 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 428 /** | 446 /** |
| 429 * @param {string} cookieDomain | 447 * @param {string} cookieDomain |
| 430 * @param {string} resourceDomain | 448 * @param {string} resourceDomain |
| 431 * @return {boolean} | 449 * @return {boolean} |
| 432 */ | 450 */ |
| 433 SDK.Cookies.cookieDomainMatchesResourceDomain = function(cookieDomain, resourceD omain) { | 451 SDK.Cookies.cookieDomainMatchesResourceDomain = function(cookieDomain, resourceD omain) { |
| 434 if (cookieDomain.charAt(0) !== '.') | 452 if (cookieDomain.charAt(0) !== '.') |
| 435 return resourceDomain === cookieDomain; | 453 return resourceDomain === cookieDomain; |
| 436 return !!resourceDomain.match(new RegExp('^([^\\.]+\\.)*' + cookieDomain.subst ring(1).escapeForRegExp() + '$', 'i')); | 454 return !!resourceDomain.match(new RegExp('^([^\\.]+\\.)*' + cookieDomain.subst ring(1).escapeForRegExp() + '$', 'i')); |
| 437 }; | 455 }; |
| OLD | NEW |