feat: convert shell.openItem to async shell.openPath (#20682)
This commit is contained in:
		
					parent
					
						
							
								fd70ac1173
							
						
					
				
			
			
				commit
				
					
						d3622f9c37
					
				
			
		
					 8 changed files with 121 additions and 58 deletions
				
			
		|  | @ -30,6 +30,7 @@ | |||
| #include "base/win/scoped_com_initializer.h" | ||||
| #include "base/win/windows_version.h" | ||||
| #include "content/public/browser/browser_task_traits.h" | ||||
| #include "content/public/browser/browser_thread.h" | ||||
| #include "ui/base/win/shell.h" | ||||
| #include "url/gurl.h" | ||||
| 
 | ||||
|  | @ -303,6 +304,19 @@ void ShowItemInFolderOnWorkerThread(const base::FilePath& full_path) { | |||
|   } | ||||
| } | ||||
| 
 | ||||
| std::string OpenPathOnThread(const base::FilePath& full_path) { | ||||
|   // May result in an interactive dialog.
 | ||||
|   base::ScopedBlockingCall scoped_blocking_call(FROM_HERE, | ||||
|                                                 base::BlockingType::MAY_BLOCK); | ||||
|   bool success; | ||||
|   if (base::DirectoryExists(full_path)) | ||||
|     success = ui::win::OpenFolderViaShell(full_path); | ||||
|   else | ||||
|     success = ui::win::OpenFileViaShell(full_path); | ||||
| 
 | ||||
|   return success ? "" : "Failed to open path"; | ||||
| } | ||||
| 
 | ||||
| }  // namespace
 | ||||
| 
 | ||||
| namespace platform_util { | ||||
|  | @ -314,16 +328,20 @@ void ShowItemInFolder(const base::FilePath& full_path) { | |||
|                  base::BindOnce(&ShowItemInFolderOnWorkerThread, full_path)); | ||||
| } | ||||
| 
 | ||||
| bool OpenItem(const base::FilePath& full_path) { | ||||
|   if (base::DirectoryExists(full_path)) | ||||
|     return ui::win::OpenFolderViaShell(full_path); | ||||
|   else | ||||
|     return ui::win::OpenFileViaShell(full_path); | ||||
| void OpenPath(const base::FilePath& full_path, OpenCallback callback) { | ||||
|   DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | ||||
| 
 | ||||
|   base::PostTaskAndReplyWithResult( | ||||
|       base::CreateCOMSTATaskRunner({base::ThreadPool(), base::MayBlock(), | ||||
|                                     base::TaskPriority::USER_BLOCKING}) | ||||
|           .get(), | ||||
|       FROM_HERE, base::BindOnce(&OpenPathOnThread, full_path), | ||||
|       std::move(callback)); | ||||
| } | ||||
| 
 | ||||
| void OpenExternal(const GURL& url, | ||||
|                   const OpenExternalOptions& options, | ||||
|                   OpenExternalCallback callback) { | ||||
|                   OpenCallback callback) { | ||||
|   base::PostTaskAndReplyWithResult( | ||||
|       base::CreateCOMSTATaskRunner({base::ThreadPool(), base::MayBlock(), | ||||
|                                     base::TaskPriority::USER_BLOCKING}) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Shelley Vohr
				Shelley Vohr