Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / android / login_prompt_android.cc
blob7f478bf011463d244566bd656eda56b6c559b34f
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/android/window_android.h"
19 using content::BrowserThread;
20 using net::URLRequest;
21 using net::AuthChallengeInfo;
23 class LoginHandlerAndroid : public LoginHandler {
24 public:
25 LoginHandlerAndroid(AuthChallengeInfo* auth_info, URLRequest* request)
26 : LoginHandler(auth_info, request) {
29 // LoginHandler methods:
31 void OnAutofillDataAvailable(const base::string16& username,
32 const base::string16& password) override {
33 DCHECK_CURRENTLY_ON(BrowserThread::UI);
34 DCHECK(chrome_http_auth_handler_.get() != NULL);
35 chrome_http_auth_handler_->OnAutofillDataAvailable(
36 username, password);
38 void OnLoginModelDestroying() override {}
40 void BuildViewForPasswordManager(password_manager::PasswordManager* manager,
41 const base::string16& explanation) override {
42 DCHECK_CURRENTLY_ON(BrowserThread::UI);
44 // Get pointer to TabAndroid
45 content::WebContents* web_contents = GetWebContentsForLogin();
46 CHECK(web_contents);
47 WindowAndroidHelper* window_helper = WindowAndroidHelper::FromWebContents(
48 web_contents);
50 // Notify WindowAndroid that HTTP authentication is required.
51 if (window_helper->GetWindowAndroid()) {
52 chrome_http_auth_handler_.reset(new ChromeHttpAuthHandler(explanation));
53 chrome_http_auth_handler_->Init();
54 chrome_http_auth_handler_->SetObserver(this);
55 chrome_http_auth_handler_->ShowDialog(
56 window_helper->GetWindowAndroid()->GetJavaObject().obj());
58 // Register to receive a callback to OnAutofillDataAvailable().
59 SetModel(manager);
60 NotifyAuthNeeded();
61 } else {
62 CancelAuth();
63 LOG(WARNING) << "HTTP Authentication failed because TabAndroid is "
64 "missing";
68 protected:
69 ~LoginHandlerAndroid() override {}
71 void CloseDialog() override {}
73 private:
74 scoped_ptr<ChromeHttpAuthHandler> chrome_http_auth_handler_;
77 // static
78 LoginHandler* LoginHandler::Create(net::AuthChallengeInfo* auth_info,
79 net::URLRequest* request) {
80 return new LoginHandlerAndroid(auth_info, request);