| 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/strings/string16.h" | 7 #include "base/strings/string16.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/ui/views/login_view.h" | 9 #include "chrome/browser/ui/views/login_view.h" |
| 10 #include "chrome/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // have been called. | 27 // have been called. |
| 28 class LoginHandlerViews : public LoginHandler, public views::DialogDelegate { | 28 class LoginHandlerViews : public LoginHandler, public views::DialogDelegate { |
| 29 public: | 29 public: |
| 30 LoginHandlerViews(net::AuthChallengeInfo* auth_info, net::URLRequest* request) | 30 LoginHandlerViews(net::AuthChallengeInfo* auth_info, net::URLRequest* request) |
| 31 : LoginHandler(auth_info, request), | 31 : LoginHandler(auth_info, request), |
| 32 login_view_(NULL), | 32 login_view_(NULL), |
| 33 dialog_(NULL) { | 33 dialog_(NULL) { |
| 34 } | 34 } |
| 35 | 35 |
| 36 // LoginModelObserver: | 36 // LoginModelObserver: |
| 37 void OnAutofillDataAvailable(const base::string16& username, | 37 void OnAutofillDataAvailableInternal( |
| 38 const base::string16& password) override { | 38 const base::string16& username, |
| 39 const base::string16& password) override { |
| 39 // Nothing to do here since LoginView takes care of autofill for win. | 40 // Nothing to do here since LoginView takes care of autofill for win. |
| 40 } | 41 } |
| 41 void OnLoginModelDestroying() override {} | 42 void OnLoginModelDestroying() override {} |
| 42 | 43 |
| 43 // views::DialogDelegate: | 44 // views::DialogDelegate: |
| 44 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override { | 45 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override { |
| 45 if (button == ui::DIALOG_BUTTON_OK) | 46 if (button == ui::DIALOG_BUTTON_OK) |
| 46 return l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL); | 47 return l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL); |
| 47 return DialogDelegate::GetDialogButtonLabel(button); | 48 return DialogDelegate::GetDialogButtonLabel(button); |
| 48 } | 49 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 60 // Reference is no longer valid. | 61 // Reference is no longer valid. |
| 61 dialog_ = NULL; | 62 dialog_ = NULL; |
| 62 CancelAuth(); | 63 CancelAuth(); |
| 63 } | 64 } |
| 64 | 65 |
| 65 void DeleteDelegate() override { | 66 void DeleteDelegate() override { |
| 66 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 67 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 67 | 68 |
| 68 // The widget is going to delete itself; clear our pointer. | 69 // The widget is going to delete itself; clear our pointer. |
| 69 dialog_ = NULL; | 70 dialog_ = NULL; |
| 70 SetModel(NULL); | 71 SetModel(nullptr, nullptr); |
| 71 | 72 |
| 72 ReleaseSoon(); | 73 ReleaseSoon(); |
| 73 } | 74 } |
| 74 | 75 |
| 75 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_CHILD; } | 76 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_CHILD; } |
| 76 | 77 |
| 77 bool Cancel() override { | 78 bool Cancel() override { |
| 78 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 79 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 79 CancelAuth(); | 80 CancelAuth(); |
| 80 return true; | 81 return true; |
| 81 } | 82 } |
| 82 | 83 |
| 83 bool Accept() override { | 84 bool Accept() override { |
| 84 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 85 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 85 SetAuth(login_view_->GetUsername(), login_view_->GetPassword()); | 86 SetAuth(login_view_->GetUsername(), login_view_->GetPassword()); |
| 86 return true; | 87 return true; |
| 87 } | 88 } |
| 88 | 89 |
| 89 views::View* GetInitiallyFocusedView() override { | 90 views::View* GetInitiallyFocusedView() override { |
| 90 return login_view_->GetInitiallyFocusedView(); | 91 return login_view_->GetInitiallyFocusedView(); |
| 91 } | 92 } |
| 92 | 93 |
| 93 views::View* GetContentsView() override { return login_view_; } | 94 views::View* GetContentsView() override { return login_view_; } |
| 94 views::Widget* GetWidget() override { return login_view_->GetWidget(); } | 95 views::Widget* GetWidget() override { return login_view_->GetWidget(); } |
| 95 const views::Widget* GetWidget() const override { | 96 const views::Widget* GetWidget() const override { |
| 96 return login_view_->GetWidget(); | 97 return login_view_->GetWidget(); |
| 97 } | 98 } |
| 98 | 99 |
| 99 // LoginHandler: | 100 // LoginHandler: |
| 100 void BuildViewForPasswordManager(password_manager::PasswordManager* manager, | 101 void BuildViewForPasswordManager( |
| 101 const base::string16& explanation) override { | 102 password_manager::PasswordManager* manager, |
| 103 const base::string16& explanation, |
| 104 const autofill::PasswordForm* observed_form) override { |
| 102 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 105 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 106 DCHECK_EQ(manager == nullptr, observed_form == nullptr); |
| 103 | 107 |
| 104 // Create a new LoginView and set the model for it. The model (password | 108 // Create a new LoginView and set the model for it. The model (password |
| 105 // manager) is owned by the WebContents, but the view is parented to the | 109 // manager) is owned by the WebContents, but the view is parented to the |
| 106 // browser window, so the view may be destroyed after the password | 110 // browser window, so the view may be destroyed after the password |
| 107 // manager. The view listens for model destruction and unobserves | 111 // manager. The view listens for model destruction and unobserves |
| 108 // accordingly. | 112 // accordingly. |
| 109 login_view_ = new LoginView(explanation, manager); | 113 login_view_ = new LoginView(explanation, manager, observed_form); |
| 110 | 114 |
| 111 // Scary thread safety note: This can potentially be called *after* SetAuth | 115 // Scary thread safety note: This can potentially be called *after* SetAuth |
| 112 // or CancelAuth (say, if the request was cancelled before the UI thread got | 116 // or CancelAuth (say, if the request was cancelled before the UI thread got |
| 113 // control). However, that's OK since any UI interaction in those functions | 117 // control). However, that's OK since any UI interaction in those functions |
| 114 // will occur via an InvokeLater on the UI thread, which is guaranteed | 118 // will occur via an InvokeLater on the UI thread, which is guaranteed |
| 115 // to happen after this is called (since this was InvokeLater'd first). | 119 // to happen after this is called (since this was InvokeLater'd first). |
| 116 dialog_ = constrained_window::ShowWebModalDialogViews( | 120 dialog_ = constrained_window::ShowWebModalDialogViews( |
| 117 this, GetWebContentsForLogin()); | 121 this, GetWebContentsForLogin()); |
| 118 NotifyAuthNeeded(); | 122 NotifyAuthNeeded(); |
| 119 } | 123 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 139 }; | 143 }; |
| 140 | 144 |
| 141 namespace chrome { | 145 namespace chrome { |
| 142 | 146 |
| 143 LoginHandler* CreateLoginHandlerViews(net::AuthChallengeInfo* auth_info, | 147 LoginHandler* CreateLoginHandlerViews(net::AuthChallengeInfo* auth_info, |
| 144 net::URLRequest* request) { | 148 net::URLRequest* request) { |
| 145 return new LoginHandlerViews(auth_info, request); | 149 return new LoginHandlerViews(auth_info, request); |
| 146 } | 150 } |
| 147 | 151 |
| 148 } // namespace chrome | 152 } // namespace chrome |
| OLD | NEW |