Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/shell/shell_login_dialog.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/utf_string_conversions.h" | |
| 10 #include "content/public/browser/browser_thread.h" | |
| 11 #include "content/public/browser/resource_dispatcher_host.h" | |
| 12 #include "net/base/auth.h" | |
| 13 #include "net/url_request/url_request.h" | |
| 14 #include "ui/base/text/text_elider.h" | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 ShellLoginDialog::ShellLoginDialog(net::AuthChallengeInfo* auth_info, | |
| 19 net::URLRequest* request) : auth_info_(auth_info), | |
|
jochen (gone - plz use gerrit)
2012/04/04 15:46:56
Align parameters and put the initialization on a n
Avi (use Gerrit)
2012/04/04 16:18:03
Done.
| |
| 20 request_(request) { | |
| 21 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 22 BrowserThread::PostTask( | |
| 23 BrowserThread::UI, FROM_HERE, | |
| 24 base::Bind(&ShellLoginDialog::CreateDialog, this, | |
| 25 ASCIIToUTF16(auth_info->challenger.ToString()), | |
| 26 UTF8ToUTF16(auth_info->realm))); | |
| 27 } | |
| 28 | |
| 29 ShellLoginDialog::~ShellLoginDialog() { | |
| 30 // Cannot post any tasks here; this object is going away and cannot be | |
| 31 // referenced/dereferenced. | |
| 32 } | |
| 33 | |
| 34 void ShellLoginDialog::OnRequestCancelled() { | |
| 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 36 BrowserThread::PostTask( | |
| 37 BrowserThread::UI, FROM_HERE, | |
| 38 base::Bind(&ShellLoginDialog::PlatformRequestCancelled, this)); | |
| 39 } | |
| 40 | |
| 41 void ShellLoginDialog::CreateDialog(const string16& host, | |
| 42 const string16& realm) { | |
| 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 44 // The realm is controlled by the remote server, so there is no reason to | |
| 45 // believe it is of a reasonable length. | |
| 46 string16 elided_realm; | |
| 47 ui::ElideString(realm, 120, &elided_realm); | |
| 48 | |
| 49 string16 explanation = | |
| 50 ASCIIToUTF16("The server ") + host + | |
| 51 ASCIIToUTF16(" requires a username and password."); | |
| 52 | |
| 53 if (!elided_realm.empty()) { | |
| 54 explanation += ASCIIToUTF16(" The server says: "); | |
| 55 explanation += elided_realm; | |
| 56 explanation += ASCIIToUTF16("."); | |
| 57 } | |
| 58 | |
| 59 PlatformCreateDialog(explanation); | |
| 60 } | |
| 61 | |
| 62 void ShellLoginDialog::UserAcceptedAuth(const string16& username, | |
| 63 const string16& password) { | |
| 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 65 BrowserThread::PostTask( | |
| 66 BrowserThread::IO, FROM_HERE, | |
| 67 base::Bind(&ShellLoginDialog::SendAuthToRequester, this, | |
| 68 true, username, password)); | |
| 69 } | |
| 70 | |
| 71 void ShellLoginDialog::UserCancelledAuth() { | |
| 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 73 BrowserThread::PostTask( | |
| 74 BrowserThread::IO, FROM_HERE, | |
| 75 base::Bind(&ShellLoginDialog::SendAuthToRequester, this, | |
| 76 false, string16(), string16())); | |
| 77 BrowserThread::PostTask( | |
| 78 BrowserThread::UI, FROM_HERE, | |
| 79 base::Bind(&ShellLoginDialog::PlatformCleanUp, this)); | |
| 80 } | |
| 81 | |
| 82 void ShellLoginDialog::SendAuthToRequester(bool success, | |
| 83 const string16& username, | |
| 84 const string16& password) { | |
| 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 86 if (success) | |
| 87 request_->SetAuth(net::AuthCredentials(username, password)); | |
| 88 else | |
| 89 request_->CancelAuth(); | |
| 90 ResourceDispatcherHost::Get()->ClearLoginDelegateForRequest(request_); | |
| 91 | |
| 92 BrowserThread::PostTask( | |
| 93 BrowserThread::UI, FROM_HERE, | |
| 94 base::Bind(&ShellLoginDialog::PlatformCleanUp, this)); | |
| 95 } | |
| 96 | |
| 97 } // namespace content | |
| OLD | NEW |