diff --git a/shell/app/electron_crash_reporter_client.cc b/shell/app/electron_crash_reporter_client.cc index 07fc91e30c..6ad5557f13 100644 --- a/shell/app/electron_crash_reporter_client.cc +++ b/shell/app/electron_crash_reporter_client.cc @@ -33,6 +33,10 @@ #include "base/debug/dump_without_crashing.h" #endif +#if defined(OS_WIN) +#include "base/strings/string_util_win.h" +#endif + namespace { ElectronCrashReporterClient* Instance() { @@ -130,8 +134,8 @@ void ElectronCrashReporterClient::GetProductNameAndVersion( std::wstring* version, std::wstring* special_build, std::wstring* channel_name) { - *product_name = base::UTF8ToUTF16(ELECTRON_PRODUCT_NAME); - *version = base::UTF8ToUTF16(ELECTRON_VERSION_STRING); + *product_name = base::UTF8ToWide(ELECTRON_PRODUCT_NAME); + *version = base::UTF8ToWide(ELECTRON_VERSION_STRING); } #endif diff --git a/shell/app/node_main.cc b/shell/app/node_main.cc index bc0f3f7469..73db4f0e18 100644 --- a/shell/app/node_main.cc +++ b/shell/app/node_main.cc @@ -66,7 +66,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 diff --git a/shell/browser/api/electron_api_base_window.cc b/shell/browser/api/electron_api_base_window.cc index ec3b6f7d22..edd62803e0 100644 --- a/shell/browser/api/electron_api_base_window.cc +++ b/shell/browser/api/electron_api_base_window.cc @@ -1101,8 +1101,10 @@ void BaseWindow::SetAppDetails(const gin_helper::Dictionary& options) { options.Get("relaunchCommand", &relaunch_command); options.Get("relaunchDisplayName", &relaunch_display_name); - ui::win::SetAppDetailsForWindow(app_id, app_icon_path, app_icon_index, - relaunch_command, relaunch_display_name, + ui::win::SetAppDetailsForWindow(base::UTF16ToWide(app_id), app_icon_path, + app_icon_index, + base::UTF16ToWide(relaunch_command), + base::UTF16ToWide(relaunch_display_name), window_->GetAcceleratedWidget()); } #endif diff --git a/shell/browser/api/electron_api_crash_reporter.cc b/shell/browser/api/electron_api_crash_reporter.cc index e0ee029609..bb7c8d6770 100644 --- a/shell/browser/api/electron_api_crash_reporter.cc +++ b/shell/browser/api/electron_api_crash_reporter.cc @@ -175,7 +175,7 @@ void Start(const std::string& submit_url, base::PathService::Get(DIR_USER_DATA, &user_data_dir); ::crash_reporter::InitializeCrashpadWithEmbeddedHandler( process_type.empty(), process_type, - base::UTF16ToUTF8(user_data_dir.value()), base::FilePath()); + base::WideToUTF8(user_data_dir.value()), base::FilePath()); #endif #endif } diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index a56bf717a7..859779fe13 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -418,7 +418,7 @@ bool IsDeviceNameValid(const std::u16string& device_name) { return printer_exists; #elif defined(OS_WIN) printing::ScopedPrinterHandle printer; - return printer.OpenPrinterWithName(device_name.c_str()); + return printer.OpenPrinterWithName(base::UTF16ToWide(device_name).c_str()); #endif return true; } diff --git a/shell/browser/browser.h b/shell/browser/browser.h index b6d1438998..4768196c0a 100755 --- a/shell/browser/browser.h +++ b/shell/browser/browser.h @@ -112,10 +112,10 @@ class Browser : public WindowListObserver { #if defined(OS_WIN) struct LaunchItem { - std::u16string name; - std::u16string path; - std::u16string scope; - std::vector args; + std::wstring name; + std::wstring path; + std::wstring scope; + std::vector args; bool enabled = true; LaunchItem(); @@ -137,7 +137,7 @@ class Browser : public WindowListObserver { #if defined(OS_WIN) // used in browser::setLoginItemSettings bool enabled = true; - std::u16string name = std::u16string(); + std::wstring name = std::wstring(); // used in browser::getLoginItemSettings bool executable_will_launch_at_login = false; @@ -237,9 +237,9 @@ class Browser : public WindowListObserver { #if defined(OS_WIN) struct UserTask { base::FilePath program; - std::u16string arguments; - std::u16string title; - std::u16string description; + std::wstring arguments; + std::wstring title; + std::wstring description; base::FilePath working_dir; base::FilePath icon_path; int icon_index; diff --git a/shell/browser/browser_win.cc b/shell/browser/browser_win.cc index 5014bd5d7b..04519a20d4 100755 --- a/shell/browser/browser_win.cc +++ b/shell/browser/browser_win.cc @@ -48,7 +48,7 @@ namespace electron { namespace { -bool GetProcessExecPath(std::u16string* exe) { +bool GetProcessExecPath(std::wstring* exe) { base::FilePath path; if (!base::PathService::Get(base::FILE_EXE, &path)) { return false; @@ -57,13 +57,13 @@ bool GetProcessExecPath(std::u16string* exe) { return true; } -bool GetProtocolLaunchPath(gin::Arguments* args, std::u16string* exe) { +bool GetProtocolLaunchPath(gin::Arguments* args, std::wstring* exe) { if (!args->GetNext(exe) && !GetProcessExecPath(exe)) { return false; } // Read in optional args arg - std::vector launch_args; + std::vector launch_args; if (args->GetNext(&launch_args) && !launch_args.empty()) *exe = base::StringPrintf(L"\"%ls\" %ls \"%%1\"", exe->c_str(), base::JoinString(launch_args, L" ").c_str()); @@ -75,7 +75,7 @@ bool GetProtocolLaunchPath(gin::Arguments* args, std::u16string* exe) { // Windows treats a given scheme as an Internet scheme only if its registry // entry has a "URL Protocol" key. Check this, otherwise we allow ProgIDs to be // used as custom protocols which leads to security bugs. -bool IsValidCustomProtocol(const std::u16string& scheme) { +bool IsValidCustomProtocol(const std::wstring& scheme) { if (scheme.empty()) return false; base::win::RegKey cmd_key(HKEY_CLASSES_ROOT, scheme.c_str(), KEY_QUERY_VALUE); @@ -90,11 +90,10 @@ bool IsValidCustomProtocol(const std::u16string& scheme) { // Windows 8 introduced a new protocol->executable binding system which cannot // be retrieved in the HKCR registry subkey method implemented below. We call // AssocQueryString with the new Win8-only flag ASSOCF_IS_PROTOCOL instead. -std::u16string GetAppInfoHelperForProtocol(ASSOCSTR assoc_str, - const GURL& url) { - const std::u16string url_scheme = base::ASCIIToUTF16(url.scheme()); +std::wstring GetAppInfoHelperForProtocol(ASSOCSTR assoc_str, const GURL& url) { + const std::wstring url_scheme = base::ASCIIToWide(url.scheme()); if (!IsValidCustomProtocol(url_scheme)) - return std::u16string(); + return std::wstring(); wchar_t out_buffer[1024]; DWORD buffer_size = base::size(out_buffer); @@ -103,13 +102,13 @@ std::u16string GetAppInfoHelperForProtocol(ASSOCSTR assoc_str, out_buffer, &buffer_size); if (FAILED(hr)) { DLOG(WARNING) << "AssocQueryString failed!"; - return std::u16string(); + return std::wstring(); } - return std::u16string(out_buffer); + return std::wstring(out_buffer); } void OnIconDataAvailable(const base::FilePath& app_path, - const std::u16string& app_display_name, + const std::wstring& app_display_name, gin_helper::Promise promise, gfx::Image icon) { if (!icon.IsEmpty()) { @@ -126,21 +125,21 @@ void OnIconDataAvailable(const base::FilePath& app_path, } } -std::u16string GetAppDisplayNameForProtocol(const GURL& url) { +std::wstring GetAppDisplayNameForProtocol(const GURL& url) { return GetAppInfoHelperForProtocol(ASSOCSTR_FRIENDLYAPPNAME, url); } -std::u16string GetAppPathForProtocol(const GURL& url) { +std::wstring GetAppPathForProtocol(const GURL& url) { return GetAppInfoHelperForProtocol(ASSOCSTR_EXECUTABLE, url); } -std::u16string GetAppForProtocolUsingRegistry(const GURL& url) { - const std::u16string url_scheme = base::ASCIIToUTF16(url.scheme()); +std::wstring GetAppForProtocolUsingRegistry(const GURL& url) { + const std::wstring url_scheme = base::ASCIIToWide(url.scheme()); if (!IsValidCustomProtocol(url_scheme)) - return std::u16string(); + return std::wstring(); // First, try and extract the application's display name. - std::u16string command_to_launch; + std::wstring command_to_launch; base::win::RegKey cmd_key_name(HKEY_CLASSES_ROOT, url_scheme.c_str(), KEY_READ); if (cmd_key_name.ReadValue(NULL, &command_to_launch) == ERROR_SUCCESS && @@ -150,7 +149,7 @@ std::u16string GetAppForProtocolUsingRegistry(const GURL& url) { // Otherwise, parse the command line in the registry, and return the basename // of the program path if it exists. - const std::u16string cmd_key_path = url_scheme + L"\\shell\\open\\command"; + const std::wstring cmd_key_path = url_scheme + L"\\shell\\open\\command"; base::win::RegKey cmd_key_exe(HKEY_CLASSES_ROOT, cmd_key_path.c_str(), KEY_READ); if (cmd_key_exe.ReadValue(NULL, &command_to_launch) == ERROR_SUCCESS) { @@ -159,18 +158,20 @@ std::u16string GetAppForProtocolUsingRegistry(const GURL& url) { return command_line.GetProgram().BaseName().value(); } - return std::u16string(); + return std::wstring(); } -bool FormatCommandLineString(std::u16string* exe, +bool FormatCommandLineString(std::wstring* exe, const std::vector& launch_args) { if (exe->empty() && !GetProcessExecPath(exe)) { return false; } if (!launch_args.empty()) { + std::u16string joined_launch_args = + base::JoinString(launch_args, base::UTF8ToUTF16(" ")); *exe = base::StringPrintf(L"%ls %ls", exe->c_str(), - base::JoinString(launch_args, L" ").c_str()); + base::UTF16ToWide(joined_launch_args).c_str()); } return true; @@ -184,18 +185,20 @@ bool FormatCommandLineString(std::u16string* exe, std::vector GetLoginItemSettingsHelper( base::win::RegistryValueIterator* it, boolean* executable_will_launch_at_login, - std::u16string scope, + std::wstring scope, const Browser::LoginItemSettings& options) { std::vector launch_items; base::FilePath lookup_exe_path; if (options.path.empty()) { - std::u16string process_exe_path; + std::wstring process_exe_path; GetProcessExecPath(&process_exe_path); lookup_exe_path = base::CommandLine::FromString(process_exe_path).GetProgram(); } else { - lookup_exe_path = base::CommandLine::FromString(options.path).GetProgram(); + lookup_exe_path = + base::CommandLine::FromString(base::UTF16ToWide(options.path)) + .GetProgram(); } if (!lookup_exe_path.empty()) { @@ -287,7 +290,7 @@ Browser::UserTask::~UserTask() = default; void GetFileIcon(const base::FilePath& path, v8::Isolate* isolate, base::CancelableTaskTracker* cancelable_task_tracker_, - const std::u16string app_display_name, + const std::wstring app_display_name, gin_helper::Promise promise) { base::FilePath normalized_path = path.NormalizePathSeparators(); IconLoader::IconSize icon_size = IconLoader::IconSize::LARGE; @@ -316,13 +319,13 @@ void GetApplicationInfoForProtocolUsingRegistry( base::CancelableTaskTracker* cancelable_task_tracker_) { base::FilePath app_path; - const std::u16string url_scheme = base::ASCIIToUTF16(url.scheme()); + const std::wstring url_scheme = base::ASCIIToWide(url.scheme()); if (!IsValidCustomProtocol(url_scheme)) { promise.RejectWithErrorMessage("invalid url_scheme"); return; } - std::u16string command_to_launch; - const std::u16string cmd_key_path = url_scheme + L"\\shell\\open\\command"; + std::wstring command_to_launch; + const std::wstring cmd_key_path = url_scheme + L"\\shell\\open\\command"; base::win::RegKey cmd_key_exe(HKEY_CLASSES_ROOT, cmd_key_path.c_str(), KEY_READ); if (cmd_key_exe.ReadValue(NULL, &command_to_launch) == ERROR_SUCCESS) { @@ -334,7 +337,7 @@ void GetApplicationInfoForProtocolUsingRegistry( "Unable to retrieve installation path to app"); return; } - const std::u16string app_display_name = GetAppForProtocolUsingRegistry(url); + const std::wstring app_display_name = GetAppForProtocolUsingRegistry(url); if (app_display_name.empty()) { promise.RejectWithErrorMessage( @@ -354,7 +357,7 @@ void GetApplicationInfoForProtocolUsingAssocQuery( const GURL& url, gin_helper::Promise promise, base::CancelableTaskTracker* cancelable_task_tracker_) { - std::u16string app_path = GetAppPathForProtocol(url); + std::wstring app_path = GetAppPathForProtocol(url); if (app_path.empty()) { promise.RejectWithErrorMessage( @@ -362,7 +365,7 @@ void GetApplicationInfoForProtocolUsingAssocQuery( return; } - std::u16string app_display_name = GetAppDisplayNameForProtocol(url); + std::wstring app_display_name = GetAppDisplayNameForProtocol(url); if (app_display_name.empty()) { promise.RejectWithErrorMessage("Unable to retrieve display name of app"); @@ -426,12 +429,12 @@ bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol, // Main Registry Key HKEY root = HKEY_CURRENT_USER; - std::u16string keyPath = L"Software\\Classes\\"; + std::wstring keyPath = L"Software\\Classes\\"; // Command Key - std::u16string wprotocol = base::UTF8ToUTF16(protocol); - std::u16string shellPath = wprotocol + L"\\shell"; - std::u16string cmdPath = keyPath + shellPath + L"\\open\\command"; + std::wstring wprotocol = base::UTF8ToWide(protocol); + std::wstring shellPath = wprotocol + L"\\shell"; + std::wstring cmdPath = keyPath + shellPath + L"\\open\\command"; base::win::RegKey classesKey; base::win::RegKey commandKey; @@ -445,12 +448,12 @@ bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol, // Key doesn't even exist, we can confirm that it is not set return true; - std::u16string keyVal; + std::wstring keyVal; if (FAILED(commandKey.ReadValue(L"", &keyVal))) // Default value not set, we can confirm that it is not set return true; - std::u16string exe; + std::wstring exe; if (!GetProtocolLaunchPath(args, &exe)) return false; @@ -461,7 +464,7 @@ bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol, // Let's clean up after ourselves base::win::RegKey protocolKey; - std::u16string protocolPath = keyPath + wprotocol; + std::wstring protocolPath = keyPath + wprotocol; if (SUCCEEDED( protocolKey.Open(root, protocolPath.c_str(), KEY_ALL_ACCESS))) { @@ -500,17 +503,17 @@ bool Browser::SetAsDefaultProtocolClient(const std::string& protocol, if (protocol.empty()) return false; - std::u16string exe; + std::wstring exe; if (!GetProtocolLaunchPath(args, &exe)) return false; // Main Registry Key HKEY root = HKEY_CURRENT_USER; - std::u16string keyPath = base::UTF8ToUTF16("Software\\Classes\\" + protocol); - std::u16string urlDecl = base::UTF8ToUTF16("URL:" + protocol); + std::wstring keyPath = base::UTF8ToWide("Software\\Classes\\" + protocol); + std::wstring urlDecl = base::UTF8ToWide("URL:" + protocol); // Command Key - std::u16string cmdPath = keyPath + L"\\shell\\open\\command"; + std::wstring cmdPath = keyPath + L"\\shell\\open\\command"; // Write information to registry base::win::RegKey key(root, keyPath.c_str(), KEY_ALL_ACCESS); @@ -530,16 +533,16 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol, if (protocol.empty()) return false; - std::u16string exe; + std::wstring exe; if (!GetProtocolLaunchPath(args, &exe)) return false; // Main Registry Key HKEY root = HKEY_CURRENT_USER; - std::u16string keyPath = base::UTF8ToUTF16("Software\\Classes\\" + protocol); + std::wstring keyPath = base::UTF8ToWide("Software\\Classes\\" + protocol); // Command Key - std::u16string cmdPath = keyPath + L"\\shell\\open\\command"; + std::wstring cmdPath = keyPath + L"\\shell\\open\\command"; base::win::RegKey key; base::win::RegKey commandKey; @@ -551,7 +554,7 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol, // Key doesn't exist, we can confirm that it is not set return false; - std::u16string keyVal; + std::wstring keyVal; if (FAILED(commandKey.ReadValue(L"", &keyVal))) // Default value not set, we can confirm that it is not set return false; @@ -563,12 +566,12 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol, std::u16string Browser::GetApplicationNameForProtocol(const GURL& url) { // Windows 8 or above has a new protocol association query. if (base::win::GetVersion() >= base::win::Version::WIN8) { - std::u16string application_name = GetAppDisplayNameForProtocol(url); + std::wstring application_name = GetAppDisplayNameForProtocol(url); if (!application_name.empty()) - return application_name; + return base::WideToUTF16(application_name); } - return GetAppForProtocolUsingRegistry(url); + return base::WideToUTF16(GetAppForProtocolUsingRegistry(url)); } v8::Local Browser::GetApplicationInfoForProtocol( @@ -686,11 +689,10 @@ void Browser::UpdateBadgeContents( } void Browser::SetLoginItemSettings(LoginItemSettings settings) { - std::u16string key_path = - L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; + std::wstring key_path = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; base::win::RegKey key(HKEY_CURRENT_USER, key_path.c_str(), KEY_ALL_ACCESS); - std::u16string startup_approved_key_path = + std::wstring startup_approved_key_path = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved" L"\\Run"; base::win::RegKey startup_approved_key( @@ -699,7 +701,7 @@ void Browser::SetLoginItemSettings(LoginItemSettings settings) { !settings.name.empty() ? settings.name.c_str() : GetAppUserModelID(); if (settings.open_at_login) { - std::u16string exe = settings.path; + std::wstring exe = base::UTF16ToWide(settings.path); if (FormatCommandLineString(&exe, settings.args)) { key.WriteValue(key_name, exe.c_str()); @@ -732,13 +734,13 @@ void Browser::SetLoginItemSettings(LoginItemSettings settings) { Browser::LoginItemSettings Browser::GetLoginItemSettings( const LoginItemSettings& options) { LoginItemSettings settings; - std::u16string keyPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; + std::wstring keyPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; base::win::RegKey key(HKEY_CURRENT_USER, keyPath.c_str(), KEY_ALL_ACCESS); - std::u16string keyVal; + std::wstring keyVal; // keep old openAtLogin behaviour if (!FAILED(key.ReadValue(GetAppUserModelID(), &keyVal))) { - std::u16string exe = options.path; + std::wstring exe = base::UTF16ToWide(options.path); if (FormatCommandLineString(&exe, options.args)) { settings.open_at_login = keyVal == exe; } diff --git a/shell/browser/electron_browser_client.cc b/shell/browser/electron_browser_client.cc index 7efd0359ac..95afaf080f 100644 --- a/shell/browser/electron_browser_client.cc +++ b/shell/browser/electron_browser_client.cc @@ -920,7 +920,7 @@ ElectronBrowserClient::CreateWindowForPictureInPicture( content::PictureInPictureWindowController* controller) { auto overlay_window = content::OverlayWindow::Create(controller); #if defined(OS_WIN) - std::u16string app_user_model_id = Browser::Get()->GetAppUserModelID(); + std::wstring app_user_model_id = Browser::Get()->GetAppUserModelID(); if (!app_user_model_id.empty()) { auto* overlay_window_view = static_cast(overlay_window.get()); diff --git a/shell/browser/notifications/win/notification_presenter_win.cc b/shell/browser/notifications/win/notification_presenter_win.cc index f74a26aef5..e1f7fbdf3a 100644 --- a/shell/browser/notifications/win/notification_presenter_win.cc +++ b/shell/browser/notifications/win/notification_presenter_win.cc @@ -72,7 +72,7 @@ bool NotificationPresenterWin::Init() { return temp_dir_.CreateUniqueTempDir(); } -std::u16string NotificationPresenterWin::SaveIconToFilesystem( +std::wstring NotificationPresenterWin::SaveIconToFilesystem( const SkBitmap& icon, const GURL& origin) { std::string filename; @@ -85,12 +85,12 @@ std::u16string NotificationPresenterWin::SaveIconToFilesystem( } base::ThreadRestrictions::ScopedAllowIO allow_io; - base::FilePath path = temp_dir_.GetPath().Append(base::UTF8ToUTF16(filename)); + base::FilePath path = temp_dir_.GetPath().Append(base::UTF8ToWide(filename)); if (base::PathExists(path)) return path.value(); if (SaveIconToPath(icon, path)) return path.value(); - return base::UTF8ToUTF16(origin.spec()); + return base::UTF8ToWide(origin.spec()); } Notification* NotificationPresenterWin::CreateNotificationObject( diff --git a/shell/browser/notifications/win/notification_presenter_win.h b/shell/browser/notifications/win/notification_presenter_win.h index 58d9cc3819..670cfd6db2 100644 --- a/shell/browser/notifications/win/notification_presenter_win.h +++ b/shell/browser/notifications/win/notification_presenter_win.h @@ -38,7 +38,7 @@ class NotificationPresenterWin : public NotificationPresenter { bool Init(); - std::u16string SaveIconToFilesystem(const SkBitmap& icon, const GURL& origin); + std::wstring SaveIconToFilesystem(const SkBitmap& icon, const GURL& origin); private: Notification* CreateNotificationObject( diff --git a/shell/browser/notifications/win/win32_notification.cc b/shell/browser/notifications/win/win32_notification.cc index 2b04f09eb7..b0cdaeb72d 100644 --- a/shell/browser/notifications/win/win32_notification.cc +++ b/shell/browser/notifications/win/win32_notification.cc @@ -13,6 +13,7 @@ #include #include +#include "base/strings/utf_string_conversions.h" #include "third_party/skia/include/core/SkBitmap.h" namespace electron { @@ -49,13 +50,15 @@ void Win32Notification::Show(const NotificationOptions& options) { existing->tag_.clear(); this->notification_ref_ = std::move(existing->notification_ref_); - this->notification_ref_.Set(options.title, options.msg, image); + this->notification_ref_.Set(base::UTF16ToWide(options.title), + base::UTF16ToWide(options.msg), image); // Need to remove the entry in the notifications set that // NotificationPresenter is holding existing->Destroy(); } else { this->notification_ref_ = - presenter->AddNotification(options.title, options.msg, image); + presenter->AddNotification(base::UTF16ToWide(options.title), + base::UTF16ToWide(options.msg), image); } this->tag_ = options.tag; diff --git a/shell/browser/notifications/win/windows_toast_notification.cc b/shell/browser/notifications/win/windows_toast_notification.cc index 4f07915185..2ece87ae91 100644 --- a/shell/browser/notifications/win/windows_toast_notification.cc +++ b/shell/browser/notifications/win/windows_toast_notification.cc @@ -21,7 +21,7 @@ #include "shell/browser/notifications/win/notification_presenter_win.h" #include "shell/browser/win/scoped_hstring.h" #include "shell/common/application_info.h" -#include "ui/base/l10n/l10n_util.h" +#include "ui/base/l10n/l10n_util_win.h" #include "ui/strings/grit/ui_strings.h" using ABI::Windows::Data::Xml::Dom::IXmlAttribute; @@ -132,15 +132,18 @@ HRESULT WindowsToastNotification::ShowInternal( // The custom xml takes priority over the preset template. if (!options.toast_xml.empty()) { REPORT_AND_RETURN_IF_FAILED( - XmlDocumentFromString(options.toast_xml.c_str(), &toast_xml), + XmlDocumentFromString(base::UTF16ToWide(options.toast_xml).c_str(), + &toast_xml), "XML: Invalid XML"); } else { auto* presenter_win = static_cast(presenter()); std::wstring icon_path = presenter_win->SaveIconToFilesystem(options.icon, options.icon_url); REPORT_AND_RETURN_IF_FAILED( - GetToastXml(toast_manager_.Get(), options.title, options.msg, icon_path, - options.timeout_type, options.silent, &toast_xml), + GetToastXml(toast_manager_.Get(), base::UTF16ToWide(options.title), + base::UTF16ToWide(options.msg), icon_path, + base::UTF16ToWide(options.timeout_type), options.silent, + &toast_xml), "XML: Failed to create XML document"); } @@ -211,7 +214,7 @@ HRESULT WindowsToastNotification::GetToastXml( } // Configure the toast's timeout settings - if (timeout_type == base::ASCIIToUTF16("never")) { + if (timeout_type == base::ASCIIToWide("never")) { REPORT_AND_RETURN_IF_FAILED( (SetXmlScenarioReminder(*toast_xml)), "XML: Setting \"scenario\" option on notification failed"); @@ -379,7 +382,7 @@ HRESULT WindowsToastNotification::SetXmlScenarioReminder(IXmlDocument* doc) { RETURN_IF_FAILED(content_attribute.As(&content_attribute_node)); // Set content attribute to Dismiss - ScopedHString content_value(l10n_util::GetStringUTF16(IDS_APP_CLOSE)); + ScopedHString content_value(l10n_util::GetWideString(IDS_APP_CLOSE)); if (!content_value.success()) return E_FAIL; diff --git a/shell/browser/ui/file_dialog_win.cc b/shell/browser/ui/file_dialog_win.cc index 931e0346e3..ddf3660ba6 100644 --- a/shell/browser/ui/file_dialog_win.cc +++ b/shell/browser/ui/file_dialog_win.cc @@ -118,10 +118,10 @@ static void ApplySettings(IFileDialog* dialog, const DialogSettings& settings) { dialog->SetFileName(file_part.c_str()); if (!settings.title.empty()) - dialog->SetTitle(base::UTF8ToUTF16(settings.title).c_str()); + dialog->SetTitle(base::UTF8ToWide(settings.title).c_str()); if (!settings.button_label.empty()) - dialog->SetOkButtonLabel(base::UTF8ToUTF16(settings.button_label).c_str()); + dialog->SetOkButtonLabel(base::UTF8ToWide(settings.button_label).c_str()); std::vector buffer; std::vector filterspec; diff --git a/shell/browser/ui/message_box_win.cc b/shell/browser/ui/message_box_win.cc index 2e5751e723..0fffbd8bc0 100644 --- a/shell/browser/ui/message_box_win.cc +++ b/shell/browser/ui/message_box_win.cc @@ -39,8 +39,8 @@ struct CommonButtonID { int button; int id; }; -CommonButtonID GetCommonID(const std::u16string& button) { - std::u16string lower = base::ToLowerASCII(button); +CommonButtonID GetCommonID(const std::wstring& button) { + std::wstring lower = base::ToLowerASCII(button); if (lower == L"ok") return {TDCBF_OK_BUTTON, IDOK}; else if (lower == L"yes") @@ -63,15 +63,15 @@ void MapToCommonID(const std::vector& buttons, TASKDIALOG_COMMON_BUTTON_FLAGS* button_flags, std::vector* dialog_buttons) { for (size_t i = 0; i < buttons.size(); ++i) { - auto common = GetCommonID(buttons[i]); + auto common = GetCommonID(base::UTF16ToWide(buttons[i])); if (common.button != -1) { // It is a common button. (*id_map)[common.id] = i; (*button_flags) |= common.button; } else { // It is a custom button. - dialog_buttons->push_back( - {static_cast(i + kIDStart), buttons[i].c_str()}); + dialog_buttons->push_back({static_cast(i + kIDStart), + base::UTF16ToWide(buttons[i]).c_str()}); } } } @@ -107,11 +107,11 @@ DialogResult ShowTaskDialogUTF16(NativeWindow* parent, // TaskDialogIndirect doesn't allow empty name, if we set empty title it // will show "electron.exe" in title. - std::u16string app_name = base::UTF8ToUTF16(Browser::Get()->GetName()); + std::wstring app_name = base::UTF8ToWide(Browser::Get()->GetName()); if (title.empty()) config.pszWindowTitle = app_name.c_str(); else - config.pszWindowTitle = title.c_str(); + config.pszWindowTitle = base::UTF16ToWide(title).c_str(); base::win::ScopedHICON hicon; if (!icon.isNull()) { @@ -138,14 +138,14 @@ DialogResult ShowTaskDialogUTF16(NativeWindow* parent, // If "detail" is empty then don't make message highlighted. if (detail.empty()) { - config.pszContent = message.c_str(); + config.pszContent = base::UTF16ToWide(message).c_str(); } else { - config.pszMainInstruction = message.c_str(); - config.pszContent = detail.c_str(); + config.pszMainInstruction = base::UTF16ToWide(message).c_str(); + config.pszContent = base::UTF16ToWide(detail).c_str(); } if (!checkbox_label.empty()) { - config.pszVerificationText = checkbox_label.c_str(); + config.pszVerificationText = base::UTF16ToWide(checkbox_label).c_str(); if (checkbox_checked) config.dwFlags |= TDF_VERIFICATION_FLAG_CHECKED; } @@ -156,8 +156,8 @@ DialogResult ShowTaskDialogUTF16(NativeWindow* parent, std::vector dialog_buttons; if (no_link) { for (size_t i = 0; i < buttons.size(); ++i) - dialog_buttons.push_back( - {static_cast(i + kIDStart), buttons[i].c_str()}); + dialog_buttons.push_back({static_cast(i + kIDStart), + base::UTF16ToWide(buttons[i]).c_str()}); } else { MapToCommonID(buttons, &id_map, &config.dwCommonButtons, &dialog_buttons); } @@ -222,7 +222,8 @@ void ShowMessageBox(const MessageBoxSettings& settings, void ShowErrorBox(const std::u16string& title, const std::u16string& content) { electron::UnresponsiveSuppressor suppressor; ShowTaskDialogUTF16(nullptr, MessageBoxType::kError, {}, -1, 0, false, - L"Error", title, content, L"", false, gfx::ImageSkia()); + base::UTF8ToUTF16("Error"), title, content, + base::UTF8ToUTF16(""), false, gfx::ImageSkia()); } } // namespace electron diff --git a/shell/browser/ui/win/jump_list.cc b/shell/browser/ui/win/jump_list.cc index 22d72b6e9b..ecea78b1fa 100644 --- a/shell/browser/ui/win/jump_list.cc +++ b/shell/browser/ui/win/jump_list.cc @@ -158,7 +158,7 @@ JumpListCategory::JumpListCategory() = default; JumpListCategory::JumpListCategory(const JumpListCategory&) = default; JumpListCategory::~JumpListCategory() = default; -JumpList::JumpList(const std::u16string& app_id) : app_id_(app_id) { +JumpList::JumpList(const std::wstring& app_id) : app_id_(app_id) { destinations_.CoCreateInstance(CLSID_DestinationList); } diff --git a/shell/browser/ui/win/jump_list.h b/shell/browser/ui/win/jump_list.h index ae202dbc35..9bed90477f 100644 --- a/shell/browser/ui/win/jump_list.h +++ b/shell/browser/ui/win/jump_list.h @@ -46,9 +46,9 @@ struct JumpListItem { // For tasks this is the path to the program executable, for file links this // is the full filename. base::FilePath path; - std::u16string arguments; - std::u16string title; - std::u16string description; + std::wstring arguments; + std::wstring title; + std::wstring description; base::FilePath working_dir; base::FilePath icon_path; int icon_index = 0; @@ -73,7 +73,7 @@ struct JumpListCategory { }; Type type = Type::kTasks; - std::u16string name; + std::wstring name; std::vector items; JumpListCategory(); @@ -88,7 +88,7 @@ class JumpList { // |app_id| must be the Application User Model ID of the app for which the // custom Jump List should be created/removed, it's usually obtained by // calling GetCurrentProcessExplicitAppUserModelID(). - explicit JumpList(const std::u16string& app_id); + explicit JumpList(const std::wstring& app_id); ~JumpList(); // Starts a new transaction, must be called before appending any categories, @@ -111,7 +111,7 @@ class JumpList { const std::vector& categories); private: - std::u16string app_id_; + std::wstring app_id_; CComPtr destinations_; DISALLOW_COPY_AND_ASSIGN(JumpList); diff --git a/shell/browser/ui/win/notify_icon.cc b/shell/browser/ui/win/notify_icon.cc index 405c599481..aff97784f4 100644 --- a/shell/browser/ui/win/notify_icon.cc +++ b/shell/browser/ui/win/notify_icon.cc @@ -141,7 +141,7 @@ void NotifyIcon::SetToolTip(const std::string& tool_tip) { NOTIFYICONDATA icon_data; InitIconData(&icon_data); icon_data.uFlags |= NIF_TIP; - wcsncpy_s(icon_data.szTip, base::UTF8ToUTF16(tool_tip).c_str(), _TRUNCATE); + wcsncpy_s(icon_data.szTip, base::UTF8ToWide(tool_tip).c_str(), _TRUNCATE); BOOL result = Shell_NotifyIcon(NIM_MODIFY, &icon_data); if (!result) LOG(WARNING) << "Unable to set tooltip for status tray icon"; @@ -151,8 +151,10 @@ void NotifyIcon::DisplayBalloon(const BalloonOptions& options) { NOTIFYICONDATA icon_data; InitIconData(&icon_data); icon_data.uFlags |= NIF_INFO; - wcsncpy_s(icon_data.szInfoTitle, options.title.c_str(), _TRUNCATE); - wcsncpy_s(icon_data.szInfo, options.content.c_str(), _TRUNCATE); + wcsncpy_s(icon_data.szInfoTitle, base::UTF16ToWide(options.title).c_str(), + _TRUNCATE); + wcsncpy_s(icon_data.szInfo, base::UTF16ToWide(options.content).c_str(), + _TRUNCATE); icon_data.uTimeout = 0; icon_data.hBalloonIcon = options.icon; icon_data.dwInfoFlags = ConvertIconType(options.icon_type); diff --git a/shell/browser/ui/win/taskbar_host.cc b/shell/browser/ui/win/taskbar_host.cc index 272cc2fc98..32fd515113 100644 --- a/shell/browser/ui/win/taskbar_host.cc +++ b/shell/browser/ui/win/taskbar_host.cc @@ -104,7 +104,7 @@ bool TaskbarHost::SetThumbarButtons(HWND window, // Set tooltip. if (!button.tooltip.empty()) { thumb_button.dwMask |= THB_TOOLTIP; - wcsncpy_s(thumb_button.szTip, base::UTF8ToUTF16(button.tooltip).c_str(), + wcsncpy_s(thumb_button.szTip, base::UTF8ToWide(button.tooltip).c_str(), _TRUNCATE); } @@ -173,7 +173,7 @@ bool TaskbarHost::SetOverlayIcon(HWND window, base::win::ScopedHICON icon(IconUtil::CreateHICONFromSkBitmap(overlay)); return SUCCEEDED(taskbar_->SetOverlayIcon(window, icon.get(), - base::UTF8ToUTF16(text).c_str())); + base::UTF8ToWide(text).c_str())); } bool TaskbarHost::SetThumbnailClip(HWND window, const gfx::Rect& region) { @@ -193,8 +193,8 @@ bool TaskbarHost::SetThumbnailToolTip(HWND window, const std::string& tooltip) { if (!InitializeTaskbar()) return false; - return SUCCEEDED(taskbar_->SetThumbnailTooltip( - window, base::UTF8ToUTF16(tooltip).c_str())); + return SUCCEEDED( + taskbar_->SetThumbnailTooltip(window, base::UTF8ToWide(tooltip).c_str())); } bool TaskbarHost::HandleThumbarButtonEvent(int button_id) { diff --git a/shell/browser/web_contents_preferences.cc b/shell/browser/web_contents_preferences.cc index 20317bfd6d..d609da0296 100644 --- a/shell/browser/web_contents_preferences.cc +++ b/shell/browser/web_contents_preferences.cc @@ -235,18 +235,24 @@ bool WebContentsPreferences::GetPreference(base::StringPiece name, bool WebContentsPreferences::GetPreloadPath(base::FilePath* path) const { DCHECK(path); base::FilePath::StringType preload_path; - if (GetAsString(&preference_, options::kPreloadScript, &preload_path)) { - base::FilePath preload(preload_path); + std::u16string preload_path_str; + if (GetAsString(&preference_, options::kPreloadScript, &preload_path_str)) { +#if defined(OS_WIN) + base::FilePath preload(base::UTF16ToWide(preload_path_str)); +#else + base::FilePath preload(preload_path_str); +#endif if (preload.IsAbsolute()) { *path = std::move(preload); return true; } else { LOG(ERROR) << "preload script must have absolute path."; } - } else if (GetAsString(&preference_, options::kPreloadURL, &preload_path)) { + } else if (GetAsString(&preference_, options::kPreloadURL, + &preload_path_str)) { // Translate to file path if there is "preload-url" option. base::FilePath preload; - if (net::FileURLToFilePath(GURL(preload_path), &preload)) { + if (net::FileURLToFilePath(GURL(preload_path_str), &preload)) { *path = std::move(preload); return true; } else { diff --git a/shell/browser/web_dialog_helper.cc b/shell/browser/web_dialog_helper.cc index 976eaedeb9..8146b7e055 100644 --- a/shell/browser/web_dialog_helper.cc +++ b/shell/browser/web_dialog_helper.cc @@ -86,7 +86,7 @@ file_dialog::Filters GetFileTypesFromAcceptType( for (const auto& extension : extensions) { #if defined(OS_WIN) - filters[0].second.push_back(base::UTF16ToASCII(extension)); + filters[0].second.push_back(base::WideToASCII(extension)); #else filters[0].second.push_back(extension); #endif diff --git a/shell/common/api/electron_api_native_image.cc b/shell/common/api/electron_api_native_image.cc index 98fe8d9044..d1e7ce6c00 100644 --- a/shell/common/api/electron_api_native_image.cc +++ b/shell/common/api/electron_api_native_image.cc @@ -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 diff --git a/shell/common/api/electron_api_native_image_win.cc b/shell/common/api/electron_api_native_image_win.cc index 23f24e30b3..455b702f23 100644 --- a/shell/common/api/electron_api_native_image_win.cc +++ b/shell/common/api/electron_api_native_image_win.cc @@ -37,7 +37,7 @@ v8::Local NativeImage::CreateThumbnailFromPath( // create an IShellItem Microsoft::WRL::ComPtr pItem; - std::wstring image_path = path.AsUTF16Unsafe(); + std::wstring image_path = path.value(); hr = SHCreateItemFromParsingName(image_path.c_str(), nullptr, IID_PPV_ARGS(&pItem)); diff --git a/shell/common/api/electron_api_shell.cc b/shell/common/api/electron_api_shell.cc index 1679afe5ec..a6222f7f7e 100644 --- a/shell/common/api/electron_api_shell.cc +++ b/shell/common/api/electron_api_shell.cc @@ -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)) diff --git a/shell/common/application_info_win.cc b/shell/common/application_info_win.cc index f900a193a2..c6af65fd19 100644 --- a/shell/common/application_info_win.cc +++ b/shell/common/application_info_win.cc @@ -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); diff --git a/shell/common/gin_converters/file_path_converter.h b/shell/common/gin_converters/file_path_converter.h index 3136222955..28d5c4bfda 100644 --- a/shell/common/gin_converters/file_path_converter.h +++ b/shell/common/gin_converters/file_path_converter.h @@ -7,6 +7,7 @@ #include "base/files/file_path.h" #include "gin/converter.h" +#include "shell/common/gin_converters/std_converter.h" namespace gin { diff --git a/shell/common/gin_converters/std_converter.h b/shell/common/gin_converters/std_converter.h index 7a4240b621..fef3cd26fa 100644 --- a/shell/common/gin_converters/std_converter.h +++ b/shell/common/gin_converters/std_converter.h @@ -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> { } }; +#if defined(OS_WIN) +template <> +struct Converter { + static v8::Local ToV8(v8::Isolate* isolate, + const std::wstring& val) { + return Converter::ToV8(isolate, base::AsString16(val)); + } + static bool FromV8(v8::Isolate* isolate, + v8::Local val, + std::wstring* out) { + if (!val->IsString()) + return false; + + std::u16string str; + if (Converter::FromV8(isolate, val, &str)) { + *out = base::AsWString(str); + return true; + } else { + return false; + } + } +}; +#endif + } // namespace gin #endif // SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_ diff --git a/shell/common/language_util.h b/shell/common/language_util.h index 6f15cc6802..eac23ad4ed 100644 --- a/shell/common/language_util.h +++ b/shell/common/language_util.h @@ -14,11 +14,6 @@ namespace electron { // overrides from command line arguments. std::vector GetPreferredLanguages(); -#if defined(OS_WIN) -bool GetPreferredLanguagesUsingGlobalization( - std::vector* languages); -#endif - } // namespace electron #endif // SHELL_COMMON_LANGUAGE_UTIL_H_ diff --git a/shell/common/language_util_win.cc b/shell/common/language_util_win.cc index 708802c1ab..e8e681aaaf 100644 --- a/shell/common/language_util_win.cc +++ b/shell/common/language_util_win.cc @@ -16,24 +16,8 @@ namespace electron { -std::vector GetPreferredLanguages() { - std::vector 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 languages; - for (const auto& language : languages16) { - languages.push_back(base::SysWideToUTF8(language)); - } - return languages; -} - bool GetPreferredLanguagesUsingGlobalization( - std::vector* languages) { + std::vector* 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 GetPreferredLanguages() { + std::vector 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 languages; + for (const auto& language : languages16) { + languages.push_back(base::SysWideToUTF8(language)); + } + return languages; +} + } // namespace electron diff --git a/shell/common/node_bindings.cc b/shell/common/node_bindings.cc index 7db58675e5..b6efb9b0e2 100644 --- a/shell/common/node_bindings.cc +++ b/shell/common/node_bindings.cc @@ -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 diff --git a/shell/common/platform_util_win.cc b/shell/common/platform_util_win.cc index 90505ae27b..f66fc80650 100644 --- a/shell/common/platform_util_win.cc +++ b/shell/common/platform_util_win.cc @@ -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( ShellExecuteW(nullptr, L"open", escaped_url.c_str(), nullptr, diff --git a/shell/renderer/renderer_client_base.cc b/shell/renderer/renderer_client_base.cc index 126401675e..57b19b76ef 100644 --- a/shell/renderer/renderer_client_base.cc +++ b/shell/renderer/renderer_client_base.cc @@ -218,7 +218,7 @@ void RendererClientBase::RenderThreadStarted() { #if defined(OS_WIN) // Set ApplicationUserModelID in renderer process. - std::u16string app_id = + std::wstring app_id = command_line->GetSwitchValueNative(switches::kAppUserModelId); if (!app_id.empty()) { SetCurrentProcessExplicitAppUserModelID(app_id.c_str());