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

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

Issue 12851002: Remove ConstrainedWindowGtkDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move SetBackgroundColor() Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
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 "chrome/browser/ui/login/login_prompt.h" 5 #include "chrome/browser/ui/login/login_prompt.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 18 matching lines...) Expand all
29 using content::PasswordForm; 29 using content::PasswordForm;
30 using content::WebContents; 30 using content::WebContents;
31 31
32 // ---------------------------------------------------------------------------- 32 // ----------------------------------------------------------------------------
33 // LoginHandlerGtk 33 // LoginHandlerGtk
34 34
35 // This class simply forwards the authentication from the LoginView (on 35 // This class simply forwards the authentication from the LoginView (on
36 // the UI thread) to the net::URLRequest (on the I/O thread). 36 // the UI thread) to the net::URLRequest (on the I/O thread).
37 // This class uses ref counting to ensure that it lives until all InvokeLaters 37 // This class uses ref counting to ensure that it lives until all InvokeLaters
38 // have been called. 38 // have been called.
39 class LoginHandlerGtk : public LoginHandler, 39 class LoginHandlerGtk : public LoginHandler {
40 public ConstrainedWindowGtkDelegate {
41 public: 40 public:
42 LoginHandlerGtk(net::AuthChallengeInfo* auth_info, net::URLRequest* request) 41 LoginHandlerGtk(net::AuthChallengeInfo* auth_info, net::URLRequest* request)
43 : LoginHandler(auth_info, request), 42 : LoginHandler(auth_info, request),
44 username_entry_(NULL), 43 username_entry_(NULL),
45 password_entry_(NULL), 44 password_entry_(NULL),
46 ok_(NULL), 45 ok_(NULL),
47 dialog_(NULL) { 46 dialog_(NULL) {
48 } 47 }
49 48
50 // LoginModelObserver implementation. 49 // LoginModelObserver implementation.
(...skipping 12 matching lines...) Expand all
63 } 62 }
64 } 63 }
65 64
66 // LoginHandler: 65 // LoginHandler:
67 virtual void BuildViewForPasswordManager( 66 virtual void BuildViewForPasswordManager(
68 PasswordManager* manager, 67 PasswordManager* manager,
69 const string16& explanation) OVERRIDE { 68 const string16& explanation) OVERRIDE {
70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
71 70
72 root_.Own(gtk_vbox_new(FALSE, ui::kContentAreaBorder)); 71 root_.Own(gtk_vbox_new(FALSE, ui::kContentAreaBorder));
72 g_signal_connect(root_.get(), "destroy", G_CALLBACK(OnDestroyThunk), this);
73
73 GtkWidget* label = gtk_label_new(UTF16ToUTF8(explanation).c_str()); 74 GtkWidget* label = gtk_label_new(UTF16ToUTF8(explanation).c_str());
74 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); 75 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
75 gtk_box_pack_start(GTK_BOX(root_.get()), label, FALSE, FALSE, 0); 76 gtk_box_pack_start(GTK_BOX(root_.get()), label, FALSE, FALSE, 0);
76 77
77 username_entry_ = gtk_entry_new(); 78 username_entry_ = gtk_entry_new();
78 gtk_entry_set_activates_default(GTK_ENTRY(username_entry_), TRUE); 79 gtk_entry_set_activates_default(GTK_ENTRY(username_entry_), TRUE);
79 80
80 password_entry_ = gtk_entry_new(); 81 password_entry_ = gtk_entry_new();
81 gtk_entry_set_activates_default(GTK_ENTRY(password_entry_), TRUE); 82 gtk_entry_set_activates_default(GTK_ENTRY(password_entry_), TRUE);
82 gtk_entry_set_visibility(GTK_ENTRY(password_entry_), FALSE); 83 gtk_entry_set_visibility(GTK_ENTRY(password_entry_), FALSE);
(...skipping 26 matching lines...) Expand all
109 SetModel(manager); 110 SetModel(manager);
110 111
111 // Scary thread safety note: This can potentially be called *after* SetAuth 112 // Scary thread safety note: This can potentially be called *after* SetAuth
112 // or CancelAuth (say, if the request was cancelled before the UI thread got 113 // or CancelAuth (say, if the request was cancelled before the UI thread got
113 // control). However, that's OK since any UI interaction in those functions 114 // control). However, that's OK since any UI interaction in those functions
114 // will occur via an InvokeLater on the UI thread, which is guaranteed 115 // will occur via an InvokeLater on the UI thread, which is guaranteed
115 // to happen after this is called (since this was InvokeLater'd first). 116 // to happen after this is called (since this was InvokeLater'd first).
116 WebContents* requesting_contents = GetWebContentsForLogin(); 117 WebContents* requesting_contents = GetWebContentsForLogin();
117 DCHECK(requesting_contents); 118 DCHECK(requesting_contents);
118 119
119 dialog_ = CreateWebContentsModalDialogGtk(requesting_contents, this); 120 dialog_ = CreateWebContentsModalDialogGtk(requesting_contents,
121 root_.get(),
122 username_entry_);
120 123
121 WebContentsModalDialogManager* web_contents_modal_dialog_manager = 124 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
122 WebContentsModalDialogManager::FromWebContents(requesting_contents); 125 WebContentsModalDialogManager::FromWebContents(requesting_contents);
123 web_contents_modal_dialog_manager->ShowDialog(dialog_); 126 web_contents_modal_dialog_manager->ShowDialog(dialog_);
124 127
125 NotifyAuthNeeded(); 128 NotifyAuthNeeded();
126 } 129 }
127 130
128 virtual void CloseDialog() OVERRIDE { 131 virtual void CloseDialog() OVERRIDE {
129 // The hosting dialog may have been freed. 132 // The hosting dialog may have been freed.
130 if (dialog_) 133 if (dialog_)
131 gtk_widget_destroy(dialog_); 134 gtk_widget_destroy(dialog_);
132 } 135 }
133 136
134 // Overridden from ConstrainedWindowGtkDelegate:
135 virtual GtkWidget* GetWidgetRoot() OVERRIDE {
136 return root_.get();
137 }
138
139 virtual GtkWidget* GetFocusWidget() OVERRIDE {
140 return username_entry_;
141 }
142
143 virtual void DeleteDelegate() OVERRIDE {
144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
145
146 // The constrained window is going to delete itself; clear our pointer.
147 dialog_ = NULL;
148 SetModel(NULL);
149
150 ReleaseSoon();
151 }
152
153 protected: 137 protected:
154 virtual ~LoginHandlerGtk() { 138 virtual ~LoginHandlerGtk() {
155 root_.Destroy(); 139 root_.Destroy();
156 } 140 }
157 141
158 private: 142 private:
159 friend class LoginPrompt; 143 friend class LoginPrompt;
160 144
161 CHROMEGTK_CALLBACK_0(LoginHandlerGtk, void, OnOKClicked); 145 CHROMEGTK_CALLBACK_0(LoginHandlerGtk, void, OnOKClicked);
162 CHROMEGTK_CALLBACK_0(LoginHandlerGtk, void, OnCancelClicked); 146 CHROMEGTK_CALLBACK_0(LoginHandlerGtk, void, OnCancelClicked);
163 CHROMEGTK_CALLBACK_1(LoginHandlerGtk, void, OnPromptHierarchyChanged, 147 CHROMEGTK_CALLBACK_1(LoginHandlerGtk, void, OnPromptHierarchyChanged,
164 GtkWidget*); 148 GtkWidget*);
149 CHROMEGTK_CALLBACK_0(LoginHandlerGtk, void, OnDestroy);
165 150
166 // The GtkWidgets that form our visual hierarchy: 151 // The GtkWidgets that form our visual hierarchy:
167 // The root container we pass to our parent. 152 // The root container we pass to our parent.
168 ui::OwnedWidgetGtk root_; 153 ui::OwnedWidgetGtk root_;
169 154
170 // GtkEntry widgets that the user types into. 155 // GtkEntry widgets that the user types into.
171 GtkWidget* username_entry_; 156 GtkWidget* username_entry_;
172 GtkWidget* password_entry_; 157 GtkWidget* password_entry_;
173 GtkWidget* ok_; 158 GtkWidget* ok_;
174 159
(...skipping 23 matching lines...) Expand all
198 // button the default action and mess with the focus. 183 // button the default action and mess with the focus.
199 gtk_widget_set_can_default(ok_, TRUE); 184 gtk_widget_set_can_default(ok_, TRUE);
200 gtk_widget_grab_default(ok_); 185 gtk_widget_grab_default(ok_);
201 } 186 }
202 187
203 // static 188 // static
204 LoginHandler* LoginHandler::Create(net::AuthChallengeInfo* auth_info, 189 LoginHandler* LoginHandler::Create(net::AuthChallengeInfo* auth_info,
205 net::URLRequest* request) { 190 net::URLRequest* request) {
206 return new LoginHandlerGtk(auth_info, request); 191 return new LoginHandlerGtk(auth_info, request);
207 } 192 }
193
194 void LoginHandlerGtk::OnDestroy(GtkWidget* widget) {
195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
196
197 // The web contents modal dialog is going to delete itself; clear our pointer.
198 dialog_ = NULL;
199 SetModel(NULL);
200
201 ReleaseSoon();
202 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698