Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: content/shell/shell_login_dialog.cc

Issue 10069054: RefCounted types should not have public destructors, content/ remaining bits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased to Trunk Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/shell/shell_login_dialog.h ('k') | content/test/mock_download_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/shell/shell_login_dialog.h" 5 #include "content/shell/shell_login_dialog.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/resource_dispatcher_host.h" 11 #include "content/public/browser/resource_dispatcher_host.h"
12 #include "net/base/auth.h" 12 #include "net/base/auth.h"
13 #include "net/url_request/url_request.h" 13 #include "net/url_request/url_request.h"
14 #include "ui/base/text/text_elider.h" 14 #include "ui/base/text/text_elider.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 ShellLoginDialog::ShellLoginDialog( 18 ShellLoginDialog::ShellLoginDialog(
19 net::AuthChallengeInfo* auth_info, 19 net::AuthChallengeInfo* auth_info,
20 net::URLRequest* request) : auth_info_(auth_info), 20 net::URLRequest* request) : auth_info_(auth_info),
21 request_(request) { 21 request_(request) {
22 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 22 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
23 BrowserThread::PostTask( 23 BrowserThread::PostTask(
24 BrowserThread::UI, FROM_HERE, 24 BrowserThread::UI, FROM_HERE,
25 base::Bind(&ShellLoginDialog::PrepDialog, this, 25 base::Bind(&ShellLoginDialog::PrepDialog, this,
26 ASCIIToUTF16(auth_info->challenger.ToString()), 26 ASCIIToUTF16(auth_info->challenger.ToString()),
27 UTF8ToUTF16(auth_info->realm))); 27 UTF8ToUTF16(auth_info->realm)));
28 } 28 }
29 29
30 ShellLoginDialog::~ShellLoginDialog() {
31 // Cannot post any tasks here; this object is going away and cannot be
32 // referenced/dereferenced.
33 }
34
35 void ShellLoginDialog::OnRequestCancelled() { 30 void ShellLoginDialog::OnRequestCancelled() {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
37 BrowserThread::PostTask( 32 BrowserThread::PostTask(
38 BrowserThread::UI, FROM_HERE, 33 BrowserThread::UI, FROM_HERE,
39 base::Bind(&ShellLoginDialog::PlatformRequestCancelled, this)); 34 base::Bind(&ShellLoginDialog::PlatformRequestCancelled, this));
40 } 35 }
41 36
37 void ShellLoginDialog::UserAcceptedAuth(const string16& username,
38 const string16& password) {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
40 BrowserThread::PostTask(
41 BrowserThread::IO, FROM_HERE,
42 base::Bind(&ShellLoginDialog::SendAuthToRequester, this,
43 true, username, password));
44 }
45
46 void ShellLoginDialog::UserCancelledAuth() {
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
48 BrowserThread::PostTask(
49 BrowserThread::IO, FROM_HERE,
50 base::Bind(&ShellLoginDialog::SendAuthToRequester, this,
51 false, string16(), string16()));
52 BrowserThread::PostTask(
53 BrowserThread::UI, FROM_HERE,
54 base::Bind(&ShellLoginDialog::PlatformCleanUp, this));
55 }
56
57 ShellLoginDialog::~ShellLoginDialog() {
58 // Cannot post any tasks here; this object is going away and cannot be
59 // referenced/dereferenced.
60 }
61
62 #if !defined(OS_MACOSX)
63 // Bogus implementations for linking. They are never called because
64 // ResourceDispatcherHostDelegate::CreateLoginDelegate returns NULL.
65 // TODO: implement ShellLoginDialog for other platforms, drop this #if
66 void ShellLoginDialog::PlatformCreateDialog(const string16& message) {}
67 void ShellLoginDialog::PlatformCleanUp() {}
68 void ShellLoginDialog::PlatformRequestCancelled() {}
69 #endif
70
42 void ShellLoginDialog::PrepDialog(const string16& host, 71 void ShellLoginDialog::PrepDialog(const string16& host,
43 const string16& realm) { 72 const string16& realm) {
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
45 // The realm is controlled by the remote server, so there is no reason to 74 // The realm is controlled by the remote server, so there is no reason to
46 // believe it is of a reasonable length. 75 // believe it is of a reasonable length.
47 string16 elided_realm; 76 string16 elided_realm;
48 ui::ElideString(realm, 120, &elided_realm); 77 ui::ElideString(realm, 120, &elided_realm);
49 78
50 string16 explanation = 79 string16 explanation =
51 ASCIIToUTF16("The server ") + host + 80 ASCIIToUTF16("The server ") + host +
52 ASCIIToUTF16(" requires a username and password."); 81 ASCIIToUTF16(" requires a username and password.");
53 82
54 if (!elided_realm.empty()) { 83 if (!elided_realm.empty()) {
55 explanation += ASCIIToUTF16(" The server says: "); 84 explanation += ASCIIToUTF16(" The server says: ");
56 explanation += elided_realm; 85 explanation += elided_realm;
57 explanation += ASCIIToUTF16("."); 86 explanation += ASCIIToUTF16(".");
58 } 87 }
59 88
60 PlatformCreateDialog(explanation); 89 PlatformCreateDialog(explanation);
61 } 90 }
62 91
63 void ShellLoginDialog::UserAcceptedAuth(const string16& username,
64 const string16& password) {
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
66 BrowserThread::PostTask(
67 BrowserThread::IO, FROM_HERE,
68 base::Bind(&ShellLoginDialog::SendAuthToRequester, this,
69 true, username, password));
70 }
71
72 void ShellLoginDialog::UserCancelledAuth() {
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
74 BrowserThread::PostTask(
75 BrowserThread::IO, FROM_HERE,
76 base::Bind(&ShellLoginDialog::SendAuthToRequester, this,
77 false, string16(), string16()));
78 BrowserThread::PostTask(
79 BrowserThread::UI, FROM_HERE,
80 base::Bind(&ShellLoginDialog::PlatformCleanUp, this));
81 }
82
83 void ShellLoginDialog::SendAuthToRequester(bool success, 92 void ShellLoginDialog::SendAuthToRequester(bool success,
84 const string16& username, 93 const string16& username,
85 const string16& password) { 94 const string16& password) {
86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
87 if (success) 96 if (success)
88 request_->SetAuth(net::AuthCredentials(username, password)); 97 request_->SetAuth(net::AuthCredentials(username, password));
89 else 98 else
90 request_->CancelAuth(); 99 request_->CancelAuth();
91 ResourceDispatcherHost::Get()->ClearLoginDelegateForRequest(request_); 100 ResourceDispatcherHost::Get()->ClearLoginDelegateForRequest(request_);
92 101
93 BrowserThread::PostTask( 102 BrowserThread::PostTask(
94 BrowserThread::UI, FROM_HERE, 103 BrowserThread::UI, FROM_HERE,
95 base::Bind(&ShellLoginDialog::PlatformCleanUp, this)); 104 base::Bind(&ShellLoginDialog::PlatformCleanUp, this));
96 } 105 }
97 106
98 #if !defined(OS_MACOSX)
99 // Bogus implementations for linking. They are never called because
100 // ResourceDispatcherHostDelegate::CreateLoginDelegate returns NULL.
101 // TODO: implement ShellLoginDialog for other platforms, drop this #if
102 void ShellLoginDialog::PlatformCreateDialog(const string16& message) {}
103 void ShellLoginDialog::PlatformCleanUp() {}
104 void ShellLoginDialog::PlatformRequestCancelled() {}
105 #endif
106
107 } // namespace content 107 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/shell_login_dialog.h ('k') | content/test/mock_download_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698