summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-25 17:11:44 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-25 17:11:44 +0000
commit12c8f8ebcd8d24e1ae70eb6e76b03c18e54278ab (patch)
tree0a7274369024d76a2eac33468209a0b7981bf918
parent948808497c7efae50a2ccb01bf551505f12f3fa1 (diff)
downloadchromium_src-12c8f8ebcd8d24e1ae70eb6e76b03c18e54278ab.zip
chromium_src-12c8f8ebcd8d24e1ae70eb6e76b03c18e54278ab.tar.gz
chromium_src-12c8f8ebcd8d24e1ae70eb6e76b03c18e54278ab.tar.bz2
Autofill http auth dialog on os x and linux.
BUG=19801 TEST=See bug (on both mac and linux) Review URL: http://codereview.chromium.org/173341 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24241 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/login_prompt_gtk.cc35
-rw-r--r--chrome/browser/login_prompt_mac.h3
-rw-r--r--chrome/browser/login_prompt_mac.mm44
3 files changed, 75 insertions, 7 deletions
diff --git a/chrome/browser/login_prompt_gtk.cc b/chrome/browser/login_prompt_gtk.cc
index f38be97..dda0e15 100644
--- a/chrome/browser/login_prompt_gtk.cc
+++ b/chrome/browser/login_prompt_gtk.cc
@@ -9,6 +9,7 @@
#include "app/l10n_util.h"
#include "base/message_loop.h"
#include "chrome/browser/gtk/constrained_window_gtk.h"
+#include "chrome/browser/login_model.h"
#include "chrome/browser/password_manager/password_manager.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
@@ -30,7 +31,8 @@ using webkit_glue::PasswordForm;
// have been called.
class LoginHandlerGtk : public LoginHandler,
public base::RefCountedThreadSafe<LoginHandlerGtk>,
- public ConstrainedWindowGtkDelegate {
+ public ConstrainedWindowGtkDelegate,
+ public LoginModelObserver {
public:
LoginHandlerGtk(URLRequest* request, MessageLoop* ui_loop)
: handled_auth_(false),
@@ -38,7 +40,8 @@ class LoginHandlerGtk : public LoginHandler,
ui_loop_(ui_loop),
request_(request),
request_loop_(MessageLoop::current()),
- password_manager_(NULL) {
+ password_manager_(NULL),
+ login_model_(NULL) {
DCHECK(request_) << "LoginHandlerGtk constructed with NULL request";
AddRef(); // matched by ReleaseLater.
@@ -50,9 +53,31 @@ class LoginHandlerGtk : public LoginHandler,
}
virtual ~LoginHandlerGtk() {
+ if (login_model_)
+ login_model_->SetObserver(NULL);
root_.Destroy();
}
+ void SetModel(LoginModel* model) {
+ login_model_ = model;
+ if (login_model_)
+ login_model_->SetObserver(this);
+ }
+
+ // LoginModelObserver implementation.
+ virtual void OnAutofillDataAvailable(const std::wstring& username,
+ const std::wstring& password) {
+ // NOTE: Would be nice to use gtk_entry_get_text_length, but it is fairly
+ // new and not always in our GTK version.
+ if (strlen(gtk_entry_get_text(GTK_ENTRY(username_entry_))) == 0) {
+ gtk_entry_set_text(GTK_ENTRY(username_entry_),
+ WideToUTF8(username).c_str());
+ gtk_entry_set_text(GTK_ENTRY(password_entry_),
+ WideToUTF8(password).c_str());
+ gtk_editable_select_region(GTK_EDITABLE(username_entry_), 0, -1);
+ }
+ }
+
// LoginHandler:
virtual void BuildViewForPasswordManager(PasswordManager* manager,
std::wstring explanation) {
@@ -92,6 +117,8 @@ class LoginHandlerGtk : public LoginHandler,
g_signal_connect(cancel, "clicked", G_CALLBACK(OnCancelClicked), this);
gtk_box_pack_end(GTK_BOX(hbox), cancel, FALSE, FALSE, 0);
+ SetModel(manager);
+
// Scary thread safety note: This can potentially be called *after* SetAuth
// or CancelAuth (say, if the request was cancelled before the UI thread got
// control). However, that's OK since any UI interaction in those functions
@@ -306,6 +333,10 @@ class LoginHandlerGtk : public LoginHandler,
GtkWidget* username_entry_;
GtkWidget* password_entry_;
+ // If not null, points to a model we need to notify of our own destruction
+ // so it doesn't try and access this when its too late.
+ LoginModel* login_model_;
+
DISALLOW_COPY_AND_ASSIGN(LoginHandlerGtk);
};
diff --git a/chrome/browser/login_prompt_mac.h b/chrome/browser/login_prompt_mac.h
index 3cc5f8b..28e8c38 100644
--- a/chrome/browser/login_prompt_mac.h
+++ b/chrome/browser/login_prompt_mac.h
@@ -22,7 +22,8 @@ class LoginHandlerMac;
- (IBAction)cancelPressed:(id)sender;
- (void)sheetDidEnd:(NSWindow*)sheet
returnCode:(int)returnCode
- contextInfo:(void *)contextInfo;
+ contextInfo:(void*)contextInfo;
+- (void)autofillLogin:(NSString*)login password:(NSString*)password;
@end
#endif // CHROME_BROWSER_LOGIN_PROMPT_MAC_H_
diff --git a/chrome/browser/login_prompt_mac.mm b/chrome/browser/login_prompt_mac.mm
index a8da380..99bbaba 100644
--- a/chrome/browser/login_prompt_mac.mm
+++ b/chrome/browser/login_prompt_mac.mm
@@ -10,6 +10,7 @@
#include "base/message_loop.h"
#include "base/sys_string_conversions.h"
#include "chrome/browser/cocoa/constrained_window_mac.h"
+#include "chrome/browser/login_model.h"
#include "chrome/browser/password_manager/password_manager.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
@@ -30,7 +31,8 @@ using webkit_glue::PasswordForm;
// have been called.
class LoginHandlerMac : public LoginHandler,
public base::RefCountedThreadSafe<LoginHandlerMac>,
- public ConstrainedWindowMacDelegateCustomSheet {
+ public ConstrainedWindowMacDelegateCustomSheet,
+ public LoginModelObserver {
public:
LoginHandlerMac(URLRequest* request, MessageLoop* ui_loop)
: handled_auth_(false),
@@ -38,7 +40,9 @@ class LoginHandlerMac : public LoginHandler,
ui_loop_(ui_loop),
request_(request),
request_loop_(MessageLoop::current()),
- password_manager_(NULL) {
+ password_manager_(NULL),
+ sheet_controller_(nil),
+ login_model_(NULL) {
// This constructor is called on the I/O thread, so we cannot load the nib
// here. BuildViewForPasswordManager() will be invoked on the UI thread
// later, so wait with loading the nib until then.
@@ -53,6 +57,21 @@ class LoginHandlerMac : public LoginHandler,
}
virtual ~LoginHandlerMac() {
+ if (login_model_)
+ login_model_->SetObserver(NULL);
+ }
+
+ void SetModel(LoginModel* model) {
+ login_model_ = model;
+ if (login_model_)
+ login_model_->SetObserver(this);
+ }
+
+ // LoginModelObserver implementation.
+ virtual void OnAutofillDataAvailable(const std::wstring& username,
+ const std::wstring& password) {
+ [sheet_controller_ autofillLogin:base::SysWideToNSString(username)
+ password:base::SysWideToNSString(password)];
}
// LoginHandler:
@@ -61,11 +80,13 @@ class LoginHandlerMac : public LoginHandler,
DCHECK(MessageLoop::current() == ui_loop_);
// Load nib here instead of in constructor.
- LoginHandlerSheet* sheetController = [[[LoginHandlerSheet alloc]
+ sheet_controller_ = [[[LoginHandlerSheet alloc]
initWithLoginHandler:this] autorelease];
- init([sheetController window], sheetController,
+ init([sheet_controller_ window], sheet_controller_,
@selector(sheetDidEnd:returnCode:contextInfo:));
+ SetModel(manager);
+
// Scary thread safety note: This can potentially be called *after* SetAuth
// or CancelAuth (say, if the request was cancelled before the UI thread got
// control). However, that's OK since any UI interaction in those functions
@@ -265,6 +286,13 @@ class LoginHandlerMac : public LoginHandler,
int render_process_host_id_;
int tab_contents_id_;
+ // The Cocoa controller of the GUI.
+ LoginHandlerSheet* sheet_controller_;
+
+ // If not null, points to a model we need to notify of our own destruction
+ // so it doesn't try and access this when its too late.
+ LoginModel* login_model_;
+
DISALLOW_COPY_AND_ASSIGN(LoginHandlerMac);
};
@@ -305,4 +333,12 @@ LoginHandler* LoginHandler::Create(URLRequest* request, MessageLoop* ui_loop) {
// Also called when user navigates to another page while the sheet is open.
}
+- (void)autofillLogin:(NSString*)login password:(NSString*)password {
+ if ([[nameField_ stringValue] length] == 0) {
+ [nameField_ setStringValue:login];
+ [passwordField_ setStringValue:password];
+ [nameField_ selectText:self];
+ }
+}
+
@end