OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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/login_prompt.h" | 5 #include "chrome/browser/login_prompt.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/common/notification_service.h" | 23 #include "chrome/common/notification_service.h" |
24 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
25 #include "net/base/auth.h" | 25 #include "net/base/auth.h" |
26 #include "net/base/net_util.h" | 26 #include "net/base/net_util.h" |
27 #include "net/url_request/url_request.h" | 27 #include "net/url_request/url_request.h" |
28 | 28 |
29 using webkit_glue::PasswordForm; | 29 using webkit_glue::PasswordForm; |
30 | 30 |
31 class LoginHandlerImpl; | 31 class LoginHandlerImpl; |
32 | 32 |
33 // Helper to remove the ref from an URLRequest to the LoginHandler. | 33 // Helper to remove the ref from an net::URLRequest to the LoginHandler. |
34 // Should only be called from the IO thread, since it accesses an URLRequest. | 34 // Should only be called from the IO thread, since it accesses an |
35 void ResetLoginHandlerForRequest(URLRequest* request) { | 35 // net::URLRequest. |
| 36 void ResetLoginHandlerForRequest(net::URLRequest* request) { |
36 ResourceDispatcherHostRequestInfo* info = | 37 ResourceDispatcherHostRequestInfo* info = |
37 ResourceDispatcherHost::InfoForRequest(request); | 38 ResourceDispatcherHost::InfoForRequest(request); |
38 if (!info) | 39 if (!info) |
39 return; | 40 return; |
40 | 41 |
41 info->set_login_handler(NULL); | 42 info->set_login_handler(NULL); |
42 } | 43 } |
43 | 44 |
44 // Get the signon_realm under which this auth info should be stored. | 45 // Get the signon_realm under which this auth info should be stored. |
45 // | 46 // |
(...skipping 16 matching lines...) Expand all Loading... |
62 // This ends with a "/". | 63 // This ends with a "/". |
63 } | 64 } |
64 signon_realm.append(WideToUTF8(auth_info.realm)); | 65 signon_realm.append(WideToUTF8(auth_info.realm)); |
65 return signon_realm; | 66 return signon_realm; |
66 } | 67 } |
67 | 68 |
68 // ---------------------------------------------------------------------------- | 69 // ---------------------------------------------------------------------------- |
69 // LoginHandler | 70 // LoginHandler |
70 | 71 |
71 LoginHandler::LoginHandler(net::AuthChallengeInfo* auth_info, | 72 LoginHandler::LoginHandler(net::AuthChallengeInfo* auth_info, |
72 URLRequest* request) | 73 net::URLRequest* request) |
73 : handled_auth_(false), | 74 : handled_auth_(false), |
74 dialog_(NULL), | 75 dialog_(NULL), |
75 auth_info_(auth_info), | 76 auth_info_(auth_info), |
76 request_(request), | 77 request_(request), |
77 password_manager_(NULL), | 78 password_manager_(NULL), |
78 login_model_(NULL) { | 79 login_model_(NULL) { |
79 // This constructor is called on the I/O thread, so we cannot load the nib | 80 // This constructor is called on the I/O thread, so we cannot load the nib |
80 // here. BuildViewForPasswordManager() will be invoked on the UI thread | 81 // here. BuildViewForPasswordManager() will be invoked on the UI thread |
81 // later, so wait with loading the nib until then. | 82 // later, so wait with loading the nib until then. |
82 DCHECK(request_) << "LoginHandler constructed with NULL request"; | 83 DCHECK(request_) << "LoginHandler constructed with NULL request"; |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 // The hosting ConstrainedWindow may have been freed. | 345 // The hosting ConstrainedWindow may have been freed. |
345 if (dialog_) | 346 if (dialog_) |
346 dialog_->CloseConstrainedWindow(); | 347 dialog_->CloseConstrainedWindow(); |
347 } | 348 } |
348 | 349 |
349 // ---------------------------------------------------------------------------- | 350 // ---------------------------------------------------------------------------- |
350 // LoginDialogTask | 351 // LoginDialogTask |
351 | 352 |
352 // This task is run on the UI thread and creates a constrained window with | 353 // This task is run on the UI thread and creates a constrained window with |
353 // a LoginView to prompt the user. The response will be sent to LoginHandler, | 354 // a LoginView to prompt the user. The response will be sent to LoginHandler, |
354 // which then routes it to the URLRequest on the I/O thread. | 355 // which then routes it to the net::URLRequest on the I/O thread. |
355 class LoginDialogTask : public Task { | 356 class LoginDialogTask : public Task { |
356 public: | 357 public: |
357 LoginDialogTask(const GURL& request_url, | 358 LoginDialogTask(const GURL& request_url, |
358 net::AuthChallengeInfo* auth_info, | 359 net::AuthChallengeInfo* auth_info, |
359 LoginHandler* handler) | 360 LoginHandler* handler) |
360 : request_url_(request_url), auth_info_(auth_info), handler_(handler) { | 361 : request_url_(request_url), auth_info_(auth_info), handler_(handler) { |
361 } | 362 } |
362 virtual ~LoginDialogTask() { | 363 virtual ~LoginDialogTask() { |
363 } | 364 } |
364 | 365 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 NOTREACHED(); // crbug.com/32718 | 420 NOTREACHED(); // crbug.com/32718 |
420 } else { | 421 } else { |
421 dialog_form.origin = GURL(request_url_.scheme() + "://" + host_and_port); | 422 dialog_form.origin = GURL(request_url_.scheme() + "://" + host_and_port); |
422 } | 423 } |
423 dialog_form.signon_realm = GetSignonRealm(dialog_form.origin, *auth_info_); | 424 dialog_form.signon_realm = GetSignonRealm(dialog_form.origin, *auth_info_); |
424 password_manager_input->push_back(dialog_form); | 425 password_manager_input->push_back(dialog_form); |
425 // Set the password form for the handler (by copy). | 426 // Set the password form for the handler (by copy). |
426 handler_->SetPasswordForm(dialog_form); | 427 handler_->SetPasswordForm(dialog_form); |
427 } | 428 } |
428 | 429 |
429 // The url from the URLRequest initiating the auth challenge. | 430 // The url from the net::URLRequest initiating the auth challenge. |
430 GURL request_url_; | 431 GURL request_url_; |
431 | 432 |
432 // Info about who/where/what is asking for authentication. | 433 // Info about who/where/what is asking for authentication. |
433 scoped_refptr<net::AuthChallengeInfo> auth_info_; | 434 scoped_refptr<net::AuthChallengeInfo> auth_info_; |
434 | 435 |
435 // Where to send the authentication when obtained. | 436 // Where to send the authentication when obtained. |
436 // This is owned by the ResourceDispatcherHost that invoked us. | 437 // This is owned by the ResourceDispatcherHost that invoked us. |
437 LoginHandler* handler_; | 438 LoginHandler* handler_; |
438 | 439 |
439 DISALLOW_COPY_AND_ASSIGN(LoginDialogTask); | 440 DISALLOW_COPY_AND_ASSIGN(LoginDialogTask); |
440 }; | 441 }; |
441 | 442 |
442 // ---------------------------------------------------------------------------- | 443 // ---------------------------------------------------------------------------- |
443 // Public API | 444 // Public API |
444 | 445 |
445 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, | 446 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, |
446 URLRequest* request) { | 447 net::URLRequest* request) { |
447 LoginHandler* handler = LoginHandler::Create(auth_info, request); | 448 LoginHandler* handler = LoginHandler::Create(auth_info, request); |
448 BrowserThread::PostTask( | 449 BrowserThread::PostTask( |
449 BrowserThread::UI, FROM_HERE, new LoginDialogTask( | 450 BrowserThread::UI, FROM_HERE, new LoginDialogTask( |
450 request->url(), auth_info, handler)); | 451 request->url(), auth_info, handler)); |
451 return handler; | 452 return handler; |
452 } | 453 } |
OLD | NEW |