Changeset View
Changeset View
Standalone View
Standalone View
extension/extension.js
Show First 20 Lines • Show All 419 Lines • ▼ Show 20 Line(s) | 408 | chrome.downloads.onCreated.addListener(function (download) { | |||
---|---|---|---|---|---|
420 | port.postMessage({subsystem: "downloads", event: "created", download: filteredDownload}); | 420 | port.postMessage({subsystem: "downloads", event: "created", download: filteredDownload}); | ||
421 | }); | 421 | }); | ||
422 | 422 | | |||
423 | chrome.downloads.onChanged.addListener(function (delta) { | 423 | chrome.downloads.onChanged.addListener(function (delta) { | ||
424 | if (activeDownloads.indexOf(delta.id) === -1) { | 424 | if (activeDownloads.indexOf(delta.id) === -1) { | ||
425 | return; | 425 | return; | ||
426 | } | 426 | } | ||
427 | 427 | | |||
428 | // An interrupted download was resumed. When a download is interrupted, we finish (and delete) | ||||
429 | // the job but the browser re-uses the existing download, so when this happen, | ||||
430 | // pretend a new download was created. | ||||
431 | if (delta.state) { | ||||
432 | if (delta.state.previous === "interrupted" && delta.state.current === "in_progress") { | ||||
433 | console.log("Resuming previously interrupted download, pretending a new download was created"); | ||||
434 | chrome.downloads.search({ | ||||
435 | id: delta.id | ||||
436 | }, function (downloads) { | ||||
437 | createDownload(downloads[0]); | ||||
438 | }); | ||||
439 | return; | ||||
440 | } | ||||
441 | } | ||||
442 | | ||||
428 | var payload = {}; | 443 | var payload = {}; | ||
429 | 444 | | |||
430 | whitelistedDownloadProperties.forEach(function (item) { | 445 | whitelistedDownloadProperties.forEach(function (item) { | ||
431 | if (delta[item]) { | 446 | if (delta[item]) { | ||
432 | payload[item] = delta[item].current; | 447 | payload[item] = delta[item].current; | ||
433 | } | 448 | } | ||
434 | }); | 449 | }); | ||
435 | 450 | | |||
▲ Show 20 Lines • Show All 262 Lines • Show Last 20 Lines |