1// Copyright 2014 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.
4
5#ifndef CHROME_BROWSER_UI_ANDROID_INFOBARS_AUTO_LOGIN_PROMPTER_H_
6#define CHROME_BROWSER_UI_ANDROID_INFOBARS_AUTO_LOGIN_PROMPTER_H_
7
8#include <string>
9
10#include "base/compiler_specific.h"
11#include "chrome/browser/ui/auto_login_infobar_delegate.h"
12#include "content/public/browser/web_contents_observer.h"
13#include "url/gurl.h"
14
15namespace content {
16class RenderViewHost;
17class WebContents;
18}
19
20namespace net {
21class URLRequest;
22}
23
24// This class displays an infobar that allows the user to automatically login to
25// the currently loaded page with one click.  This is used when the browser
26// detects that the user has navigated to a login page and that there are stored
27// tokens that would allow a one-click login.
28class AutoLoginPrompter : public content::WebContentsObserver {
29 public:
30  typedef AutoLoginInfoBarDelegate::Params Params;
31
32  // Looks for the X-Auto-Login response header in the request, and if found,
33  // tries to display an infobar in the tab contents identified by the
34  // child/route id.
35  static void ShowInfoBarIfPossible(net::URLRequest* request,
36                                    int child_id,
37                                    int route_id);
38
39 private:
40  friend class AutoLoginPrompterTest;
41
42  AutoLoginPrompter(content::WebContents* web_contents,
43                    const Params& params,
44                    const GURL& url);
45
46  virtual ~AutoLoginPrompter();
47
48  static void ShowInfoBarUIThread(Params params,
49                                  const GURL& url,
50                                  int child_id,
51                                  int route_id);
52
53  virtual void DidStopLoading(
54      content::RenderViewHost* render_view_host) OVERRIDE;
55
56  virtual void WebContentsDestroyed() OVERRIDE;
57
58  // Add the infobar to the WebContents, if it's still needed.
59  void AddInfoBarToWebContents();
60
61  const Params params_;
62  const GURL url_;
63  bool infobar_shown_;
64
65  DISALLOW_COPY_AND_ASSIGN(AutoLoginPrompter);
66};
67
68#endif  // CHROME_BROWSER_UI_ANDROID_INFOBARS_AUTO_LOGIN_PROMPTER_H_
69