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

Unified Diff: chrome/browser/resources/downloads/downloads.js

Issue 442133002: Typecheck chrome://downloads using CompilerPass.java (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@true_master
Patch Set: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/webui/downloads_dom_handler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/downloads/downloads.js
diff --git a/chrome/browser/resources/downloads/downloads.js b/chrome/browser/resources/downloads/downloads.js
index 40593b7e96bdf2860e9f04dfd2bbb795a2ecef76..311267a197b40828fe626dce24a6923c8aa835fe 100644
--- a/chrome/browser/resources/downloads/downloads.js
+++ b/chrome/browser/resources/downloads/downloads.js
@@ -5,6 +5,33 @@
// TODO(jhawkins): Use hidden instead of showInline* and display:none.
/**
+ * The type of the download object. The definition is based on
+ * chrome/browser/ui/webui/downloads_dom_handler.cc:CreateDownloadItemValue()
+ * @typedef {{by_ext_id: (string|undefined),
+ * by_ext_name: (string|undefined),
+ * danger_type: (string|undefined),
+ * date_string: string,
+ * file_externally_removed: boolean,
+ * file_name: string,
+ * file_path: string,
+ * file_url: string,
+ * id: string,
+ * last_reason_text: (string|undefined),
+ * otr: boolean,
+ * percent: (number|undefined),
+ * progress_status_text: (string|undefined),
+ * received: (number|undefined),
+ * resume: boolean,
+ * retry: boolean,
+ * since_string: string,
+ * started: number,
+ * state: string,
+ * total: number,
+ * url: string}}
+ */
+var BackendDownloadObject;
+
+/**
* Sets the display style of a node.
* @param {!Element} node The target element to show or hide.
* @param {boolean} isShow Should the target element be visible.
@@ -26,7 +53,7 @@ function showInlineBlock(node, isShow) {
* Creates a link with a specified onclick handler and content.
* @param {function()} onclick The onclick handler.
* @param {string} value The link text.
- * @return {Element} The created link element.
+ * @return {!Element} The created link element.
*/
function createLink(onclick, value) {
var link = document.createElement('a');
@@ -58,6 +85,10 @@ function createButton(onclick, value) {
* @constructor
*/
function Downloads() {
+ /**
+ * @type {!Object.<string, Download>}
+ * @private
+ */
this.downloads_ = {};
this.node_ = $('downloads-display');
this.summary_ = $('downloads-summary-text');
@@ -74,7 +105,7 @@ function Downloads() {
/**
* Called when a download has been updated or added.
- * @param {Object} download A backend download object (see downloads_ui.cc)
+ * @param {BackendDownloadObject} download A backend download object
*/
Downloads.prototype.updated = function(download) {
var id = download.id;
@@ -129,7 +160,7 @@ Downloads.prototype.updateSummary = function() {
/**
* Returns the number of downloads in the model. Used by tests.
- * @return {integer} Returns the number of downloads shown on the page.
+ * @return {number} Returns the number of downloads shown on the page.
*/
Downloads.prototype.size = function() {
return Object.keys(this.downloads_).length;
@@ -156,7 +187,7 @@ Downloads.prototype.updateDateDisplay_ = function() {
/**
* Remove a download.
- * @param {number} id The id of the download to remove.
+ * @param {string} id The id of the download to remove.
*/
Downloads.prototype.remove = function(id) {
this.node_.removeChild(this.downloads_[id].node);
@@ -233,7 +264,7 @@ Downloads.prototype.isUpdateNeeded = function(downloads) {
// Download
/**
* A download and the DOM representation for that download.
- * @param {Object} download A backend download object (see downloads_ui.cc)
+ * @param {BackendDownloadObject} download A backend download object
* @constructor
*/
function Download(download) {
@@ -387,6 +418,7 @@ function Download(download) {
/**
* The states a download can be in. These correspond to states defined in
* DownloadsDOMHandler::CreateDownloadItemValue
+ * @enum {string}
*/
Download.States = {
IN_PROGRESS: 'IN_PROGRESS',
@@ -399,6 +431,7 @@ Download.States = {
/**
* Explains why a download is in DANGEROUS state.
+ * @enum {string}
*/
Download.DangerType = {
NOT_DANGEROUS: 'NOT_DANGEROUS',
@@ -413,7 +446,7 @@ Download.DangerType = {
/**
* @param {number} a Some float.
* @param {number} b Some float.
- * @param {number} opt_pct Percent of min(a,b).
+ * @param {number=} opt_pct Percent of min(a,b).
* @return {boolean} true if a is within opt_pct percent of b.
*/
function floatEq(a, b, opt_pct) {
@@ -449,7 +482,8 @@ computeDownloadProgress();
// Listens for when device-pixel-ratio changes between any zoom level.
[0.3, 0.4, 0.6, 0.7, 0.8, 0.95, 1.05, 1.2, 1.4, 1.6, 1.9, 2.2, 2.7, 3.5, 4.5
].forEach(function(scale) {
- matchMedia('(-webkit-min-device-pixel-ratio:' + scale + ')').addListener(
+ window.matchMedia('(-webkit-min-device-pixel-ratio:' + scale + ')')
+ .addListener(
Dan Beam 2014/08/05 23:14:33 var media = '(-webkit-min-device-pixel-ratio:' + s
Vitaly Pavlenko 2014/08/06 00:28:53 Done.
function() {
computeDownloadProgress();
});
@@ -466,7 +500,7 @@ function getCachedImage(src) {
/**
* Updates the download to reflect new data.
- * @param {Object} download A backend download object (see downloads_ui.cc)
+ * @param {BackendDownloadObject} download A backend download object
*/
Download.prototype.update = function(download) {
this.id_ = download.id;
@@ -714,6 +748,9 @@ Download.prototype.getStatusText_ = function() {
case Download.States.COMPLETE:
return this.fileExternallyRemoved_ ?
loadTimeData.getString('status_removed') : '';
+ default:
+ assertNotReached();
+ return '';
}
Dan Beam 2014/08/05 23:14:33 nit: assertNotReached(); return ''; after th
Vitaly Pavlenko 2014/08/06 00:29:25 Done.
};
@@ -866,7 +903,7 @@ function load() {
};
$('term').onsearch = function(e) {
- setSearch(this.value);
+ setSearch($('term').value);
};
}
« no previous file with comments | « no previous file | chrome/browser/ui/webui/downloads_dom_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698