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

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

Issue 6969057: Support for re-using open tabs (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
(...skipping 13 matching lines...) Expand all
24 #include "chrome/browser/chromeos/cros/cros_library.h" 24 #include "chrome/browser/chromeos/cros/cros_library.h"
25 #include "chrome/browser/chromeos/login/user_manager.h" 25 #include "chrome/browser/chromeos/login/user_manager.h"
26 #include "chrome/browser/download/download_item.h" 26 #include "chrome/browser/download/download_item.h"
27 #include "chrome/browser/download/download_manager.h" 27 #include "chrome/browser/download/download_manager.h"
28 #include "chrome/browser/download/download_util.h" 28 #include "chrome/browser/download/download_util.h"
29 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/tabs/tab_strip_model.h" 30 #include "chrome/browser/tabs/tab_strip_model.h"
31 #include "chrome/browser/ui/browser.h" 31 #include "chrome/browser/ui/browser.h"
32 #include "chrome/browser/ui/browser_list.h" 32 #include "chrome/browser/ui/browser_list.h"
33 #include "chrome/browser/ui/browser_window.h" 33 #include "chrome/browser/ui/browser_window.h"
34 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
34 #include "chrome/browser/ui/webui/favicon_source.h" 35 #include "chrome/browser/ui/webui/favicon_source.h"
35 #include "chrome/browser/ui/webui/mediaplayer_ui.h" 36 #include "chrome/browser/ui/webui/mediaplayer_ui.h"
36 #include "chrome/common/chrome_paths.h" 37 #include "chrome/common/chrome_paths.h"
37 #include "chrome/common/chrome_switches.h" 38 #include "chrome/common/chrome_switches.h"
38 #include "chrome/common/jstemplate_builder.h" 39 #include "chrome/common/jstemplate_builder.h"
39 #include "chrome/common/net/url_fetcher.h" 40 #include "chrome/common/net/url_fetcher.h"
40 #include "chrome/common/url_constants.h" 41 #include "chrome/common/url_constants.h"
41 #include "content/browser/browser_thread.h" 42 #include "content/browser/browser_thread.h"
42 #include "content/browser/tab_contents/tab_contents.h" 43 #include "content/browser/tab_contents/tab_contents.h"
43 #include "grit/browser_resources.h" 44 #include "grit/browser_resources.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 virtual void OnDownloadOpened(DownloadItem* item) { } 104 virtual void OnDownloadOpened(DownloadItem* item) { }
104 105
105 // DownloadManager::Observer interface. 106 // DownloadManager::Observer interface.
106 virtual void ModelChanged(); 107 virtual void ModelChanged();
107 108
108 // WebUI Callbacks. 109 // WebUI Callbacks.
109 void HandleGetDownloads(const ListValue* args); 110 void HandleGetDownloads(const ListValue* args);
110 void HandlePauseToggleDownload(const ListValue* args); 111 void HandlePauseToggleDownload(const ListValue* args);
111 void HandleCancelDownload(const ListValue* args); 112 void HandleCancelDownload(const ListValue* args);
112 void HandleAllowDownload(const ListValue* args); 113 void HandleAllowDownload(const ListValue* args);
113 void OpenNewPopupWindow(const ListValue* args);
114 void OpenNewFullWindow(const ListValue* args); 114 void OpenNewFullWindow(const ListValue* args);
115 void PlayMediaFile(const ListValue* args); 115 void PlayMediaFile(const ListValue* args);
116 116
117 private: 117 private:
118 // Downloads helpers. 118 // Downloads helpers.
119 DownloadItem* GetDownloadById(const ListValue* args); 119 DownloadItem* GetDownloadById(const ListValue* args);
120 void UpdateDownloadList(); 120 void UpdateDownloadList();
121 void SendDownloads(); 121 void SendDownloads();
122 void AddDownload(DownloadItem* item); 122 void AddDownload(DownloadItem* item);
123 123 bool SelectTab(const GURL& url);
124 void OpenNewWindow(const ListValue* args, bool popup);
125 124
126 Profile* profile_; 125 Profile* profile_;
127 TabContents* tab_contents_; 126 TabContents* tab_contents_;
128 DownloadManager* download_manager_; 127 DownloadManager* download_manager_;
129 128
130 typedef std::vector<DownloadItem*> DownloadList; 129 typedef std::vector<DownloadItem*> DownloadList;
131 DownloadList active_downloads_; 130 DownloadList active_downloads_;
132 DownloadList downloads_; 131 DownloadList downloads_;
133 132
134 DISALLOW_COPY_AND_ASSIGN(ActiveDownloadsHandler); 133 DISALLOW_COPY_AND_ASSIGN(ActiveDownloadsHandler);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 222
224 void ActiveDownloadsHandler::RegisterMessages() { 223 void ActiveDownloadsHandler::RegisterMessages() {
225 web_ui_->RegisterMessageCallback("getDownloads", 224 web_ui_->RegisterMessageCallback("getDownloads",
226 NewCallback(this, &ActiveDownloadsHandler::HandleGetDownloads)); 225 NewCallback(this, &ActiveDownloadsHandler::HandleGetDownloads));
227 web_ui_->RegisterMessageCallback("pauseToggleDownload", 226 web_ui_->RegisterMessageCallback("pauseToggleDownload",
228 NewCallback(this, &ActiveDownloadsHandler::HandlePauseToggleDownload)); 227 NewCallback(this, &ActiveDownloadsHandler::HandlePauseToggleDownload));
229 web_ui_->RegisterMessageCallback("cancelDownload", 228 web_ui_->RegisterMessageCallback("cancelDownload",
230 NewCallback(this, &ActiveDownloadsHandler::HandleCancelDownload)); 229 NewCallback(this, &ActiveDownloadsHandler::HandleCancelDownload));
231 web_ui_->RegisterMessageCallback("allowDownload", 230 web_ui_->RegisterMessageCallback("allowDownload",
232 NewCallback(this, &ActiveDownloadsHandler::HandleAllowDownload)); 231 NewCallback(this, &ActiveDownloadsHandler::HandleAllowDownload));
233 web_ui_->RegisterMessageCallback("openNewPopupWindow",
234 NewCallback(this, &ActiveDownloadsHandler::OpenNewPopupWindow));
235 web_ui_->RegisterMessageCallback("openNewFullWindow", 232 web_ui_->RegisterMessageCallback("openNewFullWindow",
236 NewCallback(this, &ActiveDownloadsHandler::OpenNewFullWindow)); 233 NewCallback(this, &ActiveDownloadsHandler::OpenNewFullWindow));
237 web_ui_->RegisterMessageCallback("playMediaFile", 234 web_ui_->RegisterMessageCallback("playMediaFile",
238 NewCallback(this, &ActiveDownloadsHandler::PlayMediaFile)); 235 NewCallback(this, &ActiveDownloadsHandler::PlayMediaFile));
239 } 236 }
240 237
241 void ActiveDownloadsHandler::PlayMediaFile(const ListValue* args) { 238 void ActiveDownloadsHandler::PlayMediaFile(const ListValue* args) {
242 FilePath file_path(UTF16ToUTF8(ExtractStringValue(args))); 239 FilePath file_path(UTF16ToUTF8(ExtractStringValue(args)));
243 240
244 Browser* browser = Browser::GetBrowserForController( 241 Browser* browser = Browser::GetBrowserForController(
(...skipping 25 matching lines...) Expand all
270 267
271 void ActiveDownloadsHandler::HandleCancelDownload(const ListValue* args) { 268 void ActiveDownloadsHandler::HandleCancelDownload(const ListValue* args) {
272 DownloadItem* item = GetDownloadById(args); 269 DownloadItem* item = GetDownloadById(args);
273 if (item) { 270 if (item) {
274 if (item->IsPartialDownload()) 271 if (item->IsPartialDownload())
275 item->Cancel(true); 272 item->Cancel(true);
276 item->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); 273 item->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
277 } 274 }
278 } 275 }
279 276
280 void ActiveDownloadsHandler::OpenNewFullWindow(const ListValue* args) { 277 bool ActiveDownloadsHandler::SelectTab(const GURL& url) {
281 OpenNewWindow(args, false); 278 for (TabContentsIterator it; !it.done(); ++it) {
279 TabContents* tab_contents = it->tab_contents();
280 if (tab_contents->GetURL() == url) {
281 tab_contents->Activate();
282 return true;
283 }
284 }
285 return false;
282 } 286 }
283 287
284 void ActiveDownloadsHandler::OpenNewPopupWindow(const ListValue* args) { 288 void ActiveDownloadsHandler::OpenNewFullWindow(const ListValue* args) {
285 OpenNewWindow(args, true); 289 std::string url = UTF16ToUTF8(ExtractStringValue(args));
286 }
287 290
288 void ActiveDownloadsHandler::OpenNewWindow(const ListValue* args, bool popup) { 291 if (SelectTab(GURL(url)))
289 std::string url = UTF16ToUTF8(ExtractStringValue(args)); 292 return;
290 Browser* browser = popup ? 293
291 Browser::CreateForApp(Browser::TYPE_PANEL, kActiveDownloadAppName, 294 Browser* browser = BrowserList::GetLastActive();
292 gfx::Size(), profile_) :
293 BrowserList::GetLastActive();
294 browser::NavigateParams params(browser, GURL(url), PageTransition::LINK); 295 browser::NavigateParams params(browser, GURL(url), PageTransition::LINK);
295 params.disposition = NEW_FOREGROUND_TAB; 296 params.disposition = NEW_FOREGROUND_TAB;
296 browser::Navigate(&params); 297 browser::Navigate(&params);
297 // TODO(beng): The following two calls should be automatic by Navigate(). 298 browser->window()->Show();
298 if (popup)
299 params.browser->window()->SetBounds(gfx::Rect(0, 0, 400, 300));
300 params.browser->window()->Show();
301 } 299 }
302 300
303 void ActiveDownloadsHandler::ModelChanged() { 301 void ActiveDownloadsHandler::ModelChanged() {
304 UpdateDownloadList(); 302 UpdateDownloadList();
305 } 303 }
306 304
307 void ActiveDownloadsHandler::HandleGetDownloads(const ListValue* args) { 305 void ActiveDownloadsHandler::HandleGetDownloads(const ListValue* args) {
308 UpdateDownloadList(); 306 UpdateDownloadList();
309 } 307 }
310 308
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 browser = Browser::CreateForApp(Browser::TYPE_PANEL, kActiveDownloadAppName, 394 browser = Browser::CreateForApp(Browser::TYPE_PANEL, kActiveDownloadAppName,
397 gfx::Size(), profile); 395 gfx::Size(), profile);
398 396
399 browser::NavigateParams params( 397 browser::NavigateParams params(
400 browser, 398 browser,
401 GURL(chrome::kChromeUIActiveDownloadsURL), 399 GURL(chrome::kChromeUIActiveDownloadsURL),
402 PageTransition::LINK); 400 PageTransition::LINK);
403 params.disposition = NEW_FOREGROUND_TAB; 401 params.disposition = NEW_FOREGROUND_TAB;
404 browser::Navigate(&params); 402 browser::Navigate(&params);
405 403
404 DCHECK_EQ(browser, params.browser);
406 // TODO(beng): The following two calls should be automatic by Navigate(). 405 // TODO(beng): The following two calls should be automatic by Navigate().
407 params.browser->window()->SetBounds(gfx::Rect(kPopupLeft, 406 browser->window()->SetBounds(gfx::Rect(kPopupLeft,
408 kPopupTop, 407 kPopupTop,
409 kPopupWidth, 408 kPopupWidth,
410 kPopupHeight)); 409 kPopupHeight));
411 params.browser->window()->Show();
412 } else {
413 browser->window()->Show();
414 } 410 }
415 411
412 browser->window()->Show();
416 return browser; 413 return browser;
417 } 414 }
418 415
419 Browser* ActiveDownloadsUI::GetPopup(Profile* profile) { 416 Browser* ActiveDownloadsUI::GetPopup(Profile* profile) {
420 for (BrowserList::const_iterator it = BrowserList::begin(); 417 for (BrowserList::const_iterator it = BrowserList::begin();
421 it != BrowserList::end(); 418 it != BrowserList::end();
422 ++it) { 419 ++it) {
423 if ((*it)->is_type_panel() && (*it)->is_app()) { 420 if ((*it)->is_type_panel() && (*it)->is_app()) {
424 TabContents* tab_contents = (*it)->GetSelectedTabContents(); 421 TabContents* tab_contents = (*it)->GetSelectedTabContents();
425 DCHECK(tab_contents); 422 DCHECK(tab_contents);
426 if (!tab_contents) 423 if (!tab_contents)
427 continue; 424 continue;
428 const GURL& url = tab_contents->GetURL(); 425 const GURL& url = tab_contents->GetURL();
429 426
430 if (url.SchemeIs(chrome::kChromeUIScheme) && 427 if (url.SchemeIs(chrome::kChromeUIScheme) &&
431 url.host() == chrome::kChromeUIActiveDownloadsHost && 428 url.host() == chrome::kChromeUIActiveDownloadsHost &&
432 (*it)->profile() == profile) { 429 (*it)->profile() == profile) {
433 return (*it); 430 return (*it);
434 } 431 }
435 } 432 }
436 } 433 }
437 return NULL; 434 return NULL;
438 } 435 }
439 436
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698