| 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_handler.h" | 5 #include "chrome/browser/ui/login/login_handler.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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 password_manager_(NULL), | 109 password_manager_(NULL), |
| 110 login_model_(NULL) { | 110 login_model_(NULL) { |
| 111 // This constructor is called on the I/O thread, so we cannot load the nib | 111 // This constructor is called on the I/O thread, so we cannot load the nib |
| 112 // here. BuildViewImpl() will be invoked on the UI thread later, so wait with | 112 // here. BuildViewImpl() will be invoked on the UI thread later, so wait with |
| 113 // loading the nib until then. | 113 // loading the nib until then. |
| 114 DCHECK(request_) << "LoginHandler constructed with NULL request"; | 114 DCHECK(request_) << "LoginHandler constructed with NULL request"; |
| 115 DCHECK(auth_info_.get()) << "LoginHandler constructed with NULL auth info"; | 115 DCHECK(auth_info_.get()) << "LoginHandler constructed with NULL auth info"; |
| 116 | 116 |
| 117 AddRef(); // matched by LoginHandler::ReleaseSoon(). | 117 AddRef(); // matched by LoginHandler::ReleaseSoon(). |
| 118 | 118 |
| 119 BrowserThread::PostTask( | |
| 120 BrowserThread::UI, FROM_HERE, | |
| 121 base::Bind(&LoginHandler::AddObservers, this)); | |
| 122 | |
| 123 const content::ResourceRequestInfo* info = | 119 const content::ResourceRequestInfo* info = |
| 124 ResourceRequestInfo::ForRequest(request); | 120 ResourceRequestInfo::ForRequest(request); |
| 125 DCHECK(info); | 121 DCHECK(info); |
| 126 web_contents_getter_ = info->GetWebContentsGetterForRequest(); | 122 web_contents_getter_ = info->GetWebContentsGetterForRequest(); |
| 123 |
| 124 BrowserThread::PostTask( |
| 125 BrowserThread::UI, FROM_HERE, |
| 126 base::Bind(&LoginHandler::AddObservers, this)); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void LoginHandler::OnRequestCancelled() { | 129 void LoginHandler::OnRequestCancelled() { |
| 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) << | 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) << |
| 131 "Why is OnRequestCancelled called from the UI thread?"; | 131 "Why is OnRequestCancelled called from the UI thread?"; |
| 132 | 132 |
| 133 // Reference is no longer valid. | 133 // Reference is no longer valid. |
| 134 request_ = NULL; | 134 request_ = NULL; |
| 135 | 135 |
| 136 // Give up on auth if the request was cancelled. Since the dialog was canceled | 136 // Give up on auth if the request was cancelled. Since the dialog was canceled |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 331 |
| 332 // This is probably OK; we need to listen to everything and we break out of | 332 // This is probably OK; we need to listen to everything and we break out of |
| 333 // the Observe() if we aren't handling the same auth_info(). | 333 // the Observe() if we aren't handling the same auth_info(). |
| 334 registrar_.reset(new content::NotificationRegistrar); | 334 registrar_.reset(new content::NotificationRegistrar); |
| 335 registrar_->Add(this, chrome::NOTIFICATION_AUTH_SUPPLIED, | 335 registrar_->Add(this, chrome::NOTIFICATION_AUTH_SUPPLIED, |
| 336 content::NotificationService::AllBrowserContextsAndSources()); | 336 content::NotificationService::AllBrowserContextsAndSources()); |
| 337 registrar_->Add(this, chrome::NOTIFICATION_AUTH_CANCELLED, | 337 registrar_->Add(this, chrome::NOTIFICATION_AUTH_CANCELLED, |
| 338 content::NotificationService::AllBrowserContextsAndSources()); | 338 content::NotificationService::AllBrowserContextsAndSources()); |
| 339 | 339 |
| 340 #if !defined(OS_ANDROID) | 340 #if !defined(OS_ANDROID) |
| 341 dialog_helper_.reset(new AppModalDialogHelper(GetWebContentsForLogin())); | 341 WebContents* requesting_contents = GetWebContentsForLogin(); |
| 342 if (requesting_contents) |
| 343 dialog_helper_.reset(new AppModalDialogHelper(requesting_contents)); |
| 342 #endif | 344 #endif |
| 343 } | 345 } |
| 344 | 346 |
| 345 void LoginHandler::RemoveObservers() { | 347 void LoginHandler::RemoveObservers() { |
| 346 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 348 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 347 | 349 |
| 348 registrar_.reset(); | 350 registrar_.reset(); |
| 349 } | 351 } |
| 350 | 352 |
| 351 void LoginHandler::NotifyAuthSupplied(const base::string16& username, | 353 void LoginHandler::NotifyAuthSupplied(const base::string16& username, |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 bool is_main_frame = | 659 bool is_main_frame = |
| 658 (request->load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0; | 660 (request->load_flags() & net::LOAD_MAIN_FRAME_DEPRECATED) != 0; |
| 659 LoginHandler* handler = LoginHandler::Create(auth_info, request); | 661 LoginHandler* handler = LoginHandler::Create(auth_info, request); |
| 660 BrowserThread::PostTask( | 662 BrowserThread::PostTask( |
| 661 BrowserThread::UI, FROM_HERE, | 663 BrowserThread::UI, FROM_HERE, |
| 662 base::Bind(&LoginHandler::LoginDialogCallback, request->url(), | 664 base::Bind(&LoginHandler::LoginDialogCallback, request->url(), |
| 663 base::RetainedRef(auth_info), base::RetainedRef(handler), | 665 base::RetainedRef(auth_info), base::RetainedRef(handler), |
| 664 is_main_frame)); | 666 is_main_frame)); |
| 665 return handler; | 667 return handler; |
| 666 } | 668 } |
| OLD | NEW |