| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/login_prompt.h" | 5 #include "chrome/browser/login_prompt.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/gtk_signal.h" |
| 10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/chrome_thread.h" | 12 #include "chrome/browser/chrome_thread.h" |
| 12 #include "chrome/browser/gtk/constrained_window_gtk.h" | 13 #include "chrome/browser/gtk/constrained_window_gtk.h" |
| 13 #include "chrome/browser/gtk/gtk_util.h" | 14 #include "chrome/browser/gtk/gtk_util.h" |
| 14 #include "chrome/browser/login_model.h" | 15 #include "chrome/browser/login_model.h" |
| 15 #include "chrome/browser/password_manager/password_manager.h" | 16 #include "chrome/browser/password_manager/password_manager.h" |
| 16 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 17 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 17 #include "chrome/browser/tab_contents/navigation_controller.h" | 18 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 18 #include "chrome/browser/tab_contents/tab_contents.h" | 19 #include "chrome/browser/tab_contents/tab_contents.h" |
| 20 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h" |
| 19 #include "chrome/browser/tab_contents/tab_util.h" | 21 #include "chrome/browser/tab_contents/tab_util.h" |
| 20 #include "chrome/common/notification_service.h" | 22 #include "chrome/common/notification_service.h" |
| 21 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 22 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
| 23 | 25 |
| 24 using webkit_glue::PasswordForm; | 26 using webkit_glue::PasswordForm; |
| 25 | 27 |
| 26 // ---------------------------------------------------------------------------- | 28 // ---------------------------------------------------------------------------- |
| 27 // LoginHandlerGtk | 29 // LoginHandlerGtk |
| 28 | 30 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 NULL); | 84 NULL); |
| 83 gtk_box_pack_start(GTK_BOX(root_.get()), table, FALSE, FALSE, 0); | 85 gtk_box_pack_start(GTK_BOX(root_.get()), table, FALSE, FALSE, 0); |
| 84 | 86 |
| 85 GtkWidget* hbox = gtk_hbox_new(FALSE, 12); | 87 GtkWidget* hbox = gtk_hbox_new(FALSE, 12); |
| 86 gtk_box_pack_start(GTK_BOX(root_.get()), hbox, FALSE, FALSE, 0); | 88 gtk_box_pack_start(GTK_BOX(root_.get()), hbox, FALSE, FALSE, 0); |
| 87 | 89 |
| 88 ok_ = gtk_button_new_from_stock(GTK_STOCK_OK); | 90 ok_ = gtk_button_new_from_stock(GTK_STOCK_OK); |
| 89 gtk_button_set_label( | 91 gtk_button_set_label( |
| 90 GTK_BUTTON(ok_), | 92 GTK_BUTTON(ok_), |
| 91 l10n_util::GetStringUTF8(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL).c_str()); | 93 l10n_util::GetStringUTF8(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL).c_str()); |
| 92 g_signal_connect(ok_, "clicked", G_CALLBACK(OnOKClicked), this); | 94 g_signal_connect(ok_, "clicked", G_CALLBACK(OnOKClickedThunk), this); |
| 93 gtk_box_pack_end(GTK_BOX(hbox), ok_, FALSE, FALSE, 0); | 95 gtk_box_pack_end(GTK_BOX(hbox), ok_, FALSE, FALSE, 0); |
| 94 | 96 |
| 95 GtkWidget* cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | 97 GtkWidget* cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL); |
| 96 g_signal_connect(cancel, "clicked", G_CALLBACK(OnCancelClicked), this); | 98 g_signal_connect(cancel, "clicked", G_CALLBACK(OnCancelClickedThunk), this); |
| 97 gtk_box_pack_end(GTK_BOX(hbox), cancel, FALSE, FALSE, 0); | 99 gtk_box_pack_end(GTK_BOX(hbox), cancel, FALSE, FALSE, 0); |
| 98 | 100 |
| 99 g_signal_connect(root_.get(), "hierarchy-changed", | 101 g_signal_connect(root_.get(), "hierarchy-changed", |
| 100 G_CALLBACK(OnPromptShown), this); | 102 G_CALLBACK(OnPromptHierarchyChangedThunk), this); |
| 101 | 103 |
| 102 SetModel(manager); | 104 SetModel(manager); |
| 103 | 105 |
| 104 // Scary thread safety note: This can potentially be called *after* SetAuth | 106 // Scary thread safety note: This can potentially be called *after* SetAuth |
| 105 // or CancelAuth (say, if the request was cancelled before the UI thread got | 107 // or CancelAuth (say, if the request was cancelled before the UI thread got |
| 106 // control). However, that's OK since any UI interaction in those functions | 108 // control). However, that's OK since any UI interaction in those functions |
| 107 // will occur via an InvokeLater on the UI thread, which is guaranteed | 109 // will occur via an InvokeLater on the UI thread, which is guaranteed |
| 108 // to happen after this is called (since this was InvokeLater'd first). | 110 // to happen after this is called (since this was InvokeLater'd first). |
| 109 SetDialog(GetTabContentsForLogin()->CreateConstrainedDialog(this)); | 111 SetDialog(GetTabContentsForLogin()->CreateConstrainedDialog(this)); |
| 110 | 112 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 122 // The constrained window is going to delete itself; clear our pointer. | 124 // The constrained window is going to delete itself; clear our pointer. |
| 123 SetDialog(NULL); | 125 SetDialog(NULL); |
| 124 SetModel(NULL); | 126 SetModel(NULL); |
| 125 | 127 |
| 126 ReleaseSoon(); | 128 ReleaseSoon(); |
| 127 } | 129 } |
| 128 | 130 |
| 129 private: | 131 private: |
| 130 friend class LoginPrompt; | 132 friend class LoginPrompt; |
| 131 | 133 |
| 132 static void OnOKClicked(GtkButton *button, LoginHandlerGtk* handler) { | 134 CHROMEGTK_CALLBACK_0(LoginHandlerGtk, void, OnOKClicked); |
| 133 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 135 CHROMEGTK_CALLBACK_0(LoginHandlerGtk, void, OnCancelClicked); |
| 134 | 136 CHROMEGTK_CALLBACK_1(LoginHandlerGtk, void, OnPromptHierarchyChanged, |
| 135 handler->SetAuth( | 137 GtkWidget*); |
| 136 UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(handler->username_entry_))), | |
| 137 UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(handler->password_entry_)))); | |
| 138 } | |
| 139 | |
| 140 static void OnCancelClicked(GtkButton *button, LoginHandlerGtk* handler) { | |
| 141 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | |
| 142 | |
| 143 handler->CancelAuth(); | |
| 144 } | |
| 145 | |
| 146 static void OnPromptShown(GtkButton* root, | |
| 147 GtkWidget* previous_toplevel, | |
| 148 LoginHandlerGtk* handler) { | |
| 149 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | |
| 150 | |
| 151 if (!GTK_WIDGET_TOPLEVEL(gtk_widget_get_toplevel(handler->ok_))) | |
| 152 return; | |
| 153 | |
| 154 // Now that we have attached ourself to the window, we can make our OK | |
| 155 // button the default action and mess with the focus. | |
| 156 GTK_WIDGET_SET_FLAGS(handler->ok_, GTK_CAN_DEFAULT); | |
| 157 gtk_widget_grab_default(handler->ok_); | |
| 158 gtk_widget_grab_focus(handler->username_entry_); | |
| 159 } | |
| 160 | 138 |
| 161 // The GtkWidgets that form our visual hierarchy: | 139 // The GtkWidgets that form our visual hierarchy: |
| 162 // The root container we pass to our parent. | 140 // The root container we pass to our parent. |
| 163 OwnedWidgetGtk root_; | 141 OwnedWidgetGtk root_; |
| 164 | 142 |
| 165 // GtkEntry widgets that the user types into. | 143 // GtkEntry widgets that the user types into. |
| 166 GtkWidget* username_entry_; | 144 GtkWidget* username_entry_; |
| 167 GtkWidget* password_entry_; | 145 GtkWidget* password_entry_; |
| 168 GtkWidget* ok_; | 146 GtkWidget* ok_; |
| 169 | 147 |
| 170 DISALLOW_COPY_AND_ASSIGN(LoginHandlerGtk); | 148 DISALLOW_COPY_AND_ASSIGN(LoginHandlerGtk); |
| 171 }; | 149 }; |
| 172 | 150 |
| 151 void LoginHandlerGtk::OnOKClicked(GtkWidget* sender) { |
| 152 SetAuth( |
| 153 UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(username_entry_))), |
| 154 UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(password_entry_)))); |
| 155 } |
| 156 |
| 157 void LoginHandlerGtk::OnCancelClicked(GtkWidget* sender) { |
| 158 CancelAuth(); |
| 159 } |
| 160 |
| 161 void LoginHandlerGtk::OnPromptHierarchyChanged(GtkWidget* sender, |
| 162 GtkWidget* previous_toplevel) { |
| 163 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 164 |
| 165 if (!GTK_WIDGET_TOPLEVEL(gtk_widget_get_toplevel(ok_))) |
| 166 return; |
| 167 |
| 168 // Now that we have attached ourself to the window, we can make our OK |
| 169 // button the default action and mess with the focus. |
| 170 GTK_WIDGET_SET_FLAGS(ok_, GTK_CAN_DEFAULT); |
| 171 gtk_widget_grab_default(ok_); |
| 172 |
| 173 // The user may have focused another tab. In this case do not grab focus |
| 174 // until this tab is refocused. |
| 175 if (gtk_util::IsWidgetAncestryVisible(username_entry_)) { |
| 176 gtk_widget_grab_focus(username_entry_); |
| 177 } else { |
| 178 // TODO(estade): this define should not need to be here because this class |
| 179 // should not be used on linux/views. |
| 180 #if defined(TOOLKIT_GTK) |
| 181 static_cast<TabContentsViewGtk*>(GetTabContentsForLogin()->view())-> |
| 182 SetFocusedWidget(username_entry_); |
| 183 #endif |
| 184 } |
| 185 } |
| 186 |
| 173 // static | 187 // static |
| 174 LoginHandler* LoginHandler::Create(net::AuthChallengeInfo* auth_info, | 188 LoginHandler* LoginHandler::Create(net::AuthChallengeInfo* auth_info, |
| 175 URLRequest* request) { | 189 URLRequest* request) { |
| 176 return new LoginHandlerGtk(auth_info, request); | 190 return new LoginHandlerGtk(auth_info, request); |
| 177 } | 191 } |
| OLD | NEW |