| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/download/chrome_download_manager_delegate.h" | 5 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 } | 473 } |
| 474 | 474 |
| 475 void ChromeDownloadManagerDelegate::OpenDownload(DownloadItem* download) { | 475 void ChromeDownloadManagerDelegate::OpenDownload(DownloadItem* download) { |
| 476 DCHECK_EQ(DownloadItem::COMPLETE, download->GetState()); | 476 DCHECK_EQ(DownloadItem::COMPLETE, download->GetState()); |
| 477 DCHECK(!download->GetTargetFilePath().empty()); | 477 DCHECK(!download->GetTargetFilePath().empty()); |
| 478 if (!download->CanOpenDownload()) | 478 if (!download->CanOpenDownload()) |
| 479 return; | 479 return; |
| 480 | 480 |
| 481 if (!DownloadItemModel(download).ShouldPreferOpeningInBrowser()) { | 481 if (!DownloadItemModel(download).ShouldPreferOpeningInBrowser()) { |
| 482 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_DEFAULT_PLATFORM); | 482 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_DEFAULT_PLATFORM); |
| 483 DownloadItemModel(download).SetOpenedOrShown(true); |
| 483 OpenDownloadUsingPlatformHandler(download); | 484 OpenDownloadUsingPlatformHandler(download); |
| 484 return; | 485 return; |
| 485 } | 486 } |
| 486 | 487 |
| 487 #if !defined(OS_ANDROID) | 488 #if !defined(OS_ANDROID) |
| 488 content::WebContents* web_contents = download->GetWebContents(); | 489 content::WebContents* web_contents = download->GetWebContents(); |
| 489 Browser* browser = | 490 Browser* browser = |
| 490 web_contents ? chrome::FindBrowserWithWebContents(web_contents) : NULL; | 491 web_contents ? chrome::FindBrowserWithWebContents(web_contents) : NULL; |
| 491 std::unique_ptr<chrome::ScopedTabbedBrowserDisplayer> browser_displayer; | 492 std::unique_ptr<chrome::ScopedTabbedBrowserDisplayer> browser_displayer; |
| 492 if (!browser || | 493 if (!browser || |
| 493 !browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) { | 494 !browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) { |
| 494 browser_displayer.reset(new chrome::ScopedTabbedBrowserDisplayer(profile_)); | 495 browser_displayer.reset(new chrome::ScopedTabbedBrowserDisplayer(profile_)); |
| 495 browser = browser_displayer->browser(); | 496 browser = browser_displayer->browser(); |
| 496 } | 497 } |
| 497 content::OpenURLParams params( | 498 content::OpenURLParams params( |
| 498 net::FilePathToFileURL(download->GetTargetFilePath()), | 499 net::FilePathToFileURL(download->GetTargetFilePath()), |
| 499 content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, | 500 content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 500 ui::PAGE_TRANSITION_LINK, false); | 501 ui::PAGE_TRANSITION_LINK, false); |
| 501 | 502 |
| 502 if (download->GetMimeType() == "application/x-x509-user-cert") | 503 if (download->GetMimeType() == "application/x-x509-user-cert") |
| 503 chrome::ShowSettingsSubPage(browser, "certificates"); | 504 chrome::ShowSettingsSubPage(browser, "certificates"); |
| 504 else | 505 else |
| 505 browser->OpenURL(params); | 506 browser->OpenURL(params); |
| 506 | 507 |
| 507 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_DEFAULT_BROWSER); | 508 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_DEFAULT_BROWSER); |
| 509 DownloadItemModel(download).SetOpenedOrShown(true); |
| 508 #else | 510 #else |
| 509 // ShouldPreferOpeningInBrowser() should never be true on Android. | 511 // ShouldPreferOpeningInBrowser() should never be true on Android. |
| 510 NOTREACHED(); | 512 NOTREACHED(); |
| 511 #endif | 513 #endif |
| 512 } | 514 } |
| 513 | 515 |
| 514 void ChromeDownloadManagerDelegate::ShowDownloadInShell( | 516 void ChromeDownloadManagerDelegate::ShowDownloadInShell( |
| 515 DownloadItem* download) { | 517 DownloadItem* download) { |
| 516 if (!download->CanShowInFolder()) | 518 if (!download->CanShowInFolder()) |
| 517 return; | 519 return; |
| 518 base::FilePath platform_path( | 520 base::FilePath platform_path( |
| 519 GetPlatformDownloadPath(profile_, download, PLATFORM_CURRENT_PATH)); | 521 GetPlatformDownloadPath(profile_, download, PLATFORM_CURRENT_PATH)); |
| 520 DCHECK(!platform_path.empty()); | 522 DCHECK(!platform_path.empty()); |
| 523 DownloadItemModel(download).SetOpenedOrShown(true); |
| 521 platform_util::ShowItemInFolder(profile_, platform_path); | 524 platform_util::ShowItemInFolder(profile_, platform_path); |
| 522 } | 525 } |
| 523 | 526 |
| 524 void ChromeDownloadManagerDelegate::CheckForFileExistence( | 527 void ChromeDownloadManagerDelegate::CheckForFileExistence( |
| 525 DownloadItem* download, | 528 DownloadItem* download, |
| 526 const content::CheckForFileExistenceCallback& callback) { | 529 const content::CheckForFileExistenceCallback& callback) { |
| 527 #if defined(OS_CHROMEOS) | 530 #if defined(OS_CHROMEOS) |
| 528 drive::DownloadHandler* drive_download_handler = | 531 drive::DownloadHandler* drive_download_handler = |
| 529 drive::DownloadHandler::GetForProfile(profile_); | 532 drive::DownloadHandler::GetForProfile(profile_); |
| 530 if (drive_download_handler && | 533 if (drive_download_handler && |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || | 816 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || |
| 814 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || | 817 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || |
| 815 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || | 818 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || |
| 816 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || | 819 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || |
| 817 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { | 820 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { |
| 818 return true; | 821 return true; |
| 819 } | 822 } |
| 820 #endif | 823 #endif |
| 821 return false; | 824 return false; |
| 822 } | 825 } |
| OLD | NEW |