| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/platform_util.h" | 5 #include "chrome/browser/platform_util.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/process/kill.h" | 9 #include "base/process/kill.h" |
| 10 #include "base/process/launch.h" | 10 #include "base/process/launch.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 } | 43 } |
| 44 | 44 |
| 45 void XDGOpen(const std::string& path) { | 45 void XDGOpen(const std::string& path) { |
| 46 XDGUtil("xdg-open", path); | 46 XDGUtil("xdg-open", path); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void XDGEmail(const std::string& email) { | 49 void XDGEmail(const std::string& email) { |
| 50 XDGUtil("xdg-email", email); | 50 XDGUtil("xdg-email", email); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // TODO(estade): It would be nice to be able to select the file in the file | 53 void OpenFileOnFileThread(const base::FilePath& full_path) { |
| 54 // manager, but that probably requires extending xdg-open. For now just | 54 if (!base::PathExists(full_path) || base::DirectoryExists(full_path)) |
| 55 // show the folder. | |
| 56 void ShowItemInFolderOnFileThread(const base::FilePath& full_path) { | |
| 57 base::FilePath dir = full_path.DirName(); | |
| 58 if (!base::DirectoryExists(dir)) | |
| 59 return; | 55 return; |
| 56 XDGOpen(full_path.value()); |
| 57 } |
| 60 | 58 |
| 61 XDGOpen(dir.value()); | 59 void OpenFolderOnFileThread(const base::FilePath& full_path) { |
| 60 if (!base::DirectoryExists(full_path)) |
| 61 return; |
| 62 XDGOpen(full_path.value()); |
| 62 } | 63 } |
| 63 | 64 |
| 64 } // namespace | 65 } // namespace |
| 65 | 66 |
| 66 namespace platform_util { | 67 namespace platform_util { |
| 67 | 68 |
| 68 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { | 69 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { |
| 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 70 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 71 // TODO(estade): It would be nice to be able to select the file in the file |
| 71 base::Bind(&ShowItemInFolderOnFileThread, full_path)); | 72 // manager, but that probably requires extending xdg-open. For now just show |
| 73 // the folder. |
| 74 BrowserThread::PostTask( |
| 75 BrowserThread::FILE, |
| 76 FROM_HERE, |
| 77 base::Bind(&OpenFolderOnFileThread, full_path.DirName())); |
| 72 } | 78 } |
| 73 | 79 |
| 74 void OpenItem(Profile* profile, const base::FilePath& full_path) { | 80 void OpenFile(Profile* profile, const base::FilePath& full_path) { |
| 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 76 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 82 BrowserThread::PostTask(BrowserThread::FILE, |
| 77 base::Bind(&XDGOpen, full_path.value())); | 83 FROM_HERE, |
| 84 base::Bind(&OpenFileOnFileThread, full_path)); |
| 85 } |
| 86 |
| 87 void OpenFolder(Profile* profile, const base::FilePath& full_path) { |
| 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 89 BrowserThread::PostTask(BrowserThread::FILE, |
| 90 FROM_HERE, |
| 91 base::Bind(&OpenFolderOnFileThread, full_path)); |
| 78 } | 92 } |
| 79 | 93 |
| 80 void OpenExternal(Profile* profile, const GURL& url) { | 94 void OpenExternal(Profile* profile, const GURL& url) { |
| 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 82 if (url.SchemeIs("mailto")) | 96 if (url.SchemeIs("mailto")) |
| 83 XDGEmail(url.spec()); | 97 XDGEmail(url.spec()); |
| 84 else | 98 else |
| 85 XDGOpen(url.spec()); | 99 XDGOpen(url.spec()); |
| 86 } | 100 } |
| 87 | 101 |
| 88 } // namespace platform_util | 102 } // namespace platform_util |
| OLD | NEW |