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 |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 handler_(new ActiveDownloadsHandler()) { | 362 handler_(new ActiveDownloadsHandler()) { |
363 AddMessageHandler(handler_->Attach(this)); | 363 AddMessageHandler(handler_->Attach(this)); |
364 handler_->Init(); | 364 handler_->Init(); |
365 | 365 |
366 // Set up the chrome://active-downloads/ source. | 366 // Set up the chrome://active-downloads/ source. |
367 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | 367 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
368 profile->GetChromeURLDataManager()->AddDataSource( | 368 profile->GetChromeURLDataManager()->AddDataSource( |
369 CreateActiveDownloadsUIHTMLSource()); | 369 CreateActiveDownloadsUIHTMLSource()); |
370 } | 370 } |
371 | 371 |
372 #if defined(TOUCH_UI) | |
373 | |
374 // static | |
375 TabContents* ActiveDownloadsUI::OpenPopup(Profile* profile) { | |
376 Browser* browser = Browser::GetOrCreateTabbedBrowser(profile); | |
377 OpenURLParams params(GURL(chrome::kChromeUIActiveDownloadsURL), GURL(), | |
378 SINGLETON_TAB, content::PAGE_TRANSITION_LINK, false); | |
379 TabContents* download_contents = browser->OpenURL(params); | |
380 browser->window()->Show(); | |
381 return download_contents; | |
382 } | |
383 | |
384 TabContents* ActiveDownloadsUI::GetPopup(Browser** browser) { | |
385 for (TabContentsIterator it; !it.done(); ++it) { | |
386 TabContents* tab = it->tab_contents(); | |
387 const GURL& url = tab->GetURL(); | |
388 if (url.SchemeIs(chrome::kChromeUIScheme) && | |
389 url.host() == chrome::kChromeUIActiveDownloadsHost) { | |
390 if (browser) | |
391 *browser = it.browser(); | |
392 return tab; | |
393 } | |
394 } | |
395 return NULL; | |
396 } | |
397 | |
398 #else // defined(TOUCH_UI) | |
399 // static | 372 // static |
400 Browser* ActiveDownloadsUI::OpenPopup(Profile* profile) { | 373 Browser* ActiveDownloadsUI::OpenPopup(Profile* profile) { |
401 Browser* browser = GetPopup(); | 374 Browser* browser = GetPopup(); |
402 | 375 |
403 // Create new browser if no matching pop up is found. | 376 // Create new browser if no matching pop up is found. |
404 if (browser == NULL) { | 377 if (browser == NULL) { |
405 browser = Browser::CreateForApp(Browser::TYPE_PANEL, kActiveDownloadAppName, | 378 browser = Browser::CreateForApp(Browser::TYPE_PANEL, kActiveDownloadAppName, |
406 gfx::Rect(), profile); | 379 gfx::Rect(), profile); |
407 | 380 |
408 browser::NavigateParams params( | 381 browser::NavigateParams params( |
(...skipping 27 matching lines...) Expand all Loading... |
436 const GURL& url = tab_contents->GetURL(); | 409 const GURL& url = tab_contents->GetURL(); |
437 | 410 |
438 if (url.SchemeIs(chrome::kChromeUIScheme) && | 411 if (url.SchemeIs(chrome::kChromeUIScheme) && |
439 url.host() == chrome::kChromeUIActiveDownloadsHost) { | 412 url.host() == chrome::kChromeUIActiveDownloadsHost) { |
440 return (*it); | 413 return (*it); |
441 } | 414 } |
442 } | 415 } |
443 } | 416 } |
444 return NULL; | 417 return NULL; |
445 } | 418 } |
446 #endif // defined(TOUCH_UI) | |
447 | 419 |
448 const ActiveDownloadsUI::DownloadList& ActiveDownloadsUI::GetDownloads() const { | 420 const ActiveDownloadsUI::DownloadList& ActiveDownloadsUI::GetDownloads() const { |
449 return handler_->downloads(); | 421 return handler_->downloads(); |
450 } | 422 } |
OLD | NEW |