Commit 0079e15c authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

Remove the usage of std::wstring in ui/shell_dialogs/

Bug: 884075
Change-Id: I7fba4358da8876c591490dd15263f3b669abdaf7
Reviewed-on: https://chromium-review.googlesource.com/c/1277950
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599866}
parent 7e01cd09
...@@ -296,20 +296,20 @@ bool RunOpenMultiFileDialog(HWND owner, ...@@ -296,20 +296,20 @@ bool RunOpenMultiFileDialog(HWND owner,
// '*.something', for example '*.*' or it can be blank (which is treated as // '*.something', for example '*.*' or it can be blank (which is treated as
// *.*). |suggested_ext| should contain the extension without the dot (.) in // *.*). |suggested_ext| should contain the extension without the dot (.) in
// front, for example 'jpg'. // front, for example 'jpg'.
std::wstring AppendExtensionIfNeeded(const std::wstring& filename, base::string16 AppendExtensionIfNeeded(const base::string16& filename,
const std::wstring& filter_selected, const base::string16& filter_selected,
const std::wstring& suggested_ext) { const base::string16& suggested_ext) {
DCHECK(!filename.empty()); DCHECK(!filename.empty());
std::wstring return_value = filename; base::string16 return_value = filename;
// If we wanted a specific extension, but the user's filename deleted it or // If we wanted a specific extension, but the user's filename deleted it or
// changed it to something that the system doesn't understand, re-append. // changed it to something that the system doesn't understand, re-append.
// Careful: Checking net::GetMimeTypeFromExtension() will only find // Careful: Checking net::GetMimeTypeFromExtension() will only find
// extensions with a known MIME type, which many "known" extensions on Windows // extensions with a known MIME type, which many "known" extensions on Windows
// don't have. So we check directly for the "known extension" registry key. // don't have. So we check directly for the "known extension" registry key.
std::wstring file_extension( base::string16 file_extension(
GetExtensionWithoutLeadingDot(base::FilePath(filename).Extension())); GetExtensionWithoutLeadingDot(base::FilePath(filename).Extension()));
std::wstring key(L"." + file_extension); base::string16 key(L"." + file_extension);
if (!(filter_selected.empty() || filter_selected == L"*.*") && if (!(filter_selected.empty() || filter_selected == L"*.*") &&
!base::win::RegKey(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ).Valid() && !base::win::RegKey(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ).Valid() &&
file_extension != suggested_ext) { file_extension != suggested_ext) {
......
...@@ -20,10 +20,10 @@ class FilePath; ...@@ -20,10 +20,10 @@ class FilePath;
namespace ui { namespace ui {
// Implementation detail exported for unit tests. // Implementation detail exported for unit tests.
SHELL_DIALOGS_EXPORT std::wstring AppendExtensionIfNeeded( SHELL_DIALOGS_EXPORT base::string16 AppendExtensionIfNeeded(
const std::wstring& filename, const base::string16& filename,
const std::wstring& filter_selected, const base::string16& filter_selected,
const std::wstring& suggested_ext); const base::string16& suggested_ext);
// Shows the file selection dialog modal to |owner| returns the selected // Shows the file selection dialog modal to |owner| returns the selected
// file(s) and file type index via the return value. The file path vector will // file(s) and file type index via the return value. The file path vector will
......
...@@ -46,7 +46,7 @@ TEST(ShellDialogsWin, AppendExtensionIfNeeded) { ...@@ -46,7 +46,7 @@ TEST(ShellDialogsWin, AppendExtensionIfNeeded) {
for (size_t i = 0; i < base::size(test_cases); ++i) { for (size_t i = 0; i < base::size(test_cases); ++i) {
SCOPED_TRACE(base::StringPrintf("i=%zu", i)); SCOPED_TRACE(base::StringPrintf("i=%zu", i));
EXPECT_EQ(std::wstring(test_cases[i].expected_filename), EXPECT_EQ(base::string16(test_cases[i].expected_filename),
ui::AppendExtensionIfNeeded(test_cases[i].filename, ui::AppendExtensionIfNeeded(test_cases[i].filename,
test_cases[i].filter_selected, test_cases[i].filter_selected,
test_cases[i].suggested_ext)); test_cases[i].suggested_ext));
......
...@@ -36,11 +36,11 @@ namespace { ...@@ -36,11 +36,11 @@ namespace {
// for .txt files, "JPEG Image" for .jpg files, etc. If the registry doesn't // for .txt files, "JPEG Image" for .jpg files, etc. If the registry doesn't
// have an entry for the file type, we return false, true if the description was // have an entry for the file type, we return false, true if the description was
// found. 'file_ext' must be in form ".txt". // found. 'file_ext' must be in form ".txt".
bool GetRegistryDescriptionFromExtension(const std::wstring& file_ext, bool GetRegistryDescriptionFromExtension(const base::string16& file_ext,
std::wstring* reg_description) { base::string16* reg_description) {
DCHECK(reg_description); DCHECK(reg_description);
base::win::RegKey reg_ext(HKEY_CLASSES_ROOT, file_ext.c_str(), KEY_READ); base::win::RegKey reg_ext(HKEY_CLASSES_ROOT, file_ext.c_str(), KEY_READ);
std::wstring reg_app; base::string16 reg_app;
if (reg_ext.ReadValue(NULL, &reg_app) == ERROR_SUCCESS && !reg_app.empty()) { if (reg_ext.ReadValue(NULL, &reg_app) == ERROR_SUCCESS && !reg_app.empty()) {
base::win::RegKey reg_link(HKEY_CLASSES_ROOT, reg_app.c_str(), KEY_READ); base::win::RegKey reg_link(HKEY_CLASSES_ROOT, reg_app.c_str(), KEY_READ);
if (reg_link.ReadValue(NULL, reg_description) == ERROR_SUCCESS) if (reg_link.ReadValue(NULL, reg_description) == ERROR_SUCCESS)
...@@ -65,12 +65,12 @@ bool GetRegistryDescriptionFromExtension(const std::wstring& file_ext, ...@@ -65,12 +65,12 @@ bool GetRegistryDescriptionFromExtension(const std::wstring& file_ext,
// If a description is not provided for a file extension, it will be retrieved // If a description is not provided for a file extension, it will be retrieved
// from the registry. If the file extension does not exist in the registry, it // from the registry. If the file extension does not exist in the registry, it
// will be omitted from the filter, as it is likely a bogus extension. // will be omitted from the filter, as it is likely a bogus extension.
std::wstring FormatFilterForExtensions( base::string16 FormatFilterForExtensions(
const std::vector<std::wstring>& file_ext, const std::vector<base::string16>& file_ext,
const std::vector<std::wstring>& ext_desc, const std::vector<base::string16>& ext_desc,
bool include_all_files) { bool include_all_files) {
const std::wstring all_ext = L"*.*"; const base::string16 all_ext = L"*.*";
const std::wstring all_desc = const base::string16 all_desc =
l10n_util::GetStringUTF16(IDS_APP_SAVEAS_ALL_FILES); l10n_util::GetStringUTF16(IDS_APP_SAVEAS_ALL_FILES);
DCHECK(file_ext.size() >= ext_desc.size()); DCHECK(file_ext.size() >= ext_desc.size());
...@@ -78,11 +78,11 @@ std::wstring FormatFilterForExtensions( ...@@ -78,11 +78,11 @@ std::wstring FormatFilterForExtensions(
if (file_ext.empty()) if (file_ext.empty())
include_all_files = true; include_all_files = true;
std::wstring result; base::string16 result;
for (size_t i = 0; i < file_ext.size(); ++i) { for (size_t i = 0; i < file_ext.size(); ++i) {
std::wstring ext = file_ext[i]; base::string16 ext = file_ext[i];
std::wstring desc; base::string16 desc;
if (i < ext_desc.size()) if (i < ext_desc.size())
desc = ext_desc[i]; desc = ext_desc[i];
...@@ -94,16 +94,16 @@ std::wstring FormatFilterForExtensions( ...@@ -94,16 +94,16 @@ std::wstring FormatFilterForExtensions(
} }
if (desc.empty()) { if (desc.empty()) {
DCHECK(ext.find(L'.') != std::wstring::npos); DCHECK(ext.find(L'.') != base::string16::npos);
std::wstring first_extension = ext.substr(ext.find(L'.')); base::string16 first_extension = ext.substr(ext.find(L'.'));
size_t first_separator_index = first_extension.find(L';'); size_t first_separator_index = first_extension.find(L';');
if (first_separator_index != std::wstring::npos) if (first_separator_index != base::string16::npos)
first_extension = first_extension.substr(0, first_separator_index); first_extension = first_extension.substr(0, first_separator_index);
// Find the extension name without the preceeding '.' character. // Find the extension name without the preceeding '.' character.
std::wstring ext_name = first_extension; base::string16 ext_name = first_extension;
size_t ext_index = ext_name.find_first_not_of(L'.'); size_t ext_index = ext_name.find_first_not_of(L'.');
if (ext_index != std::wstring::npos) if (ext_index != base::string16::npos)
ext_name = ext_name.substr(ext_index); ext_name = ext_name.substr(ext_index);
if (!GetRegistryDescriptionFromExtension(first_extension, &desc)) { if (!GetRegistryDescriptionFromExtension(first_extension, &desc)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment