| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chrome_browser_main_gtk.h" | |
| 6 | |
| 7 #include <gtk/gtk.h> | |
| 8 | |
| 9 #include "base/command_line.h" | |
| 10 #include "chrome/common/chrome_switches.h" | |
| 11 #include "grit/chromium_strings.h" | |
| 12 #include "grit/generated_resources.h" | |
| 13 #include "ui/base/l10n/l10n_util.h" | |
| 14 #include "ui/base/resource/resource_bundle.h" | |
| 15 #include "ui/gfx/gtk_util.h" | |
| 16 | |
| 17 ChromeBrowserMainPartsGtk::ChromeBrowserMainPartsGtk( | |
| 18 const MainFunctionParams& parameters) | |
| 19 : ChromeBrowserMainPartsPosix(parameters) { | |
| 20 } | |
| 21 | |
| 22 void ChromeBrowserMainPartsGtk::PreEarlyInitialization() { | |
| 23 DetectRunningAsRoot(); | |
| 24 | |
| 25 ChromeBrowserMainPartsPosix::PreEarlyInitialization(); | |
| 26 } | |
| 27 | |
| 28 void ChromeBrowserMainPartsGtk::DetectRunningAsRoot() { | |
| 29 if (geteuid() == 0) { | |
| 30 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 31 if (parsed_command_line().HasSwitch(switches::kUserDataDir)) | |
| 32 return; | |
| 33 | |
| 34 gfx::GtkInitFromCommandLine(command_line); | |
| 35 | |
| 36 // Get just enough of our resource machinery up so we can extract the | |
| 37 // locale appropriate string. Note that the GTK implementation ignores the | |
| 38 // passed in parameter and checks the LANG environment variables instead. | |
| 39 ResourceBundle::InitSharedInstance(""); | |
| 40 | |
| 41 std::string message = l10n_util::GetStringFUTF8( | |
| 42 IDS_REFUSE_TO_RUN_AS_ROOT, | |
| 43 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | |
| 44 GtkWidget* dialog = gtk_message_dialog_new( | |
| 45 NULL, | |
| 46 static_cast<GtkDialogFlags>(0), | |
| 47 GTK_MESSAGE_ERROR, | |
| 48 GTK_BUTTONS_CLOSE, | |
| 49 "%s", | |
| 50 message.c_str()); | |
| 51 | |
| 52 LOG(ERROR) << "Startup refusing to run as root."; | |
| 53 message = l10n_util::GetStringFUTF8( | |
| 54 IDS_REFUSE_TO_RUN_AS_ROOT_2, | |
| 55 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | |
| 56 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), | |
| 57 "%s", | |
| 58 message.c_str()); | |
| 59 | |
| 60 message = l10n_util::GetStringUTF8(IDS_PRODUCT_NAME); | |
| 61 gtk_window_set_title(GTK_WINDOW(dialog), message.c_str()); | |
| 62 | |
| 63 gtk_dialog_run(GTK_DIALOG(dialog)); | |
| 64 gtk_widget_destroy(dialog); | |
| 65 exit(EXIT_FAILURE); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 void ShowMissingLocaleMessageBox() { | |
| 70 GtkWidget* dialog = gtk_message_dialog_new( | |
| 71 NULL, | |
| 72 static_cast<GtkDialogFlags>(0), | |
| 73 GTK_MESSAGE_ERROR, | |
| 74 GTK_BUTTONS_CLOSE, | |
| 75 "%s", | |
| 76 chrome_browser::kMissingLocaleDataMessage); | |
| 77 | |
| 78 gtk_window_set_title(GTK_WINDOW(dialog), | |
| 79 chrome_browser::kMissingLocaleDataTitle); | |
| 80 | |
| 81 gtk_dialog_run(GTK_DIALOG(dialog)); | |
| 82 gtk_widget_destroy(dialog); | |
| 83 } | |
| OLD | NEW |