| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/common/platform_util.h" | |
| 6 | |
| 7 #include <gtk/gtk.h> | |
| 8 | |
| 9 #include "app/gtk_util.h" | |
| 10 #include "base/file_util.h" | |
| 11 #include "base/process_util.h" | |
| 12 #include "base/utf_string_conversions.h" | |
| 13 #include "chrome/common/process_watcher.h" | |
| 14 #include "googleurl/src/gurl.h" | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 void XDGOpen(const std::string& path) { | |
| 19 std::vector<std::string> argv; | |
| 20 argv.push_back("xdg-open"); | |
| 21 argv.push_back(path); | |
| 22 | |
| 23 base::environment_vector env; | |
| 24 // xdg-open can fall back on mailcap which eventually might plumb through | |
| 25 // to a command that needs a terminal. Set the environment variable telling | |
| 26 // it that we definitely don't have a terminal available and that it should | |
| 27 // bring up a new terminal if necessary. See "man mailcap". | |
| 28 env.push_back(std::make_pair("MM_NOTTTY", "1")); | |
| 29 | |
| 30 // In Google Chrome, we do not let GNOME's bug-buddy intercept our crashes. | |
| 31 // However, we do not want this environment variable to propagate to external | |
| 32 // applications. See http://crbug.com/24120 | |
| 33 char* disable_gnome_bug_buddy = getenv("GNOME_DISABLE_CRASH_DIALOG"); | |
| 34 if (disable_gnome_bug_buddy && | |
| 35 disable_gnome_bug_buddy == std::string("SET_BY_GOOGLE_CHROME")) { | |
| 36 env.push_back(std::make_pair("GNOME_DISABLE_CRASH_DIALOG", "")); | |
| 37 } | |
| 38 | |
| 39 base::file_handle_mapping_vector no_files; | |
| 40 base::ProcessHandle handle; | |
| 41 if (base::LaunchApp(argv, env, no_files, false, &handle)) | |
| 42 ProcessWatcher::EnsureProcessGetsReaped(handle); | |
| 43 } | |
| 44 | |
| 45 } // namespace | |
| 46 | |
| 47 namespace platform_util { | |
| 48 | |
| 49 // TODO(estade): It would be nice to be able to select the file in the file | |
| 50 // manager, but that probably requires extending xdg-open. For now just | |
| 51 // show the folder. | |
| 52 void ShowItemInFolder(const FilePath& full_path) { | |
| 53 FilePath dir = full_path.DirName(); | |
| 54 if (!file_util::DirectoryExists(dir)) | |
| 55 return; | |
| 56 | |
| 57 XDGOpen(dir.value()); | |
| 58 } | |
| 59 | |
| 60 void OpenItem(const FilePath& full_path) { | |
| 61 XDGOpen(full_path.value()); | |
| 62 } | |
| 63 | |
| 64 void OpenExternal(const GURL& url) { | |
| 65 XDGOpen(url.spec()); | |
| 66 } | |
| 67 | |
| 68 gfx::NativeWindow GetTopLevel(gfx::NativeView view) { | |
| 69 // A detached widget won't have a toplevel window as an ancestor, so we can't | |
| 70 // assume that the query for toplevel will return a window. | |
| 71 GtkWidget* toplevel = gtk_widget_get_ancestor(view, GTK_TYPE_WINDOW); | |
| 72 return GTK_IS_WINDOW(toplevel) ? GTK_WINDOW(toplevel) : NULL; | |
| 73 } | |
| 74 | |
| 75 bool IsWindowActive(gfx::NativeWindow window) { | |
| 76 return gtk_window_is_active(window); | |
| 77 } | |
| 78 | |
| 79 bool IsVisible(gfx::NativeView view) { | |
| 80 return GTK_WIDGET_VISIBLE(view); | |
| 81 } | |
| 82 | |
| 83 void SimpleErrorBox(gfx::NativeWindow parent, | |
| 84 const string16& title, | |
| 85 const string16& message) { | |
| 86 GtkWidget* dialog = gtk_message_dialog_new(parent, GTK_DIALOG_MODAL, | |
| 87 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", UTF16ToUTF8(message).c_str()); | |
| 88 gtk_util::ApplyMessageDialogQuirks(dialog); | |
| 89 gtk_window_set_title(GTK_WINDOW(dialog), UTF16ToUTF8(title).c_str()); | |
| 90 | |
| 91 g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL); | |
| 92 gtk_widget_show_all(dialog); | |
| 93 | |
| 94 // Make sure it's big enough to show the title. | |
| 95 GtkRequisition req; | |
| 96 gtk_widget_size_request(dialog, &req); | |
| 97 int width; | |
| 98 gtk_util::GetWidgetSizeFromCharacters(dialog, title.length(), 0, | |
| 99 &width, NULL); | |
| 100 // The fudge factor accounts for extra space needed by the frame | |
| 101 // decorations as well as width differences between average text and the | |
| 102 // actual title text. | |
| 103 width = width * 1.2 + 50; | |
| 104 | |
| 105 if (width > req.width) | |
| 106 gtk_widget_set_size_request(dialog, width, -1); | |
| 107 } | |
| 108 | |
| 109 /* Warning: this may be either Linux or ChromeOS */ | |
| 110 string16 GetVersionStringModifier() { | |
| 111 char* env = getenv("CHROME_VERSION_EXTRA"); | |
| 112 if (!env) | |
| 113 return string16(); | |
| 114 std::string modifier(env); | |
| 115 | |
| 116 #if defined(GOOGLE_CHROME_BUILD) | |
| 117 // Only ever return "", "unknown", "dev" or "beta" in a branded build. | |
| 118 if (modifier == "unstable") // linux version of "dev" | |
| 119 modifier = "dev"; | |
| 120 if (modifier == "stable") { | |
| 121 modifier = ""; | |
| 122 } else if ((modifier == "dev") || (modifier == "beta")) { | |
| 123 // do nothing. | |
| 124 } else { | |
| 125 modifier = "unknown"; | |
| 126 } | |
| 127 #endif | |
| 128 | |
| 129 return ASCIIToUTF16(modifier); | |
| 130 } | |
| 131 | |
| 132 } // namespace platform_util | |
| OLD | NEW |