OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/password_manager/password_manager.h" | 13 #include "chrome/browser/password_manager/password_manager.h" |
14 #include "chrome/browser/tab_contents/tab_util.h" | 14 #include "chrome/browser/tab_contents/tab_util.h" |
15 #include "chrome/browser/ui/constrained_window.h" | 15 #include "chrome/browser/ui/constrained_window.h" |
16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
18 #include "content/browser/renderer_host/render_view_host.h" | 18 #include "content/browser/renderer_host/render_view_host.h" |
19 #include "content/browser/renderer_host/render_view_host_delegate.h" | 19 #include "content/browser/renderer_host/render_view_host_delegate.h" |
20 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 20 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
21 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 21 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
22 #include "content/browser/tab_contents/tab_contents.h" | 22 #include "content/browser/tab_contents/tab_contents.h" |
23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
25 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
26 #include "net/base/auth.h" | 26 #include "net/base/auth.h" |
27 #include "net/base/net_util.h" | 27 #include "net/base/net_util.h" |
| 28 #include "net/http/http_transaction_factory.h" |
28 #include "net/url_request/url_request.h" | 29 #include "net/url_request/url_request.h" |
| 30 #include "net/url_request/url_request_context.h" |
29 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
30 #include "ui/base/text/text_elider.h" | 32 #include "ui/base/text/text_elider.h" |
31 | 33 |
32 using content::BrowserThread; | 34 using content::BrowserThread; |
33 using webkit_glue::PasswordForm; | 35 using webkit_glue::PasswordForm; |
34 | 36 |
35 class LoginHandlerImpl; | 37 class LoginHandlerImpl; |
36 | 38 |
37 // Helper to remove the ref from an net::URLRequest to the LoginHandler. | 39 // Helper to remove the ref from an net::URLRequest to the LoginHandler. |
38 // Should only be called from the IO thread, since it accesses an | 40 // Should only be called from the IO thread, since it accesses an |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 74 |
73 // ---------------------------------------------------------------------------- | 75 // ---------------------------------------------------------------------------- |
74 // LoginHandler | 76 // LoginHandler |
75 | 77 |
76 LoginHandler::LoginHandler(net::AuthChallengeInfo* auth_info, | 78 LoginHandler::LoginHandler(net::AuthChallengeInfo* auth_info, |
77 net::URLRequest* request) | 79 net::URLRequest* request) |
78 : handled_auth_(false), | 80 : handled_auth_(false), |
79 dialog_(NULL), | 81 dialog_(NULL), |
80 auth_info_(auth_info), | 82 auth_info_(auth_info), |
81 request_(request), | 83 request_(request), |
| 84 http_network_session_( |
| 85 request_->context()->http_transaction_factory()->GetSession()), |
82 password_manager_(NULL), | 86 password_manager_(NULL), |
83 login_model_(NULL) { | 87 login_model_(NULL) { |
84 // This constructor is called on the I/O thread, so we cannot load the nib | 88 // This constructor is called on the I/O thread, so we cannot load the nib |
85 // here. BuildViewForPasswordManager() will be invoked on the UI thread | 89 // here. BuildViewForPasswordManager() will be invoked on the UI thread |
86 // later, so wait with loading the nib until then. | 90 // later, so wait with loading the nib until then. |
87 DCHECK(request_) << "LoginHandler constructed with NULL request"; | 91 DCHECK(request_) << "LoginHandler constructed with NULL request"; |
88 DCHECK(auth_info_) << "LoginHandler constructed with NULL auth info"; | 92 DCHECK(auth_info_) << "LoginHandler constructed with NULL auth info"; |
89 | 93 |
90 AddRef(); // matched by LoginHandler::ReleaseSoon(). | 94 AddRef(); // matched by LoginHandler::ReleaseSoon(). |
91 | 95 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 content::Details<LoginNotificationDetails>(details).ptr(); | 236 content::Details<LoginNotificationDetails>(details).ptr(); |
233 | 237 |
234 // WasAuthHandled() should always test positive before we publish | 238 // WasAuthHandled() should always test positive before we publish |
235 // AUTH_SUPPLIED or AUTH_CANCELLED notifications. | 239 // AUTH_SUPPLIED or AUTH_CANCELLED notifications. |
236 DCHECK(login_details->handler() != this); | 240 DCHECK(login_details->handler() != this); |
237 | 241 |
238 // Only handle notification for the identical auth info. | 242 // Only handle notification for the identical auth info. |
239 if (!login_details->handler()->auth_info()->Equals(*auth_info())) | 243 if (!login_details->handler()->auth_info()->Equals(*auth_info())) |
240 return; | 244 return; |
241 | 245 |
| 246 // Ignore login notification events from other profiles. |
| 247 if (login_details->handler()->http_network_session_ != |
| 248 http_network_session_) |
| 249 return; |
| 250 |
242 // Set or cancel the auth in this handler. | 251 // Set or cancel the auth in this handler. |
243 if (type == chrome::NOTIFICATION_AUTH_SUPPLIED) { | 252 if (type == chrome::NOTIFICATION_AUTH_SUPPLIED) { |
244 AuthSuppliedLoginNotificationDetails* supplied_details = | 253 AuthSuppliedLoginNotificationDetails* supplied_details = |
245 content::Details<AuthSuppliedLoginNotificationDetails>(details).ptr(); | 254 content::Details<AuthSuppliedLoginNotificationDetails>(details).ptr(); |
246 SetAuth(supplied_details->username(), supplied_details->password()); | 255 SetAuth(supplied_details->username(), supplied_details->password()); |
247 } else { | 256 } else { |
248 DCHECK(type == chrome::NOTIFICATION_AUTH_CANCELLED); | 257 DCHECK(type == chrome::NOTIFICATION_AUTH_CANCELLED); |
249 CancelAuth(); | 258 CancelAuth(); |
250 } | 259 } |
251 } | 260 } |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 // Public API | 499 // Public API |
491 | 500 |
492 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, | 501 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, |
493 net::URLRequest* request) { | 502 net::URLRequest* request) { |
494 LoginHandler* handler = LoginHandler::Create(auth_info, request); | 503 LoginHandler* handler = LoginHandler::Create(auth_info, request); |
495 BrowserThread::PostTask( | 504 BrowserThread::PostTask( |
496 BrowserThread::UI, FROM_HERE, new LoginDialogTask( | 505 BrowserThread::UI, FROM_HERE, new LoginDialogTask( |
497 request->url(), auth_info, handler)); | 506 request->url(), auth_info, handler)); |
498 return handler; | 507 return handler; |
499 } | 508 } |
OLD | NEW |