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/chrome_download_manager_delegate.h" |
27 #include "chrome/browser/download/download_prefs.h" | 28 #include "chrome/browser/download/download_prefs.h" |
28 #include "chrome/browser/download/download_service.h" | 29 #include "chrome/browser/download/download_service.h" |
29 #include "chrome/browser/download/download_service_factory.h" | 30 #include "chrome/browser/download/download_service_factory.h" |
30 #include "chrome/browser/download/download_util.h" | 31 #include "chrome/browser/download/download_util.h" |
| 32 #include "chrome/browser/extensions/extension_service.h" |
31 #include "chrome/browser/extensions/file_manager_util.h" | 33 #include "chrome/browser/extensions/file_manager_util.h" |
32 #include "chrome/browser/profiles/profile.h" | 34 #include "chrome/browser/profiles/profile.h" |
33 #include "chrome/browser/tabs/tab_strip_model.h" | 35 #include "chrome/browser/tabs/tab_strip_model.h" |
34 #include "chrome/browser/ui/browser.h" | 36 #include "chrome/browser/ui/browser.h" |
35 #include "chrome/browser/ui/browser_list.h" | 37 #include "chrome/browser/ui/browser_list.h" |
36 #include "chrome/browser/ui/browser_window.h" | 38 #include "chrome/browser/ui/browser_window.h" |
37 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 39 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
38 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 40 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
39 #include "chrome/browser/ui/webui/fileicon_source_chromeos.h" | 41 #include "chrome/browser/ui/webui/fileicon_source_chromeos.h" |
40 #include "chrome/common/chrome_paths.h" | 42 #include "chrome/common/chrome_paths.h" |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 AddMessageHandler(handler_->Attach(this)); | 365 AddMessageHandler(handler_->Attach(this)); |
364 handler_->Init(); | 366 handler_->Init(); |
365 | 367 |
366 // Set up the chrome://active-downloads/ source. | 368 // Set up the chrome://active-downloads/ source. |
367 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | 369 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
368 profile->GetChromeURLDataManager()->AddDataSource( | 370 profile->GetChromeURLDataManager()->AddDataSource( |
369 CreateActiveDownloadsUIHTMLSource()); | 371 CreateActiveDownloadsUIHTMLSource()); |
370 } | 372 } |
371 | 373 |
372 // static | 374 // static |
| 375 bool ActiveDownloadsUI::ShouldShowPopup(Profile* profile, |
| 376 DownloadItem* download) { |
| 377 // Don't show downloads panel for extension/theme downloads from gallery, |
| 378 // or temporary downloads. |
| 379 ExtensionService* service = profile->GetExtensionService(); |
| 380 return !download->IsTemporary() && |
| 381 (!ChromeDownloadManagerDelegate::IsExtensionDownload(download) || |
| 382 service == NULL || |
| 383 !service->IsDownloadFromGallery(download->GetURL(), |
| 384 download->GetReferrerUrl())); |
| 385 } |
| 386 |
| 387 // static |
373 Browser* ActiveDownloadsUI::OpenPopup(Profile* profile) { | 388 Browser* ActiveDownloadsUI::OpenPopup(Profile* profile) { |
374 Browser* browser = GetPopup(); | 389 Browser* browser = GetPopup(); |
375 | 390 |
376 // Create new browser if no matching pop up is found. | 391 // Create new browser if no matching pop up is found. |
377 if (browser == NULL) { | 392 if (browser == NULL) { |
378 browser = Browser::CreateForApp(Browser::TYPE_PANEL, kActiveDownloadAppName, | 393 browser = Browser::CreateForApp(Browser::TYPE_PANEL, kActiveDownloadAppName, |
379 gfx::Rect(), profile); | 394 gfx::Rect(), profile); |
380 | 395 |
381 browser::NavigateParams params( | 396 browser::NavigateParams params( |
382 browser, | 397 browser, |
383 GURL(chrome::kChromeUIActiveDownloadsURL), | 398 GURL(chrome::kChromeUIActiveDownloadsURL), |
384 content::PAGE_TRANSITION_LINK); | 399 content::PAGE_TRANSITION_LINK); |
385 params.disposition = NEW_FOREGROUND_TAB; | 400 params.disposition = NEW_FOREGROUND_TAB; |
386 browser::Navigate(¶ms); | 401 browser::Navigate(¶ms); |
387 | 402 |
388 DCHECK_EQ(browser, params.browser); | 403 DCHECK_EQ(browser, params.browser); |
389 // TODO(beng): The following two calls should be automatic by Navigate(). | 404 // TODO(beng): The following two calls should be automatic by Navigate(). |
390 browser->window()->SetBounds(gfx::Rect(kPopupLeft, | 405 browser->window()->SetBounds(gfx::Rect(kPopupLeft, |
391 kPopupTop, | 406 kPopupTop, |
392 kPopupWidth, | 407 kPopupWidth, |
393 kPopupHeight)); | 408 kPopupHeight)); |
394 } | 409 } |
395 | 410 |
396 browser->window()->Show(); | 411 browser->window()->Show(); |
397 return browser; | 412 return browser; |
398 } | 413 } |
399 | 414 |
| 415 // static |
400 Browser* ActiveDownloadsUI::GetPopup() { | 416 Browser* ActiveDownloadsUI::GetPopup() { |
401 for (BrowserList::const_iterator it = BrowserList::begin(); | 417 for (BrowserList::const_iterator it = BrowserList::begin(); |
402 it != BrowserList::end(); | 418 it != BrowserList::end(); |
403 ++it) { | 419 ++it) { |
404 if ((*it)->is_type_panel() && (*it)->is_app()) { | 420 if ((*it)->is_type_panel() && (*it)->is_app()) { |
405 TabContents* tab_contents = (*it)->GetSelectedTabContents(); | 421 TabContents* tab_contents = (*it)->GetSelectedTabContents(); |
406 DCHECK(tab_contents); | 422 DCHECK(tab_contents); |
407 if (!tab_contents) | 423 if (!tab_contents) |
408 continue; | 424 continue; |
409 const GURL& url = tab_contents->GetURL(); | 425 const GURL& url = tab_contents->GetURL(); |
410 | 426 |
411 if (url.SchemeIs(chrome::kChromeUIScheme) && | 427 if (url.SchemeIs(chrome::kChromeUIScheme) && |
412 url.host() == chrome::kChromeUIActiveDownloadsHost) { | 428 url.host() == chrome::kChromeUIActiveDownloadsHost) { |
413 return (*it); | 429 return (*it); |
414 } | 430 } |
415 } | 431 } |
416 } | 432 } |
417 return NULL; | 433 return NULL; |
418 } | 434 } |
419 | 435 |
420 const ActiveDownloadsUI::DownloadList& ActiveDownloadsUI::GetDownloads() const { | 436 const ActiveDownloadsUI::DownloadList& ActiveDownloadsUI::GetDownloads() const { |
421 return handler_->downloads(); | 437 return handler_->downloads(); |
422 } | 438 } |
OLD | NEW |