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

Side by Side Diff: chrome/browser/ui/webui/downloads_dom_handler.cc

Issue 7398026: Added a link to the downloads tab that opens the downloads folder. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed the issues discovered during review. Created 9 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/downloads_dom_handler.h" 5 #include "chrome/browser/ui/webui/downloads_dom_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
13 #include "base/string_piece.h" 13 #include "base/string_piece.h"
14 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/download/download_history.h" 18 #include "chrome/browser/download/download_history.h"
19 #include "chrome/browser/download/download_item.h" 19 #include "chrome/browser/download/download_item.h"
20 #include "chrome/browser/download/download_util.h" 20 #include "chrome/browser/download/download_util.h"
21 #include "chrome/browser/download/download_prefs.h"
asanka 2011/07/19 18:58:00 download_prefs.h should go before download_util.h
22 #include "chrome/browser/platform_util.h"
21 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 24 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
23 #include "chrome/browser/ui/webui/fileicon_source.h" 25 #include "chrome/browser/ui/webui/fileicon_source.h"
24 #include "chrome/browser/ui/webui/fileicon_source_cros.h" 26 #include "chrome/browser/ui/webui/fileicon_source_cros.h"
25 #include "chrome/common/jstemplate_builder.h" 27 #include "chrome/common/jstemplate_builder.h"
28 #include "chrome/common/pref_names.h"
asanka 2011/07/19 18:58:00 Do you need this anymore?
26 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
27 #include "content/browser/browser_thread.h" 30 #include "content/browser/browser_thread.h"
28 #include "content/browser/tab_contents/tab_contents.h" 31 #include "content/browser/tab_contents/tab_contents.h"
29 #include "content/browser/user_metrics.h" 32 #include "content/browser/user_metrics.h"
30 #include "grit/generated_resources.h" 33 #include "grit/generated_resources.h"
31 #include "ui/gfx/image/image.h" 34 #include "ui/gfx/image/image.h"
32 35
33 namespace { 36 namespace {
34 37
35 // Maximum number of downloads to show. TODO(glen): Remove this and instead 38 // Maximum number of downloads to show. TODO(glen): Remove this and instead
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 web_ui_->RegisterMessageCallback("togglepause", 93 web_ui_->RegisterMessageCallback("togglepause",
91 NewCallback(this, &DownloadsDOMHandler::HandlePause)); 94 NewCallback(this, &DownloadsDOMHandler::HandlePause));
92 web_ui_->RegisterMessageCallback("resume", 95 web_ui_->RegisterMessageCallback("resume",
93 NewCallback(this, &DownloadsDOMHandler::HandlePause)); 96 NewCallback(this, &DownloadsDOMHandler::HandlePause));
94 web_ui_->RegisterMessageCallback("remove", 97 web_ui_->RegisterMessageCallback("remove",
95 NewCallback(this, &DownloadsDOMHandler::HandleRemove)); 98 NewCallback(this, &DownloadsDOMHandler::HandleRemove));
96 web_ui_->RegisterMessageCallback("cancel", 99 web_ui_->RegisterMessageCallback("cancel",
97 NewCallback(this, &DownloadsDOMHandler::HandleCancel)); 100 NewCallback(this, &DownloadsDOMHandler::HandleCancel));
98 web_ui_->RegisterMessageCallback("clearAll", 101 web_ui_->RegisterMessageCallback("clearAll",
99 NewCallback(this, &DownloadsDOMHandler::HandleClearAll)); 102 NewCallback(this, &DownloadsDOMHandler::HandleClearAll));
103 web_ui_->RegisterMessageCallback("openDownloadsFolder",
104 NewCallback(this, &DownloadsDOMHandler::HandleOpenDownloadsFolder));
100 } 105 }
101 106
102 void DownloadsDOMHandler::OnDownloadUpdated(DownloadItem* download) { 107 void DownloadsDOMHandler::OnDownloadUpdated(DownloadItem* download) {
103 // Get the id for the download. Our downloads are sorted latest to first, 108 // Get the id for the download. Our downloads are sorted latest to first,
104 // and the id is the index into that list. We should be careful of sync 109 // and the id is the index into that list. We should be careful of sync
105 // errors between the UI and the download_items_ list (we may wish to use 110 // errors between the UI and the download_items_ list (we may wish to use
106 // something other than 'id'). 111 // something other than 'id').
107 OrderedDownloads::iterator it = find(download_items_.begin(), 112 OrderedDownloads::iterator it = find(download_items_.begin(),
108 download_items_.end(), 113 download_items_.end(),
109 download); 114 download);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 void DownloadsDOMHandler::HandleCancel(const ListValue* args) { 225 void DownloadsDOMHandler::HandleCancel(const ListValue* args) {
221 DownloadItem* file = GetDownloadByValue(args); 226 DownloadItem* file = GetDownloadByValue(args);
222 if (file) 227 if (file)
223 file->Cancel(true); 228 file->Cancel(true);
224 } 229 }
225 230
226 void DownloadsDOMHandler::HandleClearAll(const ListValue* args) { 231 void DownloadsDOMHandler::HandleClearAll(const ListValue* args) {
227 download_manager_->RemoveAllDownloads(); 232 download_manager_->RemoveAllDownloads();
228 } 233 }
229 234
235 void DownloadsDOMHandler::HandleOpenDownloadsFolder(const ListValue* args) {
236 FilePath path = download_manager_->download_prefs()->download_path();
237
238 #if defined(OS_MACOSX)
239 // Must be called from the UI thread on Mac.
240 platform_util::OpenItem(path);
241 #else
242 BrowserThread::PostTask(
243 BrowserThread::FILE, FROM_HERE,
244 NewRunnableFunction(&platform_util::OpenItem, path));
245 #endif
246 }
247
230 // DownloadsDOMHandler, private: ---------------------------------------------- 248 // DownloadsDOMHandler, private: ----------------------------------------------
231 249
232 void DownloadsDOMHandler::SendCurrentDownloads() { 250 void DownloadsDOMHandler::SendCurrentDownloads() {
233 ListValue results_value; 251 ListValue results_value;
234 for (OrderedDownloads::iterator it = download_items_.begin(); 252 for (OrderedDownloads::iterator it = download_items_.begin();
235 it != download_items_.end(); ++it) { 253 it != download_items_.end(); ++it) {
236 int index = static_cast<int>(it - download_items_.begin()); 254 int index = static_cast<int>(it - download_items_.begin());
237 if (index > kMaxDownloads) 255 if (index > kMaxDownloads)
238 break; 256 break;
239 if (!*it) 257 if (!*it)
(...skipping 26 matching lines...) Expand all
266 return NULL; 284 return NULL;
267 } 285 }
268 286
269 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) { 287 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const ListValue* args) {
270 int id; 288 int id;
271 if (ExtractIntegerValue(args, &id)) { 289 if (ExtractIntegerValue(args, &id)) {
272 return GetDownloadById(id); 290 return GetDownloadById(id);
273 } 291 }
274 return NULL; 292 return NULL;
275 } 293 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698