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 26 matching lines...) Expand all Loading... |
51 } | 55 } |
52 | 56 |
53 } // namespace | 57 } // namespace |
54 | 58 |
55 namespace platform_util { | 59 namespace platform_util { |
56 | 60 |
57 // TODO(estade): It would be nice to be able to select the file in the file | 61 // 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 | 62 // manager, but that probably requires extending xdg-open. For now just |
59 // show the folder. | 63 // show the folder. |
60 void ShowItemInFolder(const FilePath& full_path) { | 64 void ShowItemInFolder(const FilePath& full_path) { |
61 FilePath dir = full_path.DirName(); | 65 if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
62 if (!file_util::DirectoryExists(dir)) | 66 FilePath dir = full_path.DirName(); |
63 return; | 67 if (!file_util::DirectoryExists(dir)) |
| 68 return; |
64 | 69 |
65 XDGOpen(dir.value()); | 70 XDGOpen(dir.value()); |
| 71 } else { |
| 72 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 73 base::Bind(&ShowItemInFolder, full_path)); |
| 74 } |
66 } | 75 } |
67 | 76 |
68 void OpenItem(const FilePath& full_path) { | 77 void OpenItem(const FilePath& full_path) { |
69 XDGOpen(full_path.value()); | 78 if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
| 79 XDGOpen(full_path.value()); |
| 80 } else { |
| 81 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 82 base::Bind(&OpenItem, full_path)); |
| 83 } |
70 } | 84 } |
71 | 85 |
72 void OpenExternal(const GURL& url) { | 86 void OpenExternal(const GURL& url) { |
73 if (url.SchemeIs("mailto")) | 87 if (url.SchemeIs("mailto")) |
74 XDGEmail(url.spec()); | 88 XDGEmail(url.spec()); |
75 else | 89 else |
76 XDGOpen(url.spec()); | 90 XDGOpen(url.spec()); |
77 } | 91 } |
78 | 92 |
79 } // namespace platform_util | 93 } // namespace platform_util |
OLD | NEW |