| OLD | NEW |
| 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 23 matching lines...) Expand all Loading... |
| 34 // the UI thread) to the net::URLRequest (on the I/O thread). | 34 // the UI thread) to the net::URLRequest (on the I/O thread). |
| 35 // This class uses ref counting to ensure that it lives until all InvokeLaters | 35 // This class uses ref counting to ensure that it lives until all InvokeLaters |
| 36 // have been called. | 36 // have been called. |
| 37 class LoginHandlerGtk : public LoginHandler, | 37 class LoginHandlerGtk : public LoginHandler, |
| 38 public ConstrainedWindowGtkDelegate { | 38 public ConstrainedWindowGtkDelegate { |
| 39 public: | 39 public: |
| 40 LoginHandlerGtk(net::AuthChallengeInfo* auth_info, net::URLRequest* request) | 40 LoginHandlerGtk(net::AuthChallengeInfo* auth_info, net::URLRequest* request) |
| 41 : LoginHandler(auth_info, request), | 41 : LoginHandler(auth_info, request), |
| 42 username_entry_(NULL), | 42 username_entry_(NULL), |
| 43 password_entry_(NULL), | 43 password_entry_(NULL), |
| 44 ok_(NULL) { | 44 ok_(NULL), |
| 45 dialog_(NULL) { |
| 45 } | 46 } |
| 46 | 47 |
| 47 // LoginModelObserver implementation. | 48 // LoginModelObserver implementation. |
| 48 virtual void OnAutofillDataAvailable(const string16& username, | 49 virtual void OnAutofillDataAvailable(const string16& username, |
| 49 const string16& password) OVERRIDE { | 50 const string16& password) OVERRIDE { |
| 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 51 | 52 |
| 52 // NOTE: Would be nice to use gtk_entry_get_text_length, but it is fairly | 53 // NOTE: Would be nice to use gtk_entry_get_text_length, but it is fairly |
| 53 // new and not always in our GTK version. | 54 // new and not always in our GTK version. |
| 54 if (strlen(gtk_entry_get_text(GTK_ENTRY(username_entry_))) == 0) { | 55 if (strlen(gtk_entry_get_text(GTK_ENTRY(username_entry_))) == 0) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 SetModel(manager); | 107 SetModel(manager); |
| 107 | 108 |
| 108 // Scary thread safety note: This can potentially be called *after* SetAuth | 109 // Scary thread safety note: This can potentially be called *after* SetAuth |
| 109 // or CancelAuth (say, if the request was cancelled before the UI thread got | 110 // or CancelAuth (say, if the request was cancelled before the UI thread got |
| 110 // control). However, that's OK since any UI interaction in those functions | 111 // control). However, that's OK since any UI interaction in those functions |
| 111 // will occur via an InvokeLater on the UI thread, which is guaranteed | 112 // will occur via an InvokeLater on the UI thread, which is guaranteed |
| 112 // to happen after this is called (since this was InvokeLater'd first). | 113 // to happen after this is called (since this was InvokeLater'd first). |
| 113 WebContents* requesting_contents = GetWebContentsForLogin(); | 114 WebContents* requesting_contents = GetWebContentsForLogin(); |
| 114 DCHECK(requesting_contents); | 115 DCHECK(requesting_contents); |
| 115 | 116 |
| 116 SetDialog(new ConstrainedWindowGtk(requesting_contents, this)); | 117 dialog_ = new ConstrainedWindowGtk(requesting_contents, this); |
| 117 NotifyAuthNeeded(); | 118 NotifyAuthNeeded(); |
| 118 } | 119 } |
| 119 | 120 |
| 121 virtual void CloseDialog() OVERRIDE { |
| 122 // The hosting WebContentsModalDialog may have been freed. |
| 123 if (dialog_) |
| 124 dialog_->CloseWebContentsModalDialog(); |
| 125 } |
| 126 |
| 120 // Overridden from ConstrainedWindowGtkDelegate: | 127 // Overridden from ConstrainedWindowGtkDelegate: |
| 121 virtual GtkWidget* GetWidgetRoot() OVERRIDE { | 128 virtual GtkWidget* GetWidgetRoot() OVERRIDE { |
| 122 return root_.get(); | 129 return root_.get(); |
| 123 } | 130 } |
| 124 | 131 |
| 125 virtual GtkWidget* GetFocusWidget() OVERRIDE { | 132 virtual GtkWidget* GetFocusWidget() OVERRIDE { |
| 126 return username_entry_; | 133 return username_entry_; |
| 127 } | 134 } |
| 128 | 135 |
| 129 virtual void DeleteDelegate() OVERRIDE { | 136 virtual void DeleteDelegate() OVERRIDE { |
| 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 131 | 138 |
| 132 // The constrained window is going to delete itself; clear our pointer. | 139 // The constrained window is going to delete itself; clear our pointer. |
| 133 SetDialog(NULL); | 140 dialog_ = NULL; |
| 134 SetModel(NULL); | 141 SetModel(NULL); |
| 135 | 142 |
| 136 ReleaseSoon(); | 143 ReleaseSoon(); |
| 137 } | 144 } |
| 138 | 145 |
| 139 protected: | 146 protected: |
| 140 virtual ~LoginHandlerGtk() { | 147 virtual ~LoginHandlerGtk() { |
| 141 root_.Destroy(); | 148 root_.Destroy(); |
| 142 } | 149 } |
| 143 | 150 |
| 144 private: | 151 private: |
| 145 friend class LoginPrompt; | 152 friend class LoginPrompt; |
| 146 | 153 |
| 147 CHROMEGTK_CALLBACK_0(LoginHandlerGtk, void, OnOKClicked); | 154 CHROMEGTK_CALLBACK_0(LoginHandlerGtk, void, OnOKClicked); |
| 148 CHROMEGTK_CALLBACK_0(LoginHandlerGtk, void, OnCancelClicked); | 155 CHROMEGTK_CALLBACK_0(LoginHandlerGtk, void, OnCancelClicked); |
| 149 CHROMEGTK_CALLBACK_1(LoginHandlerGtk, void, OnPromptHierarchyChanged, | 156 CHROMEGTK_CALLBACK_1(LoginHandlerGtk, void, OnPromptHierarchyChanged, |
| 150 GtkWidget*); | 157 GtkWidget*); |
| 151 | 158 |
| 152 // The GtkWidgets that form our visual hierarchy: | 159 // The GtkWidgets that form our visual hierarchy: |
| 153 // The root container we pass to our parent. | 160 // The root container we pass to our parent. |
| 154 ui::OwnedWidgetGtk root_; | 161 ui::OwnedWidgetGtk root_; |
| 155 | 162 |
| 156 // GtkEntry widgets that the user types into. | 163 // GtkEntry widgets that the user types into. |
| 157 GtkWidget* username_entry_; | 164 GtkWidget* username_entry_; |
| 158 GtkWidget* password_entry_; | 165 GtkWidget* password_entry_; |
| 159 GtkWidget* ok_; | 166 GtkWidget* ok_; |
| 160 | 167 |
| 168 ConstrainedWindowGtk* dialog_; |
| 169 |
| 161 DISALLOW_COPY_AND_ASSIGN(LoginHandlerGtk); | 170 DISALLOW_COPY_AND_ASSIGN(LoginHandlerGtk); |
| 162 }; | 171 }; |
| 163 | 172 |
| 164 void LoginHandlerGtk::OnOKClicked(GtkWidget* sender) { | 173 void LoginHandlerGtk::OnOKClicked(GtkWidget* sender) { |
| 165 SetAuth( | 174 SetAuth( |
| 166 UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(username_entry_))), | 175 UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(username_entry_))), |
| 167 UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(password_entry_)))); | 176 UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(password_entry_)))); |
| 168 } | 177 } |
| 169 | 178 |
| 170 void LoginHandlerGtk::OnCancelClicked(GtkWidget* sender) { | 179 void LoginHandlerGtk::OnCancelClicked(GtkWidget* sender) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 182 // button the default action and mess with the focus. | 191 // button the default action and mess with the focus. |
| 183 gtk_widget_set_can_default(ok_, TRUE); | 192 gtk_widget_set_can_default(ok_, TRUE); |
| 184 gtk_widget_grab_default(ok_); | 193 gtk_widget_grab_default(ok_); |
| 185 } | 194 } |
| 186 | 195 |
| 187 // static | 196 // static |
| 188 LoginHandler* LoginHandler::Create(net::AuthChallengeInfo* auth_info, | 197 LoginHandler* LoginHandler::Create(net::AuthChallengeInfo* auth_info, |
| 189 net::URLRequest* request) { | 198 net::URLRequest* request) { |
| 190 return new LoginHandlerGtk(auth_info, request); | 199 return new LoginHandlerGtk(auth_info, request); |
| 191 } | 200 } |
| OLD | NEW |