2757472: Reland "Reland "[LSC] Remove base::string16 alias""

2757472
This commit is contained in:
John Kleinschmidt 2021-03-18 15:55:51 -04:00
parent 3b183854ff
commit 2d3c65beca
31 changed files with 200 additions and 152 deletions

View file

@ -156,7 +156,7 @@ bool NativeImage::TryConvertNativeImage(v8::Isolate* isolate,
*native_image = NativeImage::CreateFromPath(isolate, icon_path).get();
if ((*native_image)->image().IsEmpty()) {
#if defined(OS_WIN)
const auto img_path = base::UTF16ToUTF8(icon_path.value());
const auto img_path = base::WideToUTF8(icon_path.value());
#else
const auto img_path = icon_path.value();
#endif

View file

@ -37,7 +37,7 @@ v8::Local<v8::Promise> NativeImage::CreateThumbnailFromPath(
// create an IShellItem
Microsoft::WRL::ComPtr<IShellItem> pItem;
std::wstring image_path = path.AsUTF16Unsafe();
std::wstring image_path = path.value();
hr = SHCreateItemFromParsingName(image_path.c_str(), nullptr,
IID_PPV_ARGS(&pItem));

View file

@ -117,7 +117,7 @@ bool WriteShortcutLink(const base::FilePath& shortcut_path,
base::win::ShortcutProperties properties;
base::FilePath path;
std::u16string str;
std::wstring str;
UUID toastActivatorClsid;
int index;
if (options.Get("target", &path))

View file

@ -15,6 +15,7 @@
#include "base/file_version_info.h"
#include "base/notreached.h"
#include "base/strings/string_util.h"
#include "base/strings/string_util_win.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "shell/browser/win/scoped_hstring.h"
@ -23,7 +24,7 @@ namespace electron {
namespace {
std::u16string g_app_user_model_id;
std::wstring g_app_user_model_id;
}
const wchar_t kAppUserModelIDFormat[] = L"electron.app.$1";
@ -42,7 +43,7 @@ std::string GetApplicationVersion() {
return base::UTF16ToUTF8(info->product_version());
}
void SetAppUserModelID(const std::u16string& name) {
void SetAppUserModelID(const std::wstring& name) {
g_app_user_model_id = name;
SetCurrentProcessExplicitAppUserModelID(g_app_user_model_id.c_str());
}
@ -54,8 +55,8 @@ PCWSTR GetRawAppUserModelID() {
g_app_user_model_id = current_app_id;
} else {
std::string name = GetApplicationName();
std::u16string generated_app_id = base::ReplaceStringPlaceholders(
kAppUserModelIDFormat, base::UTF8ToUTF16(name), nullptr);
std::wstring generated_app_id = base::ReplaceStringPlaceholders(
kAppUserModelIDFormat, {base::UTF8ToWide(name)}, nullptr);
SetAppUserModelID(generated_app_id);
}
CoTaskMemFree(current_app_id);

View file

@ -7,6 +7,7 @@
#include "base/files/file_path.h"
#include "gin/converter.h"
#include "shell/common/gin_converters/std_converter.h"
namespace gin {

View file

@ -11,6 +11,10 @@
#include "gin/converter.h"
#if defined(OS_WIN)
#include "base/strings/string_util_win.h"
#endif
namespace gin {
// Make it possible to convert move-only types.
@ -182,6 +186,30 @@ struct Converter<std::map<K, V>> {
}
};
#if defined(OS_WIN)
template <>
struct Converter<std::wstring> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const std::wstring& val) {
return Converter<std::u16string>::ToV8(isolate, base::AsString16(val));
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
std::wstring* out) {
if (!val->IsString())
return false;
std::u16string str;
if (Converter<std::u16string>::FromV8(isolate, val, &str)) {
*out = base::AsWString(str);
return true;
} else {
return false;
}
}
};
#endif
} // namespace gin
#endif // SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_

View file

@ -14,11 +14,6 @@ namespace electron {
// overrides from command line arguments.
std::vector<std::string> GetPreferredLanguages();
#if defined(OS_WIN)
bool GetPreferredLanguagesUsingGlobalization(
std::vector<std::u16string>* languages);
#endif
} // namespace electron
#endif // SHELL_COMMON_LANGUAGE_UTIL_H_

View file

@ -16,24 +16,8 @@
namespace electron {
std::vector<std::string> GetPreferredLanguages() {
std::vector<std::u16string> languages16;
// Attempt to use API available on Windows 10 or later, which
// returns the full list of language preferences.
if (!GetPreferredLanguagesUsingGlobalization(&languages16)) {
base::win::i18n::GetThreadPreferredUILanguageList(&languages16);
}
std::vector<std::string> languages;
for (const auto& language : languages16) {
languages.push_back(base::SysWideToUTF8(language));
}
return languages;
}
bool GetPreferredLanguagesUsingGlobalization(
std::vector<std::u16string>* languages) {
std::vector<std::wstring>* languages) {
if (base::win::GetVersion() < base::win::Version::WIN10)
return false;
if (!base::win::ResolveCoreWinRTDelayload() ||
@ -73,4 +57,20 @@ bool GetPreferredLanguagesUsingGlobalization(
return true;
}
std::vector<std::string> GetPreferredLanguages() {
std::vector<std::wstring> languages16;
// Attempt to use API available on Windows 10 or later, which
// returns the full list of language preferences.
if (!GetPreferredLanguagesUsingGlobalization(&languages16)) {
base::win::i18n::GetThreadPreferredUILanguageList(&languages16);
}
std::vector<std::string> languages;
for (const auto& language : languages16) {
languages.push_back(base::SysWideToUTF8(language));
}
return languages;
}
} // namespace electron

View file

@ -214,7 +214,7 @@ void SetNodeCliFlags() {
for (const auto& arg : argv) {
#if defined(OS_WIN)
const auto& option = base::UTF16ToUTF8(arg);
const auto& option = base::WideToUTF8(arg);
#else
const auto& option = arg;
#endif

View file

@ -241,8 +241,8 @@ std::string OpenExternalOnWorkerThread(
// Quote the input scheme to be sure that the command does not have
// parameters unexpected by the external program. This url should already
// have been escaped.
std::u16string escaped_url = L"\"" + base::UTF8ToUTF16(url.spec()) + L"\"";
std::u16string working_dir = options.working_dir.value();
std::wstring escaped_url = L"\"" + base::UTF8ToWide(url.spec()) + L"\"";
std::wstring working_dir = options.working_dir.value();
if (reinterpret_cast<ULONG_PTR>(
ShellExecuteW(nullptr, L"open", escaped_url.c_str(), nullptr,