| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 177 |
| 178 #endif // FULL_SAFE_BROWSING | 178 #endif // FULL_SAFE_BROWSING |
| 179 | 179 |
| 180 // Called on the blocking pool to determine the MIME type for |path|. | 180 // Called on the blocking pool to determine the MIME type for |path|. |
| 181 std::string GetMimeType(const base::FilePath& path) { | 181 std::string GetMimeType(const base::FilePath& path) { |
| 182 std::string mime_type; | 182 std::string mime_type; |
| 183 net::GetMimeTypeFromFile(path, &mime_type); | 183 net::GetMimeTypeFromFile(path, &mime_type); |
| 184 return mime_type; | 184 return mime_type; |
| 185 } | 185 } |
| 186 | 186 |
| 187 bool IsOpenInBrowserPreferreredForFile(const base::FilePath& path) { | |
| 188 // On Android, always prefer opening with an external app. On ChromeOS, there | |
| 189 // are no external apps so just allow all opens to be handled by the "System." | |
| 190 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && defined(ENABLE_PLUGINS) | |
| 191 // TODO(asanka): Consider other file types and MIME types. | |
| 192 // http://crbug.com/323561 | |
| 193 if (path.MatchesExtension(FILE_PATH_LITERAL(".pdf")) || | |
| 194 path.MatchesExtension(FILE_PATH_LITERAL(".htm")) || | |
| 195 path.MatchesExtension(FILE_PATH_LITERAL(".html")) || | |
| 196 path.MatchesExtension(FILE_PATH_LITERAL(".shtm")) || | |
| 197 path.MatchesExtension(FILE_PATH_LITERAL(".shtml")) || | |
| 198 path.MatchesExtension(FILE_PATH_LITERAL(".svg")) || | |
| 199 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || | |
| 200 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || | |
| 201 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || | |
| 202 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || | |
| 203 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { | |
| 204 return true; | |
| 205 } | |
| 206 #endif | |
| 207 return false; | |
| 208 } | |
| 209 | |
| 210 } // namespace | 187 } // namespace |
| 211 | 188 |
| 212 ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) | 189 ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) |
| 213 : profile_(profile), | 190 : profile_(profile), |
| 214 next_download_id_(content::DownloadItem::kInvalidId), | 191 next_download_id_(content::DownloadItem::kInvalidId), |
| 215 download_prefs_(new DownloadPrefs(profile)), | 192 download_prefs_(new DownloadPrefs(profile)), |
| 216 weak_ptr_factory_(this) { | 193 weak_ptr_factory_(this) { |
| 217 } | 194 } |
| 218 | 195 |
| 219 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { | 196 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 DownloadItem* item = download_manager_->GetDownload(download_id); | 692 DownloadItem* item = download_manager_->GetDownload(download_id); |
| 716 if (!target_info->target_path.empty() && item && | 693 if (!target_info->target_path.empty() && item && |
| 717 IsOpenInBrowserPreferreredForFile(target_info->target_path) && | 694 IsOpenInBrowserPreferreredForFile(target_info->target_path) && |
| 718 target_info->is_filetype_handled_safely) | 695 target_info->is_filetype_handled_safely) |
| 719 DownloadItemModel(item).SetShouldPreferOpeningInBrowser(true); | 696 DownloadItemModel(item).SetShouldPreferOpeningInBrowser(true); |
| 720 callback.Run(target_info->target_path, | 697 callback.Run(target_info->target_path, |
| 721 target_info->target_disposition, | 698 target_info->target_disposition, |
| 722 target_info->danger_type, | 699 target_info->danger_type, |
| 723 target_info->intermediate_path); | 700 target_info->intermediate_path); |
| 724 } | 701 } |
| 702 |
| 703 bool ChromeDownloadManagerDelegate::IsOpenInBrowserPreferreredForFile( |
| 704 const base::FilePath& path) { |
| 705 // On Windows, PDFs should open in Acrobat Reader if the user chooses. |
| 706 #if defined(OS_WIN) |
| 707 if (path.MatchesExtension(FILE_PATH_LITERAL(".pdf")) && |
| 708 DownloadTargetDeterminer::IsAdobeReaderUpToDate()) { |
| 709 return !download_prefs_->ShouldOpenPdfInAdobeReader(); |
| 710 } |
| 711 #endif |
| 712 |
| 713 // On Android, always prefer opening with an external app. On ChromeOS, there |
| 714 // are no external apps so just allow all opens to be handled by the "System." |
| 715 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && defined(ENABLE_PLUGINS) |
| 716 // TODO(asanka): Consider other file types and MIME types. |
| 717 // http://crbug.com/323561 |
| 718 if (path.MatchesExtension(FILE_PATH_LITERAL(".pdf")) || |
| 719 path.MatchesExtension(FILE_PATH_LITERAL(".htm")) || |
| 720 path.MatchesExtension(FILE_PATH_LITERAL(".html")) || |
| 721 path.MatchesExtension(FILE_PATH_LITERAL(".shtm")) || |
| 722 path.MatchesExtension(FILE_PATH_LITERAL(".shtml")) || |
| 723 path.MatchesExtension(FILE_PATH_LITERAL(".svg")) || |
| 724 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || |
| 725 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || |
| 726 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || |
| 727 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || |
| 728 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { |
| 729 return true; |
| 730 } |
| 731 #endif |
| 732 return false; |
| 733 } |
| OLD | NEW |