| OLD | NEW |
| 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/ui/select_file_dialog.h" | 5 #include "chrome/browser/ui/select_file_dialog.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <commdlg.h> | 8 #include <commdlg.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 | 10 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // This function takes the output of a SaveAs dialog: a filename, a filter and | 82 // This function takes the output of a SaveAs dialog: a filename, a filter and |
| 83 // the extension originally suggested to the user (shown in the dialog box) and | 83 // the extension originally suggested to the user (shown in the dialog box) and |
| 84 // returns back the filename with the appropriate extension tacked on. If the | 84 // returns back the filename with the appropriate extension tacked on. If the |
| 85 // user requests an unknown extension and is not using the 'All files' filter, | 85 // user requests an unknown extension and is not using the 'All files' filter, |
| 86 // the suggested extension will be appended, otherwise we will leave the | 86 // the suggested extension will be appended, otherwise we will leave the |
| 87 // filename unmodified. |filename| should contain the filename selected in the | 87 // filename unmodified. |filename| should contain the filename selected in the |
| 88 // SaveAs dialog box and may include the path, |filter_selected| should be | 88 // SaveAs dialog box and may include the path, |filter_selected| should be |
| 89 // '*.something', for example '*.*' or it can be blank (which is treated as | 89 // '*.something', for example '*.*' or it can be blank (which is treated as |
| 90 // *.*). |suggested_ext| should contain the extension without the dot (.) in | 90 // *.*). |suggested_ext| should contain the extension without the dot (.) in |
| 91 // front, for example 'jpg'. | 91 // front, for example 'jpg'. |
| 92 std::wstring AppendExtensionIfNeeded(const std::wstring& filename, | 92 extern std::wstring AppendExtensionIfNeeded( |
| 93 const std::wstring& filter_selected, | 93 const std::wstring& filename, |
| 94 const std::wstring& suggested_ext) { | 94 const std::wstring& filter_selected, |
| 95 const std::wstring& suggested_ext) { |
| 95 DCHECK(!filename.empty()); | 96 DCHECK(!filename.empty()); |
| 96 std::wstring return_value = filename; | 97 std::wstring return_value = filename; |
| 97 | 98 |
| 98 // If we wanted a specific extension, but the user's filename deleted it or | 99 // If we wanted a specific extension, but the user's filename deleted it or |
| 99 // changed it to something that the system doesn't understand, re-append. | 100 // changed it to something that the system doesn't understand, re-append. |
| 100 // Careful: Checking net::GetMimeTypeFromExtension() will only find | 101 // Careful: Checking net::GetMimeTypeFromExtension() will only find |
| 101 // extensions with a known MIME type, which many "known" extensions on Windows | 102 // extensions with a known MIME type, which many "known" extensions on Windows |
| 102 // don't have. So we check directly for the "known extension" registry key. | 103 // don't have. So we check directly for the "known extension" registry key. |
| 103 std::wstring file_extension( | 104 std::wstring file_extension( |
| 104 GetExtensionWithoutLeadingDot(FilePath(filename).Extension())); | 105 GetExtensionWithoutLeadingDot(FilePath(filename).Extension())); |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 } | 850 } |
| 850 } | 851 } |
| 851 return success; | 852 return success; |
| 852 } | 853 } |
| 853 | 854 |
| 854 // static | 855 // static |
| 855 SelectFileDialog* SelectFileDialog::Create(Listener* listener, | 856 SelectFileDialog* SelectFileDialog::Create(Listener* listener, |
| 856 ui::SelectFilePolicy* policy) { | 857 ui::SelectFilePolicy* policy) { |
| 857 return new SelectFileDialogImpl(listener, policy); | 858 return new SelectFileDialogImpl(listener, policy); |
| 858 } | 859 } |
| OLD | NEW |