diff options
author | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-09 08:42:51 +0000 |
---|---|---|
committer | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-09 08:42:51 +0000 |
commit | 35896a39fe47d8b17969a07c629c69e6a17ceb30 (patch) | |
tree | 588f2208a07630501597e3ba3ecfc6034954c7c0 /chrome/browser | |
parent | 7ac1ce2f4d2e385c53340f501764bdd59bd86ad4 (diff) | |
download | chromium_src-35896a39fe47d8b17969a07c629c69e6a17ceb30.zip chromium_src-35896a39fe47d8b17969a07c629c69e6a17ceb30.tar.gz chromium_src-35896a39fe47d8b17969a07c629c69e6a17ceb30.tar.bz2 |
Don't save last used locations in open and save dialogs when in incognito mode.
For "Save page as..." we simply don't store the save location in incognito mode.
For "Open File"... and file upload controls, it's a bit more complicated: because NSOpenPanel and NSSavePanel default to using the last chosen directory from NavigationServices (which we can't influence),
we provide a preference value prefs::kLastChosenDirectory as fallback there, which is not persisted in incognito mode.
BUG=45064
TEST=See bug for manual test.
Review URL: http://codereview.chromium.org/2450004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49237 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser.cc | 5 | ||||
-rw-r--r-- | chrome/browser/download/save_package.cc | 3 | ||||
-rw-r--r-- | chrome/browser/profile.cc | 23 | ||||
-rw-r--r-- | chrome/browser/profile.h | 6 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 8 |
5 files changed, 42 insertions, 3 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 0dc47d2..0c3d035 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1583,10 +1583,12 @@ void Browser::OpenFile() { if (!select_file_dialog_.get()) select_file_dialog_ = SelectFileDialog::Create(this); + const FilePath directory = profile_->last_selected_directory(); + // TODO(beng): figure out how to juggle this. gfx::NativeWindow parent_window = window_->GetNativeHandle(); select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, - string16(), FilePath(), + string16(), directory, NULL, 0, FILE_PATH_LITERAL(""), parent_window, NULL); #endif @@ -2855,6 +2857,7 @@ void Browser::OnDidGetApplicationInfo(TabContents* tab_contents, // Browser, SelectFileDialog::Listener implementation: void Browser::FileSelected(const FilePath& path, int index, void* params) { + profile_->set_last_selected_directory(path.DirName()); GURL file_url = net::FilePathToFileURL(path); if (!file_url.is_empty()) OpenURL(file_url, GURL(), CURRENT_TAB, PageTransition::TYPED); diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc index 0510653..8c841b6 100644 --- a/chrome/browser/download/save_package.cc +++ b/chrome/browser/download/save_package.cc @@ -1268,7 +1268,8 @@ void SavePackage::ContinueSave(SavePackageParam* param, save_file_path.Init(prefs::kSaveFileDefaultDirectory, prefs, NULL); // If user change the default saving directory, we will remember it just // like IE and FireFox. - if (save_file_path.GetValue() != param->dir.ToWStringHack()) + if (!tab_contents_->profile()->IsOffTheRecord() && + save_file_path.GetValue() != param->dir.ToWStringHack()) save_file_path.SetValue(param->dir.ToWStringHack()); param->save_type = (index == 1) ? SavePackage::SAVE_AS_ONLY_HTML : diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index c0be2f9..b2bdf7f 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -215,6 +215,7 @@ void Profile::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints); prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties); prefs->RegisterBooleanPref(prefs::kDisableExtensions, false); + prefs->RegisterStringPref(prefs::kSelectFileLastDirectory, L""); } // static @@ -583,6 +584,18 @@ class OffTheRecordProfileImpl : public Profile, return profile_->GetNTPResourceCache(); } + virtual FilePath last_selected_directory() { + const FilePath& directory = last_selected_directory_; + if (directory.empty()) { + return profile_->last_selected_directory(); + } + return directory; + } + + virtual void set_last_selected_directory(const FilePath& path) { + last_selected_directory_ = path; + } + virtual void ExitedOffTheRecordMode() { // Drop our download manager so we forget about all the downloads made // in off-the-record mode. @@ -648,6 +661,8 @@ class OffTheRecordProfileImpl : public Profile, // Should be used only on the file thread. scoped_refptr<webkit_database::DatabaseTracker> db_tracker_; + FilePath last_selected_directory_; + DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl); }; @@ -824,6 +839,14 @@ NTPResourceCache* ProfileImpl::GetNTPResourceCache() { return ntp_resource_cache_.get(); } +FilePath ProfileImpl::last_selected_directory() { + return GetPrefs()->GetFilePath(prefs::kSelectFileLastDirectory); +} + +void ProfileImpl::set_last_selected_directory(const FilePath& path) { + GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, path); +} + ProfileImpl::~ProfileImpl() { NotificationService::current()->Notify( NotificationType::PROFILE_DESTROYED, diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h index 7f8a6a1..5ec66d6 100644 --- a/chrome/browser/profile.h +++ b/chrome/browser/profile.h @@ -417,6 +417,10 @@ class Profile { // Returns the new tab page resource cache. virtual NTPResourceCache* GetNTPResourceCache() = 0; + // Returns the last directory that was chosen for uploading or opening a file. + virtual FilePath last_selected_directory() = 0; + virtual void set_last_selected_directory(const FilePath& path) = 0; + #ifdef UNIT_TEST // Use with caution. GetDefaultRequestContext may be called on any thread! static void set_default_request_context(URLRequestContextGetter* c) { @@ -537,6 +541,8 @@ class ProfileImpl : public Profile, virtual void InitExtensions(); virtual void InitWebResources(); virtual NTPResourceCache* GetNTPResourceCache(); + virtual FilePath last_selected_directory(); + virtual void set_last_selected_directory(const FilePath& path); virtual ProfileSyncService* GetProfileSyncService(); void InitSyncService(); virtual CloudPrintProxyService* GetCloudPrintProxyService(); diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 6cbf922..15206a5 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -2589,8 +2589,11 @@ void TabContents::RunFileChooser( dialog_type = SelectFileDialog::SELECT_OPEN_FILE; // Prevent warning. NOTREACHED(); } + FilePath default_file_name = params.default_file_name; + if (default_file_name.empty()) + default_file_name = profile()->last_selected_directory(); select_file_dialog_->SelectFile(dialog_type, params.title, - params.default_file_name, + default_file_name, NULL, 0, FILE_PATH_LITERAL(""), view_->GetTopLevelNativeWindow(), NULL); } @@ -2851,6 +2854,7 @@ void TabContents::FocusedNodeChanged() { void TabContents::FileSelected(const FilePath& path, int index, void* params) { + profile()->set_last_selected_directory(path.DirName()); std::vector<FilePath> files; files.push_back(path); render_view_host()->FilesSelectedInChooser(files); @@ -2858,6 +2862,8 @@ void TabContents::FileSelected(const FilePath& path, void TabContents::MultiFilesSelected(const std::vector<FilePath>& files, void* params) { + if (!files.empty()) + profile()->set_last_selected_directory(files[0].DirName()); render_view_host()->FilesSelectedInChooser(files); } |