1// Copyright (c) 2011 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_WEBUI_NTP_NTP_LOGIN_HANDLER_H_
6#define CHROME_BROWSER_UI_WEBUI_NTP_NTP_LOGIN_HANDLER_H_
7
8#include "base/prefs/pref_member.h"
9#include "content/public/browser/notification_observer.h"
10#include "content/public/browser/notification_registrar.h"
11#include "content/public/browser/web_ui_message_handler.h"
12
13class Profile;
14
15// The NTP login handler currently simply displays the current logged in
16// username at the top of the NTP (and update itself when that changes).
17// In the future it may expand to allow users to login from the NTP.
18class NTPLoginHandler : public content::WebUIMessageHandler,
19                        public content::NotificationObserver {
20 public:
21  NTPLoginHandler();
22  virtual ~NTPLoginHandler();
23
24  // WebUIMessageHandler interface
25  virtual void RegisterMessages() OVERRIDE;
26
27  // content::NotificationObserver interface
28  virtual void Observe(int type,
29                       const content::NotificationSource& source,
30                       const content::NotificationDetails& details) OVERRIDE;
31
32  // Returns true if the login handler should be shown in a new tab page
33  // for the given |profile|. |profile| must not be NULL.
34  static bool ShouldShow(Profile* profile);
35
36  // Registers values (strings etc.) for the page.
37  static void GetLocalizedValues(Profile* profile,
38                                 base::DictionaryValue* values);
39
40 private:
41  // User actions while on the NTP when clicking on or viewing the sync promo.
42  enum NTPSignInPromoBuckets {
43    NTP_SIGN_IN_PROMO_VIEWED,
44    NTP_SIGN_IN_PROMO_CLICKED,
45    NTP_SIGN_IN_PROMO_BUCKET_BOUNDARY,
46  };
47
48  // Called from JS when the NTP is loaded. |args| is the list of arguments
49  // passed from JS and should be an empty list.
50  void HandleInitializeSyncLogin(const base::ListValue* args);
51
52  // Called from JS when the user clicks the login container. It shows the
53  // appropriate UI based on the current sync state. |args| is the list of
54  // arguments passed from JS and should be an empty list.
55  void HandleShowSyncLoginUI(const base::ListValue* args);
56
57  // Records actions in SyncPromo.NTPPromo histogram.
58  void RecordInHistogram(int type);
59
60  // Called from JS when the sync promo NTP bubble has been displayed. |args| is
61  // the list of arguments passed from JS and should be an empty list.
62  void HandleLoginMessageSeen(const base::ListValue* args);
63
64  // Called from JS when the user clicks on the advanced link the sync promo NTP
65  // bubble. Use use this to navigate to the sync settings page. |args| is the
66  // list of arguments passed from JS and should be an empty list.
67  void HandleShowAdvancedLoginUI(const base::ListValue* args);
68
69  // Internal helper method
70  void UpdateLogin();
71
72  StringPrefMember username_pref_;
73  BooleanPrefMember signin_allowed_pref_;
74  content::NotificationRegistrar registrar_;
75};
76
77#endif  // CHROME_BROWSER_UI_WEBUI_NTP_NTP_LOGIN_HANDLER_H_
78