Home | History | Annotate | Download | only in ui
      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.
      4 
      5 #ifndef CHROME_BROWSER_UI_AUTO_LOGIN_PROMPTER_H_
      6 #define CHROME_BROWSER_UI_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 
     15 namespace content {
     16 class RenderViewHost;
     17 class WebContents;
     18 }
     19 
     20 namespace net {
     21 class 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.
     28 class 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(
     57       content::WebContents* web_contents) OVERRIDE;
     58 
     59   // Add the infobar to the WebContents, if it's still needed.
     60   void AddInfoBarToWebContents();
     61 
     62   const Params params_;
     63   const GURL url_;
     64   bool infobar_shown_;
     65 
     66   DISALLOW_COPY_AND_ASSIGN(AutoLoginPrompter);
     67 };
     68 
     69 #endif  // CHROME_BROWSER_UI_AUTO_LOGIN_PROMPTER_H_
     70