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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "components/password_manager/core/browser/log_manager.h" | 25 #include "components/password_manager/core/browser/log_manager.h" |
26 #include "components/password_manager/core/browser/password_manager.h" | 26 #include "components/password_manager/core/browser/password_manager.h" |
27 #include "components/url_formatter/elide_url.h" | 27 #include "components/url_formatter/elide_url.h" |
28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
29 #include "content/public/browser/notification_registrar.h" | 29 #include "content/public/browser/notification_registrar.h" |
30 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
31 #include "content/public/browser/render_frame_host.h" | 31 #include "content/public/browser/render_frame_host.h" |
32 #include "content/public/browser/resource_dispatcher_host.h" | 32 #include "content/public/browser/resource_dispatcher_host.h" |
33 #include "content/public/browser/resource_request_info.h" | 33 #include "content/public/browser/resource_request_info.h" |
34 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 35 #include "content/public/common/origin_util.h" |
35 #include "net/base/auth.h" | 36 #include "net/base/auth.h" |
36 #include "net/base/load_flags.h" | 37 #include "net/base/load_flags.h" |
37 #include "net/base/net_util.h" | 38 #include "net/base/net_util.h" |
38 #include "net/http/http_transaction_factory.h" | 39 #include "net/http/http_transaction_factory.h" |
39 #include "net/url_request/url_request.h" | 40 #include "net/url_request/url_request.h" |
40 #include "net/url_request/url_request_context.h" | 41 #include "net/url_request/url_request_context.h" |
41 #include "ui/base/l10n/l10n_util.h" | 42 #include "ui/base/l10n/l10n_util.h" |
42 #include "ui/gfx/text_elider.h" | 43 #include "ui/gfx/text_elider.h" |
43 | 44 |
44 #if defined(ENABLE_EXTENSIONS) | 45 #if defined(ENABLE_EXTENSIONS) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 WebContents* parent_contents = handler->GetWebContentsForLogin(); | 103 WebContents* parent_contents = handler->GetWebContentsForLogin(); |
103 if (!parent_contents) | 104 if (!parent_contents) |
104 return; | 105 return; |
105 prerender::PrerenderContents* prerender_contents = | 106 prerender::PrerenderContents* prerender_contents = |
106 prerender::PrerenderContents::FromWebContents(parent_contents); | 107 prerender::PrerenderContents::FromWebContents(parent_contents); |
107 if (prerender_contents) { | 108 if (prerender_contents) { |
108 prerender_contents->Destroy(prerender::FINAL_STATUS_AUTH_NEEDED); | 109 prerender_contents->Destroy(prerender::FINAL_STATUS_AUTH_NEEDED); |
109 return; | 110 return; |
110 } | 111 } |
111 | 112 |
112 // The realm is controlled by the remote server, so there is no reason | |
113 // to believe it is of a reasonable length. | |
114 base::string16 elided_realm; | |
115 gfx::ElideString(base::UTF8ToUTF16(auth_info->realm), 120, &elided_realm); | |
116 | |
117 std::string languages; | 113 std::string languages; |
118 content::WebContents* web_contents = handler->GetWebContentsForLogin(); | 114 content::WebContents* web_contents = handler->GetWebContentsForLogin(); |
119 if (web_contents) { | 115 if (web_contents) { |
120 Profile* profile = | 116 Profile* profile = |
121 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 117 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
122 if (profile) | 118 if (profile) |
123 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 119 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
124 } | 120 } |
125 | 121 |
126 base::string16 authority = | 122 base::string16 authority = l10n_util::GetStringFUTF16( |
127 url_formatter::FormatUrlForSecurityDisplay(request_url, languages); | 123 auth_info->is_proxy ? IDS_LOGIN_DIALOG_PROXY_AUTHORITY |
| 124 : IDS_LOGIN_DIALOG_AUTHORITY, |
| 125 url_formatter::FormatUrlForSecurityDisplay(request_url, languages)); |
128 base::string16 explanation; | 126 base::string16 explanation; |
129 if (auth_info->is_proxy) { | 127 if (!content::IsOriginSecure(request_url)) { |
130 explanation = elided_realm.empty() | 128 explanation = |
131 ? l10n_util::GetStringFUTF16( | 129 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_NON_SECURE_TRANSPORT); |
132 IDS_LOGIN_DIALOG_DESCRIPTION_PROXY_NO_REALM, authority) | |
133 : l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION_PROXY, | |
134 authority, elided_realm); | |
135 } else { | |
136 explanation = elided_realm.empty() | |
137 ? l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION_NO_REALM, | |
138 authority) | |
139 : l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION, authority, | |
140 elided_realm); | |
141 } | 130 } |
142 | 131 |
143 password_manager::PasswordManager* password_manager = | 132 password_manager::PasswordManager* password_manager = |
144 handler->GetPasswordManagerForLogin(); | 133 handler->GetPasswordManagerForLogin(); |
145 | 134 |
146 if (!password_manager) { | 135 if (!password_manager) { |
147 #if defined(ENABLE_EXTENSIONS) | 136 #if defined(ENABLE_EXTENSIONS) |
148 // A WebContents in a <webview> (a GuestView type) does not have a password | 137 // A WebContents in a <webview> (a GuestView type) does not have a password |
149 // manager, but still needs to be able to show login prompts. | 138 // manager, but still needs to be able to show login prompts. |
150 if (guest_view::GuestViewBase::FromWebContents(parent_contents)) { | 139 if (guest_view::GuestViewBase::FromWebContents(parent_contents)) { |
151 handler->BuildViewWithoutPasswordManager(explanation); | 140 handler->BuildViewWithoutPasswordManager(authority, explanation); |
152 return; | 141 return; |
153 } | 142 } |
154 #endif | 143 #endif |
155 handler->CancelAuth(); | 144 handler->CancelAuth(); |
156 return; | 145 return; |
157 } | 146 } |
158 | 147 |
159 if (password_manager && | 148 if (password_manager && |
160 password_manager->client()->GetLogManager()->IsLoggingActive()) { | 149 password_manager->client()->GetLogManager()->IsLoggingActive()) { |
161 password_manager::BrowserSavePasswordProgressLogger logger( | 150 password_manager::BrowserSavePasswordProgressLogger logger( |
162 password_manager->client()->GetLogManager()); | 151 password_manager->client()->GetLogManager()); |
163 logger.LogMessage( | 152 logger.LogMessage( |
164 autofill::SavePasswordProgressLogger::STRING_SHOW_LOGIN_PROMPT_METHOD); | 153 autofill::SavePasswordProgressLogger::STRING_SHOW_LOGIN_PROMPT_METHOD); |
165 } | 154 } |
166 | 155 |
167 PasswordForm observed_form( | 156 PasswordForm observed_form( |
168 MakeInputForPasswordManager(request_url, auth_info)); | 157 MakeInputForPasswordManager(request_url, auth_info)); |
169 handler->BuildViewWithPasswordManager(explanation, password_manager, | 158 handler->BuildViewWithPasswordManager(authority, explanation, |
170 observed_form); | 159 password_manager, observed_form); |
171 } | 160 } |
172 | 161 |
173 } // namespace | 162 } // namespace |
174 | 163 |
175 // ---------------------------------------------------------------------------- | 164 // ---------------------------------------------------------------------------- |
176 // LoginHandler | 165 // LoginHandler |
177 | 166 |
178 LoginHandler::LoginModelData::LoginModelData( | 167 LoginHandler::LoginModelData::LoginModelData( |
179 password_manager::LoginModel* login_model, | 168 password_manager::LoginModel* login_model, |
180 const autofill::PasswordForm& observed_form) | 169 const autofill::PasswordForm& observed_form) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 // Reference is no longer valid. | 205 // Reference is no longer valid. |
217 request_ = NULL; | 206 request_ = NULL; |
218 | 207 |
219 // Give up on auth if the request was cancelled. Since the dialog was canceled | 208 // Give up on auth if the request was cancelled. Since the dialog was canceled |
220 // by the ResourceLoader and not the user, we should cancel the navigation as | 209 // by the ResourceLoader and not the user, we should cancel the navigation as |
221 // well. This can happen when a new navigation interrupts the current one. | 210 // well. This can happen when a new navigation interrupts the current one. |
222 DoCancelAuth(true); | 211 DoCancelAuth(true); |
223 } | 212 } |
224 | 213 |
225 void LoginHandler::BuildViewWithPasswordManager( | 214 void LoginHandler::BuildViewWithPasswordManager( |
| 215 const base::string16& authority, |
226 const base::string16& explanation, | 216 const base::string16& explanation, |
227 password_manager::PasswordManager* password_manager, | 217 password_manager::PasswordManager* password_manager, |
228 const autofill::PasswordForm& observed_form) { | 218 const autofill::PasswordForm& observed_form) { |
229 password_manager_ = password_manager; | 219 password_manager_ = password_manager; |
230 password_form_ = observed_form; | 220 password_form_ = observed_form; |
231 LoginHandler::LoginModelData model_data(password_manager, observed_form); | 221 LoginHandler::LoginModelData model_data(password_manager, observed_form); |
232 BuildViewImpl(explanation, &model_data); | 222 BuildViewImpl(authority, explanation, &model_data); |
233 } | 223 } |
234 | 224 |
235 void LoginHandler::BuildViewWithoutPasswordManager( | 225 void LoginHandler::BuildViewWithoutPasswordManager( |
| 226 const base::string16& authority, |
236 const base::string16& explanation) { | 227 const base::string16& explanation) { |
237 BuildViewImpl(explanation, nullptr); | 228 BuildViewImpl(authority, explanation, nullptr); |
238 } | 229 } |
239 | 230 |
240 WebContents* LoginHandler::GetWebContentsForLogin() const { | 231 WebContents* LoginHandler::GetWebContentsForLogin() const { |
241 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 232 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
242 | 233 |
243 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID( | 234 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID( |
244 render_process_host_id_, render_frame_id_); | 235 render_process_host_id_, render_frame_id_); |
245 return WebContents::FromRenderFrameHost(rfh); | 236 return WebContents::FromRenderFrameHost(rfh); |
246 } | 237 } |
247 | 238 |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 signon_realm = auth_info.challenger.ToString(); | 606 signon_realm = auth_info.challenger.ToString(); |
616 signon_realm.append("/"); | 607 signon_realm.append("/"); |
617 } else { | 608 } else { |
618 // Take scheme, host, and port from the url. | 609 // Take scheme, host, and port from the url. |
619 signon_realm = url.GetOrigin().spec(); | 610 signon_realm = url.GetOrigin().spec(); |
620 // This ends with a "/". | 611 // This ends with a "/". |
621 } | 612 } |
622 signon_realm.append(auth_info.realm); | 613 signon_realm.append(auth_info.realm); |
623 return signon_realm; | 614 return signon_realm; |
624 } | 615 } |
OLD | NEW |