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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/login/login_prompt.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/ui/android/chrome_http_auth_handler.h"
12 #include "chrome/browser/ui/android/window_android_helper.h"
13 #include "chrome/browser/ui/login/login_prompt.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/web_contents.h"
16 #include "net/base/auth.h"
17 #include "ui/base/android/window_android.h"
19 using content::BrowserThread
;
20 using net::URLRequest
;
21 using net::AuthChallengeInfo
;
23 class LoginHandlerAndroid
: public LoginHandler
{
25 LoginHandlerAndroid(AuthChallengeInfo
* auth_info
, URLRequest
* request
)
26 : LoginHandler(auth_info
, request
) {
29 // LoginHandler methods:
31 virtual void OnAutofillDataAvailable(
32 const base::string16
& username
,
33 const base::string16
& password
) override
{
34 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
35 DCHECK(chrome_http_auth_handler_
.get() != NULL
);
36 chrome_http_auth_handler_
->OnAutofillDataAvailable(
39 virtual void OnLoginModelDestroying() override
{}
41 virtual void BuildViewForPasswordManager(
42 password_manager::PasswordManager
* manager
,
43 const base::string16
& explanation
) override
{
44 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
46 // Get pointer to TabAndroid
47 content::WebContents
* web_contents
= GetWebContentsForLogin();
49 WindowAndroidHelper
* window_helper
= WindowAndroidHelper::FromWebContents(
52 // Notify WindowAndroid that HTTP authentication is required.
53 if (window_helper
->GetWindowAndroid()) {
54 chrome_http_auth_handler_
.reset(new ChromeHttpAuthHandler(explanation
));
55 chrome_http_auth_handler_
->Init();
56 chrome_http_auth_handler_
->SetObserver(this);
57 chrome_http_auth_handler_
->ShowDialog(
58 window_helper
->GetWindowAndroid()->GetJavaObject().obj());
60 // Register to receive a callback to OnAutofillDataAvailable().
65 LOG(WARNING
) << "HTTP Authentication failed because TabAndroid is "
71 virtual ~LoginHandlerAndroid() {}
73 virtual void CloseDialog() override
{}
76 scoped_ptr
<ChromeHttpAuthHandler
> chrome_http_auth_handler_
;
80 LoginHandler
* LoginHandler::Create(net::AuthChallengeInfo
* auth_info
,
81 net::URLRequest
* request
) {
82 return new LoginHandlerAndroid(auth_info
, request
);