summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorcpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-05 02:25:32 +0000
committercpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-05 02:25:32 +0000
commitf052118e0a1dea89270f0c92cb78d8b277720dc6 (patch)
treeb491b444b48facae9315b8f9053ff9aa27bd923f /chrome
parent200abc3b412aa5129bca6c90cfe298b05ad547b2 (diff)
downloadchromium_src-f052118e0a1dea89270f0c92cb78d8b277720dc6.zip
chromium_src-f052118e0a1dea89270f0c92cb78d8b277720dc6.tar.gz
chromium_src-f052118e0a1dea89270f0c92cb78d8b277720dc6.tar.bz2
Same CL as 448. Had to redo it.
Change the default download path if needed, in Vista it could be set tothe destkop which is a risky location.- Remove reading the download location from IE in vista.BUG=b/1355855 This was already LGTmed Review URL: http://codereview.chromium.org/462 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1753 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/download_manager.cc53
-rw-r--r--chrome/common/chrome_paths.cc2
-rw-r--r--chrome/common/chrome_paths.h2
-rw-r--r--chrome/common/pref_names.cc4
-rw-r--r--chrome/common/pref_names.h1
5 files changed, 41 insertions, 21 deletions
diff --git a/chrome/browser/download_manager.cc b/chrome/browser/download_manager.cc
index 4f008d8..a587445 100644
--- a/chrome/browser/download_manager.cc
+++ b/chrome/browser/download_manager.cc
@@ -82,6 +82,15 @@ static bool UniquifyPath(std::wstring* path) {
return false;
}
+static bool DownloadPathIsDangerous(const std::wstring& download_path) {
+ std::wstring desktop_dir;
+ if (!PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_dir)) {
+ NOTREACHED();
+ return false;
+ }
+ return (download_path == desktop_dir);
+}
+
// DownloadItem implementation -------------------------------------------------
// Constructor for reading from the history service.
@@ -252,6 +261,31 @@ void DownloadItem::TogglePause() {
void DownloadManager::RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterBooleanPref(prefs::kPromptForDownload, false);
prefs->RegisterStringPref(prefs::kDownloadExtensionsToOpen, L"");
+ prefs->RegisterBooleanPref(prefs::kDownloadDirUpgraded, false);
+
+ // The default download path is userprofile\download.
+ std::wstring default_download_path;
+ if (!PathService::Get(chrome::DIR_USER_DOCUMENTS, &default_download_path)) {
+ NOTREACHED();
+ }
+ file_util::AppendToPath(&default_download_path,
+ l10n_util::GetString(IDS_DOWNLOAD_DIRECTORY));
+ prefs->RegisterStringPref(prefs::kDownloadDefaultDirectory,
+ default_download_path);
+
+ // 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.
+
+ if (!prefs->GetBoolean(prefs::kDownloadDirUpgraded)) {
+ std::wstring current_download_dir =
+ prefs->GetString(prefs::kDownloadDefaultDirectory);
+ if (DownloadPathIsDangerous(current_download_dir)) {
+ prefs->SetString(prefs::kDownloadDefaultDirectory,
+ default_download_path);
+ }
+ prefs->SetBoolean(prefs::kDownloadDirUpgraded, true);
+ }
}
DownloadManager::DownloadManager()
@@ -387,25 +421,6 @@ bool DownloadManager::Init(Profile* profile) {
DCHECK(prefs);
prompt_for_download_.Init(prefs::kPromptForDownload, prefs, NULL);
- // Use the IE download directory on Vista, if available.
- std::wstring default_download_path;
- if (win_util::GetWinVersion() == win_util::WINVERSION_VISTA) {
- RegKey vista_reg(HKEY_CURRENT_USER,
- L"Software\\Microsoft\\Internet Explorer", KEY_READ);
- const wchar_t* const vista_dir = L"Download Directory";
- if (vista_reg.ValueExists(vista_dir))
- vista_reg.ReadValue(vista_dir, &default_download_path);
- }
- if (default_download_path.empty()) {
- PathService::Get(chrome::DIR_USER_DOCUMENTS, &default_download_path);
- file_util::AppendToPath(&default_download_path,
- l10n_util::GetString(IDS_DOWNLOAD_DIRECTORY));
- }
- // Check if the pref has already been registered, as the user profile and the
- // "off the record" profile might register it.
- if (!prefs->IsPrefRegistered(prefs::kDownloadDefaultDirectory))
- prefs->RegisterStringPref(prefs::kDownloadDefaultDirectory,
- default_download_path);
download_path_.Init(prefs::kDownloadDefaultDirectory, prefs, NULL);
// Ensure that the download directory specified in the preferences exists.
diff --git a/chrome/common/chrome_paths.cc b/chrome/common/chrome_paths.cc
index 7f8c3b6..029a269 100644
--- a/chrome/common/chrome_paths.cc
+++ b/chrome/common/chrome_paths.cc
@@ -95,7 +95,7 @@ bool PathProvider(int key, std::wstring* result) {
return false;
file_util::AppendToPath(&cur, L"Crash Reports");
break;
- case chrome::DIR_DEFAULT_DOWNLOAD:
+ case chrome::DIR_USER_DESKTOP:
if (FAILED(SHGetFolderPath(NULL, CSIDL_DESKTOPDIRECTORY, NULL,
SHGFP_TYPE_CURRENT, system_buffer)))
return false;
diff --git a/chrome/common/chrome_paths.h b/chrome/common/chrome_paths.h
index 77913d4..02b14ae 100644
--- a/chrome/common/chrome_paths.h
+++ b/chrome/common/chrome_paths.h
@@ -17,7 +17,7 @@ enum {
DIR_LOGS, // directory where logs should be written
DIR_USER_DATA, // directory where user data can be written
DIR_CRASH_DUMPS, // directory where crash dumps are written
- DIR_DEFAULT_DOWNLOAD, // directory where downloads go by default
+ DIR_USER_DESKTOP, // directory that correspond to the desktop
DIR_RESOURCES, // directory where application resources are stored
DIR_INSPECTOR, // directory where web inspector is located
DIR_THEMES, // directory where theme dll files are stored
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index 0564bc7..b664b24 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -345,6 +345,10 @@ const wchar_t kMemoryCacheSize[] = L"renderer.memory_cache.size";
// String which specifies where to download files to by default.
const wchar_t kDownloadDefaultDirectory[] = L"download.default_directory";
+// Boolean that records if the download directory was changed by an
+// upgrade a unsafe location to a safe location.
+const wchar_t kDownloadDirUpgraded[] = L"download.directory_upgrade";
+
// String which specifies where to save html files to by default.
const wchar_t kSaveFileDefaultDirectory[] = L"savefile.default_directory";
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 4d991a1..a3c4736 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -112,6 +112,7 @@ extern const wchar_t kMemoryCacheSize[];
extern const wchar_t kDownloadDefaultDirectory[];
extern const wchar_t kDownloadExtensionsToOpen[];
+extern const wchar_t kDownloadDirUpgraded[];
extern const wchar_t kSaveFileDefaultDirectory[];