summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/app_modal_dialog.h3
-rw-r--r--chrome/browser/app_modal_dialog_gtk.cc120
-rw-r--r--chrome/browser/automation/automation_provider.cc5
-rw-r--r--chrome/browser/jsmessage_box_handler.cc4
-rw-r--r--chrome/chrome.gyp2
5 files changed, 128 insertions, 6 deletions
diff --git a/chrome/browser/app_modal_dialog.h b/chrome/browser/app_modal_dialog.h
index 2f09a7e..7aa0b10 100644
--- a/chrome/browser/app_modal_dialog.h
+++ b/chrome/browser/app_modal_dialog.h
@@ -15,7 +15,8 @@
class JavascriptMessageBoxDialog;
typedef JavascriptMessageBoxDialog* NativeDialog;
#elif defined(OS_LINUX)
-typedef void* NativeDialog;
+typedef struct _GtkWidget GtkWidget;
+typedef GtkWidget* NativeDialog;
#elif defined(OS_MACOSX)
typedef void* NativeDialog;
#endif
diff --git a/chrome/browser/app_modal_dialog_gtk.cc b/chrome/browser/app_modal_dialog_gtk.cc
new file mode 100644
index 0000000..37a4ac2
--- /dev/null
+++ b/chrome/browser/app_modal_dialog_gtk.cc
@@ -0,0 +1,120 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/app_modal_dialog.h"
+
+#include <gtk/gtk.h>
+
+#include "base/logging.h"
+#include "base/string_util.h"
+#include "chrome/browser/tab_contents/web_contents.h"
+#include "chrome/browser/tab_contents/web_contents_view.h"
+#include "chrome/common/l10n_util.h"
+#include "chrome/common/message_box_flags.h"
+#include "grit/generated_resources.h"
+
+namespace {
+
+void OnDialogResponse(GtkDialog* dialog, gint response_id,
+ AppModalDialog* app_modal_dialog) {
+ switch (response_id) {
+ case GTK_RESPONSE_OK:
+ // The first arg is the prompt text and the second is true if we want to
+ // suppress additional popups from the page.
+ app_modal_dialog->OnAccept(std::wstring(), false);
+ break;
+
+ case GTK_RESPONSE_CANCEL:
+ case GTK_RESPONSE_DELETE_EVENT: // User hit the X on the dialog.
+ app_modal_dialog->OnCancel();
+ break;
+
+ default:
+ NOTREACHED();
+ }
+ gtk_widget_destroy(GTK_WIDGET(dialog));
+ delete app_modal_dialog;
+}
+
+} // namespace
+
+AppModalDialog::~AppModalDialog() {
+}
+
+void AppModalDialog::CreateAndShowDialog() {
+ GtkButtonsType buttons;
+ GtkMessageType message_type;
+ switch (dialog_flags_) {
+ case MessageBox::kIsJavascriptAlert:
+ buttons = GTK_BUTTONS_OK;
+ message_type = GTK_MESSAGE_WARNING;
+ break;
+
+ case MessageBox::kIsJavascriptConfirm:
+ if (is_before_unload_dialog_) {
+ // onbeforeunload also uses a confirm prompt, it just has custom
+ // buttons. We add the buttons using gtk_dialog_add_button below.
+ buttons = GTK_BUTTONS_NONE;
+ } else {
+ buttons = GTK_BUTTONS_OK_CANCEL;
+ }
+ message_type = GTK_MESSAGE_QUESTION;
+ break;
+
+ case MessageBox::kIsJavascriptPrompt:
+ // We need to make a custom message box for javascript prompts. For now
+ // just have an OK button and send back an empty string. Maybe we can
+ // cram a GtkEntry into the content area of the message box via
+ // gtk_dialog_get_content_area.
+ // http://crbug.com/9623
+ NOTIMPLEMENTED();
+ buttons = GTK_BUTTONS_OK;
+ message_type = GTK_MESSAGE_QUESTION;
+ break;
+
+ default:
+ NOTREACHED();
+ }
+
+ GtkWindow* window = web_contents_->view()->GetTopLevelNativeWindow();
+ dialog_ = gtk_message_dialog_new(window, GTK_DIALOG_MODAL,
+ message_type, buttons, WideToUTF8(message_text_).c_str());
+ gtk_window_set_title(GTK_WINDOW(dialog_), WideToUTF8(title_).c_str());
+
+ if (is_before_unload_dialog_) {
+ std::string button_text = l10n_util::GetStringUTF8(
+ IDS_BEFOREUNLOAD_MESSAGEBOX_OK_BUTTON_LABEL);
+ gtk_dialog_add_button(GTK_DIALOG(dialog_), button_text.c_str(),
+ GTK_RESPONSE_OK);
+
+ button_text = l10n_util::GetStringUTF8(
+ IDS_BEFOREUNLOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL);
+ gtk_dialog_add_button(GTK_DIALOG(dialog_), button_text.c_str(),
+ GTK_RESPONSE_CANCEL);
+ }
+
+ g_signal_connect(dialog_, "response", G_CALLBACK(OnDialogResponse), this);
+ gtk_widget_show(GTK_WIDGET(GTK_DIALOG(dialog_)));
+}
+
+void AppModalDialog::ActivateModalDialog() {
+ NOTIMPLEMENTED();
+}
+
+void AppModalDialog::CloseModalDialog() {
+ NOTIMPLEMENTED();
+}
+
+int AppModalDialog::GetDialogButtons() {
+ NOTIMPLEMENTED();
+ return 0;
+}
+
+void AppModalDialog::AcceptWindow() {
+ NOTIMPLEMENTED();
+}
+
+void AppModalDialog::CancelWindow() {
+ NOTIMPLEMENTED();
+}
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index a7853be..81d0137 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -10,6 +10,7 @@
#include "base/thread.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/app_modal_dialog.h"
+#include "chrome/browser/app_modal_dialog_queue.h"
#include "chrome/browser/automation/automation_provider_list.h"
#include "chrome/browser/automation/url_request_failed_dns_job.h"
#include "chrome/browser/automation/url_request_mock_http_job.h"
@@ -35,7 +36,6 @@
#if defined(OS_WIN)
// TODO(port): Port these headers.
-#include "chrome/browser/app_modal_dialog_queue.h"
#include "chrome/browser/automation/ui_controls.h"
#include "chrome/browser/character_encoding.h"
#include "chrome/browser/download/save_package.h"
@@ -1257,7 +1257,8 @@ void AutomationProvider::GetBrowserWindowCount(int* window_count) {
}
#if defined(OS_WIN)
-// TODO(port): Enable when dialog delegate is ported.
+// TODO(port): Move the views::DialogDelegate::DialogButton enum out into a
+// common place then remove the OS_WIN guard.
void AutomationProvider::GetShowingAppModalDialog(bool* showing_dialog,
int* dialog_button) {
AppModalDialog* dialog_delegate = AppModalDialogQueue::active_dialog();
diff --git a/chrome/browser/jsmessage_box_handler.cc b/chrome/browser/jsmessage_box_handler.cc
index 426d10b..1bf7b21 100644
--- a/chrome/browser/jsmessage_box_handler.cc
+++ b/chrome/browser/jsmessage_box_handler.cc
@@ -53,7 +53,7 @@ void RunJavascriptMessageBox(WebContents* web_contents,
IPC::Message* reply_msg) {
std::wstring title = GetWindowTitle(web_contents, frame_url);
-#if defined(OS_WIN)
+#if defined(OS_WIN) || defined(OS_LINUX)
AppModalDialogQueue::AddDialog(new AppModalDialog(web_contents, title,
dialog_flags, message_text, default_prompt_text,
display_suppress_checkbox, false, reply_msg));
@@ -68,7 +68,7 @@ void RunBeforeUnloadDialog(WebContents* web_contents,
std::wstring full_message =
message_text + L"\n\n" +
l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_FOOTER);
-#if defined(OS_WIN)
+#if defined(OS_WIN) || defined(OS_LINUX)
AppModalDialogQueue::AddDialog(new AppModalDialog(
web_contents, l10n_util::GetString(IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE),
MessageBox::kIsJavascriptConfirm, message_text, std::wstring(), false,
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 6d1c473..8738ed2 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -384,6 +384,7 @@
'browser/app_controller_mac.mm',
'browser/app_modal_dialog.cc',
'browser/app_modal_dialog.h',
+ 'browser/app_modal_dialog_gtk.cc',
'browser/app_modal_dialog_win.cc',
'browser/app_modal_dialog_queue.cc',
'browser/app_modal_dialog_queue.h',
@@ -1345,7 +1346,6 @@
['exclude', '^browser/views/'],
],
'sources!': [
- 'browser/app_modal_dialog_queue.cc',
'browser/autocomplete/autocomplete_accessibility.cc',
'browser/automation/ui_controls.cc',
'browser/browser_accessibility.cc',