diff options
author | arv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-07 21:21:12 +0000 |
---|---|---|
committer | arv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-07 21:21:12 +0000 |
commit | d41355e6f0576dc372a6047ffc8e6f0fdea0129d (patch) | |
tree | 559d0200951e69c1b904edeafd45f5edb53844c5 | |
parent | b4abd1f1c5973ba9877f6617549d72c1fde74595 (diff) | |
download | chromium_src-d41355e6f0576dc372a6047ffc8e6f0fdea0129d.zip chromium_src-d41355e6f0576dc372a6047ffc8e6f0fdea0129d.tar.gz chromium_src-d41355e6f0576dc372a6047ffc8e6f0fdea0129d.tar.bz2 |
Cloned from 62030
Add a "Clear All" link to the downloads page.
Fixes jankiness of the blue bar in the download page as it loads.
Improve rendering time of the downloads page by chunking the number of
download items to do before scheduling the timeout.
BUG=9033
Review URL: http://codereview.chromium.org/62115
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13285 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/generated_resources.grd | 4 | ||||
-rw-r--r-- | chrome/browser/dom_ui/downloads_ui.cc | 20 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.cc | 7 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.h | 6 | ||||
-rw-r--r-- | chrome/browser/resources/downloads.html | 45 |
5 files changed, 63 insertions, 19 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 9613e4551..394a5c0 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -1311,6 +1311,10 @@ each locale. --> desc="Indicate the download is in progress but paused"> Paused </message> + <message name="IDS_DOWNLOAD_LINK_CLEAR_ALL" + desc="Clear all downloads link"> + Clear All + </message> <!-- Download Context Menu Items --> <message name="IDS_DOWNLOAD_MENU_COPY_PATH" diff --git a/chrome/browser/dom_ui/downloads_ui.cc b/chrome/browser/dom_ui/downloads_ui.cc index 3e52879..ddd3ee2 100644 --- a/chrome/browser/dom_ui/downloads_ui.cc +++ b/chrome/browser/dom_ui/downloads_ui.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -64,11 +64,13 @@ void DownloadsUIHTMLSource::StartDataRequest(const std::string& path, localized_strings.SetString(L"searchbutton", l10n_util::GetString(IDS_DOWNLOAD_SEARCH_BUTTON)); localized_strings.SetString(L"no_results", - l10n_util::GetString(IDS_DOWNLOAD_SEARCH_BUTTON)); + l10n_util::GetString(IDS_DOWNLOAD_SEARCH_BUTTON)); localized_strings.SetString(L"searchresultsfor", - l10n_util::GetString(IDS_DOWNLOAD_SEARCHRESULTSFOR)); + l10n_util::GetString(IDS_DOWNLOAD_SEARCHRESULTSFOR)); localized_strings.SetString(L"downloads", - l10n_util::GetString(IDS_DOWNLOAD_TITLE)); + l10n_util::GetString(IDS_DOWNLOAD_TITLE)); + localized_strings.SetString(L"clear_all", + l10n_util::GetString(IDS_DOWNLOAD_LINK_CLEAR_ALL)); // Status. localized_strings.SetString(L"status_cancelled", @@ -160,6 +162,9 @@ class DownloadsDOMHandler : public DOMMessageHandler, // Callback for the "cancel" message - cancels the download. void HandleCancel(const Value* value); + // Callback for the "clearAll" message - clears all the downloads. + void HandleClearAll(const Value* value); + private: // Send the current list of downloads to the page. void SendCurrentDownloads(); @@ -229,6 +234,9 @@ DownloadsDOMHandler::DownloadsDOMHandler(DOMUI* dom_ui, DownloadManager* dlm) NewCallback(this, &DownloadsDOMHandler::HandlePause)); dom_ui_->RegisterMessageCallback("cancel", NewCallback(this, &DownloadsDOMHandler::HandleCancel)); + dom_ui_->RegisterMessageCallback("clearAll", + NewCallback(this, &DownloadsDOMHandler::HandleClearAll)); + // Create our fileicon data source. g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, @@ -357,6 +365,10 @@ void DownloadsDOMHandler::HandleCancel(const Value* value) { file->Cancel(true); } +void DownloadsDOMHandler::HandleClearAll(const Value* value) { + download_manager_->RemoveAllDownloads(); +} + // DownloadsDOMHandler, private: ---------------------------------------------- void DownloadsDOMHandler::SendCurrentDownloads() { diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc index 04c6aeb..8d65eba 100644 --- a/chrome/browser/download/download_manager.cc +++ b/chrome/browser/download/download_manager.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -1083,6 +1083,11 @@ int DownloadManager::RemoveDownloads(const base::Time remove_begin) { return RemoveDownloadsBetween(remove_begin, base::Time()); } +int DownloadManager::RemoveAllDownloads() { + // The null times make the date range unbounded. + return RemoveDownloadsBetween(base::Time(), base::Time()); +} + // Initiate a download of a specific URL. We send the request to the // ResourceDispatcherHost, and let it send us responses like a regular // download. diff --git a/chrome/browser/download/download_manager.h b/chrome/browser/download/download_manager.h index 5f73b22..378f2b4 100644 --- a/chrome/browser/download/download_manager.h +++ b/chrome/browser/download/download_manager.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -355,6 +355,10 @@ class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>, // deleted is returned back to the caller. int RemoveDownloads(const base::Time remove_begin); + // Remove all downloads will delete all downloads. The number of downloads + // deleted is returned back to the caller. + int RemoveAllDownloads(); + // Download the object at the URL. Used in cases such as "Save Link As..." void DownloadUrl(const GURL& url, const GURL& referrer, diff --git a/chrome/browser/resources/downloads.html b/chrome/browser/resources/downloads.html index 6d85f3b..6f1a545 100644 --- a/chrome/browser/resources/downloads.html +++ b/chrome/browser/resources/downloads.html @@ -32,10 +32,18 @@ html[dir='rtl'] .form { margin-top:12px; border-top:1px solid #9cc2ef; background-color:#ebeff9; - font-weight:bold; padding:3px; margin-bottom:6px; } +#downloads-summary-text { + font-weight:bold; +} +#downloads-summary > a { + float:right; +} +html[dir='rtl'] #downloads-summary > a { + float:left; +} #downloads-display { max-width:740px; } @@ -111,7 +119,7 @@ html[dir='rtl'] .name { } .download .url { color:#080; - width:500px; + max-width:500px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; @@ -239,7 +247,7 @@ function createButton(onclick, value) { function Downloads() { this.downloads_ = {}; this.node_ = $('downloads-display'); - this.summary_ = $('downloads-summary'); + this.summary_ = $('downloads-summary-text'); this.searchText_ = ""; // Keep track of the dates of the newest and oldest downloads so that we @@ -648,8 +656,7 @@ var downloads, localStrings, resultsTimeout; function load() { localStrings = new LocalStrings($('l10n')); - Download.Progress.dir = - !!(document.getElementsByTagName('html')[0].dir == 'rtl'); + Download.Progress.dir = document.documentElement.dir == 'rtl'; downloads = new Downloads(); $('term').focus(); setSearch(""); @@ -661,6 +668,13 @@ function setSearch(searchText) { chrome.send("getDownloads", [searchText.toString()]); } +function clearAll() { + downloads.clear(); + downloads.setSearchText(''); + chrome.send('clearAll', []); + return false; +} + /////////////////////////////////////////////////////////////////////////////// // Chrome callbacks: /** @@ -673,6 +687,7 @@ function downloadsList(results) { window.console.log('results'); downloads.clear(); downloadUpdated(results); + downloads.updateSummary(); } /** @@ -683,17 +698,18 @@ function downloadUpdated(results) { if (!downloads) return; - if (results.length) { - downloads.updated(results[0]); - - if (results.length > 1) { + var start = Date.now(); + for (var i = 0; i < results.length; i++) { + downloads.updated(results[i]); + // Do as much as we can in 50ms. + if (Date.now() - start > 50) { clearTimeout(resultsTimeout); - resultsTimeout = setTimeout(downloadUpdated, 5, results.slice(1)); - } else { - downloads.updateSummary(); + resultsTimeout = setTimeout(downloadUpdated, 5, results.slice(i + 1)); + break; } } } + </script> </head> <body onload="load();" jsvalues=".style.fontFamily:fontfamily;.style.fontSize:fontsize"> @@ -709,7 +725,10 @@ function downloadUpdated(results) { </form> </div> <div class="main"> - <div id="downloads-summary"></div> + <div id="downloads-summary"> + <span id="downloads-summary-text" jscontent="downloads">Downloads</span> + <a id="clear-all" href="" onclick="clearAll();" jscontent="clear_all">Clear All</a> + </div> <div id="downloads-display"></div> </div> <div class="footer"> |