Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Commit

Permalink
Added a link to the downloads tab that opens the downloads folder.
Browse files Browse the repository at this point in the history
Contributed by fhd@ubercode.de

BUG=8915
TEST=chrome://downloads has a link labeled "Open downloads folder" that opens the configured downloads folder.


Review URL: http://codereview.chromium.org/7398026

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94493 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
fhd@ubercode.de committed Jul 28, 2011
1 parent 6585833 commit f6a4225
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -116,3 +116,4 @@ NVIDIA Corporation <*@nvidia.com>
Torsten Kurbad <google@tk-webart.de>
Max Perepelitsyn <pph34r@gmail.com>
Luke Zarko <lukezarko@gmail.com>
Felix H. Dahlke <fhd@ubercode.de>
4 changes: 4 additions & 0 deletions chrome/app/generated_resources.grd
Expand Up @@ -2313,6 +2313,10 @@ are declared in build/common.gypi.
desc="Clear all downloads link">
Clear all
</message>
<message name="IDS_DOWNLOAD_LINK_OPEN_DOWNLOADS_FOLDER"
desc="Open downloads folder link">
Open downloads folder
</message>

<!-- Download Context Menu Items -->
<if expr="not pp_ifdef('use_titlecase')">
Expand Down
18 changes: 15 additions & 3 deletions chrome/browser/resources/downloads.html
Expand Up @@ -43,14 +43,22 @@
font-weight: bold;
}

#downloads-summary > a {
#downloads-actions {
float: right;
}

html[dir=rtl] #downloads-summary > a {
html[dir=rtl] #downloads-actions {
float: left;
}

#downloads-actions > a {
margin-left: 10px;
}

#downloads-actions > a:first-child {
margin-left: 0;
}

#downloads-display {
max-width: 740px;
}
Expand Down Expand Up @@ -195,7 +203,11 @@
<div class="main">
<div id="downloads-summary">
<span id="downloads-summary-text" i18n-content="downloads">Downloads</span>
<a id="clear-all" href="" i18n-content="clear_all">Clear All</a>
<span id="downloads-actions">
<a id="open-downloads-folder" href=""
i18n-content="open_downloads_folder">Open downloads folder</a>
<a id="clear-all" href="" i18n-content="clear_all">Clear All</a>
</span>
</div>
<div id="downloads-display"></div>
</div>
Expand Down
11 changes: 10 additions & 1 deletion chrome/browser/resources/downloads.js
Expand Up @@ -575,6 +575,11 @@ function clearAll() {
return false;
}

function openDownloadsFolder() {
chrome.send('openDownloadsFolder');
return false;
}

///////////////////////////////////////////////////////////////////////////////
// Chrome callbacks:
/**
Expand Down Expand Up @@ -622,10 +627,15 @@ function tryDownloadUpdatedPeriodically() {

// Add handlers to HTML elements.
document.body.onload = load;

var clearAllLink = $('clear-all');
clearAllLink.onclick = function () { clearAll(''); };
clearAllLink.oncontextmenu = function() { return false; };

var openDownloadsFolderLink = $('open-downloads-folder');
openDownloadsFolderLink.onclick = openDownloadsFolder;
openDownloadsFolderLink.oncontextmenu = function() { return false; };

$('search-link').onclick = function () {
setSearch('');
return false;
Expand All @@ -634,4 +644,3 @@ $('search-form').onsubmit = function () {
setSearch(this.term.value);
return false;
};

17 changes: 17 additions & 0 deletions chrome/browser/ui/webui/downloads_dom_handler.cc
Expand Up @@ -17,7 +17,9 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/download_history.h"
#include "chrome/browser/download/download_item.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/download/download_util.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
#include "chrome/browser/ui/webui/fileicon_source.h"
Expand Down Expand Up @@ -97,6 +99,8 @@ void DownloadsDOMHandler::RegisterMessages() {
NewCallback(this, &DownloadsDOMHandler::HandleCancel));
web_ui_->RegisterMessageCallback("clearAll",
NewCallback(this, &DownloadsDOMHandler::HandleClearAll));
web_ui_->RegisterMessageCallback("openDownloadsFolder",
NewCallback(this, &DownloadsDOMHandler::HandleOpenDownloadsFolder));
}

void DownloadsDOMHandler::OnDownloadUpdated(DownloadItem* download) {
Expand Down Expand Up @@ -227,6 +231,19 @@ void DownloadsDOMHandler::HandleClearAll(const ListValue* args) {
download_manager_->RemoveAllDownloads();
}

void DownloadsDOMHandler::HandleOpenDownloadsFolder(const ListValue* args) {
FilePath path = download_manager_->download_prefs()->download_path();

#if defined(OS_MACOSX)
// Must be called from the UI thread on Mac.
platform_util::OpenItem(path);
#else
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
NewRunnableFunction(&platform_util::OpenItem, path));
#endif
}

// DownloadsDOMHandler, private: ----------------------------------------------

void DownloadsDOMHandler::SendCurrentDownloads() {
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/ui/webui/downloads_dom_handler.h
Expand Up @@ -71,6 +71,10 @@ class DownloadsDOMHandler : public WebUIMessageHandler,
// Callback for the "clearAll" message - clears all the downloads.
void HandleClearAll(const base::ListValue* args);

// Callback for the "openDownloadsFolder" message - opens the downloads
// folder.
void HandleOpenDownloadsFolder(const base::ListValue* args);

private:
// Send the current list of downloads to the page.
void SendCurrentDownloads();
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/ui/webui/downloads_ui.cc
Expand Up @@ -36,6 +36,8 @@ ChromeWebUIDataSource *CreateDownloadsUIHTMLSource() {
source->AddLocalizedString("searchresultsfor", IDS_DOWNLOAD_SEARCHRESULTSFOR);
source->AddLocalizedString("downloads", IDS_DOWNLOAD_TITLE);
source->AddLocalizedString("clear_all", IDS_DOWNLOAD_LINK_CLEAR_ALL);
source->AddLocalizedString("open_downloads_folder",
IDS_DOWNLOAD_LINK_OPEN_DOWNLOADS_FOLDER);

// Status.
source->AddLocalizedString("status_cancelled", IDS_DOWNLOAD_TAB_CANCELED);
Expand Down

0 comments on commit f6a4225

Please sign in to comment.