summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-04 04:07:23 +0000
committerglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-04 04:07:23 +0000
commit05ea0a37ff80d8dc71d795d5c08fb5dee0cd9bfb (patch)
treec4b3cacf61a17bcc98810c18dea1612580cb347e /chrome/browser
parent8d2b6c3e969cdbb83b0cf23493e527869ff25e9e (diff)
downloadchromium_src-05ea0a37ff80d8dc71d795d5c08fb5dee0cd9bfb.zip
chromium_src-05ea0a37ff80d8dc71d795d5c08fb5dee0cd9bfb.tar.gz
chromium_src-05ea0a37ff80d8dc71d795d5c08fb5dee0cd9bfb.tar.bz2
* Make the download page focus the input field onload.* Fix spacing between controls (Pause/Cancel).* Help deblock download UI creation (timeout in downloads.html, kMaxDownloads in downloads_ui.cc)* Allow resume for paused downloads
BUG=8271,8270,8130,8330 Review URL: http://codereview.chromium.org/40047 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10863 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/dom_ui/downloads_ui.cc28
-rw-r--r--chrome/browser/resources/downloads.html46
2 files changed, 56 insertions, 18 deletions
diff --git a/chrome/browser/dom_ui/downloads_ui.cc b/chrome/browser/dom_ui/downloads_ui.cc
index e801434..c7cdcd7 100644
--- a/chrome/browser/dom_ui/downloads_ui.cc
+++ b/chrome/browser/dom_ui/downloads_ui.cc
@@ -25,6 +25,10 @@ using base::Time;
// DownloadsUI is accessible from chrome-ui://downloads.
static const char kDownloadsHost[] = "downloads";
+// Maximum number of downloads to show. TODO(glen): Remove this and instead
+// stuff the downloads down the pipe slowly.
+static const int kMaxDownloads = 150;
+
///////////////////////////////////////////////////////////////////////////////
//
// DownloadsHTMLSource
@@ -73,6 +77,10 @@ void DownloadsUIHTMLSource::StartDataRequest(const std::string& path,
localized_strings.SetString(L"control_resume",
l10n_util::GetString(IDS_DOWNLOAD_LINK_RESUME));
+ localized_strings.SetString(L"textdirection",
+ (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
+ L"rtl" : L"ltr");
+
static const StringPiece downloads_html(
ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_DOWNLOADS_HTML));
@@ -98,7 +106,7 @@ class DownloadItemSorter : public std::binary_function<DownloadItem*,
bool> {
public:
bool operator()(const DownloadItem* lhs, const DownloadItem* rhs) {
- return lhs->start_time() < rhs->start_time();
+ return lhs->start_time() > rhs->start_time();
}
};
@@ -120,7 +128,9 @@ DownloadsDOMHandler::DownloadsDOMHandler(DOMUI* dom_ui, DownloadManager* dlm)
NewCallback(this, &DownloadsDOMHandler::HandleDiscardDangerous));
dom_ui_->RegisterMessageCallback("show",
NewCallback(this, &DownloadsDOMHandler::HandleShow));
- dom_ui_->RegisterMessageCallback("pause",
+ dom_ui_->RegisterMessageCallback("togglepause",
+ NewCallback(this, &DownloadsDOMHandler::HandlePause));
+ dom_ui_->RegisterMessageCallback("resume",
NewCallback(this, &DownloadsDOMHandler::HandlePause));
dom_ui_->RegisterMessageCallback("cancel",
NewCallback(this, &DownloadsDOMHandler::HandleCancel));
@@ -179,6 +189,9 @@ void DownloadsDOMHandler::SetDownloads(
// Scan for any in progress downloads and add ourself to them as an observer.
for (OrderedDownloads::iterator it = download_items_.begin();
it != download_items_.end(); ++it) {
+ if (static_cast<int>(it - download_items_.begin()) > kMaxDownloads)
+ break;
+
DownloadItem* download = *it;
if (download->state() == DownloadItem::IN_PROGRESS) {
// We want to know what happens as the download progresses.
@@ -253,11 +266,12 @@ void DownloadsDOMHandler::HandleCancel(const Value* value) {
void DownloadsDOMHandler::SendCurrentDownloads() {
ListValue results_value;
-
for (OrderedDownloads::iterator it = download_items_.begin();
- it != download_items_.end(); ++it) {
- results_value.Append(CreateDownloadItemValue(*it,
- static_cast<int>(it - download_items_.begin())));
+ it != download_items_.end(); ++it) {
+ int index = static_cast<int>(it - download_items_.begin());
+ if (index > kMaxDownloads)
+ break;
+ results_value.Append(CreateDownloadItemValue(*it,index));
}
dom_ui_->CallJavascriptFunction(L"downloadsList", results_value);
@@ -267,7 +281,7 @@ DictionaryValue* DownloadsDOMHandler::CreateDownloadItemValue(
DownloadItem* download, int id) {
DictionaryValue* file_value = new DictionaryValue();
- file_value->SetInteger(L"time",
+ file_value->SetInteger(L"started",
static_cast<int>(download->start_time().ToTimeT()));
file_value->SetInteger(L"id", id);
file_value->SetString(L"file_path", download->full_path().ToWStringHack());
diff --git a/chrome/browser/resources/downloads.html b/chrome/browser/resources/downloads.html
index 5c38db8..9fa94f1 100644
--- a/chrome/browser/resources/downloads.html
+++ b/chrome/browser/resources/downloads.html
@@ -1,5 +1,5 @@
<!DOCTYPE HTML>
-<html id="t">
+<html id="t" jsvalues="dir:textdirection;">
<head>
<meta charset="utf-8">
<title jscontent="title"></title>
@@ -65,6 +65,7 @@ body {
}
.controls a {
color:#777;
+ margin-right:16px;
}
#downloads-pagination {
padding-top:24px;
@@ -187,6 +188,10 @@ function Downloads() {
this.node_ = $('downloads-display');
this.summary_ = $('downloads-summary');
this.searchText_ = "";
+
+ // Keep track of the dates of the newest and oldest downloads so that we
+ // know where to insert them.
+ this.newestTime_ = -1;
}
/**
@@ -200,9 +205,15 @@ Downloads.prototype.updated = function(download) {
} else {
this.downloads_[id] = new Download(download);
// We get downloads in display order, so we don't have to worry about
- // maintaining correct order for now.
- this.node_.insertBefore(this.downloads_[id].node,
- this.node_.firstChild);
+ // maintaining correct order - we can assume that any downloads not in
+ // display order are new ones and so we can add them to the top of the
+ // list.
+ if (download.started > this.newestTime_) {
+ this.node_.insertBefore(this.downloads_[id].node, this.node_.firstChild);
+ this.newestTime_ = download.started;
+ } else {
+ this.node_.appendChild(this.downloads_[id].node);
+ }
}
}
@@ -300,10 +311,15 @@ function Download(download) {
localStrings.getString('control_showinfolder'));
this.nodeControls_.appendChild(this.controlShow_);
- this.controlPause_ = createLink(bind(this.pause_, this),
+ // Pause/Resume are a toggle.
+ this.controlPause_ = createLink(bind(this.togglePause_, this),
localStrings.getString('control_pause'));
this.nodeControls_.appendChild(this.controlPause_);
+ this.controlResume_ = createLink(bind(this.togglePause_, this),
+ localStrings.getString('control_resume'));
+ this.nodeControls_.appendChild(this.controlResume_);
+
this.controlCancel_ = createLink(bind(this.cancel_, this),
localStrings.getString('control_cancel'));
this.nodeControls_.appendChild(this.controlCancel_);
@@ -373,6 +389,7 @@ Download.prototype.update = function(download) {
showInline(this.controlShow_, this.state_ == Download.States.COMPLETE);
showInline(this.controlPause_, this.state_ == Download.States.IN_PROGRESS);
+ showInline(this.controlResume_, this.state_ == Download.States.PAUSED);
showInline(this.controlCancel_, this.state_ == Download.States.IN_PROGRESS);
this.nodeURL_.innerHTML = this.url_;
@@ -392,6 +409,7 @@ Download.prototype.clear = function() {
this.controlShow_.onclick = null;
this.controlCancel_.onclick = null;
this.controlPause_.onclick = null;
+ this.controlResume_.onclick = null;
this.dangerDiscard_.onclick = null;
this.node.innerHTML = '';
@@ -462,8 +480,8 @@ Download.prototype.show_ = function() {
/**
* Tells the backend to pause this download.
*/
-Download.prototype.pause_ = function() {
- chrome.send("pause", [this.id_.toString()]);
+Download.prototype.togglePause_ = function() {
+ chrome.send("togglepause", [this.id_.toString()]);
return false;
}
@@ -477,11 +495,12 @@ Download.prototype.cancel_ = function() {
///////////////////////////////////////////////////////////////////////////////
// Page:
-var downloads, localStrings;
+var downloads, localStrings, resultsTimeout;
function load() {
localStrings = new LocalStrings($('l10n'));
downloads = new Downloads();
+ $('term').focus();
setSearch("");
}
@@ -498,16 +517,21 @@ function setSearch(searchText) {
* downloads are added or removed.
*/
function downloadsList(results) {
+ if (resultsTimeout)
+ clearTimeout(resultsTimeout);
downloadUpdated(results);
- downloads.updateSummary();
}
/**
* When a download is updated (progress, state change), this is called.
*/
function downloadUpdated(results) {
- for (var i = 0, thisResult; thisResult = results[i]; i++) {
- downloads.updated(thisResult);
+ if (results.length) {
+ downloads.updated(results[0]);
+ if (results.length > 1)
+ resultsTimeout = setTimeout(downloadUpdated, 5, results.slice(1));
+ else
+ downloads.updateSummary();
}
}
</script>