OLD | NEW |
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/active_downloads_ui.h" | 5 #include "chrome/browser/ui/webui/active_downloads_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
19 #include "base/string_piece.h" | 19 #include "base/string_piece.h" |
20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
21 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
22 #include "base/time.h" | 22 #include "base/time.h" |
23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
24 #include "base/values.h" | 24 #include "base/values.h" |
25 #include "chrome/browser/chromeos/cros/cros_library.h" | 25 #include "chrome/browser/chromeos/cros/cros_library.h" |
26 #include "chrome/browser/chromeos/media/media_player.h" | 26 #include "chrome/browser/chromeos/media/media_player.h" |
| 27 #include "chrome/browser/download/download_prefs.h" |
27 #include "chrome/browser/download/download_service.h" | 28 #include "chrome/browser/download/download_service.h" |
28 #include "chrome/browser/download/download_service_factory.h" | 29 #include "chrome/browser/download/download_service_factory.h" |
29 #include "chrome/browser/download/download_util.h" | 30 #include "chrome/browser/download/download_util.h" |
| 31 #include "chrome/browser/extensions/file_manager_util.h" |
30 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/browser/tabs/tab_strip_model.h" | 33 #include "chrome/browser/tabs/tab_strip_model.h" |
32 #include "chrome/browser/ui/browser.h" | 34 #include "chrome/browser/ui/browser.h" |
33 #include "chrome/browser/ui/browser_list.h" | 35 #include "chrome/browser/ui/browser_list.h" |
34 #include "chrome/browser/ui/browser_window.h" | 36 #include "chrome/browser/ui/browser_window.h" |
35 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 37 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
36 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 38 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
37 #include "chrome/browser/ui/webui/fileicon_source_chromeos.h" | 39 #include "chrome/browser/ui/webui/fileicon_source_chromeos.h" |
38 #include "chrome/common/chrome_paths.h" | 40 #include "chrome/common/chrome_paths.h" |
39 #include "chrome/common/chrome_switches.h" | 41 #include "chrome/common/chrome_switches.h" |
40 #include "chrome/common/url_constants.h" | 42 #include "chrome/common/url_constants.h" |
41 #include "content/browser/download/download_item.h" | 43 #include "content/browser/download/download_item.h" |
42 #include "content/browser/download/download_manager.h" | 44 #include "content/browser/download/download_manager.h" |
43 #include "content/browser/tab_contents/tab_contents.h" | 45 #include "content/browser/tab_contents/tab_contents.h" |
44 #include "grit/browser_resources.h" | 46 #include "grit/browser_resources.h" |
45 #include "grit/chromium_strings.h" | 47 #include "grit/chromium_strings.h" |
46 #include "grit/generated_resources.h" | 48 #include "grit/generated_resources.h" |
47 #include "grit/locale_settings.h" | 49 #include "grit/locale_settings.h" |
48 #include "net/base/escape.h" | 50 #include "net/base/escape.h" |
49 #include "net/url_request/url_request_file_job.h" | 51 #include "net/url_request/url_request_file_job.h" |
50 #include "ui/base/resource/resource_bundle.h" | 52 #include "ui/base/resource/resource_bundle.h" |
51 | 53 |
52 namespace { | 54 namespace { |
53 | 55 |
54 static const int kPopupLeft = 0; | 56 static const int kPopupLeft = 0; |
55 static const int kPopupTop = 0; | 57 static const int kPopupTop = 0; |
56 static const int kPopupWidth = 250; | 58 static const int kPopupWidth = 250; |
57 // Minimum height of window must be 100, so kPopupHeight has space for | 59 // Minimum height of window must be 100, so kPopupHeight has space for |
58 // 2 download rows of 36 px and 'Show All Downloads' which is 29px. | 60 // 2 download rows of 36 px and 'Show all files' link which is 29px. |
59 static const int kPopupHeight = 36 * 2 + 29; | 61 static const int kPopupHeight = 36 * 2 + 29; |
60 | 62 |
61 static const char kPropertyPath[] = "path"; | 63 static const char kPropertyPath[] = "path"; |
62 static const char kPropertyTitle[] = "title"; | 64 static const char kPropertyTitle[] = "title"; |
63 static const char kPropertyDirectory[] = "isDirectory"; | 65 static const char kPropertyDirectory[] = "isDirectory"; |
64 static const char kActiveDownloadAppName[] = "active-downloads"; | 66 static const char kActiveDownloadAppName[] = "active-downloads"; |
65 | 67 |
66 ChromeWebUIDataSource* CreateActiveDownloadsUIHTMLSource() { | 68 ChromeWebUIDataSource* CreateActiveDownloadsUIHTMLSource() { |
67 ChromeWebUIDataSource* source = | 69 ChromeWebUIDataSource* source = |
68 new ChromeWebUIDataSource(chrome::kChromeUIActiveDownloadsHost); | 70 new ChromeWebUIDataSource(chrome::kChromeUIActiveDownloadsHost); |
69 | 71 |
70 source->AddLocalizedString("dangerousfile", IDS_PROMPT_DANGEROUS_DOWNLOAD); | 72 source->AddLocalizedString("dangerousfile", IDS_PROMPT_DANGEROUS_DOWNLOAD); |
71 source->AddLocalizedString("dangerousextension", | 73 source->AddLocalizedString("dangerousextension", |
72 IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION); | 74 IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION); |
73 source->AddLocalizedString("dangerousurl", IDS_PROMPT_UNSAFE_DOWNLOAD_URL); | 75 source->AddLocalizedString("dangerousurl", IDS_PROMPT_UNSAFE_DOWNLOAD_URL); |
74 source->AddLocalizedString("cancel", IDS_DOWNLOAD_LINK_CANCEL); | 76 source->AddLocalizedString("cancel", IDS_DOWNLOAD_LINK_CANCEL); |
75 source->AddLocalizedString("discard", IDS_DISCARD_DOWNLOAD); | 77 source->AddLocalizedString("discard", IDS_DISCARD_DOWNLOAD); |
76 source->AddLocalizedString("continue", IDS_CONTINUE_EXTENSION_DOWNLOAD); | 78 source->AddLocalizedString("continue", IDS_CONTINUE_EXTENSION_DOWNLOAD); |
77 source->AddLocalizedString("pause", IDS_DOWNLOAD_LINK_PAUSE); | 79 source->AddLocalizedString("pause", IDS_DOWNLOAD_LINK_PAUSE); |
78 source->AddLocalizedString("resume", IDS_DOWNLOAD_LINK_RESUME); | 80 source->AddLocalizedString("resume", IDS_DOWNLOAD_LINK_RESUME); |
79 source->AddLocalizedString("showalldownloads", | 81 source->AddLocalizedString("showallfiles", |
80 IDS_FILEBROWSER_SHOW_ALL_DOWNLOADS); | 82 IDS_FILE_BROWSER_MORE_FILES); |
81 source->AddLocalizedString("error_unknown_file_type", | 83 source->AddLocalizedString("error_unknown_file_type", |
82 IDS_FILEBROWSER_ERROR_UNKNOWN_FILE_TYPE); | 84 IDS_FILEBROWSER_ERROR_UNKNOWN_FILE_TYPE); |
83 | 85 |
84 FilePath default_download_path; | 86 FilePath default_download_path; |
85 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, | 87 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, |
86 &default_download_path)) { | 88 &default_download_path)) { |
87 NOTREACHED(); | 89 NOTREACHED(); |
88 } | 90 } |
89 // TODO(viettrungluu): this is wrong -- FilePath's need not be Unicode. | 91 // TODO(viettrungluu): this is wrong -- FilePath's need not be Unicode. |
90 source->AddString("downloadpath", UTF8ToUTF16(default_download_path.value())); | 92 source->AddString("downloadpath", UTF8ToUTF16(default_download_path.value())); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // DownloadItem::Observer interface. | 124 // DownloadItem::Observer interface. |
123 virtual void OnDownloadUpdated(DownloadItem* item) OVERRIDE; | 125 virtual void OnDownloadUpdated(DownloadItem* item) OVERRIDE; |
124 virtual void OnDownloadOpened(DownloadItem* item) OVERRIDE { } | 126 virtual void OnDownloadOpened(DownloadItem* item) OVERRIDE { } |
125 | 127 |
126 // DownloadManager::Observer interface. | 128 // DownloadManager::Observer interface. |
127 virtual void ModelChanged() OVERRIDE; | 129 virtual void ModelChanged() OVERRIDE; |
128 | 130 |
129 // WebUI Callbacks. | 131 // WebUI Callbacks. |
130 void HandleGetDownloads(const ListValue* args); | 132 void HandleGetDownloads(const ListValue* args); |
131 void HandlePauseToggleDownload(const ListValue* args); | 133 void HandlePauseToggleDownload(const ListValue* args); |
| 134 void HandleAllowDownload(const ListValue* args); |
132 void HandleCancelDownload(const ListValue* args); | 135 void HandleCancelDownload(const ListValue* args); |
133 void HandleAllowDownload(const ListValue* args); | 136 void HandleShowAllFiles(const ListValue* args); |
134 void OpenNewFullWindow(const ListValue* args); | 137 void OpenNewFullWindow(const ListValue* args); |
135 void PlayMediaFile(const ListValue* args); | 138 void PlayMediaFile(const ListValue* args); |
136 | 139 |
137 // For testing. | 140 // For testing. |
138 typedef std::vector<DownloadItem*> DownloadList; | 141 typedef std::vector<DownloadItem*> DownloadList; |
139 const DownloadList& downloads() const { return downloads_; } | 142 const DownloadList& downloads() const { return downloads_; } |
140 | 143 |
141 private: | 144 private: |
142 // Downloads helpers. | 145 // Downloads helpers. |
143 DownloadItem* GetDownloadById(const ListValue* args); | 146 DownloadItem* GetDownloadById(const ListValue* args); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 download_manager_->AddObserver(this); | 185 download_manager_->AddObserver(this); |
183 } | 186 } |
184 | 187 |
185 void ActiveDownloadsHandler::RegisterMessages() { | 188 void ActiveDownloadsHandler::RegisterMessages() { |
186 web_ui_->RegisterMessageCallback("getDownloads", | 189 web_ui_->RegisterMessageCallback("getDownloads", |
187 base::Bind(&ActiveDownloadsHandler::HandleGetDownloads, | 190 base::Bind(&ActiveDownloadsHandler::HandleGetDownloads, |
188 base::Unretained(this))); | 191 base::Unretained(this))); |
189 web_ui_->RegisterMessageCallback("pauseToggleDownload", | 192 web_ui_->RegisterMessageCallback("pauseToggleDownload", |
190 base::Bind(&ActiveDownloadsHandler::HandlePauseToggleDownload, | 193 base::Bind(&ActiveDownloadsHandler::HandlePauseToggleDownload, |
191 base::Unretained(this))); | 194 base::Unretained(this))); |
| 195 web_ui_->RegisterMessageCallback("allowDownload", |
| 196 base::Bind(&ActiveDownloadsHandler::HandleAllowDownload, |
| 197 base::Unretained(this))); |
192 web_ui_->RegisterMessageCallback("cancelDownload", | 198 web_ui_->RegisterMessageCallback("cancelDownload", |
193 base::Bind(&ActiveDownloadsHandler::HandleCancelDownload, | 199 base::Bind(&ActiveDownloadsHandler::HandleCancelDownload, |
194 base::Unretained(this))); | 200 base::Unretained(this))); |
195 web_ui_->RegisterMessageCallback("allowDownload", | 201 web_ui_->RegisterMessageCallback("showAllFiles", |
196 base::Bind(&ActiveDownloadsHandler::HandleAllowDownload, | 202 base::Bind(&ActiveDownloadsHandler::HandleShowAllFiles, |
197 base::Unretained(this))); | 203 base::Unretained(this))); |
198 web_ui_->RegisterMessageCallback("openNewFullWindow", | 204 web_ui_->RegisterMessageCallback("openNewFullWindow", |
199 base::Bind(&ActiveDownloadsHandler::OpenNewFullWindow, | 205 base::Bind(&ActiveDownloadsHandler::OpenNewFullWindow, |
200 base::Unretained(this))); | 206 base::Unretained(this))); |
201 web_ui_->RegisterMessageCallback("playMediaFile", | 207 web_ui_->RegisterMessageCallback("playMediaFile", |
202 base::Bind(&ActiveDownloadsHandler::PlayMediaFile, | 208 base::Bind(&ActiveDownloadsHandler::PlayMediaFile, |
203 base::Unretained(this))); | 209 base::Unretained(this))); |
204 } | 210 } |
205 | 211 |
206 void ActiveDownloadsHandler::PlayMediaFile(const ListValue* args) { | 212 void ActiveDownloadsHandler::PlayMediaFile(const ListValue* args) { |
(...skipping 29 matching lines...) Expand all Loading... |
236 | 242 |
237 void ActiveDownloadsHandler::HandleCancelDownload(const ListValue* args) { | 243 void ActiveDownloadsHandler::HandleCancelDownload(const ListValue* args) { |
238 DownloadItem* item = GetDownloadById(args); | 244 DownloadItem* item = GetDownloadById(args); |
239 if (item) { | 245 if (item) { |
240 if (item->IsPartialDownload()) | 246 if (item->IsPartialDownload()) |
241 item->Cancel(true); | 247 item->Cancel(true); |
242 item->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 248 item->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
243 } | 249 } |
244 } | 250 } |
245 | 251 |
| 252 void ActiveDownloadsHandler::HandleShowAllFiles(const ListValue* args) { |
| 253 FileManagerUtil::ViewFolder( |
| 254 DownloadPrefs::FromDownloadManager(download_manager_)->download_path()); |
| 255 } |
| 256 |
246 bool ActiveDownloadsHandler::SelectTab(const GURL& url) { | 257 bool ActiveDownloadsHandler::SelectTab(const GURL& url) { |
247 for (TabContentsIterator it; !it.done(); ++it) { | 258 for (TabContentsIterator it; !it.done(); ++it) { |
248 TabContents* tab_contents = it->tab_contents(); | 259 TabContents* tab_contents = it->tab_contents(); |
249 if (tab_contents->GetURL() == url) { | 260 if (tab_contents->GetURL() == url) { |
250 static_cast<RenderViewHostDelegate*>(tab_contents)->Activate(); | 261 static_cast<RenderViewHostDelegate*>(tab_contents)->Activate(); |
251 return true; | 262 return true; |
252 } | 263 } |
253 } | 264 } |
254 return false; | 265 return false; |
255 } | 266 } |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 } | 439 } |
429 } | 440 } |
430 } | 441 } |
431 return NULL; | 442 return NULL; |
432 } | 443 } |
433 #endif // defined(TOUCH_UI) | 444 #endif // defined(TOUCH_UI) |
434 | 445 |
435 const ActiveDownloadsUI::DownloadList& ActiveDownloadsUI::GetDownloads() const { | 446 const ActiveDownloadsUI::DownloadList& ActiveDownloadsUI::GetDownloads() const { |
436 return handler_->downloads(); | 447 return handler_->downloads(); |
437 } | 448 } |
OLD | NEW |