| 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/constrained_window_views.h" | 9 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 10 #include "chrome/browser/ui/views/login_view.h" | 10 #include "chrome/browser/ui/views/login_view.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 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 virtual void OnAutofillDataAvailable( | 37 virtual void OnAutofillDataAvailable( |
| 38 const base::string16& username, | 38 const base::string16& username, |
| 39 const base::string16& password) OVERRIDE { | 39 const base::string16& password) override { |
| 40 // 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. |
| 41 } | 41 } |
| 42 virtual void OnLoginModelDestroying() OVERRIDE {} | 42 virtual void OnLoginModelDestroying() override {} |
| 43 | 43 |
| 44 // views::DialogDelegate: | 44 // views::DialogDelegate: |
| 45 virtual base::string16 GetDialogButtonLabel( | 45 virtual base::string16 GetDialogButtonLabel( |
| 46 ui::DialogButton button) const OVERRIDE { | 46 ui::DialogButton button) const override { |
| 47 if (button == ui::DIALOG_BUTTON_OK) | 47 if (button == ui::DIALOG_BUTTON_OK) |
| 48 return l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL); | 48 return l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL); |
| 49 return DialogDelegate::GetDialogButtonLabel(button); | 49 return DialogDelegate::GetDialogButtonLabel(button); |
| 50 } | 50 } |
| 51 | 51 |
| 52 virtual base::string16 GetWindowTitle() const OVERRIDE { | 52 virtual base::string16 GetWindowTitle() const override { |
| 53 return l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_TITLE); | 53 return l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_TITLE); |
| 54 } | 54 } |
| 55 | 55 |
| 56 virtual void WindowClosing() OVERRIDE { | 56 virtual void WindowClosing() override { |
| 57 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 57 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 58 content::WebContents* web_contents = GetWebContentsForLogin(); | 58 content::WebContents* web_contents = GetWebContentsForLogin(); |
| 59 if (web_contents) | 59 if (web_contents) |
| 60 web_contents->GetRenderViewHost()->SetIgnoreInputEvents(false); | 60 web_contents->GetRenderViewHost()->SetIgnoreInputEvents(false); |
| 61 | 61 |
| 62 // Reference is no longer valid. | 62 // Reference is no longer valid. |
| 63 dialog_ = NULL; | 63 dialog_ = NULL; |
| 64 CancelAuth(); | 64 CancelAuth(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 virtual void DeleteDelegate() OVERRIDE { | 67 virtual void DeleteDelegate() override { |
| 68 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 68 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 69 | 69 |
| 70 // The widget is going to delete itself; clear our pointer. | 70 // The widget is going to delete itself; clear our pointer. |
| 71 dialog_ = NULL; | 71 dialog_ = NULL; |
| 72 SetModel(NULL); | 72 SetModel(NULL); |
| 73 | 73 |
| 74 ReleaseSoon(); | 74 ReleaseSoon(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 virtual ui::ModalType GetModalType() const OVERRIDE { | 77 virtual ui::ModalType GetModalType() const override { |
| 78 return ui::MODAL_TYPE_CHILD; | 78 return ui::MODAL_TYPE_CHILD; |
| 79 } | 79 } |
| 80 | 80 |
| 81 virtual bool Cancel() OVERRIDE { | 81 virtual bool Cancel() override { |
| 82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 83 CancelAuth(); | 83 CancelAuth(); |
| 84 return true; | 84 return true; |
| 85 } | 85 } |
| 86 | 86 |
| 87 virtual bool Accept() OVERRIDE { | 87 virtual bool Accept() override { |
| 88 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 88 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 89 SetAuth(login_view_->GetUsername(), login_view_->GetPassword()); | 89 SetAuth(login_view_->GetUsername(), login_view_->GetPassword()); |
| 90 return true; | 90 return true; |
| 91 } | 91 } |
| 92 | 92 |
| 93 virtual views::View* GetInitiallyFocusedView() OVERRIDE { | 93 virtual views::View* GetInitiallyFocusedView() override { |
| 94 return login_view_->GetInitiallyFocusedView(); | 94 return login_view_->GetInitiallyFocusedView(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 virtual views::View* GetContentsView() OVERRIDE { | 97 virtual views::View* GetContentsView() override { |
| 98 return login_view_; | 98 return login_view_; |
| 99 } | 99 } |
| 100 virtual views::Widget* GetWidget() OVERRIDE { | 100 virtual views::Widget* GetWidget() override { |
| 101 return login_view_->GetWidget(); | 101 return login_view_->GetWidget(); |
| 102 } | 102 } |
| 103 virtual const views::Widget* GetWidget() const OVERRIDE { | 103 virtual const views::Widget* GetWidget() const override { |
| 104 return login_view_->GetWidget(); | 104 return login_view_->GetWidget(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 // LoginHandler: | 107 // LoginHandler: |
| 108 virtual void BuildViewForPasswordManager( | 108 virtual void BuildViewForPasswordManager( |
| 109 password_manager::PasswordManager* manager, | 109 password_manager::PasswordManager* manager, |
| 110 const base::string16& explanation) OVERRIDE { | 110 const base::string16& explanation) override { |
| 111 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 111 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 112 | 112 |
| 113 // Create a new LoginView and set the model for it. The model (password | 113 // Create a new LoginView and set the model for it. The model (password |
| 114 // manager) is owned by the WebContents, but the view is parented to the | 114 // manager) is owned by the WebContents, but the view is parented to the |
| 115 // browser window, so the view may be destroyed after the password | 115 // browser window, so the view may be destroyed after the password |
| 116 // manager. The view listens for model destruction and unobserves | 116 // manager. The view listens for model destruction and unobserves |
| 117 // accordingly. | 117 // accordingly. |
| 118 login_view_ = new LoginView(explanation, manager); | 118 login_view_ = new LoginView(explanation, manager); |
| 119 | 119 |
| 120 // Scary thread safety note: This can potentially be called *after* SetAuth | 120 // Scary thread safety note: This can potentially be called *after* SetAuth |
| 121 // or CancelAuth (say, if the request was cancelled before the UI thread got | 121 // or CancelAuth (say, if the request was cancelled before the UI thread got |
| 122 // control). However, that's OK since any UI interaction in those functions | 122 // control). However, that's OK since any UI interaction in those functions |
| 123 // will occur via an InvokeLater on the UI thread, which is guaranteed | 123 // will occur via an InvokeLater on the UI thread, which is guaranteed |
| 124 // to happen after this is called (since this was InvokeLater'd first). | 124 // to happen after this is called (since this was InvokeLater'd first). |
| 125 dialog_ = ShowWebModalDialogViews(this, GetWebContentsForLogin()); | 125 dialog_ = ShowWebModalDialogViews(this, GetWebContentsForLogin()); |
| 126 NotifyAuthNeeded(); | 126 NotifyAuthNeeded(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 virtual void CloseDialog() OVERRIDE { | 129 virtual void CloseDialog() override { |
| 130 // The hosting widget may have been freed. | 130 // The hosting widget may have been freed. |
| 131 if (dialog_) | 131 if (dialog_) |
| 132 dialog_->Close(); | 132 dialog_->Close(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 private: | 135 private: |
| 136 friend class base::RefCountedThreadSafe<LoginHandlerViews>; | 136 friend class base::RefCountedThreadSafe<LoginHandlerViews>; |
| 137 friend class LoginPrompt; | 137 friend class LoginPrompt; |
| 138 | 138 |
| 139 virtual ~LoginHandlerViews() {} | 139 virtual ~LoginHandlerViews() {} |
| 140 | 140 |
| 141 // The LoginView that contains the user's login information. | 141 // The LoginView that contains the user's login information. |
| 142 LoginView* login_view_; | 142 LoginView* login_view_; |
| 143 | 143 |
| 144 views::Widget* dialog_; | 144 views::Widget* dialog_; |
| 145 | 145 |
| 146 DISALLOW_COPY_AND_ASSIGN(LoginHandlerViews); | 146 DISALLOW_COPY_AND_ASSIGN(LoginHandlerViews); |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 // static | 149 // static |
| 150 LoginHandler* LoginHandler::Create(net::AuthChallengeInfo* auth_info, | 150 LoginHandler* LoginHandler::Create(net::AuthChallengeInfo* auth_info, |
| 151 net::URLRequest* request) { | 151 net::URLRequest* request) { |
| 152 return new LoginHandlerViews(auth_info, request); | 152 return new LoginHandlerViews(auth_info, request); |
| 153 } | 153 } |
| OLD | NEW |