@@ -230,6 +230,29 @@ HRESULT DeleteFileProgressSink::ResumeTimer() {
230230 return S_OK;
231231}
232232
233+ std::string OpenExternalOnWorkerThread (
234+ const GURL& url,
235+ const platform_util::OpenExternalOptions& options) {
236+ base::ScopedBlockingCall scoped_blocking_call (FROM_HERE,
237+ base::BlockingType::MAY_BLOCK);
238+ // Quote the input scheme to be sure that the command does not have
239+ // parameters unexpected by the external program. This url should already
240+ // have been escaped.
241+ std::string escaped_url = url.spec ();
242+ escaped_url.insert (0 , " \" " );
243+ escaped_url += " \" " ;
244+
245+ std::string working_dir = options.working_dir .AsUTF8Unsafe ();
246+
247+ if (reinterpret_cast <ULONG_PTR>(
248+ ShellExecuteA (nullptr , " open" , escaped_url.c_str (), nullptr ,
249+ working_dir.empty () ? nullptr : working_dir.c_str (),
250+ SW_SHOWNORMAL)) <= 32 ) {
251+ return " Failed to open" ;
252+ }
253+ return " " ;
254+ }
255+
233256void ShowItemInFolderOnWorkerThread (const base::FilePath& full_path) {
234257 base::ScopedBlockingCall scoped_blocking_call (FROM_HERE,
235258 base::BlockingType::MAY_BLOCK);
@@ -301,31 +324,15 @@ bool OpenItem(const base::FilePath& full_path) {
301324 return ui::win::OpenFileViaShell (full_path);
302325}
303326
304- bool OpenExternal (const base::string16& url,
305- const OpenExternalOptions& options) {
306- // Quote the input scheme to be sure that the command does not have
307- // parameters unexpected by the external program. This url should already
308- // have been escaped.
309- base::string16 escaped_url = L" \" " + url + L" \" " ;
310- auto working_dir = options.working_dir .value ();
311-
312- if (reinterpret_cast <ULONG_PTR>(
313- ShellExecuteW (nullptr , L" open" , escaped_url.c_str (), nullptr ,
314- working_dir.empty () ? nullptr : working_dir.c_str (),
315- SW_SHOWNORMAL)) <= 32 ) {
316- // We fail to execute the call. We could display a message to the user.
317- // TODO(nsylvain): we should also add a dialog to warn on errors. See
318- // bug 1136923.
319- return false ;
320- }
321- return true ;
322- }
323-
324- void OpenExternal (const base::string16& url,
327+ void OpenExternal (const GURL& url,
325328 const OpenExternalOptions& options,
326329 OpenExternalCallback callback) {
327- // TODO(gabriel): Implement async open if callback is specified
328- std::move (callback).Run (OpenExternal (url, options) ? " " : " Failed to open" );
330+ base::PostTaskAndReplyWithResult (
331+ base::CreateCOMSTATaskRunnerWithTraits (
332+ {base::MayBlock (), base::TaskPriority::USER_BLOCKING})
333+ .get (),
334+ FROM_HERE, base::BindOnce (&OpenExternalOnWorkerThread, url, options),
335+ std::move (callback));
329336}
330337
331338bool MoveItemToTrash (const base::FilePath& path) {
0 commit comments