Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(850)

Side by Side Diff: chrome/common/platform_util_linux.cc

Issue 177040: Linux: handle external protocols, e.g. mailto: links. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/platform_util.h ('k') | chrome/common/platform_util_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/common/platform_util.h" 5 #include "chrome/common/platform_util.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "chrome/common/process_watcher.h" 12 #include "chrome/common/process_watcher.h"
13 #include "googleurl/src/gurl.h"
13 14
14 namespace { 15 namespace {
15 16
16 void XDGOpen(const FilePath& path) { 17 void XDGOpen(const std::string& path) {
17 std::vector<std::string> argv; 18 std::vector<std::string> argv;
18 argv.push_back("xdg-open"); 19 argv.push_back("xdg-open");
19 argv.push_back(path.value()); 20 argv.push_back(path);
20 21
21 base::environment_vector env; 22 base::environment_vector env;
22 // xdg-open can fall back on mailcap which eventually might plumb through 23 // xdg-open can fall back on mailcap which eventually might plumb through
23 // to a command that needs a terminal. Set the environment variable telling 24 // to a command that needs a terminal. Set the environment variable telling
24 // it that we definitely don't have a terminal available and that it should 25 // it that we definitely don't have a terminal available and that it should
25 // bring up a new terminal if necessary. See "man mailcap". 26 // bring up a new terminal if necessary. See "man mailcap".
26 env.push_back(std::make_pair("MM_NOTTTY", "1")); 27 env.push_back(std::make_pair("MM_NOTTTY", "1"));
27 28
28 base::file_handle_mapping_vector no_files; 29 base::file_handle_mapping_vector no_files;
29 base::ProcessHandle handle; 30 base::ProcessHandle handle;
30 if (base::LaunchApp(argv, env, no_files, false, &handle)) 31 if (base::LaunchApp(argv, env, no_files, false, &handle))
31 ProcessWatcher::EnsureProcessGetsReaped(handle); 32 ProcessWatcher::EnsureProcessGetsReaped(handle);
32 } 33 }
33 34
34 } // namespace 35 } // namespace
35 36
36 namespace platform_util { 37 namespace platform_util {
37 38
38 // TODO(estade): It would be nice to be able to select the file in the file 39 // TODO(estade): It would be nice to be able to select the file in the file
39 // manager, but that probably requires extending xdg-open. For now just 40 // manager, but that probably requires extending xdg-open. For now just
40 // show the folder. 41 // show the folder.
41 void ShowItemInFolder(const FilePath& full_path) { 42 void ShowItemInFolder(const FilePath& full_path) {
42 FilePath dir = full_path.DirName(); 43 FilePath dir = full_path.DirName();
43 if (!file_util::DirectoryExists(dir)) 44 if (!file_util::DirectoryExists(dir))
44 return; 45 return;
45 46
46 XDGOpen(dir); 47 XDGOpen(dir.value());
47 } 48 }
48 49
49 void OpenItem(const FilePath& full_path) { 50 void OpenItem(const FilePath& full_path) {
50 XDGOpen(full_path); 51 XDGOpen(full_path.value());
52 }
53
54 void OpenExternal(const GURL& url) {
55 XDGOpen(url.spec());
51 } 56 }
52 57
53 gfx::NativeWindow GetTopLevel(gfx::NativeView view) { 58 gfx::NativeWindow GetTopLevel(gfx::NativeView view) {
54 // A detached widget won't have a toplevel window as an ancestor, so we can't 59 // A detached widget won't have a toplevel window as an ancestor, so we can't
55 // assume that the query for toplevel will return a window. 60 // assume that the query for toplevel will return a window.
56 GtkWidget* toplevel = gtk_widget_get_ancestor(view, GTK_TYPE_WINDOW); 61 GtkWidget* toplevel = gtk_widget_get_ancestor(view, GTK_TYPE_WINDOW);
57 return GTK_IS_WINDOW(toplevel) ? GTK_WINDOW(toplevel) : NULL; 62 return GTK_IS_WINDOW(toplevel) ? GTK_WINDOW(toplevel) : NULL;
58 } 63 }
59 64
60 string16 GetWindowTitle(gfx::NativeWindow window) { 65 string16 GetWindowTitle(gfx::NativeWindow window) {
61 const gchar* title = gtk_window_get_title(window); 66 const gchar* title = gtk_window_get_title(window);
62 return UTF8ToUTF16(title); 67 return UTF8ToUTF16(title);
63 } 68 }
64 69
65 bool IsWindowActive(gfx::NativeWindow window) { 70 bool IsWindowActive(gfx::NativeWindow window) {
66 return gtk_window_is_active(window); 71 return gtk_window_is_active(window);
67 } 72 }
68 73
69 bool IsVisible(gfx::NativeView view) { 74 bool IsVisible(gfx::NativeView view) {
70 return GTK_WIDGET_VISIBLE(view); 75 return GTK_WIDGET_VISIBLE(view);
71 } 76 }
72 77
73 } // namespace platform_util 78 } // namespace platform_util
OLDNEW
« no previous file with comments | « chrome/common/platform_util.h ('k') | chrome/common/platform_util_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698