Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(743)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/CookieParser.js

Issue 2567873002: DevTools: Add ability to add and edit cookies (Closed)
Patch Set: Rebase. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 * @return {!Protocol.Network.CookieSameSite}
254 */ 254 */
255 sameSite() { 255 sameSite() {
256 return this._attributes['samesite']; 256 // TODO(allada) This should not rely on _attributes and instead store them i ndividually.
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 13 matching lines...) Expand all
280 } 281 }
281 282
282 /** 283 /**
283 * @return {string} 284 * @return {string}
284 */ 285 */
285 domain() { 286 domain() {
286 return this._attributes['domain']; 287 return this._attributes['domain'];
287 } 288 }
288 289
289 /** 290 /**
290 * @return {string} 291 * @return {number}
291 */ 292 */
292 expires() { 293 expires() {
293 return this._attributes['expires']; 294 return this._attributes['expires'];
294 } 295 }
295 296
296 /** 297 /**
297 * @return {string} 298 * @return {string}
298 */ 299 */
299 maxAge() { 300 maxAge() {
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() {
dgozman 2017/01/24 01:23:25 @return {string}
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
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(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, mycallback);
372
373 /**
374 * @param {?Protocol.Error} error
375 * @param {boolean} success
376 */
377 function mycallback(error, success) {
378 callback(success);
dgozman 2017/01/24 01:23:25 callback(error ? false : success)
379 }
354 } 380 }
355 }; 381 };
356 382
357 /** 383 /**
358 * @enum {number} 384 * @enum {number}
359 */ 385 */
360 SDK.Cookie.Type = { 386 SDK.Cookie.Type = {
361 Request: 0, 387 Request: 0,
362 Response: 1 388 Response: 1
363 }; 389 };
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 /** 454 /**
429 * @param {string} cookieDomain 455 * @param {string} cookieDomain
430 * @param {string} resourceDomain 456 * @param {string} resourceDomain
431 * @return {boolean} 457 * @return {boolean}
432 */ 458 */
433 SDK.Cookies.cookieDomainMatchesResourceDomain = function(cookieDomain, resourceD omain) { 459 SDK.Cookies.cookieDomainMatchesResourceDomain = function(cookieDomain, resourceD omain) {
434 if (cookieDomain.charAt(0) !== '.') 460 if (cookieDomain.charAt(0) !== '.')
435 return resourceDomain === cookieDomain; 461 return resourceDomain === cookieDomain;
436 return !!resourceDomain.match(new RegExp('^([^\\.]+\\.)*' + cookieDomain.subst ring(1).escapeForRegExp() + '$', 'i')); 462 return !!resourceDomain.match(new RegExp('^([^\\.]+\\.)*' + cookieDomain.subst ring(1).escapeForRegExp() + '$', 'i'));
437 }; 463 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698