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

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

Issue 12084075: SavePackageFilePickerChromeOS should only force MHTML when saving HTML, not when saving text/image/… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r185696 Created 7 years, 9 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) 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/save_package_file_picker_chromeos.h" 5 #include "chrome/browser/download/save_package_file_picker_chromeos.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/i18n/file_util_icu.h" 9 #include "base/i18n/file_util_icu.h"
10 #include "base/threading/sequenced_worker_pool.h" 10 #include "base/threading/sequenced_worker_pool.h"
11 #include "chrome/browser/chromeos/drive/drive_download_handler.h" 11 #include "chrome/browser/chromeos/drive/drive_download_handler.h"
12 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" 12 #include "chrome/browser/chromeos/drive/drive_file_system_util.h"
13 #include "chrome/browser/platform_util.h" 13 #include "chrome/browser/platform_util.h"
14 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/ui/chrome_select_file_policy.h" 15 #include "chrome/browser/ui/chrome_select_file_policy.h"
16 #include "content/public/browser/download_item.h" 16 #include "content/public/browser/download_item.h"
17 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
18 #include "content/public/browser/web_contents_view.h" 18 #include "content/public/browser/web_contents_view.h"
19 #include "ui/shell_dialogs/selected_file_info.h" 19 #include "ui/shell_dialogs/selected_file_info.h"
20 20
21 namespace { 21 namespace {
22 22
23 // If false, we don't prompt the user as to where to save the file. This 23 // If false, we don't prompt the user as to where to save the file. This
24 // exists only for testing. 24 // exists only for testing.
25 bool g_should_prompt_for_filename = true; 25 bool g_should_prompt_for_filename = true;
26 26
27 // Trampoline callback between SubstituteDriveDownloadPath() and |callback|. 27 // Trampoline callback between SubstituteDriveDownloadPath() and |callback|.
28 void ContinueSettingUpDriveDownload( 28 void ContinueSettingUpDriveDownload(
29 const content::SavePackagePathPickedCallback& callback, 29 const content::SavePackagePathPickedCallback& callback,
30 bool is_html,
30 Profile* profile, 31 Profile* profile,
31 const base::FilePath& drive_path, 32 const base::FilePath& drive_path,
32 const base::FilePath& drive_tmp_download_path) { 33 const base::FilePath& drive_tmp_download_path) {
33 if (drive_tmp_download_path.empty()) // Substitution failed. 34 if (drive_tmp_download_path.empty()) // Substitution failed.
34 return; 35 return;
35 36
36 callback.Run( 37 callback.Run(
37 drive_tmp_download_path, content::SAVE_PAGE_TYPE_AS_MHTML, 38 drive_tmp_download_path,
39 (is_html ?
40 content::SAVE_PAGE_TYPE_AS_MHTML :
41 content::SAVE_PAGE_TYPE_AS_ONLY_HTML),
38 base::Bind(&drive::DriveDownloadHandler::SetDownloadParams, 42 base::Bind(&drive::DriveDownloadHandler::SetDownloadParams,
39 base::Unretained( 43 base::Unretained(
40 drive::DriveDownloadHandler::GetForProfile(profile)), 44 drive::DriveDownloadHandler::GetForProfile(profile)),
41 drive_path)); 45 drive_path));
42 } 46 }
43 47
44 } // namespace 48 } // namespace
45 49
46 SavePackageFilePickerChromeOS::SavePackageFilePickerChromeOS( 50 SavePackageFilePickerChromeOS::SavePackageFilePickerChromeOS(
47 content::WebContents* web_contents, 51 content::WebContents* web_contents,
48 const base::FilePath& suggested_path, 52 const base::FilePath& suggested_path,
53 bool is_html,
49 const content::SavePackagePathPickedCallback& callback) 54 const content::SavePackagePathPickedCallback& callback)
50 : content::WebContentsObserver(web_contents), 55 : content::WebContentsObserver(web_contents),
51 callback_(callback) { 56 callback_(callback),
57 is_html_(is_html) {
58 base::FilePath suggested_path_copy(is_html_ ?
59 suggested_path.ReplaceExtension("mhtml") :
60 suggested_path);
52 if (g_should_prompt_for_filename) { 61 if (g_should_prompt_for_filename) {
53 select_file_dialog_ = ui::SelectFileDialog::Create( 62 select_file_dialog_ = ui::SelectFileDialog::Create(
54 this, new ChromeSelectFilePolicy(web_contents)); 63 this, new ChromeSelectFilePolicy(web_contents));
55 ui::SelectFileDialog::FileTypeInfo file_types; 64 ui::SelectFileDialog::FileTypeInfo file_types;
56 file_types.support_drive = true; 65 file_types.support_drive = true;
57 select_file_dialog_->SelectFile( 66 select_file_dialog_->SelectFile(
58 ui::SelectFileDialog::SELECT_SAVEAS_FILE, 67 ui::SelectFileDialog::SELECT_SAVEAS_FILE,
59 string16(), 68 string16(),
60 suggested_path.ReplaceExtension("mhtml"), 69 suggested_path_copy,
61 &file_types, 70 &file_types,
62 0, 71 0,
63 "mhtml", 72 suggested_path_copy.Extension(),
64 platform_util::GetTopLevel(web_contents->GetView()->GetNativeView()), 73 platform_util::GetTopLevel(web_contents->GetView()->GetNativeView()),
65 NULL); 74 NULL);
66 } else { 75 } else {
67 FileSelected(suggested_path.ReplaceExtension("mhtml"), 0, NULL); 76 FileSelected(suggested_path_copy, 0, NULL);
68 } 77 }
69 } 78 }
70 79
71 void SavePackageFilePickerChromeOS::SetShouldPromptUser(bool should_prompt) { 80 void SavePackageFilePickerChromeOS::SetShouldPromptUser(bool should_prompt) {
72 g_should_prompt_for_filename = should_prompt; 81 g_should_prompt_for_filename = should_prompt;
73 } 82 }
74 83
75 SavePackageFilePickerChromeOS::~SavePackageFilePickerChromeOS() { 84 SavePackageFilePickerChromeOS::~SavePackageFilePickerChromeOS() {
76 } 85 }
77 86
(...skipping 27 matching lines...) Expand all
105 // ContinueSettingUpDriveDownload -> 114 // ContinueSettingUpDriveDownload ->
106 // callback_ = SavePackage::OnPathPicked -> 115 // callback_ = SavePackage::OnPathPicked ->
107 // download_created_callback = OnSavePackageDownloadCreated 116 // download_created_callback = OnSavePackageDownloadCreated
108 drive::DriveDownloadHandler* drive_download_handler = 117 drive::DriveDownloadHandler* drive_download_handler =
109 drive::DriveDownloadHandler::GetForProfile(profile); 118 drive::DriveDownloadHandler::GetForProfile(profile);
110 DCHECK(drive_download_handler); 119 DCHECK(drive_download_handler);
111 drive_download_handler-> 120 drive_download_handler->
112 SubstituteDriveDownloadPath(selected_path, NULL, 121 SubstituteDriveDownloadPath(selected_path, NULL,
113 base::Bind(&ContinueSettingUpDriveDownload, 122 base::Bind(&ContinueSettingUpDriveDownload,
114 callback_, 123 callback_,
124 is_html_,
115 profile, 125 profile,
116 selected_path)); 126 selected_path));
117 } else { 127 } else {
118 callback_.Run(selected_path, content::SAVE_PAGE_TYPE_AS_MHTML, 128 callback_.Run(selected_path,
129 (is_html_ ?
130 content::SAVE_PAGE_TYPE_AS_MHTML :
131 content::SAVE_PAGE_TYPE_AS_ONLY_HTML),
119 content::SavePackageDownloadCreatedCallback()); 132 content::SavePackageDownloadCreatedCallback());
120 } 133 }
121 delete this; 134 delete this;
122 } 135 }
123 136
124 void SavePackageFilePickerChromeOS::FileSelectionCanceled(void* params) { 137 void SavePackageFilePickerChromeOS::FileSelectionCanceled(void* params) {
125 delete this; 138 delete this;
126 } 139 }
OLDNEW
« no previous file with comments | « chrome/browser/download/save_package_file_picker_chromeos.h ('k') | chrome/browser/download/save_page_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698