| 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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 * @enum {number} | 358 * @enum {number} |
| 359 */ | 359 */ |
| 360 SDK.Cookie.Type = { | 360 SDK.Cookie.Type = { |
| 361 Request: 0, | 361 Request: 0, |
| 362 Response: 1 | 362 Response: 1 |
| 363 }; | 363 }; |
| 364 | 364 |
| 365 SDK.Cookies = {}; | 365 SDK.Cookies = {}; |
| 366 | 366 |
| 367 /** | 367 /** |
| 368 * @param {!SDK.Target} target |
| 369 * @param {!Array.<string>} urls |
| 368 * @param {function(!Array.<!SDK.Cookie>)} callback | 370 * @param {function(!Array.<!SDK.Cookie>)} callback |
| 369 */ | 371 */ |
| 370 SDK.Cookies.getCookiesAsync = function(callback) { | 372 SDK.Cookies.getCookiesAsync = function(target, urls, callback) { |
| 371 var allCookies = []; | 373 target.networkAgent().getCookies(urls, (err, cookies) => { |
| 372 /** | 374 if (err) { |
| 373 * @param {!SDK.Target} target | 375 console.error(err); |
| 374 * @param {?Protocol.Error} error | 376 return callback([]); |
| 375 * @param {!Array.<!Protocol.Network.Cookie>} cookies | |
| 376 */ | |
| 377 function mycallback(target, error, cookies) { | |
| 378 if (error) { | |
| 379 console.error(error); | |
| 380 return; | |
| 381 } | 377 } |
| 382 for (var i = 0; i < cookies.length; ++i) | |
| 383 allCookies.push(SDK.Cookies._parseProtocolCookie(target, cookies[i])); | |
| 384 } | |
| 385 | 378 |
| 386 var barrier = new CallbackBarrier(); | 379 callback(cookies.map(cookie => SDK.Cookies._parseProtocolCookie(target, cook
ie))); |
| 387 for (var target of SDK.targetManager.targets(SDK.Target.Capability.Network)) | 380 }); |
| 388 target.networkAgent().getCookies(barrier.createCallback(mycallback.bind(null
, target))); | |
| 389 barrier.callWhenDone(callback.bind(null, allCookies)); | |
| 390 }; | 381 }; |
| 391 | 382 |
| 392 /** | 383 /** |
| 393 * @param {!SDK.Target} target | 384 * @param {!SDK.Target} target |
| 394 * @param {!Protocol.Network.Cookie} protocolCookie | 385 * @param {!Protocol.Network.Cookie} protocolCookie |
| 395 * @return {!SDK.Cookie} | 386 * @return {!SDK.Cookie} |
| 396 */ | 387 */ |
| 397 SDK.Cookies._parseProtocolCookie = function(target, protocolCookie) { | 388 SDK.Cookies._parseProtocolCookie = function(target, protocolCookie) { |
| 398 var cookie = new SDK.Cookie(target, protocolCookie.name, protocolCookie.value,
null); | 389 var cookie = new SDK.Cookie(target, protocolCookie.name, protocolCookie.value,
null); |
| 399 cookie.addAttribute('domain', protocolCookie['domain']); | 390 cookie.addAttribute('domain', protocolCookie['domain']); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 428 /** | 419 /** |
| 429 * @param {string} cookieDomain | 420 * @param {string} cookieDomain |
| 430 * @param {string} resourceDomain | 421 * @param {string} resourceDomain |
| 431 * @return {boolean} | 422 * @return {boolean} |
| 432 */ | 423 */ |
| 433 SDK.Cookies.cookieDomainMatchesResourceDomain = function(cookieDomain, resourceD
omain) { | 424 SDK.Cookies.cookieDomainMatchesResourceDomain = function(cookieDomain, resourceD
omain) { |
| 434 if (cookieDomain.charAt(0) !== '.') | 425 if (cookieDomain.charAt(0) !== '.') |
| 435 return resourceDomain === cookieDomain; | 426 return resourceDomain === cookieDomain; |
| 436 return !!resourceDomain.match(new RegExp('^([^\\.]+\\.)*' + cookieDomain.subst
ring(1).escapeForRegExp() + '$', 'i')); | 427 return !!resourceDomain.match(new RegExp('^([^\\.]+\\.)*' + cookieDomain.subst
ring(1).escapeForRegExp() + '$', 'i')); |
| 437 }; | 428 }; |
| OLD | NEW |