| 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/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 content::WebContents* web_contents = download->GetWebContents(); | 451 content::WebContents* web_contents = download->GetWebContents(); |
| 452 Browser* browser = | 452 Browser* browser = |
| 453 web_contents ? chrome::FindBrowserWithWebContents(web_contents) : NULL; | 453 web_contents ? chrome::FindBrowserWithWebContents(web_contents) : NULL; |
| 454 scoped_ptr<chrome::ScopedTabbedBrowserDisplayer> browser_displayer; | 454 scoped_ptr<chrome::ScopedTabbedBrowserDisplayer> browser_displayer; |
| 455 if (!browser || | 455 if (!browser || |
| 456 !browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) { | 456 !browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) { |
| 457 browser_displayer.reset(new chrome::ScopedTabbedBrowserDisplayer( | 457 browser_displayer.reset(new chrome::ScopedTabbedBrowserDisplayer( |
| 458 profile_, chrome::GetActiveDesktop())); | 458 profile_, chrome::GetActiveDesktop())); |
| 459 browser = browser_displayer->browser(); | 459 browser = browser_displayer->browser(); |
| 460 } | 460 } |
| 461 |
| 461 content::OpenURLParams params( | 462 content::OpenURLParams params( |
| 462 net::FilePathToFileURL(download->GetTargetFilePath()), | 463 net::FilePathToFileURL(download->GetTargetFilePath()), |
| 463 content::Referrer(), | 464 content::Referrer(), |
| 464 NEW_FOREGROUND_TAB, | 465 NEW_FOREGROUND_TAB, |
| 465 ui::PAGE_TRANSITION_LINK, | 466 ui::PAGE_TRANSITION_LINK, |
| 466 false); | 467 false); |
| 468 |
| 469 if (download->GetTargetFilePath().MatchesExtension( |
| 470 FILE_PATH_LITERAL(".crt"))) { |
| 471 params = content::OpenURLParams(GURL("chrome://settings/certificates"), |
| 472 content::Referrer(), NEW_FOREGROUND_TAB, |
| 473 ui::PAGE_TRANSITION_LINK, false); |
| 474 } |
| 475 |
| 467 browser->OpenURL(params); | 476 browser->OpenURL(params); |
| 468 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_DEFAULT_BROWSER); | 477 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_DEFAULT_BROWSER); |
| 469 #else | 478 #else |
| 470 // ShouldPreferOpeningInBrowser() should never be true on Android. | 479 // ShouldPreferOpeningInBrowser() should never be true on Android. |
| 471 NOTREACHED(); | 480 NOTREACHED(); |
| 472 #endif | 481 #endif |
| 473 } | 482 } |
| 474 | 483 |
| 475 void ChromeDownloadManagerDelegate::ShowDownloadInShell( | 484 void ChromeDownloadManagerDelegate::ShowDownloadInShell( |
| 476 DownloadItem* download) { | 485 DownloadItem* download) { |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 DownloadItemModel(item).SetIsDangerousFileBasedOnType(true); | 731 DownloadItemModel(item).SetIsDangerousFileBasedOnType(true); |
| 723 } | 732 } |
| 724 callback.Run(target_info->target_path, | 733 callback.Run(target_info->target_path, |
| 725 target_info->target_disposition, | 734 target_info->target_disposition, |
| 726 target_info->danger_type, | 735 target_info->danger_type, |
| 727 target_info->intermediate_path); | 736 target_info->intermediate_path); |
| 728 } | 737 } |
| 729 | 738 |
| 730 bool ChromeDownloadManagerDelegate::IsOpenInBrowserPreferreredForFile( | 739 bool ChromeDownloadManagerDelegate::IsOpenInBrowserPreferreredForFile( |
| 731 const base::FilePath& path) { | 740 const base::FilePath& path) { |
| 741 #if defined(OS_LINUX) || defined(OS_CHROMEOS) |
| 742 if (path.MatchesExtension(FILE_PATH_LITERAL(".crt"))) { |
| 743 return true; |
| 744 } |
| 745 #endif |
| 746 |
| 732 #if defined(OS_WIN) || defined(OS_LINUX) || \ | 747 #if defined(OS_WIN) || defined(OS_LINUX) || \ |
| 733 (defined(OS_MACOSX) && !defined(OS_IOS)) | 748 (defined(OS_MACOSX) && !defined(OS_IOS)) |
| 734 if (path.MatchesExtension(FILE_PATH_LITERAL(".pdf"))) { | 749 if (path.MatchesExtension(FILE_PATH_LITERAL(".pdf"))) { |
| 735 return !download_prefs_->ShouldOpenPdfInSystemReader(); | 750 return !download_prefs_->ShouldOpenPdfInSystemReader(); |
| 736 } | 751 } |
| 737 #endif | 752 #endif |
| 738 | 753 |
| 739 // On Android, always prefer opening with an external app. On ChromeOS, there | 754 // On Android, always prefer opening with an external app. On ChromeOS, there |
| 740 // are no external apps so just allow all opens to be handled by the "System." | 755 // are no external apps so just allow all opens to be handled by the "System." |
| 741 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && defined(ENABLE_PLUGINS) | 756 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && defined(ENABLE_PLUGINS) |
| 742 // TODO(asanka): Consider other file types and MIME types. | 757 // TODO(asanka): Consider other file types and MIME types. |
| 743 // http://crbug.com/323561 | 758 // http://crbug.com/323561 |
| 744 if (path.MatchesExtension(FILE_PATH_LITERAL(".pdf")) || | 759 if (path.MatchesExtension(FILE_PATH_LITERAL(".pdf")) || |
| 745 path.MatchesExtension(FILE_PATH_LITERAL(".htm")) || | 760 path.MatchesExtension(FILE_PATH_LITERAL(".htm")) || |
| 746 path.MatchesExtension(FILE_PATH_LITERAL(".html")) || | 761 path.MatchesExtension(FILE_PATH_LITERAL(".html")) || |
| 747 path.MatchesExtension(FILE_PATH_LITERAL(".shtm")) || | 762 path.MatchesExtension(FILE_PATH_LITERAL(".shtm")) || |
| 748 path.MatchesExtension(FILE_PATH_LITERAL(".shtml")) || | 763 path.MatchesExtension(FILE_PATH_LITERAL(".shtml")) || |
| 749 path.MatchesExtension(FILE_PATH_LITERAL(".svg")) || | 764 path.MatchesExtension(FILE_PATH_LITERAL(".svg")) || |
| 750 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || | 765 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || |
| 751 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || | 766 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || |
| 752 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || | 767 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || |
| 753 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || | 768 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || |
| 754 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { | 769 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { |
| 755 return true; | 770 return true; |
| 756 } | 771 } |
| 757 #endif | 772 #endif |
| 758 return false; | 773 return false; |
| 759 } | 774 } |
| OLD | NEW |