| Index: chrome/browser/login_prompt_gtk.cc
|
| ===================================================================
|
| --- chrome/browser/login_prompt_gtk.cc (revision 42281)
|
| +++ chrome/browser/login_prompt_gtk.cc (working copy)
|
| @@ -31,43 +31,20 @@
|
| // This class uses ref counting to ensure that it lives until all InvokeLaters
|
| // have been called.
|
| class LoginHandlerGtk : public LoginHandler,
|
| - public base::RefCountedThreadSafe<LoginHandlerGtk>,
|
| - public ConstrainedWindowGtkDelegate,
|
| - public LoginModelObserver {
|
| + public ConstrainedWindowGtkDelegate {
|
| public:
|
| - explicit LoginHandlerGtk(URLRequest* request)
|
| - : handled_auth_(false),
|
| - dialog_(NULL),
|
| - request_(request),
|
| - password_manager_(NULL),
|
| - login_model_(NULL) {
|
| - DCHECK(request_) << "LoginHandlerGtk constructed with NULL request";
|
| -
|
| - AddRef(); // matched by ReleaseLater.
|
| - if (!ResourceDispatcherHost::RenderViewForRequest(request_,
|
| - &render_process_host_id_,
|
| - &tab_contents_id_)) {
|
| - NOTREACHED();
|
| - }
|
| + explicit LoginHandlerGtk(URLRequest* request) : LoginHandler(request) {
|
| }
|
|
|
| virtual ~LoginHandlerGtk() {
|
| - if (login_model_)
|
| - login_model_->SetObserver(NULL);
|
| root_.Destroy();
|
| }
|
|
|
| - void SetModel(LoginModel* model) {
|
| - if (login_model_)
|
| - login_model_->SetObserver(NULL);
|
| - login_model_ = model;
|
| - if (login_model_)
|
| - login_model_->SetObserver(this);
|
| - }
|
| -
|
| // LoginModelObserver implementation.
|
| virtual void OnAutofillDataAvailable(const std::wstring& username,
|
| const std::wstring& password) {
|
| + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
|
| +
|
| // 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) {
|
| @@ -128,168 +105,29 @@
|
| // 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);
|
| + SetDialog(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(ChromeThread::CurrentlyOn(ChromeThread::UI));
|
| -
|
| - 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 = WideToUTF16Hack(username);
|
| - password_form_.password_value = WideToUTF16Hack(password);
|
| - password_manager_->ProvisionallySavePassword(password_form_);
|
| - }
|
| -
|
| - ChromeThread::PostTask(
|
| - ChromeThread::UI, FROM_HERE,
|
| - NewRunnableMethod(this, &LoginHandlerGtk::CloseContentsDeferred));
|
| - ChromeThread::PostTask(
|
| - ChromeThread::UI, FROM_HERE,
|
| - NewRunnableMethod(this, &LoginHandlerGtk::SendNotifications));
|
| - ChromeThread::PostTask(
|
| - ChromeThread::IO, FROM_HERE,
|
| - NewRunnableMethod(this, &LoginHandlerGtk::SetAuthDeferred, username,
|
| - password));
|
| - }
|
| -
|
| - virtual void CancelAuth() {
|
| - if (WasAuthHandled(true))
|
| - return;
|
| -
|
| - ChromeThread::PostTask(
|
| - ChromeThread::UI, FROM_HERE,
|
| - NewRunnableMethod(this, &LoginHandlerGtk::CloseContentsDeferred));
|
| - ChromeThread::PostTask(
|
| - ChromeThread::UI, FROM_HERE,
|
| - NewRunnableMethod(this, &LoginHandlerGtk::SendNotifications));
|
| - ChromeThread::PostTask(
|
| - ChromeThread::IO, FROM_HERE,
|
| - NewRunnableMethod(this, &LoginHandlerGtk::CancelAuthDeferred));
|
| - }
|
| -
|
| - virtual void OnRequestCancelled() {
|
| - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)) <<
|
| - "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();
|
| - }
|
| -
|
| // Overridden from ConstrainedWindowGtkDelegate:
|
| virtual GtkWidget* GetWidgetRoot() {
|
| return root_.get();
|
| }
|
|
|
| virtual void DeleteDelegate() {
|
| - if (!WasAuthHandled(true)) {
|
| - ChromeThread::PostTask(
|
| - ChromeThread::IO, FROM_HERE,
|
| - NewRunnableMethod(this, &LoginHandlerGtk::CancelAuthDeferred));
|
| - ChromeThread::PostTask(
|
| - ChromeThread::UI, FROM_HERE,
|
| - NewRunnableMethod(this, &LoginHandlerGtk::SendNotifications));
|
| - }
|
| + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
|
|
|
| // The constrained window is going to delete itself; clear our pointer.
|
| - dialog_ = NULL;
|
| + SetDialog(NULL);
|
| SetModel(NULL);
|
|
|
| - // Delete this object once all InvokeLaters have been called.
|
| - ChromeThread::ReleaseSoon(ChromeThread::IO, FROM_HERE, this);
|
| + ReleaseSoon();
|
| }
|
|
|
| private:
|
| friend class LoginPrompt;
|
|
|
| - // Calls SetAuth from the IO loop.
|
| - void SetAuthDeferred(const std::wstring& username,
|
| - const std::wstring& password) {
|
| - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
|
| -
|
| - if (request_) {
|
| - request_->SetAuth(username, password);
|
| - ResetLoginHandlerForRequest(request_);
|
| - }
|
| - }
|
| -
|
| - // Calls CancelAuth from the IO loop.
|
| - void CancelAuthDeferred() {
|
| - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
|
| -
|
| - 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(ChromeThread::CurrentlyOn(ChromeThread::UI));
|
| -
|
| - // 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(ChromeThread::CurrentlyOn(ChromeThread::UI));
|
| -
|
| - 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<NavigationController>(controller),
|
| - Details<LoginNotificationDetails>(&details));
|
| - } else {
|
| - service->Notify(NotificationType::AUTH_SUPPLIED,
|
| - Source<NavigationController>(controller),
|
| - NotificationService::NoDetails());
|
| - }
|
| - }
|
| -
|
| static void OnOKClicked(GtkButton *button, LoginHandlerGtk* handler) {
|
| DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
|
|
|
| @@ -300,6 +138,7 @@
|
|
|
| static void OnCancelClicked(GtkButton *button, LoginHandlerGtk* handler) {
|
| DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
|
| +
|
| handler->CancelAuth();
|
| }
|
|
|
| @@ -307,6 +146,7 @@
|
| GtkWidget* previous_toplevel,
|
| LoginHandlerGtk* handler) {
|
| DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
|
| +
|
| if (!GTK_WIDGET_TOPLEVEL(gtk_widget_get_toplevel(handler->ok_)))
|
| return;
|
|
|
| @@ -315,35 +155,8 @@
|
| GTK_WIDGET_SET_FLAGS(handler->ok_, GTK_CAN_DEFAULT);
|
| gtk_widget_grab_default(handler->ok_);
|
| gtk_widget_grab_focus(handler->username_entry_);
|
| -}
|
| + }
|
|
|
| - // 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 request that wants login data.
|
| - // This should only be accessed on the IO loop.
|
| - URLRequest* request_;
|
| -
|
| - // 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_;
|
| -
|
| // The GtkWidgets that form our visual hierarchy:
|
| // The root container we pass to our parent.
|
| OwnedWidgetGtk root_;
|
| @@ -353,10 +166,6 @@
|
| GtkWidget* password_entry_;
|
| GtkWidget* ok_;
|
|
|
| - // 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);
|
| };
|
|
|
|
|