one_click_signin_bubble_view.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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_VIEWS_SYNC_ONE_CLICK_SIGNIN_BUBBLE_VIEW_H_
6#define CHROME_BROWSER_UI_VIEWS_SYNC_ONE_CLICK_SIGNIN_BUBBLE_VIEW_H_
7
8#include "base/basictypes.h"
9#include "base/callback.h"
10#include "base/compiler_specific.h"
11#include "base/gtest_prod_util.h"
12#include "base/memory/scoped_ptr.h"
13#include "base/strings/string16.h"
14#include "chrome/browser/ui/browser_window.h"
15#include "chrome/browser/ui/sync/one_click_signin_bubble_delegate.h"
16#include "ui/views/bubble/bubble_delegate.h"
17#include "ui/views/controls/button/button.h"
18#include "ui/views/controls/link_listener.h"
19
20namespace views {
21class GridLayout;
22class ImageButton;
23class LabelButton;
24class View;
25}
26
27// OneClickSigninBubbleView is a view intended to be used as the content of an
28// Bubble. It provides simple and concise feedback to the user that sync'ing
29// has started after using the one-click singin infobar.
30class OneClickSigninBubbleView : public views::BubbleDelegateView,
31                                 public views::LinkListener,
32                                 public views::ButtonListener {
33 public:
34  // Show the one-click signin bubble if not already showing.  The bubble
35  // will be placed visually beneath |anchor_view|.  |start_sync| is called
36  // to start sync.
37  static void ShowBubble(BrowserWindow::OneClickSigninBubbleType type,
38                         const base::string16& email,
39                         const base::string16& error_message,
40                         scoped_ptr<OneClickSigninBubbleDelegate> delegate,
41                         views::View* anchor_view,
42                         const BrowserWindow::StartSyncCallback& start_sync);
43
44  static bool IsShowing();
45
46  static void Hide();
47
48  // Gets the global bubble view.  If its not showing returns NULL.  This
49  // method is meant to be called only from tests.
50  static OneClickSigninBubbleView* view_for_testing() { return bubble_view_; }
51
52 protected:
53  // Creates a OneClickSigninBubbleView.
54  OneClickSigninBubbleView(
55      const base::string16& error_message,
56      const base::string16& email,
57      scoped_ptr<OneClickSigninBubbleDelegate> delegate,
58      views::View* anchor_view,
59      const BrowserWindow::StartSyncCallback& start_sync_callback,
60      bool is_sync_dialog);
61
62  virtual ~OneClickSigninBubbleView();
63
64 private:
65  friend class OneClickSigninBubbleViewTest;
66
67  FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewTest, BubbleOkButton);
68  FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewTest, DialogOkButton);
69  FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewTest, DialogUndoButton);
70  FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewTest, BubbleAdvancedLink);
71  FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewTest, DialogAdvancedLink);
72  FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewTest, BubbleLearnMoreLink);
73  FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewTest, DialogLearnMoreLink);
74
75  // Overridden from views::BubbleDelegateView:
76  virtual void Init() OVERRIDE;
77
78  // Overridden from views::LinkListener:
79  virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
80
81  // Overridden from views::ButtonListener:
82  virtual void ButtonPressed(views::Button* sender,
83                             const ui::Event& event) OVERRIDE;
84
85  // Overridden from views::View:
86  virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
87
88  // Overridden from views::WidgetDelegate:
89  virtual void WindowClosing() OVERRIDE;
90  virtual ui::ModalType GetModalType() const OVERRIDE;
91
92  // Builds a popup bubble anchored under the wrench menu
93  void InitBubbleContent(views::GridLayout* layout);
94
95  // Builds a modal dialog aligned center top
96  void InitDialogContent(views::GridLayout* layout);
97
98  // Initializes the OK/Undo buttons to be used at the bottom of the bubble.
99  void InitButtons(views::GridLayout* layout);
100  void GetButtons(views::LabelButton** ok_button,
101                          views::LabelButton** undo_button);
102
103  // Creates learn more link to be used at the bottom of the bubble.
104  void InitLearnMoreLink();
105
106  // Creates advanced link to be used at the bottom of the bubble.
107  void InitAdvancedLink();
108
109  // Delegate to handle clicking on links in the bubble.
110  scoped_ptr<OneClickSigninBubbleDelegate> delegate_;
111
112  // Alternate error message to be displayed.
113  const base::string16 error_message_;
114
115  // The user's email address to be used for sync.
116  const base::string16 email_;
117
118  // This callback is nulled once its called, so that it is called only once.
119  // It will be called when the bubble is closed if it has not been called
120  // and nulled earlier.
121  BrowserWindow::StartSyncCallback start_sync_callback_;
122
123  const bool is_sync_dialog_;
124
125  // Link to sync setup advanced page.
126  views::Link* advanced_link_;
127
128  // Link to the Learn More details page
129  views::Link* learn_more_link_;
130
131  // Controls at bottom of bubble.
132  views::LabelButton* ok_button_;
133  views::LabelButton* undo_button_;
134
135  // Close button for the modal dialog
136  views::ImageButton* close_button_;
137
138  bool clicked_learn_more_;
139
140  // The bubble, if we're showing one.
141  static OneClickSigninBubbleView* bubble_view_;
142
143  DISALLOW_COPY_AND_ASSIGN(OneClickSigninBubbleView);
144};
145
146#endif  // CHROME_BROWSER_UI_VIEWS_SYNC_ONE_CLICK_SIGNIN_BUBBLE_VIEW_H_
147