Disable TabDragController tests that fail with a real compositor.
[chromium-blink-merge.git] / chrome / browser / ui / android / login_prompt_android.cc
blob8dd465b7815e59f7d3acb83407a91b2cc84d55f1
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/android/tab_android.h"
12 #include "chrome/browser/ui/android/chrome_http_auth_handler.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"
18 using content::BrowserThread;
19 using net::URLRequest;
20 using net::AuthChallengeInfo;
22 class LoginHandlerAndroid : public LoginHandler {
23 public:
24 LoginHandlerAndroid(AuthChallengeInfo* auth_info, URLRequest* request)
25 : LoginHandler(auth_info, request) {
28 // LoginHandler methods:
30 virtual void OnAutofillDataAvailable(
31 const base::string16& username,
32 const base::string16& password) OVERRIDE {
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
34 DCHECK(chrome_http_auth_handler_.get() != NULL);
35 chrome_http_auth_handler_->OnAutofillDataAvailable(
36 username, password);
38 virtual void OnLoginModelDestroying() OVERRIDE {}
40 virtual void BuildViewForPasswordManager(
41 PasswordManager* manager,
42 const base::string16& explanation) OVERRIDE {
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
45 // Get pointer to TabAndroid
46 content::WebContents* web_contents = GetWebContentsForLogin();
47 CHECK(web_contents);
48 TabAndroid* tab_android = TabAndroid::FromWebContents(web_contents);
50 // Notify TabAndroid that HTTP authentication is required for current page.
51 if (tab_android) {
52 chrome_http_auth_handler_.reset(new ChromeHttpAuthHandler(explanation));
53 chrome_http_auth_handler_->Init();
54 chrome_http_auth_handler_->SetObserver(this);
56 tab_android->OnReceivedHttpAuthRequest(
57 chrome_http_auth_handler_.get()->GetJavaObject(),
58 base::ASCIIToUTF16(auth_info()->challenger.ToString()),
59 base::UTF8ToUTF16(auth_info()->realm));
61 // Register to receive a callback to OnAutofillDataAvailable().
62 SetModel(manager);
63 NotifyAuthNeeded();
64 } else {
65 CancelAuth();
66 LOG(WARNING) << "HTTP Authentication failed because TabAndroid is "
67 "missing";
71 protected:
72 virtual ~LoginHandlerAndroid() {}
74 virtual void CloseDialog() OVERRIDE {}
76 private:
77 scoped_ptr<ChromeHttpAuthHandler> chrome_http_auth_handler_;
80 // static
81 LoginHandler* LoginHandler::Create(net::AuthChallengeInfo* auth_info,
82 net::URLRequest* request) {
83 return new LoginHandlerAndroid(auth_info, request);