| 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/download_prefs.h" | 5 #include "chrome/browser/download/download_prefs.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 131 |
| 132 // Ensure that the default download directory exists. | 132 // Ensure that the default download directory exists. |
| 133 BrowserThread::PostTask( | 133 BrowserThread::PostTask( |
| 134 BrowserThread::FILE, FROM_HERE, | 134 BrowserThread::FILE, FROM_HERE, |
| 135 base::Bind(base::IgnoreResult(&base::CreateDirectory), | 135 base::Bind(base::IgnoreResult(&base::CreateDirectory), |
| 136 GetDefaultDownloadDirectoryForProfile())); | 136 GetDefaultDownloadDirectoryForProfile())); |
| 137 #endif // defined(OS_CHROMEOS) | 137 #endif // defined(OS_CHROMEOS) |
| 138 | 138 |
| 139 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) | 139 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) |
| 140 should_open_pdf_in_system_reader_ = | 140 should_open_pdf_in_system_reader_ = |
| 141 prefs->GetBoolean(prefs::kOpenPdfDownloadInSystemReader); | 141 prefs->GetBoolean(prefs::kOpenPdfDownloadInSystemReader) || |
| 142 prefs->GetBoolean(prefs::kPluginsAlwaysOpenPdfExternally); |
| 143 disable_adobe_version_check_for_tests_ = false; |
| 142 #endif | 144 #endif |
| 143 | 145 |
| 144 // If the download path is dangerous we forcefully reset it. But if we do | 146 // If the download path is dangerous we forcefully reset it. But if we do |
| 145 // so we set a flag to make sure we only do it once, to avoid fighting | 147 // so we set a flag to make sure we only do it once, to avoid fighting |
| 146 // the user if he really wants it on an unsafe place such as the desktop. | 148 // the user if he really wants it on an unsafe place such as the desktop. |
| 147 if (!prefs->GetBoolean(prefs::kDownloadDirUpgraded)) { | 149 if (!prefs->GetBoolean(prefs::kDownloadDirUpgraded)) { |
| 148 base::FilePath current_download_dir = prefs->GetFilePath( | 150 base::FilePath current_download_dir = prefs->GetFilePath( |
| 149 prefs::kDownloadDefaultDirectory); | 151 prefs::kDownloadDefaultDirectory); |
| 150 if (DownloadPathIsDangerous(current_download_dir)) { | 152 if (DownloadPathIsDangerous(current_download_dir)) { |
| 151 prefs->SetFilePath(prefs::kDownloadDefaultDirectory, | 153 prefs->SetFilePath(prefs::kDownloadDefaultDirectory, |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 if (extension.empty()) | 335 if (extension.empty()) |
| 334 return; | 336 return; |
| 335 DCHECK(extension[0] == base::FilePath::kExtensionSeparator); | 337 DCHECK(extension[0] == base::FilePath::kExtensionSeparator); |
| 336 extension.erase(0, 1); | 338 extension.erase(0, 1); |
| 337 auto_open_.erase(extension); | 339 auto_open_.erase(extension); |
| 338 SaveAutoOpenState(); | 340 SaveAutoOpenState(); |
| 339 } | 341 } |
| 340 | 342 |
| 341 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) | 343 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) |
| 342 void DownloadPrefs::SetShouldOpenPdfInSystemReader(bool should_open) { | 344 void DownloadPrefs::SetShouldOpenPdfInSystemReader(bool should_open) { |
| 343 if (should_open_pdf_in_system_reader_ == should_open) | 345 should_open_pdf_in_system_reader_ = should_open || |
| 344 return; | 346 profile_->GetPrefs()->GetBoolean(prefs::kPluginsAlwaysOpenPdfExternally); |
| 345 should_open_pdf_in_system_reader_ = should_open; | |
| 346 profile_->GetPrefs()->SetBoolean(prefs::kOpenPdfDownloadInSystemReader, | 347 profile_->GetPrefs()->SetBoolean(prefs::kOpenPdfDownloadInSystemReader, |
| 347 should_open); | 348 should_open); |
| 348 } | 349 } |
| 349 | 350 |
| 350 bool DownloadPrefs::ShouldOpenPdfInSystemReader() const { | 351 bool DownloadPrefs::ShouldOpenPdfInSystemReader() const { |
| 351 #if defined(OS_WIN) | 352 #if defined(OS_WIN) |
| 352 if (IsAdobeReaderDefaultPDFViewer() && | 353 if (!disable_adobe_version_check_for_tests_ && |
| 354 IsAdobeReaderDefaultPDFViewer() && |
| 353 !DownloadTargetDeterminer::IsAdobeReaderUpToDate()) { | 355 !DownloadTargetDeterminer::IsAdobeReaderUpToDate()) { |
| 354 return false; | 356 return false; |
| 355 } | 357 } |
| 356 #endif | 358 #endif |
| 357 return should_open_pdf_in_system_reader_; | 359 return should_open_pdf_in_system_reader_; |
| 358 } | 360 } |
| 361 |
| 362 void DownloadPrefs::DisableAdobeVersionCheckForTests() { |
| 363 disable_adobe_version_check_for_tests_ = true; |
| 364 } |
| 359 #endif | 365 #endif |
| 360 | 366 |
| 361 void DownloadPrefs::ResetAutoOpen() { | 367 void DownloadPrefs::ResetAutoOpen() { |
| 362 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) | 368 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) |
| 363 SetShouldOpenPdfInSystemReader(false); | 369 SetShouldOpenPdfInSystemReader(false); |
| 364 #endif | 370 #endif |
| 365 auto_open_.clear(); | 371 auto_open_.clear(); |
| 366 SaveAutoOpenState(); | 372 SaveAutoOpenState(); |
| 367 } | 373 } |
| 368 | 374 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 382 extensions.erase(extensions.size() - 1); | 388 extensions.erase(extensions.size() - 1); |
| 383 | 389 |
| 384 profile_->GetPrefs()->SetString(prefs::kDownloadExtensionsToOpen, extensions); | 390 profile_->GetPrefs()->SetString(prefs::kDownloadExtensionsToOpen, extensions); |
| 385 } | 391 } |
| 386 | 392 |
| 387 bool DownloadPrefs::AutoOpenCompareFunctor::operator()( | 393 bool DownloadPrefs::AutoOpenCompareFunctor::operator()( |
| 388 const base::FilePath::StringType& a, | 394 const base::FilePath::StringType& a, |
| 389 const base::FilePath::StringType& b) const { | 395 const base::FilePath::StringType& b) const { |
| 390 return base::FilePath::CompareLessIgnoreCase(a, b); | 396 return base::FilePath::CompareLessIgnoreCase(a, b); |
| 391 } | 397 } |
| OLD | NEW |