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

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, 10 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
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/resources/ResourcesPanel.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
310 /** 311 /**
312 * @return {string}
313 */
314 url() {
315 return (this.secure() ? 'https://' : 'http://') + this.domain() + this.path( );
316 }
317
318 /**
311 * @param {number} size 319 * @param {number} size
312 */ 320 */
313 setSize(size) { 321 setSize(size) {
314 this._size = size; 322 this._size = size;
315 } 323 }
316 324
317 /** 325 /**
318 * @return {?Date} 326 * @return {?Date}
319 */ 327 */
320 expiresDate(requestDate) { 328 expiresDate(requestDate) {
(...skipping 21 matching lines...) Expand all
342 * @param {string=} value 350 * @param {string=} value
343 */ 351 */
344 addAttribute(key, value) { 352 addAttribute(key, value) {
345 this._attributes[key.toLowerCase()] = value; 353 this._attributes[key.toLowerCase()] = value;
346 } 354 }
347 355
348 /** 356 /**
349 * @param {function(?Protocol.Error)=} callback 357 * @param {function(?Protocol.Error)=} callback
350 */ 358 */
351 remove(callback) { 359 remove(callback) {
352 this._target.networkAgent().deleteCookie( 360 this._target.networkAgent().deleteCookie(this.name(), this.url(), callback);
353 this.name(), (this.secure() ? 'https://' : 'http://') + this.domain() + this.path(), callback); 361 }
362
363 /**
364 * @param {function(boolean)=} callback
365 */
366 save(callback) {
367 var domain = this.domain();
368 if (!domain.startsWith('.'))
369 domain = '';
370 var expires = undefined;
371 if (this.expires())
372 expires = Math.floor(Date.parse(this.expires()) / 1000);
373 this._target.networkAgent().setCookie(this.url(), this.name(), this.value(), domain, this.path(), this.secure(),
374 this.httpOnly(), this.sameSite(), expires, mycallback);
375
376 /**
377 * @param {?Protocol.Error} error
378 * @param {boolean} success
379 */
380 function mycallback(error, success) {
381 callback(error ? false : success);
382 }
354 } 383 }
355 }; 384 };
356 385
357 /** 386 /**
358 * @enum {number} 387 * @enum {number}
359 */ 388 */
360 SDK.Cookie.Type = { 389 SDK.Cookie.Type = {
361 Request: 0, 390 Request: 0,
362 Response: 1 391 Response: 1
363 }; 392 };
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 /** 448 /**
420 * @param {string} cookieDomain 449 * @param {string} cookieDomain
421 * @param {string} resourceDomain 450 * @param {string} resourceDomain
422 * @return {boolean} 451 * @return {boolean}
423 */ 452 */
424 SDK.Cookies.cookieDomainMatchesResourceDomain = function(cookieDomain, resourceD omain) { 453 SDK.Cookies.cookieDomainMatchesResourceDomain = function(cookieDomain, resourceD omain) {
425 if (cookieDomain.charAt(0) !== '.') 454 if (cookieDomain.charAt(0) !== '.')
426 return resourceDomain === cookieDomain; 455 return resourceDomain === cookieDomain;
427 return !!resourceDomain.match(new RegExp('^([^\\.]+\\.)*' + cookieDomain.subst ring(1).escapeForRegExp() + '$', 'i')); 456 return !!resourceDomain.match(new RegExp('^([^\\.]+\\.)*' + cookieDomain.subst ring(1).escapeForRegExp() + '$', 'i'));
428 }; 457 };
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/resources/ResourcesPanel.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698