Changeset View
Changeset View
Standalone View
Standalone View
extension/extension.js
Show First 20 Lines • Show All 430 Lines • ▼ Show 20 Line(s) | |||||
431 | 431 | | |||
432 | chrome.downloads.onCreated.addListener(createDownload); | 432 | chrome.downloads.onCreated.addListener(createDownload); | ||
433 | 433 | | |||
434 | chrome.downloads.onChanged.addListener(function (delta) { | 434 | chrome.downloads.onChanged.addListener(function (delta) { | ||
435 | if (activeDownloads.indexOf(delta.id) === -1) { | 435 | if (activeDownloads.indexOf(delta.id) === -1) { | ||
436 | return; | 436 | return; | ||
437 | } | 437 | } | ||
438 | 438 | | |||
439 | // An interrupted download was resumed. When a download is interrupted, we finish (and delete) | ||||
440 | // the job but the browser re-uses the existing download, so when this happen, | ||||
441 | // pretend a new download was created. | ||||
442 | if (delta.state) { | ||||
443 | if (delta.state.previous === "interrupted" && delta.state.current === "in_progress") { | ||||
444 | console.log("Resuming previously interrupted download, pretending a new download was created"); | ||||
445 | chrome.downloads.search({ | ||||
446 | id: delta.id | ||||
447 | }, function (downloads) { | ||||
448 | createDownload(downloads[0]); | ||||
449 | }); | ||||
450 | return; | ||||
451 | } | ||||
452 | } | ||||
453 | | ||||
439 | var payload = {}; | 454 | var payload = {}; | ||
440 | 455 | | |||
441 | whitelistedDownloadProperties.forEach(function (item) { | 456 | whitelistedDownloadProperties.forEach(function (item) { | ||
442 | if (delta[item]) { | 457 | if (delta[item]) { | ||
443 | payload[item] = delta[item].current; | 458 | payload[item] = delta[item].current; | ||
444 | } | 459 | } | ||
445 | }); | 460 | }); | ||
446 | 461 | | |||
▲ Show 20 Lines • Show All 263 Lines • Show Last 20 Lines |