| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/shell/shell_javascript_dialog.h" | 5 #include "content/shell/shell_javascript_dialog.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "content/shell/resource.h" | 12 #include "content/shell/resource.h" |
| 13 #include "content/shell/shell.h" | 13 #include "content/shell/shell.h" |
| 14 #include "content/shell/shell_javascript_dialog_creator.h" | 14 #include "content/shell/shell_javascript_dialog_manager.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const char kPromptTextId[] = "content_shell_prompt_text"; | 18 const char kPromptTextId[] = "content_shell_prompt_text"; |
| 19 | 19 |
| 20 // If there's a text entry in the dialog, get the text from the first one and | 20 // If there's a text entry in the dialog, get the text from the first one and |
| 21 // return it. | 21 // return it. |
| 22 string16 GetPromptText(GtkDialog* dialog) { | 22 string16 GetPromptText(GtkDialog* dialog) { |
| 23 GtkWidget* widget = static_cast<GtkWidget*>( | 23 GtkWidget* widget = static_cast<GtkWidget*>( |
| 24 g_object_get_data(G_OBJECT(dialog), kPromptTextId)); | 24 g_object_get_data(G_OBJECT(dialog), kPromptTextId)); |
| 25 if (widget) | 25 if (widget) |
| 26 return UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(widget))); | 26 return UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(widget))); |
| 27 return string16(); | 27 return string16(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 | 32 |
| 33 namespace content { | 33 namespace content { |
| 34 | 34 |
| 35 ShellJavaScriptDialog::ShellJavaScriptDialog( | 35 ShellJavaScriptDialog::ShellJavaScriptDialog( |
| 36 ShellJavaScriptDialogCreator* creator, | 36 ShellJavaScriptDialogManager* manager, |
| 37 gfx::NativeWindow parent_window, | 37 gfx::NativeWindow parent_window, |
| 38 JavaScriptMessageType message_type, | 38 JavaScriptMessageType message_type, |
| 39 const string16& message_text, | 39 const string16& message_text, |
| 40 const string16& default_prompt_text, | 40 const string16& default_prompt_text, |
| 41 const JavaScriptDialogCreator::DialogClosedCallback& callback) | 41 const JavaScriptDialogManager::DialogClosedCallback& callback) |
| 42 : creator_(creator), | 42 : manager_(manager), |
| 43 callback_(callback), | 43 callback_(callback), |
| 44 parent_window_(parent_window) { | 44 parent_window_(parent_window) { |
| 45 GtkButtonsType buttons = GTK_BUTTONS_NONE; | 45 GtkButtonsType buttons = GTK_BUTTONS_NONE; |
| 46 GtkMessageType gtk_message_type = GTK_MESSAGE_OTHER; | 46 GtkMessageType gtk_message_type = GTK_MESSAGE_OTHER; |
| 47 | 47 |
| 48 switch (message_type) { | 48 switch (message_type) { |
| 49 case content::JAVASCRIPT_MESSAGE_TYPE_ALERT: | 49 case content::JAVASCRIPT_MESSAGE_TYPE_ALERT: |
| 50 buttons = GTK_BUTTONS_NONE; | 50 buttons = GTK_BUTTONS_NONE; |
| 51 gtk_message_type = GTK_MESSAGE_WARNING; | 51 gtk_message_type = GTK_MESSAGE_WARNING; |
| 52 break; | 52 break; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 case GTK_RESPONSE_CANCEL: | 114 case GTK_RESPONSE_CANCEL: |
| 115 case GTK_RESPONSE_DELETE_EVENT: | 115 case GTK_RESPONSE_DELETE_EVENT: |
| 116 callback_.Run(false, string16()); | 116 callback_.Run(false, string16()); |
| 117 break; | 117 break; |
| 118 default: | 118 default: |
| 119 NOTREACHED(); | 119 NOTREACHED(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 gtk_widget_destroy(dialog); | 122 gtk_widget_destroy(dialog); |
| 123 | 123 |
| 124 creator_->DialogClosed(this); | 124 manager_->DialogClosed(this); |
| 125 } | 125 } |
| 126 | 126 |
| 127 } // namespace content | 127 } // namespace content |
| OLD | NEW |