OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
| 9 #include "base/bind.h" |
9 #include "base/file_util.h" | 10 #include "base/file_util.h" |
10 #include "base/process_util.h" | 11 #include "base/process_util.h" |
11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
12 #include "content/common/process_watcher.h" | 13 #include "content/common/process_watcher.h" |
| 14 #include "content/public/browser/browser_thread.h" |
13 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
14 | 16 |
| 17 using content::BrowserThread; |
| 18 |
15 namespace { | 19 namespace { |
16 | 20 |
17 void XDGUtil(const std::string& util, const std::string& arg) { | 21 void XDGUtil(const std::string& util, const std::string& arg) { |
18 std::vector<std::string> argv; | 22 std::vector<std::string> argv; |
19 argv.push_back(util); | 23 argv.push_back(util); |
20 argv.push_back(arg); | 24 argv.push_back(arg); |
21 | 25 |
22 base::environment_vector env; | 26 base::environment_vector env; |
23 // xdg-open can fall back on mailcap which eventually might plumb through | 27 // xdg-open can fall back on mailcap which eventually might plumb through |
24 // to a command that needs a terminal. Set the environment variable telling | 28 // to a command that needs a terminal. Set the environment variable telling |
(...skipping 18 matching lines...) Expand all Loading... |
43 } | 47 } |
44 | 48 |
45 void XDGOpen(const std::string& path) { | 49 void XDGOpen(const std::string& path) { |
46 XDGUtil("xdg-open", path); | 50 XDGUtil("xdg-open", path); |
47 } | 51 } |
48 | 52 |
49 void XDGEmail(const std::string& email) { | 53 void XDGEmail(const std::string& email) { |
50 XDGUtil("xdg-email", email); | 54 XDGUtil("xdg-email", email); |
51 } | 55 } |
52 | 56 |
53 } // namespace | |
54 | |
55 namespace platform_util { | |
56 | |
57 // TODO(estade): It would be nice to be able to select the file in the file | 57 // TODO(estade): It would be nice to be able to select the file in the file |
58 // manager, but that probably requires extending xdg-open. For now just | 58 // manager, but that probably requires extending xdg-open. For now just |
59 // show the folder. | 59 // show the folder. |
60 void ShowItemInFolder(const FilePath& full_path) { | 60 void ShowItemInFolderOnFileThread(const FilePath& full_path) { |
61 FilePath dir = full_path.DirName(); | 61 FilePath dir = full_path.DirName(); |
62 if (!file_util::DirectoryExists(dir)) | 62 if (!file_util::DirectoryExists(dir)) |
63 return; | 63 return; |
64 | 64 |
65 XDGOpen(dir.value()); | 65 XDGOpen(dir.value()); |
66 } | 66 } |
67 | 67 |
| 68 } // namespace |
| 69 |
| 70 namespace platform_util { |
| 71 |
| 72 void ShowItemInFolder(const FilePath& full_path) { |
| 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 74 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 75 base::Bind(&ShowItemInFolderOnFileThread, full_path)); |
| 76 } |
| 77 |
68 void OpenItem(const FilePath& full_path) { | 78 void OpenItem(const FilePath& full_path) { |
69 XDGOpen(full_path.value()); | 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 80 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 81 base::Bind(&XDGOpen, full_path.value())); |
70 } | 82 } |
71 | 83 |
72 void OpenExternal(const GURL& url) { | 84 void OpenExternal(const GURL& url) { |
73 if (url.SchemeIs("mailto")) | 85 if (url.SchemeIs("mailto")) |
74 XDGEmail(url.spec()); | 86 XDGEmail(url.spec()); |
75 else | 87 else |
76 XDGOpen(url.spec()); | 88 XDGOpen(url.spec()); |
77 } | 89 } |
78 | 90 |
79 } // namespace platform_util | 91 } // namespace platform_util |
OLD | NEW |