From effb25df8e23ffc027fefe0b271a47e16f7a6240 Mon Sep 17 00:00:00 2001 From: "erg@chromium.org" Date: Wed, 17 Jun 2009 16:48:11 +0000 Subject: Remove the windows specific bits from login_prompt.cc and make LoginPromptWin conform to a general cross platform interface. (Also tightens the interface for ConstrainedWindows a bit more) Review URL: http://codereview.chromium.org/125217 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18623 0039d316-1c4b-4281-b951-d872f2087c98 --- .../download_request_dialog_delegate_win.cc | 2 +- chrome/browser/login_prompt.cc | 301 +-------------------- chrome/browser/login_prompt.h | 31 ++- chrome/browser/login_prompt_win.cc | 292 ++++++++++++++++++++ chrome/browser/tab_contents/constrained_window.h | 2 - chrome/browser/tab_contents/tab_contents.cc | 5 +- chrome/browser/tab_contents/tab_contents.h | 3 +- chrome/browser/views/constrained_window_impl.cc | 12 +- chrome/browser/views/constrained_window_impl.h | 5 - 9 files changed, 339 insertions(+), 314 deletions(-) mode change 100644 => 100755 chrome/browser/login_prompt.cc create mode 100644 chrome/browser/login_prompt_win.cc (limited to 'chrome/browser') diff --git a/chrome/browser/download/download_request_dialog_delegate_win.cc b/chrome/browser/download/download_request_dialog_delegate_win.cc index cbecc7b..6129af6 100644 --- a/chrome/browser/download/download_request_dialog_delegate_win.cc +++ b/chrome/browser/download/download_request_dialog_delegate_win.cc @@ -26,7 +26,7 @@ DownloadRequestDialogDelegateWin::DownloadRequestDialogDelegateWin( MessageBoxFlags::kIsConfirmMessageBox, l10n_util::GetString(IDS_MULTI_DOWNLOAD_WARNING), std::wstring()); - window_ = tab->CreateConstrainedDialog(this, message_view_); + window_ = tab->CreateConstrainedDialog(this); } void DownloadRequestDialogDelegateWin::CloseWindow() { diff --git a/chrome/browser/login_prompt.cc b/chrome/browser/login_prompt.cc old mode 100644 new mode 100755 index dbed8aa..b897378 --- a/chrome/browser/login_prompt.cc +++ b/chrome/browser/login_prompt.cc @@ -13,26 +13,19 @@ #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/browser/tab_contents/constrained_window.h" -#include "chrome/browser/tab_contents/navigation_controller.h" -#include "chrome/browser/tab_contents/tab_util.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/browser/views/login_view.h" #include "chrome/common/chrome_switches.h" -#include "chrome/common/notification_service.h" #include "grit/generated_resources.h" #include "net/base/auth.h" #include "net/url_request/url_request.h" -#include "views/window/dialog_delegate.h" -using namespace std; -using views::LoginView; using webkit_glue::PasswordForm; class LoginHandlerImpl; // Helper to remove the ref from an URLRequest to the LoginHandler. // Should only be called from the IO thread, since it accesses an URLRequest. -static void ResetLoginHandlerForRequest(URLRequest* request) { +void ResetLoginHandlerForRequest(URLRequest* request) { ResourceDispatcherHost::ExtraRequestInfo* info = ResourceDispatcherHost::ExtraInfoForRequest(request); if (!info) @@ -50,7 +43,6 @@ static void ResetLoginHandlerForRequest(URLRequest* request) { // // Be careful when changing this function, since you could make existing // saved logins un-retrievable. - std::string GetSignonRealm(const GURL& url, const net::AuthChallengeInfo& auth_info) { std::string signon_realm; @@ -67,262 +59,6 @@ std::string GetSignonRealm(const GURL& url, } // ---------------------------------------------------------------------------- -// LoginHandlerImpl - -// This class simply forwards the authentication from the LoginView (on -// the UI thread) to the URLRequest (on the I/O thread). -// This class uses ref counting to ensure that it lives until all InvokeLaters -// have been called. -class LoginHandlerImpl : public LoginHandler, - public base::RefCountedThreadSafe, - public views::DialogDelegate { - public: - LoginHandlerImpl(URLRequest* request, MessageLoop* ui_loop) - : dialog_(NULL), - handled_auth_(false), - request_(request), - request_loop_(MessageLoop::current()), - ui_loop_(ui_loop), - password_manager_(NULL) { - DCHECK(request_) << "LoginHandler constructed with NULL request"; - - AddRef(); // matched by ReleaseLater. - if (!tab_util::GetTabContentsID(request_, &render_process_host_id_, - &tab_contents_id_)) { - NOTREACHED(); - } - } - - ~LoginHandlerImpl() { - } - - // Initialize the UI part of the LoginHandler. - // 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 - // will occur via an InvokeLater on the UI thread, which is guaranteed - // to happen after this is called (since this was InvokeLater'd first). - void InitWithDialog(ConstrainedWindow* dlg) { - DCHECK(MessageLoop::current() == ui_loop_); - dialog_ = dlg; - SendNotifications(); - } - - // Returns the TabContents that needs authentication. - TabContents* GetTabContentsForLogin() { - DCHECK(MessageLoop::current() == ui_loop_); - - return tab_util::GetTabContentsByID(render_process_host_id_, - tab_contents_id_); - } - - void set_login_view(LoginView* login_view) { - login_view_ = login_view; - } - - void set_password_form(const PasswordForm& form) { - password_form_ = form; - } - - void set_password_manager(PasswordManager* password_manager) { - password_manager_ = password_manager; - } - - // views::DialogDelegate methods: - virtual std::wstring GetDialogButtonLabel( - MessageBoxFlags::DialogButton button) const { - if (button == MessageBoxFlags::DIALOGBUTTON_OK) - return l10n_util::GetString(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL); - return DialogDelegate::GetDialogButtonLabel(button); - } - virtual std::wstring GetWindowTitle() const { - return l10n_util::GetString(IDS_LOGIN_DIALOG_TITLE); - } - virtual void WindowClosing() { - DCHECK(MessageLoop::current() == ui_loop_); - - // Reference is no longer valid. - dialog_ = NULL; - - if (!WasAuthHandled(true)) { - request_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &LoginHandlerImpl::CancelAuthDeferred)); - SendNotifications(); - } - } - virtual void DeleteDelegate() { - // Delete this object once all InvokeLaters have been called. - request_loop_->ReleaseSoon(FROM_HERE, this); - } - virtual bool Cancel() { - DCHECK(MessageLoop::current() == ui_loop_); - DCHECK(dialog_) << "LoginHandler invoked without being attached"; - CancelAuth(); - return true; - } - virtual bool Accept() { - DCHECK(MessageLoop::current() == ui_loop_); - DCHECK(dialog_) << "LoginHandler invoked without being attached"; - SetAuth(login_view_->GetUsername(), login_view_->GetPassword()); - return true; - } - virtual views::View* GetContentsView() { - return login_view_; - } - - // LoginHandler: - virtual void SetAuth(const std::wstring& username, - const std::wstring& password) { - if (WasAuthHandled(true)) - return; - - // Tell the password manager the credentials were submitted / accepted. - if (password_manager_) { - password_form_.username_value = username; - password_form_.password_value = password; - password_manager_->ProvisionallySavePassword(password_form_); - } - - ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &LoginHandlerImpl::CloseContentsDeferred)); - ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &LoginHandlerImpl::SendNotifications)); - request_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &LoginHandlerImpl::SetAuthDeferred, username, password)); - } - - virtual void CancelAuth() { - if (WasAuthHandled(true)) - return; - - ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &LoginHandlerImpl::CloseContentsDeferred)); - ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &LoginHandlerImpl::SendNotifications)); - request_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &LoginHandlerImpl::CancelAuthDeferred)); - } - - virtual void OnRequestCancelled() { - DCHECK(MessageLoop::current() == request_loop_) << - "Why is OnRequestCancelled called from the UI thread?"; - - // Reference is no longer valid. - request_ = NULL; - - // Give up on auth if the request was cancelled. - CancelAuth(); - } - - private: - - // Calls SetAuth from the request_loop. - void SetAuthDeferred(const std::wstring& username, - const std::wstring& password) { - DCHECK(MessageLoop::current() == request_loop_); - - if (request_) { - request_->SetAuth(username, password); - ResetLoginHandlerForRequest(request_); - } - } - - // Calls CancelAuth from the request_loop. - void CancelAuthDeferred() { - DCHECK(MessageLoop::current() == request_loop_); - - if (request_) { - request_->CancelAuth(); - // Verify that CancelAuth does destroy the request via our delegate. - DCHECK(request_ != NULL); - ResetLoginHandlerForRequest(request_); - } - } - - // Closes the view_contents from the UI loop. - void CloseContentsDeferred() { - DCHECK(MessageLoop::current() == ui_loop_); - - // The hosting ConstrainedWindow may have been freed. - if (dialog_) - dialog_->CloseConstrainedWindow(); - } - - // Returns whether authentication had been handled (SetAuth or CancelAuth). - // If |set_handled| is true, it will mark authentication as handled. - bool WasAuthHandled(bool set_handled) { - AutoLock lock(handled_auth_lock_); - bool was_handled = handled_auth_; - if (set_handled) - handled_auth_ = true; - return was_handled; - } - - // Notify observers that authentication is needed or received. The automation - // proxy uses this for testing. - void SendNotifications() { - DCHECK(MessageLoop::current() == ui_loop_); - - NotificationService* service = NotificationService::current(); - TabContents* requesting_contents = GetTabContentsForLogin(); - if (!requesting_contents) - return; - - NavigationController* controller = &requesting_contents->controller(); - - if (!WasAuthHandled(false)) { - LoginNotificationDetails details(this); - service->Notify(NotificationType::AUTH_NEEDED, - Source(controller), - Details(&details)); - } else { - service->Notify(NotificationType::AUTH_SUPPLIED, - Source(controller), - NotificationService::NoDetails()); - } - } - - // True if we've handled auth (SetAuth or CancelAuth has been called). - bool handled_auth_; - Lock handled_auth_lock_; - - // The ConstrainedWindow that is hosting our LoginView. - // This should only be accessed on the ui_loop_. - ConstrainedWindow* dialog_; - - // The MessageLoop of the thread that the ChromeViewContents lives in. - MessageLoop* ui_loop_; - - // The request that wants login data. - // This should only be accessed on the request_loop_. - URLRequest* request_; - - // The MessageLoop of the thread that the URLRequest lives in. - MessageLoop* request_loop_; - - // The LoginView that contains the user's login information - LoginView* login_view_; - - // The PasswordForm sent to the PasswordManager. This is so we can refer to it - // when later notifying the password manager if the credentials were accepted - // or rejected. - // This should only be accessed on the ui_loop_. - PasswordForm password_form_; - - // Points to the password manager owned by the TabContents requesting auth. - // Can be null if the TabContents is not a TabContents. - // This should only be accessed on the ui_loop_. - PasswordManager* password_manager_; - - // Cached from the URLRequest, in case it goes NULL on us. - int render_process_host_id_; - int tab_contents_id_; - - DISALLOW_EVIL_CONSTRUCTORS(LoginHandlerImpl); -}; - - -// ---------------------------------------------------------------------------- // LoginDialogTask // This task is run on the UI thread and creates a constrained window with @@ -330,7 +66,7 @@ class LoginHandlerImpl : public LoginHandler, // which then routes it to the URLRequest on the I/O thread. class LoginDialogTask : public Task { public: - LoginDialogTask(net::AuthChallengeInfo* auth_info, LoginHandlerImpl* handler) + LoginDialogTask(net::AuthChallengeInfo* auth_info, LoginHandler* handler) : auth_info_(auth_info), handler_(handler) { } virtual ~LoginDialogTask() { @@ -343,31 +79,22 @@ class LoginDialogTask : public Task { return; } - wstring explanation = auth_info_->realm.empty() ? - l10n_util::GetStringF(IDS_LOGIN_DIALOG_DESCRIPTION_NO_REALM, - auth_info_->host_and_port) : - l10n_util::GetStringF(IDS_LOGIN_DIALOG_DESCRIPTION, - auth_info_->host_and_port, - auth_info_->realm); - LoginView* view = new LoginView(explanation); - // Tell the password manager to look for saved passwords. PasswordManager* password_manager = parent_contents->GetPasswordManager(); - // Set the model for the login view. The model (password manager) is owned - // by the view's parent TabContents, so natural destruction order means we - // don't have to worry about calling SetModel(NULL), because the view will - // be deleted before the password manager. - view->SetModel(password_manager); std::vector v; MakeInputForPasswordManager(parent_contents->GetURL(), &v); password_manager->PasswordFormsSeen(v); - handler_->set_password_manager(password_manager); + handler_->SetPasswordManager(password_manager); - handler_->set_login_view(view); - ConstrainedWindow* dialog = - parent_contents->CreateConstrainedDialog(handler_, view); - handler_->InitWithDialog(dialog); + std::wstring explanation = auth_info_->realm.empty() ? + l10n_util::GetStringF(IDS_LOGIN_DIALOG_DESCRIPTION_NO_REALM, + auth_info_->host_and_port) : + l10n_util::GetStringF(IDS_LOGIN_DIALOG_DESCRIPTION, + auth_info_->host_and_port, + auth_info_->realm); + handler_->BuildViewForPasswordManager(password_manager, + explanation); } private: @@ -388,7 +115,7 @@ class LoginDialogTask : public Task { dialog_form.signon_realm = GetSignonRealm(dialog_form.origin, *auth_info_); password_manager_input->push_back(dialog_form); // Set the password form for the handler (by copy). - handler_->set_password_form(dialog_form); + handler_->SetPasswordForm(dialog_form); } // Info about who/where/what is asking for authentication. @@ -396,7 +123,7 @@ class LoginDialogTask : public Task { // Where to send the authentication when obtained. // This is owned by the ResourceDispatcherHost that invoked us. - LoginHandlerImpl* handler_; + LoginHandler* handler_; DISALLOW_EVIL_CONSTRUCTORS(LoginDialogTask); }; @@ -407,7 +134,7 @@ class LoginDialogTask : public Task { LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, URLRequest* request, MessageLoop* ui_loop) { - LoginHandlerImpl* handler = new LoginHandlerImpl(request, ui_loop); + LoginHandler* handler = LoginHandler::Create(request, ui_loop); ui_loop->PostTask(FROM_HERE, new LoginDialogTask(auth_info, handler)); return handler; } diff --git a/chrome/browser/login_prompt.h b/chrome/browser/login_prompt.h index b10ec57..5027409 100644 --- a/chrome/browser/login_prompt.h +++ b/chrome/browser/login_prompt.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_LOGIN_PROMPT_H__ -#define CHROME_BROWSER_LOGIN_PROMPT_H__ +#ifndef CHROME_BROWSER_LOGIN_PROMPT_H_ +#define CHROME_BROWSER_LOGIN_PROMPT_H_ #include @@ -13,8 +13,14 @@ namespace net { class AuthChallengeInfo; } +namespace webkit_glue { +struct PasswordForm; +} + +class ConstrainedWindow; class GURL; class MessageLoop; +class PasswordManager; class TabContents; class URLRequest; @@ -24,6 +30,22 @@ class URLRequest; // a thread safe manner. class LoginHandler { public: + // Builds the platform specific LoginHandler. Used from within + // CreateLoginPrompt() which creates tasks. + static LoginHandler* Create(URLRequest* request, MessageLoop* ui_loop); + + // Initializes the underlying platform specific view. + virtual void BuildViewForPasswordManager(PasswordManager* manager, + std::wstring explanation) = 0; + + // Sets information about the authentication type (|form|) and the + // |password_manager| for this profile. + virtual void SetPasswordForm(const webkit_glue::PasswordForm& form) = 0; + virtual void SetPasswordManager(PasswordManager* password_manager) = 0; + + // Returns the TabContents that needs authentication. + virtual TabContents* GetTabContentsForLogin() = 0; + // Resend the request with authentication credentials. // This function can be called from either thread. virtual void SetAuth(const std::wstring& username, @@ -66,9 +88,12 @@ LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, URLRequest* request, MessageLoop* ui_loop); +// Helper to remove the ref from an URLRequest to the LoginHandler. +// Should only be called from the IO thread, since it accesses an URLRequest. +void ResetLoginHandlerForRequest(URLRequest* request); // Get the signon_realm under which the identity should be saved. std::string GetSignonRealm(const GURL& url, const net::AuthChallengeInfo& auth_info); -#endif // CHROME_BROWSER_LOGIN_PROMPT_H__ +#endif // CHROME_BROWSER_LOGIN_PROMPT_H_ diff --git a/chrome/browser/login_prompt_win.cc b/chrome/browser/login_prompt_win.cc new file mode 100644 index 0000000..4437737 --- /dev/null +++ b/chrome/browser/login_prompt_win.cc @@ -0,0 +1,292 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/login_prompt.h" + +#include "app/l10n_util.h" +#include "base/message_loop.h" +#include "chrome/browser/password_manager/password_manager.h" +#include "chrome/browser/tab_contents/navigation_controller.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents/tab_util.h" +#include "chrome/browser/views/login_view.h" +#include "chrome/common/notification_service.h" +#include "grit/generated_resources.h" +#include "net/url_request/url_request.h" +#include "views/window/dialog_delegate.h" + +using views::LoginView; +using webkit_glue::PasswordForm; + +// ---------------------------------------------------------------------------- +// LoginHandlerWin + +// This class simply forwards the authentication from the LoginView (on +// the UI thread) to the URLRequest (on the I/O thread). +// This class uses ref counting to ensure that it lives until all InvokeLaters +// have been called. +class LoginHandlerWin : public LoginHandler, + public base::RefCountedThreadSafe, + public views::DialogDelegate { + public: + LoginHandlerWin(URLRequest* request, MessageLoop* ui_loop) + : dialog_(NULL), + handled_auth_(false), + request_(request), + request_loop_(MessageLoop::current()), + ui_loop_(ui_loop), + password_manager_(NULL) { + DCHECK(request_) << "LoginHandler constructed with NULL request"; + + AddRef(); // matched by ReleaseLater. + if (!tab_util::GetTabContentsID(request_, &render_process_host_id_, + &tab_contents_id_)) { + NOTREACHED(); + } + } + + ~LoginHandlerWin() { + } + + void set_login_view(LoginView* login_view) { + login_view_ = login_view; + } + + // views::DialogDelegate methods: + virtual std::wstring GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) + return l10n_util::GetString(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL); + return DialogDelegate::GetDialogButtonLabel(button); + } + virtual std::wstring GetWindowTitle() const { + return l10n_util::GetString(IDS_LOGIN_DIALOG_TITLE); + } + virtual void WindowClosing() { + DCHECK(MessageLoop::current() == ui_loop_); + + // Reference is no longer valid. + dialog_ = NULL; + + if (!WasAuthHandled(true)) { + request_loop_->PostTask(FROM_HERE, NewRunnableMethod( + this, &LoginHandlerWin::CancelAuthDeferred)); + SendNotifications(); + } + } + virtual void DeleteDelegate() { + // Delete this object once all InvokeLaters have been called. + request_loop_->ReleaseSoon(FROM_HERE, this); + } + virtual bool Cancel() { + DCHECK(MessageLoop::current() == ui_loop_); + DCHECK(dialog_) << "LoginHandler invoked without being attached"; + CancelAuth(); + return true; + } + virtual bool Accept() { + DCHECK(MessageLoop::current() == ui_loop_); + DCHECK(dialog_) << "LoginHandler invoked without being attached"; + SetAuth(login_view_->GetUsername(), login_view_->GetPassword()); + return true; + } + virtual views::View* GetContentsView() { + return login_view_; + } + + // LoginHandler: + + virtual void BuildViewForPasswordManager(PasswordManager* manager, + std::wstring explanation) { + DCHECK(MessageLoop::current() == ui_loop_); + + LoginView* view = new LoginView(explanation); + + // Set the model for the login view. The model (password manager) is owned + // by the view's parent TabContents, so natural destruction order means we + // don't have to worry about calling SetModel(NULL), because the view will + // be deleted before the password manager. + view->SetModel(manager); + + set_login_view(view); + + // 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 + // will occur via an InvokeLater on the UI thread, which is guaranteed + // to happen after this is called (since this was InvokeLater'd first). + dialog_ = GetTabContentsForLogin()->CreateConstrainedDialog(this); + SendNotifications(); + } + + virtual void SetPasswordForm(const webkit_glue::PasswordForm& form) { + password_form_ = form; + } + + virtual void SetPasswordManager(PasswordManager* password_manager) { + password_manager_ = password_manager; + } + + virtual TabContents* GetTabContentsForLogin() { + DCHECK(MessageLoop::current() == ui_loop_); + + return tab_util::GetTabContentsByID(render_process_host_id_, + tab_contents_id_); + } + + virtual void SetAuth(const std::wstring& username, + const std::wstring& password) { + if (WasAuthHandled(true)) + return; + + // Tell the password manager the credentials were submitted / accepted. + if (password_manager_) { + password_form_.username_value = username; + password_form_.password_value = password; + password_manager_->ProvisionallySavePassword(password_form_); + } + + ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( + this, &LoginHandlerWin::CloseContentsDeferred)); + ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( + this, &LoginHandlerWin::SendNotifications)); + request_loop_->PostTask(FROM_HERE, NewRunnableMethod( + this, &LoginHandlerWin::SetAuthDeferred, username, password)); + } + + virtual void CancelAuth() { + if (WasAuthHandled(true)) + return; + + ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( + this, &LoginHandlerWin::CloseContentsDeferred)); + ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( + this, &LoginHandlerWin::SendNotifications)); + request_loop_->PostTask(FROM_HERE, NewRunnableMethod( + this, &LoginHandlerWin::CancelAuthDeferred)); + } + + virtual void OnRequestCancelled() { + DCHECK(MessageLoop::current() == request_loop_) << + "Why is OnRequestCancelled called from the UI thread?"; + + // Reference is no longer valid. + request_ = NULL; + + // Give up on auth if the request was cancelled. + CancelAuth(); + } + + private: + friend class LoginPrompt; + + // Calls SetAuth from the request_loop. + void SetAuthDeferred(const std::wstring& username, + const std::wstring& password) { + DCHECK(MessageLoop::current() == request_loop_); + + if (request_) { + request_->SetAuth(username, password); + ResetLoginHandlerForRequest(request_); + } + } + + // Calls CancelAuth from the request_loop. + void CancelAuthDeferred() { + DCHECK(MessageLoop::current() == request_loop_); + + if (request_) { + request_->CancelAuth(); + // Verify that CancelAuth does destroy the request via our delegate. + DCHECK(request_ != NULL); + ResetLoginHandlerForRequest(request_); + } + } + + // Closes the view_contents from the UI loop. + void CloseContentsDeferred() { + DCHECK(MessageLoop::current() == ui_loop_); + + // The hosting ConstrainedWindow may have been freed. + if (dialog_) + dialog_->CloseConstrainedWindow(); + } + + // Returns whether authentication had been handled (SetAuth or CancelAuth). + // If |set_handled| is true, it will mark authentication as handled. + bool WasAuthHandled(bool set_handled) { + AutoLock lock(handled_auth_lock_); + bool was_handled = handled_auth_; + if (set_handled) + handled_auth_ = true; + return was_handled; + } + + // Notify observers that authentication is needed or received. The automation + // proxy uses this for testing. + void SendNotifications() { + DCHECK(MessageLoop::current() == ui_loop_); + + NotificationService* service = NotificationService::current(); + TabContents* requesting_contents = GetTabContentsForLogin(); + if (!requesting_contents) + return; + + NavigationController* controller = &requesting_contents->controller(); + + if (!WasAuthHandled(false)) { + LoginNotificationDetails details(this); + service->Notify(NotificationType::AUTH_NEEDED, + Source(controller), + Details(&details)); + } else { + service->Notify(NotificationType::AUTH_SUPPLIED, + Source(controller), + NotificationService::NoDetails()); + } + } + + // True if we've handled auth (SetAuth or CancelAuth has been called). + bool handled_auth_; + Lock handled_auth_lock_; + + // The ConstrainedWindow that is hosting our LoginView. + // This should only be accessed on the ui_loop_. + ConstrainedWindow* dialog_; + + // The MessageLoop of the thread that the ChromeViewContents lives in. + MessageLoop* ui_loop_; + + // The request that wants login data. + // This should only be accessed on the request_loop_. + URLRequest* request_; + + // The MessageLoop of the thread that the URLRequest lives in. + MessageLoop* request_loop_; + + // The LoginView that contains the user's login information + LoginView* login_view_; + + // The PasswordForm sent to the PasswordManager. This is so we can refer to it + // when later notifying the password manager if the credentials were accepted + // or rejected. + // This should only be accessed on the ui_loop_. + PasswordForm password_form_; + + // Points to the password manager owned by the TabContents requesting auth. + // Can be null if the TabContents is not a TabContents. + // This should only be accessed on the ui_loop_. + PasswordManager* password_manager_; + + // Cached from the URLRequest, in case it goes NULL on us. + int render_process_host_id_; + int tab_contents_id_; + + DISALLOW_COPY_AND_ASSIGN(LoginHandlerWin); +}; + +// static +LoginHandler* LoginHandler::Create(URLRequest* request, MessageLoop* ui_loop) { + return new LoginHandlerWin(request, ui_loop); +} diff --git a/chrome/browser/tab_contents/constrained_window.h b/chrome/browser/tab_contents/constrained_window.h index eb30363..35679a5 100644 --- a/chrome/browser/tab_contents/constrained_window.h +++ b/chrome/browser/tab_contents/constrained_window.h @@ -36,8 +36,6 @@ class ConstrainedWindow { // within the constraining TabContents. static ConstrainedWindow* CreateConstrainedDialog( TabContents* owner, - const gfx::Rect& initial_bounds, - views::View* contents_view, views::WindowDelegate* window_delegate); // Closes the Constrained Window. diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index bd4e803..bb3a80f 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -741,11 +741,10 @@ void TabContents::CreateShortcut() { #if defined(OS_WIN) ConstrainedWindow* TabContents::CreateConstrainedDialog( - views::WindowDelegate* window_delegate, - views::View* contents_view) { + views::WindowDelegate* window_delegate) { ConstrainedWindow* window = ConstrainedWindow::CreateConstrainedDialog( - this, gfx::Rect(), contents_view, window_delegate); + this, window_delegate); child_windows_.push_back(window); return window; } diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index ddf42b5..609e154 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -330,8 +330,7 @@ class TabContents : public PageNavigator, // is sized according to the preferred size of the content_view, and centered // within the contents. ConstrainedWindow* CreateConstrainedDialog( - views::WindowDelegate* window_delegate, - views::View* contents_view); + views::WindowDelegate* window_delegate); #endif // Adds a new tab or window with the given already-created contents diff --git a/chrome/browser/views/constrained_window_impl.cc b/chrome/browser/views/constrained_window_impl.cc index 4ff891e..75f3771 100644 --- a/chrome/browser/views/constrained_window_impl.cc +++ b/chrome/browser/views/constrained_window_impl.cc @@ -626,18 +626,13 @@ ConstrainedWindowImpl::ConstrainedWindowImpl( : WindowWin(window_delegate), owner_(owner) { GetNonClientView()->SetFrameView(CreateFrameViewForWindow()); - Init(); -} -void ConstrainedWindowImpl::Init() { focus_restoration_disabled_ = false; set_window_style(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_CAPTION | WS_THICKFRAME | WS_SYSMENU); set_focus_on_creation(false); -} -void ConstrainedWindowImpl::InitAsDialog(const gfx::Rect& initial_bounds) { - WindowWin::Init(owner_->GetNativeView(), initial_bounds); + WindowWin::Init(owner_->GetNativeView(), gfx::Rect()); ActivateConstrainedWindow(); } @@ -720,17 +715,12 @@ void ConstrainedWindowImpl::OnWindowPosChanged(WINDOWPOS* window_pos) { SetMsgHandled(FALSE); } -/////////////////////////////////////////////////////////////////////////////// -// ConstrainedWindow, public: // static ConstrainedWindow* ConstrainedWindow::CreateConstrainedDialog( TabContents* parent, - const gfx::Rect& initial_bounds, - views::View* contents_view, views::WindowDelegate* window_delegate) { ConstrainedWindowImpl* window = new ConstrainedWindowImpl(parent, window_delegate); - window->InitAsDialog(initial_bounds); return window; } diff --git a/chrome/browser/views/constrained_window_impl.h b/chrome/browser/views/constrained_window_impl.h index 2f3c32e..1afd658 100644 --- a/chrome/browser/views/constrained_window_impl.h +++ b/chrome/browser/views/constrained_window_impl.h @@ -53,11 +53,6 @@ class ConstrainedWindowImpl : public ConstrainedWindow, // ConstrainedWindow. ConstrainedWindowImpl(TabContents* owner, views::WindowDelegate* window_delegate); - void Init(); - - // Initialize the Constrained Window as a Constrained Dialog containing a - // views::View client area. - void InitAsDialog(const gfx::Rect& initial_bounds); // Moves this window to the front of the Z-order and registers us with the // focus manager. -- cgit v1.1