1616
1717namespace {
1818
19+ // If there's a text entry in the dialog, get the text from the first one and
20+ // return it.
21+ std::wstring GetPromptText (GtkDialog* dialog) {
22+ // TODO(tc): Replace with gtk_dialog_get_content_area() when using GTK 2.14+
23+ GtkWidget* contents_vbox = dialog->vbox ;
24+ GList* first_child = gtk_container_get_children (GTK_CONTAINER (contents_vbox));
25+ for (GList* item = first_child; item; g_list_next (item)) {
26+ if (GTK_IS_ENTRY (item->data )) {
27+ return UTF8ToWide (gtk_entry_get_text (GTK_ENTRY (item->data )));
28+ }
29+ }
30+ return std::wstring ();
31+ }
32+
1933void OnDialogResponse (GtkDialog* dialog, gint response_id,
2034 AppModalDialog* app_modal_dialog) {
2135 switch (response_id) {
2236 case GTK_RESPONSE_OK:
2337 // The first arg is the prompt text and the second is true if we want to
2438 // suppress additional popups from the page.
25- app_modal_dialog->OnAccept (std::wstring ( ), false );
39+ app_modal_dialog->OnAccept (GetPromptText (dialog ), false );
2640 break ;
2741
2842 case GTK_RESPONSE_CANCEL:
@@ -63,13 +77,7 @@ void AppModalDialog::CreateAndShowDialog() {
6377 break ;
6478
6579 case MessageBoxFlags::kIsJavascriptPrompt :
66- // We need to make a custom message box for javascript prompts. For now
67- // just have an OK button and send back an empty string. Maybe we can
68- // cram a GtkEntry into the content area of the message box via
69- // gtk_dialog_get_content_area.
70- // http://crbug.com/9623
71- NOTIMPLEMENTED ();
72- buttons = GTK_BUTTONS_OK;
80+ buttons = GTK_BUTTONS_OK_CANCEL;
7381 message_type = GTK_MESSAGE_QUESTION;
7482 break ;
7583
@@ -92,18 +100,26 @@ void AppModalDialog::CreateAndShowDialog() {
92100 IDS_BEFOREUNLOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL);
93101 gtk_dialog_add_button (GTK_DIALOG (dialog_), button_text.c_str (),
94102 GTK_RESPONSE_CANCEL);
103+ } else if (MessageBoxFlags::kIsJavascriptPrompt == dialog_flags_) {
104+ // TODO(tc): Replace with gtk_dialog_get_content_area() when using GTK 2.14+
105+ GtkWidget* contents_vbox = GTK_DIALOG (dialog_)->vbox ;
106+ GtkWidget* text_box = gtk_entry_new ();
107+ gtk_entry_set_text (GTK_ENTRY (text_box),
108+ WideToUTF8 (default_prompt_text_).c_str ());
109+ gtk_widget_show (text_box);
110+ gtk_box_pack_start (GTK_BOX (contents_vbox), text_box, TRUE , TRUE , 0 );
95111 }
96112
97113 g_signal_connect (dialog_, " response" , G_CALLBACK (OnDialogResponse), this );
98114 gtk_widget_show (GTK_WIDGET (GTK_DIALOG (dialog_)));
99115}
100116
101117void AppModalDialog::ActivateModalDialog () {
102- NOTIMPLEMENTED ( );
118+ gtk_window_present ( GTK_WINDOW (dialog_) );
103119}
104120
105121void AppModalDialog::CloseModalDialog () {
106- NOTIMPLEMENTED ( );
122+ OnDialogResponse ( GTK_DIALOG (dialog_), GTK_RESPONSE_DELETE_EVENT, this );
107123}
108124
109125int AppModalDialog::GetDialogButtons () {
0 commit comments