|
@@ -48,7 +48,7 @@ namespace electron {
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
-bool GetProcessExecPath(base::string16* exe) {
|
|
|
+bool GetProcessExecPath(std::u16string* exe) {
|
|
|
base::FilePath path;
|
|
|
if (!base::PathService::Get(base::FILE_EXE, &path)) {
|
|
|
return false;
|
|
@@ -57,13 +57,13 @@ bool GetProcessExecPath(base::string16* exe) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-bool GetProtocolLaunchPath(gin::Arguments* args, base::string16* exe) {
|
|
|
+bool GetProtocolLaunchPath(gin::Arguments* args, std::u16string* exe) {
|
|
|
if (!args->GetNext(exe) && !GetProcessExecPath(exe)) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// Read in optional args arg
|
|
|
- std::vector<base::string16> launch_args;
|
|
|
+ std::vector<std::u16string> 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, base::string16* 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 base::string16& scheme) {
|
|
|
+bool IsValidCustomProtocol(const std::u16string& scheme) {
|
|
|
if (scheme.empty())
|
|
|
return false;
|
|
|
base::win::RegKey cmd_key(HKEY_CLASSES_ROOT, scheme.c_str(), KEY_QUERY_VALUE);
|
|
@@ -90,11 +90,11 @@ bool IsValidCustomProtocol(const base::string16& 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.
|
|
|
-base::string16 GetAppInfoHelperForProtocol(ASSOCSTR assoc_str,
|
|
|
+std::u16string GetAppInfoHelperForProtocol(ASSOCSTR assoc_str,
|
|
|
const GURL& url) {
|
|
|
- const base::string16 url_scheme = base::ASCIIToUTF16(url.scheme());
|
|
|
+ const std::u16string url_scheme = base::ASCIIToUTF16(url.scheme());
|
|
|
if (!IsValidCustomProtocol(url_scheme))
|
|
|
- return base::string16();
|
|
|
+ return std::u16string();
|
|
|
|
|
|
wchar_t out_buffer[1024];
|
|
|
DWORD buffer_size = base::size(out_buffer);
|
|
@@ -103,13 +103,13 @@ base::string16 GetAppInfoHelperForProtocol(ASSOCSTR assoc_str,
|
|
|
out_buffer, &buffer_size);
|
|
|
if (FAILED(hr)) {
|
|
|
DLOG(WARNING) << "AssocQueryString failed!";
|
|
|
- return base::string16();
|
|
|
+ return std::u16string();
|
|
|
}
|
|
|
- return base::string16(out_buffer);
|
|
|
+ return std::u16string(out_buffer);
|
|
|
}
|
|
|
|
|
|
void OnIconDataAvailable(const base::FilePath& app_path,
|
|
|
- const base::string16& app_display_name,
|
|
|
+ const std::u16string& app_display_name,
|
|
|
gin_helper::Promise<gin_helper::Dictionary> promise,
|
|
|
gfx::Image icon) {
|
|
|
if (!icon.IsEmpty()) {
|
|
@@ -126,21 +126,21 @@ void OnIconDataAvailable(const base::FilePath& app_path,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-base::string16 GetAppDisplayNameForProtocol(const GURL& url) {
|
|
|
+std::u16string GetAppDisplayNameForProtocol(const GURL& url) {
|
|
|
return GetAppInfoHelperForProtocol(ASSOCSTR_FRIENDLYAPPNAME, url);
|
|
|
}
|
|
|
|
|
|
-base::string16 GetAppPathForProtocol(const GURL& url) {
|
|
|
+std::u16string GetAppPathForProtocol(const GURL& url) {
|
|
|
return GetAppInfoHelperForProtocol(ASSOCSTR_EXECUTABLE, url);
|
|
|
}
|
|
|
|
|
|
-base::string16 GetAppForProtocolUsingRegistry(const GURL& url) {
|
|
|
- const base::string16 url_scheme = base::ASCIIToUTF16(url.scheme());
|
|
|
+std::u16string GetAppForProtocolUsingRegistry(const GURL& url) {
|
|
|
+ const std::u16string url_scheme = base::ASCIIToUTF16(url.scheme());
|
|
|
if (!IsValidCustomProtocol(url_scheme))
|
|
|
- return base::string16();
|
|
|
+ return std::u16string();
|
|
|
|
|
|
// First, try and extract the application's display name.
|
|
|
- base::string16 command_to_launch;
|
|
|
+ std::u16string 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 +150,7 @@ base::string16 GetAppForProtocolUsingRegistry(const GURL& url) {
|
|
|
|
|
|
// Otherwise, parse the command line in the registry, and return the basename
|
|
|
// of the program path if it exists.
|
|
|
- const base::string16 cmd_key_path = url_scheme + L"\\shell\\open\\command";
|
|
|
+ const std::u16string 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,11 +159,11 @@ base::string16 GetAppForProtocolUsingRegistry(const GURL& url) {
|
|
|
return command_line.GetProgram().BaseName().value();
|
|
|
}
|
|
|
|
|
|
- return base::string16();
|
|
|
+ return std::u16string();
|
|
|
}
|
|
|
|
|
|
-bool FormatCommandLineString(base::string16* exe,
|
|
|
- const std::vector<base::string16>& launch_args) {
|
|
|
+bool FormatCommandLineString(std::u16string* exe,
|
|
|
+ const std::vector<std::u16string>& launch_args) {
|
|
|
if (exe->empty() && !GetProcessExecPath(exe)) {
|
|
|
return false;
|
|
|
}
|
|
@@ -184,13 +184,13 @@ bool FormatCommandLineString(base::string16* exe,
|
|
|
std::vector<Browser::LaunchItem> GetLoginItemSettingsHelper(
|
|
|
base::win::RegistryValueIterator* it,
|
|
|
boolean* executable_will_launch_at_login,
|
|
|
- base::string16 scope,
|
|
|
+ std::u16string scope,
|
|
|
const Browser::LoginItemSettings& options) {
|
|
|
std::vector<Browser::LaunchItem> launch_items;
|
|
|
|
|
|
base::FilePath lookup_exe_path;
|
|
|
if (options.path.empty()) {
|
|
|
- base::string16 process_exe_path;
|
|
|
+ std::u16string process_exe_path;
|
|
|
GetProcessExecPath(&process_exe_path);
|
|
|
lookup_exe_path =
|
|
|
base::CommandLine::FromString(process_exe_path).GetProgram();
|
|
@@ -287,7 +287,7 @@ Browser::UserTask::~UserTask() = default;
|
|
|
void GetFileIcon(const base::FilePath& path,
|
|
|
v8::Isolate* isolate,
|
|
|
base::CancelableTaskTracker* cancelable_task_tracker_,
|
|
|
- const base::string16 app_display_name,
|
|
|
+ const std::u16string app_display_name,
|
|
|
gin_helper::Promise<gin_helper::Dictionary> promise) {
|
|
|
base::FilePath normalized_path = path.NormalizePathSeparators();
|
|
|
IconLoader::IconSize icon_size = IconLoader::IconSize::LARGE;
|
|
@@ -316,13 +316,13 @@ void GetApplicationInfoForProtocolUsingRegistry(
|
|
|
base::CancelableTaskTracker* cancelable_task_tracker_) {
|
|
|
base::FilePath app_path;
|
|
|
|
|
|
- const base::string16 url_scheme = base::ASCIIToUTF16(url.scheme());
|
|
|
+ const std::u16string url_scheme = base::ASCIIToUTF16(url.scheme());
|
|
|
if (!IsValidCustomProtocol(url_scheme)) {
|
|
|
promise.RejectWithErrorMessage("invalid url_scheme");
|
|
|
return;
|
|
|
}
|
|
|
- base::string16 command_to_launch;
|
|
|
- const base::string16 cmd_key_path = url_scheme + L"\\shell\\open\\command";
|
|
|
+ std::u16string command_to_launch;
|
|
|
+ const std::u16string 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 +334,7 @@ void GetApplicationInfoForProtocolUsingRegistry(
|
|
|
"Unable to retrieve installation path to app");
|
|
|
return;
|
|
|
}
|
|
|
- const base::string16 app_display_name = GetAppForProtocolUsingRegistry(url);
|
|
|
+ const std::u16string app_display_name = GetAppForProtocolUsingRegistry(url);
|
|
|
|
|
|
if (app_display_name.empty()) {
|
|
|
promise.RejectWithErrorMessage(
|
|
@@ -354,7 +354,7 @@ void GetApplicationInfoForProtocolUsingAssocQuery(
|
|
|
const GURL& url,
|
|
|
gin_helper::Promise<gin_helper::Dictionary> promise,
|
|
|
base::CancelableTaskTracker* cancelable_task_tracker_) {
|
|
|
- base::string16 app_path = GetAppPathForProtocol(url);
|
|
|
+ std::u16string app_path = GetAppPathForProtocol(url);
|
|
|
|
|
|
if (app_path.empty()) {
|
|
|
promise.RejectWithErrorMessage(
|
|
@@ -362,7 +362,7 @@ void GetApplicationInfoForProtocolUsingAssocQuery(
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- base::string16 app_display_name = GetAppDisplayNameForProtocol(url);
|
|
|
+ std::u16string app_display_name = GetAppDisplayNameForProtocol(url);
|
|
|
|
|
|
if (app_display_name.empty()) {
|
|
|
promise.RejectWithErrorMessage("Unable to retrieve display name of app");
|
|
@@ -390,7 +390,7 @@ void Browser::ClearRecentDocuments() {
|
|
|
SHAddToRecentDocs(SHARD_APPIDINFO, nullptr);
|
|
|
}
|
|
|
|
|
|
-void Browser::SetAppUserModelID(const base::string16& name) {
|
|
|
+void Browser::SetAppUserModelID(const std::u16string& name) {
|
|
|
electron::SetAppUserModelID(name);
|
|
|
}
|
|
|
|
|
@@ -426,12 +426,12 @@ bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
|
|
|
|
|
|
// Main Registry Key
|
|
|
HKEY root = HKEY_CURRENT_USER;
|
|
|
- base::string16 keyPath = L"Software\\Classes\\";
|
|
|
+ std::u16string keyPath = L"Software\\Classes\\";
|
|
|
|
|
|
// Command Key
|
|
|
- base::string16 wprotocol = base::UTF8ToUTF16(protocol);
|
|
|
- base::string16 shellPath = wprotocol + L"\\shell";
|
|
|
- base::string16 cmdPath = keyPath + shellPath + L"\\open\\command";
|
|
|
+ std::u16string wprotocol = base::UTF8ToUTF16(protocol);
|
|
|
+ std::u16string shellPath = wprotocol + L"\\shell";
|
|
|
+ std::u16string cmdPath = keyPath + shellPath + L"\\open\\command";
|
|
|
|
|
|
base::win::RegKey classesKey;
|
|
|
base::win::RegKey commandKey;
|
|
@@ -445,12 +445,12 @@ bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
|
|
|
// Key doesn't even exist, we can confirm that it is not set
|
|
|
return true;
|
|
|
|
|
|
- base::string16 keyVal;
|
|
|
+ std::u16string keyVal;
|
|
|
if (FAILED(commandKey.ReadValue(L"", &keyVal)))
|
|
|
// Default value not set, we can confirm that it is not set
|
|
|
return true;
|
|
|
|
|
|
- base::string16 exe;
|
|
|
+ std::u16string exe;
|
|
|
if (!GetProtocolLaunchPath(args, &exe))
|
|
|
return false;
|
|
|
|
|
@@ -461,7 +461,7 @@ bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
|
|
|
|
|
|
// Let's clean up after ourselves
|
|
|
base::win::RegKey protocolKey;
|
|
|
- base::string16 protocolPath = keyPath + wprotocol;
|
|
|
+ std::u16string protocolPath = keyPath + wprotocol;
|
|
|
|
|
|
if (SUCCEEDED(
|
|
|
protocolKey.Open(root, protocolPath.c_str(), KEY_ALL_ACCESS))) {
|
|
@@ -500,17 +500,17 @@ bool Browser::SetAsDefaultProtocolClient(const std::string& protocol,
|
|
|
if (protocol.empty())
|
|
|
return false;
|
|
|
|
|
|
- base::string16 exe;
|
|
|
+ std::u16string exe;
|
|
|
if (!GetProtocolLaunchPath(args, &exe))
|
|
|
return false;
|
|
|
|
|
|
// Main Registry Key
|
|
|
HKEY root = HKEY_CURRENT_USER;
|
|
|
- base::string16 keyPath = base::UTF8ToUTF16("Software\\Classes\\" + protocol);
|
|
|
- base::string16 urlDecl = base::UTF8ToUTF16("URL:" + protocol);
|
|
|
+ std::u16string keyPath = base::UTF8ToUTF16("Software\\Classes\\" + protocol);
|
|
|
+ std::u16string urlDecl = base::UTF8ToUTF16("URL:" + protocol);
|
|
|
|
|
|
// Command Key
|
|
|
- base::string16 cmdPath = keyPath + L"\\shell\\open\\command";
|
|
|
+ std::u16string cmdPath = keyPath + L"\\shell\\open\\command";
|
|
|
|
|
|
// Write information to registry
|
|
|
base::win::RegKey key(root, keyPath.c_str(), KEY_ALL_ACCESS);
|
|
@@ -530,16 +530,16 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol,
|
|
|
if (protocol.empty())
|
|
|
return false;
|
|
|
|
|
|
- base::string16 exe;
|
|
|
+ std::u16string exe;
|
|
|
if (!GetProtocolLaunchPath(args, &exe))
|
|
|
return false;
|
|
|
|
|
|
// Main Registry Key
|
|
|
HKEY root = HKEY_CURRENT_USER;
|
|
|
- base::string16 keyPath = base::UTF8ToUTF16("Software\\Classes\\" + protocol);
|
|
|
+ std::u16string keyPath = base::UTF8ToUTF16("Software\\Classes\\" + protocol);
|
|
|
|
|
|
// Command Key
|
|
|
- base::string16 cmdPath = keyPath + L"\\shell\\open\\command";
|
|
|
+ std::u16string cmdPath = keyPath + L"\\shell\\open\\command";
|
|
|
|
|
|
base::win::RegKey key;
|
|
|
base::win::RegKey commandKey;
|
|
@@ -551,7 +551,7 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol,
|
|
|
// Key doesn't exist, we can confirm that it is not set
|
|
|
return false;
|
|
|
|
|
|
- base::string16 keyVal;
|
|
|
+ std::u16string keyVal;
|
|
|
if (FAILED(commandKey.ReadValue(L"", &keyVal)))
|
|
|
// Default value not set, we can confirm that it is not set
|
|
|
return false;
|
|
@@ -560,10 +560,10 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol,
|
|
|
return keyVal == exe;
|
|
|
}
|
|
|
|
|
|
-base::string16 Browser::GetApplicationNameForProtocol(const GURL& url) {
|
|
|
+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) {
|
|
|
- base::string16 application_name = GetAppDisplayNameForProtocol(url);
|
|
|
+ std::u16string application_name = GetAppDisplayNameForProtocol(url);
|
|
|
if (!application_name.empty())
|
|
|
return application_name;
|
|
|
}
|
|
@@ -686,11 +686,11 @@ void Browser::UpdateBadgeContents(
|
|
|
}
|
|
|
|
|
|
void Browser::SetLoginItemSettings(LoginItemSettings settings) {
|
|
|
- base::string16 key_path =
|
|
|
+ std::u16string key_path =
|
|
|
L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
|
|
base::win::RegKey key(HKEY_CURRENT_USER, key_path.c_str(), KEY_ALL_ACCESS);
|
|
|
|
|
|
- base::string16 startup_approved_key_path =
|
|
|
+ std::u16string startup_approved_key_path =
|
|
|
L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved"
|
|
|
L"\\Run";
|
|
|
base::win::RegKey startup_approved_key(
|
|
@@ -699,7 +699,7 @@ void Browser::SetLoginItemSettings(LoginItemSettings settings) {
|
|
|
!settings.name.empty() ? settings.name.c_str() : GetAppUserModelID();
|
|
|
|
|
|
if (settings.open_at_login) {
|
|
|
- base::string16 exe = settings.path;
|
|
|
+ std::u16string exe = settings.path;
|
|
|
if (FormatCommandLineString(&exe, settings.args)) {
|
|
|
key.WriteValue(key_name, exe.c_str());
|
|
|
|
|
@@ -732,13 +732,13 @@ void Browser::SetLoginItemSettings(LoginItemSettings settings) {
|
|
|
Browser::LoginItemSettings Browser::GetLoginItemSettings(
|
|
|
const LoginItemSettings& options) {
|
|
|
LoginItemSettings settings;
|
|
|
- base::string16 keyPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
|
|
+ std::u16string keyPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
|
|
base::win::RegKey key(HKEY_CURRENT_USER, keyPath.c_str(), KEY_ALL_ACCESS);
|
|
|
- base::string16 keyVal;
|
|
|
+ std::u16string keyVal;
|
|
|
|
|
|
// keep old openAtLogin behaviour
|
|
|
if (!FAILED(key.ReadValue(GetAppUserModelID(), &keyVal))) {
|
|
|
- base::string16 exe = options.path;
|
|
|
+ std::u16string exe = options.path;
|
|
|
if (FormatCommandLineString(&exe, options.args)) {
|
|
|
settings.open_at_login = keyVal == exe;
|
|
|
}
|