#include "chrome/browser/download/download_extensions.h"
#include "chrome/browser/download/download_service.h"
#include "chrome/browser/download/download_service_factory.h"
+#include "chrome/browser/download/download_target_determiner.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
-#include "components/user_prefs/pref_registry_syncable.h"
+#include "components/pref_registry/pref_registry_syncable.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/save_page_type.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
+#include "chrome/browser/chromeos/file_manager/path_util.h"
+#endif
+
+#if defined(OS_WIN)
+#include "chrome/browser/ui/pdf/adobe_reader_info_win.h"
#endif
using content::BrowserContext;
// to the desktop on any platform.
bool DownloadPathIsDangerous(const base::FilePath& download_path) {
#if defined(OS_LINUX)
- base::FilePath home_dir = file_util::GetHomeDir();
+ base::FilePath home_dir = base::GetHomeDir();
if (download_path == home_dir) {
return true;
}
DISALLOW_COPY_AND_ASSIGN(DefaultDownloadDirectory);
};
-static base::LazyInstance<DefaultDownloadDirectory>
+base::LazyInstance<DefaultDownloadDirectory>
g_default_download_directory = LAZY_INSTANCE_INITIALIZER;
} // namespace
DownloadPrefs::DownloadPrefs(Profile* profile) : profile_(profile) {
PrefService* prefs = profile->GetPrefs();
+#if defined(OS_CHROMEOS)
+ // On Chrome OS, the default download directory is different for each profile.
+ // If the profile-unaware default path (from GetDefaultDownloadDirectory())
+ // is set (this happens during the initial preference registration in static
+ // RegisterProfilePrefs()), alter by GetDefaultDownloadDirectoryForProfile().
+ // file_manager::util::MigratePathFromOldFormat will do this.
+ const char* path_pref[] = {
+ prefs::kSaveFileDefaultDirectory,
+ prefs::kDownloadDefaultDirectory
+ };
+ for (size_t i = 0; i < arraysize(path_pref); ++i) {
+ const base::FilePath current = prefs->GetFilePath(path_pref[i]);
+ base::FilePath migrated;
+ if (!current.empty() &&
+ file_manager::util::MigratePathFromOldFormat(
+ profile_, current, &migrated)) {
+ prefs->SetFilePath(path_pref[i], migrated);
+ }
+ }
+
+ // Ensure that the default download directory exists.
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(base::IgnoreResult(&base::CreateDirectory),
+ GetDefaultDownloadDirectoryForProfile()));
+#endif // defined(OS_CHROMEOS)
+
+#if defined(OS_WIN)
+ should_open_pdf_in_adobe_reader_ =
+ prefs->GetBoolean(prefs::kOpenPdfDownloadInAdobeReader);
+#endif
+
// If the download path is dangerous we forcefully reset it. But if we do
// so we set a flag to make sure we only do it once, to avoid fighting
// the user if he really wants it on an unsafe place such as the desktop.
prefs::kDownloadDefaultDirectory);
if (DownloadPathIsDangerous(current_download_dir)) {
prefs->SetFilePath(prefs::kDownloadDefaultDirectory,
- GetDefaultDownloadDirectory());
+ GetDefaultDownloadDirectoryForProfile());
}
prefs->SetBoolean(prefs::kDownloadDirUpgraded, true);
}
#if defined(OS_POSIX)
base::FilePath path(extensions[i]);
#elif defined(OS_WIN)
- base::FilePath path(UTF8ToWide(extensions[i]));
+ base::FilePath path(base::UTF8ToWide(extensions[i]));
#endif
if (!extensions[i].empty() &&
download_util::GetFileDangerLevel(path) == download_util::NOT_DANGEROUS)
content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
- // The default download path is userprofile\download.
const base::FilePath& default_download_path = GetDefaultDownloadDirectory();
registry->RegisterFilePathPref(
prefs::kDownloadDefaultDirectory,
prefs::kSaveFileDefaultDirectory,
default_download_path,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
+#if defined(OS_WIN)
+ registry->RegisterBooleanPref(
+ prefs::kOpenPdfDownloadInAdobeReader,
+ false,
+ user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
+#endif
+}
+base::FilePath DownloadPrefs::GetDefaultDownloadDirectoryForProfile() const {
#if defined(OS_CHROMEOS)
- // Ensure that the download directory specified in the preferences exists.
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::Bind(base::IgnoreResult(&file_util::CreateDirectory),
- default_download_path));
-#endif // defined(OS_CHROMEOS)
+ return file_manager::util::GetDownloadsFolderForProfile(profile_);
+#else
+ return GetDefaultDownloadDirectory();
+#endif
}
// static
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::FindForProfile(profile_);
if (!integration_service || !integration_service->is_enabled())
- return GetDefaultDownloadDirectory();
+ return GetDefaultDownloadDirectoryForProfile();
}
#endif
return *download_path_;
}
bool DownloadPrefs::IsAutoOpenUsed() const {
+#if defined(OS_WIN)
+ if (ShouldOpenPdfInAdobeReader())
+ return true;
+#endif
return !auto_open_.empty();
}
return false;
DCHECK(extension[0] == base::FilePath::kExtensionSeparator);
extension.erase(0, 1);
+#if defined(OS_WIN)
+ if (extension == FILE_PATH_LITERAL("pdf") &&
+ DownloadTargetDeterminer::IsAdobeReaderUpToDate() &&
+ ShouldOpenPdfInAdobeReader())
+ return true;
+#endif
return auto_open_.find(extension) != auto_open_.end();
}
SaveAutoOpenState();
}
+#if defined(OS_WIN)
+void DownloadPrefs::SetShouldOpenPdfInAdobeReader(bool should_open) {
+ if (should_open_pdf_in_adobe_reader_ == should_open)
+ return;
+ should_open_pdf_in_adobe_reader_ = should_open;
+ profile_->GetPrefs()->SetBoolean(prefs::kOpenPdfDownloadInAdobeReader,
+ should_open);
+}
+
+bool DownloadPrefs::ShouldOpenPdfInAdobeReader() const {
+ return should_open_pdf_in_adobe_reader_;
+}
+#endif
+
void DownloadPrefs::ResetAutoOpen() {
+#if defined(OS_WIN)
+ SetShouldOpenPdfInAdobeReader(false);
+#endif
auto_open_.clear();
SaveAutoOpenState();
}