diff options
-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"> |