Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: chrome/browser/login_prompt_gtk.cc

Issue 173341: Autofill http auth dialog on os x and linux. (Closed)
Patch Set: linux compiles and works Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/login_prompt_mac.h » ('j') | chrome/browser/login_prompt_mac.mm » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "chrome/browser/gtk/constrained_window_gtk.h" 11 #include "chrome/browser/gtk/constrained_window_gtk.h"
12 #include "chrome/browser/login_model.h"
12 #include "chrome/browser/password_manager/password_manager.h" 13 #include "chrome/browser/password_manager/password_manager.h"
13 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" 14 #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
14 #include "chrome/browser/tab_contents/navigation_controller.h" 15 #include "chrome/browser/tab_contents/navigation_controller.h"
15 #include "chrome/browser/tab_contents/tab_contents.h" 16 #include "chrome/browser/tab_contents/tab_contents.h"
16 #include "chrome/browser/tab_contents/tab_util.h" 17 #include "chrome/browser/tab_contents/tab_util.h"
17 #include "chrome/common/gtk_util.h" 18 #include "chrome/common/gtk_util.h"
18 #include "chrome/common/notification_service.h" 19 #include "chrome/common/notification_service.h"
19 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
20 #include "net/url_request/url_request.h" 21 #include "net/url_request/url_request.h"
21 22
22 using webkit_glue::PasswordForm; 23 using webkit_glue::PasswordForm;
23 24
24 // ---------------------------------------------------------------------------- 25 // ----------------------------------------------------------------------------
25 // LoginHandlerGtk 26 // LoginHandlerGtk
26 27
27 // This class simply forwards the authentication from the LoginView (on 28 // This class simply forwards the authentication from the LoginView (on
28 // the UI thread) to the URLRequest (on the I/O thread). 29 // the UI thread) to the URLRequest (on the I/O thread).
29 // This class uses ref counting to ensure that it lives until all InvokeLaters 30 // This class uses ref counting to ensure that it lives until all InvokeLaters
30 // have been called. 31 // have been called.
31 class LoginHandlerGtk : public LoginHandler, 32 class LoginHandlerGtk : public LoginHandler,
32 public base::RefCountedThreadSafe<LoginHandlerGtk>, 33 public base::RefCountedThreadSafe<LoginHandlerGtk>,
33 public ConstrainedWindowGtkDelegate { 34 public ConstrainedWindowGtkDelegate,
35 public LoginModelObserver {
34 public: 36 public:
35 LoginHandlerGtk(URLRequest* request, MessageLoop* ui_loop) 37 LoginHandlerGtk(URLRequest* request, MessageLoop* ui_loop)
36 : handled_auth_(false), 38 : handled_auth_(false),
37 dialog_(NULL), 39 dialog_(NULL),
38 ui_loop_(ui_loop), 40 ui_loop_(ui_loop),
39 request_(request), 41 request_(request),
40 request_loop_(MessageLoop::current()), 42 request_loop_(MessageLoop::current()),
41 password_manager_(NULL) { 43 password_manager_(NULL),
44 login_model_(NULL) {
42 DCHECK(request_) << "LoginHandlerGtk constructed with NULL request"; 45 DCHECK(request_) << "LoginHandlerGtk constructed with NULL request";
43 46
44 AddRef(); // matched by ReleaseLater. 47 AddRef(); // matched by ReleaseLater.
45 if (!ResourceDispatcherHost::RenderViewForRequest(request_, 48 if (!ResourceDispatcherHost::RenderViewForRequest(request_,
46 &render_process_host_id_, 49 &render_process_host_id_,
47 &tab_contents_id_)) { 50 &tab_contents_id_)) {
48 NOTREACHED(); 51 NOTREACHED();
49 } 52 }
50 } 53 }
51 54
52 virtual ~LoginHandlerGtk() { 55 virtual ~LoginHandlerGtk() {
56 if (login_model_)
57 login_model_->SetObserver(NULL);
53 root_.Destroy(); 58 root_.Destroy();
54 } 59 }
55 60
61 void SetModel(LoginModel* model) {
62 login_model_ = model;
63 if (login_model_)
64 login_model_->SetObserver(this);
65 }
66
67 // LoginModelObserver implementation.
68 virtual void OnAutofillDataAvailable(const std::wstring& username,
69 const std::wstring& password) {
70 // NOTE: Would be nice to use gtk_entry_get_text_length, but it is fairly
71 // new and not always in our GTK version.
72 if (strlen(gtk_entry_get_text(GTK_ENTRY(username_entry_))) == 0) {
73 gtk_entry_set_text(GTK_ENTRY(username_entry_),
74 WideToUTF8(username).c_str());
75 gtk_entry_set_text(GTK_ENTRY(password_entry_),
76 WideToUTF8(password).c_str());
77 gtk_editable_select_region(GTK_EDITABLE(username_entry_), 0, -1);
78 }
79 }
80
56 // LoginHandler: 81 // LoginHandler:
57 virtual void BuildViewForPasswordManager(PasswordManager* manager, 82 virtual void BuildViewForPasswordManager(PasswordManager* manager,
58 std::wstring explanation) { 83 std::wstring explanation) {
59 DCHECK(MessageLoop::current() == ui_loop_); 84 DCHECK(MessageLoop::current() == ui_loop_);
60 85
61 root_.Own(gtk_vbox_new(NULL, gtk_util::kContentAreaBorder)); 86 root_.Own(gtk_vbox_new(NULL, gtk_util::kContentAreaBorder));
62 GtkWidget* label = gtk_label_new(WideToUTF8(explanation).c_str()); 87 GtkWidget* label = gtk_label_new(WideToUTF8(explanation).c_str());
63 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); 88 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
64 gtk_box_pack_start(GTK_BOX(root_.get()), label, FALSE, FALSE, 0); 89 gtk_box_pack_start(GTK_BOX(root_.get()), label, FALSE, FALSE, 0);
65 90
(...skipping 19 matching lines...) Expand all
85 gtk_button_set_label( 110 gtk_button_set_label(
86 GTK_BUTTON(ok), 111 GTK_BUTTON(ok),
87 l10n_util::GetStringUTF8(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL).c_str()); 112 l10n_util::GetStringUTF8(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL).c_str());
88 g_signal_connect(ok, "clicked", G_CALLBACK(OnOKClicked), this); 113 g_signal_connect(ok, "clicked", G_CALLBACK(OnOKClicked), this);
89 gtk_box_pack_end(GTK_BOX(hbox), ok, FALSE, FALSE, 0); 114 gtk_box_pack_end(GTK_BOX(hbox), ok, FALSE, FALSE, 0);
90 115
91 GtkWidget* cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL); 116 GtkWidget* cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
92 g_signal_connect(cancel, "clicked", G_CALLBACK(OnCancelClicked), this); 117 g_signal_connect(cancel, "clicked", G_CALLBACK(OnCancelClicked), this);
93 gtk_box_pack_end(GTK_BOX(hbox), cancel, FALSE, FALSE, 0); 118 gtk_box_pack_end(GTK_BOX(hbox), cancel, FALSE, FALSE, 0);
94 119
120 SetModel(manager);
121
95 // Scary thread safety note: This can potentially be called *after* SetAuth 122 // Scary thread safety note: This can potentially be called *after* SetAuth
96 // or CancelAuth (say, if the request was cancelled before the UI thread got 123 // or CancelAuth (say, if the request was cancelled before the UI thread got
97 // control). However, that's OK since any UI interaction in those functions 124 // control). However, that's OK since any UI interaction in those functions
98 // will occur via an InvokeLater on the UI thread, which is guaranteed 125 // will occur via an InvokeLater on the UI thread, which is guaranteed
99 // to happen after this is called (since this was InvokeLater'd first). 126 // to happen after this is called (since this was InvokeLater'd first).
100 dialog_ = GetTabContentsForLogin()->CreateConstrainedDialog(this); 127 dialog_ = GetTabContentsForLogin()->CreateConstrainedDialog(this);
101 128
102 // Now that we have attached ourself to the window, we can make our OK 129 // Now that we have attached ourself to the window, we can make our OK
103 // button the default action and mess with the focus. 130 // button the default action and mess with the focus.
104 GTK_WIDGET_SET_FLAGS(ok, GTK_CAN_DEFAULT); 131 GTK_WIDGET_SET_FLAGS(ok, GTK_CAN_DEFAULT);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 int tab_contents_id_; 326 int tab_contents_id_;
300 327
301 // The GtkWidgets that form our visual hierarchy: 328 // The GtkWidgets that form our visual hierarchy:
302 // The root container we pass to our parent. 329 // The root container we pass to our parent.
303 OwnedWidgetGtk root_; 330 OwnedWidgetGtk root_;
304 331
305 // GtkEntry widgets that the user types into. 332 // GtkEntry widgets that the user types into.
306 GtkWidget* username_entry_; 333 GtkWidget* username_entry_;
307 GtkWidget* password_entry_; 334 GtkWidget* password_entry_;
308 335
336 // If not null, points to a model we need to notify of our own destruction
337 // so it doesn't try and access this when its too late.
338 LoginModel* login_model_;
339
309 DISALLOW_COPY_AND_ASSIGN(LoginHandlerGtk); 340 DISALLOW_COPY_AND_ASSIGN(LoginHandlerGtk);
310 }; 341 };
311 342
312 // static 343 // static
313 LoginHandler* LoginHandler::Create(URLRequest* request, MessageLoop* ui_loop) { 344 LoginHandler* LoginHandler::Create(URLRequest* request, MessageLoop* ui_loop) {
314 return new LoginHandlerGtk(request, ui_loop); 345 return new LoginHandlerGtk(request, ui_loop);
315 } 346 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/login_prompt_mac.h » ('j') | chrome/browser/login_prompt_mac.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698