feat: add workingDirectory option to shell.openExternal() (#15065)

Allows passing `workingDirectory` to the underlying `ShellExecuteW` API on Windows.

the motivation is that by default `ShellExecute` would use the current working directory, which would get locked on Windows and can prevent autoUpdater from working correctly. We need to be able specify a different `workingDirectory` to prevent this situation.
This commit is contained in:
Milan Burda 2018-10-10 22:46:54 +02:00 committed by Alexey Kuzmin
parent 2d186cb31a
commit a9475f3590
7 changed files with 42 additions and 35 deletions

View file

@ -294,15 +294,18 @@ bool OpenItem(const base::FilePath& full_path) {
return ui::win::OpenFileViaShell(full_path);
}
bool OpenExternal(const base::string16& url, bool activate) {
bool OpenExternal(const base::string16& url,
const OpenExternalOptions& options) {
// 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.
base::string16 escaped_url = L"\"" + url + L"\"";
auto working_dir = options.working_dir.value();
if (reinterpret_cast<ULONG_PTR>(ShellExecuteW(
NULL, L"open", escaped_url.c_str(), NULL, NULL, SW_SHOWNORMAL)) <=
32) {
if (reinterpret_cast<ULONG_PTR>(
ShellExecuteW(nullptr, L"open", escaped_url.c_str(), nullptr,
working_dir.empty() ? nullptr : working_dir.c_str(),
SW_SHOWNORMAL)) <= 32) {
// We fail to execute the call. We could display a message to the user.
// TODO(nsylvain): we should also add a dialog to warn on errors. See
// bug 1136923.
@ -312,10 +315,10 @@ bool OpenExternal(const base::string16& url, bool activate) {
}
void OpenExternal(const base::string16& url,
bool activate,
const OpenExternalOptions& options,
const OpenExternalCallback& callback) {
// TODO(gabriel): Implement async open if callback is specified
callback.Run(OpenExternal(url, activate) ? "" : "Failed to open");
callback.Run(OpenExternal(url, options) ? "" : "Failed to open");
}
bool MoveItemToTrash(const base::FilePath& path) {