15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/gtk/one_click_signin_bubble_gtk.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <gtk/gtk.h> 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/callback_helpers.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/i18n/rtl.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h" 129ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch#include "base/message_loop/message_loop.h" 13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_finder.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/gtk/browser_window_gtk.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/gtk/gtk_theme_service.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/gtk/gtk_util.h" 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/gtk/tabs/tab_strip_gtk.h" 21c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/ui/sync/one_click_signin_helper.h" 22c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/ui/sync/one_click_signin_histogram.h" 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/url_constants.h" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "grit/chromium_strings.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "grit/generated_resources.h" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/gtk/gtk_hig_constants.h" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h" 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)static const int kModalDialogMessageWidth = 400; 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)OneClickSigninBubbleGtk::OneClickSigninBubbleGtk( 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BrowserWindowGtk* browser_window_gtk, 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BrowserWindow::OneClickSigninBubbleType type, 34a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16& email, 35a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16& error_message, 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const BrowserWindow::StartSyncCallback& start_sync_callback) 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : bubble_(NULL), 38c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) email_(email), 39c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) error_message_(error_message), 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) start_sync_callback_(start_sync_callback), 41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) is_sync_dialog_(type!=BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE), 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) message_label_(NULL), 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) advanced_link_(NULL), 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ok_button_(NULL), 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) undo_button_(NULL), 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) learn_more_(NULL), 47c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) header_label_(NULL), 48c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) clicked_learn_more_(false) { 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InitializeWidgets(browser_window_gtk); 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ShowWidget(browser_window_gtk, LayoutWidgets()); 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void OneClickSigninBubbleGtk::BubbleClosing( 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BubbleGtk* bubble, bool closed_by_escape) { 553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // If we get here and |start_sync_callback_| is not null, act like this is 563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // an undo. All actions that start sign in are explicitly handled below. 57c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (is_sync_dialog_ && !start_sync_callback_.is_null()) { 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::ResetAndReturn(&start_sync_callback_).Run( 593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) OneClickSigninSyncStarter::UNDO_SYNC); 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The bubble needs to close and remove the widgets from the window before 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |close_button_| (which is a CustomDrawButton) can be destroyed, because it 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // depends on all references being cleared for the GtkWidget before it is 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // destroyed. 66b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) base::MessageLoopForUI::current()->DeleteSoon(FROM_HERE, 67b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) close_button_.release()); 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delete this; 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void OneClickSigninBubbleGtk::OnClickAdvancedLink(GtkWidget* link) { 73c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (is_sync_dialog_) { 74c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) OneClickSigninHelper::LogConfirmHistogramValue( 75c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) clicked_learn_more_ ? 76c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE_ADVANCED : 77c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) one_click_signin::HISTOGRAM_CONFIRM_ADVANCED); 78c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 79c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::ResetAndReturn(&start_sync_callback_).Run( 803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); 81c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } else { 82c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) Browser* browser = chrome::FindBrowserWithWindow( 83c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) gtk_window_get_transient_for(bubble_->GetNativeWindow())); 84c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(browser); 85c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) chrome::NavigateParams params(browser, GURL(chrome::kChromeUISettingsURL), 86c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) content::PAGE_TRANSITION_LINK); 87c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) params.disposition = CURRENT_TAB; 88c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) chrome::Navigate(¶ms); 89c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bubble_->Close(); 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void OneClickSigninBubbleGtk::OnClickOK(GtkWidget* link) { 94c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (is_sync_dialog_) { 95c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) OneClickSigninHelper::LogConfirmHistogramValue( 96c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) clicked_learn_more_ ? 97c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE_OK : 98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) one_click_signin::HISTOGRAM_CONFIRM_OK); 99c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::ResetAndReturn(&start_sync_callback_).Run( 1013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); 102c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bubble_->Close(); 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void OneClickSigninBubbleGtk::OnClickUndo(GtkWidget* link) { 107c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (is_sync_dialog_) { 108c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) OneClickSigninHelper::LogConfirmHistogramValue( 109c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) clicked_learn_more_ ? 110c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE_UNDO : 111c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) one_click_signin::HISTOGRAM_CONFIRM_UNDO); 112c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 113c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::ResetAndReturn(&start_sync_callback_).Run( 114c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) OneClickSigninSyncStarter::UNDO_SYNC); 115c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bubble_->Close(); 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void OneClickSigninBubbleGtk::OnClickLearnMoreLink(GtkWidget* link) { 120c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // We only want to log the Learn More click once per modal dialog instance. 121c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (is_sync_dialog_ && !clicked_learn_more_) { 122c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) OneClickSigninHelper::LogConfirmHistogramValue( 123c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE); 124c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) clicked_learn_more_ = true; 125c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Browser* browser = chrome::FindBrowserWithWindow( 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gtk_window_get_transient_for(bubble_->GetNativeWindow())); 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(browser); 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome::NavigateParams params(browser, GURL(chrome::kChromeSyncLearnMoreURL), 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::PAGE_TRANSITION_LINK); 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) params.disposition = NEW_WINDOW; 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome::Navigate(¶ms); 133c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 134c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (!is_sync_dialog_) { 135c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bubble_->Close(); 136c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void OneClickSigninBubbleGtk::OnClickCloseButton(GtkWidget* button) { 1403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DCHECK(is_sync_dialog_); 141c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) OneClickSigninHelper::LogConfirmHistogramValue( 142c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) clicked_learn_more_ ? 143c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) one_click_signin::HISTOGRAM_CONFIRM_LEARN_MORE_CLOSE : 144c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) one_click_signin::HISTOGRAM_CONFIRM_CLOSE); 1453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) base::ResetAndReturn(&start_sync_callback_).Run( 1463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) OneClickSigninSyncStarter::UNDO_SYNC); 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bubble_->Close(); 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)OneClickSigninBubbleGtk::~OneClickSigninBubbleGtk() { 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void OneClickSigninBubbleGtk::InitializeWidgets( 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BrowserWindowGtk* browser_window_gtk) { 155c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Main dialog/bubble message. 156c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::string label_text; 157c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (is_sync_dialog_) { 1587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch label_text = 159c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) l10n_util::GetStringFUTF8(IDS_ONE_CLICK_SIGNIN_DIALOG_MESSAGE_NEW, 160c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) email_); 161c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } else { 162c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) label_text = !error_message_.empty() ? UTF16ToUTF8(error_message_): 163c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) l10n_util::GetStringUTF8(IDS_ONE_CLICK_SIGNIN_BUBBLE_MESSAGE); 164c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 165c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 166c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) message_label_ = gtk_label_new(label_text.c_str()); 1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gtk_label_set_line_wrap(GTK_LABEL(message_label_), TRUE); 1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gtk_misc_set_alignment(GTK_MISC(message_label_), 0.0, 0.5); 169c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (is_sync_dialog_) 1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gtk_widget_set_size_request(message_label_, kModalDialogMessageWidth, -1); 1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GtkThemeService* const theme_provider = GtkThemeService::GetFrom( 1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser_window_gtk->browser()->profile()); 1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 17590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Advanced link. Will not be displayed in the error bubble. 17690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (is_sync_dialog_ || error_message_.empty()) { 17790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) advanced_link_ = theme_provider->BuildChromeLinkButton( 17890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) l10n_util::GetStringUTF8( 17990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) IDS_ONE_CLICK_SIGNIN_DIALOG_ADVANCED)); 18090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) g_signal_connect(advanced_link_, "clicked", 18190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) G_CALLBACK(OnClickAdvancedLinkThunk), this); 18290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 18390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 18490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // The 'Learn More...' link. 185c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) learn_more_ = theme_provider->BuildChromeLinkButton( 186c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) l10n_util::GetStringUTF8(IDS_LEARN_MORE)); 187c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) g_signal_connect(learn_more_, "clicked", 188c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) G_CALLBACK(OnClickLearnMoreLinkThunk), this); 189c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Make the OK and Undo buttons the same size horizontally. 1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GtkSizeGroup* size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); 1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // OK Button. 1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ok_button_ = gtk_button_new_with_label(l10n_util::GetStringUTF8( 194c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) is_sync_dialog_ ? IDS_ONE_CLICK_SIGNIN_DIALOG_OK_BUTTON : 195c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) IDS_OK).c_str()); 1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) g_signal_connect(ok_button_, "clicked", 1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) G_CALLBACK(OnClickOKThunk), this); 1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gtk_size_group_add_widget(size_group, ok_button_); 1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 200c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (!is_sync_dialog_) 201c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return; 202c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 203c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // The undo button is only in the modal dialog 2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) undo_button_ = gtk_button_new_with_label(l10n_util::GetStringUTF8( 205c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) IDS_ONE_CLICK_SIGNIN_DIALOG_UNDO_BUTTON).c_str()); 2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) g_signal_connect(undo_button_, "clicked", 2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) G_CALLBACK(OnClickUndoThunk), this); 2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gtk_size_group_add_widget(size_group, undo_button_); 2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) g_object_unref(size_group); 2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // The email is always set for the sync dialog. 2137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch header_label_ = theme_provider->BuildLabel( 214d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) l10n_util::GetStringUTF8(IDS_ONE_CLICK_SIGNIN_DIALOG_TITLE_NEW), 2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::kGdkBlack); 2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PangoAttrList* attributes = pango_attr_list_new(); 2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pango_attr_list_insert(attributes, 2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pango_attr_weight_new(PANGO_WEIGHT_BOLD)); 2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gtk_label_set_attributes(GTK_LABEL(header_label_), attributes); 2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pango_attr_list_unref(attributes); 222c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) close_button_.reset(CustomDrawButton::CloseButtonBubble(theme_provider)); 2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) g_signal_connect(close_button_->widget(), "clicked", 2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) G_CALLBACK(OnClickCloseButtonThunk), this); 2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)GtkWidget* OneClickSigninBubbleGtk::LayoutWidgets() { 2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Setup the BubbleGtk content. 2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GtkWidget* content_widget = gtk_vbox_new(FALSE, ui::kContentAreaSpacing); 2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gtk_container_set_border_width(GTK_CONTAINER(content_widget), 2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::kContentAreaBorder); 2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (header_label_) { 2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GtkWidget* top_line = gtk_hbox_new(FALSE, ui::kControlSpacing); 2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gtk_box_pack_start(GTK_BOX(top_line), 2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) header_label_, FALSE, FALSE, 0); 2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gtk_box_pack_end(GTK_BOX(top_line), 2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) close_button_->widget(), FALSE, FALSE, 0); 2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gtk_box_pack_start(GTK_BOX(content_widget), 2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) top_line, FALSE, FALSE, 0); 2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gtk_box_pack_start(GTK_BOX(content_widget), 2432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) message_label_, FALSE, FALSE, 0); 2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 24590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) GtkWidget* box = gtk_hbox_new(FALSE, ui::kControlSpacing); 2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GtkWidget* bottom_line = gtk_hbox_new(FALSE, ui::kControlSpacing); 247c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 248c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (is_sync_dialog_) { 24990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gtk_box_pack_end(GTK_BOX(box), learn_more_, FALSE, FALSE, 0); 25090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gtk_box_pack_start(GTK_BOX(content_widget), box, TRUE, TRUE, 0); 25190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 25290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gtk_box_pack_start(GTK_BOX(content_widget), bottom_line, FALSE, FALSE, 0); 25390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gtk_box_pack_start(GTK_BOX(bottom_line), advanced_link_, FALSE, FALSE, 0); 25490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gtk_box_pack_end(GTK_BOX(bottom_line), ok_button_, FALSE, FALSE, 0); 25590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gtk_box_pack_end(GTK_BOX(bottom_line), undo_button_, FALSE, FALSE, 0); 25690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else { 25790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gtk_box_pack_start(GTK_BOX(box), learn_more_, FALSE, FALSE, 0); 25890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gtk_box_pack_start(GTK_BOX(content_widget), box, TRUE, TRUE, 0); 25990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 26090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Don't display the Advanced link for the error bubble, and 26190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // in this case align the OK button with the Learn More link. 26290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (error_message_.empty()) { 26390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gtk_box_pack_start(GTK_BOX(bottom_line), advanced_link_, FALSE, FALSE, 0); 26490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gtk_box_pack_end(GTK_BOX(bottom_line), ok_button_, FALSE, FALSE, 0); 26590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gtk_box_pack_start(GTK_BOX(content_widget), bottom_line, FALSE, FALSE, 0); 26690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } else { 26790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gtk_box_pack_end(GTK_BOX(box), ok_button_, FALSE, FALSE, 0); 26890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 269c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return content_widget; 2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void OneClickSigninBubbleGtk::ShowWidget(BrowserWindowGtk* browser_window_gtk, 2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GtkWidget* content_widget) { 275c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (is_sync_dialog_) { 276c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) OneClickSigninHelper::LogConfirmHistogramValue( 277c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) one_click_signin::HISTOGRAM_CONFIRM_SHOWN); 278c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 279c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GtkThemeService* const theme_provider = GtkThemeService::GetFrom( 2812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser_window_gtk->browser()->profile()); 2822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 283c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) GtkWidget* parent_widget = is_sync_dialog_ ? 2842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser_window_gtk->GetToolbar()->widget() : 2852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser_window_gtk->GetToolbar()->GetAppMenuButton(); 2862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect bounds = gtk_util::WidgetBounds(parent_widget); 287c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) int flags = (is_sync_dialog_ ? BubbleGtk::NO_ACCELERATORS : 288c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) BubbleGtk::GRAB_INPUT) | 289c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) BubbleGtk::MATCH_SYSTEM_THEME | 290c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) BubbleGtk::POPUP_WINDOW; 2912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bubble_ = BubbleGtk::Show(parent_widget, &bounds, content_widget, 292c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) is_sync_dialog_ ? BubbleGtk::CENTER_OVER_RECT : 2932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BubbleGtk::ANCHOR_TOP_RIGHT, 2942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) flags, 2952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) theme_provider, this); 296c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 297c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) gtk_window_set_transient_for(bubble_->GetNativeWindow(), 2982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser_window_gtk->GetNativeWindow()); 299c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (is_sync_dialog_) { 3002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gtk_window_set_modal(bubble_->GetNativeWindow(), true); 3012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gtk_window_set_focus(bubble_->GetNativeWindow(), ok_button_); 3022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 3032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gtk_widget_grab_focus(ok_button_); 3042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 306