one_click_signin_bubble_view.h revision 868fa2fe829687343ffae624259930155e16dbd8
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/strings/string16.h" 13#include "chrome/browser/ui/browser_window.h" 14#include "chrome/browser/ui/views/toolbar_view.h" 15#include "ui/views/bubble/bubble_delegate.h" 16#include "ui/views/controls/button/button.h" 17#include "ui/views/controls/link_listener.h" 18 19namespace base { 20class MessageLoop; 21} 22 23namespace views { 24class GridLayout; 25class LabelButton; 26} 27 28// OneClickSigninBubbleView is a view intended to be used as the content of an 29// Bubble. It provides simple and concise feedback to the user that sync'ing 30// has started after using the one-click singin infobar. 31class OneClickSigninBubbleView : public views::BubbleDelegateView, 32 public views::LinkListener, 33 public views::ButtonListener { 34 public: 35 // Show the one-click signin bubble if not already showing. The bubble 36 // will be placed visually beneath |anchor_view|. |start_sync| is called 37 // to start sync. 38 static void ShowBubble(BrowserWindow::OneClickSigninBubbleType type, 39 const string16& email, 40 const string16& error_message, 41 ToolbarView* toolbar_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 content::WebContents* web_contents, 56 views::View* anchor_view, 57 const string16& error_message, 58 const string16& email, 59 const BrowserWindow::StartSyncCallback& start_sync_callback, 60 bool is_sync_dialog); 61 62 virtual ~OneClickSigninBubbleView(); 63 64 private: 65 friend class OneClickSigninBubbleViewBrowserTest; 66 67 FRIEND_TEST_ALL_PREFIXES( 68 OneClickSigninBubbleViewBrowserTest, BubbleOkButton); 69 FRIEND_TEST_ALL_PREFIXES( 70 OneClickSigninBubbleViewBrowserTest, DialogOkButton); 71 FRIEND_TEST_ALL_PREFIXES( 72 OneClickSigninBubbleViewBrowserTest, DialogUndoButton); 73 FRIEND_TEST_ALL_PREFIXES( 74 OneClickSigninBubbleViewBrowserTest, BubbleAdvancedLink); 75 FRIEND_TEST_ALL_PREFIXES( 76 OneClickSigninBubbleViewBrowserTest, DialogAdvancedLink); 77 FRIEND_TEST_ALL_PREFIXES( 78 OneClickSigninBubbleViewBrowserTest, BubbleLearnMoreLink); 79 FRIEND_TEST_ALL_PREFIXES( 80 OneClickSigninBubbleViewBrowserTest, DialogLearnMoreLink); 81 82 // Overridden from views::BubbleDelegateView: 83 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; 84 virtual void Init() OVERRIDE; 85 86 // Overridden from views::LinkListener: 87 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; 88 89 // Overridden from views::ButtonListener: 90 virtual void ButtonPressed(views::Button* sender, 91 const ui::Event& event) OVERRIDE; 92 93 // Overridden from views::View: 94 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; 95 96 // Overridden from views::WidgetDelegate: 97 virtual void WindowClosing() OVERRIDE; 98 virtual ui::ModalType GetModalType() const OVERRIDE; 99 100 // Builds a popup bubble anchored under the wrench menu 101 void InitBubbleContent(views::GridLayout* layout); 102 103 // Builds a modal dialog aligned center top 104 void InitDialogContent(views::GridLayout* layout); 105 106 // Initializes the OK/Undo buttons to be used at the bottom of the bubble. 107 void InitButtons(views::GridLayout* layout); 108 void GetButtons(views::LabelButton** ok_button, 109 views::LabelButton** undo_button); 110 111 // Creates learn more link to be used at the bottom of the bubble. 112 void InitLearnMoreLink(); 113 114 // Creates advanced link to be used at the bottom of the bubble. 115 void InitAdvancedLink(); 116 117 // The bubble/dialog will always outlive the web_content, so this is ok 118 content::WebContents* web_contents_; 119 120 // Alternate error message to be displayed 121 const string16 error_message_; 122 123 const string16 email_; 124 125 // This callback is nulled once its called, so that it is called only once. 126 // It will be called when the bubble is closed if it has not been called 127 // and nulled earlier. 128 BrowserWindow::StartSyncCallback start_sync_callback_; 129 130 const bool is_sync_dialog_; 131 132 // Link to sync setup advanced page. 133 views::Link* advanced_link_; 134 135 // Link to the Learn More details page 136 views::Link* learn_more_link_; 137 138 // Controls at bottom of bubble. 139 views::LabelButton* ok_button_; 140 views::LabelButton* undo_button_; 141 142 // Close button for the modal dialog 143 views::ImageButton* close_button_; 144 145 bool clicked_learn_more_; 146 147 // A message loop used only with unit tests. 148 base::MessageLoop* message_loop_for_testing_; 149 150 // The bubble, if we're showing one. 151 static OneClickSigninBubbleView* bubble_view_; 152 153 DISALLOW_COPY_AND_ASSIGN(OneClickSigninBubbleView); 154}; 155 156#endif // CHROME_BROWSER_UI_VIEWS_SYNC_ONE_CLICK_SIGNIN_BUBBLE_VIEW_H_ 157