Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: chrome/browser/download/save_package_file_picker.cc

Issue 9030032: Get rid of a bunch of tab_contents.h includes from chrome. These are all trivial changes to use W... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix cros Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/save_package_file_picker.h" 5 #include "chrome/browser/download/save_package_file_picker.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/download/download_prefs.h" 8 #include "chrome/browser/download/download_prefs.h"
9 #include "chrome/browser/platform_util.h" 9 #include "chrome/browser/platform_util.h"
10 #include "chrome/browser/prefs/pref_member.h" 10 #include "chrome/browser/prefs/pref_member.h"
11 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
14 #include "content/browser/download/save_package.h" 14 #include "content/browser/download/save_package.h"
15 #include "content/browser/tab_contents/tab_contents.h"
16 #include "content/public/browser/download_manager.h" 15 #include "content/public/browser/download_manager.h"
16 #include "content/public/browser/web_contents.h"
17 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
18 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
19 19
20 using content::WebContents;
21
20 namespace { 22 namespace {
21 23
22 // If false, we don't prompt the user as to where to save the file. This 24 // If false, we don't prompt the user as to where to save the file. This
23 // exists only for testing. 25 // exists only for testing.
24 bool g_should_prompt_for_filename = true; 26 bool g_should_prompt_for_filename = true;
25 27
26 // Used for mapping between SavePackageType constants and the indexes above. 28 // Used for mapping between SavePackageType constants and the indexes above.
27 const SavePackage::SavePackageType kIndexToSaveType[] = { 29 const SavePackage::SavePackageType kIndexToSaveType[] = {
28 SavePackage::SAVE_TYPE_UNKNOWN, 30 SavePackage::SAVE_TYPE_UNKNOWN,
29 SavePackage::SAVE_AS_ONLY_HTML, 31 SavePackage::SAVE_AS_ONLY_HTML,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // Drop the . 115 // Drop the .
114 file_type_info.extensions[kSelectFileHtmlOnlyIndex - 1][0].erase(0, 1); 116 file_type_info.extensions[kSelectFileHtmlOnlyIndex - 1][0].erase(0, 1);
115 } 117 }
116 118
117 file_type_info.include_all_files = true; 119 file_type_info.include_all_files = true;
118 file_type_index = 1; 120 file_type_index = 1;
119 } 121 }
120 122
121 if (g_should_prompt_for_filename) { 123 if (g_should_prompt_for_filename) {
122 select_file_dialog_ = SelectFileDialog::Create(this); 124 select_file_dialog_ = SelectFileDialog::Create(this);
123 TabContents* tab_contents = save_package_->tab_contents(); 125 WebContents* web_contents = save_package_->web_contents();
124 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, 126 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE,
125 string16(), 127 string16(),
126 suggested_path, 128 suggested_path,
127 &file_type_info, 129 &file_type_info,
128 file_type_index, 130 file_type_index,
129 default_extension, 131 default_extension,
130 tab_contents, 132 web_contents,
131 platform_util::GetTopLevel( 133 platform_util::GetTopLevel(
132 tab_contents->GetNativeView()), 134 web_contents->GetNativeView()),
133 NULL); 135 NULL);
134 } else { 136 } else {
135 // Just use 'suggested_path' instead of opening the dialog prompt. 137 // Just use 'suggested_path' instead of opening the dialog prompt.
136 save_package_->OnPathPicked( 138 save_package_->OnPathPicked(
137 suggested_path, kIndexToSaveType[file_type_index]); 139 suggested_path, kIndexToSaveType[file_type_index]);
138 } 140 }
139 } 141 }
140 142
141 SavePackageFilePicker::~SavePackageFilePicker() { 143 SavePackageFilePicker::~SavePackageFilePicker() {
142 } 144 }
143 145
144 void SavePackageFilePicker::SetShouldPromptUser(bool should_prompt) { 146 void SavePackageFilePicker::SetShouldPromptUser(bool should_prompt) {
145 g_should_prompt_for_filename = should_prompt; 147 g_should_prompt_for_filename = should_prompt;
146 } 148 }
147 149
148 void SavePackageFilePicker::FileSelected(const FilePath& path, 150 void SavePackageFilePicker::FileSelected(const FilePath& path,
149 int index, 151 int index,
150 void* params) { 152 void* params) {
151 // The option index is not zero-based. 153 // The option index is not zero-based.
152 DCHECK(index >= kSelectFileHtmlOnlyIndex && 154 DCHECK(index >= kSelectFileHtmlOnlyIndex &&
153 index <= kSelectFileCompleteIndex); 155 index <= kSelectFileCompleteIndex);
154 156
155 if (save_package_) { 157 if (save_package_) {
156 TabContents* tab_contents = save_package_->tab_contents(); 158 WebContents* web_contents = save_package_->web_contents();
157 SavePackage::SavePackageType save_type = kIndexToSaveType[index]; 159 SavePackage::SavePackageType save_type = kIndexToSaveType[index];
158 Profile* profile = 160 Profile* profile =
159 Profile::FromBrowserContext(tab_contents->GetBrowserContext()); 161 Profile::FromBrowserContext(web_contents->GetBrowserContext());
160 PrefService* prefs = profile->GetPrefs(); 162 PrefService* prefs = profile->GetPrefs();
161 if (select_file_dialog_ && 163 if (select_file_dialog_ &&
162 select_file_dialog_->HasMultipleFileTypeChoices()) 164 select_file_dialog_->HasMultipleFileTypeChoices())
163 prefs->SetInteger(prefs::kSaveFileType, save_type); 165 prefs->SetInteger(prefs::kSaveFileType, save_type);
164 166
165 StringPrefMember save_file_path; 167 StringPrefMember save_file_path;
166 save_file_path.Init(prefs::kSaveFileDefaultDirectory, prefs, NULL); 168 save_file_path.Init(prefs::kSaveFileDefaultDirectory, prefs, NULL);
167 #if defined(OS_POSIX) 169 #if defined(OS_POSIX)
168 std::string path_string = path.DirName().value(); 170 std::string path_string = path.DirName().value();
169 #elif defined(OS_WIN) 171 #elif defined(OS_WIN)
170 std::string path_string = WideToUTF8(path.DirName().value()); 172 std::string path_string = WideToUTF8(path.DirName().value());
171 #endif 173 #endif
172 // If user change the default saving directory, we will remember it just 174 // If user change the default saving directory, we will remember it just
173 // like IE and FireFox. 175 // like IE and FireFox.
174 if (!tab_contents->GetBrowserContext()->IsOffTheRecord() && 176 if (!web_contents->GetBrowserContext()->IsOffTheRecord() &&
175 save_file_path.GetValue() != path_string) { 177 save_file_path.GetValue() != path_string) {
176 save_file_path.SetValue(path_string); 178 save_file_path.SetValue(path_string);
177 } 179 }
178 180
179 save_package_->OnPathPicked(path, save_type); 181 save_package_->OnPathPicked(path, save_type);
180 } 182 }
181 183
182 delete this; 184 delete this;
183 } 185 }
184 186
185 void SavePackageFilePicker::FileSelectionCanceled(void* params) { 187 void SavePackageFilePicker::FileSelectionCanceled(void* params) {
186 delete this; 188 delete this;
187 } 189 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_util.cc ('k') | chrome/browser/extensions/execute_code_in_tab_function.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698