Disable TabDragController tests that fail with a real compositor.
[chromium-blink-merge.git] / chrome / browser / ui / gtk / process_singleton_dialog.cc
blobfe784c0611a27079a35858e0e445ee05f5646de9
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.
5 #include "chrome/browser/ui/process_singleton_dialog_linux.h"
7 #include <gtk/gtk.h>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/ui/gtk/gtk_util.h"
15 #include "grit/chromium_strings.h"
16 #include "ui/base/gtk/gtk_signal.h"
17 #include "ui/base/l10n/l10n_util.h"
19 namespace {
21 class ProcessSingletonDialog {
22 public:
23 ProcessSingletonDialog(const std::string& message,
24 const std::string& relaunch_text);
26 int GetResponseId() const { return response_id_; }
28 private:
29 CHROMEGTK_CALLBACK_1(ProcessSingletonDialog, void, OnResponse, int);
31 GtkWidget* dialog_;
32 int response_id_;
34 DISALLOW_COPY_AND_ASSIGN(ProcessSingletonDialog);
37 ProcessSingletonDialog::ProcessSingletonDialog(
38 const std::string& message,
39 const std::string& relaunch_text) {
40 dialog_ = gtk_message_dialog_new(
41 NULL,
42 static_cast<GtkDialogFlags>(0),
43 GTK_MESSAGE_ERROR,
44 GTK_BUTTONS_NONE,
45 "%s",
46 message.c_str());
47 gtk_util::ApplyMessageDialogQuirks(dialog_);
48 gtk_window_set_title(GTK_WINDOW(dialog_),
49 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME).c_str());
50 gtk_dialog_add_button(GTK_DIALOG(dialog_), GTK_STOCK_QUIT,
51 GTK_RESPONSE_REJECT);
52 gtk_dialog_add_button(GTK_DIALOG(dialog_), relaunch_text.c_str(),
53 GTK_RESPONSE_ACCEPT);
54 gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT);
56 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this);
58 gtk_widget_show_all(dialog_);
59 base::MessageLoop::current()->Run();
62 void ProcessSingletonDialog::OnResponse(GtkWidget* dialog, int response_id) {
63 response_id_ = response_id;
64 gtk_widget_destroy(dialog_);
65 base::MessageLoop::current()->Quit();
68 } // namespace
70 bool ShowProcessSingletonDialog(const base::string16& message,
71 const base::string16& relaunch_text) {
72 ProcessSingletonDialog dialog(base::UTF16ToUTF8(message),
73 base::UTF16ToUTF8(relaunch_text));
74 return dialog.GetResponseId() == GTK_RESPONSE_ACCEPT;