1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h"
9 #include "base/command_line.h"
10 #include "chrome/browser/chrome_browser_main.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "grit/chromium_strings.h"
13 #include "grit/generated_resources.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/gtk_util.h"
18 ChromeBrowserMainExtraPartsGtk::ChromeBrowserMainExtraPartsGtk() {
21 void ChromeBrowserMainExtraPartsGtk::PreEarlyInitialization() {
22 DetectRunningAsRoot();
26 void ChromeBrowserMainExtraPartsGtk::DetectRunningAsRoot() {
28 const CommandLine
& command_line
= *CommandLine::ForCurrentProcess();
29 if (command_line
.HasSwitch(switches::kUserDataDir
))
32 gfx::GtkInitFromCommandLine(command_line
);
34 // Get just enough of our resource machinery up so we can extract the
35 // locale appropriate string. Note that the GTK implementation ignores the
36 // passed in parameter and checks the LANG environment variables instead.
37 ResourceBundle::InitSharedInstanceWithLocale(std::string(), NULL
);
39 std::string message
= l10n_util::GetStringFUTF8(
40 IDS_REFUSE_TO_RUN_AS_ROOT
,
41 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME
));
42 GtkWidget
* dialog
= gtk_message_dialog_new(
44 static_cast<GtkDialogFlags
>(0),
50 LOG(ERROR
) << "Startup refusing to run as root.";
51 message
= l10n_util::GetStringFUTF8(
52 IDS_REFUSE_TO_RUN_AS_ROOT_2
,
53 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME
));
54 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog
),
58 message
= l10n_util::GetStringUTF8(IDS_PRODUCT_NAME
);
59 gtk_window_set_title(GTK_WINDOW(dialog
), message
.c_str());
61 gtk_dialog_run(GTK_DIALOG(dialog
));
62 gtk_widget_destroy(dialog
);
68 void ChromeBrowserMainExtraPartsGtk::ShowMessageBox(const char* message
) {
69 GtkWidget
* dialog
= gtk_message_dialog_new(
71 static_cast<GtkDialogFlags
>(0),
77 gtk_window_set_title(GTK_WINDOW(dialog
), message
);
78 gtk_dialog_run(GTK_DIALOG(dialog
));
79 gtk_widget_destroy(dialog
);