| 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 "base/string16.h" | 7 #include "base/string16.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/password_manager/password_manager.h" | 9 #include "chrome/browser/password_manager/password_manager.h" |
| 10 #include "chrome/browser/tab_contents/tab_util.h" | 10 #include "chrome/browser/tab_contents/tab_util.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 // This class simply forwards the authentication from the LoginView (on | 29 // This class simply forwards the authentication from the LoginView (on |
| 30 // the UI thread) to the net::URLRequest (on the I/O thread). | 30 // the UI thread) to the net::URLRequest (on the I/O thread). |
| 31 // This class uses ref counting to ensure that it lives until all InvokeLaters | 31 // This class uses ref counting to ensure that it lives until all InvokeLaters |
| 32 // have been called. | 32 // have been called. |
| 33 class LoginHandlerViews : public LoginHandler, | 33 class LoginHandlerViews : public LoginHandler, |
| 34 public views::DialogDelegate { | 34 public views::DialogDelegate { |
| 35 public: | 35 public: |
| 36 LoginHandlerViews(net::AuthChallengeInfo* auth_info, net::URLRequest* request) | 36 LoginHandlerViews(net::AuthChallengeInfo* auth_info, net::URLRequest* request) |
| 37 : LoginHandler(auth_info, request), | 37 : LoginHandler(auth_info, request), |
| 38 login_view_(NULL) { | 38 login_view_(NULL), |
| 39 dialog_(NULL) { |
| 39 } | 40 } |
| 40 | 41 |
| 41 // LoginModelObserver implementation. | 42 // LoginModelObserver implementation. |
| 42 virtual void OnAutofillDataAvailable(const string16& username, | 43 virtual void OnAutofillDataAvailable(const string16& username, |
| 43 const string16& password) OVERRIDE { | 44 const string16& password) OVERRIDE { |
| 44 // Nothing to do here since LoginView takes care of autofill for win. | 45 // Nothing to do here since LoginView takes care of autofill for win. |
| 45 } | 46 } |
| 46 | 47 |
| 47 // views::DialogDelegate methods: | 48 // views::DialogDelegate methods: |
| 48 virtual string16 GetDialogButtonLabel( | 49 virtual string16 GetDialogButtonLabel( |
| 49 ui::DialogButton button) const OVERRIDE { | 50 ui::DialogButton button) const OVERRIDE { |
| 50 if (button == ui::DIALOG_BUTTON_OK) | 51 if (button == ui::DIALOG_BUTTON_OK) |
| 51 return l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL); | 52 return l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL); |
| 52 return DialogDelegate::GetDialogButtonLabel(button); | 53 return DialogDelegate::GetDialogButtonLabel(button); |
| 53 } | 54 } |
| 54 | 55 |
| 55 virtual string16 GetWindowTitle() const OVERRIDE { | 56 virtual string16 GetWindowTitle() const OVERRIDE { |
| 56 return l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_TITLE); | 57 return l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_TITLE); |
| 57 } | 58 } |
| 58 | 59 |
| 59 virtual void WindowClosing() OVERRIDE { | 60 virtual void WindowClosing() OVERRIDE { |
| 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 61 | 62 |
| 62 WebContents* tab = GetWebContentsForLogin(); | 63 WebContents* tab = GetWebContentsForLogin(); |
| 63 if (tab) | 64 if (tab) |
| 64 tab->GetRenderViewHost()->SetIgnoreInputEvents(false); | 65 tab->GetRenderViewHost()->SetIgnoreInputEvents(false); |
| 65 | 66 |
| 66 // Reference is no longer valid. | 67 // Reference is no longer valid. |
| 67 SetDialog(NULL); | 68 dialog_ = NULL; |
| 68 | 69 |
| 69 CancelAuth(); | 70 CancelAuth(); |
| 70 } | 71 } |
| 71 | 72 |
| 72 virtual void DeleteDelegate() OVERRIDE { | 73 virtual void DeleteDelegate() OVERRIDE { |
| 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 74 | 75 |
| 75 // The constrained window is going to delete itself; clear our pointer. | 76 // The constrained window is going to delete itself; clear our pointer. |
| 76 SetDialog(NULL); | 77 dialog_ = NULL; |
| 77 SetModel(NULL); | 78 SetModel(NULL); |
| 78 | 79 |
| 79 ReleaseSoon(); | 80 ReleaseSoon(); |
| 80 } | 81 } |
| 81 | 82 |
| 82 virtual ui::ModalType GetModalType() const OVERRIDE { | 83 virtual ui::ModalType GetModalType() const OVERRIDE { |
| 83 #if defined(USE_ASH) | 84 #if defined(USE_ASH) |
| 84 return ui::MODAL_TYPE_CHILD; | 85 return ui::MODAL_TYPE_CHILD; |
| 85 #else | 86 #else |
| 86 return views::WidgetDelegate::GetModalType(); | 87 return views::WidgetDelegate::GetModalType(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // disassociating the model from the view, because the view will | 129 // disassociating the model from the view, because the view will |
| 129 // be deleted before the password manager. | 130 // be deleted before the password manager. |
| 130 login_view_ = new LoginView(explanation, manager); | 131 login_view_ = new LoginView(explanation, manager); |
| 131 | 132 |
| 132 // Scary thread safety note: This can potentially be called *after* SetAuth | 133 // Scary thread safety note: This can potentially be called *after* SetAuth |
| 133 // or CancelAuth (say, if the request was cancelled before the UI thread got | 134 // or CancelAuth (say, if the request was cancelled before the UI thread got |
| 134 // control). However, that's OK since any UI interaction in those functions | 135 // control). However, that's OK since any UI interaction in those functions |
| 135 // will occur via an InvokeLater on the UI thread, which is guaranteed | 136 // will occur via an InvokeLater on the UI thread, which is guaranteed |
| 136 // to happen after this is called (since this was InvokeLater'd first). | 137 // to happen after this is called (since this was InvokeLater'd first). |
| 137 WebContents* requesting_contents = GetWebContentsForLogin(); | 138 WebContents* requesting_contents = GetWebContentsForLogin(); |
| 138 SetDialog(ConstrainedWindowViews::Create(requesting_contents, this)); | 139 dialog_ = ConstrainedWindowViews::Create(requesting_contents, this); |
| 139 NotifyAuthNeeded(); | 140 NotifyAuthNeeded(); |
| 140 } | 141 } |
| 141 | 142 |
| 143 virtual void CloseDialog() OVERRIDE { |
| 144 // The hosting WebContentsModalDialog may have been freed. |
| 145 if (dialog_) |
| 146 dialog_->CloseWebContentsModalDialog(); |
| 147 } |
| 148 |
| 142 private: | 149 private: |
| 143 friend class base::RefCountedThreadSafe<LoginHandlerViews>; | 150 friend class base::RefCountedThreadSafe<LoginHandlerViews>; |
| 144 friend class LoginPrompt; | 151 friend class LoginPrompt; |
| 145 | 152 |
| 146 virtual ~LoginHandlerViews() {} | 153 virtual ~LoginHandlerViews() {} |
| 147 | 154 |
| 148 // The LoginView that contains the user's login information | 155 // The LoginView that contains the user's login information |
| 149 LoginView* login_view_; | 156 LoginView* login_view_; |
| 150 | 157 |
| 158 ConstrainedWindowViews* dialog_; |
| 159 |
| 151 DISALLOW_COPY_AND_ASSIGN(LoginHandlerViews); | 160 DISALLOW_COPY_AND_ASSIGN(LoginHandlerViews); |
| 152 }; | 161 }; |
| 153 | 162 |
| 154 // static | 163 // static |
| 155 LoginHandler* LoginHandler::Create(net::AuthChallengeInfo* auth_info, | 164 LoginHandler* LoginHandler::Create(net::AuthChallengeInfo* auth_info, |
| 156 net::URLRequest* request) { | 165 net::URLRequest* request) { |
| 157 return new LoginHandlerViews(auth_info, request); | 166 return new LoginHandlerViews(auth_info, request); |
| 158 } | 167 } |
| OLD | NEW |