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