| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/login_prompt.h" | |
| 6 | |
| 7 #include "app/l10n_util.h" | |
| 8 #include "chrome/browser/browser_thread.h" | |
| 9 #include "chrome/browser/password_manager/password_manager.h" | |
| 10 #include "chrome/browser/renderer_host/render_process_host.h" | |
| 11 #include "chrome/browser/renderer_host/render_view_host.h" | |
| 12 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | |
| 13 #include "chrome/browser/tab_contents/navigation_controller.h" | |
| 14 #include "chrome/browser/tab_contents/tab_contents.h" | |
| 15 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | |
| 16 #include "chrome/browser/tab_contents/tab_util.h" | |
| 17 #include "chrome/browser/views/login_view.h" | |
| 18 #include "chrome/common/notification_service.h" | |
| 19 #include "grit/generated_resources.h" | |
| 20 #include "net/url_request/url_request.h" | |
| 21 #include "views/window/dialog_delegate.h" | |
| 22 | |
| 23 using webkit_glue::PasswordForm; | |
| 24 | |
| 25 // ---------------------------------------------------------------------------- | |
| 26 // LoginHandlerWin | |
| 27 | |
| 28 // This class simply forwards the authentication from the LoginView (on | |
| 29 // the UI thread) to the net::URLRequest (on the I/O thread). | |
| 30 // This class uses ref counting to ensure that it lives until all InvokeLaters | |
| 31 // have been called. | |
| 32 class LoginHandlerWin : public LoginHandler, | |
| 33 public ConstrainedDialogDelegate { | |
| 34 public: | |
| 35 LoginHandlerWin(net::AuthChallengeInfo* auth_info, net::URLRequest* request) | |
| 36 : LoginHandler(auth_info, request) { | |
| 37 } | |
| 38 | |
| 39 // LoginModelObserver implementation. | |
| 40 virtual void OnAutofillDataAvailable(const std::wstring& username, | |
| 41 const std::wstring& password) { | |
| 42 // Nothing to do here since LoginView takes care of autofil for win. | |
| 43 } | |
| 44 | |
| 45 void set_login_view(LoginView* login_view) { | |
| 46 login_view_ = login_view; | |
| 47 } | |
| 48 | |
| 49 // views::DialogDelegate methods: | |
| 50 virtual std::wstring GetDialogButtonLabel( | |
| 51 MessageBoxFlags::DialogButton button) const { | |
| 52 if (button == MessageBoxFlags::DIALOGBUTTON_OK) | |
| 53 return l10n_util::GetString(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL); | |
| 54 return DialogDelegate::GetDialogButtonLabel(button); | |
| 55 } | |
| 56 | |
| 57 virtual std::wstring GetWindowTitle() const { | |
| 58 return l10n_util::GetString(IDS_LOGIN_DIALOG_TITLE); | |
| 59 } | |
| 60 | |
| 61 virtual void WindowClosing() { | |
| 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 63 | |
| 64 TabContents* tab = GetTabContentsForLogin(); | |
| 65 if (tab) | |
| 66 tab->render_view_host()->set_ignore_input_events(false); | |
| 67 | |
| 68 // Reference is no longer valid. | |
| 69 SetDialog(NULL); | |
| 70 | |
| 71 CancelAuth(); | |
| 72 } | |
| 73 | |
| 74 virtual void DeleteDelegate() { | |
| 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 76 | |
| 77 // The constrained window is going to delete itself; clear our pointer. | |
| 78 SetDialog(NULL); | |
| 79 SetModel(NULL); | |
| 80 | |
| 81 ReleaseSoon(); | |
| 82 } | |
| 83 | |
| 84 virtual bool Cancel() { | |
| 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 86 | |
| 87 CancelAuth(); | |
| 88 return true; | |
| 89 } | |
| 90 | |
| 91 virtual bool Accept() { | |
| 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 93 | |
| 94 SetAuth(login_view_->GetUsername(), login_view_->GetPassword()); | |
| 95 return true; | |
| 96 } | |
| 97 | |
| 98 virtual views::View* GetContentsView() { | |
| 99 return login_view_; | |
| 100 } | |
| 101 | |
| 102 // LoginHandler: | |
| 103 | |
| 104 virtual void BuildViewForPasswordManager(PasswordManager* manager, | |
| 105 std::wstring explanation) { | |
| 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 107 | |
| 108 TabContents* tab_contents = GetTabContentsForLogin(); | |
| 109 bool should_focus_view = !tab_contents->delegate() || | |
| 110 tab_contents->delegate()->ShouldFocusConstrainedWindow(); | |
| 111 | |
| 112 LoginView* view = new LoginView(explanation, should_focus_view); | |
| 113 | |
| 114 // Set the model for the login view. The model (password manager) is owned | |
| 115 // by the view's parent TabContents, so natural destruction order means we | |
| 116 // don't have to worry about calling SetModel(NULL), because the view will | |
| 117 // be deleted before the password manager. | |
| 118 view->SetModel(manager); | |
| 119 | |
| 120 set_login_view(view); | |
| 121 | |
| 122 // Scary thread safety note: This can potentially be called *after* SetAuth | |
| 123 // or CancelAuth (say, if the request was cancelled before the UI thread got | |
| 124 // control). However, that's OK since any UI interaction in those functions | |
| 125 // will occur via an InvokeLater on the UI thread, which is guaranteed | |
| 126 // to happen after this is called (since this was InvokeLater'd first). | |
| 127 SetDialog(GetTabContentsForLogin()->CreateConstrainedDialog(this)); | |
| 128 NotifyAuthNeeded(); | |
| 129 } | |
| 130 | |
| 131 private: | |
| 132 friend class base::RefCountedThreadSafe<LoginHandlerWin>; | |
| 133 friend class LoginPrompt; | |
| 134 | |
| 135 ~LoginHandlerWin() {} | |
| 136 | |
| 137 // The LoginView that contains the user's login information | |
| 138 LoginView* login_view_; | |
| 139 | |
| 140 DISALLOW_COPY_AND_ASSIGN(LoginHandlerWin); | |
| 141 }; | |
| 142 | |
| 143 // static | |
| 144 LoginHandler* LoginHandler::Create(net::AuthChallengeInfo* auth_info, | |
| 145 net::URLRequest* request) { | |
| 146 return new LoginHandlerWin(auth_info, request); | |
| 147 } | |
| OLD | NEW |