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 "chrome/browser/chrome_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 l10n_util::GetStringUTF8(IDS_LOGIN_DIALOG_USERNAME_FIELD).c_str(), | 99 l10n_util::GetStringUTF8(IDS_LOGIN_DIALOG_USERNAME_FIELD).c_str(), |
100 username_entry_, | 100 username_entry_, |
101 l10n_util::GetStringUTF8(IDS_LOGIN_DIALOG_PASSWORD_FIELD).c_str(), | 101 l10n_util::GetStringUTF8(IDS_LOGIN_DIALOG_PASSWORD_FIELD).c_str(), |
102 password_entry_, | 102 password_entry_, |
103 NULL); | 103 NULL); |
104 gtk_box_pack_start(GTK_BOX(root_.get()), table, FALSE, FALSE, 0); | 104 gtk_box_pack_start(GTK_BOX(root_.get()), table, FALSE, FALSE, 0); |
105 | 105 |
106 GtkWidget* hbox = gtk_hbox_new(FALSE, 12); | 106 GtkWidget* hbox = gtk_hbox_new(FALSE, 12); |
107 gtk_box_pack_start(GTK_BOX(root_.get()), hbox, FALSE, FALSE, 0); | 107 gtk_box_pack_start(GTK_BOX(root_.get()), hbox, FALSE, FALSE, 0); |
108 | 108 |
109 GtkWidget* ok = gtk_button_new_from_stock(GTK_STOCK_OK); | 109 ok_ = gtk_button_new_from_stock(GTK_STOCK_OK); |
110 gtk_button_set_label( | 110 gtk_button_set_label( |
111 GTK_BUTTON(ok), | 111 GTK_BUTTON(ok_), |
112 l10n_util::GetStringUTF8(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL).c_str()); | 112 l10n_util::GetStringUTF8(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL).c_str()); |
113 g_signal_connect(ok, "clicked", G_CALLBACK(OnOKClicked), this); | 113 g_signal_connect(ok_, "clicked", G_CALLBACK(OnOKClicked), this); |
114 gtk_box_pack_end(GTK_BOX(hbox), ok, FALSE, FALSE, 0); | 114 gtk_box_pack_end(GTK_BOX(hbox), ok_, FALSE, FALSE, 0); |
115 | 115 |
116 GtkWidget* cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | 116 GtkWidget* cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL); |
117 g_signal_connect(cancel, "clicked", G_CALLBACK(OnCancelClicked), this); | 117 g_signal_connect(cancel, "clicked", G_CALLBACK(OnCancelClicked), this); |
118 gtk_box_pack_end(GTK_BOX(hbox), cancel, FALSE, FALSE, 0); | 118 gtk_box_pack_end(GTK_BOX(hbox), cancel, FALSE, FALSE, 0); |
119 | 119 |
| 120 g_signal_connect(root_.get(), "hierarchy-changed", |
| 121 G_CALLBACK(OnPromptShown), this); |
| 122 |
120 SetModel(manager); | 123 SetModel(manager); |
121 | 124 |
122 // Scary thread safety note: This can potentially be called *after* SetAuth | 125 // Scary thread safety note: This can potentially be called *after* SetAuth |
123 // or CancelAuth (say, if the request was cancelled before the UI thread got | 126 // or CancelAuth (say, if the request was cancelled before the UI thread got |
124 // control). However, that's OK since any UI interaction in those functions | 127 // control). However, that's OK since any UI interaction in those functions |
125 // will occur via an InvokeLater on the UI thread, which is guaranteed | 128 // will occur via an InvokeLater on the UI thread, which is guaranteed |
126 // to happen after this is called (since this was InvokeLater'd first). | 129 // to happen after this is called (since this was InvokeLater'd first). |
127 dialog_ = GetTabContentsForLogin()->CreateConstrainedDialog(this); | 130 dialog_ = GetTabContentsForLogin()->CreateConstrainedDialog(this); |
128 | 131 |
129 // Now that we have attached ourself to the window, we can make our OK | |
130 // button the default action and mess with the focus. | |
131 GTK_WIDGET_SET_FLAGS(ok, GTK_CAN_DEFAULT); | |
132 gtk_widget_grab_default(ok); | |
133 gtk_widget_grab_focus(username_entry_); | |
134 | |
135 SendNotifications(); | 132 SendNotifications(); |
136 } | 133 } |
137 | 134 |
138 virtual void SetPasswordForm(const webkit_glue::PasswordForm& form) { | 135 virtual void SetPasswordForm(const webkit_glue::PasswordForm& form) { |
139 password_form_ = form; | 136 password_form_ = form; |
140 } | 137 } |
141 | 138 |
142 virtual void SetPasswordManager(PasswordManager* password_manager) { | 139 virtual void SetPasswordManager(PasswordManager* password_manager) { |
143 password_manager_ = password_manager; | 140 password_manager_ = password_manager; |
144 } | 141 } |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 service->Notify(NotificationType::AUTH_NEEDED, | 280 service->Notify(NotificationType::AUTH_NEEDED, |
284 Source<NavigationController>(controller), | 281 Source<NavigationController>(controller), |
285 Details<LoginNotificationDetails>(&details)); | 282 Details<LoginNotificationDetails>(&details)); |
286 } else { | 283 } else { |
287 service->Notify(NotificationType::AUTH_SUPPLIED, | 284 service->Notify(NotificationType::AUTH_SUPPLIED, |
288 Source<NavigationController>(controller), | 285 Source<NavigationController>(controller), |
289 NotificationService::NoDetails()); | 286 NotificationService::NoDetails()); |
290 } | 287 } |
291 } | 288 } |
292 | 289 |
293 static void OnOKClicked(GtkButton *button, LoginHandlerGtk* handler) { | 290 static void OnOKClicked(GtkButton* button, LoginHandlerGtk* handler) { |
294 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 291 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
295 | 292 |
296 handler->SetAuth( | 293 handler->SetAuth( |
297 UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(handler->username_entry_))), | 294 UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(handler->username_entry_))), |
298 UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(handler->password_entry_)))); | 295 UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(handler->password_entry_)))); |
299 } | 296 } |
300 | 297 |
301 static void OnCancelClicked(GtkButton *button, LoginHandlerGtk* handler) { | 298 static void OnCancelClicked(GtkButton* button, LoginHandlerGtk* handler) { |
302 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 299 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
303 handler->CancelAuth(); | 300 handler->CancelAuth(); |
304 } | 301 } |
305 | 302 |
| 303 static void OnPromptShown(GtkButton* root, |
| 304 GtkWidget* previous_toplevel, |
| 305 LoginHandlerGtk* handler) { |
| 306 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 307 if (!GTK_WIDGET_TOPLEVEL(gtk_widget_get_toplevel(handler->ok_))) |
| 308 return; |
| 309 |
| 310 // Now that we have attached ourself to the window, we can make our OK |
| 311 // button the default action and mess with the focus. |
| 312 GTK_WIDGET_SET_FLAGS(handler->ok_, GTK_CAN_DEFAULT); |
| 313 gtk_widget_grab_default(handler->ok_); |
| 314 gtk_widget_grab_focus(handler->username_entry_); |
| 315 } |
| 316 |
306 // True if we've handled auth (SetAuth or CancelAuth has been called). | 317 // True if we've handled auth (SetAuth or CancelAuth has been called). |
307 bool handled_auth_; | 318 bool handled_auth_; |
308 Lock handled_auth_lock_; | 319 Lock handled_auth_lock_; |
309 | 320 |
310 // The ConstrainedWindow that is hosting our LoginView. | 321 // The ConstrainedWindow that is hosting our LoginView. |
311 // This should only be accessed on the UI loop. | 322 // This should only be accessed on the UI loop. |
312 ConstrainedWindow* dialog_; | 323 ConstrainedWindow* dialog_; |
313 | 324 |
314 // The request that wants login data. | 325 // The request that wants login data. |
315 // This should only be accessed on the IO loop. | 326 // This should only be accessed on the IO loop. |
(...skipping 13 matching lines...) Expand all Loading... |
329 // Cached from the URLRequest, in case it goes NULL on us. | 340 // Cached from the URLRequest, in case it goes NULL on us. |
330 int render_process_host_id_; | 341 int render_process_host_id_; |
331 int tab_contents_id_; | 342 int tab_contents_id_; |
332 | 343 |
333 // The GtkWidgets that form our visual hierarchy: | 344 // The GtkWidgets that form our visual hierarchy: |
334 // The root container we pass to our parent. | 345 // The root container we pass to our parent. |
335 OwnedWidgetGtk root_; | 346 OwnedWidgetGtk root_; |
336 | 347 |
337 // GtkEntry widgets that the user types into. | 348 // GtkEntry widgets that the user types into. |
338 GtkWidget* username_entry_; | 349 GtkWidget* username_entry_; |
| 350 GtkWidget* ok_; |
339 GtkWidget* password_entry_; | 351 GtkWidget* password_entry_; |
340 | 352 |
341 // If not null, points to a model we need to notify of our own destruction | 353 // If not null, points to a model we need to notify of our own destruction |
342 // so it doesn't try and access this when its too late. | 354 // so it doesn't try and access this when its too late. |
343 LoginModel* login_model_; | 355 LoginModel* login_model_; |
344 | 356 |
345 DISALLOW_COPY_AND_ASSIGN(LoginHandlerGtk); | 357 DISALLOW_COPY_AND_ASSIGN(LoginHandlerGtk); |
346 }; | 358 }; |
347 | 359 |
348 // static | 360 // static |
349 LoginHandler* LoginHandler::Create(URLRequest* request) { | 361 LoginHandler* LoginHandler::Create(URLRequest* request) { |
350 return new LoginHandlerGtk(request); | 362 return new LoginHandlerGtk(request); |
351 } | 363 } |
OLD | NEW |