summaryrefslogtreecommitdiffstats
path: root/chrome/browser/login_prompt_mac.mm
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 /chrome/browser/login_prompt_mac.mm
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
Diffstat (limited to 'chrome/browser/login_prompt_mac.mm')
-rw-r--r--chrome/browser/login_prompt_mac.mm44
1 files changed, 40 insertions, 4 deletions
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